From 33c94346ac2b96d9f68fd1b8d62aebfa7b273499 Mon Sep 17 00:00:00 2001 From: woruyu <1214539920@qq.com> Date: Mon, 21 Jul 2025 15:52:50 +0800 Subject: [PATCH 1/6] [lldb-dap] support moduleId in the stackTrace response --- lldb/tools/lldb-dap/JSONUtils.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp index 41ca29a405ac9..7abd9618cc71f 100644 --- a/lldb/tools/lldb-dap/JSONUtils.cpp +++ b/lldb/tools/lldb-dap/JSONUtils.cpp @@ -550,6 +550,15 @@ llvm::json::Value CreateStackFrame(DAP &dap, lldb::SBFrame &frame, if (frame.IsArtificial() || frame.IsHidden()) object.try_emplace("presentationHint", "subtle"); + lldb::SBModule module = frame.GetModule(); + if (module.IsValid()) { + std::string uuid = module.GetUUIDString(); + if (!uuid.empty()) + object.try_emplace("moduleId", uuid); + else + object.try_emplace("moduleId", module.GetFileSpec().GetFilename()); + } + return llvm::json::Value(std::move(object)); } From 3c47de26e1e680e7d14727b6068da99963c21b2e Mon Sep 17 00:00:00 2001 From: woruyu <1214539920@qq.com> Date: Mon, 21 Jul 2025 17:09:08 +0800 Subject: [PATCH 2/6] fix: ci test for moduleId --- lldb/test/API/tools/lldb-dap/coreFile/TestDAP_coreFile.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lldb/test/API/tools/lldb-dap/coreFile/TestDAP_coreFile.py b/lldb/test/API/tools/lldb-dap/coreFile/TestDAP_coreFile.py index db43dbaf515cf..2743fca58e81d 100644 --- a/lldb/test/API/tools/lldb-dap/coreFile/TestDAP_coreFile.py +++ b/lldb/test/API/tools/lldb-dap/coreFile/TestDAP_coreFile.py @@ -26,6 +26,7 @@ def test_core_file(self): "column": 0, "id": 524288, "line": 4, + "moduleId":"01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D", "name": "bar", "source": {"name": "main.c", "path": "/home/labath/test/main.c"}, "instructionPointerReference": "0x40011C", @@ -34,6 +35,7 @@ def test_core_file(self): "column": 0, "id": 524289, "line": 10, + "moduleId":"01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D", "name": "foo", "source": {"name": "main.c", "path": "/home/labath/test/main.c"}, "instructionPointerReference": "0x400142", @@ -42,6 +44,7 @@ def test_core_file(self): "column": 0, "id": 524290, "line": 16, + "moduleId":"01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D", "name": "_start", "source": {"name": "main.c", "path": "/home/labath/test/main.c"}, "instructionPointerReference": "0x40015F", From 5359fd9fe54326f9820cc0c1a0b23f1b7e06fc93 Mon Sep 17 00:00:00 2001 From: woruyu <1214539920@qq.com> Date: Mon, 21 Jul 2025 17:21:39 +0800 Subject: [PATCH 3/6] fix: python format --- lldb/test/API/tools/lldb-dap/coreFile/TestDAP_coreFile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lldb/test/API/tools/lldb-dap/coreFile/TestDAP_coreFile.py b/lldb/test/API/tools/lldb-dap/coreFile/TestDAP_coreFile.py index 2743fca58e81d..1143cd93a70b3 100644 --- a/lldb/test/API/tools/lldb-dap/coreFile/TestDAP_coreFile.py +++ b/lldb/test/API/tools/lldb-dap/coreFile/TestDAP_coreFile.py @@ -26,7 +26,7 @@ def test_core_file(self): "column": 0, "id": 524288, "line": 4, - "moduleId":"01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D", + "moduleId": "01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D", "name": "bar", "source": {"name": "main.c", "path": "/home/labath/test/main.c"}, "instructionPointerReference": "0x40011C", @@ -35,7 +35,7 @@ def test_core_file(self): "column": 0, "id": 524289, "line": 10, - "moduleId":"01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D", + "moduleId": "01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D", "name": "foo", "source": {"name": "main.c", "path": "/home/labath/test/main.c"}, "instructionPointerReference": "0x400142", @@ -44,7 +44,7 @@ def test_core_file(self): "column": 0, "id": 524290, "line": 16, - "moduleId":"01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D", + "moduleId": "01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D", "name": "_start", "source": {"name": "main.c", "path": "/home/labath/test/main.c"}, "instructionPointerReference": "0x40015F", From 9dca8b225fa76678a8cc604c537a97e58a9fad95 Mon Sep 17 00:00:00 2001 From: woruyu <1214539920@qq.com> Date: Tue, 22 Jul 2025 15:40:07 +0800 Subject: [PATCH 4/6] fix: review --- .../lldb-dap/stackTrace/TestDAP_stackTrace.py | 26 +++++++++++++++++++ lldb/tools/lldb-dap/JSONUtils.cpp | 2 -- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py b/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py index abd469274ffd4..c7c43e5bd4bc0 100644 --- a/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py +++ b/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py @@ -242,3 +242,29 @@ def test_StackFrameFormat(self): frame = self.get_stackFrames(format={"parameters": False, "module": True})[0] self.assertEqual(frame["name"], "a.out recurse") + + def test_stackFrameModuleIdUUID(self): + program = self.getBuildArtifact("a.out") + self.build_and_launch(program) + source = "main.c" + + self.set_source_breakpoints(source, [line_number(source, "recurse end")]) + self.continue_to_next_stop() + + modules = self.dap_server.get_modules() + name_to_id = { + name: info["id"] for name, info in modules.items() if "id" in info + } + + stackFrames = self.get_stackFrames() + for frame in stackFrames: + module_id = frame.get("moduleId") + source_name = frame.get("source", {}).get("name") + + if source_name in name_to_id: + expected_id = name_to_id[source_name] + self.assertEqual( + module_id, + expected_id, + f"Expected moduleId '{expected_id}' for {source_name}, got: {module_id}", + ) diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp index 7abd9618cc71f..3fbcc23cdb278 100644 --- a/lldb/tools/lldb-dap/JSONUtils.cpp +++ b/lldb/tools/lldb-dap/JSONUtils.cpp @@ -555,8 +555,6 @@ llvm::json::Value CreateStackFrame(DAP &dap, lldb::SBFrame &frame, std::string uuid = module.GetUUIDString(); if (!uuid.empty()) object.try_emplace("moduleId", uuid); - else - object.try_emplace("moduleId", module.GetFileSpec().GetFilename()); } return llvm::json::Value(std::move(object)); From 225fd8e8cb91128aa8ae165e837e74dd69e8a890 Mon Sep 17 00:00:00 2001 From: woruyu <1214539920@qq.com> Date: Tue, 29 Jul 2025 10:33:50 +0800 Subject: [PATCH 5/6] fix: review --- .../tools/lldb-dap/stackTrace/TestDAP_stackTrace.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py b/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py index c7c43e5bd4bc0..011f0545537bd 100644 --- a/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py +++ b/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py @@ -243,13 +243,18 @@ def test_StackFrameFormat(self): frame = self.get_stackFrames(format={"parameters": False, "module": True})[0] self.assertEqual(frame["name"], "a.out recurse") - def test_stackFrameModuleIdUUID(self): + @skipIfWindows + def test_stack_frame_module_id(self): program = self.getBuildArtifact("a.out") self.build_and_launch(program) source = "main.c" + lines = [line_number(source, "recurse end")] + breakpoint_ids = self.set_source_breakpoints(source, lines) + self.assertEqual( + len(breakpoint_ids), len(lines), "expect correct number of breakpoints" + ) - self.set_source_breakpoints(source, [line_number(source, "recurse end")]) - self.continue_to_next_stop() + self.continue_to_breakpoints(breakpoint_ids) modules = self.dap_server.get_modules() name_to_id = { @@ -260,6 +265,8 @@ def test_stackFrameModuleIdUUID(self): for frame in stackFrames: module_id = frame.get("moduleId") source_name = frame.get("source", {}).get("name") + if module_id is None or source_name is None: + continue if source_name in name_to_id: expected_id = name_to_id[source_name] From cdd0884ba00f812cd9b00100ad6eebb8fac1b81b Mon Sep 17 00:00:00 2001 From: woruyu <99597449+woruyu@users.noreply.github.com> Date: Thu, 31 Jul 2025 09:45:24 +0800 Subject: [PATCH 6/6] Update lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py Co-authored-by: Ebuka Ezike --- lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py b/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py index 011f0545537bd..fd2037b5762d1 100644 --- a/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py +++ b/lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py @@ -261,8 +261,8 @@ def test_stack_frame_module_id(self): name: info["id"] for name, info in modules.items() if "id" in info } - stackFrames = self.get_stackFrames() - for frame in stackFrames: + stack_frames = self.get_stackFrames() + for frame in stack_frames: module_id = frame.get("moduleId") source_name = frame.get("source", {}).get("name") if module_id is None or source_name is None: