xref: /llvm-project/lldb/test/API/tools/lldb-server/TestGdbRemoteSaveCore.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
137cbd817SMichał Górnyimport gdbremote_testcase
237cbd817SMichał Górnyfrom lldbsuite.test.decorators import *
337cbd817SMichał Górnyfrom lldbsuite.test.lldbtest import *
437cbd817SMichał Górnyfrom lldbsuite.test import lldbutil
537cbd817SMichał Górny
637cbd817SMichał Górnyimport binascii
737cbd817SMichał Górnyimport os
837cbd817SMichał Górny
937cbd817SMichał Górny
10*2238dcc3SJonas Devlieghereclass TestGdbSaveCore(gdbremote_testcase.GdbRemoteTestCaseBase):
1137cbd817SMichał Górny    def coredump_test(self, core_path=None, expect_path=None):
1237cbd817SMichał Górny        self.build()
1337cbd817SMichał Górny        self.set_inferior_startup_attach()
1437cbd817SMichał Górny        procs = self.prep_debug_monitor_and_inferior()
1537cbd817SMichał Górny        self.add_qSupported_packets()
1637cbd817SMichał Górny        ret = self.expect_gdbremote_sequence()
1702e690baSMichał Górny        if "qSaveCore+" not in ret["qSupported_response"]:
1802e690baSMichał Górny            self.skipTest("qSaveCore not supported by lldb-server")
1937cbd817SMichał Górny        self.reset_test_sequence()
2037cbd817SMichał Górny
2137cbd817SMichał Górny        packet = "$qSaveCore"
2237cbd817SMichał Górny        if core_path is not None:
2337cbd817SMichał Górny            packet += ";path-hint:{}".format(
24*2238dcc3SJonas Devlieghere                binascii.b2a_hex(core_path.encode()).decode()
25*2238dcc3SJonas Devlieghere            )
2637cbd817SMichał Górny
27*2238dcc3SJonas Devlieghere        self.test_sequence.add_log_lines(
28*2238dcc3SJonas Devlieghere            [
2937cbd817SMichał Górny                "read packet: {}#00".format(packet),
30*2238dcc3SJonas Devlieghere                {
31*2238dcc3SJonas Devlieghere                    "direction": "send",
32*2238dcc3SJonas Devlieghere                    "regex": "[$]core-path:([0-9a-f]+)#.*",
33*2238dcc3SJonas Devlieghere                    "capture": {1: "path"},
34*2238dcc3SJonas Devlieghere                },
35*2238dcc3SJonas Devlieghere            ],
36*2238dcc3SJonas Devlieghere            True,
37*2238dcc3SJonas Devlieghere        )
3837cbd817SMichał Górny        ret = self.expect_gdbremote_sequence()
3937cbd817SMichał Górny        out_path = binascii.a2b_hex(ret["path"].encode()).decode()
4037cbd817SMichał Górny        if expect_path is not None:
4137cbd817SMichał Górny            self.assertEqual(out_path, expect_path)
4237cbd817SMichał Górny
4337cbd817SMichał Górny        target = self.dbg.CreateTarget(None)
4437cbd817SMichał Górny        process = target.LoadCore(out_path)
4537cbd817SMichał Górny        self.assertTrue(process, PROCESS_IS_VALID)
4637cbd817SMichał Górny        self.assertEqual(process.GetProcessID(), procs["inferior"].pid)
4737cbd817SMichał Górny
48b07803eeSMichał Górny    @skipUnlessPlatform(oslist=["freebsd", "netbsd"])
4937cbd817SMichał Górny    def test_netbsd_path(self):
5037cbd817SMichał Górny        core = lldbutil.append_to_process_working_directory(self, "core")
5137cbd817SMichał Górny        self.coredump_test(core, core)
5237cbd817SMichał Górny
53b07803eeSMichał Górny    @skipUnlessPlatform(oslist=["freebsd", "netbsd"])
5437cbd817SMichał Górny    def test_netbsd_no_path(self):
5537cbd817SMichał Górny        self.coredump_test()
5637cbd817SMichał Górny
57b07803eeSMichał Górny    @skipUnlessPlatform(oslist=["freebsd", "netbsd"])
5837cbd817SMichał Górny    def test_netbsd_bad_path(self):
5937cbd817SMichał Górny        self.coredump_test("/dev/null/cantwritehere")
60