Skip to content

Commit 06307d4

Browse files
author
Jeffrey Tan
committed
Fix the lldb-dap error when empty source map is specified
1 parent b111da9 commit 06307d4

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ def request_launch(
851851
args_dict["debuggerRoot"] = debuggerRoot
852852
if launchCommands:
853853
args_dict["launchCommands"] = launchCommands
854-
if sourceMap:
854+
if sourceMap is not None: # sourceMap can be empty array.
855855
args_dict["sourceMap"] = sourceMap
856856
if runInTerminal:
857857
args_dict["runInTerminal"] = runInTerminal

lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ def test_stopOnEntry(self):
9999
reason, "breakpoint", 'verify stop isn\'t "main" breakpoint'
100100
)
101101

102+
@skipIfWindows
103+
def test_empty_sourceMap(self):
104+
"""
105+
Tests the launch with empty source map should not issue source map command.
106+
"""
107+
program = self.getBuildArtifact("a.out")
108+
self.build_and_create_debug_adapter()
109+
empty_source_map = []
110+
self.launch(program, sourceMap=empty_source_map)
111+
self.continue_to_exit()
112+
113+
# Now get the console output and verify no source map command was issued for empty source map.
114+
console_output = self.get_console()
115+
self.assertTrue(
116+
console_output and len(console_output) > 0, "expect some console output"
117+
)
118+
self.assertNotIn("Setting source map:", console_output)
119+
102120
@skipIfWindows
103121
def test_cwd(self):
104122
"""

lldb/tools/lldb-dap/Handler/RequestHandler.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ void BaseRequestHandler::SetSourceMapFromArguments(
5757
"source must be be an array of two-element arrays, "
5858
"each containing a source and replacement path string.\n";
5959

60-
std::string sourceMapCommand;
61-
llvm::raw_string_ostream strm(sourceMapCommand);
62-
strm << "settings set target.source-map ";
60+
std::string sourceMapCommandMappings;
61+
llvm::raw_string_ostream strm(sourceMapCommandMappings);
6362
const auto sourcePath = GetString(arguments, "sourcePath").value_or("");
6463

6564
// sourceMap is the new, more general form of sourcePath and overrides it.
@@ -94,7 +93,9 @@ void BaseRequestHandler::SetSourceMapFromArguments(
9493
// Do any source remapping needed before we create our targets
9594
strm << "\".\" \"" << sourcePath << "\"";
9695
}
97-
if (!sourceMapCommand.empty()) {
96+
if (!sourceMapCommandMappings.empty()) {
97+
std::string sourceMapCommand = "settings set target.source-map ";
98+
sourceMapCommand += sourceMapCommandMappings;
9899
dap.RunLLDBCommands("Setting source map:", {sourceMapCommand});
99100
}
100101
}

0 commit comments

Comments
 (0)