When ASan currently detects a bug, by default it will only print out the text of the report to stderr. This patch changes this behavior and writes the full text of the report to syslog before we terminate the process. It also calls os_trace (Activity Tracing available on OS X and iOS) with a message saying that the report is available in syslog. This is useful, because this message will be shown in the crash log.
For this to work, the patch makes sure we store the full report into error_message_buffer unconditionally, and it also strips out ANSI escape sequences from the report (they are used when producing colored reports).
This is the second version of the patch that addresses several concerns raised in http://reviews.llvm.org/D11981
- Added a unit test for removal of color sequences
- Moved the logic to sanitizer_common, instead of ASan so that all other tools could use error report logging. (Note, that this introduced some ugliness due to the specifics of os_trace, which only allows us to log literal strings and I think it's important to log the name of the tool that produced the report there.)
- Refactored the Android specific WriteToSyslog logic to make it reusable by other platforms.
- Added a lock to AppendToErrorMessageBuffer.
- Made sure the logging is off for testing. The code will get executed by abort_on_error.cc test that runs with the default options.
I've initially tried to log to syslog during printing, which is done on Android right now. The advantage is that if we crash during error reporting or the produced error does not go through ScopedInErrorReport, we would still get a (partial) message in the syslog. However, that solution is very problematic on OS X. One issue is that the logging routine uses GCD, which may spawn a new thread on its behalf. In many cases, the reporting logic locks threadRegistry, which leads to deadlocks.
This should be error_message_buf_mutex(LINKER_INITIALIZED);