================ @@ -0,0 +1,195 @@ +""" +Test lldb-dap stack trace when some of the source paths are missing +""" + +from lldbsuite.test.decorators import skipIfWindows +from lldbsuite.test.lldbtest import line_number +import lldbdap_testcase +from contextlib import contextmanager +import os + + +OTHER_C_SOURCE_CODE = """ +int fibonacci(int n) { + if (n < 0) return -1; + if (n == 0) return 0; + if (n == 1) return 1; + int a = 0, b = 1, c; + for (int i = 2; i <= n; ++i) { + c = a + b; + a = b; + b = c; + } + + return b; // Break here +} +""" + + +@contextmanager +def delete_file_on_exit(path): + try: + yield path + finally: + if os.path.exists(path): + os.remove(path) + + +class TestDAP_stackTraceMissingSourcePath(lldbdap_testcase.DAPTestCaseBase): + def build_and_run_until_breakpoint(self, stop_disassembly_display: str): + """ + Build the program and run until the breakpoint is hit, and return the stack frames. + """ + other_source_file = "other.c" + with delete_file_on_exit(other_source_file): + with open(other_source_file, "w") as f: + f.write(OTHER_C_SOURCE_CODE) + + breakpoint_line = line_number(other_source_file, "// Break here") + + program = self.getBuildArtifact("a.out") + init_commands = [ + f"settings set stop-disassembly-display {stop_disassembly_display}" + ] + self.build_and_launch(program, initCommands=init_commands) + + breakpoint_ids = self.set_source_breakpoints( + other_source_file, [breakpoint_line] + ) + self.assertEqual( + len(breakpoint_ids), 1, "expect correct number of breakpoints" + ) + + self.continue_to_breakpoints(breakpoint_ids) + + frames = self.get_stackFrames() + self.assertLessEqual(2, len(frames), "expect at least 2 frames") + + self.assertIn( + "path", + frames[0]["source"], + "Expect source path to always be in frame (other.c)", + ) + self.assertIn( + "path", + frames[1]["source"], + "Expect source path in always be in frame (main.c)", + ) + + return frames + + @skipIfWindows + def test_stopDisassemblyDispay_noSource(self): + """ + Test that with with stop-disassembly-display = no-source - frames without source available give assembly code. + """ + frames = self.build_and_run_until_breakpoint("no-source") + + self.assertNotIn( + "other.c", + frames[0]["source"]["path"], + "Expect original source path to not be in unavailable source frame (other.c)", + ) + self.assertIn( + "sourceReference", + frames[0]["source"], + "Expect sourceReference source path in to be in unavailable source frame (other.c)", + ) + + self.assertIn( + "main.c", + frames[1]["source"]["path"], + "Expect original source path to be in source code frame (main.c)", + ) + self.assertNotIn( + "sourceReference", + frames[1]["source"], + "Expect no sourceReference in source code frame (main.c)", + ) + + @skipIfWindows ---------------- da-viper wrote:
Some of the dap test skip windows if it has platform specific code or the feature is not implemented yet. For example run in the terminal. In this case it is not needed and should work fine https://github.com/llvm/llvm-project/pull/136494 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits