[PATCH] D28342: [asan] Fix comparison in BufferedStackTrace::LocatePcInTrace

Vitaly Buka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 5 13:15:43 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL291173: [asan] Fix comparison in BufferedStackTrace::LocatePcInTrace (authored by vitalybuka).

Changed prior to commit:
  https://reviews.llvm.org/D28342?vs=83190&id=83291#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28342

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc
@@ -106,27 +106,22 @@
   }
 }
 
-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;
   for (uptr i = 0; i < size; ++i) {
     trace_buffer[i] = trace_buffer[i + 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28342.83291.patch
Type: text/x-patch
Size: 1258 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170105/94ffe17d/attachment.bin>


More information about the llvm-commits mailing list