How to load program reading stdin and taking parameters in gdb?
If you were doing it from a shell you'd do it like this:
% gdb myprogram
gdb> run params ... < input.txt
This seems to work within emacs too.
Pass File Input and Stdin to gdb
You can run the program in one console and attach to it with gdb from another one when it is waiting for input. Therefore you will be able to enter program input in the 1st console and debug it in the 2nd.
How to use gdb with input redirection?
~$ gdb <executable>
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/abhishek/maxtest...done.
(gdb) run < input.txt
This is doing the trick for me. Wondering if this was what you were looking for.
How to pass arguments and redirect stdin from a file to program run in gdb?
Pass the arguments to the run
command from within gdb.
$ gdb ./a.out
(gdb) r < t
Starting program: /dir/a.out < t
How to debug a program that takes user input from stdin with GDB?
$ 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)
How to debug C program with argument and stdin as input
For easier debugging with GDB, you should convert the "here string" lines between the <<end
and end
into a text file (say "input.txt"). Then, in gdb
you can use the set args
command to set up the command-line arguments and redirection of standard input from the file.
For example: suppose the file "input.txt" contains:
Monos(1,2)
Monos(6)
Run gdb
from the shell as follows:
$ gdb ./test
Within GDB, set the command-line arguments and redirection of standard input:
(gdb) set args 1 2 3 < input.txt
Set any breakpoints, e.g.:
(gdb) b main
And start running the code:
(gdb) r
How do I pass the arguments from a text file to run a program under gdb?
Thanks and I got an simple solution.
(gdb) run $( cat arg.txt )
It is also possible to pass the output of a command to be the arguments.
(gdb) run $( ruby -e 'print( "text as arguments" )' )
Related Topics
Getting Root Privileges in Ansible
Store Passwords Required by a Linux Daemon
Version Control for My Web Server
Time Taken by 'Less' Command to Show Output
Assembly Divisions and Floating Points
Embedded Linux Poll() Returns Constantly
Pipe Tar Extract into Tar Create
Using for Loop to Move Files from Subdirectories to Parent Directories
Total Number of Bytes Read/Written by a Linux Process and Its Children
Process-Local Override of Name Resolution
Getting Kernel Version from The Compressed Kernel Image
How to Finding All Runnable Processes
Why Does Gdb Prompt "Unexpected Size of Section '.Reg-Xstate/Xxxxx' in Core File."
How to Solve Ssh: /Usr/Lib64/Libcrypto.So.10: No Version Information Available
Using Find But Only in Subdirectories Matching Certain Pattern