[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
This commit is contained in:
@@ -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 @@ public:
|
||||
DWARFAbbreviationDeclarationSetMap::const_iterator end() const {
|
||||
return AbbrDeclSets.end();
|
||||
}
|
||||
|
||||
private:
|
||||
void clear();
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user