From 7314fa3f8682c9ebff6dc820bd40c490d9ec1bec Mon Sep 17 00:00:00 2001 From: Shinichiro Hamaji Date: Tue, 9 May 2017 17:01:07 +0900 Subject: [PATCH 1/6] Use LOG(FATAL) instead of CHECK(false) --- src/logging_unittest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logging_unittest.cc b/src/logging_unittest.cc index b886222..97cbeaa 100644 --- a/src/logging_unittest.cc +++ b/src/logging_unittest.cc @@ -282,7 +282,7 @@ void TestLogging(bool check_counts) { } static void NoAllocNewHook() { - CHECK(false) << "unexpected new"; + LOG(FATAL) << "unexpected new"; } struct NewHook { From 0d78884a22802cffc96d3779e953e764cb4fdaa4 Mon Sep 17 00:00:00 2001 From: Shinichiro Hamaji Date: Tue, 9 May 2017 17:05:55 +0900 Subject: [PATCH 2/6] Relax test for symbolize Don't rely on an internal-linkage extern "C" function having an unmangled name. This isn't required by the ABI, and in fact is not valid for a conforming compiler(!). Instead, allow symbolization to produce either a mangled or an unmangled name here. --- src/symbolize_unittest.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/symbolize_unittest.cc b/src/symbolize_unittest.cc index 05cb8a1..26616e6 100644 --- a/src/symbolize_unittest.cc +++ b/src/symbolize_unittest.cc @@ -99,7 +99,13 @@ TEST(Symbolize, Symbolize) { // Compilers should give us pointers to them. EXPECT_STREQ("nonstatic_func", TrySymbolize((void *)(&nonstatic_func))); - EXPECT_STREQ("static_func", TrySymbolize((void *)(&static_func))); + + // The name of an internal linkage symbol is not specified; allow either a + // mangled or an unmangled name here. + const char *static_func_symbol = TrySymbolize((void *)(&static_func)); + CHECK(NULL != static_func_symbol); + EXPECT_TRUE(strcmp("static_func", static_func_symbol) == 0 || + strcmp("static_func()", static_func_symbol) == 0); EXPECT_TRUE(NULL == TrySymbolize(NULL)); } @@ -267,9 +273,13 @@ TEST(Symbolize, SymbolizeStackConsumption) { EXPECT_GT(stack_consumed, 0); EXPECT_LT(stack_consumed, kStackConsumptionUpperLimit); + // The name of an internal linkage symbol is not specified; allow either a + // mangled or an unmangled name here. symbol = SymbolizeStackConsumption((void *)(&static_func), &stack_consumed); - EXPECT_STREQ("static_func", symbol); + CHECK(NULL != symbol); + EXPECT_TRUE(strcmp("static_func", symbol) == 0 || + strcmp("static_func()", symbol) == 0); EXPECT_GT(stack_consumed, 0); EXPECT_LT(stack_consumed, kStackConsumptionUpperLimit); } From f278d734c1c02901631e04d1ac9099a4897ab75b Mon Sep 17 00:00:00 2001 From: Shinichiro Hamaji Date: Tue, 9 May 2017 17:11:51 +0900 Subject: [PATCH 3/6] x86 stacktrace: Use __builtin_frame_address if possible --- src/stacktrace_x86-inl.h | 15 +++++++++++---- 1 file 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(__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. From c4814b729a950131ce143376869f7900c6c147dc Mon Sep 17 00:00:00 2001 From: Shinichiro Hamaji Date: Tue, 9 May 2017 17:21:16 +0900 Subject: [PATCH 4/6] symbolize: Allow 4kB stack consumption on PPC64 --- src/symbolize_unittest.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/symbolize_unittest.cc b/src/symbolize_unittest.cc index 26616e6..bdd2f03 100644 --- a/src/symbolize_unittest.cc +++ b/src/symbolize_unittest.cc @@ -260,8 +260,13 @@ static const char *SymbolizeStackConsumption(void *pc, int *stack_consumed) { return g_symbolize_result; } +#ifdef __ppc64__ +// Symbolize stack consumption should be within 4kB. +const int kStackConsumptionUpperLimit = 4096; +#else // Symbolize stack consumption should be within 2kB. const int kStackConsumptionUpperLimit = 2048; +#endif TEST(Symbolize, SymbolizeStackConsumption) { int stack_consumed; From ee9d4877829b76094dbcff089411e6bc2c3468cc Mon Sep 17 00:00:00 2001 From: Shinichiro Hamaji Date: Tue, 9 May 2017 17:22:38 +0900 Subject: [PATCH 5/6] Define OS_LINUX only if it's not defined yet --- src/utilities.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utilities.h b/src/utilities.h index 5f79968..101ca64 100644 --- a/src/utilities.h +++ b/src/utilities.h @@ -39,7 +39,9 @@ #elif defined(__CYGWIN__) || defined(__CYGWIN32__) # define OS_CYGWIN #elif defined(linux) || defined(__linux) || defined(__linux__) -# define OS_LINUX +# ifndef OS_LINUX +# define OS_LINUX +# endif #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) # define OS_MACOSX #elif defined(__FreeBSD__) From a6266db97a552dd9a5df91a10b14a637a8cbfc2f Mon Sep 17 00:00:00 2001 From: Shinichiro Hamaji Date: Tue, 9 May 2017 17:35:18 +0900 Subject: [PATCH 6/6] Add a hack for naive include scanners --- src/utilities.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/utilities.cc b/src/utilities.cc index 5c88e58..0d686eb 100644 --- a/src/utilities.cc +++ b/src/utilities.cc @@ -349,4 +349,12 @@ _END_GOOGLE_NAMESPACE_ // Make an implementation of stacktrace compiled. #ifdef STACKTRACE_H # include STACKTRACE_H +# if 0 +// For include scanners which can't handle macro expansions. +# include "stacktrace_libunwind-inl.h" +# include "stacktrace_x86-inl.h" +# include "stacktrace_x86_64-inl.h" +# include "stacktrace_powerpc-inl.h" +# include "stacktrace_generic-inl.h" +# endif #endif