[llvm-commits] [compiler-rt] r163060 - in /compiler-rt/trunk/lib/tsan/rtl: tsan_report.cc tsan_report.h tsan_rtl.h tsan_rtl_mutex.cc tsan_rtl_report.cc
Dmitry Vyukov
dvyukov at google.com
Sat Sep 1 05:13:18 PDT 2012
Author: dvyukov
Date: Sat Sep 1 07:13:18 2012
New Revision: 163060
URL: http://llvm.org/viewvc/llvm-project?rev=163060&view=rev
Log:
tsan: better diagnostics for mutex misuse
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_report.h
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc?rev=163060&r1=163059&r2=163060&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc Sat Sep 1 07:13:18 2012
@@ -49,7 +49,7 @@
TsanPrintf(" (pid=%d)\n", GetPid());
}
-static void PrintStack(const ReportStack *ent) {
+void PrintStack(const ReportStack *ent) {
for (int i = 0; ent; ent = ent->next, i++) {
TsanPrintf(" #%d %s %s:%d", i, ent->func, ent->file, ent->line);
if (ent->col)
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_report.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_report.h?rev=163060&r1=163059&r2=163060&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_report.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_report.h Sat Sep 1 07:13:18 2012
@@ -97,6 +97,7 @@
// Format and output the report to the console/log. No additional logic.
void PrintReport(const ReportDesc *rep);
+void PrintStack(const ReportStack *stack);
} // namespace __tsan
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=163060&r1=163059&r2=163060&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h Sat Sep 1 07:13:18 2012
@@ -453,6 +453,7 @@
#endif
u32 CurrentStackId(ThreadState *thr, uptr pc);
+void PrintCurrentStack(ThreadState *thr, uptr pc);
void Initialize(ThreadState *thr);
int Finalize(ThreadState *thr);
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc?rev=163060&r1=163059&r2=163060&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_mutex.cc Sat Sep 1 07:13:18 2012
@@ -79,6 +79,7 @@
CHECK_GT(s->recursion, 0);
} else {
TsanPrintf("ThreadSanitizer WARNING: double lock\n");
+ PrintCurrentStack(thr, pc);
}
if (s->recursion == 0) {
StatInc(thr, StatMutexLock);
@@ -106,11 +107,13 @@
if (!s->is_broken) {
s->is_broken = true;
TsanPrintf("ThreadSanitizer WARNING: unlock of unlocked mutex\n");
+ PrintCurrentStack(thr, pc);
}
} else if (s->owner_tid != thr->tid) {
if (!s->is_broken) {
s->is_broken = true;
TsanPrintf("ThreadSanitizer WARNING: mutex unlock by another thread\n");
+ PrintCurrentStack(thr, pc);
}
} else {
s->recursion--;
@@ -137,8 +140,10 @@
thr->fast_state.IncrementEpoch();
TraceAddEvent(thr, thr->fast_state.epoch(), EventTypeRLock, addr);
SyncVar *s = CTX()->synctab.GetAndLock(thr, pc, addr, false);
- if (s->owner_tid != SyncVar::kInvalidTid)
+ if (s->owner_tid != SyncVar::kInvalidTid) {
TsanPrintf("ThreadSanitizer WARNING: read lock of a write locked mutex\n");
+ PrintCurrentStack(thr, pc);
+ }
thr->clock.set(thr->tid, thr->fast_state.epoch());
thr->clock.acquire(&s->clock);
s->last_lock = thr->fast_state.raw();
@@ -155,9 +160,11 @@
thr->fast_state.IncrementEpoch();
TraceAddEvent(thr, thr->fast_state.epoch(), EventTypeRUnlock, addr);
SyncVar *s = CTX()->synctab.GetAndLock(thr, pc, addr, true);
- if (s->owner_tid != SyncVar::kInvalidTid)
+ if (s->owner_tid != SyncVar::kInvalidTid) {
TsanPrintf("ThreadSanitizer WARNING: read unlock of a write "
"locked mutex\n");
+ PrintCurrentStack(thr, pc);
+ }
thr->clock.set(thr->tid, thr->fast_state.epoch());
thr->fast_synch_epoch = thr->fast_state.epoch();
thr->clock.release(&s->read_clock);
@@ -203,6 +210,7 @@
} else if (!s->is_broken) {
s->is_broken = true;
TsanPrintf("ThreadSanitizer WARNING: mutex unlock by another thread\n");
+ PrintCurrentStack(thr, pc);
}
s->mtx.Unlock();
}
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=163060&r1=163059&r2=163060&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc Sat Sep 1 07:13:18 2012
@@ -435,4 +435,10 @@
AddRacyStacks(thr, traces, addr_min, addr_max);
}
+void PrintCurrentStack(ThreadState *thr, uptr pc) {
+ StackTrace trace;
+ trace.ObtainCurrent(thr, pc);
+ PrintStack(SymbolizeStack(trace));
+}
+
} // namespace __tsan
More information about the llvm-commits
mailing list