summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2017-05-09 17:11:51 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2017-05-09 17:14:15 +0900
commitf278d734c1c02901631e04d1ac9099a4897ab75b (patch)
tree3a4d2bcd6d3752ada01739e1abd1f630b49cfb45
parent0d78884a22802cffc96d3779e953e764cb4fdaa4 (diff)
downloadglog-f278d734c1c02901631e04d1ac9099a4897ab75b.tar.gz
glog-f278d734c1c02901631e04d1ac9099a4897ab75b.tar.bz2
glog-f278d734c1c02901631e04d1ac9099a4897ab75b.zip
x86 stacktrace: Use __builtin_frame_address if possible
-rw-r--r--src/stacktrace_x86-inl.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/stacktrace_x86-inl.h b/src/stacktrace_x86-inl.h
index cfd31f7..3b8d5a8 100644
--- a/src/stacktrace_x86-inl.h
+++ b/src/stacktrace_x86-inl.h
@@ -93,16 +93,23 @@ static void **NextStackFrame(void **old_sp) {
// If you change this function, also change GetStackFrames below.
int GetStackTrace(void** result, int max_depth, int skip_count) {
void **sp;
-#ifdef __i386__
+
+#ifdef __GNUC__
+#if __GNUC__ * 100 + __GNUC_MINOR__ >= 402
+#define USE_BUILTIN_FRAME_ADDRESS
+#endif
+#endif
+
+#ifdef USE_BUILTIN_FRAME_ADDRESS
+ sp = reinterpret_cast<void**>(__builtin_frame_address(0));
+#elif defined(__i386__)
// Stack frame format:
// sp[0] pointer to previous frame
// sp[1] caller address
// sp[2] first argument
// ...
sp = (void **)&result - 2;
-#endif
-
-#ifdef __x86_64__
+#elif defined(__x86_64__)
// __builtin_frame_address(0) can return the wrong address on gcc-4.1.0-k8
unsigned long rbp;
// Move the value of the register %rbp into the local variable rbp.