[Lldb-commits] [lldb] cd7b450 - [lldb/API] Make Launch(Simple) use args and env from target properties

Fred Riss via lldb-commits lldb-commits at lists.llvm.org
Mon Mar 23 07:59:06 PDT 2020


Author: Fred Riss
Date: 2020-03-23T07:58:33-07:00
New Revision: cd7b45057ca9bc72b99a0abc6c9be25e0f72fbcf

URL: https://github.com/llvm/llvm-project/commit/cd7b45057ca9bc72b99a0abc6c9be25e0f72fbcf
DIFF: https://github.com/llvm/llvm-project/commit/cd7b45057ca9bc72b99a0abc6c9be25e0f72fbcf.diff

LOG: [lldb/API] Make Launch(Simple) use args and env from target properties

Summary:
When no arguments or environment is provided to SBTarget::LaunchSimple,
make it use the values surrently set in the target properties. You can
get the current behavior back by passing an empty array instead.

It seems like using the target defaults is a much more intuitive
behavior for those APIs. It's unllikely that anyone passed NULL/None to
this API after having set properties in order to explicitely ignore them.

One direct application of this change is within the testsuite. We have
plenty of tests calling LaunchSimple and passing None as environment.
If you passed --inferior-env to dotest.py to, for example, set
(DY)LD_LIBRARY_PATH, it wouldn't be taken into account.

Reviewers: jingham, labath, #libc_abi!

Subscribers: libcxx-commits, lldb-commits

Tags: #lldb, #libc_abi

Differential Revision: https://reviews.llvm.org/D76045

Added: 
    

Modified: 
    lldb/include/lldb/API/SBTarget.h
    lldb/source/API/SBTarget.cpp
    lldb/test/API/commands/settings/TestSettings.py

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index a50e791d4fe3..1db54279fcb5 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -127,7 +127,9 @@ class LLDB_API SBTarget {
   ///     The argument array.
   ///
   /// \param[in] envp
-  ///     The environment array.
+  ///     The environment array. If this is null, the default
+  ///     environment values (provided through `settings set
+  ///     target.env-vars`) will be used.
   ///
   /// \param[in] stdin_path
   ///     The path to use when re-directing the STDIN of the new
@@ -175,7 +177,9 @@ class LLDB_API SBTarget {
   ///     The argument array.
   ///
   /// \param[in] envp
-  ///     The environment array.
+  ///     The environment array. If this isn't provided, the default
+  ///     environment values (provided through `settings set
+  ///     target.env-vars`) will be used.
   ///
   /// \param[in] working_directory
   ///     The working directory to have the child process run in

diff  --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index b90e77280d24..a70f54135e02 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -371,10 +371,19 @@ SBProcess SBTarget::Launch(SBListener &listener, char const **argv,
     Module *exe_module = target_sp->GetExecutableModulePointer();
     if (exe_module)
       launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
-    if (argv)
+    if (argv) {
       launch_info.GetArguments().AppendArguments(argv);
-    if (envp)
+    } else {
+      auto default_launch_info = target_sp->GetProcessLaunchInfo();
+      launch_info.GetArguments().AppendArguments(
+          default_launch_info.GetArguments());
+    }
+    if (envp) {
       launch_info.GetEnvironment() = Environment(envp);
+    } else {
+      auto default_launch_info = target_sp->GetProcessLaunchInfo();
+      launch_info.GetEnvironment() = default_launch_info.GetEnvironment();
+    }
 
     if (listener.IsValid())
       launch_info.SetListener(listener.GetSP());

diff  --git a/lldb/test/API/commands/settings/TestSettings.py b/lldb/test/API/commands/settings/TestSettings.py
index 6ec59bbe7a09..b203f85de9fb 100644
--- a/lldb/test/API/commands/settings/TestSettings.py
+++ b/lldb/test/API/commands/settings/TestSettings.py
@@ -204,10 +204,15 @@ def test_disassembler_settings(self):
 
     @skipIfDarwinEmbedded   # <rdar://problem/34446098> debugserver on ios etc can't write files
     def test_run_args_and_env_vars(self):
+        self.do_test_run_args_and_env_vars(use_launchsimple=False)
+
+    @skipIfDarwinEmbedded   # <rdar://problem/34446098> debugserver on ios etc can't write files
+    def test_launchsimple_args_and_env_vars(self):
+        self.do_test_run_args_and_env_vars(use_launchsimple=True)
+
+    def do_test_run_args_and_env_vars(self, use_launchsimple):
         """Test that run-args and env-vars are passed to the launched process."""
         self.build()
-        exe = self.getBuildArtifact("a.out")
-        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
 
         # Set the run-args and the env-vars.
         # And add hooks to restore the settings during tearDown().
@@ -218,7 +223,11 @@ def test_run_args_and_env_vars(self):
         self.addTearDownHook(
             lambda: self.runCmd("settings clear target.env-vars"))
 
-        launch_info = self.dbg.GetTargetAtIndex(0).GetLaunchInfo()
+        exe = self.getBuildArtifact("a.out")
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        target = self.dbg.GetTargetAtIndex(0)
+        launch_info = target.GetLaunchInfo()
         found_env_var = False
         for i in range(0, launch_info.GetNumEnvironmentEntries()):
             if launch_info.GetEnvironmentEntryAtIndex(i) == "MY_ENV_VAR=YES":
@@ -227,7 +236,12 @@ def test_run_args_and_env_vars(self):
         self.assertTrue(found_env_var,
                         "MY_ENV_VAR was not set in LunchInfo object")
 
-        self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()),
+        wd = self.get_process_working_directory()
+        if use_launchsimple:
+            process = target.LaunchSimple(None, None, wd)
+            self.assertTrue(process)
+        else:
+            self.runCmd("process launch --working-dir '{0}'".format(wd),
                 RUN_SUCCEEDED)
 
         # Read the output file produced by running the program.


        


More information about the lldb-commits mailing list