Skip to content

Commit 25af56f

Browse files
Jeffrey Tankusmour
authored andcommitted
Fix empty source map error from upstream
Summary: While testing against latest Beta release using fdb, I noticed that VSCode console always emits following failure: ``` Setting source map: (lldb) settings set target.source-map error: 'settings set' takes more arguments ``` Turns out fdb is sending empty source map settings to lldb, which lldb has a recent regression to setting empty mapping which causes error. This diff fixes the regression by detecting the mapping is empty and do not run the command. This internal patch aims to fix and unblock release immediately, will upstream this later. Test Plan: The mentioned error does not show up. The added test in this diff failed before but pass with the change. Reviewers: gclayton, peix, #lldb_team, zynli Reviewed By: zynli Subscribers: #lldb_team Differential Revision: https://phabricator.intern.facebook.com/D73478506
1 parent 57c2b7f commit 25af56f

File tree

3 files changed

+45
-21
lines changed

3 files changed

+45
-21
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
@@ -975,7 +975,7 @@ def request_launch(
975975
args_dict["debuggerRoot"] = debuggerRoot
976976
if launchCommands:
977977
args_dict["launchCommands"] = launchCommands
978-
if sourceMap:
978+
if sourceMap is not None: # sourceMap can be empty array.
979979
args_dict["sourceMap"] = sourceMap
980980
if runInTerminal:
981981
args_dict["runInTerminal"] = runInTerminal

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

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
import dap_server
66
from lldbsuite.test.decorators import *
77
from lldbsuite.test.lldbtest import *
8-
from lldbsuite.test import lldbutil
9-
import lldbdap_testcase
10-
import time
118
import os
129
import re
10+
import time
11+
12+
import lldbdap_testcase
13+
from lldbsuite.test import lldbutil
1314

1415
# Many tests are skipped on Windows because get_stdout() returns None there.
1516
# Despite the test program printing correctly. See
@@ -100,6 +101,23 @@ def test_stopOnEntry(self):
100101
reason, "breakpoint", 'verify stop isn\'t "main" breakpoint'
101102
)
102103

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

576594
def test_session_id_update(self):
577595
program = self.getBuildArtifact("a.out")
578-
postRunCommands = ["script print('Actual_Session_ID: ' + str(os.getenv('VSCODE_DEBUG_SESSION_ID')))"]
596+
postRunCommands = [
597+
"script print('Actual_Session_ID: ' + str(os.getenv('VSCODE_DEBUG_SESSION_ID')))"
598+
]
579599
self.build_and_launch(
580-
program,
581-
vscode_session_id="test_session_id",
600+
program,
601+
vscode_session_id="test_session_id",
582602
postRunCommands=postRunCommands,
583-
)
584-
output = self.get_console()
603+
)
604+
output = self.get_console()
585605
self.continue_to_exit()
586-
lines = filter(lambda x: 'Actual_Session_ID' in x, output.splitlines())
606+
lines = filter(lambda x: "Actual_Session_ID" in x, output.splitlines())
587607
self.assertTrue(
588-
any("test_session_id" in l for l in lines), "expect session id in console output"
608+
any("test_session_id" in l for l in lines),
609+
"expect session id in console output",
589610
)
590-
591-
def test_session_id_update_empty(self):
611+
612+
def test_session_id_update_empty(self):
592613
program = self.getBuildArtifact("a.out")
593-
self.build_and_launch(program)
594-
output = self.get_console()
614+
self.build_and_launch(program)
615+
output = self.get_console()
595616
self.continue_to_exit()
596617
self.assertTrue(
597-
all("VSCODE_DEBUG_SESSION_ID" not in l for l in output.splitlines()),
598-
"expect NO session id update command"
618+
all("VSCODE_DEBUG_SESSION_ID" not in l for l in output.splitlines()),
619+
"expect NO session id update command",
599620
)

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,9 +1112,8 @@ void DAP::ConfigureSourceMaps() {
11121112
if (configuration.sourceMap.empty() && configuration.sourcePath.empty())
11131113
return;
11141114

1115-
std::string sourceMapCommand;
1116-
llvm::raw_string_ostream strm(sourceMapCommand);
1117-
strm << "settings set target.source-map ";
1115+
std::string sourceMapCommandMappings;
1116+
llvm::raw_string_ostream strm(sourceMapCommandMappings);
11181117

11191118
if (!configuration.sourceMap.empty()) {
11201119
for (const auto &kv : configuration.sourceMap) {
@@ -1124,7 +1123,11 @@ void DAP::ConfigureSourceMaps() {
11241123
strm << "\".\" \"" << configuration.sourcePath << "\"";
11251124
}
11261125

1127-
RunLLDBCommands("Setting source map:", {sourceMapCommand});
1126+
if (!sourceMapCommandMappings.empty()) {
1127+
std::string sourceMapCommand = "settings set target.source-map ";
1128+
sourceMapCommand += sourceMapCommandMappings;
1129+
RunLLDBCommands("Setting source map:", {sourceMapCommand});
1130+
}
11281131
}
11291132

11301133
void DAP::SetConfiguration(const protocol::Configuration &config,

0 commit comments

Comments
 (0)