diff options
-rw-r--r-- | lib/asan/asan_fake_stack.cc | 10 | ||||
-rw-r--r-- | lib/asan/asan_interceptors.cc | 20 | ||||
-rw-r--r-- | lib/asan/asan_mac.cc | 27 | ||||
-rw-r--r-- | lib/asan/asan_poisoning.cc | 23 | ||||
-rw-r--r-- | lib/asan/asan_posix.cc | 12 | ||||
-rw-r--r-- | lib/asan/asan_rtl.cc | 18 | ||||
-rw-r--r-- | lib/asan/asan_thread.cc | 23 | ||||
-rw-r--r-- | lib/msan/msan.cc | 13 | ||||
-rw-r--r-- | lib/msan/msan_interceptors.cc | 13 | ||||
-rw-r--r-- | lib/msan/msan_linux.cc | 14 | ||||
-rw-r--r-- | lib/msan/msan_report.cc | 3 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_common.h | 8 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_coverage.cc | 3 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_libignore.cc | 7 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_linux_libcdep.cc | 6 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_printf.cc | 1 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc | 37 |
17 files changed, 100 insertions, 138 deletions
diff --git a/lib/asan/asan_fake_stack.cc b/lib/asan/asan_fake_stack.cc index d3e55bff1..1ff97f430 100644 --- a/lib/asan/asan_fake_stack.cc +++ b/lib/asan/asan_fake_stack.cc @@ -45,12 +45,10 @@ FakeStack *FakeStack::Create(uptr stack_size_log) { FakeStack *res = reinterpret_cast<FakeStack *>( MmapOrDie(RequiredSize(stack_size_log), "FakeStack")); res->stack_size_log_ = stack_size_log; - if (common_flags()->verbosity) { - u8 *p = reinterpret_cast<u8 *>(res); - Report("T%d: FakeStack created: %p -- %p stack_size_log: %zd \n", - GetCurrentTidOrInvalid(), p, - p + FakeStack::RequiredSize(stack_size_log), stack_size_log); - } + u8 *p = reinterpret_cast<u8 *>(res); + VReport(1, "T%d: FakeStack created: %p -- %p stack_size_log: %zd \n", + GetCurrentTidOrInvalid(), p, + p + FakeStack::RequiredSize(stack_size_log), stack_size_log); return res; } diff --git a/lib/asan/asan_interceptors.cc b/lib/asan/asan_interceptors.cc index a25827b6b..821e7c090 100644 --- a/lib/asan/asan_interceptors.cc +++ b/lib/asan/asan_interceptors.cc @@ -108,11 +108,10 @@ DECLARE_REAL_AND_INTERCEPTOR(void *, malloc, uptr) DECLARE_REAL_AND_INTERCEPTOR(void, free, void *) #if !SANITIZER_MAC -#define ASAN_INTERCEPT_FUNC(name) \ - do { \ - if ((!INTERCEPT_FUNCTION(name) || !REAL(name)) && \ - common_flags()->verbosity > 0) \ - Report("AddressSanitizer: failed to intercept '" #name "'\n"); \ +#define ASAN_INTERCEPT_FUNC(name) \ + do { \ + if ((!INTERCEPT_FUNCTION(name) || !REAL(name))) \ + VReport(1, "AddressSanitizer: failed to intercept '" #name "'\n"); \ } while (0) #else // OS X interceptors don't need to be initialized with INTERCEPT_FUNCTION. @@ -286,10 +285,9 @@ static void MlockIsUnsupported() { static bool printed = false; if (printed) return; printed = true; - if (common_flags()->verbosity > 0) { - Printf("INFO: AddressSanitizer ignores " - "mlock/mlockall/munlock/munlockall\n"); - } + VPrintf(1, + "INFO: AddressSanitizer ignores " + "mlock/mlockall/munlock/munlockall\n"); } INTERCEPTOR(int, mlock, const void *addr, uptr len) { @@ -787,9 +785,7 @@ void InitializeAsanInterceptors() { InitializeWindowsInterceptors(); #endif - if (common_flags()->verbosity > 0) { - Report("AddressSanitizer: libc interceptors initialized\n"); - } + VReport(1, "AddressSanitizer: libc interceptors initialized\n"); } } // namespace __asan diff --git a/lib/asan/asan_mac.cc b/lib/asan/asan_mac.cc index e27d70adb..b5608842a 100644 --- a/lib/asan/asan_mac.cc +++ b/lib/asan/asan_mac.cc @@ -174,12 +174,10 @@ void MaybeReexec() { // Set DYLD_INSERT_LIBRARIES equal to the runtime dylib name. setenv(kDyldInsertLibraries, info.dli_fname, /*overwrite*/0); } - if (common_flags()->verbosity >= 1) { - Report("exec()-ing the program with\n"); - Report("%s=%s\n", kDyldInsertLibraries, new_env); - Report("to enable ASan wrappers.\n"); - Report("Set ASAN_OPTIONS=allow_reexec=0 to disable this.\n"); - } + VReport(1, "exec()-ing the program with\n"); + VReport(1, "%s=%s\n", kDyldInsertLibraries, new_env); + VReport(1, "to enable ASan wrappers.\n"); + VReport(1, "Set ASAN_OPTIONS=allow_reexec=0 to disable this.\n"); execv(program_name, *_NSGetArgv()); } else { // DYLD_INSERT_LIBRARIES is set and contains the runtime library. @@ -311,11 +309,10 @@ extern "C" void asan_dispatch_call_block_and_release(void *block) { GET_STACK_TRACE_THREAD; asan_block_context_t *context = (asan_block_context_t*)block; - if (common_flags()->verbosity >= 2) { - Report("asan_dispatch_call_block_and_release(): " - "context: %p, pthread_self: %p\n", - block, pthread_self()); - } + VReport(2, + "asan_dispatch_call_block_and_release(): " + "context: %p, pthread_self: %p\n", + block, pthread_self()); asan_register_worker_thread(context->parent_tid, &stack); // Call the original dispatcher for the block. context->func(context->block); @@ -349,10 +346,10 @@ asan_block_context_t *alloc_asan_context(void *ctxt, dispatch_function_t func, if (common_flags()->verbosity >= 2) { \ Report(#dispatch_x_f "(): context: %p, pthread_self: %p\n", \ asan_ctxt, pthread_self()); \ - PRINT_CURRENT_STACK(); \ - } \ - return REAL(dispatch_x_f)(dq, (void*)asan_ctxt, \ - asan_dispatch_call_block_and_release); \ + PRINT_CURRENT_STACK(); \ + } \ + return REAL(dispatch_x_f)(dq, (void*)asan_ctxt, \ + asan_dispatch_call_block_and_release); \ } INTERCEPT_DISPATCH_X_F_3(dispatch_async_f) diff --git a/lib/asan/asan_poisoning.cc b/lib/asan/asan_poisoning.cc index 2d1706e2d..ef3ba9fb6 100644 --- a/lib/asan/asan_poisoning.cc +++ b/lib/asan/asan_poisoning.cc @@ -69,10 +69,8 @@ void __asan_poison_memory_region(void const volatile *addr, uptr size) { if (!flags()->allow_user_poisoning || size == 0) return; uptr beg_addr = (uptr)addr; uptr end_addr = beg_addr + size; - if (common_flags()->verbosity >= 1) { - Printf("Trying to poison memory region [%p, %p)\n", - (void*)beg_addr, (void*)end_addr); - } + VPrintf(1, "Trying to poison memory region [%p, %p)\n", (void *)beg_addr, + (void *)end_addr); ShadowSegmentEndpoint beg(beg_addr); ShadowSegmentEndpoint end(end_addr); if (beg.chunk == end.chunk) { @@ -111,10 +109,8 @@ void __asan_unpoison_memory_region(void const volatile *addr, uptr size) { if (!flags()->allow_user_poisoning || size == 0) return; uptr beg_addr = (uptr)addr; uptr end_addr = beg_addr + size; - if (common_flags()->verbosity >= 1) { - Printf("Trying to unpoison memory region [%p, %p)\n", - (void*)beg_addr, (void*)end_addr); - } + VPrintf(1, "Trying to unpoison memory region [%p, %p)\n", (void *)beg_addr, + (void *)end_addr); ShadowSegmentEndpoint beg(beg_addr); ShadowSegmentEndpoint end(end_addr); if (beg.chunk == end.chunk) { @@ -245,14 +241,12 @@ static void PoisonAlignedStackMemory(uptr addr, uptr size, bool do_poison) { } void __asan_poison_stack_memory(uptr addr, uptr size) { - if (common_flags()->verbosity > 0) - Report("poisoning: %p %zx\n", (void*)addr, size); + VReport(1, "poisoning: %p %zx\n", (void *)addr, size); PoisonAlignedStackMemory(addr, size, true); } void __asan_unpoison_stack_memory(uptr addr, uptr size) { - if (common_flags()->verbosity > 0) - Report("unpoisoning: %p %zx\n", (void*)addr, size); + VReport(1, "unpoisoning: %p %zx\n", (void *)addr, size); PoisonAlignedStackMemory(addr, size, false); } @@ -260,9 +254,8 @@ void __sanitizer_annotate_contiguous_container(const void *beg_p, const void *end_p, const void *old_mid_p, const void *new_mid_p) { - if (common_flags()->verbosity >= 2) - Printf("contiguous_container: %p %p %p %p\n", beg_p, end_p, old_mid_p, - new_mid_p); + VPrintf(2, "contiguous_container: %p %p %p %p\n", beg_p, end_p, old_mid_p, + new_mid_p); uptr beg = reinterpret_cast<uptr>(beg_p); uptr end= reinterpret_cast<uptr>(end_p); uptr old_mid = reinterpret_cast<uptr>(old_mid_p); diff --git a/lib/asan/asan_posix.cc b/lib/asan/asan_posix.cc index bcc6b381a..91b35113e 100644 --- a/lib/asan/asan_posix.cc +++ b/lib/asan/asan_posix.cc @@ -44,9 +44,7 @@ static void MaybeInstallSigaction(int signum, sigact.sa_flags = SA_SIGINFO; if (flags()->use_sigaltstack) sigact.sa_flags |= SA_ONSTACK; CHECK_EQ(0, REAL(sigaction)(signum, &sigact, 0)); - if (common_flags()->verbosity >= 1) { - Report("Installed the sigaction for signal %d\n", signum); - } + VReport(1, "Installed the sigaction for signal %d\n", signum); } static void ASAN_OnSIGSEGV(int, siginfo_t *siginfo, void *context) { @@ -71,11 +69,9 @@ void SetAlternateSignalStack() { altstack.ss_flags = 0; altstack.ss_size = kAltStackSize; CHECK_EQ(0, sigaltstack(&altstack, 0)); - if (common_flags()->verbosity > 0) { - Report("Alternative stack for T%d set: [%p,%p)\n", - GetCurrentTidOrInvalid(), - altstack.ss_sp, (char*)altstack.ss_sp + altstack.ss_size); - } + VReport(1, "Alternative stack for T%d set: [%p,%p)\n", + GetCurrentTidOrInvalid(), altstack.ss_sp, + (char *)altstack.ss_sp + altstack.ss_size); } void UnsetAlternateSignalStack() { diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc index 25cafc8dc..649894060 100644 --- a/lib/asan/asan_rtl.cc +++ b/lib/asan/asan_rtl.cc @@ -62,8 +62,8 @@ static void AsanDie() { static void AsanCheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2) { - Report("AddressSanitizer CHECK failed: %s:%d \"%s\" (0x%zx, 0x%zx)\n", - file, line, cond, (uptr)v1, (uptr)v2); + Report("AddressSanitizer CHECK failed: %s:%d \"%s\" (0x%zx, 0x%zx)\n", file, + line, cond, (uptr)v1, (uptr)v2); // FIXME: check for infinite recursion without a thread-local counter here. PRINT_CURRENT_STACK(); Die(); @@ -182,10 +182,8 @@ void InitializeFlags(Flags *f, const char *env) { // Override from user-specified string. ParseFlagsFromString(f, MaybeCallAsanDefaultOptions()); - if (cf->verbosity) { - Report("Using the defaults from __asan_default_options: %s\n", - MaybeCallAsanDefaultOptions()); - } + VReport(1, "Using the defaults from __asan_default_options: %s\n", + MaybeCallAsanDefaultOptions()); // Override from command line. ParseFlagsFromString(f, env); @@ -460,8 +458,8 @@ void __asan_init() { __asan_option_detect_stack_use_after_return = flags()->detect_stack_use_after_return; - if (common_flags()->verbosity && options) { - Report("Parsed ASAN_OPTIONS: %s\n", options); + if (options) { + VReport(1, "Parsed ASAN_OPTIONS: %s\n", options); } // Re-exec ourselves if we need to set additional env or command line args. @@ -569,7 +567,5 @@ void __asan_init() { } #endif // CAN_SANITIZE_LEAKS - if (common_flags()->verbosity) { - Report("AddressSanitizer Init done\n"); - } + VReport(1, "AddressSanitizer Init done\n"); } diff --git a/lib/asan/asan_thread.cc b/lib/asan/asan_thread.cc index 77156ebe7..cbbfe7678 100644 --- a/lib/asan/asan_thread.cc +++ b/lib/asan/asan_thread.cc @@ -87,16 +87,13 @@ AsanThread *AsanThread::Create(thread_callback_t start_routine, void AsanThread::TSDDtor(void *tsd) { AsanThreadContext *context = (AsanThreadContext*)tsd; - if (common_flags()->verbosity >= 1) - Report("T%d TSDDtor\n", context->tid); + VReport(1, "T%d TSDDtor\n", context->tid); if (context->thread) context->thread->Destroy(); } void AsanThread::Destroy() { - if (common_flags()->verbosity >= 1) { - Report("T%d exited\n", tid()); - } + VReport(1, "T%d exited\n", tid()); malloc_storage().CommitBack(); if (flags()->use_sigaltstack) UnsetAlternateSignalStack(); @@ -142,12 +139,10 @@ void AsanThread::Init() { CHECK(AddrIsInMem(stack_bottom_)); CHECK(AddrIsInMem(stack_top_ - 1)); ClearShadowForThreadStackAndTLS(); - if (common_flags()->verbosity >= 1) { - int local = 0; - Report("T%d: stack [%p,%p) size 0x%zx; local=%p\n", - tid(), (void*)stack_bottom_, (void*)stack_top_, - stack_top_ - stack_bottom_, &local); - } + int local = 0; + VReport(1, "T%d: stack [%p,%p) size 0x%zx; local=%p\n", tid(), + (void *)stack_bottom_, (void *)stack_top_, stack_top_ - stack_bottom_, + &local); fake_stack_ = 0; // Will be initialized lazily if needed. AsanPlatformThreadInit(); } @@ -267,10 +262,8 @@ AsanThread *GetCurrentThread() { void SetCurrentThread(AsanThread *t) { CHECK(t->context()); - if (common_flags()->verbosity >= 2) { - Report("SetCurrentThread: %p for thread %p\n", - t->context(), (void*)GetThreadSelf()); - } + VReport(2, "SetCurrentThread: %p for thread %p\n", t->context(), + (void *)GetThreadSelf()); // Make sure we do not reset the current AsanThread. CHECK_EQ(0, AsanTSDGet()); AsanTSDSet(t->context()); diff --git a/lib/msan/msan.cc b/lib/msan/msan.cc index 890a5d93f..72c9a2ea1 100644 --- a/lib/msan/msan.cc +++ b/lib/msan/msan.cc @@ -307,21 +307,19 @@ void __msan_init() { if (MSAN_REPLACE_OPERATORS_NEW_AND_DELETE) ReplaceOperatorsNewAndDelete(); if (StackSizeIsUnlimited()) { - if (common_flags()->verbosity) - Printf("Unlimited stack, doing reexec\n"); + VPrintf(1, "Unlimited stack, doing reexec\n"); // A reasonably large stack size. It is bigger than the usual 8Mb, because, // well, the program could have been run with unlimited stack for a reason. SetStackSizeLimitInBytes(32 * 1024 * 1024); ReExec(); } - if (common_flags()->verbosity) - Printf("MSAN_OPTIONS: %s\n", msan_options ? msan_options : "<empty>"); + VPrintf(1, "MSAN_OPTIONS: %s\n", msan_options ? msan_options : "<empty>"); msan_running_under_dr = IsRunningUnderDr(); __msan_clear_on_return(); - if (__msan_get_track_origins() && common_flags()->verbosity > 0) - Printf("msan_track_origins\n"); + if (__msan_get_track_origins()) + VPrintf(1, "msan_track_origins\n"); if (!InitShadow(/* prot1 */ false, /* prot2 */ true, /* map_shadow */ true, __msan_get_track_origins())) { // FIXME: prot1 = false is only required when running under DR. @@ -345,8 +343,7 @@ void __msan_init() { GetThreadStackTopAndBottom(/* at_initialization */true, &__msan_stack_bounds.stack_top, &__msan_stack_bounds.stack_bottom); - if (common_flags()->verbosity) - Printf("MemorySanitizer init done\n"); + VPrintf(1, "MemorySanitizer init done\n"); msan_init_is_running = 0; msan_inited = 1; } diff --git a/lib/msan/msan_interceptors.cc b/lib/msan/msan_interceptors.cc index 15a8bec12..873d72ec2 100644 --- a/lib/msan/msan_interceptors.cc +++ b/lib/msan/msan_interceptors.cc @@ -1195,8 +1195,8 @@ static void MlockIsUnsupported() { static atomic_uint8_t printed; if (atomic_exchange(&printed, 1, memory_order_relaxed)) return; - if (common_flags()->verbosity > 0) - Printf("INFO: MemorySanitizer ignores mlock/mlockall/munlock/munlockall\n"); + VPrintf(1, + "INFO: MemorySanitizer ignores mlock/mlockall/munlock/munlockall\n"); } INTERCEPTOR(int, mlock, const void *addr, uptr len) { @@ -1242,11 +1242,10 @@ extern "C" int *__errno_location(void); CHECK_UNPOISONED_0(x, n); \ } while (0) -#define MSAN_INTERCEPT_FUNC(name) \ - do { \ - if ((!INTERCEPT_FUNCTION(name) || !REAL(name)) && \ - common_flags()->verbosity > 0) \ - Report("MemorySanitizer: failed to intercept '" #name "'\n"); \ +#define MSAN_INTERCEPT_FUNC(name) \ + do { \ + if ((!INTERCEPT_FUNCTION(name) || !REAL(name))) \ + VReport(1, "MemorySanitizer: failed to intercept '" #name "'\n"); \ } while (0) #define COMMON_INTERCEPT_FUNCTION(name) MSAN_INTERCEPT_FUNC(name) diff --git a/lib/msan/msan_linux.cc b/lib/msan/msan_linux.cc index 46f501e48..4cb46e484 100644 --- a/lib/msan/msan_linux.cc +++ b/lib/msan/msan_linux.cc @@ -51,14 +51,12 @@ bool InitShadow(bool prot1, bool prot2, bool map_shadow, bool init_origins) { return false; } - if (common_flags()->verbosity) { - Printf("__msan_init %p\n", &__msan_init); - Printf("Memory : %p %p\n", kMemBeg, kMemEnd); - Printf("Bad2 : %p %p\n", kBad2Beg, kBad2End); - Printf("Origins : %p %p\n", kOriginsBeg, kOriginsEnd); - Printf("Shadow : %p %p\n", kShadowBeg, kShadowEnd); - Printf("Bad1 : %p %p\n", kBad1Beg, kBad1End); - } + VPrintf(1, "__msan_init %p\n", &__msan_init); + VPrintf(1, "Memory : %p %p\n", kMemBeg, kMemEnd); + VPrintf(1, "Bad2 : %p %p\n", kBad2Beg, kBad2End); + VPrintf(1, "Origins : %p %p\n", kOriginsBeg, kOriginsEnd); + VPrintf(1, "Shadow : %p %p\n", kShadowBeg, kShadowEnd); + VPrintf(1, "Bad1 : %p %p\n", kBad1Beg, kBad1End); if (!MemoryRangeIsAvailable(kShadowBeg, init_origins ? kOriginsEnd : kShadowEnd)) { diff --git a/lib/msan/msan_report.cc b/lib/msan/msan_report.cc index e3ef99307..83c1fbb84 100644 --- a/lib/msan/msan_report.cc +++ b/lib/msan/msan_report.cc @@ -36,8 +36,7 @@ class Decorator: private __sanitizer::AnsiColorDecorator { static void DescribeOrigin(u32 origin) { Decorator d; - if (common_flags()->verbosity) - Printf(" raw origin id: %d\n", origin); + VPrintf(1, " raw origin id: %d\n", origin); uptr pc; if (const char *so = GetOriginDescrIfStack(origin, &pc)) { char* s = internal_strdup(so); diff --git a/lib/sanitizer_common/sanitizer_common.h b/lib/sanitizer_common/sanitizer_common.h index ab67be21c..604f1b013 100644 --- a/lib/sanitizer_common/sanitizer_common.h +++ b/lib/sanitizer_common/sanitizer_common.h @@ -128,6 +128,14 @@ bool PrintsToTtyCached(); void Printf(const char *format, ...); void Report(const char *format, ...); void SetPrintfAndReportCallback(void (*callback)(const char *)); +#define VReport(level, ...) \ + do { \ + if ((uptr)common_flags()->verbosity >= (level)) Report(__VA_ARGS__); \ + } while (0) +#define VPrintf(level, ...) \ + do { \ + if ((uptr)common_flags()->verbosity >= (level)) Printf(__VA_ARGS__); \ + } while (0) // Can be used to prevent mixing error reports from different sanitizers. extern StaticSpinMutex CommonSanitizerReportMutex; diff --git a/lib/sanitizer_common/sanitizer_coverage.cc b/lib/sanitizer_common/sanitizer_coverage.cc index 9e7a0f8b9..0e928e0cb 100644 --- a/lib/sanitizer_common/sanitizer_coverage.cc +++ b/lib/sanitizer_common/sanitizer_coverage.cc @@ -96,8 +96,7 @@ void CovDump() { uptr fd = OpenFile(path.data(), true); internal_write(fd, offsets.data(), offsets.size() * sizeof(u32)); internal_close(fd); - if (common_flags()->verbosity) - Report(" CovDump: %s: %zd PCs written\n", path.data(), vb - old_vb); + VReport(1, " CovDump: %s: %zd PCs written\n", path.data(), vb - old_vb); } } #endif // !SANITIZER_WINDOWS diff --git a/lib/sanitizer_common/sanitizer_libignore.cc b/lib/sanitizer_common/sanitizer_libignore.cc index 0f193a130..a0bb871b2 100644 --- a/lib/sanitizer_common/sanitizer_libignore.cc +++ b/lib/sanitizer_common/sanitizer_libignore.cc @@ -76,9 +76,10 @@ void LibIgnore::OnLibraryLoaded(const char *name) { loaded = true; if (lib->loaded) continue; - if (common_flags()->verbosity) - Report("Matched called_from_lib suppression '%s' against library" - " '%s'\n", lib->templ, module.data()); + VReport(1, + "Matched called_from_lib suppression '%s' against library" + " '%s'\n", + lib->templ, module.data()); lib->loaded = true; lib->name = internal_strdup(module.data()); const uptr idx = atomic_load(&loaded_count_, memory_order_relaxed); diff --git a/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/lib/sanitizer_common/sanitizer_linux_libcdep.cc index 79b0295a5..a755f2adf 100644 --- a/lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ b/lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -284,9 +284,9 @@ void AdjustStackSizeLinux(void *attr_) { const uptr minstacksize = GetTlsSize() + 128*1024; if (stacksize < minstacksize) { if (!stack_set) { - if (common_flags()->verbosity && stacksize != 0) - Printf("Sanitizer: increasing stacksize %zu->%zu\n", stacksize, - minstacksize); + if (stacksize != 0) + VPrintf(1, "Sanitizer: increasing stacksize %zu->%zu\n", stacksize, + minstacksize); pthread_attr_setstacksize(attr, minstacksize); } else { Printf("Sanitizer: pre-allocated stack size is insufficient: " diff --git a/lib/sanitizer_common/sanitizer_printf.cc b/lib/sanitizer_common/sanitizer_printf.cc index bbdb24b68..4417a50f8 100644 --- a/lib/sanitizer_common/sanitizer_printf.cc +++ b/lib/sanitizer_common/sanitizer_printf.cc @@ -16,6 +16,7 @@ #include "sanitizer_common.h" +#include "sanitizer_flags.h" #include "sanitizer_libc.h" #include <stdio.h> diff --git a/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc b/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc index 8a0ffd434..ef275f546 100644 --- a/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc +++ b/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc @@ -100,12 +100,11 @@ bool ThreadSuspender::SuspendThread(SuspendedThreadID thread_id) { &pterrno)) { // Either the thread is dead, or something prevented us from attaching. // Log this event and move on. - if (common_flags()->verbosity) - Report("Could not attach to thread %d (errno %d).\n", thread_id, pterrno); + VReport(1, "Could not attach to thread %d (errno %d).\n", thread_id, + pterrno); return false; } else { - if (common_flags()->verbosity) - Report("Attached to thread %d.\n", thread_id); + VReport(1, "Attached to thread %d.\n", thread_id); // The thread is not guaranteed to stop before ptrace returns, so we must // wait on it. uptr waitpid_status; @@ -114,9 +113,8 @@ bool ThreadSuspender::SuspendThread(SuspendedThreadID thread_id) { if (internal_iserror(waitpid_status, &wperrno)) { // Got a ECHILD error. I don't think this situation is possible, but it // doesn't hurt to report it. - if (common_flags()->verbosity) - Report("Waiting on thread %d failed, detaching (errno %d).\n", - thread_id, wperrno); + VReport(1, "Waiting on thread %d failed, detaching (errno %d).\n", + thread_id, wperrno); internal_ptrace(PTRACE_DETACH, thread_id, NULL, NULL); return false; } @@ -131,14 +129,12 @@ void ThreadSuspender::ResumeAllThreads() { int pterrno; if (!internal_iserror(internal_ptrace(PTRACE_DETACH, tid, NULL, NULL), &pterrno)) { - if (common_flags()->verbosity) - Report("Detached from thread %d.\n", tid); + VReport(1, "Detached from thread %d.\n", tid); } else { // Either the thread is dead, or we are already detached. // The latter case is possible, for instance, if this function was called // from a signal handler. - if (common_flags()->verbosity) - Report("Could not detach from thread %d (errno %d).\n", tid, pterrno); + VReport(1, "Could not detach from thread %d (errno %d).\n", tid, pterrno); } } } @@ -260,8 +256,7 @@ static int TracerThread(void* argument) { int exit_code = 0; if (!thread_suspender.SuspendAllThreads()) { - if (common_flags()->verbosity) - Report("Failed suspending threads.\n"); + VReport(1, "Failed suspending threads.\n"); exit_code = 3; } else { tracer_thread_argument->callback(thread_suspender.suspended_threads_list(), @@ -389,8 +384,7 @@ void StopTheWorld(StopTheWorldCallback callback, void *argument) { /* child_tidptr */); int local_errno = 0; if (internal_iserror(tracer_pid, &local_errno)) { - if (common_flags()->verbosity) - Report("Failed spawning a tracer thread (errno %d).\n", local_errno); + VReport(1, "Failed spawning a tracer thread (errno %d).\n", local_errno); tracer_thread_argument.mutex.Unlock(); } else { ScopedSetTracerPID scoped_set_tracer_pid(tracer_pid); @@ -406,11 +400,9 @@ void StopTheWorld(StopTheWorldCallback callback, void *argument) { // At this point, any signal will either be blocked or kill us, so waitpid // should never return (and set errno) while the tracer thread is alive. uptr waitpid_status = internal_waitpid(tracer_pid, NULL, __WALL); - if (internal_iserror(waitpid_status, &local_errno)) { - if (common_flags()->verbosity) - Report("Waiting on the tracer thread failed (errno %d).\n", - local_errno); - } + if (internal_iserror(waitpid_status, &local_errno)) + VReport(1, "Waiting on the tracer thread failed (errno %d).\n", + local_errno); } } @@ -451,9 +443,8 @@ int SuspendedThreadsList::GetRegistersAndSP(uptr index, int pterrno; if (internal_iserror(internal_ptrace(PTRACE_GETREGS, tid, NULL, ®s), &pterrno)) { - if (common_flags()->verbosity) - Report("Could not get registers from thread %d (errno %d).\n", - tid, pterrno); + VReport(1, "Could not get registers from thread %d (errno %d).\n", tid, + pterrno); return -1; } |