From: Shinichiro Hamaji Date: Tue, 9 May 2017 08:11:51 +0000 (+0900) Subject: x86 stacktrace: Use __builtin_frame_address if possible X-Git-Tag: accepted/tizen/5.0/unified/20181102.024921~43^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=f278d734c1c02901631e04d1ac9099a4897ab75b;p=platform%2Fupstream%2Fglog.git x86 stacktrace: Use __builtin_frame_address if possible --- 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(__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.