This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [python][patch] Pretty printers for anonymous types.


Here's a thought for the interface; sorry if it's totally
unimplementable or you've already considered and rejected it.

You currently take a dict of regex->printer pairs, but you're using it
just as a set of pairs since you can't reverse-engineer the regex from
the type. What about, instead, if you let the first element of the
pair be any function from a gdb.Type->bool? Then, assuming that
gdb.Type(x_typedef)==gdb.Type(x), I could look up a type by any of its
typedef names and write a predicate to match it. It's straightforward
to write a generator for such predicates for regexes to maintain
compatibility:

def match_by_regex(regex_str):
  regex = re.compile(regex_str)
  def match(type):
    # Just guessing that str(type) is the right conversion.
    return regex.search(str(type)) is not None
  return match

At least at first glance, matching by any typedef's name seems like it
would be an easier interface than trying to guess the right string for
the type. And it'd be relatively easy to write similar
matcher-generators for templates or more complex type patterns.

Jeffrey

On Fri, Jan 16, 2009 at 6:16 PM, Paul Pluzhnikov <ppluzhnikov@google.com> wrote:
> On Fri, Jan 16, 2009 at 4:49 PM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>>> "Paul" == Paul Pluzhnikov <ppluzhnikov@google.com> writes:
>>
>> Paul> AFAICT, currently there is no way to establish a pretty printer for
>> Paul> 'Foo', because get_type() in python/python.c answers with
>> Paul> "struct { ... }" for either 'f' or 'b'.
>>
>> This needs a patch to the documentation -- the search process is
>> documented.  This is ok with that addition.
>
> Ok...
>
>> One issue I think you will hit is that gdb is fairly aggressive about
>> calling check_typedef.  For instance, value_cast strips typedefs from
>> the target type; so I suspect that "p (Foo *) x" will not do the right
>> thing even with your patch.  This is just something we'll have to
>> (eventually) fix.
>
> You are correct:
>
> (gdb) p *(Foo *)&f
> $1 = {x = 0}         # "custom" pretty-printer did not kick in.
>
> There is a further complication: when the same source is compiled
> in C++ mode, then the 'TYPE_NAME (type) == NULL' condition is
> always false -- the name is set to "<anonymous struct>" by GCC 4.3.1.
>
> I think that's somewhat unfortunate :-(
>
> Yikes!
>
> gcc-4.0.3:  DW_AT_name        : Foo
> gcc-4.1.1:  DW_AT_name        : ._0
> gcc-4.2.2:  DW_AT_name        : ._0
> gcc-4.3.1:  DW_AT_name        : (indirect string, offset: 0x121):
> <anonymous struct>
>
> And we aren't even looking at the typedef anymore:
>
> #3  0x00000000004abfa9 in print_formatted (val=0x1209230, size=0,
> options=0x7fffffffdd80, stream=0xcb7410) at ../../gdb/printcmd.c:305
> 305         value_print (val, stream, options);
> (top) p val.type.main_type[0]
> $15 = {code = TYPE_CODE_STRUCT, flag_unsigned = 0, flag_nosign = 0,
>       flag_stub = 0, flag_target_stub = 0, flag_static = 0,
> flag_prototyped = 0,
>       flag_incomplete = 0, flag_varargs = 0, flag_vector = 0,
>       flag_stub_supported = 1, flag_nottext = 0, flag_fixed_instance = 0,
>       nfields = 1, vptr_fieldno = -1, name = 0xb70b79 "<anonymous struct>",
>       tag_name = 0xb70b79 "<anonymous struct>", objfile = 0xbbab50,
>       target_type = 0x0, fields = 0xb10b08, vptr_basetype = 0x0,
>       type_specific = {cplus_stuff = 0xa10040, floatformat = 0xa10040,
>       calling_convention = 10551360}}
>
> Given that C/C++ consistency is desirable, but dealing with
> anonymous C++ structs will clearly take a lot more work, should I
> still commit this (with doc update), or file a gdb-archer PR in bugzilla?
>
> Thanks,
> --
> Paul Pluzhnikov
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]