diazhector98 updated this revision to Diff 244719.
diazhector98 added a comment.

- Merge branch 'master' of https://github.com/llvm/llvm-project


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74579

Files:
  
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/environmentVariables/Makefile
  
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/environmentVariables/TestVSCode_environmentVariables.py
  
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/environmentVariables/main.cpp
  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/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
@@ -84,6 +84,11 @@
 								"description": "Additional environment variables.",
 								"default": []
 							},
+							"inheritEnvironment": {
+								"type": "boolean",
+								"description": "Inherit the VSCode Environment Variables",
+								"default": false
+							},
 							"stopOnEntry": {
 								"type": "boolean",
 								"description": "Automatically stop after launch.",
Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===================================================================
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -49,6 +49,8 @@
 #include "LLDBUtils.h"
 #include "VSCode.h"
 
+extern char **environ;
+
 #if defined(_WIN32)
 #ifndef PATH_MAX
 #define PATH_MAX MAX_PATH
@@ -1327,6 +1329,7 @@
   auto launchCommands = GetStrings(arguments, "launchCommands");
   g_vsc.stop_at_entry = GetBoolean(arguments, "stopOnEntry", false);
   const auto debuggerRoot = GetString(arguments, "debuggerRoot");
+  bool launchWithDebuggerEnvironment = GetBoolean(arguments, "inheritEnvironment", false);
 
   // This is a hack for loading DWARF in .o files on Mac where the .o files
   // in the debug map of the main executable have relative paths which require
@@ -1364,13 +1367,24 @@
   // Extract any extra arguments and append them to our program arguments for
   // when we launch
   auto args = GetStrings(arguments, "args");
-  if (!args.empty())
+  if (!args.empty()) 
     g_vsc.launch_info.SetArguments(MakeArgv(args).data(), true);
 
   // Pass any environment variables along that the user specified.
   auto envs = GetStrings(arguments, "env");
-  if (!envs.empty())
+
+  if (launchWithDebuggerEnvironment) {
+    char** env_var_pointer = environ;
+    std::vector<std::string> vscode_env_variables;
+    for (char* env_variable = *env_var_pointer; env_variable; env_variable=*++env_var_pointer){
+      vscode_env_variables.push_back(env_variable);
+    }
+    envs.insert(std::end(envs), std::begin(vscode_env_variables), std::end(vscode_env_variables));
+  } 
+
+  if (!envs.empty()) {
     g_vsc.launch_info.SetEnvironmentEntries(MakeArgv(envs).data(), true);
+  }
 
   auto flags = g_vsc.launch_info.GetLaunchFlags();
 
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
@@ -570,7 +570,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, inheritEnvironment=False):
         args_dict = {
             'program': program
         }
@@ -605,6 +605,8 @@
             args_dict['debuggerRoot'] = debuggerRoot
         if launchCommands:
             args_dict['launchCommands'] = launchCommands
+        if inheritEnvironment:
+            args_dict['inheritEnvironment'] = inheritEnvironment
         command_dict = {
             'command': 'launch',
             'type': 'request',
@@ -912,7 +914,9 @@
                                       initCommands=options.initCmds,
                                       preRunCommands=options.preRunCmds,
                                       stopCommands=options.stopCmds,
-                                      exitCommands=options.exitCmds)
+                                      exitCommands=options.exitCmds
+                                      inheritEnvironment=options.inheritEnvironment
+                                      )
 
     if response['success']:
         if options.sourceBreakpoints:
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
@@ -267,7 +267,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, inheritEnvironment=False):
         '''Sending launch request to vscode
         '''
 
@@ -298,7 +298,9 @@
             exitCommands=exitCommands,
             sourcePath=sourcePath,
             debuggerRoot=debuggerRoot,
-            launchCommands=launchCommands)
+            launchCommands=launchCommands,
+            inheritEnvironment=inheritEnvironment
+            )
         if not (response and response['success']):
             self.assertTrue(response['success'],
                             'launch failed (%s)' % (response['message']))
@@ -308,14 +310,13 @@
                          disableSTDIO=False, shellExpandArguments=False,
                          trace=False, initCommands=None, preRunCommands=None,
                          stopCommands=None, exitCommands=None,
-                         sourcePath=None, debuggerRoot=None):
+                         sourcePath=None, debuggerRoot=None, inheritEnvironment=False):
         '''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)
+                    sourcePath, debuggerRoot, inheritEnvironment=inheritEnvironment)
Index: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/environmentVariables/main.cpp
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/environmentVariables/main.cpp
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+extern char **environ;
+
+int main(int argc, char const *argv[], char const *envp[]) {
+    char** env_var_pointer = environ;
+    // std::vector<std::string> vscode_env_variables;
+    int count = 0;
+    for (char* env_variable = *env_var_pointer; env_variable; env_variable=*++env_var_pointer) {
+        printf("%s\n", env_variable);
+        count++;
+    }
+    return 0; // breakpoint 1
+}
Index: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/environmentVariables/TestVSCode_environmentVariables.py
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/environmentVariables/TestVSCode_environmentVariables.py
@@ -0,0 +1,36 @@
+"""
+Test lldb-vscode completions request
+"""
+
+
+import lldbvscode_testcase
+import unittest2
+import vscode
+from lldbsuite.test import lldbutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+import os
+
+
+class TestVSCode_variables(lldbvscode_testcase.VSCodeTestCaseBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @skipIfWindows
+    #@skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
+    def test_environment_variable(self):
+        """
+            Tests the completion request at different breakpoints
+        """
+        program = self.getBuildArtifact("a.out")
+        path_env_variable = 'PATH='+os.environ['PATH']
+        self.build_and_launch(program, inheritEnvironment=False)
+        self.continue_to_exit()
+        output = self.get_stdout().encode('utf-8')
+        lines = output.splitlines()
+        found = False
+        for line in lines:
+            if line.startswith('PATH='):
+                found = True
+                self.assertTrue(path_env_variable == line, "PATH environment variable not the same")
+        self.assertTrue(found, 'PATH environment variable not found')
\ No newline at end of file
Index: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/environmentVariables/Makefile
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/environmentVariables/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] ... Héctor Luis Díaz Aceves via Phabricator via lldb-commits
    • [Lldb-comm... Héctor Luis Díaz Aceves via Phabricator via lldb-commits
    • [Lldb-comm... Héctor Luis Díaz Aceves via Phabricator via lldb-commits
    • [Lldb-comm... walter erquinigo via Phabricator via lldb-commits
    • [Lldb-comm... Héctor Luis Díaz Aceves via Phabricator via lldb-commits
    • [Lldb-comm... walter erquinigo via Phabricator via lldb-commits
    • [Lldb-comm... Héctor Luis Díaz Aceves via Phabricator via lldb-commits
    • [Lldb-comm... Héctor Luis Díaz Aceves via Phabricator via lldb-commits
    • [Lldb-comm... Héctor Luis Díaz Aceves via Phabricator via lldb-commits
    • [Lldb-comm... Héctor Luis Díaz Aceves via Phabricator via lldb-commits

Reply via email to