diff options
Diffstat (limited to 'lib/sanitizer_common')
-rw-r--r-- | lib/sanitizer_common/sanitizer_stacktrace.h | 21 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc | 10 | ||||
-rw-r--r-- | lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc | 23 |
3 files changed, 32 insertions, 22 deletions
diff --git a/lib/sanitizer_common/sanitizer_stacktrace.h b/lib/sanitizer_common/sanitizer_stacktrace.h index b03f5791..035f39f8 100644 --- a/lib/sanitizer_common/sanitizer_stacktrace.h +++ b/lib/sanitizer_common/sanitizer_stacktrace.h @@ -47,17 +47,26 @@ struct StackTrace { trace[i] = src[i]; } + static bool WillUseFastUnwind(bool request_fast_unwind) { + // Check if fast unwind is available. Fast unwind is the only option on Mac. + if (!SANITIZER_CAN_FAST_UNWIND) + return false; + else if (SANITIZER_MAC) + return true; + return request_fast_unwind; + } + void Unwind(uptr max_depth, uptr pc, uptr bp, uptr stack_top, - uptr stack_bottom, bool fast); - // FIXME: Make FastUnwindStack and SlowUnwindStack private methods. + uptr stack_bottom, bool request_fast_unwind); + + static uptr GetCurrentPc(); + static uptr GetPreviousInstructionPc(uptr pc); + + private: void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom, uptr max_depth); void SlowUnwindStack(uptr pc, uptr max_depth); - void PopStackFrames(uptr count); - - static uptr GetCurrentPc(); - static uptr GetPreviousInstructionPc(uptr pc); }; } // namespace __sanitizer diff --git a/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc b/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc index 8ce0918d..a8e70c96 100644 --- a/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc +++ b/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc @@ -16,14 +16,8 @@ namespace __sanitizer { void StackTrace::Unwind(uptr max_depth, uptr pc, uptr bp, uptr stack_top, - uptr stack_bottom, bool fast) { - // Check if fast unwind is available. Fast unwind is the only option on Mac. - if (!SANITIZER_CAN_FAST_UNWIND) - fast = false; - else if (SANITIZER_MAC) - fast = true; - - if (!fast) + uptr stack_bottom, bool request_fast_unwind) { + if (!WillUseFastUnwind(request_fast_unwind)) SlowUnwindStack(pc, max_depth); else FastUnwindStack(pc, bp, stack_top, stack_bottom, max_depth); diff --git a/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc b/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc index 8d2ac2bd..5e6d3fdb 100644 --- a/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc +++ b/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc @@ -20,6 +20,13 @@ namespace __sanitizer { class FastUnwindTest : public ::testing::Test { protected: virtual void SetUp(); + bool TryFastUnwind(uptr max_depth) { + if (!StackTrace::WillUseFastUnwind(true)) + return false; + trace.Unwind(max_depth, start_pc, (uptr)&fake_stack[0], fake_top, + fake_bottom, true); + return true; + } uptr fake_stack[10]; uptr start_pc; @@ -50,8 +57,8 @@ void FastUnwindTest::SetUp() { } TEST_F(FastUnwindTest, Basic) { - trace.FastUnwindStack(start_pc, (uptr)&fake_stack[0], - fake_top, fake_bottom, kStackTraceMax); + if (!TryFastUnwind(kStackTraceMax)) + return; // Should get all on-stack retaddrs and start_pc. EXPECT_EQ(6U, trace.size); EXPECT_EQ(start_pc, trace.trace[0]); @@ -64,8 +71,8 @@ TEST_F(FastUnwindTest, Basic) { TEST_F(FastUnwindTest, FramePointerLoop) { // Make one fp point to itself. fake_stack[4] = (uptr)&fake_stack[4]; - trace.FastUnwindStack(start_pc, (uptr)&fake_stack[0], - fake_top, fake_bottom, kStackTraceMax); + if (!TryFastUnwind(kStackTraceMax)) + return; // Should get all on-stack retaddrs up to the 4th slot and start_pc. EXPECT_EQ(4U, trace.size); EXPECT_EQ(start_pc, trace.trace[0]); @@ -77,8 +84,8 @@ TEST_F(FastUnwindTest, FramePointerLoop) { TEST_F(FastUnwindTest, MisalignedFramePointer) { // Make one fp misaligned. fake_stack[4] += 3; - trace.FastUnwindStack(start_pc, (uptr)&fake_stack[0], - fake_top, fake_bottom, kStackTraceMax); + if (!TryFastUnwind(kStackTraceMax)) + return; // Should get all on-stack retaddrs up to the 4th slot and start_pc. EXPECT_EQ(4U, trace.size); EXPECT_EQ(start_pc, trace.trace[0]); @@ -88,8 +95,8 @@ TEST_F(FastUnwindTest, MisalignedFramePointer) { } TEST_F(FastUnwindTest, OneFrameStackTrace) { - trace.FastUnwindStack(start_pc, (uptr)&fake_stack[0], - fake_top, fake_bottom, 1); + if (!TryFastUnwind(1)) + return; EXPECT_EQ(1U, trace.size); EXPECT_EQ(start_pc, trace.trace[0]); } |