aboutsummaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_stacktrace.cc
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-01-06 20:13:44 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-01-06 20:13:44 +0000
commit91d212a4a6c2c87a6e09bc8a5e665b011022aaaf (patch)
tree31eb77cd1eadc56f19819a157ec87f83291c392c /lib/sanitizer_common/sanitizer_stacktrace.cc
parentdad1defd96f21c31ea21e4d4b6f969641fe368f8 (diff)
downloadsrc-91d212a4a6c2c87a6e09bc8a5e665b011022aaaf.tar.gz
src-91d212a4a6c2c87a6e09bc8a5e665b011022aaaf.zip
Vendor import of compiler-rt trunk r291274:vendor/compiler-rt/compiler-rt-trunk-r291274
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=311536 svn path=/vendor/compiler-rt/compiler-rt-trunk-r291274/; revision=311537; tag=vendor/compiler-rt/compiler-rt-trunk-r291274
Diffstat (limited to 'lib/sanitizer_common/sanitizer_stacktrace.cc')
-rw-r--r--lib/sanitizer_common/sanitizer_stacktrace.cc17
1 files changed, 6 insertions, 11 deletions
diff --git a/lib/sanitizer_common/sanitizer_stacktrace.cc b/lib/sanitizer_common/sanitizer_stacktrace.cc
index 7ad1f1f25abd..2741dde7a3f3 100644
--- a/lib/sanitizer_common/sanitizer_stacktrace.cc
+++ b/lib/sanitizer_common/sanitizer_stacktrace.cc
@@ -106,10 +106,6 @@ void BufferedStackTrace::FastUnwindStack(uptr pc, uptr bp, uptr stack_top,
}
}
-static bool MatchPc(uptr cur_pc, uptr trace_pc, uptr threshold) {
- return cur_pc - trace_pc <= threshold || trace_pc - cur_pc <= threshold;
-}
-
void BufferedStackTrace::PopStackFrames(uptr count) {
CHECK_LT(count, size);
size -= count;
@@ -118,15 +114,14 @@ void BufferedStackTrace::PopStackFrames(uptr count) {
}
}
+static uptr Distance(uptr a, uptr b) { return a < b ? b - a : a - b; }
+
uptr BufferedStackTrace::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 = 350;
- for (uptr i = 0; i < size; ++i) {
- if (MatchPc(pc, trace[i], kPcThreshold))
- return i;
+ uptr best = 0;
+ for (uptr i = 1; i < size; ++i) {
+ if (Distance(trace[i], pc) < Distance(trace[best], pc)) best = i;
}
- return 0;
+ return best;
}
} // namespace __sanitizer