Skip to content

[lldb-dap] support moduleId in the stackTrace response #149774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lldb/test/API/tools/lldb-dap/coreFile/TestDAP_coreFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
33 changes: 33 additions & 0 deletions lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,36 @@ def test_StackFrameFormat(self):

frame = self.get_stackFrames(format={"parameters": False, "module": True})[0]
self.assertEqual(frame["name"], "a.out recurse")

@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.continue_to_breakpoints(breakpoint_ids)

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 module_id is None or source_name is None:
continue

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}",
)
7 changes: 7 additions & 0 deletions lldb/tools/lldb-dap/JSONUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,13 @@ 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);
}

return llvm::json::Value(std::move(object));
}

Expand Down
Loading