69 lines · python
1"""Test that we can unwind out of a SIGABRT handler"""2 3 4import lldb5from lldbsuite.test.decorators import *6from lldbsuite.test.lldbtest import *7from lldbsuite.test import lldbutil8 9 10class HandleAbortTestCase(TestBase):11 NO_DEBUG_INFO_TESTCASE = True12 13 @skipIfWindows # signals do not exist on Windows14 @expectedFailureNetBSD15 def test_inferior_handle_sigabrt(self):16 """Inferior calls abort() and handles the resultant SIGABRT.17 Stopped at a breakpoint in the handler, verify that the backtrace18 includes the function that called abort()."""19 self.build()20 exe = self.getBuildArtifact("a.out")21 22 # Create a target by the debugger.23 target = self.dbg.CreateTarget(exe)24 self.assertTrue(target, VALID_TARGET)25 26 # launch27 process = target.LaunchSimple(None, None, self.get_process_working_directory())28 self.assertTrue(process, PROCESS_IS_VALID)29 self.assertState(process.GetState(), lldb.eStateStopped)30 signo = process.GetUnixSignals().GetSignalNumberFromName("SIGABRT")31 32 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonSignal)33 self.assertTrue(34 thread and thread.IsValid(), "Thread should be stopped due to a signal"35 )36 self.assertGreaterEqual(37 thread.GetStopReasonDataCount(), 1, "There should be data in the event."38 )39 self.assertEqual(40 thread.GetStopReasonDataAtIndex(0),41 signo,42 "The stop signal should be SIGABRT",43 )44 45 # Continue to breakpoint in abort handler46 bkpt = target.FindBreakpointByID(47 lldbutil.run_break_set_by_source_regexp(self, "Set a breakpoint here")48 )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 = False59 for frame in thread:60 if frame.GetDisplayFunctionName() == "abort_caller":61 foundFoo = True62 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