[Lldb-commits] [PATCH] D83306: [lldb/API] Overwrite variables with SBLaunchInfo::SetEnvironment(append=true)

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Jul 8 04:51:06 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG695b33a56919: [lldb/API] Overwrite variables with SBLaunchInfo::SetEnvironment(append=true) (authored by labath).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83306/new/

https://reviews.llvm.org/D83306

Files:
  lldb/source/API/SBLaunchInfo.cpp
  lldb/test/API/python_api/sbenvironment/TestSBEnvironment.py


Index: lldb/test/API/python_api/sbenvironment/TestSBEnvironment.py
===================================================================
--- lldb/test/API/python_api/sbenvironment/TestSBEnvironment.py
+++ lldb/test/API/python_api/sbenvironment/TestSBEnvironment.py
@@ -53,6 +53,11 @@
         launch_info.SetEnvironment(env, append=True)
         self.assertEqual(launch_info.GetEnvironment().GetNumValues(), env_count + 1)
 
+        env.Set("FOO", "baz", overwrite=True)
+        launch_info.SetEnvironment(env, append=True)
+        self.assertEqual(launch_info.GetEnvironment().GetNumValues(), env_count + 1)
+        self.assertEqual(launch_info.GetEnvironment().Get("FOO"), "baz")
+
         # Make sure we can replace the launchInfo's environment
         env.Clear()
         env.Set("BAR", "foo", overwrite=True)
@@ -120,6 +125,11 @@
         env.SetEntries(entries, append=False)
         self.assertEqualEntries(env, ["X=x", "Y=y"])
 
+        entries.Clear()
+        entries.AppendList(["X=y", "Y=x"], 2)
+        env.SetEntries(entries, append=True)
+        self.assertEqualEntries(env, ["X=y", "Y=x"])
+
         # Test clear
         env.Clear()
         self.assertEqualEntries(env, [])
Index: lldb/source/API/SBLaunchInfo.cpp
===================================================================
--- lldb/source/API/SBLaunchInfo.cpp
+++ lldb/source/API/SBLaunchInfo.cpp
@@ -190,9 +190,10 @@
   LLDB_RECORD_METHOD(void, SBLaunchInfo, SetEnvironment,
                      (const lldb::SBEnvironment &, bool), env, append);
   Environment &refEnv = env.ref();
-  if (append)
-    m_opaque_sp->GetEnvironment().insert(refEnv.begin(), refEnv.end());
-  else
+  if (append) {
+    for (auto &KV : refEnv)
+      m_opaque_sp->GetEnvironment().insert_or_assign(KV.first(), KV.second);
+  } else
     m_opaque_sp->GetEnvironment() = refEnv;
   m_opaque_sp->RegenerateEnvp();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83306.276378.patch
Type: text/x-patch
Size: 1885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200708/12ce691c/attachment.bin>


More information about the lldb-commits mailing list