[Lldb-commits] [lldb] r344644 - Code cleanup: Remove DWARFDebugInfoEntry::m_empty_children

Jan Kratochvil via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 16 13:49:15 PDT 2018


Author: jankratochvil
Date: Tue Oct 16 13:49:15 2018
New Revision: 344644

URL: http://llvm.org/viewvc/llvm-project?rev=344644&view=rev
Log:
Code cleanup: Remove DWARFDebugInfoEntry::m_empty_children

It merges DWARFDebugInfoEntry's m_empty_children into m_has_children.
m_empty_children was implemented by rL144983.

As Greg confirmed m_has_children was used to represent what was in the DWARF in
the byte that follows the DW_TAG. m_empty_children was used for DIEs that said
they had children but actually only contain a single NULL tag. It is fine to
not differentiate between the two.

Also changed assert()->lldbassert() for m_abbr_idx 16-bit overflow check as
that could be a tough bug to catch if it ever happens.

I have checked all calls of HasChildren() that this change should not matter to
them. The code even wants to know if there are any children - it does not
matter how the children presence is coded in the binary.

Patch written based on suggestions by Greg Clayton.

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

Modified:
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp?rev=344644&r1=344643&r2=344644&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Tue Oct 16 13:49:15 2018
@@ -40,9 +40,8 @@ bool DWARFDebugInfoEntry::FastExtract(
   m_offset = *offset_ptr;
   m_parent_idx = 0;
   m_sibling_idx = 0;
-  m_empty_children = false;
   const uint64_t abbr_idx = debug_info_data.GetULEB128(offset_ptr);
-  assert(abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE));
+  lldbassert(abbr_idx <= UINT16_MAX);
   m_abbr_idx = abbr_idx;
 
   // assert (fixed_form_sizes);  // For best performance this should be
@@ -220,7 +219,7 @@ bool DWARFDebugInfoEntry::Extract(Symbol
     m_offset = offset;
 
     const uint64_t abbr_idx = debug_info_data.GetULEB128(&offset);
-    assert(abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE));
+    lldbassert(abbr_idx <= UINT16_MAX);
     m_abbr_idx = abbr_idx;
     if (abbr_idx) {
       const DWARFAbbreviationDeclaration *abbrevDecl =
@@ -1836,7 +1835,6 @@ void DWARFDebugInfoEntry::DumpDIECollect
 bool DWARFDebugInfoEntry::operator==(const DWARFDebugInfoEntry &rhs) const {
   return m_offset == rhs.m_offset && m_parent_idx == rhs.m_parent_idx &&
          m_sibling_idx == rhs.m_sibling_idx &&
-         m_empty_children == rhs.m_empty_children &&
          m_abbr_idx == rhs.m_abbr_idx && m_has_children == rhs.m_has_children &&
          m_tag == rhs.m_tag;
 }

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h?rev=344644&r1=344643&r2=344644&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h Tue Oct 16 13:49:15 2018
@@ -43,7 +43,6 @@ typedef UInt32ToDIEMMap::const_iterator
 class DWARFDeclContext;
 
 #define DIE_SIBLING_IDX_BITSIZE 31
-#define DIE_ABBR_IDX_BITSIZE 15
 
 class DWARFDebugInfoEntry {
 public:
@@ -57,8 +56,7 @@ public:
 
   DWARFDebugInfoEntry()
       : m_offset(DW_INVALID_OFFSET), m_parent_idx(0), m_sibling_idx(0),
-        m_empty_children(false), m_abbr_idx(0), m_has_children(false),
-        m_tag(0) {}
+        m_has_children(false), m_abbr_idx(0), m_tag(0) {}
 
   explicit operator bool() const { return m_offset != DW_INVALID_OFFSET; }
   bool operator==(const DWARFDebugInfoEntry &rhs) const;
@@ -227,10 +225,10 @@ public:
   // we don't need to store our child pointer, if we have a child it will
   // be the next entry in the list...
   DWARFDebugInfoEntry *GetFirstChild() {
-    return (HasChildren() && !m_empty_children) ? this + 1 : NULL;
+    return HasChildren() ? this + 1 : NULL;
   }
   const DWARFDebugInfoEntry *GetFirstChild() const {
-    return (HasChildren() && !m_empty_children) ? this + 1 : NULL;
+    return HasChildren() ? this + 1 : NULL;
   }
 
   void GetDeclContextDIEs(DWARFUnit *cu,
@@ -271,10 +269,6 @@ public:
 
   void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }
 
-  bool GetEmptyChildren() const { return m_empty_children; }
-
-  void SetEmptyChildren(bool b) { m_empty_children = b; }
-
   static void
   DumpDIECollection(lldb_private::Stream &strm,
                     DWARFDebugInfoEntry::collection &die_collection);
@@ -285,13 +279,13 @@ protected:
   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.
-      m_empty_children : 1;    // If a DIE says it had children, yet it just
-                               // contained a NULL tag, this will be set.
-  uint32_t m_abbr_idx : DIE_ABBR_IDX_BITSIZE,
-                        m_has_children : 1, // Set to 1 if this DIE has children
-                        m_tag : 16; // A copy of the DW_TAG value so we don't
-                                    // have to go through the compile unit
-                                    // abbrev table
+      // If it is zero, then the DIE doesn't have children, or the
+      // DWARF claimed it had children but the DIE only contained
+      // a single NULL terminating child.
+      m_has_children : 1;
+  uint16_t m_abbr_idx;
+  uint16_t m_tag; // A copy of the DW_TAG value so we don't have to go through
+                  // the compile unit abbrev table
 };
 
 #endif // SymbolFileDWARF_DWARFDebugInfoEntry_h_

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=344644&r1=344643&r2=344644&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp Tue Oct 16 13:49:15 2018
@@ -223,7 +223,7 @@ void DWARFUnit::ExtractDIEsRWLocked() {
           // the list (saves up to 25% in C++ code), we need a way to let the
           // DIE know that it actually doesn't have children.
           if (!m_die_array.empty())
-            m_die_array.back().SetEmptyChildren(true);
+            m_die_array.back().SetHasChildren(false);
         }
       } else {
         die.SetParentIndex(m_die_array.size() - die_index_stack[depth - 1]);
@@ -263,7 +263,7 @@ void DWARFUnit::ExtractDIEsRWLocked() {
   if (!m_die_array.empty()) {
     if (m_first_die) {
       // Only needed for the assertion.
-      m_first_die.SetEmptyChildren(m_die_array.front().GetEmptyChildren());
+      m_first_die.SetHasChildren(m_die_array.front().HasChildren());
       lldbassert(m_first_die == m_die_array.front());
     }
     m_first_die = m_die_array.front();




More information about the lldb-commits mailing list