3

I want to run an executable, redirect it's stdout to my program's via pipe, and LLDB debug my program. So, for example:

cat my_file | ./main

and then debug ./main. I'm aware of process launch -i my_file, but that's not exactly what I want to do - I want the output to come from cat's stdout (it could be any other executable which -i wouldn't achieve similar behaviour with). I see no relevant options under help process launch.

Gal Gofrit
  • 31
  • 3

3 Answers3

2

That isn't an option supported by lldb. You can get almost the same effect by running:

(lldb) process attach -w -n main

then go to the command line and run the cat | ./main command.

lldb will attach to the process called main when it is created. lldb does this by polling the process table, so it won't stop at the very beginning of the program's life. However, it usually catches it very early on (often in the dyld loading phase) so this might not be an issue for you. If it is - and main is a program you can rebuild, one solution is to put something like this at the beginning of main:

int go_on = 1
while (go_on) { sleep(1); }

Then when you attach, do:

(lldb) expr go_on = 0
(lldb) continue
Jim Ingham
  • 25,260
  • 2
  • 55
  • 63
  • Too bad it isn't supported. That's a cool solution! I can play around with it, this is often gonna be enough without the sleep, especially with programs with heavy set-up. If it's during loading phase it's even better. Thanks for the suggestion :) – Gal Gofrit Dec 19 '18 at 12:21
1

For those still looking to pass shell command outputs to lldb as arguments.

One solution that you can try, is creating an environment variable with the result of the command and then passing this as an argument to lldb. When lldb runs it sets the target.run-args option taken from the environment variable.

In your example you would do something along those lines.

ARG=`cat my_file`

(echo $ARG to validate the result is that you want)

lldb -- main $ARG

tsiolkas
  • 11
  • 1
0

It is supported with the command process launch -i <file>

See here for more info: Cannot get mac os x lldb process to read the STDIN

Dweezahr
  • 190
  • 1
  • 9