[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
This commit is contained in:
Julian Lettner 2019-03-01 23:50:47 +00:00
parent 4b1b4bf3b3
commit a30b116e6f
2 changed files with 24 additions and 25 deletions

View File

@ -139,6 +139,8 @@ struct BufferedStackTrace : public StackTrace {
BufferedStackTrace(const BufferedStackTrace &) = delete; BufferedStackTrace(const BufferedStackTrace &) = delete;
void operator=(const BufferedStackTrace &) = delete; void operator=(const BufferedStackTrace &) = delete;
friend class FastUnwindTest;
}; };
// Check if given pointer points into allocated stack area. // Check if given pointer points into allocated stack area.

View File

@ -20,18 +20,15 @@ class FastUnwindTest : public ::testing::Test {
protected: protected:
virtual void SetUp(); virtual void SetUp();
virtual void TearDown(); virtual void TearDown();
bool TryFastUnwind(uptr max_depth) {
if (!StackTrace::WillUseFastUnwind(true)) void UnwindFast();
return false;
trace.Unwind(max_depth, start_pc, (uptr)&fake_stack[0], 0, fake_top,
fake_bottom, true);
return true;
}
void *mapping; void *mapping;
uhwptr *fake_stack; uhwptr *fake_stack;
const uptr fake_stack_size = 10; const uptr fake_stack_size = 10;
uhwptr start_pc; uhwptr start_pc;
uhwptr fake_bp;
uhwptr fake_top; uhwptr fake_top;
uhwptr fake_bottom; uhwptr fake_bottom;
BufferedStackTrace trace; BufferedStackTrace trace;
@ -62,6 +59,7 @@ void FastUnwindTest::SetUp() {
fake_top = (uhwptr)&fake_stack[fake_stack_size + 2]; fake_top = (uhwptr)&fake_stack[fake_stack_size + 2];
// Bottom is one slot before the start because UnwindFast uses >. // Bottom is one slot before the start because UnwindFast uses >.
fake_bottom = (uhwptr)mapping; fake_bottom = (uhwptr)mapping;
fake_bp = (uptr)&fake_stack[0];
start_pc = PC(0); start_pc = PC(0);
} }
@ -70,9 +68,14 @@ void FastUnwindTest::TearDown() {
UnmapOrDie(mapping, 2 * ps); 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) { TEST_F(FastUnwindTest, Basic) {
if (!TryFastUnwind(kStackTraceMax)) UnwindFast();
return;
// Should get all on-stack retaddrs and start_pc. // Should get all on-stack retaddrs and start_pc.
EXPECT_EQ(6U, trace.size); EXPECT_EQ(6U, trace.size);
EXPECT_EQ(start_pc, trace.trace[0]); EXPECT_EQ(start_pc, trace.trace[0]);
@ -85,8 +88,7 @@ TEST_F(FastUnwindTest, Basic) {
TEST_F(FastUnwindTest, FramePointerLoop) { TEST_F(FastUnwindTest, FramePointerLoop) {
// Make one fp point to itself. // Make one fp point to itself.
fake_stack[4] = (uhwptr)&fake_stack[4]; fake_stack[4] = (uhwptr)&fake_stack[4];
if (!TryFastUnwind(kStackTraceMax)) UnwindFast();
return;
// Should get all on-stack retaddrs up to the 4th slot and start_pc. // Should get all on-stack retaddrs up to the 4th slot and start_pc.
EXPECT_EQ(4U, trace.size); EXPECT_EQ(4U, trace.size);
EXPECT_EQ(start_pc, trace.trace[0]); EXPECT_EQ(start_pc, trace.trace[0]);
@ -98,8 +100,7 @@ TEST_F(FastUnwindTest, FramePointerLoop) {
TEST_F(FastUnwindTest, MisalignedFramePointer) { TEST_F(FastUnwindTest, MisalignedFramePointer) {
// Make one fp misaligned. // Make one fp misaligned.
fake_stack[4] += 3; fake_stack[4] += 3;
if (!TryFastUnwind(kStackTraceMax)) UnwindFast();
return;
// Should get all on-stack retaddrs up to the 4th slot and start_pc. // Should get all on-stack retaddrs up to the 4th slot and start_pc.
EXPECT_EQ(4U, trace.size); EXPECT_EQ(4U, trace.size);
EXPECT_EQ(start_pc, trace.trace[0]); EXPECT_EQ(start_pc, trace.trace[0]);
@ -109,16 +110,14 @@ TEST_F(FastUnwindTest, MisalignedFramePointer) {
} }
TEST_F(FastUnwindTest, OneFrameStackTrace) { TEST_F(FastUnwindTest, OneFrameStackTrace) {
if (!TryFastUnwind(1)) trace.Unwind(start_pc, fake_bp, nullptr, true, 1);
return;
EXPECT_EQ(1U, trace.size); EXPECT_EQ(1U, trace.size);
EXPECT_EQ(start_pc, trace.trace[0]); EXPECT_EQ(start_pc, trace.trace[0]);
EXPECT_EQ((uhwptr)&fake_stack[0], trace.top_frame_bp); EXPECT_EQ((uhwptr)&fake_stack[0], trace.top_frame_bp);
} }
TEST_F(FastUnwindTest, ZeroFramesStackTrace) { TEST_F(FastUnwindTest, ZeroFramesStackTrace) {
if (!TryFastUnwind(0)) trace.Unwind(start_pc, fake_bp, nullptr, true, 0);
return;
EXPECT_EQ(0U, trace.size); EXPECT_EQ(0U, trace.size);
EXPECT_EQ(0U, trace.top_frame_bp); EXPECT_EQ(0U, trace.top_frame_bp);
} }
@ -128,8 +127,7 @@ TEST_F(FastUnwindTest, FPBelowPrevFP) {
// current FP. // current FP.
fake_stack[0] = (uhwptr)&fake_stack[-50]; fake_stack[0] = (uhwptr)&fake_stack[-50];
fake_stack[1] = PC(1); fake_stack[1] = PC(1);
if (!TryFastUnwind(3)) UnwindFast();
return;
EXPECT_EQ(2U, trace.size); EXPECT_EQ(2U, trace.size);
EXPECT_EQ(PC(0), trace.trace[0]); EXPECT_EQ(PC(0), trace.trace[0]);
EXPECT_EQ(PC(1), trace.trace[1]); EXPECT_EQ(PC(1), trace.trace[1]);
@ -138,8 +136,7 @@ TEST_F(FastUnwindTest, FPBelowPrevFP) {
TEST_F(FastUnwindTest, CloseToZeroFrame) { TEST_F(FastUnwindTest, CloseToZeroFrame) {
// Make one pc a NULL pointer. // Make one pc a NULL pointer.
fake_stack[5] = 0x0; fake_stack[5] = 0x0;
if (!TryFastUnwind(kStackTraceMax)) UnwindFast();
return;
// The stack should be truncated at the NULL pointer (and not include it). // The stack should be truncated at the NULL pointer (and not include it).
EXPECT_EQ(3U, trace.size); EXPECT_EQ(3U, trace.size);
EXPECT_EQ(start_pc, trace.trace[0]); EXPECT_EQ(start_pc, trace.trace[0]);
@ -148,16 +145,16 @@ TEST_F(FastUnwindTest, CloseToZeroFrame) {
} }
} }
#endif // SANITIZER_CAN_FAST_UNWIND
TEST(SlowUnwindTest, ShortStackTrace) { TEST(SlowUnwindTest, ShortStackTrace) {
if (StackTrace::WillUseFastUnwind(false))
return;
BufferedStackTrace stack; BufferedStackTrace stack;
uptr pc = StackTrace::GetCurrentPc(); uptr pc = StackTrace::GetCurrentPc();
uptr bp = GET_CURRENT_FRAME(); 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.size);
EXPECT_EQ(0U, stack.top_frame_bp); 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(1U, stack.size);
EXPECT_EQ(pc, stack.trace[0]); EXPECT_EQ(pc, stack.trace[0]);
EXPECT_EQ(bp, stack.top_frame_bp); EXPECT_EQ(bp, stack.top_frame_bp);