JDevlieghere created this revision.
JDevlieghere added reviewers: labath, clayborg, shafik.
Herald added a subscriber: aprantl.
Herald added a project: LLDB.

When talking to Shafik about D67994 <https://reviews.llvm.org/D67994>, we 
discovered that `dw_tag_t` is a typedef for `uint16_t`. I believe it would be 
better to typedef it to `llvm::dwarf::Tag` instead, so we can use the full 
power of the DWARF utilities in LLVM without having to do the cast. With this 
approach, we only have to do the cast when reading the ULEB value.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D68005

Files:
  lldb/include/lldb/Core/dwarf.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
  lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h

Index: lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
+++ lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
@@ -53,7 +53,7 @@
 
   struct DIEInfo {
     dw_offset_t die_offset = DW_INVALID_OFFSET;
-    dw_tag_t tag = 0;
+    dw_tag_t tag = llvm::dwarf::DW_TAG_null;
 
     /// Any flags for this DIEInfo.
     uint32_t type_flags = 0;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
@@ -23,7 +23,7 @@
 class DWARFDeclContext {
 public:
   struct Entry {
-    Entry() : tag(0), name(nullptr) {}
+    Entry() : tag(llvm::dwarf::DW_TAG_null), name(nullptr) {}
     Entry(dw_tag_t t, const char *n) : tag(t), name(n) {}
 
     bool NameMatches(const Entry &rhs) const {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
@@ -31,7 +31,7 @@
 
   DWARFDebugInfoEntry()
       : m_offset(DW_INVALID_OFFSET), m_parent_idx(0), m_sibling_idx(0),
-        m_has_children(false), m_abbr_idx(0), m_tag(0) {}
+        m_has_children(false), m_abbr_idx(0), m_tag(llvm::dwarf::DW_TAG_null) {}
 
   explicit operator bool() const { return m_offset != DW_INVALID_OFFSET; }
   bool operator==(const DWARFDebugInfoEntry &rhs) const;
@@ -178,8 +178,9 @@
       // 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
+  /// A copy of the DW_TAG value so we don't have to go through the compile
+  /// unit abbrev table
+  dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
 };
 
 #endif // SymbolFileDWARF_DWARFDebugInfoEntry_h_
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -192,7 +192,7 @@
     *offset_ptr = offset;
     return true;
   } else {
-    m_tag = 0;
+    m_tag = llvm::dwarf::DW_TAG_null;
     m_has_children = false;
     return true; // NULL debug tag entry
   }
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
@@ -30,7 +30,7 @@
   if (m_die)
     return m_die->Tag();
   else
-    return 0;
+    return llvm::dwarf::DW_TAG_null;
 }
 
 const char *DWARFBaseDIE::GetTagAsCString() const {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
@@ -18,7 +18,8 @@
 using namespace lldb_private;
 
 DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration()
-    : m_code(InvalidCode), m_tag(0), m_has_children(0), m_attributes() {}
+    : m_code(InvalidCode), m_tag(llvm::dwarf::DW_TAG_null), m_has_children(0),
+      m_attributes() {}
 
 DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration(dw_tag_t tag,
                                                            uint8_t has_children)
@@ -33,7 +34,7 @@
     return DWARFEnumState::Complete;
 
   m_attributes.clear();
-  m_tag = data.GetULEB128(offset_ptr);
+  m_tag = static_cast<dw_tag_t>(data.GetULEB128(offset_ptr));
   if (m_tag == DW_TAG_null)
     return llvm::make_error<llvm::object::GenericBinaryError>(
         "abbrev decl requires non-null tag.");
@@ -68,7 +69,7 @@
 }
 
 bool DWARFAbbreviationDeclaration::IsValid() {
-  return m_code != 0 && m_tag != 0;
+  return m_code != 0 && m_tag != llvm::dwarf::DW_TAG_null;
 }
 
 uint32_t
Index: lldb/include/lldb/Core/dwarf.h
===================================================================
--- lldb/include/lldb/Core/dwarf.h
+++ lldb/include/lldb/Core/dwarf.h
@@ -22,7 +22,7 @@
 typedef int32_t dw_sleb128_t;
 typedef uint16_t dw_attr_t;
 typedef uint16_t dw_form_t;
-typedef uint16_t dw_tag_t;
+typedef llvm::dwarf::Tag dw_tag_t;
 typedef uint64_t dw_addr_t; // Dwarf address define that must be big enough for
                             // any addresses in the compile units that get
                             // parsed
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to