diff options
author | Alexey Samsonov <samsonov@google.com> | 2012-08-09 09:27:24 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2012-08-09 09:27:24 +0000 |
commit | 65b9acf0afce2e34259c4ca557196bd7445b7e80 (patch) | |
tree | 283790792e2142d6ce91daff43e5282eb8c78266 /compiler-rt | |
parent | 4ce12349d630e854437291a55d3be21b14716a17 (diff) | |
download | bcm5719-llvm-65b9acf0afce2e34259c4ca557196bd7445b7e80.tar.gz bcm5719-llvm-65b9acf0afce2e34259c4ca557196bd7445b7e80.zip |
[ASan] move code that describes globals to asan_report.cc
llvm-svn: 161572
Diffstat (limited to 'compiler-rt')
-rw-r--r-- | compiler-rt/lib/asan/asan_globals.cc | 35 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_report.cc | 31 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_report.h | 2 |
3 files changed, 37 insertions, 31 deletions
diff --git a/compiler-rt/lib/asan/asan_globals.cc b/compiler-rt/lib/asan/asan_globals.cc index b7015afefae..87e990960e2 100644 --- a/compiler-rt/lib/asan/asan_globals.cc +++ b/compiler-rt/lib/asan/asan_globals.cc @@ -16,12 +16,11 @@ #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" -#include <ctype.h> - namespace __asan { typedef __asan_global Global; @@ -60,32 +59,6 @@ static uptr GetAlignedSize(uptr size) { * kGlobalAndStackRedzone; } - // Check if the global is a zero-terminated ASCII string. If so, print it. -void PrintIfASCII(const Global &g) { - for (uptr p = g.beg; p < g.beg + g.size - 1; p++) { - if (!isascii(*(char*)p)) return; - } - if (*(char*)(g.beg + g.size - 1) != 0) return; - AsanPrintf(" '%s' is ascii string '%s'\n", g.name, (char*)g.beg); -} - -bool DescribeAddrIfMyRedZone(const Global &g, uptr addr) { - if (addr < g.beg - kGlobalAndStackRedzone) return false; - if (addr >= g.beg + g.size_with_redzone) return false; - AsanPrintf("%p is located ", (void*)addr); - if (addr < g.beg) { - AsanPrintf("%zd bytes to the left", g.beg - addr); - } else if (addr >= g.beg + g.size) { - AsanPrintf("%zd bytes to the right", addr - (g.beg + g.size)); - } else { - AsanPrintf("%zd bytes inside", addr - g.beg); // Can it happen? - } - AsanPrintf(" of global variable '%s' (0x%zx) of size %zu\n", - g.name, g.beg, g.size); - PrintIfASCII(g); - return true; -} - bool DescribeAddressIfGlobal(uptr addr) { if (!flags()->report_globals) return false; ScopedLock lock(&mu_for_globals); @@ -93,9 +66,9 @@ bool DescribeAddressIfGlobal(uptr addr) { for (ListOfGlobals *l = list_of_globals; l; l = l->next) { const Global &g = *l->g; if (flags()->report_globals >= 2) - AsanPrintf("Search Global: beg=%p size=%zu name=%s\n", - (void*)g.beg, g.size, (char*)g.name); - res |= DescribeAddrIfMyRedZone(g, addr); + Report("Search Global: beg=%p size=%zu name=%s\n", + (void*)g.beg, g.size, (char*)g.name); + res |= DescribeAddressRelativeToGlobal(addr, g); } return res; } diff --git a/compiler-rt/lib/asan/asan_report.cc b/compiler-rt/lib/asan/asan_report.cc index 394e25603dc..f61c42168e2 100644 --- a/compiler-rt/lib/asan/asan_report.cc +++ b/compiler-rt/lib/asan/asan_report.cc @@ -15,12 +15,43 @@ #include "asan_mapping.h" #include "asan_report.h" #include "asan_stack.h" +#include "asan_thread.h" #include "asan_thread_registry.h" namespace __asan { // ---------------------- Address Descriptions ------------------- {{{1 +static bool IsASCII(unsigned char c) { + return 0x00 <= c && c <= 0x7F; +} + +// Check if the global is a zero-terminated ASCII string. If so, print it. +static void PrintGlobalNameIfASCII(const __asan_global &g) { + for (uptr p = g.beg; p < g.beg + g.size - 1; p++) { + if (!IsASCII(*(unsigned char*)p)) return; + } + if (*(char*)(g.beg + g.size - 1) != 0) return; + AsanPrintf(" '%s' is ascii string '%s'\n", g.name, (char*)g.beg); +} + +bool DescribeAddressRelativeToGlobal(uptr addr, const __asan_global &g) { + if (addr < g.beg - kGlobalAndStackRedzone) return false; + if (addr >= g.beg + g.size_with_redzone) return false; + AsanPrintf("%p is located ", (void*)addr); + if (addr < g.beg) { + AsanPrintf("%zd bytes to the left", g.beg - addr); + } else if (addr >= g.beg + g.size) { + AsanPrintf("%zd bytes to the right", addr - (g.beg + g.size)); + } else { + AsanPrintf("%zd bytes inside", addr - g.beg); // Can it happen? + } + AsanPrintf(" of global variable '%s' (0x%zx) of size %zu\n", + g.name, g.beg, g.size); + PrintGlobalNameIfASCII(g); + return true; +} + bool DescribeAddressIfShadow(uptr addr) { if (AddrIsInMem(addr)) return false; diff --git a/compiler-rt/lib/asan/asan_report.h b/compiler-rt/lib/asan/asan_report.h index b47b13114b3..101797eadf7 100644 --- a/compiler-rt/lib/asan/asan_report.h +++ b/compiler-rt/lib/asan/asan_report.h @@ -12,6 +12,7 @@ // ASan-private header for error reporting functions. //===----------------------------------------------------------------------===// +#include "asan_interface.h" #include "asan_internal.h" namespace __asan { @@ -20,6 +21,7 @@ namespace __asan { // on the memory type (shadow/heap/stack/global). void DescribeHeapAddress(uptr addr, uptr access_size); bool DescribeAddressIfGlobal(uptr addr); +bool DescribeAddressRelativeToGlobal(uptr addr, const __asan_global &g); bool DescribeAddressIfShadow(uptr addr); bool DescribeAddressIfStack(uptr addr, uptr access_size); // Determines memory type on its own. |