tsan: be silent if verbosity=0

Currently tests fail with:
Check failed: 'AAA' == 'AAA ==26017==Could not detach from thread 361395 (errno 3).'

llvm-svn: 192711
This commit is contained in:
Dmitry Vyukov 2013-10-15 15:35:56 +00:00
parent dd6dc8276f
commit 21e99319f4
3 changed files with 21 additions and 13 deletions

View File

@ -18,7 +18,6 @@
namespace __sanitizer {
const char *SanitizerToolName = "SanitizerTool";
uptr SanitizerVerbosity = 0;
uptr GetPageSizeCached() {
static uptr PageSize;

View File

@ -36,7 +36,6 @@ const uptr kCacheLineSize = 64;
const uptr kMaxPathLength = 512;
extern const char *SanitizerToolName; // Can be changed by the tool.
extern uptr SanitizerVerbosity;
uptr GetPageSize();
uptr GetPageSizeCached();

View File

@ -42,6 +42,7 @@
#endif
#include "sanitizer_common.h"
#include "sanitizer_flags.h"
#include "sanitizer_libc.h"
#include "sanitizer_linux.h"
#include "sanitizer_mutex.h"
@ -99,10 +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.
Report("Could not attach to thread %d (errno %d).\n", thread_id, pterrno);
if (common_flags()->verbosity)
Report("Could not attach to thread %d (errno %d).\n", thread_id, pterrno);
return false;
} else {
if (SanitizerVerbosity > 0)
if (common_flags()->verbosity)
Report("Attached to thread %d.\n", thread_id);
// The thread is not guaranteed to stop before ptrace returns, so we must
// wait on it.
@ -112,8 +114,9 @@ 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.
Report("Waiting on thread %d failed, detaching (errno %d).\n", thread_id,
wperrno);
if (common_flags()->verbosity)
Report("Waiting on thread %d failed, detaching (errno %d).\n",
thread_id, wperrno);
internal_ptrace(PTRACE_DETACH, thread_id, NULL, NULL);
return false;
}
@ -128,13 +131,14 @@ void ThreadSuspender::ResumeAllThreads() {
int pterrno;
if (!internal_iserror(internal_ptrace(PTRACE_DETACH, tid, NULL, NULL),
&pterrno)) {
if (SanitizerVerbosity > 0)
if (common_flags()->verbosity)
Report("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.
Report("Could not detach from thread %d (errno %d).\n", tid, pterrno);
if (common_flags()->verbosity)
Report("Could not detach from thread %d (errno %d).\n", tid, pterrno);
}
}
}
@ -256,7 +260,8 @@ static int TracerThread(void* argument) {
int exit_code = 0;
if (!thread_suspender.SuspendAllThreads()) {
Report("Failed suspending threads.\n");
if (common_flags()->verbosity)
Report("Failed suspending threads.\n");
exit_code = 3;
} else {
tracer_thread_argument->callback(thread_suspender.suspended_threads_list(),
@ -370,7 +375,8 @@ void StopTheWorld(StopTheWorldCallback callback, void *argument) {
/* child_tidptr */);
int local_errno = 0;
if (internal_iserror(tracer_pid, &local_errno)) {
Report("Failed spawning a tracer thread (errno %d).\n", local_errno);
if (common_flags()->verbosity)
Report("Failed spawning a tracer thread (errno %d).\n", local_errno);
tracer_thread_argument.mutex.Unlock();
} else {
// On some systems we have to explicitly declare that we want to be traced
@ -385,8 +391,11 @@ 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))
Report("Waiting on the tracer thread failed (errno %d).\n", local_errno);
if (internal_iserror(waitpid_status, &local_errno)) {
if (common_flags()->verbosity)
Report("Waiting on the tracer thread failed (errno %d).\n",
local_errno);
}
}
}
@ -427,7 +436,8 @@ int SuspendedThreadsList::GetRegistersAndSP(uptr index,
int pterrno;
if (internal_iserror(internal_ptrace(PTRACE_GETREGS, tid, NULL, &regs),
&pterrno)) {
Report("Could not get registers from thread %d (errno %d).\n",
if (common_flags()->verbosity)
Report("Could not get registers from thread %d (errno %d).\n",
tid, pterrno);
return -1;
}