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 | e23add20aee3c4973be19f76b2681007f25babfa (patch) | |
| tree | 751464286b5903a7296292a7d7d9abd80616960c /compiler-rt/lib | |
| parent | 2e09d93f74d8af94c1f345dbcac976a0d8c8c527 (diff) | |
| download | bcm5719-llvm-e23add20aee3c4973be19f76b2681007f25babfa.tar.gz bcm5719-llvm-e23add20aee3c4973be19f76b2681007f25babfa.zip | |
[sanitizer] Add a flag to enable/disable report colorization.
llvm-svn: 202249
Diffstat (limited to 'compiler-rt/lib')
5 files changed, 15 insertions, 1 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 89fba920cc1..1b87d54aa75 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/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/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc index f3430074eb0..b7041447956 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc +++ b/compiler-rt/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/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc index ad13a029e08..2f52fa72ad5 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc +++ b/compiler-rt/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/compiler-rt/lib/sanitizer_common/sanitizer_flags.h b/compiler-rt/lib/sanitizer_common/sanitizer_flags.h index 9632ca5f926..4d2d684b818 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.h +++ b/compiler-rt/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/compiler-rt/lib/sanitizer_common/sanitizer_report_decorator.h b/compiler-rt/lib/sanitizer_common/sanitizer_report_decorator.h index 2b6365fd19e..6e5b0ed32b5 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_report_decorator.h +++ b/compiler-rt/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(); } }; |

