Add Win32 support to llvm::llvm_execute_on_thread(). Thanks to Aaron Ballman!
[oota-llvm.git] / lib / DebugInfo / DWARFDebugInfoEntry.cpp
index bfe89dd326219f2ffece6d8d572368a6b0952d73..1b089adbe13b5f52f61ba1420ae4391e75184b13 100644 (file)
@@ -28,12 +28,16 @@ void DWARFDebugInfoEntryMinimal::dump(raw_ostream &OS,
   if (debug_info_data.isValidOffset(offset)) {
     uint64_t abbrCode = debug_info_data.getULEB128(&offset);
 
-    OS.indent(indent) << format("\n0x%8.8x: ", Offset);
+    OS << format("\n0x%8.8x: ", Offset);
     if (abbrCode) {
       if (AbbrevDecl) {
-        OS << TagString(AbbrevDecl->getTag())
-           << format(" [%u] %c\n", abbrCode,
-                                   AbbrevDecl->hasChildren() ? '*': ' ');
+        const char *tagString = TagString(getTag());
+        if (tagString)
+          OS.indent(indent) << tagString;
+        else
+          OS.indent(indent) << format("DW_TAG_Unknown_%x", getTag());
+        OS << format(" [%u] %c\n", abbrCode,
+                     AbbrevDecl->hasChildren() ? '*' : ' ');
 
         // Dump all data in the .debug_info for the attributes
         const uint32_t numAttributes = AbbrevDecl->getNumAttributes();
@@ -45,19 +49,17 @@ void DWARFDebugInfoEntryMinimal::dump(raw_ostream &OS,
 
         const DWARFDebugInfoEntryMinimal *child = getFirstChild();
         if (recurseDepth > 0 && child) {
-          indent += 2;
           while (child) {
-            child->dump(OS, cu, recurseDepth-1, indent);
+            child->dump(OS, cu, recurseDepth-1, indent+2);
             child = child->getSibling();
           }
-          indent -= 2;
         }
       } else {
         OS << "Abbreviation code not found in 'debug_abbrev' class for code: "
            << abbrCode << '\n';
       }
     } else {
-      OS << "NULL\n";
+      OS.indent(indent) << "NULL\n";
     }
   }
 }
@@ -68,9 +70,18 @@ void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS,
                                                uint16_t attr,
                                                uint16_t form,
                                                unsigned indent) const {
-  OS.indent(indent) << format("0x%8.8x: ", *offset_ptr)
-                    << AttributeString(attr)
-                    << " [" << FormEncodingString(form) << ']';
+  OS << format("0x%8.8x: ", *offset_ptr);
+  OS.indent(indent+2);
+  const char *attrString = AttributeString(attr);
+  if (attrString)
+    OS << attrString;
+  else
+    OS << format("DW_AT_Unknown_%x", attr);
+  const char *formString = FormEncodingString(form);
+  if (formString)
+    OS << " [" << formString << ']';
+  else
+    OS << format(" [DW_FORM_Unknown_%x]", form);
 
   DWARFFormValue formValue(form);
 
@@ -78,7 +89,7 @@ void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS,
     return;
 
   OS << "\t(";
-  formValue.dump(OS, 0, cu);
+  formValue.dump(OS, cu);
   OS << ")\n";
 }
 
@@ -399,7 +410,8 @@ DWARFDebugInfoEntryMinimal::getAttributeValueAsSigned(
 }
 
 uint64_t
-DWARFDebugInfoEntryMinimal::getAttributeValueAsReference(const DWARFCompileUnit* cu,
+DWARFDebugInfoEntryMinimal::getAttributeValueAsReference(
+                                                  const DWARFCompileUnit* cu,
                                                   const uint16_t attr,
                                                   uint64_t fail_value) const {
   DWARFFormValue form_value;
@@ -407,3 +419,26 @@ DWARFDebugInfoEntryMinimal::getAttributeValueAsReference(const DWARFCompileUnit*
       return form_value.getReference(cu);
   return fail_value;
 }
+
+void
+DWARFDebugInfoEntryMinimal::buildAddressRangeTable(const DWARFCompileUnit *cu,
+                                               DWARFDebugAranges *debug_aranges)
+                                                   const {
+  if (AbbrevDecl) {
+    uint16_t tag = AbbrevDecl->getTag();
+    if (tag == DW_TAG_subprogram) {
+      uint64_t hi_pc = -1ULL;
+      uint64_t lo_pc = getAttributeValueAsUnsigned(cu, DW_AT_low_pc, -1ULL);
+      if (lo_pc != -1ULL)
+        hi_pc = getAttributeValueAsUnsigned(cu, DW_AT_high_pc, -1ULL);
+      if (hi_pc != -1ULL)
+        debug_aranges->appendRange(cu->getOffset(), lo_pc, hi_pc);
+    }
+
+    const DWARFDebugInfoEntryMinimal *child = getFirstChild();
+    while (child) {
+      child->buildAddressRangeTable(cu, debug_aranges);
+      child = child->getSibling();
+    }
+  }
+}