public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb: specify sh pointer register types
@ 2024-04-26 13:56 Simon Marchi
  0 siblings, 0 replies; only message in thread
From: Simon Marchi @ 2024-04-26 13:56 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=afdd600c0982f0ce95439f2936c6d6d6d0201f77

commit afdd600c0982f0ce95439f2936c6d6d6d0201f77
Author: Sébastien Michelland <sebastien.michelland@lcis.grenoble-inp.fr>
Date:   Mon Apr 1 11:55:53 2024 +0200

    gdb: specify sh pointer register types
    
    This patch fixes a pretty funny issue on sh targets that occurred
    because $pc (and similar registers) were typed as int. When $pc is in
    the upper half of the address space (i.e. kernel code on sh), `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
    
    The issue is fixed by specifying pointer types for pc and other pointer
    registers. Code pointer registers on sh include pc, pr (return address
    of a call), vbr (interrupt handler) and spc (return address after
    interrupt). Data pointers include r15 (stack pointer) and gbr (base
    register for a few specific addressing modes).
    
    Change-Id: I043a058f7cbc6494f380dc0461616a9f3e0d87e0
    Approved-By: Simon Marchi <simon.marchi@efficios.com>

Diff:
---
 gdb/sh-tdep.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 0a3b50702d9..0dbb905f1db 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -1401,6 +1401,11 @@ sh_sh2a_register_type (struct gdbarch *gdbarch, int reg_nr)
     return builtin_type (gdbarch)->builtin_float;
   else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
     return builtin_type (gdbarch)->builtin_double;
+  else if (reg_nr == PC_REGNUM || reg_nr == PR_REGNUM || reg_nr == VBR_REGNUM
+	   || reg_nr == SPC_REGNUM)
+    return builtin_type (gdbarch)->builtin_func_ptr;
+  else if (reg_nr == R0_REGNUM + 15 || reg_nr == GBR_REGNUM)
+    return builtin_type (gdbarch)->builtin_data_ptr;
   else
     return builtin_type (gdbarch)->builtin_int;
 }
@@ -1413,6 +1418,11 @@ sh_sh3e_register_type (struct gdbarch *gdbarch, int reg_nr)
   if ((reg_nr >= gdbarch_fp0_regnum (gdbarch)
        && (reg_nr <= FP_LAST_REGNUM)) || (reg_nr == FPUL_REGNUM))
     return builtin_type (gdbarch)->builtin_float;
+  else if (reg_nr == PC_REGNUM || reg_nr == PR_REGNUM || reg_nr == VBR_REGNUM
+	   || reg_nr == SPC_REGNUM)
+    return builtin_type (gdbarch)->builtin_func_ptr;
+  else if (reg_nr == R0_REGNUM + 15 || reg_nr == GBR_REGNUM)
+    return builtin_type (gdbarch)->builtin_data_ptr;
   else
     return builtin_type (gdbarch)->builtin_int;
 }
@@ -1434,6 +1444,11 @@ sh_sh4_register_type (struct gdbarch *gdbarch, int reg_nr)
     return builtin_type (gdbarch)->builtin_double;
   else if (reg_nr >= FV0_REGNUM && reg_nr <= FV_LAST_REGNUM)
     return sh_sh4_build_float_register_type (gdbarch, 3);
+  else if (reg_nr == PC_REGNUM || reg_nr == PR_REGNUM || reg_nr == VBR_REGNUM
+	   || reg_nr == SPC_REGNUM)
+    return builtin_type (gdbarch)->builtin_func_ptr;
+  else if (reg_nr == R0_REGNUM + 15 || reg_nr == GBR_REGNUM)
+    return builtin_type (gdbarch)->builtin_data_ptr;
   else
     return builtin_type (gdbarch)->builtin_int;
 }
@@ -1441,7 +1456,13 @@ sh_sh4_register_type (struct gdbarch *gdbarch, int reg_nr)
 static struct type *
 sh_default_register_type (struct gdbarch *gdbarch, int reg_nr)
 {
-  return builtin_type (gdbarch)->builtin_int;
+  if (reg_nr == PC_REGNUM || reg_nr == PR_REGNUM || reg_nr == VBR_REGNUM
+      || reg_nr == SPC_REGNUM)
+    return builtin_type (gdbarch)->builtin_func_ptr;
+  else if (reg_nr == R0_REGNUM + 15 || reg_nr == GBR_REGNUM)
+    return builtin_type (gdbarch)->builtin_data_ptr;
+  else
+    return builtin_type (gdbarch)->builtin_int;
 }
 
 /* Is a register in a reggroup?

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-26 13:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-26 13:56 [binutils-gdb] gdb: specify sh pointer register types Simon Marchi

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).