diff options
author | Sergey Matveev <earthdok@google.com> | 2013-09-03 13:31:03 +0000 |
---|---|---|
committer | Sergey Matveev <earthdok@google.com> | 2013-09-03 13:31:03 +0000 |
commit | b9d34443f25f0444427d3a1dd376a3a18a6cf1c7 (patch) | |
tree | 1996877989a65362bddcbf0abc646e5dbbaf7713 /compiler-rt | |
parent | 4fe4a999a4a7f35ebd44dd908b299a309baf0bd0 (diff) | |
download | bcm5719-llvm-b9d34443f25f0444427d3a1dd376a3a18a6cf1c7.tar.gz bcm5719-llvm-b9d34443f25f0444427d3a1dd376a3a18a6cf1c7.zip |
[lsan] Colorize LSan reports.
llvm-svn: 189804
Diffstat (limited to 'compiler-rt')
-rw-r--r-- | compiler-rt/lib/asan/asan_report.cc | 14 | ||||
-rw-r--r-- | compiler-rt/lib/lsan/lsan_common.cc | 15 | ||||
-rw-r--r-- | compiler-rt/lib/msan/msan_report.cc | 11 | ||||
-rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_common.h | 2 | ||||
-rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc | 14 |
5 files changed, 31 insertions, 25 deletions
diff --git a/compiler-rt/lib/asan/asan_report.cc b/compiler-rt/lib/asan/asan_report.cc index a80efffcd10..9c7501e7b35 100644 --- a/compiler-rt/lib/asan/asan_report.cc +++ b/compiler-rt/lib/asan/asan_report.cc @@ -44,20 +44,6 @@ void AppendToErrorMessageBuffer(const char *buffer) { } // ---------------------- Decorator ------------------------------ {{{1 -bool PrintsToTtyCached() { - // FIXME: Add proper Windows support to AnsiColorDecorator and re-enable color - // printing on Windows. - if (SANITIZER_WINDOWS) - return 0; - - static int cached = 0; - static bool prints_to_tty; - if (!cached) { // Ok wrt threads since we are printing only from one thread. - prints_to_tty = PrintsToTty(); - cached = 1; - } - return prints_to_tty; -} class Decorator: private __sanitizer::AnsiColorDecorator { public: Decorator() : __sanitizer::AnsiColorDecorator(PrintsToTtyCached()) { } diff --git a/compiler-rt/lib/lsan/lsan_common.cc b/compiler-rt/lib/lsan/lsan_common.cc index 8a05b0c822a..1d895a3b169 100644 --- a/compiler-rt/lib/lsan/lsan_common.cc +++ b/compiler-rt/lib/lsan/lsan_common.cc @@ -21,6 +21,7 @@ #include "sanitizer_common/sanitizer_stacktrace.h" #include "sanitizer_common/sanitizer_stoptheworld.h" #include "sanitizer_common/sanitizer_suppressions.h" +#include "sanitizer_common/sanitizer_report_decorator.h" #if CAN_SANITIZE_LEAKS namespace __lsan { @@ -96,6 +97,14 @@ void InitCommonLsan() { InitializePlatformSpecificModules(); } +class Decorator: private __sanitizer::AnsiColorDecorator { + public: + Decorator() : __sanitizer::AnsiColorDecorator(PrintsToTtyCached()) { } + const char *Error() { return Red(); } + const char *Leak() { return Blue(); } + const char *End() { return Default(); } +}; + static inline bool CanBeAHeapPointer(uptr p) { // Since our heap is located in mmap-ed memory, we can assume a sensible lower // bound on heap addresses. @@ -372,10 +381,13 @@ void DoLeakCheck() { } uptr have_unsuppressed = param.leak_report.ApplySuppressions(); if (have_unsuppressed) { + Decorator d; Printf("\n" "=================================================================" "\n"); + Printf("%s", d.Error()); Report("ERROR: LeakSanitizer: detected memory leaks\n"); + Printf("%s", d.End()); param.leak_report.PrintLargest(flags()->max_leaks); } if (have_unsuppressed || (flags()->verbosity >= 1)) { @@ -460,11 +472,14 @@ void LeakReport::PrintLargest(uptr num_leaks_to_print) { Printf("The %zu largest leak(s):\n", num_leaks_to_print); InternalSort(&leaks_, leaks_.size(), LeakComparator); uptr leaks_printed = 0; + Decorator d; for (uptr i = 0; i < leaks_.size(); i++) { if (leaks_[i].is_suppressed) continue; + Printf("%s", d.Leak()); Printf("%s leak of %zu byte(s) in %zu object(s) allocated from:\n", leaks_[i].is_directly_leaked ? "Direct" : "Indirect", leaks_[i].total_size, leaks_[i].hit_count); + Printf("%s", d.End()); PrintStackTraceById(leaks_[i].stack_trace_id); Printf("\n"); leaks_printed++; diff --git a/compiler-rt/lib/msan/msan_report.cc b/compiler-rt/lib/msan/msan_report.cc index d8a699696bb..b1cfe87b4cc 100644 --- a/compiler-rt/lib/msan/msan_report.cc +++ b/compiler-rt/lib/msan/msan_report.cc @@ -25,16 +25,6 @@ using namespace __sanitizer; namespace __msan { -static bool PrintsToTtyCached() { - static int cached = 0; - static bool prints_to_tty; - if (!cached) { // Ok wrt threads since we are printing only from one thread. - prints_to_tty = PrintsToTty(); - cached = 1; - } - return prints_to_tty; -} - class Decorator: private __sanitizer::AnsiColorDecorator { public: Decorator() : __sanitizer::AnsiColorDecorator(PrintsToTtyCached()) { } @@ -120,5 +110,4 @@ void ReportAtExitStatistics() { Printf("%s", d.End()); } - } // namespace __msan diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index ddbae5ccea6..7a96a481bc3 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -107,6 +107,8 @@ void SetLowLevelAllocateCallback(LowLevelAllocateCallback callback); // IO void RawWrite(const char *buffer); bool PrintsToTty(); +// Caching version of PrintsToTty(). Not thread-safe. +bool PrintsToTtyCached(); void Printf(const char *format, ...); void Report(const char *format, ...); void SetPrintfAndReportCallback(void (*callback)(const char *)); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc index c730ccfbd7b..f3430074eb0 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc @@ -20,4 +20,18 @@ bool PrintsToTty() { return internal_isatty(report_fd) != 0; } +bool PrintsToTtyCached() { + // FIXME: Add proper Windows support to AnsiColorDecorator and re-enable color + // printing on Windows. + if (SANITIZER_WINDOWS) + return 0; + + static int cached = 0; + static bool prints_to_tty; + if (!cached) { // Not thread-safe. + prints_to_tty = PrintsToTty(); + cached = 1; + } + return prints_to_tty; +} } // namespace __sanitizer |