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 03/16] gdb: convert address_class_name_to_type_flags to address_class_name_to_id
Date: Mon, 13 Jul 2026 09:00:02 -0500	[thread overview]
Message-ID: <20260713-users-aktemur-type-instance-flags-v1-3-779cad0c85ec@amd.com> (raw)
In-Reply-To: <20260713-users-aktemur-type-instance-flags-v1-0-779cad0c85ec@amd.com>

This is the dual of the previous patch, where we refactor the gdbarch
method 'address_class_name_to_type_flags'.  We make it take a name and
return an address class id, instead of a whole type instance flags.

In one case, there is hardcoded `aclass << 4` to convert an id to type
instance flags.  This will go away in a future patch.
---
 gdb/avr-tdep.c            | 16 ++++++++--------
 gdb/ft32-tdep.c           | 16 ++++++++--------
 gdb/gdbarch-gen.c         | 30 +++++++++++++++---------------
 gdb/gdbarch-gen.h         | 12 ++++++------
 gdb/gdbarch_components.py |  8 ++++----
 gdb/gdbtypes.c            | 16 +++++++++-------
 gdb/s390-tdep.c           | 14 +++++++-------
 7 files changed, 57 insertions(+), 55 deletions(-)

diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index d29e47b3a71..58330eececd 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -1401,18 +1401,18 @@ avr_address_class_id_to_name (struct gdbarch *gdbarch,
     return NULL;
 }
 
-/* Implementation of `address_class_name_to_type_flags' gdbarch method.
+/* Implementation of `address_class_name_to_id' gdbarch method.
 
-   Convert an address space qualifier to a type_instance_flag_value.  */
+   Convert an address class name to an address class id.  */
 
 static bool
-avr_address_class_name_to_type_flags (struct gdbarch *gdbarch,
-				      const char* name,
-				      type_instance_flags *type_flags_ptr)
+avr_address_class_name_to_id (struct gdbarch *gdbarch,
+			      const char* name,
+			      unsigned int &address_class)
 {
   if (streq (name, "flash"))
     {
-      *type_flags_ptr = AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH;
+      address_class = AVR_ADDRESS_CLASS_FLASH;
       return true;
     }
   else
@@ -1535,8 +1535,8 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_unwind_sp (gdbarch, avr_unwind_sp);
 
   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_name_to_id
+    (gdbarch, avr_address_class_name_to_id);
   set_gdbarch_address_class_id_to_name
     (gdbarch, avr_address_class_id_to_name);
 
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index b0da5bf815b..8906a09b0b6 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -368,18 +368,18 @@ ft32_address_class_id_to_name (struct gdbarch *gdbarch,
     return NULL;
 }
 
-/* Implementation of `address_class_name_to_type_flags' gdbarch method.
+/* Implementation of `address_class_name_to_id' gdbarch method.
 
-   Convert an address space qualifier to a type_instance_flag_value.  */
+   Convert an address class name to an address class id.  */
 
 static bool
-ft32_address_class_name_to_type_flags (struct gdbarch *gdbarch,
-				       const char* name,
-				       type_instance_flags *type_flags_ptr)
+ft32_address_class_name_to_id (struct gdbarch *gdbarch,
+			       const char* name,
+			       unsigned int &address_class)
 {
   if (streq (name, "flash"))
     {
-      *type_flags_ptr = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1;
+      address_class = 1;
       return true;
     }
   else
@@ -610,8 +610,8 @@ ft32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_overlay_update (gdbarch, simple_overlay_update);
 
   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_name_to_id
+    (gdbarch, ft32_address_class_name_to_id);
   set_gdbarch_address_class_id_to_name
     (gdbarch, ft32_address_class_id_to_name);
 
diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c
index e1c5a902b00..980682e1bfb 100644
--- a/gdb/gdbarch-gen.c
+++ b/gdb/gdbarch-gen.c
@@ -166,7 +166,7 @@ struct gdbarch
   gdbarch_address_class_type_flags_ftype *address_class_type_flags = 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_address_class_name_to_id_ftype *address_class_name_to_id = nullptr;
   gdbarch_register_reggroup_p_ftype *register_reggroup_p = default_register_reggroup_p;
   gdbarch_fetch_pointer_argument_ftype *fetch_pointer_argument = nullptr;
   gdbarch_iterate_over_regset_sections_ftype *iterate_over_regset_sections = nullptr;
@@ -421,7 +421,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
   /* Skip verify of address_class_type_flags, 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 address_class_name_to_id, has predicate.  */
   /* Skip verify of register_reggroup_p, invalid_p == 0.  */
   /* Skip verify of fetch_pointer_argument, invalid_p == 0.  */
   /* Skip verify of iterate_over_regset_sections, has predicate.  */
@@ -974,11 +974,11 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
 	      "gdbarch_dump: execute_dwarf_cfa_vendor_op = <%s>\n",
 	      host_address_to_string (gdbarch->execute_dwarf_cfa_vendor_op));
   gdb_printf (file,
-	      "gdbarch_dump: gdbarch_address_class_name_to_type_flags_p() = %d\n",
-	      gdbarch_address_class_name_to_type_flags_p (gdbarch));
+	      "gdbarch_dump: gdbarch_address_class_name_to_id_p() = %d\n",
+	      gdbarch_address_class_name_to_id_p (gdbarch));
   gdb_printf (file,
-	      "gdbarch_dump: address_class_name_to_type_flags = <%s>\n",
-	      host_address_to_string (gdbarch->address_class_name_to_type_flags));
+	      "gdbarch_dump: address_class_name_to_id = <%s>\n",
+	      host_address_to_string (gdbarch->address_class_name_to_id));
   gdb_printf (file,
 	      "gdbarch_dump: register_reggroup_p = <%s>\n",
 	      host_address_to_string (gdbarch->register_reggroup_p));
@@ -3561,27 +3561,27 @@ set_gdbarch_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch,
 }
 
 bool
-gdbarch_address_class_name_to_type_flags_p (struct gdbarch *gdbarch)
+gdbarch_address_class_name_to_id_p (struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != nullptr);
-  return gdbarch->address_class_name_to_type_flags != nullptr;
+  return gdbarch->address_class_name_to_id != nullptr;
 }
 
 bool
-gdbarch_address_class_name_to_type_flags (struct gdbarch *gdbarch, const char *name, type_instance_flags *type_flags_ptr)
+gdbarch_address_class_name_to_id (struct gdbarch *gdbarch, const char *name, unsigned int &address_class)
 {
   gdb_assert (gdbarch != nullptr);
-  gdb_assert (gdbarch->address_class_name_to_type_flags != nullptr);
+  gdb_assert (gdbarch->address_class_name_to_id != nullptr);
   if (gdbarch_debug >= 2)
-    gdb_printf (gdb_stdlog, "gdbarch_address_class_name_to_type_flags called\n");
-  return gdbarch->address_class_name_to_type_flags (gdbarch, name, type_flags_ptr);
+    gdb_printf (gdb_stdlog, "gdbarch_address_class_name_to_id called\n");
+  return gdbarch->address_class_name_to_id (gdbarch, name, address_class);
 }
 
 void
-set_gdbarch_address_class_name_to_type_flags (struct gdbarch *gdbarch,
-					      gdbarch_address_class_name_to_type_flags_ftype address_class_name_to_type_flags)
+set_gdbarch_address_class_name_to_id (struct gdbarch *gdbarch,
+				      gdbarch_address_class_name_to_id_ftype address_class_name_to_id)
 {
-  gdbarch->address_class_name_to_type_flags = address_class_name_to_type_flags;
+  gdbarch->address_class_name_to_id = address_class_name_to_id;
 }
 
 bool
diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index 5de522faf1c..1e413796e11 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -915,15 +915,15 @@ using gdbarch_execute_dwarf_cfa_vendor_op_ftype = bool (struct gdbarch *gdbarch,
 bool gdbarch_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op, struct dwarf2_frame_state *fs);
 void set_gdbarch_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdbarch_execute_dwarf_cfa_vendor_op_ftype *execute_dwarf_cfa_vendor_op);
 
-/* Return the appropriate type_flags for the supplied address class.
+/* Return the appropriate address class id for the supplied address class name.
    This function should return true if the address class was recognized and
-   type_flags was set, false otherwise. */
+   address_class was set, false otherwise. */
 
-bool gdbarch_address_class_name_to_type_flags_p (struct gdbarch *gdbarch);
+bool gdbarch_address_class_name_to_id_p (struct gdbarch *gdbarch);
 
-using gdbarch_address_class_name_to_type_flags_ftype = bool (struct gdbarch *gdbarch, const char *name, type_instance_flags *type_flags_ptr);
-bool gdbarch_address_class_name_to_type_flags (struct gdbarch *gdbarch, const char *name, type_instance_flags *type_flags_ptr);
-void set_gdbarch_address_class_name_to_type_flags (struct gdbarch *gdbarch, gdbarch_address_class_name_to_type_flags_ftype *address_class_name_to_type_flags);
+using gdbarch_address_class_name_to_id_ftype = bool (struct gdbarch *gdbarch, const char *name, unsigned int &address_class);
+bool gdbarch_address_class_name_to_id (struct gdbarch *gdbarch, const char *name, unsigned int &address_class);
+void set_gdbarch_address_class_name_to_id (struct gdbarch *gdbarch, gdbarch_address_class_name_to_id_ftype *address_class_name_to_id);
 
 /* Is a register in a group */
 
diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py
index e1acd1dd62b..da2dbd75c4d 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -1566,13 +1566,13 @@ FS are passed from the generic execute_cfa_program function.
 
 Method(
     comment="""
-Return the appropriate type_flags for the supplied address class.
+Return the appropriate address class id for the supplied address class name.
 This function should return true if the address class was recognized and
-type_flags was set, false otherwise.
+address_class was set, false otherwise.
 """,
     type="bool",
-    name="address_class_name_to_type_flags",
-    params=[("const char *", "name"), ("type_instance_flags *", "type_flags_ptr")],
+    name="address_class_name_to_id",
+    params=[("const char *", "name"), ("unsigned int &", "address_class")],
     predicate=True,
 )
 
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index c3e7f1d26c1..f972a1f4278 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -543,18 +543,20 @@ type_instance_flags
 address_space_name_to_type_instance_flags (struct gdbarch *gdbarch,
 					   const char *space_identifier)
 {
-  type_instance_flags type_flags;
-
   /* Check for known address space delimiters.  */
   if (streq (space_identifier, "code"))
     return TYPE_INSTANCE_FLAG_CODE_SPACE;
   else if (streq (space_identifier, "data"))
     return TYPE_INSTANCE_FLAG_DATA_SPACE;
-  else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
-	   && gdbarch_address_class_name_to_type_flags (gdbarch,
-							space_identifier,
-							&type_flags))
-    return type_flags;
+
+  unsigned int aclass;
+  if (gdbarch_address_class_name_to_id_p (gdbarch)
+      && gdbarch_address_class_name_to_id (gdbarch,
+					   space_identifier,
+					   aclass))
+    {
+      return (enum type_instance_flag_value) (aclass << 4);
+    }
   else
     error (_("Unknown address space specifier: \"%s\""), space_identifier);
 }
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 57ddce44644..1aebdfa46d3 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -1632,17 +1632,17 @@ s390_address_class_id_to_name (struct gdbarch *gdbarch,
     return NULL;
 }
 
-/* Implement addr_class_name_to_type_flags gdbarch method.
+/* Implement addr_class_name_to_id gdbarch method.
    Only used for ABI_LINUX_ZSERIES.  */
 
 static bool
-s390_address_class_name_to_type_flags (struct gdbarch *gdbarch,
-				       const char *name,
-				       type_instance_flags *type_flags_ptr)
+s390_address_class_name_to_id (struct gdbarch *gdbarch,
+			       const char *name,
+			       unsigned int &address_class)
 {
   if (streq (name, "mode32"))
     {
-      *type_flags_ptr = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1;
+      address_class = 1;
       return true;
     }
   else
@@ -7359,8 +7359,8 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 					    s390_address_class_type_flags);
       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);
+      set_gdbarch_address_class_name_to_id (gdbarch,
+					    s390_address_class_name_to_id);
       break;
     }
 

-- 
2.34.1


  parent reply	other threads:[~2026-07-13 14:02 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 ` [PATCH 02/16] gdb: convert address_class_type_flags_to_name to address_class_id_to_name Tankut Baris Aktemur
2026-07-21 18:03   ` Tom Tromey
2026-07-13 14:00 ` Tankut Baris Aktemur [this message]
2026-07-21 18:10   ` [PATCH 03/16] gdb: convert address_class_name_to_type_flags to address_class_name_to_id 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-3-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