24

I'm using lldb as a standalone debugger in OSX. I'm trying to debug a C executable, using a text file as input, by way of a redirect. The lldb documentation specifies the following command for changing stdin to a given file:

process launch -i <file>

Using this command, lldb seems to ignore the specified file, instead waiting for keyboard input.

Is this intended behavior? If so; what do I need to do to actually get the process to operate on my wanted input file?

tl;dr: How do I get lldb to imitate a standard terminal execution with a redirect like:

./executable < <file>
Harald Husum
  • 1,059
  • 1
  • 7
  • 21
  • To clarify, your application is written to always read from stdin? – Jonathon Reinhart Feb 23 '16 at 16:30
  • @JonathonReinhart I assume so, but I'm not entirely sure. My program's IO is defined in source generated by flex and bison. I call yyparse() which in turn calls yylex(), which should do the IO. The executable have, however, been run outside debugger with the textfile as stdin, and behaved as intended. It was done as follows: ./executable outputfile.txt – Harald Husum Feb 23 '16 at 18:19
  • `./executable infile.txt outfile.txt` does **not** mean the program is reading from stdin. In fact, it implies the opposite - that the program is expecting a filename on the command-line. You need to look at the `int main` for your program and understand it first. – Jonathon Reinhart Feb 23 '16 at 18:59
  • @JonathonReinhart Sorry for the confusion. `./executable outfile.txt`, is from a secondary makefile (for producing output files). In terminal, I can run `./executable < infile.txt` for desired result, or just `./executable` for it to read keyboard input. As I understand it, this **is** stdin. Am I wrong? – Harald Husum Feb 23 '16 at 19:34
  • @HaraldHusum I think he misunderstood `` as a placeholder rather than literal shell syntax. Your program is indeed reading from stdin. – zwol Feb 23 '16 at 19:37
  • @zwol It is easy to see why. Hence sorry for the confusion. :P – Harald Husum Feb 23 '16 at 19:49
  • @zwol Ha, yes, you are indeed correct. Yes, your program is reading from stdin. Sorry for the noise. – Jonathon Reinhart Feb 23 '16 at 22:43

1 Answers1

47

I got it to work as follows:

lldb <executable>
(lldb) settings set target.input-path <file>
(lldb) process launch

It solves my problem, but I don't really have an explanation for why the method in my question doesn't work.

Harald Husum
  • 1,059
  • 1
  • 7
  • 21