[Lldb-commits] [lldb] r360014 - [DWARF] Reimplement/simplify DWARFUnit::GetID

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon May 6 00:45:28 PDT 2019


Author: labath
Date: Mon May  6 00:45:28 2019
New Revision: 360014

URL: http://llvm.org/viewvc/llvm-project?rev=360014&view=rev
Log:
[DWARF] Reimplement/simplify DWARFUnit::GetID

Summary:
The implementation of GetID used a relatively complicated algorithm,
which returned some kind of an offset of the unit in some file
(depending on the debug info flavour). The only thing this ID was used
for was to enable subseqent retrieval of the unit from the SymbolFile.

This can be made simpler if we just make the "ID" of the unit an index
into the list of the units belonging to the symbol file. We already
support indexed access to the units, so each unit already has a well
"index" -- this just makes it accessible from within the unit.

To make the distincion between "id" and "offset" clearer (and help catch
any misuses), I also rename DWARFDebugInfo::GetCompileUnit (which
accesses by offset) into DWARFDebugInfo::GetCompileUnitAtOffset.

On its own, this only brings a minor simplification, but it enables
further simplifications in the DIERef class (coming in a follow-up
patch).

Reviewers: JDevlieghere, clayborg, aprantl

Subscribers: arphaman, jdoerfert, lldb-commits, tberghammer, jankratochvil

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

Modified:
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp?rev=360014&r1=360013&r2=360014&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Mon May  6 00:45:28 2019
@@ -15,17 +15,19 @@
 using namespace lldb;
 using namespace lldb_private;
 
-DWARFCompileUnit::DWARFCompileUnit(SymbolFileDWARF *dwarf2Data)
-    : DWARFUnit(dwarf2Data) {}
+DWARFCompileUnit::DWARFCompileUnit(SymbolFileDWARF *dwarf2Data,
+                                   lldb::user_id_t uid)
+    : DWARFUnit(dwarf2Data, uid) {}
 
-llvm::Expected<DWARFUnitSP>
-DWARFCompileUnit::extract(SymbolFileDWARF *dwarf2Data,
-                          const DWARFDataExtractor &debug_info,
-                          lldb::offset_t *offset_ptr) {
+
+llvm::Expected<DWARFUnitSP> DWARFCompileUnit::extract(
+    SymbolFileDWARF *dwarf2Data, user_id_t uid,
+    const DWARFDataExtractor &debug_info, lldb::offset_t *offset_ptr) {
   assert(debug_info.ValidOffset(*offset_ptr));
 
   // std::make_shared would require the ctor to be public.
-  std::shared_ptr<DWARFCompileUnit> cu_sp(new DWARFCompileUnit(dwarf2Data));
+  std::shared_ptr<DWARFCompileUnit> cu_sp(
+      new DWARFCompileUnit(dwarf2Data, uid));
 
   cu_sp->m_offset = *offset_ptr;
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h?rev=360014&r1=360013&r2=360014&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h Mon May  6 00:45:28 2019
@@ -15,7 +15,7 @@
 class DWARFCompileUnit : public DWARFUnit {
 public:
   static llvm::Expected<DWARFUnitSP>
-  extract(SymbolFileDWARF *dwarf2Data,
+  extract(SymbolFileDWARF *dwarf2Data, lldb::user_id_t uid,
           const lldb_private::DWARFDataExtractor &debug_info,
           lldb::offset_t *offset_ptr);
   void Dump(lldb_private::Stream *s) const override;
@@ -35,7 +35,7 @@ public:
   uint32_t GetHeaderByteSize() const override;
 
 private:
-  DWARFCompileUnit(SymbolFileDWARF *dwarf2Data);
+  DWARFCompileUnit(SymbolFileDWARF *dwarf2Data, lldb::user_id_t uid);
   DISALLOW_COPY_AND_ASSIGN(DWARFCompileUnit);
 };
 

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=360014&r1=360013&r2=360014&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp Mon May  6 00:45:28 2019
@@ -87,8 +87,8 @@ void DWARFDebugInfo::ParseCompileUnitHea
   const auto &debug_info_data = m_dwarf2Data->get_debug_info_data();
 
   while (debug_info_data.ValidOffset(offset)) {
-    llvm::Expected<DWARFUnitSP> cu_sp =
-        DWARFCompileUnit::extract(m_dwarf2Data, debug_info_data, &offset);
+    llvm::Expected<DWARFUnitSP> cu_sp = DWARFCompileUnit::extract(
+        m_dwarf2Data, m_compile_units.size(), debug_info_data, &offset);
 
     if (!cu_sp) {
       // FIXME: Propagate this error up.
@@ -111,7 +111,7 @@ size_t DWARFDebugInfo::GetNumCompileUnit
   return m_compile_units.size();
 }
 
-DWARFUnit *DWARFDebugInfo::GetCompileUnitAtIndex(uint32_t idx) {
+DWARFUnit *DWARFDebugInfo::GetCompileUnitAtIndex(user_id_t idx) {
   DWARFUnit *cu = NULL;
   if (idx < GetNumCompileUnits())
     cu = m_compile_units[idx].get();
@@ -123,8 +123,8 @@ bool DWARFDebugInfo::OffsetLessThanCompi
   return offset < cu_sp->GetOffset();
 }
 
-DWARFUnit *DWARFDebugInfo::GetCompileUnit(dw_offset_t cu_offset,
-                                                 uint32_t *idx_ptr) {
+DWARFUnit *DWARFDebugInfo::GetCompileUnitAtOffset(dw_offset_t cu_offset,
+                                                  uint32_t *idx_ptr) {
   DWARFUnitSP cu_sp;
   uint32_t cu_idx = DW_INVALID_INDEX;
   if (cu_offset != DW_INVALID_OFFSET) {
@@ -160,7 +160,7 @@ DWARFUnit *DWARFDebugInfo::GetCompileUni
   if (die_ref.cu_offset == DW_INVALID_OFFSET)
     return GetCompileUnitContainingDIEOffset(die_ref.die_offset);
   else
-    return GetCompileUnit(die_ref.cu_offset);
+    return GetCompileUnitAtOffset(die_ref.cu_offset);
 }
 
 DWARFUnit *

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h?rev=360014&r1=360013&r2=360014&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h Mon May  6 00:45:28 2019
@@ -40,8 +40,9 @@ public:
   void SetDwarfData(SymbolFileDWARF *dwarf2Data);
 
   size_t GetNumCompileUnits();
-  DWARFUnit *GetCompileUnitAtIndex(uint32_t idx);
-  DWARFUnit *GetCompileUnit(dw_offset_t cu_offset, uint32_t *idx_ptr = NULL);
+  DWARFUnit *GetCompileUnitAtIndex(lldb::user_id_t idx);
+  DWARFUnit *GetCompileUnitAtOffset(dw_offset_t cu_offset,
+                                    uint32_t *idx_ptr = NULL);
   DWARFUnit *GetCompileUnitContainingDIEOffset(dw_offset_t die_offset);
   DWARFUnit *GetCompileUnit(const DIERef &die_ref);
   DWARFDIE GetDIEForDIEOffset(dw_offset_t die_offset);

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp?rev=360014&r1=360013&r2=360014&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp Mon May  6 00:45:28 2019
@@ -29,8 +29,8 @@ using namespace std;
 
 extern int g_verbose;
 
-DWARFUnit::DWARFUnit(SymbolFileDWARF *dwarf)
-    : m_dwarf(dwarf), m_cancel_scopes(false) {}
+DWARFUnit::DWARFUnit(SymbolFileDWARF *dwarf, user_id_t uid)
+    : UserID(uid), m_dwarf(dwarf), m_cancel_scopes(false) {}
 
 DWARFUnit::~DWARFUnit() {}
 
@@ -366,15 +366,6 @@ size_t DWARFUnit::AppendDIEsWithTag(cons
   return dies.size() - old_size;
 }
 
-lldb::user_id_t DWARFUnit::GetID() const {
-  dw_offset_t local_id =
-      m_base_obj_offset != DW_INVALID_OFFSET ? m_base_obj_offset : m_offset;
-  if (m_dwarf)
-    return DIERef(local_id, local_id).GetUID(m_dwarf);
-  else
-    return local_id;
-}
-
 dw_offset_t DWARFUnit::GetNextCompileUnitOffset() const {
   return m_offset + GetLengthByteSize() + GetLength();
 }

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h?rev=360014&r1=360013&r2=360014&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h Mon May  6 00:45:28 2019
@@ -31,7 +31,7 @@ enum DWARFProducer {
   eProcucerOther
 };
 
-class DWARFUnit {
+class DWARFUnit : public lldb_private::UserID {
   using die_iterator_range =
       llvm::iterator_range<DWARFDebugInfoEntry::collection::iterator>;
 
@@ -74,7 +74,6 @@ public:
   virtual uint32_t GetHeaderByteSize() const = 0;
   // Offset of the initial length field.
   dw_offset_t GetOffset() const { return m_offset; }
-  lldb::user_id_t GetID() const;
   /// Get the size in bytes of the length field in the header.
   ///
   /// In DWARF32 this is just 4 bytes
@@ -169,7 +168,7 @@ public:
   }
 
 protected:
-  DWARFUnit(SymbolFileDWARF *dwarf);
+  DWARFUnit(SymbolFileDWARF *dwarf, lldb::user_id_t uid);
 
   SymbolFileDWARF *m_dwarf = nullptr;
   std::unique_ptr<SymbolFileDWARFDwo> m_dwo_symbol_file;

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=360014&r1=360013&r2=360014&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp Mon May  6 00:45:28 2019
@@ -55,7 +55,7 @@ DIERef DebugNamesDWARFIndex::ToDIERef(co
   if (!cu_offset)
     return DIERef();
 
-  DWARFUnit *cu = m_debug_info.GetCompileUnit(*cu_offset);
+  DWARFUnit *cu = m_debug_info.GetCompileUnitAtOffset(*cu_offset);
   if (!cu)
     return DIERef();
 
@@ -164,7 +164,7 @@ void DebugNamesDWARFIndex::GetCompleteOb
     if (!ref)
       continue;
 
-    DWARFUnit *cu = m_debug_info.GetCompileUnit(ref.cu_offset);
+    DWARFUnit *cu = m_debug_info.GetCompileUnitAtOffset(ref.cu_offset);
     if (!cu || !cu->Supports_DW_AT_APPLE_objc_complete_type()) {
       incomplete_types.push_back(ref);
       continue;

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=360014&r1=360013&r2=360014&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Mon May  6 00:45:28 2019
@@ -689,11 +689,8 @@ SymbolFileDWARF::GetDWARFCompileUnit(lld
 
   DWARFDebugInfo *info = DebugInfo();
   if (info) {
-    // Just a normal DWARF file whose user ID for the compile unit is the DWARF
-    // offset itself
-
-    DWARFUnit *dwarf_cu =
-        info->GetCompileUnit((dw_offset_t)comp_unit->GetID());
+    // The compile unit ID is the index of the DWARF unit.
+    DWARFUnit *dwarf_cu = info->GetCompileUnitAtIndex(comp_unit->GetID());
     if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
       dwarf_cu->SetUserData(comp_unit);
     return dwarf_cu;
@@ -781,7 +778,7 @@ lldb::CompUnitSP SymbolFileDWARF::ParseC
 
               // Figure out the compile unit index if we weren't given one
               if (cu_idx == UINT32_MAX)
-                DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
+                cu_idx = dwarf_cu->GetID();
 
               m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(
                   cu_idx, cu_sp);
@@ -1764,7 +1761,7 @@ uint32_t SymbolFileDWARF::ResolveSymbolC
       } else {
         uint32_t cu_idx = DW_INVALID_INDEX;
         DWARFUnit *dwarf_cu =
-            debug_info->GetCompileUnit(cu_offset, &cu_idx);
+            debug_info->GetCompileUnitAtOffset(cu_offset, &cu_idx);
         if (dwarf_cu) {
           sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
           if (sc.comp_unit) {
@@ -3121,7 +3118,7 @@ size_t SymbolFileDWARF::ParseVariablesFo
         return num_variables;
       }
     } else if (sc.comp_unit) {
-      DWARFUnit *dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID());
+      DWARFUnit *dwarf_cu = info->GetCompileUnitAtIndex(sc.comp_unit->GetID());
 
       if (dwarf_cu == NULL)
         return 0;




More information about the lldb-commits mailing list