diff options
| author | Alexey Samsonov <samsonov@google.com> | 2012-06-06 10:13:27 +0000 |
|---|---|---|
| committer | Alexey Samsonov <samsonov@google.com> | 2012-06-06 10:13:27 +0000 |
| commit | ac4c290d029146fdadcba235899c398830a6bba6 (patch) | |
| tree | 1eae5050e72f957106779a9cba80ba5113b32236 | |
| parent | 201aa367fc1431fbd675e993134c8e6c3043349e (diff) | |
| download | bcm5719-llvm-ac4c290d029146fdadcba235899c398830a6bba6.tar.gz bcm5719-llvm-ac4c290d029146fdadcba235899c398830a6bba6.zip | |
[TSan] run some renaming as a preparation for factoring out Printf implementation.
llvm-svn: 158058
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_interceptors.cc | 12 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_interface_ann.cc | 8 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_mman.cc | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_mutex.cc | 24 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc | 21 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_printf.cc | 11 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_report.cc | 54 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_rtl.cc | 19 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_rtl.h | 8 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc | 13 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc | 4 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc | 15 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_stat.cc | 4 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_suppressions.cc | 12 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc | 16 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/unit_tests/tsan_printf_test.cc | 12 |
16 files changed, 120 insertions, 115 deletions
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc index 58c1d616a3d..397883dca0d 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc @@ -238,13 +238,13 @@ TSAN_INTERCEPTOR(int, atexit, void (*f)()) { TSAN_INTERCEPTOR(void, longjmp, void *env, int val) { SCOPED_TSAN_INTERCEPTOR(longjmp, env, val); - Printf("ThreadSanitizer: longjmp() is not supported\n"); + TsanPrintf("ThreadSanitizer: longjmp() is not supported\n"); Die(); } TSAN_INTERCEPTOR(void, siglongjmp, void *env, int val) { SCOPED_TSAN_INTERCEPTOR(siglongjmp, env, val); - Printf("ThreadSanitizer: siglongjmp() is not supported\n"); + TsanPrintf("ThreadSanitizer: siglongjmp() is not supported\n"); Die(); } @@ -620,7 +620,7 @@ static void thread_finalize(void *v) { uptr iter = (uptr)v; if (iter > 1) { if (pthread_setspecific(g_thread_finalize_key, (void*)(iter - 1))) { - Printf("ThreadSanitizer: failed to set thread key\n"); + TsanPrintf("ThreadSanitizer: failed to set thread key\n"); Die(); } return; @@ -647,7 +647,7 @@ extern "C" void *__tsan_thread_start_func(void *arg) { ThreadState *thr = cur_thread(); ScopedInRtl in_rtl; if (pthread_setspecific(g_thread_finalize_key, (void*)4)) { - Printf("ThreadSanitizer: failed to set thread key\n"); + TsanPrintf("ThreadSanitizer: failed to set thread key\n"); Die(); } while ((tid = atomic_load(&p->tid, memory_order_acquire)) == 0) @@ -1511,12 +1511,12 @@ void InitializeInterceptors() { AtExitContext(); if (__cxa_atexit(&finalize, 0, 0)) { - Printf("ThreadSanitizer: failed to setup atexit callback\n"); + TsanPrintf("ThreadSanitizer: failed to setup atexit callback\n"); Die(); } if (pthread_key_create(&g_thread_finalize_key, &thread_finalize)) { - Printf("ThreadSanitizer: failed to create thread key\n"); + TsanPrintf("ThreadSanitizer: failed to create thread key\n"); Die(); } } diff --git a/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cc b/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cc index 25662cb9e6b..6395847ae7a 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cc @@ -215,11 +215,11 @@ void AnnotateNoOp(char *f, int l, uptr mem) { } static void ReportMissedExpectedRace(ExpectRace *race) { - Printf("==================\n"); - Printf("WARNING: ThreadSanitizer: missed expected data race\n"); - Printf(" %s addr=%lx %s:%d\n", + TsanPrintf("==================\n"); + TsanPrintf("WARNING: ThreadSanitizer: missed expected data race\n"); + TsanPrintf(" %s addr=%lx %s:%d\n", race->desc, race->addr, race->file, race->line); - Printf("==================\n"); + TsanPrintf("==================\n"); } void AnnotateFlushExpectedRaces(char *f, int l) { diff --git a/compiler-rt/lib/tsan/rtl/tsan_mman.cc b/compiler-rt/lib/tsan/rtl/tsan_mman.cc index 7a668db30f5..423c2578271 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_mman.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_mman.cc @@ -92,7 +92,7 @@ MBlock *user_mblock(ThreadState *thr, void *p) { MBlock *b = (MBlock*)AllocBlock(p); // FIXME: Output a warning, it's a user error. if (p < (char*)(b + 1) || p > (char*)(b + 1) + b->size) { - Printf("user_mblock p=%p b=%p size=%lu beg=%p end=%p\n", + TsanPrintf("user_mblock p=%p b=%p size=%lu beg=%p end=%p\n", p, b, b->size, (char*)(b + 1), (char*)(b + 1) + b->size); CHECK_GE(p, (char*)(b + 1)); CHECK_LE(p, (char*)(b + 1) + b->size); diff --git a/compiler-rt/lib/tsan/rtl/tsan_mutex.cc b/compiler-rt/lib/tsan/rtl/tsan_mutex.cc index e24430736ce..3d5c225e2c6 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_mutex.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_mutex.cc @@ -91,25 +91,25 @@ void InitializeMutex() { } } #if 0 - Printf("Can lock graph:\n"); + TsanPrintf("Can lock graph:\n"); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { - Printf("%d ", CanLockAdj[i][j]); + TsanPrintf("%d ", CanLockAdj[i][j]); } - Printf("\n"); + TsanPrintf("\n"); } - Printf("Can lock graph closure:\n"); + TsanPrintf("Can lock graph closure:\n"); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { - Printf("%d ", CanLockAdj2[i][j]); + TsanPrintf("%d ", CanLockAdj2[i][j]); } - Printf("\n"); + TsanPrintf("\n"); } #endif // Verify that the graph is acyclic. for (int i = 0; i < N; i++) { if (CanLockAdj2[i][i]) { - Printf("Mutex %d participates in a cycle\n", i); + TsanPrintf("Mutex %d participates in a cycle\n", i); Die(); } } @@ -120,7 +120,7 @@ DeadlockDetector::DeadlockDetector() { } void DeadlockDetector::Lock(MutexType t) { - // Printf("LOCK %d @%llu\n", t, seq_ + 1); + // TsanPrintf("LOCK %d @%llu\n", t, seq_ + 1); u64 max_seq = 0; u64 max_idx = MutexTypeInvalid; for (int i = 0; i != MutexTypeCount; i++) { @@ -135,16 +135,16 @@ void DeadlockDetector::Lock(MutexType t) { locked_[t] = ++seq_; if (max_idx == MutexTypeInvalid) return; - // Printf(" last %d @%llu\n", max_idx, max_seq); + // TsanPrintf(" last %d @%llu\n", max_idx, max_seq); if (!CanLockAdj[max_idx][t]) { - Printf("ThreadSanitizer: internal deadlock detected\n"); - Printf("ThreadSanitizer: can't lock %d while under %llu\n", t, max_idx); + TsanPrintf("ThreadSanitizer: internal deadlock detected\n"); + TsanPrintf("ThreadSanitizer: can't lock %d while under %llu\n", t, max_idx); Die(); } } void DeadlockDetector::Unlock(MutexType t) { - // Printf("UNLO %d @%llu #%llu\n", t, seq_, locked_[t]); + // TsanPrintf("UNLO %d @%llu #%llu\n", t, seq_, locked_[t]); CHECK(locked_[t]); locked_[t] = 0; } diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc index 2d744433696..9c8240d1433 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc @@ -96,8 +96,8 @@ static void ProtectRange(uptr beg, uptr end) { PROT_NONE, MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE, -1, 0)) { - Printf("FATAL: ThreadSanitizer can not protect [%lx,%lx]\n", beg, end); - Printf("FATAL: Make sure you are not using unlimited stack\n"); + TsanPrintf("FATAL: ThreadSanitizer can not protect [%lx,%lx]\n", beg, end); + TsanPrintf("FATAL: Make sure you are not using unlimited stack\n"); Die(); } } @@ -113,8 +113,9 @@ void InitializeShadowMemory() { MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE, -1, 0); if (shadow != kLinuxShadowBeg) { - Printf("FATAL: ThreadSanitizer can not mmap the shadow memory\n"); - Printf("FATAL: Make sure to compile with -fPIE and to link with -pie.\n"); + TsanPrintf("FATAL: ThreadSanitizer can not mmap the shadow memory\n"); + TsanPrintf("FATAL: Make sure to compile with -fPIE and " + "to link with -pie.\n"); Die(); } ProtectRange(kClosedLowBeg, kClosedLowEnd); @@ -142,10 +143,10 @@ static void CheckPIE() { buf[sizeof(buf) - 1] = 0; u64 addr = strtoll(buf, 0, 16); if ((u64)addr < kLinuxAppMemBeg) { - Printf("FATAL: ThreadSanitizer can not mmap the shadow memory (" + TsanPrintf("FATAL: ThreadSanitizer can not mmap the shadow memory (" "something is mapped at 0x%llx < 0x%lx)\n", addr, kLinuxAppMemBeg); - Printf("FATAL: Make sure to compile with -fPIE" + TsanPrintf("FATAL: Make sure to compile with -fPIE" " and to link with -pie.\n"); Die(); } @@ -209,7 +210,7 @@ void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size, MAP_PRIVATE | MAP_ANON, -1, 0); fd_t maps = internal_open("/proc/self/maps", false); if (maps == kInvalidFd) { - Printf("Failed to open /proc/self/maps\n"); + TsanPrintf("Failed to open /proc/self/maps\n"); Die(); } char *end = buf; @@ -222,18 +223,18 @@ void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size, end[0] = 0; end = (char*)internal_strstr(buf, "[stack]"); if (end == 0) { - Printf("Can't find [stack] in /proc/self/maps\n"); + TsanPrintf("Can't find [stack] in /proc/self/maps\n"); Die(); } end[0] = 0; char *pos = (char*)internal_strrchr(buf, '\n'); if (pos == 0) { - Printf("Can't find [stack] in /proc/self/maps\n"); + TsanPrintf("Can't find [stack] in /proc/self/maps\n"); Die(); } pos = (char*)internal_strchr(pos, '-'); if (pos == 0) { - Printf("Can't find [stack] in /proc/self/maps\n"); + TsanPrintf("Can't find [stack] in /proc/self/maps\n"); Die(); } uptr stack = 0; diff --git a/compiler-rt/lib/tsan/rtl/tsan_printf.cc b/compiler-rt/lib/tsan/rtl/tsan_printf.cc index 2540d224c27..d2946ff0035 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_printf.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_printf.cc @@ -78,8 +78,8 @@ static int AppendPointer(char **buff, const char *buff_end, u64 ptr_value) { return result; } -static uptr VSNPrintf(char *buff, int buff_length, - const char *format, va_list args) { +uptr VSNPrintf(char *buff, int buff_length, + const char *format, va_list args) { const char *buff_end = &buff[buff_length - 1]; const char *cur = format; int result = 0; @@ -126,7 +126,7 @@ static uptr VSNPrintf(char *buff, int buff_length, return result; } -void Printf(const char *format, ...) { +void TsanPrintf(const char *format, ...) { ScopedInRtl in_rtl; const uptr kMaxLen = 16 * 1024; InternalScopedBuf<char> buffer(kMaxLen); @@ -138,11 +138,12 @@ void Printf(const char *format, ...) { buffer, len < buffer.Size() ? len : buffer.Size() - 1); } -uptr Snprintf(char *buffer, uptr length, const char *format, ...) { +uptr SNPrintf(char *buffer, uptr length, const char *format, ...) { va_list args; va_start(args, format); uptr len = VSNPrintf(buffer, length, format, args); va_end(args); return len; } -} + +} // namespace __tsan diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.cc b/compiler-rt/lib/tsan/rtl/tsan_report.cc index 86617669643..726185ff213 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_report.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_report.cc @@ -28,81 +28,81 @@ ReportDesc::~ReportDesc() { } static void PrintHeader(ReportType typ) { - Printf("WARNING: ThreadSanitizer: "); + TsanPrintf("WARNING: ThreadSanitizer: "); if (typ == ReportTypeRace) - Printf("data race"); + TsanPrintf("data race"); else if (typ == ReportTypeUseAfterFree) - Printf("heap-use-after-free"); + TsanPrintf("heap-use-after-free"); else if (typ == ReportTypeThreadLeak) - Printf("thread leak"); + TsanPrintf("thread leak"); else if (typ == ReportTypeMutexDestroyLocked) - Printf("destroy of a locked mutex"); + TsanPrintf("destroy of a locked mutex"); else if (typ == ReportTypeSignalUnsafe) - Printf("signal-unsafe call inside of a signal"); + TsanPrintf("signal-unsafe call inside of a signal"); - Printf(" (pid=%d)\n", GetPid()); + TsanPrintf(" (pid=%d)\n", GetPid()); } static void PrintStack(const ReportStack *ent) { for (int i = 0; ent; ent = ent->next, i++) { - Printf(" #%d %s %s:%d", i, ent->func, ent->file, ent->line); + TsanPrintf(" #%d %s %s:%d", i, ent->func, ent->file, ent->line); if (ent->col) - Printf(":%d", ent->col); + TsanPrintf(":%d", ent->col); if (ent->module && ent->offset) - Printf(" (%s+%p)\n", ent->module, (void*)ent->offset); + TsanPrintf(" (%s+%p)\n", ent->module, (void*)ent->offset); else - Printf(" (%p)\n", (void*)ent->pc); + TsanPrintf(" (%p)\n", (void*)ent->pc); } } static void PrintMop(const ReportMop *mop, bool first) { - Printf(" %s of size %d at %p", + TsanPrintf(" %s of size %d at %p", (first ? (mop->write ? "Write" : "Read") : (mop->write ? "Previous write" : "Previous read")), mop->size, (void*)mop->addr); if (mop->tid == 0) - Printf(" by main thread:\n"); + TsanPrintf(" by main thread:\n"); else - Printf(" by thread %d:\n", mop->tid); + TsanPrintf(" by thread %d:\n", mop->tid); PrintStack(mop->stack); } static void PrintLocation(const ReportLocation *loc) { if (loc->type == ReportLocationGlobal) { - Printf(" Location is global '%s' of size %lu at %lx %s:%d\n", - loc->name, loc->size, loc->addr, loc->file, loc->line); + TsanPrintf(" Location is global '%s' of size %lu at %lx %s:%d\n", + loc->name, loc->size, loc->addr, loc->file, loc->line); } else if (loc->type == ReportLocationHeap) { - Printf(" Location is heap of size %lu at %lx allocated by thread %d:\n", - loc->size, loc->addr, loc->tid); + TsanPrintf(" Location is heap of size %lu at %lx allocated " + "by thread %d:\n", loc->size, loc->addr, loc->tid); PrintStack(loc->stack); } else if (loc->type == ReportLocationStack) { - Printf(" Location is stack of thread %d:\n", loc->tid); + TsanPrintf(" Location is stack of thread %d:\n", loc->tid); } } static void PrintMutex(const ReportMutex *rm) { if (rm->stack == 0) return; - Printf(" Mutex %d created at:\n", rm->id); + TsanPrintf(" Mutex %d created at:\n", rm->id); PrintStack(rm->stack); } static void PrintThread(const ReportThread *rt) { if (rt->id == 0) // Little sense in describing the main thread. return; - Printf(" Thread %d", rt->id); + TsanPrintf(" Thread %d", rt->id); if (rt->name) - Printf(" '%s'", rt->name); - Printf(" (%s)", rt->running ? "running" : "finished"); + TsanPrintf(" '%s'", rt->name); + TsanPrintf(" (%s)", rt->running ? "running" : "finished"); if (rt->stack) - Printf(" created at:"); - Printf("\n"); + TsanPrintf(" created at:"); + TsanPrintf("\n"); PrintStack(rt->stack); } void PrintReport(const ReportDesc *rep) { - Printf("==================\n"); + TsanPrintf("==================\n"); PrintHeader(rep->typ); for (uptr i = 0; i < rep->stacks.Size(); i++) @@ -120,7 +120,7 @@ void PrintReport(const ReportDesc *rep) { for (uptr i = 0; i < rep->threads.Size(); i++) PrintThread(rep->threads[i]); - Printf("==================\n"); + TsanPrintf("==================\n"); } } // namespace __tsan diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc index d4a99e1a249..e25cc8f6630 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc @@ -104,7 +104,7 @@ static void WriteMemoryProfile(char *buf, uptr buf_size, int num) { uptr nsync = 0; uptr syncmem = CTX()->synctab.GetMemoryConsumption(&nsync); - Snprintf(buf, buf_size, "%d: shadow=%luMB" + SNPrintf(buf, buf_size, "%d: shadow=%luMB" " thread=%luMB(total=%d/live=%d)" " sync=%luMB(cnt=%lu)\n", num, @@ -128,11 +128,11 @@ static void InitializeMemoryProfile() { if (flags()->profile_memory == 0 || flags()->profile_memory[0] == 0) return; InternalScopedBuf<char> filename(4096); - Snprintf(filename.Ptr(), filename.Size(), "%s.%d", + SNPrintf(filename.Ptr(), filename.Size(), "%s.%d", flags()->profile_memory, GetPid()); fd_t fd = internal_open(filename.Ptr(), true); if (fd == kInvalidFd) { - Printf("Failed to open memory profile file '%s'\n", &filename[0]); + TsanPrintf("Failed to open memory profile file '%s'\n", &filename[0]); Die(); } internal_start_thread(&MemoryProfileThread, (void*)(uptr)fd); @@ -177,7 +177,8 @@ void Initialize(ThreadState *thr) { InitializeMemoryFlush(); if (ctx->flags.verbosity) - Printf("***** Running under ThreadSanitizer v2 (pid %d) *****\n", GetPid()); + TsanPrintf("***** Running under ThreadSanitizer v2 (pid %d) *****\n", + GetPid()); // Initialize thread 0. ctx->thread_seq = 0; @@ -188,7 +189,7 @@ void Initialize(ThreadState *thr) { ctx->initialized = true; if (flags()->stop_on_start) { - Printf("ThreadSanitizer is suspended at startup (pid %d)." + TsanPrintf("ThreadSanitizer is suspended at startup (pid %d)." " Call __tsan_resume().\n", GetPid()); while (__tsan_resumed == 0); @@ -204,12 +205,12 @@ int Finalize(ThreadState *thr) { if (ctx->nreported) { failed = true; - Printf("ThreadSanitizer: reported %d warnings\n", ctx->nreported); + TsanPrintf("ThreadSanitizer: reported %d warnings\n", ctx->nreported); } if (ctx->nmissed_expected) { failed = true; - Printf("ThreadSanitizer: missed %d expected races\n", + TsanPrintf("ThreadSanitizer: missed %d expected races\n", ctx->nmissed_expected); } @@ -364,11 +365,11 @@ void MemoryAccess(ThreadState *thr, uptr pc, uptr addr, shadow_mem[0], shadow_mem[1], shadow_mem[2], shadow_mem[3]); #if TSAN_DEBUG if (!IsAppMem(addr)) { - Printf("Access to non app mem %lx\n", addr); + TsanPrintf("Access to non app mem %lx\n", addr); DCHECK(IsAppMem(addr)); } if (!IsShadowMem((uptr)shadow_mem)) { - Printf("Bad shadow addr %p (%lx)\n", shadow_mem, addr); + TsanPrintf("Bad shadow addr %p (%lx)\n", shadow_mem, addr); DCHECK(IsShadowMem((uptr)shadow_mem)); } #endif diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h index f89f2420b57..48bf0555c46 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h @@ -37,8 +37,8 @@ namespace __tsan { -void Printf(const char *format, ...) FORMAT(1, 2); -uptr Snprintf(char *buffer, uptr length, const char *format, ...) FORMAT(3, 4); +void TsanPrintf(const char *format, ...) FORMAT(1, 2); +uptr SNPrintf(char *buffer, uptr length, const char *format, ...) FORMAT(3, 4); // FastState (from most significant bit): // unused : 1 @@ -398,13 +398,13 @@ bool OutputReport(const ScopedReport &srep, bool IsExpectedReport(uptr addr, uptr size); #if defined(TSAN_DEBUG_OUTPUT) && TSAN_DEBUG_OUTPUT >= 1 -# define DPrintf Printf +# define DPrintf TsanPrintf #else # define DPrintf(...) #endif #if defined(TSAN_DEBUG_OUTPUT) && TSAN_DEBUG_OUTPUT >= 2 -# define DPrintf2 Printf +# define DPrintf2 TsanPrintf #else # define DPrintf2(...) #endif diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc index b16905396f7..8f1324d5bc0 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc @@ -63,7 +63,7 @@ void MutexLock(ThreadState *thr, uptr pc, uptr addr) { } else if (s->owner_tid == thr->tid) { CHECK_GT(s->recursion, 0); } else { - Printf("ThreadSanitizer WARNING: double lock\n"); + TsanPrintf("ThreadSanitizer WARNING: double lock\n"); } if (s->recursion == 0) { StatInc(thr, StatMutexLock); @@ -89,12 +89,12 @@ void MutexUnlock(ThreadState *thr, uptr pc, uptr addr) { if (s->recursion == 0) { if (!s->is_broken) { s->is_broken = true; - Printf("ThreadSanitizer WARNING: unlock of unlocked mutex\n"); + TsanPrintf("ThreadSanitizer WARNING: unlock of unlocked mutex\n"); } } else if (s->owner_tid != thr->tid) { if (!s->is_broken) { s->is_broken = true; - Printf("ThreadSanitizer WARNING: mutex unlock by another thread\n"); + TsanPrintf("ThreadSanitizer WARNING: mutex unlock by another thread\n"); } } else { s->recursion--; @@ -121,7 +121,7 @@ void MutexReadLock(ThreadState *thr, uptr pc, uptr addr) { TraceAddEvent(thr, thr->fast_state.epoch(), EventTypeRLock, addr); SyncVar *s = CTX()->synctab.GetAndLock(thr, pc, addr, false); if (s->owner_tid != SyncVar::kInvalidTid) - Printf("ThreadSanitizer WARNING: read lock of a write locked mutex\n"); + TsanPrintf("ThreadSanitizer WARNING: read lock of a write locked mutex\n"); thr->clock.set(thr->tid, thr->fast_state.epoch()); thr->clock.acquire(&s->clock); StatInc(thr, StatSyncAcquire); @@ -137,7 +137,8 @@ void MutexReadUnlock(ThreadState *thr, uptr pc, uptr addr) { TraceAddEvent(thr, thr->fast_state.epoch(), EventTypeRUnlock, addr); SyncVar *s = CTX()->synctab.GetAndLock(thr, pc, addr, true); if (s->owner_tid != SyncVar::kInvalidTid) - Printf("ThreadSanitizer WARNING: read unlock of a write locked mutex\n"); + TsanPrintf("ThreadSanitizer WARNING: read unlock of a write " + "locked mutex\n"); thr->clock.set(thr->tid, thr->fast_state.epoch()); thr->fast_synch_epoch = thr->fast_state.epoch(); thr->clock.release(&s->read_clock); @@ -181,7 +182,7 @@ void MutexReadOrWriteUnlock(ThreadState *thr, uptr pc, uptr addr) { } } else if (!s->is_broken) { s->is_broken = true; - Printf("ThreadSanitizer WARNING: mutex unlock by another thread\n"); + TsanPrintf("ThreadSanitizer WARNING: mutex unlock by another thread\n"); } s->mtx.Unlock(); } diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc index d8392724d79..6d8758b4ae4 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc @@ -68,7 +68,7 @@ static void StackStripMain(ReportStack *stack) { // can actually happen if we do not instrument some code, // so it's only a DCHECK. However we must try hard to not miss it // due to our fault. - Printf("Bottom stack frame of stack %lx is missed\n", stack->pc); + TsanPrintf("Bottom stack frame of stack %lx is missed\n", stack->pc); } } @@ -349,7 +349,7 @@ void ReportRace(ThreadState *thr) { void CheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2) { ScopedInRtl in_rtl; - Printf("FATAL: ThreadSanitizer CHECK failed: %s:%d \"%s\" (%llx, %llx)\n", + TsanPrintf("FATAL: ThreadSanitizer CHECK failed: %s:%d \"%s\" (%llx, %llx)\n", file, line, cond, v1, v2); Die(); } diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc index d4bf2ee4952..655309d162f 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc @@ -78,7 +78,8 @@ int ThreadCreate(ThreadState *thr, uptr pc, uptr uid, bool detached) { if (ctx->dead_list_size > kThreadQuarantineSize || ctx->thread_seq >= kMaxTid) { if (ctx->dead_list_size == 0) { - Printf("ThreadSanitizer: %d thread limit exceeded. Dying.\n", kMaxTid); + TsanPrintf("ThreadSanitizer: %d thread limit exceeded. Dying.\n", + kMaxTid); Die(); } StatInc(thr, StatThreadReuse); @@ -251,7 +252,7 @@ void ThreadJoin(ThreadState *thr, uptr pc, int tid) { Lock l(&ctx->thread_mtx); ThreadContext *tctx = ctx->threads[tid]; if (tctx->status == ThreadStatusInvalid) { - Printf("ThreadSanitizer: join of non-existent thread\n"); + TsanPrintf("ThreadSanitizer: join of non-existent thread\n"); return; } CHECK_EQ(tctx->detached, false); @@ -269,7 +270,7 @@ void ThreadDetach(ThreadState *thr, uptr pc, int tid) { Lock l(&ctx->thread_mtx); ThreadContext *tctx = ctx->threads[tid]; if (tctx->status == ThreadStatusInvalid) { - Printf("ThreadSanitizer: detach of non-existent thread\n"); + TsanPrintf("ThreadSanitizer: detach of non-existent thread\n"); return; } if (tctx->status == ThreadStatusFinished) { @@ -291,19 +292,19 @@ void MemoryAccessRange(ThreadState *thr, uptr pc, uptr addr, #if TSAN_DEBUG if (!IsAppMem(addr)) { - Printf("Access to non app mem %lx\n", addr); + TsanPrintf("Access to non app mem %lx\n", addr); DCHECK(IsAppMem(addr)); } if (!IsAppMem(addr + size - 1)) { - Printf("Access to non app mem %lx\n", addr + size - 1); + TsanPrintf("Access to non app mem %lx\n", addr + size - 1); DCHECK(IsAppMem(addr + size - 1)); } if (!IsShadowMem((uptr)shadow_mem)) { - Printf("Bad shadow addr %p (%lx)\n", shadow_mem, addr); + TsanPrintf("Bad shadow addr %p (%lx)\n", shadow_mem, addr); DCHECK(IsShadowMem((uptr)shadow_mem)); } if (!IsShadowMem((uptr)(shadow_mem + size * kShadowCnt / 8 - 1))) { - Printf("Bad shadow addr %p (%lx)\n", + TsanPrintf("Bad shadow addr %p (%lx)\n", shadow_mem + size * kShadowCnt / 8 - 1, addr + size - 1); DCHECK(IsShadowMem((uptr)(shadow_mem + size * kShadowCnt / 8 - 1))); } diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.cc b/compiler-rt/lib/tsan/rtl/tsan_stat.cc index f1afef05ac2..43eeb9d9b4c 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_stat.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_stat.cc @@ -241,9 +241,9 @@ void StatOutput(u64 *stat) { name[StatMtxAtExit] = " Atexit "; name[StatMtxAnnotations] = " Annotations "; - Printf("Statistics:\n"); + TsanPrintf("Statistics:\n"); for (int i = 0; i < StatCnt; i++) - Printf("%s: %llu\n", name[i], stat[i]); + TsanPrintf("%s: %llu\n", name[i], stat[i]); } } // namespace __tsan diff --git a/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc b/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc index 891518fc892..d4c37e1ad75 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc @@ -27,24 +27,24 @@ static char *ReadFile(const char *filename) { return 0; InternalScopedBuf<char> tmp(4*1024); if (filename[0] == '/') - Snprintf(tmp, tmp.Size(), "%s", filename); + SNPrintf(tmp, tmp.Size(), "%s", filename); else - Snprintf(tmp, tmp.Size(), "%s/%s", internal_getpwd(), filename); + SNPrintf(tmp, tmp.Size(), "%s/%s", internal_getpwd(), filename); fd_t fd = internal_open(tmp, false); if (fd == kInvalidFd) { - Printf("ThreadSanitizer: failed to open suppressions file '%s'\n", + TsanPrintf("ThreadSanitizer: failed to open suppressions file '%s'\n", tmp.Ptr()); Die(); } const uptr fsize = internal_filesize(fd); if (fsize == (uptr)-1) { - Printf("ThreadSanitizer: failed to stat suppressions file '%s'\n", + TsanPrintf("ThreadSanitizer: failed to stat suppressions file '%s'\n", tmp.Ptr()); Die(); } char *buf = (char*)internal_alloc(MBlockSuppression, fsize + 1); if (fsize != internal_read(fd, buf, fsize)) { - Printf("ThreadSanitizer: failed to read suppressions file '%s'\n", + TsanPrintf("ThreadSanitizer: failed to read suppressions file '%s'\n", tmp.Ptr()); Die(); } @@ -109,7 +109,7 @@ Suppression *SuppressionParse(const char* supp) { stype = SuppressionSignal; line += sizeof("signal:") - 1; } else { - Printf("ThreadSanitizer: failed to parse suppressions file\n"); + TsanPrintf("ThreadSanitizer: failed to parse suppressions file\n"); Die(); } Suppression *s = (Suppression*)internal_alloc(MBlockSuppression, diff --git a/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc b/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc index f7366423730..2a01df6938c 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc @@ -50,12 +50,12 @@ struct DlIteratePhdrCtx { static void NOINLINE InitModule(ModuleDesc *m) { int outfd[2] = {}; if (pipe(&outfd[0])) { - Printf("ThreadSanitizer: outfd pipe() failed (%d)\n", errno); + TsanPrintf("ThreadSanitizer: outfd pipe() failed (%d)\n", errno); Die(); } int infd[2] = {}; if (pipe(&infd[0])) { - Printf("ThreadSanitizer: infd pipe() failed (%d)\n", errno); + TsanPrintf("ThreadSanitizer: infd pipe() failed (%d)\n", errno); Die(); } int pid = fork(); @@ -72,7 +72,7 @@ static void NOINLINE InitModule(ModuleDesc *m) { execl("/usr/bin/addr2line", "/usr/bin/addr2line", "-Cfe", m->fullname, 0); _exit(0); } else if (pid < 0) { - Printf("ThreadSanitizer: failed to fork symbolizer\n"); + TsanPrintf("ThreadSanitizer: failed to fork symbolizer\n"); Die(); } internal_close(outfd[0]); @@ -85,7 +85,7 @@ static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { DlIteratePhdrCtx *ctx = (DlIteratePhdrCtx*)arg; InternalScopedBuf<char> tmp(128); if (ctx->is_first) { - Snprintf(tmp.Ptr(), tmp.Size(), "/proc/%d/exe", GetPid()); + SNPrintf(tmp.Ptr(), tmp.Size(), "/proc/%d/exe", GetPid()); info->dlpi_name = tmp.Ptr(); } ctx->is_first = false; @@ -158,16 +158,16 @@ ReportStack *SymbolizeCode(uptr addr) { ModuleDesc *m = s->module; uptr offset = addr - m->base; char addrstr[32]; - Snprintf(addrstr, sizeof(addrstr), "%p\n", (void*)offset); + SNPrintf(addrstr, sizeof(addrstr), "%p\n", (void*)offset); if (0 >= internal_write(m->out_fd, addrstr, internal_strlen(addrstr))) { - Printf("ThreadSanitizer: can't write from symbolizer (%d, %d)\n", + TsanPrintf("ThreadSanitizer: can't write from symbolizer (%d, %d)\n", m->out_fd, errno); Die(); } InternalScopedBuf<char> func(1024); ssize_t len = internal_read(m->inp_fd, func, func.Size() - 1); if (len <= 0) { - Printf("ThreadSanitizer: can't read from symbolizer (%d, %d)\n", + TsanPrintf("ThreadSanitizer: can't read from symbolizer (%d, %d)\n", m->inp_fd, errno); Die(); } @@ -198,7 +198,7 @@ ReportStack *SymbolizeData(uptr addr) { base = GetImageBase(); int res = 0; InternalScopedBuf<char> cmd(1024); - Snprintf(cmd, cmd.Size(), + SNPrintf(cmd, cmd.Size(), "nm -alC %s|grep \"%lx\"|awk '{printf(\"%%s\\n%%s\", $3, $4)}' > tsan.tmp2", exe, (addr - base)); if (system(cmd)) diff --git a/compiler-rt/lib/tsan/unit_tests/tsan_printf_test.cc b/compiler-rt/lib/tsan/unit_tests/tsan_printf_test.cc index 2836c0d7d0e..3a905d2a1ff 100644 --- a/compiler-rt/lib/tsan/unit_tests/tsan_printf_test.cc +++ b/compiler-rt/lib/tsan/unit_tests/tsan_printf_test.cc @@ -20,7 +20,7 @@ namespace __tsan { TEST(Printf, Basic) { char buf[1024]; - uptr len = Snprintf(buf, sizeof(buf), + uptr len = SNPrintf(buf, sizeof(buf), "a%db%ldc%lldd%ue%luf%llug%xh%lxq%llxw%pe%sr", (int)-1, (long)-2, (long long)-3, // NOLINT (unsigned)-4, (unsigned long)5, (unsigned long long)6, // NOLINT @@ -33,7 +33,7 @@ TEST(Printf, Basic) { TEST(Printf, OverflowStr) { char buf[] = "123456789"; - uptr len = Snprintf(buf, 4, "%s", "abcdef"); + uptr len = SNPrintf(buf, 4, "%s", "abcdef"); EXPECT_EQ(len, (uptr)6); EXPECT_EQ(0, strcmp(buf, "abc")); EXPECT_EQ(buf[3], 0); @@ -47,7 +47,7 @@ TEST(Printf, OverflowStr) { TEST(Printf, OverflowInt) { char buf[] = "123456789"; - Snprintf(buf, 4, "%d", -123456789); + SNPrintf(buf, 4, "%d", -123456789); EXPECT_EQ(0, strcmp(buf, "-12")); EXPECT_EQ(buf[3], 0); EXPECT_EQ(buf[4], '5'); @@ -60,7 +60,7 @@ TEST(Printf, OverflowInt) { TEST(Printf, OverflowUint) { char buf[] = "123456789"; - Snprintf(buf, 4, "a%llx", (long long)0x123456789); // NOLINT + SNPrintf(buf, 4, "a%llx", (long long)0x123456789); // NOLINT EXPECT_EQ(0, strcmp(buf, "a12")); EXPECT_EQ(buf[3], 0); EXPECT_EQ(buf[4], '5'); @@ -73,7 +73,7 @@ TEST(Printf, OverflowUint) { TEST(Printf, OverflowPtr) { char buf[] = "123456789"; - Snprintf(buf, 4, "%p", (void*)0x123456789); + SNPrintf(buf, 4, "%p", (void*)0x123456789); EXPECT_EQ(0, strcmp(buf, "0x0")); EXPECT_EQ(buf[3], 0); EXPECT_EQ(buf[4], '5'); @@ -87,7 +87,7 @@ TEST(Printf, OverflowPtr) { template<typename T> static void TestMinMax(const char *fmt, T min, T max) { char buf[1024]; - uptr len = Snprintf(buf, sizeof(buf), fmt, min, max); + uptr len = SNPrintf(buf, sizeof(buf), fmt, min, max); char buf2[1024]; snprintf(buf2, sizeof(buf2), fmt, min, max); EXPECT_EQ(len, strlen(buf)); |

