1"""Test that we can unwind out of a SIGABRT handler"""
2
3
4
5
6import lldb
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9from lldbsuite.test import lldbutil
10
11
12class HandleAbortTestCase(TestBase):
13
14    mydir = TestBase.compute_mydir(__file__)
15
16    NO_DEBUG_INFO_TESTCASE = True
17
18    @skipIfWindows  # signals do not exist on Windows
19    # Fails on Ubuntu Focal
20    @skipIf(archs=["aarch64"], oslist=["linux"])
21    @expectedFailureNetBSD
22    def test_inferior_handle_sigabrt(self):
23        """Inferior calls abort() and handles the resultant SIGABRT.
24           Stopped at a breakpoint in the handler, verify that the backtrace
25           includes the function that called abort()."""
26        self.build()
27        exe = self.getBuildArtifact("a.out")
28
29        # Create a target by the debugger.
30        target = self.dbg.CreateTarget(exe)
31        self.assertTrue(target, VALID_TARGET)
32
33        # launch
34        process = target.LaunchSimple(
35            None, None, self.get_process_working_directory())
36        self.assertTrue(process, PROCESS_IS_VALID)
37        self.assertEqual(process.GetState(), lldb.eStateStopped)
38        signo = process.GetUnixSignals().GetSignalNumberFromName("SIGABRT")
39
40        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonSignal)
41        self.assertTrue(
42            thread and thread.IsValid(),
43            "Thread should be stopped due to a signal")
44        self.assertTrue(
45            thread.GetStopReasonDataCount() >= 1,
46            "There should be data in the event.")
47        self.assertEqual(thread.GetStopReasonDataAtIndex(0),
48                         signo, "The stop signal should be SIGABRT")
49
50        # Continue to breakpoint in abort handler
51        bkpt = target.FindBreakpointByID(
52            lldbutil.run_break_set_by_source_regexp(self, "Set a breakpoint here"))
53        threads = lldbutil.continue_to_breakpoint(process, bkpt)
54        self.assertEqual(len(threads), 1, "Expected single thread")
55        thread = threads[0]
56
57        # Expect breakpoint in 'handler'
58        frame = thread.GetFrameAtIndex(0)
59        self.assertEqual(frame.GetDisplayFunctionName(), "handler", "Unexpected break?")
60
61        # Expect that unwinding should find 'abort_caller'
62        foundFoo = False
63        for frame in thread:
64            if frame.GetDisplayFunctionName() == "abort_caller":
65                foundFoo = True
66
67        self.assertTrue(foundFoo, "Unwinding did not find func that called abort")
68
69        # Continue until we exit.
70        process.Continue()
71        self.assertEqual(process.GetState(), lldb.eStateExited)
72        self.assertEqual(process.GetExitStatus(), 0)
73