2 Test that the Python operating system plugin works correctly
9 from lldbsuite.test.lldbtest import *
10 import lldbsuite.test.lldbutil as lldbutil
13 class PluginPythonOSPlugin(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
16 NO_DEBUG_INFO_TESTCASE = True
18 def test_python_os_plugin(self):
19 """Test that the Python operating system plugin works correctly"""
21 self.run_python_os_funcionality()
23 def run_python_os_step(self):
24 """Test that the Python operating system plugin works correctly when single stepping a virtual thread"""
26 self.run_python_os_step()
28 def verify_os_thread_registers(self, thread):
29 frame = thread.GetFrameAtIndex(0)
30 registers = frame.GetRegisters().GetValueAtIndex(0)
31 reg_value = thread.GetThreadID() + 1
34 reg.GetValueAsUnsigned() == reg_value,
35 "Verify the registers contains the correct value")
36 reg_value = reg_value + 1
38 def run_python_os_funcionality(self):
39 """Test that the Python operating system plugin works correctly"""
41 # Set debugger into synchronous mode
42 self.dbg.SetAsync(False)
44 # Create a target by the debugger.
45 exe = self.getBuildArtifact("a.out")
46 python_os_plugin_path = os.path.join(self.getSourceDir(),
47 "operating_system.py")
48 target = self.dbg.CreateTarget(exe)
49 self.assertTrue(target, VALID_TARGET)
51 # Set breakpoints inside and outside methods that take pointers to the
53 lldbutil.run_break_set_by_source_regexp(self, "// Set breakpoint here")
55 # Register our shared libraries for remote targets so they get
56 # automatically uploaded
60 # Now launch the process, and do not stop at entry point.
61 process = target.LaunchSimple(
62 arguments, environment, self.get_process_working_directory())
63 self.assertTrue(process, PROCESS_IS_VALID)
65 # Make sure there are no OS plug-in created thread when we first stop
66 # at our breakpoint in main
67 thread = process.GetThreadByID(0x111111111)
70 "Make sure there is no thread 0x111111111 before we load the python OS plug-in")
71 thread = process.GetThreadByID(0x222222222)
74 "Make sure there is no thread 0x222222222 before we load the python OS plug-in")
75 thread = process.GetThreadByID(0x333333333)
78 "Make sure there is no thread 0x333333333 before we load the python OS plug-in")
80 # Now load the python OS plug-in which should update the thread list and we should have
81 # OS plug-in created threads with the IDs: 0x111111111, 0x222222222,
83 command = "settings set target.process.python-os-plugin-path '%s'" % python_os_plugin_path
84 self.dbg.HandleCommand(command)
86 # Verify our OS plug-in threads showed up
87 thread = process.GetThreadByID(0x111111111)
90 "Make sure there is a thread 0x111111111 after we load the python OS plug-in")
91 self.verify_os_thread_registers(thread)
92 thread = process.GetThreadByID(0x222222222)
95 "Make sure there is a thread 0x222222222 after we load the python OS plug-in")
96 self.verify_os_thread_registers(thread)
97 thread = process.GetThreadByID(0x333333333)
100 "Make sure there is a thread 0x333333333 after we load the python OS plug-in")
101 self.verify_os_thread_registers(thread)
103 # Now clear the OS plug-in path to make the OS plug-in created threads
105 self.dbg.HandleCommand(
106 "settings clear target.process.python-os-plugin-path")
108 # Verify the threads are gone after unloading the python OS plug-in
109 thread = process.GetThreadByID(0x111111111)
112 "Make sure there is no thread 0x111111111 after we unload the python OS plug-in")
113 thread = process.GetThreadByID(0x222222222)
116 "Make sure there is no thread 0x222222222 after we unload the python OS plug-in")
117 thread = process.GetThreadByID(0x333333333)
120 "Make sure there is no thread 0x333333333 after we unload the python OS plug-in")
122 def run_python_os_step(self):
123 """Test that the Python operating system plugin works correctly and allows single stepping of a virtual thread that is backed by a real thread"""
125 # Set debugger into synchronous mode
126 self.dbg.SetAsync(False)
128 # Create a target by the debugger.
129 exe = self.getBuildArtifact("a.out")
130 python_os_plugin_path = os.path.join(self.getSourceDir(),
131 "operating_system2.py")
132 target = self.dbg.CreateTarget(exe)
133 self.assertTrue(target, VALID_TARGET)
135 # Set breakpoints inside and outside methods that take pointers to the
137 lldbutil.run_break_set_by_source_regexp(self, "// Set breakpoint here")
139 # Register our shared libraries for remote targets so they get
140 # automatically uploaded
144 # Now launch the process, and do not stop at entry point.
145 process = target.LaunchSimple(
146 arguments, environment, self.get_process_working_directory())
147 self.assertTrue(process, PROCESS_IS_VALID)
149 # Make sure there are no OS plug-in created thread when we first stop
150 # at our breakpoint in main
151 thread = process.GetThreadByID(0x111111111)
154 "Make sure there is no thread 0x111111111 before we load the python OS plug-in")
156 # Now load the python OS plug-in which should update the thread list and we should have
157 # OS plug-in created threads with the IDs: 0x111111111, 0x222222222,
159 command = "settings set target.process.python-os-plugin-path '%s'" % python_os_plugin_path
160 self.dbg.HandleCommand(command)
162 # Verify our OS plug-in threads showed up
163 thread = process.GetThreadByID(0x111111111)
166 "Make sure there is a thread 0x111111111 after we load the python OS plug-in")
168 frame = thread.GetFrameAtIndex(0)
171 "Make sure we get a frame from thread 0x111111111")
172 line_entry = frame.GetLineEntry()
175 line_entry.GetFileSpec().GetFilename() == 'main.c',
176 "Make sure we stopped on line 5 in main.c")
178 line_entry.GetLine() == 5,
179 "Make sure we stopped on line 5 in main.c")
181 # Now single step thread 0x111111111 and make sure it does what we need
185 frame = thread.GetFrameAtIndex(0)
188 "Make sure we get a frame from thread 0x111111111")
189 line_entry = frame.GetLineEntry()
192 line_entry.GetFileSpec().GetFilename() == 'main.c',
193 "Make sure we stepped from line 5 to line 6 in main.c")
194 self.assertTrue(line_entry.GetLine() == 6,
195 "Make sure we stepped from line 5 to line 6 in main.c")