[Sanitizer] Unify summary reporting across all sanitizers.

This change unifies the summary printing across sanitizers:
now each tool uses specific version of ReportErrorSummary() method,
which deals with symbolization of the top frame and formatting a
summary message. This change modifies the summary line for ASan+LSan mode:
now the summary mentions "AddressSanitizer" instead of "LeakSanitizer".

llvm-svn: 193864
This commit is contained in:
Alexey Samsonov 2013-11-01 17:02:14 +00:00
parent 170d70be68
commit 5dc6cff06a
27 changed files with 69 additions and 66 deletions

View File

@ -549,17 +549,6 @@ class ScopedInErrorReport {
}
};
static void ReportSummary(const char *error_type, StackTrace *stack) {
AddressInfo ai;
if (Symbolizer::Get()->IsAvailable()) {
// Currently, we include the first stack frame into the report summary.
// Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc).
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
Symbolizer::Get()->SymbolizeCode(pc, &ai, 1);
}
ReportErrorSummary(error_type, ai.file, ai.line, ai.function);
}
void ReportSIGSEGV(uptr pc, uptr sp, uptr bp, uptr addr) {
ScopedInErrorReport in_report;
Decorator d;
@ -572,7 +561,7 @@ void ReportSIGSEGV(uptr pc, uptr sp, uptr bp, uptr addr) {
GET_STACK_TRACE_FATAL(pc, bp);
PrintStack(&stack);
Printf("AddressSanitizer can not provide additional info.\n");
ReportSummary("SEGV", &stack);
ReportErrorSummary("SEGV", &stack);
}
void ReportDoubleFree(uptr addr, StackTrace *stack) {
@ -589,7 +578,7 @@ void ReportDoubleFree(uptr addr, StackTrace *stack) {
Printf("%s", d.EndWarning());
PrintStack(stack);
DescribeHeapAddress(addr, 1);
ReportSummary("double-free", stack);
ReportErrorSummary("double-free", stack);
}
void ReportFreeNotMalloced(uptr addr, StackTrace *stack) {
@ -604,7 +593,7 @@ void ReportFreeNotMalloced(uptr addr, StackTrace *stack) {
Printf("%s", d.EndWarning());
PrintStack(stack);
DescribeHeapAddress(addr, 1);
ReportSummary("bad-free", stack);
ReportErrorSummary("bad-free", stack);
}
void ReportAllocTypeMismatch(uptr addr, StackTrace *stack,
@ -623,7 +612,7 @@ void ReportAllocTypeMismatch(uptr addr, StackTrace *stack,
Printf("%s", d.EndWarning());
PrintStack(stack);
DescribeHeapAddress(addr, 1);
ReportSummary("alloc-dealloc-mismatch", stack);
ReportErrorSummary("alloc-dealloc-mismatch", stack);
Report("HINT: if you don't care about these warnings you may set "
"ASAN_OPTIONS=alloc_dealloc_mismatch=0\n");
}
@ -638,7 +627,7 @@ void ReportMallocUsableSizeNotOwned(uptr addr, StackTrace *stack) {
Printf("%s", d.EndWarning());
PrintStack(stack);
DescribeHeapAddress(addr, 1);
ReportSummary("bad-malloc_usable_size", stack);
ReportErrorSummary("bad-malloc_usable_size", stack);
}
void ReportAsanGetAllocatedSizeNotOwned(uptr addr, StackTrace *stack) {
@ -651,7 +640,7 @@ void ReportAsanGetAllocatedSizeNotOwned(uptr addr, StackTrace *stack) {
Printf("%s", d.EndWarning());
PrintStack(stack);
DescribeHeapAddress(addr, 1);
ReportSummary("bad-__asan_get_allocated_size", stack);
ReportErrorSummary("bad-__asan_get_allocated_size", stack);
}
void ReportStringFunctionMemoryRangesOverlap(
@ -669,7 +658,7 @@ void ReportStringFunctionMemoryRangesOverlap(
PrintStack(stack);
DescribeAddress((uptr)offset1, length1);
DescribeAddress((uptr)offset2, length2);
ReportSummary(bug_type, stack);
ReportErrorSummary(bug_type, stack);
}
// ----------------------- Mac-specific reports ----------------- {{{1
@ -779,7 +768,7 @@ void __asan_report_error(uptr pc, uptr bp, uptr sp,
PrintStack(&stack);
DescribeAddress(addr, access_size);
ReportSummary(bug_descr, &stack);
ReportErrorSummary(bug_descr, &stack);
PrintShadowMemoryForAddress(addr);
}

View File

@ -20,4 +20,4 @@ int main() {
fprintf(stderr, "Test alloc: %p.\n", q);
return 0;
}
// CHECK: SUMMARY: LeakSanitizer: 1337 byte(s) leaked in 1 allocation(s)
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s)

View File

@ -32,5 +32,5 @@ int main(int argc, char *argv[]) {
return 0;
}
// CHECK-strict: SUMMARY: LeakSanitizer: 2003 byte(s) leaked in 2 allocation(s)
// CHECK-normal: SUMMARY: LeakSanitizer: 666 byte(s) leaked in 1 allocation(s)
// CHECK-strict: SUMMARY: {{(Leak|Address)}}Sanitizer: 2003 byte(s) leaked in 2 allocation(s)
// CHECK-normal: SUMMARY: {{(Leak|Address)}}Sanitizer: 666 byte(s) leaked in 1 allocation(s)

View File

@ -27,4 +27,4 @@ int main() {
}
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: ignoring heap object at [[ADDR]]
// CHECK: SUMMARY: LeakSanitizer: 1337 byte(s) leaked in 1 allocation(s)
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s)

View File

@ -15,4 +15,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: Directly leaked 33554432 byte object at [[ADDR]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: SUMMARY: LeakSanitizer:
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:

View File

@ -15,5 +15,5 @@ int main(int argc, char *argv[]) {
return 0;
}
// CHECK-do: SUMMARY: LeakSanitizer:
// CHECK-dont-NOT: SUMMARY: LeakSanitizer:
// CHECK-do: SUMMARY: {{(Leak|Address)}}Sanitizer:
// CHECK-dont-NOT: SUMMARY: {{(Leak|Address)}}Sanitizer:

View File

@ -21,4 +21,4 @@ int main(int argc, char *argv[]) {
return 0;
}
// CHECK: SUMMARY: LeakSanitizer: 4 byte(s) leaked in 1 allocation(s)
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 4 byte(s) leaked in 1 allocation(s)

View File

@ -15,4 +15,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: Directly leaked 1337 byte object at [[ADDR]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: SUMMARY: LeakSanitizer:
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:

View File

@ -38,5 +38,5 @@ void ConfirmPointerHasSurvived() {
// CHECK-sanity: Test alloc: [[ADDR:.*]].
// CHECK: Directly leaked 1337 byte object at [[ADDR]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: SUMMARY: LeakSanitizer:
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:
// CHECK-sanity: Value after LSan: [[ADDR]].

View File

@ -26,4 +26,4 @@ int main() {
}
// CHECK: Suppressions used:
// CHECK: 1 666 *LSanTestLeakingFunc*
// CHECK: SUMMARY: LeakSanitizer: 1337 byte(s) leaked in 1 allocation(s)
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s)

View File

@ -26,4 +26,4 @@ int main() {
}
// CHECK: Suppressions used:
// CHECK: 1 666 *LSanTestLeakingFunc*
// CHECK: SUMMARY: LeakSanitizer: 1337 byte(s) leaked in 1 allocation(s)
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s)

View File

@ -39,4 +39,4 @@ int main(int argc, char *argv[]) {
return 0;
}
// CHECK: SUMMARY: LeakSanitizer: 2664 byte(s) leaked in 1 allocation(s)
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 2664 byte(s) leaked in 1 allocation(s)

View File

@ -20,4 +20,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: Directly leaked 1337 byte object at [[ADDR]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: SUMMARY: LeakSanitizer:
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:

View File

@ -18,4 +18,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: Directly leaked 1337 byte object at [[ADDR]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: SUMMARY: LeakSanitizer:
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:

View File

@ -18,4 +18,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: Directly leaked 1337 byte object at [[ADDR]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: SUMMARY: LeakSanitizer:
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:

View File

@ -48,4 +48,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: Directly leaked 1337 byte object at [[ADDR]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: SUMMARY: LeakSanitizer:
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:

View File

@ -17,4 +17,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: Directly leaked 1337 byte object at [[ADDR]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: SUMMARY: LeakSanitizer:
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:

View File

@ -33,4 +33,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: Directly leaked 1337 byte object at [[ADDR]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: SUMMARY: LeakSanitizer:
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:

View File

@ -30,4 +30,4 @@ int main(int argc, char *argv[]) {
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: leaked 1337 byte object at [[ADDR]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: SUMMARY: LeakSanitizer:
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:

View File

@ -34,4 +34,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: leaked 1337 byte object at [[ADDR]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: SUMMARY: LeakSanitizer:
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:

View File

@ -28,4 +28,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: Directly leaked 1337 byte object at [[ADDR]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: SUMMARY: LeakSanitizer:
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:

View File

@ -18,4 +18,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: Directly leaked 1337 byte object at [[ADDR]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: SUMMARY: LeakSanitizer:
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:

View File

@ -20,4 +20,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: Directly leaked 1337 byte object at [[ADDR]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: SUMMARY: LeakSanitizer:
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:

View File

@ -509,13 +509,11 @@ void LeakReport::PrintSummary() {
bytes += leaks_[i].total_size;
allocations += leaks_[i].hit_count;
}
const int kMaxSummaryLength = 128;
InternalScopedBuffer<char> summary(kMaxSummaryLength);
internal_snprintf(summary.data(), kMaxSummaryLength,
"SUMMARY: LeakSanitizer: %zu byte(s) leaked in %zu "
"allocation(s).",
bytes, allocations);
__sanitizer_report_error_summary(summary.data());
internal_snprintf(summary.data(), summary.size(),
"%zu byte(s) leaked in %zu allocation(s).", bytes,
allocations);
ReportErrorSummary(summary.data());
}
uptr LeakReport::ApplySuppressions() {

View File

@ -66,14 +66,6 @@ static void DescribeOrigin(u32 origin) {
}
}
static void ReportSummary(const char *error_type, StackTrace *stack) {
if (!stack->size || !Symbolizer::Get()->IsAvailable()) return;
AddressInfo ai;
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
Symbolizer::Get()->SymbolizeCode(pc, &ai, 1);
ReportErrorSummary(error_type, ai.file, ai.line, ai.function);
}
void ReportUMR(StackTrace *stack, u32 origin) {
if (!__msan::flags()->report_umrs) return;
@ -87,7 +79,7 @@ void ReportUMR(StackTrace *stack, u32 origin) {
if (origin) {
DescribeOrigin(origin);
}
ReportSummary("use-of-uninitialized-value", stack);
ReportErrorSummary("use-of-uninitialized-value", stack);
}
void ReportExpectedUMRNotFound(StackTrace *stack) {

View File

@ -14,6 +14,8 @@
#include "sanitizer_common.h"
#include "sanitizer_flags.h"
#include "sanitizer_libc.h"
#include "sanitizer_stacktrace.h"
#include "sanitizer_symbolizer.h"
namespace __sanitizer {
@ -163,16 +165,32 @@ void PrintModuleAndOffset(const char *module, uptr offset) {
StripPathPrefix(module, common_flags()->strip_path_prefix), offset);
}
void ReportErrorSummary(const char *error_message) {
InternalScopedBuffer<char> buff(kMaxSummaryLength);
internal_snprintf(buff.data(), buff.size(),
"SUMMARY: %s: %s", SanitizerToolName, error_message);
__sanitizer_report_error_summary(buff.data());
}
void ReportErrorSummary(const char *error_type, const char *file,
int line, const char *function) {
const int kMaxSize = 1024; // We don't want a summary too long.
InternalScopedBuffer<char> buff(kMaxSize);
InternalScopedBuffer<char> buff(kMaxSummaryLength);
internal_snprintf(
buff.data(), kMaxSize, "SUMMARY: %s: %s %s:%d %s", SanitizerToolName,
error_type,
buff.data(), buff.size(), "%s %s:%d %s", error_type,
file ? StripPathPrefix(file, common_flags()->strip_path_prefix) : "??",
line, function ? function : "??");
__sanitizer_report_error_summary(buff.data());
ReportErrorSummary(buff.data());
}
void ReportErrorSummary(const char *error_type, StackTrace *stack) {
AddressInfo ai;
if (stack->size > 0 && Symbolizer::Get()->IsAvailable()) {
// Currently, we include the first stack frame into the report summary.
// Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc).
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
Symbolizer::Get()->SymbolizeCode(pc, &ai, 1);
}
ReportErrorSummary(error_type, ai.file, ai.line, ai.function);
}
LoadedModule::LoadedModule(const char *module_name, uptr base_address) {

View File

@ -184,11 +184,17 @@ typedef void (*CheckFailedCallbackType)(const char *, int, const char *,
u64, u64);
void SetCheckFailedCallback(CheckFailedCallbackType callback);
// Construct a one-line string like
// SanitizerToolName: error_type file:line function
// and call __sanitizer_report_error_summary on it.
// We don't want a summary too long.
const int kMaxSummaryLength = 1024;
// Construct a one-line string:
// SUMMARY: SanitizerToolName: error_message
// and pass it to __sanitizer_report_error_summary.
void ReportErrorSummary(const char *error_message);
// Same as above, but construct error_message as:
// error_type: file:line function
void ReportErrorSummary(const char *error_type, const char *file,
int line, const char *function);
void ReportErrorSummary(const char *error_type, StackTrace *trace);
// Math
#if SANITIZER_WINDOWS && !defined(__clang__) && !defined(__GNUC__)