summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Matveev <earthdok@google.com>2013-09-03 13:31:03 +0000
committerSergey Matveev <earthdok@google.com>2013-09-03 13:31:03 +0000
commit650c7d44b659ddfb4af471dc2ad79a727b7de939 (patch)
treedb9f0ace7d8f6d95b8f054f97c7cdc40ebe2d9a6
parent68c016aea0b61f649b9d9ba65c7d7217e0c0f6cb (diff)
[lsan] Colorize LSan reports.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@189804 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/asan/asan_report.cc14
-rw-r--r--lib/lsan/lsan_common.cc15
-rw-r--r--lib/msan/msan_report.cc11
-rw-r--r--lib/sanitizer_common/sanitizer_common.h2
-rw-r--r--lib/sanitizer_common/sanitizer_common_libcdep.cc14
5 files changed, 31 insertions, 25 deletions
diff --git a/lib/asan/asan_report.cc b/lib/asan/asan_report.cc
index a80efffcd..9c7501e7b 100644
--- a/lib/asan/asan_report.cc
+++ b/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/lib/lsan/lsan_common.cc b/lib/lsan/lsan_common.cc
index 8a05b0c82..1d895a3b1 100644
--- a/lib/lsan/lsan_common.cc
+++ b/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/lib/msan/msan_report.cc b/lib/msan/msan_report.cc
index d8a699696..b1cfe87b4 100644
--- a/lib/msan/msan_report.cc
+++ b/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/lib/sanitizer_common/sanitizer_common.h b/lib/sanitizer_common/sanitizer_common.h
index ddbae5cce..7a96a481b 100644
--- a/lib/sanitizer_common/sanitizer_common.h
+++ b/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/lib/sanitizer_common/sanitizer_common_libcdep.cc b/lib/sanitizer_common/sanitizer_common_libcdep.cc
index c730ccfbd..f3430074e 100644
--- a/lib/sanitizer_common/sanitizer_common_libcdep.cc
+++ b/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