Reputation: 4016
If there is a way to do this natively in gdb, something like 'load script', then feel free to ignore the emacs part of this question.
I frequently wind up doing the following in a pretty high-count loop:
So it would make my life much easier if I could save the commands to write to a buffer or file, and load and execute that set of commands every time I start gdb. Bonus points if I don't have to enter "y" to confirm that gdb should make the breakpoints pending on future library load.
What would be super awesom is if I could save all current breakpoints (by name not by address as those might change).
Upvotes: 0
Views: 398
Reputation: 10261
You can put all your commands in a file and invoke gdb with the arguments -x /path/to/file
. The answers to any questions will be defaulted to something safe...
$ cat init.gdb
break write
$ gdb -q -x init.gdb a.out
Reading symbols from a.out...done.
Function "write" not defined.
Make breakpoint pending on future shared library load? (y or [n]) [answered N;
input not from terminal]
(gdb)
But in this case, you want the answer to be y
. There's often a gdb variable that can be set to override the default choice. Here, it's set breakpoint pending on
.
$ cat init2.gdb
set breakpoint pending on
break write
$ gdb -q -x init2.gdb a.out
Reading symbols from a.out...done.
Function "write" not defined.
Breakpoint 1 (write) pending.
(gdb)
To save breakpoints, use the save breakpoints
command.
(gdb) save breakpoints bp.gdb
Saved to file 'bp.gdb'.
(gdb) quit
$ cat bp.gdb
break write
Upvotes: 2
Reputation: 22519
In addition to the above, gdb will automatically load a script file. Exactly which file is loaded depends on gdb version, but in older ones it reads .gdbinit in the current directory; and in newer ones will read "$EXE-gdb.gdb", where $EXE is the name of the program you're debugging. See the manual for all the details.
Upvotes: 1
Reputation: 1934
Well i think you can save command history by set history save
The correct explanation for the same type of question is given in below link
How can I make gdb save the command history?
Upvotes: 1