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?
Passing arguments to the program being debugged. The --args option must be immediately followed by the command invoking the program you wish to debug. That command should consist of the program name and then its arguments, just as they would appear if you were starting that program without GDB.
To debug your program in gdb, you have to run it by typing "run". However, if you just type "run" gdb will run your program to completion without debugging it at all. If your program crashes, gdb will stop it and allow you to debug it.
To run a program in a debuggerClick the Image File tab. In the Image box, type the name of an executable file or DLL, including the file name extension,and then press the TAB key. This activates the check boxes on the Image File tab. Click the Debugger check box to select it.
$ 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)
You can also run your program first, then attach GDB to it:
gdb --pid $(pgrep your_program)
This way you will be able to run your program interactively in a separate terminal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With