tsan: be silent if verbosity=0

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



git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192711 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/sanitizer_common/sanitizer_common.cc b/lib/sanitizer_common/sanitizer_common.cc
index 76f9071..5c61f77 100644
--- a/lib/sanitizer_common/sanitizer_common.cc
+++ b/lib/sanitizer_common/sanitizer_common.cc
@@ -18,7 +18,6 @@
 namespace __sanitizer {
 
 const char *SanitizerToolName = "SanitizerTool";
-uptr SanitizerVerbosity = 0;
 
 uptr GetPageSizeCached() {
   static uptr PageSize;
diff --git a/lib/sanitizer_common/sanitizer_common.h b/lib/sanitizer_common/sanitizer_common.h
index af1e4f1..87f3b48 100644
--- a/lib/sanitizer_common/sanitizer_common.h
+++ b/lib/sanitizer_common/sanitizer_common.h
@@ -36,7 +36,6 @@
 const uptr kMaxPathLength = 512;
 
 extern const char *SanitizerToolName;  // Can be changed by the tool.
-extern uptr SanitizerVerbosity;
 
 uptr GetPageSize();
 uptr GetPageSizeCached();
diff --git a/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc b/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
index 3fb2886..a34ddd8 100644
--- a/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+++ b/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
@@ -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 @@
                        &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 @@
     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 @@
     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 @@
 
   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 @@
       /* 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 @@
     // 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 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;
   }