What are the best ways to automate a GDB debugging session?

automation, expect, gdb, scripting

Solution

`gdb` executes file `.gdbinit` after running. So you can add your commands to this file and see if it is OK for you. This is an example of `.gdbinit` in order to print backtrace for all `f()` calls:

set pagination off
set logging file gdb.txt
set logging on
file a.out
b f
commands
bt
continue
end
info breakpoints
r
set logging off
quit

Problem

Does GDB have a built in scripting mechanism, should I code up an expect script, or is there an even better solution out there? I'll be sending the same sequence of commands every time and I'll be saving the output of each command to a file (most likely using GDB's built-in logging mechanism, unless someone has a better idea).

Original source

Related problems