From: Tankut Baris Aktemur <tankutbaris.aktemur@amd.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH 06/16] gdb: split make_type_with_address_space
Date: Mon, 13 Jul 2026 09:00:05 -0500 [thread overview]
Message-ID: <20260713-users-aktemur-type-instance-flags-v1-6-779cad0c85ec@amd.com> (raw)
In-Reply-To: <20260713-users-aktemur-type-instance-flags-v1-0-779cad0c85ec@amd.com>
The function make_type_with_address_space is used for creating a type
variant with a particular Harvard address space or an address class
id. The argument is type instance flags. Split the function into
two, each doing one task: (1) making a type variant with a given
Harvard address space id, and (2) making a type variant with a given
address class id. This is a step towards making function signatures
clearer and more descriptive.
Hardcoded shift operations ("<< 2", "<< 4", ">> 4") will go away in a
future patch.
---
gdb/dwarf2/read.c | 6 +-----
gdb/gdbtypes.c | 42 +++++++++++++++++++++++++++++++++---------
gdb/gdbtypes.h | 14 ++++++++++++--
gdb/gnu-v3-abi.c | 2 +-
gdb/printcmd.c | 13 ++++++++++++-
gdb/type-stack.c | 27 +++++++++++++++++----------
6 files changed, 76 insertions(+), 28 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 3671e39daa2..ce4d6ca8675 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -12056,11 +12056,7 @@ read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
unsigned int aclass
= gdbarch_address_class_dwarf_to_id (gdbarch, byte_size,
addr_class);
- type_instance_flags type_flags
- = (enum type_instance_flag_value) (aclass << 4);
- gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
- == 0);
- type = make_type_with_address_space (type, type_flags);
+ type = make_type_with_address_class (type, aclass);
}
else if (type->length () != byte_size)
{
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 97f1b3e1417..205a79dfbc1 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -590,7 +590,7 @@ make_qualified_type (struct type *type, type_instance_flags new_flags,
return ntype;
}
-/* Make an address-space-delimited variant of a type -- a type that
+/* Make a Harvard-address-space-delimited variant of a type -- a type that
is identical to the one supplied except that it has an address
space attribute attached to it (such as "code" or "data").
@@ -600,14 +600,38 @@ make_qualified_type (struct type *type, type_instance_flags new_flags,
representations. */
struct type *
-make_type_with_address_space (struct type *type,
- type_instance_flags space_flag)
-{
- type_instance_flags new_flags = ((type->instance_flags ()
- & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
- | TYPE_INSTANCE_FLAG_DATA_SPACE
- | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL))
- | space_flag);
+make_type_with_harvard_address_space (struct type *type,
+ enum harvard_address_space aspace)
+{
+ type_instance_flags new_flags
+ = (enum type_instance_flag_value) (aspace << 2);
+
+ gdb_assert ((new_flags & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
+ | TYPE_INSTANCE_FLAG_DATA_SPACE)) == 0);
+ new_flags |= (type->instance_flags ()
+ & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
+ | TYPE_INSTANCE_FLAG_DATA_SPACE));
+
+ return make_qualified_type (type, new_flags, NULL);
+}
+
+/* Make an address-class-delimited variant of a type -- a type that is
+ identical to the one supplied except that it has an address class
+ attribute attached to it. The address class attribute is
+ architecture specific. It may denote an alternately sized pointer
+ or a pointer with alternate representation. */
+
+struct type *
+make_type_with_address_class (struct type *type,
+ unsigned int address_class)
+{
+ type_instance_flags new_flags
+ = (enum type_instance_flag_value) (address_class << 4);
+
+ gdb_assert ((new_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) == 0);
+
+ new_flags |= (type->instance_flags ()
+ & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL);
return make_qualified_type (type, new_flags, NULL);
}
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 1d5c96ab2c1..854679141ff 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -71,6 +71,13 @@ enum type_code
};
+enum harvard_address_space
+{
+ HARVARD_ASPACE_NONE = 0,
+ HARVARD_ASPACE_CODE = 1,
+ HARVARD_ASPACE_DATA = 2,
+};
+
/* Some bits for the type's instance_flags word. See the macros
below for documentation on each bit. */
@@ -2420,8 +2427,11 @@ extern struct type *make_atomic_type (struct type *);
extern void replace_type (struct type *, struct type *);
-extern struct type *make_type_with_address_space
- (struct type *type, type_instance_flags space_identifier);
+extern struct type *make_type_with_harvard_address_space
+ (struct type *type, enum harvard_address_space aspace);
+
+extern struct type *make_type_with_address_class
+ (struct type *type, unsigned int address_class);
/* Implement direct support for MEMBER_TYPE in GNU C++.
TO_TYPE is the type of the member. DOMAIN is the type of the aggregate that
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 35910be0f06..52e31776242 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -184,7 +184,7 @@ get_gdb_vtable_type (struct gdbarch *arch)
t->set_name ("gdb_gnu_v3_abi_vtable");
INIT_CPLUS_SPECIFIC (t);
- result = make_type_with_address_space (t, TYPE_INSTANCE_FLAG_CODE_SPACE);
+ result = make_type_with_harvard_address_space (t, HARVARD_ASPACE_CODE);
vtable_type_gdbarch_data.set (arch, result);
return result;
}
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index a337a6b7db9..3f6cfa9dde3 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1055,7 +1055,18 @@ format_to_type (format_data fmt, gdbarch *gdbarch, type_instance_flags flags)
}
gdb_assert (val_type != nullptr);
- val_type = make_type_with_address_space (val_type, flags);
+
+ if ((flags & TYPE_INSTANCE_FLAG_CODE_SPACE) != 0)
+ val_type = make_type_with_harvard_address_space (val_type,
+ HARVARD_ASPACE_CODE);
+ else if ((flags & TYPE_INSTANCE_FLAG_DATA_SPACE) != 0)
+ val_type = make_type_with_harvard_address_space (val_type,
+ HARVARD_ASPACE_DATA);
+
+ unsigned int aclass
+ = (unsigned int) (flags & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) >> 4;
+ if (aclass != 0)
+ val_type = make_type_with_address_class (val_type, aclass);
return val_type;
}
diff --git a/gdb/type-stack.c b/gdb/type-stack.c
index e2783eaab11..f49e6d05e10 100644
--- a/gdb/type-stack.c
+++ b/gdb/type-stack.c
@@ -72,12 +72,12 @@ type_stack::insert (struct gdbarch *gdbarch, const char *string)
if (streq (string, "code"))
{
piece = tp_harvard_aspace_identifier;
- int_val = TYPE_INSTANCE_FLAG_CODE_SPACE;
+ int_val = HARVARD_ASPACE_CODE;
}
else if (streq (string, "data"))
{
piece = tp_harvard_aspace_identifier;
- int_val = TYPE_INSTANCE_FLAG_DATA_SPACE;
+ int_val = HARVARD_ASPACE_DATA;
}
else if (gdbarch_address_class_name_to_id_p (gdbarch)
&& gdbarch_address_class_name_to_id (gdbarch,
@@ -85,7 +85,7 @@ type_stack::insert (struct gdbarch *gdbarch, const char *string)
aclass))
{
piece = tp_aclass_identifier;
- int_val = (enum type_instance_flag_value) (aclass << 4);
+ int_val = aclass;
}
else
error (_("Unknown address space/class specifier: \"%s\""), string);
@@ -133,7 +133,8 @@ type_stack::follow_types (struct type *follow_type)
int done = 0;
int make_const = 0;
int make_volatile = 0;
- type_instance_flags make_addr_space = 0;
+ harvard_address_space make_harvard_aspace = HARVARD_ASPACE_NONE;
+ int make_address_class = 0;
bool make_restrict = false;
bool make_atomic = false;
int array_size;
@@ -152,10 +153,10 @@ type_stack::follow_types (struct type *follow_type)
make_volatile = 1;
break;
case tp_harvard_aspace_identifier:
- make_addr_space = (enum type_instance_flag_value) pop_int ();
+ make_harvard_aspace = (harvard_address_space) pop_int ();
break;
case tp_aclass_identifier:
- make_addr_space = (enum type_instance_flag_value) pop_int ();
+ make_address_class = pop_int ();
break;
case tp_atomic:
make_atomic = true;
@@ -180,15 +181,21 @@ type_stack::follow_types (struct type *follow_type)
follow_type = make_cv_type (TYPE_CONST (follow_type),
make_volatile,
follow_type);
- if (make_addr_space)
- follow_type = make_type_with_address_space (follow_type,
- make_addr_space);
+ if (make_harvard_aspace != HARVARD_ASPACE_NONE)
+ follow_type
+ = make_type_with_harvard_address_space (follow_type,
+ make_harvard_aspace);
+ if (make_address_class != 0)
+ follow_type
+ = make_type_with_address_class (follow_type,
+ make_address_class);
if (make_restrict)
follow_type = make_restrict_type (follow_type);
if (make_atomic)
follow_type = make_atomic_type (follow_type);
make_const = make_volatile = 0;
- make_addr_space = 0;
+ make_harvard_aspace = HARVARD_ASPACE_NONE;
+ make_address_class = 0;
make_restrict = make_atomic = false;
break;
case tp_array:
--
2.34.1
next prev 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 ` [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 ` [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 ` Tankut Baris Aktemur [this message]
2026-07-21 18:49 ` [PATCH 06/16] gdb: split make_type_with_address_space 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-6-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