From cf6ac12e23f162e93e291e66f0852b2ccf06ce62 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Wed, 13 Nov 2013 15:20:10 +0000 Subject: [PATCH] [Sanitizer] Use same PC threshold in slow unwinder on all platforms llvm-svn: 194580 --- .../lib/sanitizer_common/sanitizer_linux_libcdep.cc | 2 +- compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc | 7 +++++-- compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc index eba6eb9682fe..f6de9f1f815a 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -161,7 +161,7 @@ void StackTrace::SlowUnwindStack(uptr pc, uptr max_depth) { UnwindTraceArg arg = {this, Min(max_depth + 1, kStackTraceMax)}; _Unwind_Backtrace(Unwind_Trace, &arg); // We need to pop a few frames so that pc is on top. - uptr to_pop = LocatePcInTrace(pc, 64, 6); + uptr to_pop = LocatePcInTrace(pc, 6); // trace[0] belongs to the current function so we always pop it. if (to_pop == 0) to_pop = 1; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc index f03490b8c4eb..8e591189dc5c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc @@ -152,9 +152,12 @@ static bool MatchPc(uptr cur_pc, uptr trace_pc, uptr threshold) { } uptr -StackTrace::LocatePcInTrace(uptr pc, uptr pc_threshold, uptr max_pc_depth) { +StackTrace::LocatePcInTrace(uptr pc, uptr max_pc_depth) { + // 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 = 64; for (uptr i = 0; i < max_pc_depth && i < size; ++i) { - if (MatchPc(pc, trace[i], pc_threshold)) + if (MatchPc(pc, trace[i], kPcThreshold)) return i; } return 0; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h index 88f0a03b1117..73474e65b6a7 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h @@ -69,7 +69,7 @@ struct StackTrace { uptr max_depth); void SlowUnwindStack(uptr pc, uptr max_depth); void PopStackFrames(uptr count); - uptr LocatePcInTrace(uptr pc, uptr pc_threshold = 0, uptr max_pc_depth = -1); + uptr LocatePcInTrace(uptr pc, uptr max_pc_depth = -1); }; } // namespace __sanitizer