Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Hui Zhu <teawater@gmail.com>
To: Mark Kettenis <mark.kettenis@xs4all.nl>
Cc: gdb-patches@sourceware.org, msnyder@vmware.com
Subject: Re: [RFA] Make the prec support signal better[3/4] -- i386-linux
Date: Thu, 10 Sep 2009 01:51:00 -0000	[thread overview]
Message-ID: <daef60380909091851s2a3cd485q7cd1c3ab342895c9@mail.gmail.com> (raw)
In-Reply-To: <200909091345.n89DjW0u028957@brahms.sibelius.xs4all.nl>

[-- Attachment #1: Type: text/plain, Size: 6884 bytes --]

Thanks Mark.

On Wed, Sep 9, 2009 at 21:45, Mark Kettenis<mark.kettenis@xs4all.nl> wrote:
>> From: Hui Zhu <teawater@gmail.com>
>> Date: Wed, 9 Sep 2009 21:29:07 +0800
>>
>> This patch make i386-linux support signal record.
>> When signal happen, i386_linux_record_signal will record the change.
>> When the signal handler want return, new code in
>> "i386_linux_intx80_sysenter_record" will record the change.
>>
>>  i386-linux-tdep.c |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 71 insertions(+)
>>
>> --- a/i386-linux-tdep.c
>> +++ b/i386-linux-tdep.c
>> @@ -354,6 +354,33 @@ i386_linux_write_pc (struct regcache *re
>>    regcache_cooked_write_unsigned (regcache, I386_LINUX_ORIG_EAX_REGNUM, -1);
>>  }
>>
>> +/* Record all registers for process-record.  */
>
> Not quite true isn't it?

I will update it.

>
>> +static int
>> +i386_all_but_ip_registers_record (struct regcache *regcache)
>> +{
>> +  if (record_arch_list_add_reg (regcache, I386_EAX_REGNUM))
>> +    return -1;
>> +  if (record_arch_list_add_reg (regcache, I386_ECX_REGNUM))
>> +    return -1;
>> +  if (record_arch_list_add_reg (regcache, I386_EDX_REGNUM))
>> +    return -1;
>> +  if (record_arch_list_add_reg (regcache, I386_EBX_REGNUM))
>> +    return -1;
>> +  if (record_arch_list_add_reg (regcache, I386_ESP_REGNUM))
>> +    return -1;
>> +  if (record_arch_list_add_reg (regcache, I386_EBP_REGNUM))
>> +    return -1;
>> +  if (record_arch_list_add_reg (regcache, I386_ESI_REGNUM))
>> +    return -1;
>> +  if (record_arch_list_add_reg (regcache, I386_EDI_REGNUM))
>> +    return -1;
>> +  if (record_arch_list_add_reg (regcache, I386_EFLAGS_REGNUM))
>> +    return -1;
>> +
>> +  return 0;
>> +}
>
> Why exactly is it that you're not recording the instruction pointer?

This is because this function will be called by
"i386_linux_intx80_sysenter_record", this function will be called by
i386_process_record,  i386_process_record will record the ip when
return, so i386_linux_intx80_sysenter_record don't need record ip.

>
>>  static struct linux_record_tdep i386_linux_record_tdep;
>>
>>  /* i386_canonicalize_syscall maps from the native i386 Linux set
>> @@ -388,6 +415,14 @@ i386_linux_intx80_sysenter_record (struc
>>
>>    regcache_raw_read_signed (regcache, I386_EAX_REGNUM, &syscall_native);
>>
>> +  if (syscall_native == 119 || syscall_native == 173)
>> +   {
>
> Ugh, magic numbers.  We have symbolic constants for them isn't it?
> Any reason not to use them?

I will fix them.

>
>> +enum i386_linux_signal_stack {
>> +  xstate = 270,
>> +  frame_size = 732,
>> +};
>
> IMHO, these should be #define's, spelled with all capitals and have
> I386_LINUX_ prefixes.
>

I will fix them.

I make a new patch for it.  Please help me with it.

Hui

2009-09-10  Michael Snyder  <msnyder@vmware.com>
	    Hui Zhu  <teawater@gmail.com>

	* i386-linux-tdep.c (i386_all_but_ip_registers_record): New
	function.
	(i386_linux_intx80_sysenter_record): Call
	i386_all_but_ip_registers_record if syscall is sys_sigreturn
	or sys_rt_sigreturn.
	(I386_LINUX_xstate, I386_LINUX_frame_size): New macros.
	(i386_linux_record_signal): New function.
	(i386_linux_init_abi): Call set_gdbarch_process_record_signal.

---
 i386-linux-tdep.c |   72 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 1 deletion(-)

--- a/i386-linux-tdep.c
+++ b/i386-linux-tdep.c
@@ -354,7 +354,32 @@ i386_linux_write_pc (struct regcache *re
   regcache_cooked_write_unsigned (regcache, I386_LINUX_ORIG_EAX_REGNUM, -1);
 }

-static struct linux_record_tdep i386_linux_record_tdep;
+/* Record all registers but IP register for process-record.  */
+
+static int
+i386_all_but_ip_registers_record (struct regcache *regcache)
+{
+  if (record_arch_list_add_reg (regcache, I386_EAX_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_ECX_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_EDX_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_EBX_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_ESP_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_EBP_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_ESI_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_EDI_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_EFLAGS_REGNUM))
+    return -1;
+
+  return 0;
+}

 /* i386_canonicalize_syscall maps from the native i386 Linux set
    of syscall ids into a canonical set of syscall ids used by
@@ -379,6 +404,8 @@ i386_canonicalize_syscall (int syscall)

    Return -1 if something wrong.  */

+static struct linux_record_tdep i386_linux_record_tdep;
+
 static int
 i386_linux_intx80_sysenter_record (struct regcache *regcache)
 {
@@ -398,6 +425,14 @@ i386_linux_intx80_sysenter_record (struc
       return -1;
     }

+  if (syscall_gdb == gdb_sys_sigreturn
+      || syscall_gdb == gdb_sys_rt_sigreturn)
+   {
+     if (i386_all_but_ip_registers_record (regcache))
+       return -1;
+     return 0;
+   }
+
   ret = record_linux_system_call (syscall_gdb, regcache,
 				  &i386_linux_record_tdep);
   if (ret)
@@ -409,6 +444,40 @@ i386_linux_intx80_sysenter_record (struc

   return 0;
 }
+
+#define I386_LINUX_xstate	270
+#define I386_LINUX_frame_size	732
+
+int
+i386_linux_record_signal (struct gdbarch *gdbarch,
+                          struct regcache *regcache,
+                          enum target_signal signal)
+{
+  ULONGEST esp;
+
+  if (i386_all_but_ip_registers_record (regcache))
+    return -1;
+
+  if (record_arch_list_add_reg (regcache, I386_EIP_REGNUM))
+    return -1;
+
+  /* Record the change in the stack.  */
+  regcache_raw_read_unsigned (regcache, I386_ESP_REGNUM, &esp);
+  /* This is for xstate.
+     sp -= sizeof (struct _fpstate);  */
+  esp -= I386_LINUX_xstate;
+  /* This is for frame_size.
+     sp -= sizeof (struct rt_sigframe);  */
+  esp -= I386_LINUX_frame_size;
+  if (record_arch_list_add_mem (esp,
+                                I386_LINUX_xstate + I386_LINUX_frame_size))
+    return -1;
+
+  if (record_arch_list_add_end ())
+    return -1;
+
+  return 0;
+}


 /* The register sets used in GNU/Linux ELF core-dumps are identical to
@@ -504,6 +573,7 @@ i386_linux_init_abi (struct gdbarch_info
   tdep->sc_num_regs = ARRAY_SIZE (i386_linux_sc_reg_offset);

   set_gdbarch_process_record (gdbarch, i386_process_record);
+  set_gdbarch_process_record_signal (gdbarch, i386_linux_record_signal);

   /* Initialize the i386_linux_record_tdep.  */
   /* These values are the size of the type that will be used in a system

[-- Attachment #2: prec-support-signal-i386-linux.txt --]
[-- Type: text/plain, Size: 3460 bytes --]

---
 i386-linux-tdep.c |   72 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 1 deletion(-)

--- a/i386-linux-tdep.c
+++ b/i386-linux-tdep.c
@@ -354,7 +354,32 @@ i386_linux_write_pc (struct regcache *re
   regcache_cooked_write_unsigned (regcache, I386_LINUX_ORIG_EAX_REGNUM, -1);
 }
 
-static struct linux_record_tdep i386_linux_record_tdep;
+/* Record all registers but IP register for process-record.  */
+
+static int
+i386_all_but_ip_registers_record (struct regcache *regcache)
+{
+  if (record_arch_list_add_reg (regcache, I386_EAX_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_ECX_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_EDX_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_EBX_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_ESP_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_EBP_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_ESI_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_EDI_REGNUM))
+    return -1;
+  if (record_arch_list_add_reg (regcache, I386_EFLAGS_REGNUM))
+    return -1;
+
+  return 0;
+}
 
 /* i386_canonicalize_syscall maps from the native i386 Linux set
    of syscall ids into a canonical set of syscall ids used by
@@ -379,6 +404,8 @@ i386_canonicalize_syscall (int syscall)
 
    Return -1 if something wrong.  */
 
+static struct linux_record_tdep i386_linux_record_tdep;
+
 static int
 i386_linux_intx80_sysenter_record (struct regcache *regcache)
 {
@@ -398,6 +425,14 @@ i386_linux_intx80_sysenter_record (struc
       return -1;
     }
 
+  if (syscall_gdb == gdb_sys_sigreturn
+      || syscall_gdb == gdb_sys_rt_sigreturn)
+   {
+     if (i386_all_but_ip_registers_record (regcache))
+       return -1;
+     return 0;
+   }
+
   ret = record_linux_system_call (syscall_gdb, regcache,
 				  &i386_linux_record_tdep);
   if (ret)
@@ -409,6 +444,40 @@ i386_linux_intx80_sysenter_record (struc
 
   return 0;
 }
+
+#define I386_LINUX_xstate	270
+#define I386_LINUX_frame_size	732
+
+int
+i386_linux_record_signal (struct gdbarch *gdbarch,
+                          struct regcache *regcache,
+                          enum target_signal signal)
+{
+  ULONGEST esp;
+
+  if (i386_all_but_ip_registers_record (regcache))
+    return -1;
+
+  if (record_arch_list_add_reg (regcache, I386_EIP_REGNUM))
+    return -1;
+
+  /* Record the change in the stack.  */
+  regcache_raw_read_unsigned (regcache, I386_ESP_REGNUM, &esp);
+  /* This is for xstate.
+     sp -= sizeof (struct _fpstate);  */
+  esp -= I386_LINUX_xstate;
+  /* This is for frame_size.
+     sp -= sizeof (struct rt_sigframe);  */
+  esp -= I386_LINUX_frame_size;
+  if (record_arch_list_add_mem (esp,
+                                I386_LINUX_xstate + I386_LINUX_frame_size))
+    return -1;
+
+  if (record_arch_list_add_end ())
+    return -1;
+
+  return 0;
+}
 \f
 
 /* The register sets used in GNU/Linux ELF core-dumps are identical to
@@ -504,6 +573,7 @@ i386_linux_init_abi (struct gdbarch_info
   tdep->sc_num_regs = ARRAY_SIZE (i386_linux_sc_reg_offset);
 
   set_gdbarch_process_record (gdbarch, i386_process_record);
+  set_gdbarch_process_record_signal (gdbarch, i386_linux_record_signal);
 
   /* Initialize the i386_linux_record_tdep.  */
   /* These values are the size of the type that will be used in a system

      reply	other threads:[~2009-09-10  1:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-09 13:29 Hui Zhu
2009-09-09 13:45 ` Mark Kettenis
2009-09-10  1:51   ` Hui Zhu [this message]

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=daef60380909091851s2a3cd485q7cd1c3ab342895c9@mail.gmail.com \
    --to=teawater@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=mark.kettenis@xs4all.nl \
    --cc=msnyder@vmware.com \
    /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