From 11b9466c04db4da7439fc1d9d8ba7241a9d68705 Mon Sep 17 00:00:00 2001 From: Felipe de Azevedo Piovezan Date: Fri, 28 Feb 2025 16:13:12 -0800 Subject: [lldb] Add ability to inspect backing threads with `thread info` (#129275) When OS plugins are present, it can be helpful to query information about the backing thread behind an OS thread, if it exists. There is no mechanism to do so prior to this commit. As a first step, this commit enhances `thread info` with a `--backing-thread` flag, causing the command to use the backing thread of the selected thread, if it exists. --- .../plugins/python_os_plugin/TestPythonOSPlugin.py | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lldb/test/API/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py') 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 fe78edd98f4d..e4997f0742d0 100644 --- a/lldb/test/API/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py +++ b/lldb/test/API/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py @@ -131,6 +131,26 @@ class PluginPythonOSPlugin(TestBase): "Make sure there is no thread 0x333333333 after we unload the python OS plug-in", ) + tid_regex = re.compile(r"tid = ((0x)?[0-9a-fA-F]+)") + + def get_tid_from_thread_info_command(self, thread, use_backing_thread): + interp = self.dbg.GetCommandInterpreter() + result = lldb.SBCommandReturnObject() + + backing_thread_arg = "" + if use_backing_thread: + backing_thread_arg = "--backing-thread" + + interp.HandleCommand( + "thread info {0} {1}".format(thread.GetIndexID(), backing_thread_arg), + result, + True, + ) + self.assertTrue(result.Succeeded(), "failed to run thread info") + match = self.tid_regex.search(result.GetOutput()) + self.assertNotEqual(match, None) + return int(match.group(1), 0) + 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""" @@ -209,6 +229,11 @@ class PluginPythonOSPlugin(TestBase): # it to thread.StepOver() + tid_os = self.get_tid_from_thread_info_command(thread, False) + self.assertEqual(tid_os, 0x111111111) + tid_real = self.get_tid_from_thread_info_command(thread, True) + self.assertNotEqual(tid_os, tid_real) + frame = thread.GetFrameAtIndex(0) self.assertTrue( frame.IsValid(), "Make sure we get a frame from thread 0x111111111" -- cgit v1.2.3