Evgeniy Stepanov | 367dc64 | 2012-12-26 09:32:05 +0000 | [diff] [blame^] | 1 | //===-- msan_report.cc -----------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file is a part of MemorySanitizer. |
| 11 | // |
| 12 | // Error reporting. |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "msan.h" |
| 16 | #include "sanitizer_common/sanitizer_common.h" |
| 17 | #include "sanitizer_common/sanitizer_mutex.h" |
| 18 | #include "sanitizer_common/sanitizer_stackdepot.h" |
| 19 | |
| 20 | using namespace __sanitizer; |
| 21 | |
| 22 | static StaticSpinMutex report_mu; |
| 23 | |
| 24 | namespace __msan { |
| 25 | |
| 26 | static void DescribeOrigin(u32 origin) { |
| 27 | if (flags()->verbosity) |
| 28 | Printf(" raw origin id: %d\n", origin); |
| 29 | if (const char *so = __msan_get_origin_descr_if_stack(origin)) { |
| 30 | char* s = internal_strdup(so); |
| 31 | char* sep = internal_strchr(s, '@'); |
| 32 | CHECK(sep); |
| 33 | *sep = '\0'; |
| 34 | Printf(" Uninitialised value was created by an allocation of '%s'" |
| 35 | " in the stack frame of function '%s'\n", s, sep + 1); |
| 36 | InternalFree(s); |
| 37 | } else { |
| 38 | uptr size = 0; |
| 39 | const uptr *trace = StackDepotGet(origin, &size); |
| 40 | Printf(" Uninitialised value was created by a heap allocation\n"); |
| 41 | StackTrace::PrintStack(trace, size, true, "", 0); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | void ReportUMR(StackTrace *stack, u32 origin) { |
| 46 | if (!__msan::flags()->report_umrs) return; |
| 47 | |
| 48 | GenericScopedLock<StaticSpinMutex> lock(&report_mu); |
| 49 | |
| 50 | Report(" WARNING: Use of uninitialized value\n"); |
| 51 | StackTrace::PrintStack(stack->trace, stack->size, true, "", 0); |
| 52 | if (origin) { |
| 53 | DescribeOrigin(origin); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | void ReportExpectedUMRNotFound(StackTrace *stack) { |
| 58 | GenericScopedLock<StaticSpinMutex> lock(&report_mu); |
| 59 | |
| 60 | Printf(" WARNING: Expected use of uninitialized value not found\n"); |
| 61 | StackTrace::PrintStack(stack->trace, stack->size, true, "", 0); |
| 62 | } |
| 63 | |
| 64 | } // namespace msan |