[memprof: 38/76] stack-frame: Introduce macros for stack pointer regs and use them.



commit b81964607b8e07a2d36ddbffea26532f9403bcec
Author: Stefan Schmidt <stefan datenfreihafen org>
Date:   Wed Sep 30 00:26:00 2009 +0200

    stack-frame: Introduce macros for stack pointer regs and use them.
    
    Instead of going through #IFDEF hell we use soem macros to set the reg name
    correctly for different archs.
    
    Signed-off-by: Stefan Schmidt <stefan datenfreihafen org>
    Signed-off-by: Holger Hans Peter Freyther <zecke selfish org>

 lib/mi-perfctr.c     |    4 ++--
 lib/speedintercept.c |    8 ++++----
 lib/stack-frame.c    |    2 +-
 lib/stack-frame.h    |   13 +++++++++++++
 4 files changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/lib/mi-perfctr.c b/lib/mi-perfctr.c
index 134f9e6..1d386da 100644
--- a/lib/mi-perfctr.c
+++ b/lib/mi-perfctr.c
@@ -65,8 +65,8 @@ sigprof_handler (int unused, siginfo_t *si, ucontext_t *ucontext)
     info.alloc.new_ptr = NULL;
     info.alloc.size = 1;
     
-    mi_call_with_signal_backtrace ((void *)ctx->eip, (void *)ctx->ebp, (void *)ctx->esp,
-				   mi_write_stack, &info);
+    mi_call_with_signal_backtrace ((void *)ctx->EIPRIP, (void *)ctx->EBPRBP,
+					(void *)ctx->ESPRSP, mi_write_stack, &info);
 
     if (ioctl (perfctr_fd, VPERFCTR_IRESUME) < 0)
 	    mi_perror ("Error restarting handler interrupt");
diff --git a/lib/speedintercept.c b/lib/speedintercept.c
index 555833d..a5032ba 100644
--- a/lib/speedintercept.c
+++ b/lib/speedintercept.c
@@ -155,7 +155,7 @@ start_itimer_timer (int timer_type)
 #define SIGHANDLER_FRAMES 2
 
 static void
-#if defined (__linux__) && defined (__i386__)
+#if defined (__linux__)
 sigprof_handler (int unused, struct sigcontext ctx)
 #else
 sigprof_handler (int unused)
@@ -169,9 +169,9 @@ sigprof_handler (int unused)
 	info.alloc.new_ptr = NULL;
 	info.alloc.size = 1;
     
-#if defined (__linux__) && defined (__i386__)
-	mi_call_with_signal_backtrace ((void *)ctx.eip, (void *)ctx.ebp, (void *)ctx.esp,
-				       mi_write_stack, &info);
+#if defined (__linux__)
+	mi_call_with_signal_backtrace ((void *)ctx.EIPRIP, (void *)ctx.EBPRBP,
+					(void *)ctx.ESPRSP, mi_write_stack, &info);
 #else
 	mi_call_with_backtrace (SIGHANDLER_FRAMES, saved_pc, mi_write_stack, &info);
 #endif
diff --git a/lib/stack-frame.c b/lib/stack-frame.c
index ebb2c92..96d3534 100644
--- a/lib/stack-frame.c
+++ b/lib/stack-frame.c
@@ -72,7 +72,7 @@ again:
 
 #define HAVE_FRAME_ACCESSORS
 
-#if defined (__GNUC__) && defined (__i386__)
+#if defined (__GNUC__)
 typedef struct stack_frame_struct stack_frame;
 struct stack_frame_struct {
     stack_frame *next;
diff --git a/lib/stack-frame.h b/lib/stack-frame.h
index b39ee01..7eccfa6 100644
--- a/lib/stack-frame.h
+++ b/lib/stack-frame.h
@@ -33,6 +33,19 @@
 #ifndef __STACK_FRAME_H__
 #define __STACK_FRAME_H__
 
+/* STACKPOINTER macros to access the right regs on different ARCHs */
+#if defined (__i386__)
+#define EIPRIP eip
+#define EBPRBP ebp
+#define ESPRSP esp
+#elif defined (__x86_64__)
+#define EIPRIP rip
+#define EBPRBP rbp
+#define ESPRSP rsp
+#else
+#error "Unknown architecture and generating backtrace is broken"
+#endif
+
 void mi_call_with_backtrace (int   to_skip,
 			     void  callback (int, void **, void *),
 			     void *data);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]