How to dump the entire GDB session to a file, including commands I type and their output?

If you want to log GDB's output, you can use the GDB logging output commands, eg.

set logging file mylog.txt
set logging on

If you want to redirect your program's output to a file, you can use a redirect, eg.

run myprog > mylog.txt

see the chapter on program IO in the GDB manual for more information


  • Create a text file, i.e. gdbCommands.txt, with the following commands

set logging on my_log_file\nbt 10\nq

bt 10, indicates the number of lines (function calls) we need from the backtrace, in our example is 10 lines.

  • Execute gdb using the following command, assuming a core dump file core.2345

gdb -x gdbCommands.txt myApp core.2345

  • Open my_log_file and inspect backtrace!

howto-redirect-gdb-backtrace-output-to-a-text-file

Tags:

Gdb