[libc][test] fix memory leak pt.2 (#122384)
[llvm-project.git] / lldb / test / API / linux / aarch64 / unwind_signal / TestUnwindSignal.py
blob46f05b8285a5151695dc0e1a3aea2b057f9ace83
1 """Test that we can unwind out of a signal handler.
2 Which for AArch64 Linux requires a specific unwind plan."""
5 import lldb
6 from lldbsuite.test.decorators import *
7 from lldbsuite.test.lldbtest import *
8 from lldbsuite.test import lldbutil
11 class UnwindSignalTestCase(TestBase):
12 NO_DEBUG_INFO_TESTCASE = True
14 @skipUnlessArch("aarch64")
15 @skipUnlessPlatform(["linux"])
16 def test_unwind_signal(self):
17 """Inferior calls sigill() and handles the resultant SIGILL.
18 Stopped at a breakpoint in the handler, check that we can unwind
19 back to sigill() and get the expected register contents there."""
20 self.build()
21 exe = self.getBuildArtifact("a.out")
23 target = self.dbg.CreateTarget(exe)
24 self.assertTrue(target, VALID_TARGET)
26 process = target.LaunchSimple(None, None, self.get_process_working_directory())
27 self.assertTrue(process, PROCESS_IS_VALID)
28 self.assertState(process.GetState(), lldb.eStateStopped)
29 signo = process.GetUnixSignals().GetSignalNumberFromName("SIGILL")
31 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonSignal)
32 self.assertTrue(
33 thread and thread.IsValid(), "Thread should be stopped due to a signal"
35 self.assertGreaterEqual(
36 thread.GetStopReasonDataCount(), 1, "There should be data in the event."
38 self.assertEqual(
39 thread.GetStopReasonDataAtIndex(0),
40 signo,
41 "The stop signal should be SIGILL",
44 # Continue to breakpoint in sigill handler
45 bkpt = target.FindBreakpointByID(
46 lldbutil.run_break_set_by_source_regexp(self, "Set a breakpoint here")
48 threads = lldbutil.continue_to_breakpoint(process, bkpt)
49 self.assertEqual(len(threads), 1, "Expected single thread")
50 thread = threads[0]
52 # Expect breakpoint in 'handler'
53 frame = thread.GetFrameAtIndex(0)
54 self.assertEqual(frame.GetDisplayFunctionName(), "handler", "Unexpected break?")
56 # Expect that unwinding should find 'sigill'
57 found_caller = False
58 for frame in thread.get_thread_frames():
59 if frame.GetDisplayFunctionName() == "sigill":
60 # We should have ascending values in the x registers
61 regs = frame.GetRegisters().GetValueAtIndex(0)
62 err = lldb.SBError()
64 for i in range(31):
65 name = "x{}".format(i)
66 value = regs.GetChildMemberWithName(name).GetValueAsUnsigned(err)
67 self.assertSuccess(err, "Failed to get register {}".format(name))
68 self.assertEqual(
69 value, i, "Unexpected value for register {}".format(name)
72 found_caller = True
73 break
75 self.assertTrue(
76 found_caller, "Unwinding did not find func that caused the SIGILL"
79 # Continue until we exit.
80 process.Continue()
81 self.assertState(process.GetState(), lldb.eStateExited)
82 self.assertEqual(process.GetExitStatus(), 0)