1import lldb 2from lldbsuite.test.lldbtest import * 3from lldbsuite.test.decorators import * 4from lldbsuite.test.gdbclientutils import * 5from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase 6 7 8class TestThreadSelectionBug(GDBRemoteTestBase): 9 10 mydir = TestBase.compute_mydir(__file__) 11 12 def test(self): 13 class MyResponder(MockGDBServerResponder): 14 def cont(self): 15 # Simulate process stopping due to a raise(SIGINT) 16 return "T01reason:signal" 17 18 self.server.responder = MyResponder() 19 target = self.createTarget("a.yaml") 20 process = self.connect(target) 21 python_os_plugin_path = os.path.join(self.getSourceDir(), 22 'operating_system.py') 23 command = "settings set target.process.python-os-plugin-path '{}'".format( 24 python_os_plugin_path) 25 self.dbg.HandleCommand(command) 26 27 self.assertTrue(process, PROCESS_IS_VALID) 28 self.assertEqual(process.GetNumThreads(), 3) 29 30 # Verify our OS plug-in threads showed up 31 thread = process.GetThreadByID(0x1) 32 self.assertTrue( 33 thread.IsValid(), 34 "Make sure there is a thread 0x1 after we load the python OS plug-in") 35 thread = process.GetThreadByID(0x2) 36 self.assertTrue( 37 thread.IsValid(), 38 "Make sure there is a thread 0x2 after we load the python OS plug-in") 39 thread = process.GetThreadByID(0x3) 40 self.assertTrue( 41 thread.IsValid(), 42 "Make sure there is a thread 0x3 after we load the python OS plug-in") 43 44 # Verify that a thread other than 3 is selected. 45 thread = process.GetSelectedThread() 46 self.assertNotEqual(thread.GetThreadID(), 0x3) 47 48 # Verify that we select the thread backed by physical thread 1, rather 49 # than virtual thread 1. The mapping comes from the OS plugin, where we 50 # specified that thread 3 is backed by real thread 1. 51 process.Continue() 52 thread = process.GetSelectedThread() 53 self.assertEqual(thread.GetThreadID(), 0x3) 54