Walking an array of structs under gdb-Python

Tom Tromey tromey@redhat.com
Tue Mar 22 16:40:00 GMT 2011


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



More information about the Gdb mailing list