This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Pretty Printing
On Fri, Feb 1, 2013 at 1:22 AM, Graham Labdon
<Graham.Labdon@avalonsciences.com> wrote:
> Hi
> I don't know if there is anyone on this forum who can help
>
> I am developing a set of gdb pretty printers for Qt
> A dictionary is built of the functions to call when a variable of a given type is detected
> Code:
> def build_dictionary ():
> pretty_printers_dict[re.compile ('^QFile$')] = lambda val:QFilePrinter(val,"false")
> pretty_printers_dict[re.compile ('^QFile \*$')] = lambda val: QFilePointerPrinter(val)
>
>
> Here I have declared handlers for the QFile and QFile * types
>
> In the QFile handler I have this code
> Code:
> exp = "((class QFile *)%s)->%s()" % (value.address, "exists")
>
>
> The problem is that this causes the handler for QFile * to be called which causes great problems
>
> If any Python guru knows how to overcome this I would appreciate it
Have you tried beginning with an existing pretty-printer that works?
Here are the pretty-printers for libstdc++:
http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/python/libstdcxx/v6/printers.py?revision=193573&view=markup
It's not clear what you're trying to do with "exp".
Secondly, it's bad practice for pretty-printers to run code on the
inferior (which appears to be what exp is for).
- won't work with core files
- the inferior (gdb parlance for the program you're debugging) may not
be in a good enough state to run the code
- if you're debugging a problem, that last thing you want is to
perturb inferior state