diff options
author | Alexey Samsonov <samsonov@google.com> | 2013-03-27 10:41:22 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2013-03-27 10:41:22 +0000 |
commit | 7152debedd8db358812ed1090b9056037c8b3f6a (patch) | |
tree | 038cf0789d15d22b86e6f1afda6e4196891ad18c | |
parent | ec25de421c8412459cd5735daa15771981b916c1 (diff) | |
download | bcm5719-llvm-7152debedd8db358812ed1090b9056037c8b3f6a.tar.gz bcm5719-llvm-7152debedd8db358812ed1090b9056037c8b3f6a.zip |
[ASan] Demangle global names in error reports.
llvm-svn: 178131
-rw-r--r-- | compiler-rt/lib/asan/asan_report.cc | 8 | ||||
-rw-r--r-- | compiler-rt/lib/asan/lit_tests/global-demangle.cc | 17 |
2 files changed, 24 insertions, 1 deletions
diff --git a/compiler-rt/lib/asan/asan_report.cc b/compiler-rt/lib/asan/asan_report.cc index 11ffa43da76..522d713d1e6 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 00000000000..94d2849fb90 --- /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 +} |