Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Keith Goldberg <keith.goldberg@actifio.com>
Cc: gdb@sourceware.org
Subject: Re: Walking an array of structs under gdb-Python
Date: Tue, 22 Mar 2011 16:40:00 -0000	[thread overview]
Message-ID: <m3pqpjrtva.fsf@fleche.redhat.com> (raw)
In-Reply-To: <AANLkTikzMH8QgAZRUEt-VNjaT4+3a_Go9BeUNSkpUL+=@mail.gmail.com>	(Keith Goldberg's message of "Fri, 18 Mar 2011 13:02:04 -0400")

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


  reply	other threads:[~2011-03-22 16:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-18 17:02 Keith Goldberg
2011-03-22 16:40 ` Tom Tromey [this message]
2011-03-23 16:36   ` kidoshisama
2011-03-23 18:15     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3pqpjrtva.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb@sourceware.org \
    --cc=keith.goldberg@actifio.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox