Skip to content

Commit

Permalink
Merge target and launch info environments
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JDevlieghere authored and MrSidims committed May 24, 2019
1 parent c6105b7 commit 4b3bc2c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lldb/lit/Process/Inputs/env.cpp
@@ -0,0 +1,7 @@
#include <cstdlib>
#include <iostream>

int main() {
if (const char *env_p = std::getenv("FOO"))
std::cout << "FOO=" << env_p << '\n';
}
7 changes: 7 additions & 0 deletions 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
5 changes: 4 additions & 1 deletion lldb/source/Commands/CommandObjectProcess.cpp
Expand Up @@ -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(
Expand Down

0 comments on commit 4b3bc2c

Please sign in to comment.