Skip to content

Commit 1b11034

Browse files
committed
[lldb-vscode] Fix handling of RestartRequest arguments.
According to the spec, RestartRequest has an optional "arguments" field, which is a RestartArguments object. RestartArguments has its own optional "arguments" field, which is a (LaunchRequestArguments | AttachRequestArguments) object. So we need to to the "arguments" lookup twice to get to the actual launch arguments. Differential Revision: https://reviews.llvm.org/D150392
1 parent 8a67460 commit 1b11034

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,14 @@ def request_continue(self, threadId=None):
588588
# Caller must still call wait_for_stopped.
589589
return response
590590

591-
def request_restart(self):
591+
def request_restart(self, restartArguments=None):
592592
command_dict = {
593593
'command': 'restart',
594594
'type': 'request',
595595
}
596+
if restartArguments:
597+
command_dict['arguments'] = restartArguments
598+
596599
response = self.send_recv(command_dict)
597600
# Caller must still call wait_for_stopped.
598601
return response

lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,37 @@ def test_stopOnEntry(self):
8080
reason, 'breakpoint',
8181
'verify stop after restart isn\'t "main" breakpoint')
8282

83+
@skipIfWindows
84+
@skipIfRemote
85+
def test_arguments(self):
86+
'''
87+
Tests that lldb-vscode will use updated launch arguments included
88+
with a restart request.
89+
'''
90+
line_A = line_number('main.c', '// breakpoint A')
91+
92+
program = self.getBuildArtifact("a.out")
93+
self.build_and_launch(program)
94+
[bp_A] = self.set_source_breakpoints('main.c', [line_A])
95+
96+
# Verify we hit A, then B.
97+
self.vscode.request_configurationDone()
98+
self.verify_breakpoint_hit([bp_A])
99+
100+
# We don't set any arguments in the initial launch request, so argc
101+
# should be 1.
102+
self.assertEquals(int(self.vscode.get_local_variable_value('argc')),
103+
1, 'argc != 1 before restart')
104+
105+
# Restart with some extra 'args' and check that the new argc reflects
106+
# the updated launch config.
107+
self.vscode.request_restart(restartArguments={
108+
'arguments': {
109+
'program': program,
110+
'args': ['a', 'b', 'c', 'd'],
111+
}
112+
})
113+
self.verify_breakpoint_hit([bp_A])
114+
self.assertEquals(int(self.vscode.get_local_variable_value('argc')),
115+
5, 'argc != 5 after restart')
116+

lldb/tools/lldb-vscode/lldb-vscode.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,11 +1963,13 @@ void request_restart(const llvm::json::Object &request) {
19631963

19641964
// The optional `arguments` field in RestartRequest can contain an updated
19651965
// version of the launch arguments. If there's one, use it.
1966-
auto request_arguments = request.getObject("arguments");
1967-
if (request_arguments) {
1968-
llvm::json::Object arguments = *request_arguments;
1969-
(*g_vsc.last_launch_or_attach_request)["arguments"] =
1970-
llvm::json::Value(std::move(arguments));
1966+
auto restart_arguments = request.getObject("arguments");
1967+
if (restart_arguments) {
1968+
auto launch_request_arguments = restart_arguments->getObject("arguments");
1969+
if (launch_request_arguments) {
1970+
(*g_vsc.last_launch_or_attach_request)["arguments"] =
1971+
llvm::json::Value(llvm::json::Object(*launch_request_arguments));
1972+
}
19711973
}
19721974

19731975
// Keep track of the old PID so when we get a "process exited" event from the

0 commit comments

Comments
 (0)