[RFC] embryo of type/main_type pretty_printing...

Joel Brobecker brobecker@adacore.com
Sun Dec 20 07:41:00 GMT 2009


As discussed with Daniel and Tom on IRC, I started looking at writing
pretty printers for struct type and struct main_type.  I have not fully
tested it yet, just with various integer types (not even range types).
It's just a prototype at this stage.  But before finishing this up,
I want to finish up the patch I have been working on on-and-off, that
will provide a discriminant for the type-specific stuff, making it
easier to print the right component for type_specific.

Eventually, I think it'd be nice if we printed the data even more
intelligently, omitting fields that are not relevant for the given
type_code for instance. Or perhaps, we might want to leave the
C-like representation, and show something more synthetic, tailored
for each type kind.

Here is a transcript with the current version:

    (top-gdb) p *type
    $2 = 
    {pointer_type = 0x0,
     reference_type = 0x0,
     chain = 0x0,
     instance_flags = 0x443 [CONST|VOLATILE|UNSIGNED|STATIC],
     length = 4,
     main_type = 0xc8dcd0}

Not much to show off, in this case, except that the pretty-printer
prints a decoded version of the instance_flags. Always nice when
one looks at them.

And then, trying to print *type.main_type:

    $4 = 
    {name = 0xc8dd20 "int",
     tag_name = 0x0,
     code = TYPE_CODE_INT,
     flags = [unsigned|static|objfile_owned],
     owner = 0xcfd450 (objfile),
     target_type = 0x0,
     vptr_basetype = 0x0}

I've only tested with TYPE_CODE_INT, right now, so it's probably
still buggy as is with other types, in particular when fields or
bounds are involved. I will look at that if no one else beats me
to it, but after I have introduced the type_specific discriminant.

Enjoy! Suggestions and comments welcome.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gdb-gdb.py
Type: text/x-python
Size: 9587 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20091220/2cd760ed/attachment.py>

More information about the Gdb-patches mailing list