67 lines · python
1"""2Test lldb-dap stackTrace request for compiler generated code3"""4 5import os6 7import lldbdap_testcase8from lldbsuite.test.decorators import *9from lldbsuite.test.lldbtest import *10 11 12class TestDAP_stackTraceCompilerGeneratedCode(lldbdap_testcase.DAPTestCaseBase):13 def test_non_leaf_frame_compiler_generate_code(self):14 """15 Test that non-leaf frames with compiler-generated code are properly resolved.16 17 This test verifies that LLDB correctly handles stack frames containing18 compiler-generated code (code without valid source location information).19 When a non-leaf frame contains compiler-generated code immediately after a20 call instruction, LLDB should resolve the frame's source location to the21 call instruction's line, rather than to the compiler-generated code that22 follows, which lacks proper symbolication information.23 """24 program = self.getBuildArtifact("a.out")25 self.build_and_launch(program)26 source = "main.c"27 28 # Set breakpoint inside bar() function29 lines = [line_number(source, "// breakpoint here")]30 breakpoint_ids = self.set_source_breakpoints(source, lines)31 self.assertEqual(32 len(breakpoint_ids), len(lines), "expect correct number of breakpoints"33 )34 35 self.continue_to_breakpoints(breakpoint_ids)36 37 # Get the stack frames: [0] = bar(), [1] = foo(), [2] = main()38 stack_frames = self.get_stackFrames()39 self.assertGreater(len(stack_frames), 2, "Expected more than 2 stack frames")40 41 # Examine the foo() frame (stack_frames[1])42 # This is the critical frame containing compiler-generated code43 foo_frame = stack_frames[1]44 45 # Verify that the frame's line number points to the bar() call,46 # not to the compiler-generated code after it47 foo_call_bar_source_line = foo_frame.get("line")48 self.assertEqual(49 foo_call_bar_source_line,50 line_number(source, "foo call bar"),51 "Expected foo call bar to be the source line of the frame",52 )53 54 # Verify the source file name is correctly resolved55 foo_source_name = foo_frame.get("source", {}).get("name")56 self.assertEqual(57 foo_source_name, "main.c", "Expected foo source name to be main.c"58 )59 60 # When lldb fails to symbolicate a frame it will emit a fake assembly61 # source with path of format <module>`<symbol> or <module>`<address> with62 # sourceReference to retrieve disassembly source file.63 # Verify that this didn't happen - the path should be a real file path.64 foo_path = foo_frame.get("source", {}).get("path")65 self.assertNotIn("`", foo_path, "Expected foo source path to not contain `")66 self.continue_to_exit()67