diff options
author | Julian Lettner <jlettner@apple.com> | 2019-03-01 23:50:47 +0000 |
---|---|---|
committer | Julian Lettner <jlettner@apple.com> | 2019-03-01 23:50:47 +0000 |
commit | a30b116e6f744adca1ae3cbf4eed94621ed851e1 (patch) | |
tree | 1799d166b0a55e960b523e0b5c6c1d741a92ef6e | |
parent | 4b1b4bf3b3ddc4a3d64c12dd42489f50e56d0774 (diff) | |
download | bcm5719-llvm-a30b116e6f744adca1ae3cbf4eed94621ed851e1.tar.gz bcm5719-llvm-a30b116e6f744adca1ae3cbf4eed94621ed851e1.zip |
[NFC][Sanitizer] Replace last uses of old Unwind API
Replace remaining uses of old Unwind API in unit tests.
Allows us to remove the old API and WillUseFastUnwind can be made
private.
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D58754
llvm-svn: 355242
-rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h | 2 | ||||
-rw-r--r-- | compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc | 47 |
2 files changed, 24 insertions, 25 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h index a3a9a418a47..4d19979f2c5 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h @@ -139,6 +139,8 @@ struct BufferedStackTrace : public StackTrace { BufferedStackTrace(const BufferedStackTrace &) = delete; void operator=(const BufferedStackTrace &) = delete; + + friend class FastUnwindTest; }; // Check if given pointer points into allocated stack area. diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc index 45eb1b26e04..771a3e4d961 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc @@ -20,18 +20,15 @@ class FastUnwindTest : public ::testing::Test { protected: virtual void SetUp(); virtual void TearDown(); - bool TryFastUnwind(uptr max_depth) { - if (!StackTrace::WillUseFastUnwind(true)) - return false; - trace.Unwind(max_depth, start_pc, (uptr)&fake_stack[0], 0, fake_top, - fake_bottom, true); - return true; - } + + void UnwindFast(); void *mapping; uhwptr *fake_stack; const uptr fake_stack_size = 10; uhwptr start_pc; + + uhwptr fake_bp; uhwptr fake_top; uhwptr fake_bottom; BufferedStackTrace trace; @@ -62,6 +59,7 @@ void FastUnwindTest::SetUp() { fake_top = (uhwptr)&fake_stack[fake_stack_size + 2]; // Bottom is one slot before the start because UnwindFast uses >. fake_bottom = (uhwptr)mapping; + fake_bp = (uptr)&fake_stack[0]; start_pc = PC(0); } @@ -70,9 +68,14 @@ void FastUnwindTest::TearDown() { UnmapOrDie(mapping, 2 * ps); } +#if SANITIZER_CAN_FAST_UNWIND + +void FastUnwindTest::UnwindFast() { + trace.UnwindFast(start_pc, fake_bp, fake_top, fake_bottom, kStackTraceMax); +} + TEST_F(FastUnwindTest, Basic) { - if (!TryFastUnwind(kStackTraceMax)) - return; + UnwindFast(); // Should get all on-stack retaddrs and start_pc. EXPECT_EQ(6U, trace.size); EXPECT_EQ(start_pc, trace.trace[0]); @@ -85,8 +88,7 @@ TEST_F(FastUnwindTest, Basic) { TEST_F(FastUnwindTest, FramePointerLoop) { // Make one fp point to itself. fake_stack[4] = (uhwptr)&fake_stack[4]; - if (!TryFastUnwind(kStackTraceMax)) - return; + UnwindFast(); // 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]); @@ -98,8 +100,7 @@ TEST_F(FastUnwindTest, FramePointerLoop) { TEST_F(FastUnwindTest, MisalignedFramePointer) { // Make one fp misaligned. fake_stack[4] += 3; - if (!TryFastUnwind(kStackTraceMax)) - return; + UnwindFast(); // 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]); @@ -109,16 +110,14 @@ TEST_F(FastUnwindTest, MisalignedFramePointer) { } TEST_F(FastUnwindTest, OneFrameStackTrace) { - if (!TryFastUnwind(1)) - return; + trace.Unwind(start_pc, fake_bp, nullptr, true, 1); EXPECT_EQ(1U, trace.size); EXPECT_EQ(start_pc, trace.trace[0]); EXPECT_EQ((uhwptr)&fake_stack[0], trace.top_frame_bp); } TEST_F(FastUnwindTest, ZeroFramesStackTrace) { - if (!TryFastUnwind(0)) - return; + trace.Unwind(start_pc, fake_bp, nullptr, true, 0); EXPECT_EQ(0U, trace.size); EXPECT_EQ(0U, trace.top_frame_bp); } @@ -128,8 +127,7 @@ TEST_F(FastUnwindTest, FPBelowPrevFP) { // current FP. fake_stack[0] = (uhwptr)&fake_stack[-50]; fake_stack[1] = PC(1); - if (!TryFastUnwind(3)) - return; + UnwindFast(); EXPECT_EQ(2U, trace.size); EXPECT_EQ(PC(0), trace.trace[0]); EXPECT_EQ(PC(1), trace.trace[1]); @@ -138,8 +136,7 @@ TEST_F(FastUnwindTest, FPBelowPrevFP) { TEST_F(FastUnwindTest, CloseToZeroFrame) { // Make one pc a NULL pointer. fake_stack[5] = 0x0; - if (!TryFastUnwind(kStackTraceMax)) - return; + UnwindFast(); // The stack should be truncated at the NULL pointer (and not include it). EXPECT_EQ(3U, trace.size); EXPECT_EQ(start_pc, trace.trace[0]); @@ -148,16 +145,16 @@ TEST_F(FastUnwindTest, CloseToZeroFrame) { } } +#endif // SANITIZER_CAN_FAST_UNWIND + TEST(SlowUnwindTest, ShortStackTrace) { - if (StackTrace::WillUseFastUnwind(false)) - return; BufferedStackTrace stack; uptr pc = StackTrace::GetCurrentPc(); uptr bp = GET_CURRENT_FRAME(); - stack.Unwind(0, pc, bp, 0, 0, 0, false); + stack.Unwind(pc, bp, nullptr, false, /*max_depth=*/0); EXPECT_EQ(0U, stack.size); EXPECT_EQ(0U, stack.top_frame_bp); - stack.Unwind(1, pc, bp, 0, 0, 0, false); + stack.Unwind(pc, bp, nullptr, false, /*max_depth=*/1); EXPECT_EQ(1U, stack.size); EXPECT_EQ(pc, stack.trace[0]); EXPECT_EQ(bp, stack.top_frame_bp); |