[llvm-commits] [compiler-rt] r170346 - in /compiler-rt/trunk/lib/tsan: lit_tests/race_on_heap.cc lit_tests/race_with_finished_thread.cc lit_tests/simple_stack.c rtl/tsan_report.cc rtl/tsan_report.h rtl/tsan_rtl.h rtl/tsan_rtl_report.cc rtl/tsan_rtl_thread.cc
Dmitry Vyukov
dvyukov at google.com
Mon Dec 17 08:28:15 PST 2012
Author: dvyukov
Date: Mon Dec 17 10:28:15 2012
New Revision: 170346
URL: http://llvm.org/viewvc/llvm-project?rev=170346&view=rev
Log:
tsan: say what thread had created a thread in reports
Modified:
compiler-rt/trunk/lib/tsan/lit_tests/race_on_heap.cc
compiler-rt/trunk/lib/tsan/lit_tests/race_with_finished_thread.cc
compiler-rt/trunk/lib/tsan/lit_tests/simple_stack.c
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_report.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc
Modified: compiler-rt/trunk/lib/tsan/lit_tests/race_on_heap.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/race_on_heap.cc?rev=170346&r1=170345&r2=170346&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/race_on_heap.cc (original)
+++ compiler-rt/trunk/lib/tsan/lit_tests/race_on_heap.cc Mon Dec 17 10:28:15 2012
@@ -42,6 +42,6 @@
// CHECK: #1 alloc
// CHECK: #2 AllocThread
// ...
-// CHECK: Thread T1 (tid={{.*}}, finished) created at:
+// CHECK: Thread T1 (tid={{.*}}, finished) created by main thread at:
// CHECK: #0 pthread_create
// CHECK: #1 main
Modified: compiler-rt/trunk/lib/tsan/lit_tests/race_with_finished_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/race_with_finished_thread.cc?rev=170346&r1=170345&r2=170346&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/race_with_finished_thread.cc (original)
+++ compiler-rt/trunk/lib/tsan/lit_tests/race_with_finished_thread.cc Mon Dec 17 10:28:15 2012
@@ -38,6 +38,6 @@
// CHECK: Previous write of size 4 at {{.*}} by thread T1:
// CHECK: #0 foobar
// CHECK: #1 Thread1
-// CHECK: Thread T1 (tid={{.*}}, finished) created at:
+// CHECK: Thread T1 (tid={{.*}}, finished) created by main thread at:
// CHECK: #0 pthread_create
// CHECK: #1 main
Modified: compiler-rt/trunk/lib/tsan/lit_tests/simple_stack.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/simple_stack.c?rev=170346&r1=170345&r2=170346&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/simple_stack.c (original)
+++ compiler-rt/trunk/lib/tsan/lit_tests/simple_stack.c Mon Dec 17 10:28:15 2012
@@ -56,11 +56,11 @@
// CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack.c:18{{(:26)?}} ({{.*}})
// CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack.c:23{{(:3)?}} ({{.*}})
// CHECK-NEXT: #2 Thread2{{.*}} {{.*}}simple_stack.c:33{{(:3)?}} ({{.*}})
-// CHECK: Thread T1 (tid={{.*}}, running) created at:
+// CHECK: Thread T1 (tid={{.*}}, running) created by main thread at:
// CHECK-NEXT: #0 pthread_create {{.*}} ({{.*}})
// CHECK-NEXT: #1 StartThread{{.*}} {{.*}}simple_stack.c:38{{(:3)?}} ({{.*}})
// CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack.c:43{{(:3)?}} ({{.*}})
-// CHECK: Thread T2 ({{.*}}) created at:
+// CHECK: Thread T2 ({{.*}}) created by main thread at:
// CHECK-NEXT: #0 pthread_create {{.*}} ({{.*}})
// CHECK-NEXT: #1 StartThread{{.*}} {{.*}}simple_stack.c:38{{(:3)?}} ({{.*}})
// CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack.c:44{{(:3)?}} ({{.*}})
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=170346&r1=170345&r2=170346&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc Mon Dec 17 10:28:15 2012
@@ -35,6 +35,14 @@
#ifndef TSAN_GO
+const int kThreadBufSize = 32;
+const char *thread_name(char *buf, int tid) {
+ if (tid == 0)
+ return "main thread";
+ internal_snprintf(buf, kThreadBufSize, "thread T%d", tid);
+ return buf;
+}
+
static void PrintHeader(ReportType typ) {
Printf("WARNING: ThreadSanitizer: ");
@@ -82,14 +90,12 @@
}
static void PrintMop(const ReportMop *mop, bool first) {
- Printf(" %s of size %d at %p",
+ char thrbuf[kThreadBufSize];
+ Printf(" %s of size %d at %p by %s",
(first ? (mop->write ? "Write" : "Read")
: (mop->write ? "Previous write" : "Previous read")),
- mop->size, (void*)mop->addr);
- if (mop->tid == 0)
- Printf(" by main thread");
- else
- Printf(" by thread T%d", mop->tid);
+ mop->size, (void*)mop->addr,
+ thread_name(thrbuf, mop->tid));
PrintMutexSet(mop->mset);
Printf(":\n");
PrintStack(mop->stack);
@@ -101,12 +107,9 @@
loc->name, loc->size, loc->addr, loc->file, loc->line,
loc->module, loc->offset);
} else if (loc->type == ReportLocationHeap) {
- Printf(" Location is heap block of size %zu at %p allocated",
- loc->size, loc->addr);
- if (loc->tid == 0)
- Printf(" by main thread:\n");
- else
- Printf(" by thread T%d:\n", loc->tid);
+ char thrbuf[kThreadBufSize];
+ Printf(" Location is heap block of size %zu at %p allocated by %s:\n",
+ loc->size, loc->addr, thread_name(thrbuf, loc->tid));
PrintStack(loc->stack);
} else if (loc->type == ReportLocationStack) {
Printf(" Location is stack of thread T%d:\n\n", loc->tid);
@@ -128,9 +131,12 @@
Printf(" Thread T%d", rt->id);
if (rt->name)
Printf(" '%s'", rt->name);
- Printf(" (tid=%zu, %s)", rt->pid, rt->running ? "running" : "finished");
+ char thrbuf[kThreadBufSize];
+ Printf(" (tid=%zu, %s) created by %s",
+ rt->pid, rt->running ? "running" : "finished",
+ thread_name(thrbuf, rt->parent_tid));
if (rt->stack)
- Printf(" created at:");
+ Printf(" at:");
Printf("\n");
PrintStack(rt->stack);
}
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=170346&r1=170345&r2=170346&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_report.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_report.h Mon Dec 17 10:28:15 2012
@@ -78,6 +78,7 @@
uptr pid;
bool running;
char *name;
+ int parent_tid;
ReportStack *stack;
};
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=170346&r1=170345&r2=170346&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h Mon Dec 17 10:28:15 2012
@@ -377,6 +377,7 @@
u64 epoch0;
u64 epoch1;
StackTrace creation_stack;
+ int creation_tid;
ThreadDeadInfo *dead_info;
ThreadContext *dead_next; // In dead thread list.
char *name; // As annotated by user.
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=170346&r1=170345&r2=170346&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc Mon Dec 17 10:28:15 2012
@@ -180,6 +180,7 @@
rt->pid = tctx->os_id;
rt->running = (tctx->status == ThreadStatusRunning);
rt->name = tctx->name ? internal_strdup(tctx->name) : 0;
+ rt->parent_tid = tctx->creation_tid;
rt->stack = SymbolizeStack(tctx->creation_stack);
}
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc?rev=170346&r1=170345&r2=170346&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc Mon Dec 17 10:28:15 2012
@@ -156,6 +156,7 @@
thr->clock.release(&tctx->sync);
StatInc(thr, StatSyncRelease);
tctx->creation_stack.ObtainCurrent(thr, pc);
+ tctx->creation_tid = thr->tid;
}
return tid;
}
More information about the llvm-commits
mailing list