I have some gdb commands in a file that I want to execute. I also want the commands run and the output to be logged to a file.
I wrote the following gdb script in a file named gdb.in
.
set logging file gdb.out
set logging on
echo hi\n
printf "bye\n"
quit
However, if I execute this gdb script, I can only see the output logged to gdb.out
. I don't see the commands executed.
$ gdb -x gdb.in
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6)
Copyright (C) 2010 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 "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
hi
bye
$ cat gdb.out
hi
bye
As far as I can remember, a few years ago, I found a way to log the commands. Each command used to appear in the log file with a +
-sign as a prefix. For example, I was able to get an output like this a few years ago.
+ echo hi\n
hi
+ printf "bye\n"
bye
+ quit
But I am unable to recall what I did to get such an output. Searching the web also didn't help me. I came across this question at How to dump the entire GDB session to a file, including commands I type and their output? but the answers there don't capture the commands executed in the log file.
set trace-commands on
: echos the command in screen before executing it. Use this along with logging to get the command written to file.
This is the subject of GDB feature request, which is at least 12 years old :-(
There is currently no way to achieve this. You may use script
to record the entire GDB session, but that has a distinct disadvantage of also recording various screen control "garbage" characters.
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