(gdb) break *0x972

Debugging, GNU± Linux and WebHosting and ... and ...

[Dev-tools configuration] GDB's .gdbinit

In the next posts, I'll share the configuration files of my development and debugging tool. I think having a nice dev environment is key to good quality programming. At least, it makes your experience better. It's also verrrry nice for the people that will have to interact with you and your code!

I'll start with my .gdbinit:

  • No window size, we can scroll:

    set height 0
    set width 0
    
  • Allow pending breakpoints, we know what we're doing:

    (gdb) break foobar Function "foobar" not defined. Breakpoint 9 (foobar) pending.

    means that there is no "foobar" currently loaded, but maybe you know it will appear later.

    set breakpoint pending on
    
  • We're doing python development, so print the full stack trace when it crashes:

    set python print-stack full
    
  • GDB, please don't complain, I know what I'm doing! ... but beware, you may loose your session if you enter start in the middle of your debugging

    set confirm off
    
  • Structure easier to read:

    set print pretty
    
  • Save history, up-arrow and ctrl-r can save a lot of time:

    set history filename ~/.gdb_history
    set history save
    

We can also add a little bit of Python shortcut commands:

import gdb
  • quickly print Python objects pp instead of py print:

    class pp(gdb.Command):
        """Python print its arg"""
        def __init__(self):
            gdb.Command.__init__ (self, "pp", gdb.COMMAND_DATA,
                                  completer_class=gdb.COMPLETE_SYMBOL)
        def invoke (self, arg, from_tty):
            gdb.execute("python print %s" % arg)
    pp()
    
  • quickly list attributes of a Python object: ppd

    class ppd(gdb.Command):
        """Python print dir() of its arg"""
        def __init__(self):
            gdb.Command.__init__ (self, "ppd", gdb.COMMAND_DATA, completer_class=gdb.COMPLETE_SYMBOL)
    
        def invoke (self, arg, from_tty):
            gdb.execute("python print dir(%s)" % arg)
    ppd()
    

And finally a code I retrieved from ratmice@gitorious, an extended prompt for GDB, which shows the current source file, line and function, all that with colors (my version is here):

(src/ls.c:1242 main gdb)
$

ratmice :

Ran across this while looking for a patch in the archives, glad to see the prompt stuff in use,
I used it for a while to keep a vim remote synchronized to the current file/line at the prompt as well,
which is kind of weird because it's a bunch of prompt generation code, but hey it worked :)

let me know if there is anything you would like me to pull in to my copy on gitorious.