1"""Test that backtraces can follow cross-object tail calls"""
2
3
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class TestCrossObjectTailCalls(TestBase):
12
13    def setUp(self):
14        TestBase.setUp(self)
15
16    @skipIf(compiler="clang", compiler_version=['<', '10.0'])
17    @skipIf(dwarf_version=['<', '4'])
18    @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr26265")
19    @expectedFailureAll(archs=['arm', 'aarch64'], bugnumber="llvm.org/PR44561")
20    def test_cross_object_tail_calls(self):
21        self.build()
22        exe = self.getBuildArtifact("a.out")
23        target = self.dbg.CreateTarget(exe)
24        self.assertTrue(target, VALID_TARGET)
25
26        lldbutil.run_break_set_by_source_regexp(self, '// break here',
27                extra_options='-f Two.c')
28
29        process = target.LaunchSimple(
30            None, None, self.get_process_working_directory())
31        self.assertTrue(process, PROCESS_IS_VALID)
32
33        # We should be stopped in the second dylib.
34        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
35
36        # Debug helper:
37        # self.runCmd("log enable -f /tmp/lldb.log lldb step")
38        # self.runCmd("bt")
39
40        # Check that the backtrace is what we expect:
41        #  frame #0: 0x000000010be73f94 a.out`tail_called_in_b_from_b at Two.c:7:3 [opt]
42        #  frame #1: 0x000000010be73fa0 a.out`tail_called_in_b_from_a at Two.c:8:1 [opt] [artificial]
43        #  frame #2: 0x000000010be73f80 a.out`helper_in_a at One.c:11:1 [opt] [artificial]
44        #  frame #3: 0x000000010be73f79 a.out`tail_called_in_a_from_main at One.c:10:3 [opt]
45        #  frame #4: 0x000000010be73f60 a.out`helper at main.c:11:3 [opt] [artificial]
46        #  frame #5: 0x000000010be73f59 a.out`main at main.c:10:3 [opt]
47        expected_frames = [
48                ("tail_called_in_b_from_b", False),
49                ("tail_called_in_b_from_a", True),
50                ("helper_in_a", True),
51                ("tail_called_in_a_from_main", False),
52                ("helper", True),
53                ("main", False)
54        ]
55        for idx, (name, is_artificial) in enumerate(expected_frames):
56            frame = thread.GetFrameAtIndex(idx)
57            self.assertIn(name, frame.GetDisplayFunctionName())
58            self.assertEqual(frame.IsArtificial(), is_artificial)
59