Fix StackTrace::LocatePcInTrace, add more unit tests for generic StackTrace

llvm-svn: 202849
This commit is contained in:
Alexey Samsonov 2014-03-04 14:06:11 +00:00
parent d920770add
commit 359c105c92
3 changed files with 25 additions and 3 deletions

View File

@ -59,9 +59,9 @@ void GetStackTraceWithPcBpAndContext(StackTrace *stack, uptr max_depth, uptr pc,
if (max_size > 0) { \
stack.top_frame_bp = GET_CURRENT_FRAME(); \
stack.trace[0] = StackTrace::GetCurrentPc(); \
if (max_size > 1) \
stack.trace[1] = GET_CALLER_PC(); \
} \
if (max_size > 1) \
stack.trace[1] = GET_CALLER_PC(); \
} else { \
GetStackTraceWithPcBpAndContext(&stack, max_size, \
StackTrace::GetCurrentPc(), \

View File

@ -72,7 +72,7 @@ void StackTrace::PopStackFrames(uptr count) {
uptr StackTrace::LocatePcInTrace(uptr pc) {
// Use threshold to find PC in stack trace, as PC we want to unwind from may
// slightly differ from return address in the actual unwinded stack trace.
const int kPcThreshold = 192;
const int kPcThreshold = 256;
for (uptr i = 0; i < size; ++i) {
if (MatchPc(pc, trace[i], kPcThreshold))
return i;

View File

@ -102,4 +102,26 @@ TEST_F(FastUnwindTest, OneFrameStackTrace) {
EXPECT_EQ((uptr)&fake_stack[0], trace.top_frame_bp);
}
TEST_F(FastUnwindTest, ZeroFramesStackTrace) {
if (!TryFastUnwind(0))
return;
EXPECT_EQ(0U, trace.size);
EXPECT_EQ(0U, trace.top_frame_bp);
}
TEST(SlowUnwindTest, ShortStackTrace) {
if (StackTrace::WillUseFastUnwind(false))
return;
StackTrace stack;
uptr pc = StackTrace::GetCurrentPc();
uptr bp = GET_CURRENT_FRAME();
stack.Unwind(0, pc, bp, 0, 0, 0, false);
EXPECT_EQ(0U, stack.size);
EXPECT_EQ(0U, stack.top_frame_bp);
stack.Unwind(1, pc, bp, 0, 0, 0, false);
EXPECT_EQ(1U, stack.size);
EXPECT_EQ(pc, stack.trace[0]);
EXPECT_EQ(bp, stack.top_frame_bp);
}
} // namespace __sanitizer