[RFA] Make the prec support signal better[3/4] -- i386-linux

Hui Zhu teawater@gmail.com
Thu Sep 10 01:51:00 GMT 2009


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
-------------- next part --------------
---
 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


More information about the Gdb-patches mailing list