Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

gdb

In bash, I can use the script command, which dumps everything that shows on the shell to a file, including:

  • commands typed
  • PS1 line
  • stdout and stderr of commands

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.

like image 806
Jichao Avatar asked Nov 10 '09 11:11

Jichao


People also ask

How do I redirect output to a file in GDB?

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.

How do you break out of GDB?

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.

When running GDB What does the up command do?

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.


2 Answers

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

like image 107
Hasturkun Avatar answered Oct 01 '22 14:10

Hasturkun


  • 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

like image 34
hackhowtofaq Avatar answered Oct 01 '22 14:10

hackhowtofaq