Re: Option to elide single-bit bitfields when printing structures

Michael Snyder
2001-02-23T10:09:00Z

Eli Zaretskii wrote:
>
> > From: "Zack Weinberg" <zackw@stanford.edu>
> > Date: Thu, 22 Feb 2001 11:56:33 -0800
> >
> > (gdb) p decl->common
> > $1 = {chain = 0x40253000, type = 0x40253138, code = FUNCTION_DECL,
> > side_effects_flag = 0, constant_flag = 0, addressable_flag = 0,
> > volatile_flag = 0, readonly_flag = 0, unsigned_flag = 0,
> > asm_written_flag = 0, used_flag = 0, nothrow_flag = 0, static_flag = 0,
> > public_flag = 1, private_flag = 0, protected_flag = 0, bounded_flag = 0,
> > lang_flag_0 = 0, lang_flag_1 = 0, lang_flag_2 = 0, lang_flag_3 = 0,
> > lang_flag_4 = 0, lang_flag_5 = 0, lang_flag_6 = 0, dummy = 0}
> >
> > It's hard to see which are set and which aren't. With this patch, you
> > can get it printed like this:
> >
> > (gdb) set print elide-bitflags on
> > (gdb) p decl->common
> > $2 = {chain = 0x40253000, type = 0x40253138, code = FUNCTION_DECL, public_flag}
> >
> > which is, IMHO, much easier to read.
>
> What if someone wants to know which flags are _reset_? What if there
> are more than one set flag in your example? What if the bit fields
> span more than one bit? I don't see how your suggestion would deal
> with these cases in a way that the resulting display is
> self-explaining. That trailing "public_flag" is already hard to
> understand; I stared at it for a few moments without understanding
> what's going on here, before it hit me.
>
> Perhaps we need a special command or a special format that would put
> the burden on the user. For example, if the user specifies exactly
> what flags (set or unset) does she want to see, the display doesn't
> need to explain that, because the user asked for it.
>
> > * cp-valprint.c (elide_bitflag_print): New flag.
> > (cp_print_value_fields): If elide_bitflag_print, skip printing
> > single-bit fields whose value is zero entirely, and skip
> > printing the value for single-bit fields whose value is one.
> > (_initialize_cp_valprint): Add 'set print elide-bitflags'
> > command, default to old behavior.
>
> If these changes are approved by the cp-valprint maintainer, please
> add some minimal changes in gdb.texinfo which describe this feature.

I don't think this feature is necessary. This is just an
instance of special display of data. This is what the
gdb scripting language is for.