Displaying structs
Daniel Berlin
dberlin@redhat.com
Sat Oct 7 11:36:00 GMT 2000
Ben Elliston <bje@redhat.com> writes:
Try this patch.
set print follow-pointers to the max depth you want to follow, it defaults to 0.
Then print *ptr, should follow the pointers in the structures up to
that depth.
11 dans=new dan;
(gdb) n
12 dans->next=new dan;
(gdb) p dans
$1 = (dan *) 0x8049760
(gdb) n
13 dans->prev=NULL;
(gdb) p dans
$2 = (dan *) 0x8049760
(gdb) set print follow-pointers 1
(gdb) p dans
$3 = (dan *) 0x8049760
(gdb) p dans[0]
$4 = {next = {next = 0x0, prev = 0x0}, prev = 0x0}
(gdb) set print pretty on
(gdb) p dans[0]
$5 = {
next = {
next = 0x0,
prev = 0x0
},
prev = 0x0
}
Howzat for ya?
I didn't have it print the type of the pointer it's following, it
seemed like it would just waste space.
Is this useful to people?
Should i clean it up and submit it to gdb-patches?
--Dan
> Often, when debugging, I like to examine pointers to structures. When
> examining the struct instance that the pointer is addressing, I might use:
>
> (gdb) print/x *ptr
>
> If the struct has fields which are further pointers to structs, I have to
> manually follow these pointers:
>
> (gdb) print/x *ptr->next
> or
> (gdb) print/x *ptr->prev
>
> Is there a way that GDB can recursively follow these (to some level)? I am
> guessing that there is enough debugging information for it to know that the
> pointers are to meaningful types.
>
> Ben
More information about the Gdb
mailing list