diff options
author | Dmitry Vyukov <dvyukov@google.com> | 2013-03-25 12:58:09 +0000 |
---|---|---|
committer | Dmitry Vyukov <dvyukov@google.com> | 2013-03-25 12:58:09 +0000 |
commit | 13f62b2cdaa09376e917a1efd0b1dd3d23bbff8d (patch) | |
tree | fd56220a297dbd1aaf9740bc5edd2d3988e5720a /lib/sanitizer_common/sanitizer_printf.cc | |
parent | 39cbb56fb3ba2af53e537107862c51f1dd252150 (diff) |
asan/tsan: add Printf/Report hook
The hook can be overriden in frontend to print to e.g. a file.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177864 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_printf.cc')
-rw-r--r-- | lib/sanitizer_common/sanitizer_printf.cc | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/sanitizer_common/sanitizer_printf.cc b/lib/sanitizer_common/sanitizer_printf.cc index 4b5a8b4af..0b6c9c6b7 100644 --- a/lib/sanitizer_common/sanitizer_printf.cc +++ b/lib/sanitizer_common/sanitizer_printf.cc @@ -173,6 +173,21 @@ void SetPrintfAndReportCallback(void (*callback)(const char *)) { PrintfAndReportCallback = callback; } +// Can be overriden in frontend. +#ifndef SANITIZER_GO +SANITIZER_INTERFACE_ATTRIBUTE void WEAK OnPrint(const char *str) { + (void)str; +} +#endif + +static void CallPrintfAndReportCallback(const char *str) { +#ifndef SANITIZER_GO + OnPrint(str); +#endif + if (PrintfAndReportCallback) + PrintfAndReportCallback(str); +} + void Printf(const char *format, ...) { const int kLen = 16 * 1024; InternalScopedBuffer<char> buffer(kLen); @@ -182,8 +197,7 @@ void Printf(const char *format, ...) { va_end(args); RAW_CHECK_MSG(needed_length < kLen, "Buffer in Printf is too short!\n"); RawWrite(buffer.data()); - if (PrintfAndReportCallback) - PrintfAndReportCallback(buffer.data()); + CallPrintfAndReportCallback(buffer.data()); } // Writes at most "length" symbols to "buffer" (including trailing '\0'). @@ -238,8 +252,7 @@ void Report(const char *format, ...) { } } else { RawWrite(buffer); - if (PrintfAndReportCallback) - PrintfAndReportCallback(buffer); + CallPrintfAndReportCallback(buffer); // Don't do anything for the second time if the first iteration // succeeded. break; |