Skip to content

Fix the lldb-dap error when empty source map is specified #137722

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 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ def request_launch(
args_dict["debuggerRoot"] = debuggerRoot
if launchCommands:
args_dict["launchCommands"] = launchCommands
if sourceMap:
if sourceMap is not None: # sourceMap can be empty array.
args_dict["sourceMap"] = sourceMap
if runInTerminal:
args_dict["runInTerminal"] = runInTerminal
Expand Down
18 changes: 18 additions & 0 deletions lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ def test_stopOnEntry(self):
reason, "breakpoint", 'verify stop isn\'t "main" breakpoint'
)

@skipIfWindows
def test_empty_sourceMap(self):
"""
Tests the launch with empty source map should not issue source map command.
"""
program = self.getBuildArtifact("a.out")
self.build_and_create_debug_adapter()
empty_source_map = []
self.launch(program, sourceMap=empty_source_map)
self.continue_to_exit()

# Now get the console output and verify no source map command was issued for empty source map.
console_output = self.get_console()
self.assertTrue(
console_output and len(console_output) > 0, "expect some console output"
)
self.assertNotIn("Setting source map:", console_output)

@skipIfWindows
def test_cwd(self):
"""
Expand Down
9 changes: 5 additions & 4 deletions lldb/tools/lldb-dap/Handler/RequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ void BaseRequestHandler::SetSourceMapFromArguments(
"source must be be an array of two-element arrays, "
Copy link
Contributor

Choose a reason for hiding this comment

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

Just FYI, the launch command has been updated and is going through

void DAP::ConfigureSourceMaps() {
for setting the target.source-map value. I've been working on migrating the requests to not use raw json objects but I haven't updated the attach handler yet.

The test, as currently written, is not actually going to run this code. Its still good to have and check though.

"each containing a source and replacement path string.\n";

std::string sourceMapCommand;
llvm::raw_string_ostream strm(sourceMapCommand);
strm << "settings set target.source-map ";
std::string sourceMapCommandMappings;
llvm::raw_string_ostream strm(sourceMapCommandMappings);
Comment on lines +60 to +61
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::string sourceMapCommandMappings;
llvm::raw_string_ostream strm(sourceMapCommandMappings);
std::string source_map_command_mappings;
llvm::raw_string_ostream strm(source_map_command_mappings);

const auto sourcePath = GetString(arguments, "sourcePath").value_or("");

// sourceMap is the new, more general form of sourcePath and overrides it.
Expand Down Expand Up @@ -94,7 +93,9 @@ void BaseRequestHandler::SetSourceMapFromArguments(
// Do any source remapping needed before we create our targets
strm << "\".\" \"" << sourcePath << "\"";
}
if (!sourceMapCommand.empty()) {
if (!sourceMapCommandMappings.empty()) {
std::string sourceMapCommand = "settings set target.source-map ";
sourceMapCommand += sourceMapCommandMappings;
Comment on lines +96 to +98
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (!sourceMapCommandMappings.empty()) {
std::string sourceMapCommand = "settings set target.source-map ";
sourceMapCommand += sourceMapCommandMappings;
if (!sourceMapCommandMappings.empty()) {
dap.RunLLDBCommands("Setting source map:", llvm::formatv("settings set target.source-map {0}", source_map_command_mappings));

dap.RunLLDBCommands("Setting source map:", {sourceMapCommand});
}
}
Expand Down
Loading