This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Walking an array of structs under gdb-Python
- From: Tom Tromey <tromey at redhat dot com>
- To: Keith Goldberg <keith dot goldberg at actifio dot com>
- Cc: gdb at sourceware dot org
- Date: Tue, 22 Mar 2011 10:40:41 -0600
- Subject: Re: Walking an array of structs under gdb-Python
- References: <AANLkTikzMH8QgAZRUEt-VNjaT4+3a_Go9BeUNSkpUL+=@mail.gmail.com>
Keith> Can someone please point me to an example of how to walk through an
Keith> array of structs using python under GDB? Presuming I have malloc'd
Keith> enough space for 100 of mystruct, I would like to be able to use
Keith> "pointer math" to inspect each element and its members at will. I
Keith> appreciate any pointer to the right resource.
I don't know of an example offhand, but it should pretty much work as
you'd expect.
Suppose you have 'type *array' in the source.
python v = gdb.parse_and_eval('array')
python print v.dereference() # print array[0]
python print (v + 1).dereference() # print array[1]
python print (v + 2)['field'] # print array[2].field
Tom