[compiler-rt] r192428 - [Sanitizer] Simplify StackTrace::FastUnwindStack interface and fix a bug with one-frame stack traces
Alexey Samsonov
samsonov at google.com
Fri Oct 11 02:58:31 PDT 2013
Author: samsonov
Date: Fri Oct 11 04:58:30 2013
New Revision: 192428
URL: http://llvm.org/viewvc/llvm-project?rev=192428&view=rev
Log:
[Sanitizer] Simplify StackTrace::FastUnwindStack interface and fix a bug with one-frame stack traces
Modified:
compiler-rt/trunk/lib/msan/msan.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc
Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=192428&r1=192427&r2=192428&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Fri Oct 11 04:58:30 2013
@@ -190,10 +190,7 @@ void GetStackTrace(StackTrace *stack, up
uptr stack_top, stack_bottom;
GetCurrentStackBounds(&stack_top, &stack_bottom);
- stack->size = 0;
- stack->trace[0] = pc;
- stack->max_size = max_s;
- stack->FastUnwindStack(pc, bp, stack_top, stack_bottom);
+ stack->FastUnwindStack(pc, bp, stack_top, stack_bottom, max_s);
}
void PrintWarning(uptr pc, uptr bp) {
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc?rev=192428&r1=192427&r2=192428&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc Fri Oct 11 04:58:30 2013
@@ -32,6 +32,10 @@ void ParseCommonFlagsFromString(const ch
ParseFlag(str, &f->detect_leaks, "detect_leaks");
ParseFlag(str, &f->leak_check_at_exit, "leak_check_at_exit");
ParseFlag(str, &f->allocator_may_return_null, "allocator_may_return_null");
+
+ // Do a sanity check for certain flags.
+ if (f->malloc_context_size < 1)
+ f->malloc_context_size = 1;
}
static bool GetFlagValue(const char *env, const char *name,
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc?rev=192428&r1=192427&r2=192428&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc Fri Oct 11 04:58:30 2013
@@ -92,22 +92,16 @@ int internal_isatty(fd_t fd) {
#ifndef SANITIZER_GO
void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp,
uptr stack_top, uptr stack_bottom, bool fast) {
-#if !SANITIZER_CAN_FAST_UNWIND
- fast = false;
-#endif
-#if SANITIZER_MAC
- // Always unwind fast on Mac.
- (void)fast;
-#else
+ // 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)
- return stack->SlowUnwindStack(pc, max_s);
-#endif // SANITIZER_MAC
- stack->size = 0;
- stack->trace[0] = pc;
- if (max_s > 1) {
- stack->max_size = max_s;
- stack->FastUnwindStack(pc, bp, stack_top, stack_bottom);
- }
+ stack->SlowUnwindStack(pc, max_s);
+ else
+ stack->FastUnwindStack(pc, bp, stack_top, stack_bottom, max_s);
}
#endif // SANITIZER_GO
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc?rev=192428&r1=192427&r2=192428&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc Fri Oct 11 04:58:30 2013
@@ -106,8 +106,14 @@ uptr StackTrace::GetCurrentPc() {
}
void StackTrace::FastUnwindStack(uptr pc, uptr bp,
- uptr stack_top, uptr stack_bottom) {
- CHECK(size == 0 && trace[0] == pc);
+ uptr stack_top, uptr stack_bottom,
+ uptr max_depth) {
+ max_size = max_depth;
+ if (max_size == 0) {
+ size = 0;
+ return;
+ }
+ trace[0] = pc;
size = 1;
uhwptr *frame = (uhwptr *)bp;
uhwptr *prev_frame = frame - 1;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h?rev=192428&r1=192427&r2=192428&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h Fri Oct 11 04:58:30 2013
@@ -51,7 +51,8 @@ struct StackTrace {
}
}
- void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom);
+ 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);
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc?rev=192428&r1=192427&r2=192428&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc Fri Oct 11 04:58:30 2013
@@ -47,16 +47,11 @@ void FastUnwindTest::SetUp() {
// Bottom is one slot before the start because FastUnwindStack uses >.
fake_bottom = (uptr)&fake_stack[-1];
start_pc = PC(0);
-
- // This is common setup done by __asan::GetStackTrace().
- trace.size = 0;
- trace.max_size = ARRAY_SIZE(fake_stack);
- trace.trace[0] = start_pc;
}
TEST_F(FastUnwindTest, Basic) {
trace.FastUnwindStack(start_pc, (uptr)&fake_stack[0],
- fake_top, fake_bottom);
+ fake_top, fake_bottom, kStackTraceMax);
// Should get all on-stack retaddrs and start_pc.
EXPECT_EQ(6U, trace.size);
EXPECT_EQ(start_pc, trace.trace[0]);
@@ -70,7 +65,7 @@ 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);
+ fake_top, fake_bottom, kStackTraceMax);
// 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]);
@@ -83,7 +78,7 @@ TEST_F(FastUnwindTest, MisalignedFramePo
// Make one fp misaligned.
fake_stack[4] += 3;
trace.FastUnwindStack(start_pc, (uptr)&fake_stack[0],
- fake_top, fake_bottom);
+ fake_top, fake_bottom, kStackTraceMax);
// 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]);
@@ -92,5 +87,12 @@ TEST_F(FastUnwindTest, MisalignedFramePo
}
}
+TEST_F(FastUnwindTest, OneFrameStackTrace) {
+ trace.FastUnwindStack(start_pc, (uptr)&fake_stack[0],
+ fake_top, fake_bottom, 1);
+ EXPECT_EQ(1U, trace.size);
+ EXPECT_EQ(1U, trace.max_size);
+ EXPECT_EQ(start_pc, trace.trace[0]);
+}
} // namespace __sanitizer
More information about the llvm-commits
mailing list