diff options
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/sanitizer_common.cc')
-rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_common.cc | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc index 22c7093db5f..614b7b9d465 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc @@ -16,6 +16,9 @@ namespace __sanitizer { +static fd_t report_fd = 2; // By default, dump to stderr. +static char report_path[4096]; // Set via __sanitizer_set_report_path. + static void (*DieCallback)(void); void SetDieCallback(void (*callback)(void)) { DieCallback = callback; @@ -46,8 +49,17 @@ void NORETURN CheckFailed(const char *file, int line, const char *cond, void RawWrite(const char *buffer) { static const char *kRawWriteError = "RawWrite can't output requested buffer!"; uptr length = (uptr)internal_strlen(buffer); - if (length != internal_write(2, buffer, length)) { - internal_write(2, kRawWriteError, internal_strlen(kRawWriteError)); + if (report_fd == kInvalidFd) { + fd_t fd = internal_open(report_path, true); + if (fd == kInvalidFd) { + report_fd = 2; + Report("ERROR: Can't open file: %s\n", report_path); + Die(); + } + report_fd = fd; + } + if (length != internal_write(report_fd, buffer, length)) { + internal_write(report_fd, kRawWriteError, internal_strlen(kRawWriteError)); Die(); } } @@ -125,3 +137,17 @@ void SortArray(uptr *array, uptr size) { } } // namespace __sanitizer + +void __sanitizer_set_report_path(const char *path) { + if (!path) return; + uptr len = internal_strlen(path); + if (len > sizeof(__sanitizer::report_path) - 100) { + Report("ERROR: Path is too long: %c%c%c%c%c%c%c%c...\n", + path[0], path[1], path[2], path[3], + path[4], path[5], path[6], path[7]); + Die(); + } + internal_snprintf(__sanitizer::report_path, + sizeof(__sanitizer::report_path), "%s.%d", path, GetPid()); + __sanitizer::report_fd = kInvalidFd; +} |