Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to let the gdb repeat the same instrcutions on every start again?

Tags:

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!

like image 417
hennr Avatar asked Aug 25 '11 18:08

hennr


2 Answers

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
like image 142
ks1322 Avatar answered Sep 20 '22 06:09

ks1322


The interwebs differ on whether the name of the file is .gdbrc or .gdbinit, but GDB will read this file from your home directory on start-up, and it can give any GDB command (including setting breakpoints).

Also check out http://www.andrews.edu/~seidel/gdb.help

like image 26
Jon Watte Avatar answered Sep 20 '22 06:09

Jon Watte