[Lldb-commits] [lldb] 882d8e6 - [lldb] Make SBTarget::LaunchSimple start form the target's LaunchInfo

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 5 10:08:35 PDT 2020


Author: Jonas Devlieghere
Date: 2020-08-05T10:08:28-07:00
New Revision: 882d8e60dd40c01c74b4e16b02cf7ca02e846434

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

LOG: [lldb] Make SBTarget::LaunchSimple start form the target's LaunchInfo

Currently SBTarget::LaunchSimple creates a new LaunchInfo which means it
ignores any target properties that have been set. Instead, it should
start from the target's LaunchInfo and populated the specified fields.

Differential revision: https://reviews.llvm.org/D85235

Added: 
    

Modified: 
    lldb/source/API/SBTarget.cpp
    lldb/test/API/python_api/target/TestTargetAPI.py
    lldb/test/API/python_api/target/main.c

Removed: 
    


################################################################################
diff  --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index b84e9f10fafe..04540a2fab43 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -287,16 +287,24 @@ SBProcess SBTarget::LaunchSimple(char const **argv, char const **envp,
                      (const char **, const char **, const char *), argv, envp,
                      working_directory);
 
-  char *stdin_path = nullptr;
-  char *stdout_path = nullptr;
-  char *stderr_path = nullptr;
-  uint32_t launch_flags = 0;
-  bool stop_at_entry = false;
+  TargetSP target_sp = GetSP();
+  if (!target_sp)
+    return LLDB_RECORD_RESULT(SBProcess());
+
+  SBLaunchInfo launch_info = GetLaunchInfo();
+
+  if (Module *exe_module = target_sp->GetExecutableModulePointer())
+    launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(),
+                                  /*add_as_first_arg*/ true);
+  if (argv)
+    launch_info.SetArguments(argv, /*append*/ true);
+  if (envp)
+    launch_info.SetEnvironmentEntries(envp, /*append*/ false);
+  if (working_directory)
+    launch_info.SetWorkingDirectory(working_directory);
+
   SBError error;
-  SBListener listener = GetDebugger().GetListener();
-  return LLDB_RECORD_RESULT(Launch(listener, argv, envp, stdin_path,
-                                   stdout_path, stderr_path, working_directory,
-                                   launch_flags, stop_at_entry, error));
+  return LLDB_RECORD_RESULT(Launch(launch_info, error));
 }
 
 SBError SBTarget::Install() {

diff  --git a/lldb/test/API/python_api/target/TestTargetAPI.py b/lldb/test/API/python_api/target/TestTargetAPI.py
index 016754720c8c..f6b349bd6a3d 100644
--- a/lldb/test/API/python_api/target/TestTargetAPI.py
+++ b/lldb/test/API/python_api/target/TestTargetAPI.py
@@ -150,6 +150,38 @@ def test_read_memory(self):
         self.assertTrue(error.Success(), "Make sure memory read succeeded")
         self.assertEqual(len(content), 1)
 
+
+    @add_test_categories(['pyapi'])
+    def test_launch_simple(self):
+        d = {'EXE': 'b.out'}
+        self.build(dictionary=d)
+        self.setTearDownCleanup(dictionary=d)
+        target = self.create_simple_target('b.out')
+
+        process = target.LaunchSimple(
+            ['foo', 'bar'], ['baz'], self.get_process_working_directory())
+        self.runCmd("run")
+        output = process.GetSTDOUT(9999)
+        self.assertIn('arg: foo', output)
+        self.assertIn('arg: bar', output)
+        self.assertIn('env: baz', output)
+
+        self.runCmd("setting set target.run-args foo")
+        self.runCmd("setting set target.env-vars bar=baz")
+        process = target.LaunchSimple(None, None,
+                                      self.get_process_working_directory())
+        self.runCmd("run")
+        output = process.GetSTDOUT(9999)
+        self.assertIn('arg: foo', output)
+        self.assertIn('env: bar=baz', output)
+
+        self.runCmd("settings set target.disable-stdio true")
+        process = target.LaunchSimple(
+            None, None, self.get_process_working_directory())
+        self.runCmd("run")
+        output = process.GetSTDOUT(9999)
+        self.assertEqual(output, "")
+
     def create_simple_target(self, fn):
         exe = self.getBuildArtifact(fn)
         target = self.dbg.CreateTarget(exe)

diff  --git a/lldb/test/API/python_api/target/main.c b/lldb/test/API/python_api/target/main.c
index 7724fa74d9ef..0949c1550a9f 100644
--- a/lldb/test/API/python_api/target/main.c
+++ b/lldb/test/API/python_api/target/main.c
@@ -36,17 +36,24 @@ int c(int val)
     return val + 3;
 }
 
-int main (int argc, char const *argv[])
+int main (int argc, char const *argv[], char** env)
 {
     // Set a break at entry to main.
     int A1 = a(1);  // a(1) -> b(1) -> c(1)
     printf("a(1) returns %d\n", A1);
-    
+
     int B2 = b(2);  // b(2) -> c(2)
     printf("b(2) returns %d\n", B2);
-    
+
     int A3 = a(3);  // a(3) -> c(3)
     printf("a(3) returns %d\n", A3);
-    
+
+    for (int i = 1; i < argc; i++) {
+      printf("arg: %s\n", argv[i]);
+    }
+
+    while (*env)
+      printf("env: %s\n", *env++);
+
     return 0;
 }


        


More information about the lldb-commits mailing list