summaryrefslogtreecommitdiff
path: root/lldb
diff options
context:
space:
mode:
authorJorge Gorbe Moya <jgorbe@google.com>2023-05-11 12:06:32 -0700
committerJorge Gorbe Moya <jgorbe@google.com>2023-05-11 13:11:38 -0700
commit1b11034c672fc90d35b4bc0e93f3507657b14094 (patch)
tree64b9503b3fe29068e20cdac3d79a7047e493420b /lldb
parent8a6746065a90a7cc7f8925e6c65ac378a7f91db7 (diff)
downloadllvm-1b11034c672fc90d35b4bc0e93f3507657b14094.tar.gz
[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
Diffstat (limited to 'lldb')
-rw-r--r--lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py5
-rw-r--r--lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart.py34
-rw-r--r--lldb/tools/lldb-vscode/lldb-vscode.cpp12
3 files changed, 45 insertions, 6 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
index 16d26a8fa221..d3b7867359b3 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
@@ -588,11 +588,14 @@ class DebugCommunication(object):
# Caller must still call wait_for_stopped.
return response
- def request_restart(self):
+ def request_restart(self, restartArguments=None):
command_dict = {
'command': 'restart',
'type': 'request',
}
+ if restartArguments:
+ command_dict['arguments'] = restartArguments
+
response = self.send_recv(command_dict)
# Caller must still call wait_for_stopped.
return response
diff --git a/lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart.py b/lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart.py
index 6715b167bcdb..a64dba531969 100644
--- a/lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart.py
+++ b/lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart.py
@@ -80,3 +80,37 @@ class TestVSCode_restart(lldbvscode_testcase.VSCodeTestCaseBase):
reason, 'breakpoint',
'verify stop after restart isn\'t "main" breakpoint')
+ @skipIfWindows
+ @skipIfRemote
+ def test_arguments(self):
+ '''
+ Tests that lldb-vscode will use updated launch arguments included
+ with a restart request.
+ '''
+ line_A = line_number('main.c', '// breakpoint A')
+
+ program = self.getBuildArtifact("a.out")
+ self.build_and_launch(program)
+ [bp_A] = self.set_source_breakpoints('main.c', [line_A])
+
+ # Verify we hit A, then B.
+ self.vscode.request_configurationDone()
+ self.verify_breakpoint_hit([bp_A])
+
+ # We don't set any arguments in the initial launch request, so argc
+ # should be 1.
+ self.assertEquals(int(self.vscode.get_local_variable_value('argc')),
+ 1, 'argc != 1 before restart')
+
+ # Restart with some extra 'args' and check that the new argc reflects
+ # the updated launch config.
+ self.vscode.request_restart(restartArguments={
+ 'arguments': {
+ 'program': program,
+ 'args': ['a', 'b', 'c', 'd'],
+ }
+ })
+ self.verify_breakpoint_hit([bp_A])
+ self.assertEquals(int(self.vscode.get_local_variable_value('argc')),
+ 5, 'argc != 5 after restart')
+
diff --git a/lldb/tools/lldb-vscode/lldb-vscode.cpp b/lldb/tools/lldb-vscode/lldb-vscode.cpp
index f56a5368939e..126719e1494e 100644
--- a/lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ b/lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1963,11 +1963,13 @@ void request_restart(const llvm::json::Object &request) {
// The optional `arguments` field in RestartRequest can contain an updated
// version of the launch arguments. If there's one, use it.
- auto request_arguments = request.getObject("arguments");
- if (request_arguments) {
- llvm::json::Object arguments = *request_arguments;
- (*g_vsc.last_launch_or_attach_request)["arguments"] =
- llvm::json::Value(std::move(arguments));
+ auto restart_arguments = request.getObject("arguments");
+ if (restart_arguments) {
+ auto launch_request_arguments = restart_arguments->getObject("arguments");
+ if (launch_request_arguments) {
+ (*g_vsc.last_launch_or_attach_request)["arguments"] =
+ llvm::json::Value(llvm::json::Object(*launch_request_arguments));
+ }
}
// Keep track of the old PID so when we get a "process exited" event from the