public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: Vladimir <volo.zyko@gmail.com>
To: archer@sourceware.org
Subject: pretty printing of smart pointers and making function calls
Date: Wed, 25 Jan 2012 13:20:00 -0000	[thread overview]
Message-ID: <loom.20120125T133523-441@post.gmane.org> (raw)

Hi All,

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

1. For example, I want to implement a pretty printer for variable a of type
std::auto_ptr<std::string>. It's rather straight forward so I will not add here
my implementation of such printer. Then I use it as follows:

(gdb) print a
$1 = std::auto_ptr<std::string> 0x804d030

Now I want to take a look at what is the value inside that pointer.

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

How can I implement a printer for the second case?

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

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

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

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

             reply	other threads:[~2012-01-25 13:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-25 13:20 Vladimir [this message]
2012-01-31 18:26 ` Tom Tromey
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=loom.20120125T133523-441@post.gmane.org \
    --to=volo.zyko@gmail.com \
    --cc=archer@sourceware.org \
    /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).