Skip to content

Commit 518320f

Browse files
committed
[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 llvm#4: 0x0000fffff7b373fc libc.so.6`___lldb_unnamed_symbol2962 + 108 frame llvm#5: 0x0000fffff7b374cc libc.so.6`__libc_start_main + 152 frame llvm#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
1 parent 8aedad0 commit 518320f

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

lldb/test/API/functionalities/unwind/aarch64_unwind_pac/TestAArch64UnwindPAC.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,31 @@ def test(self):
4242
"func_b",
4343
"func_a",
4444
"main",
45+
]
46+
47+
libc_backtrace = [
4548
"__libc_start_main",
4649
"_start",
4750
]
48-
self.assertEqual(thread.GetNumFrames(), len(backtrace))
49-
for frame_idx, frame in enumerate(thread.frames):
50-
frame = thread.GetFrameAtIndex(frame_idx)
51+
52+
self.assertTrue(thread.GetNumFrames() >= (len(backtrace) + len(libc_backtrace)))
53+
54+
# Strictly check frames that are in the test program's source.
55+
for frame_idx, frame in enumerate(thread.frames[:len(backtrace)]):
5156
self.assertTrue(frame)
5257
self.assertEqual(frame.GetFunctionName(), backtrace[frame_idx])
53-
# Check line number for functions in main.c
54-
if frame_idx < 4:
55-
self.assertEqual(
56-
frame.GetLineEntry().GetLine(),
57-
line_number("main.c", "Frame " + backtrace[frame_idx]),
58-
)
58+
self.assertEqual(
59+
frame.GetLineEntry().GetLine(),
60+
line_number("main.c", "Frame " + backtrace[frame_idx]),
61+
)
62+
63+
# After the program comes some libc frames. The number varies by
64+
# system, so ensure we have at least these two in this order,
65+
# skipping frames in between.
66+
start_idx = frame_idx + 1
67+
for frame_idx, frame in enumerate(thread.frames[start_idx:], start=start_idx):
68+
self.assertTrue(frame)
69+
if libc_backtrace[0] == frame.GetFunctionName():
70+
libc_backtrace.pop(0)
71+
72+
self.assertFalse(libc_backtrace, "Did not find expected libc frames.")

0 commit comments

Comments
 (0)