Skip to content

Commit

Permalink
Update selected thread after loading mach core
Browse files Browse the repository at this point in the history
The OS plugins might have updated the thread list after a core file has
been loaded. The physical thread in the core file may no longer be the
one that should be selected. Hence we should run the thread selection
logic after loading the core.

Differential revision: https://reviews.llvm.org/D44139

llvm-svn: 327501
  • Loading branch information
JDevlieghere committed Mar 14, 2018
1 parent 8ed6582 commit 25486b7
Show file tree
Hide file tree
Showing 4 changed files with 969 additions and 3 deletions.
@@ -0,0 +1,68 @@
"""
Test basics of mach core file debugging.
"""

from __future__ import print_function

import shutil
import struct

import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class MachCoreTestCase(TestBase):
NO_DEBUG_INFO_TESTCASE = True

mydir = TestBase.compute_mydir(__file__)

def setUp(self):
super(MachCoreTestCase, self).setUp()
self._initial_platform = lldb.DBG.GetSelectedPlatform()

def tearDown(self):
lldb.DBG.SetSelectedPlatform(self._initial_platform)
super(MachCoreTestCase, self).tearDown()

def test_selected_thread(self):
"""Test that the right thread is selected after a core is loaded."""
# Create core form YAML.
self.yaml2obj("test.core.yaml", self.getBuildArtifact("test.core"))

# Set debugger into synchronous mode
self.dbg.SetAsync(False)

# Create a target by the debugger.
target = self.dbg.CreateTarget("")

# Load OS plugin.
python_os_plugin_path = os.path.join(self.getSourceDir(),
'operating_system.py')
command = "settings set target.process.python-os-plugin-path '{}'".format(
python_os_plugin_path)
self.dbg.HandleCommand(command)

# Load core.
process = target.LoadCore(self.getBuildArtifact("test.core"))
self.assertTrue(process, PROCESS_IS_VALID)
self.assertEqual(process.GetNumThreads(), 3)

# Verify our OS plug-in threads showed up
thread = process.GetThreadByID(0x111111111)
self.assertTrue(thread.IsValid(
), "Make sure there is a thread 0x111111111 after we load the python OS plug-in"
)
thread = process.GetThreadByID(0x222222222)
self.assertTrue(thread.IsValid(
), "Make sure there is a thread 0x222222222 after we load the python OS plug-in"
)
thread = process.GetThreadByID(0x333333333)
self.assertTrue(thread.IsValid(
), "Make sure there is a thread 0x333333333 after we load the python OS plug-in"
)

# Verify that the correct thread is selected
thread = process.GetSelectedThread()
self.assertEqual(thread.GetThreadID(), 0x333333333)
@@ -0,0 +1,45 @@
import lldb
import struct


class OperatingSystemPlugIn(object):
"""Class that provides data for an instance of a LLDB 'OperatingSystemPython' plug-in class"""

def __init__(self, process):
'''Initialization needs a valid.SBProcess object.
This plug-in will get created after a live process is valid and has stopped for the first time.
'''
self.process = None
self.registers = None
self.threads = None
if isinstance(process, lldb.SBProcess) and process.IsValid():
self.process = process
self.threads = None # Will be an dictionary containing info for each thread

def get_target(self):
return self.process.target

def get_thread_info(self):
if not self.threads:
self.threads = [{
'tid': 0x111111111,
'name': 'one',
'queue': 'queue1',
'state': 'stopped',
'stop_reason': 'none'
}, {
'tid': 0x222222222,
'name': 'two',
'queue': 'queue2',
'state': 'stopped',
'stop_reason': 'none'
}, {
'tid': 0x333333333,
'name': 'three',
'queue': 'queue3',
'state': 'stopped',
'stop_reason': 'sigstop',
'core': 0
}]
return self.threads

0 comments on commit 25486b7

Please sign in to comment.