[llvm-commits] [compiler-rt] r161572 - in /compiler-rt/trunk/lib/asan: asan_globals.cc asan_report.cc asan_report.h
Alexey Samsonov
samsonov at google.com
Thu Aug 9 02:27:25 PDT 2012
Author: samsonov
Date: Thu Aug 9 04:27:24 2012
New Revision: 161572
URL: http://llvm.org/viewvc/llvm-project?rev=161572&view=rev
Log:
[ASan] move code that describes globals to asan_report.cc
Modified:
compiler-rt/trunk/lib/asan/asan_globals.cc
compiler-rt/trunk/lib/asan/asan_report.cc
compiler-rt/trunk/lib/asan/asan_report.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=161572&r1=161571&r2=161572&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_globals.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_globals.cc Thu Aug 9 04:27:24 2012
@@ -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 @@
* 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 @@
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;
}
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=161572&r1=161571&r2=161572&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_report.cc Thu Aug 9 04:27:24 2012
@@ -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;
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=161572&r1=161571&r2=161572&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.h (original)
+++ compiler-rt/trunk/lib/asan/asan_report.h Thu Aug 9 04:27:24 2012
@@ -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 @@
// 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.
More information about the llvm-commits
mailing list