diff options
author | Alexey Samsonov <samsonov@google.com> | 2013-11-01 17:02:14 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2013-11-01 17:02:14 +0000 |
commit | 2fb08720b11b4c339e191b90d85477c6a2dd74db (patch) | |
tree | eb6edea41d09acfd47a5960ccb958907f77e0e80 | |
parent | 21bf90dcf562bd05df20eb55b8d0559017574ffb (diff) | |
download | compiler-rt-2fb08720b11b4c339e191b90d85477c6a2dd74db.tar.gz compiler-rt-2fb08720b11b4c339e191b90d85477c6a2dd74db.tar.bz2 compiler-rt-2fb08720b11b4c339e191b90d85477c6a2dd74db.tar.xz |
[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".
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193864 91177308-0d34-0410-b5e6-96231b3b80d8
27 files changed, 69 insertions, 66 deletions
diff --git a/lib/asan/asan_report.cc b/lib/asan/asan_report.cc index 5406ac02..cbd850ed 100644 --- a/lib/asan/asan_report.cc +++ b/lib/asan/asan_report.cc @@ -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); } diff --git a/lib/lsan/lit_tests/TestCases/disabler.cc b/lib/lsan/lit_tests/TestCases/disabler.cc index aef9e116..db0cd8fa 100644 --- a/lib/lsan/lit_tests/TestCases/disabler.cc +++ b/lib/lsan/lit_tests/TestCases/disabler.cc @@ -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) diff --git a/lib/lsan/lit_tests/TestCases/do_leak_check_override.cc b/lib/lsan/lit_tests/TestCases/do_leak_check_override.cc index 213d2602..be0ed0a6 100644 --- a/lib/lsan/lit_tests/TestCases/do_leak_check_override.cc +++ b/lib/lsan/lit_tests/TestCases/do_leak_check_override.cc @@ -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) diff --git a/lib/lsan/lit_tests/TestCases/ignore_object.cc b/lib/lsan/lit_tests/TestCases/ignore_object.cc index 43744e4a..cbc743b7 100644 --- a/lib/lsan/lit_tests/TestCases/ignore_object.cc +++ b/lib/lsan/lit_tests/TestCases/ignore_object.cc @@ -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) diff --git a/lib/lsan/lit_tests/TestCases/large_allocation_leak.cc b/lib/lsan/lit_tests/TestCases/large_allocation_leak.cc index 28e38ca2..57d05659 100644 --- a/lib/lsan/lit_tests/TestCases/large_allocation_leak.cc +++ b/lib/lsan/lit_tests/TestCases/large_allocation_leak.cc @@ -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: diff --git a/lib/lsan/lit_tests/TestCases/leak_check_at_exit.cc b/lib/lsan/lit_tests/TestCases/leak_check_at_exit.cc index 441012a8..38c1063b 100644 --- a/lib/lsan/lit_tests/TestCases/leak_check_at_exit.cc +++ b/lib/lsan/lit_tests/TestCases/leak_check_at_exit.cc @@ -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: diff --git a/lib/lsan/lit_tests/TestCases/link_turned_off.cc b/lib/lsan/lit_tests/TestCases/link_turned_off.cc index 6db7a183..93628a1d 100644 --- a/lib/lsan/lit_tests/TestCases/link_turned_off.cc +++ b/lib/lsan/lit_tests/TestCases/link_turned_off.cc @@ -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) diff --git a/lib/lsan/lit_tests/TestCases/pointer_to_self.cc b/lib/lsan/lit_tests/TestCases/pointer_to_self.cc index ecfe11b7..0d2818d2 100644 --- a/lib/lsan/lit_tests/TestCases/pointer_to_self.cc +++ b/lib/lsan/lit_tests/TestCases/pointer_to_self.cc @@ -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: diff --git a/lib/lsan/lit_tests/TestCases/stale_stack_leak.cc b/lib/lsan/lit_tests/TestCases/stale_stack_leak.cc index 4f2b26cf..fabfb4ff 100644 --- a/lib/lsan/lit_tests/TestCases/stale_stack_leak.cc +++ b/lib/lsan/lit_tests/TestCases/stale_stack_leak.cc @@ -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]]. diff --git a/lib/lsan/lit_tests/TestCases/suppressions_default.cc b/lib/lsan/lit_tests/TestCases/suppressions_default.cc index e8e0921f..9a165f87 100644 --- a/lib/lsan/lit_tests/TestCases/suppressions_default.cc +++ b/lib/lsan/lit_tests/TestCases/suppressions_default.cc @@ -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) diff --git a/lib/lsan/lit_tests/TestCases/suppressions_file.cc b/lib/lsan/lit_tests/TestCases/suppressions_file.cc index e8e0921f..9a165f87 100644 --- a/lib/lsan/lit_tests/TestCases/suppressions_file.cc +++ b/lib/lsan/lit_tests/TestCases/suppressions_file.cc @@ -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) diff --git a/lib/lsan/lit_tests/TestCases/swapcontext.cc b/lib/lsan/lit_tests/TestCases/swapcontext.cc index aada9a51..a06685ca 100644 --- a/lib/lsan/lit_tests/TestCases/swapcontext.cc +++ b/lib/lsan/lit_tests/TestCases/swapcontext.cc @@ -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) diff --git a/lib/lsan/lit_tests/TestCases/use_after_return.cc b/lib/lsan/lit_tests/TestCases/use_after_return.cc index 7ccbe435..93b0ea60 100644 --- a/lib/lsan/lit_tests/TestCases/use_after_return.cc +++ b/lib/lsan/lit_tests/TestCases/use_after_return.cc @@ -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: diff --git a/lib/lsan/lit_tests/TestCases/use_globals_initialized.cc b/lib/lsan/lit_tests/TestCases/use_globals_initialized.cc index 2849495e..5a7c48bd 100644 --- a/lib/lsan/lit_tests/TestCases/use_globals_initialized.cc +++ b/lib/lsan/lit_tests/TestCases/use_globals_initialized.cc @@ -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: diff --git a/lib/lsan/lit_tests/TestCases/use_globals_uninitialized.cc b/lib/lsan/lit_tests/TestCases/use_globals_uninitialized.cc index f48d08fa..e1d045e3 100644 --- a/lib/lsan/lit_tests/TestCases/use_globals_uninitialized.cc +++ b/lib/lsan/lit_tests/TestCases/use_globals_uninitialized.cc @@ -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: diff --git a/lib/lsan/lit_tests/TestCases/use_registers.cc b/lib/lsan/lit_tests/TestCases/use_registers.cc index 636fac82..a7d8a69d 100644 --- a/lib/lsan/lit_tests/TestCases/use_registers.cc +++ b/lib/lsan/lit_tests/TestCases/use_registers.cc @@ -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: diff --git a/lib/lsan/lit_tests/TestCases/use_stacks.cc b/lib/lsan/lit_tests/TestCases/use_stacks.cc index 06a058ef..4287a96b 100644 --- a/lib/lsan/lit_tests/TestCases/use_stacks.cc +++ b/lib/lsan/lit_tests/TestCases/use_stacks.cc @@ -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: diff --git a/lib/lsan/lit_tests/TestCases/use_stacks_threaded.cc b/lib/lsan/lit_tests/TestCases/use_stacks_threaded.cc index 9e1b1cf6..c7dfaf8a 100644 --- a/lib/lsan/lit_tests/TestCases/use_stacks_threaded.cc +++ b/lib/lsan/lit_tests/TestCases/use_stacks_threaded.cc @@ -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: diff --git a/lib/lsan/lit_tests/TestCases/use_tls_dynamic.cc b/lib/lsan/lit_tests/TestCases/use_tls_dynamic.cc index 3e45e1aa..2570b63f 100644 --- a/lib/lsan/lit_tests/TestCases/use_tls_dynamic.cc +++ b/lib/lsan/lit_tests/TestCases/use_tls_dynamic.cc @@ -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: diff --git a/lib/lsan/lit_tests/TestCases/use_tls_pthread_specific_dynamic.cc b/lib/lsan/lit_tests/TestCases/use_tls_pthread_specific_dynamic.cc index 032def7f..3dea41ed 100644 --- a/lib/lsan/lit_tests/TestCases/use_tls_pthread_specific_dynamic.cc +++ b/lib/lsan/lit_tests/TestCases/use_tls_pthread_specific_dynamic.cc @@ -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: diff --git a/lib/lsan/lit_tests/TestCases/use_tls_pthread_specific_static.cc b/lib/lsan/lit_tests/TestCases/use_tls_pthread_specific_static.cc index 86e2b299..b75f1515 100644 --- a/lib/lsan/lit_tests/TestCases/use_tls_pthread_specific_static.cc +++ b/lib/lsan/lit_tests/TestCases/use_tls_pthread_specific_static.cc @@ -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: diff --git a/lib/lsan/lit_tests/TestCases/use_tls_static.cc b/lib/lsan/lit_tests/TestCases/use_tls_static.cc index 460aee45..9ccb2b2b 100644 --- a/lib/lsan/lit_tests/TestCases/use_tls_static.cc +++ b/lib/lsan/lit_tests/TestCases/use_tls_static.cc @@ -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: diff --git a/lib/lsan/lit_tests/TestCases/use_unaligned.cc b/lib/lsan/lit_tests/TestCases/use_unaligned.cc index 851d2498..bc75f11b 100644 --- a/lib/lsan/lit_tests/TestCases/use_unaligned.cc +++ b/lib/lsan/lit_tests/TestCases/use_unaligned.cc @@ -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: diff --git a/lib/lsan/lsan_common.cc b/lib/lsan/lsan_common.cc index cfa9db0b..18354e9e 100644 --- a/lib/lsan/lsan_common.cc +++ b/lib/lsan/lsan_common.cc @@ -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() { diff --git a/lib/msan/msan_report.cc b/lib/msan/msan_report.cc index 524e9752..e3ef9930 100644 --- a/lib/msan/msan_report.cc +++ b/lib/msan/msan_report.cc @@ -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) { diff --git a/lib/sanitizer_common/sanitizer_common.cc b/lib/sanitizer_common/sanitizer_common.cc index efc976d1..1a01718a 100644 --- a/lib/sanitizer_common/sanitizer_common.cc +++ b/lib/sanitizer_common/sanitizer_common.cc @@ -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) { diff --git a/lib/sanitizer_common/sanitizer_common.h b/lib/sanitizer_common/sanitizer_common.h index 31c22362..dda72b59 100644 --- a/lib/sanitizer_common/sanitizer_common.h +++ b/lib/sanitizer_common/sanitizer_common.h @@ -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__) |