Search code examples
gdb

How to debug a program that takes user input from stdin with GDB?


I have a program and I am trying to debug it using gdb. Inside the program I have methods that require the user to enter an input using stdin. How can I enter this input when I am in gdb? So that I can trace how my methods work?


Solution

  • $ cat >foo <<EOF
    something
    EOF
    $ gdb -quiet /bin/cat
    Reading symbols from /bin/cat...(no debugging symbols found)...done.
    Missing separate debuginfos, use: debuginfo-install coreutils-8.12-7.fc16.x86_64
    (gdb) run <foo
    Starting program: /bin/cat <foo
    something
    [Inferior 1 (process 22436) exited normally]
    (gdb)