Re: [PATCH 2/3] Use type_instance_flags more throughout

Andrew Burgess
2020-08-26T10:06:53Z

* Pedro Alves <pedro@palves.net> [2020-08-21 15:45:22 +0100]:

> The next patch in this series will rewrites enum_flags fixing some API
> holes. That would cause build failures around code using
> type_instance_flags. Or rather, that should be using it, but wasn't.
>
> This patch fixes it by using type_instance_flags throughout instead of
> plain integers.
>
> Note that we can't make the seemingly obvious change to struct
> type::instance_flags:
>
> - unsigned instance_flags : 9;
> + ENUM_BITFIELD (type_instance_flag_value) instance_flags : 9;
>
> Because G++ complains then that 9 bits isn't sufficient for holding
> all values of type_instance_flag_value.
>
> So the patch adds a cast to TYPE_INSTANCE_FLAGS, and adds a separate
> SET_TYPE_INSTANCE_FLAGS macro.
>
> gdb/ChangeLog:
>
> * dwarf2/read.c (read_tag_pointer_type): Use type_instance_flags.
> * eval.c (fake_method::fake_method): Use SET_TYPE_INSTANCE_FLAGS.
> * gdbarch.h, gdbarch.c: Regenerate.
> * gdbarch.sh (address_class_type_flags): Use type_instance_flags.
> (address_class_name_to_type_flags): Use type_instance_flags and
> bool.
> * gdbtypes.c (address_space_name_to_int)
> (address_space_int_to_name, make_qualified_type): Use
> type_instance_flags.
> (make_qualified_type): Use type_instance_flags and
> SET_TYPE_INSTANCE_FLAGS.
> (make_type_with_address_space, make_cv_type, make_vector_type)
> (check_typedef): Use type_instance_flags.
> (recursive_dump_type): Cast type_instance_flags to unsigned for
> printing.
> (copy_type_recursive): Use SET_TYPE_INSTANCE_FLAGS.
> * gdbtypes.h (TYPE_INSTANCE_FLAGS): Return a type_instance_flags.
> (SET_TYPE_INSTANCE_FLAGS): New.
> (address_space_name_to_int, address_space_int_to_name)
> (make_type_with_address_space): Pass flags using
> type_instance_flags instead of int.
> * stabsread.c (cleanup_undefined_types_noname): Use
> SET_TYPE_INSTANCE_FLAGS.
> * type-stack.c (type_stack::follow_types): Use type_instance_flags.

Pedro,

While testing this I found a few issues building with
--enable-targets=all. The patch below fixes all of the issues I ran
into. Feel free to merge this with your work of keep it as a separate
patch, whatever works for you.

Thanks,
Andrew

---

commit b6c8d1ca8077fa7ea2d6f6336b2115b3dcf9dfbb
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date: Wed Aug 26 11:02:22 2020 +0100

gdb: additional changes to make use of type_instance_flags more

Further updates to make use of type_instance_flags.

gdb/ChangeLog:

* avr-tdep.c (avr_address_class_type_flags): Update return type.
(avr_address_class_type_flags_to_name): Update argument types.
(avr_address_class_name_to_type_flags): Update return type and
argument types.
* ft32-tdep.c (ft32_address_class_type_flags): Update return type.
(ft32_address_class_type_flags_to_name): Update argument types.
(ft32_address_class_name_to_type_flags): Update return type and
argument types.
* gdbarch.c: Regenerate.
* gdbarch.h: Regenerate.
* gdbarch.sh (address_class_type_flags_to_name): Update argument
types.
* s390-tdep.c (s390_address_class_type_flags): Update return type.
(s390_address_class_type_flags_to_name): Update argument types.
(s390_address_class_name_to_type_flags): Update return type and
argument types.

diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index 74ab531711e..0148f4e4db2 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -1372,7 +1372,7 @@ avr_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
This method maps DW_AT_address_class attributes to a
type_instance_flag_value. */

-static int
+static type_instance_flags
avr_address_class_type_flags (int byte_size, int dwarf2_addr_class)
{
/* The value 1 of the DW_AT_address_class attribute corresponds to the
@@ -1389,7 +1389,8 @@ avr_address_class_type_flags (int byte_size, int dwarf2_addr_class)
Convert a type_instance_flag_value to an address space qualifier. */

static const char*
-avr_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags)
+avr_address_class_type_flags_to_name (struct gdbarch *gdbarch,
+ type_instance_flags type_flags)
{
if (type_flags & AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH)
return "flash";
@@ -1401,18 +1402,18 @@ avr_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags)

Convert an address space qualifier to a type_instance_flag_value. */

-static int
+static bool
avr_address_class_name_to_type_flags (struct gdbarch *gdbarch,
const char* name,
- int *type_flags_ptr)
+ type_instance_flags *type_flags_ptr)
{
if (strcmp (name, "flash") == 0)
{
*type_flags_ptr = AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH;
- return 1;
+ return true;
}
else
- return 0;
+ return false;
}

/* Initialize the gdbarch structure for the AVR's. */
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index 99ef69de770..8ce16c06505 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -341,7 +341,7 @@ ft32_pointer_to_address (struct gdbarch *gdbarch,
This method maps DW_AT_address_class attributes to a
type_instance_flag_value. */

-static int
+static type_instance_flags
ft32_address_class_type_flags (int byte_size, int dwarf2_addr_class)
{
/* The value 1 of the DW_AT_address_class attribute corresponds to the
@@ -357,7 +357,8 @@ ft32_address_class_type_flags (int byte_size, int dwarf2_addr_class)
Convert a type_instance_flag_value to an address space qualifier. */

static const char*
-ft32_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags)
+ft32_address_class_type_flags_to_name (struct gdbarch *gdbarch,
+ type_instance_flags type_flags)
{
if (type_flags & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1)
return "flash";
@@ -369,18 +370,18 @@ ft32_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags)

Convert an address space qualifier to a type_instance_flag_value. */

-static int
+static bool
ft32_address_class_name_to_type_flags (struct gdbarch *gdbarch,
const char* name,
- int *type_flags_ptr)
+ type_instance_flags *type_flags_ptr)
{
if (strcmp (name, "flash") == 0)
{
*type_flags_ptr = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1;
- return 1;
+ return true;
}
else
- return 0;
+ return false;
}

/* Given a return value in `regbuf' with a type `valtype',
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 2be959ecfc9..a3a67020078 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -3526,7 +3526,7 @@ gdbarch_address_class_type_flags_to_name_p (struct gdbarch *gdbarch)
}

const char *
-gdbarch_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags)
+gdbarch_address_class_type_flags_to_name (struct gdbarch *gdbarch, type_instance_flags type_flags)
{
gdb_assert (gdbarch != NULL);
gdb_assert (gdbarch->address_class_type_flags_to_name != NULL);
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 8a4a384fda9..5ac4f5495c4 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -854,8 +854,8 @@ extern void set_gdbarch_address_class_type_flags (struct gdbarch *gdbarch, gdbar

extern int gdbarch_address_class_type_flags_to_name_p (struct gdbarch *gdbarch);

-typedef const char * (gdbarch_address_class_type_flags_to_name_ftype) (struct gdbarch *gdbarch, int type_flags);
-extern const char * gdbarch_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags);
+typedef const char * (gdbarch_address_class_type_flags_to_name_ftype) (struct gdbarch *gdbarch, type_instance_flags type_flags);
+extern const char * gdbarch_address_class_type_flags_to_name (struct gdbarch *gdbarch, type_instance_flags type_flags);
extern void set_gdbarch_address_class_type_flags_to_name (struct gdbarch *gdbarch, gdbarch_address_class_type_flags_to_name_ftype *address_class_type_flags_to_name);

/* Execute vendor-specific DWARF Call Frame Instruction. OP is the instruction.
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index 7e9204119bd..a64afb5a3d2 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -690,7 +690,7 @@ v;int;cannot_step_breakpoint;;;0;0;;0
# non-steppable watchpoints.
v;int;have_nonsteppable_watchpoint;;;0;0;;0
F;type_instance_flags;address_class_type_flags;int byte_size, int dwarf2_addr_class;byte_size, dwarf2_addr_class
-M;const char *;address_class_type_flags_to_name;int type_flags;type_flags
+M;const char *;address_class_type_flags_to_name;type_instance_flags type_flags;type_flags
# Execute vendor-specific DWARF Call Frame Instruction. OP is the instruction.
# FS are passed from the generic execute_cfa_program function.
m;bool;execute_dwarf_cfa_vendor_op;gdb_byte op, struct dwarf2_frame_state *fs;op, fs;;default_execute_dwarf_cfa_vendor_op;;0
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 65cb23705d2..49a507f7c2d 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -1583,7 +1583,7 @@ s390_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
/* Implement addr_class_type_flags gdbarch method.
Only used for ABI_LINUX_ZSERIES. */

-static int
+static type_instance_flags
s390_address_class_type_flags (int byte_size, int dwarf2_addr_class)
{
if (byte_size == 4)
@@ -1596,7 +1596,8 @@ s390_address_class_type_flags (int byte_size, int dwarf2_addr_class)
Only used for ABI_LINUX_ZSERIES. */

static const char *
-s390_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags)
+s390_address_class_type_flags_to_name (struct gdbarch *gdbarch,
+ type_instance_flags type_flags)
{
if (type_flags & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1)
return "mode32";
@@ -1607,18 +1608,18 @@ s390_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags)
/* Implement addr_class_name_to_type_flags gdbarch method.
Only used for ABI_LINUX_ZSERIES. */

-static int
+static bool
s390_address_class_name_to_type_flags (struct gdbarch *gdbarch,
const char *name,
- int *type_flags_ptr)
+ type_instance_flags *type_flags_ptr)
{
if (strcmp (name, "mode32") == 0)
{
*type_flags_ptr = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1;
- return 1;
+ return true;
}
else
- return 0;
+ return false;
}

/* Inferior function calls. */