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 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py +++ b/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,8 @@ 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,7 +309,7 @@ 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. ''' @@ -318,4 +319,4 @@ self.launch(program, args, cwd, env, stopOnEntry, disableASLR, disableSTDIO, shellExpandArguments, trace, initCommands, preRunCommands, stopCommands, exitCommands, - sourcePath, debuggerRoot) + sourcePath, debuggerRoot, inheritEnvironment=inheritEnvironment) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py +++ b/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,8 @@ initCommands=options.initCmds, preRunCommands=options.preRunCmds, stopCommands=options.stopCmds, - exitCommands=options.exitCmds) + exitCommands=options.exitCmds + inheritEnvironment=options.inheritEnvironment) if response['success']: if options.sourceBreakpoints: diff --git a/lldb/test/API/tools/lldb-vscode/environmentVariables/TestVSCode_environmentVariables.py b/lldb/test/API/tools/lldb-vscode/environmentVariables/TestVSCode_environmentVariables.py new file mode 100644 --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/environmentVariables/TestVSCode_environmentVariables.py @@ -0,0 +1,33 @@ +""" +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 * + +class TestVSCode_variables(lldbvscode_testcase.VSCodeTestCaseBase): + + @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 environment variables + """ + 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 diff --git a/lldb/test/API/tools/lldb-vscode/environmentVariables/main.cpp b/lldb/test/API/tools/lldb-vscode/environmentVariables/main.cpp new file mode 100644 --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/environmentVariables/main.cpp @@ -0,0 +1,14 @@ +#include +#include +#include +#include + +extern char **environ; + +int main(int argc, char const *argv[], char const *envp[]) { + char** env_var_pointer = environ; + for (char* env_variable = *env_var_pointer; env_variable; env_variable=*++env_var_pointer) { + printf("%s\n", env_variable); + } + return 0; +} \ No newline at end of file diff --git a/lldb/tools/lldb-vscode/package.json b/lldb/tools/lldb-vscode/package.json --- a/lldb/tools/lldb-vscode/package.json +++ b/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.",