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

Vitaly Buka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 4 20:24:44 PST 2017


vitalybuka created this revision.
vitalybuka added a reviewer: eugenis.
vitalybuka added a subscriber: llvm-commits.
Herald added a subscriber: kubabrecka.

Debug builds can have larger distance between stack trace and PC on that stack.
If we assume that PC is always correct we can snap it to the nearest trace.


https://reviews.llvm.org/D28342

Files:
  lib/sanitizer_common/sanitizer_stacktrace.cc
  lib/tsan/rtl/tsan_rtl_report.cc


Index: lib/tsan/rtl/tsan_rtl_report.cc
===================================================================
--- lib/tsan/rtl/tsan_rtl_report.cc
+++ lib/tsan/rtl/tsan_rtl_report.cc
@@ -36,7 +36,7 @@
                      u64 v1, u64 v2) {
   // There is high probability that interceptors will check-fail as well,
   // on the other hand there is no sense in processing interceptors
-  // since we are going to die soon.
+  // q since we are going to die soon.
   ScopedIgnoreInterceptors ignore;
 #if !SANITIZER_GO
   cur_thread()->ignore_sync++;
Index: lib/sanitizer_common/sanitizer_stacktrace.cc
===================================================================
--- lib/sanitizer_common/sanitizer_stacktrace.cc
+++ 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.83189.patch
Type: text/x-patch
Size: 1750 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170105/d66591d8/attachment.bin>


More information about the llvm-commits mailing list