diff options
author | Anna Zaks <ganna@apple.com> | 2016-01-06 23:15:01 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2016-01-06 23:15:01 +0000 |
commit | 89251b08eb4bd2111bd50c72b947370e06e3acaa (patch) | |
tree | 1ed5b627e96a3df96f6a949adc9f0f79726ca583 /lib | |
parent | 5c2b59ac6e0ba0c26a8cc2fa7983faca30aa25ce (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@256988 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/asan/asan_report.cc | 3 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_common.h | 4 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_common_libcdep.cc | 3 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_linux_libcdep.cc | 9 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_mac.cc | 10 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_mac.h | 6 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_printf.cc | 7 |
7 files changed, 25 insertions, 17 deletions
diff --git a/lib/asan/asan_report.cc b/lib/asan/asan_report.cc index 0fb60846c..bb7e36e84 100644 --- a/lib/asan/asan_report.cc +++ b/lib/asan/asan_report.cc @@ -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) { diff --git a/lib/sanitizer_common/sanitizer_common.h b/lib/sanitizer_common/sanitizer_common.h index 0585f6b15..7e80507ba 100644 --- a/lib/sanitizer_common/sanitizer_common.h +++ b/lib/sanitizer_common/sanitizer_common.h @@ -665,17 +665,17 @@ INLINE void LogFullErrorReport(const char *buffer) {} #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 diff --git a/lib/sanitizer_common/sanitizer_common_libcdep.cc b/lib/sanitizer_common/sanitizer_common_libcdep.cc index b5d46f244..596f5bcd3 100644 --- a/lib/sanitizer_common/sanitizer_common_libcdep.cc +++ b/lib/sanitizer_common/sanitizer_common_libcdep.cc @@ -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 { diff --git a/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/lib/sanitizer_common/sanitizer_linux_libcdep.cc index 0bb66c9d6..8cf2c73b1 100644 --- a/lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ b/lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -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 diff --git a/lib/sanitizer_common/sanitizer_mac.cc b/lib/sanitizer_common/sanitizer_mac.cc index 1c96a6b95..715509d30 100644 --- a/lib/sanitizer_common/sanitizer_mac.cc +++ b/lib/sanitizer_common/sanitizer_mac.cc @@ -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 *buffer) { 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) { diff --git a/lib/sanitizer_common/sanitizer_mac.h b/lib/sanitizer_common/sanitizer_mac.h index 86a995668..6e2b84f43 100644 --- a/lib/sanitizer_common/sanitizer_mac.h +++ b/lib/sanitizer_common/sanitizer_mac.h @@ -44,9 +44,11 @@ static const char *__crashreporter_info__ __attribute__((__used__)) = &__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 diff --git a/lib/sanitizer_common/sanitizer_printf.cc b/lib/sanitizer_common/sanitizer_printf.cc index 2794e667e..434ebb93d 100644 --- a/lib/sanitizer_common/sanitizer_printf.cc +++ b/lib/sanitizer_common/sanitizer_printf.cc @@ -278,9 +278,12 @@ static void SharedPrintfCode(bool append_pid, const char *format, # 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); |