xref: /llvm-project/lldb/test/API/functionalities/gdb_remote_client/TestStopPCs.py (revision 5dbec8c6ce473352cac2d89d6a5b81f65182df59)
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 TestStopPCs(GDBRemoteTestBase):
999451b44SJordan Rupprecht    @skipIfXmlSupportMissing
1099451b44SJordan Rupprecht    def test(self):
1199451b44SJordan Rupprecht        class MyResponder(MockGDBServerResponder):
1299451b44SJordan Rupprecht            def haltReason(self):
13*5dbec8c6Sxusheng                # lldb should treat the default halt reason, hwbreak and swbreak in the same way. Which is that it
14*5dbec8c6Sxusheng                # expects the stub to have corrected the PC already, so lldb should not modify it further.
15*5dbec8c6Sxusheng                return "T02thread:1ff0d;threads:1ff0d,2ff0d,3ff0d;thread-pcs:10001bc00,10002bc00,10003bc00;"
1699451b44SJordan Rupprecht
1799451b44SJordan Rupprecht            def threadStopInfo(self, threadnum):
182238dcc3SJonas Devlieghere                if threadnum == 0x1FF0D:
19*5dbec8c6Sxusheng                    return "T02thread:1ff0d;threads:1ff0d,2ff0d,3ff0d;thread-pcs:10001bc00,10002bc00,10003bc00;"
202238dcc3SJonas Devlieghere                if threadnum == 0x2FF0D:
21*5dbec8c6Sxusheng                    return "T00swbreak:;thread:2ff0d;threads:1ff0d,2ff0d,3ff0d;thread-pcs:10001bc00,10002bc00,10003bc00;"
22*5dbec8c6Sxusheng                if threadnum == 0x3FF0D:
23*5dbec8c6Sxusheng                    return "T00hwbreak:;thread:3ff0d;threads:1ff0d,2ff0d,3ff0d;thread-pcs:10001bc00,10002bc00,10003bc00;"
2499451b44SJordan Rupprecht
2599451b44SJordan Rupprecht            def qXferRead(self, obj, annex, offset, length):
2699451b44SJordan Rupprecht                if annex == "target.xml":
272238dcc3SJonas Devlieghere                    return (
282238dcc3SJonas Devlieghere                        """<?xml version="1.0"?>
2999451b44SJordan Rupprecht                        <target version="1.0">
3099451b44SJordan Rupprecht                          <architecture>i386:x86-64</architecture>
3199451b44SJordan Rupprecht                          <feature name="org.gnu.gdb.i386.core">
3299451b44SJordan Rupprecht                            <reg name="rip" bitsize="64" regnum="0" type="code_ptr" group="general"/>
3399451b44SJordan Rupprecht                          </feature>
342238dcc3SJonas Devlieghere                        </target>""",
352238dcc3SJonas Devlieghere                        False,
362238dcc3SJonas Devlieghere                    )
3799451b44SJordan Rupprecht                else:
3899451b44SJordan Rupprecht                    return None, False
3999451b44SJordan Rupprecht
4099451b44SJordan Rupprecht        self.server.responder = MyResponder()
412238dcc3SJonas Devlieghere        target = self.dbg.CreateTarget("")
4299451b44SJordan Rupprecht        if self.TraceOn():
4399451b44SJordan Rupprecht            self.runCmd("log enable gdb-remote packets")
442238dcc3SJonas Devlieghere            self.addTearDownHook(lambda: self.runCmd("log disable gdb-remote packets"))
4599451b44SJordan Rupprecht        process = self.connect(target)
4699451b44SJordan Rupprecht
47*5dbec8c6Sxusheng        self.assertEqual(process.GetNumThreads(), 3)
4899451b44SJordan Rupprecht        th0 = process.GetThreadAtIndex(0)
4999451b44SJordan Rupprecht        th1 = process.GetThreadAtIndex(1)
50*5dbec8c6Sxusheng        th2 = process.GetThreadAtIndex(2)
512238dcc3SJonas Devlieghere        self.assertEqual(th0.GetThreadID(), 0x1FF0D)
522238dcc3SJonas Devlieghere        self.assertEqual(th1.GetThreadID(), 0x2FF0D)
53*5dbec8c6Sxusheng        self.assertEqual(th2.GetThreadID(), 0x3FF0D)
542238dcc3SJonas Devlieghere        self.assertEqual(th0.GetFrameAtIndex(0).GetPC(), 0x10001BC00)
552238dcc3SJonas Devlieghere        self.assertEqual(th1.GetFrameAtIndex(0).GetPC(), 0x10002BC00)
56*5dbec8c6Sxusheng        self.assertEqual(th2.GetFrameAtIndex(0).GetPC(), 0x10003BC00)
57