# gdb initialisation file



## balanga (Oct 18, 2018)

I can't find a gdb initialisation file which I believe should be called .gdbinit. Is this something I need to create?

I 'd like to start gdb with specific paramaters and/or predefined breakpoints but don't know where to set them. 
Any help would be appreciated.


----------



## Deleted member 55987 (Oct 18, 2018)

"I can't find a gdb initialisation file which I believe should be called .gdbinit. Is this something I need to create?"

yes.  in the same directory where you start gdb.

"I 'd like to start gdb with specific paramaters and/or predefined breakpoints but don't know where to set them."

in gdb you can use 'set args' to supply command-line arguments.

breakpoints in the .gdbinit file, something like:

  b main
  r

will set a breakpoint and start the program.


----------



## balanga (Oct 19, 2018)

I'm trying to get devel/gdb to start up automatically as if I had entered `gdb -q --args ./myprog /parm1 /parm2` but am unable to do this using .gdbinit....

There seems to be a steep learning curve when it comes to using gdbinit....

https://gist.github.com/chrislongo/3351197

https://wikileaks.org/ciav7p1/cms/files/.gdbinit

... far too much to take in.

Does anyone have a simple gdbinit I can use to learn from?


----------



## Deleted member 55987 (Oct 19, 2018)

balanga said:
			
		

> ... far too much to take in.



  the documentation defines the file format in 14 words.



> "A command file for GDB is a file of lines that are GDB commands."



note I'm very new to FreeBSD, so no idea how 'devel/gdb -q ...' differs from a regular invocation.  also note that you do not have to use a '.gdbinit', you can supply such command files via an option also.  hth.


----------



## _martin (Oct 20, 2018)

gdb shipped by FreeBSD (i.e. in /usr/bin/gdb) is older than devel/gdb. Newer version has some neat features. .gdbinit is sourced by gdb from $HOME,  you can specify it explicitly or even tell it not to source anything. If the .gdbinit doesn't exist feel free to create one and customize it to your liking.

I put breakpoints into .gdbinit only when I'm debugging something that I need to re-execute very often and I'm lazy. Generally it's not a good idea. Forgotten breakpoint in the middle of the instruction can cause a headache, I know it from my own experience .

You can invoke gdb with -x,  like so (example on /bin/ls):


```
$ readelf -h /bin/ls  | grep Entry

  Entry point address:               0x401f50
$
$ cat debugls
set args /tmp
b *0x401f50
r
$ gdb -x debugls /bin/ls
```

The 'r' is there to run the debugger. You can remove it if you don't want to start debugging immediately. Of course if you're debugging binary with symbols you can use their (symbols) names instead of addresses.


----------

