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    NO_DEBUG_INFO_TESTCASE = True
15
16    @skipIfWindows  # signals do not exist on Windows
17    @expectedFailureNetBSD
18    def test_inferior_handle_sigabrt(self):
19        """Inferior calls abort() and handles the resultant SIGABRT.
20           Stopped at a breakpoint in the handler, verify that the backtrace
21           includes the function that called abort()."""
22        self.build()
23        exe = self.getBuildArtifact("a.out")
24
25        # Create a target by the debugger.
26        target = self.dbg.CreateTarget(exe)
27        self.assertTrue(target, VALID_TARGET)
28
29        # launch
30        process = target.LaunchSimple(
31            None, None, self.get_process_working_directory())
32        self.assertTrue(process, PROCESS_IS_VALID)
33        self.assertState(process.GetState(), lldb.eStateStopped)
34        signo = process.GetUnixSignals().GetSignalNumberFromName("SIGABRT")
35
36        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonSignal)
37        self.assertTrue(
38            thread and thread.IsValid(),
39            "Thread should be stopped due to a signal")
40        self.assertTrue(
41            thread.GetStopReasonDataCount() >= 1,
42            "There should be data in the event.")
43        self.assertEqual(thread.GetStopReasonDataAtIndex(0),
44                         signo, "The stop signal should be SIGABRT")
45
46        # Continue to breakpoint in abort handler
47        bkpt = target.FindBreakpointByID(
48            lldbutil.run_break_set_by_source_regexp(self, "Set a breakpoint here"))
49        threads = lldbutil.continue_to_breakpoint(process, bkpt)
50        self.assertEqual(len(threads), 1, "Expected single thread")
51        thread = threads[0]
52
53        # Expect breakpoint in 'handler'
54        frame = thread.GetFrameAtIndex(0)
55        self.assertEqual(frame.GetDisplayFunctionName(), "handler", "Unexpected break?")
56
57        # Expect that unwinding should find 'abort_caller'
58        foundFoo = False
59        for frame in thread:
60            if frame.GetDisplayFunctionName() == "abort_caller":
61                foundFoo = True
62
63        self.assertTrue(foundFoo, "Unwinding did not find func that called abort")
64
65        # Continue until we exit.
66        process.Continue()
67        self.assertState(process.GetState(), lldb.eStateExited)
68        self.assertEqual(process.GetExitStatus(), 0)
69