199451b44SJordan Rupprechtimport lldb 299451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 399451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 4*33c0f93fSPavel Labathfrom lldbsuite.test.gdbclientutils import * 5*33c0f93fSPavel Labathfrom lldbsuite.test.lldbgdbclient import GDBRemoteTestBase 699451b44SJordan Rupprecht 799451b44SJordan Rupprecht 899451b44SJordan Rupprechtclass TestThreadSelectionBug(GDBRemoteTestBase): 9*33c0f93fSPavel Labath 1099451b44SJordan Rupprecht def test(self): 1199451b44SJordan Rupprecht class MyResponder(MockGDBServerResponder): 1299451b44SJordan Rupprecht def cont(self): 1399451b44SJordan Rupprecht # Simulate process stopping due to a raise(SIGINT) 1499451b44SJordan Rupprecht return "T01reason:signal" 1599451b44SJordan Rupprecht 1699451b44SJordan Rupprecht self.server.responder = MyResponder() 1799451b44SJordan Rupprecht target = self.createTarget("a.yaml") 1899451b44SJordan Rupprecht process = self.connect(target) 1999451b44SJordan Rupprecht python_os_plugin_path = os.path.join(self.getSourceDir(), 2099451b44SJordan Rupprecht 'operating_system.py') 2199451b44SJordan Rupprecht command = "settings set target.process.python-os-plugin-path '{}'".format( 2299451b44SJordan Rupprecht python_os_plugin_path) 2399451b44SJordan Rupprecht self.dbg.HandleCommand(command) 2499451b44SJordan Rupprecht 2599451b44SJordan Rupprecht self.assertTrue(process, PROCESS_IS_VALID) 2699451b44SJordan Rupprecht self.assertEqual(process.GetNumThreads(), 3) 2799451b44SJordan Rupprecht 2899451b44SJordan Rupprecht # Verify our OS plug-in threads showed up 2999451b44SJordan Rupprecht thread = process.GetThreadByID(0x1) 3099451b44SJordan Rupprecht self.assertTrue( 3199451b44SJordan Rupprecht thread.IsValid(), 3299451b44SJordan Rupprecht "Make sure there is a thread 0x1 after we load the python OS plug-in") 3399451b44SJordan Rupprecht thread = process.GetThreadByID(0x2) 3499451b44SJordan Rupprecht self.assertTrue( 3599451b44SJordan Rupprecht thread.IsValid(), 3699451b44SJordan Rupprecht "Make sure there is a thread 0x2 after we load the python OS plug-in") 3799451b44SJordan Rupprecht thread = process.GetThreadByID(0x3) 3899451b44SJordan Rupprecht self.assertTrue( 3999451b44SJordan Rupprecht thread.IsValid(), 4099451b44SJordan Rupprecht "Make sure there is a thread 0x3 after we load the python OS plug-in") 4199451b44SJordan Rupprecht 4299451b44SJordan Rupprecht # Verify that a thread other than 3 is selected. 4399451b44SJordan Rupprecht thread = process.GetSelectedThread() 4499451b44SJordan Rupprecht self.assertNotEqual(thread.GetThreadID(), 0x3) 4599451b44SJordan Rupprecht 4699451b44SJordan Rupprecht # Verify that we select the thread backed by physical thread 1, rather 4799451b44SJordan Rupprecht # than virtual thread 1. The mapping comes from the OS plugin, where we 4899451b44SJordan Rupprecht # specified that thread 3 is backed by real thread 1. 4999451b44SJordan Rupprecht process.Continue() 5099451b44SJordan Rupprecht thread = process.GetSelectedThread() 5199451b44SJordan Rupprecht self.assertEqual(thread.GetThreadID(), 0x3) 52