This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Walking an array of structs under gdb-Python


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]