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 4 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
26 changes: 26 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,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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_stackFrameModuleIdUUID(self):
def test_stack_frame_module_id(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()
Comment on lines +251 to +252
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use self.continue_to_breakpoints instead as other things can cause a stop. see TestDAP_module.py for an example.


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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source_name and module_id can be none, continue if it is none.


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