From 76fd5f745a0ba0b163fada011bece5084b3079c7 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 12 Feb 2014 12:27:49 +0000 Subject: [PATCH] H8/300: Fix gdb<->sim register mapping. Currently, printing the H8/300 ccr register when debugging with the sim is broken: (gdb) target sim ... (gdb) load ... (gdb) start ... Breakpoint 1, foo (i=0x0 ) at main.c:4 4 { (gdb) info registers ccr Register 13 is not available '13' is the ccr pseudo-register. This pseudo-register provides an 8-bit view into the raw ccr register (regno=8). The problem is that the H8/300 port does not define a register_sim_regno gdbarch hook, and thus when fetching the raw register off of the sim, we end up in legacy_register_sim_regno trying to figure out the sim register number for the raw CCR register: int legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum) { /* Only makes sense to supply raw registers. */ gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)); /* NOTE: cagney/2002-05-13: The old code did it this way and it is suspected that some GDB/SIM combinations may rely on this behavour. The default should be one2one_register_sim_regno (below). */ if (gdbarch_register_name (gdbarch, regnum) != NULL && gdbarch_register_name (gdbarch, regnum)[0] != '\0') return regnum; else return LEGACY_SIM_REGNO_IGNORE; } Because the raw ccr register does not have a name (so that it is hidden from the user), that returns LEGACY_SIM_REGNO_IGNORE. That means that we never actually read the value of the raw ccr register. Before the support, this must have meant that ccr was _always_ read as 0... At least, I'm not seeing how this ever worked. The fix for that is adding a gdbarch_register_sim_regno hook that maps all raw registers. Looking at sim/h8300/sim-main.h, I believe the sim's register numbers are compatible with gdb's, so no actual convertion is necessary. gdb/ 2014-02-12 Pedro Alves * h8300-tdep.c (h8300_register_sim_regno): New function. (h8300_gdbarch_init): Install h8300_register_sim_regno as gdbarch_register_sim_regno hook. --- gdb/ChangeLog | 6 ++++++ gdb/h8300-tdep.c | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index bb977b5..6f0f903 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2014-02-12 Pedro Alves + + * h8300-tdep.c (h8300_register_sim_regno): New function. + (h8300_gdbarch_init): Install h8300_register_sim_regno as + gdbarch_register_sim_regno hook. + 2014-02-12 Sanimir Agovic * nios2-tdep.c (nios2_stub_frame_base): Remove global. diff --git a/gdb/h8300-tdep.c b/gdb/h8300-tdep.c index ffffbc9..4193287 100644 --- a/gdb/h8300-tdep.c +++ b/gdb/h8300-tdep.c @@ -939,6 +939,22 @@ h8300h_return_value (struct gdbarch *gdbarch, struct value *function, static struct cmd_list_element *setmachinelist; +/* Implementation of 'register_sim_regno' gdbarch method. */ + +static int +h8300_register_sim_regno (struct gdbarch *gdbarch, int regnum) +{ + /* Only makes sense to supply raw registers. */ + gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)); + + /* We hide the raw ccr from the user by making it nameless. Because + the default register_sim_regno hook returns + LEGACY_SIM_REGNO_IGNORE for unnamed registers, we need to + override it. The sim register numbering is compatible with + gdb's. */ + return regnum; +} + static const char * h8300_register_name (struct gdbarch *gdbarch, int regno) { @@ -1230,6 +1246,8 @@ h8300_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) gdbarch = gdbarch_alloc (&info, 0); + set_gdbarch_register_sim_regno (gdbarch, h8300_register_sim_regno); + switch (info.bfd_arch_info->mach) { case bfd_mach_h8300: -- 2.7.4