Saturday, May 7, 2022

[SOLVED] Run file in LLDB using output of a command

Issue

In command line it is possible to use the output of a command as the stdin of an executable. For example, pbpaste returns the value of the clipboard on OSX. I could run a program using this, e.g. pbpaste | ./program

Is this also possible in LLDB?


Solution

lldb only has access to a program's stdio if it launched the program and is sharing the terminal with it. So you can't always do this.

There isn't an lldb command to send text to the debuggee's stdin, but you can write to the process stdin (when that's possible) from Python using SBProcess.PutSTDIN:

https://lldb.llvm.org/python_api/lldb.SBProcess.html#lldb.SBProcess.PutSTDIN

So you could pretty easily cons up Python command that runs the shell command you want, gets the output, and uses this API to write it to the target.



Answered By - Jim Ingham
Answer Checked By - David Goodson (WPSolving Volunteer)