diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py index 99fcc423894b6..95bc60c41fd50 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py @@ -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 diff --git a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py index 931456299e03e..df371d02cbf71 100644 --- a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py +++ b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py @@ -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): """ diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp index b7d3c8ced69f1..9b97e26ed7bd0 100644 --- a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp @@ -57,9 +57,8 @@ void BaseRequestHandler::SetSourceMapFromArguments( "source must be be an array of two-element arrays, " "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); const auto sourcePath = GetString(arguments, "sourcePath").value_or(""); // sourceMap is the new, more general form of sourcePath and overrides it. @@ -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; dap.RunLLDBCommands("Setting source map:", {sourceMapCommand}); } }