jgorbe updated this revision to Diff 521412.
jgorbe added a comment.

Added test case.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150392/new/

https://reviews.llvm.org/D150392

Files:
  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


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===================================================================
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1963,11 +1963,13 @@
 
   // 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
Index: lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart.py
===================================================================
--- lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart.py
+++ lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart.py
@@ -80,3 +80,37 @@
                         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')
+
Index: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
@@ -588,11 +588,14 @@
         # 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


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===================================================================
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1963,11 +1963,13 @@
 
   // 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
Index: lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart.py
===================================================================
--- lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart.py
+++ lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart.py
@@ -80,3 +80,37 @@
                         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')
+
Index: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
@@ -588,11 +588,14 @@
         # 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
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to