puremourning created this revision.
puremourning added a reviewer: clayborg.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

When testing terminal-mode applications using lldb-vscode on macOS, it's
currently required to set LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY when starting
lldb-vscode so that the application launches in a new Terminal.app
window. This is unlikely to work for VSCode as there's no obvious way to
set it.

vscode-cpptools uses `externalConsole: true` to enable this behaviour,
so we implement the same here .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72152

Files:
  
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/launch/TestVSCode_launch.py
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
  lldb/tools/lldb-vscode/README.md
  lldb/tools/lldb-vscode/lldb-vscode.cpp
  lldb/tools/lldb-vscode/package.json

Index: lldb/tools/lldb-vscode/package.json
===================================================================
--- lldb/tools/lldb-vscode/package.json
+++ lldb/tools/lldb-vscode/package.json
@@ -89,6 +89,11 @@
 								"description": "Automatically stop after launch.",
 								"default": false
 							},
+							"externalConsole": {
+								"type": "boolean",
+								"description": "Launch the program in a new terminal",
+								"default": false
+							},
 							"disableASLR": {
 								"type": "boolean",
 								"description": "Enable or disable Address space layout randomization if the debugger supports it.",
Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===================================================================
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1395,6 +1395,8 @@
     flags |= lldb::eLaunchFlagDisableSTDIO;
   if (GetBoolean(arguments, "shellExpandArguments", false))
     flags |= lldb::eLaunchFlagShellExpandArguments;
+  if (GetBoolean(arguments, "externalConsole", false ))
+    flags |= lldb::eLaunchFlagLaunchInTTY | lldb::eLaunchFlagCloseTTYOnExit;
   const bool detatchOnError = GetBoolean(arguments, "detachOnError", false);
   g_vsc.launch_info.SetDetachOnError(detatchOnError);
   g_vsc.launch_info.SetLaunchFlags(flags | lldb::eLaunchFlagDebug |
Index: lldb/tools/lldb-vscode/README.md
===================================================================
--- lldb/tools/lldb-vscode/README.md
+++ lldb/tools/lldb-vscode/README.md
@@ -88,6 +88,7 @@
 |**exitCommands**   |[string]| | LLDB commands executed when the program exits. Commands and command output will be sent to the debugger console when they are executed.
 |**sourceMap**      |[string[2]]| | Specify an array of path re-mappings. Each element in the array must be a two element array containing a source and destination pathname.
 |**debuggerRoot**   | string| |Specify a working directory to use when launching lldb-vscode. If the debug information in your executable contains relative paths, this option can be used so that `lldb-vscode` can find source files and object files that have relative paths.
+| **externalConsole** |boolean| | Set to TRUE to start the application in a new terminal. Useful for testing console applications.
 
 ## Attaching Settings
 
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
@@ -562,7 +562,7 @@
                        disableSTDIO=False, shellExpandArguments=False,
                        trace=False, initCommands=None, preRunCommands=None,
                        stopCommands=None, exitCommands=None, sourcePath=None,
-                       debuggerRoot=None, launchCommands=None):
+                       debuggerRoot=None, launchCommands=None, **kwargs):
         args_dict = {
             'program': program
         }
@@ -597,6 +597,8 @@
             args_dict['debuggerRoot'] = debuggerRoot
         if launchCommands:
             args_dict['launchCommands'] = launchCommands
+        args_dict.update(kwargs)
+
         command_dict = {
             'command': 'launch',
             'type': 'request',
Index: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
@@ -265,7 +265,7 @@
                disableSTDIO=False, shellExpandArguments=False,
                trace=False, initCommands=None, preRunCommands=None,
                stopCommands=None, exitCommands=None,sourcePath= None,
-               debuggerRoot=None, launchCommands=None):
+               debuggerRoot=None, launchCommands=None, **kwargs):
         '''Sending launch request to vscode
         '''
 
@@ -296,7 +296,8 @@
             exitCommands=exitCommands,
             sourcePath=sourcePath,
             debuggerRoot=debuggerRoot,
-            launchCommands=launchCommands)
+            launchCommands=launchCommands,
+            **kwargs)
         if not (response and response['success']):
             self.assertTrue(response['success'],
                             'launch failed (%s)' % (response['message']))
@@ -306,7 +307,8 @@
                          disableSTDIO=False, shellExpandArguments=False,
                          trace=False, initCommands=None, preRunCommands=None,
                          stopCommands=None, exitCommands=None,
-                         sourcePath=None, debuggerRoot=None):
+                         sourcePath=None, debuggerRoot=None,
+                         **kwargs):
         '''Build the default Makefile target, create the VSCode debug adaptor,
            and launch the process.
         '''
@@ -316,4 +318,4 @@
         self.launch(program, args, cwd, env, stopOnEntry, disableASLR,
                     disableSTDIO, shellExpandArguments, trace,
                     initCommands, preRunCommands, stopCommands, exitCommands,
-                    sourcePath, debuggerRoot)
+                    sourcePath, debuggerRoot, **kwargs)
Index: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/launch/TestVSCode_launch.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/launch/TestVSCode_launch.py
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/launch/TestVSCode_launch.py
@@ -17,7 +17,6 @@
     mydir = TestBase.compute_mydir(__file__)
 
     @skipIfWindows
-    @skipIfDarwin # Flaky
     def test_default(self):
         '''
             Tests the default launch of a simple program. No arguments,
@@ -53,6 +52,19 @@
                         reason != 'breakpoint',
                         'verify stop isn\'t "main" breakpoint')
 
+    @skipIfWindows
+    def test_externalConsole(self):
+        '''
+            Tests the default launch of a simple program that launches in a
+            new TTY.
+        '''
+        program = self.getBuildArtifact("a.out")
+        self.build_and_launch(program, externalConsole=True)
+        self.continue_to_exit()
+        # Now get the STDOUT and verify we connected it to another TTY
+        output = self.get_stdout()
+        self.assertEqual(output, None, "Program output goes TTY")
+
     @skipIfWindows
     def test_cwd(self):
         '''
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to