[Lldb-commits] [lldb] r360612 - Merge target and launch info environments
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Mon May 13 12:17:48 PDT 2019
Author: jdevlieghere
Date: Mon May 13 12:17:48 2019
New Revision: 360612
URL: http://llvm.org/viewvc/llvm-project?rev=360612&view=rev
Log:
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
Added:
lldb/trunk/lit/Process/Inputs/
lldb/trunk/lit/Process/Inputs/env.cpp
lldb/trunk/lit/Process/TestEnvironment.test
Modified:
lldb/trunk/source/Commands/CommandObjectProcess.cpp
Added: lldb/trunk/lit/Process/Inputs/env.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Process/Inputs/env.cpp?rev=360612&view=auto
==============================================================================
--- lldb/trunk/lit/Process/Inputs/env.cpp (added)
+++ lldb/trunk/lit/Process/Inputs/env.cpp Mon May 13 12:17:48 2019
@@ -0,0 +1,7 @@
+#include <cstdlib>
+#include <iostream>
+
+int main() {
+ if (const char *env_p = std::getenv("FOO"))
+ std::cout << "FOO=" << env_p << '\n';
+}
Added: lldb/trunk/lit/Process/TestEnvironment.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Process/TestEnvironment.test?rev=360612&view=auto
==============================================================================
--- lldb/trunk/lit/Process/TestEnvironment.test (added)
+++ lldb/trunk/lit/Process/TestEnvironment.test Mon May 13 12:17:48 2019
@@ -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
Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=360612&r1=360611&r2=360612&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Mon May 13 12:17:48 2019
@@ -193,7 +193,10 @@ protected:
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(
More information about the lldb-commits
mailing list