[sanitizer] Add a flag to enable/disable report colorization.

llvm-svn: 202249
This commit is contained in:
Evgeniy Stepanov 2014-02-26 09:06:59 +00:00
parent 2e09d93f74
commit e23add20ae
5 changed files with 15 additions and 1 deletions

View File

@ -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 *));

View File

@ -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

View File

@ -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)

View File

@ -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() {

View File

@ -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(); }
};