In bash, I can use the script
command, which dumps everything that shows on the shell to a file, including:
What is the equivalent in gdb?
I tried to run shell script
from inside GDB, but after I hit return, I was in the shell and lost the shell prompt and could not run command any more. Moreover I could not use ctrl+c or ctrl+\ to exit. I needed to force kill the /bin/login tty2
to exit.
Logging GDB's output to a file This is done by first issuing the command set logging file my-gdb-log , followed by the command set logging on . Later on, you can issue the set logging off command to stop sending GDB output to the log file.
To exit GDB, use the quit command (abbreviated q ), or type an end-of-file character (usually C-d ). If you do not supply expression , GDB will terminate normally; otherwise it will terminate using the result of expression as the error code.
The command up can be used to examine the contents of other active frames, by moving the focus up the stack, that is to say from callee to caller, one frame at a time. Inspect the frame with the given number. The value 0 denotes the frame of the current breakpoint, that is to say the top of the call stack.
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
gdbCommands.txt
, with the following commandsset 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.
gdb -x gdbCommands.txt myApp core.2345
my_log_file
and inspect backtrace!howto-redirect-gdb-backtrace-output-to-a-text-file
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