How to include GDB commands in logging 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.
I don't know when it was introduced, but @prasannatsm presents the solution here): set trace-commands on
.
I'd just like to add upon that and show the full process. Here's how I like to start logging now:
set logging file ~/temp/gdb.txt
set logging on
set trace-commands on
show logging
flush
show logging
at the end is just to verify everything is logging and working as-expected.
Notice that set trace-commands on
causes each command you type to be echoed back out to you now (and also logged if logging is on) with a +
preceding it to show it was an echoed command input, not the response.
This can be seen in the output here, for instance:
+show logging Currently logging to "/home/gabriel.staples/temp/gdb.txt". Logs will be appended to the log file. Output will be logged and displayed. +flush Register cache flushed.
set trace-commands on
: echos the command in screen before executing it. Use this along with logging to get the command written to file.