* remote-fileio.c (remote_fileio_func_rename): Use Cygwin 1.7
[deliverable/binutils-gdb.git] / gdb / i386-tdep.c
index c2515fe84cb62bd53876d8368ef2248a73a99496..83aa81fa9462f6e1c81911c24ede20b57fefa556 100644 (file)
@@ -1,8 +1,8 @@
 /* Intel 386 target-dependent stuff.
 
    Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
-   Free Software Foundation, Inc.
+   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
+   2010 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -43,6 +43,7 @@
 #include "target.h"
 #include "value.h"
 #include "dis-asm.h"
+#include "disasm.h"
 
 #include "gdb_assert.h"
 #include "gdb_string.h"
@@ -414,6 +415,8 @@ i386_displaced_step_fixup (struct gdbarch *gdbarch,
                            CORE_ADDR from, CORE_ADDR to,
                            struct regcache *regs)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
   /* The offset we applied to the instruction's address.
      This could well be negative (when viewed as a signed 32-bit
      value), but ULONGEST won't reflect that, so take care when
@@ -428,9 +431,10 @@ i386_displaced_step_fixup (struct gdbarch *gdbarch,
 
   if (debug_displaced)
     fprintf_unfiltered (gdb_stdlog,
-                        "displaced: fixup (0x%s, 0x%s), "
+                        "displaced: fixup (%s, %s), "
                         "insn = 0x%02x 0x%02x ...\n",
-                        paddr_nz (from), paddr_nz (to), insn[0], insn[1]);
+                        paddress (gdbarch, from), paddress (gdbarch, to),
+                       insn[0], insn[1]);
 
   /* The list of issues to contend with here is taken from
      resume_execution in arch/i386/kernel/kprobes.c, Linux 2.6.20.
@@ -499,8 +503,9 @@ i386_displaced_step_fixup (struct gdbarch *gdbarch,
           if (debug_displaced)
             fprintf_unfiltered (gdb_stdlog,
                                 "displaced: "
-                                "relocated %%eip from 0x%s to 0x%s\n",
-                                paddr_nz (orig_eip), paddr_nz (eip));
+                                "relocated %%eip from %s to %s\n",
+                                paddress (gdbarch, orig_eip),
+                               paddress (gdbarch, eip));
         }
     }
 
@@ -519,16 +524,15 @@ i386_displaced_step_fixup (struct gdbarch *gdbarch,
       const ULONGEST retaddr_len = 4;
 
       regcache_cooked_read_unsigned (regs, I386_ESP_REGNUM, &esp);
-      retaddr = read_memory_unsigned_integer (esp, retaddr_len);
+      retaddr = read_memory_unsigned_integer (esp, retaddr_len, byte_order);
       retaddr = (retaddr - insn_offset) & 0xffffffffUL;
-      write_memory_unsigned_integer (esp, retaddr_len, retaddr);
+      write_memory_unsigned_integer (esp, retaddr_len, byte_order, retaddr);
 
       if (debug_displaced)
         fprintf_unfiltered (gdb_stdlog,
-                            "displaced: relocated return addr at 0x%s "
-                            "to 0x%s\n",
-                            paddr_nz (esp),
-                            paddr_nz (retaddr));
+                            "displaced: relocated return addr at %s to %s\n",
+                            paddress (gdbarch, esp),
+                            paddress (gdbarch, retaddr));
     }
 }
 \f
@@ -594,8 +598,9 @@ i386_alloc_frame_cache (void)
    target.  Otherwise, return PC.  */
 
 static CORE_ADDR
-i386_follow_jump (CORE_ADDR pc)
+i386_follow_jump (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte op;
   long delta = 0;
   int data16 = 0;
@@ -604,7 +609,7 @@ i386_follow_jump (CORE_ADDR pc)
   if (op == 0x66)
     {
       data16 = 1;
-      op = read_memory_unsigned_integer (pc + 1, 1);
+      op = read_memory_unsigned_integer (pc + 1, 1, byte_order);
     }
 
   switch (op)
@@ -613,7 +618,7 @@ i386_follow_jump (CORE_ADDR pc)
       /* Relative jump: if data16 == 0, disp32, else disp16.  */
       if (data16)
        {
-         delta = read_memory_integer (pc + 2, 2);
+         delta = read_memory_integer (pc + 2, 2, byte_order);
 
          /* Include the size of the jmp instruction (including the
              0x66 prefix).  */
@@ -621,7 +626,7 @@ i386_follow_jump (CORE_ADDR pc)
        }
       else
        {
-         delta = read_memory_integer (pc + 1, 4);
+         delta = read_memory_integer (pc + 1, 4, byte_order);
 
          /* Include the size of the jmp instruction.  */
          delta += 5;
@@ -629,7 +634,7 @@ i386_follow_jump (CORE_ADDR pc)
       break;
     case 0xeb:
       /* Relative jump, disp8 (ignore data16).  */
-      delta = read_memory_integer (pc + data16 + 1, 1);
+      delta = read_memory_integer (pc + data16 + 1, 1, byte_order);
 
       delta += data16 + 2;
       break;
@@ -1005,9 +1010,11 @@ i386_skip_noop (CORE_ADDR pc)
    whichever is smaller.  If we don't recognize the code, return PC.  */
 
 static CORE_ADDR
-i386_analyze_frame_setup (CORE_ADDR pc, CORE_ADDR limit,
+i386_analyze_frame_setup (struct gdbarch *gdbarch,
+                         CORE_ADDR pc, CORE_ADDR limit,
                          struct i386_frame_cache *cache)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct i386_insn *insn;
   gdb_byte op;
   int skip = 0;
@@ -1056,11 +1063,13 @@ i386_analyze_frame_setup (CORE_ADDR pc, CORE_ADDR limit,
       switch (op)
        {
        case 0x8b:
-         if (read_memory_unsigned_integer (pc + skip + 1, 1) != 0xec)
+         if (read_memory_unsigned_integer (pc + skip + 1, 1, byte_order)
+             != 0xec)
            return pc;
          break;
        case 0x89:
-         if (read_memory_unsigned_integer (pc + skip + 1, 1) != 0xe5)
+         if (read_memory_unsigned_integer (pc + skip + 1, 1, byte_order)
+             != 0xe5)
            return pc;
          break;
        default:
@@ -1088,24 +1097,24 @@ i386_analyze_frame_setup (CORE_ADDR pc, CORE_ADDR limit,
       if (op == 0x83)
        {
          /* `subl' with 8-bit immediate.  */
-         if (read_memory_unsigned_integer (pc + 1, 1) != 0xec)
+         if (read_memory_unsigned_integer (pc + 1, 1, byte_order) != 0xec)
            /* Some instruction starting with 0x83 other than `subl'.  */
            return pc;
 
          /* `subl' with signed 8-bit immediate (though it wouldn't
             make sense to be negative).  */
-         cache->locals = read_memory_integer (pc + 2, 1);
+         cache->locals = read_memory_integer (pc + 2, 1, byte_order);
          return pc + 3;
        }
       else if (op == 0x81)
        {
          /* Maybe it is `subl' with a 32-bit immediate.  */
-         if (read_memory_unsigned_integer (pc + 1, 1) != 0xec)
+         if (read_memory_unsigned_integer (pc + 1, 1, byte_order) != 0xec)
            /* Some instruction starting with 0x81 other than `subl'.  */
            return pc;
 
          /* It is `subl' with a 32-bit immediate.  */
-         cache->locals = read_memory_integer (pc + 2, 4);
+         cache->locals = read_memory_integer (pc + 2, 4, byte_order);
          return pc + 6;
        }
       else
@@ -1116,7 +1125,7 @@ i386_analyze_frame_setup (CORE_ADDR pc, CORE_ADDR limit,
     }
   else if (op == 0xc8)         /* enter */
     {
-      cache->locals = read_memory_unsigned_integer (pc + 1, 2);
+      cache->locals = read_memory_unsigned_integer (pc + 1, 2, byte_order);
       return pc + 4;
     }
 
@@ -1181,15 +1190,16 @@ i386_analyze_register_saves (CORE_ADDR pc, CORE_ADDR current_pc,
    instruction will be a branch back to the start.  */
 
 static CORE_ADDR
-i386_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
+i386_analyze_prologue (struct gdbarch *gdbarch,
+                      CORE_ADDR pc, CORE_ADDR current_pc,
                       struct i386_frame_cache *cache)
 {
   pc = i386_skip_noop (pc);
-  pc = i386_follow_jump (pc);
+  pc = i386_follow_jump (gdbarch, pc);
   pc = i386_analyze_struct_return (pc, current_pc, cache);
   pc = i386_skip_probe (pc);
   pc = i386_analyze_stack_align (pc, current_pc, cache);
-  pc = i386_analyze_frame_setup (pc, current_pc, cache);
+  pc = i386_analyze_frame_setup (gdbarch, pc, current_pc, cache);
   return i386_analyze_register_saves (pc, current_pc, cache);
 }
 
@@ -1198,6 +1208,8 @@ i386_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
 static CORE_ADDR
 i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
   static gdb_byte pic_pat[6] =
   {
     0xe8, 0, 0, 0, 0,          /* call 0x0 */
@@ -1209,7 +1221,7 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
   int i;
 
   cache.locals = -1;
-  pc = i386_analyze_prologue (start_pc, 0xffffffff, &cache);
+  pc = i386_analyze_prologue (gdbarch, start_pc, 0xffffffff, &cache);
   if (cache.locals < 0)
     return start_pc;
 
@@ -1242,7 +1254,7 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 
       if (op == 0x89)          /* movl %ebx, x(%ebp) */
        {
-         op = read_memory_unsigned_integer (pc + delta + 1, 1);
+         op = read_memory_unsigned_integer (pc + delta + 1, 1, byte_order);
 
          if (op == 0x5d)       /* One byte offset from %ebp.  */
            delta += 3;
@@ -1256,7 +1268,8 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 
       /* addl y,%ebx */
       if (delta > 0 && op == 0x81
-         && read_memory_unsigned_integer (pc + delta + 1, 1) == 0xc3)
+         && read_memory_unsigned_integer (pc + delta + 1, 1, byte_order)
+            == 0xc3)
        {
          pc += delta + 6;
        }
@@ -1265,8 +1278,8 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
   /* If the function starts with a branch (to startup code at the end)
      the last instruction should bring us back to the first
      instruction of the real code.  */
-  if (i386_follow_jump (start_pc) != start_pc)
-    pc = i386_follow_jump (pc);
+  if (i386_follow_jump (gdbarch, start_pc) != start_pc)
+    pc = i386_follow_jump (gdbarch, pc);
 
   return pc;
 }
@@ -1277,6 +1290,7 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 CORE_ADDR
 i386_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte op;
 
   target_read_memory (pc, &op, 1);
@@ -1289,8 +1303,9 @@ i386_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
          /* Make sure address is computed correctly as a 32bit
             integer even if CORE_ADDR is 64 bit wide.  */
          struct minimal_symbol *s;
-         CORE_ADDR call_dest = pc + 5 + extract_signed_integer (buf, 4);
+         CORE_ADDR call_dest;
 
+         call_dest = pc + 5 + extract_signed_integer (buf, 4, byte_order);
          call_dest = call_dest & 0xffffffffU;
          s = lookup_minimal_symbol_by_pc (call_dest);
          if (s != NULL
@@ -1320,6 +1335,8 @@ i386_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
 static struct i386_frame_cache *
 i386_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
+  struct gdbarch *gdbarch = get_frame_arch (this_frame);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct i386_frame_cache *cache;
   gdb_byte buf[4];
   int i;
@@ -1340,7 +1357,7 @@ i386_frame_cache (struct frame_info *this_frame, void **this_cache)
      in progress when the signal occurred.  */
 
   get_frame_register (this_frame, I386_EBP_REGNUM, buf);
-  cache->base = extract_unsigned_integer (buf, 4);
+  cache->base = extract_unsigned_integer (buf, 4, byte_order);
   if (cache->base == 0)
     return cache;
 
@@ -1349,13 +1366,14 @@ i386_frame_cache (struct frame_info *this_frame, void **this_cache)
 
   cache->pc = get_frame_func (this_frame);
   if (cache->pc != 0)
-    i386_analyze_prologue (cache->pc, get_frame_pc (this_frame), cache);
+    i386_analyze_prologue (gdbarch, cache->pc, get_frame_pc (this_frame),
+                          cache);
 
   if (cache->saved_sp_reg != -1)
     {
       /* Saved stack pointer has been saved.  */
       get_frame_register (this_frame, cache->saved_sp_reg, buf);
-      cache->saved_sp = extract_unsigned_integer(buf, 4);
+      cache->saved_sp = extract_unsigned_integer (buf, 4, byte_order);
     }
 
   if (cache->locals < 0)
@@ -1377,11 +1395,24 @@ i386_frame_cache (struct frame_info *this_frame, void **this_cache)
          /* This will be added back below.  */
          cache->saved_regs[I386_EIP_REGNUM] -= cache->base;
        }
-      else
+      else if (cache->pc != 0
+              || target_read_memory (get_frame_pc (this_frame), buf, 1))
        {
+         /* We're in a known function, but did not find a frame
+            setup.  Assume that the function does not use %ebp.
+            Alternatively, we may have jumped to an invalid
+            address; in that case there is definitely no new
+            frame in %ebp.  */
          get_frame_register (this_frame, I386_ESP_REGNUM, buf);
-         cache->base = extract_unsigned_integer (buf, 4) + cache->sp_offset;
+         cache->base = extract_unsigned_integer (buf, 4, byte_order)
+                       + cache->sp_offset;
        }
+      else
+       /* We're in an unknown function.  We could not find the start
+          of the function to analyze the prologue; our best option is
+          to assume a typical frame layout with the caller's %ebp
+          saved.  */
+       cache->saved_regs[I386_EBP_REGNUM] = 0;
     }
 
   /* Now that we have the base address for the stack frame we can
@@ -1469,6 +1500,89 @@ static const struct frame_unwind i386_frame_unwind =
   NULL,
   default_frame_sniffer
 };
+
+/* Normal frames, but in a function epilogue.  */
+
+/* The epilogue is defined here as the 'ret' instruction, which will
+   follow any instruction such as 'leave' or 'pop %ebp' that destroys
+   the function's stack frame.  */
+
+static int
+i386_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
+{
+  gdb_byte insn;
+
+  if (target_read_memory (pc, &insn, 1))
+    return 0;  /* Can't read memory at pc.  */
+
+  if (insn != 0xc3)    /* 'ret' instruction.  */
+    return 0;
+
+  return 1;
+}
+
+static int
+i386_epilogue_frame_sniffer (const struct frame_unwind *self,
+                            struct frame_info *this_frame,
+                            void **this_prologue_cache)
+{
+  if (frame_relative_level (this_frame) == 0)
+    return i386_in_function_epilogue_p (get_frame_arch (this_frame),
+                                       get_frame_pc (this_frame));
+  else
+    return 0;
+}
+
+static struct i386_frame_cache *
+i386_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
+{
+  struct gdbarch *gdbarch = get_frame_arch (this_frame);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+  struct i386_frame_cache *cache;
+  gdb_byte buf[4];
+
+  if (*this_cache)
+    return *this_cache;
+
+  cache = i386_alloc_frame_cache ();
+  *this_cache = cache;
+
+  /* Cache base will be %esp plus cache->sp_offset (-4).  */
+  get_frame_register (this_frame, I386_ESP_REGNUM, buf);
+  cache->base = extract_unsigned_integer (buf, 4, 
+                                         byte_order) + cache->sp_offset;
+
+  /* Cache pc will be the frame func.  */
+  cache->pc = get_frame_pc (this_frame);
+
+  /* The saved %esp will be at cache->base plus 8.  */
+  cache->saved_sp = cache->base + 8;
+
+  /* The saved %eip will be at cache->base plus 4.  */
+  cache->saved_regs[I386_EIP_REGNUM] = cache->base + 4;
+
+  return cache;
+}
+
+static void
+i386_epilogue_frame_this_id (struct frame_info *this_frame,
+                            void **this_cache,
+                            struct frame_id *this_id)
+{
+  struct i386_frame_cache *cache = i386_epilogue_frame_cache (this_frame,
+                                                             this_cache);
+
+  (*this_id) = frame_id_build (cache->base + 8, cache->pc);
+}
+
+static const struct frame_unwind i386_epilogue_frame_unwind =
+{
+  NORMAL_FRAME,
+  i386_epilogue_frame_this_id,
+  i386_frame_prev_register,
+  NULL, 
+  i386_epilogue_frame_sniffer
+};
 \f
 
 /* Signal trampolines.  */
@@ -1476,8 +1590,10 @@ static const struct frame_unwind i386_frame_unwind =
 static struct i386_frame_cache *
 i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
+  struct gdbarch *gdbarch = get_frame_arch (this_frame);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct i386_frame_cache *cache;
-  struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (this_frame));
   CORE_ADDR addr;
   gdb_byte buf[4];
 
@@ -1487,7 +1603,7 @@ i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
   cache = i386_alloc_frame_cache ();
 
   get_frame_register (this_frame, I386_ESP_REGNUM, buf);
-  cache->base = extract_unsigned_integer (buf, 4) - 4;
+  cache->base = extract_unsigned_integer (buf, 4, byte_order) - 4;
 
   addr = tdep->sigcontext_addr (this_frame);
   if (tdep->sc_reg_offset)
@@ -1611,6 +1727,7 @@ i386_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   gdb_byte buf[4];
   CORE_ADDR sp, jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int jb_pc_offset = gdbarch_tdep (gdbarch)->jb_pc_offset;
 
   /* If JB_PC_OFFSET is -1, we have no way to find out where the
@@ -1619,15 +1736,15 @@ i386_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
     return 0;
 
   get_frame_register (frame, I386_ESP_REGNUM, buf);
-  sp = extract_unsigned_integer (buf, 4);
+  sp = extract_unsigned_integer (buf, 4, byte_order);
   if (target_read_memory (sp + 4, buf, 4))
     return 0;
 
-  jb_addr = extract_unsigned_integer (buf, 4);
+  jb_addr = extract_unsigned_integer (buf, 4, byte_order);
   if (target_read_memory (jb_addr + jb_pc_offset, buf, 4))
     return 0;
 
-  *pc = extract_unsigned_integer (buf, 4);
+  *pc = extract_unsigned_integer (buf, 4, byte_order);
   return 1;
 }
 \f
@@ -1666,6 +1783,7 @@ i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
                      struct value **args, CORE_ADDR sp, int struct_return,
                      CORE_ADDR struct_addr)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[4];
   int i;
   int write_pass;
@@ -1685,7 +1803,7 @@ i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
          if (write_pass)
            {
              /* Push value address.  */
-             store_unsigned_integer (buf, 4, struct_addr);
+             store_unsigned_integer (buf, 4, byte_order, struct_addr);
              write_memory (sp, buf, 4);
              args_space_used += 4;
            }
@@ -1734,11 +1852,11 @@ i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 
   /* Store return address.  */
   sp -= 4;
-  store_unsigned_integer (buf, 4, bp_addr);
+  store_unsigned_integer (buf, 4, byte_order, bp_addr);
   write_memory (sp, buf, 4);
 
   /* Finally, update the stack pointer...  */
-  store_unsigned_integer (buf, 4, sp);
+  store_unsigned_integer (buf, 4, byte_order, sp);
   regcache_cooked_write (regcache, I386_ESP_REGNUM, buf);
 
   /* ...and fake a frame pointer.  */
@@ -1787,7 +1905,7 @@ i386_extract_return_value (struct gdbarch *gdbarch, struct type *type,
         exactly how it would happen on the target itself, but it is
         the best we can do.  */
       regcache_raw_read (regcache, I386_ST0_REGNUM, buf);
-      convert_typed_floating (buf, builtin_type_i387_ext, valbuf, type);
+      convert_typed_floating (buf, i387_ext_type (gdbarch), valbuf, type);
     }
   else
     {
@@ -1841,7 +1959,7 @@ i386_store_return_value (struct gdbarch *gdbarch, struct type *type,
         floating-point format used by the FPU.  This is probably
         not exactly how it would happen on the target itself, but
         it is the best we can do.  */
-      convert_typed_floating (valbuf, type, buf, builtin_type_i387_ext);
+      convert_typed_floating (valbuf, type, buf, i387_ext_type (gdbarch));
       regcache_raw_write (regcache, I386_ST0_REGNUM, buf);
 
       /* Set the top of the floating-point register stack to 7.  The
@@ -1994,54 +2112,83 @@ i386_return_value (struct gdbarch *gdbarch, struct type *func_type,
 }
 \f
 
-/* Type for %eflags.  */
-struct type *i386_eflags_type;
+/* Construct types for ISA-specific registers.  */
+struct type *
+i386_eflags_type (struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-/* Type for %mxcsr.  */
-struct type *i386_mxcsr_type;
+  if (!tdep->i386_eflags_type)
+    {
+      struct type *type;
+
+      type = arch_flags_type (gdbarch, "builtin_type_i386_eflags", 4);
+      append_flags_type_flag (type, 0, "CF");
+      append_flags_type_flag (type, 1, NULL);
+      append_flags_type_flag (type, 2, "PF");
+      append_flags_type_flag (type, 4, "AF");
+      append_flags_type_flag (type, 6, "ZF");
+      append_flags_type_flag (type, 7, "SF");
+      append_flags_type_flag (type, 8, "TF");
+      append_flags_type_flag (type, 9, "IF");
+      append_flags_type_flag (type, 10, "DF");
+      append_flags_type_flag (type, 11, "OF");
+      append_flags_type_flag (type, 14, "NT");
+      append_flags_type_flag (type, 16, "RF");
+      append_flags_type_flag (type, 17, "VM");
+      append_flags_type_flag (type, 18, "AC");
+      append_flags_type_flag (type, 19, "VIF");
+      append_flags_type_flag (type, 20, "VIP");
+      append_flags_type_flag (type, 21, "ID");
+
+      tdep->i386_eflags_type = type;
+    }
 
-/* Construct types for ISA-specific registers.  */
-static void
-i386_init_types (void)
+  return tdep->i386_eflags_type;
+}
+
+struct type *
+i386_mxcsr_type (struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  if (!tdep->i386_mxcsr_type)
+    {
+      struct type *type;
+
+      type = arch_flags_type (gdbarch, "builtin_type_i386_mxcsr", 4);
+      append_flags_type_flag (type, 0, "IE");
+      append_flags_type_flag (type, 1, "DE");
+      append_flags_type_flag (type, 2, "ZE");
+      append_flags_type_flag (type, 3, "OE");
+      append_flags_type_flag (type, 4, "UE");
+      append_flags_type_flag (type, 5, "PE");
+      append_flags_type_flag (type, 6, "DAZ");
+      append_flags_type_flag (type, 7, "IM");
+      append_flags_type_flag (type, 8, "DM");
+      append_flags_type_flag (type, 9, "ZM");
+      append_flags_type_flag (type, 10, "OM");
+      append_flags_type_flag (type, 11, "UM");
+      append_flags_type_flag (type, 12, "PM");
+      append_flags_type_flag (type, 15, "FZ");
+
+      tdep->i386_mxcsr_type = type;
+    }
+
+  return tdep->i386_mxcsr_type;
+}
+
+struct type *
+i387_ext_type (struct gdbarch *gdbarch)
 {
-  struct type *type;
-
-  type = init_flags_type ("builtin_type_i386_eflags", 4);
-  append_flags_type_flag (type, 0, "CF");
-  append_flags_type_flag (type, 1, NULL);
-  append_flags_type_flag (type, 2, "PF");
-  append_flags_type_flag (type, 4, "AF");
-  append_flags_type_flag (type, 6, "ZF");
-  append_flags_type_flag (type, 7, "SF");
-  append_flags_type_flag (type, 8, "TF");
-  append_flags_type_flag (type, 9, "IF");
-  append_flags_type_flag (type, 10, "DF");
-  append_flags_type_flag (type, 11, "OF");
-  append_flags_type_flag (type, 14, "NT");
-  append_flags_type_flag (type, 16, "RF");
-  append_flags_type_flag (type, 17, "VM");
-  append_flags_type_flag (type, 18, "AC");
-  append_flags_type_flag (type, 19, "VIF");
-  append_flags_type_flag (type, 20, "VIP");
-  append_flags_type_flag (type, 21, "ID");
-  i386_eflags_type = type;
-
-  type = init_flags_type ("builtin_type_i386_mxcsr", 4);
-  append_flags_type_flag (type, 0, "IE");
-  append_flags_type_flag (type, 1, "DE");
-  append_flags_type_flag (type, 2, "ZE");
-  append_flags_type_flag (type, 3, "OE");
-  append_flags_type_flag (type, 4, "UE");
-  append_flags_type_flag (type, 5, "PE");
-  append_flags_type_flag (type, 6, "DAZ");
-  append_flags_type_flag (type, 7, "IM");
-  append_flags_type_flag (type, 8, "DM");
-  append_flags_type_flag (type, 9, "ZM");
-  append_flags_type_flag (type, 10, "OM");
-  append_flags_type_flag (type, 11, "UM");
-  append_flags_type_flag (type, 12, "PM");
-  append_flags_type_flag (type, 15, "FZ");
-  i386_mxcsr_type = type;
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  if (!tdep->i387_ext_type)
+    tdep->i387_ext_type
+      = arch_float_type (gdbarch, -1, "builtin_type_i387_ext",
+                        floatformats_i387_ext);
+
+  return tdep->i387_ext_type;
 }
 
 /* Construct vector type for MMX registers.  */
@@ -2052,6 +2199,8 @@ i386_mmx_type (struct gdbarch *gdbarch)
 
   if (!tdep->i386_mmx_type)
     {
+      const struct builtin_type *bt = builtin_type (gdbarch);
+
       /* The type we're building is this: */
 #if 0
       union __gdb_builtin_type_vec64i
@@ -2065,14 +2214,16 @@ i386_mmx_type (struct gdbarch *gdbarch)
 
       struct type *t;
 
-      t = init_composite_type ("__gdb_builtin_type_vec64i", TYPE_CODE_UNION);
-      append_composite_type_field (t, "uint64", builtin_type_int64);
+      t = arch_composite_type (gdbarch,
+                              "__gdb_builtin_type_vec64i", TYPE_CODE_UNION);
+
+      append_composite_type_field (t, "uint64", bt->builtin_int64);
       append_composite_type_field (t, "v2_int32",
-                                  init_vector_type (builtin_type_int32, 2));
+                                  init_vector_type (bt->builtin_int32, 2));
       append_composite_type_field (t, "v4_int16",
-                                  init_vector_type (builtin_type_int16, 4));
+                                  init_vector_type (bt->builtin_int16, 4));
       append_composite_type_field (t, "v8_int8",
-                                  init_vector_type (builtin_type_int8, 8));
+                                  init_vector_type (bt->builtin_int8, 8));
 
       TYPE_VECTOR (t) = 1;
       TYPE_NAME (t) = "builtin_type_vec64i";
@@ -2089,6 +2240,8 @@ i386_sse_type (struct gdbarch *gdbarch)
 
   if (!tdep->i386_sse_type)
     {
+      const struct builtin_type *bt = builtin_type (gdbarch);
+
       /* The type we're building is this: */
 #if 0
       union __gdb_builtin_type_vec128i
@@ -2105,22 +2258,21 @@ i386_sse_type (struct gdbarch *gdbarch)
 
       struct type *t;
 
-      t = init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION);
+      t = arch_composite_type (gdbarch,
+                              "__gdb_builtin_type_vec128i", TYPE_CODE_UNION);
       append_composite_type_field (t, "v4_float",
-                                  init_vector_type (builtin_type (gdbarch)
-                                                    ->builtin_float, 4));
+                                  init_vector_type (bt->builtin_float, 4));
       append_composite_type_field (t, "v2_double",
-                                  init_vector_type (builtin_type (gdbarch)
-                                                    ->builtin_double, 2));
+                                  init_vector_type (bt->builtin_double, 2));
       append_composite_type_field (t, "v16_int8",
-                                  init_vector_type (builtin_type_int8, 16));
+                                  init_vector_type (bt->builtin_int8, 16));
       append_composite_type_field (t, "v8_int16",
-                                  init_vector_type (builtin_type_int16, 8));
+                                  init_vector_type (bt->builtin_int16, 8));
       append_composite_type_field (t, "v4_int32",
-                                  init_vector_type (builtin_type_int32, 4));
+                                  init_vector_type (bt->builtin_int32, 4));
       append_composite_type_field (t, "v2_int64",
-                                  init_vector_type (builtin_type_int64, 2));
-      append_composite_type_field (t, "uint128", builtin_type_int128);
+                                  init_vector_type (bt->builtin_int64, 2));
+      append_composite_type_field (t, "uint128", bt->builtin_int128);
 
       TYPE_VECTOR (t) = 1;
       TYPE_NAME (t) = "builtin_type_vec128i";
@@ -2141,13 +2293,13 @@ i386_register_type (struct gdbarch *gdbarch, int regnum)
     return builtin_type (gdbarch)->builtin_func_ptr;
 
   if (regnum == I386_EFLAGS_REGNUM)
-    return i386_eflags_type;
+    return i386_eflags_type (gdbarch);
 
   if (regnum == I386_EBP_REGNUM || regnum == I386_ESP_REGNUM)
     return builtin_type (gdbarch)->builtin_data_ptr;
 
   if (i386_fp_regnum_p (gdbarch, regnum))
-    return builtin_type_i387_ext;
+    return i387_ext_type (gdbarch);
 
   if (i386_mmx_regnum_p (gdbarch, regnum))
     return i386_mmx_type (gdbarch);
@@ -2156,7 +2308,7 @@ i386_register_type (struct gdbarch *gdbarch, int regnum)
     return i386_sse_type (gdbarch);
 
   if (regnum == I387_MXCSR_REGNUM (gdbarch_tdep (gdbarch)))
-    return i386_mxcsr_type;
+    return i386_mxcsr_type (gdbarch);
 
   return builtin_type (gdbarch)->builtin_int;
 }
@@ -2465,11 +2617,17 @@ i386_regset_from_core_section (struct gdbarch *gdbarch,
 /* Stuff for WIN32 PE style DLL's but is pretty generic really.  */
 
 CORE_ADDR
-i386_pe_skip_trampoline_code (CORE_ADDR pc, char *name)
+i386_pe_skip_trampoline_code (struct frame_info *frame,
+                             CORE_ADDR pc, char *name)
 {
-  if (pc && read_memory_unsigned_integer (pc, 2) == 0x25ff) /* jmp *(dest) */
+  struct gdbarch *gdbarch = get_frame_arch (frame);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
+  /* jmp *(dest) */
+  if (pc && read_memory_unsigned_integer (pc, 2, byte_order) == 0x25ff)
     {
-      unsigned long indirect = read_memory_unsigned_integer (pc + 2, 4);
+      unsigned long indirect =
+       read_memory_unsigned_integer (pc + 2, 4, byte_order);
       struct minimal_symbol *indsym =
        indirect ? lookup_minimal_symbol_by_pc (indirect) : 0;
       char *symname = indsym ? SYMBOL_LINKAGE_NAME (indsym) : 0;
@@ -2478,7 +2636,8 @@ i386_pe_skip_trampoline_code (CORE_ADDR pc, char *name)
        {
          if (strncmp (symname, "__imp_", 6) == 0
              || strncmp (symname, "_imp_", 5) == 0)
-           return name ? 1 : read_memory_unsigned_integer (indirect, 4);
+           return name ? 1 :
+                  read_memory_unsigned_integer (indirect, 4, byte_order);
        }
     }
   return 0;                    /* Not a trampoline.  */
@@ -2546,13 +2705,15 @@ i386_svr4_sigtramp_p (struct frame_info *this_frame)
 static CORE_ADDR
 i386_svr4_sigcontext_addr (struct frame_info *this_frame)
 {
+  struct gdbarch *gdbarch = get_frame_arch (this_frame);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[4];
   CORE_ADDR sp;
 
   get_frame_register (this_frame, I386_ESP_REGNUM, buf);
-  sp = extract_unsigned_integer (buf, 4);
+  sp = extract_unsigned_integer (buf, 4, byte_order);
 
-  return read_memory_unsigned_integer (sp + 8, 4);
+  return read_memory_unsigned_integer (sp + 8, 4, byte_order);
 }
 \f
 
@@ -2601,6 +2762,13 @@ i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   /* DJGPP does not support the SSE registers.  */
   tdep->num_xmm_regs = 0;
   set_gdbarch_num_regs (gdbarch, I386_NUM_GREGS + I386_NUM_FREGS);
+
+  /* Native compiler is GCC, which uses the SVR4 register numbering
+     even in COFF and STABS.  See the comment in i386_gdbarch_init,
+     before the calls to set_gdbarch_stab_reg_to_regnum and
+     set_gdbarch_sdb_reg_to_regnum.  */
+  set_gdbarch_stab_reg_to_regnum (gdbarch, i386_svr4_reg_to_regnum);
+  set_gdbarch_sdb_reg_to_regnum (gdbarch, i386_svr4_reg_to_regnum);
 }
 \f
 
@@ -2662,8 +2830,10 @@ static CORE_ADDR
 i386_fetch_pointer_argument (struct frame_info *frame, int argi, 
                             struct type *type)
 {
+  struct gdbarch *gdbarch = get_frame_arch (frame);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR sp = get_frame_register_unsigned  (frame, I386_ESP_REGNUM);
-  return read_memory_unsigned_integer (sp + (4 * (argi + 1)), 4);
+  return read_memory_unsigned_integer (sp + (4 * (argi + 1)), 4, byte_order);
 }
 
 static void
@@ -2690,6 +2860,7 @@ enum
   OT_BYTE = 0,
   OT_WORD,
   OT_LONG,
+  OT_QUAD,
 };
 
 /* i386 arith/logic operations */
@@ -2707,7 +2878,9 @@ enum
 
 struct i386_record_s
 {
+  struct gdbarch *gdbarch;
   struct regcache *regcache;
+  CORE_ADDR orig_addr;
   CORE_ADDR addr;
   int aflag;
   int dflag;
@@ -2715,6 +2888,11 @@ struct i386_record_s
   uint8_t modrm;
   uint8_t mod, reg, rm;
   int ot;
+  uint8_t rex_x;
+  uint8_t rex_b;
+  int rip_offset;
+  int popl_esp_hack;
+  const int *regmap;
 };
 
 /* Parse "modrm" part in current memory address that irp->addr point to
@@ -2723,12 +2901,14 @@ struct i386_record_s
 static int
 i386_record_modrm (struct i386_record_s *irp)
 {
+  struct gdbarch *gdbarch = irp->gdbarch;
+
   if (target_read_memory (irp->addr, &irp->modrm, 1))
     {
       if (record_debug)
        printf_unfiltered (_("Process record: error reading memory at "
-                            "addr 0x%s len = 1.\n"),
-                          paddr_nz (irp->addr));
+                            "addr %s len = 1.\n"),
+                          paddress (gdbarch, irp->addr));
       return -1;
     }
   irp->addr++;
@@ -2744,11 +2924,13 @@ i386_record_modrm (struct i386_record_s *irp)
    Return -1 if something wrong. */
 
 static int
-i386_record_lea_modrm_addr (struct i386_record_s *irp, uint32_t * addr)
+i386_record_lea_modrm_addr (struct i386_record_s *irp, uint64_t *addr)
 {
+  struct gdbarch *gdbarch = irp->gdbarch;
   uint8_t tmpu8;
-  uint16_t tmpu16;
-  uint32_t tmpu32;
+  int16_t tmpi16;
+  int32_t tmpi32;
+  ULONGEST tmpulongest;
 
   *addr = 0;
   if (irp->aflag)
@@ -2766,15 +2948,16 @@ i386_record_lea_modrm_addr (struct i386_record_s *irp, uint32_t * addr)
            {
              if (record_debug)
                printf_unfiltered (_("Process record: error reading memory "
-                                    "at addr 0x%s len = 1.\n"),
-                                  paddr_nz (irp->addr));
+                                    "at addr %s len = 1.\n"),
+                                  paddress (gdbarch, irp->addr));
              return -1;
            }
          irp->addr++;
          scale = (tmpu8 >> 6) & 3;
-         index = ((tmpu8 >> 3) & 7);
+         index = ((tmpu8 >> 3) & 7) | irp->rex_x;
          base = (tmpu8 & 7);
        }
+      base |= irp->rex_b;
 
       switch (irp->mod)
        {
@@ -2782,15 +2965,18 @@ i386_record_lea_modrm_addr (struct i386_record_s *irp, uint32_t * addr)
          if ((base & 7) == 5)
            {
              base = 0xff;
-             if (target_read_memory (irp->addr, (gdb_byte *) addr, 4))
+             if (target_read_memory (irp->addr, (gdb_byte *) &tmpi32, 4))
                {
                  if (record_debug)
                    printf_unfiltered (_("Process record: error reading "
-                                        "memory at addr 0x%s len = 4.\n"),
-                                      paddr_nz (irp->addr));
+                                        "memory at addr %s len = 4.\n"),
+                                      paddress (gdbarch, irp->addr));
                  return -1;
                }
              irp->addr += 4;
+             *addr = tmpi32;
+             if (irp->regmap[X86_RECORD_R8_REGNUM] && !havesib)
+               *addr += irp->addr + irp->rip_offset;
            }
          else
            {
@@ -2802,37 +2988,50 @@ i386_record_lea_modrm_addr (struct i386_record_s *irp, uint32_t * addr)
            {
              if (record_debug)
                printf_unfiltered (_("Process record: error reading memory "
-                                    "at addr 0x%s len = 1.\n"),
-                                  paddr_nz (irp->addr));
+                                    "at addr %s len = 1.\n"),
+                                  paddress (gdbarch, irp->addr));
              return -1;
            }
          irp->addr++;
          *addr = (int8_t) tmpu8;
          break;
        case 2:
-         if (target_read_memory (irp->addr, (gdb_byte *) addr, 4))
+         if (target_read_memory (irp->addr, (gdb_byte *) &tmpi32, 4))
            {
              if (record_debug)
                printf_unfiltered (_("Process record: error reading memory "
-                                    "at addr 0x%s len = 4.\n"),
-                                  paddr_nz (irp->addr));
+                                    "at addr %s len = 4.\n"),
+                                  paddress (gdbarch, irp->addr));
              return -1;
            }
+         *addr = tmpi32;
          irp->addr += 4;
          break;
        }
 
+      tmpulongest = 0;
       if (base != 0xff)
-       {
-         regcache_raw_read (irp->regcache, base, (gdb_byte *) & tmpu32);
-         *addr += tmpu32;
+        {
+         if (base == 4 && irp->popl_esp_hack)
+           *addr += irp->popl_esp_hack;
+         regcache_raw_read_unsigned (irp->regcache, irp->regmap[base],
+                                      &tmpulongest);
        }
+      if (irp->aflag == 2)
+        {
+         *addr += tmpulongest;
+        }
+      else
+        *addr = (uint32_t) (tmpulongest + *addr);
 
-      /* XXX: index == 4 is always invalid */
       if (havesib && (index != 4 || scale != 0))
        {
-         regcache_raw_read (irp->regcache, index, (gdb_byte *) & tmpu32);
-         *addr += tmpu32 << scale;
+         regcache_raw_read_unsigned (irp->regcache, irp->regmap[index],
+                                      &tmpulongest);
+         if (irp->aflag == 2)
+           *addr += tmpulongest << scale;
+         else
+           *addr = (uint32_t) (*addr + (tmpulongest << scale));
        }
     }
   else
@@ -2844,16 +3043,16 @@ i386_record_lea_modrm_addr (struct i386_record_s *irp, uint32_t * addr)
          if (irp->rm == 6)
            {
              if (target_read_memory
-                 (irp->addr, (gdb_byte *) & tmpu16, 2))
+                 (irp->addr, (gdb_byte *) &tmpi16, 2))
                {
                  if (record_debug)
                    printf_unfiltered (_("Process record: error reading "
-                                        "memory at addr 0x%s len = 2.\n"),
-                                      paddr_nz (irp->addr));
+                                        "memory at addr %s len = 2.\n"),
+                                      paddress (gdbarch, irp->addr));
                  return -1;
                }
              irp->addr += 2;
-             *addr = (int16_t) tmpu16;
+             *addr = tmpi16;
              irp->rm = 0;
              goto no_rm;
            }
@@ -2867,86 +3066,98 @@ i386_record_lea_modrm_addr (struct i386_record_s *irp, uint32_t * addr)
            {
              if (record_debug)
                printf_unfiltered (_("Process record: error reading memory "
-                                    "at addr 0x%s len = 1.\n"),
-                                  paddr_nz (irp->addr));
+                                    "at addr %s len = 1.\n"),
+                                  paddress (gdbarch, irp->addr));
              return -1;
            }
          irp->addr++;
          *addr = (int8_t) tmpu8;
          break;
        case 2:
-         if (target_read_memory (irp->addr, (gdb_byte *) & tmpu16, 2))
+         if (target_read_memory (irp->addr, (gdb_byte *) &tmpi16, 2))
            {
              if (record_debug)
                printf_unfiltered (_("Process record: error reading memory "
-                                    "at addr 0x%s len = 2.\n"),
-                                  paddr_nz (irp->addr));
+                                    "at addr %s len = 2.\n"),
+                                  paddress (gdbarch, irp->addr));
              return -1;
            }
          irp->addr += 2;
-         *addr = (int16_t) tmpu16;
+         *addr = tmpi16;
          break;
        }
 
       switch (irp->rm)
        {
        case 0:
-         regcache_raw_read (irp->regcache, I386_EBX_REGNUM,
-                            (gdb_byte *) & tmpu32);
-         *addr += tmpu32;
-         regcache_raw_read (irp->regcache, I386_ESI_REGNUM,
-                            (gdb_byte *) & tmpu32);
-         *addr += tmpu32;
+         regcache_raw_read_unsigned (irp->regcache,
+                                     irp->regmap[X86_RECORD_REBX_REGNUM],
+                                      &tmpulongest);
+         *addr = (uint32_t) (*addr + tmpulongest);
+         regcache_raw_read_unsigned (irp->regcache,
+                                     irp->regmap[X86_RECORD_RESI_REGNUM],
+                                      &tmpulongest);
+         *addr = (uint32_t) (*addr + tmpulongest);
          break;
        case 1:
-         regcache_raw_read (irp->regcache, I386_EBX_REGNUM,
-                            (gdb_byte *) & tmpu32);
-         *addr += tmpu32;
-         regcache_raw_read (irp->regcache, I386_EDI_REGNUM,
-                            (gdb_byte *) & tmpu32);
-         *addr += tmpu32;
+         regcache_raw_read_unsigned (irp->regcache,
+                                     irp->regmap[X86_RECORD_REBX_REGNUM],
+                                      &tmpulongest);
+         *addr = (uint32_t) (*addr + tmpulongest);
+         regcache_raw_read_unsigned (irp->regcache,
+                                     irp->regmap[X86_RECORD_REDI_REGNUM],
+                                      &tmpulongest);
+         *addr = (uint32_t) (*addr + tmpulongest);
          break;
        case 2:
-         regcache_raw_read (irp->regcache, I386_EBP_REGNUM,
-                            (gdb_byte *) & tmpu32);
-         *addr += tmpu32;
-         regcache_raw_read (irp->regcache, I386_ESI_REGNUM,
-                            (gdb_byte *) & tmpu32);
-         *addr += tmpu32;
+         regcache_raw_read_unsigned (irp->regcache,
+                                     irp->regmap[X86_RECORD_REBP_REGNUM],
+                                      &tmpulongest);
+         *addr = (uint32_t) (*addr + tmpulongest);
+         regcache_raw_read_unsigned (irp->regcache,
+                                     irp->regmap[X86_RECORD_RESI_REGNUM],
+                                      &tmpulongest);
+         *addr = (uint32_t) (*addr + tmpulongest);
          break;
        case 3:
-         regcache_raw_read (irp->regcache, I386_EBP_REGNUM,
-                            (gdb_byte *) & tmpu32);
-         *addr += tmpu32;
-         regcache_raw_read (irp->regcache, I386_EDI_REGNUM,
-                            (gdb_byte *) & tmpu32);
-         *addr += tmpu32;
+         regcache_raw_read_unsigned (irp->regcache,
+                                     irp->regmap[X86_RECORD_REBP_REGNUM],
+                                      &tmpulongest);
+         *addr = (uint32_t) (*addr + tmpulongest);
+         regcache_raw_read_unsigned (irp->regcache,
+                                     irp->regmap[X86_RECORD_REDI_REGNUM],
+                                      &tmpulongest);
+         *addr = (uint32_t) (*addr + tmpulongest);
          break;
        case 4:
-         regcache_raw_read (irp->regcache, I386_ESI_REGNUM,
-                            (gdb_byte *) & tmpu32);
-         *addr += tmpu32;
+         regcache_raw_read_unsigned (irp->regcache,
+                                     irp->regmap[X86_RECORD_RESI_REGNUM],
+                                      &tmpulongest);
+         *addr = (uint32_t) (*addr + tmpulongest);
          break;
        case 5:
-         regcache_raw_read (irp->regcache, I386_EDI_REGNUM,
-                            (gdb_byte *) & tmpu32);
-         *addr += tmpu32;
+         regcache_raw_read_unsigned (irp->regcache,
+                                     irp->regmap[X86_RECORD_REDI_REGNUM],
+                                      &tmpulongest);
+         *addr = (uint32_t) (*addr + tmpulongest);
          break;
        case 6:
-         regcache_raw_read (irp->regcache, I386_EBP_REGNUM,
-                            (gdb_byte *) & tmpu32);
-         *addr += tmpu32;
+         regcache_raw_read_unsigned (irp->regcache,
+                                     irp->regmap[X86_RECORD_REBP_REGNUM],
+                                      &tmpulongest);
+         *addr = (uint32_t) (*addr + tmpulongest);
          break;
        case 7:
-         regcache_raw_read (irp->regcache, I386_EBX_REGNUM,
-                            (gdb_byte *) & tmpu32);
-         *addr += tmpu32;
+         regcache_raw_read_unsigned (irp->regcache,
+                                     irp->regmap[X86_RECORD_REBX_REGNUM],
+                                      &tmpulongest);
+         *addr = (uint32_t) (*addr + tmpulongest);
          break;
        }
       *addr &= 0xffff;
     }
 
-no_rm:
+ no_rm:
   return 0;
 }
 
@@ -2957,15 +3168,15 @@ no_rm:
 static int
 i386_record_lea_modrm (struct i386_record_s *irp)
 {
-  uint32_t addr;
+  struct gdbarch *gdbarch = irp->gdbarch;
+  uint64_t addr;
 
-  if (irp->override)
+  if (irp->override >= 0)
     {
-      if (record_debug)
-       printf_unfiltered (_("Process record ignores the memory change "
-                            "of instruction at address 0x%s because it "
-                            "can't get the value of the segment register.\n"),
-                          paddr_nz (irp->addr));
+      warning (_("Process record ignores the memory change "
+                 "of instruction at address %s because it "
+                 "can't get the value of the segment register."),
+               paddress (gdbarch, irp->orig_addr));
       return 0;
     }
 
@@ -2978,11 +3189,102 @@ i386_record_lea_modrm (struct i386_record_s *irp)
   return 0;
 }
 
+/* Record the push operation to "record_arch_list".
+   Return -1 if something wrong. */
+
+static int
+i386_record_push (struct i386_record_s *irp, int size)
+{
+  ULONGEST tmpulongest;
+
+  if (record_arch_list_add_reg (irp->regcache,
+                               irp->regmap[X86_RECORD_RESP_REGNUM]))
+    return -1;
+  regcache_raw_read_unsigned (irp->regcache,
+                             irp->regmap[X86_RECORD_RESP_REGNUM],
+                             &tmpulongest);
+  if (record_arch_list_add_mem ((CORE_ADDR) tmpulongest - size, size))
+    return -1;
+
+  return 0;
+}
+
+
+/* Defines contents to record.  */
+#define I386_SAVE_FPU_REGS              0xfffd
+#define I386_SAVE_FPU_ENV               0xfffe
+#define I386_SAVE_FPU_ENV_REG_STACK     0xffff
+
+/* Record the value of floating point registers which will be changed by the
+   current instruction to "record_arch_list".  Return -1 if something is wrong.
+*/
+
+static int i386_record_floats (struct gdbarch *gdbarch,
+                               struct i386_record_s *ir,
+                               uint32_t iregnum)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  int i;
+
+  /* Oza: Because of floating point insn push/pop of fpu stack is going to
+     happen.  Currently we store st0-st7 registers, but we need not store all
+     registers all the time, in future we use ftag register and record only
+     those who are not marked as an empty.  */
+
+  if (I386_SAVE_FPU_REGS == iregnum)
+    {
+      for (i = I387_ST0_REGNUM (tdep); i <= I387_ST0_REGNUM (tdep) + 7; i++)
+        {
+          if (record_arch_list_add_reg (ir->regcache, i))
+            return -1;
+        }
+    }
+  else if (I386_SAVE_FPU_ENV == iregnum)
+    {
+      for (i = I387_FCTRL_REGNUM (tdep); i <= I387_FOP_REGNUM (tdep); i++)
+             {
+             if (record_arch_list_add_reg (ir->regcache, i))
+               return -1;
+             }
+    }
+  else if (I386_SAVE_FPU_ENV_REG_STACK == iregnum)
+    {
+      for (i = I387_ST0_REGNUM (tdep); i <= I387_FOP_REGNUM (tdep); i++)
+      {
+        if (record_arch_list_add_reg (ir->regcache, i))
+          return -1;
+      }
+    }
+  else if ((iregnum >= I387_ST0_REGNUM (tdep)) &&
+           (iregnum <= I387_FOP_REGNUM (tdep)))
+    {
+      if (record_arch_list_add_reg (ir->regcache,iregnum))
+        return -1;
+    }
+  else
+    {
+      /* Parameter error.  */
+      return -1;
+    }
+  if(I386_SAVE_FPU_ENV != iregnum)
+    {
+    for (i = I387_FCTRL_REGNUM (tdep); i <= I387_FOP_REGNUM (tdep); i++)
+      {
+      if (record_arch_list_add_reg (ir->regcache, i))
+        return -1;
+      }
+    }
+  return 0;
+}
+
 /* Parse the current instruction and record the values of the registers and
    memory that will be changed in current instruction to "record_arch_list".
    Return -1 if something wrong. */
 
-static int
+#define I386_RECORD_ARCH_LIST_ADD_REG(regnum) \
+    record_arch_list_add_reg (ir.regcache, ir.regmap[(regnum)])
+
+int
 i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
                     CORE_ADDR addr)
 {
@@ -2990,19 +3292,29 @@ i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
   uint8_t tmpu8;
   uint16_t tmpu16;
   uint32_t tmpu32;
+  ULONGEST tmpulongest;
   uint32_t opcode;
   struct i386_record_s ir;
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  int rex = 0;
+  uint8_t rex_w = -1;
+  uint8_t rex_r = 0;
 
-  bzero (&ir, sizeof (struct i386_record_s));
+  memset (&ir, 0, sizeof (struct i386_record_s));
   ir.regcache = regcache;
   ir.addr = addr;
+  ir.orig_addr = addr;
   ir.aflag = 1;
   ir.dflag = 1;
+  ir.override = -1;
+  ir.popl_esp_hack = 0;
+  ir.regmap = gdbarch_tdep (gdbarch)->record_regmap;
+  ir.gdbarch = gdbarch;
 
   if (record_debug > 1)
     fprintf_unfiltered (gdb_stdlog, "Process record: i386_process_record "
-                                   "addr = 0x%s\n",
-                       paddr_nz (ir.addr));
+                                   "addr = %s\n",
+                       paddress (gdbarch, ir.addr));
 
   /* prefixes */
   while (1)
@@ -3011,60 +3323,97 @@ i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
        {
          if (record_debug)
            printf_unfiltered (_("Process record: error reading memory at "
-                                "addr 0x%s len = 1.\n"),
-                              paddr_nz (ir.addr));
+                                "addr %s len = 1.\n"),
+                              paddress (gdbarch, ir.addr));
          return -1;
        }
       ir.addr++;
-      switch (tmpu8)
+      switch (tmpu8)   /* Instruction prefixes */
        {
-       case 0xf3:
+       case REPE_PREFIX_OPCODE:
          prefixes |= PREFIX_REPZ;
          break;
-       case 0xf2:
+       case REPNE_PREFIX_OPCODE:
          prefixes |= PREFIX_REPNZ;
          break;
-       case 0xf0:
+       case LOCK_PREFIX_OPCODE:
          prefixes |= PREFIX_LOCK;
          break;
-       case 0x2e:
-         ir.override = I386_CS_REGNUM;
+       case CS_PREFIX_OPCODE:
+         ir.override = X86_RECORD_CS_REGNUM;
          break;
-       case 0x36:
-         ir.override = I386_SS_REGNUM;
+       case SS_PREFIX_OPCODE:
+         ir.override = X86_RECORD_SS_REGNUM;
          break;
-       case 0x3e:
-         ir.override = I386_DS_REGNUM;
+       case DS_PREFIX_OPCODE:
+         ir.override = X86_RECORD_DS_REGNUM;
          break;
-       case 0x26:
-         ir.override = I386_ES_REGNUM;
+       case ES_PREFIX_OPCODE:
+         ir.override = X86_RECORD_ES_REGNUM;
          break;
-       case 0x64:
-         ir.override = I386_FS_REGNUM;
+       case FS_PREFIX_OPCODE:
+         ir.override = X86_RECORD_FS_REGNUM;
          break;
-       case 0x65:
-         ir.override = I386_GS_REGNUM;
+       case GS_PREFIX_OPCODE:
+         ir.override = X86_RECORD_GS_REGNUM;
          break;
-       case 0x66:
+       case DATA_PREFIX_OPCODE:
          prefixes |= PREFIX_DATA;
          break;
-       case 0x67:
+       case ADDR_PREFIX_OPCODE:
          prefixes |= PREFIX_ADDR;
          break;
+        case 0x40:     /* i386 inc %eax */
+        case 0x41:     /* i386 inc %ecx */
+        case 0x42:     /* i386 inc %edx */
+        case 0x43:     /* i386 inc %ebx */
+        case 0x44:     /* i386 inc %esp */
+        case 0x45:     /* i386 inc %ebp */
+        case 0x46:     /* i386 inc %esi */
+        case 0x47:     /* i386 inc %edi */
+        case 0x48:     /* i386 dec %eax */
+        case 0x49:     /* i386 dec %ecx */
+        case 0x4a:     /* i386 dec %edx */
+        case 0x4b:     /* i386 dec %ebx */
+        case 0x4c:     /* i386 dec %esp */
+        case 0x4d:     /* i386 dec %ebp */
+        case 0x4e:     /* i386 dec %esi */
+        case 0x4f:     /* i386 dec %edi */
+          if (ir.regmap[X86_RECORD_R8_REGNUM]) /* 64 bit target */
+            {
+               /* REX */
+               rex = 1;
+               rex_w = (tmpu8 >> 3) & 1;
+               rex_r = (tmpu8 & 0x4) << 1;
+               ir.rex_x = (tmpu8 & 0x2) << 2;
+               ir.rex_b = (tmpu8 & 0x1) << 3;
+            }
+         else                                  /* 32 bit target */
+           goto out_prefixes;
+          break;
        default:
          goto out_prefixes;
          break;
        }
     }
-out_prefixes:
-  if (prefixes & PREFIX_DATA)
-    ir.dflag ^= 1;
+ out_prefixes:
+  if (ir.regmap[X86_RECORD_R8_REGNUM] && rex_w == 1)
+    {
+      ir.dflag = 2;
+    }
+  else
+    {
+      if (prefixes & PREFIX_DATA)
+        ir.dflag ^= 1;
+    }
   if (prefixes & PREFIX_ADDR)
     ir.aflag ^= 1;
+  else if (ir.regmap[X86_RECORD_R8_REGNUM])
+    ir.aflag = 2;
 
   /* now check op code */
   opcode = (uint32_t) tmpu8;
-reswitch:
+ reswitch:
   switch (opcode)
     {
     case 0x0f:
@@ -3072,8 +3421,8 @@ reswitch:
        {
          if (record_debug)
            printf_unfiltered (_("Process record: error reading memory at "
-                                "addr 0x%s len = 1.\n"),
-                              paddr_nz (ir.addr));
+                                "addr %s len = 1.\n"),
+                              paddress (gdbarch, ir.addr));
          return -1;
        }
       ir.addr++;
@@ -3081,8 +3430,7 @@ reswitch:
       goto reswitch;
       break;
 
-      /* arith & logic */
-    case 0x00:
+    case 0x00:    /* arith & logic */
     case 0x01:
     case 0x02:
     case 0x03:
@@ -3139,8 +3487,7 @@ reswitch:
 
          switch ((opcode >> 1) & 3)
            {
-             /* OP Ev, Gv */
-           case 0:
+           case 0:    /* OP Ev, Gv */
              if (i386_record_modrm (&ir))
                return -1;
              if (ir.mod != 3)
@@ -3150,34 +3497,29 @@ reswitch:
                }
              else
                {
-                 if (ir.ot == OT_BYTE)
+                  ir.rm |= ir.rex_b;
+                 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
                    ir.rm &= 0x3;
-                 if (record_arch_list_add_reg (ir.regcache, ir.rm))
-                   return -1;
+                 I386_RECORD_ARCH_LIST_ADD_REG (ir.rm);
                }
              break;
-             /* OP Gv, Ev */
-           case 1:
+           case 1:    /* OP Gv, Ev */
              if (i386_record_modrm (&ir))
                return -1;
-             if (ir.ot == OT_BYTE)
+              ir.reg |= rex_r;
+             if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
                ir.reg &= 0x3;
-             if (record_arch_list_add_reg (ir.regcache, ir.reg))
-               return -1;
+             I386_RECORD_ARCH_LIST_ADD_REG (ir.reg);
              break;
-             /* OP A, Iv */
-           case 2:
-             if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-               return -1;
+           case 2:    /* OP A, Iv */
+             I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
              break;
            }
        }
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* GRP1 */
-    case 0x80:
+    case 0x80:    /* GRP1 */
     case 0x81:
     case 0x82:
     case 0x83:
@@ -3193,21 +3535,20 @@ reswitch:
 
          if (ir.mod != 3)
            {
+              if (opcode == 0x83)
+                ir.rip_offset = 1;
+              else
+                ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
              if (i386_record_lea_modrm (&ir))
                return -1;
            }
          else
-           {
-             if (record_arch_list_add_reg (ir.regcache, ir.rm))
-               return -1;
-           }
+           I386_RECORD_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
        }
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* inv */
-    case 0x40:
+    case 0x40:      /* inc */
     case 0x41:
     case 0x42:
     case 0x43:
@@ -3215,8 +3556,8 @@ reswitch:
     case 0x45:
     case 0x46:
     case 0x47:
-      /* dec */
-    case 0x48:
+
+    case 0x48:      /* dec */
     case 0x49:
     case 0x4a:
     case 0x4b:
@@ -3224,14 +3565,12 @@ reswitch:
     case 0x4d:
     case 0x4e:
     case 0x4f:
-      if (record_arch_list_add_reg (ir.regcache, opcode & 7))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+
+      I386_RECORD_ARCH_LIST_ADD_REG (opcode & 7);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* GRP3 */
-    case 0xf6:
+    case 0xf6:    /* GRP3 */
     case 0xf7:
       if ((opcode & 1) == 0)
        ir.ot = OT_BYTE;
@@ -3240,30 +3579,16 @@ reswitch:
       if (i386_record_modrm (&ir))
        return -1;
 
+      if (ir.mod != 3 && ir.reg == 0)
+        ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
+
       switch (ir.reg)
        {
-         /* test */
-       case 0:
-         if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-           return -1;
-         break;
-         /* not */
-       case 2:
-         if (ir.mod != 3)
-           {
-             if (i386_record_lea_modrm (&ir))
-               return -1;
-           }
-         else
-           {
-             if (ir.ot == OT_BYTE)
-               ir.rm &= 0x3;
-             if (record_arch_list_add_reg (ir.regcache, ir.rm))
-               return -1;
-           }
+       case 0:    /* test */
+         I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
          break;
-         /* neg */
-       case 3:
+       case 2:    /* not */
+       case 3:    /* neg */
          if (ir.mod != 3)
            {
              if (i386_record_lea_modrm (&ir))
@@ -3271,31 +3596,22 @@ reswitch:
            }
          else
            {
-             if (ir.ot == OT_BYTE)
+              ir.rm |= ir.rex_b;
+             if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
                ir.rm &= 0x3;
-             if (record_arch_list_add_reg (ir.regcache, ir.rm))
-               return -1;
+             I386_RECORD_ARCH_LIST_ADD_REG (ir.rm);
            }
-         if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-           return -1;
+         if (ir.reg == 3)  /* neg */
+           I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
          break;
-         /* mul */
-       case 4:
-         /* imul */
-       case 5:
-         /* div */
-       case 6:
-         /* idiv */
-       case 7:
-         if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-           return -1;
+       case 4:    /* mul  */
+       case 5:    /* imul */
+       case 6:    /* div  */
+       case 7:    /* idiv */
+         I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
          if (ir.ot != OT_BYTE)
-           {
-             if (record_arch_list_add_reg (ir.regcache, I386_EDX_REGNUM))
-               return -1;
-           }
-         if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-           return -1;
+           I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
+         I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
          break;
        default:
          ir.addr -= 2;
@@ -3305,14 +3621,8 @@ reswitch:
        }
       break;
 
-      /* GRP4 */
-    case 0xfe:
-      /* GRP5 */
-    case 0xff:
-      if ((opcode & 1) == 0)
-       ir.ot = OT_BYTE;
-      else
-       ir.ot = ir.dflag + OT_WORD;
+    case 0xfe:    /* GRP4 */
+    case 0xff:    /* GRP5 */
       if (i386_record_modrm (&ir))
        return -1;
       if (ir.reg >= 2 && opcode == 0xfe)
@@ -3321,13 +3631,14 @@ reswitch:
          opcode = opcode << 8 | ir.modrm;
          goto no_support;
        }
-
       switch (ir.reg)
        {
-         /* inc */
-       case 0:
-         /* dec */
-       case 1:
+       case 0:    /* inc */
+       case 1:    /* dec */
+          if ((opcode & 1) == 0)
+           ir.ot = OT_BYTE;
+          else
+           ir.ot = ir.dflag + OT_WORD;
          if (ir.mod != 3)
            {
              if (i386_record_lea_modrm (&ir))
@@ -3335,42 +3646,35 @@ reswitch:
            }
          else
            {
-             if (ir.ot == OT_BYTE)
+             ir.rm |= ir.rex_b;
+             if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
                ir.rm &= 0x3;
-             if (record_arch_list_add_reg (ir.regcache, ir.rm))
-               return -1;
+             I386_RECORD_ARCH_LIST_ADD_REG (ir.rm);
            }
-         if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-           return -1;
+         I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
          break;
-         /* call */
-       case 2:
-         /* push */
-       case 6:
-         if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-           return -1;
-         regcache_raw_read (ir.regcache, I386_ESP_REGNUM,
-                            (gdb_byte *) & tmpu32);
-         if (record_arch_list_add_mem
-             ((CORE_ADDR) tmpu32 - (1 << (ir.dflag + 1)), (1 << (ir.dflag + 1))))
+       case 2:    /* call */
+          if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
+            ir.dflag = 2;
+         if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
            return -1;
+         I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
          break;
-         /* lcall */
-       case 3:
-         if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-           return -1;
-         if (record_arch_list_add_reg (ir.regcache, I386_CS_REGNUM))
-           return -1;
-         regcache_raw_read (ir.regcache, I386_ESP_REGNUM,
-                            (gdb_byte *) & tmpu32);
-         if (record_arch_list_add_mem
-             ((CORE_ADDR) tmpu32 - (1 << (ir.dflag + 2)), (1 << (ir.dflag + 2))))
+       case 3:    /* lcall */
+         I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM);
+         if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
            return -1;
+         I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
          break;
-         /* jmp */
-       case 4:
-         /* ljmp */
-       case 5:
+       case 4:    /* jmp  */
+       case 5:    /* ljmp */
+         I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
+         break;
+       case 6:    /* push */
+          if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
+            ir.dflag = 2;
+         if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
+           return -1;
          break;
        default:
          ir.addr -= 2;
@@ -3380,46 +3684,40 @@ reswitch:
        }
       break;
 
-      /* test */
-    case 0x84:
+    case 0x84:    /* test */
     case 0x85:
     case 0xa8:
     case 0xa9:
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* CWDE/CBW */
-    case 0x98:
-      if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-       return -1;
+    case 0x98:    /* CWDE/CBW */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
       break;
 
-      /* CDQ/CWD */
-    case 0x99:
-      if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EDX_REGNUM))
-       return -1;
+    case 0x99:    /* CDQ/CWD */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
       break;
 
-      /* imul */
-    case 0x0faf:
+    case 0x0faf:  /* imul */
     case 0x69:
     case 0x6b:
       ir.ot = ir.dflag + OT_WORD;
       if (i386_record_modrm (&ir))
        return -1;
-      if (ir.ot == OT_BYTE)
+      if (opcode == 0x69)
+        ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
+      else if (opcode == 0x6b)
+        ir.rip_offset = 1;
+      ir.reg |= rex_r;
+      if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
        ir.reg &= 0x3;
-      if (record_arch_list_add_reg (ir.regcache, ir.reg))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (ir.reg);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* xadd */
-    case 0x0fc0:
+    case 0x0fc0:  /* xadd */
     case 0x0fc1:
       if ((opcode & 1) == 0)
        ir.ot = OT_BYTE;
@@ -3427,32 +3725,28 @@ reswitch:
        ir.ot = ir.dflag + OT_WORD;
       if (i386_record_modrm (&ir))
        return -1;
+      ir.reg |= rex_r;
       if (ir.mod == 3)
        {
-         if (ir.ot == OT_BYTE)
+         if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
            ir.reg &= 0x3;
-         if (record_arch_list_add_reg (ir.regcache, ir.reg))
-           return -1;
-         if (ir.ot == OT_BYTE)
+         I386_RECORD_ARCH_LIST_ADD_REG (ir.reg);
+         if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
            ir.rm &= 0x3;
-         if (record_arch_list_add_reg (ir.regcache, ir.rm))
-           return -1;
+         I386_RECORD_ARCH_LIST_ADD_REG (ir.rm);
        }
       else
        {
          if (i386_record_lea_modrm (&ir))
            return -1;
-         if (ir.ot == OT_BYTE)
+         if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
            ir.reg &= 0x3;
-         if (record_arch_list_add_reg (ir.regcache, ir.reg))
-           return -1;
+         I386_RECORD_ARCH_LIST_ADD_REG (ir.reg);
        }
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* cmpxchg */
-    case 0x0fb0:
+    case 0x0fb0:  /* cmpxchg */
     case 0x0fb1:
       if ((opcode & 1) == 0)
        ir.ot = OT_BYTE;
@@ -3462,26 +3756,22 @@ reswitch:
        return -1;
       if (ir.mod == 3)
        {
-         if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-           return -1;
-         if (ir.ot == OT_BYTE)
+          ir.reg |= rex_r;
+         I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
+         if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
            ir.reg &= 0x3;
-         if (record_arch_list_add_reg (ir.regcache, ir.reg))
-           return -1;
+         I386_RECORD_ARCH_LIST_ADD_REG (ir.reg);
        }
       else
        {
-         if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-           return -1;
+         I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
          if (i386_record_lea_modrm (&ir))
            return -1;
        }
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* cmpxchg8b */
-    case 0x0fc7:
+    case 0x0fc7:    /* cmpxchg8b */
       if (i386_record_modrm (&ir))
        return -1;
       if (ir.mod == 3)
@@ -3490,18 +3780,14 @@ reswitch:
          opcode = opcode << 8 | ir.modrm;
          goto no_support;
        }
-      if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EDX_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
       if (i386_record_lea_modrm (&ir))
        return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* push */
-    case 0x50:
+    case 0x50:    /* push */
     case 0x51:
     case 0x52:
     case 0x53:
@@ -3511,147 +3797,146 @@ reswitch:
     case 0x57:
     case 0x68:
     case 0x6a:
-      /* push es */
-    case 0x06:
-      /* push cs */
-    case 0x0e:
-      /* push ss */
-    case 0x16:
-      /* push ds */
-    case 0x1e:
-      /* push fs */
-    case 0x0fa0:
-      /* push gs */
-    case 0x0fa8:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      regcache_raw_read (ir.regcache, I386_ESP_REGNUM,
-                        (gdb_byte *) & tmpu32);
-      if (record_arch_list_add_mem
-         ((CORE_ADDR) tmpu32 - (1 << (ir.dflag + 1)), (1 << (ir.dflag + 1))))
+      if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
+        ir.dflag = 2;
+      if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
        return -1;
       break;
 
-      /* pop */
-    case 0x58:
-    case 0x59:
-    case 0x5a:
-    case 0x5b:
-    case 0x5c:
-    case 0x5d:
-    case 0x5e:
-    case 0x5f:
-      ir.ot = ir.dflag + OT_WORD;
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      if (ir.ot == OT_BYTE)
-       opcode &= 0x3;
-      if (record_arch_list_add_reg (ir.regcache, opcode & 0x7))
+    case 0x06:    /* push es */
+    case 0x0e:    /* push cs */
+    case 0x16:    /* push ss */
+    case 0x1e:    /* push ds */
+      if (ir.regmap[X86_RECORD_R8_REGNUM])
+        {
+         ir.addr -= 1;
+         goto no_support;
+       }
+      if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
        return -1;
       break;
 
-      /* pusha */
-    case 0x60:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
+    case 0x0fa0:    /* push fs */
+    case 0x0fa8:    /* push gs */
+      if (ir.regmap[X86_RECORD_R8_REGNUM])
+        {
+         ir.addr -= 2;
+         goto no_support;
+       }
+      if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
        return -1;
-      regcache_raw_read (ir.regcache, I386_ESP_REGNUM,
-                        (gdb_byte *) & tmpu32);
-      if (record_arch_list_add_mem
-         ((CORE_ADDR) tmpu32 - (1 << (ir.dflag + 4)), (1 << (ir.dflag + 4))))
+      break;
+
+    case 0x60:    /* pusha */
+      if (ir.regmap[X86_RECORD_R8_REGNUM])
+        {
+         ir.addr -= 1;
+         goto no_support;
+       }
+      if (i386_record_push (&ir, 1 << (ir.dflag + 4)))
        return -1;
       break;
 
-      /* popa */
-    case 0x61:
-      for (tmpu8 = I386_EAX_REGNUM; tmpu8 <= I386_EDI_REGNUM; tmpu8++)
-       {
-         if (record_arch_list_add_reg (ir.regcache, tmpu8))
-           return -1;
+    case 0x58:    /* pop */
+    case 0x59:
+    case 0x5a:
+    case 0x5b:
+    case 0x5c:
+    case 0x5d:
+    case 0x5e:
+    case 0x5f:
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG ((opcode & 0x7) | ir.rex_b);
+      break;
+
+    case 0x61:    /* popa */
+      if (ir.regmap[X86_RECORD_R8_REGNUM])
+        {
+         ir.addr -= 1;
+         goto no_support;
        }
+      for (tmpu8 = X86_RECORD_REAX_REGNUM; tmpu8 <= X86_RECORD_REDI_REGNUM;
+          tmpu8++)
+       I386_RECORD_ARCH_LIST_ADD_REG (tmpu8);
       break;
 
-      /* pop */
-    case 0x8f:
-      ir.ot = ir.dflag + OT_WORD;
+    case 0x8f:    /* pop */
+      if (ir.regmap[X86_RECORD_R8_REGNUM])
+       ir.ot = ir.dflag ? OT_QUAD : OT_WORD;
+      else
+        ir.ot = ir.dflag + OT_WORD;
       if (i386_record_modrm (&ir))
        return -1;
       if (ir.mod == 3)
-       {
-         if (record_arch_list_add_reg (ir.regcache, ir.rm))
-           return -1;
-       }
+       I386_RECORD_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
       else
        {
+          ir.popl_esp_hack = 1 << ir.ot;
          if (i386_record_lea_modrm (&ir))
            return -1;
        }
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
       break;
 
-      /* enter */
-    case 0xc8:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EBP_REGNUM))
-       return -1;
-      regcache_raw_read (ir.regcache, I386_ESP_REGNUM,
-                        (gdb_byte *) & tmpu32);
-      if (record_arch_list_add_mem
-         ((CORE_ADDR) tmpu32 - (1 << (ir.dflag + 1)), (1 << (ir.dflag + 1))))
+    case 0xc8:    /* enter */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM);
+      if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
+        ir.dflag = 2;
+      if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
        return -1;
       break;
 
-      /* leave */
-    case 0xc9:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EBP_REGNUM))
-       return -1;
+    case 0xc9:    /* leave */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM);
       break;
 
-      /* pop es */
-    case 0x07:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_ES_REGNUM))
-       return -1;
+    case 0x07:    /* pop es */
+      if (ir.regmap[X86_RECORD_R8_REGNUM])
+        {
+         ir.addr -= 1;
+         goto no_support;
+       }
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_ES_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* pop ss */
-    case 0x17:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_SS_REGNUM))
-       return -1;
+    case 0x17:    /* pop ss */
+      if (ir.regmap[X86_RECORD_R8_REGNUM])
+        {
+         ir.addr -= 1;
+         goto no_support;
+       }
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_SS_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* pop ds */
-    case 0x1f:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_DS_REGNUM))
-       return -1;
+    case 0x1f:    /* pop ds */
+      if (ir.regmap[X86_RECORD_R8_REGNUM])
+        {
+         ir.addr -= 1;
+         goto no_support;
+       }
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_DS_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* pop fs */
-    case 0x0fa1:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_FS_REGNUM))
-       return -1;
+    case 0x0fa1:    /* pop fs */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_FS_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* pop gs */
-    case 0x0fa9:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_GS_REGNUM))
-       return -1;
+    case 0x0fa9:    /* pop gs */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_GS_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* mov */
-    case 0x88:
+    case 0x88:    /* mov */
     case 0x89:
     case 0xc6:
     case 0xc7:
@@ -3665,60 +3950,74 @@ reswitch:
 
       if (ir.mod != 3)
        {
+          if (opcode == 0xc6 || opcode == 0xc7)
+           ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
          if (i386_record_lea_modrm (&ir))
            return -1;
        }
       else
        {
-         if (ir.ot == OT_BYTE)
+          if (opcode == 0xc6 || opcode == 0xc7)
+           ir.rm |= ir.rex_b;
+         if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
            ir.rm &= 0x3;
-         if (record_arch_list_add_reg (ir.regcache, ir.rm))
-           return -1;
+         I386_RECORD_ARCH_LIST_ADD_REG (ir.rm);
        }
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
       break;
-      /* mov */
-    case 0x8a:
+
+    case 0x8a:    /* mov */
     case 0x8b:
       if ((opcode & 1) == 0)
        ir.ot = OT_BYTE;
       else
        ir.ot = ir.dflag + OT_WORD;
-
       if (i386_record_modrm (&ir))
        return -1;
-
-      if (ir.ot == OT_BYTE)
+      ir.reg |= rex_r;
+      if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
        ir.reg &= 0x3;
-      if (record_arch_list_add_reg (ir.regcache, ir.reg))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (ir.reg);
+      break;
 
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
+    case 0x8c:    /* mov seg */
+      if (i386_record_modrm (&ir))
        return -1;
+      if (ir.reg > 5)
+       {
+         ir.addr -= 2;
+         opcode = opcode << 8 | ir.modrm;
+         goto no_support;
+       }
+
+      if (ir.mod == 3)
+       I386_RECORD_ARCH_LIST_ADD_REG (ir.rm);
+      else
+       {
+         ir.ot = OT_WORD;
+         if (i386_record_lea_modrm (&ir))
+           return -1;
+       }
       break;
 
-      /* mov seg */
-    case 0x8e:
+    case 0x8e:    /* mov seg */
       if (i386_record_modrm (&ir))
        return -1;
-
       switch (ir.reg)
        {
        case 0:
-         tmpu8 = I386_ES_REGNUM;
+         tmpu8 = X86_RECORD_ES_REGNUM;
          break;
        case 2:
-         tmpu8 = I386_SS_REGNUM;
+         tmpu8 = X86_RECORD_SS_REGNUM;
          break;
        case 3:
-         tmpu8 = I386_DS_REGNUM;
+         tmpu8 = X86_RECORD_DS_REGNUM;
          break;
        case 4:
-         tmpu8 = I386_FS_REGNUM;
+         tmpu8 = X86_RECORD_FS_REGNUM;
          break;
        case 5:
-         tmpu8 = I386_GS_REGNUM;
+         tmpu8 = X86_RECORD_GS_REGNUM;
          break;
        default:
          ir.addr -= 2;
@@ -3726,56 +4025,20 @@ reswitch:
          goto no_support;
          break;
        }
-      if (record_arch_list_add_reg (ir.regcache, tmpu8))
-       return -1;
-
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (tmpu8);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* mov seg */
-    case 0x8c:
+    case 0x0fb6:    /* movzbS */
+    case 0x0fb7:    /* movzwS */
+    case 0x0fbe:    /* movsbS */
+    case 0x0fbf:    /* movswS */
       if (i386_record_modrm (&ir))
        return -1;
-      if (ir.reg > 5)
-       {
-         ir.addr -= 2;
-         opcode = opcode << 8 | ir.modrm;
-         goto no_support;
-       }
-
-      if (ir.mod == 3)
-       {
-         if (record_arch_list_add_reg (ir.regcache, ir.rm))
-           return -1;
-       }
-      else
-       {
-         ir.ot = OT_WORD;
-         if (i386_record_lea_modrm (&ir))
-           return -1;
-       }
-
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
-      break;
-
-      /* movzbS */
-    case 0x0fb6:
-      /* movzwS */
-    case 0x0fb7:
-      /* movsbS */
-    case 0x0fbe:
-      /* movswS */
-    case 0x0fbf:
-      if (i386_record_modrm (&ir))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, ir.reg))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (ir.reg | rex_r);
       break;
 
-      /* lea */
-    case 0x8d:
+    case 0x8d:      /* lea */
       if (i386_record_modrm (&ir))
        return -1;
       if (ir.mod == 3)
@@ -3784,79 +4047,80 @@ reswitch:
          opcode = opcode << 8 | ir.modrm;
          goto no_support;
        }
-
       ir.ot = ir.dflag;
-      if (ir.ot == OT_BYTE)
+      ir.reg |= rex_r;
+      if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
        ir.reg &= 0x3;
-      if (record_arch_list_add_reg (ir.regcache, ir.reg))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (ir.reg);
       break;
 
-      /* mov EAX */
-    case 0xa0:
+    case 0xa0:    /* mov EAX */
     case 0xa1:
-      /* xlat */
-    case 0xd7:
-      if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-       return -1;
+
+    case 0xd7:    /* xlat */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
       break;
 
-      /* mov EAX */
-    case 0xa2:
+    case 0xa2:    /* mov EAX */
     case 0xa3:
-      {
-       uint32_t addr;
-
-       if (ir.override)
-         {
-           if (record_debug)
-             printf_unfiltered (_("Process record ignores the memory change "
-                                  "of instruction at address 0x%s because "
-                                  "it can't get the value of the segment "
-                                  "register.\n"),
-                                paddr_nz (ir.addr));
-         }
-       else
-         {
-           if ((opcode & 1) == 0)
-             ir.ot = OT_BYTE;
-           else
-             ir.ot = ir.dflag + OT_WORD;
-           if (ir.aflag)
-             {
-               if (target_read_memory
-                   (ir.addr, (gdb_byte *) & addr, 4))
-                 {
-                   if (record_debug)
-                     printf_unfiltered (_("Process record: error reading "
-                                          "memory at addr 0x%s len = 4.\n"),
-                                        paddr_nz (ir.addr));
-                   return -1;
-                 }
-               ir.addr += 4;
-             }
-           else
-             {
-               if (target_read_memory
-                   (ir.addr, (gdb_byte *) & tmpu16, 4))
-                 {
-                   if (record_debug)
-                     printf_unfiltered (_("Process record: error reading "
-                                          "memory at addr 0x%s len = 4.\n"),
-                                        paddr_nz (ir.addr));
-                   return -1;
-                 }
-               ir.addr += 2;
-               addr = tmpu16;
-             }
-           if (record_arch_list_add_mem (addr, 1 << ir.ot))
-             return -1;
-         }
-      }
+      if (ir.override >= 0)
+        {
+         warning (_("Process record ignores the memory change "
+                     "of instruction at address %s because "
+                     "it can't get the value of the segment "
+                     "register."),
+                   paddress (gdbarch, ir.orig_addr));
+       }
+      else
+       {
+          if ((opcode & 1) == 0)
+           ir.ot = OT_BYTE;
+         else
+           ir.ot = ir.dflag + OT_WORD;
+         if (ir.aflag == 2)
+           {
+              if (target_read_memory (ir.addr, (gdb_byte *) &addr, 8))
+               {
+                 if (record_debug)
+                   printf_unfiltered (_("Process record: error reading "
+                                        "memory at addr 0x%s len = 8.\n"),
+                                      paddress (gdbarch, ir.addr));
+                 return -1;
+               }
+             ir.addr += 8;
+           }
+          else if (ir.aflag)
+           {
+              if (target_read_memory (ir.addr, (gdb_byte *) &tmpu32, 4))
+               {
+                 if (record_debug)
+                   printf_unfiltered (_("Process record: error reading "
+                                        "memory at addr 0x%s len = 4.\n"),
+                                      paddress (gdbarch, ir.addr));
+                 return -1;
+               }
+             ir.addr += 4;
+              addr = tmpu32;
+           }
+          else
+           {
+              if (target_read_memory (ir.addr, (gdb_byte *) &tmpu16, 2))
+               {
+                 if (record_debug)
+                   printf_unfiltered (_("Process record: error reading "
+                                        "memory at addr 0x%s len = 2.\n"),
+                                      paddress (gdbarch, ir.addr));
+                 return -1;
+               }
+             ir.addr += 2;
+              addr = tmpu16;
+           }
+         if (record_arch_list_add_mem (addr, 1 << ir.ot))
+           return -1;
+        }
       break;
 
-      /* mov R, Ib */
-    case 0xb0:
+    case 0xb0:    /* mov R, Ib */
     case 0xb1:
     case 0xb2:
     case 0xb3:
@@ -3864,12 +4128,12 @@ reswitch:
     case 0xb5:
     case 0xb6:
     case 0xb7:
-      if (record_arch_list_add_reg (ir.regcache, (opcode & 0x7) & 0x3))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG ((ir.regmap[X86_RECORD_R8_REGNUM])
+                                        ? ((opcode & 0x7) | ir.rex_b)
+                                       : ((opcode & 0x7) & 0x3));
       break;
 
-      /* mov R, Iv */
-    case 0xb8:
+    case 0xb8:    /* mov R, Iv */
     case 0xb9:
     case 0xba:
     case 0xbb:
@@ -3877,64 +4141,56 @@ reswitch:
     case 0xbd:
     case 0xbe:
     case 0xbf:
-      if (record_arch_list_add_reg (ir.regcache, opcode & 0x7))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG ((opcode & 0x7) | ir.rex_b);
       break;
 
-      /* xchg R, EAX */
-    case 0x91:
+    case 0x91:    /* xchg R, EAX */
     case 0x92:
     case 0x93:
     case 0x94:
     case 0x95:
     case 0x96:
     case 0x97:
-      if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, opcode & 0x7))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (opcode & 0x7);
       break;
 
-      /* xchg Ev, Gv */
-    case 0x86:
+    case 0x86:    /* xchg Ev, Gv */
     case 0x87:
       if ((opcode & 1) == 0)
        ir.ot = OT_BYTE;
       else
        ir.ot = ir.dflag + OT_WORD;
-
       if (i386_record_modrm (&ir))
        return -1;
-
       if (ir.mod == 3)
        {
-         if (ir.ot == OT_BYTE)
+         ir.rm |= ir.rex_b;
+         if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
            ir.rm &= 0x3;
-         if (record_arch_list_add_reg (ir.regcache, ir.rm))
-           return -1;
+         I386_RECORD_ARCH_LIST_ADD_REG (ir.rm);
        }
       else
        {
          if (i386_record_lea_modrm (&ir))
            return -1;
        }
-
-      if (ir.ot == OT_BYTE)
+      ir.reg |= rex_r;
+      if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
        ir.reg &= 0x3;
-      if (record_arch_list_add_reg (ir.regcache, ir.reg))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (ir.reg);
       break;
 
-      /* les Gv */
-    case 0xc4:
-      /* lds Gv */
-    case 0xc5:
-      /* lss Gv */
-    case 0x0fb2:
-      /* lfs Gv */
-    case 0x0fb4:
-      /* lgs Gv */
-    case 0x0fb5:
+    case 0xc4:    /* les Gv */
+    case 0xc5:    /* lds Gv */
+      if (ir.regmap[X86_RECORD_R8_REGNUM])
+        {
+         ir.addr -= 1;
+         goto no_support;
+       }
+    case 0x0fb2:    /* lss Gv */
+    case 0x0fb4:    /* lfs Gv */
+    case 0x0fb5:    /* lgs Gv */
       if (i386_record_modrm (&ir))
        return -1;
       if (ir.mod == 3)
@@ -3946,39 +4202,30 @@ reswitch:
          opcode = opcode << 8 | ir.modrm;
          goto no_support;
        }
-
       switch (opcode)
        {
-         /* les Gv */
-       case 0xc4:
-         tmpu8 = I386_ES_REGNUM;
+       case 0xc4:    /* les Gv */
+         tmpu8 = X86_RECORD_ES_REGNUM;
          break;
-         /* lds Gv */
-       case 0xc5:
-         tmpu8 = I386_DS_REGNUM;
+       case 0xc5:    /* lds Gv */
+         tmpu8 = X86_RECORD_DS_REGNUM;
          break;
-         /* lss Gv */
-       case 0x0fb2:
-         tmpu8 = I386_SS_REGNUM;
+       case 0x0fb2:  /* lss Gv */
+         tmpu8 = X86_RECORD_SS_REGNUM;
          break;
-         /* lfs Gv */
-       case 0x0fb4:
-         tmpu8 = I386_FS_REGNUM;
+       case 0x0fb4:  /* lfs Gv */
+         tmpu8 = X86_RECORD_FS_REGNUM;
          break;
-         /* lgs Gv */
-       case 0x0fb5:
-         tmpu8 = I386_GS_REGNUM;
+       case 0x0fb5:  /* lgs Gv */
+         tmpu8 = X86_RECORD_GS_REGNUM;
          break;
        }
-      if (record_arch_list_add_reg (ir.regcache, tmpu8))
-       return -1;
-
-      if (record_arch_list_add_reg (ir.regcache, ir.reg))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (tmpu8);
+      I386_RECORD_ARCH_LIST_ADD_REG (ir.reg | rex_r);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* shifts */
-    case 0xc0:
+    case 0xc0:    /* shifts */
     case 0xc1:
     case 0xd0:
     case 0xd1:
@@ -3988,10 +4235,8 @@ reswitch:
        ir.ot = OT_BYTE;
       else
        ir.ot = ir.dflag + OT_WORD;
-
       if (i386_record_modrm (&ir))
        return -1;
-
       if (ir.mod != 3 && (opcode == 0xd2 || opcode == 0xd3))
        {
          if (i386_record_lea_modrm (&ir))
@@ -3999,14 +4244,12 @@ reswitch:
        }
       else
        {
-         if (ir.ot == OT_BYTE)
+         ir.rm |= ir.rex_b;
+         if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
            ir.rm &= 0x3;
-         if (record_arch_list_add_reg (ir.regcache, ir.rm))
-           return -1;
+         I386_RECORD_ARCH_LIST_ADD_REG (ir.rm);
        }
-
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
     case 0x0fa4:
@@ -4027,9 +4270,7 @@ reswitch:
        }
       break;
 
-      /* floats */
-      /* It just record the memory change of instrcution. */
-    case 0xd8:
+    case 0xd8:    /* Floats.  */
     case 0xd9:
     case 0xda:
     case 0xdb:
@@ -4042,45 +4283,56 @@ reswitch:
       ir.reg |= ((opcode & 7) << 3);
       if (ir.mod != 3)
        {
-         /* memory */
-         uint32_t addr;
+         /* Memory. */
+         uint64_t tmpu64;
 
-         if (i386_record_lea_modrm_addr (&ir, &addr))
+         if (i386_record_lea_modrm_addr (&ir, &tmpu64))
            return -1;
          switch (ir.reg)
            {
-           case 0x00:
-           case 0x01:
            case 0x02:
+            case 0x12:
+            case 0x22:
+            case 0x32:
+             /* For fcom, ficom nothing to do.  */
+              break;
            case 0x03:
+            case 0x13:
+            case 0x23:
+            case 0x33:
+             /* For fcomp, ficomp pop FPU stack, store all.  */
+              if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
+                return -1;
+              break;
+            case 0x00:
+            case 0x01:
            case 0x04:
            case 0x05:
            case 0x06:
            case 0x07:
            case 0x10:
            case 0x11:
-           case 0x12:
-           case 0x13:
            case 0x14:
            case 0x15:
            case 0x16:
            case 0x17:
            case 0x20:
            case 0x21:
-           case 0x22:
-           case 0x23:
            case 0x24:
            case 0x25:
            case 0x26:
            case 0x27:
            case 0x30:
            case 0x31:
-           case 0x32:
-           case 0x33:
            case 0x34:
            case 0x35:
            case 0x36:
            case 0x37:
+              /* For fadd, fmul, fsub, fsubr, fdiv, fdivr, fiadd, fimul,
+                 fisub, fisubr, fidiv, fidivr, modR/M.reg is an extension
+                 of code,  always affects st(0) register.  */
+              if (i386_record_floats (gdbarch, &ir, I387_ST0_REGNUM (tdep)))
+                return -1;
              break;
            case 0x08:
            case 0x0a:
@@ -4089,6 +4341,7 @@ reswitch:
            case 0x19:
            case 0x1a:
            case 0x1b:
+            case 0x1d:
            case 0x28:
            case 0x29:
            case 0x2a:
@@ -4097,24 +4350,30 @@ reswitch:
            case 0x39:
            case 0x3a:
            case 0x3b:
+            case 0x3c:
+            case 0x3d:
              switch (ir.reg & 7)
                {
                case 0:
+                 /* Handling fld, fild.  */
+                 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
+                   return -1;
                  break;
                case 1:
                  switch (ir.reg >> 4)
                    {
                    case 0:
-                     if (record_arch_list_add_mem (addr, 4))
+                     if (record_arch_list_add_mem (tmpu64, 4))
                        return -1;
                      break;
                    case 2:
-                     if (record_arch_list_add_mem (addr, 8))
+                     if (record_arch_list_add_mem (tmpu64, 8))
                        return -1;
                      break;
                    case 3:
+                     break;
                    default:
-                     if (record_arch_list_add_mem (addr, 2))
+                     if (record_arch_list_add_mem (tmpu64, 2))
                        return -1;
                      break;
                    }
@@ -4123,17 +4382,51 @@ reswitch:
                  switch (ir.reg >> 4)
                    {
                    case 0:
+                     if (record_arch_list_add_mem (tmpu64, 4))
+                       return -1;
+                     if (3 == (ir.reg & 7))
+                       {
+                         /* For fstp m32fp.  */
+                         if (i386_record_floats (gdbarch, &ir,
+                                                 I386_SAVE_FPU_REGS))
+                           return -1;
+                       }
+                     break;
                    case 1:
-                     if (record_arch_list_add_mem (addr, 4))
+                     if (record_arch_list_add_mem (tmpu64, 4))
                        return -1;
+                     if ((3 == (ir.reg & 7))
+                         || (5 == (ir.reg & 7))
+                         || (7 == (ir.reg & 7)))
+                       {
+                         /* For fstp insn.  */
+                         if (i386_record_floats (gdbarch, &ir,
+                                                 I386_SAVE_FPU_REGS))
+                           return -1;
+                       }
                      break;
                    case 2:
-                     if (record_arch_list_add_mem (addr, 8))
+                     if (record_arch_list_add_mem (tmpu64, 8))
                        return -1;
+                     if (3 == (ir.reg & 7))
+                       {
+                         /* For fstp m64fp.  */
+                         if (i386_record_floats (gdbarch, &ir,
+                                                 I386_SAVE_FPU_REGS))
+                           return -1;
+                       }
                      break;
                    case 3:
+                     if ((3 <= (ir.reg & 7)) && (6 <= (ir.reg & 7)))
+                       {
+                         /* For fistp, fbld, fild, fbstp.  */
+                         if (i386_record_floats (gdbarch, &ir,
+                                                 I386_SAVE_FPU_REGS))
+                           return -1;
+                       }
+                     /* Fall through */
                    default:
-                     if (record_arch_list_add_mem (addr, 2))
+                     if (record_arch_list_add_mem (tmpu64, 2))
                        return -1;
                      break;
                    }
@@ -4141,52 +4434,72 @@ reswitch:
                }
              break;
            case 0x0c:
+              /* Insn fldenv.  */
+              if (i386_record_floats (gdbarch, &ir,
+                                      I386_SAVE_FPU_ENV_REG_STACK))
+                return -1;
+              break;
            case 0x0d:
-           case 0x1d:
+              /* Insn fldcw.  */
+              if (i386_record_floats (gdbarch, &ir, I387_FCTRL_REGNUM (tdep)))
+                return -1;
+              break;
            case 0x2c:
-           case 0x3c:
-           case 0x3d:
+              /* Insn frstor.  */
+              if (i386_record_floats (gdbarch, &ir,
+                                      I386_SAVE_FPU_ENV_REG_STACK))
+                return -1;
              break;
            case 0x0e:
              if (ir.dflag)
                {
-                 if (record_arch_list_add_mem (addr, 28))
+                 if (record_arch_list_add_mem (tmpu64, 28))
                    return -1;
                }
              else
                {
-                 if (record_arch_list_add_mem (addr, 14))
+                 if (record_arch_list_add_mem (tmpu64, 14))
                    return -1;
                }
              break;
            case 0x0f:
            case 0x2f:
-             if (record_arch_list_add_mem (addr, 2))
+             if (record_arch_list_add_mem (tmpu64, 2))
                return -1;
+              /* Insn fstp, fbstp.  */
+              if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
+                return -1;
              break;
            case 0x1f:
            case 0x3e:
-             if (record_arch_list_add_mem (addr, 10))
+             if (record_arch_list_add_mem (tmpu64, 10))
                return -1;
              break;
            case 0x2e:
              if (ir.dflag)
                {
-                 if (record_arch_list_add_mem (addr, 28))
+                 if (record_arch_list_add_mem (tmpu64, 28))
                    return -1;
-                 addr += 28;
+                 tmpu64 += 28;
                }
              else
                {
-                 if (record_arch_list_add_mem (addr, 14))
+                 if (record_arch_list_add_mem (tmpu64, 14))
                    return -1;
-                 addr += 14;
+                 tmpu64 += 14;
                }
-             if (record_arch_list_add_mem (addr, 80))
+             if (record_arch_list_add_mem (tmpu64, 80))
+               return -1;
+             /* Insn fsave.  */
+             if (i386_record_floats (gdbarch, &ir,
+                                     I386_SAVE_FPU_ENV_REG_STACK))
                return -1;
              break;
            case 0x3f:
-             if (record_arch_list_add_mem (addr, 8))
+             if (record_arch_list_add_mem (tmpu64, 8))
+               return -1;
+             /* Insn fistp.  */
+             if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
                return -1;
              break;
            default:
@@ -4196,144 +4509,303 @@ reswitch:
              break;
            }
        }
+      /* Opcode is an extension of modR/M byte.  */
+      else
+        {
+         switch (opcode)
+           {
+           case 0xd8:
+             if (i386_record_floats (gdbarch, &ir, I387_ST0_REGNUM (tdep)))
+               return -1;
+             break;
+           case 0xd9:
+             if (0x0c == (ir.modrm >> 4))
+               {
+                 if ((ir.modrm & 0x0f) <= 7)
+                   {
+                     if (i386_record_floats (gdbarch, &ir,
+                                             I386_SAVE_FPU_REGS))
+                       return -1;
+                   }
+                  else
+                   {
+                     if (i386_record_floats (gdbarch, &ir,
+                                             I387_ST0_REGNUM (tdep)))
+                       return -1;
+                     /* If only st(0) is changing, then we have already
+                        recorded.  */
+                     if ((ir.modrm & 0x0f) - 0x08)
+                       {
+                         if (i386_record_floats (gdbarch, &ir,
+                                                 I387_ST0_REGNUM (tdep) +
+                                                 ((ir.modrm & 0x0f) - 0x08)))
+                           return -1;
+                       }
+                   }
+               }
+              else
+                {
+                 switch (ir.modrm)
+                   {
+                   case 0xe0:
+                   case 0xe1:
+                   case 0xf0:
+                   case 0xf5:
+                   case 0xf8:
+                   case 0xfa:
+                   case 0xfc:
+                   case 0xfe:
+                   case 0xff:
+                     if (i386_record_floats (gdbarch, &ir,
+                                             I387_ST0_REGNUM (tdep)))
+                       return -1;
+                     break;
+                   case 0xf1:
+                   case 0xf2:
+                   case 0xf3:
+                   case 0xf4:
+                   case 0xf6:
+                   case 0xf7:
+                   case 0xe8:
+                   case 0xe9:
+                   case 0xea:
+                   case 0xeb:
+                   case 0xec:
+                   case 0xed:
+                   case 0xee:
+                   case 0xf9:
+                   case 0xfb:
+                     if (i386_record_floats (gdbarch, &ir,
+                                             I386_SAVE_FPU_REGS))
+                       return -1;
+                     break;
+                   case 0xfd:
+                     if (i386_record_floats (gdbarch, &ir,
+                                             I387_ST0_REGNUM (tdep)))
+                       return -1;
+                     if (i386_record_floats (gdbarch, &ir,
+                                             I387_ST0_REGNUM (tdep) + 1))
+                       return -1;
+                     break;
+                   }
+               }
+              break;
+            case 0xda:
+              if (0xe9 == ir.modrm)
+                {
+                 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
+                   return -1;
+                }
+              else if ((0x0c == ir.modrm >> 4) || (0x0d == ir.modrm >> 4))
+                {
+                 if (i386_record_floats (gdbarch, &ir,
+                                         I387_ST0_REGNUM (tdep)))
+                   return -1;
+                 if (((ir.modrm & 0x0f) > 0) && ((ir.modrm & 0x0f) <= 7))
+                   {
+                     if (i386_record_floats (gdbarch, &ir,
+                                             I387_ST0_REGNUM (tdep) +
+                                             (ir.modrm & 0x0f)))
+                       return -1;
+                   }
+                 else if ((ir.modrm & 0x0f) - 0x08)
+                   {
+                     if (i386_record_floats (gdbarch, &ir,
+                                             I387_ST0_REGNUM (tdep) +
+                                             ((ir.modrm & 0x0f) - 0x08)))
+                       return -1;
+                   }
+                }
+              break;
+            case 0xdb:
+              if (0xe3 == ir.modrm)
+                {
+                 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_ENV))
+                   return -1;
+                }
+              else if ((0x0c == ir.modrm >> 4) || (0x0d == ir.modrm >> 4))
+                {
+                 if (i386_record_floats (gdbarch, &ir,
+                                         I387_ST0_REGNUM (tdep)))
+                   return -1;
+                 if (((ir.modrm & 0x0f) > 0) && ((ir.modrm & 0x0f) <= 7))
+                   {
+                     if (i386_record_floats (gdbarch, &ir,
+                                             I387_ST0_REGNUM (tdep) +
+                                             (ir.modrm & 0x0f)))
+                       return -1;
+                   }
+                 else if ((ir.modrm & 0x0f) - 0x08)
+                   {
+                     if (i386_record_floats (gdbarch, &ir,
+                                             I387_ST0_REGNUM (tdep) +
+                                             ((ir.modrm & 0x0f) - 0x08)))
+                       return -1;
+                   }
+                }
+              break;
+            case 0xdc:
+              if ((0x0c == ir.modrm >> 4)
+                 || (0x0d == ir.modrm >> 4)
+                 || (0x0f == ir.modrm >> 4))
+                {
+                 if ((ir.modrm & 0x0f) <= 7)
+                   {
+                     if (i386_record_floats (gdbarch, &ir,
+                                             I387_ST0_REGNUM (tdep) +
+                                             (ir.modrm & 0x0f)))
+                       return -1;
+                   }
+                 else
+                   {
+                     if (i386_record_floats (gdbarch, &ir,
+                                             I387_ST0_REGNUM (tdep) +
+                                             ((ir.modrm & 0x0f) - 0x08)))
+                       return -1;
+                   }
+                }
+             break;
+            case 0xdd:
+              if (0x0c == ir.modrm >> 4)
+                {
+                  if (i386_record_floats (gdbarch, &ir,
+                                          I387_FTAG_REGNUM (tdep)))
+                    return -1;
+                }
+              else if ((0x0d == ir.modrm >> 4) || (0x0e == ir.modrm >> 4))
+                {
+                  if ((ir.modrm & 0x0f) <= 7)
+                    {
+                     if (i386_record_floats (gdbarch, &ir,
+                                             I387_ST0_REGNUM (tdep) +
+                                             (ir.modrm & 0x0f)))
+                       return -1;
+                    }
+                  else
+                    {
+                      if (i386_record_floats (gdbarch, &ir,
+                                             I386_SAVE_FPU_REGS))
+                        return -1;
+                    }
+                }
+              break;
+            case 0xde:
+              if ((0x0c == ir.modrm >> 4)
+                 || (0x0e == ir.modrm >> 4)
+                 || (0x0f == ir.modrm >> 4)
+                 || (0xd9 == ir.modrm))
+                {
+                 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
+                   return -1;
+                }
+              break;
+            case 0xdf:
+              if (0xe0 == ir.modrm)
+                {
+                 if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
+                   return -1;
+                }
+              else if ((0x0f == ir.modrm >> 4) || (0x0e == ir.modrm >> 4))
+                {
+                 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
+                   return -1;
+                }
+              break;
+           }
+       }
       break;
-
       /* string ops */
-      /* movsS */
-    case 0xa4:
+    case 0xa4:    /* movsS */
     case 0xa5:
-      /* stosS */
-    case 0xaa:
+    case 0xaa:    /* stosS */
     case 0xab:
-      /* insS */
-    case 0x6c:
+    case 0x6c:    /* insS */
     case 0x6d:
-      {
-       uint32_t addr;
-
-       if ((opcode & 1) == 0)
-         ir.ot = OT_BYTE;
-       else
-         ir.ot = ir.dflag + OT_WORD;
-       if (opcode == 0xa4 || opcode == 0xa5)
-         {
-           if (record_arch_list_add_reg (ir.regcache, I386_ESI_REGNUM))
-             return -1;
-         }
-       if (record_arch_list_add_reg (ir.regcache, I386_EDI_REGNUM))
-         return -1;
-
-       regcache_raw_read (ir.regcache, I386_EDI_REGNUM,
-                          (gdb_byte *) & addr);
-       if (!ir.aflag)
-         {
-           addr &= 0xffff;
-           /* addr += ((uint32_t)read_register (I386_ES_REGNUM)) << 4; */
-           if (record_debug)
-             printf_unfiltered (_("Process record ignores the memory change "
-                                  "of instruction at address 0x%s because "
-                                  "it can't get the value of the segment "
-                                  "register.\n"),
-                                paddr_nz (ir.addr));
-         }
-
-       if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
-         {
-           uint32_t count;
-
-           regcache_raw_read (ir.regcache, I386_ECX_REGNUM,
-                              (gdb_byte *) & count);
-           if (!ir.aflag)
-             count &= 0xffff;
-
-           regcache_raw_read (ir.regcache, I386_EFLAGS_REGNUM,
-                              (gdb_byte *) & tmpu32);
-           if ((tmpu32 >> 10) & 0x1)
-             addr -= (count - 1) * (1 << ir.ot);
-
-           if (ir.aflag)
-             {
-               if (record_arch_list_add_mem (addr, count * (1 << ir.ot)))
-                 return -1;
-             }
+      regcache_raw_read_unsigned (ir.regcache,
+                                  ir.regmap[X86_RECORD_RECX_REGNUM],
+                                  &tmpulongest);
+      if (tmpulongest)
+        {
+          ULONGEST es, ds;
 
-           if (record_arch_list_add_reg (ir.regcache, I386_ECX_REGNUM))
-             return -1;
-         }
-       else
-         {
-           if (ir.aflag)
-             {
-               if (record_arch_list_add_mem (addr, 1 << ir.ot))
-                 return -1;
-             }
-         }
-      }
+          if ((opcode & 1) == 0)
+           ir.ot = OT_BYTE;
+          else
+           ir.ot = ir.dflag + OT_WORD;
+          regcache_raw_read_unsigned (ir.regcache,
+                                      ir.regmap[X86_RECORD_REDI_REGNUM],
+                                      &tmpulongest);
+
+          regcache_raw_read_unsigned (ir.regcache,
+                                      ir.regmap[X86_RECORD_ES_REGNUM],
+                                      &es);
+          regcache_raw_read_unsigned (ir.regcache,
+                                      ir.regmap[X86_RECORD_DS_REGNUM],
+                                      &ds);
+          if (ir.aflag && (es != ds))
+            {
+              /* addr += ((uint32_t) read_register (I386_ES_REGNUM)) << 4; */
+              warning (_("Process record ignores the memory "
+                         "change of instruction at address %s "
+                         "because it can't get the value of the "
+                         "ES segment register."),
+                       paddress (gdbarch, ir.orig_addr));
+            }
+          else
+            {
+              if (record_arch_list_add_mem (tmpulongest, 1 << ir.ot))
+                return -1;
+            }
+
+          if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
+            I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
+          if (opcode == 0xa4 || opcode == 0xa5)
+            I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
+          I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
+          I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
+       }
       break;
 
-      /* lodsS */
-    case 0xac:
-    case 0xad:
-      if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_ESI_REGNUM))
-       return -1;
+    case 0xa6:    /* cmpsS */
+    case 0xa7:
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
       if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
-       {
-         if (record_arch_list_add_reg (ir.regcache, I386_ECX_REGNUM))
-           return -1;
-       }
+        I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* outsS */
-    case 0x6e:
-    case 0x6f:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESI_REGNUM))
-       return -1;
+    case 0xac:    /* lodsS */
+    case 0xad:
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
       if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
-       {
-         if (record_arch_list_add_reg (ir.regcache, I386_ECX_REGNUM))
-           return -1;
-       }
+        I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* scasS */
-    case 0xae:
+    case 0xae:    /* scasS */
     case 0xaf:
-      if (record_arch_list_add_reg (ir.regcache, I386_EDI_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
       if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
-       {
-         if (record_arch_list_add_reg (ir.regcache, I386_ECX_REGNUM))
-           return -1;
-       }
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+        I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* cmpsS */
-    case 0xa6:
-    case 0xa7:
-      if (record_arch_list_add_reg (ir.regcache, I386_EDI_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_ESI_REGNUM))
-       return -1;
+    case 0x6e:    /* outsS */
+    case 0x6f:
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
       if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
-       {
-         if (record_arch_list_add_reg (ir.regcache, I386_ECX_REGNUM))
-           return -1;
-       }
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+        I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* port I/O */
-    case 0xe4:
+    case 0xe4:    /* port I/O */
     case 0xe5:
     case 0xec:
     case 0xed:
-      if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
       break;
 
     case 0xe6:
@@ -4343,62 +4815,42 @@ reswitch:
       break;
 
       /* control */
-      /* ret im */
-    case 0xc2:
-      /* ret */
-    case 0xc3:
-      /* lret im */
-    case 0xca:
-      /* lret */
-    case 0xcb:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_CS_REGNUM))
-       return -1;
+    case 0xc2:    /* ret im */
+    case 0xc3:    /* ret */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* iret */
-    case 0xcf:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_CS_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+    case 0xca:    /* lret im */
+    case 0xcb:    /* lret */
+    case 0xcf:    /* iret */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* call im */
-    case 0xe8:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      regcache_raw_read (ir.regcache, I386_ESP_REGNUM,
-                        (gdb_byte *) & tmpu32);
-      if (record_arch_list_add_mem
-         ((CORE_ADDR) tmpu32 - (1 << (ir.dflag + 1)), (1 << (ir.dflag + 1))))
-       return -1;
+    case 0xe8:    /* call im */
+      if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
+        ir.dflag = 2;
+      if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
+        return -1;
       break;
 
-      /* lcall im */
-    case 0x9a:
-      if (record_arch_list_add_reg (ir.regcache, I386_CS_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      regcache_raw_read (ir.regcache, I386_ESP_REGNUM,
-                        (gdb_byte *) & tmpu32);
-      if (record_arch_list_add_mem
-         ((CORE_ADDR) tmpu32 - (1 << (ir.dflag + 2)), (1 << (ir.dflag + 2))))
-       return -1;
+    case 0x9a:    /* lcall im */
+      if (ir.regmap[X86_RECORD_R8_REGNUM])
+        {
+          ir.addr -= 1;
+          goto no_support;
+        }
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM);
+      if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
+        return -1;
       break;
 
-      /* jmp im */
-    case 0xe9:
-      /* ljmp im */
-    case 0xea:
-      /* jmp Jb */
-    case 0xeb:
-      /* jcc Jb */
-    case 0x70:
+    case 0xe9:    /* jmp im */
+    case 0xea:    /* ljmp im */
+    case 0xeb:    /* jmp Jb */
+    case 0x70:    /* jcc Jb */
     case 0x71:
     case 0x72:
     case 0x73:
@@ -4414,8 +4866,7 @@ reswitch:
     case 0x7d:
     case 0x7e:
     case 0x7f:
-      /* jcc Jv */
-    case 0x0f80:
+    case 0x0f80:  /* jcc Jv */
     case 0x0f81:
     case 0x0f82:
     case 0x0f83:
@@ -4433,8 +4884,7 @@ reswitch:
     case 0x0f8f:
       break;
 
-      /* setcc Gv */
-    case 0x0f90:
+    case 0x0f90:  /* setcc Gv */
     case 0x0f91:
     case 0x0f92:
     case 0x0f93:
@@ -4450,14 +4900,13 @@ reswitch:
     case 0x0f9d:
     case 0x0f9e:
     case 0x0f9f:
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       ir.ot = OT_BYTE;
       if (i386_record_modrm (&ir))
        return -1;
       if (ir.mod == 3)
-       {
-         if (record_arch_list_add_reg (ir.regcache, ir.rm & 0x3))
-           return -1;
-       }
+        I386_RECORD_ARCH_LIST_ADD_REG (ir.rex_b ? (ir.rm | ir.rex_b)
+                                               : (ir.rm & 0x3));
       else
        {
          if (i386_record_lea_modrm (&ir))
@@ -4465,8 +4914,7 @@ reswitch:
        }
       break;
 
-      /* cmov Gv, Ev */
-    case 0x0f40:
+    case 0x0f40:    /* cmov Gv, Ev */
     case 0x0f41:
     case 0x0f42:
     case 0x0f43:
@@ -4484,128 +4932,138 @@ reswitch:
     case 0x0f4f:
       if (i386_record_modrm (&ir))
        return -1;
+      ir.reg |= rex_r;
       if (ir.dflag == OT_BYTE)
        ir.reg &= 0x3;
-      if (record_arch_list_add_reg (ir.regcache, ir.reg & 0x3))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (ir.reg);
       break;
 
       /* flags */
-      /* pushf */
-    case 0x9c:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      regcache_raw_read (ir.regcache, I386_ESP_REGNUM,
-                        (gdb_byte *) & tmpu32);
-      if (record_arch_list_add_mem
-         ((CORE_ADDR) tmpu32 - (1 << (ir.dflag + 1)), (1 << (ir.dflag + 1))))
-       return -1;
+    case 0x9c:    /* pushf */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
+      if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
+        ir.dflag = 2;
+      if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
+        return -1;
       break;
 
-      /* popf */
-    case 0x9d:
-      if (record_arch_list_add_reg (ir.regcache, I386_ESP_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+    case 0x9d:    /* popf */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* sahf */
-    case 0x9e:
-      /* cmc */
-    case 0xf5:
-      /* clc */
-    case 0xf8:
-      /* stc */
-    case 0xf9:
-      /* cld */
-    case 0xfc:
-      /* std */
-    case 0xfd:
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+    case 0x9e:    /* sahf */
+      if (ir.regmap[X86_RECORD_R8_REGNUM])
+        {
+          ir.addr -= 1;
+          goto no_support;
+        }
+    case 0xf5:    /* cmc */
+    case 0xf8:    /* clc */
+    case 0xf9:    /* stc */
+    case 0xfc:    /* cld */
+    case 0xfd:    /* std */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* lahf */
-    case 0x9f:
-      if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-       return -1;
+    case 0x9f:    /* lahf */
+      if (ir.regmap[X86_RECORD_R8_REGNUM])
+        {
+          ir.addr -= 1;
+          goto no_support;
+        }
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
       break;
 
       /* bit operations */
-      /* bt/bts/btr/btc Gv, im */
-    case 0x0fba:
-      /* bts */
-    case 0x0fab:
-      /* btr */
-    case 0x0fb3:
-      /* btc */
-    case 0x0fbb:
+    case 0x0fba:    /* bt/bts/btr/btc Gv, im */
       ir.ot = ir.dflag + OT_WORD;
       if (i386_record_modrm (&ir))
        return -1;
       if (ir.reg < 4)
        {
-         ir.addr -= 3;
+         ir.addr -= 2;
          opcode = opcode << 8 | ir.modrm;
          goto no_support;
        }
-      ir.reg -= 4;
-      if (ir.reg != 0)
+      if (ir.reg != 4)
        {
-         if (ir.mod != 3)
-           {
-             if (i386_record_lea_modrm (&ir))
-               return -1;
-           }
+          if (ir.mod == 3)
+            I386_RECORD_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
          else
            {
-             if (record_arch_list_add_reg (ir.regcache, ir.rm))
+             if (i386_record_lea_modrm (&ir))
                return -1;
            }
        }
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* bt Gv, Ev */
-    case 0x0fa3:
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+    case 0x0fa3:    /* bt Gv, Ev */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* bsf */
-    case 0x0fbc:
-      /* bsr */
-    case 0x0fbd:
-      if (record_arch_list_add_reg (ir.regcache, ir.reg))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+    case 0x0fab:    /* bts */
+    case 0x0fb3:    /* btr */
+    case 0x0fbb:    /* btc */
+      ir.ot = ir.dflag + OT_WORD;
+      if (i386_record_modrm (&ir))
+        return -1;
+      if (ir.mod == 3)
+        I386_RECORD_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
+      else
+        {
+          uint64_t tmpu64;
+          if (i386_record_lea_modrm_addr (&ir, &tmpu64))
+            return -1;
+          regcache_raw_read_unsigned (ir.regcache,
+                                      ir.regmap[ir.reg | rex_r],
+                                      &tmpulongest);
+          switch (ir.dflag)
+            {
+            case 0:
+              tmpu64 += ((int16_t) tmpulongest >> 4) << 4;
+              break;
+            case 1:
+              tmpu64 += ((int32_t) tmpulongest >> 5) << 5;
+              break;
+            case 2:
+              tmpu64 += ((int64_t) tmpulongest >> 6) << 6;
+              break;
+            }
+          if (record_arch_list_add_mem (tmpu64, 1 << ir.ot))
+            return -1;
+          if (i386_record_lea_modrm (&ir))
+            return -1;
+        }
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
+      break;
+
+    case 0x0fbc:    /* bsf */
+    case 0x0fbd:    /* bsr */
+      I386_RECORD_ARCH_LIST_ADD_REG (ir.reg | rex_r);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
       /* bcd */
-      /* daa */
-    case 0x27:
-      /* das */
-    case 0x2f:
-      /* aaa */
-    case 0x37:
-      /* aas */
-    case 0x3f:
-      /* aam */
-    case 0xd4:
-      /* aad */
-    case 0xd5:
-      if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+    case 0x27:    /* daa */
+    case 0x2f:    /* das */
+    case 0x37:    /* aaa */
+    case 0x3f:    /* aas */
+    case 0xd4:    /* aam */
+    case 0xd5:    /* aad */
+      if (ir.regmap[X86_RECORD_R8_REGNUM])
+        {
+          ir.addr -= 1;
+          goto no_support;
+        }
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
       /* misc */
-      /* nop */
-    case 0x90:
+    case 0x90:    /* nop */
       if (prefixes & PREFIX_LOCK)
        {
          ir.addr -= 1;
@@ -4613,35 +5071,38 @@ reswitch:
        }
       break;
 
-      /* fwait */
-      /* XXX */
-    case 0x9b:
-      printf_unfiltered (_("Process record doesn't support instruction "
-                          "fwait.\n"));
-      ir.addr -= 1;
-      goto no_support;
+    case 0x9b:    /* fwait */
+      if (target_read_memory (ir.addr, &tmpu8, 1))
+        {
+          if (record_debug)
+            printf_unfiltered (_("Process record: error reading memory at "
+                                "addr 0x%s len = 1.\n"),
+                              paddress (gdbarch, ir.addr));
+          return -1;
+        }
+      opcode = (uint32_t) tmpu8;
+      ir.addr++;
+      goto reswitch;
       break;
 
-      /* int3 */
       /* XXX */
-    case 0xcc:
+    case 0xcc:    /* int3 */
       printf_unfiltered (_("Process record doesn't support instruction "
                           "int3.\n"));
       ir.addr -= 1;
       goto no_support;
       break;
 
-      /* int */
       /* XXX */
-    case 0xcd:
+    case 0xcd:    /* int */
       {
        int ret;
        if (target_read_memory (ir.addr, &tmpu8, 1))
          {
            if (record_debug)
              printf_unfiltered (_("Process record: error reading memory "
-                                  "at addr 0x%s len = 1.\n"),
-                                paddr_nz (ir.addr));
+                                  "at addr %s len = 1.\n"),
+                                paddress (gdbarch, ir.addr));
            return -1;
          }
        ir.addr++;
@@ -4660,31 +5121,26 @@ reswitch:
       }
       break;
 
-      /* into */
       /* XXX */
-    case 0xce:
+    case 0xce:    /* into */
       printf_unfiltered (_("Process record doesn't support "
                           "instruction into.\n"));
       ir.addr -= 1;
       goto no_support;
       break;
 
-      /* cli */
-    case 0xfa:
-      /* sti */
-    case 0xfb:
+    case 0xfa:    /* cli */
+    case 0xfb:    /* sti */
       break;
 
-      /* bound */
-    case 0x62:
+    case 0x62:    /* bound */
       printf_unfiltered (_("Process record doesn't support "
                           "instruction bound.\n"));
       ir.addr -= 1;
       goto no_support;
       break;
 
-      /* bswap reg */
-    case 0x0fc8:
+    case 0x0fc8:    /* bswap reg */
     case 0x0fc9:
     case 0x0fca:
     case 0x0fcb:
@@ -4692,58 +5148,56 @@ reswitch:
     case 0x0fcd:
     case 0x0fce:
     case 0x0fcf:
-      if (record_arch_list_add_reg (ir.regcache, opcode & 7))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG ((opcode & 7) | ir.rex_b);
       break;
 
-      /* salc */
-    case 0xd6:
-      if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+    case 0xd6:    /* salc */
+      if (ir.regmap[X86_RECORD_R8_REGNUM])
+        {
+          ir.addr -= 1;
+          goto no_support;
+        }
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* loopnz */
-    case 0xe0:
-      /* loopz */
-    case 0xe1:
-      /* loop */
-    case 0xe2:
-      /* jecxz */
-    case 0xe3:
-      if (record_arch_list_add_reg (ir.regcache, I386_ECX_REGNUM))
-       return -1;
+    case 0xe0:    /* loopnz */
+    case 0xe1:    /* loopz */
+    case 0xe2:    /* loop */
+    case 0xe3:    /* jecxz */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* wrmsr */
-    case 0x0f30:
+    case 0x0f30:    /* wrmsr */
       printf_unfiltered (_("Process record doesn't support "
                           "instruction wrmsr.\n"));
       ir.addr -= 2;
       goto no_support;
       break;
 
-      /* rdmsr */
-    case 0x0f32:
+    case 0x0f32:    /* rdmsr */
       printf_unfiltered (_("Process record doesn't support "
                           "instruction rdmsr.\n"));
       ir.addr -= 2;
       goto no_support;
       break;
 
-      /* rdtsc */
-    case 0x0f31:
+    case 0x0f31:    /* rdtsc */
       printf_unfiltered (_("Process record doesn't support "
                           "instruction rdtsc.\n"));
       ir.addr -= 2;
       goto no_support;
       break;
 
-      /* sysenter */
-    case 0x0f34:
+    case 0x0f34:    /* sysenter */
       {
        int ret;
+        if (ir.regmap[X86_RECORD_R8_REGNUM])
+          {
+            ir.addr -= 2;
+            goto no_support;
+          }
        if (gdbarch_tdep (gdbarch)->i386_sysenter_record == NULL)
          {
            printf_unfiltered (_("Process record doesn't support "
@@ -4757,28 +5211,44 @@ reswitch:
       }
       break;
 
-      /* sysexit */
-    case 0x0f35:
+    case 0x0f35:    /* sysexit */
       printf_unfiltered (_("Process record doesn't support "
                           "instruction sysexit.\n"));
       ir.addr -= 2;
       goto no_support;
       break;
 
-      /* cpuid */
-    case 0x0fa2:
-      if (record_arch_list_add_reg (ir.regcache, I386_EAX_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_ECX_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EDX_REGNUM))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EBX_REGNUM))
-       return -1;
+    case 0x0f05:    /* syscall */
+      {
+       int ret;
+       if (gdbarch_tdep (gdbarch)->i386_syscall_record == NULL)
+         {
+           printf_unfiltered (_("Process record doesn't support "
+                                "instruction syscall.\n"));
+           ir.addr -= 2;
+           goto no_support;
+         }
+       ret = gdbarch_tdep (gdbarch)->i386_syscall_record (ir.regcache);
+       if (ret)
+         return ret;
+      }
       break;
 
-      /* hlt */
-    case 0xf4:
+    case 0x0f07:    /* sysret */
+      printf_unfiltered (_("Process record doesn't support "
+                           "instruction sysret.\n"));
+      ir.addr -= 2;
+      goto no_support;
+      break;
+
+    case 0x0fa2:    /* cpuid */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REBX_REGNUM);
+      break;
+
+    case 0xf4:    /* hlt */
       printf_unfiltered (_("Process record doesn't support "
                           "instruction hlt.\n"));
       ir.addr -= 1;
@@ -4790,15 +5260,10 @@ reswitch:
        return -1;
       switch (ir.reg)
        {
-         /* sldt */
-       case 0:
-         /* str */
-       case 1:
+       case 0:  /* sldt */
+       case 1:  /* str  */
          if (ir.mod == 3)
-           {
-             if (record_arch_list_add_reg (ir.regcache, ir.rm))
-               return -1;
-           }
+            I386_RECORD_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
          else
            {
              ir.ot = OT_WORD;
@@ -4806,17 +5271,12 @@ reswitch:
                return -1;
            }
          break;
-         /* lldt */
-       case 2:
-         /* ltr */
-       case 3:
+       case 2:  /* lldt */
+       case 3:  /* ltr */
          break;
-         /* verr */
-       case 4:
-         /* verw */
-       case 5:
-         if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-           return -1;
+       case 4:  /* verr */
+       case 5:  /* verw */
+          I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
          break;
        default:
          ir.addr -= 3;
@@ -4831,10 +5291,9 @@ reswitch:
        return -1;
       switch (ir.reg)
        {
-         /* sgdt */
-       case 0:
+       case 0:  /* sgdt */
          {
-           uint32_t addr;
+           uint64_t tmpu64;
 
            if (ir.mod == 3)
              {
@@ -4842,26 +5301,32 @@ reswitch:
                opcode = opcode << 8 | ir.modrm;
                goto no_support;
              }
-
-           if (ir.override)
+           if (ir.override >= 0)
              {
-               if (record_debug)
-                 printf_unfiltered (_("Process record ignores the memory "
-                                      "change of instruction at "
-                                      "address 0x%s because it can't get "
-                                      "the value of the segment "
-                                      "register.\n"),
-                                    paddr_nz (ir.addr));
+               warning (_("Process record ignores the memory "
+                           "change of instruction at "
+                           "address %s because it can't get "
+                           "the value of the segment "
+                           "register."),
+                         paddress (gdbarch, ir.orig_addr));
              }
            else
              {
-               if (i386_record_lea_modrm_addr (&ir, &addr))
-                 return -1;
-               if (record_arch_list_add_mem (addr, 2))
+               if (i386_record_lea_modrm_addr (&ir, &tmpu64))
                  return -1;
-               addr += 2;
-               if (record_arch_list_add_mem (addr, 4))
+               if (record_arch_list_add_mem (tmpu64, 2))
                  return -1;
+               tmpu64 += 2;
+                if (ir.regmap[X86_RECORD_R8_REGNUM])
+                  {
+                    if (record_arch_list_add_mem (tmpu64, 8))
+                     return -1;
+                  }
+                else
+                  {
+                    if (record_arch_list_add_mem (tmpu64, 4))
+                     return -1;
+                  }
              }
          }
          break;
@@ -4870,13 +5335,10 @@ reswitch:
            {
              switch (ir.rm)
                {
-                 /* monitor */
-               case 0:
+               case 0:  /* monitor */
                  break;
-                 /* mwait */
-               case 1:
-                 if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-                   return -1;
+               case 1:  /* mwait */
+                 I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
                  break;
                default:
                  ir.addr -= 3;
@@ -4888,37 +5350,52 @@ reswitch:
          else
            {
              /* sidt */
-             if (ir.override)
+             if (ir.override >= 0)
                {
-                 if (record_debug)
-                   printf_unfiltered (_("Process record ignores the memory "
-                                        "change of instruction at "
-                                        "address 0x%s because it can't get "
-                                        "the value of the segment "
-                                        "register.\n"),
-                                      paddr_nz (ir.addr));
+                 warning (_("Process record ignores the memory "
+                             "change of instruction at "
+                             "address %s because it can't get "
+                             "the value of the segment "
+                             "register."),
+                           paddress (gdbarch, ir.orig_addr));
                }
              else
                {
-                 uint32_t addr;
+                 uint64_t tmpu64;
 
-                 if (i386_record_lea_modrm_addr (&ir, &addr))
+                 if (i386_record_lea_modrm_addr (&ir, &tmpu64))
                    return -1;
-                 if (record_arch_list_add_mem (addr, 2))
+                 if (record_arch_list_add_mem (tmpu64, 2))
                    return -1;
                  addr += 2;
-                 if (record_arch_list_add_mem (addr, 4))
-                   return -1;
+                  if (ir.regmap[X86_RECORD_R8_REGNUM])
+                    {
+                      if (record_arch_list_add_mem (tmpu64, 8))
+                       return -1;
+                    }
+                  else
+                    {
+                      if (record_arch_list_add_mem (tmpu64, 4))
+                       return -1;
+                    }
                }
            }
          break;
-         /* lgdt */
-       case 2:
-         /* lidt */
-       case 3:
-         /* invlpg */
-       case 7:
-       default:
+       case 2:  /* lgdt */
+         if (ir.mod == 3)
+           {
+             /* xgetbv */
+             if (ir.rm == 0)
+               {
+                 I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
+                 I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
+                 break;
+               }
+             /* xsetbv */
+             else if (ir.rm == 1)
+               break;
+           }
+       case 3:  /* lidt */
          if (ir.mod == 3)
            {
              ir.addr -= 3;
@@ -4926,11 +5403,10 @@ reswitch:
              goto no_support;
            }
          break;
-         /* smsw */
-       case 4:
+       case 4:  /* smsw */
          if (ir.mod == 3)
            {
-             if (record_arch_list_add_reg (ir.regcache, ir.rm))
+             if (record_arch_list_add_reg (ir.regcache, ir.rm | ir.rex_b))
                return -1;
            }
          else
@@ -4939,54 +5415,75 @@ reswitch:
              if (i386_record_lea_modrm (&ir))
                return -1;
            }
+         I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
          break;
-         /* lmsw */
-       case 6:
+       case 6:  /* lmsw */
+         I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
+         break;
+       case 7:  /* invlpg */
+         if (ir.mod == 3)
+           {
+             if (ir.rm == 0 && ir.regmap[X86_RECORD_R8_REGNUM])
+               I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_GS_REGNUM);
+             else
+               {
+                 ir.addr -= 3;
+                 opcode = opcode << 8 | ir.modrm;
+                 goto no_support;
+               }
+           }
+         else
+           I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
+         break;
+       default:
+         ir.addr -= 3;
+         opcode = opcode << 8 | ir.modrm;
+         goto no_support;
          break;
        }
       break;
 
-      /* invd */
-    case 0x0f08:
-      /* wbinvd */
-    case 0x0f09:
+    case 0x0f08:    /* invd */
+    case 0x0f09:    /* wbinvd */
       break;
 
-      /* arpl */
-    case 0x63:
-      ir.ot = ir.dflag ? OT_LONG : OT_WORD;
+    case 0x63:    /* arpl */
       if (i386_record_modrm (&ir))
        return -1;
-      if (ir.mod != 3)
-       {
-         if (i386_record_lea_modrm (&ir))
-           return -1;
-       }
+      if (ir.mod == 3 || ir.regmap[X86_RECORD_R8_REGNUM])
+        {
+          I386_RECORD_ARCH_LIST_ADD_REG (ir.regmap[X86_RECORD_R8_REGNUM]
+                                          ? (ir.reg | rex_r) : ir.rm);
+        }
       else
-       {
-         if (record_arch_list_add_reg (ir.regcache, ir.rm))
-           return -1;
-       }
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+        {
+          ir.ot = ir.dflag ? OT_LONG : OT_WORD;
+          if (i386_record_lea_modrm (&ir))
+            return -1;
+        }
+      if (!ir.regmap[X86_RECORD_R8_REGNUM])
+        I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
-      /* lar */
-    case 0x0f02:
-      /* lsl */
-    case 0x0f03:
+    case 0x0f02:    /* lar */
+    case 0x0f03:    /* lsl */
       if (i386_record_modrm (&ir))
        return -1;
-      if (record_arch_list_add_reg (ir.regcache, ir.reg))
-       return -1;
-      if (record_arch_list_add_reg (ir.regcache, I386_EFLAGS_REGNUM))
-       return -1;
+      I386_RECORD_ARCH_LIST_ADD_REG (ir.reg | rex_r);
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
     case 0x0f18:
+      if (i386_record_modrm (&ir))
+       return -1;
+      if (ir.mod == 3 && ir.reg == 3)
+        {
+         ir.addr -= 3;
+         opcode = opcode << 8 | ir.modrm;
+         goto no_support;
+       }
       break;
 
-      /* nop (multi byte) */
     case 0x0f19:
     case 0x0f1a:
     case 0x0f1b:
@@ -4994,17 +5491,16 @@ reswitch:
     case 0x0f1d:
     case 0x0f1e:
     case 0x0f1f:
+      /* nop (multi byte) */
       break;
 
-      /* mov reg, crN */
-    case 0x0f20:
-      /* mov crN, reg */
-    case 0x0f22:
+    case 0x0f20:    /* mov reg, crN */
+    case 0x0f22:    /* mov crN, reg */
       if (i386_record_modrm (&ir))
        return -1;
       if ((ir.modrm & 0xc0) != 0xc0)
        {
-         ir.addr -= 2;
+         ir.addr -= 3;
          opcode = opcode << 8 | ir.modrm;
          goto no_support;
        }
@@ -5016,47 +5512,37 @@ reswitch:
        case 4:
        case 8:
          if (opcode & 2)
-           {
-           }
+           I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
          else
-           {
-             if (record_arch_list_add_reg (ir.regcache, ir.rm))
-               return -1;
-           }
+            I386_RECORD_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
          break;
        default:
-         ir.addr -= 2;
+         ir.addr -= 3;
          opcode = opcode << 8 | ir.modrm;
          goto no_support;
          break;
        }
       break;
 
-      /* mov reg, drN */
-    case 0x0f21:
-      /* mov drN, reg */
-    case 0x0f23:
+    case 0x0f21:    /* mov reg, drN */
+    case 0x0f23:    /* mov drN, reg */
       if (i386_record_modrm (&ir))
        return -1;
       if ((ir.modrm & 0xc0) != 0xc0 || ir.reg == 4
          || ir.reg == 5 || ir.reg >= 8)
        {
-         ir.addr -= 2;
+         ir.addr -= 3;
          opcode = opcode << 8 | ir.modrm;
          goto no_support;
        }
       if (opcode & 2)
-       {
-       }
+        I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       else
-       {
-         if (record_arch_list_add_reg (ir.regcache, ir.rm))
-           return -1;
-       }
+       I386_RECORD_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
       break;
 
-      /* clts */
-    case 0x0f06:
+    case 0x0f06:    /* clts */
+      I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
       break;
 
       /* MMX/SSE/SSE2/PNI support */
@@ -5071,21 +5557,72 @@ reswitch:
       break;
     }
 
-/* In the future, Maybe still need to deal with need_dasm */
-  if (record_arch_list_add_reg (ir.regcache, I386_EIP_REGNUM))
-    return -1;
+  /* In the future, maybe still need to deal with need_dasm.  */
+  I386_RECORD_ARCH_LIST_ADD_REG (X86_RECORD_REIP_REGNUM);
   if (record_arch_list_add_end ())
     return -1;
 
   return 0;
 
-no_support:
+ no_support:
   printf_unfiltered (_("Process record doesn't support instruction 0x%02x "
-                      "at address 0x%s.\n"),
-                    (unsigned int) (opcode), paddr_nz (ir.addr));
+                      "at address %s.\n"),
+                    (unsigned int) (opcode), paddress (gdbarch, ir.addr));
   return -1;
 }
 
+static const int i386_record_regmap[] =
+{
+  I386_EAX_REGNUM, I386_ECX_REGNUM, I386_EDX_REGNUM, I386_EBX_REGNUM,
+  I386_ESP_REGNUM, I386_EBP_REGNUM, I386_ESI_REGNUM, I386_EDI_REGNUM,
+  0, 0, 0, 0, 0, 0, 0, 0,
+  I386_EIP_REGNUM, I386_EFLAGS_REGNUM, I386_CS_REGNUM, I386_SS_REGNUM,
+  I386_DS_REGNUM, I386_ES_REGNUM, I386_FS_REGNUM, I386_GS_REGNUM
+};
+
+/* Check that the given address appears suitable for a fast
+   tracepoint, which on x86 means that we need an instruction of at
+   least 5 bytes, so that we can overwrite it with a 4-byte-offset
+   jump and not have to worry about program jumps to an address in the
+   middle of the tracepoint jump.  Returns 1 if OK, and writes a size
+   of instruction to replace, and 0 if not, plus an explanatory
+   string.  */
+
+static int
+i386_fast_tracepoint_valid_at (struct gdbarch *gdbarch,
+                              CORE_ADDR addr, int *isize, char **msg)
+{
+  int len, jumplen;
+  static struct ui_file *gdb_null = NULL;
+
+  /* This is based on the target agent using a 4-byte relative jump.
+     Alternate future possibilities include 8-byte offset for x86-84,
+     or 3-byte jumps if the program has trampoline space close by.  */
+  jumplen = 5;
+
+  /* Dummy file descriptor for the disassembler.  */
+  if (!gdb_null)
+    gdb_null = ui_file_new ();
+
+  /* Check for fit.  */
+  len = gdb_print_insn (gdbarch, addr, gdb_null, NULL);
+  if (len < jumplen)
+    {
+      /* Return a bit of target-specific detail to add to the caller's
+        generic failure message.  */
+      if (msg)
+       *msg = xstrprintf (_("; instruction is only %d bytes long, need at least %d bytes for the jump"),
+                          len, jumplen);
+      return 0;
+    }
+
+  if (isize)
+    *isize = len;
+  if (msg)
+    *msg = NULL;
+  return 1;
+}
+
 \f
 static struct gdbarch *
 i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
@@ -5146,6 +5683,8 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   tdep->sc_pc_offset = -1;
   tdep->sc_sp_offset = -1;
 
+  tdep->record_regmap = i386_record_regmap;
+
   /* The format used for `long double' on almost all i386 targets is
      the i387 extended floating-point format.  In fact, of all targets
      in the GCC 2.95 tree, only OSF/1 does it different, and insists
@@ -5251,7 +5790,15 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* Helper for function argument information.  */
   set_gdbarch_fetch_pointer_argument (gdbarch, i386_fetch_pointer_argument);
 
-  /* Hook in the DWARF CFI frame unwinder.  */
+  /* Hook the function epilogue frame unwinder.  This unwinder is
+     appended to the list first, so that it supercedes the Dwarf
+     unwinder in function epilogues (where the Dwarf unwinder
+     currently fails).  */
+  frame_unwind_append_unwinder (gdbarch, &i386_epilogue_frame_unwind);
+
+  /* Hook in the DWARF CFI frame unwinder.  This unwinder is appended
+     to the list before the prologue-based unwinders, so that Dwarf
+     CFI info will be used if it is available.  */
   dwarf2_append_unwinders (gdbarch);
 
   frame_base_set_default (gdbarch, &i386_frame_base);
@@ -5259,6 +5806,7 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* Hook in ABI-specific overrides, if they have been registered.  */
   gdbarch_init_osabi (info, gdbarch);
 
+  /* Hook in the legacy prologue-based unwinders last (fallback).  */
   frame_unwind_append_unwinder (gdbarch, &i386_sigtramp_frame_unwind);
   frame_unwind_append_unwinder (gdbarch, &i386_frame_unwind);
 
@@ -5277,7 +5825,8 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_skip_permanent_breakpoint (gdbarch,
                                         i386_skip_permanent_breakpoint);
 
-  set_gdbarch_process_record (gdbarch, i386_process_record);
+  set_gdbarch_fast_tracepoint_valid_at (gdbarch,
+                                       i386_fast_tracepoint_valid_at);
 
   return gdbarch;
 }
@@ -5331,7 +5880,6 @@ is \"default\"."),
   gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_GO32,
                          i386_go32_init_abi);
 
-  /* Initialize the i386-specific register groups & types.  */
+  /* Initialize the i386-specific register groups.  */
   i386_init_reggroups ();
-  i386_init_types();
 }
This page took 0.0792 seconds and 4 git commands to generate.