[compiler-rt] r256988 - [sanitizers] Log all output to CrashReport on OS X

Anna Zaks via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 6 15:15:01 PST 2016


Author: zaks
Date: Wed Jan  6 17:15:01 2016
New Revision: 256988

URL: http://llvm.org/viewvc/llvm-project?rev=256988&view=rev
Log:
[sanitizers] Log all output to CrashReport on OS X

Log all of sanitizers' output (not just ASan bug reports) to CrashReport,
which simplifies diagnosing failed checks as well as other errors. This
also allows to strip the color sequences early from the printed buffer,
which is more efficient than what we had perviously.

Differential Revision: http://reviews.llvm.org/D15396

Modified:
    compiler-rt/trunk/lib/asan/asan_report.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc

Modified: compiler-rt/trunk/lib/asan/asan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.cc?rev=256988&r1=256987&r2=256988&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_report.cc Wed Jan  6 17:15:01 2016
@@ -696,9 +696,6 @@ class ScopedInErrorReport {
                       error_message_buffer, kErrorMessageBufferSize);
     }
 
-    // Remove color sequences since logs cannot print them.
-    RemoveANSIEscapeSequencesFromString(buffer_copy.data());
-
     LogFullErrorReport(buffer_copy.data());
 
     if (error_report_callback) {

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=256988&r1=256987&r2=256988&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Wed Jan  6 17:15:01 2016
@@ -665,17 +665,17 @@ INLINE void LogFullErrorReport(const cha
 
 #if SANITIZER_LINUX || SANITIZER_MAC
 void WriteOneLineToSyslog(const char *s);
+void LogMessageOnPrintf(const char *str);
 #else
 INLINE void WriteOneLineToSyslog(const char *s) {}
+INLINE void LogMessageOnPrintf(const char *str) {}
 #endif
 
 #if SANITIZER_LINUX
 // Initialize Android logging. Any writes before this are silently lost.
 void AndroidLogInit();
-bool ShouldLogAfterPrintf();
 #else
 INLINE void AndroidLogInit() {}
-INLINE bool ShouldLogAfterPrintf() { return false; }
 #endif
 
 #if SANITIZER_ANDROID

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc?rev=256988&r1=256987&r2=256988&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc Wed Jan  6 17:15:01 2016
@@ -125,9 +125,6 @@ void WriteToSyslog(const char *msg) {
   char *p = msg_copy.data();
   char *q;
 
-  // Remove color sequences since syslogs cannot print them.
-  RemoveANSIEscapeSequencesFromString(p);
-
   // Print one line at a time.
   // syslog, at least on Android, has an implicit message length limit.
   do {

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc?rev=256988&r1=256987&r2=256988&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc Wed Jan  6 17:15:01 2016
@@ -524,13 +524,13 @@ void AndroidLogInit() {
   atomic_store(&android_log_initialized, 1, memory_order_release);
 }
 
-bool ShouldLogAfterPrintf() {
+static bool ShouldLogAfterPrintf() {
   return atomic_load(&android_log_initialized, memory_order_acquire);
 }
 #else
 void AndroidLogInit() {}
 
-bool ShouldLogAfterPrintf() { return true; }
+static bool ShouldLogAfterPrintf() { return true; }
 #endif  // SANITIZER_ANDROID
 
 void WriteOneLineToSyslog(const char *s) {
@@ -541,6 +541,11 @@ void WriteOneLineToSyslog(const char *s)
 #endif
 }
 
+void LogMessageOnPrintf(const char *str) {
+  if (common_flags()->log_to_syslog && ShouldLogAfterPrintf())
+    WriteToSyslog(str);
+}
+
 #endif // SANITIZER_LINUX
 
 } // namespace __sanitizer

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=256988&r1=256987&r2=256988&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Wed Jan  6 17:15:01 2016
@@ -430,6 +430,12 @@ void WriteOneLineToSyslog(const char *s)
   asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", s);
 }
 
+void LogMessageOnPrintf(const char *str) {
+  // Log all printf output to CrashLog.
+  if (common_flags()->abort_on_error)
+    CRAppendCrashLogMessage(str);
+}
+
 void LogFullErrorReport(const char *buffer) {
   // Log with os_trace. This will make it into the crash log.
 #if SANITIZER_OS_TRACE
@@ -463,9 +469,7 @@ void LogFullErrorReport(const char *buff
   if (common_flags()->log_to_syslog)
     WriteToSyslog(buffer);
 
-  // Log to CrashLog.
-  if (common_flags()->abort_on_error)
-    CRSetCrashLogMessage(buffer);
+  // The report is added to CrashLog as part of logging all of Printf output.
 }
 
 void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h?rev=256988&r1=256987&r2=256988&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h Wed Jan  6 17:15:01 2016
@@ -44,9 +44,11 @@ static const char *__crashreporter_info_
   &__crashreporter_info_buff__[0];
 asm(".desc ___crashreporter_info__, 0x10");
 } // extern "C"
+static BlockingMutex crashreporter_info_mutex(LINKER_INITIALIZED);
 
-INLINE void CRSetCrashLogMessage(const char *msg) {
-  internal_strlcpy(__crashreporter_info_buff__, msg,
+INLINE void CRAppendCrashLogMessage(const char *msg) {
+  BlockingMutexLock l(&crashreporter_info_mutex);
+  internal_strlcat(__crashreporter_info_buff__, msg,
                    sizeof(__crashreporter_info_buff__)); }
 
 #endif  // SANITIZER_MAC

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc?rev=256988&r1=256987&r2=256988&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc Wed Jan  6 17:15:01 2016
@@ -278,9 +278,12 @@ static void SharedPrintfCode(bool append
 #   undef CHECK_NEEDED_LENGTH
   }
   RawWrite(buffer);
-  if (common_flags()->log_to_syslog && ShouldLogAfterPrintf())
-    WriteToSyslog(buffer);
+
+  // Remove color sequences from the message.
+  RemoveANSIEscapeSequencesFromString(buffer);
   CallPrintfAndReportCallback(buffer);
+  LogMessageOnPrintf(buffer);
+
   // If we had mapped any memory, clean up.
   if (buffer != local_buffer)
     UnmapOrDie((void *)buffer, buffer_size);




More information about the llvm-commits mailing list