Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tankut Baris Aktemur <tankutbaris.aktemur@amd.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH 02/16] gdb: convert address_class_type_flags_to_name to address_class_id_to_name
Date: Mon, 13 Jul 2026 09:00:01 -0500	[thread overview]
Message-ID: <20260713-users-aktemur-type-instance-flags-v1-2-779cad0c85ec@amd.com> (raw)
In-Reply-To: <20260713-users-aktemur-type-instance-flags-v1-0-779cad0c85ec@amd.com>

In type instance flags, two bits are allocated for encoding the
address class.  Although defined like a bitmask, those two bits in
fact represent an architecture-specific enum value.  As a step towards
making this conceptual separation clear, refactor the gdbarch method
'address_class_type_flags_to_name'.  This method is used for returning
the name for the address class id encoded in type instance flags.
Make this clear by passing it the address class id, instead of the
whole flags.
---
 gdb/avr-tdep.c            | 27 ++++++++++++---------------
 gdb/ft32-tdep.c           | 14 +++++++-------
 gdb/gdbarch-gen.c         | 30 +++++++++++++++---------------
 gdb/gdbarch-gen.h         |  8 ++++----
 gdb/gdbarch_components.py |  4 ++--
 gdb/gdbtypes.c            |  9 ++++++---
 gdb/gdbtypes.h            |  4 ++++
 gdb/s390-tdep.c           | 12 ++++++------
 8 files changed, 56 insertions(+), 52 deletions(-)

diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index ddb917fda5f..d29e47b3a71 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -72,13 +72,10 @@
 
 /* Constants: prefixed with AVR_ to avoid name space clashes */
 
-/* Address space flags */
+/* We are assigning the id 1 to the flash address space.  */
 
-/* We are assigning the TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 to the flash address
-   space.  */
-
-#define AVR_TYPE_ADDRESS_CLASS_FLASH TYPE_ADDRESS_CLASS_1
-#define AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH  \
+#define AVR_ADDRESS_CLASS_FLASH 1
+#define AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH	\
   TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1
 
 
@@ -310,7 +307,7 @@ avr_address_to_pointer (struct gdbarch *gdbarch,
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* Is it a data address in flash?  */
-  if (AVR_TYPE_ADDRESS_CLASS_FLASH (type))
+  if (TYPE_ADDRESS_CLASS (type) == AVR_ADDRESS_CLASS_FLASH)
     {
       /* A data pointer in flash is byte addressed.  */
       store_unsigned_integer (buf, type->length (), byte_order,
@@ -342,7 +339,7 @@ avr_pointer_to_address (struct gdbarch *gdbarch,
     = extract_unsigned_integer (buf, type->length (), byte_order);
 
   /* Is it a data address in flash?  */
-  if (AVR_TYPE_ADDRESS_CLASS_FLASH (type))
+  if (TYPE_ADDRESS_CLASS (type) == AVR_ADDRESS_CLASS_FLASH)
     {
       /* A data pointer in flash is already byte addressed.  */
       return avr_make_iaddr (addr);
@@ -1390,15 +1387,15 @@ avr_address_class_type_flags (int byte_size, int dwarf2_addr_class)
   return 0;
 }
 
-/* Implementation of `address_class_type_flags_to_name' gdbarch method.
+/* Implementation of `address_class_id_to_name' gdbarch method.
 
-   Convert a type_instance_flag_value to an address space qualifier.  */
+   Convert an address class id to an address class qualifier.  */
 
 static const char*
-avr_address_class_type_flags_to_name (struct gdbarch *gdbarch,
-				      type_instance_flags type_flags)
+avr_address_class_id_to_name (struct gdbarch *gdbarch,
+			      unsigned int address_class)
 {
-  if (type_flags & AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH)
+  if (address_class == AVR_ADDRESS_CLASS_FLASH)
     return "flash";
   else
     return NULL;
@@ -1540,8 +1537,8 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_address_class_type_flags (gdbarch, avr_address_class_type_flags);
   set_gdbarch_address_class_name_to_type_flags
     (gdbarch, avr_address_class_name_to_type_flags);
-  set_gdbarch_address_class_type_flags_to_name
-    (gdbarch, avr_address_class_type_flags_to_name);
+  set_gdbarch_address_class_id_to_name
+    (gdbarch, avr_address_class_id_to_name);
 
   return gdbarch;
 }
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index 45afebb18e9..b0da5bf815b 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -354,15 +354,15 @@ ft32_address_class_type_flags (int byte_size, int dwarf2_addr_class)
   return 0;
 }
 
-/* Implementation of `address_class_type_flags_to_name' gdbarch method.
+/* Implementation of `address_class_id_to_name' gdbarch method.
 
-   Convert a type_instance_flag_value to an address space qualifier.  */
+   Convert an address class id to an address space qualifier.  */
 
 static const char*
-ft32_address_class_type_flags_to_name (struct gdbarch *gdbarch,
-				       type_instance_flags type_flags)
+ft32_address_class_id_to_name (struct gdbarch *gdbarch,
+			       unsigned int address_class)
 {
-  if (type_flags & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1)
+  if (address_class == 1)
     return "flash";
   else
     return NULL;
@@ -612,8 +612,8 @@ ft32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_address_class_type_flags (gdbarch, ft32_address_class_type_flags);
   set_gdbarch_address_class_name_to_type_flags
     (gdbarch, ft32_address_class_name_to_type_flags);
-  set_gdbarch_address_class_type_flags_to_name
-    (gdbarch, ft32_address_class_type_flags_to_name);
+  set_gdbarch_address_class_id_to_name
+    (gdbarch, ft32_address_class_id_to_name);
 
   return gdbarch;
 }
diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c
index f424fa2a86e..e1c5a902b00 100644
--- a/gdb/gdbarch-gen.c
+++ b/gdb/gdbarch-gen.c
@@ -164,7 +164,7 @@ struct gdbarch
   bool cannot_step_breakpoint = false;
   bool have_nonsteppable_watchpoint = false;
   gdbarch_address_class_type_flags_ftype *address_class_type_flags = nullptr;
-  gdbarch_address_class_type_flags_to_name_ftype *address_class_type_flags_to_name = nullptr;
+  gdbarch_address_class_id_to_name_ftype *address_class_id_to_name = nullptr;
   gdbarch_execute_dwarf_cfa_vendor_op_ftype *execute_dwarf_cfa_vendor_op = default_execute_dwarf_cfa_vendor_op;
   gdbarch_address_class_name_to_type_flags_ftype *address_class_name_to_type_flags = nullptr;
   gdbarch_register_reggroup_p_ftype *register_reggroup_p = default_register_reggroup_p;
@@ -419,7 +419,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
   /* Skip verify of cannot_step_breakpoint, invalid_p == 0.  */
   /* Skip verify of have_nonsteppable_watchpoint, invalid_p == 0.  */
   /* Skip verify of address_class_type_flags, has predicate.  */
-  /* Skip verify of address_class_type_flags_to_name, has predicate.  */
+  /* Skip verify of address_class_id_to_name, has predicate.  */
   /* Skip verify of execute_dwarf_cfa_vendor_op, invalid_p == 0.  */
   /* Skip verify of address_class_name_to_type_flags, has predicate.  */
   /* Skip verify of register_reggroup_p, invalid_p == 0.  */
@@ -965,11 +965,11 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
 	      "gdbarch_dump: address_class_type_flags = <%s>\n",
 	      host_address_to_string (gdbarch->address_class_type_flags));
   gdb_printf (file,
-	      "gdbarch_dump: gdbarch_address_class_type_flags_to_name_p() = %d\n",
-	      gdbarch_address_class_type_flags_to_name_p (gdbarch));
+	      "gdbarch_dump: gdbarch_address_class_id_to_name_p() = %d\n",
+	      gdbarch_address_class_id_to_name_p (gdbarch));
   gdb_printf (file,
-	      "gdbarch_dump: address_class_type_flags_to_name = <%s>\n",
-	      host_address_to_string (gdbarch->address_class_type_flags_to_name));
+	      "gdbarch_dump: address_class_id_to_name = <%s>\n",
+	      host_address_to_string (gdbarch->address_class_id_to_name));
   gdb_printf (file,
 	      "gdbarch_dump: execute_dwarf_cfa_vendor_op = <%s>\n",
 	      host_address_to_string (gdbarch->execute_dwarf_cfa_vendor_op));
@@ -3520,27 +3520,27 @@ set_gdbarch_address_class_type_flags (struct gdbarch *gdbarch,
 }
 
 bool
-gdbarch_address_class_type_flags_to_name_p (struct gdbarch *gdbarch)
+gdbarch_address_class_id_to_name_p (struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != nullptr);
-  return gdbarch->address_class_type_flags_to_name != nullptr;
+  return gdbarch->address_class_id_to_name != nullptr;
 }
 
 const char *
-gdbarch_address_class_type_flags_to_name (struct gdbarch *gdbarch, type_instance_flags type_flags)
+gdbarch_address_class_id_to_name (struct gdbarch *gdbarch, unsigned int address_class)
 {
   gdb_assert (gdbarch != nullptr);
-  gdb_assert (gdbarch->address_class_type_flags_to_name != nullptr);
+  gdb_assert (gdbarch->address_class_id_to_name != nullptr);
   if (gdbarch_debug >= 2)
-    gdb_printf (gdb_stdlog, "gdbarch_address_class_type_flags_to_name called\n");
-  return gdbarch->address_class_type_flags_to_name (gdbarch, type_flags);
+    gdb_printf (gdb_stdlog, "gdbarch_address_class_id_to_name called\n");
+  return gdbarch->address_class_id_to_name (gdbarch, address_class);
 }
 
 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)
+set_gdbarch_address_class_id_to_name (struct gdbarch *gdbarch,
+				      gdbarch_address_class_id_to_name_ftype address_class_id_to_name)
 {
-  gdbarch->address_class_type_flags_to_name = address_class_type_flags_to_name;
+  gdbarch->address_class_id_to_name = address_class_id_to_name;
 }
 
 bool
diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index 678b308fba5..5de522faf1c 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -902,11 +902,11 @@ using gdbarch_address_class_type_flags_ftype = type_instance_flags (int byte_siz
 type_instance_flags gdbarch_address_class_type_flags (struct gdbarch *gdbarch, int byte_size, int dwarf2_addr_class);
 void set_gdbarch_address_class_type_flags (struct gdbarch *gdbarch, gdbarch_address_class_type_flags_ftype *address_class_type_flags);
 
-bool gdbarch_address_class_type_flags_to_name_p (struct gdbarch *gdbarch);
+bool gdbarch_address_class_id_to_name_p (struct gdbarch *gdbarch);
 
-using gdbarch_address_class_type_flags_to_name_ftype = const char *(struct gdbarch *gdbarch, type_instance_flags type_flags);
-const char *gdbarch_address_class_type_flags_to_name (struct gdbarch *gdbarch, type_instance_flags type_flags);
-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);
+using gdbarch_address_class_id_to_name_ftype = const char *(struct gdbarch *gdbarch, unsigned int address_class);
+const char *gdbarch_address_class_id_to_name (struct gdbarch *gdbarch, unsigned int address_class);
+void set_gdbarch_address_class_id_to_name (struct gdbarch *gdbarch, gdbarch_address_class_id_to_name_ftype *address_class_id_to_name);
 
 /* Execute vendor-specific DWARF Call Frame Instruction.  OP is the instruction.
    FS are passed from the generic execute_cfa_program function. */
diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py
index b9304d3036d..e1acd1dd62b 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -1547,8 +1547,8 @@ Function(
 
 Method(
     type="const char *",
-    name="address_class_type_flags_to_name",
-    params=[("type_instance_flags", "type_flags")],
+    name="address_class_id_to_name",
+    params=[("unsigned int", "address_class")],
     predicate=True,
 )
 
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index d1a2914e1e6..c3e7f1d26c1 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -570,9 +570,12 @@ address_space_type_instance_flags_to_name (struct gdbarch *gdbarch,
     return "code";
   else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE)
     return "data";
-  else if ((space_flag & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
-	   && gdbarch_address_class_type_flags_to_name_p (gdbarch))
-    return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
+
+  unsigned int aclass = TYPE_ADDRESS_CLASS_FROM_INSTANCE_FLAGS (space_flag);
+
+  if (aclass != 0
+      && gdbarch_address_class_id_to_name_p (gdbarch))
+    return gdbarch_address_class_id_to_name (gdbarch, aclass);
   else
     return NULL;
 }
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 572bf6d3d6f..3c21d4ad214 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -175,6 +175,10 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
   (TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2)
 #define TYPE_ADDRESS_CLASS_ALL(t) (((t)->instance_flags ()) \
 				   & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
+#define TYPE_ADDRESS_CLASS_FROM_INSTANCE_FLAGS(t) \
+  ((unsigned int) ((t) & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) >> 4)
+#define TYPE_ADDRESS_CLASS(t) \
+  (TYPE_ADDRESS_CLASS_FROM_INSTANCE_FLAGS ((t)->instance_flags ()))
 
 /* Information about a single discriminant.  */
 
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index f74e55284c0..57ddce44644 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -1619,14 +1619,14 @@ s390_address_class_type_flags (int byte_size, int dwarf2_addr_class)
     return 0;
 }
 
-/* Implement addr_class_type_flags_to_name gdbarch method.
+/* Implement addr_class_id_to_name gdbarch method.
    Only used for ABI_LINUX_ZSERIES.  */
 
 static const char *
-s390_address_class_type_flags_to_name (struct gdbarch *gdbarch,
-				       type_instance_flags type_flags)
+s390_address_class_id_to_name (struct gdbarch *gdbarch,
+			       unsigned int address_class)
 {
-  if (type_flags & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1)
+  if (address_class == 1)
     return "mode32";
   else
     return NULL;
@@ -7357,8 +7357,8 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       set_gdbarch_ptr_bit (gdbarch, 64);
       set_gdbarch_address_class_type_flags (gdbarch,
 					    s390_address_class_type_flags);
-      set_gdbarch_address_class_type_flags_to_name (gdbarch,
-						    s390_address_class_type_flags_to_name);
+      set_gdbarch_address_class_id_to_name (gdbarch,
+					    s390_address_class_id_to_name);
       set_gdbarch_address_class_name_to_type_flags (gdbarch,
 						    s390_address_class_name_to_type_flags);
       break;

-- 
2.34.1


  parent reply	other threads:[~2026-07-13 14:01 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13 13:59 [PATCH 00/16] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
2026-07-13 14:00 ` [PATCH 01/16] gdb: use type instance macros to query const, volatile, restrict Tankut Baris Aktemur
2026-07-21 17:52   ` Tom Tromey
2026-07-13 14:00 ` Tankut Baris Aktemur [this message]
2026-07-21 18:03   ` [PATCH 02/16] gdb: convert address_class_type_flags_to_name to address_class_id_to_name Tom Tromey
2026-07-13 14:00 ` [PATCH 03/16] gdb: convert address_class_name_to_type_flags to address_class_name_to_id Tankut Baris Aktemur
2026-07-21 18:10   ` Tom Tromey
2026-07-13 14:00 ` [PATCH 04/16] gdb: convert address_class_type_flags to address_class_dwarf_to_id Tankut Baris Aktemur
2026-07-21 18:19   ` Tom Tromey
2026-07-13 14:00 ` [PATCH 05/16] gdb: inline address_space_{name, type_instance_flags}_to_{type_instance_flags, name} Tankut Baris Aktemur
2026-07-21 18:29   ` Tom Tromey
2026-07-22 10:29     ` Aktemur, Baris
2026-07-22 13:38       ` Tom Tromey
2026-07-13 14:00 ` [PATCH 06/16] gdb: split make_type_with_address_space Tankut Baris Aktemur
2026-07-21 18:49   ` Tom Tromey
2026-07-13 14:00 ` [PATCH 07/16] gdb: convert type instance flags to bitfields Tankut Baris Aktemur
2026-07-21 19:13   ` Tom Tromey
2026-07-22 10:29     ` Aktemur, Baris
2026-07-13 14:00 ` [PATCH 08/16] gdb: convert TYPE_NOTTEXT macro to type::is_nottext Tankut Baris Aktemur
2026-07-21 18:39   ` Tom Tromey
2026-07-13 14:00 ` [PATCH 09/16] gdb: convert TYPE_CONST macro to type::is_const Tankut Baris Aktemur
2026-07-21 18:40   ` Tom Tromey
2026-07-13 14:00 ` [PATCH 10/16] gdb: convert TYPE_VOLATILE macro to type::is_volatile Tankut Baris Aktemur
2026-07-13 14:00 ` [PATCH 11/16] gdb: convert TYPE_CODE_SPACE macro to type::is_code_space Tankut Baris Aktemur
2026-07-13 14:00 ` [PATCH 12/16] gdb: convert TYPE_DATA_SPACE macro to type::is_data_space Tankut Baris Aktemur
2026-07-13 14:00 ` [PATCH 13/16] gdb: convert TYPE_RESTRICT macro to type::is_restrict Tankut Baris Aktemur
2026-07-13 14:00 ` [PATCH 14/16] gdb: convert TYPE_ATOMIC macro to type::is_atomic Tankut Baris Aktemur
2026-07-13 14:00 ` [PATCH 15/16] gdb: convert TYPE_ADDRESS_CLASS macro to type::address_class Tankut Baris Aktemur
2026-07-13 14:00 ` [PATCH 16/16] gdb: remove unnecessary braces in recursive_dump_type Tankut Baris Aktemur
2026-07-21 18:45   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260713-users-aktemur-type-instance-flags-v1-2-779cad0c85ec@amd.com \
    --to=tankutbaris.aktemur@amd.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox