Files
clang-p2996/lldb/test/API/functionalities/unwind/aarch64_unwind_pac/TestAArch64UnwindPAC.py
David Spickett 518320fd98 [lldb][AArch64] Account for extra libc frames in PAC unwind test
Running this on Amazon Ubuntu the final backtrace is:
```
(lldb) thread backtrace
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
  * frame #0: 0x0000aaaaaaaa07d0 a.out`func_c at main.c:10:3
    frame #1: 0x0000aaaaaaaa07c4 a.out`func_b at main.c:14:3
    frame #2: 0x0000aaaaaaaa07b4 a.out`func_a at main.c:18:3
    frame #3: 0x0000aaaaaaaa07a4 a.out`main(argc=<unavailable>, argv=<unavailable>) at main.c:22:3
    frame #4: 0x0000fffff7b373fc libc.so.6`___lldb_unnamed_symbol2962 + 108
    frame #5: 0x0000fffff7b374cc libc.so.6`__libc_start_main + 152
    frame #6: 0x0000aaaaaaaa06b0 a.out`_start + 48
```
This causes the test to fail because of the extra ___lldb_unnamed_symbol2962 frame
(an inlined function?).

To fix this, strictly check all the frames in main.c then for the rest
just check we find __libc_start_main and _start in that order regardless
of other frames in between.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D154204
2023-07-04 11:15:18 +01:00

73 lines
2.4 KiB
Python

"""
Test that we can backtrace correctly when AArch64 PAC is enabled
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class AArch64UnwindPAC(TestBase):
@skipIf(archs=no_match(["aarch64"]))
@skipIf(oslist=no_match(["linux"]))
def test(self):
"""Test that we can backtrace correctly when AArch64 PAC is enabled"""
if not self.isAArch64PAuth():
self.skipTest("Target must support Pointer Authentication.")
self.build()
self.line = line_number("main.c", "// Frame func_c")
exe = self.getBuildArtifact("a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
lldbutil.run_break_set_by_file_and_line(
self, "main.c", self.line, num_expected_locations=1
)
self.runCmd("run", RUN_SUCCEEDED)
self.expect(
"thread backtrace",
STOPPED_DUE_TO_BREAKPOINT,
substrs=["stop reason = breakpoint 1."],
)
target = self.dbg.GetSelectedTarget()
process = target.GetProcess()
thread = process.GetThreadAtIndex(0)
backtrace = [
"func_c",
"func_b",
"func_a",
"main",
]
libc_backtrace = [
"__libc_start_main",
"_start",
]
self.assertTrue(thread.GetNumFrames() >= (len(backtrace) + len(libc_backtrace)))
# Strictly check frames that are in the test program's source.
for frame_idx, frame in enumerate(thread.frames[:len(backtrace)]):
self.assertTrue(frame)
self.assertEqual(frame.GetFunctionName(), backtrace[frame_idx])
self.assertEqual(
frame.GetLineEntry().GetLine(),
line_number("main.c", "Frame " + backtrace[frame_idx]),
)
# After the program comes some libc frames. The number varies by
# system, so ensure we have at least these two in this order,
# skipping frames in between.
start_idx = frame_idx + 1
for frame_idx, frame in enumerate(thread.frames[start_idx:], start=start_idx):
self.assertTrue(frame)
if libc_backtrace[0] == frame.GetFunctionName():
libc_backtrace.pop(0)
self.assertFalse(libc_backtrace, "Did not find expected libc frames.")