xref: /llvm-project/lldb/test/API/tools/lldb-server/inferior-crash/TestGdbRemoteSegFault.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1import gdbremote_testcase
2from lldbsuite.test.decorators import *
3from lldbsuite.test.lldbtest import *
4from lldbsuite.test import lldbutil
5
6
7class TestGdbRemoteSegFault(gdbremote_testcase.GdbRemoteTestCaseBase):
8    GDB_REMOTE_STOP_CODE_BAD_ACCESS = 0x91
9
10    def inferior_seg_fault_received(self, expected_signo):
11        procs = self.prep_debug_monitor_and_inferior(inferior_args=["segfault"])
12        self.assertIsNotNone(procs)
13
14        self.test_sequence.add_log_lines(
15            [
16                "read packet: $vCont;c#a8",
17                {
18                    "direction": "send",
19                    "regex": r"^\$T([0-9a-fA-F]{2}).*#[0-9a-fA-F]{2}$",
20                    "capture": {1: "hex_exit_code"},
21                },
22            ],
23            True,
24        )
25
26        context = self.expect_gdbremote_sequence()
27        self.assertIsNotNone(context)
28
29        hex_exit_code = context.get("hex_exit_code")
30        self.assertIsNotNone(hex_exit_code)
31        self.assertEqual(int(hex_exit_code, 16), expected_signo)
32
33    @skipIfWindows  # No signal is sent on Windows.
34    def test_inferior_seg_fault_received(self):
35        self.build()
36        if self.platformIsDarwin():
37            self.inferior_seg_fault_received(self.GDB_REMOTE_STOP_CODE_BAD_ACCESS)
38        else:
39            self.inferior_seg_fault_received(lldbutil.get_signal_number("SIGSEGV"))
40