Way to let the gdb repeat the same instrcutions on every start again

gdb

I am currently debugging a program with gdb.
I have to start gdb over and over again and do the same steps:

set a breakpoint,
run,
print a variable,
quit

Is there a way to let gdb do that automatically for me? Probably a script that could be attached as a parameter?

Thanks in advance!

Best Answer

You can do it either by -x file option or by -ex command option. From Gdb manual:

-command file
-x file
Execute commands from file file. The contents of this file is evaluated exactly as the source command would. See Command files. 
-eval-command command
-ex command
Execute a single gdb command.
This option may be used multiple times to call multiple commands. It may also be interleaved with `-command' as required.

          gdb -ex 'target sim' -ex 'load' \
             -x setbreakpoints -ex 'run' a.out
Related Topic