Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Mark Kettenis <mark.kettenis@xs4all.nl>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/3] Add sp_regnum_from_eax and pc_regnum_from_eax
Date: Tue, 03 Jul 2012 23:56:00 -0000	[thread overview]
Message-ID: <CAMe9rOobeeBvmYkMeqBsFkqz5ybxbuwLZKpRt_HJmj-fNf0i6Q@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOr3xrN43vnvH7Y3fDYwXMVYQ7pTRsOYiOBeMicoa59tRA@mail.gmail.com>

On Tue, Jul 3, 2012 at 12:14 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Jul 3, 2012 at 10:35 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Tue, Jul 3, 2012 at 8:54 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Tue, Jul 3, 2012 at 7:08 AM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
>>>>> Date: Thu, 21 Jun 2012 11:14:52 -0700
>>>>> From: "H.J. Lu" <hongjiu.lu@intel.com>
>>>>>
>>>>> Hi,
>>>>>
>>>>> Here are the first of the last 3 patches for x32 support in GDB.  This
>>>>> patch maps $pc to $eip and $sp to $esp for x32.  OK to install?
>>>>
>>>> The pseudo register handling code is getting too complex :(.  I feel
>>>> that hiding the set_gdbarch_pc_regnum() and set_gdbarch_sp_regnum()
>>>> calls in i386-tdep.c isn't the right approach.  But I haven't found a
>>>> better one yet :(.
>>>>
>>>
>>> One possibility is to set pc/sp to register name instead of regnum.
>>> i386_gdbarch_init can map them to regnum after all pseudo registers
>>> are finalized.
>>>
>>> --
>>> H.J.
>>
>> How about this patch? I can also change amd64 and i386
>> to use "rsp/"rsp"/"esp"/"eip".
>>
>
> This patch sets SP?PC regnums from register names.
>
>

Here is another approach to set SP/PC regnums after
setting up pseudo registers.

-- 
H.J.
---
	* amd64-tdep.c (amd64_init_abi): Set sp_regnum to AMD64_RSP_REGNUM
	and set pc_regnum to AMD64_RIP_REGNUM.  Don't call
	set_gdbarch_sp_regnum nor set_gdbarch_pc_regnum here.
	(amd64_x32_init_abi): Set sp_regnum to -AMD64_RSP_REGNUM and set
	pc_regnum to -AMD64_RIP_REGNUM.

	* i386-tdep.c (i386_gdbarch_init): Set sp_regnum to I386_ESP_REGNUM
	and set pc_regnum to I386_EIP_REGNUM.  Call set_gdbarch_sp_regnum
	and set_gdbarch_pc_regnum after setting up pseudo registers.

	* i386-tdep.h (gdbarch_tdep): Add sp_regnum and pc_regnum.

diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 8ae1142..df0df08 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -2846,8 +2846,8 @@ amd64_init_abi (struct gdbarch_info info, struct
gdbarch *gdbarch)
   set_gdbarch_num_regs (gdbarch, AMD64_NUM_REGS);

   /* Register numbers of various important registers.  */
-  set_gdbarch_sp_regnum (gdbarch, AMD64_RSP_REGNUM); /* %rsp */
-  set_gdbarch_pc_regnum (gdbarch, AMD64_RIP_REGNUM); /* %rip */
+  tdep->sp_regnum = AMD64_RSP_REGNUM; /* %rsp */
+  tdep->pc_regnum = AMD64_RIP_REGNUM; /* %rip */
   set_gdbarch_ps_regnum (gdbarch, AMD64_EFLAGS_REGNUM); /* %eflags */
   set_gdbarch_fp0_regnum (gdbarch, AMD64_ST0_REGNUM); /* %st(0) */

@@ -2946,6 +2946,9 @@ amd64_x32_init_abi (struct gdbarch_info info,
struct gdbarch *gdbarch)
     tdesc = tdesc_x32;
   tdep->tdesc = tdesc;

+  tdep->sp_regnum = -AMD64_RSP_REGNUM; /* %esp */
+  tdep->pc_regnum = -AMD64_RIP_REGNUM; /* %eip */
+
   tdep->num_dword_regs = 17;
   set_tdesc_pseudo_register_type (gdbarch, amd64_x32_pseudo_register_type);

diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index fd5969d..a287785 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -7671,8 +7671,8 @@ i386_gdbarch_init (struct gdbarch_info info,
struct gdbarch_list *arches)
   set_gdbarch_long_double_bit (gdbarch, 96);

   /* Register numbers of various important registers.  */
-  set_gdbarch_sp_regnum (gdbarch, I386_ESP_REGNUM); /* %esp */
-  set_gdbarch_pc_regnum (gdbarch, I386_EIP_REGNUM); /* %eip */
+  tdep->sp_regnum = I386_ESP_REGNUM; /* %esp */
+  tdep->pc_regnum = I386_EIP_REGNUM; /* %eip */
   set_gdbarch_ps_regnum (gdbarch, I386_EFLAGS_REGNUM); /* %eflags */
   set_gdbarch_fp0_regnum (gdbarch, I386_ST0_REGNUM); /* %st(0) */

@@ -7871,6 +7871,16 @@ i386_gdbarch_init (struct gdbarch_info info,
struct gdbarch_list *arches)
   else
     tdep->mm0_regnum = -1;

+  /* Set up SP and PC register numbers.  */
+  set_gdbarch_sp_regnum (gdbarch,
+			 tdep->sp_regnum >= 0
+			 ? tdep->sp_regnum
+			 : tdep->eax_regnum - tdep->sp_regnum);
+  set_gdbarch_pc_regnum (gdbarch,
+			 tdep->pc_regnum >= 0
+			 ? tdep->pc_regnum
+			 : tdep->eax_regnum - tdep->pc_regnum);
+
   /* Hook in the legacy prologue-based unwinders last (fallback).  */
   frame_unwind_append_unwinder (gdbarch, &i386_stack_tramp_frame_unwind);
   frame_unwind_append_unwinder (gdbarch, &i386_sigtramp_frame_unwind);
diff --git a/gdb/i386-tdep.h b/gdb/i386-tdep.h
index 5f233f5..99b5f42 100644
--- a/gdb/i386-tdep.h
+++ b/gdb/i386-tdep.h
@@ -149,6 +149,14 @@ struct gdbarch_tdep
      of pseudo dword register support.  */
   int eax_regnum;

+  /* Register number for SP.  If it < 0, SP register number is
+     eax_regnum - sp_regnum.  */
+  int sp_regnum;
+
+  /* Register number for PC.  If it < 0, PC register number is
+     eax_regnum - pc_regnum.  */
+  int pc_regnum;
+
   /* Number of core registers.  */
   int num_core_regs;


  reply	other threads:[~2012-07-03 23:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-21 18:15 H.J. Lu
2012-07-03 14:08 ` Mark Kettenis
2012-07-03 15:54   ` H.J. Lu
2012-07-03 17:35     ` H.J. Lu
2012-07-03 19:15       ` H.J. Lu
2012-07-03 23:56         ` H.J. Lu [this message]
2012-07-04 19:53           ` Mark Kettenis
2012-07-04 20:51             ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMe9rOobeeBvmYkMeqBsFkqz5ybxbuwLZKpRt_HJmj-fNf0i6Q@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=mark.kettenis@xs4all.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox