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 Tue, May 15, 2012 at 7:34 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> 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?
>

A small update to avoid amd64_dword_names change.  OK to
instal?

Thanks.

-- 
H.J.
---
	* amd64-tdep.c (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 df91a51..18a60b9 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -261,6 +261,31 @@ static const char *amd64_dword_names[] =
   "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,12 @@ 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 (regnum == AMD64_RIP_REGNUM)
+	return gdbarch_ptr_bit (gdbarch) == 32 ? "eip" : "";
+      return amd64_dword_names[regnum];
+    }
   else
     return i386_pseudo_register_name (gdbarch, regnum);
 }
@@ -2632,7 +2702,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 +2711,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 5b04505..9cc2e30 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -2780,7 +2780,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 f297ae7..e1f7c44 100644
--- a/gdb/i386-tdep.h
+++ b/gdb/i386-tdep.h
@@ -307,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]