1"""Test that backtraces can follow cross-DSO 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 TestCrossDSOTailCalls(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_dso_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 # Register our shared libraries for remote targets so they get 27 # automatically uploaded 28 environment = self.registerSharedLibrariesWithTarget( 29 target, ['One', 'Two']) 30 31 lldbutil.run_break_set_by_source_regexp(self, '// break here', 32 extra_options='-f Two.c') 33 34 process = target.LaunchSimple( 35 None, environment, self.get_process_working_directory()) 36 self.assertTrue(process, PROCESS_IS_VALID) 37 38 # We should be stopped in the second dylib. 39 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) 40 41 # Debug helper: 42 # self.runCmd("log enable -f /tmp/lldb.log lldb step") 43 # self.runCmd("bt") 44 45 # Check that the backtrace is what we expect: 46 # frame #0: 0x000000010d5e5f94 libTwo.dylib`tail_called_in_b_from_b at Two.c:7:3 [opt] 47 # frame #1: 0x000000010d5e5fa0 libTwo.dylib`tail_called_in_b_from_a [opt] [artificial] 48 # frame #2: 0x000000010d5dcf80 libOne.dylib`helper_in_a [opt] [artificial] 49 # frame #3: 0x000000010d5dcf79 libOne.dylib`tail_called_in_a_from_main at One.c:10:3 [opt] 50 # frame #4: 0x000000010d5d3f80 a.out`helper [opt] [artificial] 51 # frame #5: 0x000000010d5d3f79 a.out`main at main.c:10:3 [opt] 52 expected_frames = [ 53 ("tail_called_in_b_from_b", False), 54 ("tail_called_in_b_from_a", True), 55 ("helper_in_a", True), 56 ("tail_called_in_a_from_main", False), 57 ("helper", True), 58 ("main", False) 59 ] 60 for idx, (name, is_artificial) in enumerate(expected_frames): 61 frame = thread.GetFrameAtIndex(idx) 62 self.assertIn(name, frame.GetDisplayFunctionName()) 63 self.assertEqual(frame.IsArtificial(), is_artificial) 64