|
| 1 | +""" |
| 2 | +Test lldb-dap stack trace when some of the source paths are missing |
| 3 | +""" |
| 4 | + |
| 5 | +from lldbsuite.test.lldbtest import line_number |
| 6 | +import lldbdap_testcase |
| 7 | +from contextlib import contextmanager |
| 8 | +import os |
| 9 | + |
| 10 | + |
| 11 | +OTHER_C_SOURCE_CODE = """ |
| 12 | +int no_source_func(int n) { |
| 13 | + return n + 1; // Break here |
| 14 | +} |
| 15 | +""" |
| 16 | + |
| 17 | + |
| 18 | +@contextmanager |
| 19 | +def delete_file_on_exit(path): |
| 20 | + try: |
| 21 | + yield path |
| 22 | + finally: |
| 23 | + if os.path.exists(path): |
| 24 | + os.remove(path) |
| 25 | + |
| 26 | + |
| 27 | +class TestDAP_stackTraceMissingSourcePath(lldbdap_testcase.DAPTestCaseBase): |
| 28 | + def build_and_run_until_breakpoint(self): |
| 29 | + """ |
| 30 | + Build the program and run until the breakpoint is hit, and return the stack frames. |
| 31 | + """ |
| 32 | + other_source_file = "other.c" |
| 33 | + with delete_file_on_exit(other_source_file): |
| 34 | + with open(other_source_file, "w") as f: |
| 35 | + f.write(OTHER_C_SOURCE_CODE) |
| 36 | + |
| 37 | + breakpoint_line = line_number(other_source_file, "// Break here") |
| 38 | + |
| 39 | + program = self.getBuildArtifact("a.out") |
| 40 | + self.build_and_launch(program, commandEscapePrefix="") |
| 41 | + |
| 42 | + breakpoint_ids = self.set_source_breakpoints( |
| 43 | + other_source_file, [breakpoint_line] |
| 44 | + ) |
| 45 | + self.assertEqual( |
| 46 | + len(breakpoint_ids), 1, "expect correct number of breakpoints" |
| 47 | + ) |
| 48 | + |
| 49 | + self.continue_to_breakpoints(breakpoint_ids) |
| 50 | + |
| 51 | + frames = self.get_stackFrames() |
| 52 | + self.assertLessEqual(2, len(frames), "expect at least 2 frames") |
| 53 | + |
| 54 | + self.assertIn( |
| 55 | + "path", |
| 56 | + frames[0]["source"], |
| 57 | + "Expect source path to always be in frame (other.c)", |
| 58 | + ) |
| 59 | + self.assertIn( |
| 60 | + "path", |
| 61 | + frames[1]["source"], |
| 62 | + "Expect source path in always be in frame (main.c)", |
| 63 | + ) |
| 64 | + |
| 65 | + return frames |
| 66 | + |
| 67 | + def verify_frames_source( |
| 68 | + self, frames, main_frame_assembly: bool, other_frame_assembly: bool |
| 69 | + ): |
| 70 | + if other_frame_assembly: |
| 71 | + self.assertFalse( |
| 72 | + frames[0]["source"]["path"].endswith("other.c"), |
| 73 | + "Expect original source path to not be in unavailable source frame (other.c)", |
| 74 | + ) |
| 75 | + self.assertIn( |
| 76 | + "sourceReference", |
| 77 | + frames[0]["source"], |
| 78 | + "Expect sourceReference to be in unavailable source frame (other.c)", |
| 79 | + ) |
| 80 | + else: |
| 81 | + self.assertTrue( |
| 82 | + frames[0]["source"]["path"].endswith("other.c"), |
| 83 | + "Expect original source path to be in normal source frame (other.c)", |
| 84 | + ) |
| 85 | + self.assertNotIn( |
| 86 | + "sourceReference", |
| 87 | + frames[0]["source"], |
| 88 | + "Expect sourceReference to not be in normal source frame (other.c)", |
| 89 | + ) |
| 90 | + |
| 91 | + if main_frame_assembly: |
| 92 | + self.assertFalse( |
| 93 | + frames[1]["source"]["path"].endswith("main.c"), |
| 94 | + "Expect original source path to not be in unavailable source frame (main.c)", |
| 95 | + ) |
| 96 | + self.assertIn( |
| 97 | + "sourceReference", |
| 98 | + frames[1]["source"], |
| 99 | + "Expect sourceReference to be in unavailable source frame (main.c)", |
| 100 | + ) |
| 101 | + else: |
| 102 | + self.assertTrue( |
| 103 | + frames[1]["source"]["path"].endswith("main.c"), |
| 104 | + "Expect original source path to be in normal source frame (main.c)", |
| 105 | + ) |
| 106 | + self.assertNotIn( |
| 107 | + "sourceReference", |
| 108 | + frames[1]["source"], |
| 109 | + "Expect sourceReference to not be in normal source code frame (main.c)", |
| 110 | + ) |
| 111 | + |
| 112 | + def test_stopDisassemblyDisplay(self): |
| 113 | + """ |
| 114 | + Test that with with all stop-disassembly-display values you get correct assembly / no assembly source code. |
| 115 | + """ |
| 116 | + self.build_and_run_until_breakpoint() |
| 117 | + frames = self.get_stackFrames() |
| 118 | + self.assertLessEqual(2, len(frames), "expect at least 2 frames") |
| 119 | + |
| 120 | + self.assertIn( |
| 121 | + "path", |
| 122 | + frames[0]["source"], |
| 123 | + "Expect source path to always be in frame (other.c)", |
| 124 | + ) |
| 125 | + self.assertIn( |
| 126 | + "path", |
| 127 | + frames[1]["source"], |
| 128 | + "Expect source path in always be in frame (main.c)", |
| 129 | + ) |
| 130 | + |
| 131 | + self.dap_server.request_evaluate( |
| 132 | + "settings set stop-disassembly-display never", context="repl" |
| 133 | + ) |
| 134 | + frames = self.get_stackFrames() |
| 135 | + self.verify_frames_source( |
| 136 | + frames, main_frame_assembly=False, other_frame_assembly=False |
| 137 | + ) |
| 138 | + |
| 139 | + self.dap_server.request_evaluate( |
| 140 | + "settings set stop-disassembly-display always", context="repl" |
| 141 | + ) |
| 142 | + frames = self.get_stackFrames() |
| 143 | + self.verify_frames_source( |
| 144 | + frames, main_frame_assembly=True, other_frame_assembly=True |
| 145 | + ) |
| 146 | + |
| 147 | + self.dap_server.request_evaluate( |
| 148 | + "settings set stop-disassembly-display no-source", context="repl" |
| 149 | + ) |
| 150 | + frames = self.get_stackFrames() |
| 151 | + self.verify_frames_source( |
| 152 | + frames, main_frame_assembly=False, other_frame_assembly=True |
| 153 | + ) |
| 154 | + |
| 155 | + self.dap_server.request_evaluate( |
| 156 | + "settings set stop-disassembly-display no-debuginfo", context="repl" |
| 157 | + ) |
| 158 | + frames = self.get_stackFrames() |
| 159 | + self.verify_frames_source( |
| 160 | + frames, main_frame_assembly=False, other_frame_assembly=False |
| 161 | + ) |
0 commit comments