Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>,
	       Mark Kettenis <mark.kettenis@xs4all.nl>
Subject: [PATCH 1/2] H8/300: Fix gdb<->sim register mapping.
Date: Wed, 12 Feb 2014 12:42:00 -0000	[thread overview]
Message-ID: <1392208927-15739-2-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1392208927-15739-1-git-send-email-palves@redhat.com>

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 <foo>) 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 <unavailable> 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  <palves@redhat.com>

	* 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  <palves@redhat.com>
+
+	* 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  <sanimir.agovic@intel.com>
 
 	* 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:
-- 
1.7.11.7


      parent reply	other threads:[~2014-02-12 12:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-01 12:43 [PATCH] h8300 "info registers" broken Yoshinori Sato
2014-02-04 19:38 ` Pedro Alves
2014-02-05 17:51   ` Yoshinori Sato
2014-02-05 17:59     ` Mark Kettenis
2014-02-08 18:36       ` Yoshinori Sato
2014-02-10 15:53         ` Pedro Alves
2014-02-11 10:29           ` Yoshinori Sato
2014-02-11 11:47             ` Pedro Alves
2014-02-11 13:11               ` Yoshinori Sato
2014-02-12 12:42                 ` [PATCH 0/2] H8/300: Fix registers Pedro Alves
2014-02-12 12:42                   ` [PATCH 2/2] H8/300: Fix pseudo registers reads/writes Pedro Alves
2014-02-12 12:59                     ` Mark Kettenis
2014-02-12 12:42                   ` Pedro Alves [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1392208927-15739-2-git-send-email-palves@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=mark.kettenis@xs4all.nl \
    --cc=ysato@users.sourceforge.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox