xref: /llvm-project/lldb/test/API/functionalities/gdb_remote_client/TestThreadSelectionBug.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprechtimport lldb
299451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
399451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
433c0f93fSPavel Labathfrom lldbsuite.test.gdbclientutils import *
533c0f93fSPavel Labathfrom lldbsuite.test.lldbgdbclient import GDBRemoteTestBase
699451b44SJordan Rupprecht
799451b44SJordan Rupprecht
899451b44SJordan Rupprechtclass TestThreadSelectionBug(GDBRemoteTestBase):
999451b44SJordan Rupprecht    def test(self):
1099451b44SJordan Rupprecht        class MyResponder(MockGDBServerResponder):
1199451b44SJordan Rupprecht            def cont(self):
1299451b44SJordan Rupprecht                # Simulate process stopping due to a raise(SIGINT)
1399451b44SJordan Rupprecht                return "T01reason:signal"
1499451b44SJordan Rupprecht
1599451b44SJordan Rupprecht        self.server.responder = MyResponder()
1699451b44SJordan Rupprecht        target = self.createTarget("a.yaml")
1799451b44SJordan Rupprecht        process = self.connect(target)
18*2238dcc3SJonas Devlieghere        python_os_plugin_path = os.path.join(self.getSourceDir(), "operating_system.py")
1999451b44SJordan Rupprecht        command = "settings set target.process.python-os-plugin-path '{}'".format(
20*2238dcc3SJonas Devlieghere            python_os_plugin_path
21*2238dcc3SJonas Devlieghere        )
2299451b44SJordan Rupprecht        self.dbg.HandleCommand(command)
2399451b44SJordan Rupprecht
2499451b44SJordan Rupprecht        self.assertTrue(process, PROCESS_IS_VALID)
2599451b44SJordan Rupprecht        self.assertEqual(process.GetNumThreads(), 3)
2699451b44SJordan Rupprecht
2799451b44SJordan Rupprecht        # Verify our OS plug-in threads showed up
2899451b44SJordan Rupprecht        thread = process.GetThreadByID(0x1)
2999451b44SJordan Rupprecht        self.assertTrue(
3099451b44SJordan Rupprecht            thread.IsValid(),
31*2238dcc3SJonas Devlieghere            "Make sure there is a thread 0x1 after we load the python OS plug-in",
32*2238dcc3SJonas Devlieghere        )
3399451b44SJordan Rupprecht        thread = process.GetThreadByID(0x2)
3499451b44SJordan Rupprecht        self.assertTrue(
3599451b44SJordan Rupprecht            thread.IsValid(),
36*2238dcc3SJonas Devlieghere            "Make sure there is a thread 0x2 after we load the python OS plug-in",
37*2238dcc3SJonas Devlieghere        )
3899451b44SJordan Rupprecht        thread = process.GetThreadByID(0x3)
3999451b44SJordan Rupprecht        self.assertTrue(
4099451b44SJordan Rupprecht            thread.IsValid(),
41*2238dcc3SJonas Devlieghere            "Make sure there is a thread 0x3 after we load the python OS plug-in",
42*2238dcc3SJonas Devlieghere        )
4399451b44SJordan Rupprecht
4499451b44SJordan Rupprecht        # Verify that a thread other than 3 is selected.
4599451b44SJordan Rupprecht        thread = process.GetSelectedThread()
4699451b44SJordan Rupprecht        self.assertNotEqual(thread.GetThreadID(), 0x3)
4799451b44SJordan Rupprecht
4899451b44SJordan Rupprecht        # Verify that we select the thread backed by physical thread 1, rather
4999451b44SJordan Rupprecht        # than virtual thread 1. The mapping comes from the OS plugin, where we
5099451b44SJordan Rupprecht        # specified that thread 3 is backed by real thread 1.
5199451b44SJordan Rupprecht        process.Continue()
5299451b44SJordan Rupprecht        thread = process.GetSelectedThread()
5399451b44SJordan Rupprecht        self.assertEqual(thread.GetThreadID(), 0x3)
54