]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb tdesc: Handle mismatched pointer register types.
authorJohn Baldwin <jhb@FreeBSD.org>
Wed, 16 Nov 2022 01:35:09 +0000 (17:35 -0800)
committerJohn Baldwin <jhb@FreeBSD.org>
Wed, 16 Nov 2022 01:40:27 +0000 (17:40 -0800)
In the XML target descriptions, registers can be given a type of
"code_ptr" or "data_ptr".  GDB always uses the builtin type for "void
*" for these registers.  However, this is wrong if the register's size
does not match (e.g. the legacy "sp" and "pc" ARM64 registers when
using a purecap binary for which "void *" is a capability).  If the
sizes don't match, try to find a matching type such as "long" or
"intcap_t" to use instead.

gdb/target-descriptions.c

index 5b886f498728f909c7b62028eadf252bc810e843..a00300995b73a1d39e624802946fd059da047ac8 100644 (file)
@@ -945,7 +945,24 @@ tdesc_register_type (struct gdbarch *gdbarch, int regno)
     {
       /* First check for a predefined or target defined type.  */
       if (reg->tdesc_type)
-       arch_reg->type = make_gdb_type (gdbarch, reg->tdesc_type);
+       {
+         if ((reg->type == "code_ptr" || reg->type == "data_ptr")
+             && reg->bitsize != gdbarch_ptr_bit (gdbarch))
+           {
+             if (reg->bitsize == gdbarch_long_bit (gdbarch))
+               arch_reg->type = builtin_type (gdbarch)->builtin_long;
+             else if (reg->bitsize == gdbarch_capability_bit (gdbarch))
+               arch_reg->type = builtin_type (gdbarch)->builtin_data_capability;
+             else
+               {
+                 warning (_("Register \"%s\" has an unsupported size (%d bits)"),
+                          reg->name.c_str (), reg->bitsize);
+                 arch_reg->type = builtin_type (gdbarch)->builtin_data_ptr;
+               }
+           }
+         else
+           arch_reg->type = make_gdb_type (gdbarch, reg->tdesc_type);
+       }
 
       /* Next try size-sensitive type shortcuts.  */
       else if (reg->type == "float")