[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
diff --git a/lib/asan/asan_report.cc b/lib/asan/asan_report.cc
index 5406ac0..cbd850e 100644
--- a/lib/asan/asan_report.cc
+++ b/lib/asan/asan_report.cc
@@ -549,17 +549,6 @@
   }
 };
 
-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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 aef9e11..db0cd8f 100644
--- a/lib/lsan/lit_tests/TestCases/disabler.cc
+++ b/lib/lsan/lit_tests/TestCases/disabler.cc
@@ -20,4 +20,4 @@
   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 213d260..be0ed0a 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 @@
   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 43744e4..cbc743b 100644
--- a/lib/lsan/lit_tests/TestCases/ignore_object.cc
+++ b/lib/lsan/lit_tests/TestCases/ignore_object.cc
@@ -27,4 +27,4 @@
 }
 // 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 28e38ca..57d0565 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 @@
 // 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 441012a..38c1063 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 @@
   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 6db7a18..93628a1 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 @@
   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 ecfe11b..0d2818d 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 @@
 // 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 4f2b26c..fabfb4f 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 @@
 // 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 e8e0921..9a165f8 100644
--- a/lib/lsan/lit_tests/TestCases/suppressions_default.cc
+++ b/lib/lsan/lit_tests/TestCases/suppressions_default.cc
@@ -26,4 +26,4 @@
 }
 // 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 e8e0921..9a165f8 100644
--- a/lib/lsan/lit_tests/TestCases/suppressions_file.cc
+++ b/lib/lsan/lit_tests/TestCases/suppressions_file.cc
@@ -26,4 +26,4 @@
 }
 // 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 aada9a5..a06685c 100644
--- a/lib/lsan/lit_tests/TestCases/swapcontext.cc
+++ b/lib/lsan/lit_tests/TestCases/swapcontext.cc
@@ -39,4 +39,4 @@
   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 7ccbe43..93b0ea6 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 @@
 // 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 2849495..5a7c48b 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 @@
 // 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 f48d08f..e1d045e 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 @@
 // 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 636fac8..a7d8a69 100644
--- a/lib/lsan/lit_tests/TestCases/use_registers.cc
+++ b/lib/lsan/lit_tests/TestCases/use_registers.cc
@@ -48,4 +48,4 @@
 // 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 06a058e..4287a96 100644
--- a/lib/lsan/lit_tests/TestCases/use_stacks.cc
+++ b/lib/lsan/lit_tests/TestCases/use_stacks.cc
@@ -17,4 +17,4 @@
 // 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 9e1b1cf..c7dfaf8 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 @@
 // 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 3e45e1a..2570b63 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 @@
 // 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 032def7..3dea41e 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 @@
 // 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 86e2b29..b75f151 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 @@
 // 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 460aee4..9ccb2b2 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 @@
 // 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 851d249..bc75f11 100644
--- a/lib/lsan/lit_tests/TestCases/use_unaligned.cc
+++ b/lib/lsan/lit_tests/TestCases/use_unaligned.cc
@@ -20,4 +20,4 @@
 // 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 cfa9db0..18354e9 100644
--- a/lib/lsan/lsan_common.cc
+++ b/lib/lsan/lsan_common.cc
@@ -509,13 +509,11 @@
       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 524e975..e3ef993 100644
--- a/lib/msan/msan_report.cc
+++ b/lib/msan/msan_report.cc
@@ -66,14 +66,6 @@
   }
 }
 
-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 @@
   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 efc976d..1a01718 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 @@
          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 31c2236..dda72b5 100644
--- a/lib/sanitizer_common/sanitizer_common.h
+++ b/lib/sanitizer_common/sanitizer_common.h
@@ -184,11 +184,17 @@
                                        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__)