From db010dae23962ab6089ad1e97af176b7215cb35c Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Wed, 26 Dec 2012 09:32:05 +0000 Subject: [msan] Refactor report printing. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@171105 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/msan/msan_report.cc | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 lib/msan/msan_report.cc (limited to 'lib/msan/msan_report.cc') diff --git a/lib/msan/msan_report.cc b/lib/msan/msan_report.cc new file mode 100644 index 000000000..a1a1bee63 --- /dev/null +++ b/lib/msan/msan_report.cc @@ -0,0 +1,64 @@ +//===-- msan_report.cc -----------------------------------------------------===// +// +// 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" +#include "sanitizer_common/sanitizer_mutex.h" +#include "sanitizer_common/sanitizer_stackdepot.h" + +using namespace __sanitizer; + +static StaticSpinMutex report_mu; + +namespace __msan { + +static void DescribeOrigin(u32 origin) { + 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'; + Printf(" Uninitialised value was created by an allocation of '%s'" + " in the stack frame of function '%s'\n", s, sep + 1); + InternalFree(s); + } else { + uptr size = 0; + const uptr *trace = StackDepotGet(origin, &size); + Printf(" Uninitialised value was created by a heap allocation\n"); + StackTrace::PrintStack(trace, size, true, "", 0); + } +} + +void ReportUMR(StackTrace *stack, u32 origin) { + if (!__msan::flags()->report_umrs) return; + + GenericScopedLock lock(&report_mu); + + Report(" WARNING: Use of uninitialized value\n"); + StackTrace::PrintStack(stack->trace, stack->size, true, "", 0); + if (origin) { + DescribeOrigin(origin); + } +} + +void ReportExpectedUMRNotFound(StackTrace *stack) { + GenericScopedLock lock(&report_mu); + + Printf(" WARNING: Expected use of uninitialized value not found\n"); + StackTrace::PrintStack(stack->trace, stack->size, true, "", 0); +} + +} // namespace msan -- cgit v1.2.3