[PATCH] Allow 64-bit enum values

Siddhesh Poyarekar
2012-03-21T10:06:03Z

Hi,

I took a separate approach from the one I took in:

http://sourceware.org/ml/gdb-patches/2012-02/msg00403.html

and removed the overloaded meaning of the bitpos location variable to
fix PR symtab/7259. In the following patch, I introduce a separate
field_location union member 'enumval' which can accept LONGEST and
hence expand enum values to 64-bit signed values. With this change,
bitpos now only is used for (non-negative) offsets into structures,
since the other overload of bitpos (range bounds) were already
separated into struct range_bound.

I have used the enum test from the PR here, so I will try to write
another test for the bitpos expansion for large struct offsets.

Regards,
Siddhesh

ChangeLog:

2012-03-21 Siddhesh Poyarekar <siddhesh@redhat.com>

PR symtab/7259:
* gdbtypes.h (enum field_loc_kind): New
FIELD_LOC_KIND_ENUMVAL.
(struct main_type.fields): Adjust loc_kind and bitsize to
accommodate FIELD_LOC_KIND_ENUMVAL.
(struct main_type.fields.field_location): New enumval.
New macros: FIELD_ENUMVAL, SET_FIELD_ENUMVAL and
TYPE_FIELD_ENUMVAL.
* ada-exp.y (convert_char_literal): use TYPE_FIELD_ENUMVAL.
* ada-lang.c (ada_discrete_type_high_bound): Ditto.
(ada_discrete_type_low_bound, value_val_atr): Ditto.
(ada_identical_enum_types_p, pos_atr): Ditto.
* ada-typeprint.c (print_enum_type): Ditto.
* ada-valprint.c (print_optional_low_bound): Ditto.
(ada_print_scalar, ada_val_print_1): Ditto.
* c-typeprint.c (c_type_print_base): Ditto.
* coffread.c (coff_read_enum_type): Ditto.
* dwarf2read.c (process_enumeration_scope): Ditto.
* gdb-gdb.py (class StructMainTypePrettyPrinter): Ditto.
* gdbtypes.c (get_discrete_bounds): Ditto
(recursive_dump_type, copy_type_recursive): Ditto.
* m2-typeprint.c (m2_enum): Ditto.
* mdebugread.c (parse_symbol): Ditto.
* p-typeprint.c (pascal_type_print_base): Ditto.
* python/py-type.c (check_types_equal): Ditto.
* stabsread.c (read_enum_type): Ditto.
* typepint.c (print_type_scalar): Ditto.
* valprint.c (generic_val_print): Ditto.

testsuite/ChangeLog:

2012-03-21 Siddhesh Poyarekar <siddhesh@redhat.com>

PR symtab/7259:
* gdb.base/enumval.exp: New test case.
* gdb.base/enumval.c: New test case.

diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 226cc1d..ef052d7 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -1458,7 +1458,7 @@ convert_char_literal (struct type *type, LONGEST val)
for (f = 0; f < TYPE_NFIELDS (type); f += 1)
{
if (strcmp (name, TYPE_FIELD_NAME (type, f)) == 0)
- return TYPE_FIELD_BITPOS (type, f);
+ return TYPE_FIELD_ENUMVAL (type, f);
}
return val;
}
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 78a0261..5d77b1a 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -690,7 +690,7 @@ ada_discrete_type_high_bound (struct type *type)
case TYPE_CODE_RANGE:
return TYPE_HIGH_BOUND (type);
case TYPE_CODE_ENUM:
- return TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1);
+ return TYPE_FIELD_ENUMVAL (type, TYPE_NFIELDS (type) - 1);
case TYPE_CODE_BOOL:
return 1;
case TYPE_CODE_CHAR:
@@ -701,7 +701,7 @@ ada_discrete_type_high_bound (struct type *type)
}
}

-/* The largest value in the domain of TYPE, a discrete type, as an integer. */
+/* The smallest value in the domain of TYPE, a discrete type, as an integer. */
LONGEST
ada_discrete_type_low_bound (struct type *type)
{
@@ -710,7 +710,7 @@ ada_discrete_type_low_bound (struct type *type)
case TYPE_CODE_RANGE:
return TYPE_LOW_BOUND (type);
case TYPE_CODE_ENUM:
- return TYPE_FIELD_BITPOS (type, 0);
+ return TYPE_FIELD_ENUMVAL (type, 0);
case TYPE_CODE_BOOL:
return 0;
case TYPE_CODE_CHAR:
@@ -4479,7 +4479,7 @@ ada_identical_enum_types_p (struct type *type1, struct type *type2)

/* All enums in the type should have an identical underlying value. */
for (i = 0; i < TYPE_NFIELDS (type1); i++)
- if (TYPE_FIELD_BITPOS (type1, i) != TYPE_FIELD_BITPOS (type2, i))
+ if (TYPE_FIELD_ENUMVAL (type1, i) != TYPE_FIELD_ENUMVAL (type2, i))
return 0;

/* All enumerals should also have the same name (modulo any numerical
@@ -8284,7 +8284,7 @@ pos_atr (struct value *arg)

for (i = 0; i < TYPE_NFIELDS (type); i += 1)
{
- if (v == TYPE_FIELD_BITPOS (type, i))
+ if (v == TYPE_FIELD_ENUMVAL (type, i))
return i;
}
error (_("enumeration value is invalid: can't find 'POS"));
@@ -8315,7 +8315,7 @@ value_val_atr (struct type *type, struct value *arg)

if (pos < 0 || pos >= TYPE_NFIELDS (type))
error (_("argument to 'VAL out of range"));
- return value_from_longest (type, TYPE_FIELD_BITPOS (type, pos));
+ return value_from_longest (type, TYPE_FIELD_ENUMVAL (type, pos));
}
else
return value_from_longest (type, value_as_long (arg));
diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index 5599278..40f3058 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -274,7 +274,8 @@ static void
print_enum_type (struct type *type, struct ui_file *stream)
{
int len = TYPE_NFIELDS (type);
- int i, lastval;
+ int i;
+ LONGEST lastval;

fprintf_filtered (stream, "(");
wrap_here (" ");
@@ -287,10 +288,11 @@ print_enum_type (struct type *type, struct ui_file *stream)
fprintf_filtered (stream, ", ");
wrap_here (" ");
fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream);
- if (lastval != TYPE_FIELD_BITPOS (type, i))
+ if (lastval != TYPE_FIELD_ENUMVAL (type, i))
{
- fprintf_filtered (stream, " => %d", TYPE_FIELD_BITPOS (type, i));
- lastval = TYPE_FIELD_BITPOS (type, i);
+ fprintf_filtered (stream, " => %s",
+ plongest (TYPE_FIELD_ENUMVAL (type, i)));
+ lastval = TYPE_FIELD_ENUMVAL (type, i);
}
lastval += 1;
}
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index a8351dd..72c6863 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -109,7 +109,7 @@ print_optional_low_bound (struct ui_file *stream, struct type *type,
return 0;
break;
case TYPE_CODE_ENUM:
- if (low_bound == TYPE_FIELD_BITPOS (index_type, 0))
+ if (low_bound == TYPE_FIELD_ENUMVAL (index_type, 0))
return 0;
break;
case TYPE_CODE_UNDEF:
@@ -402,7 +402,7 @@ ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
len = TYPE_NFIELDS (type);
for (i = 0; i < len; i++)
{
- if (TYPE_FIELD_BITPOS (type, i) == val)
+ if (TYPE_FIELD_ENUMVAL (type, i) == val)
{
break;
}
@@ -822,7 +822,7 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr,
for (i = 0; i < len; i++)
{
QUIT;
- if (val == TYPE_FIELD_BITPOS (type, i))
+ if (val == TYPE_FIELD_ENUMVAL (type, i))
{
break;
}
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 21887c6..7de7b12 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -717,7 +717,6 @@ c_type_print_base (struct type *type, struct ui_file *stream,
{
int i;
int len, real_len;
- int lastval;
enum
{
s_none, s_public, s_private, s_protected
@@ -1194,9 +1193,9 @@ c_type_print_base (struct type *type, struct ui_file *stream,
}
else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
{
+ LONGEST lastval = 0;
fprintf_filtered (stream, "{");
len = TYPE_NFIELDS (type);
- lastval = 0;
for (i = 0; i < len; i++)
{
QUIT;
@@ -1204,11 +1203,11 @@ c_type_print_base (struct type *type, struct ui_file *stream,
fprintf_filtered (stream, ", ");
wrap_here (" ");
fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
- if (lastval != TYPE_FIELD_BITPOS (type, i))
+ if (lastval != TYPE_FIELD_ENUMVAL (type, i))
{
- fprintf_filtered (stream, " = %d",
- TYPE_FIELD_BITPOS (type, i));
- lastval = TYPE_FIELD_BITPOS (type, i);
+ fprintf_filtered (stream, " = %s",
+ plongest (TYPE_FIELD_ENUMVAL (type, i)));
+ lastval = TYPE_FIELD_ENUMVAL (type, i);
}
lastval++;
}
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 30bf3f7..7c59535 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -2159,7 +2159,7 @@ coff_read_enum_type (int index, int length, int lastsym,

SYMBOL_TYPE (xsym) = type;
TYPE_FIELD_NAME (type, n) = SYMBOL_LINKAGE_NAME (xsym);
- SET_FIELD_BITPOS (TYPE_FIELD (type, n), SYMBOL_VALUE (xsym));
+ SET_FIELD_ENUMVAL (TYPE_FIELD (type, n), SYMBOL_VALUE (xsym));
if (SYMBOL_VALUE (xsym) < 0)
unsigned_enum = 0;
TYPE_FIELD_BITSIZE (type, n) = 0;
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 4b49484..9fa7678 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8047,7 +8047,7 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)

FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
FIELD_TYPE (fields[num_fields]) = NULL;
- SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
+ SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym));
FIELD_BITSIZE (fields[num_fields]) = 0;

num_fields++;
diff --git a/gdb/gdb-gdb.py b/gdb/gdb-gdb.py
index 579500f..013bcbb 100644
--- a/gdb/gdb-gdb.py
+++ b/gdb/gdb-gdb.py
@@ -154,6 +154,8 @@ class StructMainTypePrettyPrinter:
loc_kind = str(field_val['loc_kind'])
if loc_kind == "FIELD_LOC_KIND_BITPOS":
return 'bitpos = %d' % loc_val['bitpos']
+ elif loc_kind == "FIELD_LOC_KIND_ENUMVAL":
+ return 'enumval = %d' % loc_val['enumval']
elif loc_kind == "FIELD_LOC_KIND_PHYSADDR":
return 'physaddr = 0x%x' % loc_val['physaddr']
elif loc_kind == "FIELD_LOC_KIND_PHYSNAME":
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index b6e8b4c..a55d93b 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -775,13 +775,13 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
entries. */
int i;

- *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
+ *lowp = *highp = TYPE_FIELD_ENUMVAL (type, 0);
for (i = 0; i < TYPE_NFIELDS (type); i++)
{
- if (TYPE_FIELD_BITPOS (type, i) < *lowp)
- *lowp = TYPE_FIELD_BITPOS (type, i);
- if (TYPE_FIELD_BITPOS (type, i) > *highp)
- *highp = TYPE_FIELD_BITPOS (type, i);
+ if (TYPE_FIELD_ENUMVAL (type, i) < *lowp)
+ *lowp = TYPE_FIELD_ENUMVAL (type, i);
+ if (TYPE_FIELD_ENUMVAL (type, i) > *highp)
+ *highp = TYPE_FIELD_ENUMVAL (type, i);
}

/* Set unsigned indicator if warranted. */
@@ -3197,10 +3197,15 @@ recursive_dump_type (struct type *type, int spaces)
puts_filtered ("\n");
for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
{
- printfi_filtered (spaces + 2,
- "[%d] bitpos %d bitsize %d type ",
- idx, TYPE_FIELD_BITPOS (type, idx),
- TYPE_FIELD_BITSIZE (type, idx));
+ if (TYPE_CODE (type) == TYPE_CODE_ENUM)
+ printfi_filtered (spaces + 2,
+ "[%d] enumval %s type ",
+ idx, plongest (TYPE_FIELD_ENUMVAL (type, idx)));
+ else
+ printfi_filtered (spaces + 2,
+ "[%d] bitpos %d bitsize %d type ",
+ idx, TYPE_FIELD_BITPOS (type, idx),
+ TYPE_FIELD_BITSIZE (type, idx));
gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
printf_filtered (" name '%s' (",
TYPE_FIELD_NAME (type, idx) != NULL
@@ -3397,6 +3402,10 @@ copy_type_recursive (struct objfile *objfile,
SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
TYPE_FIELD_BITPOS (type, i));
break;
+ case FIELD_LOC_KIND_ENUMVAL:
+ SET_FIELD_ENUMVAL (TYPE_FIELD (new_type, i),
+ TYPE_FIELD_ENUMVAL (type, i));
+ break;
case FIELD_LOC_KIND_PHYSADDR:
SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
TYPE_FIELD_STATIC_PHYSADDR (type, i));
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 07c3a86..01c62a5 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -351,6 +351,7 @@ enum type_instance_flag_value
enum field_loc_kind
{
FIELD_LOC_KIND_BITPOS, /* bitpos */
+ FIELD_LOC_KIND_ENUMVAL, /* enumval */
FIELD_LOC_KIND_PHYSADDR, /* physaddr */
FIELD_LOC_KIND_PHYSNAME, /* physname */
FIELD_LOC_KIND_DWARF_BLOCK /* dwarf_block */
@@ -511,11 +512,13 @@ struct main_type
containing structure. For gdbarch_bits_big_endian=1
targets, it is the bit offset to the MSB. For
gdbarch_bits_big_endian=0 targets, it is the bit offset to
- the LSB. For a range bound or enum value, this is the
- value itself. */
+ the LSB. */

int bitpos;

+ /* Enum value. */
+ LONGEST enumval;
+
/* For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then physaddr
is the location (in the target) of the static field.
Otherwise, physname is the mangled label of the static field. */
@@ -538,7 +541,7 @@ struct main_type
unsigned int artificial : 1;

/* Discriminant for union field_location. */
- ENUM_BITFIELD(field_loc_kind) loc_kind : 2;
+ ENUM_BITFIELD(field_loc_kind) loc_kind : 3;

/* Size of this field, in bits, or zero if not packed.
If non-zero in an array type, indicates the element size in
@@ -546,7 +549,7 @@ struct main_type
For an unpacked field, the field's type's length
says how many bytes the field occupies. */

- unsigned int bitsize : 29;
+ unsigned int bitsize : 28;

/* In a struct or union type, type of this field.
In a function or member type, type of this argument.
@@ -931,7 +934,7 @@ struct call_site
union field_location loc;

/* Discriminant for union field_location. */
- ENUM_BITFIELD(field_loc_kind) loc_kind : 2;
+ ENUM_BITFIELD(field_loc_kind) loc_kind : 3;
}
target;

@@ -1088,12 +1091,16 @@ extern void allocate_gnat_aux_type (struct type *);
#define FIELD_NAME(thisfld) ((thisfld).name)
#define FIELD_LOC_KIND(thisfld) ((thisfld).loc_kind)
#define FIELD_BITPOS(thisfld) ((thisfld).loc.bitpos)
+#define FIELD_ENUMVAL(thisfld) ((thisfld).loc.enumval)
#define FIELD_STATIC_PHYSNAME(thisfld) ((thisfld).loc.physname)
#define FIELD_STATIC_PHYSADDR(thisfld) ((thisfld).loc.physaddr)
#define FIELD_DWARF_BLOCK(thisfld) ((thisfld).loc.dwarf_block)
#define SET_FIELD_BITPOS(thisfld, bitpos) \
(FIELD_LOC_KIND (thisfld) = FIELD_LOC_KIND_BITPOS, \
FIELD_BITPOS (thisfld) = (bitpos))
+#define SET_FIELD_ENUMVAL(thisfld, enumval) \
+ (FIELD_LOC_KIND (thisfld) = FIELD_LOC_KIND_ENUMVAL, \
+ FIELD_ENUMVAL (thisfld) = (enumval))
#define SET_FIELD_PHYSNAME(thisfld, name) \
(FIELD_LOC_KIND (thisfld) = FIELD_LOC_KIND_PHYSNAME, \
FIELD_STATIC_PHYSNAME (thisfld) = (name))
@@ -1111,6 +1118,7 @@ extern void allocate_gnat_aux_type (struct type *);
#define TYPE_FIELD_NAME(thistype, n) FIELD_NAME(TYPE_FIELD(thistype, n))
#define TYPE_FIELD_LOC_KIND(thistype, n) FIELD_LOC_KIND (TYPE_FIELD (thistype, n))
#define TYPE_FIELD_BITPOS(thistype, n) FIELD_BITPOS (TYPE_FIELD (thistype, n))
+#define TYPE_FIELD_ENUMVAL(thistype, n) FIELD_ENUMVAL (TYPE_FIELD (thistype, n))
#define TYPE_FIELD_STATIC_PHYSNAME(thistype, n) FIELD_STATIC_PHYSNAME (TYPE_FIELD (thistype, n))
#define TYPE_FIELD_STATIC_PHYSADDR(thistype, n) FIELD_STATIC_PHYSADDR (TYPE_FIELD (thistype, n))
#define TYPE_FIELD_DWARF_BLOCK(thistype, n) FIELD_DWARF_BLOCK (TYPE_FIELD (thistype, n))
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index 9735d7f..fb3d49c 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -607,10 +607,11 @@ m2_enum (struct type *type, struct ui_file *stream, int show, int level)
fprintf_filtered (stream, ", ");
wrap_here (" ");
fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
- if (lastval != TYPE_FIELD_BITPOS (type, i))
+ if (lastval != TYPE_FIELD_ENUMVAL (type, i))
{
- fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
- lastval = TYPE_FIELD_BITPOS (type, i);
+ fprintf_filtered (stream, " = %s",
+ plongest (TYPE_FIELD_ENUMVAL (type, i)));
+ lastval = TYPE_FIELD_ENUMVAL (type, i);
}
lastval++;
}
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 299e94c..a20f953 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1047,7 +1047,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
if (tsym.st != stMember)
break;

- SET_FIELD_BITPOS (*f, tsym.value);
+ SET_FIELD_ENUMVAL (*f, tsym.value);
FIELD_TYPE (*f) = t;
FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss;
FIELD_BITSIZE (*f) = 0;
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index bc24495..a00f5b3 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -750,11 +750,12 @@ pascal_type_print_base (struct type *type, struct ui_file *stream, int show,
fprintf_filtered (stream, ", ");
wrap_here (" ");
fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
- if (lastval != TYPE_FIELD_BITPOS (type, i))
+ if (lastval != TYPE_FIELD_ENUMVAL (type, i))
{
fprintf_filtered (stream,
- " := %d", TYPE_FIELD_BITPOS (type, i));
- lastval = TYPE_FIELD_BITPOS (type, i);
+ " := %s",
+ plongest (TYPE_FIELD_ENUMVAL (type, i)));
+ lastval = TYPE_FIELD_ENUMVAL (type, i);
}
lastval++;
}
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index d47d4c8..701c457 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1018,6 +1018,10 @@ check_types_equal (struct type *type1, struct type *type2,
if (FIELD_BITPOS (*field1) != FIELD_BITPOS (*field2))
return Py_NE;
break;
+ case FIELD_LOC_KIND_ENUMVAL:
+ if (FIELD_ENUMVAL (*field1) != FIELD_ENUMVAL (*field2))
+ return Py_NE;
+ break;
case FIELD_LOC_KIND_PHYSADDR:
if (FIELD_STATIC_PHYSADDR (*field1)
!= FIELD_STATIC_PHYSADDR (*field2))
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index ac82652..bfd6c2e 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -3730,7 +3730,7 @@ read_enum_type (char **pp, struct type *type,

SYMBOL_TYPE (xsym) = type;
TYPE_FIELD_NAME (type, n) = SYMBOL_LINKAGE_NAME (xsym);
- TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
+ TYPE_FIELD_ENUMVAL (type, n) = SYMBOL_VALUE (xsym);
TYPE_FIELD_BITSIZE (type, n) = 0;
}
if (syms == osyms)
diff --git a/gdb/testsuite/gdb.base/enumval.c b/gdb/testsuite/gdb.base/enumval.c
new file mode 100644
index 0000000..790d86c
--- /dev/null
+++ b/gdb/testsuite/gdb.base/enumval.c
@@ -0,0 +1,30 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2012 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+enum e { I, J = 0xffffffffU } e = J;
+
+void
+dummy()
+{
+}
+
+int
+main(void)
+{
+ dummy();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/enumval.exp b/gdb/testsuite/gdb.base/enumval.exp
new file mode 100644
index 0000000..5ec7950
--- /dev/null
+++ b/gdb/testsuite/gdb.base/enumval.exp
@@ -0,0 +1,29 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+set testfile "enumval"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+if { [prepare_for_testing enumval.exp "enumval" "" {debug}] } {
+ return -1
+}
+
+# Check the real contents.
+gdb_test "print e" "= J"
+
+gdb_test "print J" "= J"
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index f257f47..c25e705 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -206,7 +206,7 @@ print_type_scalar (struct type *type, LONGEST val, struct ui_file *stream)
len = TYPE_NFIELDS (type);
for (i = 0; i < len; i++)
{
- if (TYPE_FIELD_BITPOS (type, i) == val)
+ if (TYPE_FIELD_ENUMVAL (type, i) == val)
{
break;
}
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 0037cb9..fdbd3e6 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -453,7 +453,7 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
for (i = 0; i < len; i++)
{
QUIT;
- if (val == TYPE_FIELD_BITPOS (type, i))
+ if (val == TYPE_FIELD_ENUMVAL (type, i))
{
break;
}
@@ -474,13 +474,13 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
{
QUIT;

- if ((val & TYPE_FIELD_BITPOS (type, i)) != 0)
+ if ((val & TYPE_FIELD_ENUMVAL (type, i)) != 0)
{
if (!first)
fputs_filtered (" | ", stream);
first = 0;

- val &= ~TYPE_FIELD_BITPOS (type, i);
+ val &= ~TYPE_FIELD_ENUMVAL (type, i);
fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
}
}