This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Pretty-printers for members can't be influenced by pretty-printers for their containing structure
- From: Tom Tromey <tromey at redhat dot com>
- To: Jim Blandy <jimb at red-bean dot com>
- Cc: gdb ml <gdb at sourceware dot org>
- Date: Wed, 28 Nov 2012 11:59:10 -0700
- Subject: Re: Pretty-printers for members can't be influenced by pretty-printers for their containing structure
- References: <CAHgb+0=rnEUHksnXov=MJnGxw0LGCix_S4trO-uEA2Rade9w2g@mail.gmail.com>
>>>>> "Jim" == Jim Blandy <jimb@red-bean.com> writes:
Jim> Mozilla's JavaScript engine uses a number of struct types that contain
Jim> unions. I'd like to define a pretty-printer such that the dead union
Jim> branches simply don't show up. Here's an example, from our string
Jim> representation.
Jim> Certainly, I can write a pretty-printer that just generates a
Jim> string like this:
Jim> { lengthAndFlags = blah, u1 = { left = blah }, s = { right = blah } ... }
Jim> Unfortunately, I can't do that. The pretty-printer for JSString::Data
Jim> can report 'u1' as one of its children, but then when I'm asked to
Jim> create a pretty-printer for that 'u1' value, I have no way of finding
Jim> the JSString::Data instance from which it was extracted. I've lost the
Jim> context I need to make a pretty-printer that lists only 'left' (say)
Jim> as a child, omitting 'chars'.
Couldn't you have 'children' return a list like
[ ('lengthAndFlags', ...), ('u1.chars', ...), ... ]
Jim> One possible fix would be to allow the second element of the 2-tuple
Jim> items produced by the iterator returned by the pretty-printer's
Jim> 'children' method to be a new pretty-printer. The set of Python values
Jim> that GDB will convert to gdb.Values doesn't include any object types,
Jim> so this is unambiguous.
Jim> How does this sound? Am I looking for a solution in the wrong place?
Jim> Is there a better way to get what I want?
I think your proposed solution is fine. It's been requested a few
times, and is http://sourceware.org/bugzilla/show_bug.cgi?id=12806
Tom