* [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields
@ 2026-07-22 10:41 Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 01/17] gdb: use type instance macros to query const, volatile, restrict Tankut Baris Aktemur
` (17 more replies)
0 siblings, 18 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:41 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
This is v2 of the series at
https://inbox.sourceware.org/gdb-patches/20260713-users-aktemur-type-instance-flags-v1-0-779cad0c85ec@amd.com
This revision addresses the review comments given by Tom Tromey. The
patch titled "gdb: refactor type_stack::insert methods" is new.
Some patches are already approved. They are still included in the
series for completeness.
===
A type in GDB has an "instance flags" fields that encodes some
information about the type as a bitmask. The information includes
things like whether the type is const, volatile, restrict, etc. These
are boolean flags and the meaning is clear.
There are two bits to encode Harvard address space information (code
and data space), which are seemingly indepedent bits in the current
encoding. However, those two bits essentially encode an enum of
no-space, code-space, and data-space. That is, it doesn't make sense
that code and data space bits are both set. But the current encoding
does not make this clear.
Similarly, two bits are allocated to store address class information.
Architectures are left completely free to set/unset these bits to
encode address class information specific to them. It is reasonable
to expect that architectures would also encode enum values in these
bits. (Currently, in upstream GDB, there are three architectures that
use the address class information: avr, ft32, and s390. They all use
the first bit only.)
The aim of this series is to rewrite type instance flags to a struct
with bitfields with boolean types for flag fields and unsigned scalar
types for Harvard address space and address class information to
enable enum-like usage. This transformation helps make the code
cleaner by avoiding low level bitwise manipulation and by not passing
the complete bitmask around.
A complication in this rewrite is the Harvard address space and
address class topics. First, the code and data space topic is
currently usually referred to as "address space" in the code.
However, "address space" is an overloaded term. For example, see the
DWARF issues
https://dwarfstd.org/issues/260617.1.html
and
https://dwarfstd.org/issues/260211.1.html
and OpenCL's address space qualifiers:
https://registry.khronos.org/OpenCL/specs/unified/refpages/man/html/addressSpaceQualifiers.html
To make the current meaning of "address space" in GDB code base clear,
the series aims to consistently say "Harvard address spaces" and
update the code accordingly. (Based on the DWARF discussions listed
above, we can expect GDB to have support for target architecture
address spaces in the future; so it would be nice to separate the
topics.)
Furthermore, when dealing with Harvard address spaces and address
classes, GDB passes a whole type instance flags bitmask value around,
which makes the boundaries unclear. For example,
`address_space_name_to_type_instance_flags` takes a Harvard address
space or an address class name, and returns type instance flags. The
function `address_space_type_instance_flags_to_name` does the opposite
transformation. The separation between the two concepts is not
reflected. The series performs a number of renamings and refactorings
to gradually separate the two topics and make type instance flags
clearer, eventually reaching a struct definition.
Regards,
Baris
---
Tankut Baris Aktemur (17):
gdb: use type instance macros to query const, volatile, restrict
gdb: convert address_class_type_flags_to_name to address_class_id_to_name
gdb: convert address_class_name_to_type_flags to address_class_name_to_id
gdb: convert address_class_type_flags to address_class_dwarf_to_id
gdb: refactor type_stack::insert methods
gdb: inline address_space_{name,type_instance_flags}_to_{type_instance_flags,name}
gdb: split make_type_with_address_space
gdb: convert type instance flags to bitfields
gdb: convert TYPE_NOTTEXT macro to type::is_nottext
gdb: convert TYPE_CONST macro to type::is_const
gdb: convert TYPE_VOLATILE macro to type::is_volatile
gdb: convert TYPE_CODE_SPACE macro to type::is_code_space
gdb: convert TYPE_DATA_SPACE macro to type::is_data_space
gdb: convert TYPE_RESTRICT macro to type::is_restrict
gdb: convert TYPE_ATOMIC macro to type::is_atomic
gdb: convert TYPE_ADDRESS_CLASS macro to type::address_class
gdb: remove unnecessary braces in recursive_dump_type
gdb/avr-tdep.c | 62 +++--
gdb/c-typeprint.c | 33 ++-
gdb/c-valprint.c | 2 +-
gdb/compile/compile-c-types.c | 10 +-
gdb/compile/compile-cplus-types.c | 16 +-
gdb/ctfread.c | 8 +-
gdb/d-lang.c | 9 +-
gdb/dwarf2/read.c | 26 +--
gdb/expop.h | 6 +
gdb/expprint.c | 4 +-
gdb/ft32-tdep.c | 50 ++--
gdb/gdb-gdb.py.in | 99 ++------
gdb/gdbarch-gen.c | 92 ++++----
gdb/gdbarch-gen.h | 34 +--
gdb/gdbarch_components.py | 24 +-
gdb/gdbtypes.c | 260 +++++++--------------
gdb/gdbtypes.h | 231 +++++++++++-------
gdb/gnu-v3-abi.c | 2 +-
gdb/iq2000-tdep.c | 2 +-
gdb/m2-typeprint.c | 2 +-
gdb/m2-valprint.c | 2 +-
gdb/opencl-lang.c | 2 +-
gdb/printcmd.c | 12 +-
gdb/python/py-type.c | 8 +-
gdb/rl78-tdep.c | 2 +-
gdb/s390-tdep.c | 38 +--
gdb/testsuite/gdb.base/address_space_qualifier.exp | 4 +-
gdb/testsuite/gdb.base/maint.exp | 2 +-
gdb/testsuite/gdb.gdb/python-helper.exp | 8 +-
gdb/type-stack.c | 85 ++++---
gdb/type-stack.h | 49 ++--
gdb/valops.c | 10 +-
32 files changed, 595 insertions(+), 599 deletions(-)
---
base-commit: 640a79623d40d951092e3da46075d8db6b4679f1
change-id: 20260713-users-aktemur-type-instance-flags-71f5a70c9875
Best regards,
--
Tankut Baris Aktemur <tankutbaris.aktemur@amd.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 01/17] gdb: use type instance macros to query const, volatile, restrict
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
@ 2026-07-22 10:41 ` Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 02/17] gdb: convert address_class_type_flags_to_name to address_class_id_to_name Tankut Baris Aktemur
` (16 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:41 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
In two cases in compile/compile-c-types.c and
compile/compile-cplus-types.c, we query if a type is const, volatile,
or restrict using bitmasks. For such read-only queries, there are
macros. Use them for code uniformity. The new code may be slightly
less optimal, but I don't think this would matter in practice. This
is a code cleanup step in a series.
Approved-By: Tom Tromey <tom@tromey.com>
---
gdb/compile/compile-c-types.c | 4 +---
gdb/compile/compile-cplus-types.c | 4 +---
2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index be79b582081..af9dea730eb 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -278,9 +278,7 @@ convert_type_basic (compile_c_instance *context, struct type *type)
{
/* If we are converting a qualified type, first convert the
unqualified type and then apply the qualifiers. */
- if ((type->instance_flags () & (TYPE_INSTANCE_FLAG_CONST
- | TYPE_INSTANCE_FLAG_VOLATILE
- | TYPE_INSTANCE_FLAG_RESTRICT)) != 0)
+ if (TYPE_CONST (type) || TYPE_VOLATILE (type) || TYPE_RESTRICT (type))
return convert_qualified (context, type);
switch (type->code ())
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index 031775c3679..ff25fc62c8b 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -1126,9 +1126,7 @@ convert_type_cplus_basic (compile_cplus_instance *instance,
{
/* If we are converting a qualified type, first convert the
unqualified type and then apply the qualifiers. */
- if ((type->instance_flags () & (TYPE_INSTANCE_FLAG_CONST
- | TYPE_INSTANCE_FLAG_VOLATILE
- | TYPE_INSTANCE_FLAG_RESTRICT)) != 0)
+ if (TYPE_CONST (type) || TYPE_VOLATILE (type) || TYPE_RESTRICT (type))
return compile_cplus_convert_qualified (instance, type);
switch (type->code ())
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 02/17] gdb: convert address_class_type_flags_to_name to address_class_id_to_name
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 01/17] gdb: use type instance macros to query const, volatile, restrict Tankut Baris Aktemur
@ 2026-07-22 10:41 ` Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 03/17] gdb: convert address_class_name_to_type_flags to address_class_name_to_id Tankut Baris Aktemur
` (15 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:41 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
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 | 11 +++++++----
gdb/gdbarch_components.py | 8 ++++++--
gdb/gdbtypes.c | 8 +++++---
gdb/gdbtypes.h | 4 ++++
gdb/s390-tdep.c | 12 ++++++------
8 files changed, 62 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..9fea082a690 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -902,11 +902,14 @@ 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);
+/* Given an architecture-specific address class identifier, return the
+ name of that address class. */
-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);
+bool gdbarch_address_class_id_to_name_p (struct gdbarch *gdbarch);
+
+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..5ec4bdee819 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -1546,9 +1546,13 @@ Function(
)
Method(
+ comment="""
+Given an architecture-specific address class identifier, return the
+name of that address class.
+""",
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..f3c77073f70 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -570,9 +570,11 @@ 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 (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
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 03/17] gdb: convert address_class_name_to_type_flags to address_class_name_to_id
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 01/17] gdb: use type instance macros to query const, volatile, restrict Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 02/17] gdb: convert address_class_type_flags_to_name to address_class_id_to_name Tankut Baris Aktemur
@ 2026-07-22 10:41 ` Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 04/17] gdb: convert address_class_type_flags to address_class_dwarf_to_id Tankut Baris Aktemur
` (14 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:41 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
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.
Approved-By: Tom Tromey <tom@tromey.com>
---
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 9fea082a690..05b1656a511 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -918,15 +918,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 5ec4bdee819..d5d5a6d4fe3 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -1570,13 +1570,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 f3c77073f70..87cc7d15d0d 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
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 04/17] gdb: convert address_class_type_flags to address_class_dwarf_to_id
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (2 preceding siblings ...)
2026-07-22 10:41 ` [PATCH v2 03/17] gdb: convert address_class_name_to_type_flags to address_class_name_to_id Tankut Baris Aktemur
@ 2026-07-22 10:41 ` Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 05/17] gdb: refactor type_stack::insert methods Tankut Baris Aktemur
` (13 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:41 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
The gdbarch method 'address_class_type_flags' is used for letting an
architecture translate the DW_AT_address_class attribute to an address
class id. Make this clear by refactoring the method to return an id,
instead of a whole type instance flags value. There is hardcoding of
"<< 4" left in dwarf/read.c. This will go away in a future patch.
---
gdb/avr-tdep.c | 17 ++++++++---------
gdb/dwarf2/read.c | 8 +++++---
gdb/ft32-tdep.c | 15 ++++++++-------
gdb/gdbarch-gen.c | 32 ++++++++++++++++----------------
gdb/gdbarch-gen.h | 11 +++++++----
gdb/gdbarch_components.py | 8 ++++++--
gdb/s390-tdep.c | 12 ++++++------
7 files changed, 56 insertions(+), 47 deletions(-)
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index 58330eececd..2191ada4c2e 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -75,8 +75,6 @@
/* We are assigning the id 1 to the flash address space. */
#define AVR_ADDRESS_CLASS_FLASH 1
-#define AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH \
- TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1
enum
@@ -1370,20 +1368,20 @@ avr_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
return -1;
}
-/* Implementation of `address_class_type_flags' gdbarch method.
+/* Implementation of `address_class_dwarf_to_id' gdbarch method.
- This method maps DW_AT_address_class attributes to a
- type_instance_flag_value. */
+ This method maps a DW_AT_address_class attribute to an address
+ class id. */
-static type_instance_flags
-avr_address_class_type_flags (int byte_size, int dwarf2_addr_class)
+static unsigned int
+avr_address_class_dwarf_to_id (int byte_size, int dwarf2_addr_class)
{
/* The value 1 of the DW_AT_address_class attribute corresponds to the
__flash qualifier. Note that this attribute is only valid with
pointer types and therefore the flag is set to the pointer type and
not its target type. */
if (dwarf2_addr_class == 1 && byte_size == 2)
- return AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH;
+ return AVR_ADDRESS_CLASS_FLASH;
return 0;
}
@@ -1534,7 +1532,8 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
set_gdbarch_unwind_pc (gdbarch, avr_unwind_pc);
set_gdbarch_unwind_sp (gdbarch, avr_unwind_sp);
- set_gdbarch_address_class_type_flags (gdbarch, avr_address_class_type_flags);
+ set_gdbarch_address_class_dwarf_to_id
+ (gdbarch, avr_address_class_dwarf_to_id);
set_gdbarch_address_class_name_to_id
(gdbarch, avr_address_class_name_to_id);
set_gdbarch_address_class_id_to_name
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 114c608fde3..3671e39daa2 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -12051,11 +12051,13 @@ read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
&& alignment != TYPE_RAW_ALIGN (type))
|| addr_class != DW_ADDR_none)
{
- if (gdbarch_address_class_type_flags_p (gdbarch))
+ if (gdbarch_address_class_dwarf_to_id_p (gdbarch))
{
+ unsigned int aclass
+ = gdbarch_address_class_dwarf_to_id (gdbarch, byte_size,
+ addr_class);
type_instance_flags type_flags
- = gdbarch_address_class_type_flags (gdbarch, byte_size,
- addr_class);
+ = (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);
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index 8906a09b0b6..476e79355c7 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -338,19 +338,19 @@ ft32_pointer_to_address (struct gdbarch *gdbarch,
return addr | RAM_BIAS;
}
-/* Implementation of `address_class_type_flags' gdbarch method.
+/* Implementation of `address_class_dwarf_to_id' gdbarch method.
- This method maps DW_AT_address_class attributes to a
- type_instance_flag_value. */
+ This method maps a DW_AT_address_class attribute to an address
+ class id. */
-static type_instance_flags
-ft32_address_class_type_flags (int byte_size, int dwarf2_addr_class)
+static unsigned int
+ft32_address_class_dwarf_to_id (int byte_size, int dwarf2_addr_class)
{
/* The value 1 of the DW_AT_address_class attribute corresponds to the
__flash__ qualifier, meaning pointer to data in FT32 program memory.
*/
if (dwarf2_addr_class == 1)
- return TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1;
+ return 1;
return 0;
}
@@ -609,7 +609,8 @@ ft32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
/* Support simple overlay manager. */
set_gdbarch_overlay_update (gdbarch, simple_overlay_update);
- set_gdbarch_address_class_type_flags (gdbarch, ft32_address_class_type_flags);
+ set_gdbarch_address_class_dwarf_to_id
+ (gdbarch, ft32_address_class_dwarf_to_id);
set_gdbarch_address_class_name_to_id
(gdbarch, ft32_address_class_name_to_id);
set_gdbarch_address_class_id_to_name
diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c
index 980682e1bfb..6008003466c 100644
--- a/gdb/gdbarch-gen.c
+++ b/gdb/gdbarch-gen.c
@@ -163,7 +163,7 @@ struct gdbarch
gdbarch_adjust_dwarf2_line_ftype *adjust_dwarf2_line = default_adjust_dwarf2_line;
bool cannot_step_breakpoint = false;
bool have_nonsteppable_watchpoint = false;
- gdbarch_address_class_type_flags_ftype *address_class_type_flags = nullptr;
+ gdbarch_address_class_dwarf_to_id_ftype *address_class_dwarf_to_id = 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_id_ftype *address_class_name_to_id = nullptr;
@@ -418,7 +418,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of adjust_dwarf2_line, invalid_p == 0. */
/* 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_dwarf_to_id, 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_id, has predicate. */
@@ -959,11 +959,11 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
"gdbarch_dump: have_nonsteppable_watchpoint = %s\n",
plongest (gdbarch->have_nonsteppable_watchpoint));
gdb_printf (file,
- "gdbarch_dump: gdbarch_address_class_type_flags_p() = %d\n",
- gdbarch_address_class_type_flags_p (gdbarch));
+ "gdbarch_dump: gdbarch_address_class_dwarf_to_id_p() = %d\n",
+ gdbarch_address_class_dwarf_to_id_p (gdbarch));
gdb_printf (file,
- "gdbarch_dump: address_class_type_flags = <%s>\n",
- host_address_to_string (gdbarch->address_class_type_flags));
+ "gdbarch_dump: address_class_dwarf_to_id = <%s>\n",
+ host_address_to_string (gdbarch->address_class_dwarf_to_id));
gdb_printf (file,
"gdbarch_dump: gdbarch_address_class_id_to_name_p() = %d\n",
gdbarch_address_class_id_to_name_p (gdbarch));
@@ -3496,27 +3496,27 @@ set_gdbarch_have_nonsteppable_watchpoint (struct gdbarch *gdbarch,
}
bool
-gdbarch_address_class_type_flags_p (struct gdbarch *gdbarch)
+gdbarch_address_class_dwarf_to_id_p (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != nullptr);
- return gdbarch->address_class_type_flags != nullptr;
+ return gdbarch->address_class_dwarf_to_id != nullptr;
}
-type_instance_flags
-gdbarch_address_class_type_flags (struct gdbarch *gdbarch, int byte_size, int dwarf2_addr_class)
+unsigned int
+gdbarch_address_class_dwarf_to_id (struct gdbarch *gdbarch, int byte_size, int dwarf2_addr_class)
{
gdb_assert (gdbarch != nullptr);
- gdb_assert (gdbarch->address_class_type_flags != nullptr);
+ gdb_assert (gdbarch->address_class_dwarf_to_id != nullptr);
if (gdbarch_debug >= 2)
- gdb_printf (gdb_stdlog, "gdbarch_address_class_type_flags called\n");
- return gdbarch->address_class_type_flags (byte_size, dwarf2_addr_class);
+ gdb_printf (gdb_stdlog, "gdbarch_address_class_dwarf_to_id called\n");
+ return gdbarch->address_class_dwarf_to_id (byte_size, dwarf2_addr_class);
}
void
-set_gdbarch_address_class_type_flags (struct gdbarch *gdbarch,
- gdbarch_address_class_type_flags_ftype address_class_type_flags)
+set_gdbarch_address_class_dwarf_to_id (struct gdbarch *gdbarch,
+ gdbarch_address_class_dwarf_to_id_ftype address_class_dwarf_to_id)
{
- gdbarch->address_class_type_flags = address_class_type_flags;
+ gdbarch->address_class_dwarf_to_id = address_class_dwarf_to_id;
}
bool
diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index 05b1656a511..6eda8693d58 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -896,11 +896,14 @@ void set_gdbarch_cannot_step_breakpoint (struct gdbarch *gdbarch, bool cannot_st
bool gdbarch_have_nonsteppable_watchpoint (struct gdbarch *gdbarch);
void set_gdbarch_have_nonsteppable_watchpoint (struct gdbarch *gdbarch, bool have_nonsteppable_watchpoint);
-bool gdbarch_address_class_type_flags_p (struct gdbarch *gdbarch);
+/* Given the DWARF identifier for an architecture-specific address class,
+ return the id of that address class. */
-using gdbarch_address_class_type_flags_ftype = type_instance_flags (int byte_size, int dwarf2_addr_class);
-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_dwarf_to_id_p (struct gdbarch *gdbarch);
+
+using gdbarch_address_class_dwarf_to_id_ftype = unsigned int (int byte_size, int dwarf2_addr_class);
+unsigned int gdbarch_address_class_dwarf_to_id (struct gdbarch *gdbarch, int byte_size, int dwarf2_addr_class);
+void set_gdbarch_address_class_dwarf_to_id (struct gdbarch *gdbarch, gdbarch_address_class_dwarf_to_id_ftype *address_class_dwarf_to_id);
/* Given an architecture-specific address class identifier, return the
name of that address class. */
diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py
index d5d5a6d4fe3..d8b2d114909 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -1539,8 +1539,12 @@ non-steppable watchpoints.
)
Function(
- type="type_instance_flags",
- name="address_class_type_flags",
+ comment="""
+Given the DWARF identifier for an architecture-specific address class,
+return the id of that address class.
+""",
+ type="unsigned int",
+ name="address_class_dwarf_to_id",
params=[("int", "byte_size"), ("int", "dwarf2_addr_class")],
predicate=True,
)
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 1aebdfa46d3..1155b8dd648 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -1607,14 +1607,14 @@ s390_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
return addr & 0x7fffffff;
}
-/* Implement addr_class_type_flags gdbarch method.
+/* Implement addr_class_dwarf_to_id gdbarch method.
Only used for ABI_LINUX_ZSERIES. */
-static type_instance_flags
-s390_address_class_type_flags (int byte_size, int dwarf2_addr_class)
+static unsigned int
+s390_address_class_dwarf_to_id (int byte_size, int dwarf2_addr_class)
{
if (byte_size == 4)
- return TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1;
+ return 1;
else
return 0;
}
@@ -7355,8 +7355,8 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
set_gdbarch_long_bit (gdbarch, 64);
set_gdbarch_long_long_bit (gdbarch, 64);
set_gdbarch_ptr_bit (gdbarch, 64);
- set_gdbarch_address_class_type_flags (gdbarch,
- s390_address_class_type_flags);
+ set_gdbarch_address_class_dwarf_to_id (gdbarch,
+ s390_address_class_dwarf_to_id);
set_gdbarch_address_class_id_to_name (gdbarch,
s390_address_class_id_to_name);
set_gdbarch_address_class_name_to_id (gdbarch,
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 05/17] gdb: refactor type_stack::insert methods
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (3 preceding siblings ...)
2026-07-22 10:41 ` [PATCH v2 04/17] gdb: convert address_class_type_flags to address_class_dwarf_to_id Tankut Baris Aktemur
@ 2026-07-22 10:41 ` Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 06/17] gdb: inline address_space_{name, type_instance_flags}_to_{type_instance_flags, name} Tankut Baris Aktemur
` (12 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:41 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
Clone the 'insert_into' method of struct type_stack into two
overloads, one taking a type piece and the other taking an integer,
and use the overloads to simplify the 'insert' methods. This is a
refactoring.
---
gdb/type-stack.c | 27 +++++++--------------------
gdb/type-stack.h | 18 ++++++++++++++++--
2 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/gdb/type-stack.c b/gdb/type-stack.c
index 7e790a003ec..d19854363a2 100644
--- a/gdb/type-stack.c
+++ b/gdb/type-stack.c
@@ -26,9 +26,6 @@
void
type_stack::insert (enum type_pieces tp)
{
- union type_stack_elt element;
- int slot;
-
gdb_assert (tp == tp_pointer || tp == tp_reference
|| tp == tp_rvalue_reference || tp == tp_const
|| tp == tp_volatile || tp == tp_restrict
@@ -39,12 +36,9 @@ type_stack::insert (enum type_pieces tp)
push this on the top of the stack. */
if (!m_elements.empty () && (tp == tp_const || tp == tp_volatile
|| tp == tp_restrict))
- slot = 1;
+ insert_into (1, tp);
else
- slot = 0;
-
- element.piece = tp;
- insert_into (slot, element);
+ insert_into (0, tp);
}
/* See type-stack.h. */
@@ -52,22 +46,15 @@ type_stack::insert (enum type_pieces tp)
void
type_stack::insert (struct gdbarch *gdbarch, const char *string)
{
- union type_stack_elt element;
- int slot;
-
/* If there is anything on the stack (we know it will be a
tp_pointer), insert the address space qualifier above it.
Otherwise, simply push this on the top of the stack. */
- if (!m_elements.empty ())
- slot = 1;
- else
- slot = 0;
+ int slot = (!m_elements.empty ()) ? 1 : 0;
- element.piece = tp_space_identifier;
- insert_into (slot, element);
- element.int_val
- = address_space_name_to_type_instance_flags (gdbarch, string);
- insert_into (slot, element);
+ insert_into (slot, tp_space_identifier);
+ insert_into (slot,
+ address_space_name_to_type_instance_flags (gdbarch,
+ string));
}
/* See type-stack.h. */
diff --git a/gdb/type-stack.h b/gdb/type-stack.h
index 318ef715b2e..1be6d569d8e 100644
--- a/gdb/type-stack.h
+++ b/gdb/type-stack.h
@@ -238,12 +238,26 @@ struct type_stack
private:
/* A helper function for the insert methods. This does work of
- expanding the type stack and inserting the new element, ELEMENT,
+ expanding the type stack and inserting the new element, TP,
into the stack at location SLOT. */
- void insert_into (int slot, union type_stack_elt element)
+ void insert_into (int slot, enum type_pieces tp)
{
gdb_assert (slot <= m_elements.size ());
+ union type_stack_elt element;
+ element.piece = tp;
+ m_elements.insert (m_elements.begin () + slot, element);
+ }
+
+ /* A helper function for the insert methods. This does work of
+ expanding the type stack and inserting the new element, VAL,
+ into the stack at location SLOT. */
+
+ void insert_into (int slot, int val)
+ {
+ gdb_assert (slot <= m_elements.size ());
+ union type_stack_elt element;
+ element.int_val = val;
m_elements.insert (m_elements.begin () + slot, element);
}
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 06/17] gdb: inline address_space_{name, type_instance_flags}_to_{type_instance_flags, name}
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (4 preceding siblings ...)
2026-07-22 10:41 ` [PATCH v2 05/17] gdb: refactor type_stack::insert methods Tankut Baris Aktemur
@ 2026-07-22 10:41 ` Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 07/17] gdb: split make_type_with_address_space Tankut Baris Aktemur
` (11 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:41 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
This is yet another refactoring step to treat Harvard address space
ids and address class ids separately and transparently from the fact
that they are stored in type instance flags.
The function 'address_space_name_to_type_instance_flags' converts
address space and address class names to type instance flags. It
deals with the Harvard address space names "code" and "data" as well
as architecture specific address class names. As a result, it may
produce type instance flags where either the Harvard address space
bits or the address class bits are set. The function
'address_space_type_instance_flags_to_name' does the conversion in the
opposite direction.
Inline the functions and remove them. This is a step towards
separating the handling of two concepts.
In type-stack.c, which is used by the parser to convert user inputs
into types, "@code" and "@data" and architecture-specific address
class names are treated the same, too, blurring the difference and
their storage in type instance flags. While we inline the use of
address_space_name_to_type_instance_flags there, we also separate the
two topics by defining different tokens. The patch still pushes type
instance flags into the type stack. The subsequent patch will further
clean this up to store address class and address space ids.
A hardcoded shift operation will go away in a future patch.
---
gdb/c-typeprint.c | 17 ++++++--
gdb/gdbtypes.c | 45 ----------------------
gdb/gdbtypes.h | 6 ---
gdb/testsuite/gdb.base/address_space_qualifier.exp | 4 +-
gdb/type-stack.c | 33 +++++++++++++---
gdb/type-stack.h | 31 +++++++++------
6 files changed, 62 insertions(+), 74 deletions(-)
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 1168464a9f9..db3bc29475f 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -19,6 +19,7 @@
#include "event-top.h"
#include "bfd.h"
#include "symtab.h"
+#include "gdbarch.h"
#include "gdbtypes.h"
#include "expression.h"
#include "value.h"
@@ -482,10 +483,18 @@ c_type_print_modifier (struct type *type, struct ui_file *stream,
did_print_modifier = 1;
}
- address_space_id
- = address_space_type_instance_flags_to_name (type->arch (),
- type->instance_flags ());
- if (address_space_id)
+ address_space_id = nullptr;
+
+ if (TYPE_CODE_SPACE (type))
+ address_space_id = "code";
+ else if (TYPE_DATA_SPACE (type))
+ address_space_id = "data";
+ else if (gdbarch_address_class_id_to_name_p (type->arch ()))
+ address_space_id
+ = gdbarch_address_class_id_to_name (type->arch (),
+ TYPE_ADDRESS_CLASS (type));
+
+ if (address_space_id != nullptr)
{
if (did_print_modifier || need_pre_space)
gdb_printf (stream, " ");
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 87cc7d15d0d..97f1b3e1417 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -536,51 +536,6 @@ lookup_function_type_with_arguments (struct type *return_type,
return create_function_type (return_type, nparams, param_types);
}
-/* Identify address space identifier by name -- return a
- type_instance_flags. */
-
-type_instance_flags
-address_space_name_to_type_instance_flags (struct gdbarch *gdbarch,
- const char *space_identifier)
-{
- /* 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;
-
- 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);
-}
-
-/* Identify address space identifier by type_instance_flags and return
- the string version of the address space name. */
-
-const char *
-address_space_type_instance_flags_to_name (struct gdbarch *gdbarch,
- type_instance_flags space_flag)
-{
- if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE)
- return "code";
- else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE)
- return "data";
-
- unsigned int aclass = TYPE_ADDRESS_CLASS_FROM_INSTANCE_FLAGS (space_flag);
-
- if (gdbarch_address_class_id_to_name_p (gdbarch))
- return gdbarch_address_class_id_to_name (gdbarch, aclass);
- else
- return NULL;
-}
-
/* Create a new type with instance flags NEW_FLAGS, based on TYPE.
If STORAGE is non-NULL, create the new type instance there.
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 3c21d4ad214..1d5c96ab2c1 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -2420,12 +2420,6 @@ extern struct type *make_atomic_type (struct type *);
extern void replace_type (struct type *, struct type *);
-extern type_instance_flags address_space_name_to_type_instance_flags
- (struct gdbarch *, const char *);
-
-extern const char *address_space_type_instance_flags_to_name
- (struct gdbarch *, type_instance_flags);
-
extern struct type *make_type_with_address_space
(struct type *type, type_instance_flags space_identifier);
diff --git a/gdb/testsuite/gdb.base/address_space_qualifier.exp b/gdb/testsuite/gdb.base/address_space_qualifier.exp
index 49437dad60d..3e94e895493 100644
--- a/gdb/testsuite/gdb.base/address_space_qualifier.exp
+++ b/gdb/testsuite/gdb.base/address_space_qualifier.exp
@@ -22,12 +22,12 @@ gdb_test_no_output "set language c"
with_test_prefix "C" {
gdb_test "p *(@somerandomqualifiername int *) 0x12345678" \
- "Unknown address space specifier: \"somerandomqualifiername\""
+ "Unknown address space/class specifier: \"somerandomqualifiername\""
}
gdb_test_no_output "set language c++"
with_test_prefix "C++" {
gdb_test "p *(@somerandomqualifiername int *) 0x12345678" \
- "Unknown address space specifier: \"somerandomqualifiername\""
+ "Unknown address space/class specifier: \"somerandomqualifiername\""
}
diff --git a/gdb/type-stack.c b/gdb/type-stack.c
index d19854363a2..dce1a138e36 100644
--- a/gdb/type-stack.c
+++ b/gdb/type-stack.c
@@ -20,6 +20,7 @@
#include "type-stack.h"
#include "gdbtypes.h"
+#include "gdbarch.h"
/* See type-stack.h. */
@@ -51,10 +52,29 @@ type_stack::insert (struct gdbarch *gdbarch, const char *string)
Otherwise, simply push this on the top of the stack. */
int slot = (!m_elements.empty ()) ? 1 : 0;
- insert_into (slot, tp_space_identifier);
- insert_into (slot,
- address_space_name_to_type_instance_flags (gdbarch,
- string));
+ /* Check for Harvard address space delimiters and
+ architecture-specific address classes. */
+ if (streq (string, "code"))
+ {
+ insert_into (slot, tp_harvard_aspace_identifier);
+ insert_into (slot, TYPE_INSTANCE_FLAG_CODE_SPACE);
+ }
+ else if (streq (string, "data"))
+ {
+ insert_into (slot, tp_harvard_aspace_identifier);
+ insert_into (slot, TYPE_INSTANCE_FLAG_DATA_SPACE);
+ }
+ else if (unsigned int aclass = 0;
+ gdbarch_address_class_name_to_id_p (gdbarch)
+ && gdbarch_address_class_name_to_id (gdbarch,
+ string,
+ aclass))
+ {
+ insert_into (slot, tp_aclass_identifier);
+ insert_into (slot, (enum type_instance_flag_value) (aclass << 4));
+ }
+ else
+ error (_("Unknown address space/class specifier: \"%s\""), string);
}
/* See type-stack.h. */
@@ -112,7 +132,10 @@ type_stack::follow_types (struct type *follow_type)
case tp_volatile:
make_volatile = 1;
break;
- case tp_space_identifier:
+ case tp_harvard_aspace_identifier:
+ make_addr_space = (enum type_instance_flag_value) pop_int ();
+ break;
+ case tp_aclass_identifier:
make_addr_space = (enum type_instance_flag_value) pop_int ();
break;
case tp_atomic:
diff --git a/gdb/type-stack.h b/gdb/type-stack.h
index 1be6d569d8e..19199afd432 100644
--- a/gdb/type-stack.h
+++ b/gdb/type-stack.h
@@ -45,9 +45,12 @@ enum type_pieces
tp_function_with_arguments,
tp_const,
tp_volatile,
- /* An address space identifier. The address space is also pushed on
+ /* An Harvard address space identifier (i.e. "code" or "data"). The
+ address space is also pushed on the stack. */
+ tp_harvard_aspace_identifier,
+ /* An address class identifier. The address class is also pushed on
the stack. */
- tp_space_identifier,
+ tp_aclass_identifier,
tp_atomic,
tp_restrict,
/* A separate type stack, which is also pushed onto this type
@@ -114,7 +117,8 @@ struct type_stack
accept an integer argument are allowed. */
void push (enum type_pieces tp, int n)
{
- gdb_assert (tp == tp_array || tp == tp_space_identifier || tp == tp_kind);
+ gdb_assert (tp == tp_array || tp == tp_harvard_aspace_identifier
+ || tp == tp_aclass_identifier || tp == tp_kind);
type_stack_elt elt;
elt.int_val = n;
m_elements.push_back (elt);
@@ -172,7 +176,8 @@ struct type_stack
type_stack_elt elt = m_elements.back ();
m_elements.pop_back ();
type_pieces tp = elt.piece;
- gdb_assert (tp == tp_array || tp == tp_space_identifier || tp == tp_kind);
+ gdb_assert (tp == tp_array || tp == tp_harvard_aspace_identifier
+ || tp == tp_aclass_identifier || tp == tp_kind);
elt = m_elements.back ();
m_elements.pop_back ();
return elt.int_val;
@@ -204,13 +209,14 @@ struct type_stack
return elt.stack_val;
}
- /* Insert a tp_space_identifier and the corresponding address space
- value into the stack. STRING is the name of an address space, as
- recognized by address_space_name_to_type_instance_flags. If the
- stack is empty, the new elements are simply pushed. If the stack
- is not empty, this function assumes that the first item on the
- stack is a tp_pointer, and the new values are inserted above the
- first item. */
+ /* Insert an address space or address class identifier and the
+ corresponding id value into the stack. STRING is the name of a
+ Harvard address space ("code" or "data"), or the name of an
+ address class as recognized by gdbarch_address_class_name_to_id.
+ If the stack is empty, the new elements are simply pushed. If
+ the stack is not empty, this function assumes that the first item
+ on the stack is a tp_pointer, and the new values are inserted
+ above the first item. */
void insert (struct gdbarch *gdbarch, const char *string);
@@ -266,7 +272,8 @@ struct type_stack
{
return (tp == tp_array || tp == tp_kind || tp == tp_type_stack
|| tp == tp_function_with_arguments
- || tp == tp_space_identifier);
+ || tp == tp_harvard_aspace_identifier
+ || tp == tp_aclass_identifier);
}
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 07/17] gdb: split make_type_with_address_space
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (5 preceding siblings ...)
2026-07-22 10:41 ` [PATCH v2 06/17] gdb: inline address_space_{name, type_instance_flags}_to_{type_instance_flags, name} Tankut Baris Aktemur
@ 2026-07-22 10:41 ` Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 08/17] gdb: convert type instance flags to bitfields Tankut Baris Aktemur
` (10 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:41 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
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 | 54 ++++++++++++++++++++++++++++++++++--------------------
gdb/gnu-v3-abi.c | 2 +-
gdb/printcmd.c | 13 ++++++++++++-
gdb/type-stack.c | 27 +++++++++++++++++----------
6 files changed, 98 insertions(+), 46 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..aa80dfb51c0 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,16 +600,40 @@ 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)
+make_type_with_harvard_address_space (struct type *type,
+ enum harvard_address_space aspace)
{
- 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);
+ type_instance_flags new_flags
+ = (enum type_instance_flag_value) (aspace << 2);
- return make_qualified_type (type, new_flags, NULL);
+ 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, nullptr);
+}
+
+/* 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, nullptr);
}
/* See gdbtypes.h. */
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 1d5c96ab2c1..1749c3ba741 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -71,6 +71,34 @@ enum type_code
};
+/* Enum encoded in instance flags of a type to denote which Harvard
+ address space the type refers to.
+
+ Harvard architectures have separate instruction and data address
+ spaces (and perhaps others). GDB usually defines a flat address
+ space that is a superset of the architecture's two (or more)
+ address spaces, but this is an extension of the architecture's
+ model.
+
+ If using HARVARD_ASPACE_CODE, an object of the corresponding type
+ resides in instruction memory, even if its address (in the extended
+ flat address space) does not reflect this.
+
+ Similarly, if using HARVARD_ASPACE_DATA, then an object of the
+ corresponding type resides in the data memory space, even if this
+ is not indicated by its (flat address space) address.
+
+ If using HARVARD_ASPACE_NONE, the default space for functions /
+ methods is instruction space, and for data objects is data
+ memory. */
+
+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. */
@@ -135,24 +163,7 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
(((t)->dyn_prop (DYN_PROP_BYTE_SIZE) != nullptr) \
|| ((t)->dyn_prop (DYN_PROP_BIT_SIZE) != nullptr))
-/* Instruction-space delimited type. This is for Harvard architectures
- which have separate instruction and data address spaces (and perhaps
- others).
-
- GDB usually defines a flat address space that is a superset of the
- architecture's two (or more) address spaces, but this is an extension
- of the architecture's model.
-
- If TYPE_INSTANCE_FLAG_CODE_SPACE is set, an object of the corresponding type
- resides in instruction memory, even if its address (in the extended
- flat address space) does not reflect this.
-
- Similarly, if TYPE_INSTANCE_FLAG_DATA_SPACE is set, then an object of the
- corresponding type resides in the data memory space, even if
- this is not indicated by its (flat address space) address.
-
- If neither flag is set, the default space for functions / methods
- is instruction space, and for data objects is data memory. */
+/* See enum harvard_address_space above. */
#define TYPE_CODE_SPACE(t) \
((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CODE_SPACE) != 0)
@@ -2420,8 +2431,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 15c086a9284..b79dbe24c17 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 dce1a138e36..c5ff1d718c4 100644
--- a/gdb/type-stack.c
+++ b/gdb/type-stack.c
@@ -57,12 +57,12 @@ type_stack::insert (struct gdbarch *gdbarch, const char *string)
if (streq (string, "code"))
{
insert_into (slot, tp_harvard_aspace_identifier);
- insert_into (slot, TYPE_INSTANCE_FLAG_CODE_SPACE);
+ insert_into (slot, HARVARD_ASPACE_CODE);
}
else if (streq (string, "data"))
{
insert_into (slot, tp_harvard_aspace_identifier);
- insert_into (slot, TYPE_INSTANCE_FLAG_DATA_SPACE);
+ insert_into (slot, HARVARD_ASPACE_DATA);
}
else if (unsigned int aclass = 0;
gdbarch_address_class_name_to_id_p (gdbarch)
@@ -71,7 +71,7 @@ type_stack::insert (struct gdbarch *gdbarch, const char *string)
aclass))
{
insert_into (slot, tp_aclass_identifier);
- insert_into (slot, (enum type_instance_flag_value) (aclass << 4));
+ insert_into (slot, aclass);
}
else
error (_("Unknown address space/class specifier: \"%s\""), string);
@@ -114,7 +114,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;
@@ -133,10 +134,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;
@@ -161,15 +162,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
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 08/17] gdb: convert type instance flags to bitfields
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (6 preceding siblings ...)
2026-07-22 10:41 ` [PATCH v2 07/17] gdb: split make_type_with_address_space Tankut Baris Aktemur
@ 2026-07-22 10:41 ` Tankut Baris Aktemur
2026-07-24 19:10 ` Keith Seitz
2026-07-22 10:41 ` [PATCH v2 09/17] gdb: convert TYPE_NOTTEXT macro to type::is_nottext Tankut Baris Aktemur
` (9 subsequent siblings)
17 siblings, 1 reply; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:41 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
Convert the instance flags of a type to a struct with bitfields. This
helps avoid bitwise operations and instead refer to the fields by
name. In particular, Harvard address space information (i.e. code
space and data space) and address class information become enum values
instead of being handled by seemingly independent bits.
---
gdb/d-lang.c | 9 +--
gdb/expop.h | 6 ++
gdb/expprint.c | 4 +-
gdb/ft32-tdep.c | 5 +-
gdb/gdb-gdb.py.in | 99 ++++++-----------------
gdb/gdbtypes.c | 105 +++++++++---------------
gdb/gdbtypes.h | 138 ++++++++++++++++++--------------
gdb/printcmd.c | 17 ++--
gdb/testsuite/gdb.base/maint.exp | 2 +-
gdb/testsuite/gdb.gdb/python-helper.exp | 8 +-
gdb/type-stack.c | 10 +--
11 files changed, 172 insertions(+), 231 deletions(-)
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 0a779a7b7c0..c2a11375830 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -233,13 +233,8 @@ build_d_types (struct gdbarch *gdbarch)
= init_float_type (alloc, gdbarch_long_double_bit (gdbarch),
"real", gdbarch_long_double_format (gdbarch));
- builtin_d_type->builtin_byte->set_instance_flags
- (builtin_d_type->builtin_byte->instance_flags ()
- | TYPE_INSTANCE_FLAG_NOTTEXT);
-
- builtin_d_type->builtin_ubyte->set_instance_flags
- (builtin_d_type->builtin_ubyte->instance_flags ()
- | TYPE_INSTANCE_FLAG_NOTTEXT);
+ builtin_d_type->builtin_byte->set_nottext (true);
+ builtin_d_type->builtin_ubyte->set_nottext (true);
/* Imaginary and complex types. */
builtin_d_type->builtin_ifloat
diff --git a/gdb/expop.h b/gdb/expop.h
index 6d6f4acdc24..ce175afbc3d 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -275,6 +275,12 @@ check_objfile (enum_flags<T> val, struct objfile *objfile)
return false;
}
+static inline bool
+check_objfile (type_instance_flags val, struct objfile *objfile)
+{
+ return false;
+}
+
template<typename T>
static inline bool
check_objfile (const std::vector<T> &collection, struct objfile *objfile)
diff --git a/gdb/expprint.c b/gdb/expprint.c
index e99430d2325..bc1929b1a1b 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -148,9 +148,9 @@ dump_for_expression (struct ui_file *stream, int depth,
type_instance_flags flags)
{
gdb_printf (stream, _("%*sType flags: "), depth, "");
- if (flags & TYPE_INSTANCE_FLAG_CONST)
+ if (flags.is_const)
gdb_puts ("const ", stream);
- if (flags & TYPE_INSTANCE_FLAG_VOLATILE)
+ if (flags.is_volatile)
gdb_puts ("volatile", stream);
gdb_printf (stream, "\n");
}
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index 476e79355c7..f951a6f25e3 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -332,7 +332,7 @@ ft32_pointer_to_address (struct gdbarch *gdbarch,
CORE_ADDR addr
= extract_unsigned_integer (buf, type->length (), byte_order);
- if (TYPE_ADDRESS_CLASS_1 (type))
+ if (TYPE_ADDRESS_CLASS (type) == 1)
return addr;
else
return addr | RAM_BIAS;
@@ -579,8 +579,7 @@ ft32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
func_void_type = lookup_function_type (void_type);
tdep->pc_type = init_pointer_type (alloc, 4 * TARGET_CHAR_BIT, NULL,
func_void_type);
- tdep->pc_type->set_instance_flags (tdep->pc_type->instance_flags ()
- | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1);
+ tdep->pc_type->set_address_class (1);
set_gdbarch_num_regs (gdbarch, FT32_NUM_REGS);
set_gdbarch_sp_regnum (gdbarch, FT32_SP_REGNUM);
diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
index 417b6492db5..7e39d27366e 100644
--- a/gdb/gdb-gdb.py.in
+++ b/gdb/gdb-gdb.py.in
@@ -20,86 +20,32 @@ import os.path
import gdb
-class TypeFlag:
- """A class that allows us to store a flag name, its short name,
- and its value.
-
- In the GDB sources, struct type has a component called instance_flags
- in which the value is the addition of various flags. These flags are
- defined by the enumerates type_instance_flag_value. This class helps us
- recreate a list with all these flags that is easy to manipulate and sort.
- Because all flag names start with TYPE_INSTANCE_FLAG_, a short_name
- attribute is provided that strips this prefix.
-
- ATTRIBUTES
- name: The enumeration name (eg: "TYPE_INSTANCE_FLAG_CONST").
- value: The associated value.
- short_name: The enumeration name, with the suffix stripped.
- """
-
- def __init__(self, name, value):
- self.name = name
- self.value = value
- self.short_name = name.replace("TYPE_INSTANCE_FLAG_", "")
-
- def __lt__(self, other):
- """Sort by value order."""
- return self.value < other.value
-
-
-# A list of all existing TYPE_INSTANCE_FLAGS_* enumerations,
-# stored as TypeFlags objects. Lazy-initialized.
-TYPE_FLAGS = None
-
-
-class TypeFlagsPrinter:
- """A class that prints a decoded form of an instance_flags value.
-
- This class uses a global named TYPE_FLAGS, which is a list of
- all defined TypeFlag values. Using a global allows us to compute
- this list only once.
-
- This class relies on a couple of enumeration types being defined.
- If not, then printing of the instance_flag is going to be degraded,
- but it's not a fatal error.
- """
+class StructTypeInstanceFlagsPrettyPrinter:
+ """Pretty-print an object of type struct type_instance_flags"""
def __init__(self, val):
self.val = val
def __str__(self):
- global TYPE_FLAGS
- if TYPE_FLAGS is None:
- self.init_TYPE_FLAGS()
- if not self.val:
- return "0"
- if TYPE_FLAGS:
- flag_list = [
- flag.short_name for flag in TYPE_FLAGS if self.val & flag.value
- ]
- else:
- flag_list = ["???"]
- return "0x%x [%s]" % (self.val, "|".join(flag_list))
-
- def init_TYPE_FLAGS(self):
- """Initialize the TYPE_FLAGS global as a list of TypeFlag objects.
- This operation requires the search of a couple of enumeration types.
- If not found, a warning is printed on stdout, and TYPE_FLAGS is
- set to the empty list.
-
- The resulting list is sorted by increasing value, to facilitate
- printing of the list of flags used in an instance_flags value.
- """
- global TYPE_FLAGS
- TYPE_FLAGS = []
- try:
- iflags = gdb.lookup_type("enum type_instance_flag_value")
- except:
- print("Warning: Cannot find enum type_instance_flag_value type.")
- print(" `struct type' pretty-printer will be degraded")
- return
- TYPE_FLAGS = [TypeFlag(field.name, field.enumval) for field in iflags.fields()]
- TYPE_FLAGS.sort()
+ fields = []
+ if self.val["is_const"]:
+ fields.append("CONST")
+ if self.val["is_volatile"]:
+ fields.append("VOLATILE")
+ if self.val["harvard_aspace"] == 1: # HARVARD_ASPACE_CODE
+ fields.append("CODE_SPACE")
+ elif self.val["harvard_aspace"] == 2: # HARVARD_ASPACE_DATA
+ fields.append("DATA_SPACE")
+ if self.val["address_class"] != 0:
+ fields.append("ADDRESS_CLASS(%d)" % self.val["address_class"])
+ if self.val["is_nottext"]:
+ fields.append("NOTTEXT")
+ if self.val["is_restrict"]:
+ fields.append("RESTRICT")
+ if self.val["is_atomic"]:
+ fields.append("ATOMIC")
+
+ return "[" + "|".join(fields) + "]"
class StructTypePrettyPrinter:
@@ -114,7 +60,8 @@ class StructTypePrettyPrinter:
fields.append("reference_type = %s" % self.val["reference_type"])
fields.append("chain = %s" % self.val["reference_type"])
fields.append(
- "instance_flags = %s" % TypeFlagsPrinter(self.val["m_instance_flags"])
+ "instance_flags = %s"
+ % StructTypeInstanceFlagsPrettyPrinter(self.val["m_instance_flags"])
)
fields.append("length = %d" % self.val["m_length"])
fields.append("main_type = %s" % self.val["main_type"])
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index aa80dfb51c0..a866f36d1ea 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -603,14 +603,11 @@ struct type *
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));
+ gdb_assert (aspace == HARVARD_ASPACE_NONE
+ || aspace == HARVARD_ASPACE_CODE
+ || aspace == HARVARD_ASPACE_DATA);
+ type_instance_flags new_flags = type->instance_flags ();
+ new_flags.harvard_aspace = aspace;
return make_qualified_type (type, new_flags, nullptr);
}
@@ -625,13 +622,9 @@ 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);
+ gdb_assert (address_class < 4); /* We use two bits for this field. */
+ type_instance_flags new_flags = type->instance_flags ();
+ new_flags.address_class = address_class;
return make_qualified_type (type, new_flags, nullptr);
}
@@ -641,15 +634,9 @@ make_type_with_address_class (struct type *type,
type *
make_cv_type (int cnst, int voltl, type *type)
{
- type_instance_flags new_flags = (type->instance_flags ()
- & ~(TYPE_INSTANCE_FLAG_CONST
- | TYPE_INSTANCE_FLAG_VOLATILE));
-
- if (cnst)
- new_flags |= TYPE_INSTANCE_FLAG_CONST;
-
- if (voltl)
- new_flags |= TYPE_INSTANCE_FLAG_VOLATILE;
+ type_instance_flags new_flags = type->instance_flags ();
+ new_flags.is_const = cnst;
+ new_flags.is_volatile = voltl;
return make_qualified_type (type, new_flags, nullptr);
}
@@ -659,10 +646,10 @@ make_cv_type (int cnst, int voltl, type *type)
struct type *
make_restrict_type (struct type *type)
{
- return make_qualified_type (type,
- (type->instance_flags ()
- | TYPE_INSTANCE_FLAG_RESTRICT),
- NULL);
+ type_instance_flags new_flags = type->instance_flags ();
+ new_flags.is_restrict = true;
+
+ return make_qualified_type (type, new_flags, nullptr);
}
/* Make a type without const, volatile, or restrict. */
@@ -670,12 +657,12 @@ make_restrict_type (struct type *type)
struct type *
make_unqualified_type (struct type *type)
{
- return make_qualified_type (type,
- (type->instance_flags ()
- & ~(TYPE_INSTANCE_FLAG_CONST
- | TYPE_INSTANCE_FLAG_VOLATILE
- | TYPE_INSTANCE_FLAG_RESTRICT)),
- NULL);
+ type_instance_flags new_flags = type->instance_flags ();
+ new_flags.is_const = false;
+ new_flags.is_volatile = false;
+ new_flags.is_restrict = false;
+
+ return make_qualified_type (type, new_flags, nullptr);
}
/* Make a '_Atomic'-qualified version of TYPE. */
@@ -683,10 +670,10 @@ make_unqualified_type (struct type *type)
struct type *
make_atomic_type (struct type *type)
{
- return make_qualified_type (type,
- (type->instance_flags ()
- | TYPE_INSTANCE_FLAG_ATOMIC),
- NULL);
+ type_instance_flags new_flags = type->instance_flags ();
+ new_flags.is_atomic = true;
+
+ return make_qualified_type (type, new_flags, nullptr);
}
/* Replace the contents of ntype with the type *type. This changes the
@@ -723,7 +710,7 @@ replace_type (struct type *ntype, struct type *type)
variants. This assertion shouldn't ever be triggered because
symbol readers which do construct address-class variants don't
call replace_type(). */
- gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
+ gdb_assert (TYPE_ADDRESS_CLASS (chain) == 0);
chain->set_length (type->length ());
chain = chain->chain;
@@ -1362,8 +1349,8 @@ make_vector_type (struct type *array_type)
elt_type = inner_array->target_type ();
if (elt_type->code () == TYPE_CODE_INT)
{
- type_instance_flags flags
- = elt_type->instance_flags () | TYPE_INSTANCE_FLAG_NOTTEXT;
+ type_instance_flags flags = elt_type->instance_flags ();
+ flags.is_nottext = true;
elt_type = make_qualified_type (elt_type, flags, NULL);
inner_array->set_target_type (elt_type);
}
@@ -3074,19 +3061,13 @@ check_typedef (struct type *type)
outer cast in a chain of casting win), instead of assuming
"it can't happen". */
{
- const type_instance_flags ALL_SPACES
- = (TYPE_INSTANCE_FLAG_CODE_SPACE
- | TYPE_INSTANCE_FLAG_DATA_SPACE);
- const type_instance_flags ALL_CLASSES
- = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL;
-
type_instance_flags new_instance_flags = type->instance_flags ();
/* Treat code vs data spaces and address classes separately. */
- if ((instance_flags & ALL_SPACES) != 0)
- new_instance_flags &= ~ALL_SPACES;
- if ((instance_flags & ALL_CLASSES) != 0)
- new_instance_flags &= ~ALL_CLASSES;
+ if (instance_flags.harvard_aspace != HARVARD_ASPACE_NONE)
+ new_instance_flags.harvard_aspace = HARVARD_ASPACE_NONE;
+ if (instance_flags.address_class != 0)
+ new_instance_flags.address_class = 0;
instance_flags |= new_instance_flags;
}
@@ -5039,8 +5020,7 @@ recursive_dump_type (struct type *type, int spaces)
host_address_to_string (type->reference_type));
gdb_printf ("%*stype_chain %s\n", spaces, "",
host_address_to_string (type->chain));
- gdb_printf ("%*sinstance_flags 0x%x", spaces, "",
- (unsigned) type->instance_flags ());
+ gdb_printf ("%*sinstance_flags [", spaces, "");
if (TYPE_CONST (type))
{
gdb_puts (" TYPE_CONST");
@@ -5057,13 +5037,9 @@ recursive_dump_type (struct type *type, int spaces)
{
gdb_puts (" TYPE_DATA_SPACE");
}
- if (TYPE_ADDRESS_CLASS_1 (type))
+ if (TYPE_ADDRESS_CLASS (type) != 0)
{
- gdb_puts (" TYPE_ADDRESS_CLASS_1");
- }
- if (TYPE_ADDRESS_CLASS_2 (type))
- {
- gdb_puts (" TYPE_ADDRESS_CLASS_2");
+ gdb_printf (" TYPE_ADDRESS_CLASS(%u)", TYPE_ADDRESS_CLASS (type));
}
if (TYPE_RESTRICT (type))
{
@@ -5073,7 +5049,7 @@ recursive_dump_type (struct type *type, int spaces)
{
gdb_puts (" TYPE_ATOMIC");
}
- gdb_puts ("\n");
+ gdb_puts ("]\n");
gdb_printf ("%*sflags", spaces, "");
if (type->is_unsigned ())
@@ -5875,13 +5851,8 @@ create_gdbtypes_data (struct gdbarch *gdbarch)
builtin_type->builtin_uint128
= init_integer_type (alloc, 128, 1, "uint128_t");
- builtin_type->builtin_int8->set_instance_flags
- (builtin_type->builtin_int8->instance_flags ()
- | TYPE_INSTANCE_FLAG_NOTTEXT);
-
- builtin_type->builtin_uint8->set_instance_flags
- (builtin_type->builtin_uint8->instance_flags ()
- | TYPE_INSTANCE_FLAG_NOTTEXT);
+ builtin_type->builtin_int8->set_nottext (true);
+ builtin_type->builtin_uint8->set_nottext (true);
/* Wide character types. */
builtin_type->builtin_char16
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 1749c3ba741..11a08428baf 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -99,51 +99,80 @@ enum harvard_address_space
HARVARD_ASPACE_DATA = 2,
};
-/* Some bits for the type's instance_flags word. See the macros
- below for documentation on each bit. */
+/* A type's instance_flags. */
-enum type_instance_flag_value : unsigned
+struct type_instance_flags
{
- TYPE_INSTANCE_FLAG_CONST = (1 << 0),
- TYPE_INSTANCE_FLAG_VOLATILE = (1 << 1),
- TYPE_INSTANCE_FLAG_CODE_SPACE = (1 << 2),
- TYPE_INSTANCE_FLAG_DATA_SPACE = (1 << 3),
- TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 = (1 << 4),
- TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2 = (1 << 5),
- TYPE_INSTANCE_FLAG_NOTTEXT = (1 << 6),
- TYPE_INSTANCE_FLAG_RESTRICT = (1 << 7),
- TYPE_INSTANCE_FLAG_ATOMIC = (1 << 8)
-};
+ bool operator== (const type_instance_flags &other) const
+ {
+ return (is_const == other.is_const
+ && is_volatile == other.is_volatile
+ && harvard_aspace == other.harvard_aspace
+ && address_class == other.address_class
+ && is_nottext == other.is_nottext
+ && is_restrict == other.is_restrict
+ && is_atomic == other.is_atomic);
+ }
-DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
+ bool operator!= (const type_instance_flags &other) const
+ {
+ return !(*this == other);
+ }
-/* Not textual. By default, GDB treats all single byte integers as
- characters (or elements of strings) unless this flag is set. */
+ type_instance_flags &operator|= (const type_instance_flags &other)
+ {
+ is_const = is_const || other.is_const;
+ is_volatile = is_volatile || other.is_volatile;
+
+ gdb_assert (harvard_aspace == 0);
+ harvard_aspace = other.harvard_aspace;
-#define TYPE_NOTTEXT(t) (((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_NOTTEXT)
+ gdb_assert (address_class == 0);
+ address_class = other.address_class;
+
+ is_nottext = is_nottext || other.is_nottext;
+ is_restrict = is_restrict || other.is_restrict;
+ is_atomic = is_atomic || other.is_atomic;
+ return *this;
+ }
-/* Constant type. If this is set, the corresponding type has a
- const modifier. */
+ /* Constant type. If this is set, the corresponding type has a
+ const modifier. */
+ bool is_const : 1;
-#define TYPE_CONST(t) ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CONST) != 0)
+ /* Volatile type. If this is set, the corresponding type has a
+ volatile modifier. */
+ bool is_volatile : 1;
-/* Volatile type. If this is set, the corresponding type has a
- volatile modifier. */
+ /* See enum harvard_address_space above. */
+ harvard_address_space harvard_aspace : 2;
-#define TYPE_VOLATILE(t) \
- ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_VOLATILE) != 0)
+ /* Address class field. Some environments provide for pointers
+ whose size is different from that of a normal pointer or address
+ types where the bits are interpreted differently than normal
+ addresses. The ADDRESS_CLASS field may be used in target
+ specific ways to represent these different types of address
+ classes. */
+ unsigned int address_class : 2;
-/* Restrict type. If this is set, the corresponding type has a
- restrict modifier. */
+ /* Not textual. By default, GDB treats all single byte integers as
+ characters (or elements of strings) unless this flag is set. */
+ bool is_nottext : 1;
-#define TYPE_RESTRICT(t) \
- ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_RESTRICT) != 0)
+ /* Restrict type. If this is set, the corresponding type has a
+ restrict modifier. */
+ bool is_restrict : 1;
-/* Atomic type. If this is set, the corresponding type has an
- _Atomic modifier. */
+ /* Atomic type. If this is set, the corresponding type has an
+ _Atomic modifier. */
+ bool is_atomic : 1;
+};
-#define TYPE_ATOMIC(t) \
- ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_ATOMIC) != 0)
+#define TYPE_NOTTEXT(t) (((t)->instance_flags ()).is_nottext)
+#define TYPE_CONST(t) (((t)->instance_flags ()).is_const)
+#define TYPE_VOLATILE(t) (((t)->instance_flags ()).is_volatile)
+#define TYPE_RESTRICT(t) (((t)->instance_flags ()).is_restrict)
+#define TYPE_ATOMIC(t) (((t)->instance_flags ()).is_atomic)
/* True if this type represents either an lvalue or lvalue reference type. */
@@ -163,33 +192,14 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
(((t)->dyn_prop (DYN_PROP_BYTE_SIZE) != nullptr) \
|| ((t)->dyn_prop (DYN_PROP_BIT_SIZE) != nullptr))
-/* See enum harvard_address_space above. */
-
#define TYPE_CODE_SPACE(t) \
- ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CODE_SPACE) != 0)
+ (((t)->instance_flags ()).harvard_aspace == HARVARD_ASPACE_CODE)
#define TYPE_DATA_SPACE(t) \
- ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_DATA_SPACE) != 0)
-
-/* Address class flags. Some environments provide for pointers
- whose size is different from that of a normal pointer or address
- types where the bits are interpreted differently than normal
- addresses. The TYPE_INSTANCE_FLAG_ADDRESS_CLASS_n flags may be used in
- target specific ways to represent these different types of address
- classes. */
-
-#define TYPE_ADDRESS_CLASS_1(t) (((t)->instance_flags ()) \
- & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1)
-#define TYPE_ADDRESS_CLASS_2(t) (((t)->instance_flags ()) \
- & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2)
-#define TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL \
- (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)
+ (((t)->instance_flags ()).harvard_aspace == HARVARD_ASPACE_DATA)
+
#define TYPE_ADDRESS_CLASS(t) \
- (TYPE_ADDRESS_CLASS_FROM_INSTANCE_FLAGS ((t)->instance_flags ()))
+ (((t)->instance_flags ()).address_class)
/* Information about a single discriminant. */
@@ -1167,10 +1177,10 @@ struct type
this->field (0).set_type (index_type);
}
- /* Return the instance flags converted to the correct type. */
+ /* Return the instance flags. */
const type_instance_flags instance_flags () const
{
- return (enum type_instance_flag_value) this->m_instance_flags;
+ return this->m_instance_flags;
}
/* Set the instance flags. */
@@ -1179,6 +1189,18 @@ struct type
this->m_instance_flags = flags;
}
+ /* Set the address class id. */
+ void set_address_class (unsigned int address_class)
+ {
+ this->m_instance_flags.address_class = address_class;
+ }
+
+ /* Set the is_nottext flag. */
+ void set_nottext (bool flag)
+ {
+ this->m_instance_flags.is_nottext = flag;
+ }
+
/* Get the bounds bounds of this type. The type must be a range type. */
range_bounds *bounds () const
{
@@ -1597,7 +1619,7 @@ struct type
instance flags are completely inherited from the target type. No
qualifiers can be cleared by the typedef. See also
check_typedef. */
- unsigned m_instance_flags : 9;
+ type_instance_flags m_instance_flags;
/* Length of storage for a value of this type. The value is the
expression in host bytes of what sizeof(type) would return. This
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index b79dbe24c17..c9e6e4886e3 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1056,17 +1056,12 @@ format_to_type (format_data fmt, gdbarch *gdbarch, type_instance_flags flags)
gdb_assert (val_type != nullptr);
- if ((flags & TYPE_INSTANCE_FLAG_CODE_SPACE) != 0)
+ if (flags.harvard_aspace != HARVARD_ASPACE_NONE)
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);
+ flags.harvard_aspace);
- 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);
+ if (flags.address_class != 0)
+ val_type = make_type_with_address_class (val_type, flags.address_class);
return val_type;
}
@@ -1899,7 +1894,7 @@ x_command (const char *exp, int from_tty)
else
next_address = value_as_address (val);
- type_instance_flags flags = 0;
+ type_instance_flags flags {};
if (val->type ()->is_pointer_or_reference ())
flags = val->type ()->target_type ()->instance_flags ();
@@ -2186,7 +2181,7 @@ do_one_display (struct display *d)
if (d->format.format == 'i')
addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr);
- type_instance_flags flags = 0;
+ type_instance_flags flags {};
if (val->type ()->is_pointer_or_reference ())
flags = val->type ()->target_type ()->instance_flags ();
diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
index 0099eb672dc..f0c183c8c41 100644
--- a/gdb/testsuite/gdb.base/maint.exp
+++ b/gdb/testsuite/gdb.base/maint.exp
@@ -280,7 +280,7 @@ foreach { test_name command } $test_list {
set msg "maint print type"
gdb_test_multiple "maint print type argc" $msg {
- -re "type node $hex\r\nname .int. \\($hex\\)\r\ncode $hex \\(TYPE_CODE_INT\\)\r\nlength \[24\]\r\nobjfile $hex\r\ntarget_type $hex\r\npointer_type $hex\r\nreference_type $hex\r\ntype_chain $hex\r\ninstance_flags $hex\r\nflags\r\nnfields 0 $hex\r\n$gdb_prompt $" {
+ -re "type node $hex\r\nname .int. \\($hex\\)\r\ncode $hex \\(TYPE_CODE_INT\\)\r\nlength \[24\]\r\nobjfile $hex\r\ntarget_type $hex\r\npointer_type $hex\r\nreference_type $hex\r\ntype_chain $hex\r\ninstance_flags \\\[\\\]\r\nflags\r\nnfields 0 $hex\r\n$gdb_prompt $" {
pass $msg
}
}
diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp
index e700deda16d..d1cca48cbb8 100644
--- a/gdb/testsuite/gdb.gdb/python-helper.exp
+++ b/gdb/testsuite/gdb.gdb/python-helper.exp
@@ -151,7 +151,7 @@ proc test_python_helper {} {
"\{pointer_type = 0x0," \
" reference_type = 0x0," \
" chain = 0x0," \
- " instance_flags = 0," \
+ " instance_flags = \\\[\\\]," \
" length = $decimal," \
" main_type = $hex\}"]
gdb_test -prompt $outer_prompt_re "print *val->m_type" $answer "pretty print type"
@@ -166,6 +166,12 @@ proc test_python_helper {} {
" int_stuff = \{ bit_size = $decimal, bit_offset = $decimal \}\}"]
gdb_test -prompt $outer_prompt_re "print *val->m_type->main_type" $answer "pretty print type->main_type"
+ # Test printing instance flags using an artificial type.
+ set answer [string_to_regexp {instance_flags = [VOLATILE|DATA_SPACE|ADDRESS_CLASS(3)]}]
+ gdb_test -prompt $outer_prompt_re \
+ "print *make_type_with_harvard_address_space (make_cv_type (0, 1, make_type_with_address_class (val->m_type, 3)), 2)" \
+ "${answer}.*" "pretty print type instance flags"
+
# Send the continue to the outer GDB, which resumes the inner GDB,
# we then detect the prompt from the inner GDB, hence the use of
# -i here.
diff --git a/gdb/type-stack.c b/gdb/type-stack.c
index c5ff1d718c4..476848fcad1 100644
--- a/gdb/type-stack.c
+++ b/gdb/type-stack.c
@@ -82,7 +82,7 @@ type_stack::insert (struct gdbarch *gdbarch, const char *string)
type_instance_flags
type_stack::follow_type_instance_flags ()
{
- type_instance_flags flags = 0;
+ type_instance_flags flags {};
for (;;)
switch (pop ())
@@ -90,16 +90,16 @@ type_stack::follow_type_instance_flags ()
case tp_end:
return flags;
case tp_const:
- flags |= TYPE_INSTANCE_FLAG_CONST;
+ flags.is_const = true;
break;
case tp_volatile:
- flags |= TYPE_INSTANCE_FLAG_VOLATILE;
+ flags.is_volatile = true;
break;
case tp_atomic:
- flags |= TYPE_INSTANCE_FLAG_ATOMIC;
+ flags.is_atomic = true;
break;
case tp_restrict:
- flags |= TYPE_INSTANCE_FLAG_RESTRICT;
+ flags.is_restrict = true;
break;
default:
gdb_assert_not_reached ("unrecognized tp_ value in follow_types");
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 09/17] gdb: convert TYPE_NOTTEXT macro to type::is_nottext
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (7 preceding siblings ...)
2026-07-22 10:41 ` [PATCH v2 08/17] gdb: convert type instance flags to bitfields Tankut Baris Aktemur
@ 2026-07-22 10:41 ` Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 10/17] gdb: convert TYPE_CONST macro to type::is_const Tankut Baris Aktemur
` (8 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:41 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
Convert the TYPE_NOTTEXT macro to a method of the type class. This is
a refactoring.
---
gdb/c-valprint.c | 2 +-
gdb/gdbtypes.c | 8 +++-----
gdb/gdbtypes.h | 7 ++++++-
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index 9f9f61ea2e0..2ee65c41061 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -109,7 +109,7 @@ c_textual_element_type (struct type *type, char format)
being used as data. */
if (true_type->code () == TYPE_CODE_INT
&& true_type->length () == 1
- && !TYPE_NOTTEXT (true_type))
+ && !true_type->is_nottext ())
return 1;
}
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index a866f36d1ea..dd73d9e624f 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -4126,7 +4126,7 @@ check_types_equal (struct type *type1, struct type *type2,
|| type1->endianity_is_not_default () != type2->endianity_is_not_default ()
|| type1->has_varargs () != type2->has_varargs ()
|| type1->is_vector () != type2->is_vector ()
- || TYPE_NOTTEXT (type1) != TYPE_NOTTEXT (type2)
+ || type1->is_nottext () != type2->is_nottext ()
|| type1->instance_flags () != type2->instance_flags ()
|| type1->num_fields () != type2->num_fields ())
return false;
@@ -5091,10 +5091,8 @@ recursive_dump_type (struct type *type, int spaces)
{
gdb_puts (" TYPE_FIXED_INSTANCE");
}
- if (TYPE_NOTTEXT (type))
- {
- gdb_puts (" TYPE_NOTTEXT");
- }
+ if (type->is_nottext ())
+ gdb_puts (" TYPE_NOTTEXT");
gdb_puts ("\n");
gdb_printf ("%*snfields %d ", spaces, "", type->num_fields ());
if (type->dyn_prop (DYN_PROP_ASSOCIATED) != nullptr
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 11a08428baf..176d3936661 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -168,7 +168,6 @@ struct type_instance_flags
bool is_atomic : 1;
};
-#define TYPE_NOTTEXT(t) (((t)->instance_flags ()).is_nottext)
#define TYPE_CONST(t) (((t)->instance_flags ()).is_const)
#define TYPE_VOLATILE(t) (((t)->instance_flags ()).is_volatile)
#define TYPE_RESTRICT(t) (((t)->instance_flags ()).is_restrict)
@@ -1201,6 +1200,12 @@ struct type
this->m_instance_flags.is_nottext = flag;
}
+ /* Return if this type is nottext. */
+ bool is_nottext () const
+ {
+ return this->m_instance_flags.is_nottext;
+ }
+
/* Get the bounds bounds of this type. The type must be a range type. */
range_bounds *bounds () const
{
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 10/17] gdb: convert TYPE_CONST macro to type::is_const
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (8 preceding siblings ...)
2026-07-22 10:41 ` [PATCH v2 09/17] gdb: convert TYPE_NOTTEXT macro to type::is_nottext Tankut Baris Aktemur
@ 2026-07-22 10:41 ` Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 11/17] gdb: convert TYPE_VOLATILE macro to type::is_volatile Tankut Baris Aktemur
` (7 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:41 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
Convert the TYPE_CONST macro to a method of the type class. This is
a refactoring.
---
gdb/c-typeprint.c | 4 ++--
gdb/compile/compile-c-types.c | 4 ++--
gdb/compile/compile-cplus-types.c | 6 +++---
gdb/ctfread.c | 4 ++--
gdb/dwarf2/read.c | 8 ++++----
gdb/gdbtypes.c | 12 +++++-------
gdb/gdbtypes.h | 7 ++++++-
gdb/m2-typeprint.c | 2 +-
gdb/m2-valprint.c | 2 +-
gdb/opencl-lang.c | 2 +-
gdb/python/py-type.c | 4 ++--
gdb/type-stack.c | 2 +-
gdb/valops.c | 6 +++---
13 files changed, 33 insertions(+), 30 deletions(-)
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index db3bc29475f..97e547a92ef 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -311,7 +311,7 @@ cp_type_print_method_args (struct type *mtype,
gdb_assert (args[0].type ()->code () == TYPE_CODE_PTR);
domain = args[0].type ()->target_type ();
- if (TYPE_CONST (domain))
+ if (domain->is_const ())
gdb_printf (stream, " const");
if (TYPE_VOLATILE (domain))
@@ -449,7 +449,7 @@ c_type_print_modifier (struct type *type, struct ui_file *stream,
/* We don't print `const' qualifiers for references --- since all
operators affect the thing referenced, not the reference itself,
every reference is `const'. */
- if (TYPE_CONST (type) && !TYPE_IS_REFERENCE (type))
+ if (type->is_const () && !TYPE_IS_REFERENCE (type))
{
if (need_pre_space)
gdb_printf (stream, " ");
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index af9dea730eb..2e5ca12a61b 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -247,7 +247,7 @@ convert_qualified (compile_c_instance *context, struct type *type)
unqual_converted = context->convert_type (unqual);
- if (TYPE_CONST (type))
+ if (type->is_const ())
quals |= GCC_QUALIFIER_CONST;
if (TYPE_VOLATILE (type))
quals |= GCC_QUALIFIER_VOLATILE;
@@ -278,7 +278,7 @@ convert_type_basic (compile_c_instance *context, struct type *type)
{
/* If we are converting a qualified type, first convert the
unqualified type and then apply the qualifiers. */
- if (TYPE_CONST (type) || TYPE_VOLATILE (type) || TYPE_RESTRICT (type))
+ if (type->is_const () || TYPE_VOLATILE (type) || TYPE_RESTRICT (type))
return convert_qualified (context, type);
switch (type->code ())
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index ff25fc62c8b..90ef1bda2cb 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -669,7 +669,7 @@ compile_cplus_convert_method (compile_cplus_instance *instance,
gcc_type class_type = instance->convert_type (parent_type);
gcc_cp_qualifiers_flags quals = 0;
- if (TYPE_CONST (method_type))
+ if (method_type->is_const ())
quals |= GCC_CP_QUALIFIER_CONST;
if (TYPE_VOLATILE (method_type))
quals |= GCC_CP_QUALIFIER_VOLATILE;
@@ -1066,7 +1066,7 @@ compile_cplus_convert_qualified (compile_cplus_instance *instance,
gcc_cp_qualifiers_flags quals = (enum gcc_cp_qualifiers) 0;
gcc_type unqual_converted = instance->convert_type (unqual);
- if (TYPE_CONST (type))
+ if (type->is_const ())
quals |= GCC_CP_QUALIFIER_CONST;
if (TYPE_VOLATILE (type))
quals |= GCC_CP_QUALIFIER_VOLATILE;
@@ -1126,7 +1126,7 @@ convert_type_cplus_basic (compile_cplus_instance *instance,
{
/* If we are converting a qualified type, first convert the
unqualified type and then apply the qualifiers. */
- if (TYPE_CONST (type) || TYPE_VOLATILE (type) || TYPE_RESTRICT (type))
+ if (type->is_const () || TYPE_VOLATILE (type) || TYPE_RESTRICT (type))
return compile_cplus_convert_qualified (instance, type);
switch (type->code ())
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 5f8c54a34df..b40d3de6763 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -757,7 +757,7 @@ add_array_cv_type (struct ctf_context *ccp,
}
el_type = inner_array->target_type ();
- cnst |= TYPE_CONST (el_type);
+ cnst |= el_type->is_const ();
voltl |= TYPE_VOLATILE (el_type);
inner_array->set_target_type (make_cv_type (cnst, voltl, el_type));
@@ -857,7 +857,7 @@ read_volatile_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
if (ctf_type_kind (dict, btid) == CTF_K_ARRAY)
return add_array_cv_type (ccp, tid, base_type, 0, 1);
- cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type);
+ cv_type = make_cv_type (base_type->is_const (), 1, base_type);
return set_tid_type (ccp, tid, cv_type);
}
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index ce4d6ca8675..067561b6e48 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -5178,7 +5178,7 @@ dwarf2_compute_name (const char *name,
if (type->num_fields () > 0
&& type->field (0).is_artificial ()
&& type->field (0).type ()->code () == TYPE_CODE_PTR
- && TYPE_CONST (type->field (0).type ()->target_type ()))
+ && type->field (0).type ()->target_type ()->is_const ())
buf.puts (" const");
}
}
@@ -12176,7 +12176,7 @@ add_array_cv_type (struct die_info *die, struct dwarf2_cu *cu,
}
el_type = inner_array->target_type ();
- cnst |= TYPE_CONST (el_type);
+ cnst |= el_type->is_const ();
voltl |= TYPE_VOLATILE (el_type);
inner_array->set_target_type (make_cv_type (cnst, voltl, el_type));
@@ -12222,7 +12222,7 @@ read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
if (base_type->code () == TYPE_CODE_ARRAY)
return add_array_cv_type (die, cu, base_type, 0, 1);
- cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type);
+ cv_type = make_cv_type (base_type->is_const (), 1, base_type);
return set_die_type (die, cv_type, cu);
}
@@ -12521,7 +12521,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
expects. GCC marks THIS as const in method definitions,
but not in the class specifications (GCC PR 43053). */
if (cu->lang () == language_cplus
- && !TYPE_CONST (arg_type)
+ && !arg_type->is_const ()
&& ftype->field (iparams).is_artificial ())
{
int is_this = 0;
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index dd73d9e624f..74b043de9f9 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -4314,7 +4314,7 @@ rank_one_type_parm_ptr (struct type *parm, struct type *arg, struct value *value
if (types_equal (t1, t2))
{
/* Make sure they are CV equal. */
- if (TYPE_CONST (t1) != TYPE_CONST (t2))
+ if (t1->is_const () != t2->is_const ())
rank.subrank |= CV_CONVERSION_CONST;
if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
rank.subrank |= CV_CONVERSION_VOLATILE;
@@ -4700,7 +4700,7 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value)
lvalue references. */
if (parm->code () == TYPE_CODE_RVALUE_REF)
rank.subrank = REFERENCE_CONVERSION_RVALUE;
- else if (TYPE_CONST (parm->target_type ()))
+ else if (parm->target_type ()->is_const ())
rank.subrank = REFERENCE_CONVERSION_CONST_LVALUE;
else
return INCOMPATIBLE_TYPE_BADNESS;
@@ -4727,7 +4727,7 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value)
}
/* Make sure they are CV equal, too. */
- if (TYPE_CONST (t1) != TYPE_CONST (t2))
+ if (t1->is_const () != t2->is_const ())
rank.subrank |= CV_CONVERSION_CONST;
if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
rank.subrank |= CV_CONVERSION_VOLATILE;
@@ -5021,10 +5021,8 @@ recursive_dump_type (struct type *type, int spaces)
gdb_printf ("%*stype_chain %s\n", spaces, "",
host_address_to_string (type->chain));
gdb_printf ("%*sinstance_flags [", spaces, "");
- if (TYPE_CONST (type))
- {
- gdb_puts (" TYPE_CONST");
- }
+ if (type->is_const ())
+ gdb_puts (" TYPE_CONST");
if (TYPE_VOLATILE (type))
{
gdb_puts (" TYPE_VOLATILE");
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 176d3936661..a4fcd4d07b4 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -168,7 +168,6 @@ struct type_instance_flags
bool is_atomic : 1;
};
-#define TYPE_CONST(t) (((t)->instance_flags ()).is_const)
#define TYPE_VOLATILE(t) (((t)->instance_flags ()).is_volatile)
#define TYPE_RESTRICT(t) (((t)->instance_flags ()).is_restrict)
#define TYPE_ATOMIC(t) (((t)->instance_flags ()).is_atomic)
@@ -1206,6 +1205,12 @@ struct type
return this->m_instance_flags.is_nottext;
}
+ /* Return if this type is const. */
+ bool is_const () const
+ {
+ return this->m_instance_flags.is_const;
+ }
+
/* Get the bounds bounds of this type. The type must be a range type. */
range_bounds *bounds () const
{
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index 59616e7f2d6..30b40105405 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -244,7 +244,7 @@ static void
m2_pointer (struct type *type, struct ui_file *stream, int show,
int level, const struct type_print_options *flags)
{
- if (TYPE_CONST (type))
+ if (type->is_const ())
gdb_printf (stream, "[...] : ");
else
gdb_printf (stream, "POINTER TO ");
diff --git a/gdb/m2-valprint.c b/gdb/m2-valprint.c
index eb2be9d33a8..ee0ab9fda6a 100644
--- a/gdb/m2-valprint.c
+++ b/gdb/m2-valprint.c
@@ -356,7 +356,7 @@ m2_language::value_print_inner (struct value *val, struct ui_file *stream,
break;
case TYPE_CODE_PTR:
- if (TYPE_CONST (type))
+ if (type->is_const ())
print_variable_at_address (type, valaddr, stream, recurse, options);
else if (options->format && options->format != 's')
value_print_scalar_formatted (val, options, 0, stream);
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 8576f4224a2..96119785f92 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -292,7 +292,7 @@ create_value (struct gdbarch *gdbarch, struct value *val, enum noside noside,
if (dst_type == NULL)
dst_type = init_vector_type (elm_type, n);
- make_cv_type (TYPE_CONST (type), TYPE_VOLATILE (type), dst_type);
+ make_cv_type (type->is_const (), TYPE_VOLATILE (type), dst_type);
if (noside == EVAL_AVOID_SIDE_EFFECTS)
ret = value::allocate (dst_type);
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 7831e838481..5b98ec1fa7f 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -733,7 +733,7 @@ typy_volatile (PyObject *self, PyObject *args)
try
{
- type = make_cv_type (TYPE_CONST (type), 1, type);
+ type = make_cv_type (type->is_const (), 1, type);
}
catch (const gdb_exception &except)
{
@@ -894,7 +894,7 @@ typy_lookup_type (struct demangle_component *demangled,
rtype = make_cv_type (1, TYPE_VOLATILE (type), type);
break;
case DEMANGLE_COMPONENT_VOLATILE:
- rtype = make_cv_type (TYPE_CONST (type), 1, type);
+ rtype = make_cv_type (type->is_const (), 1, type);
break;
}
}
diff --git a/gdb/type-stack.c b/gdb/type-stack.c
index 476848fcad1..05c5ee6e47f 100644
--- a/gdb/type-stack.c
+++ b/gdb/type-stack.c
@@ -159,7 +159,7 @@ type_stack::follow_types (struct type *follow_type)
TYPE_VOLATILE (follow_type),
follow_type);
if (make_volatile)
- follow_type = make_cv_type (TYPE_CONST (follow_type),
+ follow_type = make_cv_type (follow_type->is_const (),
make_volatile,
follow_type);
if (make_harvard_aspace != HARVARD_ASPACE_NONE)
diff --git a/gdb/valops.c b/gdb/valops.c
index 76be9c58e6a..ccb2ae21adc 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3650,7 +3650,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
{
for (j = 0; j < len; ++j)
{
- if (TYPE_CONST (intype) != TYPE_FN_FIELD_CONST (f, j))
+ if (intype->is_const () != TYPE_FN_FIELD_CONST (f, j))
continue;
if (TYPE_VOLATILE (intype) != TYPE_FN_FIELD_VOLATILE (f, j))
continue;
@@ -3873,7 +3873,7 @@ value_rtti_indirect_type (struct value *v, int *full,
{
/* Copy qualifiers to the referenced object. */
target_type = target->type ();
- real_type = make_cv_type (TYPE_CONST (target_type),
+ real_type = make_cv_type (target_type->is_const (),
TYPE_VOLATILE (target_type), real_type);
if (TYPE_IS_REFERENCE (type))
real_type = lookup_reference_type (real_type, type->code ());
@@ -3883,7 +3883,7 @@ value_rtti_indirect_type (struct value *v, int *full,
internal_error (_("Unexpected value type."));
/* Copy qualifiers to the pointer/reference. */
- real_type = make_cv_type (TYPE_CONST (type), TYPE_VOLATILE (type),
+ real_type = make_cv_type (type->is_const (), TYPE_VOLATILE (type),
real_type);
}
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 11/17] gdb: convert TYPE_VOLATILE macro to type::is_volatile
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (9 preceding siblings ...)
2026-07-22 10:41 ` [PATCH v2 10/17] gdb: convert TYPE_CONST macro to type::is_const Tankut Baris Aktemur
@ 2026-07-22 10:42 ` Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 12/17] gdb: convert TYPE_CODE_SPACE macro to type::is_code_space Tankut Baris Aktemur
` (6 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:42 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
Convert the TYPE_VOLATILE macro to a method of the type class. This
is a refactoring.
---
gdb/c-typeprint.c | 4 ++--
gdb/compile/compile-c-types.c | 4 ++--
gdb/compile/compile-cplus-types.c | 6 +++---
gdb/ctfread.c | 4 ++--
gdb/dwarf2/read.c | 6 +++---
gdb/gdbtypes.c | 10 ++++------
gdb/gdbtypes.h | 7 ++++++-
gdb/opencl-lang.c | 2 +-
gdb/python/py-type.c | 4 ++--
gdb/type-stack.c | 2 +-
gdb/valops.c | 6 +++---
11 files changed, 29 insertions(+), 26 deletions(-)
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 97e547a92ef..fb8b228ea38 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -314,7 +314,7 @@ cp_type_print_method_args (struct type *mtype,
if (domain->is_const ())
gdb_printf (stream, " const");
- if (TYPE_VOLATILE (domain))
+ if (domain->is_volatile ())
gdb_printf (stream, " volatile");
if (TYPE_RESTRICT (domain))
@@ -457,7 +457,7 @@ c_type_print_modifier (struct type *type, struct ui_file *stream,
did_print_modifier = 1;
}
- if (TYPE_VOLATILE (type))
+ if (type->is_volatile ())
{
if (did_print_modifier || need_pre_space)
gdb_printf (stream, " ");
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index 2e5ca12a61b..2c115632a7c 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -249,7 +249,7 @@ convert_qualified (compile_c_instance *context, struct type *type)
if (type->is_const ())
quals |= GCC_QUALIFIER_CONST;
- if (TYPE_VOLATILE (type))
+ if (type->is_volatile ())
quals |= GCC_QUALIFIER_VOLATILE;
if (TYPE_RESTRICT (type))
quals |= GCC_QUALIFIER_RESTRICT;
@@ -278,7 +278,7 @@ convert_type_basic (compile_c_instance *context, struct type *type)
{
/* If we are converting a qualified type, first convert the
unqualified type and then apply the qualifiers. */
- if (type->is_const () || TYPE_VOLATILE (type) || TYPE_RESTRICT (type))
+ if (type->is_const () || type->is_volatile () || TYPE_RESTRICT (type))
return convert_qualified (context, type);
switch (type->code ())
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index 90ef1bda2cb..787ca321a5f 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -671,7 +671,7 @@ compile_cplus_convert_method (compile_cplus_instance *instance,
if (method_type->is_const ())
quals |= GCC_CP_QUALIFIER_CONST;
- if (TYPE_VOLATILE (method_type))
+ if (method_type->is_volatile ())
quals |= GCC_CP_QUALIFIER_VOLATILE;
if (TYPE_RESTRICT (method_type))
quals |= GCC_CP_QUALIFIER_RESTRICT;
@@ -1068,7 +1068,7 @@ compile_cplus_convert_qualified (compile_cplus_instance *instance,
if (type->is_const ())
quals |= GCC_CP_QUALIFIER_CONST;
- if (TYPE_VOLATILE (type))
+ if (type->is_volatile ())
quals |= GCC_CP_QUALIFIER_VOLATILE;
if (TYPE_RESTRICT (type))
quals |= GCC_CP_QUALIFIER_RESTRICT;
@@ -1126,7 +1126,7 @@ convert_type_cplus_basic (compile_cplus_instance *instance,
{
/* If we are converting a qualified type, first convert the
unqualified type and then apply the qualifiers. */
- if (type->is_const () || TYPE_VOLATILE (type) || TYPE_RESTRICT (type))
+ if (type->is_const () || type->is_volatile () || TYPE_RESTRICT (type))
return compile_cplus_convert_qualified (instance, type);
switch (type->code ())
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index b40d3de6763..ff34f42146a 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -758,7 +758,7 @@ add_array_cv_type (struct ctf_context *ccp,
el_type = inner_array->target_type ();
cnst |= el_type->is_const ();
- voltl |= TYPE_VOLATILE (el_type);
+ voltl |= el_type->is_volatile ();
inner_array->set_target_type (make_cv_type (cnst, voltl, el_type));
return set_tid_type (ccp, tid, base_type);
@@ -830,7 +830,7 @@ read_const_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
base_type = builtin_type (objfile)->builtin_error;
}
}
- cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type);
+ cv_type = make_cv_type (1, base_type->is_volatile (), base_type);
return set_tid_type (ccp, tid, cv_type);
}
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 067561b6e48..38c498b1901 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -12177,7 +12177,7 @@ add_array_cv_type (struct die_info *die, struct dwarf2_cu *cu,
el_type = inner_array->target_type ();
cnst |= el_type->is_const ();
- voltl |= TYPE_VOLATILE (el_type);
+ voltl |= el_type->is_volatile ();
inner_array->set_target_type (make_cv_type (cnst, voltl, el_type));
return set_die_type (die, base_type, cu);
@@ -12200,7 +12200,7 @@ read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
if (base_type->code () == TYPE_CODE_ARRAY)
return add_array_cv_type (die, cu, base_type, 1, 0);
- cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type);
+ cv_type = make_cv_type (1, base_type->is_volatile (), base_type);
return set_die_type (die, cv_type, cu);
}
@@ -12545,7 +12545,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
is_this = 1;
if (is_this)
- arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
+ arg_type = make_cv_type (1, arg_type->is_volatile (),
arg_type);
}
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 74b043de9f9..1019f02e2e1 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -4316,7 +4316,7 @@ rank_one_type_parm_ptr (struct type *parm, struct type *arg, struct value *value
/* Make sure they are CV equal. */
if (t1->is_const () != t2->is_const ())
rank.subrank |= CV_CONVERSION_CONST;
- if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
+ if (t1->is_volatile () != t2->is_volatile ())
rank.subrank |= CV_CONVERSION_VOLATILE;
if (rank.subrank != 0)
return sum_ranks (CV_CONVERSION_BADNESS, rank);
@@ -4729,7 +4729,7 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value)
/* Make sure they are CV equal, too. */
if (t1->is_const () != t2->is_const ())
rank.subrank |= CV_CONVERSION_CONST;
- if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
+ if (t1->is_volatile () != t2->is_volatile ())
rank.subrank |= CV_CONVERSION_VOLATILE;
if (rank.subrank != 0)
return sum_ranks (CV_CONVERSION_BADNESS, rank);
@@ -5023,10 +5023,8 @@ recursive_dump_type (struct type *type, int spaces)
gdb_printf ("%*sinstance_flags [", spaces, "");
if (type->is_const ())
gdb_puts (" TYPE_CONST");
- if (TYPE_VOLATILE (type))
- {
- gdb_puts (" TYPE_VOLATILE");
- }
+ if (type->is_volatile ())
+ gdb_puts (" TYPE_VOLATILE");
if (TYPE_CODE_SPACE (type))
{
gdb_puts (" TYPE_CODE_SPACE");
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index a4fcd4d07b4..6a8bc425d45 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -168,7 +168,6 @@ struct type_instance_flags
bool is_atomic : 1;
};
-#define TYPE_VOLATILE(t) (((t)->instance_flags ()).is_volatile)
#define TYPE_RESTRICT(t) (((t)->instance_flags ()).is_restrict)
#define TYPE_ATOMIC(t) (((t)->instance_flags ()).is_atomic)
@@ -1211,6 +1210,12 @@ struct type
return this->m_instance_flags.is_const;
}
+ /* Return if this type is volatile. */
+ bool is_volatile () const
+ {
+ return this->m_instance_flags.is_volatile;
+ }
+
/* Get the bounds bounds of this type. The type must be a range type. */
range_bounds *bounds () const
{
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 96119785f92..895f7a41f01 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -292,7 +292,7 @@ create_value (struct gdbarch *gdbarch, struct value *val, enum noside noside,
if (dst_type == NULL)
dst_type = init_vector_type (elm_type, n);
- make_cv_type (type->is_const (), TYPE_VOLATILE (type), dst_type);
+ make_cv_type (type->is_const (), type->is_volatile (), dst_type);
if (noside == EVAL_AVOID_SIDE_EFFECTS)
ret = value::allocate (dst_type);
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 5b98ec1fa7f..9dd0fe2ab37 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -715,7 +715,7 @@ typy_const (PyObject *self, PyObject *args)
try
{
- type = make_cv_type (1, TYPE_VOLATILE (type), type);
+ type = make_cv_type (1, type->is_volatile (), type);
}
catch (const gdb_exception &except)
{
@@ -891,7 +891,7 @@ typy_lookup_type (struct demangle_component *demangled,
rtype = lookup_pointer_type (type);
break;
case DEMANGLE_COMPONENT_CONST:
- rtype = make_cv_type (1, TYPE_VOLATILE (type), type);
+ rtype = make_cv_type (1, type->is_volatile (), type);
break;
case DEMANGLE_COMPONENT_VOLATILE:
rtype = make_cv_type (type->is_const (), 1, type);
diff --git a/gdb/type-stack.c b/gdb/type-stack.c
index 05c5ee6e47f..01616ae4a14 100644
--- a/gdb/type-stack.c
+++ b/gdb/type-stack.c
@@ -156,7 +156,7 @@ type_stack::follow_types (struct type *follow_type)
process_qualifiers:
if (make_const)
follow_type = make_cv_type (make_const,
- TYPE_VOLATILE (follow_type),
+ follow_type->is_volatile (),
follow_type);
if (make_volatile)
follow_type = make_cv_type (follow_type->is_const (),
diff --git a/gdb/valops.c b/gdb/valops.c
index ccb2ae21adc..d2dc3d9e869 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3652,7 +3652,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
{
if (intype->is_const () != TYPE_FN_FIELD_CONST (f, j))
continue;
- if (TYPE_VOLATILE (intype) != TYPE_FN_FIELD_VOLATILE (f, j))
+ if (intype->is_volatile () != TYPE_FN_FIELD_VOLATILE (f, j))
continue;
if (compare_parameters (TYPE_FN_FIELD_TYPE (f, j), intype, 0)
@@ -3874,7 +3874,7 @@ value_rtti_indirect_type (struct value *v, int *full,
/* Copy qualifiers to the referenced object. */
target_type = target->type ();
real_type = make_cv_type (target_type->is_const (),
- TYPE_VOLATILE (target_type), real_type);
+ target_type->is_volatile (), real_type);
if (TYPE_IS_REFERENCE (type))
real_type = lookup_reference_type (real_type, type->code ());
else if (type->code () == TYPE_CODE_PTR)
@@ -3883,7 +3883,7 @@ value_rtti_indirect_type (struct value *v, int *full,
internal_error (_("Unexpected value type."));
/* Copy qualifiers to the pointer/reference. */
- real_type = make_cv_type (type->is_const (), TYPE_VOLATILE (type),
+ real_type = make_cv_type (type->is_const (), type->is_volatile (),
real_type);
}
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 12/17] gdb: convert TYPE_CODE_SPACE macro to type::is_code_space
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (10 preceding siblings ...)
2026-07-22 10:42 ` [PATCH v2 11/17] gdb: convert TYPE_VOLATILE macro to type::is_volatile Tankut Baris Aktemur
@ 2026-07-22 10:42 ` Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 13/17] gdb: convert TYPE_DATA_SPACE macro to type::is_data_space Tankut Baris Aktemur
` (5 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:42 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
Convert the TYPE_CODE_SPACE macro to a method of the type class. This
is a refactoring.
---
gdb/avr-tdep.c | 2 +-
gdb/c-typeprint.c | 2 +-
gdb/gdbtypes.c | 6 ++----
gdb/gdbtypes.h | 9 ++++++---
gdb/iq2000-tdep.c | 2 +-
gdb/rl78-tdep.c | 2 +-
6 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index 2191ada4c2e..26b786c68b7 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -345,7 +345,7 @@ avr_pointer_to_address (struct gdbarch *gdbarch,
/* Is it a code address? */
else if (type->target_type ()->code () == TYPE_CODE_FUNC
|| type->target_type ()->code () == TYPE_CODE_METHOD
- || TYPE_CODE_SPACE (type->target_type ()))
+ || type->target_type ()->is_code_space ())
{
/* A code pointer is word (16 bits) addressed so we shift it up
by 1 bit to convert it to an address. */
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index fb8b228ea38..a8927e0ac43 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -485,7 +485,7 @@ c_type_print_modifier (struct type *type, struct ui_file *stream,
address_space_id = nullptr;
- if (TYPE_CODE_SPACE (type))
+ if (type->is_code_space ())
address_space_id = "code";
else if (TYPE_DATA_SPACE (type))
address_space_id = "data";
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 1019f02e2e1..465af4790fd 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -5025,10 +5025,8 @@ recursive_dump_type (struct type *type, int spaces)
gdb_puts (" TYPE_CONST");
if (type->is_volatile ())
gdb_puts (" TYPE_VOLATILE");
- if (TYPE_CODE_SPACE (type))
- {
- gdb_puts (" TYPE_CODE_SPACE");
- }
+ if (type->is_code_space ())
+ gdb_puts (" TYPE_CODE_SPACE");
if (TYPE_DATA_SPACE (type))
{
gdb_puts (" TYPE_DATA_SPACE");
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 6a8bc425d45..d9988312e1b 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -189,9 +189,6 @@ struct type_instance_flags
(((t)->dyn_prop (DYN_PROP_BYTE_SIZE) != nullptr) \
|| ((t)->dyn_prop (DYN_PROP_BIT_SIZE) != nullptr))
-#define TYPE_CODE_SPACE(t) \
- (((t)->instance_flags ()).harvard_aspace == HARVARD_ASPACE_CODE)
-
#define TYPE_DATA_SPACE(t) \
(((t)->instance_flags ()).harvard_aspace == HARVARD_ASPACE_DATA)
@@ -1216,6 +1213,12 @@ struct type
return this->m_instance_flags.is_volatile;
}
+ /* Return if this type is in the code space. */
+ bool is_code_space () const
+ {
+ return this->m_instance_flags.harvard_aspace == HARVARD_ASPACE_CODE;
+ }
+
/* Get the bounds bounds of this type. The type must be a range type. */
range_bounds *bounds () const
{
diff --git a/gdb/iq2000-tdep.c b/gdb/iq2000-tdep.c
index 32e3750aca4..783e1720a02 100644
--- a/gdb/iq2000-tdep.c
+++ b/gdb/iq2000-tdep.c
@@ -95,7 +95,7 @@ iq2000_pointer_to_address (struct gdbarch *gdbarch,
if (target == TYPE_CODE_FUNC
|| target == TYPE_CODE_METHOD
- || TYPE_CODE_SPACE (type->target_type ()))
+ || type->target_type ()->is_code_space ())
addr = insn_addr_from_ptr (addr);
return addr;
diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
index 0de2fceb795..4204ce5c8cb 100644
--- a/gdb/rl78-tdep.c
+++ b/gdb/rl78-tdep.c
@@ -1052,7 +1052,7 @@ rl78_pointer_to_address (struct gdbarch *gdbarch,
/* Is it a code address? */
if (type->target_type ()->code () == TYPE_CODE_FUNC
|| type->target_type ()->code () == TYPE_CODE_METHOD
- || TYPE_CODE_SPACE (type->target_type ())
+ || type->target_type ()->is_code_space ()
|| type->length () == 4)
return rl78_make_instruction_address (addr);
else
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 13/17] gdb: convert TYPE_DATA_SPACE macro to type::is_data_space
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (11 preceding siblings ...)
2026-07-22 10:42 ` [PATCH v2 12/17] gdb: convert TYPE_CODE_SPACE macro to type::is_code_space Tankut Baris Aktemur
@ 2026-07-22 10:42 ` Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 14/17] gdb: convert TYPE_RESTRICT macro to type::is_restrict Tankut Baris Aktemur
` (4 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:42 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
Convert the TYPE_DATA_SPACE macro to a method of the type class. This
is a refactoring.
---
gdb/avr-tdep.c | 2 +-
gdb/c-typeprint.c | 2 +-
gdb/gdbtypes.c | 6 ++----
gdb/gdbtypes.h | 9 ++++++---
4 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index 26b786c68b7..682b7e8586d 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -361,7 +361,7 @@ avr_integer_to_address (struct gdbarch *gdbarch,
{
ULONGEST addr = unpack_long (type, buf);
- if (TYPE_DATA_SPACE (type))
+ if (type->is_data_space ())
return avr_make_saddr (addr);
else
return avr_make_iaddr (addr);
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index a8927e0ac43..d26640e10e6 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -487,7 +487,7 @@ c_type_print_modifier (struct type *type, struct ui_file *stream,
if (type->is_code_space ())
address_space_id = "code";
- else if (TYPE_DATA_SPACE (type))
+ else if (type->is_data_space ())
address_space_id = "data";
else if (gdbarch_address_class_id_to_name_p (type->arch ()))
address_space_id
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 465af4790fd..731c7436dc6 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -5027,10 +5027,8 @@ recursive_dump_type (struct type *type, int spaces)
gdb_puts (" TYPE_VOLATILE");
if (type->is_code_space ())
gdb_puts (" TYPE_CODE_SPACE");
- if (TYPE_DATA_SPACE (type))
- {
- gdb_puts (" TYPE_DATA_SPACE");
- }
+ if (type->is_data_space ())
+ gdb_puts (" TYPE_DATA_SPACE");
if (TYPE_ADDRESS_CLASS (type) != 0)
{
gdb_printf (" TYPE_ADDRESS_CLASS(%u)", TYPE_ADDRESS_CLASS (type));
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index d9988312e1b..b6c3b219419 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -189,9 +189,6 @@ struct type_instance_flags
(((t)->dyn_prop (DYN_PROP_BYTE_SIZE) != nullptr) \
|| ((t)->dyn_prop (DYN_PROP_BIT_SIZE) != nullptr))
-#define TYPE_DATA_SPACE(t) \
- (((t)->instance_flags ()).harvard_aspace == HARVARD_ASPACE_DATA)
-
#define TYPE_ADDRESS_CLASS(t) \
(((t)->instance_flags ()).address_class)
@@ -1219,6 +1216,12 @@ struct type
return this->m_instance_flags.harvard_aspace == HARVARD_ASPACE_CODE;
}
+ /* Return if this type is in the data space. */
+ bool is_data_space () const
+ {
+ return this->m_instance_flags.harvard_aspace == HARVARD_ASPACE_DATA;
+ }
+
/* Get the bounds bounds of this type. The type must be a range type. */
range_bounds *bounds () const
{
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 14/17] gdb: convert TYPE_RESTRICT macro to type::is_restrict
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (12 preceding siblings ...)
2026-07-22 10:42 ` [PATCH v2 13/17] gdb: convert TYPE_DATA_SPACE macro to type::is_data_space Tankut Baris Aktemur
@ 2026-07-22 10:42 ` Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 15/17] gdb: convert TYPE_ATOMIC macro to type::is_atomic Tankut Baris Aktemur
` (3 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:42 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
Convert the TYPE_RESTRICT macro to a method of the type class. This
is a refactoring.
---
gdb/c-typeprint.c | 4 ++--
gdb/compile/compile-c-types.c | 4 ++--
gdb/compile/compile-cplus-types.c | 6 +++---
gdb/gdbtypes.c | 6 ++----
gdb/gdbtypes.h | 7 ++++++-
5 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index d26640e10e6..1c3b0fba04d 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -317,7 +317,7 @@ cp_type_print_method_args (struct type *mtype,
if (domain->is_volatile ())
gdb_printf (stream, " volatile");
- if (TYPE_RESTRICT (domain))
+ if (domain->is_restrict ())
gdb_printf (stream, (language == language_cplus
? " __restrict__"
: " restrict"));
@@ -465,7 +465,7 @@ c_type_print_modifier (struct type *type, struct ui_file *stream,
did_print_modifier = 1;
}
- if (TYPE_RESTRICT (type))
+ if (type->is_restrict ())
{
if (did_print_modifier || need_pre_space)
gdb_printf (stream, " ");
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index 2c115632a7c..818cdecd50d 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -251,7 +251,7 @@ convert_qualified (compile_c_instance *context, struct type *type)
quals |= GCC_QUALIFIER_CONST;
if (type->is_volatile ())
quals |= GCC_QUALIFIER_VOLATILE;
- if (TYPE_RESTRICT (type))
+ if (type->is_restrict ())
quals |= GCC_QUALIFIER_RESTRICT;
return context->plugin ().build_qualified_type (unqual_converted,
@@ -278,7 +278,7 @@ convert_type_basic (compile_c_instance *context, struct type *type)
{
/* If we are converting a qualified type, first convert the
unqualified type and then apply the qualifiers. */
- if (type->is_const () || type->is_volatile () || TYPE_RESTRICT (type))
+ if (type->is_const () || type->is_volatile () || type->is_restrict ())
return convert_qualified (context, type);
switch (type->code ())
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index 787ca321a5f..8352c9324f4 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -673,7 +673,7 @@ compile_cplus_convert_method (compile_cplus_instance *instance,
quals |= GCC_CP_QUALIFIER_CONST;
if (method_type->is_volatile ())
quals |= GCC_CP_QUALIFIER_VOLATILE;
- if (TYPE_RESTRICT (method_type))
+ if (method_type->is_restrict ())
quals |= GCC_CP_QUALIFIER_RESTRICT;
/* Not yet implemented. */
@@ -1070,7 +1070,7 @@ compile_cplus_convert_qualified (compile_cplus_instance *instance,
quals |= GCC_CP_QUALIFIER_CONST;
if (type->is_volatile ())
quals |= GCC_CP_QUALIFIER_VOLATILE;
- if (TYPE_RESTRICT (type))
+ if (type->is_restrict ())
quals |= GCC_CP_QUALIFIER_RESTRICT;
return instance->convert_qualified_base (unqual_converted, quals);
@@ -1126,7 +1126,7 @@ convert_type_cplus_basic (compile_cplus_instance *instance,
{
/* If we are converting a qualified type, first convert the
unqualified type and then apply the qualifiers. */
- if (type->is_const () || type->is_volatile () || TYPE_RESTRICT (type))
+ if (type->is_const () || type->is_volatile () || type->is_restrict ())
return compile_cplus_convert_qualified (instance, type);
switch (type->code ())
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 731c7436dc6..a682d525134 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -5033,10 +5033,8 @@ recursive_dump_type (struct type *type, int spaces)
{
gdb_printf (" TYPE_ADDRESS_CLASS(%u)", TYPE_ADDRESS_CLASS (type));
}
- if (TYPE_RESTRICT (type))
- {
- gdb_puts (" TYPE_RESTRICT");
- }
+ if (type->is_restrict ())
+ gdb_puts (" TYPE_RESTRICT");
if (TYPE_ATOMIC (type))
{
gdb_puts (" TYPE_ATOMIC");
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index b6c3b219419..0acfda0d74b 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -168,7 +168,6 @@ struct type_instance_flags
bool is_atomic : 1;
};
-#define TYPE_RESTRICT(t) (((t)->instance_flags ()).is_restrict)
#define TYPE_ATOMIC(t) (((t)->instance_flags ()).is_atomic)
/* True if this type represents either an lvalue or lvalue reference type. */
@@ -1222,6 +1221,12 @@ struct type
return this->m_instance_flags.harvard_aspace == HARVARD_ASPACE_DATA;
}
+ /* Return if this type is restrict. */
+ bool is_restrict () const
+ {
+ return this->m_instance_flags.is_restrict;
+ }
+
/* Get the bounds bounds of this type. The type must be a range type. */
range_bounds *bounds () const
{
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 15/17] gdb: convert TYPE_ATOMIC macro to type::is_atomic
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (13 preceding siblings ...)
2026-07-22 10:42 ` [PATCH v2 14/17] gdb: convert TYPE_RESTRICT macro to type::is_restrict Tankut Baris Aktemur
@ 2026-07-22 10:42 ` Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 16/17] gdb: convert TYPE_ADDRESS_CLASS macro to type::address_class Tankut Baris Aktemur
` (2 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:42 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
Convert the TYPE_ATOMIC macro to a method of the type class. This
is a refactoring.
---
gdb/c-typeprint.c | 4 ++--
gdb/gdbtypes.c | 6 ++----
gdb/gdbtypes.h | 8 ++++++--
3 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 1c3b0fba04d..92938270647 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -322,7 +322,7 @@ cp_type_print_method_args (struct type *mtype,
? " __restrict__"
: " restrict"));
- if (TYPE_ATOMIC (domain))
+ if (domain->is_atomic ())
gdb_printf (stream, " _Atomic");
}
}
@@ -475,7 +475,7 @@ c_type_print_modifier (struct type *type, struct ui_file *stream,
did_print_modifier = 1;
}
- if (TYPE_ATOMIC (type))
+ if (type->is_atomic ())
{
if (did_print_modifier || need_pre_space)
gdb_printf (stream, " ");
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index a682d525134..34eaac42e20 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -5035,10 +5035,8 @@ recursive_dump_type (struct type *type, int spaces)
}
if (type->is_restrict ())
gdb_puts (" TYPE_RESTRICT");
- if (TYPE_ATOMIC (type))
- {
- gdb_puts (" TYPE_ATOMIC");
- }
+ if (type->is_atomic ())
+ gdb_puts (" TYPE_ATOMIC");
gdb_puts ("]\n");
gdb_printf ("%*sflags", spaces, "");
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 0acfda0d74b..624d468e4f2 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -168,8 +168,6 @@ struct type_instance_flags
bool is_atomic : 1;
};
-#define TYPE_ATOMIC(t) (((t)->instance_flags ()).is_atomic)
-
/* True if this type represents either an lvalue or lvalue reference type. */
#define TYPE_IS_REFERENCE(t) \
@@ -1227,6 +1225,12 @@ struct type
return this->m_instance_flags.is_restrict;
}
+ /* Return if this type is atomic. */
+ bool is_atomic () const
+ {
+ return this->m_instance_flags.is_atomic;
+ }
+
/* Get the bounds bounds of this type. The type must be a range type. */
range_bounds *bounds () const
{
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 16/17] gdb: convert TYPE_ADDRESS_CLASS macro to type::address_class
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (14 preceding siblings ...)
2026-07-22 10:42 ` [PATCH v2 15/17] gdb: convert TYPE_ATOMIC macro to type::is_atomic Tankut Baris Aktemur
@ 2026-07-22 10:42 ` Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 17/17] gdb: remove unnecessary braces in recursive_dump_type Tankut Baris Aktemur
2026-07-22 15:42 ` [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tom Tromey
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:42 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
Convert the TYPE_ADDRESS_CLASS macro to a method of the type class. This
is a refactoring.
---
gdb/avr-tdep.c | 4 ++--
gdb/c-typeprint.c | 2 +-
gdb/ft32-tdep.c | 2 +-
gdb/gdbtypes.c | 8 +++-----
gdb/gdbtypes.h | 9 ++++++---
5 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index 682b7e8586d..012022f2b73 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -305,7 +305,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 (TYPE_ADDRESS_CLASS (type) == AVR_ADDRESS_CLASS_FLASH)
+ if (type->address_class () == AVR_ADDRESS_CLASS_FLASH)
{
/* A data pointer in flash is byte addressed. */
store_unsigned_integer (buf, type->length (), byte_order,
@@ -337,7 +337,7 @@ avr_pointer_to_address (struct gdbarch *gdbarch,
= extract_unsigned_integer (buf, type->length (), byte_order);
/* Is it a data address in flash? */
- if (TYPE_ADDRESS_CLASS (type) == AVR_ADDRESS_CLASS_FLASH)
+ if (type->address_class () == AVR_ADDRESS_CLASS_FLASH)
{
/* A data pointer in flash is already byte addressed. */
return avr_make_iaddr (addr);
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 92938270647..07f01c92b15 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -492,7 +492,7 @@ c_type_print_modifier (struct type *type, struct ui_file *stream,
else if (gdbarch_address_class_id_to_name_p (type->arch ()))
address_space_id
= gdbarch_address_class_id_to_name (type->arch (),
- TYPE_ADDRESS_CLASS (type));
+ type->address_class ());
if (address_space_id != nullptr)
{
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index f951a6f25e3..38b4784ed35 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -332,7 +332,7 @@ ft32_pointer_to_address (struct gdbarch *gdbarch,
CORE_ADDR addr
= extract_unsigned_integer (buf, type->length (), byte_order);
- if (TYPE_ADDRESS_CLASS (type) == 1)
+ if (type->address_class () == 1)
return addr;
else
return addr | RAM_BIAS;
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 34eaac42e20..f9764fb1da3 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -710,7 +710,7 @@ replace_type (struct type *ntype, struct type *type)
variants. This assertion shouldn't ever be triggered because
symbol readers which do construct address-class variants don't
call replace_type(). */
- gdb_assert (TYPE_ADDRESS_CLASS (chain) == 0);
+ gdb_assert (chain->address_class () == 0);
chain->set_length (type->length ());
chain = chain->chain;
@@ -5029,10 +5029,8 @@ recursive_dump_type (struct type *type, int spaces)
gdb_puts (" TYPE_CODE_SPACE");
if (type->is_data_space ())
gdb_puts (" TYPE_DATA_SPACE");
- if (TYPE_ADDRESS_CLASS (type) != 0)
- {
- gdb_printf (" TYPE_ADDRESS_CLASS(%u)", TYPE_ADDRESS_CLASS (type));
- }
+ if (type->address_class () != 0)
+ gdb_printf (" TYPE_ADDRESS_CLASS(%u)", type->address_class ());
if (type->is_restrict ())
gdb_puts (" TYPE_RESTRICT");
if (type->is_atomic ())
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 624d468e4f2..ecd71f96497 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -186,9 +186,6 @@ struct type_instance_flags
(((t)->dyn_prop (DYN_PROP_BYTE_SIZE) != nullptr) \
|| ((t)->dyn_prop (DYN_PROP_BIT_SIZE) != nullptr))
-#define TYPE_ADDRESS_CLASS(t) \
- (((t)->instance_flags ()).address_class)
-
/* Information about a single discriminant. */
struct discriminant_range
@@ -1231,6 +1228,12 @@ struct type
return this->m_instance_flags.is_atomic;
}
+ /* Return the address class of this type. */
+ unsigned int address_class () const
+ {
+ return this->m_instance_flags.address_class;
+ }
+
/* Get the bounds bounds of this type. The type must be a range type. */
range_bounds *bounds () const
{
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 17/17] gdb: remove unnecessary braces in recursive_dump_type
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (15 preceding siblings ...)
2026-07-22 10:42 ` [PATCH v2 16/17] gdb: convert TYPE_ADDRESS_CLASS macro to type::address_class Tankut Baris Aktemur
@ 2026-07-22 10:42 ` Tankut Baris Aktemur
2026-07-22 15:42 ` [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tom Tromey
17 siblings, 0 replies; 20+ messages in thread
From: Tankut Baris Aktemur @ 2026-07-22 10:42 UTC (permalink / raw)
To: gdb-patches; +Cc: tom
Following the refactoring patches, remove unnecessary branches in
recursive_dump_type to comply with the GNU code style.
Approved-By: Tom Tromey <tom@tromey.com>
---
gdb/gdbtypes.c | 46 +++++++++++++---------------------------------
1 file changed, 13 insertions(+), 33 deletions(-)
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index f9764fb1da3..9098727959e 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -5011,9 +5011,8 @@ recursive_dump_type (struct type *type, int spaces)
gdb_printf ("%*starget_type %s\n", spaces, "",
host_address_to_string (type->target_type ()));
if (type->target_type () != NULL)
- {
- recursive_dump_type (type->target_type (), spaces + 2);
- }
+ recursive_dump_type (type->target_type (), spaces + 2);
+
gdb_printf ("%*spointer_type %s\n", spaces, "",
host_address_to_string (type->pointer_type));
gdb_printf ("%*sreference_type %s\n", spaces, "",
@@ -5039,44 +5038,27 @@ recursive_dump_type (struct type *type, int spaces)
gdb_printf ("%*sflags", spaces, "");
if (type->is_unsigned ())
- {
- gdb_puts (" TYPE_UNSIGNED");
- }
+ gdb_puts (" TYPE_UNSIGNED");
if (type->has_no_signedness ())
- {
- gdb_puts (" TYPE_NOSIGN");
- }
+ gdb_puts (" TYPE_NOSIGN");
if (type->endianity_is_not_default ())
- {
- gdb_puts (" TYPE_ENDIANITY_NOT_DEFAULT");
- }
+ gdb_puts (" TYPE_ENDIANITY_NOT_DEFAULT");
if (type->is_stub ())
- {
- gdb_puts (" TYPE_STUB");
- }
+ gdb_puts (" TYPE_STUB");
if (type->target_is_stub ())
- {
- gdb_puts (" TYPE_TARGET_STUB");
- }
+ gdb_puts (" TYPE_TARGET_STUB");
if (type->is_prototyped ())
- {
- gdb_puts (" TYPE_PROTOTYPED");
- }
+ gdb_puts (" TYPE_PROTOTYPED");
if (type->has_varargs ())
- {
- gdb_puts (" TYPE_VARARGS");
- }
+ gdb_puts (" TYPE_VARARGS");
+
/* This is used for things like AltiVec registers on ppc. Gcc emits
an attribute for the array type, which tells whether or not we
have a vector, instead of a regular array. */
if (type->is_vector ())
- {
- gdb_puts (" TYPE_VECTOR");
- }
+ gdb_puts (" TYPE_VECTOR");
if (type->is_fixed_instance ())
- {
- gdb_puts (" TYPE_FIXED_INSTANCE");
- }
+ gdb_puts (" TYPE_FIXED_INSTANCE");
if (type->is_nottext ())
gdb_puts (" TYPE_NOTTEXT");
gdb_puts ("\n");
@@ -5128,9 +5110,7 @@ recursive_dump_type (struct type *type, int spaces)
gdb_printf ("\n");
if (fld.type () != NULL)
- {
- recursive_dump_type (fld.type (), spaces + 4);
- }
+ recursive_dump_type (fld.type (), spaces + 4);
}
if (type->code () == TYPE_CODE_RANGE)
{
--
2.34.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
` (16 preceding siblings ...)
2026-07-22 10:42 ` [PATCH v2 17/17] gdb: remove unnecessary braces in recursive_dump_type Tankut Baris Aktemur
@ 2026-07-22 15:42 ` Tom Tromey
17 siblings, 0 replies; 20+ messages in thread
From: Tom Tromey @ 2026-07-22 15:42 UTC (permalink / raw)
To: Tankut Baris Aktemur; +Cc: gdb-patches, tom
>>>>> Tankut Baris Aktemur <tankutbaris.aktemur@amd.com> writes:
> This is v2 of the series at
> https://inbox.sourceware.org/gdb-patches/20260713-users-aktemur-type-instance-flags-v1-0-779cad0c85ec@amd.com
> This revision addresses the review comments given by Tom Tromey. The
> patch titled "gdb: refactor type_stack::insert methods" is new.
> Some patches are already approved. They are still included in the
> series for completeness.
Thank you. This all looks good to me.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v2 08/17] gdb: convert type instance flags to bitfields
2026-07-22 10:41 ` [PATCH v2 08/17] gdb: convert type instance flags to bitfields Tankut Baris Aktemur
@ 2026-07-24 19:10 ` Keith Seitz
0 siblings, 0 replies; 20+ messages in thread
From: Keith Seitz @ 2026-07-24 19:10 UTC (permalink / raw)
To: Tankut Baris Aktemur, gdb-patches
Hi,
I know Tom has already approved this, but I want to raise
awareness of a small problem introduced in this patch.
On 7/22/26 3:41 AM, Tankut Baris Aktemur wrote:
> diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
> index 1749c3ba741..11a08428baf 100644
> --- a/gdb/gdbtypes.h
> +++ b/gdb/gdbtypes.h
> @@ -99,51 +99,80 @@ enum harvard_address_space
[snip]
> > -/* Not textual. By default, GDB treats all single byte integers as
> - characters (or elements of strings) unless this flag is set. */
> + type_instance_flags &operator|= (const type_instance_flags &other)
> + {
> + is_const = is_const || other.is_const;
> + is_volatile = is_volatile || other.is_volatile;
> +
> + gdb_assert (harvard_aspace == 0);
> + harvard_aspace = other.harvard_aspace;
>
This assumes the left-hand side is empty, but check_typedef can call
|= when the accumulated (outer) flags already have a Harvard space or
address class set.
Here's a concrete demonstration of the problem:
typedef int myint;
(gdb) ptype (@code myint) 3
../../src/gdb/gdbtypes.h:127: internal-error: operator|=: Assertion
`harvard_aspace == 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
----- Backtrace -----
0x5bb1d1 gdb_internal_backtrace_1
../../src/gdb/bt-utils.c:122
0x5bb210 _Z22gdb_internal_backtracev
../../src/gdb/bt-utils.c:173
0xdfbbaa internal_vproblem
../../src/gdb/utils.c:434
0xdfbf45 _Z15internal_verrorPKciS0_P13__va_list_tag
../../src/gdb/utils.c:514
0x162763f _Z18internal_error_locPKciS0_z
../../src/gdbsupport/errors.cc:57
0x87e8e6 _ZN19type_instance_flagsoRERKS_
../../src/gdb/gdbtypes.h:127
0x875d71 _Z13check_typedefP4type
../../src/gdb/gdbtypes.c:3072
[snip]
The "outer" type (associated with "@code") has an address space
set. When check_typedef then attempts to merge the inner "myint"
definition, the assert triggers.
Keith
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2026-07-24 19:11 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-22 10:41 [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 01/17] gdb: use type instance macros to query const, volatile, restrict Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 02/17] gdb: convert address_class_type_flags_to_name to address_class_id_to_name Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 03/17] gdb: convert address_class_name_to_type_flags to address_class_name_to_id Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 04/17] gdb: convert address_class_type_flags to address_class_dwarf_to_id Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 05/17] gdb: refactor type_stack::insert methods Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 06/17] gdb: inline address_space_{name, type_instance_flags}_to_{type_instance_flags, name} Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 07/17] gdb: split make_type_with_address_space Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 08/17] gdb: convert type instance flags to bitfields Tankut Baris Aktemur
2026-07-24 19:10 ` Keith Seitz
2026-07-22 10:41 ` [PATCH v2 09/17] gdb: convert TYPE_NOTTEXT macro to type::is_nottext Tankut Baris Aktemur
2026-07-22 10:41 ` [PATCH v2 10/17] gdb: convert TYPE_CONST macro to type::is_const Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 11/17] gdb: convert TYPE_VOLATILE macro to type::is_volatile Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 12/17] gdb: convert TYPE_CODE_SPACE macro to type::is_code_space Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 13/17] gdb: convert TYPE_DATA_SPACE macro to type::is_data_space Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 14/17] gdb: convert TYPE_RESTRICT macro to type::is_restrict Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 15/17] gdb: convert TYPE_ATOMIC macro to type::is_atomic Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 16/17] gdb: convert TYPE_ADDRESS_CLASS macro to type::address_class Tankut Baris Aktemur
2026-07-22 10:42 ` [PATCH v2 17/17] gdb: remove unnecessary braces in recursive_dump_type Tankut Baris Aktemur
2026-07-22 15:42 ` [PATCH v2 00/17] Rewrite type instance flags as a struct with bitfields Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox