[compiler-rt] r202249 - [sanitizer] Add a flag to enable/disable report colorization.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Wed Feb 26 01:07:00 PST 2014
Author: eugenis
Date: Wed Feb 26 03:06:59 2014
New Revision: 202249
URL: http://llvm.org/viewvc/llvm-project?rev=202249&view=rev
Log:
[sanitizer] Add a flag to enable/disable report colorization.
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_report_decorator.h
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=202249&r1=202248&r2=202249&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Wed Feb 26 03:06:59 2014
@@ -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 *));
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc?rev=202249&r1=202248&r2=202249&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc Wed Feb 26 03:06:59 2014
@@ -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
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc?rev=202249&r1=202248&r2=202249&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc Wed Feb 26 03:06:59 2014
@@ -42,6 +42,7 @@ void SetCommonFlagsDefaults(CommonFlags
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(CommonFl
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)
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h?rev=202249&r1=202248&r2=202249&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h Wed Feb 26 03:06:59 2014
@@ -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() {
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_report_decorator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_report_decorator.h?rev=202249&r1=202248&r2=202249&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_report_decorator.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_report_decorator.h Wed Feb 26 03:06:59 2014
@@ -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(); }
};
More information about the llvm-commits
mailing list