[binutils-gdb] gdb: track type instead of gdbarch for `next_address`
Tankut Baris Aktemur via Gdb-cvs <[email protected]>
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e17a2548e12c91d34d750ec54768483df8116c5d commit e17a2548e12c91d34d750ec54768483df8116c5d Author: Tankut Baris Aktemur <[email protected]> Date: Tue Mar 24 16:56:03 2026 +0100 gdb: track type instead of gdbarch for `next_address` The `next_address` global that is used for tracking the next address to show in the 'x' command is declared as plain CORE_ADDR. In addition to this CORE_ADDR, a gdbarch is also being tracked, so that the right type can be determined based on the format specified by the user. In GDB, a pointer may be pointing to a particular address class. This is indicated in the type instance flags of the pointer's target type. In case an address class other than the default one is being pointed at, the data needs to be fetched from the target accordingly. Hence, in addition to the CORE_ADDR and gdbarch, we also need to track the address class of the next address. Rather than adding one more variable to the global state, we can track the type instead of gdbarch. The architecture can be obtained from the type anyway. This patch does the refactoring to replace the `next_gdbarch` global with the `next_type` global. No observable change in the behavior of GDB is expected. The type instance flags that may carry address class information mentioned above are still lost, though. The next patch handles this problem, while this patch focuses on the refactoring only. Regression-tested on X86-64 Linux. Approved-By: Tom Tromey <[email protected]> Diff: --- gdb/printcmd.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 49f7209ca40..49e97ca336c 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -76,9 +76,9 @@ static int last_count; static bool last_print_tags = false; -/* Default address to examine next, and associated architecture. */ +/* Default address to examine next, and associated type. */ -static struct gdbarch *next_gdbarch; +static type *next_type; static CORE_ADDR next_address; /* Number of delay instructions following current disassembled insn. */ @@ -529,7 +529,7 @@ set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr) { type *ptr_type = builtin_type (gdbarch)->builtin_func_ptr; - next_gdbarch = gdbarch; + next_type = ptr_type; next_address = addr; /* Make address available to the user as $_. */ @@ -1064,8 +1064,8 @@ static void do_examine_next_address (struct format_data fmt) { char format = fmt.format; - type *val_type = format_to_type (fmt, next_gdbarch); - gdbarch *gdbarch = next_gdbarch; + type *val_type = next_type; + gdbarch *gdbarch = next_type->arch (); char size; switch (val_type->length ()) @@ -1884,10 +1884,10 @@ x_command (const char *exp, int from_tty) else next_address = value_as_address (val); - next_gdbarch = expr->gdbarch; + next_type = format_to_type (fmt, expr->gdbarch); } - if (!next_gdbarch) + if (next_type == nullptr) error_no_arg (_("starting display address")); do_examine_next_address (fmt); @@ -2167,7 +2167,7 @@ do_one_display (struct display *d) if (d->format.format == 'i') addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr); - next_gdbarch = d->exp->gdbarch; + next_type = format_to_type (d->format, d->exp->gdbarch); next_address = addr; do_examine_next_address (d->format); }