gdb initialisation file

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

Code:
$ 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.
 
Back
Top