[sheepdog] [PATCH] Fix hardcode AMD64 assembly code (RSP)
YunQiang Su
wzssyqa at gmail.com
Sat Jul 27 20:05:49 CEST 2013
RSP is a register name only for AMD64 (x86_64) platform,
while on other platform it may be another name.
On i386 (x86_32) platform, it is "esp".
On most of RISC platform (PowerPC, SPARC, MIPS, ARM, etc),
it is "sp".
---
include/logger.h | 23 ++++++++++++++++++++++-
lib/logger.c | 5 -----
2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/include/logger.h b/include/logger.h
index 79eb108..81691b2 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -38,10 +38,31 @@ void log_write(int prio, const char *func, int line, const char *fmt, ...)
void set_thread_name(const char *name, bool show_idx);
void get_thread_name(char *name);
+#ifdef __i386__
+#define SP_REG "esp"
+#elif defined(__x86_64__)
+#define SP_REG "rsp"
+#elif defined(__mips__) || defined(__sparc__) || \
+ defined (__arm__) || (defined __powerpc__) || \
+ defined (__s390__) || (defined __s390x__) || \
+ defined (__ia64__)
+#define SP_REG "sp"
+#endif
+
+#ifdef SP_REG
+#define dump_stack_frames() ({ \
+ register void *current_sp asm(SP_REG); \
+ __dump_stack_frames(current_sp); \
+})
#define sd_dump_variable(var) ({ \
- register void *current_sp asm("rsp"); \
+ register void *current_sp asm(SP_REG); \
__sd_dump_variable(#var, current_sp); \
})
+#else
+#define dump_stack_frames() ()
+#define sd_dump_variable(var) ()
+#endif
+
int __sd_dump_variable(const char *var, const void *base_sp);
void sd_backtrace(void);
diff --git a/lib/logger.c b/lib/logger.c
index 253163d..ba55adc 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -742,11 +742,6 @@ notrace int __sd_dump_variable(const char *var, const void *base_sp)
return 0;
}
-#define dump_stack_frames() ({ \
- register void *current_sp asm("rsp"); \
- __dump_stack_frames(current_sp); \
-})
-
__attribute__ ((__noinline__))
static notrace int __dump_stack_frames(const void *base_sp)
{
--
1.8.3.2
More information about the sheepdog
mailing list