llvm-symbolizer: don't always run demangler on global object names
authorAlexey Samsonov <samsonov@google.com>
Wed, 16 Oct 2013 09:54:49 +0000 (09:54 +0000)
committerAlexey Samsonov <samsonov@google.com>
Wed, 16 Oct 2013 09:54:49 +0000 (09:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192781 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-symbolizer/LLVMSymbolize.cpp
tools/llvm-symbolizer/LLVMSymbolize.h

index 45c86641d8a046f59d459e345007e978cedfb2d1..320ab3fcbcfe43ebcdef3b0401291bbc9c25e81f 100644 (file)
@@ -196,7 +196,7 @@ std::string LLVMSymbolizer::symbolizeData(const std::string &ModuleName,
   if (Opts.UseSymbolTable) {
     if (ModuleInfo *Info = getOrCreateModuleInfo(ModuleName)) {
       if (Info->symbolizeData(ModuleOffset, Name, Start, Size) && Opts.Demangle)
-        Name = DemangleName(Name);
+        Name = DemangleGlobalName(Name);
     }
   }
   std::stringstream ss;
@@ -436,5 +436,11 @@ std::string LLVMSymbolizer::DemangleName(const std::string &Name) {
 #endif
 }
 
+std::string LLVMSymbolizer::DemangleGlobalName(const std::string &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.substr(0, 2) == "_Z") ? DemangleName(Name) : Name;
+}
+
 } // namespace symbolize
 } // namespace llvm
index 03c765cc9c309a8d6aa282b0f03b4c070bddd1dc..eb2666a542c97344df9269f5aa9f63838c9541f3 100644 (file)
@@ -71,6 +71,7 @@ private:
   ObjectFile *getObjectFileFromBinary(Binary *Bin, const std::string &ArchName);
 
   std::string printDILineInfo(DILineInfo LineInfo) const;
+  static std::string DemangleGlobalName(const std::string &Name);
 
   // Owns all the parsed binaries and object files.
   SmallVector<Binary*, 4> ParsedBinariesAndObjects;