Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pierre Marsais <pierre.marsais@lse.epita.fr>
To: gdb-patches@sourceware.org
Subject: [PATCH v4 2/3] Do not mistreat instructions as cmpxchg8b
Date: Sat, 06 Oct 2018 00:16:00 -0000	[thread overview]
Message-ID: <20181006001539.32414-2-pierre.marsais@lse.epita.fr> (raw)
In-Reply-To: <20181006001539.32414-1-pierre.marsais@lse.epita.fr>

All x86 instructions starting with opcode 0x0f7c where considered as
cmpxchg8b if ir.mod == 3, regardless of ir.reg. However, there are some
instructions (such as xsavec) sharing the same opcode, but with
different ir.reg.

This change throws an error when recording on unsupported instructions
instead of considering them as cmpxchg8b.

gdb/ChangeLog:

2018-10-05  Pierre Marsais <pierre.marsais@lse.epita.fr>

	* i386-tdep.c: (i386_process_record): Improve decoding of
	instructions starting with 0x0f7c.
---
 gdb/i386-tdep.c | 76 ++++++++++++++++++++++++++++---------------------
 1 file changed, 43 insertions(+), 33 deletions(-)

diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index a9fe290307..90c78e0bbc 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -5477,39 +5477,49 @@ i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
     case 0x0fc7:    /* cmpxchg8b / rdrand / rdseed */
       if (i386_record_modrm (&ir))
 	return -1;
-      if (ir.mod == 3)
-	{
-	  /* rdrand and rdseed use the 3 bits of the REG field of ModR/M as
-	     an extended opcode.  rdrand has bits 110 (/6) and rdseed
-	     has bits 111 (/7).  */
-	  if (ir.reg == 6 || ir.reg == 7)
-	    {
-	      /* The storage register is described by the 3 R/M bits, but the
-		 REX.B prefix may be used to give access to registers
-		 R8~R15.  In this case ir.rex_b + R/M will give us the register
-		 in the range R8~R15.
-
-		 REX.W may also be used to access 64-bit registers, but we
-		 already record entire registers and not just partial bits
-		 of them.  */
-	      I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rex_b + ir.rm);
-	      /* These instructions also set conditional bits.  */
-	      I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
-	      break;
-	    }
-	  else
-	    {
-	      /* We don't handle this particular instruction yet.  */
-	      ir.addr -= 2;
-	      opcode = opcode << 8 | ir.modrm;
-	      goto no_support;
-	    }
-	}
-      I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
-      I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
-      if (i386_record_lea_modrm (&ir))
-	return -1;
-      I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
+      switch (ir.reg) {
+        case 1: /* cmpxchg8b */
+          if (ir.mod == 3)
+            {
+              ir.addr -= 2;
+              opcode = opcode << 8 | ir.modrm;
+              goto no_support;
+            }
+          I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
+          I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
+          if (i386_record_lea_modrm (&ir))
+            return -1;
+          I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
+          break;
+        case 6: /* rdrand */
+        case 7: /* rdseed */
+          if (ir.mod != 3)
+            {
+              /* We don't handle this particular instruction yet.  */
+              ir.addr -= 2;
+              opcode = opcode << 8 | ir.modrm;
+              goto no_support;
+            }
+          /* rdrand and rdseed use the 3 bits of the REG field of ModR/M as
+             an extended opcode.  rdrand has bits 110 (/6) and rdseed
+             has bits 111 (/7).  */
+          /* The storage register is described by the 3 R/M bits, but the
+             REX.B prefix may be used to give access to registers
+             R8~R15.  In this case ir.rex_b + R/M will give us the register
+             in the range R8~R15.
+
+             REX.W may also be used to access 64-bit registers, but we
+             already record entire registers and not just partial bits
+             of them.  */
+          I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rex_b + ir.rm);
+          /* These instructions also set conditional bits.  */
+          I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
+          break;
+        default:
+          ir.addr -= 2;
+          opcode = opcode << 8 | ir.modrm;
+          goto no_support;
+      }
       break;
 
     case 0x50:    /* push */
-- 
2.19.0


  parent reply	other threads:[~2018-10-06  0:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-21  0:38 [PATCH] Add support for recording xsave x86 instruction Pierre Marsais
2018-09-27  8:45 ` Metzger, Markus T
2018-10-01  0:25   ` Pierre Marsais
2018-10-01  6:58     ` Metzger, Markus T
2018-10-03  0:05       ` Pierre Marsais
2018-10-01  0:29 ` [PATCH v2] " Pierre Marsais
2018-10-02 23:55 ` [PATCH v3] " Pierre Marsais
     [not found]   ` <CAMe9rOqTeGBckegskZLKxJJL-aexTiorLTEbL2kps_KjJs20Rg@mail.gmail.com>
2018-10-06  0:20     ` Pierre Marsais
2018-10-06  0:16 ` [PATCH v4 1/3] " Pierre Marsais
2018-10-06  0:16   ` [PATCH v4 3/3] Add support for recording xsavec " Pierre Marsais
2018-10-06  0:16   ` Pierre Marsais [this message]
2018-10-11 11:56     ` [PATCH v4 2/3] Do not mistreat instructions as cmpxchg8b Metzger, Markus T

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=20181006001539.32414-2-pierre.marsais@lse.epita.fr \
    --to=pierre.marsais@lse.epita.fr \
    --cc=gdb-patches@sourceware.org \
    /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