public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Vladimir <volo.zyko@gmail.com>
Cc: archer@sourceware.org
Subject: Re: pretty printing of smart pointers and making function calls
Date: Wed, 22 Feb 2012 21:38:00 -0000	[thread overview]
Message-ID: <87obsqo8fb.fsf@fleche.redhat.com> (raw)
In-Reply-To: <loom.20120208T150635-160@post.gmane.org> (Vladimir's message of "Wed, 8 Feb 2012 16:35:39 +0000 (UTC)")

>>>>> "Vladimir" == Vladimir  <volo.zyko@gmail.com> writes:

Sorry about the long delay here.
I managed to forget about this thread somehow :(

Tom> You can work around this a little by having the base printer also print
Tom> the pointed-to value.  This is what the libstdc++ iterator printers do
Tom> (for now).

Vladimir> I'm not sure I understand you correctly. Do you mean that if
Vladimir> the user asks for a value of variable a and pretty printer
Vladimir> knows that it's a pointer then along with pointer address it
Vladimir> should print the value the pointer points too? Anyway some
Vladimir> reference to document or example would be useful here.

E.g., the libstdc++ printers for iterators print the referred-to object
as well.  Here's a simple one:

class StdSlistIteratorPrinter:
    "Print __gnu_cxx::slist::iterator"

    def __init__(self, typename, val):
        self.val = val

    def to_string(self):
        nodetype = find_type(self.val.type, '_Node')
        nodetype = nodetype.strip_typedefs().pointer()
        return self.val['_M_node'].cast(nodetype).dereference()['_M_data']

This looks into the iterator representation, finds the pointer to the
iterated-over data, and prints that.

This is a hack, but often a useful one.

Vladimir> But you are right that this doesn't work with core-file. Is
Vladimir> there any way to check in Python whether I debug alive process
Vladimir> or see its dead body?

Nothing direct but as a workaround you can often find this stuff using
gdb.execute(..., to_string=True) and then parsing the result.
The output here might change between releases, though, so it is
generally better to get a real Python API.

Tom

      reply	other threads:[~2012-02-22 21:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-25 13:20 Vladimir
2012-01-31 18:26 ` Tom Tromey
2012-02-08 16:36   ` Vladimir
2012-02-22 21:38     ` Tom Tromey [this message]

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=87obsqo8fb.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=archer@sourceware.org \
    --cc=volo.zyko@gmail.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).