2012-12-27 22:09:19 +08:00
|
|
|
//===-- msan_report.cc ----------------------------------------------------===//
|
2012-12-26 17:32:05 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of MemorySanitizer.
|
|
|
|
//
|
|
|
|
// Error reporting.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "msan.h"
|
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
2013-05-06 21:15:14 +08:00
|
|
|
#include "sanitizer_common/sanitizer_flags.h"
|
2012-12-26 17:32:05 +08:00
|
|
|
#include "sanitizer_common/sanitizer_mutex.h"
|
2012-12-26 18:16:45 +08:00
|
|
|
#include "sanitizer_common/sanitizer_report_decorator.h"
|
2012-12-26 17:32:05 +08:00
|
|
|
#include "sanitizer_common/sanitizer_stackdepot.h"
|
2013-02-07 16:04:56 +08:00
|
|
|
#include "sanitizer_common/sanitizer_symbolizer.h"
|
2012-12-26 17:32:05 +08:00
|
|
|
|
|
|
|
using namespace __sanitizer;
|
|
|
|
|
|
|
|
namespace __msan {
|
|
|
|
|
2012-12-26 18:16:45 +08:00
|
|
|
static bool PrintsToTtyCached() {
|
|
|
|
static int cached = 0;
|
|
|
|
static bool prints_to_tty;
|
|
|
|
if (!cached) { // Ok wrt threads since we are printing only from one thread.
|
|
|
|
prints_to_tty = PrintsToTty();
|
|
|
|
cached = 1;
|
|
|
|
}
|
|
|
|
return prints_to_tty;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Decorator: private __sanitizer::AnsiColorDecorator {
|
|
|
|
public:
|
|
|
|
Decorator() : __sanitizer::AnsiColorDecorator(PrintsToTtyCached()) { }
|
|
|
|
const char *Warning() { return Red(); }
|
|
|
|
const char *Origin() { return Magenta(); }
|
|
|
|
const char *Name() { return Green(); }
|
|
|
|
const char *End() { return Default(); }
|
|
|
|
};
|
|
|
|
|
2013-02-13 15:19:47 +08:00
|
|
|
static void PrintStack(const uptr *trace, uptr size) {
|
|
|
|
SymbolizerScope sym_scope;
|
2013-05-06 21:15:14 +08:00
|
|
|
StackTrace::PrintStack(trace, size, true,
|
|
|
|
common_flags()->strip_path_prefix, 0);
|
2013-02-13 15:19:47 +08:00
|
|
|
}
|
|
|
|
|
2012-12-26 17:32:05 +08:00
|
|
|
static void DescribeOrigin(u32 origin) {
|
2012-12-26 18:16:45 +08:00
|
|
|
Decorator d;
|
2012-12-26 17:32:05 +08:00
|
|
|
if (flags()->verbosity)
|
|
|
|
Printf(" raw origin id: %d\n", origin);
|
|
|
|
if (const char *so = __msan_get_origin_descr_if_stack(origin)) {
|
|
|
|
char* s = internal_strdup(so);
|
|
|
|
char* sep = internal_strchr(s, '@');
|
|
|
|
CHECK(sep);
|
|
|
|
*sep = '\0';
|
2012-12-26 18:16:45 +08:00
|
|
|
Printf("%s", d.Origin());
|
2013-02-11 19:34:26 +08:00
|
|
|
Printf(" %sUninitialized value was created by an allocation of '%s%s%s'"
|
2012-12-26 18:16:45 +08:00
|
|
|
" in the stack frame of function '%s%s%s'%s\n",
|
2013-04-12 15:27:30 +08:00
|
|
|
d.Origin(), d.Name(), s, d.Origin(), d.Name(), Demangle(sep + 1),
|
2012-12-26 18:16:45 +08:00
|
|
|
d.Origin(), d.End());
|
2012-12-26 17:32:05 +08:00
|
|
|
InternalFree(s);
|
|
|
|
} else {
|
|
|
|
uptr size = 0;
|
|
|
|
const uptr *trace = StackDepotGet(origin, &size);
|
2013-02-11 19:34:26 +08:00
|
|
|
Printf(" %sUninitialized value was created by a heap allocation%s\n",
|
2012-12-26 18:16:45 +08:00
|
|
|
d.Origin(), d.End());
|
2013-02-13 15:19:47 +08:00
|
|
|
PrintStack(trace, size);
|
2012-12-26 17:32:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-07 16:04:56 +08:00
|
|
|
static void ReportSummary(const char *error_type, StackTrace *stack) {
|
|
|
|
if (!stack->size || !IsSymbolizerAvailable()) return;
|
|
|
|
AddressInfo ai;
|
2013-02-12 18:46:39 +08:00
|
|
|
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
|
2013-02-13 15:19:47 +08:00
|
|
|
{
|
|
|
|
SymbolizerScope sym_scope;
|
|
|
|
SymbolizeCode(pc, &ai, 1);
|
|
|
|
}
|
2013-02-07 16:04:56 +08:00
|
|
|
ReportErrorSummary(error_type,
|
2013-05-06 21:15:14 +08:00
|
|
|
StripPathPrefix(ai.file,
|
|
|
|
common_flags()->strip_path_prefix),
|
2013-02-07 16:04:56 +08:00
|
|
|
ai.line, ai.function);
|
|
|
|
}
|
|
|
|
|
2012-12-26 17:32:05 +08:00
|
|
|
void ReportUMR(StackTrace *stack, u32 origin) {
|
|
|
|
if (!__msan::flags()->report_umrs) return;
|
|
|
|
|
2013-04-05 15:30:29 +08:00
|
|
|
SpinMutexLock l(&CommonSanitizerReportMutex);
|
2012-12-26 17:32:05 +08:00
|
|
|
|
2012-12-26 18:16:45 +08:00
|
|
|
Decorator d;
|
|
|
|
Printf("%s", d.Warning());
|
2012-12-26 17:32:05 +08:00
|
|
|
Report(" WARNING: Use of uninitialized value\n");
|
2012-12-26 18:16:45 +08:00
|
|
|
Printf("%s", d.End());
|
2013-02-13 15:19:47 +08:00
|
|
|
PrintStack(stack->trace, stack->size);
|
2012-12-26 17:32:05 +08:00
|
|
|
if (origin) {
|
|
|
|
DescribeOrigin(origin);
|
|
|
|
}
|
2013-02-07 16:04:56 +08:00
|
|
|
ReportSummary("use-of-uninitialized-value", stack);
|
2012-12-26 17:32:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReportExpectedUMRNotFound(StackTrace *stack) {
|
2013-04-05 15:30:29 +08:00
|
|
|
SpinMutexLock l(&CommonSanitizerReportMutex);
|
2012-12-26 17:32:05 +08:00
|
|
|
|
|
|
|
Printf(" WARNING: Expected use of uninitialized value not found\n");
|
2013-02-13 15:19:47 +08:00
|
|
|
PrintStack(stack->trace, stack->size);
|
2012-12-26 17:32:05 +08:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:17:55 +08:00
|
|
|
void ReportAtExitStatistics() {
|
2013-04-05 15:30:29 +08:00
|
|
|
SpinMutexLock l(&CommonSanitizerReportMutex);
|
|
|
|
|
2013-01-10 19:17:55 +08:00
|
|
|
Decorator d;
|
|
|
|
Printf("%s", d.Warning());
|
|
|
|
Printf("MemorySanitizer: %d warnings reported.\n", msan_report_count);
|
|
|
|
Printf("%s", d.End());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-30 15:45:58 +08:00
|
|
|
} // namespace __msan
|