[Lldb-commits] [lldb] 79fbbeb - [lldb-vscode] Add postRunCommands

Walter Erquinigo via lldb-commits lldb-commits at lists.llvm.org
Wed Apr 21 13:51:38 PDT 2021


Author: Walter Erquinigo
Date: 2021-04-21T13:51:30-07:00
New Revision: 79fbbeb41280ed170a387ad925c5397c0af32364

URL: https://github.com/llvm/llvm-project/commit/79fbbeb41280ed170a387ad925c5397c0af32364
DIFF: https://github.com/llvm/llvm-project/commit/79fbbeb41280ed170a387ad925c5397c0af32364.diff

LOG: [lldb-vscode] Add postRunCommands

This diff ass postRunCommands, which are the counterpart of the preRunCommands. TThey will be executed right after the target is launched or attached correctly, which means that the targets can assume that the target is running.

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

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
    lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
    lldb/test/API/tools/lldb-vscode/attach/TestVSCode_attach.py
    lldb/test/API/tools/lldb-vscode/launch/TestVSCode_launch.py
    lldb/tools/lldb-vscode/lldb-vscode.cpp
    lldb/tools/lldb-vscode/package.json

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
index 7ddb3164cb3db..d073e3692dd30 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
@@ -251,7 +251,8 @@ def continue_to_exit(self, exitCode=0):
     def attach(self, program=None, pid=None, waitFor=None, trace=None,
                initCommands=None, preRunCommands=None, stopCommands=None,
                exitCommands=None, attachCommands=None, coreFile=None,
-               disconnectAutomatically=True, terminateCommands=None):
+               disconnectAutomatically=True, terminateCommands=None,
+               postRunCommands=None):
         '''Build the default Makefile target, create the VSCode debug adaptor,
            and attach to the process.
         '''
@@ -271,7 +272,7 @@ def cleanup():
             initCommands=initCommands, preRunCommands=preRunCommands,
             stopCommands=stopCommands, exitCommands=exitCommands,
             attachCommands=attachCommands, terminateCommands=terminateCommands,
-            coreFile=coreFile)
+            coreFile=coreFile, postRunCommands=postRunCommands)
         if not (response and response['success']):
             self.assertTrue(response['success'],
                             'attach failed (%s)' % (response['message']))
@@ -283,7 +284,7 @@ def launch(self, program=None, args=None, cwd=None, env=None,
                stopCommands=None, exitCommands=None, terminateCommands=None,
                sourcePath=None, debuggerRoot=None, launchCommands=None,
                sourceMap=None, disconnectAutomatically=True, runInTerminal=False,
-               expectFailure=False):
+               expectFailure=False, postRunCommands=None):
         '''Sending launch request to vscode
         '''
 
@@ -319,7 +320,8 @@ def cleanup():
             launchCommands=launchCommands,
             sourceMap=sourceMap,
             runInTerminal=runInTerminal,
-            expectFailure=expectFailure)
+            expectFailure=expectFailure,
+            postRunCommands=postRunCommands)
 
         if expectFailure:
             return response
@@ -341,7 +343,7 @@ def build_and_launch(self, program, args=None, cwd=None, env=None,
                          stopCommands=None, exitCommands=None,
                          terminateCommands=None, sourcePath=None,
                          debuggerRoot=None, runInTerminal=False,
-                         disconnectAutomatically=True):
+                         disconnectAutomatically=True, postRunCommands=None):
         '''Build the default Makefile target, create the VSCode debug adaptor,
            and launch the process.
         '''
@@ -352,4 +354,5 @@ def build_and_launch(self, program, args=None, cwd=None, env=None,
                     disableSTDIO, shellExpandArguments, trace,
                     initCommands, preRunCommands, stopCommands, exitCommands,
                     terminateCommands, sourcePath, debuggerRoot, runInTerminal=runInTerminal,
-                    disconnectAutomatically=disconnectAutomatically)
+                    disconnectAutomatically=disconnectAutomatically,
+                    postRunCommands=postRunCommands)

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 926a63aeb239e..02e9b65e9afe2 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
@@ -494,7 +494,7 @@ def request_attach(self, program=None, pid=None, waitFor=None, trace=None,
                        initCommands=None, preRunCommands=None,
                        stopCommands=None, exitCommands=None,
                        attachCommands=None, terminateCommands=None,
-                       coreFile=None):
+                       coreFile=None, postRunCommands=None):
         args_dict = {}
         if pid is not None:
             args_dict['pid'] = pid
@@ -519,6 +519,8 @@ def request_attach(self, program=None, pid=None, waitFor=None, trace=None,
             args_dict['attachCommands'] = attachCommands
         if coreFile:
             args_dict['coreFile'] = coreFile
+        if postRunCommands:
+            args_dict['postRunCommands'] = postRunCommands
         command_dict = {
             'command': 'attach',
             'type': 'request',
@@ -621,7 +623,8 @@ def request_launch(self, program, args=None, cwd=None, env=None,
                        stopCommands=None, exitCommands=None,
                        terminateCommands=None ,sourcePath=None,
                        debuggerRoot=None, launchCommands=None, sourceMap=None,
-                       runInTerminal=False, expectFailure=False):
+                       runInTerminal=False, expectFailure=False,
+                       postRunCommands=None):
         args_dict = {
             'program': program
         }
@@ -662,6 +665,8 @@ def request_launch(self, program, args=None, cwd=None, env=None,
             args_dict['sourceMap'] = sourceMap
         if runInTerminal:
             args_dict['runInTerminal'] = runInTerminal
+        if postRunCommands:
+            args_dict['postRunCommands'] = postRunCommands
         command_dict = {
             'command': 'launch',
             'type': 'request',

diff  --git a/lldb/test/API/tools/lldb-vscode/attach/TestVSCode_attach.py b/lldb/test/API/tools/lldb-vscode/attach/TestVSCode_attach.py
index aa7a3ae17cb0d..211d1f74ec439 100644
--- a/lldb/test/API/tools/lldb-vscode/attach/TestVSCode_attach.py
+++ b/lldb/test/API/tools/lldb-vscode/attach/TestVSCode_attach.py
@@ -149,6 +149,7 @@ def test_commands(self):
         ]
         initCommands = ['target list', 'platform list']
         preRunCommands = ['image list a.out', 'image dump sections a.out']
+        postRunCommands = ['help trace', 'help process trace']
         stopCommands = ['frame variable', 'bt']
         exitCommands = ['expr 2+3', 'expr 3+4']
         terminateCommands = ['expr 4+2']
@@ -158,7 +159,8 @@ def test_commands(self):
                     preRunCommands=preRunCommands,
                     stopCommands=stopCommands,
                     exitCommands=exitCommands,
-                    terminateCommands=terminateCommands)
+                    terminateCommands=terminateCommands,
+                    postRunCommands=postRunCommands)
         # Get output from the console. This should contain both the
         # "initCommands" and the "preRunCommands".
         output = self.get_console()
@@ -166,6 +168,8 @@ def test_commands(self):
         self.verify_commands('initCommands', output, initCommands)
         # Verify all "preRunCommands" were found in console output
         self.verify_commands('preRunCommands', output, preRunCommands)
+        # Verify all "postRunCommands" were found in console output
+        self.verify_commands('postRunCommands', output, postRunCommands)
 
         functions = ['main']
         breakpoint_ids = self.set_function_breakpoints(functions)

diff  --git a/lldb/test/API/tools/lldb-vscode/launch/TestVSCode_launch.py b/lldb/test/API/tools/lldb-vscode/launch/TestVSCode_launch.py
index 1d99ecf87c4e0..6f65a7250f1e6 100644
--- a/lldb/test/API/tools/lldb-vscode/launch/TestVSCode_launch.py
+++ b/lldb/test/API/tools/lldb-vscode/launch/TestVSCode_launch.py
@@ -313,12 +313,14 @@ def test_commands(self):
         program = self.getBuildArtifact("a.out")
         initCommands = ['target list', 'platform list']
         preRunCommands = ['image list a.out', 'image dump sections a.out']
+        postRunCommands = ['help trace', 'help process trace']
         stopCommands = ['frame variable', 'bt']
         exitCommands = ['expr 2+3', 'expr 3+4']
         terminateCommands = ['expr 4+2']
         self.build_and_launch(program,
                               initCommands=initCommands,
                               preRunCommands=preRunCommands,
+                              postRunCommands=postRunCommands,
                               stopCommands=stopCommands,
                               exitCommands=exitCommands,
                               terminateCommands=terminateCommands)
@@ -330,6 +332,8 @@ def test_commands(self):
         self.verify_commands('initCommands', output, initCommands)
         # Verify all "preRunCommands" were found in console output
         self.verify_commands('preRunCommands', output, preRunCommands)
+        # Verify all "postRunCommands" were found in console output
+        self.verify_commands('postRunCommands', output, postRunCommands)
 
         source = 'main.c'
         first_line = line_number(source, '// breakpoint 1')

diff  --git a/lldb/tools/lldb-vscode/lldb-vscode.cpp b/lldb/tools/lldb-vscode/lldb-vscode.cpp
index fa623d25834f9..fd502db64c8b6 100644
--- a/lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ b/lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -570,6 +570,8 @@ void request_attach(const llvm::json::Object &request) {
   llvm::StringRef core_file = GetString(arguments, "coreFile");
   g_vsc.stop_at_entry =
       core_file.empty() ? GetBoolean(arguments, "stopOnEntry", false) : true;
+  std::vector<std::string> postRunCommands =
+      GetStrings(arguments, "postRunCommands");
   const llvm::StringRef debuggerRoot = GetString(arguments, "debuggerRoot");
 
   // This is a hack for loading DWARF in .o files on Mac where the .o files
@@ -638,12 +640,14 @@ void request_attach(const llvm::json::Object &request) {
   if (error.Fail()) {
     response["success"] = llvm::json::Value(false);
     EmplaceSafeString(response, "message", std::string(error.GetCString()));
+  } else {
+    g_vsc.RunLLDBCommands("Running postRunCommands:", postRunCommands);
   }
+
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
   if (error.Success()) {
     SendProcessEvent(Attach);
     g_vsc.SendJSON(CreateEventObject("initialized"));
-    // SendThreadStoppedEvent();
   }
 }
 
@@ -1608,6 +1612,8 @@ void request_launch(const llvm::json::Object &request) {
   g_vsc.exit_commands = GetStrings(arguments, "exitCommands");
   g_vsc.terminate_commands = GetStrings(arguments, "terminateCommands");
   auto launchCommands = GetStrings(arguments, "launchCommands");
+  std::vector<std::string> postRunCommands =
+      GetStrings(arguments, "postRunCommands");
   g_vsc.stop_at_entry = GetBoolean(arguments, "stopOnEntry", false);
   const llvm::StringRef debuggerRoot = GetString(arguments, "debuggerRoot");
 
@@ -1689,7 +1695,10 @@ void request_launch(const llvm::json::Object &request) {
   if (error.Fail()) {
     response["success"] = llvm::json::Value(false);
     EmplaceSafeString(response, "message", std::string(error.GetCString()));
+  } else {
+    g_vsc.RunLLDBCommands("Running postRunCommands:", postRunCommands);
   }
+
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
 
   if (g_vsc.is_attach)

diff  --git a/lldb/tools/lldb-vscode/package.json b/lldb/tools/lldb-vscode/package.json
index 9077ab51dd7fa..68e1be210f65a 100644
--- a/lldb/tools/lldb-vscode/package.json
+++ b/lldb/tools/lldb-vscode/package.json
@@ -161,6 +161,11 @@
 								"description": "Commands executed just before the program is launched.",
 								"default": []
 							},
+							"postRunCommands": {
+								"type": "array",
+								"description": "Commands executed just as soon as the program is successfully launched when it's in a stopped state prior to any automatic continuation.",
+								"default": []
+							},
 							"launchCommands": {
 								"type": "array",
 								"description": "Custom commands that are executed instead of launching a process. A target will be created with the launch arguments prior to executing these commands. The commands may optionally create a new target and must perform a launch. A valid process must exist after these commands complete or the \"launch\" will fail.",
@@ -237,6 +242,11 @@
 								"description": "Commands executed just before the program is attached to.",
 								"default": []
 							},
+							"postRunCommands": {
+								"type": "array",
+								"description": "Commands executed just as soon as the program is successfully attached when it's in a stopped state prior to any automatic continuation.",
+								"default": []
+							},
 							"stopCommands": {
 								"type": "array",
 								"description": "Commands executed each time the program stops.",


        


More information about the lldb-commits mailing list