diff options
5 files changed, 18 insertions, 16 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc index a00b5bb4c44..7b8d4e1d0df 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -139,12 +139,17 @@ uptr Unwind_GetIP(struct _Unwind_Context *ctx) { #endif } +struct UnwindTraceArg { + StackTrace *stack; + uptr max_depth; +}; + _Unwind_Reason_Code Unwind_Trace(struct _Unwind_Context *ctx, void *param) { - StackTrace *b = (StackTrace*)param; - CHECK(b->size < b->max_size); + UnwindTraceArg *arg = (UnwindTraceArg*)param; + CHECK_LT(arg->stack->size, arg->max_depth); uptr pc = Unwind_GetIP(ctx); - b->trace[b->size++] = pc; - if (b->size == b->max_size) return UNWIND_STOP; + arg->stack->trace[arg->stack->size++] = pc; + if (arg->stack->size == arg->max_depth) return UNWIND_STOP; return UNWIND_CONTINUE; } @@ -153,10 +158,10 @@ static bool MatchPc(uptr cur_pc, uptr trace_pc) { } void StackTrace::SlowUnwindStack(uptr pc, uptr max_depth) { - this->size = 0; - this->max_size = max_depth; + size = 0; + UnwindTraceArg arg = {this, max_depth}; if (max_depth > 1) { - _Unwind_Backtrace(Unwind_Trace, this); + _Unwind_Backtrace(Unwind_Trace, &arg); // We need to pop a few frames so that pc is on top. // trace[0] belongs to the current function so we always pop it. int to_pop = 1; @@ -165,9 +170,9 @@ void StackTrace::SlowUnwindStack(uptr pc, uptr max_depth) { else if (size > 3 && MatchPc(pc, trace[3])) to_pop = 3; else if (size > 4 && MatchPc(pc, trace[4])) to_pop = 4; else if (size > 5 && MatchPc(pc, trace[5])) to_pop = 5; - this->PopStackFrames(to_pop); + PopStackFrames(to_pop); } - this->trace[0] = pc; + trace[0] = pc; } #endif // !SANITIZER_GO diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc index 53528a84e44..9fe6656fa5d 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc @@ -114,8 +114,7 @@ uptr StackTrace::GetCurrentPc() { void StackTrace::FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom, uptr max_depth) { - max_size = max_depth; - if (max_size == 0) { + if (max_depth == 0) { size = 0; return; } @@ -129,7 +128,7 @@ void StackTrace::FastUnwindStack(uptr pc, uptr bp, frame < (uhwptr *)stack_top - 2 && frame > (uhwptr *)stack_bottom && IsAligned((uptr)frame, sizeof(*frame)) && - size < max_size) { + size < max_depth) { uhwptr pc1 = frame[1]; if (pc1 != pc) { trace[size++] = (uptr) pc1; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h index 26ffc5e3546..e7e244aaf5a 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h @@ -32,8 +32,8 @@ struct StackTrace { typedef bool (*SymbolizeCallback)(const void *pc, char *out_buffer, int out_size); uptr size; - uptr max_size; uptr trace[kStackTraceMax]; + static void PrintStack(const uptr *addr, uptr size, bool symbolize, SymbolizeCallback symbolize_callback); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_win.cc b/compiler-rt/lib/sanitizer_common/sanitizer_win.cc index f42e92f1577..77e62180f9d 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_win.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_win.cc @@ -381,13 +381,12 @@ void StackTrace::Unwind(uptr max_depth, uptr pc, uptr bp, uptr stack_top, (void)fast; (void)stack_top; (void)stack_bottom; - max_size = max_depth; void *tmp[kStackTraceMax]; // FIXME: CaptureStackBackTrace might be too slow for us. // FIXME: Compare with StackWalk64. // FIXME: Look at LLVMUnhandledExceptionFilter in Signals.inc - uptr cs_ret = CaptureStackBackTrace(1, max_size, tmp, 0); + uptr cs_ret = CaptureStackBackTrace(1, max_depth, tmp, 0); uptr offset = 0; // Skip the RTL frames by searching for the PC in the stacktrace. // FIXME: this doesn't work well for the malloc/free stacks yet. 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 82c4426d8f8..8d2ac2bd543 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc @@ -91,7 +91,6 @@ 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]); } |