49

Does anyone know how to save gdb settings (like "set print pretty on" or "set print elements 0", both from here)? I don't want to set my configuration every time that I will use gdb :/

I searched in google and SO, but I found nothing.

coelhudo
  • 4,710
  • 7
  • 38
  • 57

2 Answers2

88

Add any commands you want to auto run in the .gdbinit file in your home directory.

tyranid
  • 13,028
  • 1
  • 32
  • 34
  • For the record, this also works for the gdb inside Xcode. I added `handle SIGPIPE nostop` to `.gdbinit` to fix [this problem](http://lists.apple.com/archives/xcode-users/2010/Jul/msg00088.html). – mpontillo Feb 22 '12 at 17:27
  • Dear I like to add command to let my cross arm gdb starts the target gdb(on raspberry) automatically, how may I set the gdbinit file? please help bro, commands? –  Jun 04 '14 at 18:36
  • 4
    **TIP:** adding `add-auto-load-safe-path ` in `~/.gdbinit` allows to add additional `gdbinit`s, so you can have one per project for example! – Paschalis May 19 '16 at 15:35
  • Or even add `set-auto-load safe-path /` to `.gdbinit`, if you don't want to add every project separately and security is not a concern. – fala Nov 24 '16 at 11:28
5

The existing answer works for commands that can run before the binary is loaded, but for example if you want to add catch throw you cannot do it in .gdbinit since that command needs to run after the binary is loaded.

But gdb can take a file with commands to run after binary loading using:

-x file
       Execute GDB commands from file file.

I automated that by creating an alias:

alias gdb='gdb -x ~/.gdbinit_x'

and added my after binary load commands in that file.

Zitrax
  • 19,036
  • 20
  • 88
  • 110