[PATCH] Compute register name once in default_print_one_register_info

Tom Tromey
2026-02-27T14:34:14Z

PR gdb/9884 points out that default_print_one_register_info could call
gdbarch_register_name a single time. The current code seems harmless
but OTOH the proposed change is also harmless and perhaps slightly
faster, so why not.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=9884
---
gdb/infcmd.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 319d17d95eb..d0d1c142041 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2505,11 +2505,12 @@ default_print_registers_info (struct gdbarch *gdbarch,

/* If the register name is empty, it is undefined for this
processor, so don't display anything. */
- if (*(gdbarch_register_name (gdbarch, i)) == '\0')
+ const char *regname = gdbarch_register_name (gdbarch, i);
+ if (*regname == '\0')
continue;

default_print_one_register_info
- (file, gdbarch_register_name (gdbarch, i),
+ (file, regname,
value_of_register (i, get_next_frame_sentinel_okay (frame)));
}
}

base-commit: e302db71359c85e3c1f1eb90e8f0aaa06ee81752
--
2.53.0