From 27d5b37c38a1b303d8bcd59a069d563a39408dec Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 2 Oct 2012 11:52:05 +0000 Subject: [PATCH] tsan: output tid's in reports llvm-svn: 164998 --- compiler-rt/lib/sanitizer_common/sanitizer_common.h | 1 + compiler-rt/lib/sanitizer_common/sanitizer_posix.cc | 5 +++++ compiler-rt/lib/tsan/go/tsan_go.cc | 2 +- compiler-rt/lib/tsan/lit_tests/race_on_heap.cc | 2 +- compiler-rt/lib/tsan/lit_tests/race_with_finished_thread.cc | 2 +- compiler-rt/lib/tsan/lit_tests/simple_stack.c | 2 +- compiler-rt/lib/tsan/rtl/tsan_interceptors.cc | 2 +- compiler-rt/lib/tsan/rtl/tsan_report.cc | 2 +- compiler-rt/lib/tsan/rtl/tsan_report.h | 1 + compiler-rt/lib/tsan/rtl/tsan_rtl.cc | 3 ++- compiler-rt/lib/tsan/rtl/tsan_rtl.h | 3 ++- compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc | 1 + compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc | 3 ++- 13 files changed, 20 insertions(+), 9 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index c4d2364..04b08b7 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -34,6 +34,7 @@ const uptr kMmapGranularity = 1UL << 16; // Threads int GetPid(); +int GetTid(); uptr GetThreadSelf(); void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top, uptr *stack_bottom); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc index e3f8516..7d21b5f 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc @@ -27,6 +27,7 @@ #include #include #include +#include #include namespace __sanitizer { @@ -37,6 +38,10 @@ int GetPid() { return getpid(); } +int GetTid() { + return syscall(__NR_gettid); +} + uptr GetThreadSelf() { return (uptr)pthread_self(); } diff --git a/compiler-rt/lib/tsan/go/tsan_go.cc b/compiler-rt/lib/tsan/go/tsan_go.cc index 2aa9f17..77da9fe 100644 --- a/compiler-rt/lib/tsan/go/tsan_go.cc +++ b/compiler-rt/lib/tsan/go/tsan_go.cc @@ -149,7 +149,7 @@ void __tsan_go_start(int pgoid, int chgoid, void *pc) { thr->in_rtl++; parent->in_rtl++; int goid2 = ThreadCreate(parent, (uptr)pc, 0, true); - ThreadStart(thr, goid2); + ThreadStart(thr, goid2, 0); parent->in_rtl--; thr->in_rtl--; } diff --git a/compiler-rt/lib/tsan/lit_tests/race_on_heap.cc b/compiler-rt/lib/tsan/lit_tests/race_on_heap.cc index 1fdf54d..855c309 100644 --- a/compiler-rt/lib/tsan/lit_tests/race_on_heap.cc +++ b/compiler-rt/lib/tsan/lit_tests/race_on_heap.cc @@ -42,6 +42,6 @@ int main() { // CHECK: #1 alloc // CHECK: #2 AllocThread // ... -// CHECK: Thread 1 (finished) created at: +// CHECK: Thread 1 (tid={{.*}}, finished) created at: // CHECK: #0 pthread_create // CHECK: #1 main diff --git a/compiler-rt/lib/tsan/lit_tests/race_with_finished_thread.cc b/compiler-rt/lib/tsan/lit_tests/race_with_finished_thread.cc index e50c22b..4008ecd 100644 --- a/compiler-rt/lib/tsan/lit_tests/race_with_finished_thread.cc +++ b/compiler-rt/lib/tsan/lit_tests/race_with_finished_thread.cc @@ -38,6 +38,6 @@ int main() { // CHECK: Previous write of size 4 at {{.*}} by thread 1: // CHECK: #0 foobar // CHECK: #1 Thread1 -// CHECK: Thread 1 (finished) created at: +// CHECK: Thread 1 (tid={{.*}}, finished) created at: // CHECK: #0 pthread_create // CHECK: #1 main diff --git a/compiler-rt/lib/tsan/lit_tests/simple_stack.c b/compiler-rt/lib/tsan/lit_tests/simple_stack.c index 08f5f65..b130957 100644 --- a/compiler-rt/lib/tsan/lit_tests/simple_stack.c +++ b/compiler-rt/lib/tsan/lit_tests/simple_stack.c @@ -56,7 +56,7 @@ int main() { // 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 1 (running) created at: +// CHECK: Thread 1 (tid={{.*}}, running) created at: // CHECK-NEXT: #0 pthread_create {{.*}} ({{.*}}) // CHECK-NEXT: #1 StartThread{{.*}} {{.*}}simple_stack.c:38{{(:3)?}} ({{.*}}) // CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack.c:43{{(:3)?}} ({{.*}}) diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc index 0327299..387cfba 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc @@ -629,7 +629,7 @@ extern "C" void *__tsan_thread_start_func(void *arg) { while ((tid = atomic_load(&p->tid, memory_order_acquire)) == 0) pthread_yield(); atomic_store(&p->tid, 0, memory_order_release); - ThreadStart(thr, tid); + ThreadStart(thr, tid, GetTid()); CHECK_EQ(thr->in_rtl, 1); } void *res = callback(param); diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.cc b/compiler-rt/lib/tsan/rtl/tsan_report.cc index a284a96..ded8070 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_report.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_report.cc @@ -104,7 +104,7 @@ static void PrintThread(const ReportThread *rt) { TsanPrintf(" Thread %d", rt->id); if (rt->name) TsanPrintf(" '%s'", rt->name); - TsanPrintf(" (%s)", rt->running ? "running" : "finished"); + TsanPrintf(" (tid=%d, %s)", rt->pid, rt->running ? "running" : "finished"); if (rt->stack) TsanPrintf(" created at:"); TsanPrintf("\n"); diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.h b/compiler-rt/lib/tsan/rtl/tsan_report.h index 20223da..696e418 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_report.h +++ b/compiler-rt/lib/tsan/rtl/tsan_report.h @@ -67,6 +67,7 @@ struct ReportLocation { struct ReportThread { int id; + int pid; bool running; char *name; ReportStack *stack; diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc index 33afe3c..90e2584 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc @@ -74,6 +74,7 @@ ThreadState::ThreadState(Context *ctx, int tid, int unique_id, u64 epoch, ThreadContext::ThreadContext(int tid) : tid(tid) , unique_id() + , os_id() , user_id() , thr() , status(ThreadStatusInvalid) @@ -201,7 +202,7 @@ void Initialize(ThreadState *thr) { ctx->thread_seq = 0; int tid = ThreadCreate(thr, 0, 0, true); CHECK_EQ(tid, 0); - ThreadStart(thr, tid); + ThreadStart(thr, tid, GetPid()); CHECK_EQ(thr->in_rtl, 1); ctx->initialized = true; diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h index a56025e..f2b18e9 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h @@ -327,6 +327,7 @@ struct ThreadDeadInfo { struct ThreadContext { const int tid; int unique_id; // Non-rolling thread id. + int os_id; // pid uptr user_id; // Some opaque user thread id (e.g. pthread_t). ThreadState *thr; ThreadStatus status; @@ -480,7 +481,7 @@ void FuncEntry(ThreadState *thr, uptr pc); void FuncExit(ThreadState *thr); int ThreadCreate(ThreadState *thr, uptr pc, uptr uid, bool detached); -void ThreadStart(ThreadState *thr, int tid); +void ThreadStart(ThreadState *thr, int tid, int os_id); void ThreadFinish(ThreadState *thr); int ThreadTid(ThreadState *thr, uptr pc, uptr uid); void ThreadJoin(ThreadState *thr, uptr pc, int tid); diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc index ac3194b..d179410 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc @@ -156,6 +156,7 @@ void ScopedReport::AddThread(const ThreadContext *tctx) { ReportThread *rt = new(mem) ReportThread(); rep_->threads.PushBack(rt); rt->id = tctx->tid; + rt->pid = tctx->os_id; rt->running = (tctx->status == ThreadStatusRunning); rt->stack = SymbolizeStack(tctx->creation_stack); } diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc index 8b27522..47884b4 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc @@ -137,7 +137,7 @@ int ThreadCreate(ThreadState *thr, uptr pc, uptr uid, bool detached) { return tid; } -void ThreadStart(ThreadState *thr, int tid) { +void ThreadStart(ThreadState *thr, int tid, int os_id) { CHECK_GT(thr->in_rtl, 0); uptr stk_addr = 0; uptr stk_size = 0; @@ -169,6 +169,7 @@ void ThreadStart(ThreadState *thr, int tid) { CHECK_NE(tctx, 0); CHECK_EQ(tctx->status, ThreadStatusCreated); tctx->status = ThreadStatusRunning; + tctx->os_id = os_id; tctx->epoch0 = tctx->epoch1 + 1; tctx->epoch1 = (u64)-1; new(thr) ThreadState(CTX(), tid, tctx->unique_id, -- 2.7.4