Try again to revert the bad patch. The tree was reverted for some unknown reason
[oota-llvm.git] / tools / llvm-symbolizer / llvm-symbolizer.cpp
index 79bdcedd3b644f8dbd11a3db24ec714f944f3ca6..6a5eb4a6620bb71582c0320f721fb9123a27ac44 100644 (file)
@@ -29,7 +29,6 @@
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/raw_ostream.h"
-
 #include <cstdio>
 #include <cstring>
 #include <map>
@@ -170,18 +169,6 @@ typedef ModuleMapTy::iterator ModuleMapIter;
 
 static ModuleMapTy Modules;
 
-static bool isFullNameOfDwarfSection(const StringRef &FullName,
-                                     const StringRef &ShortName) {
-  static const char kDwarfPrefix[] = "__DWARF,";
-  StringRef Name = FullName;
-  // Skip "__DWARF," prefix.
-  if (Name.startswith(kDwarfPrefix))
-    Name = Name.substr(strlen(kDwarfPrefix));
-  // Skip . and _ prefixes.
-  Name = Name.substr(Name.find_first_not_of("._"));
-  return (Name == ShortName);
-}
-
 // Returns true if the object endianness is known.
 static bool getObjectEndianness(const ObjectFile *Obj,
                                 bool &IsLittleEndian) {
@@ -190,41 +177,6 @@ static bool getObjectEndianness(const ObjectFile *Obj,
   return true;
 }
 
-static void getDebugInfoSections(const ObjectFile *Obj,
-                                 StringRef &DebugInfoSection,
-                                 StringRef &DebugAbbrevSection,
-                                 StringRef &DebugLineSection,
-                                 StringRef &DebugArangesSection, 
-                                 StringRef &DebugStringSection, 
-                                 StringRef &DebugRangesSection) {
-  if (Obj == 0)
-    return;
-  error_code ec;
-  for (section_iterator i = Obj->begin_sections(),
-                        e = Obj->end_sections();
-                        i != e; i.increment(ec)) {
-    if (error(ec)) break;
-    StringRef Name;
-    if (error(i->getName(Name))) continue;
-    StringRef Data;
-    if (error(i->getContents(Data))) continue;
-    if (isFullNameOfDwarfSection(Name, "debug_info"))
-      DebugInfoSection = Data;
-    else if (isFullNameOfDwarfSection(Name, "debug_abbrev"))
-      DebugAbbrevSection = Data;
-    else if (isFullNameOfDwarfSection(Name, "debug_line"))
-      DebugLineSection = Data;
-    // Don't use debug_aranges for now, as address ranges contained
-    // there may not cover all instructions in the module
-    // else if (isFullNameOfDwarfSection(Name, "debug_aranges"))
-    //   DebugArangesSection = Data;
-    else if (isFullNameOfDwarfSection(Name, "debug_str"))
-      DebugStringSection = Data;
-    else if (isFullNameOfDwarfSection(Name, "debug_ranges"))
-      DebugRangesSection = Data;
-  }
-}
-
 static ObjectFile *getObjectFile(const std::string &Path) {
   OwningPtr<MemoryBuffer> Buff;
   MemoryBuffer::getFile(Path, Buff);
@@ -246,6 +198,7 @@ static ModuleInfo *getOrCreateModuleInfo(const std::string &ModuleName) {
     return I->second;
 
   ObjectFile *Obj = getObjectFile(ModuleName);
+  ObjectFile *DbgObj = Obj;
   if (Obj == 0) {
     // Module name doesn't point to a valid object file.
     Modules.insert(make_pair(ModuleName, (ModuleInfo*)0));
@@ -255,15 +208,6 @@ static ModuleInfo *getOrCreateModuleInfo(const std::string &ModuleName) {
   DIContext *Context = 0;
   bool IsLittleEndian;
   if (getObjectEndianness(Obj, IsLittleEndian)) {
-    StringRef DebugInfo;
-    StringRef DebugAbbrev;
-    StringRef DebugLine;
-    StringRef DebugAranges;
-    StringRef DebugString;
-    StringRef DebugRanges;
-    getDebugInfoSections(Obj, DebugInfo, DebugAbbrev, DebugLine,
-                         DebugAranges, DebugString, DebugRanges);
-    
     // On Darwin we may find DWARF in separate object file in
     // resource directory.
     if (isa<MachOObjectFile>(Obj)) {
@@ -271,14 +215,9 @@ static ModuleInfo *getOrCreateModuleInfo(const std::string &ModuleName) {
           ModuleName);
       ObjectFile *ResourceObj = getObjectFile(ResourceName);
       if (ResourceObj != 0)
-        getDebugInfoSections(ResourceObj, DebugInfo, DebugAbbrev, DebugLine,
-                             DebugAranges, DebugString, DebugRanges);
+        DbgObj = ResourceObj;
     }
-
-    Context = DIContext::getDWARFContext(
-        IsLittleEndian, DebugInfo, DebugAbbrev,
-        DebugAranges, DebugLine, DebugString,
-        DebugRanges);
+    Context = DIContext::getDWARFContext(DbgObj);
     assert(Context);
   }
 
@@ -287,9 +226,11 @@ static ModuleInfo *getOrCreateModuleInfo(const std::string &ModuleName) {
   return Info;
 }
 
-// Assume that __cxa_demangle is provided by libcxxabi.
+#if !defined(_MSC_VER)
+// Assume that __cxa_demangle is provided by libcxxabi (except for Windows).
 extern "C" char *__cxa_demangle(const char *mangled_name, char *output_buffer,
                                 size_t *length, int *status);
+#endif
 
 static void printDILineInfo(DILineInfo LineInfo) {
   // By default, DILineInfo contains "<invalid>" for function/filename it
@@ -300,6 +241,7 @@ static void printDILineInfo(DILineInfo LineInfo) {
     std::string FunctionName = LineInfo.getFunctionName();
     if (FunctionName == kDILineInfoBadString)
       FunctionName = kSymbolizerBadString;
+#if !defined(_MSC_VER)
     if (Demangle) {
       int status = 0;
       char *DemangledName = __cxa_demangle(
@@ -309,6 +251,7 @@ static void printDILineInfo(DILineInfo LineInfo) {
         free(DemangledName);
       }
     }
+#endif
     outs() << FunctionName << "\n";
   }
   std::string Filename = LineInfo.getFileName();