Gdb print to file
I am printing my temporary lines with this standard output:
printf "%s", nodeToString(myNode)
but I want to print this line in a file.
I tried the solution outlined here , but the printf results still go to standard output.
Edit: Clarification for cIph3r's answer.
Here's what I tried on the command line:
$ gdb
(gdb) attach 23053
(gdb) printf "%s", nodeToString(myNode) // This works and outputs to screen
(gdb) run printf "%s", nodeToString(myNode) > outputfile // I get this warning
The program being debugged has been started already.
Start it from the beginning? (y or n)
source to share
gdb can pipe like bash but I only know how to use gdb from the command line.
first start gdb and tell it to debug:
gdb ./prog
then in gdb you can run the program with run
run
here you can also run it with argumetns:
run argv1 argv2
but you can also start it with bash -pipeline commands:
run > outputfile
this is the same as
./prog > outputfile
However, if you want gdb-output like
(gdb) print "test"
$s1 = "test"
this is the wrong way. You do it like this:
(gdb) set logging on
but be aware not to do this when the program you want to debug is running
If that doesn't work, you can use tee to grab stdout from gdb and redirect it to a file:
gdb ./prog | tee output.log
then the gdb output is also saved to output.log (but everything is stdout)
after exiting gdb there is a filename output.log
containing everything you saw in gdb
source to share