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: Tue, 31 Jan 2012 18:26:00 -0000	[thread overview]
Message-ID: <m34nvbhi6j.fsf@fleche.redhat.com> (raw)
In-Reply-To: <loom.20120125T133523-441@post.gmane.org> (Vladimir's message of "Wed, 25 Jan 2012 13:18:21 +0000 (UTC)")

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

Vladimir> I have a couple of question related to Python pretty
Vladimir> printers. I tried to search for the answer on the web but had
Vladimir> no luck.

Vladimir> (gdb) print *a
Vladimir> Could not find operator*.

Vladimir> How can I implement a printer for the second case?

gdb is giving an error here before it computes a value to print.

I forget if operator* is supposed to be working now or not.
I think some operators still aren't really working in gdb; but often
they will fail anyway because they were not compiled into your program.

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

There is a bug open about the missing operators problem:

    http://sourceware.org/bugzilla/show_bug.cgi?id=12937

Vladimir> 2) Another question is about how to call from pretty printer a
Vladimir> function from my currently debugged process. For example, I
Vladimir> have an unsigned int variable which contains a hash of a
Vladimir> string and there is a function that can map the hash to the
Vladimir> original string. To make the unsigned int value a bit more
Vladimir> descriptive I want to call the function and print
Vladimir> corresponding string. Actually I managed to make such call but
Vladimir> the result looks ugly:

Vladimir> def to_string(self):
Vladimir>   crc = self.val
Vladimir>   s = gdb.execute('call hash_to_string(%d)' % crc, to_string=True)
Vladimir>   return ('crc = 0x%08X : \'%s\'' % (crc, s)))

Vladimir> (gdb) print crc
Vladimir> $1 = crc = 0x0024A837 : '$2 = "qerrrr"
Vladimir> '

Vladimir> Is there any way to obtain the result of the function call as
Vladimir> gdb.Value?

Yes, it can be done.  What you have to do is get the address of the
function as a value.  There's no super way to do this right now:

    http://sourceware.org/bugzilla/show_bug.cgi?id=12027

Once you have that you can call the Value, this is explained in the
docs:

       A `gdb.Value' that represents a function can be executed via
    inferior function call.  Any arguments provided to the call must match
    the function's prototype, and must be provided in the order specified
    by that prototype.

       For example, `some_val' is a `gdb.Value' instance representing a
    function that takes two integers as arguments.  To execute this
    function, call it like so:

         result = some_val (10,20)


However, you usually don't want to call functions when pretty-printing.
For one thing, this means core-file debugging won't work.
It is better, when possible, to do everything in Python instead.

Tom

  reply	other threads:[~2012-01-31 18:26 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 [this message]
2012-02-08 16:36   ` Vladimir
2012-02-22 21:38     ` 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=m34nvbhi6j.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).