078093a
2005-09-27  Jeff Johnston  <jjohnstn@redhat.com>
078093a
078093a
	* libunwind-frame.c (libunwind_frame_cache): Save the current
078093a
	stack pointer in the cache.
078093a
	(libunwind_sigtramp_frame_this_id): New function.
078093a
	(libunwind_sigtramp_frame_unwind): New unwinder.
078093a
	(libunwind_sigtramp_frame_sniffer): Return 
078093a
	libunwind_sigtramp_frame_unwind address.
078093a
	* libunwind-frame.h (libunwind_sigtramp_frame_this_id): New
078093a
	prototype.
078093a
	* ia64-tdep.c (ia64_libunwind_sigtramp_frame_this_id): Calculate
078093a
	the base address using the current stack pointer plus a fixed
078093a
	offset.
eb9d945
eb9d945
2007-10-14  Jan Kratochvil  <jan.kratochvil@redhat.com>
eb9d945
eb9d945
	Port to GDB-6.7.
eb9d945
25ff8a1
2008-02-24  Jan Kratochvil  <jan.kratochvil@redhat.com>
25ff8a1
25ff8a1
	Port to GDB-6.8pre.
25ff8a1
25ff8a1
Index: gdb-6.8cvs20080219/gdb/libunwind-frame.c
9231e41
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/libunwind-frame.c	2008-01-02 00:04:03.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/libunwind-frame.c	2008-02-24 20:25:56.000000000 +0100
eb9d945
@@ -61,6 +61,7 @@ static unw_word_t (*unw_find_dyn_list_p)
078093a
 struct libunwind_frame_cache
078093a
 {
078093a
   CORE_ADDR base;
078093a
+  CORE_ADDR sp;
078093a
   CORE_ADDR func_addr;
078093a
   unw_cursor_t cursor;
eb9d945
   unw_addr_space_t as;
25ff8a1
@@ -133,6 +134,7 @@ libunwind_frame_cache (struct frame_info
078093a
   unw_accessors_t *acc;
078093a
   unw_addr_space_t as;
25ff8a1
   unw_word_t fp;
078093a
+  unw_word_t fp, sp;
078093a
   unw_regnum_t uw_sp_regnum;
078093a
   struct libunwind_frame_cache *cache;
078093a
   struct libunwind_descr *descr;
25ff8a1
@@ -171,14 +173,30 @@ libunwind_frame_cache (struct frame_info
25ff8a1
 				 : __LITTLE_ENDIAN);
078093a
 
25ff8a1
   unw_init_remote_p (&cache->cursor, as, next_frame);
25ff8a1
+
078093a
+  /* For the base address, we have a small problem.  The majority
078093a
+     of the time, we can get the stack pointer of the previous
078093a
+     frame to use as a frame pointer.  In the case where we have
078093a
+     a signal trampoline, the stack may change due to a sigaltstack
078093a
+     being set up.  In that case, the normal mechanism will give us
078093a
+     an address in the regular stack which is not at the end of the
078093a
+     sigaltstack as we want.  To handle this, we record the stack
078093a
+     address so the caller may calculate a more correct base address
078093a
+     to use.  */
25ff8a1
+  uw_sp_regnum = descr->gdb2uw (gdbarch_sp_regnum (gdbarch));
078093a
+  ret = unw_get_reg_p (&cache->cursor, uw_sp_regnum, &sp);
078093a
+  if (ret < 0)
eb9d945
+    {
eb9d945
+      unw_destroy_addr_space_p (as);
eb9d945
+      error (_("Can't get libunwind sp register."));
eb9d945
+    }
078093a
+
078093a
   if (unw_step_p (&cache->cursor) < 0)
eb9d945
     {
eb9d945
       unw_destroy_addr_space_p (as);
eb9d945
       return NULL;
eb9d945
     }
078093a
 
078093a
-  /* To get base address, get sp from previous frame.  */
25ff8a1
-  uw_sp_regnum = descr->gdb2uw (gdbarch_sp_regnum (gdbarch));
078093a
   ret = unw_get_reg_p (&cache->cursor, uw_sp_regnum, &fp);
078093a
   if (ret < 0)
eb9d945
     {
25ff8a1
@@ -186,6 +204,7 @@ libunwind_frame_cache (struct frame_info
eb9d945
       error (_("Can't get libunwind sp register."));
eb9d945
     }
078093a
 
078093a
+  cache->sp = (CORE_ADDR)sp;
078093a
   cache->base = (CORE_ADDR)fp;
eb9d945
   cache->as = as;
078093a
 
25ff8a1
@@ -381,6 +400,31 @@ libunwind_search_unwind_table (void *as,
078093a
 				    di, pi, need_unwind_info, args);
078093a
 }
078093a
 
078093a
+void
078093a
+libunwind_sigtramp_frame_this_id (struct frame_info *next_frame, 
078093a
+				  void **this_cache,
078093a
+		      		  struct frame_id *this_id)
078093a
+{
078093a
+  struct libunwind_frame_cache *cache =
078093a
+    libunwind_frame_cache (next_frame, this_cache);
078093a
+
078093a
+  /* Unlike a regular frame, we can't use the normal frame pointer
078093a
+     mechanism because a sigaltstack may have been used.  Instead,
078093a
+     we return the current stack pointer for the caller to use
078093a
+     to calculate the base address.  */
078093a
+  if (cache != NULL)
078093a
+    (*this_id) = frame_id_build (cache->sp, cache->func_addr);
078093a
+  else
078093a
+    (*this_id) = null_frame_id;
078093a
+}
078093a
+
078093a
+static const struct frame_unwind libunwind_sigtramp_frame_unwind =
078093a
+{
078093a
+  SIGTRAMP_FRAME,
078093a
+  libunwind_sigtramp_frame_this_id,
078093a
+  libunwind_frame_prev_register
078093a
+};
078093a
+
078093a
 /* Verify if we are in a sigtramp frame and we can use libunwind to unwind.  */
078093a
 const struct frame_unwind *
078093a
 libunwind_sigtramp_frame_sniffer (struct frame_info *next_frame)
25ff8a1
@@ -419,7 +463,7 @@ libunwind_sigtramp_frame_sniffer (struct
078093a
   ret = unw_is_signal_frame_p (&cursor);
eb9d945
   unw_destroy_addr_space_p (as);
078093a
   if (ret > 0)
078093a
-    return &libunwind_frame_unwind;
078093a
+    return &libunwind_sigtramp_frame_unwind;
078093a
 
078093a
   return NULL;
078093a
 }
25ff8a1
Index: gdb-6.8cvs20080219/gdb/libunwind-frame.h
9231e41
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/libunwind-frame.h	2008-01-02 00:04:03.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/libunwind-frame.h	2008-02-24 20:23:47.000000000 +0100
25ff8a1
@@ -47,6 +47,9 @@ void libunwind_frame_set_descr (struct g
078093a
 
078093a
 void libunwind_frame_this_id (struct frame_info *next_frame, void **this_cache,
078093a
 			      struct frame_id *this_id);
078093a
+void libunwind_sigtramp_frame_this_id (struct frame_info *next_frame, 
078093a
+				       void **this_cache,
078093a
+			      	       struct frame_id *this_id);
078093a
 void libunwind_frame_prev_register (struct frame_info *next_frame, void **this_cache,
078093a
 				    int regnum, int *optimizedp,
078093a
 				    enum lval_type *lvalp, CORE_ADDR *addrp,
25ff8a1
Index: gdb-6.8cvs20080219/gdb/ia64-tdep.c
9231e41
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/ia64-tdep.c	2008-02-24 20:23:40.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/ia64-tdep.c	2008-02-24 20:23:47.000000000 +0100
25ff8a1
@@ -2942,7 +2942,7 @@ ia64_libunwind_sigtramp_frame_this_id (s
078093a
   struct frame_id id;
078093a
   CORE_ADDR prev_ip;
078093a
 
078093a
-  libunwind_frame_this_id (next_frame, this_cache, &id;;
078093a
+  libunwind_sigtramp_frame_this_id (next_frame, this_cache, &id;;
078093a
   if (frame_id_eq (id, null_frame_id))
078093a
     {
078093a
       (*this_id) = null_frame_id;
25ff8a1
@@ -2954,8 +2954,14 @@ ia64_libunwind_sigtramp_frame_this_id (s
078093a
   frame_unwind_register (next_frame, IA64_BSP_REGNUM, buf);
078093a
   bsp = extract_unsigned_integer (buf, 8);
078093a
 
078093a
-  /* For a sigtramp frame, we don't make the check for previous ip being 0.  */
078093a
-  (*this_id) = frame_id_build_special (id.stack_addr, id.code_addr, bsp);
078093a
+  /* For a sigtramp frame, we don't make the check for previous ip being 0.  
078093a
+     We also must calculate the frame pointer because libunwind will give
078093a
+     us back the current stack pointer instead of the frame pointer since
078093a
+     it cannot figure this out when in a sigaltstack.  We make a basic
078093a
+     assumption of 16 (default size) + 8 bytes for sigcontext address.
078093a
+     FIXME: if libunwind were to export the frame pointer address, we
078093a
+            could eliminate the assumption and get the actual value.  */
078093a
+  (*this_id) = frame_id_build_special (id.stack_addr + 24, id.code_addr, bsp);
078093a
 
078093a
   if (gdbarch_debug >= 1)
078093a
     fprintf_unfiltered (gdb_stdlog,