xref: /llvm-project/lldb/test/API/functionalities/tail_call_frames/cross_dso/TestCrossDSOTailCalls.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""Test that backtraces can follow cross-DSO tail calls"""
2
3
4import lldb
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9
10class TestCrossDSOTailCalls(TestBase):
11    @skipIf(compiler="clang", compiler_version=["<", "10.0"])
12    @skipIf(dwarf_version=["<", "4"])
13    @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr26265")
14    @expectedFailureAll(archs=["arm", "aarch64"], bugnumber="llvm.org/PR44561")
15    def test_cross_dso_tail_calls(self):
16        self.build()
17        exe = self.getBuildArtifact("a.out")
18        target = self.dbg.CreateTarget(exe)
19        self.assertTrue(target, VALID_TARGET)
20
21        # Register our shared libraries for remote targets so they get
22        # automatically uploaded
23        environment = self.registerSharedLibrariesWithTarget(target, ["One", "Two"])
24
25        lldbutil.run_break_set_by_source_regexp(
26            self, "// break here", extra_options="-f Two.c"
27        )
28
29        process = target.LaunchSimple(
30            None, environment, self.get_process_working_directory()
31        )
32        self.assertTrue(process, PROCESS_IS_VALID)
33
34        # We should be stopped in the second dylib.
35        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
36
37        # Debug helper:
38        # self.runCmd("log enable -f /tmp/lldb.log lldb step")
39        # self.runCmd("bt")
40
41        # Check that the backtrace is what we expect:
42        #  frame #0: 0x000000010d5e5f94 libTwo.dylib`tail_called_in_b_from_b at Two.c:7:3 [opt]
43        #  frame #1: 0x000000010d5e5fa0 libTwo.dylib`tail_called_in_b_from_a [opt] [artificial]
44        #  frame #2: 0x000000010d5dcf80 libOne.dylib`helper_in_a [opt] [artificial]
45        #  frame #3: 0x000000010d5dcf79 libOne.dylib`tail_called_in_a_from_main at One.c:10:3 [opt]
46        #  frame #4: 0x000000010d5d3f80 a.out`helper [opt] [artificial]
47        #  frame #5: 0x000000010d5d3f79 a.out`main at main.c:10:3 [opt]
48        expected_frames = [
49            ("tail_called_in_b_from_b", False),
50            ("tail_called_in_b_from_a", True),
51            ("helper_in_a", True),
52            ("tail_called_in_a_from_main", False),
53            ("helper", True),
54            ("main", False),
55        ]
56        for idx, (name, is_artificial) in enumerate(expected_frames):
57            frame = thread.GetFrameAtIndex(idx)
58            self.assertIn(name, frame.GetDisplayFunctionName())
59            self.assertEqual(frame.IsArtificial(), is_artificial)
60