[Lldb-commits] [lldb] 1b11034 - [lldb-vscode] Fix handling of RestartRequest arguments.

Jorge Gorbe Moya via lldb-commits lldb-commits at lists.llvm.org
Thu May 11 13:13:28 PDT 2023


Author: Jorge Gorbe Moya
Date: 2023-05-11T13:11:38-07:00
New Revision: 1b11034c672fc90d35b4bc0e93f3507657b14094

URL: https://github.com/llvm/llvm-project/commit/1b11034c672fc90d35b4bc0e93f3507657b14094
DIFF: https://github.com/llvm/llvm-project/commit/1b11034c672fc90d35b4bc0e93f3507657b14094.diff

LOG: [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

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
    lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart.py
    lldb/tools/lldb-vscode/lldb-vscode.cpp

Removed: 
    


################################################################################
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 16d26a8fa2216..d3b7867359b39 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 @@ def request_continue(self, threadId=None):
         # 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 6715b167bcdb0..a64dba5319692 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 @@ def test_stopOnEntry(self):
                         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 f56a5368939e2..126719e1494e5 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


        


More information about the lldb-commits mailing list