public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
* pretty printing of smart pointers and making function calls
@ 2012-01-25 13:20 Vladimir
  2012-01-31 18:26 ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Vladimir @ 2012-01-25 13:20 UTC (permalink / raw)
  To: archer

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?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-02-22 21:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-25 13:20 pretty printing of smart pointers and making function calls Vladimir
2012-01-31 18:26 ` Tom Tromey
2012-02-08 16:36   ` Vladimir
2012-02-22 21:38     ` Tom Tromey

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).