From 653223d3561b5976d12ade101113af9d08348b8c Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 14 Sep 2020 11:07:56 -0400 Subject: gdb: add type::is_unsigned / type::set_is_unsigned Add the `is_unsigned` and `set_is_unsigned` methods on `struct type`, in order to remove the `TYPE_UNSIGNED` macro. In this patch, the `TYPE_UNSIGNED` macro is changed to use `type::is_unsigned`, so all the call sites that are used to set this property on a type are changed to use the new method. The next patch will remove the macro completely. gdb/ChangeLog: * gdbtypes.h (struct type) : New methods. (TYPE_UNSIGNED): Use type::is_unsigned. Change all write call sites to use type::set_is_unsigned. Change-Id: Ib09ddce84eda160a801a8f288cccf61c8ef136bc --- gdb/ChangeLog | 7 +++++++ gdb/ada-valprint.c | 2 +- gdb/coffread.c | 2 +- gdb/dwarf2/read.c | 8 ++++++-- gdb/gdbtypes.c | 30 ++++++++++++++---------------- gdb/gdbtypes.h | 14 ++++++++++++-- gdb/mdebugread.c | 2 +- gdb/stabsread.c | 5 +++-- gdb/target-descriptions.c | 3 ++- gdb/windows-tdep.c | 2 +- 10 files changed, 48 insertions(+), 27 deletions(-) (limited to 'gdb') diff --git a/gdb/ChangeLog b/gdb/ChangeLog index dd31d70..a10bef5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2020-09-14 Simon Marchi + + * gdbtypes.h (struct type) : New + methods. + (TYPE_UNSIGNED): Use type::is_unsigned. Change all write call + sites to use type::set_is_unsigned. + 2020-09-14 Fredrik Hederstierna Adam Renquinha diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index 6a5b7d3..c61688d 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -43,7 +43,7 @@ adjust_type_signedness (struct type *type) { if (type != NULL && type->code () == TYPE_CODE_RANGE && type->bounds ()->low.const_val () >= 0) - TYPE_UNSIGNED (type) = 1; + type->set_is_unsigned (true); } /* Assuming TYPE is a simple array type, prints its lower bound on STREAM, diff --git a/gdb/coffread.c b/gdb/coffread.c index 1592dc6..a43d9e2 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -2152,7 +2152,7 @@ coff_read_enum_type (int index, int length, int lastsym, } if (unsigned_enum) - TYPE_UNSIGNED (type) = 1; + type->set_is_unsigned (true); return type; } diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 865f9e2..1219bb9 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -16568,7 +16568,8 @@ update_enumeration_type_from_children (struct die_info *die, } if (unsigned_enum) - TYPE_UNSIGNED (type) = 1; + type->set_is_unsigned (true); + if (flag_enum) TYPE_FLAG_ENUM (type) = 1; } @@ -16643,9 +16644,12 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) { struct type *underlying_type = TYPE_TARGET_TYPE (type); underlying_type = check_typedef (underlying_type); - TYPE_UNSIGNED (type) = TYPE_UNSIGNED (underlying_type); + + type->set_is_unsigned (underlying_type->is_unsigned ()); + if (TYPE_LENGTH (type) == 0) TYPE_LENGTH (type) = TYPE_LENGTH (underlying_type); + if (TYPE_RAW_ALIGN (type) == 0 && TYPE_RAW_ALIGN (underlying_type) != 0) set_type_align (type, TYPE_RAW_ALIGN (underlying_type)); diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index b7c8ec8..89a310f 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -375,7 +375,7 @@ make_pointer_type (struct type *type, struct type **typeptr) /* Mark pointers as unsigned. The target converts between pointers and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and gdbarch_address_to_pointer. */ - TYPE_UNSIGNED (ntype) = 1; + ntype->set_is_unsigned (true); /* Update the length of all the other variants of this type. */ chain = TYPE_CHAIN (ntype); @@ -949,14 +949,14 @@ create_range_type (struct type *result_type, struct type *index_type, result_type->set_bounds (bounds); if (low_bound->kind () == PROP_CONST && low_bound->const_val () >= 0) - TYPE_UNSIGNED (result_type) = 1; + result_type->set_is_unsigned (true); /* Ada allows the declaration of range types whose upper bound is less than the lower bound, so checking the lower bound is not enough. Make sure we do not mark a range type whose upper bound is negative as unsigned. */ if (high_bound->kind () == PROP_CONST && high_bound->const_val () < 0) - TYPE_UNSIGNED (result_type) = 0; + result_type->set_is_unsigned (false); TYPE_ENDIANITY_NOT_DEFAULT (result_type) = TYPE_ENDIANITY_NOT_DEFAULT (index_type); @@ -1073,9 +1073,7 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) /* Set unsigned indicator if warranted. */ if (*lowp >= 0) - { - TYPE_UNSIGNED (type) = 1; - } + type->set_is_unsigned (true); } else { @@ -1400,7 +1398,7 @@ create_set_type (struct type *result_type, struct type *domain_type) TYPE_LENGTH (result_type) = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; if (low_bound >= 0) - TYPE_UNSIGNED (result_type) = 1; + result_type->set_is_unsigned (true); } result_type->field (0).set_type (domain_type); @@ -3191,7 +3189,7 @@ init_integer_type (struct objfile *objfile, t = init_type (objfile, TYPE_CODE_INT, bit, name); if (unsigned_p) - TYPE_UNSIGNED (t) = 1; + t->set_is_unsigned (true); return t; } @@ -3208,7 +3206,7 @@ init_character_type (struct objfile *objfile, t = init_type (objfile, TYPE_CODE_CHAR, bit, name); if (unsigned_p) - TYPE_UNSIGNED (t) = 1; + t->set_is_unsigned (true); return t; } @@ -3225,7 +3223,7 @@ init_boolean_type (struct objfile *objfile, t = init_type (objfile, TYPE_CODE_BOOL, bit, name); if (unsigned_p) - TYPE_UNSIGNED (t) = 1; + t->set_is_unsigned (true); return t; } @@ -3319,7 +3317,7 @@ init_pointer_type (struct objfile *objfile, t = init_type (objfile, TYPE_CODE_PTR, bit, name); TYPE_TARGET_TYPE (t) = target_type; - TYPE_UNSIGNED (t) = 1; + t->set_is_unsigned (true); return t; } @@ -5477,7 +5475,7 @@ arch_integer_type (struct gdbarch *gdbarch, t = arch_type (gdbarch, TYPE_CODE_INT, bit, name); if (unsigned_p) - TYPE_UNSIGNED (t) = 1; + t->set_is_unsigned (true); return t; } @@ -5494,7 +5492,7 @@ arch_character_type (struct gdbarch *gdbarch, t = arch_type (gdbarch, TYPE_CODE_CHAR, bit, name); if (unsigned_p) - TYPE_UNSIGNED (t) = 1; + t->set_is_unsigned (true); return t; } @@ -5511,7 +5509,7 @@ arch_boolean_type (struct gdbarch *gdbarch, t = arch_type (gdbarch, TYPE_CODE_BOOL, bit, name); if (unsigned_p) - TYPE_UNSIGNED (t) = 1; + t->set_is_unsigned (true); return t; } @@ -5561,7 +5559,7 @@ arch_pointer_type (struct gdbarch *gdbarch, t = arch_type (gdbarch, TYPE_CODE_PTR, bit, name); TYPE_TARGET_TYPE (t) = target_type; - TYPE_UNSIGNED (t) = 1; + t->set_is_unsigned (true); return t; } @@ -5574,7 +5572,7 @@ arch_flags_type (struct gdbarch *gdbarch, const char *name, int bit) struct type *type; type = arch_type (gdbarch, TYPE_CODE_FLAGS, bit, name); - TYPE_UNSIGNED (type) = 1; + type->set_is_unsigned (true); type->set_num_fields (0); /* Pre-allocate enough space assuming every field is one bit. */ type->set_fields diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 9c2059d..cdd19b4 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -213,7 +213,7 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags); /* * Unsigned integer type. If this is not set for a TYPE_CODE_INT, the type is signed (unless TYPE_NOSIGN (below) is set). */ -#define TYPE_UNSIGNED(t) (TYPE_MAIN_TYPE (t)->flag_unsigned) +#define TYPE_UNSIGNED(t) ((t)->is_unsigned ()) /* * No sign for this type. In C++, "char", "signed char", and "unsigned char" are distinct types; so we need an extra flag to @@ -855,7 +855,7 @@ struct main_type because they packs nicely here. See the TYPE_* macros for documentation about these fields. */ - unsigned int flag_unsigned : 1; + unsigned int m_flag_unsigned : 1; unsigned int flag_nosign : 1; unsigned int flag_stub : 1; unsigned int flag_target_stub : 1; @@ -1068,6 +1068,16 @@ struct type return this->bounds ()->bit_stride (); } + bool is_unsigned () const + { + return this->main_type->m_flag_unsigned; + } + + void set_is_unsigned (bool is_unsigned) + { + this->main_type->m_flag_unsigned = is_unsigned; + } + /* * Return the dynamic property of the requested KIND from this type's list of dynamic properties. */ dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const; diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index d383720..376101e 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -1072,7 +1072,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, f++; } if (unsigned_enum) - TYPE_UNSIGNED (t) = 1; + t->set_is_unsigned (true); } /* Make this the current type. */ top_stack->cur_type = t; diff --git a/gdb/stabsread.c b/gdb/stabsread.c index d2ff54a..b30b075 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -3616,7 +3616,7 @@ read_enum_type (const char **pp, struct type *type, type->set_code (TYPE_CODE_ENUM); TYPE_STUB (type) = 0; if (unsigned_enum) - TYPE_UNSIGNED (type) = 1; + type->set_is_unsigned (true); type->set_num_fields (nsyms); type->set_fields ((struct field *) @@ -3731,7 +3731,8 @@ read_sun_builtin_type (const char **pp, int typenums[2], struct objfile *objfile struct type *type = init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, NULL); if (unsigned_type) - TYPE_UNSIGNED (type) = 1; + type->set_is_unsigned (true); + return type; } diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index 6778b93..611cb9c 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -289,7 +289,8 @@ make_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *ttype) m_type = arch_type (m_gdbarch, TYPE_CODE_ENUM, e->size * TARGET_CHAR_BIT, e->name.c_str ()); - TYPE_UNSIGNED (m_type) = 1; + m_type->set_is_unsigned (true); + for (const tdesc_type_field &f : e->fields) { struct field *fld diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c index aa0adeb..0dee73a 100644 --- a/gdb/windows-tdep.c +++ b/gdb/windows-tdep.c @@ -754,7 +754,7 @@ create_enum (struct gdbarch *gdbarch, int bit, const char *name, type->set_num_fields (count); type->set_fields ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * count)); - TYPE_UNSIGNED (type) = 1; + type->set_is_unsigned (true); for (i = 0; i < count; i++) { -- cgit v1.1