From: Alexey Samsonov Date: Wed, 27 Mar 2013 10:41:22 +0000 (+0000) Subject: [ASan] Demangle global names in error reports. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7152debedd8db358812ed1090b9056037c8b3f6a;p=platform%2Fupstream%2Fllvm.git [ASan] Demangle global names in error reports. llvm-svn: 178131 --- diff --git a/compiler-rt/lib/asan/asan_report.cc b/compiler-rt/lib/asan/asan_report.cc index 11ffa43..522d713 100644 --- a/compiler-rt/lib/asan/asan_report.cc +++ b/compiler-rt/lib/asan/asan_report.cc @@ -189,6 +189,12 @@ static void PrintGlobalNameIfASCII(const __asan_global &g) { 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(uptr addr, uptr size, 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; diff --git a/compiler-rt/lib/asan/lit_tests/global-demangle.cc b/compiler-rt/lib/asan/lit_tests/global-demangle.cc new file mode 100644 index 0000000..94d2849 --- /dev/null +++ b/compiler-rt/lib/asan/lit_tests/global-demangle.cc @@ -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 +}