0

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:

  1. start gdb (in emacs if that helps).
  2. set several breakpoints (same breakpoints every time). Usually have to enter "y" I want to make breakpoint pending on future shared library load.
  3. set some watchpoints (same watchpoints)
  4. debug for a while.
  5. close gdb.
  6. goto 1.

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).

3 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that seems very helpful. Playing with it now.
1

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?

Comments

1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.