This is the mail archive of the
mailing list for the Archer project.
Re: pretty printing of smart pointers and making function calls
- From: Tom Tromey <tromey at redhat dot com>
- To: Vladimir <volo dot zyko at gmail dot com>
- Cc: archer at sourceware dot org
- Date: Tue, 31 Jan 2012 10:53:56 -0700
- Subject: Re: pretty printing of smart pointers and making function calls
- References: <loom.20120125T133523email@example.com>
>>>>> "Vladimir" == Vladimir <firstname.lastname@example.org> 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
There is a bug open about the missing operators problem:
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> Is there any way to obtain the result of the function call as
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:
Once you have that you can call the Value, this is explained in the
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.