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"
|
2013-05-29 17:15:39 +08:00
|
|
|
#include "sanitizer_common/sanitizer_allocator_internal.h"
|
2012-12-26 17:32:05 +08:00
|
|
|
#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
|
|
|
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(); }
|
|
|
|
};
|
|
|
|
|
2012-12-26 17:32:05 +08:00
|
|
|
static void DescribeOrigin(u32 origin) {
|
2012-12-26 18:16:45 +08:00
|
|
|
Decorator d;
|
2013-12-05 20:04:51 +08:00
|
|
|
VPrintf(1, " raw origin id: %d\n", origin);
|
2013-09-13 20:49:13 +08:00
|
|
|
uptr pc;
|
|
|
|
if (const char *so = GetOriginDescrIfStack(origin, &pc)) {
|
2012-12-26 17:32:05 +08:00
|
|
|
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-09-10 22:36:16 +08:00
|
|
|
d.Origin(), d.Name(), s, d.Origin(), d.Name(),
|
2013-10-26 07:03:29 +08:00
|
|
|
Symbolizer::Get()->Demangle(sep + 1), d.Origin(), d.End());
|
2012-12-26 17:32:05 +08:00
|
|
|
InternalFree(s);
|
2013-09-13 20:49:13 +08:00
|
|
|
|
|
|
|
if (pc) {
|
|
|
|
// For some reason function address in LLVM IR is 1 less then the address
|
|
|
|
// of the first instruction.
|
|
|
|
pc += 1;
|
2013-11-01 08:19:46 +08:00
|
|
|
StackTrace::PrintStack(&pc, 1);
|
2013-09-13 20:49:13 +08:00
|
|
|
}
|
2012-12-26 17:32:05 +08:00
|
|
|
} 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-11-01 08:19:46 +08:00
|
|
|
StackTrace::PrintStack(trace, size);
|
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());
|
2013-05-28 22:27:30 +08:00
|
|
|
Report(" WARNING: MemorySanitizer: use-of-uninitialized-value\n");
|
2012-12-26 18:16:45 +08:00
|
|
|
Printf("%s", d.End());
|
2013-12-19 19:25:05 +08:00
|
|
|
stack->Print();
|
2012-12-26 17:32:05 +08:00
|
|
|
if (origin) {
|
|
|
|
DescribeOrigin(origin);
|
|
|
|
}
|
2013-11-02 01:02:14 +08:00
|
|
|
ReportErrorSummary("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-12-19 19:25:05 +08:00
|
|
|
stack->Print();
|
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
|