public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: specify sh4al-dsp register types
@ 2024-03-31 22:26 Sébastien Michelland
  2024-04-01  3:25 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Sébastien Michelland @ 2024-03-31 22:26 UTC (permalink / raw)
  To: gdb-patches; +Cc: Sébastien Michelland

This avoids $pc and similar registers being interpreted as negative when
in the upper half of the address space (e.g. by x/i), which doesn't
interact well with Xfer memory maps.
---

Hi,

This patch fixes a pretty funny issue for the sh4al-dsp resulting from
$pc being typed as an int. When $pc is in the upper half of the address
space, `x/i $pc' would resolve to a negative value. At least in the case
of a remote target with an Xfer memory map, this leads to a spurious
"cannot access memory" error as negative addresses are out of bounds.

(gdb) x/i $pc
   0x8c202c04:	Cannot access memory at address 0x8c202c04
(gdb) x/i 0x8c202c04
=> 0x8c202c04 <gintctl_gint_gdb+304>:	mov.l	@r1,r10

Affected registers are pc, pr (return address of a call), gbr (base
register for some specific addressing modes), vbr (interrupt handler)
and spc (return address after interrupt).

It's not immediately clear to me why existing sh variants don't also do
that. Maybe it should be considered an issue with the memory map, or
maybe it's just a rare enough condition to not care.

 gdb/sh-tdep.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 1c67ea42..c1845111 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -1437,6 +1437,16 @@ sh_sh4_register_type (struct gdbarch *gdbarch, int reg_nr)
     return builtin_type (gdbarch)->builtin_int;
 }
 
+static struct type *
+sh_sh4al_dsp_register_type (struct gdbarch *gdbarch, int reg_nr)
+{
+  if (reg_nr == PC_REGNUM || reg_nr == PR_REGNUM || reg_nr == GBR_REGNUM
+      || reg_nr == VBR_REGNUM || reg_nr == SPC_REGNUM)
+    return builtin_type (gdbarch)->builtin_func_ptr;
+  else
+    return builtin_type (gdbarch)->builtin_int;
+}
+
 static struct type *
 sh_default_register_type (struct gdbarch *gdbarch, int reg_nr)
 {
@@ -2353,6 +2363,7 @@ sh_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
     case bfd_mach_sh4al_dsp:
       set_gdbarch_register_name (gdbarch, sh_sh4al_dsp_register_name);
+      set_gdbarch_register_type (gdbarch, sh_sh4al_dsp_register_type);
       set_gdbarch_register_sim_regno (gdbarch, sh_dsp_register_sim_regno);
       break;
 
-- 
2.44.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-01  9:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-31 22:26 [PATCH] gdb: specify sh4al-dsp register types Sébastien Michelland
2024-04-01  3:25 ` Simon Marchi
2024-04-01  9:14   ` Sébastien Michelland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).