This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Implement $sp/$eip and $pc/$eip for x32


On Mon, May 14, 2012 at 11:35 AM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
>> Date: Fri, 11 May 2012 18:00:07 -0700
>> From: "H.J. Lu" <hongjiu.lu@intel.com>
>>
>> Hi,
>>
>> This patch on top of
>>
>> http://sourceware.org/ml/gdb-patches/2012-04/msg00191.html
>>
>> implements $sp/$eip and $pc/$eip for x32. ?OK to install?
>
> Sorry, no. ?You should not add "eip" to the list of pseudo registers
> for "regular" amd64.

Here is a patch which only adds "eip" to x32.   OK to install?

Thanks.

-- 
H.J.
---
	* amd64-tdep.c (amd64_dword_names): Add "".
	(amd64_pseudo_register_type): New function.
	(amd64_pseudo_register_name): Return "eip" for x32.
	(amd64_init_abi): Set num_dword_regs to 17.  Call
	set_tdesc_pseudo_register_type with amd64_pseudo_register_type.

	* i386-tdep.c (i386_pseudo_register_type): Make it global.
	* i386-tdep.h (i386_pseudo_register_type): New prototype.

diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 35d849b..2cbe718 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -258,9 +258,34 @@ static const char *amd64_word_names[] =
 static const char *amd64_dword_names[] =
 {
   "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp", "esp",
-  "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d"
+  "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d", ""
 };

+/* Return the GDB type object for the "standard" data type of data in
+   register REGNUM.  */
+
+static struct type *
+amd64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
+{
+  /* Use pointer types for ebp, esp and eip registers in x32.  */
+  if (gdbarch_ptr_bit (gdbarch) == 32)
+    {
+      struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+      switch (regnum - tdep->eax_regnum)
+	{
+	default:
+	  break;
+	case AMD64_RBP_REGNUM:	/* ebp  */
+	case AMD64_RSP_REGNUM:	/* esp	*/
+	  return builtin_type (gdbarch)->builtin_data_ptr;
+	case AMD64_RIP_REGNUM:	/* eip */
+	  return builtin_type (gdbarch)->builtin_func_ptr;
+	}
+    }
+
+  return i386_pseudo_register_type (gdbarch, regnum);
+}
+
 /* Return the name of register REGNUM.  */

 static const char *
@@ -274,7 +299,13 @@ amd64_pseudo_register_name (struct gdbarch
*gdbarch, int regnum)
   else if (i386_word_regnum_p (gdbarch, regnum))
     return amd64_word_names[regnum - tdep->ax_regnum];
   else if (i386_dword_regnum_p (gdbarch, regnum))
-    return amd64_dword_names[regnum - tdep->eax_regnum];
+    {
+      regnum -= tdep->eax_regnum;
+      if (gdbarch_ptr_bit (gdbarch) == 32
+	  && regnum == AMD64_RIP_REGNUM)
+	return "eip";
+      return amd64_dword_names[regnum];
+    }
   else
     return i386_pseudo_register_name (gdbarch, regnum);
 }
@@ -1713,7 +1744,7 @@ amd64_alloc_frame_cache (void)

 static CORE_ADDR
 amd64_analyze_stack_align (CORE_ADDR pc, CORE_ADDR current_pc,
-			   struct amd64_frame_cache *cache)
+			   struct amd64_frame_cache *cache, int is_x32)
 {
   /* There are 2 code sequences to re-align stack before the frame
      gets set up:
@@ -2632,7 +2703,7 @@ amd64_init_abi (struct gdbarch_info info, struct
gdbarch *gdbarch)

   tdep->num_byte_regs = 20;
   tdep->num_word_regs = 16;
-  tdep->num_dword_regs = 16;
+  tdep->num_dword_regs = 17;
   /* Avoid wiring in the MMX registers for now.  */
   tdep->num_mmx_regs = 0;

@@ -2641,6 +2712,7 @@ amd64_init_abi (struct gdbarch_info info, struct
gdbarch *gdbarch)
   set_gdbarch_pseudo_register_write (gdbarch,
 				     amd64_pseudo_register_write);

+  set_tdesc_pseudo_register_type (gdbarch, amd64_pseudo_register_type);
   set_tdesc_pseudo_register_name (gdbarch, amd64_pseudo_register_name);

   /* AMD64 has an FPU and 16 SSE registers.  */
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 0106eae..639ba97 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -2781,7 +2781,7 @@ i386_mmx_type (struct gdbarch *gdbarch)
 /* Return the GDB type object for the "standard" data type of data in
    register REGNUM.  */

-static struct type *
+struct type *
 i386_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
   if (i386_mmx_regnum_p (gdbarch, regnum))
diff --git a/gdb/i386-tdep.h b/gdb/i386-tdep.h
index 0eec1fb..e1f7c44 100644
--- a/gdb/i386-tdep.h
+++ b/gdb/i386-tdep.h
@@ -315,6 +315,7 @@ extern int i386_dword_regnum_p (struct gdbarch
*gdbarch, int regnum);
 extern int i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum);
 extern int i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum);

+extern struct type *i386_pseudo_register_type (struct gdbarch *, int);
 extern const char *i386_pseudo_register_name (struct gdbarch *gdbarch,
 					      int regnum);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]