1"""
2Test that we can backtrace correctly when AArch64 PAC is enabled
3"""
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class AArch64UnwindPAC(TestBase):
12
13    @skipIf(archs=no_match(["aarch64"]))
14    @skipIf(oslist=no_match(['linux']))
15    def test(self):
16        """Test that we can backtrace correctly when AArch64 PAC is enabled"""
17        if not self.isAArch64PAuth():
18            self.skipTest('Target must support Pointer Authentication.')
19
20        self.build()
21
22        self.line = line_number('main.c', '// Frame func_c')
23
24        exe = self.getBuildArtifact("a.out")
25        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
26
27        lldbutil.run_break_set_by_file_and_line(
28            self, "main.c", self.line, num_expected_locations=1)
29        self.runCmd("run", RUN_SUCCEEDED)
30        self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
31                    substrs=["stop reason = breakpoint 1."])
32
33        target = self.dbg.GetSelectedTarget()
34        process = target.GetProcess()
35        thread = process.GetThreadAtIndex(0)
36
37        backtrace = ["func_c", "func_b", "func_a", "main", "__libc_start_main", "_start"]
38        self.assertEqual(thread.GetNumFrames(), len(backtrace))
39        for frame_idx, frame in enumerate(thread.frames):
40            frame = thread.GetFrameAtIndex(frame_idx)
41            self.assertTrue(frame)
42            self.assertEqual(frame.GetFunctionName(), backtrace[frame_idx])
43			# Check line number for functions in main.c
44            if (frame_idx < 4):
45                self.assertEqual(frame.GetLineEntry().GetLine(),
46                                 line_number("main.c", "Frame " + backtrace[frame_idx]))
47