Pages

Wednesday, April 11, 2007

dbx for gdb users

As an old time gdb fan, I keep getting lost with all the different debuggers i have to deal with for userspace/kernelspace debugging (adb, kdb, kwdb, mdb, dbx). So I thought I would put some working tips for my own reference in this blog post about using dbx

dbx has a gdb mode. It supports most gdb commands. To turn it on, at the dbx prompt, type this

(dbx) gdb on

And as usual, this can be automated by creating a .dbxrc and putting 'gdb on' there.

Now all the gdb commands such as c, b, i can be used.

If you want to step over a few lines of code without recompiling, use cont at

(dbx) cont at 221

will continue the program at line 221, skipping all the code between current line and 221.

r doesn't works for run though, and thats because its already set as an alias to something else.

(dbx) alias
[='\['
alias='kalias'
commands='paged-commands'
echo='kprint'
functions='typeset -f'
help='paged-help'
integer='typeset -i'
lo='loadobject'
nohup='nohup '
pp='prettyprint'
pwd='kprint -r "$PWD"'
r='fc -e -'
sh='sh-cmd'
suspend='kill -STOP $$'
type='whence -v'

But if you wish, you can redefine it to run

(dbx) alias r run

(And to make this permanent, put it in .dbxinit)

dbx also supports histories, accessed as usual using history and !!.

Conditional breakpoints are also supported. To set one, first set a normal breakpoint, e.g.

(dbx) b code.c:2197
(dbx) i b
[1] stop at "code.c":2197
and then make it conditional
(dbx) cond 1 'codePtr->id==12'

(dbx) cond
That's it, for this post.