Don't use a potentially expensive shift if all we want is one set bit.
[oota-llvm.git] / tools / llvm-symbolizer / LLVMSymbolize.cpp
index dfcbacfbe63dcb8cfa753df187b40fd7f6ab2e35..1945d689dee4d8d7365093d8850d0c5f15c2e421 100644 (file)
@@ -74,6 +74,9 @@ ModuleInfo::ModuleInfo(ObjectFile *Obj, DIContext *DICtx)
     StringRef SymbolName;
     if (error(si->getName(SymbolName)))
       continue;
+    // Mach-O symbol table names have leading underscore, skip it.
+    if (Module->isMachO() && SymbolName.size() > 0 && SymbolName[0] == '_')
+      SymbolName = SymbolName.drop_front();
     // FIXME: If a function has alias, there are two entries in symbol table
     // with same address size. Make sure we choose the correct one.
     SymbolMapTy &M = SymbolType == SymbolRef::ST_Function ? Functions : Objects;
@@ -199,6 +202,8 @@ std::string LLVMSymbolizer::symbolizeData(const std::string &ModuleName,
 void LLVMSymbolizer::flush() {
   DeleteContainerSeconds(Modules);
   DeleteContainerPointers(ParsedBinariesAndObjects);
+  BinaryForPath.clear();
+  ObjectFileForArch.clear();
 }
 
 static std::string getDarwinDWARFResourceForPath(const std::string &Path) {
@@ -274,6 +279,11 @@ LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
   std::string BinaryName = ModuleName;
   std::string ArchName = Opts.DefaultArch;
   size_t ColonPos = ModuleName.find(':');
+#if defined(_WIN32)
+  // Recognize a drive letter on win32.
+  if (ColonPos == 1 && isalpha(ModuleName[0]))
+    ColonPos = ModuleName.find(':', 2);
+#endif
   if (ColonPos != std::string::npos) {
     BinaryName = ModuleName.substr(0, ColonPos);
     ArchName = ModuleName.substr(ColonPos + 1);