Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb alias for quick saving/loading of breakpoints

Tags:

c

debugging

gdb

So I'm pretty new to gdb, and have just learned that you can save breakpoints with:

save breakpoints filename

and load them with

source filename

which is great, but because it's something I more or less plan on doing every time I enter/exit gdb, I'd like to get it down to a quick alias.

So, in my ~/.gdbinit I have the lines

alias savebps = save breakpoints .gdb_bps
alias loadbps = source .gdb_bps
loadbps

Unfortunately, every time I open gdb I get the error:

Invalid command to alias to: save breakpoints .gdb_bps

I know(/ strongly think) I have the syntax correct, as I've tested

alias savebps = help

and that alias works. So I think it's an issue with having a non-gdb command word (the filename) as part of an alias.

So, my questions are this:

  • Am I being totally stupid and there's already a great way to auto-save and maintain my list of breakpoints?
  • Can GDB have filenames in aliases? Or am I looking for something other than an 'alias'?
  • If they CAN have filenames in them, what am I doing wrong?

Oh and as a note the '.gdb_bps' is an arbitrary file name I just kinda came up with as it'd be a nice unobtrusive thing to easily .gitignore and stuff.

Thanks!

like image 548
Phildo Avatar asked Mar 16 '23 22:03

Phildo


1 Answers

Can GDB have filenames in aliases?

Looks like no. It looks like aliases can't have any arguments to commands, not only filenames. This alias fails also:

(gdb) alias spe = set print elements 0
Invalid command to alias to: set print elements 0

Or am I looking for something other than an 'alias'?

Yes, you can use user-defined command instead:

(gdb) define savebps
Type commands for definition of "savebps".
End with a line saying just "end".
>save breakpoints .gdb_bps
>end
(gdb) 
(gdb) define loadbps
Type commands for definition of "loadbps".
End with a line saying just "end".
>source .gdb_bps
>end
(gdb) 
like image 71
ks1322 Avatar answered Mar 18 '23 13:03

ks1322