Howto Redirect Gdb Backtrace Output to a Text File

Recipe # | posted in Howto, Linux, Programming | Comments

How to redirect gdb backtrace to a text file’ ‘How to redirect gdb backtrace to a text file

1 – Problem Description

Redirecting gdb backtrace (bt) output to a text file for parsing or other uses.

2 – Solution

  • Create a text file, i.e. gdbCommands.txt, with the following commands
1
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
1
gdb -x gdbCommands.txt myApp core.2345

Open my_log_file and inspect backtrace!

Comments