Pages

Showing posts with label debugging. Show all posts
Showing posts with label debugging. Show all posts

Saturday, February 13, 2010

What is in the heap?

How to find out what is there in a process heap? Here is some Solaris fu that I found handy from a usenet post from Jonathan Adams (netbsd archives)

Let's say you have a core dump already. If you don't have it, you can always get one using gcore.

Run pmap on the core file. Look at the segment of interest. It would show you the a lot of information, starting with address, permissions, heap/stack or the name of the file that is mapped (in case of dynamically loaded libraries, for example). Once you have identified the segment of interest (which was a segment whose size was too big, in my case), use it address and get the program header using elfdump.

elfdump -p core | ggrep -iB1 -A4 FFFFFFFF7DA00000
Program Header[6]:
p_vaddr: 0xffffffff7da00000 p_flags: [ PF_W PF_R ]
p_paddr: 0 p_type: [ PT_LOAD ]
p_filesz: 0x10000 p_memsz: 0x10000
p_offset: 0x1840c8 p_align: 0

Now that you know the offset at which your segment is (p_offset), and the size, copy it using dd

dd if=core of=/tmp/data ibs=1 size=65536 seek=1589448

At this point, you could run strings on the segment to get some idea of what is contained in there.

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.