PR symtab/7259:
	* ada-exp.y (convert_char_literal): Use TYPE_FIELD_ENUMVAL.
	* ada-lang.c (ada_discrete_type_high_bound)
	(ada_discrete_type_low_bound): Use TYPE_FIELD_ENUMVAL for
	TYPE_CODE_ENUM.
	(ada_identical_enum_types_p): Use TYPE_FIELD_ENUMVAL.
	(pos_atr, value_val_atr): Use TYPE_FIELD_ENUMVAL for TYPE_CODE_ENUM.
	* ada-typeprint.c (print_enum_type): Change variable lastval to LONGEST.
	Use TYPE_FIELD_ENUMVAL.
	* ada-valprint.c (print_optional_low_bound, ada_print_scalar)
	(ada_val_print_1): Use TYPE_FIELD_ENUMVAL for TYPE_CODE_ENUM.
	* c-typeprint.c (c_type_print_base): Move variable lastval to inner
	block, change it to LONGEST.  Use TYPE_FIELD_ENUMVAL for
	TYPE_CODE_ENUM.
	* coffread.c (coff_read_enum_type): Use SET_FIELD_ENUMVAL.
	* dwarf2read.c (process_enumeration_scope): Likewise.
	* gdb-gdb.py (TypeFlagsPrinter): Use field.enumval instead of
	field.bitpos.
	(class StructMainTypePrettyPrinter): Support also
	FIELD_LOC_KIND_ENUMVAL.
	* gdbtypes.c (get_discrete_bounds): Use TYPE_FIELD_ENUMVAL for
	TYPE_CODE_ENUM.
	(recursive_dump_type): Use TYPE_FIELD_ENUMVAL for TYPE_CODE_ENUM.
	(copy_type_recursive): Support also FIELD_LOC_KIND_ENUMVAL.
	* gdbtypes.h (enum field_loc_kind): New FIELD_LOC_KIND_ENUMVAL.
	(struct main_type.flds_bnds.fields.loc): Adjust bitpos comment.  New
	field enumval.
	(struct main_type.flds_bnds.bields): Adjust loc_kind and bitsize to
	accommodate enumval.
	(struct call_site): Adjust loc_kind to accommodate enumval.
	(FIELD_ENUMVAL, FIELD_ENUMVAL_LVAL, SET_FIELD_ENUMVAL)
	(TYPE_FIELD_ENUMVAL): New macros.
	* m2-typeprint.c (m2_enum): Use TYPE_FIELD_ENUMVAL.
	* mdebugread.c (parse_symbol): Use TYPE_FIELD_ENUMVAL for
	TYPE_CODE_ENUM.
	* p-typeprint.c (pascal_type_print_base): Likewise.
	* python/lib/gdb/printing.py (class FlagEnumerationPrinter): Use
	enumval.
	* python/lib/gdb/types.py (make_enum_dict): Likewise.
	* python/py-type.c (convert_field): New variable addrstring.  Use
	TYPE_FIELD_ENUMVAL for TYPE_CODE_ENUM.
	(check_types_equal): Support also FIELD_LOC_KIND_ENUMVAL.
	* stabsread.c (read_enum_type): Use SET_FIELD_ENUMVAL.
	* typepint.c (print_type_scalar): Use TYPE_FIELD_ENUMVAL for
	TYPE_CODE_ENUM.
	* valprint.c (generic_val_print): Likewise.

gdb/testsuite/
	PR symtab/7259:
	* gdb.base/enumval.c: New test case.
	* gdb.base/enumval.exp: New test case.
	* gdb.python/py-type.exp (test_enums): Use field.enumval instead of
	field.bitpos.
This commit is contained in:
Jan Kratochvil 2012-04-18 06:46:47 +00:00
parent dcc0705263
commit 14e75d8ea4
22 changed files with 156 additions and 58 deletions

View File

@ -1,3 +1,52 @@
2012-04-18 Siddhesh Poyarekar <siddhesh@redhat.com>
PR symtab/7259:
* ada-exp.y (convert_char_literal): Use TYPE_FIELD_ENUMVAL.
* ada-lang.c (ada_discrete_type_high_bound)
(ada_discrete_type_low_bound): Use TYPE_FIELD_ENUMVAL for
TYPE_CODE_ENUM.
(ada_identical_enum_types_p): Use TYPE_FIELD_ENUMVAL.
(pos_atr, value_val_atr): Use TYPE_FIELD_ENUMVAL for TYPE_CODE_ENUM.
* ada-typeprint.c (print_enum_type): Change variable lastval to LONGEST.
Use TYPE_FIELD_ENUMVAL.
* ada-valprint.c (print_optional_low_bound, ada_print_scalar)
(ada_val_print_1): Use TYPE_FIELD_ENUMVAL for TYPE_CODE_ENUM.
* c-typeprint.c (c_type_print_base): Move variable lastval to inner
block, change it to LONGEST. Use TYPE_FIELD_ENUMVAL for
TYPE_CODE_ENUM.
* coffread.c (coff_read_enum_type): Use SET_FIELD_ENUMVAL.
* dwarf2read.c (process_enumeration_scope): Likewise.
* gdb-gdb.py (TypeFlagsPrinter): Use field.enumval instead of
field.bitpos.
(class StructMainTypePrettyPrinter): Support also
FIELD_LOC_KIND_ENUMVAL.
* gdbtypes.c (get_discrete_bounds): Use TYPE_FIELD_ENUMVAL for
TYPE_CODE_ENUM.
(recursive_dump_type): Use TYPE_FIELD_ENUMVAL for TYPE_CODE_ENUM.
(copy_type_recursive): Support also FIELD_LOC_KIND_ENUMVAL.
* gdbtypes.h (enum field_loc_kind): New FIELD_LOC_KIND_ENUMVAL.
(struct main_type.flds_bnds.fields.loc): Adjust bitpos comment. New
field enumval.
(struct main_type.flds_bnds.bields): Adjust loc_kind and bitsize to
accommodate enumval.
(struct call_site): Adjust loc_kind to accommodate enumval.
(FIELD_ENUMVAL, FIELD_ENUMVAL_LVAL, SET_FIELD_ENUMVAL)
(TYPE_FIELD_ENUMVAL): New macros.
* m2-typeprint.c (m2_enum): Use TYPE_FIELD_ENUMVAL.
* mdebugread.c (parse_symbol): Use TYPE_FIELD_ENUMVAL for
TYPE_CODE_ENUM.
* p-typeprint.c (pascal_type_print_base): Likewise.
* python/lib/gdb/printing.py (class FlagEnumerationPrinter): Use
enumval.
* python/lib/gdb/types.py (make_enum_dict): Likewise.
* python/py-type.c (convert_field): New variable addrstring. Use
TYPE_FIELD_ENUMVAL for TYPE_CODE_ENUM.
(check_types_equal): Support also FIELD_LOC_KIND_ENUMVAL.
* stabsread.c (read_enum_type): Use SET_FIELD_ENUMVAL.
* typepint.c (print_type_scalar): Use TYPE_FIELD_ENUMVAL for
TYPE_CODE_ENUM.
* valprint.c (generic_val_print): Likewise.
2012-04-17 Doug Evans <dje@google.com> 2012-04-17 Doug Evans <dje@google.com>
* dwarf2read.c (lookup_signatured_type): Return NULL instead of 0. * dwarf2read.c (lookup_signatured_type): Return NULL instead of 0.

View File

@ -1463,7 +1463,7 @@ convert_char_literal (struct type *type, LONGEST val)
for (f = 0; f < TYPE_NFIELDS (type); f += 1) for (f = 0; f < TYPE_NFIELDS (type); f += 1)
{ {
if (strcmp (name, TYPE_FIELD_NAME (type, f)) == 0) if (strcmp (name, TYPE_FIELD_NAME (type, f)) == 0)
return TYPE_FIELD_BITPOS (type, f); return TYPE_FIELD_ENUMVAL (type, f);
} }
return val; return val;
} }

View File

@ -690,7 +690,7 @@ ada_discrete_type_high_bound (struct type *type)
case TYPE_CODE_RANGE: case TYPE_CODE_RANGE:
return TYPE_HIGH_BOUND (type); return TYPE_HIGH_BOUND (type);
case TYPE_CODE_ENUM: 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: case TYPE_CODE_BOOL:
return 1; return 1;
case TYPE_CODE_CHAR: 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 LONGEST
ada_discrete_type_low_bound (struct type *type) ada_discrete_type_low_bound (struct type *type)
{ {
@ -710,7 +710,7 @@ ada_discrete_type_low_bound (struct type *type)
case TYPE_CODE_RANGE: case TYPE_CODE_RANGE:
return TYPE_LOW_BOUND (type); return TYPE_LOW_BOUND (type);
case TYPE_CODE_ENUM: case TYPE_CODE_ENUM:
return TYPE_FIELD_BITPOS (type, 0); return TYPE_FIELD_ENUMVAL (type, 0);
case TYPE_CODE_BOOL: case TYPE_CODE_BOOL:
return 0; return 0;
case TYPE_CODE_CHAR: 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. */ /* All enums in the type should have an identical underlying value. */
for (i = 0; i < TYPE_NFIELDS (type1); i++) 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; return 0;
/* All enumerals should also have the same name (modulo any numerical /* All enumerals should also have the same name (modulo any numerical
@ -8298,7 +8298,7 @@ pos_atr (struct value *arg)
for (i = 0; i < TYPE_NFIELDS (type); i += 1) 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; return i;
} }
error (_("enumeration value is invalid: can't find 'POS")); error (_("enumeration value is invalid: can't find 'POS"));
@ -8329,7 +8329,7 @@ value_val_atr (struct type *type, struct value *arg)
if (pos < 0 || pos >= TYPE_NFIELDS (type)) if (pos < 0 || pos >= TYPE_NFIELDS (type))
error (_("argument to 'VAL out of range")); 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 else
return value_from_longest (type, value_as_long (arg)); return value_from_longest (type, value_as_long (arg));

View File

@ -274,7 +274,8 @@ static void
print_enum_type (struct type *type, struct ui_file *stream) print_enum_type (struct type *type, struct ui_file *stream)
{ {
int len = TYPE_NFIELDS (type); int len = TYPE_NFIELDS (type);
int i, lastval; int i;
LONGEST lastval;
fprintf_filtered (stream, "("); fprintf_filtered (stream, "(");
wrap_here (" "); wrap_here (" ");
@ -287,10 +288,11 @@ print_enum_type (struct type *type, struct ui_file *stream)
fprintf_filtered (stream, ", "); fprintf_filtered (stream, ", ");
wrap_here (" "); wrap_here (" ");
fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream); 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)); fprintf_filtered (stream, " => %s",
lastval = TYPE_FIELD_BITPOS (type, i); plongest (TYPE_FIELD_ENUMVAL (type, i)));
lastval = TYPE_FIELD_ENUMVAL (type, i);
} }
lastval += 1; lastval += 1;
} }

View File

@ -109,7 +109,7 @@ print_optional_low_bound (struct ui_file *stream, struct type *type,
return 0; return 0;
break; break;
case TYPE_CODE_ENUM: case TYPE_CODE_ENUM:
if (low_bound == TYPE_FIELD_BITPOS (index_type, 0)) if (low_bound == TYPE_FIELD_ENUMVAL (index_type, 0))
return 0; return 0;
break; break;
case TYPE_CODE_UNDEF: case TYPE_CODE_UNDEF:
@ -402,7 +402,7 @@ ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
len = TYPE_NFIELDS (type); len = TYPE_NFIELDS (type);
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
if (TYPE_FIELD_BITPOS (type, i) == val) if (TYPE_FIELD_ENUMVAL (type, i) == val)
{ {
break; break;
} }
@ -824,7 +824,7 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr,
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
QUIT; QUIT;
if (val == TYPE_FIELD_BITPOS (type, i)) if (val == TYPE_FIELD_ENUMVAL (type, i))
{ {
break; break;
} }

View File

@ -717,7 +717,6 @@ c_type_print_base (struct type *type, struct ui_file *stream,
{ {
int i; int i;
int len, real_len; int len, real_len;
int lastval;
enum enum
{ {
s_none, s_public, s_private, s_protected s_none, s_public, s_private, s_protected
@ -1194,9 +1193,10 @@ c_type_print_base (struct type *type, struct ui_file *stream,
} }
else if (show > 0 || TYPE_TAG_NAME (type) == NULL) else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
{ {
LONGEST lastval = 0;
fprintf_filtered (stream, "{"); fprintf_filtered (stream, "{");
len = TYPE_NFIELDS (type); len = TYPE_NFIELDS (type);
lastval = 0;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
QUIT; QUIT;
@ -1204,11 +1204,11 @@ c_type_print_base (struct type *type, struct ui_file *stream,
fprintf_filtered (stream, ", "); fprintf_filtered (stream, ", ");
wrap_here (" "); wrap_here (" ");
fputs_filtered (TYPE_FIELD_NAME (type, i), stream); 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", fprintf_filtered (stream, " = %s",
TYPE_FIELD_BITPOS (type, i)); plongest (TYPE_FIELD_ENUMVAL (type, i)));
lastval = TYPE_FIELD_BITPOS (type, i); lastval = TYPE_FIELD_ENUMVAL (type, i);
} }
lastval++; lastval++;
} }

View File

@ -2159,7 +2159,7 @@ coff_read_enum_type (int index, int length, int lastsym,
SYMBOL_TYPE (xsym) = type; SYMBOL_TYPE (xsym) = type;
TYPE_FIELD_NAME (type, n) = SYMBOL_LINKAGE_NAME (xsym); 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) if (SYMBOL_VALUE (xsym) < 0)
unsigned_enum = 0; unsigned_enum = 0;
TYPE_FIELD_BITSIZE (type, n) = 0; TYPE_FIELD_BITSIZE (type, n) = 0;

View File

@ -8051,7 +8051,7 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
FIELD_TYPE (fields[num_fields]) = NULL; 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; FIELD_BITSIZE (fields[num_fields]) = 0;
num_fields++; num_fields++;

View File

@ -99,10 +99,10 @@ class TypeFlagsPrinter:
return return
# Note: TYPE_FLAG_MIN is a duplicate of TYPE_FLAG_UNSIGNED, # Note: TYPE_FLAG_MIN is a duplicate of TYPE_FLAG_UNSIGNED,
# so exclude it from the list we are building. # so exclude it from the list we are building.
TYPE_FLAGS = [TypeFlag(field.name, field.bitpos) TYPE_FLAGS = [TypeFlag(field.name, field.enumval)
for field in flags.fields() for field in flags.fields()
if field.name != 'TYPE_FLAG_MIN'] if field.name != 'TYPE_FLAG_MIN']
TYPE_FLAGS += [TypeFlag(field.name, field.bitpos) TYPE_FLAGS += [TypeFlag(field.name, field.enumval)
for field in iflags.fields()] for field in iflags.fields()]
TYPE_FLAGS.sort() TYPE_FLAGS.sort()
@ -154,6 +154,8 @@ class StructMainTypePrettyPrinter:
loc_kind = str(field_val['loc_kind']) loc_kind = str(field_val['loc_kind'])
if loc_kind == "FIELD_LOC_KIND_BITPOS": if loc_kind == "FIELD_LOC_KIND_BITPOS":
return 'bitpos = %d' % loc_val['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": elif loc_kind == "FIELD_LOC_KIND_PHYSADDR":
return 'physaddr = 0x%x' % loc_val['physaddr'] return 'physaddr = 0x%x' % loc_val['physaddr']
elif loc_kind == "FIELD_LOC_KIND_PHYSNAME": elif loc_kind == "FIELD_LOC_KIND_PHYSNAME":

View File

@ -775,13 +775,13 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
entries. */ entries. */
int i; int i;
*lowp = *highp = TYPE_FIELD_BITPOS (type, 0); *lowp = *highp = TYPE_FIELD_ENUMVAL (type, 0);
for (i = 0; i < TYPE_NFIELDS (type); i++) for (i = 0; i < TYPE_NFIELDS (type); i++)
{ {
if (TYPE_FIELD_BITPOS (type, i) < *lowp) if (TYPE_FIELD_ENUMVAL (type, i) < *lowp)
*lowp = TYPE_FIELD_BITPOS (type, i); *lowp = TYPE_FIELD_ENUMVAL (type, i);
if (TYPE_FIELD_BITPOS (type, i) > *highp) if (TYPE_FIELD_ENUMVAL (type, i) > *highp)
*highp = TYPE_FIELD_BITPOS (type, i); *highp = TYPE_FIELD_ENUMVAL (type, i);
} }
/* Set unsigned indicator if warranted. */ /* Set unsigned indicator if warranted. */
@ -3197,10 +3197,15 @@ recursive_dump_type (struct type *type, int spaces)
puts_filtered ("\n"); puts_filtered ("\n");
for (idx = 0; idx < TYPE_NFIELDS (type); idx++) for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
{ {
printfi_filtered (spaces + 2, if (TYPE_CODE (type) == TYPE_CODE_ENUM)
"[%d] bitpos %d bitsize %d type ", printfi_filtered (spaces + 2,
idx, TYPE_FIELD_BITPOS (type, idx), "[%d] enumval %s type ",
TYPE_FIELD_BITSIZE (type, idx)); 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); gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
printf_filtered (" name '%s' (", printf_filtered (" name '%s' (",
TYPE_FIELD_NAME (type, idx) != NULL TYPE_FIELD_NAME (type, idx) != NULL
@ -3397,6 +3402,10 @@ copy_type_recursive (struct objfile *objfile,
SET_FIELD_BITPOS (TYPE_FIELD (new_type, i), SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
TYPE_FIELD_BITPOS (type, i)); TYPE_FIELD_BITPOS (type, i));
break; 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: case FIELD_LOC_KIND_PHYSADDR:
SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i), SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
TYPE_FIELD_STATIC_PHYSADDR (type, i)); TYPE_FIELD_STATIC_PHYSADDR (type, i));

View File

@ -351,6 +351,7 @@ enum type_instance_flag_value
enum field_loc_kind enum field_loc_kind
{ {
FIELD_LOC_KIND_BITPOS, /* bitpos */ FIELD_LOC_KIND_BITPOS, /* bitpos */
FIELD_LOC_KIND_ENUMVAL, /* enumval */
FIELD_LOC_KIND_PHYSADDR, /* physaddr */ FIELD_LOC_KIND_PHYSADDR, /* physaddr */
FIELD_LOC_KIND_PHYSNAME, /* physname */ FIELD_LOC_KIND_PHYSNAME, /* physname */
FIELD_LOC_KIND_DWARF_BLOCK /* dwarf_block */ FIELD_LOC_KIND_DWARF_BLOCK /* dwarf_block */
@ -511,11 +512,13 @@ struct main_type
containing structure. For gdbarch_bits_big_endian=1 containing structure. For gdbarch_bits_big_endian=1
targets, it is the bit offset to the MSB. For targets, it is the bit offset to the MSB. For
gdbarch_bits_big_endian=0 targets, it is the bit offset to gdbarch_bits_big_endian=0 targets, it is the bit offset to
the LSB. For a range bound or enum value, this is the the LSB. */
value itself. */
int bitpos; int bitpos;
/* Enum value. */
LONGEST enumval;
/* For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then physaddr /* For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then physaddr
is the location (in the target) of the static field. is the location (in the target) of the static field.
Otherwise, physname is the mangled label 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; unsigned int artificial : 1;
/* Discriminant for union field_location. */ /* 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. /* Size of this field, in bits, or zero if not packed.
If non-zero in an array type, indicates the element size in 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 For an unpacked field, the field's type's length
says how many bytes the field occupies. */ 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 struct or union type, type of this field.
In a function or member type, type of this argument. In a function or member type, type of this argument.
@ -931,7 +934,7 @@ struct call_site
union field_location loc; union field_location loc;
/* Discriminant for union field_location. */ /* Discriminant for union field_location. */
ENUM_BITFIELD(field_loc_kind) loc_kind : 2; ENUM_BITFIELD(field_loc_kind) loc_kind : 3;
} }
target; target;
@ -1089,12 +1092,17 @@ extern void allocate_gnat_aux_type (struct type *);
#define FIELD_LOC_KIND(thisfld) ((thisfld).loc_kind) #define FIELD_LOC_KIND(thisfld) ((thisfld).loc_kind)
#define FIELD_BITPOS_LVAL(thisfld) ((thisfld).loc.bitpos) #define FIELD_BITPOS_LVAL(thisfld) ((thisfld).loc.bitpos)
#define FIELD_BITPOS(thisfld) (FIELD_BITPOS_LVAL (thisfld) + 0) #define FIELD_BITPOS(thisfld) (FIELD_BITPOS_LVAL (thisfld) + 0)
#define FIELD_ENUMVAL_LVAL(thisfld) ((thisfld).loc.enumval)
#define FIELD_ENUMVAL(thisfld) (FIELD_ENUMVAL_LVAL (thisfld) + 0)
#define FIELD_STATIC_PHYSNAME(thisfld) ((thisfld).loc.physname) #define FIELD_STATIC_PHYSNAME(thisfld) ((thisfld).loc.physname)
#define FIELD_STATIC_PHYSADDR(thisfld) ((thisfld).loc.physaddr) #define FIELD_STATIC_PHYSADDR(thisfld) ((thisfld).loc.physaddr)
#define FIELD_DWARF_BLOCK(thisfld) ((thisfld).loc.dwarf_block) #define FIELD_DWARF_BLOCK(thisfld) ((thisfld).loc.dwarf_block)
#define SET_FIELD_BITPOS(thisfld, bitpos) \ #define SET_FIELD_BITPOS(thisfld, bitpos) \
(FIELD_LOC_KIND (thisfld) = FIELD_LOC_KIND_BITPOS, \ (FIELD_LOC_KIND (thisfld) = FIELD_LOC_KIND_BITPOS, \
FIELD_BITPOS_LVAL (thisfld) = (bitpos)) FIELD_BITPOS_LVAL (thisfld) = (bitpos))
#define SET_FIELD_ENUMVAL(thisfld, enumval) \
(FIELD_LOC_KIND (thisfld) = FIELD_LOC_KIND_ENUMVAL, \
FIELD_ENUMVAL_LVAL (thisfld) = (enumval))
#define SET_FIELD_PHYSNAME(thisfld, name) \ #define SET_FIELD_PHYSNAME(thisfld, name) \
(FIELD_LOC_KIND (thisfld) = FIELD_LOC_KIND_PHYSNAME, \ (FIELD_LOC_KIND (thisfld) = FIELD_LOC_KIND_PHYSNAME, \
FIELD_STATIC_PHYSNAME (thisfld) = (name)) FIELD_STATIC_PHYSNAME (thisfld) = (name))
@ -1112,6 +1120,7 @@ extern void allocate_gnat_aux_type (struct type *);
#define TYPE_FIELD_NAME(thistype, n) FIELD_NAME(TYPE_FIELD(thistype, n)) #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_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_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_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_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)) #define TYPE_FIELD_DWARF_BLOCK(thistype, n) FIELD_DWARF_BLOCK (TYPE_FIELD (thistype, n))

View File

@ -607,10 +607,11 @@ m2_enum (struct type *type, struct ui_file *stream, int show, int level)
fprintf_filtered (stream, ", "); fprintf_filtered (stream, ", ");
wrap_here (" "); wrap_here (" ");
fputs_filtered (TYPE_FIELD_NAME (type, i), stream); 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)); fprintf_filtered (stream, " = %s",
lastval = TYPE_FIELD_BITPOS (type, i); plongest (TYPE_FIELD_ENUMVAL (type, i)));
lastval = TYPE_FIELD_ENUMVAL (type, i);
} }
lastval++; lastval++;
} }

View File

@ -1047,7 +1047,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
if (tsym.st != stMember) if (tsym.st != stMember)
break; break;
SET_FIELD_BITPOS (*f, tsym.value); SET_FIELD_ENUMVAL (*f, tsym.value);
FIELD_TYPE (*f) = t; FIELD_TYPE (*f) = t;
FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss; FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss;
FIELD_BITSIZE (*f) = 0; FIELD_BITSIZE (*f) = 0;

View File

@ -750,11 +750,12 @@ pascal_type_print_base (struct type *type, struct ui_file *stream, int show,
fprintf_filtered (stream, ", "); fprintf_filtered (stream, ", ");
wrap_here (" "); wrap_here (" ");
fputs_filtered (TYPE_FIELD_NAME (type, i), stream); 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, fprintf_filtered (stream,
" := %d", TYPE_FIELD_BITPOS (type, i)); " := %s",
lastval = TYPE_FIELD_BITPOS (type, i); plongest (TYPE_FIELD_ENUMVAL (type, i)));
lastval = TYPE_FIELD_ENUMVAL (type, i);
} }
lastval++; lastval++;
} }

View File

@ -247,10 +247,10 @@ class FlagEnumerationPrinter(PrettyPrinter):
flags = gdb.lookup_type(self.name) flags = gdb.lookup_type(self.name)
self.enumerators = [] self.enumerators = []
for field in flags.fields(): for field in flags.fields():
self.enumerators.append((field.name, field.bitpos)) self.enumerators.append((field.name, field.enumval))
# Sorting the enumerators by value usually does the right # Sorting the enumerators by value usually does the right
# thing. # thing.
self.enumerators.sort(key = lambda x: x.bitpos) self.enumerators.sort(key = lambda x: x.enumval)
if self.enabled: if self.enabled:
return _EnumInstance(self.enumerators, val) return _EnumInstance(self.enumerators, val)

View File

@ -86,8 +86,8 @@ def make_enum_dict(enum_type):
raise TypeError("not an enum type") raise TypeError("not an enum type")
enum_dict = {} enum_dict = {}
for field in enum_type.fields(): for field in enum_type.fields():
# The enum's value is stored in "bitpos". # The enum's value is stored in "enumval".
enum_dict[field.name] = field.bitpos enum_dict[field.name] = field.enumval
return enum_dict return enum_dict

View File

@ -167,11 +167,23 @@ convert_field (struct type *type, int field)
if (!field_is_static (&TYPE_FIELD (type, field))) if (!field_is_static (&TYPE_FIELD (type, field)))
{ {
arg = PyLong_FromLong (TYPE_FIELD_BITPOS (type, field)); const char *attrstring;
if (TYPE_CODE (type) == TYPE_CODE_ENUM)
{
arg = gdb_py_long_from_longest (TYPE_FIELD_ENUMVAL (type, field));
attrstring = "enumval";
}
else
{
arg = PyLong_FromLong (TYPE_FIELD_BITPOS (type, field));
attrstring = "bitpos";
}
if (!arg) if (!arg)
goto fail; goto fail;
if (PyObject_SetAttrString (result, "bitpos", arg) < 0) if (PyObject_SetAttrString (result, attrstring, arg) < 0)
goto failarg; goto failarg;
} }
@ -1018,6 +1030,10 @@ check_types_equal (struct type *type1, struct type *type2,
if (FIELD_BITPOS (*field1) != FIELD_BITPOS (*field2)) if (FIELD_BITPOS (*field1) != FIELD_BITPOS (*field2))
return Py_NE; return Py_NE;
break; break;
case FIELD_LOC_KIND_ENUMVAL:
if (FIELD_ENUMVAL (*field1) != FIELD_ENUMVAL (*field2))
return Py_NE;
break;
case FIELD_LOC_KIND_PHYSADDR: case FIELD_LOC_KIND_PHYSADDR:
if (FIELD_STATIC_PHYSADDR (*field1) if (FIELD_STATIC_PHYSADDR (*field1)
!= FIELD_STATIC_PHYSADDR (*field2)) != FIELD_STATIC_PHYSADDR (*field2))

View File

@ -3731,7 +3731,7 @@ read_enum_type (char **pp, struct type *type,
SYMBOL_TYPE (xsym) = type; SYMBOL_TYPE (xsym) = type;
TYPE_FIELD_NAME (type, n) = SYMBOL_LINKAGE_NAME (xsym); 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));
TYPE_FIELD_BITSIZE (type, n) = 0; TYPE_FIELD_BITSIZE (type, n) = 0;
} }
if (syms == osyms) if (syms == osyms)

View File

@ -1,3 +1,12 @@
2012-04-18 Siddhesh Poyarekar <siddhesh@redhat.com>
Jan Kratochvil <jan.kratochvil@redhat.com>
PR symtab/7259:
* gdb.base/enumval.c: New test case.
* gdb.base/enumval.exp: New test case.
* gdb.python/py-type.exp (test_enums): Use field.enumval instead of
field.bitpos.
2012-04-17 Pedro Alves <palves@redhat.com> 2012-04-17 Pedro Alves <palves@redhat.com>
* Makefile.in (site.exp): Make site.exp source * Makefile.in (site.exp): Make site.exp source

View File

@ -136,8 +136,8 @@ proc test_enums {} {
gdb_test "python print len(e.type)" "3" "Check the number of enum fields" gdb_test "python print len(e.type)" "3" "Check the number of enum fields"
gdb_test "python print e.type\['v1'\].name" "v1" "Check enum field lookup by name" gdb_test "python print e.type\['v1'\].name" "v1" "Check enum field lookup by name"
gdb_test "python print e.type\['v3'\].name" "v3" "Check enum field lookup by name" gdb_test "python print e.type\['v3'\].name" "v3" "Check enum field lookup by name"
gdb_test "python print \[v.bitpos for v in e.type.itervalues()\]" {\[0L, 1L, 2L\]} "Check num fields iteration over values" gdb_test "python print \[v.enumval for v in e.type.itervalues()\]" {\[0L, 1L, 2L\]} "Check num fields iteration over values"
gdb_test "python print \[(n, v.bitpos) for (n, v) in e.type.items()\]" {\[\('v1', 0L\), \('v2', 1L\), \('v3', 2L\)\]} "Check enum fields items list" gdb_test "python print \[(n, v.enumval) for (n, v) in e.type.items()\]" {\[\('v1', 0L\), \('v2', 1L\), \('v3', 2L\)\]} "Check enum fields items list"
} }
proc test_base_class {} { proc test_base_class {} {
gdb_py_test_silent_cmd "print d" "print value" 1 gdb_py_test_silent_cmd "print d" "print value" 1

View File

@ -206,7 +206,7 @@ print_type_scalar (struct type *type, LONGEST val, struct ui_file *stream)
len = TYPE_NFIELDS (type); len = TYPE_NFIELDS (type);
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
if (TYPE_FIELD_BITPOS (type, i) == val) if (TYPE_FIELD_ENUMVAL (type, i) == val)
{ {
break; break;
} }

View File

@ -445,7 +445,7 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
QUIT; QUIT;
if (val == TYPE_FIELD_BITPOS (type, i)) if (val == TYPE_FIELD_ENUMVAL (type, i))
{ {
break; break;
} }
@ -466,13 +466,13 @@ generic_val_print (struct type *type, const gdb_byte *valaddr,
{ {
QUIT; QUIT;
if ((val & TYPE_FIELD_BITPOS (type, i)) != 0) if ((val & TYPE_FIELD_ENUMVAL (type, i)) != 0)
{ {
if (!first) if (!first)
fputs_filtered (" | ", stream); fputs_filtered (" | ", stream);
first = 0; first = 0;
val &= ~TYPE_FIELD_BITPOS (type, i); val &= ~TYPE_FIELD_ENUMVAL (type, i);
fputs_filtered (TYPE_FIELD_NAME (type, i), stream); fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
} }
} }