ParseFlag(str, &f->report_umrs, "report_umrs", "");
ParseFlag(str, &f->wrap_signals, "wrap_signals", "");
+ ParseFlag(str, &f->print_stats, "print_stats", "");
// keep_going is an old name for halt_on_error,
// and it has inverse meaning.
f->origin_history_per_stack_limit = 20000;
f->report_umrs = true;
f->wrap_signals = true;
+ f->print_stats = false;
f->halt_on_error = !&__msan_keep_going;
// Override from user-specified string.
(void)sp;
PrintWarning(pc, bp);
if (__msan::flags()->halt_on_error) {
+ if (__msan::flags()->print_stats)
+ ReportStats();
Printf("Exiting\n");
Die();
}
GET_CALLER_PC_BP_SP;
(void)sp;
PrintWarning(pc, bp);
+ if (__msan::flags()->print_stats)
+ ReportStats();
Printf("Exiting\n");
Die();
}
void ReportUMR(StackTrace *stack, u32 origin);
void ReportExpectedUMRNotFound(StackTrace *stack);
+void ReportStats();
void ReportAtExitStatistics();
void DescribeMemoryRange(const void *x, uptr size);
void ReportUMRInsideAddressRange(const char *what, const void *start, uptr size,
bool poison_in_free; // default: true
bool report_umrs;
bool wrap_signals;
+ bool print_stats;
bool halt_on_error;
};
static void MsanAtExit(void) {
if (msan_report_count > 0) {
ReportAtExitStatistics();
+ if (flags()->print_stats)
+ ReportStats();
if (flags()->exit_code)
_exit(flags()->exit_code);
}
stack->Print();
}
+void ReportStats() {
+ SpinMutexLock l(&CommonSanitizerReportMutex);
+
+ if (__msan_get_track_origins() > 0) {
+ 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 allocated bytes: %zu\n", stack_depot_stats->allocated);
+
+ StackDepotStats *chained_origin_depot_stats = ChainedOriginDepotGetStats();
+ Printf("Unique origin histories: %zu\n",
+ chained_origin_depot_stats->n_uniq_ids);
+ Printf("History depot allocated bytes: %zu\n",
+ chained_origin_depot_stats->allocated);
+ }
+}
+
void ReportAtExitStatistics() {
SpinMutexLock l(&CommonSanitizerReportMutex);
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 allocated bytes: %zu\n", stack_depot_stats->allocated);
-
- StackDepotStats *chained_origin_depot_stats = ChainedOriginDepotGetStats();
- Printf("Unique origin histories: %zu\n",
- chained_origin_depot_stats->n_uniq_ids);
- Printf("History depot allocated bytes: %zu\n",
- chained_origin_depot_stats->allocated);
}
class OriginSet {
--- /dev/null
+// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -m64 -g %s -o %t
+// RUN: %run %t 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NOSTATS %s
+// RUN: MSAN_OPTIONS=print_stats=1 %run %t 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NOSTATS %s
+
+// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -m64 -g -DPOSITIVE=1 %s -o %t
+// RUN: not %run %t 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NOSTATS %s
+// RUN: MSAN_OPTIONS=print_stats=1 not %run %t 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-STATS %s
+
+// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -m64 -g -DPOSITIVE=1 -mllvm -msan-keep-going=1 %s -o %t
+// RUN: not %run %t 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NOSTATS --check-prefix=CHECK-KEEPGOING %s
+// RUN: MSAN_OPTIONS=print_stats=1 not %run %t 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-STATS --check-prefix=CHECK-KEEPGOING %s
+
+#include <stdio.h>
+int main(int argc, char **argv) {
+ int x;
+ int *volatile p = &x;
+ fprintf(stderr, "TEST\n");
+#ifdef POSITIVE
+ return *p;
+#else
+ return 0;
+#endif
+}
+
+// CHECK: TEST
+
+// CHECK-KEEPGOING: MemorySanitizer: 1 warnings reported.
+
+// CHECK-STATS: Unique heap origins:
+// CHECK-STATS: Stack depot allocated bytes:
+// CHECK-STATS: Unique origin histories:
+// CHECK-STATS: History depot allocated bytes:
+
+// CHECK-NOSTATS-NOT: Unique heap origins:
+// CHECK-NOSTATS-NOT: Stack depot allocated bytes:
+// CHECK-NOSTATS-NOT: Unique origin histories:
+// CHECK-NOSTATS-NOT: History depot allocated bytes: