xref: /llvm-project/lldb/test/API/python_api/signals/TestSignalsAPI.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Test SBProcess APIs, including ReadMemory(), WriteMemory(), and others.
3"""
4
5
6import lldb
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9from lldbsuite.test import lldbutil
10from lldbsuite.test.lldbutil import get_stopped_thread, state_type_to_str
11
12
13class SignalsAPITestCase(TestBase):
14    NO_DEBUG_INFO_TESTCASE = True
15
16    @skipIfWindows  # Windows doesn't have signals
17    def test_ignore_signal(self):
18        """Test Python SBUnixSignals.Suppress/Stop/Notify() API."""
19        self.build()
20        exe = self.getBuildArtifact("a.out")
21        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
22
23        target = self.dbg.CreateTarget(exe)
24        self.assertTrue(target, VALID_TARGET)
25
26        line = line_number(
27            "main.cpp", "// Set break point at this line and setup signal ignores."
28        )
29        breakpoint = target.BreakpointCreateByLocation("main.cpp", line)
30        self.assertTrue(breakpoint, VALID_BREAKPOINT)
31
32        # Launch the process, and do not stop at the entry point.
33        process = target.LaunchSimple(None, None, self.get_process_working_directory())
34
35        thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
36        self.assertTrue(
37            thread.IsValid(), "There should be a thread stopped due to breakpoint"
38        )
39
40        unix_signals = process.GetUnixSignals()
41        sigint = unix_signals.GetSignalNumberFromName("SIGINT")
42        unix_signals.SetShouldSuppress(sigint, True)
43        unix_signals.SetShouldStop(sigint, False)
44        unix_signals.SetShouldNotify(sigint, False)
45
46        process.Continue()
47        self.assertEqual(
48            process.state, lldb.eStateExited, "The process should have exited"
49        )
50        self.assertEqual(
51            process.GetExitStatus(), 0, "The process should have returned 0"
52        )
53