diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-02-26 09:06:59 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-02-26 09:06:59 +0000 |
commit | 882ed39389aa967c8a94ecb608b369a7de6ba73f (patch) | |
tree | d99c354b2fa33144c082c7da5141e459f04dc632 | |
parent | 41ee246df392e0bb29aa62eeabca2193b83b31c6 (diff) |
[sanitizer] Add a flag to enable/disable report colorization.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202249 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/sanitizer_common/sanitizer_common.h | 1 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_common_libcdep.cc | 7 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_flags.cc | 2 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_flags.h | 2 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_report_decorator.h | 4 |
5 files changed, 15 insertions, 1 deletions
diff --git a/lib/sanitizer_common/sanitizer_common.h b/lib/sanitizer_common/sanitizer_common.h index 89fba920c..1b87d54aa 100644 --- a/lib/sanitizer_common/sanitizer_common.h +++ b/lib/sanitizer_common/sanitizer_common.h @@ -124,6 +124,7 @@ void RawWrite(const char *buffer); bool PrintsToTty(); // Caching version of PrintsToTty(). Not thread-safe. bool PrintsToTtyCached(); +bool ColorizeReports(); 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 f3430074e..b70414479 100644 --- a/lib/sanitizer_common/sanitizer_common_libcdep.cc +++ b/lib/sanitizer_common/sanitizer_common_libcdep.cc @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "sanitizer_common.h" +#include "sanitizer_flags.h" namespace __sanitizer { @@ -34,4 +35,10 @@ bool PrintsToTtyCached() { } return prints_to_tty; } + +bool ColorizeReports() { + const char *flag = common_flags()->color; + return internal_strcmp(flag, "always") == 0 || + (internal_strcmp(flag, "auto") == 0 && PrintsToTtyCached()); +} } // namespace __sanitizer diff --git a/lib/sanitizer_common/sanitizer_flags.cc b/lib/sanitizer_common/sanitizer_flags.cc index ad13a029e..2f52fa72a 100644 --- a/lib/sanitizer_common/sanitizer_flags.cc +++ b/lib/sanitizer_common/sanitizer_flags.cc @@ -42,6 +42,7 @@ void SetCommonFlagsDefaults(CommonFlags *f) { f->use_sigaltstack = false; f->detect_deadlocks = false; f->clear_shadow_mmap_threshold = 64 * 1024; + f->color = "auto"; } void ParseCommonFlagsFromString(CommonFlags *f, const char *str) { @@ -66,6 +67,7 @@ void ParseCommonFlagsFromString(CommonFlags *f, const char *str) { ParseFlag(str, &f->detect_deadlocks, "detect_deadlocks"); ParseFlag(str, &f->clear_shadow_mmap_threshold, "clear_shadow_mmap_threshold"); + ParseFlag(str, &f->color, "color"); // Do a sanity check for certain flags. if (f->malloc_context_size < 1) diff --git a/lib/sanitizer_common/sanitizer_flags.h b/lib/sanitizer_common/sanitizer_flags.h index 9632ca5f9..4d2d684b8 100644 --- a/lib/sanitizer_common/sanitizer_flags.h +++ b/lib/sanitizer_common/sanitizer_flags.h @@ -76,6 +76,8 @@ struct CommonFlags { // Large shadow regions are zero-filled using mmap(NORESERVE) instead of // memset. This is the threshold size in bytes. uptr clear_shadow_mmap_threshold; + // Colorize reports: (always|never|auto). + const char *color; }; inline CommonFlags *common_flags() { diff --git a/lib/sanitizer_common/sanitizer_report_decorator.h b/lib/sanitizer_common/sanitizer_report_decorator.h index 2b6365fd1..6e5b0ed32 100644 --- a/lib/sanitizer_common/sanitizer_report_decorator.h +++ b/lib/sanitizer_common/sanitizer_report_decorator.h @@ -17,6 +17,8 @@ #ifndef SANITIZER_REPORT_DECORATOR_H #define SANITIZER_REPORT_DECORATOR_H +#include "sanitizer_common.h" + namespace __sanitizer { class AnsiColorDecorator { // FIXME: This is not portable. It assumes the special strings are printed to @@ -40,7 +42,7 @@ class AnsiColorDecorator { class SanitizerCommonDecorator: protected AnsiColorDecorator { public: SanitizerCommonDecorator() - : __sanitizer::AnsiColorDecorator(PrintsToTtyCached()) { } + : __sanitizer::AnsiColorDecorator(ColorizeReports()) { } const char *Warning() { return Red(); } const char *EndWarning() { return Default(); } }; |