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

2020-08-06 Thread Muhammad Omair Javaid via Phabricator via lldb-commits
omjavaid added subscribers: max-kudr, omjavaid.
omjavaid added a comment.

In D85235#2198062 , @JDevlieghere 
wrote:

> In D85235#2198013 , @max-kudr wrote:
>
>> @JDevlieghere This change is is failing LLDB Windows buildbot 
>>  since build 18051 
>> . Can 
>> you please fix that?
>
> Thanks for the heads up. I had just pushed a fix:
>
>   commit 927afdffbb1deebd83b86d024b67687d758521d0 
>   Author: Jonas Devlieghere 
>   Date:   Wed Aug 5 15:37:50 2020 -0700
>   
>   [lldb] Skip test_launch_simple on Windows
>   
>   Because stdio manipulation unsupported on Windows.

This still fails on http://lab.llvm.org:8011/builders/lldb-aarch64-ubuntu and 
http://lab.llvm.org:8011/builders/lldb-arm-ubuntu


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85235

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2020-08-05 Thread Max Kudryavtsev via Phabricator via lldb-commits
max-kudr added a comment.

Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85235

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2020-08-05 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

In D85235#2198013 , @max-kudr wrote:

> @JDevlieghere This change is is failing LLDB Windows buildbot 
>  since build 18051 
> . Can 
> you please fix that?

Thanks for the heads up. I had just pushed a fix:

  commit 927afdffbb1deebd83b86d024b67687d758521d0 
  Author: Jonas Devlieghere 
  Date:   Wed Aug 5 15:37:50 2020 -0700
  
  [lldb] Skip test_launch_simple on Windows
  
  Because stdio manipulation unsupported on Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85235

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2020-08-05 Thread Max Kudryavtsev via Phabricator via lldb-commits
max-kudr added a comment.

@JDevlieghere This change is is failing LLDB Windows buildbot 
 since build 18051 
. Can 
you please fix that?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85235

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2020-08-05 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG882d8e60dd40: [lldb] Make SBTarget::LaunchSimple start form 
the targets LaunchInfo (authored by JDevlieghere).

Changed prior to commit:
  https://reviews.llvm.org/D85235?vs=283136=283283#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85235

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

Index: lldb/test/API/python_api/target/main.c
===
--- lldb/test/API/python_api/target/main.c
+++ lldb/test/API/python_api/target/main.c
@@ -36,17 +36,24 @@
 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;
 }
Index: lldb/test/API/python_api/target/TestTargetAPI.py
===
--- lldb/test/API/python_api/target/TestTargetAPI.py
+++ lldb/test/API/python_api/target/TestTargetAPI.py
@@ -150,6 +150,38 @@
 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()
+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()
+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()
+self.assertEqual(output, "")
+
 def create_simple_target(self, fn):
 exe = self.getBuildArtifact(fn)
 target = self.dbg.CreateTarget(exe)
Index: lldb/source/API/SBTarget.cpp
===
--- lldb/source/API/SBTarget.cpp
+++ lldb/source/API/SBTarget.cpp
@@ -287,16 +287,24 @@
  (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() {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2020-08-05 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 283136.
JDevlieghere added a comment.

Back to previous revision.


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

https://reviews.llvm.org/D85235

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

Index: lldb/test/API/python_api/target/main.c
===
--- lldb/test/API/python_api/target/main.c
+++ lldb/test/API/python_api/target/main.c
@@ -36,17 +36,24 @@
 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;
 }
Index: lldb/test/API/python_api/target/TestTargetAPI.py
===
--- lldb/test/API/python_api/target/TestTargetAPI.py
+++ lldb/test/API/python_api/target/TestTargetAPI.py
@@ -150,6 +150,38 @@
 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()
+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()
+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()
+self.assertEqual(output, "")
+
 def create_simple_target(self, fn):
 exe = self.getBuildArtifact(fn)
 target = self.dbg.CreateTarget(exe)
Index: lldb/source/API/SBTarget.cpp
===
--- lldb/source/API/SBTarget.cpp
+++ lldb/source/API/SBTarget.cpp
@@ -287,16 +287,24 @@
  (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() {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2020-08-05 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/source/Target/Target.cpp:3918
+  if (Module *exe_module = m_target->GetExecutableModulePointer())
+m_launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
   m_launch_info.SetArg0(GetArg0()); // FIXME: Arg0 callback doesn't work

Unfortunately doing this here doesn't work. Some of the code that's using 
`GetProcessLaunchInfo()` depends on the assumption that the `m_arguments` list 
in `ProcessInfo` does not contain argv[0], while other code, most notably the 
code to actually launch a binary, depends on it being the first argument. So 
whatever I do here, I break some code. 


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

https://reviews.llvm.org/D85235

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2020-08-04 Thread Jim Ingham via Phabricator via lldb-commits
jingham accepted this revision.
jingham added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D85235

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2020-08-04 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 283100.
JDevlieghere added a comment.

Address Jim's offline feedback about `GetProcessLaunchInfo` including the 
executable.


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

https://reviews.llvm.org/D85235

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

Index: lldb/test/API/python_api/target/main.c
===
--- lldb/test/API/python_api/target/main.c
+++ lldb/test/API/python_api/target/main.c
@@ -36,17 +36,23 @@
 return val + 3;
 }
 
-int main (int argc, char const *argv[])
-{
-// 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);
-
-return 0;
+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;
 }
Index: lldb/test/API/python_api/target/TestTargetAPI.py
===
--- lldb/test/API/python_api/target/TestTargetAPI.py
+++ lldb/test/API/python_api/target/TestTargetAPI.py
@@ -150,6 +150,38 @@
 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()
+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()
+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()
+self.assertEqual(output, "")
+
 def create_simple_target(self, fn):
 exe = self.getBuildArtifact(fn)
 target = self.dbg.CreateTarget(exe)
Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -3914,6 +3914,8 @@
 }
 
 const ProcessLaunchInfo ::GetProcessLaunchInfo() {
+  if (Module *exe_module = m_target->GetExecutableModulePointer())
+m_launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
   m_launch_info.SetArg0(GetArg0()); // FIXME: Arg0 callback doesn't work
   return m_launch_info;
 }
Index: lldb/source/API/SBTarget.cpp
===
--- lldb/source/API/SBTarget.cpp
+++ lldb/source/API/SBTarget.cpp
@@ -287,16 +287,21 @@
  (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 (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() {

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

2020-08-04 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 283001.
JDevlieghere added a comment.

Test a few more cases


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

https://reviews.llvm.org/D85235

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

Index: lldb/test/API/python_api/target/main.c
===
--- lldb/test/API/python_api/target/main.c
+++ lldb/test/API/python_api/target/main.c
@@ -36,17 +36,24 @@
 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;
 }
Index: lldb/test/API/python_api/target/TestTargetAPI.py
===
--- lldb/test/API/python_api/target/TestTargetAPI.py
+++ lldb/test/API/python_api/target/TestTargetAPI.py
@@ -150,6 +150,38 @@
 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()
+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()
+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()
+self.assertEqual(output, "")
+
 def create_simple_target(self, fn):
 exe = self.getBuildArtifact(fn)
 target = self.dbg.CreateTarget(exe)
Index: lldb/source/API/SBTarget.cpp
===
--- lldb/source/API/SBTarget.cpp
+++ lldb/source/API/SBTarget.cpp
@@ -287,16 +287,24 @@
  (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() {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2020-08-04 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 282990.
JDevlieghere added a comment.

Add test


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

https://reviews.llvm.org/D85235

Files:
  lldb/source/API/SBTarget.cpp
  lldb/test/API/python_api/target/TestTargetAPI.py


Index: lldb/test/API/python_api/target/TestTargetAPI.py
===
--- lldb/test/API/python_api/target/TestTargetAPI.py
+++ lldb/test/API/python_api/target/TestTargetAPI.py
@@ -150,6 +150,20 @@
 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')
+self.runCmd("settings set target.disable-stdio true")
+process = target.LaunchSimple(
+None, None, self.get_process_working_directory())
+self.runCmd("run")
+output = process.GetSTDOUT(1000)
+self.assertEqual(output, "")
+
 def create_simple_target(self, fn):
 exe = self.getBuildArtifact(fn)
 target = self.dbg.CreateTarget(exe)
Index: lldb/source/API/SBTarget.cpp
===
--- lldb/source/API/SBTarget.cpp
+++ lldb/source/API/SBTarget.cpp
@@ -287,16 +287,24 @@
  (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() {


Index: lldb/test/API/python_api/target/TestTargetAPI.py
===
--- lldb/test/API/python_api/target/TestTargetAPI.py
+++ lldb/test/API/python_api/target/TestTargetAPI.py
@@ -150,6 +150,20 @@
 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')
+self.runCmd("settings set target.disable-stdio true")
+process = target.LaunchSimple(
+None, None, self.get_process_working_directory())
+self.runCmd("run")
+output = process.GetSTDOUT(1000)
+self.assertEqual(output, "")
+
 def create_simple_target(self, fn):
 exe = self.getBuildArtifact(fn)
 target = self.dbg.CreateTarget(exe)
Index: lldb/source/API/SBTarget.cpp
===
--- lldb/source/API/SBTarget.cpp
+++ lldb/source/API/SBTarget.cpp
@@ -287,16 +287,24 @@
  (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, 

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

2020-08-04 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added a reviewer: jingham.
JDevlieghere added a project: LLDB.
JDevlieghere requested review of this revision.

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.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D85235

Files:
  lldb/source/API/SBTarget.cpp


Index: lldb/source/API/SBTarget.cpp
===
--- lldb/source/API/SBTarget.cpp
+++ lldb/source/API/SBTarget.cpp
@@ -287,16 +287,24 @@
  (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() {


Index: lldb/source/API/SBTarget.cpp
===
--- lldb/source/API/SBTarget.cpp
+++ lldb/source/API/SBTarget.cpp
@@ -287,16 +287,24 @@
  (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() {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits