From aa05110a17273e8b1964402b783dd9ab2c847bb2 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 9 Aug 2012 07:40:58 +0000 Subject: [PATCH] [ASan] Create new files asan_report.{h,cc} as a preparation for refactoring of ASan error reporting code. Currently ASan reports many kinds of errors, and the code that actually prints error messages can be found inside allocator, OS-specific files, interceptors code etc. An example of maintenance troubles this situation causes: There is currently an ASan interface function that registers callback which should take the char buffer with error report printed by ASan. This function is now broken, as one has to insert callback calls to all the places in ASan code where the error reports are printed, surprisingly it is not only "__asan_report_error" function... llvm-svn: 161568 --- compiler-rt/lib/asan/asan_posix.cc | 10 ++------- compiler-rt/lib/asan/asan_report.cc | 32 +++++++++++++++++++++++++++++ compiler-rt/lib/asan/asan_report.h | 21 +++++++++++++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 compiler-rt/lib/asan/asan_report.cc create mode 100644 compiler-rt/lib/asan/asan_report.h diff --git a/compiler-rt/lib/asan/asan_posix.cc b/compiler-rt/lib/asan/asan_posix.cc index 061bb193034d..ceaf120fc803 100644 --- a/compiler-rt/lib/asan/asan_posix.cc +++ b/compiler-rt/lib/asan/asan_posix.cc @@ -16,6 +16,7 @@ #include "asan_internal.h" #include "asan_interceptors.h" #include "asan_mapping.h" +#include "asan_report.h" #include "asan_stack.h" #include "asan_thread_registry.h" #include "sanitizer_common/sanitizer_libc.h" @@ -53,14 +54,7 @@ static void ASAN_OnSIGSEGV(int, siginfo_t *siginfo, void *context) { if (13 != internal_write(2, "ASAN:SIGSEGV\n", 13)) Die(); uptr pc, sp, bp; GetPcSpBp(context, &pc, &sp, &bp); - AsanReport("ERROR: AddressSanitizer crashed on unknown address %p" - " (pc %p sp %p bp %p T%d)\n", - (void*)addr, (void*)pc, (void*)sp, (void*)bp, - asanThreadRegistry().GetCurrentTidOrInvalid()); - AsanPrintf("AddressSanitizer can not provide additional info. ABORTING\n"); - GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax, pc, bp); - stack.PrintStack(); - ShowStatsAndAbort(); + ReportSIGSEGV(pc, sp, bp, addr); } void SetAlternateSignalStack() { diff --git a/compiler-rt/lib/asan/asan_report.cc b/compiler-rt/lib/asan/asan_report.cc new file mode 100644 index 000000000000..8b70f320e983 --- /dev/null +++ b/compiler-rt/lib/asan/asan_report.cc @@ -0,0 +1,32 @@ +//===-- asan_report.cc ----------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// This file contains error reporting code. +//===----------------------------------------------------------------------===// +#include "asan_internal.h" +#include "asan_report.h" +#include "asan_stack.h" +#include "asan_thread_registry.h" + +namespace __asan { + +void ReportSIGSEGV(uptr pc, uptr sp, uptr bp, uptr addr) { + AsanReport("ERROR: AddressSanitizer crashed on unknown address %p" + " (pc %p sp %p bp %p T%d)\n", + (void*)addr, (void*)pc, (void*)sp, (void*)bp, + asanThreadRegistry().GetCurrentTidOrInvalid()); + AsanPrintf("AddressSanitizer can not provide additional info. ABORTING\n"); + GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax, pc, bp); + stack.PrintStack(); + ShowStatsAndAbort(); +} + +} // namespace __asan diff --git a/compiler-rt/lib/asan/asan_report.h b/compiler-rt/lib/asan/asan_report.h new file mode 100644 index 000000000000..36e622cf5e28 --- /dev/null +++ b/compiler-rt/lib/asan/asan_report.h @@ -0,0 +1,21 @@ +//===-- asan_report.h -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// ASan-private header for error reporting functions. +//===----------------------------------------------------------------------===// + +#include "asan_internal.h" + +namespace __asan { + +void ReportSIGSEGV(uptr pc, uptr sp, uptr bp, uptr addr); + +} // namespace __asan