JDevlieghere created this revision.
JDevlieghere added reviewers: labath, aprantl, davide.
Herald added a project: LLDB.

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.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D61864

Files:
  lldb/lit/Process/TestEnvironment.test
  lldb/source/Commands/CommandObjectProcess.cpp


Index: lldb/source/Commands/CommandObjectProcess.cpp
===================================================================
--- lldb/source/Commands/CommandObjectProcess.cpp
+++ lldb/source/Commands/CommandObjectProcess.cpp
@@ -193,7 +193,10 @@
     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(
Index: lldb/lit/Process/TestEnvironment.test
===================================================================
--- /dev/null
+++ lldb/lit/Process/TestEnvironment.test
@@ -0,0 +1,8 @@
+UNSUPPORTED: system-windows
+
+The double quotes around "BAR" ensure we don't match the command.
+
+RUN: %lldb /usr/bin/env -o 'process launch --environment FOO="BAR"' | 
FileCheck %s
+RUN: %lldb /usr/bin/env -o 'env FOO="BAR"' -o 'process launch' | FileCheck %s
+
+CHECK: FOO=BAR


Index: lldb/source/Commands/CommandObjectProcess.cpp
===================================================================
--- lldb/source/Commands/CommandObjectProcess.cpp
+++ lldb/source/Commands/CommandObjectProcess.cpp
@@ -193,7 +193,10 @@
     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(
Index: lldb/lit/Process/TestEnvironment.test
===================================================================
--- /dev/null
+++ lldb/lit/Process/TestEnvironment.test
@@ -0,0 +1,8 @@
+UNSUPPORTED: system-windows
+
+The double quotes around "BAR" ensure we don't match the command.
+
+RUN: %lldb /usr/bin/env -o 'process launch --environment FOO="BAR"' | FileCheck %s
+RUN: %lldb /usr/bin/env -o 'env FOO="BAR"' -o 'process launch' | FileCheck %s
+
+CHECK: FOO=BAR
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH] ... Jonas Devlieghere via Phabricator via lldb-commits

Reply via email to