forked from OSchip/llvm-project
asan/tsan: add Printf/Report hook
The hook can be overriden in frontend to print to e.g. a file. llvm-svn: 177864
This commit is contained in:
parent
3ee88e8a77
commit
7886253fee
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue