[msan] add strip_path_prefix flag; print error summary; don't crash while printing...
authorKostya Serebryany <kcc@google.com>
Thu, 7 Feb 2013 08:04:56 +0000 (08:04 +0000)
committerKostya Serebryany <kcc@google.com>
Thu, 7 Feb 2013 08:04:56 +0000 (08:04 +0000)
llvm-svn: 174595

compiler-rt/lib/msan/msan.cc
compiler-rt/lib/msan/msan_flags.h
compiler-rt/lib/msan/msan_report.cc
compiler-rt/lib/sanitizer_common/sanitizer_common.cc
compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc

index b4c6f52..27ff269 100644 (file)
@@ -111,6 +111,7 @@ static void ParseFlagsFromString(Flags *f, const char *str) {
   ParseFlag(str, &f->num_callers, "num_callers");
   ParseFlag(str, &f->report_umrs, "report_umrs");
   ParseFlag(str, &f->verbosity, "verbosity");
+  ParseFlag(str, &f->strip_path_prefix, "strip_path_prefix");
 }
 
 static void InitializeFlags(Flags *f, const char *options) {
@@ -123,6 +124,7 @@ static void InitializeFlags(Flags *f, const char *options) {
   f->num_callers = 20;
   f->report_umrs = true;
   f->verbosity = 0;
+  f->strip_path_prefix = "";
 
   ParseFlagsFromString(f, options);
 }
index a85fc57..0c41c2e 100644 (file)
@@ -25,6 +25,7 @@ struct Flags {
   bool poison_stack_with_zeroes;  // default: false
   bool poison_in_malloc;  // default: true
   bool report_umrs;
+  const char *strip_path_prefix;
 };
 
 Flags *flags();
index 648cd81..804c8ae 100644 (file)
@@ -17,6 +17,7 @@
 #include "sanitizer_common/sanitizer_mutex.h"
 #include "sanitizer_common/sanitizer_report_decorator.h"
 #include "sanitizer_common/sanitizer_stackdepot.h"
+#include "sanitizer_common/sanitizer_symbolizer.h"
 
 using namespace __sanitizer;
 
@@ -63,10 +64,19 @@ static void DescribeOrigin(u32 origin) {
     const uptr *trace = StackDepotGet(origin, &size);
     Printf("  %sUninitialised value was created by a heap allocation%s\n",
            d.Origin(), d.End());
-    StackTrace::PrintStack(trace, size, true, "", 0);
+    StackTrace::PrintStack(trace, size, true, flags()->strip_path_prefix, 0);
   }
 }
 
+static void ReportSummary(const char *error_type, StackTrace *stack) {
+  if (!stack->size || !IsSymbolizerAvailable()) return;
+  AddressInfo ai;
+  SymbolizeCode(stack->trace[0], &ai, 1);
+  ReportErrorSummary(error_type,
+                     StripPathPrefix(ai.file, flags()->strip_path_prefix),
+                     ai.line, ai.function);
+}
+
 void ReportUMR(StackTrace *stack, u32 origin) {
   if (!__msan::flags()->report_umrs) return;
 
@@ -76,17 +86,20 @@ void ReportUMR(StackTrace *stack, u32 origin) {
   Printf("%s", d.Warning());
   Report(" WARNING: Use of uninitialized value\n");
   Printf("%s", d.End());
-  StackTrace::PrintStack(stack->trace, stack->size, true, "", 0);
+  StackTrace::PrintStack(stack->trace, stack->size, true,
+                         flags()->strip_path_prefix, 0);
   if (origin) {
     DescribeOrigin(origin);
   }
+  ReportSummary("use-of-uninitialized-value", stack);
 }
 
 void ReportExpectedUMRNotFound(StackTrace *stack) {
   GenericScopedLock<StaticSpinMutex> lock(&report_mu);
 
   Printf(" WARNING: Expected use of uninitialized value not found\n");
-  StackTrace::PrintStack(stack->trace, stack->size, true, "", 0);
+  StackTrace::PrintStack(stack->trace, stack->size, true,
+                         flags()->strip_path_prefix, 0);
 }
 
 void ReportAtExitStatistics() {
index da286c6..8f95d2b 100644 (file)
@@ -198,7 +198,7 @@ void ReportErrorSummary(const char *error_type, const char *file,
   InternalScopedBuffer<char> buff(kMaxSize);
   internal_snprintf(buff.data(), kMaxSize, "%s: %s %s:%d %s",
                     SanitizerToolName, error_type,
-                    file, line, function);
+                    file ? file : "??", line, function ? function : "??");
   __sanitizer_report_error_summary(buff.data());
 }
 
index 59b42ec..639a69c 100644 (file)
@@ -19,6 +19,7 @@
 namespace __sanitizer {
 const char *StripPathPrefix(const char *filepath,
                             const char *strip_file_prefix) {
+  if (filepath == 0) return 0;
   if (filepath == internal_strstr(filepath, strip_file_prefix))
     return filepath + internal_strlen(strip_file_prefix);
   return filepath;