Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save settings in gdb?

Tags:

c++

c

debugging

gdb

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.

like image 202
coelhudo Avatar asked Jan 11 '10 22:01

coelhudo


People also ask

Where is gdb config file?

On non-macOS hosts the locations searched are: The file gdb/gdbearlyinit within the directory pointed to by the environment variable XDG_CONFIG_HOME , if it is defined. The file . config/gdb/gdbearlyinit within the directory pointed to by the environment variable HOME , if it is defined.

What is Gdbinit?

gdbinit" is a file you can drop in your home directory that gdb will parse when gdb launches, either from the command line or from within Xcode.


2 Answers

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

like image 163
tyranid Avatar answered Sep 21 '22 09:09

tyranid


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.

like image 40
Zitrax Avatar answered Sep 22 '22 09:09

Zitrax