tsan: output tid's in reports

llvm-svn: 164998
This commit is contained in:
Dmitry Vyukov 2012-10-02 11:52:05 +00:00
parent 0c40a5600c
commit 27d5b37c38
13 changed files with 20 additions and 9 deletions

View File

@ -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);

View File

@ -27,6 +27,7 @@
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <syscall.h>
#include <unistd.h>
namespace __sanitizer {
@ -37,6 +38,10 @@ int GetPid() {
return getpid();
}
int GetTid() {
return syscall(__NR_gettid);
}
uptr GetThreadSelf() {
return (uptr)pthread_self();
}

View File

@ -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--;
}

View File

@ -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

View File

@ -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

View File

@ -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)?}} ({{.*}})

View File

@ -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);

View File

@ -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");

View File

@ -67,6 +67,7 @@ struct ReportLocation {
struct ReportThread {
int id;
int pid;
bool running;
char *name;
ReportStack *stack;

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -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,