[compiler-rt] r178131 - [ASan] Demangle global names in error reports.

Alexey Samsonov samsonov at google.com
Wed Mar 27 03:41:22 PDT 2013


Author: samsonov
Date: Wed Mar 27 05:41:22 2013
New Revision: 178131

URL: http://llvm.org/viewvc/llvm-project?rev=178131&view=rev
Log:
[ASan] Demangle global names in error reports.

Added:
    compiler-rt/trunk/lib/asan/lit_tests/global-demangle.cc
Modified:
    compiler-rt/trunk/lib/asan/asan_report.cc

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=178131&r1=178130&r2=178131&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_report.cc Wed Mar 27 05:41:22 2013
@@ -189,6 +189,12 @@ static void PrintGlobalNameIfASCII(const
   Printf("  '%s' is ascii string '%s'\n", g.name, (char*)g.beg);
 }
 
+static const char *MaybeDemangleGlobalName(const char *name) {
+  // We can spoil names of globals with C linkage, so use an heuristic
+  // approach to check if the name should be demangled.
+  return (name[0] == '_' && name[1] == 'Z') ? Demangle(name) : name;
+}
+
 bool DescribeAddressRelativeToGlobal(uptr addr, uptr size,
                                      const __asan_global &g) {
   static const uptr kMinimalDistanceFromAnotherGlobal = 64;
@@ -208,7 +214,7 @@ bool DescribeAddressRelativeToGlobal(upt
     Printf("%p is located %zd bytes inside", (void*)addr, addr - g.beg);
   }
   Printf(" of global variable '%s' from '%s' (0x%zx) of size %zu\n",
-             g.name, g.module_name, g.beg, g.size);
+             MaybeDemangleGlobalName(g.name), g.module_name, g.beg, g.size);
   Printf("%s", d.EndLocation());
   PrintGlobalNameIfASCII(g);
   return true;

Added: compiler-rt/trunk/lib/asan/lit_tests/global-demangle.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/global-demangle.cc?rev=178131&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/global-demangle.cc (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/global-demangle.cc Wed Mar 27 05:41:22 2013
@@ -0,0 +1,17 @@
+// Don't run through %symbolize to avoid c++filt demangling.
+// RUN: %clangxx_asan -m64 -O0 %s -o %t && %t 2>&1 | FileCheck %s
+
+namespace XXX {
+class YYY {
+ public:
+  static int ZZZ[];
+};
+int YYY::ZZZ[] = {0, 1, 2, 3};
+}
+
+int main(int argc, char **argv) {
+  return XXX::YYY::ZZZ[argc + 5];  // BOOM
+  // CHECK: {{READ of size 4 at 0x.*}}
+  // CHECK: {{0x.* is located 8 bytes to the right of global variable}}
+  // CHECK: 'XXX::YYY::ZZZ' {{.*}} of size 16
+}





More information about the llvm-commits mailing list