diff options
| author | Jonas Devlieghere <jonas@devlieghere.com> | 2023-05-25 08:48:57 -0700 |
|---|---|---|
| committer | Jonas Devlieghere <jonas@devlieghere.com> | 2023-05-25 12:54:09 -0700 |
| commit | 2238dcc39358353cac21df75c3c3286ab20b8f53 (patch) | |
| tree | 1bb7ec8d7405ccd7fdb5a8a78d0cf5ef40bcc963 /lldb/test/API/functionalities/plugins/python_os_plugin | |
| parent | daeee56798c51e8f007e8e8e6e677a420b14c9ef (diff) | |
[NFC][Py Reformat] Reformat python files in lldb
This is an ongoing series of commits that are reformatting our Python
code. Reformatting is done with `black` (23.1.0).
If you end up having problems merging this commit because you have made
changes to a python file, the best way to handle that is to run `git
checkout --ours <yourfile>` and then reformat it with black.
RFC: https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style
Differential revision: https://reviews.llvm.org/D151460
Diffstat (limited to 'lldb/test/API/functionalities/plugins/python_os_plugin')
5 files changed, 632 insertions, 171 deletions
diff --git a/lldb/test/API/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py b/lldb/test/API/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py index c778a556f9fa..9ec49d0069a6 100644 --- a/lldb/test/API/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py +++ b/lldb/test/API/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py @@ -3,7 +3,6 @@ Test that the Python operating system plugin works correctly """ - import os import lldb from lldbsuite.test.lldbtest import * @@ -29,8 +28,10 @@ class PluginPythonOSPlugin(TestBase): reg_value = thread.GetThreadID() + 1 for reg in registers: self.assertEqual( - reg.GetValueAsUnsigned(), reg_value, - "Verify the registers contains the correct value") + reg.GetValueAsUnsigned(), + reg_value, + "Verify the registers contains the correct value", + ) reg_value = reg_value + 1 def run_python_os_funcionality(self): @@ -41,8 +42,7 @@ class PluginPythonOSPlugin(TestBase): # Create a target by the debugger. exe = self.getBuildArtifact("a.out") - python_os_plugin_path = os.path.join(self.getSourceDir(), - "operating_system.py") + python_os_plugin_path = os.path.join(self.getSourceDir(), "operating_system.py") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) @@ -57,7 +57,8 @@ class PluginPythonOSPlugin(TestBase): # Now launch the process, and do not stop at entry point. process = target.LaunchSimple( - arguments, environment, self.get_process_working_directory()) + arguments, environment, self.get_process_working_directory() + ) self.assertTrue(process, PROCESS_IS_VALID) # Make sure there are no OS plug-in created thread when we first stop @@ -65,57 +66,68 @@ class PluginPythonOSPlugin(TestBase): thread = process.GetThreadByID(0x111111111) self.assertFalse( thread.IsValid(), - "Make sure there is no thread 0x111111111 before we load the python OS plug-in") + "Make sure there is no thread 0x111111111 before we load the python OS plug-in", + ) thread = process.GetThreadByID(0x222222222) self.assertFalse( thread.IsValid(), - "Make sure there is no thread 0x222222222 before we load the python OS plug-in") + "Make sure there is no thread 0x222222222 before we load the python OS plug-in", + ) thread = process.GetThreadByID(0x333333333) self.assertFalse( thread.IsValid(), - "Make sure there is no thread 0x333333333 before we load the python OS plug-in") + "Make sure there is no thread 0x333333333 before we load the python OS plug-in", + ) # Now load the python OS plug-in which should update the thread list and we should have # OS plug-in created threads with the IDs: 0x111111111, 0x222222222, # 0x333333333 - command = "settings set target.process.python-os-plugin-path '%s'" % python_os_plugin_path + command = ( + "settings set target.process.python-os-plugin-path '%s'" + % python_os_plugin_path + ) self.dbg.HandleCommand(command) # 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") + "Make sure there is a thread 0x111111111 after we load the python OS plug-in", + ) self.verify_os_thread_registers(thread) thread = process.GetThreadByID(0x222222222) self.assertTrue( thread.IsValid(), - "Make sure there is a thread 0x222222222 after we load the python OS plug-in") + "Make sure there is a thread 0x222222222 after we load the python OS plug-in", + ) self.verify_os_thread_registers(thread) thread = process.GetThreadByID(0x333333333) self.assertTrue( thread.IsValid(), - "Make sure there is a thread 0x333333333 after we load the python OS plug-in") + "Make sure there is a thread 0x333333333 after we load the python OS plug-in", + ) self.verify_os_thread_registers(thread) # Now clear the OS plug-in path to make the OS plug-in created threads # disappear - self.dbg.HandleCommand( - "settings clear target.process.python-os-plugin-path") + self.dbg.HandleCommand("settings clear target.process.python-os-plugin-path") # Verify the threads are gone after unloading the python OS plug-in thread = process.GetThreadByID(0x111111111) self.assertFalse( thread.IsValid(), - "Make sure there is no thread 0x111111111 after we unload the python OS plug-in") + "Make sure there is no thread 0x111111111 after we unload the python OS plug-in", + ) thread = process.GetThreadByID(0x222222222) self.assertFalse( thread.IsValid(), - "Make sure there is no thread 0x222222222 after we unload the python OS plug-in") + "Make sure there is no thread 0x222222222 after we unload the python OS plug-in", + ) thread = process.GetThreadByID(0x333333333) self.assertFalse( thread.IsValid(), - "Make sure there is no thread 0x333333333 after we unload the python OS plug-in") + "Make sure there is no thread 0x333333333 after we unload the python OS plug-in", + ) def run_python_os_step(self): """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,8 +137,9 @@ class PluginPythonOSPlugin(TestBase): # Create a target by the debugger. exe = self.getBuildArtifact("a.out") - python_os_plugin_path = os.path.join(self.getSourceDir(), - "operating_system2.py") + python_os_plugin_path = os.path.join( + self.getSourceDir(), "operating_system2.py" + ) target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) @@ -141,7 +154,8 @@ class PluginPythonOSPlugin(TestBase): # Now launch the process, and do not stop at entry point. process = target.LaunchSimple( - arguments, environment, self.get_process_working_directory()) + arguments, environment, self.get_process_working_directory() + ) self.assertTrue(process, PROCESS_IS_VALID) # Make sure there are no OS plug-in created thread when we first stop @@ -149,32 +163,39 @@ class PluginPythonOSPlugin(TestBase): thread = process.GetThreadByID(0x111111111) self.assertFalse( thread.IsValid(), - "Make sure there is no thread 0x111111111 before we load the python OS plug-in") + "Make sure there is no thread 0x111111111 before we load the python OS plug-in", + ) # Now load the python OS plug-in which should update the thread list and we should have # OS plug-in created threads with the IDs: 0x111111111, 0x222222222, # 0x333333333 - command = "settings set target.process.python-os-plugin-path '%s'" % python_os_plugin_path + command = ( + "settings set target.process.python-os-plugin-path '%s'" + % python_os_plugin_path + ) self.dbg.HandleCommand(command) # 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") + "Make sure there is a thread 0x111111111 after we load the python OS plug-in", + ) frame = thread.GetFrameAtIndex(0) self.assertTrue( - frame.IsValid(), - "Make sure we get a frame from thread 0x111111111") + frame.IsValid(), "Make sure we get a frame from thread 0x111111111" + ) line_entry = frame.GetLineEntry() self.assertEqual( - line_entry.GetFileSpec().GetFilename(), 'main.c', - "Make sure we stopped on line 5 in main.c") + line_entry.GetFileSpec().GetFilename(), + "main.c", + "Make sure we stopped on line 5 in main.c", + ) self.assertEqual( - line_entry.GetLine(), 5, - "Make sure we stopped on line 5 in main.c") + line_entry.GetLine(), 5, "Make sure we stopped on line 5 in main.c" + ) # Now single step thread 0x111111111 and make sure it does what we need # it to @@ -182,12 +203,17 @@ class PluginPythonOSPlugin(TestBase): frame = thread.GetFrameAtIndex(0) self.assertTrue( - frame.IsValid(), - "Make sure we get a frame from thread 0x111111111") + frame.IsValid(), "Make sure we get a frame from thread 0x111111111" + ) line_entry = frame.GetLineEntry() self.assertEqual( - line_entry.GetFileSpec().GetFilename(), 'main.c', - "Make sure we stepped from line 5 to line 6 in main.c") - self.assertEquals(line_entry.GetLine(), 6, - "Make sure we stepped from line 5 to line 6 in main.c") + line_entry.GetFileSpec().GetFilename(), + "main.c", + "Make sure we stepped from line 5 to line 6 in main.c", + ) + self.assertEquals( + line_entry.GetLine(), + 6, + "Make sure we stepped from line 5 to line 6 in main.c", + ) diff --git a/lldb/test/API/functionalities/plugins/python_os_plugin/operating_system.py b/lldb/test/API/functionalities/plugins/python_os_plugin/operating_system.py index 3c949792983f..52c678fac2ef 100644 --- a/lldb/test/API/functionalities/plugins/python_os_plugin/operating_system.py +++ b/lldb/test/API/functionalities/plugins/python_os_plugin/operating_system.py @@ -8,10 +8,10 @@ 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. + """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.''' + first time.""" self.process = None self.registers = None self.threads = None @@ -28,11 +28,12 @@ class OperatingSystemPlugIn(object): def create_thread(self, tid, context): if tid == 0x444444444: thread_info = { - 'tid': tid, - 'name': 'four', - 'queue': 'queue4', - 'state': 'stopped', - 'stop_reason': 'none'} + "tid": tid, + "name": "four", + "queue": "queue4", + "state": "stopped", + "stop_reason": "none", + } self.threads.append(thread_info) return thread_info return None @@ -56,55 +57,264 @@ class OperatingSystemPlugIn(object): # in memory. Don't specify this if your register layout in memory doesn't match the layout # described by the dictionary returned from a call to the # get_register_info() method. - self.threads = [{'tid': 0x111111111, - 'name': 'one', - 'queue': 'queue1', - 'state': 'stopped', - 'stop_reason': 'breakpoint'}, - {'tid': 0x222222222, - 'name': 'two', - 'queue': 'queue2', - 'state': 'stopped', - 'stop_reason': 'none'}, - {'tid': 0x333333333, - 'name': 'three', - 'queue': 'queue3', - 'state': 'stopped', - 'stop_reason': 'trace'}] + self.threads = [ + { + "tid": 0x111111111, + "name": "one", + "queue": "queue1", + "state": "stopped", + "stop_reason": "breakpoint", + }, + { + "tid": 0x222222222, + "name": "two", + "queue": "queue2", + "state": "stopped", + "stop_reason": "none", + }, + { + "tid": 0x333333333, + "name": "three", + "queue": "queue3", + "state": "stopped", + "stop_reason": "trace", + }, + ] return self.threads def get_register_info(self): if self.registers is None: self.registers = dict() - self.registers['sets'] = ['GPR'] - self.registers['registers'] = [ - {'name': 'rax', 'bitsize': 64, 'offset': 0, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 0, 'dwarf': 0}, - {'name': 'rbx', 'bitsize': 64, 'offset': 8, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 3, 'dwarf': 3}, - {'name': 'rcx', 'bitsize': 64, 'offset': 16, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 2, 'dwarf': 2, 'generic': 'arg4', 'alt-name': 'arg4', }, - {'name': 'rdx', 'bitsize': 64, 'offset': 24, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 1, 'dwarf': 1, 'generic': 'arg3', 'alt-name': 'arg3', }, - {'name': 'rdi', 'bitsize': 64, 'offset': 32, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 5, 'dwarf': 5, 'generic': 'arg1', 'alt-name': 'arg1', }, - {'name': 'rsi', 'bitsize': 64, 'offset': 40, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 4, 'dwarf': 4, 'generic': 'arg2', 'alt-name': 'arg2', }, - {'name': 'rbp', 'bitsize': 64, 'offset': 48, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 6, 'dwarf': 6, 'generic': 'fp', 'alt-name': 'fp', }, - {'name': 'rsp', 'bitsize': 64, 'offset': 56, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 7, 'dwarf': 7, 'generic': 'sp', 'alt-name': 'sp', }, - {'name': 'r8', 'bitsize': 64, 'offset': 64, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 8, 'dwarf': 8, 'generic': 'arg5', 'alt-name': 'arg5', }, - {'name': 'r9', 'bitsize': 64, 'offset': 72, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 9, 'dwarf': 9, 'generic': 'arg6', 'alt-name': 'arg6', }, - {'name': 'r10', 'bitsize': 64, 'offset': 80, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 10, 'dwarf': 10}, - {'name': 'r11', 'bitsize': 64, 'offset': 88, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 11, 'dwarf': 11}, - {'name': 'r12', 'bitsize': 64, 'offset': 96, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 12, 'dwarf': 12}, - {'name': 'r13', 'bitsize': 64, 'offset': 104, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 13, 'dwarf': 13}, - {'name': 'r14', 'bitsize': 64, 'offset': 112, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 14, 'dwarf': 14}, - {'name': 'r15', 'bitsize': 64, 'offset': 120, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 15, 'dwarf': 15}, - {'name': 'rip', 'bitsize': 64, 'offset': 128, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 16, 'dwarf': 16, 'generic': 'pc', 'alt-name': 'pc'}, - {'name': 'rflags', 'bitsize': 64, 'offset': 136, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'generic': 'flags', 'alt-name': 'flags'}, - {'name': 'cs', 'bitsize': 64, 'offset': 144, 'encoding': 'uint', 'format': 'hex', 'set': 0}, - {'name': 'fs', 'bitsize': 64, 'offset': 152, 'encoding': 'uint', 'format': 'hex', 'set': 0}, - {'name': 'gs', 'bitsize': 64, 'offset': 160, 'encoding': 'uint', 'format': 'hex', 'set': 0}, + self.registers["sets"] = ["GPR"] + self.registers["registers"] = [ + { + "name": "rax", + "bitsize": 64, + "offset": 0, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 0, + "dwarf": 0, + }, + { + "name": "rbx", + "bitsize": 64, + "offset": 8, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 3, + "dwarf": 3, + }, + { + "name": "rcx", + "bitsize": 64, + "offset": 16, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 2, + "dwarf": 2, + "generic": "arg4", + "alt-name": "arg4", + }, + { + "name": "rdx", + "bitsize": 64, + "offset": 24, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 1, + "dwarf": 1, + "generic": "arg3", + "alt-name": "arg3", + }, + { + "name": "rdi", + "bitsize": 64, + "offset": 32, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 5, + "dwarf": 5, + "generic": "arg1", + "alt-name": "arg1", + }, + { + "name": "rsi", + "bitsize": 64, + "offset": 40, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 4, + "dwarf": 4, + "generic": "arg2", + "alt-name": "arg2", + }, + { + "name": "rbp", + "bitsize": 64, + "offset": 48, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 6, + "dwarf": 6, + "generic": "fp", + "alt-name": "fp", + }, + { + "name": "rsp", + "bitsize": 64, + "offset": 56, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 7, + "dwarf": 7, + "generic": "sp", + "alt-name": "sp", + }, + { + "name": "r8", + "bitsize": 64, + "offset": 64, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 8, + "dwarf": 8, + "generic": "arg5", + "alt-name": "arg5", + }, + { + "name": "r9", + "bitsize": 64, + "offset": 72, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 9, + "dwarf": 9, + "generic": "arg6", + "alt-name": "arg6", + }, + { + "name": "r10", + "bitsize": 64, + "offset": 80, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 10, + "dwarf": 10, + }, + { + "name": "r11", + "bitsize": 64, + "offset": 88, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 11, + "dwarf": 11, + }, + { + "name": "r12", + "bitsize": 64, + "offset": 96, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 12, + "dwarf": 12, + }, + { + "name": "r13", + "bitsize": 64, + "offset": 104, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 13, + "dwarf": 13, + }, + { + "name": "r14", + "bitsize": 64, + "offset": 112, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 14, + "dwarf": 14, + }, + { + "name": "r15", + "bitsize": 64, + "offset": 120, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 15, + "dwarf": 15, + }, + { + "name": "rip", + "bitsize": 64, + "offset": 128, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 16, + "dwarf": 16, + "generic": "pc", + "alt-name": "pc", + }, + { + "name": "rflags", + "bitsize": 64, + "offset": 136, + "encoding": "uint", + "format": "hex", + "set": 0, + "generic": "flags", + "alt-name": "flags", + }, + { + "name": "cs", + "bitsize": 64, + "offset": 144, + "encoding": "uint", + "format": "hex", + "set": 0, + }, + { + "name": "fs", + "bitsize": 64, + "offset": 152, + "encoding": "uint", + "format": "hex", + "set": 0, + }, + { + "name": "gs", + "bitsize": 64, + "offset": 160, + "encoding": "uint", + "format": "hex", + "set": 0, + }, ] return self.registers def get_register_data(self, tid): return struct.pack( - '21Q', + "21Q", tid + 1, tid + 2, tid + 3, @@ -125,4 +335,5 @@ class OperatingSystemPlugIn(object): tid + 18, tid + 19, tid + 20, - tid + 21) + tid + 21, + ) diff --git a/lldb/test/API/functionalities/plugins/python_os_plugin/operating_system2.py b/lldb/test/API/functionalities/plugins/python_os_plugin/operating_system2.py index 26864bbc6aa3..3ba68e40cb80 100644 --- a/lldb/test/API/functionalities/plugins/python_os_plugin/operating_system2.py +++ b/lldb/test/API/functionalities/plugins/python_os_plugin/operating_system2.py @@ -8,10 +8,10 @@ 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. + """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.''' + first time.""" self.process = None self.registers = None self.threads = None @@ -28,11 +28,12 @@ class OperatingSystemPlugIn(object): def create_thread(self, tid, context): if tid == 0x444444444: thread_info = { - 'tid': tid, - 'name': 'four', - 'queue': 'queue4', - 'state': 'stopped', - 'stop_reason': 'none'} + "tid": tid, + "name": "four", + "queue": "queue4", + "state": "stopped", + "stop_reason": "none", + } self.threads.append(thread_info) return thread_info return None @@ -56,43 +57,242 @@ class OperatingSystemPlugIn(object): # in memory. Don't specify this if your register layout in memory doesn't match the layout # described by the dictionary returned from a call to the # get_register_info() method. - self.threads = [ - {'tid': 0x111111111, 'core': 0} - ] + self.threads = [{"tid": 0x111111111, "core": 0}] return self.threads def get_register_info(self): if self.registers is None: self.registers = dict() - self.registers['sets'] = ['GPR'] - self.registers['registers'] = [ - {'name': 'rax', 'bitsize': 64, 'offset': 0, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 0, 'dwarf': 0}, - {'name': 'rbx', 'bitsize': 64, 'offset': 8, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 3, 'dwarf': 3}, - {'name': 'rcx', 'bitsize': 64, 'offset': 16, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 2, 'dwarf': 2, 'generic': 'arg4', 'alt-name': 'arg4', }, - {'name': 'rdx', 'bitsize': 64, 'offset': 24, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 1, 'dwarf': 1, 'generic': 'arg3', 'alt-name': 'arg3', }, - {'name': 'rdi', 'bitsize': 64, 'offset': 32, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 5, 'dwarf': 5, 'generic': 'arg1', 'alt-name': 'arg1', }, - {'name': 'rsi', 'bitsize': 64, 'offset': 40, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 4, 'dwarf': 4, 'generic': 'arg2', 'alt-name': 'arg2', }, - {'name': 'rbp', 'bitsize': 64, 'offset': 48, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 6, 'dwarf': 6, 'generic': 'fp', 'alt-name': 'fp', }, - {'name': 'rsp', 'bitsize': 64, 'offset': 56, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 7, 'dwarf': 7, 'generic': 'sp', 'alt-name': 'sp', }, - {'name': 'r8', 'bitsize': 64, 'offset': 64, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 8, 'dwarf': 8, 'generic': 'arg5', 'alt-name': 'arg5', }, - {'name': 'r9', 'bitsize': 64, 'offset': 72, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 9, 'dwarf': 9, 'generic': 'arg6', 'alt-name': 'arg6', }, - {'name': 'r10', 'bitsize': 64, 'offset': 80, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 10, 'dwarf': 10}, - {'name': 'r11', 'bitsize': 64, 'offset': 88, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 11, 'dwarf': 11}, - {'name': 'r12', 'bitsize': 64, 'offset': 96, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 12, 'dwarf': 12}, - {'name': 'r13', 'bitsize': 64, 'offset': 104, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 13, 'dwarf': 13}, - {'name': 'r14', 'bitsize': 64, 'offset': 112, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 14, 'dwarf': 14}, - {'name': 'r15', 'bitsize': 64, 'offset': 120, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 15, 'dwarf': 15}, - {'name': 'rip', 'bitsize': 64, 'offset': 128, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 16, 'dwarf': 16, 'generic': 'pc', 'alt-name': 'pc'}, - {'name': 'rflags', 'bitsize': 64, 'offset': 136, 'encoding': 'uint', 'format': 'hex', 'set': 0, 'generic': 'flags', 'alt-name': 'flags'}, - {'name': 'cs', 'bitsize': 64, 'offset': 144, 'encoding': 'uint', 'format': 'hex', 'set': 0}, - {'name': 'fs', 'bitsize': 64, 'offset': 152, 'encoding': 'uint', 'format': 'hex', 'set': 0}, - {'name': 'gs', 'bitsize': 64, 'offset': 160, 'encoding': 'uint', 'format': 'hex', 'set': 0}, + self.registers["sets"] = ["GPR"] + self.registers["registers"] = [ + { + "name": "rax", + "bitsize": 64, + "offset": 0, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 0, + "dwarf": 0, + }, + { + "name": "rbx", + "bitsize": 64, + "offset": 8, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 3, + "dwarf": 3, + }, + { + "name": "rcx", + "bitsize": 64, + "offset": 16, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 2, + "dwarf": 2, + "generic": "arg4", + "alt-name": "arg4", + }, + { + "name": "rdx", + "bitsize": 64, + "offset": 24, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 1, + "dwarf": 1, + "generic": "arg3", + "alt-name": "arg3", + }, + { + "name": "rdi", + "bitsize": 64, + "offset": 32, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 5, + "dwarf": 5, + "generic": "arg1", + "alt-name": "arg1", + }, + { + "name": "rsi", + "bitsize": 64, + "offset": 40, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 4, + "dwarf": 4, + "generic": "arg2", + "alt-name": "arg2", + }, + { + "name": "rbp", + "bitsize": 64, + "offset": 48, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 6, + "dwarf": 6, + "generic": "fp", + "alt-name": "fp", + }, + { + "name": "rsp", + "bitsize": 64, + "offset": 56, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 7, + "dwarf": 7, + "generic": "sp", + "alt-name": "sp", + }, + { + "name": "r8", + "bitsize": 64, + "offset": 64, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 8, + "dwarf": 8, + "generic": "arg5", + "alt-name": "arg5", + }, + { + "name": "r9", + "bitsize": 64, + "offset": 72, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 9, + "dwarf": 9, + "generic": "arg6", + "alt-name": "arg6", + }, + { + "name": "r10", + "bitsize": 64, + "offset": 80, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 10, + "dwarf": 10, + }, + { + "name": "r11", + "bitsize": 64, + "offset": 88, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 11, + "dwarf": 11, + }, + { + "name": "r12", + "bitsize": 64, + "offset": 96, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 12, + "dwarf": 12, + }, + { + "name": "r13", + "bitsize": 64, + "offset": 104, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 13, + "dwarf": 13, + }, + { + "name": "r14", + "bitsize": 64, + "offset": 112, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 14, + "dwarf": 14, + }, + { + "name": "r15", + "bitsize": 64, + "offset": 120, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 15, + "dwarf": 15, + }, + { + "name": "rip", + "bitsize": 64, + "offset": 128, + "encoding": "uint", + "format": "hex", + "set": 0, + "gcc": 16, + "dwarf": 16, + "generic": "pc", + "alt-name": "pc", + }, + { + "name": "rflags", + "bitsize": 64, + "offset": 136, + "encoding": "uint", + "format": "hex", + "set": 0, + "generic": "flags", + "alt-name": "flags", + }, + { + "name": "cs", + "bitsize": 64, + "offset": 144, + "encoding": "uint", + "format": "hex", + "set": 0, + }, + { + "name": "fs", + "bitsize": 64, + "offset": 152, + "encoding": "uint", + "format": "hex", + "set": 0, + }, + { + "name": "gs", + "bitsize": 64, + "offset": 160, + "encoding": "uint", + "format": "hex", + "set": 0, + }, ] return self.registers def get_register_data(self, tid): return struct.pack( - '21Q', + "21Q", tid + 1, tid + 2, tid + 3, @@ -113,4 +313,5 @@ class OperatingSystemPlugIn(object): tid + 18, tid + 19, tid + 20, - tid + 21) + tid + 21, + ) diff --git a/lldb/test/API/functionalities/plugins/python_os_plugin/stepping_plugin_threads/TestOSPluginStepping.py b/lldb/test/API/functionalities/plugins/python_os_plugin/stepping_plugin_threads/TestOSPluginStepping.py index 45914e408f8d..47d6f5d68bbe 100644 --- a/lldb/test/API/functionalities/plugins/python_os_plugin/stepping_plugin_threads/TestOSPluginStepping.py +++ b/lldb/test/API/functionalities/plugins/python_os_plugin/stepping_plugin_threads/TestOSPluginStepping.py @@ -17,9 +17,9 @@ class TestOSPluginStepping(TestBase): @skipIf(oslist=["freebsd"], bugnumber="llvm.org/pr48352") def test_python_os_plugin(self): """Test that stepping works when the OS Plugin doesn't report all - threads at every stop""" + threads at every stop""" self.build() - self.main_file = lldb.SBFileSpec('main.cpp') + self.main_file = lldb.SBFileSpec("main.cpp") self.run_python_os_step_missing_thread(False) @skipIfWindows @@ -27,7 +27,7 @@ class TestOSPluginStepping(TestBase): def test_python_os_plugin_prune(self): """Test that pruning the unreported PlanStacks works""" self.build() - self.main_file = lldb.SBFileSpec('main.cpp') + self.main_file = lldb.SBFileSpec("main.cpp") self.run_python_os_step_missing_thread(True) def get_os_thread(self): @@ -36,69 +36,88 @@ class TestOSPluginStepping(TestBase): def is_os_thread(self, thread): id = thread.GetID() return id == 0x111111111 - + def run_python_os_step_missing_thread(self, do_prune): """Test that the Python operating system plugin works correctly""" # Our OS plugin does NOT report all threads: - result = self.dbg.HandleCommand("settings set process.experimental.os-plugin-reports-all-threads false") + result = self.dbg.HandleCommand( + "settings set process.experimental.os-plugin-reports-all-threads false" + ) - python_os_plugin_path = os.path.join(self.getSourceDir(), - "operating_system.py") + python_os_plugin_path = os.path.join(self.getSourceDir(), "operating_system.py") (target, self.process, thread, thread_bkpt) = lldbutil.run_to_source_breakpoint( - self, "first stop in thread - do a step out", self.main_file) + self, "first stop in thread - do a step out", self.main_file + ) - main_bkpt = target.BreakpointCreateBySourceRegex('Stop here and do not make a memory thread for thread_1', - self.main_file) - self.assertEqual(main_bkpt.GetNumLocations(), 1, "Main breakpoint has one location") + main_bkpt = target.BreakpointCreateBySourceRegex( + "Stop here and do not make a memory thread for thread_1", self.main_file + ) + self.assertEqual( + main_bkpt.GetNumLocations(), 1, "Main breakpoint has one location" + ) # There should not be an os thread before we load the plugin: - self.assertFalse(self.get_os_thread().IsValid(), "No OS thread before loading plugin") - + self.assertFalse( + self.get_os_thread().IsValid(), "No OS thread before loading plugin" + ) + # Now load the python OS plug-in which should update the thread list and we should have # an OS plug-in thread overlaying thread_1 with id 0x111111111 - command = "settings set target.process.python-os-plugin-path '%s'" % python_os_plugin_path + command = ( + "settings set target.process.python-os-plugin-path '%s'" + % python_os_plugin_path + ) self.dbg.HandleCommand(command) # Verify our OS plug-in threads showed up os_thread = self.get_os_thread() self.assertTrue( os_thread.IsValid(), - "Make sure we added the thread 0x111111111 after we load the python OS plug-in") - + "Make sure we added the thread 0x111111111 after we load the python OS plug-in", + ) + # Now we are going to step-out. This should get interrupted by main_bkpt. We've # set up the OS plugin so at this stop, we have lost the OS thread 0x111111111. # Make sure both of these are true: os_thread.StepOut() - - stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(self.process, main_bkpt) + + stopped_threads = lldbutil.get_threads_stopped_at_breakpoint( + self.process, main_bkpt + ) self.assertEqual(len(stopped_threads), 1, "Stopped at main_bkpt") thread = self.process.GetThreadByID(0x111111111) self.assertFalse(thread.IsValid(), "No thread 0x111111111 on second stop.") - + # Make sure we still have the thread plans for this thread: # First, don't show unreported threads, that should fail: command = "thread plan list -t 0x111111111" result = lldb.SBCommandReturnObject() - interp = self.dbg.GetCommandInterpreter() + interp = self.dbg.GetCommandInterpreter() interp.HandleCommand(command, result) - self.assertFalse(result.Succeeded(), "We found no plans for the unreported thread.") + self.assertFalse( + result.Succeeded(), "We found no plans for the unreported thread." + ) # Now do it again but with the -u flag: - command = "thread plan list -u -t 0x111111111" + command = "thread plan list -u -t 0x111111111" result = lldb.SBCommandReturnObject() interp.HandleCommand(command, result) self.assertTrue(result.Succeeded(), "We found plans for the unreported thread.") - + if do_prune: # Prune the thread plan and continue, and we will run to exit. interp.HandleCommand("thread plan prune 0x111111111", result) - self.assertTrue(result.Succeeded(), "Found the plan for 0x111111111 and pruned it") + self.assertTrue( + result.Succeeded(), "Found the plan for 0x111111111 and pruned it" + ) # List again, make sure it doesn't work: - command = "thread plan list -u -t 0x111111111" + command = "thread plan list -u -t 0x111111111" interp.HandleCommand(command, result) - self.assertFalse(result.Succeeded(), "We still found plans for the unreported thread.") - + self.assertFalse( + result.Succeeded(), "We still found plans for the unreported thread." + ) + self.process.Continue() self.assertState(self.process.GetState(), lldb.eStateExited, "We exited.") else: @@ -108,4 +127,6 @@ class TestOSPluginStepping(TestBase): self.process.Continue() os_thread = self.get_os_thread() self.assertTrue(os_thread.IsValid(), "The OS thread is back after continue") - self.assertIn("step out", os_thread.GetStopDescription(100), "Completed step out plan") + self.assertIn( + "step out", os_thread.GetStopDescription(100), "Completed step out plan" + ) diff --git a/lldb/test/API/functionalities/plugins/python_os_plugin/stepping_plugin_threads/operating_system.py b/lldb/test/API/functionalities/plugins/python_os_plugin/stepping_plugin_threads/operating_system.py index a91852965f92..eb02ff534f21 100644 --- a/lldb/test/API/functionalities/plugins/python_os_plugin/stepping_plugin_threads/operating_system.py +++ b/lldb/test/API/functionalities/plugins/python_os_plugin/stepping_plugin_threads/operating_system.py @@ -6,57 +6,59 @@ import struct class OperatingSystemPlugIn(object): """Class that provides a OS plugin that along with the particular code in main.cpp - emulates the following scenario: - a) We stop in an OS Plugin created thread - which should be thread index 1 - b) We step-out from that thread - c) We hit a breakpoint in another thread, and DON'T produce the OS Plugin thread. - d) We continue, and when we hit the step out breakpoint, we again produce the same - OS Plugin thread. - main.cpp sets values into the global variable g_value, which we use to tell the OS - plugin whether to produce the OS plugin thread or not. - Since we are always producing an OS plugin thread with a backing thread, we don't - need to implement get_register_info or get_register_data. + emulates the following scenario: + a) We stop in an OS Plugin created thread - which should be thread index 1 + b) We step-out from that thread + c) We hit a breakpoint in another thread, and DON'T produce the OS Plugin thread. + d) We continue, and when we hit the step out breakpoint, we again produce the same + OS Plugin thread. + main.cpp sets values into the global variable g_value, which we use to tell the OS + plugin whether to produce the OS plugin thread or not. + Since we are always producing an OS plugin thread with a backing thread, we don't + need to implement get_register_info or get_register_data. """ def __init__(self, process): - '''Initialization needs a valid.SBProcess object. + """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.''' + first time.""" print("Plugin initialized.") self.process = None self.start_stop_id = 0 self.g_value = lldb.SBValue() - + if isinstance(process, lldb.SBProcess) and process.IsValid(): self.process = process self.g_value = process.GetTarget().FindFirstGlobalVariable("g_value") if not self.g_value.IsValid(): print("Could not find g_value") - + def create_thread(self, tid, context): print("Called create thread with tid: ", tid) return None def get_thread_info(self): g_value = self.g_value.GetValueAsUnsigned() - print("Called get_thread_info: g_value: %d"%(g_value)) + print("Called get_thread_info: g_value: %d" % (g_value)) if g_value == 0 or g_value == 2: - return [{'tid': 0x111111111, - 'name': 'one', - 'queue': 'queue1', - 'state': 'stopped', - 'stop_reason': 'breakpoint', - 'core' : 1 }] + return [ + { + "tid": 0x111111111, + "name": "one", + "queue": "queue1", + "state": "stopped", + "stop_reason": "breakpoint", + "core": 1, + } + ] else: return [] def get_register_info(self): - print ("called get_register_info") + print("called get_register_info") return None - def get_register_data(self, tid): - print("Get register data called for tid: %d"%(tid)) + print("Get register data called for tid: %d" % (tid)) return None - |
