aboutsummaryrefslogtreecommitdiff
path: root/gdb/c-valprint.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2012-01-16 19:44:16 +0000
committerTom Tromey <tromey@redhat.com>2012-01-16 19:44:16 +0000
commitcafec441901459c36ad92f1cd9eef648534ea53b (patch)
tree4cd1a43ea2f36c655c39948c0b0e163874bb2e24 /gdb/c-valprint.c
parent983af33b2623508a921372f02abee87aad9c8915 (diff)
downloadgdb-cafec441901459c36ad92f1cd9eef648534ea53b.zip
gdb-cafec441901459c36ad92f1cd9eef648534ea53b.tar.gz
gdb-cafec441901459c36ad92f1cd9eef648534ea53b.tar.bz2
gdb
PR python/13281: * gdbtypes.h (TYPE_FLAG_ENUM): New macro. (struct main_type) <flag_flag_enum>: New field. * dwarf2read.c (process_enumeration_scope): Detect "flag" enums. * NEWS: Add entries. * c-valprint.c (c_val_print) <TYPE_CODE_ENUM>: Handle "flag" enums. * python/lib/gdb/printing.py (_EnumInstance): New class. (FlagEnumerationPrinter): Likewise. gdb/doc * gdb.texinfo (gdb.printing): Document FlagEnumerationPrinter. gdb/testsuite * gdb.base/printcmds.c (enum flag_enum): New. (three): New global. * gdb.base/printcmds.exp (test_print_enums): Add test for flag enum printing. * gdb.python/py-pp-maint.py (build_pretty_printer): Instantiate FlagEnumerationPrinter. * gdb.python/py-pp-maint.exp: Add tests for FlagEnumerationPrinter. * gdb.python/py-pp-maint.c (enum flag_enum): New. (fval): New global.
Diffstat (limited to 'gdb/c-valprint.c')
-rw-r--r--gdb/c-valprint.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index 9949015..82551e9 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -456,10 +456,41 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
{
fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
}
- else
+ else if (TYPE_FLAG_ENUM (type))
{
- print_longest (stream, 'd', 0, val);
+ int first = 1;
+
+ /* We have a "flag" enum, so we try to decompose it into
+ pieces as appropriate. A flag enum has disjoint
+ constants by definition. */
+ fputs_filtered ("(", stream);
+ for (i = 0; i < len; ++i)
+ {
+ QUIT;
+
+ if ((val & TYPE_FIELD_BITPOS (type, i)) != 0)
+ {
+ if (!first)
+ fputs_filtered (" | ", stream);
+ first = 0;
+
+ val &= ~TYPE_FIELD_BITPOS (type, i);
+ fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
+ }
+ }
+
+ if (first || val != 0)
+ {
+ if (!first)
+ fputs_filtered (" | ", stream);
+ fputs_filtered ("unknown: ", stream);
+ print_longest (stream, 'd', 0, val);
+ }
+
+ fputs_filtered (")", stream);
}
+ else
+ print_longest (stream, 'd', 0, val);
break;
case TYPE_CODE_FLAGS: