[llvm-commits] [compiler-rt] r161571 - in /compiler-rt/trunk/lib/asan: asan_allocator.h asan_globals.cc asan_internal.h asan_report.cc asan_report.h asan_rtl.cc
Alexey Samsonov
samsonov at google.com
Thu Aug 9 02:06:52 PDT 2012
Author: samsonov
Date: Thu Aug 9 04:06:52 2012
New Revision: 161571
URL: http://llvm.org/viewvc/llvm-project?rev=161571&view=rev
Log:
[ASan] move some functions that describe addresses to asan_report.cc
Modified:
compiler-rt/trunk/lib/asan/asan_allocator.h
compiler-rt/trunk/lib/asan/asan_globals.cc
compiler-rt/trunk/lib/asan/asan_internal.h
compiler-rt/trunk/lib/asan/asan_report.cc
compiler-rt/trunk/lib/asan/asan_report.h
compiler-rt/trunk/lib/asan/asan_rtl.cc
Modified: compiler-rt/trunk/lib/asan/asan_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.h?rev=161571&r1=161570&r2=161571&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator.h (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator.h Thu Aug 9 04:06:52 2012
@@ -153,7 +153,6 @@
uptr asan_mz_size(const void *ptr);
void asan_mz_force_lock();
void asan_mz_force_unlock();
-void DescribeHeapAddress(uptr addr, uptr access_size);
} // namespace __asan
#endif // ASAN_ALLOCATOR_H
Modified: compiler-rt/trunk/lib/asan/asan_globals.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_globals.cc?rev=161571&r1=161570&r2=161571&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_globals.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_globals.cc Thu Aug 9 04:06:52 2012
@@ -86,8 +86,7 @@
return true;
}
-
-bool DescribeAddrIfGlobal(uptr addr) {
+bool DescribeAddressIfGlobal(uptr addr) {
if (!flags()->report_globals) return false;
ScopedLock lock(&mu_for_globals);
bool res = false;
Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=161571&r1=161570&r2=161571&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Thu Aug 9 04:06:52 2012
@@ -91,9 +91,6 @@
// asan_rtl.cc
void NORETURN ShowStatsAndAbort();
-// asan_globals.cc
-bool DescribeAddrIfGlobal(uptr addr);
-
void ReplaceOperatorsNewAndDelete();
// asan_malloc_linux.cc / asan_malloc_mac.cc
void ReplaceSystemMalloc();
Modified: compiler-rt/trunk/lib/asan/asan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.cc?rev=161571&r1=161570&r2=161571&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_report.cc Thu Aug 9 04:06:52 2012
@@ -11,14 +11,103 @@
//
// This file contains error reporting code.
//===----------------------------------------------------------------------===//
-#include "asan_allocator.h"
#include "asan_internal.h"
+#include "asan_mapping.h"
#include "asan_report.h"
#include "asan_stack.h"
#include "asan_thread_registry.h"
namespace __asan {
+// ---------------------- Address Descriptions ------------------- {{{1
+
+bool DescribeAddressIfShadow(uptr addr) {
+ if (AddrIsInMem(addr))
+ return false;
+ static const char kAddrInShadowReport[] =
+ "Address %p is located in the %s.\n";
+ if (AddrIsInShadowGap(addr)) {
+ AsanPrintf(kAddrInShadowReport, addr, "shadow gap area");
+ return true;
+ }
+ if (AddrIsInHighShadow(addr)) {
+ AsanPrintf(kAddrInShadowReport, addr, "high shadow area");
+ return true;
+ }
+ if (AddrIsInLowShadow(addr)) {
+ AsanPrintf(kAddrInShadowReport, addr, "low shadow area");
+ return true;
+ }
+ CHECK(0 && "Address is not in memory and not in shadow?");
+ return false;
+}
+
+bool DescribeAddressIfStack(uptr addr, uptr access_size) {
+ AsanThread *t = asanThreadRegistry().FindThreadByStackAddress(addr);
+ if (!t) return false;
+ const sptr kBufSize = 4095;
+ char buf[kBufSize];
+ uptr offset = 0;
+ const char *frame_descr = t->GetFrameNameByAddr(addr, &offset);
+ // This string is created by the compiler and has the following form:
+ // "FunctioName n alloc_1 alloc_2 ... alloc_n"
+ // where alloc_i looks like "offset size len ObjectName ".
+ CHECK(frame_descr);
+ // Report the function name and the offset.
+ const char *name_end = internal_strchr(frame_descr, ' ');
+ CHECK(name_end);
+ buf[0] = 0;
+ internal_strncat(buf, frame_descr,
+ Min(kBufSize,
+ static_cast<sptr>(name_end - frame_descr)));
+ AsanPrintf("Address %p is located at offset %zu "
+ "in frame <%s> of T%d's stack:\n",
+ (void*)addr, offset, buf, t->tid());
+ // Report the number of stack objects.
+ char *p;
+ uptr n_objects = internal_simple_strtoll(name_end, &p, 10);
+ CHECK(n_objects > 0);
+ AsanPrintf(" This frame has %zu object(s):\n", n_objects);
+ // Report all objects in this frame.
+ for (uptr i = 0; i < n_objects; i++) {
+ uptr beg, size;
+ sptr len;
+ beg = internal_simple_strtoll(p, &p, 10);
+ size = internal_simple_strtoll(p, &p, 10);
+ len = internal_simple_strtoll(p, &p, 10);
+ if (beg <= 0 || size <= 0 || len < 0 || *p != ' ') {
+ AsanPrintf("AddressSanitizer can't parse the stack frame "
+ "descriptor: |%s|\n", frame_descr);
+ break;
+ }
+ p++;
+ buf[0] = 0;
+ internal_strncat(buf, p, Min(kBufSize, len));
+ p += len;
+ AsanPrintf(" [%zu, %zu) '%s'\n", beg, beg + size, buf);
+ }
+ AsanPrintf("HINT: this may be a false positive if your program uses "
+ "some custom stack unwind mechanism\n"
+ " (longjmp and C++ exceptions *are* supported)\n");
+ t->summary()->Announce();
+ return true;
+}
+
+void DescribeAddress(uptr addr, uptr access_size) {
+ // Check if this is shadow or shadow gap.
+ if (DescribeAddressIfShadow(addr))
+ return;
+ CHECK(AddrIsInMem(addr));
+ if (DescribeAddressIfGlobal(addr))
+ return;
+ if (DescribeAddressIfStack(addr, access_size))
+ return;
+ // Assume it is a heap address.
+ DescribeHeapAddress(addr, access_size);
+}
+
+// -------------------- Different kinds of reports ----------------- {{{1
+
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",
Modified: compiler-rt/trunk/lib/asan/asan_report.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.h?rev=161571&r1=161570&r2=161571&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.h (original)
+++ compiler-rt/trunk/lib/asan/asan_report.h Thu Aug 9 04:06:52 2012
@@ -16,6 +16,16 @@
namespace __asan {
+// The following functions prints address description depending
+// on the memory type (shadow/heap/stack/global).
+void DescribeHeapAddress(uptr addr, uptr access_size);
+bool DescribeAddressIfGlobal(uptr addr);
+bool DescribeAddressIfShadow(uptr addr);
+bool DescribeAddressIfStack(uptr addr, uptr access_size);
+// Determines memory type on its own.
+void DescribeAddress(uptr addr, uptr access_size);
+
+// Different kinds of error reports.
void NORETURN ReportSIGSEGV(uptr pc, uptr sp, uptr bp, uptr addr);
void NORETURN ReportDoubleFree(uptr addr, AsanStackTrace *stack);
Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=161571&r1=161570&r2=161571&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Thu Aug 9 04:06:52 2012
@@ -17,6 +17,7 @@
#include "asan_internal.h"
#include "asan_lock.h"
#include "asan_mapping.h"
+#include "asan_report.h"
#include "asan_stack.h"
#include "asan_stats.h"
#include "asan_thread.h"
@@ -207,98 +208,6 @@
return res;
}
-// ---------------------- DescribeAddress -------------------- {{{1
-static bool DescribeStackAddress(uptr addr, uptr access_size) {
- AsanThread *t = asanThreadRegistry().FindThreadByStackAddress(addr);
- if (!t) return false;
- const sptr kBufSize = 4095;
- char buf[kBufSize];
- uptr offset = 0;
- const char *frame_descr = t->GetFrameNameByAddr(addr, &offset);
- // This string is created by the compiler and has the following form:
- // "FunctioName n alloc_1 alloc_2 ... alloc_n"
- // where alloc_i looks like "offset size len ObjectName ".
- CHECK(frame_descr);
- // Report the function name and the offset.
- const char *name_end = internal_strchr(frame_descr, ' ');
- CHECK(name_end);
- buf[0] = 0;
- internal_strncat(buf, frame_descr,
- Min(kBufSize,
- static_cast<sptr>(name_end - frame_descr)));
- AsanPrintf("Address %p is located at offset %zu "
- "in frame <%s> of T%d's stack:\n",
- (void*)addr, offset, buf, t->tid());
- // Report the number of stack objects.
- char *p;
- uptr n_objects = internal_simple_strtoll(name_end, &p, 10);
- CHECK(n_objects > 0);
- AsanPrintf(" This frame has %zu object(s):\n", n_objects);
- // Report all objects in this frame.
- for (uptr i = 0; i < n_objects; i++) {
- uptr beg, size;
- sptr len;
- beg = internal_simple_strtoll(p, &p, 10);
- size = internal_simple_strtoll(p, &p, 10);
- len = internal_simple_strtoll(p, &p, 10);
- if (beg <= 0 || size <= 0 || len < 0 || *p != ' ') {
- AsanPrintf("AddressSanitizer can't parse the stack frame "
- "descriptor: |%s|\n", frame_descr);
- break;
- }
- p++;
- buf[0] = 0;
- internal_strncat(buf, p, Min(kBufSize, len));
- p += len;
- AsanPrintf(" [%zu, %zu) '%s'\n", beg, beg + size, buf);
- }
- AsanPrintf("HINT: this may be a false positive if your program uses "
- "some custom stack unwind mechanism\n"
- " (longjmp and C++ exceptions *are* supported)\n");
- t->summary()->Announce();
- return true;
-}
-
-static bool DescribeAddrIfShadow(uptr addr) {
- if (AddrIsInMem(addr))
- return false;
- static const char kAddrInShadowReport[] =
- "Address %p is located in the %s.\n";
- if (AddrIsInShadowGap(addr)) {
- AsanPrintf(kAddrInShadowReport, addr, "shadow gap area");
- return true;
- }
- if (AddrIsInHighShadow(addr)) {
- AsanPrintf(kAddrInShadowReport, addr, "high shadow area");
- return true;
- }
- if (AddrIsInLowShadow(addr)) {
- AsanPrintf(kAddrInShadowReport, addr, "low shadow area");
- return true;
- }
-
- CHECK(0); // Unreachable.
- return false;
-}
-
-static NOINLINE void DescribeAddress(uptr addr, uptr access_size) {
- // Check if this is shadow or shadow gap.
- if (DescribeAddrIfShadow(addr))
- return;
-
- CHECK(AddrIsInMem(addr));
-
- // Check if this is a global.
- if (DescribeAddrIfGlobal(addr))
- return;
-
- if (DescribeStackAddress(addr, access_size))
- return;
-
- // finally, check if this is a heap.
- DescribeHeapAddress(addr, access_size);
-}
-
// -------------------------- Run-time entry ------------------- {{{1
// exported functions
#define ASAN_REPORT_ERROR(type, is_write, size) \
More information about the llvm-commits
mailing list