From 39687ff8d7330776fe473550f18b8a8d638ab08a Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 13 May 2019 19:17:48 +0000 Subject: [PATCH] Merge target and launch info environments Before this change we were overriding the launch info environment with the target environment. This meant that the environment variables passed to `process launch --environment <>` were lost. Instead of replacing the environment, we should merge them. Differential revision: https://reviews.llvm.org/D61864 llvm-svn: 360612 --- lldb/lit/Process/Inputs/env.cpp | 7 +++++++ lldb/lit/Process/TestEnvironment.test | 7 +++++++ lldb/source/Commands/CommandObjectProcess.cpp | 5 ++++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 lldb/lit/Process/Inputs/env.cpp create mode 100644 lldb/lit/Process/TestEnvironment.test diff --git a/lldb/lit/Process/Inputs/env.cpp b/lldb/lit/Process/Inputs/env.cpp new file mode 100644 index 0000000000000..cbf671ccd2f50 --- /dev/null +++ b/lldb/lit/Process/Inputs/env.cpp @@ -0,0 +1,7 @@ +#include +#include + +int main() { + if (const char *env_p = std::getenv("FOO")) + std::cout << "FOO=" << env_p << '\n'; +} diff --git a/lldb/lit/Process/TestEnvironment.test b/lldb/lit/Process/TestEnvironment.test new file mode 100644 index 0000000000000..8bbf8767f33fa --- /dev/null +++ b/lldb/lit/Process/TestEnvironment.test @@ -0,0 +1,7 @@ +The double quotes around "BAR" ensure we don't match the command. + +RUN: %clangxx -std=c++11 %p/Inputs/env.cpp -o %t +RUN: %lldb %t -o 'process launch --environment FOO="BAR"' | FileCheck %s +RUN: %lldb %t -o 'env FOO="BAR"' -o 'process launch' | FileCheck %s + +CHECK: FOO=BAR diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 1cc0b0b43c78a..b20a2d5333327 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -193,7 +193,10 @@ class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach { if (target->GetDisableSTDIO()) m_options.launch_info.GetFlags().Set(eLaunchFlagDisableSTDIO); - m_options.launch_info.GetEnvironment() = target->GetEnvironment(); + // Merge the launch info environment with the target environment. + Environment target_env = target->GetEnvironment(); + m_options.launch_info.GetEnvironment().insert(target_env.begin(), + target_env.end()); if (!target_settings_argv0.empty()) { m_options.launch_info.GetArguments().AppendArgument(