Skip to content

Commit 25486b7

Browse files
committedMar 14, 2018
Update selected thread after loading mach core
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
1 parent 8ed6582 commit 25486b7

File tree

4 files changed

+969
-3
lines changed

4 files changed

+969
-3
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""
2+
Test basics of mach core file debugging.
3+
"""
4+
5+
from __future__ import print_function
6+
7+
import shutil
8+
import struct
9+
10+
import lldb
11+
from lldbsuite.test.decorators import *
12+
from lldbsuite.test.lldbtest import *
13+
from lldbsuite.test import lldbutil
14+
15+
16+
class MachCoreTestCase(TestBase):
17+
NO_DEBUG_INFO_TESTCASE = True
18+
19+
mydir = TestBase.compute_mydir(__file__)
20+
21+
def setUp(self):
22+
super(MachCoreTestCase, self).setUp()
23+
self._initial_platform = lldb.DBG.GetSelectedPlatform()
24+
25+
def tearDown(self):
26+
lldb.DBG.SetSelectedPlatform(self._initial_platform)
27+
super(MachCoreTestCase, self).tearDown()
28+
29+
def test_selected_thread(self):
30+
"""Test that the right thread is selected after a core is loaded."""
31+
# Create core form YAML.
32+
self.yaml2obj("test.core.yaml", self.getBuildArtifact("test.core"))
33+
34+
# Set debugger into synchronous mode
35+
self.dbg.SetAsync(False)
36+
37+
# Create a target by the debugger.
38+
target = self.dbg.CreateTarget("")
39+
40+
# Load OS plugin.
41+
python_os_plugin_path = os.path.join(self.getSourceDir(),
42+
'operating_system.py')
43+
command = "settings set target.process.python-os-plugin-path '{}'".format(
44+
python_os_plugin_path)
45+
self.dbg.HandleCommand(command)
46+
47+
# Load core.
48+
process = target.LoadCore(self.getBuildArtifact("test.core"))
49+
self.assertTrue(process, PROCESS_IS_VALID)
50+
self.assertEqual(process.GetNumThreads(), 3)
51+
52+
# Verify our OS plug-in threads showed up
53+
thread = process.GetThreadByID(0x111111111)
54+
self.assertTrue(thread.IsValid(
55+
), "Make sure there is a thread 0x111111111 after we load the python OS plug-in"
56+
)
57+
thread = process.GetThreadByID(0x222222222)
58+
self.assertTrue(thread.IsValid(
59+
), "Make sure there is a thread 0x222222222 after we load the python OS plug-in"
60+
)
61+
thread = process.GetThreadByID(0x333333333)
62+
self.assertTrue(thread.IsValid(
63+
), "Make sure there is a thread 0x333333333 after we load the python OS plug-in"
64+
)
65+
66+
# Verify that the correct thread is selected
67+
thread = process.GetSelectedThread()
68+
self.assertEqual(thread.GetThreadID(), 0x333333333)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import lldb
2+
import struct
3+
4+
5+
class OperatingSystemPlugIn(object):
6+
"""Class that provides data for an instance of a LLDB 'OperatingSystemPython' plug-in class"""
7+
8+
def __init__(self, process):
9+
'''Initialization needs a valid.SBProcess object.
10+
11+
This plug-in will get created after a live process is valid and has stopped for the first time.
12+
'''
13+
self.process = None
14+
self.registers = None
15+
self.threads = None
16+
if isinstance(process, lldb.SBProcess) and process.IsValid():
17+
self.process = process
18+
self.threads = None # Will be an dictionary containing info for each thread
19+
20+
def get_target(self):
21+
return self.process.target
22+
23+
def get_thread_info(self):
24+
if not self.threads:
25+
self.threads = [{
26+
'tid': 0x111111111,
27+
'name': 'one',
28+
'queue': 'queue1',
29+
'state': 'stopped',
30+
'stop_reason': 'none'
31+
}, {
32+
'tid': 0x222222222,
33+
'name': 'two',
34+
'queue': 'queue2',
35+
'state': 'stopped',
36+
'stop_reason': 'none'
37+
}, {
38+
'tid': 0x333333333,
39+
'name': 'three',
40+
'queue': 'queue3',
41+
'state': 'stopped',
42+
'stop_reason': 'sigstop',
43+
'core': 0
44+
}]
45+
return self.threads

0 commit comments

Comments
 (0)
Please sign in to comment.