summaryrefslogtreecommitdiff
path: root/lib/msan/msan_report.cc
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2014-03-18 13:45:19 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2014-03-18 13:45:19 +0000
commit4786ed291f735699c2150f3dd4dffa62ddb89f28 (patch)
treee91de16416cd20dd6bdbcf370772c52f6bc914af /lib/msan/msan_report.cc
parentb4a5f1c12ad45b35ebbceffc00bbc4ee788af90f (diff)
[msan] Origin tracking with history, compiler-rt part.
Compiler-rt part of MSan implementation of advanced origin tracking, when we record not only creation point, but all locations where an uninitialized value was stored to memory, too. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204152 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/msan/msan_report.cc')
-rw-r--r--lib/msan/msan_report.cc79
1 files changed, 53 insertions, 26 deletions
diff --git a/lib/msan/msan_report.cc b/lib/msan/msan_report.cc
index 598a13e8f..7e709f879 100644
--- a/lib/msan/msan_report.cc
+++ b/lib/msan/msan_report.cc
@@ -34,34 +34,53 @@ class Decorator: private __sanitizer::AnsiColorDecorator {
const char *End() { return Default(); }
};
-static void DescribeOrigin(u32 origin) {
+static void DescribeStackOrigin(const char *so, uptr pc) {
Decorator d;
+ char *s = internal_strdup(so);
+ char *sep = internal_strchr(s, '@');
+ CHECK(sep);
+ *sep = '\0';
+ Printf("%s", d.Origin());
+ Printf(
+ " %sUninitialized value was created by an allocation of '%s%s%s'"
+ " in the stack frame of function '%s%s%s'%s\n",
+ d.Origin(), d.Name(), s, d.Origin(), d.Name(),
+ Symbolizer::Get()->Demangle(sep + 1), d.Origin(), d.End());
+ InternalFree(s);
+
+ if (pc) {
+ // For some reason function address in LLVM IR is 1 less then the address
+ // of the first instruction.
+ pc += 1;
+ StackTrace::PrintStack(&pc, 1);
+ }
+}
+
+static void DescribeOrigin(u32 origin) {
VPrintf(1, " raw origin id: %d\n", origin);
uptr pc;
- if (const char *so = GetOriginDescrIfStack(origin, &pc)) {
- char* s = internal_strdup(so);
- char* sep = internal_strchr(s, '@');
- CHECK(sep);
- *sep = '\0';
- Printf("%s", d.Origin());
- Printf(" %sUninitialized value was created by an allocation of '%s%s%s'"
- " in the stack frame of function '%s%s%s'%s\n",
- d.Origin(), d.Name(), s, d.Origin(), d.Name(),
- Symbolizer::Get()->Demangle(sep + 1), d.Origin(), d.End());
- InternalFree(s);
-
- if (pc) {
- // For some reason function address in LLVM IR is 1 less then the address
- // of the first instruction.
- pc += 1;
- StackTrace::PrintStack(&pc, 1);
+ while (true) {
+ if (const char *so = GetOriginDescrIfStack(origin, &pc)) {
+ DescribeStackOrigin(so, pc);
+ break;
}
- } else {
+ Decorator d;
uptr size = 0;
const uptr *trace = StackDepotGet(origin, &size);
- Printf(" %sUninitialized value was created by a heap allocation%s\n",
- d.Origin(), d.End());
- StackTrace::PrintStack(trace, size);
+ CHECK_GT(size, 0);
+ if (TRACE_IS_CHAINED(trace[size - 1])) {
+ // Linked origin.
+ // FIXME: copied? modified? passed through? observed?
+ Printf(" %sUninitialized value was stored to memory at%s\n", d.Origin(),
+ d.End());
+ StackTrace::PrintStack(trace, size - 1);
+ origin = TRACE_TO_CHAINED_ID(trace[size - 1]);
+ } else {
+ Printf(" %sUninitialized value was created by a heap allocation%s\n",
+ d.Origin(), d.End());
+ StackTrace::PrintStack(trace, size);
+ break;
+ }
}
}
@@ -91,10 +110,18 @@ void ReportExpectedUMRNotFound(StackTrace *stack) {
void ReportAtExitStatistics() {
SpinMutexLock l(&CommonSanitizerReportMutex);
- Decorator d;
- Printf("%s", d.Warning());
- Printf("MemorySanitizer: %d warnings reported.\n", msan_report_count);
- Printf("%s", d.End());
+ if (msan_report_count > 0) {
+ Decorator d;
+ Printf("%s", d.Warning());
+ Printf("MemorySanitizer: %d warnings reported.\n", msan_report_count);
+ Printf("%s", d.End());
+ }
+
+ StackDepotStats *stack_depot_stats = StackDepotGetStats();
+ // FIXME: we want this at normal exit, too!
+ // FIXME: but only with verbosity=1 or something
+ Printf("Unique heap origins: %zu\n", stack_depot_stats->n_uniq_ids);
+ Printf("Stack depot mapped bytes: %zu\n", stack_depot_stats->mapped);
}
} // namespace __msan