aboutsummaryrefslogtreecommitdiff
path: root/gdb/xtensa-tdep.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2018-10-21 22:29:21 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2018-10-21 22:29:21 -0400
commitf6efe3f842e72e23ec6d8a57d683ce90d2e89785 (patch)
treea0d6e232cc7bff7ef9ce51c34afc865032d8414f /gdb/xtensa-tdep.c
parent925047fed0d6ab86e6fe86d3e22e1aa9dde7b3eb (diff)
downloadgdb-f6efe3f842e72e23ec6d8a57d683ce90d2e89785.zip
gdb-f6efe3f842e72e23ec6d8a57d683ce90d2e89785.tar.gz
gdb-f6efe3f842e72e23ec6d8a57d683ce90d2e89785.tar.bz2
Introduce gdbarch_num_cooked_regs
The expression gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch) is used quite often to find the number of cooked registers (raw + pseudo registers). This patch introduces gdbarch_num_cooked_regs, which does the equivalent. It substantially reduces required wrapping in some places, so should improve readability. There is a for loop in m68hc11_frame_unwind_cache that had iterated until (the equivalent of) gdbarch_num_cooked_regs (gdbarch) - 1. During review, we concluded that this is most likely an off-by-one mistake, so I replaced it with gdbarch_num_cooked_regs (gdbarch). gdb/ChangeLog: * gdbarch.sh (gdbarch_num_cooked_regs): New. * gdbarch.h: Re-generate. * ax-gdb.c (gen_expr): Use gdbarch_num_cooked_regs. * dwarf2-frame.c (dwarf2_frame_cache): Likewise. * eval.c (evaluate_subexp_standard): Likewise. * findvar.c (value_of_register): Likewise. (value_of_register_lazy): Likewise. (address_from_register): Likewise. * frame.c (get_frame_register_bytes): Likewise. * gdbarch-selftests.c (register_to_value_test): Likewise. * h8300-tdep.c (h8300_register_type): Likewise. * i386-tdep.c (i386_dbx_reg_to_regnum): Likewise. (i386_svr4_reg_to_regnum): Likewise. * infcmd.c (default_print_registers_info): Likewise. (registers_info): Likewise. (print_vector_info): Likewise. (default_print_float_info): Likewise. * m68hc11-tdep.c (m68hc11_frame_unwind_cache): Likewise. * mdebugread.c (mdebug_reg_to_regnum): Likewise. * mi/mi-main.c (mi_cmd_data_list_register_names): Likewise. (mi_cmd_data_list_changed_registers): Likewise. (mi_cmd_data_list_register_values): Likewise. (mi_cmd_data_write_register_values): Likewise. (mi_cmd_trace_frame_collected): Likewise. * mips-tdep.c (print_gp_register_row): Likewise. (mips_print_registers_info): Likewise. * nds32-tdep.c (nds32_gdbarch_init): Likewise. * regcache.c (init_regcache_descr): Likewise. (register_size): Likewise. (register_dump::dump): Likewise. (cooked_read_test): Likewise. (cooked_write_test): Likewise. * rs6000-tdep.c (rs6000_register_sim_regno): Likewise. (rs6000_gdbarch_init): Likewise. * stabsread.c (stab_reg_to_regnum): Likewise. * stack.c (info_frame_command): Likewise. * target-descriptions.c (tdesc_register_name): Likewise. * trad-frame.c (trad_frame_alloc_saved_regs): Likewise. * tui/tui-regs.c (tui_show_register_group): Likewise. * user-regs.c (user_reg_map_name_to_regnum): Likewise. (user_reg_map_regnum_to_name): Likewise. (value_of_user_reg): Likewise. (maintenance_print_user_registers): Likewise. * xtensa-tdep.c (xtensa_find_register_by_name): Likewise. (xtensa_register_name): Likewise. (xtensa_register_type): Likewise. (xtensa_reg_to_regnum): Likewise. (xtensa_pseudo_register_read): Likewise. (xtensa_pseudo_register_write): Likewise.
Diffstat (limited to 'gdb/xtensa-tdep.c')
-rw-r--r--gdb/xtensa-tdep.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index 3b32bcf..4f29557 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -234,9 +234,7 @@ xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
{
int i;
- for (i = 0; i < gdbarch_num_regs (gdbarch)
- + gdbarch_num_pseudo_regs (gdbarch);
- i++)
+ for (i = 0; i < gdbarch_num_cooked_regs (gdbarch); i++)
if (strcasecmp (gdbarch_tdep (gdbarch)->regmap[i].name, name) == 0)
return i;
@@ -249,8 +247,7 @@ static const char *
xtensa_register_name (struct gdbarch *gdbarch, int regnum)
{
/* Return the name stored in the register map. */
- if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)
- + gdbarch_num_pseudo_regs (gdbarch))
+ if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
return gdbarch_tdep (gdbarch)->regmap[regnum].name;
internal_error (__FILE__, __LINE__, _("invalid register %d"), regnum);
@@ -276,8 +273,7 @@ xtensa_register_type (struct gdbarch *gdbarch, int regnum)
return builtin_type (gdbarch)->builtin_data_ptr;
/* Return the stored type for all other registers. */
- else if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)
- + gdbarch_num_pseudo_regs (gdbarch))
+ else if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
{
xtensa_register_t* reg = &tdep->regmap[regnum];
@@ -352,9 +348,7 @@ xtensa_reg_to_regnum (struct gdbarch *gdbarch, int regnum)
if (regnum >= 0 && regnum < 16)
return gdbarch_tdep (gdbarch)->a0_base + regnum;
- for (i = 0;
- i < gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
- i++)
+ for (i = 0; i < gdbarch_num_cooked_regs (gdbarch); i++)
if (regnum == gdbarch_tdep (gdbarch)->regmap[i].target_number)
return i;
@@ -585,9 +579,7 @@ xtensa_pseudo_register_read (struct gdbarch *gdbarch,
return REG_VALID;
}
/* Pseudo registers. */
- else if (regnum >= 0
- && regnum < gdbarch_num_regs (gdbarch)
- + gdbarch_num_pseudo_regs (gdbarch))
+ else if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
{
xtensa_register_t *reg = &gdbarch_tdep (gdbarch)->regmap[regnum];
xtensa_register_type_t type = reg->type;
@@ -670,9 +662,7 @@ xtensa_pseudo_register_write (struct gdbarch *gdbarch,
return;
}
/* Pseudo registers. */
- else if (regnum >= 0
- && regnum < gdbarch_num_regs (gdbarch)
- + gdbarch_num_pseudo_regs (gdbarch))
+ else if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
{
xtensa_register_t *reg = &gdbarch_tdep (gdbarch)->regmap[regnum];
xtensa_register_type_t type = reg->type;