Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Hui Zhu <teawater@gmail.com>
To: gdb-patches ml <gdb-patches@sourceware.org>
Cc: Michael Snyder <msnyder@vmware.com>
Subject: [RFA] Make the prec support signal better[3/4] -- i386-linux
Date: Wed, 09 Sep 2009 13:29:00 -0000	[thread overview]
Message-ID: <daef60380909090629r25ad8520pb14baaa86d406202@mail.gmail.com> (raw)

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

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.

2009-09-09  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_signal_stack): New enum.
	(i386_linux_record_signal): New function.
	(i386_linux_init_abi): Call set_gdbarch_process_record_signal.

---
 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.  */
+
+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;
+}
+
 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)
+   {
+     /* sys_sigreturn sys_rt_sigreturn */
+     if (i386_all_but_ip_registers_record (regcache))
+       return -1;
+     return 0;
+   }
+
   syscall_gdb = i386_canonicalize_syscall (syscall_native);

   if (syscall_gdb < 0)
@@ -409,6 +444,41 @@ i386_linux_intx80_sysenter_record (struc

   return 0;
 }
+
+enum i386_linux_signal_stack {
+  xstate = 270,
+  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 -= xstate;
+  /* This is for frame_size.
+     sp -= sizeof (struct rt_sigframe);  */
+  esp -= frame_size;
+  if (record_arch_list_add_mem (esp, xstate + 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 +574,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: 3106 bytes --]

---
 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.  */
+
+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;
+}
+
 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)
+   {
+     /* sys_sigreturn sys_rt_sigreturn */
+     if (i386_all_but_ip_registers_record (regcache))
+       return -1;
+     return 0;
+   }
+
   syscall_gdb = i386_canonicalize_syscall (syscall_native);
 
   if (syscall_gdb < 0)
@@ -409,6 +444,41 @@ i386_linux_intx80_sysenter_record (struc
 
   return 0;
 }
+
+enum i386_linux_signal_stack {
+  xstate = 270,
+  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 -= xstate;
+  /* This is for frame_size.
+     sp -= sizeof (struct rt_sigframe);  */
+  esp -= frame_size;
+  if (record_arch_list_add_mem (esp, xstate + 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 +574,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-09 13:29 UTC|newest]

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

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=daef60380909090629r25ad8520pb14baaa86d406202@mail.gmail.com \
    --to=teawater@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --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