[01/24] gdb: don't handle i386 k registers as pseudo registers

Message ID 20231201162751.741751-2-simon.marchi@efficios.com
State New
Headers
Series Fix reading and writing pseudo registers in non-current frames |

Commit Message

Simon Marchi Dec. 1, 2023, 4:27 p.m. UTC
  I think that i386 k registers are raw registers, and therefore shouldn't
be handled in the various functions handling pseudo registers.

What tipped me off is the code in i386_pseudo_register_read_into_value:

      else if (i386_k_regnum_p (gdbarch, regnum))
	{
	  regnum -= tdep->k0_regnum;

	  /* Extract (always little endian).  */
	  status = regcache->raw_read (tdep->k0_regnum + regnum, raw_buf);

We take regnum (the pseudo register number we want to read), subtract
k0_regnum, add k0_regnum, and pass the result to raw_read.  So we would
end up calling raw_read with the same regnum as the function received
which is supposedly a pseudo register number.

Other hints are:

 - The command `maint print raw-registers` shows the k registers.
 - Printing $k0 doesn't cause i386_pseudo_register_read_into_value to be
   called.
 - There's code in i387-tdep.c to save/restore the k registers.

Remove handling of the k registers from:

 - i386_pseudo_register_read_into_value
 - i386_pseudo_register_write
 - i386_ax_pseudo_register_collect

Change-Id: Ic97956ed59af6099fef6d36a0b61464172694562
Reviewed-by: John Baldwin <jhb@FreeBSD.org>
---
 gdb/i386-tdep.c | 23 -----------------------
 1 file changed, 23 deletions(-)
  

Patch

diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index e00c3bd9d568..f356995520fe 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -3464,17 +3464,6 @@  i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 	      memcpy (buf + size, &upper, size);
 	    }
 	}
-      else if (i386_k_regnum_p (gdbarch, regnum))
-	{
-	  regnum -= tdep->k0_regnum;
-
-	  /* Extract (always little endian).  */
-	  status = regcache->raw_read (tdep->k0_regnum + regnum, raw_buf);
-	  if (status != REG_VALID)
-	    result_value->mark_bytes_unavailable (0, 8);
-	  else
-	    memcpy (buf, raw_buf, 8);
-	}
       else if (i386_zmm_regnum_p (gdbarch, regnum))
 	{
 	  regnum -= tdep->zmm0_regnum;
@@ -3656,12 +3645,6 @@  i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 
 	  regcache->raw_write (I387_BND0R_REGNUM (tdep) + regnum, raw_buf);
 	}
-      else if (i386_k_regnum_p (gdbarch, regnum))
-	{
-	  regnum -= tdep->k0_regnum;
-
-	  regcache->raw_write (tdep->k0_regnum + regnum, buf);
-	}
       else if (i386_zmm_regnum_p (gdbarch, regnum))
 	{
 	  regnum -= tdep->zmm0_regnum;
@@ -3758,12 +3741,6 @@  i386_ax_pseudo_register_collect (struct gdbarch *gdbarch,
       ax_reg_mask (ax, I387_BND0R_REGNUM (tdep) + regnum);
       return 0;
     }
-  else if (i386_k_regnum_p (gdbarch, regnum))
-    {
-      regnum -= tdep->k0_regnum;
-      ax_reg_mask (ax, tdep->k0_regnum + regnum);
-      return 0;
-    }
   else if (i386_zmm_regnum_p (gdbarch, regnum))
     {
       regnum -= tdep->zmm0_regnum;