[llvm] 0356cee - [DebugInfo] Change DWARFDebugAbbrev initialization

Alex Langford via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 16 11:19:25 PDT 2023


Author: Alex Langford
Date: 2023-06-16T11:16:16-07:00
New Revision: 0356ceedf2e90459597adfda19db2c52faf7aacd

URL: https://github.com/llvm/llvm-project/commit/0356ceedf2e90459597adfda19db2c52faf7aacd
DIFF: https://github.com/llvm/llvm-project/commit/0356ceedf2e90459597adfda19db2c52faf7aacd.diff

LOG: [DebugInfo] Change DWARFDebugAbbrev initialization

I plan on adding better error handling to DWARFDebugAbbrev, but first I
want us to be able to better reason about a state of a DWARFDebugAbbrev.
I want us to be able to initialize a DWARFDebugAbbrev in its complete
state instead of creating it and then calling an `extract` method
manually. If its Data field is populated, then parsing is not complete.
If Data is `std::nullopt`, then parsing is done and this section is
"finalized" in some sense.

Additionally, I have removed the `clear()` method. This makes sense for other
classes like DWARFAbbreviationDeclaration where we may want to re-use an object
repeatedly to avoid repeated initializations and allocations, but for
DWARFDebugAbbrev we pretty much create one and stick with it.

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

Added: 
    

Modified: 
    llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h
    llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
    llvm/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h
index 76833cc33142b..23c219d65b8be 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h
@@ -64,14 +64,13 @@ class DWARFDebugAbbrev {
   mutable std::optional<DataExtractor> Data;
 
 public:
-  DWARFDebugAbbrev();
+  DWARFDebugAbbrev(DataExtractor Data);
 
   const DWARFAbbreviationDeclarationSet *
   getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const;
 
   void dump(raw_ostream &OS) const;
   void parse() const;
-  void extract(DataExtractor Data);
 
   DWARFAbbreviationDeclarationSetMap::const_iterator begin() const {
     parse();
@@ -81,9 +80,6 @@ class DWARFDebugAbbrev {
   DWARFAbbreviationDeclarationSetMap::const_iterator end() const {
     return AbbrDeclSets.end();
   }
-
-private:
-  void clear();
 };
 
 } // end namespace llvm

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index d9bc78a410d5d..97f7c8ec33cf3 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -938,9 +938,7 @@ const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() {
     return Abbrev.get();
 
   DataExtractor abbrData(DObj->getAbbrevSection(), isLittleEndian(), 0);
-
-  Abbrev.reset(new DWARFDebugAbbrev());
-  Abbrev->extract(abbrData);
+  Abbrev.reset(new DWARFDebugAbbrev(abbrData));
   return Abbrev.get();
 }
 
@@ -949,8 +947,7 @@ const DWARFDebugAbbrev *DWARFContext::getDebugAbbrevDWO() {
     return AbbrevDWO.get();
 
   DataExtractor abbrData(DObj->getAbbrevDWOSection(), isLittleEndian(), 0);
-  AbbrevDWO.reset(new DWARFDebugAbbrev());
-  AbbrevDWO->extract(abbrData);
+  AbbrevDWO.reset(new DWARFDebugAbbrev(abbrData));
   return AbbrevDWO.get();
 }
 

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp
index 54093dd032af0..bd6fae141a76b 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp
@@ -102,17 +102,8 @@ std::string DWARFAbbreviationDeclarationSet::getCodeRange() const {
   return Buffer;
 }
 
-DWARFDebugAbbrev::DWARFDebugAbbrev() { clear(); }
-
-void DWARFDebugAbbrev::clear() {
-  AbbrDeclSets.clear();
-  PrevAbbrOffsetPos = AbbrDeclSets.end();
-}
-
-void DWARFDebugAbbrev::extract(DataExtractor Data) {
-  clear();
-  this->Data = Data;
-}
+DWARFDebugAbbrev::DWARFDebugAbbrev(DataExtractor Data)
+    : AbbrDeclSets(), PrevAbbrOffsetPos(AbbrDeclSets.end()), Data(Data) {}
 
 void DWARFDebugAbbrev::parse() const {
   if (!Data)


        


More information about the llvm-commits mailing list