[compiler-rt] r178159 - tsan: print matched suppressions if print_suppressions=1 flag is provided

Dmitry Vyukov dvyukov at google.com
Wed Mar 27 10:59:57 PDT 2013


Author: dvyukov
Date: Wed Mar 27 12:59:57 2013
New Revision: 178159

URL: http://llvm.org/viewvc/llvm-project?rev=178159&view=rev
Log:
tsan: print matched suppressions if print_suppressions=1 flag is provided


Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.h

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h?rev=178159&r1=178158&r2=178159&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_defs.h Wed Mar 27 12:59:57 2013
@@ -162,6 +162,7 @@ class ReportDesc;
 class RegionAlloc;
 class StackTrace;
 struct MBlock;
+struct Suppression;
 
 }  // namespace __tsan
 

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc?rev=178159&r1=178158&r2=178159&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc Wed Mar 27 12:59:57 2013
@@ -49,6 +49,7 @@ void InitializeFlags(Flags *f, const cha
   f->force_seq_cst_atomics = false;
   f->strip_path_prefix = "";
   f->suppressions = "";
+  f->print_suppressions = false;
   f->exitcode = 66;
   f->log_path = "stderr";
   f->atexit_sleep_ms = 1000;
@@ -78,6 +79,7 @@ void InitializeFlags(Flags *f, const cha
   ParseFlag(env, &f->force_seq_cst_atomics, "force_seq_cst_atomics");
   ParseFlag(env, &f->strip_path_prefix, "strip_path_prefix");
   ParseFlag(env, &f->suppressions, "suppressions");
+  ParseFlag(env, &f->print_suppressions, "print_suppressions");
   ParseFlag(env, &f->exitcode, "exitcode");
   ParseFlag(env, &f->log_path, "log_path");
   ParseFlag(env, &f->atexit_sleep_ms, "atexit_sleep_ms");

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h?rev=178159&r1=178158&r2=178159&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h Wed Mar 27 12:59:57 2013
@@ -52,6 +52,8 @@ struct Flags {
   const char *strip_path_prefix;
   // Suppressions filename.
   const char *suppressions;
+  // Print matched suppressions at exit.
+  bool print_suppressions;
   // Override exit status if something was reported.
   int exitcode;
   // Write logs to "log_path.pid".

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=178159&r1=178158&r2=178159&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Wed Mar 27 12:59:57 2013
@@ -277,6 +277,9 @@ int Finalize(ThreadState *thr) {
         ctx->nmissed_expected);
   }
 
+  if (flags()->print_suppressions)
+    PrintMatchedSuppressions();
+
   failed = OnFinalize(failed);
 
   StatAggregate(ctx->stat, thr->stat);

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h?rev=178159&r1=178158&r2=178159&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h Wed Mar 27 12:59:57 2013
@@ -512,6 +512,7 @@ struct RacyAddress {
 struct FiredSuppression {
   ReportType type;
   uptr pc;
+  Suppression *supp;
 };
 
 struct Context {

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc?rev=178159&r1=178158&r2=178159&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc Wed Mar 27 12:59:57 2013
@@ -501,12 +501,13 @@ bool OutputReport(Context *ctx,
                   const ReportStack *suppress_stack2) {
   atomic_store(&ctx->last_symbolize_time_ns, NanoTime(), memory_order_relaxed);
   const ReportDesc *rep = srep.GetReport();
-  uptr suppress_pc = IsSuppressed(rep->typ, suppress_stack1);
+  Suppression *supp = 0;
+  uptr suppress_pc = IsSuppressed(rep->typ, suppress_stack1, &supp);
   if (suppress_pc == 0)
-    suppress_pc = IsSuppressed(rep->typ, suppress_stack2);
+    suppress_pc = IsSuppressed(rep->typ, suppress_stack2, &supp);
   if (suppress_pc != 0) {
-    FiredSuppression supp = {srep.GetReport()->typ, suppress_pc};
-    ctx->fired_suppressions.PushBack(supp);
+    FiredSuppression s = {srep.GetReport()->typ, suppress_pc, supp};
+    ctx->fired_suppressions.PushBack(s);
   }
   if (OnReport(rep, suppress_pc != 0))
     return false;
@@ -522,8 +523,12 @@ bool IsFiredSuppression(Context *ctx,
     if (ctx->fired_suppressions[k].type != srep.GetReport()->typ)
       continue;
     for (uptr j = 0; j < trace.Size(); j++) {
-      if (trace.Get(j) == ctx->fired_suppressions[k].pc)
+      FiredSuppression *s = &ctx->fired_suppressions[k];
+      if (trace.Get(j) == s->pc) {
+        if (s->supp)
+          s->supp->hit_count++;
         return true;
+      }
     }
   }
   return false;
@@ -560,7 +565,7 @@ static bool IsJavaNonsense(const ReportD
           || (frame->func == 0 && frame->file == 0 && frame->line == 0
           && frame->module == 0)) {
         if (frame) {
-          FiredSuppression supp = {rep->typ, frame->pc};
+          FiredSuppression supp = {rep->typ, frame->pc, 0};
           CTX()->fired_suppressions.PushBack(supp);
         }
         return true;

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc?rev=178159&r1=178158&r2=178159&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc Wed Mar 27 12:59:57 2013
@@ -127,6 +127,7 @@ Suppression *SuppressionParse(Suppressio
       s->templ = (char*)internal_alloc(MBlockSuppression, end2 - line + 1);
       internal_memcpy(s->templ, line, end2 - line);
       s->templ[end2 - line] = 0;
+      s->hit_count = 0;
     }
     if (end[0] == 0)
       break;
@@ -144,7 +145,7 @@ void InitializeSuppressions() {
 #endif
 }
 
-uptr IsSuppressed(ReportType typ, const ReportStack *stack) {
+uptr IsSuppressed(ReportType typ, const ReportStack *stack, Suppression **sp) {
   if (g_suppressions == 0 || stack == 0)
     return 0;
   SuppressionType stype;
@@ -165,10 +166,38 @@ uptr IsSuppressed(ReportType typ, const
            SuppressionMatch(supp->templ, frame->file) ||
            SuppressionMatch(supp->templ, frame->module))) {
         DPrintf("ThreadSanitizer: matched suppression '%s'\n", supp->templ);
+        supp->hit_count++;
+        *sp = supp;
         return frame->pc;
       }
     }
   }
   return 0;
 }
+
+static const char *SuppTypeStr(SuppressionType t) {
+  switch (t) {
+  case SuppressionRace:   return "race";
+  case SuppressionMutex:  return "mutex";
+  case SuppressionThread: return "thread";
+  case SuppressionSignal: return "signal";
+  }
+  CHECK(0);
+  return "unknown";
+}
+
+void PrintMatchedSuppressions() {
+  int hit_count = 0;
+  for (Suppression *supp = g_suppressions; supp; supp = supp->next)
+    hit_count += supp->hit_count;
+  if (hit_count == 0)
+    return;
+  Printf("ThreadSanitizer: Matched %d suppressions (pid=%d):\n",
+      hit_count, GetPid());
+  for (Suppression *supp = g_suppressions; supp; supp = supp->next) {
+    if (supp->hit_count == 0)
+      continue;
+    Printf("%d %s:%s\n", supp->hit_count, SuppTypeStr(supp->type), supp->templ);
+  }
+}
 }  // namespace __tsan

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.h?rev=178159&r1=178158&r2=178159&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.h Wed Mar 27 12:59:57 2013
@@ -17,10 +17,6 @@
 
 namespace __tsan {
 
-void InitializeSuppressions();
-void FinalizeSuppressions();
-uptr IsSuppressed(ReportType typ, const ReportStack *stack);
-
 // Exposed for testing.
 enum SuppressionType {
   SuppressionRace,
@@ -33,8 +29,13 @@ struct Suppression {
   Suppression *next;
   SuppressionType type;
   char *templ;
+  int hit_count;
 };
 
+void InitializeSuppressions();
+void FinalizeSuppressions();
+void PrintMatchedSuppressions();
+uptr IsSuppressed(ReportType typ, const ReportStack *stack, Suppression **sp);
 Suppression *SuppressionParse(Suppression *head, const char* supp);
 bool SuppressionMatch(char *templ, const char *str);
 





More information about the llvm-commits mailing list