[Lldb-commits] [lldb] r363910 - DWARF: Provide accessors to DIERef fields

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 20 01:24:46 PDT 2019


Author: labath
Date: Thu Jun 20 01:24:46 2019
New Revision: 363910

URL: http://llvm.org/viewvc/llvm-project?rev=363910&view=rev
Log:
DWARF: Provide accessors to DIERef fields

Summary:
Instead of accessing the fields directly, use accessor functions to
provide access to the DIERef components. This allows us to decouple the
external interface, from the internal representation. The external
interface can use llvm::Optional and similar goodies, while the data can
still be stored internally in a more compact representation.

I also document the purpose of the existing DIERef fields.

The main motivation for this change is a need to introduce an additional
field to the DIERef class, but I believe the change has its own merit.

Reviewers: JDevlieghere, aprantl, clayborg

Subscribers: arphaman, lldb-commits

Differential Revision: https://reviews.llvm.org/D63400

Modified:
    lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp?rev=363910&r1=363909&r2=363910&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp Thu Jun 20 01:24:46 2019
@@ -160,7 +160,7 @@ void AppleDWARFIndex::ReportInvalidDIERe
   m_module.ReportErrorIfModifyDetected(
       "the DWARF debug information has been modified (accelerator table had "
       "bad die 0x%8.8x for '%s')\n",
-      ref.die_offset, name.str().c_str());
+      ref.die_offset(), name.str().c_str());
 }
 
 void AppleDWARFIndex::Dump(Stream &s) {

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.cpp?rev=363910&r1=363909&r2=363910&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.cpp Thu Jun 20 01:24:46 2019
@@ -7,3 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "DIERef.h"
+#include "llvm/Support/Format.h"
+
+void llvm::format_provider<DIERef>::format(const DIERef &ref, raw_ostream &OS,
+                                           StringRef Style) {
+  OS << (ref.section() == DIERef::DebugInfo ? "INFO" : "TYPE");
+  if (ref.unit_offset())
+    OS << "/" << format_hex_no_prefix(*ref.unit_offset(), 8);
+  OS << "/" << format_hex_no_prefix(ref.die_offset(), 8);
+}

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h?rev=363910&r1=363909&r2=363910&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h Thu Jun 20 01:24:46 2019
@@ -10,19 +10,51 @@
 #define SymbolFileDWARF_DIERef_h_
 
 #include "lldb/Core/dwarf.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/Support/FormatProviders.h"
 #include <vector>
 
-struct DIERef {
+/// Identifies a DWARF debug info entry within a given Module. It contains three
+/// "coordinates":
+/// - section: identifies the section of the debug info entry: debug_info or
+///   debug_types
+/// - unit_offset: the offset of the unit containing the debug info entry. For
+///   regular (unsplit) units, this field is optional, as the die_offset is
+///   enough to uniquely identify the containing unit. For split units, this
+///   field must contain the offset of the skeleton unit in the main object
+///   file.
+/// - die_offset: The offset of te debug info entry as an absolute offset from
+///   the beginning of the section specified in the section field.
+class DIERef {
+public:
   enum Section : uint8_t { DebugInfo, DebugTypes };
 
-  DIERef(Section s, dw_offset_t c, dw_offset_t d)
-      : section(s), cu_offset(c), die_offset(d) {}
-
-  Section section;
-  dw_offset_t cu_offset;
-  dw_offset_t die_offset;
+  DIERef(Section s, llvm::Optional<dw_offset_t> u, dw_offset_t d)
+      : m_section(s), m_unit_offset(u.getValueOr(DW_INVALID_OFFSET)),
+        m_die_offset(d) {}
+
+  Section section() const { return static_cast<Section>(m_section); }
+
+  llvm::Optional<dw_offset_t> unit_offset() const {
+    if (m_unit_offset != DW_INVALID_OFFSET)
+      return m_unit_offset;
+    return llvm::None;
+  }
+
+  dw_offset_t die_offset() const { return m_die_offset; }
+
+private:
+  unsigned m_section : 1;
+  dw_offset_t m_unit_offset;
+  dw_offset_t m_die_offset;
 };
 
 typedef std::vector<DIERef> DIEArray;
 
+namespace llvm {
+template<> struct format_provider<DIERef> {
+  static void format(const DIERef &ref, raw_ostream &OS, StringRef Style);
+};
+} // namespace llvm
+
 #endif // SymbolFileDWARF_DIERef_h_

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp?rev=363910&r1=363909&r2=363910&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp Thu Jun 20 01:24:46 2019
@@ -149,10 +149,9 @@ DWARFUnit *DWARFDebugInfo::GetUnitAtOffs
 }
 
 DWARFUnit *DWARFDebugInfo::GetUnit(const DIERef &die_ref) {
-  if (die_ref.cu_offset == DW_INVALID_OFFSET)
-    return GetUnitContainingDIEOffset(die_ref.section, die_ref.die_offset);
-  else
-    return GetUnitAtOffset(die_ref.section, die_ref.cu_offset);
+  if (die_ref.unit_offset())
+    return GetUnitAtOffset(die_ref.section(), *die_ref.unit_offset());
+  return GetUnitContainingDIEOffset(die_ref.section(), die_ref.die_offset());
 }
 
 DWARFUnit *
@@ -194,7 +193,7 @@ DWARFDIE
 DWARFDebugInfo::GetDIE(const DIERef &die_ref) {
   DWARFUnit *cu = GetUnit(die_ref);
   if (cu)
-    return cu->GetDIE(die_ref.die_offset);
+    return cu->GetDIE(die_ref.die_offset());
   return DWARFDIE(); // Not found
 }
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp?rev=363910&r1=363909&r2=363910&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp Thu Jun 20 01:24:46 2019
@@ -166,7 +166,7 @@ void DebugNamesDWARFIndex::GetCompleteOb
       continue;
 
     DWARFUnit *cu = m_debug_info.GetUnitAtOffset(DIERef::Section::DebugInfo,
-                                                 ref->cu_offset);
+                                                 *ref->unit_offset());
     if (!cu || !cu->Supports_DW_AT_APPLE_objc_complete_type()) {
       incomplete_types.push_back(*ref);
       continue;

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h?rev=363910&r1=363909&r2=363910&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h Thu Jun 20 01:24:46 2019
@@ -61,7 +61,7 @@ public:
     DIEInfo(dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h);
 
     explicit operator DIERef() const {
-      return DIERef(DIERef::Section::DebugInfo, DW_INVALID_OFFSET, die_offset);
+      return DIERef(DIERef::Section::DebugInfo, llvm::None, die_offset);
     }
   };
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp?rev=363910&r1=363909&r2=363910&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp Thu Jun 20 01:24:46 2019
@@ -26,6 +26,7 @@ void NameToDIE::Finalize() {
 }
 
 void NameToDIE::Insert(ConstString name, const DIERef &die_ref) {
+  assert(die_ref.unit_offset().hasValue());
   m_map.Append(name, die_ref);
 }
 
@@ -44,7 +45,7 @@ size_t NameToDIE::FindAllEntriesForCompi
   const uint32_t size = m_map.GetSize();
   for (uint32_t i = 0; i < size; ++i) {
     const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i);
-    if (cu_offset == die_ref.cu_offset)
+    if (cu_offset == *die_ref.unit_offset())
       info_array.push_back(die_ref);
   }
   return info_array.size() - initial_size;
@@ -53,10 +54,8 @@ size_t NameToDIE::FindAllEntriesForCompi
 void NameToDIE::Dump(Stream *s) {
   const uint32_t size = m_map.GetSize();
   for (uint32_t i = 0; i < size; ++i) {
-    ConstString cstr = m_map.GetCStringAtIndex(i);
-    const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i);
-    s->Printf("%p: {0x%8.8x/0x%8.8x} \"%s\"\n", (const void *)cstr.GetCString(),
-              die_ref.cu_offset, die_ref.die_offset, cstr.GetCString());
+    s->Format("{0} \"{1}\"\n", m_map.GetValueAtIndexUnchecked(i),
+              m_map.GetCStringAtIndexUnchecked(i));
   }
 }
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=363910&r1=363909&r2=363910&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Thu Jun 20 01:24:46 2019
@@ -277,8 +277,9 @@ public:
   }
 
   lldb::user_id_t GetUID(const DIERef &ref) {
-    return GetID() | ref.die_offset |
-           (lldb::user_id_t(ref.section == DIERef::Section::DebugTypes) << 63);
+    return GetID() | ref.die_offset() |
+           (lldb::user_id_t(ref.section() == DIERef::Section::DebugTypes)
+            << 63);
   }
 
   virtual std::unique_ptr<SymbolFileDWARFDwo>

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp?rev=363910&r1=363909&r2=363910&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp Thu Jun 20 01:24:46 2019
@@ -124,7 +124,8 @@ SymbolFileDWARFDwo::GetTypeSystemForLang
 
 DWARFDIE
 SymbolFileDWARFDwo::GetDIE(const DIERef &die_ref) {
-  lldbassert(die_ref.cu_offset == m_base_dwarf_cu.GetOffset() ||
-             die_ref.cu_offset == DW_INVALID_OFFSET);
-  return DebugInfo()->GetDIEForDIEOffset(die_ref.section, die_ref.die_offset);
+  lldbassert(!die_ref.unit_offset() ||
+             *die_ref.unit_offset() == m_base_dwarf_cu.GetOffset());
+  return DebugInfo()->GetDIEForDIEOffset(die_ref.section(),
+                                         die_ref.die_offset());
 }




More information about the lldb-commits mailing list