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