[PATCH] i386 sigtramp changes

Mark Kettenis kettenis@chello.nl
Mon Jul 1 14:24:00 GMT 2002


This patch prepares the other i386 targets for the more advanced
sigtramp handling that's now only used for Linux.

Mark

Index: ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>

	* i386-tdep.h (struct gdbarch_tdep): Replace sigtramp_saved_pc
	with sigcontext_addr.  Add sc_sp_offset.
	(i386bsd_sigtramp_saved_pc): Remove prototype.
	(i386bsd_sicontext_addr): Add prototype.
	* i386-tdep.c (i386_sigtramp_saved_pc): New function.
	(i386_frame_saved_pc): Rewrite to call i386_sigtramp_saved_pc.
	(i386_svr4_sigtramp_saved_pc): Removed.
	(i386_svr4_sigcontext_addr): New function.
	(i386_svr4_init_abi): Don't initialize tdep->sigtramp_saved_pc.
	Initialize tdep->sigcontext_addr instead.  Initialize
	tdep->sc_pc_offset and tdep->sc_sp_offset.
	(i386_gdbarch_init): Likewise.
	* i386bsd-tdep.c (i386bsd_sigcontext_addr): Don't make it static
	any more.
	(i386bsd_sigtramp_saved_pc): Remove function.
	(i386bsd_init_abi): Don't initialize tdep->sigtramp_saved_pc.
	Initialize tdep->sigcontext_addr instead.  Initialize
	tdep->sc_pc_offset.
	* i386-linux-tdep.c (i386_linux_init_abi): Remove initialization
	of tdep->sigtramp_saved_pc.
	* i386-sol2-tdep.c (i386_sol2_init_abi): Don't initialize
	tdep->sigtramp_saved_pc.  Initialize tdep->sigcontext_addr
	instead.

Index: i386-linux-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-linux-tdep.c,v
retrieving revision 1.14
diff -u -p -r1.14 i386-linux-tdep.c
--- i386-linux-tdep.c 19 Jun 2002 14:59:47 -0000 1.14
+++ i386-linux-tdep.c 1 Jul 2002 21:13:04 -0000
@@ -566,7 +566,6 @@ i386_linux_init_abi (struct gdbarch_info
   set_gdbarch_frame_chain (gdbarch, i386_linux_frame_chain);
   set_gdbarch_frame_saved_pc (gdbarch, i386_linux_frame_saved_pc);
   set_gdbarch_saved_pc_after_call (gdbarch, i386_linux_saved_pc_after_call);
-  tdep->sigtramp_saved_pc = i386_linux_sigtramp_saved_pc;
 
   set_solib_svr4_fetch_link_map_offsets (gdbarch,
 				       i386_linux_svr4_fetch_link_map_offsets);
Index: i386-sol2-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-sol2-tdep.c,v
retrieving revision 1.3
diff -u -p -r1.3 i386-sol2-tdep.c
--- i386-sol2-tdep.c 1 Jul 2002 09:13:08 -0000 1.3
+++ i386-sol2-tdep.c 1 Jul 2002 21:13:04 -0000
@@ -44,7 +44,7 @@ i386_sol2_init_abi (struct gdbarch_info 
   /* Signal trampolines are different from SVR4, in fact they're
      rather similar to BSD.  */
   set_gdbarch_pc_in_sigtramp (gdbarch, i386_sol2_pc_in_sigtramp);
-  tdep->sigtramp_saved_pc = i386bsd_sigtramp_saved_pc;
+  tdep->sigcontext_addr = i386bsd_sigcontext_addr;
   tdep->sc_pc_offset = 36 + 14 * 4;
 
   /* Assume that the prototype flag can be trusted.  */
Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.67
diff -u -p -r1.67 i386-tdep.c
--- i386-tdep.c 1 Jul 2002 10:20:40 -0000 1.67
+++ i386-tdep.c 1 Jul 2002 21:13:05 -0000
@@ -481,19 +481,26 @@ i386_frameless_function_invocation (stru
   return frameless_look_for_prologue (frame);
 }
 
+/* Assuming FRAME is for a sigtramp routine, return the saved program
+   counter.  */
+
+static CORE_ADDR
+i386_sigtramp_saved_pc (struct frame_info *frame)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  CORE_ADDR addr;
+
+  addr = tdep->sigcontext_addr (frame);
+  return read_memory_unsigned_integer (addr + tdep->sc_pc_offset, 4);
+}
+
 /* Return the saved program counter for FRAME.  */
 
 static CORE_ADDR
 i386_frame_saved_pc (struct frame_info *frame)
 {
   if (frame->signal_handler_caller)
-    {
-      CORE_ADDR (*sigtramp_saved_pc) (struct frame_info *);
-      sigtramp_saved_pc = gdbarch_tdep (current_gdbarch)->sigtramp_saved_pc;
-
-      gdb_assert (sigtramp_saved_pc != NULL);
-      return sigtramp_saved_pc (frame);
-    }
+    return i386_sigtramp_saved_pc (frame);
 
   return read_memory_unsigned_integer (frame->frame + 4, 4);
 }
@@ -1244,29 +1251,31 @@ i386_svr4_pc_in_sigtramp (CORE_ADDR pc, 
 		   || strcmp ("sigvechandler", name) == 0));
 }
 
-/* Get saved user PC for sigtramp from the pushed ucontext on the
-   stack for all three variants of SVR4 sigtramps.  */
+/* Get address of the pushed ucontext (sigcontext) on the stack for
+   all three variants of SVR4 sigtramps.  */
 
 static CORE_ADDR
-i386_svr4_sigtramp_saved_pc (struct frame_info *frame)
+i386_svr4_sigcontext_addr (struct frame_info *frame)
 {
-  CORE_ADDR saved_pc_offset = 4;
+  int sigcontext_offset = -1;
   char *name = NULL;
 
   find_pc_partial_function (frame->pc, &name, NULL, NULL);
   if (name)
     {
       if (strcmp (name, "_sigreturn") == 0)
-	saved_pc_offset = 132 + 14 * 4;
+	sigcontext_offset = 132;
       else if (strcmp (name, "_sigacthandler") == 0)
-	saved_pc_offset = 80 + 14 * 4;
+	sigcontext_offset = 80;
       else if (strcmp (name, "sigvechandler") == 0)
-	saved_pc_offset = 120 + 14 * 4;
+	sigcontext_offset = 120;
     }
 
+  gdb_assert (sigcontext_offset != -1);
+
   if (frame->next)
-    return read_memory_integer (frame->next->frame + saved_pc_offset, 4);
-  return read_memory_integer (read_register (SP_REGNUM) + saved_pc_offset, 4);
+    return frame->next->frame + sigcontext_offset;
+  return read_register (SP_REGNUM) + sigcontext_offset;
 }
 
 
@@ -1303,7 +1312,9 @@ i386_svr4_init_abi (struct gdbarch_info 
   set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid);
 
   set_gdbarch_pc_in_sigtramp (gdbarch, i386_svr4_pc_in_sigtramp);
-  tdep->sigtramp_saved_pc = i386_svr4_sigtramp_saved_pc;
+  tdep->sigcontext_addr = i386_svr4_sigcontext_addr;
+  tdep->sc_pc_offset = 14 * 4;
+  tdep->sc_sp_offset = 7 * 4;
 
   tdep->jb_pc_offset = 20;
 }
@@ -1369,17 +1380,18 @@ i386_gdbarch_init (struct gdbarch_info i
 
   tdep->jb_pc_offset = -1;
   tdep->struct_return = pcc_struct_return;
-  tdep->sigtramp_saved_pc = NULL;
   tdep->sigtramp_start = 0;
   tdep->sigtramp_end = 0;
+  tdep->sigcontext_addr = NULL;
   tdep->sc_pc_offset = -1;
+  tdep->sc_sp_offset = -1;
 
   /* The format used for `long double' on almost all i386 targets is
      the i387 extended floating-point format.  In fact, of all targets
      in the GCC 2.95 tree, only OSF/1 does it different, and insists
      on having a `long double' that's not `long' at all.  */
   set_gdbarch_long_double_format (gdbarch, &floatformat_i387_ext);
-  
+
   /* Although the i386 extended floating-point has only 80 significant
      bits, a `long double' actually takes up 96, probably to enforce
      alignment.  */
@@ -1388,7 +1400,7 @@ i386_gdbarch_init (struct gdbarch_info i
   /* NOTE: tm-i386aix.h, tm-i386bsd.h, tm-i386os9k.h, tm-ptx.h,
      tm-symmetry.h currently override this.  Sigh.  */
   set_gdbarch_num_regs (gdbarch, I386_NUM_GREGS + I386_NUM_FREGS);
-  
+
   set_gdbarch_sp_regnum (gdbarch, 4);
   set_gdbarch_fp_regnum (gdbarch, 5);
   set_gdbarch_pc_regnum (gdbarch, 8);
Index: i386-tdep.h
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.h,v
retrieving revision 1.8
diff -u -p -r1.8 i386-tdep.h
--- i386-tdep.h 17 Jun 2002 23:32:30 -0000 1.8
+++ i386-tdep.h 1 Jul 2002 21:13:05 -0000
@@ -65,15 +65,16 @@ struct gdbarch_tdep
   /* Convention for returning structures.  */
   enum struct_return struct_return;
 
-  /* Get saved PC for sigtramp.  */
-  CORE_ADDR (*sigtramp_saved_pc) (struct frame_info *);
-
   /* Address range where sigtramp lives.  */
   CORE_ADDR sigtramp_start;
   CORE_ADDR sigtramp_end;
 
-  /* Offset of saved PC in `struct sigcontext'.  */
+  /* Get address of sigcontext for sigtramp.  */
+  CORE_ADDR (*sigcontext_addr) (struct frame_info *);
+
+  /* Offset of saved PC and SP in `struct sigcontext'.  */
   int sc_pc_offset;
+  int sc_sp_offset;
 };
 
 /* Floating-point registers.  */
@@ -175,6 +176,6 @@ extern void i386_svr4_init_abi (struct g
 
 /* Functions exported from i386bsd-tdep.c.  */
 
-extern CORE_ADDR i386bsd_sigtramp_saved_pc (struct frame_info *frame);
+extern CORE_ADDR i386bsd_sigcontext_addr (struct frame_info *frame);
 
 #endif /* i386-tdep.h */
Index: i386bsd-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386bsd-tdep.c,v
retrieving revision 1.4
diff -u -p -r1.4 i386bsd-tdep.c
--- i386bsd-tdep.c 1 Jul 2002 09:41:00 -0000 1.4
+++ i386bsd-tdep.c 1 Jul 2002 21:13:05 -0000
@@ -39,9 +39,12 @@ i386bsd_pc_in_sigtramp (CORE_ADDR pc, ch
 }
 
 /* Assuming FRAME is for a BSD sigtramp routine, return the address of
-   the associated sigcontext structure.  */
+   the associated sigcontext structure.
 
-static CORE_ADDR
+   Note: This function is used for Solaris 2 too, so don't make it
+   static.  */
+
+CORE_ADDR
 i386bsd_sigcontext_addr (struct frame_info *frame)
 {
   if (frame->next)
@@ -55,22 +58,6 @@ i386bsd_sigcontext_addr (struct frame_in
   return read_memory_unsigned_integer (read_register (SP_REGNUM) + 8, 4);
 }
 
-/* Assuming FRAME is for a BSD sigtramp routine, return the saved
-   program counter.
-
-   Note: This function is used for Solaris 2 too, so don't make it
-   static.  */
-
-CORE_ADDR
-i386bsd_sigtramp_saved_pc (struct frame_info *frame)
-{
-  int sc_pc_offset = gdbarch_tdep (current_gdbarch)->sc_pc_offset;
-  CORE_ADDR addr;
-
-  addr = i386bsd_sigcontext_addr (frame);
-  return read_memory_unsigned_integer (addr + sc_pc_offset, 4);
-}
-
 /* Return the start address of the sigtramp routine.  */
 
 CORE_ADDR
@@ -116,9 +103,9 @@ i386bsd_init_abi (struct gdbarch_info in
 
   tdep->jb_pc_offset = 0;
 
-  tdep->sigtramp_saved_pc = i386bsd_sigtramp_saved_pc;
   tdep->sigtramp_start = 0xfdbfdfc0;
   tdep->sigtramp_end = 0xfdbfe000;
+  tdep->sigcontext_addr = i386bsd_sigcontext_addr;
   tdep->sc_pc_offset = i386bsd_sc_pc_offset;
 }
 



More information about the Gdb-patches mailing list