From 637b2f86138a8ec0ab0fe89d3e4c5c111559d7f2 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Wed, 31 Aug 2022 15:42:43 +0100 Subject: [PATCH] gdb: update now gdbarch_register_name doesn't return nullptr After the previous few commit, gdbarch_register_name no longer returns nullptr. This commit audits all the calls to gdbarch_register_name and removes any code that checks the result against nullptr. There should be no visible change after this commit. --- gdb/alpha-tdep.c | 3 +-- gdb/arch-utils.c | 3 +-- gdb/csky-tdep.c | 3 +-- gdb/h8300-tdep.c | 2 +- gdb/infcmd.c | 3 +-- gdb/m68hc11-tdep.c | 2 +- gdb/mi/mi-main.c | 20 ++++++-------------- gdb/mips-tdep.c | 8 ++------ gdb/nds32-tdep.c | 3 +-- gdb/regcache.c | 5 +---- gdb/reggroups.c | 3 +-- gdb/riscv-tdep.c | 9 +++------ gdb/sh-tdep.c | 3 +-- gdb/tui/tui-regs.c | 4 ++-- gdb/user-regs.c | 10 +++------- gdb/valops.c | 2 +- 16 files changed, 27 insertions(+), 56 deletions(-) diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c index d30e0c369cc..9b3dbca8cde 100644 --- a/gdb/alpha-tdep.c +++ b/gdb/alpha-tdep.c @@ -140,8 +140,7 @@ alpha_register_reggroup_p (struct gdbarch *gdbarch, int regnum, { /* Filter out any registers eliminated, but whose regnum is reserved for backward compatibility, e.g. the vfp. */ - if (gdbarch_register_name (gdbarch, regnum) == NULL - || *gdbarch_register_name (gdbarch, regnum) == '\0') + if (*gdbarch_register_name (gdbarch, regnum) == '\0') return 0; if (group == all_reggroup) diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index 5943965bd75..77269425ddc 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -76,8 +76,7 @@ legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum) suspected that some GDB/SIM combinations may rely on this behaviour. The default should be one2one_register_sim_regno (below). */ - if (gdbarch_register_name (gdbarch, regnum) != NULL - && gdbarch_register_name (gdbarch, regnum)[0] != '\0') + if (gdbarch_register_name (gdbarch, regnum)[0] != '\0') return regnum; else return LEGACY_SIM_REGNO_IGNORE; diff --git a/gdb/csky-tdep.c b/gdb/csky-tdep.c index 17820aab6eb..cc8812003c8 100644 --- a/gdb/csky-tdep.c +++ b/gdb/csky-tdep.c @@ -2353,8 +2353,7 @@ csky_register_reggroup_p (struct gdbarch *gdbarch, int regnum, { int raw_p; - if (gdbarch_register_name (gdbarch, regnum) == NULL - || gdbarch_register_name (gdbarch, regnum)[0] == '\0') + if (gdbarch_register_name (gdbarch, regnum)[0] == '\0') return 0; if (reggroup == all_reggroup) diff --git a/gdb/h8300-tdep.c b/gdb/h8300-tdep.c index ed401ee45f8..8f8461fe61d 100644 --- a/gdb/h8300-tdep.c +++ b/gdb/h8300-tdep.c @@ -996,7 +996,7 @@ h8300_print_register (struct gdbarch *gdbarch, struct ui_file *file, LONGEST rval; const char *name = gdbarch_register_name (gdbarch, regno); - if (!name || !*name) + if (*name == '\0') return; rval = get_frame_register_signed (frame, regno); diff --git a/gdb/infcmd.c b/gdb/infcmd.c index b788f454432..decd61111b7 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -2224,8 +2224,7 @@ 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) == NULL - || *(gdbarch_register_name (gdbarch, i)) == '\0') + if (*(gdbarch_register_name (gdbarch, i)) == '\0') continue; default_print_one_register_info (file, diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c index f5e33e7a0f1..343ecf5c262 100644 --- a/gdb/m68hc11-tdep.c +++ b/gdb/m68hc11-tdep.c @@ -1090,7 +1090,7 @@ m68hc11_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file, { const char *name = gdbarch_register_name (gdbarch, regno); - if (!name || !*name) + if (*name == '\0') return; gdb_printf (file, "%-10s ", name); diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index b758f398e2a..80b5cd9bf90 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -880,8 +880,7 @@ mi_cmd_data_list_register_names (const char *command, char **argv, int argc) regnum < numregs; regnum++) { - if (gdbarch_register_name (gdbarch, regnum) == NULL - || *(gdbarch_register_name (gdbarch, regnum)) == '\0') + if (*(gdbarch_register_name (gdbarch, regnum)) == '\0') uiout->field_string (NULL, ""); else uiout->field_string (NULL, gdbarch_register_name (gdbarch, regnum)); @@ -895,8 +894,7 @@ mi_cmd_data_list_register_names (const char *command, char **argv, int argc) if (regnum < 0 || regnum >= numregs) error (_("bad register number")); - if (gdbarch_register_name (gdbarch, regnum) == NULL - || *(gdbarch_register_name (gdbarch, regnum)) == '\0') + if (*(gdbarch_register_name (gdbarch, regnum)) == '\0') uiout->field_string (NULL, ""); else uiout->field_string (NULL, gdbarch_register_name (gdbarch, regnum)); @@ -940,8 +938,7 @@ mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc) regnum < numregs; regnum++) { - if (gdbarch_register_name (gdbarch, regnum) == NULL - || *(gdbarch_register_name (gdbarch, regnum)) == '\0') + if (*(gdbarch_register_name (gdbarch, regnum)) == '\0') continue; if (register_changed_p (regnum, prev_regs.get (), @@ -957,7 +954,6 @@ mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc) if (regnum >= 0 && regnum < numregs - && gdbarch_register_name (gdbarch, regnum) != NULL && *gdbarch_register_name (gdbarch, regnum) != '\000') { if (register_changed_p (regnum, prev_regs.get (), @@ -1067,8 +1063,7 @@ mi_cmd_data_list_register_values (const char *command, char **argv, int argc) regnum < numregs; regnum++) { - if (gdbarch_register_name (gdbarch, regnum) == NULL - || *(gdbarch_register_name (gdbarch, regnum)) == '\0') + if (*(gdbarch_register_name (gdbarch, regnum)) == '\0') continue; output_register (frame, regnum, format, skip_unavailable); @@ -1082,7 +1077,6 @@ mi_cmd_data_list_register_values (const char *command, char **argv, int argc) if (regnum >= 0 && regnum < numregs - && gdbarch_register_name (gdbarch, regnum) != NULL && *gdbarch_register_name (gdbarch, regnum) != '\000') output_register (frame, regnum, format, skip_unavailable); else @@ -1163,8 +1157,7 @@ mi_cmd_data_write_register_values (const char *command, char **argv, int argc) int regnum = atoi (argv[i]); if (regnum >= 0 && regnum < numregs - && gdbarch_register_name (gdbarch, regnum) - && *gdbarch_register_name (gdbarch, regnum)) + && *gdbarch_register_name (gdbarch, regnum) != '\0') { LONGEST value; @@ -2632,8 +2625,7 @@ mi_cmd_trace_frame_collected (const char *command, char **argv, int argc) for (regnum = 0; regnum < numregs; regnum++) { - if (gdbarch_register_name (gdbarch, regnum) == NULL - || *(gdbarch_register_name (gdbarch, regnum)) == '\0') + if (*(gdbarch_register_name (gdbarch, regnum)) == '\0') continue; output_register (frame, regnum, registers_format, 1); diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c index 14f5c3e4e72..c5bd73ce780 100644 --- a/gdb/mips-tdep.c +++ b/gdb/mips-tdep.c @@ -712,8 +712,7 @@ mips_register_reggroup_p (struct gdbarch *gdbarch, int regnum, /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs (gdbarch), as not all architectures are multi-arch. */ raw_p = rawnum < gdbarch_num_regs (gdbarch); - if (gdbarch_register_name (gdbarch, regnum) == NULL - || gdbarch_register_name (gdbarch, regnum)[0] == '\0') + if (gdbarch_register_name (gdbarch, regnum)[0] == '\0') return 0; if (reggroup == float_reggroup) return float_p && pseudo; @@ -7952,10 +7951,7 @@ mips_register_sim_regno (struct gdbarch *gdbarch, int regnum) decide if it is valid. Should instead define a standard sim/gdb register numbering scheme. */ if (gdbarch_register_name (gdbarch, - gdbarch_num_regs (gdbarch) + regnum) != NULL - && gdbarch_register_name (gdbarch, - gdbarch_num_regs (gdbarch) - + regnum)[0] != '\0') + gdbarch_num_regs (gdbarch) + regnum)[0] != '\0') return regnum; else return LEGACY_SIM_REGNO_IGNORE; diff --git a/gdb/nds32-tdep.c b/gdb/nds32-tdep.c index 77eb5da863e..962584a3683 100644 --- a/gdb/nds32-tdep.c +++ b/gdb/nds32-tdep.c @@ -2030,8 +2030,7 @@ nds32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) { const char *regname = gdbarch_register_name (gdbarch, j); - if (regname != NULL - && strcmp (regname, nds32_register_aliases[i].name) == 0) + if (strcmp (regname, nds32_register_aliases[i].name) == 0) { regnum = j; break; diff --git a/gdb/regcache.c b/gdb/regcache.c index b0e92dd0077..279bf2258a9 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -1392,7 +1392,6 @@ regcache::debug_print_register (const char *func, int regno) gdb_printf (gdb_stdlog, "%s ", func); if (regno >= 0 && regno < gdbarch_num_regs (gdbarch) - && gdbarch_register_name (gdbarch, regno) != NULL && gdbarch_register_name (gdbarch, regno)[0] != '\0') gdb_printf (gdb_stdlog, "(%s)", gdbarch_register_name (gdbarch, regno)); @@ -1453,9 +1452,7 @@ register_dump::dump (ui_file *file) { const char *p = gdbarch_register_name (m_gdbarch, regnum); - if (p == NULL) - p = ""; - else if (p[0] == '\0') + if (p[0] == '\0') p = "''"; gdb_printf (file, " %-10s", p); } diff --git a/gdb/reggroups.c b/gdb/reggroups.c index b81031b42ac..8e4af303c54 100644 --- a/gdb/reggroups.c +++ b/gdb/reggroups.c @@ -146,8 +146,7 @@ default_register_reggroup_p (struct gdbarch *gdbarch, int regnum, int float_p; int raw_p; - if (gdbarch_register_name (gdbarch, regnum) == NULL - || *gdbarch_register_name (gdbarch, regnum) == '\0') + if (*gdbarch_register_name (gdbarch, regnum) == '\0') return 0; if (group == all_reggroup) return 1; diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index 7bddf535804..47d8f9e601b 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -1352,8 +1352,7 @@ riscv_register_reggroup_p (struct gdbarch *gdbarch, int regnum, /* Used by 'info registers' and 'info registers '. */ - if (gdbarch_register_name (gdbarch, regnum) == NULL - || gdbarch_register_name (gdbarch, regnum)[0] == '\0') + if (gdbarch_register_name (gdbarch, regnum)[0] == '\0') return 0; if (regnum > RISCV_LAST_REGNUM && regnum < gdbarch_num_regs (gdbarch)) @@ -1478,8 +1477,7 @@ riscv_print_registers_info (struct gdbarch *gdbarch, if (regnum != -1) { /* Print one specified register. */ - if (gdbarch_register_name (gdbarch, regnum) == NULL - || *(gdbarch_register_name (gdbarch, regnum)) == '\0') + if (*(gdbarch_register_name (gdbarch, regnum)) == '\0') error (_("Not a valid register for the current processor type")); riscv_print_one_register_info (gdbarch, file, frame, regnum); } @@ -1499,8 +1497,7 @@ riscv_print_registers_info (struct gdbarch *gdbarch, continue; /* Registers with no name are not valid on this ISA. */ - if (gdbarch_register_name (gdbarch, regnum) == NULL - || *(gdbarch_register_name (gdbarch, regnum)) == '\0') + if (*(gdbarch_register_name (gdbarch, regnum)) == '\0') continue; /* Is the register in the group we're interested in? */ diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c index 90f8aa4185c..b08e37117ae 100644 --- a/gdb/sh-tdep.c +++ b/gdb/sh-tdep.c @@ -1452,8 +1452,7 @@ static int sh_register_reggroup_p (struct gdbarch *gdbarch, int regnum, const struct reggroup *reggroup) { - if (gdbarch_register_name (gdbarch, regnum) == NULL - || *gdbarch_register_name (gdbarch, regnum) == '\0') + if (*gdbarch_register_name (gdbarch, regnum) == '\0') return 0; if (reggroup == float_reggroup diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c index 5106a3b9670..830df5427c7 100644 --- a/gdb/tui/tui-regs.c +++ b/gdb/tui/tui-regs.c @@ -231,7 +231,7 @@ tui_data_window::show_register_group (const reggroup *group, /* If the register name is empty, it is undefined for this processor, so don't display anything. */ name = gdbarch_register_name (gdbarch, regnum); - if (name == 0 || *name == '\0') + if (*name == '\0') continue; nr_regs++; @@ -253,7 +253,7 @@ tui_data_window::show_register_group (const reggroup *group, /* If the register name is empty, it is undefined for this processor, so don't display anything. */ name = gdbarch_register_name (gdbarch, regnum); - if (name == 0 || *name == '\0') + if (*name == '\0') continue; data_item_win = &m_regs_content[pos]; diff --git a/gdb/user-regs.c b/gdb/user-regs.c index 05bb04ef2ed..3030d952cf1 100644 --- a/gdb/user-regs.c +++ b/gdb/user-regs.c @@ -139,18 +139,14 @@ user_reg_map_name_to_regnum (struct gdbarch *gdbarch, const char *name, /* Search register name space first - always let an architecture specific register override the user registers. */ { - int i; int maxregs = gdbarch_num_cooked_regs (gdbarch); - for (i = 0; i < maxregs; i++) + for (int i = 0; i < maxregs; i++) { const char *regname = gdbarch_register_name (gdbarch, i); - if (regname != NULL && len == strlen (regname) - && strncmp (regname, name, len) == 0) - { - return i; - } + if (len == strlen (regname) && strncmp (regname, name, len) == 0) + return i; } } diff --git a/gdb/valops.c b/gdb/valops.c index b4866d089ac..0a215d699a1 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -1417,7 +1417,7 @@ address_of_variable (struct symbol *var, const struct block *b) regname = gdbarch_register_name (get_frame_arch (frame), VALUE_REGNUM (val)); - gdb_assert (regname && *regname); + gdb_assert (regname != nullptr && *regname != '\0'); error (_("Address requested for identifier " "\"%s\" which is in register $%s"), -- 2.30.2