Code and comment cleanups [NFC]
authorGreg Clayton <clayborg@gmail.com>
Thu, 30 May 2019 17:03:35 +0000 (17:03 +0000)
committerGreg Clayton <clayborg@gmail.com>
Thu, 30 May 2019 17:03:35 +0000 (17:03 +0000)
Changes:
- update comments to detail the info can come from .debug_info or .debug_types
- Rename "debug_info_data" to "data" now that we can get data from .debug_info or .debug_types.
- Also call DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr(...) instead of manually grabbing abbreviation.

llvm-svn: 362116

lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h

index c8684d2..27db5c0 100644 (file)
@@ -33,16 +33,15 @@ using namespace lldb_private;
 using namespace std;
 extern int g_verbose;
 
-// Extract a debug info entry for a given compile unit from the .debug_info and
-// .debug_abbrev data within the SymbolFileDWARF class starting at the given
-// offset
-bool DWARFDebugInfoEntry::Extract(const DWARFDataExtractor &debug_info_data,
+// Extract a debug info entry for a given DWARFUnit from the data
+// starting at the offset in offset_ptr
+bool DWARFDebugInfoEntry::Extract(const DWARFDataExtractor &data,
                                   const DWARFUnit *cu,
                                   lldb::offset_t *offset_ptr) {
   m_offset = *offset_ptr;
   m_parent_idx = 0;
   m_sibling_idx = 0;
-  const uint64_t abbr_idx = debug_info_data.GetULEB128(offset_ptr);
+  const uint64_t abbr_idx = data.GetULEB128(offset_ptr);
   lldbassert(abbr_idx <= UINT16_MAX);
   m_abbr_idx = abbr_idx;
 
@@ -51,10 +50,7 @@ bool DWARFDebugInfoEntry::Extract(const DWARFDataExtractor &debug_info_data,
 
   if (m_abbr_idx) {
     lldb::offset_t offset = *offset_ptr;
-
-    const DWARFAbbreviationDeclaration *abbrevDecl =
-        cu->GetAbbreviations()->GetAbbreviationDeclaration(m_abbr_idx);
-
+    auto *abbrevDecl = GetAbbreviationDeclarationPtr(cu);
     if (abbrevDecl == nullptr) {
       cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError(
           "{0x%8.8x}: invalid abbreviation code %u, please file a bug and "
@@ -66,14 +62,14 @@ bool DWARFDebugInfoEntry::Extract(const DWARFDataExtractor &debug_info_data,
     }
     m_tag = abbrevDecl->Tag();
     m_has_children = abbrevDecl->HasChildren();
-    // Skip all data in the .debug_info for the attributes
+    // Skip all data in the .debug_info or .debug_types for the attributes
     const uint32_t numAttributes = abbrevDecl->NumAttributes();
     uint32_t i;
     dw_form_t form;
     for (i = 0; i < numAttributes; ++i) {
       form = abbrevDecl->GetFormByIndexUnchecked(i);
-
-      llvm::Optional<uint8_t> fixed_skip_size = DWARFFormValue::GetFixedSize(form, cu);
+      llvm::Optional<uint8_t> fixed_skip_size =
+          DWARFFormValue::GetFixedSize(form, cu);
       if (fixed_skip_size)
         offset += *fixed_skip_size;
       else {
@@ -83,24 +79,24 @@ bool DWARFDebugInfoEntry::Extract(const DWARFDataExtractor &debug_info_data,
           uint32_t form_size = 0;
           switch (form) {
           // Blocks if inlined data that have a length field and the data bytes
-          // inlined in the .debug_info
+          // inlined in the .debug_info/.debug_types
           case DW_FORM_exprloc:
           case DW_FORM_block:
-            form_size = debug_info_data.GetULEB128(&offset);
+            form_size = data.GetULEB128(&offset);
             break;
           case DW_FORM_block1:
-            form_size = debug_info_data.GetU8_unchecked(&offset);
+            form_size = data.GetU8_unchecked(&offset);
             break;
           case DW_FORM_block2:
-            form_size = debug_info_data.GetU16_unchecked(&offset);
+            form_size = data.GetU16_unchecked(&offset);
             break;
           case DW_FORM_block4:
-            form_size = debug_info_data.GetU32_unchecked(&offset);
+            form_size = data.GetU32_unchecked(&offset);
             break;
 
           // Inlined NULL terminated C-strings
           case DW_FORM_string:
-            debug_info_data.GetCStr(&offset);
+            data.GetCStr(&offset);
             break;
 
           // Compile unit address sized values
@@ -166,17 +162,17 @@ bool DWARFDebugInfoEntry::Extract(const DWARFDataExtractor &debug_info_data,
           case DW_FORM_GNU_addr_index:
           case DW_FORM_GNU_str_index:
           case DW_FORM_strx:
-            debug_info_data.Skip_LEB128(&offset);
+            data.Skip_LEB128(&offset);
             break;
 
           case DW_FORM_indirect:
             form_is_indirect = true;
-            form = debug_info_data.GetULEB128(&offset);
+            form = data.GetULEB128(&offset);
             break;
 
           case DW_FORM_strp:
           case DW_FORM_sec_offset:
-            debug_info_data.GetU32(&offset);
+            data.GetU32(&offset);
             break;
 
           case DW_FORM_implicit_const:
@@ -247,10 +243,10 @@ bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
   lldb::ModuleSP module = dwarf2Data->GetObjectFile()->GetModule();
 
   if (abbrevDecl) {
-    const DWARFDataExtractor &debug_info_data = cu->GetData();
+    const DWARFDataExtractor &data = cu->GetData();
     lldb::offset_t offset = GetFirstAttributeOffset();
 
-    if (!debug_info_data.ValidOffset(offset))
+    if (!data.ValidOffset(offset))
       return false;
 
     const uint32_t numAttributes = abbrevDecl->NumAttributes();
@@ -261,7 +257,7 @@ bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
       dw_attr_t attr;
       abbrevDecl->GetAttrAndFormValueByIndex(i, attr, form_value);
 
-      if (form_value.ExtractValue(debug_info_data, &offset)) {
+      if (form_value.ExtractValue(data, &offset)) {
         switch (attr) {
         case DW_AT_low_pc:
           lo_pc = form_value.Address();
@@ -347,9 +343,9 @@ bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
           if (frame_base) {
             if (form_value.BlockData()) {
               uint32_t block_offset =
-                  form_value.BlockData() - debug_info_data.GetDataStart();
+                  form_value.BlockData() - data.GetDataStart();
               uint32_t block_length = form_value.Unsigned();
-              *frame_base = DWARFExpression(module, debug_info_data, cu,
+              *frame_base = DWARFExpression(module, data, cu,
                                             block_offset, block_length);
             } else {
               const DWARFDataExtractor &debug_loc_data =
@@ -416,32 +412,30 @@ bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
 // stream.
 void DWARFDebugInfoEntry::Dump(const DWARFUnit *cu, Stream &s,
                                uint32_t recurse_depth) const {
-  const DWARFDataExtractor &debug_info_data = cu->GetData();
+  const DWARFDataExtractor &data = cu->GetData();
   lldb::offset_t offset = m_offset;
 
-  if (debug_info_data.ValidOffset(offset)) {
-    dw_uleb128_t abbrCode = debug_info_data.GetULEB128(&offset);
+  if (data.ValidOffset(offset)) {
+    dw_uleb128_t abbrCode = data.GetULEB128(&offset);
 
     s.Printf("\n0x%8.8x: ", m_offset);
     s.Indent();
     if (abbrCode != m_abbr_idx) {
       s.Printf("error: DWARF has been modified\n");
     } else if (abbrCode) {
-      const DWARFAbbreviationDeclaration *abbrevDecl =
-          cu->GetAbbreviations()->GetAbbreviationDeclaration(abbrCode);
-
+      auto *abbrevDecl = GetAbbreviationDeclarationPtr(cu);
       if (abbrevDecl) {
         s.PutCString(DW_TAG_value_to_name(abbrevDecl->Tag()));
         s.Printf(" [%u] %c\n", abbrCode, abbrevDecl->HasChildren() ? '*' : ' ');
 
-        // Dump all data in the .debug_info for the attributes
+        // Dump all data in the .debug_info/.debug_types for the attributes
         const uint32_t numAttributes = abbrevDecl->NumAttributes();
         for (uint32_t i = 0; i < numAttributes; ++i) {
           DWARFFormValue form_value(cu);
           dw_attr_t attr;
           abbrevDecl->GetAttrAndFormValueByIndex(i, attr, form_value);
 
-          DumpAttribute(cu, debug_info_data, &offset, s, attr, form_value);
+          DumpAttribute(cu, data, &offset, s, attr, form_value);
         }
 
         const DWARFDebugInfoEntry *child = GetFirstChild();
@@ -470,7 +464,7 @@ void DWARFDebugInfoEntry::Dump(const DWARFUnit *cu, Stream &s,
 // display of attributes is done (disassemble location lists, show enumeration
 // values for attributes, etc).
 void DWARFDebugInfoEntry::DumpAttribute(
-    const DWARFUnit *cu, const DWARFDataExtractor &debug_info_data,
+    const DWARFUnit *cu, const DWARFDataExtractor &data,
     lldb::offset_t *offset_ptr, Stream &s, dw_attr_t attr,
     DWARFFormValue &form_value) {
   bool show_form = s.GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowForm);
@@ -482,7 +476,7 @@ void DWARFDebugInfoEntry::DumpAttribute(
     s.Printf("[%s", DW_FORM_value_to_name(form_value.Form()));
   }
 
-  if (!form_value.ExtractValue(debug_info_data, offset_ptr))
+  if (!form_value.ExtractValue(data, offset_ptr))
     return;
 
   if (show_form) {
@@ -517,7 +511,7 @@ void DWARFDebugInfoEntry::DumpAttribute(
     const uint8_t *blockData = form_value.BlockData();
     if (blockData) {
       // Location description is inlined in data in the form value
-      DWARFDataExtractor locationData(debug_info_data,
+      DWARFDataExtractor locationData(data,
                                       (*offset_ptr) - form_value.Unsigned(),
                                       form_value.Unsigned());
       DWARFExpression::PrintDWARFExpression(
@@ -564,7 +558,7 @@ size_t DWARFDebugInfoEntry::GetAttributes(
     uint32_t curr_depth) const {
   auto abbrevDecl = GetAbbreviationDeclarationPtr(cu);
   if (abbrevDecl) {
-    const DWARFDataExtractor &debug_info_data = cu->GetData();
+    const DWARFDataExtractor &data = cu->GetData();
     lldb::offset_t offset = GetFirstAttributeOffset();
 
     const uint32_t num_attributes = abbrevDecl->NumAttributes();
@@ -593,7 +587,7 @@ size_t DWARFDebugInfoEntry::GetAttributes(
       }
 
       if ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin)) {
-        if (form_value.ExtractValue(debug_info_data, &offset)) {
+        if (form_value.ExtractValue(data, &offset)) {
           DWARFDIE spec_die = form_value.Reference();
           if (spec_die)
             spec_die.GetAttributes(attributes, curr_depth + 1);
@@ -603,7 +597,7 @@ size_t DWARFDebugInfoEntry::GetAttributes(
         if (fixed_skip_size)
           offset += *fixed_skip_size;
         else
-          DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
+          DWARFFormValue::SkipValue(form, data, &offset, cu);
       }
     }
   } else {
@@ -614,10 +608,10 @@ size_t DWARFDebugInfoEntry::GetAttributes(
 
 // GetAttributeValue
 //
-// Get the value of an attribute and return the .debug_info offset of the
-// attribute if it was properly extracted into form_value, or zero if we fail
-// since an offset of zero is invalid for an attribute (it would be a compile
-// unit header).
+// Get the value of an attribute and return the .debug_info or .debug_types
+// offset of the attribute if it was properly extracted into form_value,
+// or zero if we fail since an offset of zero is invalid for an attribute (it
+// would be a compile unit header).
 dw_offset_t DWARFDebugInfoEntry::GetAttributeValue(
     const DWARFUnit *cu, const dw_attr_t attr, DWARFFormValue &form_value,
     dw_offset_t *end_attr_offset_ptr,
@@ -635,18 +629,18 @@ dw_offset_t DWARFDebugInfoEntry::GetAttributeValue(
     uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr);
 
     if (attr_idx != DW_INVALID_INDEX) {
-      const DWARFDataExtractor &debug_info_data = cu->GetData();
+      const DWARFDataExtractor &data = cu->GetData();
       lldb::offset_t offset = GetFirstAttributeOffset();
 
       uint32_t idx = 0;
       while (idx < attr_idx)
         DWARFFormValue::SkipValue(abbrevDecl->GetFormByIndex(idx++),
-                                  debug_info_data, &offset, cu);
+                                  data, &offset, cu);
 
       const dw_offset_t attr_offset = offset;
       form_value.SetUnit(cu);
       form_value.SetForm(abbrevDecl->GetFormByIndex(idx));
-      if (form_value.ExtractValue(debug_info_data, &offset)) {
+      if (form_value.ExtractValue(data, &offset)) {
         if (end_attr_offset_ptr)
           *end_attr_offset_ptr = offset;
         return attr_offset;
index 77a9757..1e7b5f2 100644 (file)
@@ -43,7 +43,7 @@ public:
   void BuildFunctionAddressRangeTable(const DWARFUnit *cu,
                                       DWARFDebugAranges *debug_aranges) const;
 
-  bool Extract(const lldb_private::DWARFDataExtractor &debug_info_data,
+  bool Extract(const lldb_private::DWARFDataExtractor &data,
                const DWARFUnit *cu, lldb::offset_t *offset_ptr);
 
   bool LookupAddress(const dw_addr_t address, const DWARFUnit *cu,
@@ -107,7 +107,7 @@ public:
 
   static void
   DumpAttribute(const DWARFUnit *cu,
-                const lldb_private::DWARFDataExtractor &debug_info_data,
+                const lldb_private::DWARFDataExtractor &data,
                 lldb::offset_t *offset_ptr, lldb_private::Stream &s,
                 dw_attr_t attr, DWARFFormValue &form_value);
 
@@ -169,8 +169,7 @@ public:
   void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }
 
 protected:
-  dw_offset_t
-      m_offset; // Offset within the .debug_info of the start of this entry
+  dw_offset_t m_offset; // Offset within the .debug_info/.debug_types
   uint32_t m_parent_idx; // How many to subtract from "this" to get the parent.
                          // If zero this die has no parent
   uint32_t m_sibling_idx : 31, // How many to add to "this" to get the sibling.