From dd6e12b5701af38270949fc120223be6b56c1797 Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Sequoia Date: Sun, 25 Oct 2015 16:03:00 -0700 Subject: [PATCH 2008/2008] Save the ASan report in the OS X crash log Signed-off-by: Jeremy Huddleston Sequoia --- lib/asan/asan_report.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git llvm_release_37/projects/compiler-rt/lib/asan/asan_report.cc macports_release_37/projects/compiler-rt/lib/asan/asan_report.cc index c1681e6..6f859d5 100644 --- llvm_release_37/projects/compiler-rt/lib/asan/asan_report.cc +++ macports_release_37/projects/compiler-rt/lib/asan/asan_report.cc @@ -23,6 +23,14 @@ #include "sanitizer_common/sanitizer_stackdepot.h" #include "sanitizer_common/sanitizer_symbolizer.h" +// Apple CrashReporter support. +#ifdef __APPLE__ +extern "C" { +static char *__crashreporter_info__ __attribute__((__used__)) = 0; +asm (".desc ___crashreporter_info__, 0x10"); +} +#endif + namespace __asan { // -------------------- User-specified callbacks ----------------- {{{1 @@ -45,6 +53,16 @@ static bool report_happened = false; static ReportData report_data = {}; void AppendToErrorMessageBuffer(const char *buffer) { +#if __APPLE__ + // For the Apple CrashReporter support: Always store reports into buffer. + if (!error_message_buffer) { + error_message_buffer_size = 1 << 16; + error_message_buffer = + (char*)MmapOrDie(error_message_buffer_size, __func__); + error_message_buffer_pos = 0; + } +#endif + if (error_message_buffer) { uptr length = internal_strlen(buffer); CHECK_GE(error_message_buffer_size, error_message_buffer_pos); @@ -663,6 +681,14 @@ class ScopedInErrorReport { // Print memory stats. if (flags()->print_stats) __asan_print_accumulated_stats(); + +#ifdef __APPLE__ + if (flags()->abort_on_error) { + __crashreporter_info__ = internal_strdup(error_message_buffer); + RemoveANSIEscapeSequencesFromString(__crashreporter_info__); + } +#endif + if (error_report_callback) { error_report_callback(error_message_buffer); } -- 2.6.2