Skip to content

Commit 0ec88d0

Browse files
committed
[lldb] Inherit host environment when running shell commands
Summary: On most hosts we were running shell commands with an empty environment. The only exception was windows, which was inheriting the host enviroment mostly by accident. Running the commands in an empty environment does not sound like a sensible default, so this patch changes Host::RunShellCommand to inherit the host environment. This impacts both commands run via SBPlatform::Run (in case of host platforms), as well as the "platform shell" CLI command. Reviewers: jingham, friss Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D77123
1 parent 9be4be3 commit 0ec88d0

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

lldb/source/Host/common/Host.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ Status Host::RunShellCommand(const Args &args, const FileSpec &working_dir,
501501
launch_info.SetArguments(args, first_arg_is_executable);
502502
}
503503

504+
launch_info.GetEnvironment() = Host::GetEnvironment();
505+
504506
if (working_dir)
505507
launch_info.SetWorkingDirectory(working_dir);
506508
llvm::SmallString<64> output_file_path;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Test the SBPlatform APIs."""
2+
3+
from lldbsuite.test.decorators import *
4+
from lldbsuite.test.lldbtest import *
5+
6+
class SBPlatformAPICase(TestBase):
7+
8+
mydir = TestBase.compute_mydir(__file__)
9+
NO_DEBUG_INFO_TESTCASE = True
10+
11+
@add_test_categories(['pyapi'])
12+
def test_run(self):
13+
self.build()
14+
plat = lldb.SBPlatform.GetHostPlatform()
15+
16+
os.environ["MY_TEST_ENV_VAR"]="SBPlatformAPICase.test_run"
17+
def cleanup():
18+
del os.environ["MY_TEST_ENV_VAR"]
19+
self.addTearDownHook(cleanup)
20+
cmd = lldb.SBPlatformShellCommand(self.getBuildArtifact("a.out"))
21+
self.assertTrue(plat.Run(cmd).Success())
22+
self.assertIn("MY_TEST_ENV_VAR=SBPlatformAPICase.test_run", cmd.GetOutput())
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <cstdlib>
2+
#include <cstdio>
3+
4+
int main() {
5+
printf("MY_TEST_ENV_VAR=%s\n", getenv("MY_TEST_ENV_VAR"));
6+
7+
return 0;
8+
}

0 commit comments

Comments
 (0)