[Lldb-commits] [lldb] r369296 - [lldb-vscode] add `launchCommands` to handle launch specific commands

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 19 13:17:28 PDT 2019


Author: xiaobai
Date: Mon Aug 19 13:17:27 2019
New Revision: 369296

URL: http://llvm.org/viewvc/llvm-project?rev=369296&view=rev
Log:
[lldb-vscode] add `launchCommands` to handle launch specific commands

Summary:
This can help `lldb-vscode` handle launch commands associate with remote platform
attach request have field `attachCommands` to handle attach specific commands
add a corresponding one for launch request
if no launch command is provided, create a new target and launch; otherwise, execute the launch command

Differential Revision: https://reviews.llvm.org/D65363

Patch by Wanyi Ye <kusmour at gmail.com>

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/launch/TestVSCode_launch.py
    lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
    lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
    lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp

Modified: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/launch/TestVSCode_launch.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/launch/TestVSCode_launch.py?rev=369296&r1=369295&r2=369296&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/launch/TestVSCode_launch.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/launch/TestVSCode_launch.py Mon Aug 19 13:17:27 2019
@@ -341,3 +341,68 @@ class TestVSCode_launch(lldbvscode_testc
         # "exitCommands" that were run after the second breakpoint was hit
         output = self.get_console(timeout=1.0)
         self.verify_commands('exitCommands', output, exitCommands)
+
+    @skipIfWindows
+    @skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
+    @no_debug_info_test
+    def test_extra_launch_commands(self):
+        '''
+            Tests the "luanchCommands" with extra launching settings
+        '''
+        self.build_and_create_debug_adaptor()
+        program = self.getBuildArtifact("a.out")
+
+        source = 'main.c'
+        first_line = line_number(source, '// breakpoint 1')
+        second_line = line_number(source, '// breakpoint 2')
+        # Set target binary and 2 breakoints
+        # then we can varify the "launchCommands" get run
+        # also we can verify that "stopCommands" get run as the
+        # breakpoints get hit
+        launchCommands = [
+            'target create "%s"' % (program),
+            'br s -f main.c -l %d' % first_line,
+            'br s -f main.c -l %d' % second_line,
+            'run'
+        ]
+
+        initCommands = ['target list', 'platform list']
+        preRunCommands = ['image list a.out', 'image dump sections a.out']
+        stopCommands = ['frame variable', 'bt']
+        exitCommands = ['expr 2+3', 'expr 3+4']
+        self.launch(program,
+                    initCommands=initCommands,
+                    preRunCommands=preRunCommands,
+                    stopCommands=stopCommands,
+                    exitCommands=exitCommands,
+                    launchCommands=launchCommands)
+
+        # Get output from the console. This should contain both the
+        # "initCommands" and the "preRunCommands".
+        output = self.get_console()
+        # Verify all "initCommands" were found in console output
+        self.verify_commands('initCommands', output, initCommands)
+        # Verify all "preRunCommands" were found in console output
+        self.verify_commands('preRunCommands', output, preRunCommands)
+
+        # Verify all "launchCommands" were founc in console output
+        # After execution, program should launch
+        self.verify_commands('launchCommands', output, launchCommands)
+        # Verify the "stopCommands" here
+        self.continue_to_next_stop()
+        output = self.get_console(timeout=1.0)
+        self.verify_commands('stopCommands', output, stopCommands)
+
+        # Continue and hit the second breakpoint.
+        # Get output from the console. This should contain both the
+        # "stopCommands" that were run after the first breakpoint was hit
+        self.continue_to_next_stop()
+        output = self.get_console(timeout=1.0)
+        self.verify_commands('stopCommands', output, stopCommands)
+
+        # Continue until the program exits
+        self.continue_to_exit()
+        # Get output from the console. This should contain both the
+        # "exitCommands" that were run after the second breakpoint was hit
+        output = self.get_console(timeout=1.0)
+        self.verify_commands('exitCommands', output, exitCommands)

Modified: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py?rev=369296&r1=369295&r2=369296&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py Mon Aug 19 13:17:27 2019
@@ -245,20 +245,17 @@ class VSCodeTestCaseBase(TestBase):
             self.assertTrue(response['success'],
                             'attach failed (%s)' % (response['message']))
 
-    def build_and_launch(self, program, args=None, cwd=None, env=None,
-                         stopOnEntry=False, disableASLR=True,
-                         disableSTDIO=False, shellExpandArguments=False,
-                         trace=False, initCommands=None, preRunCommands=None,
-                         stopCommands=None, exitCommands=None,
-                         sourcePath=None, debuggerRoot=None):
-        '''Build the default Makefile target, create the VSCode debug adaptor,
-           and launch the process.
+    def launch(self, program=None, args=None, cwd=None, env=None,
+               stopOnEntry=False, disableASLR=True,
+               disableSTDIO=False, shellExpandArguments=False,
+               trace=False, initCommands=None, preRunCommands=None,
+               stopCommands=None, exitCommands=None,sourcePath= None,
+               debuggerRoot=None, launchCommands=None):
+        '''Sending launch request to vscode
         '''
-        self.build_and_create_debug_adaptor()
-        self.assertTrue(os.path.exists(program), 'executable must exist')
 
-        # Make sure we disconnect and terminate the VSCode debug adaptor even
-        # if we throw an exception during the test case.
+        # Make sure we disconnet and terminate the VSCode debug adaptor,
+        # if we throw an exception during the test case
         def cleanup():
             self.vscode.request_disconnect(terminateDebuggee=True)
             self.vscode.terminate()
@@ -283,7 +280,25 @@ class VSCodeTestCaseBase(TestBase):
             stopCommands=stopCommands,
             exitCommands=exitCommands,
             sourcePath=sourcePath,
-            debuggerRoot=debuggerRoot)
+            debuggerRoot=debuggerRoot,
+            launchCommands=launchCommands)
         if not (response and response['success']):
             self.assertTrue(response['success'],
                             'launch failed (%s)' % (response['message']))
+
+    def build_and_launch(self, program, args=None, cwd=None, env=None,
+                         stopOnEntry=False, disableASLR=True,
+                         disableSTDIO=False, shellExpandArguments=False,
+                         trace=False, initCommands=None, preRunCommands=None,
+                         stopCommands=None, exitCommands=None,
+                         sourcePath=None, debuggerRoot=None):
+        '''Build the default Makefile target, create the VSCode debug adaptor,
+           and launch the process.
+        '''
+        self.build_and_create_debug_adaptor()
+        self.assertTrue(os.path.exists(program), 'executable must exist')
+
+        self.launch(program, args, cwd, env, stopOnEntry, disableASLR,
+                    disableSTDIO, shellExpandArguments, trace,
+                    initCommands, preRunCommands, stopCommands, exitCommands,
+                    sourcePath, debuggerRoot)

Modified: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py?rev=369296&r1=369295&r2=369296&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py Mon Aug 19 13:17:27 2019
@@ -558,7 +558,7 @@ class DebugCommunication(object):
                        disableSTDIO=False, shellExpandArguments=False,
                        trace=False, initCommands=None, preRunCommands=None,
                        stopCommands=None, exitCommands=None, sourcePath=None,
-                       debuggerRoot=None):
+                       debuggerRoot=None, launchCommands=None):
         args_dict = {
             'program': program
         }
@@ -591,6 +591,8 @@ class DebugCommunication(object):
             args_dict['sourcePath'] = sourcePath
         if debuggerRoot:
             args_dict['debuggerRoot'] = debuggerRoot
+        if launchCommands:
+            args_dict['launchCommands'] = launchCommands
         command_dict = {
             'command': 'launch',
             'type': 'request',

Modified: lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp?rev=369296&r1=369295&r2=369296&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp (original)
+++ lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp Mon Aug 19 13:17:27 2019
@@ -1182,6 +1182,7 @@ void request_launch(const llvm::json::Ob
   g_vsc.pre_run_commands = GetStrings(arguments, "preRunCommands");
   g_vsc.stop_commands = GetStrings(arguments, "stopCommands");
   g_vsc.exit_commands = GetStrings(arguments, "exitCommands");
+  auto launchCommands = GetStrings(arguments, "launchCommands");
   g_vsc.stop_at_entry = GetBoolean(arguments, "stopOnEntry", false);
   const auto debuggerRoot = GetString(arguments, "debuggerRoot");
 
@@ -1254,11 +1255,19 @@ void request_launch(const llvm::json::Ob
 
   // Run any pre run LLDB commands the user specified in the launch.json
   g_vsc.RunPreRunCommands();
+  if (launchCommands.empty()) {
+    // Disable async events so the launch will be successful when we return from
+    // the launch call and the launch will happen synchronously
+    g_vsc.debugger.SetAsync(false);
+    g_vsc.target.Launch(g_vsc.launch_info, error);
+    g_vsc.debugger.SetAsync(true);
+  } else {
+    g_vsc.RunLLDBCommands("Running launchCommands:", launchCommands);
+    // The custom commands might have created a new target so we should use the
+    // selected target after these commands are run.
+    g_vsc.target = g_vsc.debugger.GetSelectedTarget();
+  }
 
-  // Disable async events so the launch will be successful when we return from
-  // the launch call and the launch will happen synchronously
-  g_vsc.debugger.SetAsync(false);
-  g_vsc.target.Launch(g_vsc.launch_info, error);
   if (error.Fail()) {
     response["success"] = llvm::json::Value(false);
     EmplaceSafeString(response, "message", std::string(error.GetCString()));
@@ -1268,7 +1277,7 @@ void request_launch(const llvm::json::Ob
   SendProcessEvent(Launch);
   g_vsc.SendJSON(llvm::json::Value(CreateEventObject("initialized")));
   // Reenable async events and start the event thread to catch async events.
-  g_vsc.debugger.SetAsync(true);
+  // g_vsc.debugger.SetAsync(true);
 }
 
 // "NextRequest": {




More information about the lldb-commits mailing list