Skip to content

Commit 0356cee

Browse files
committed
[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
1 parent f2a1320 commit 0356cee

File tree

3 files changed

+5
-21
lines changed

3 files changed

+5
-21
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,13 @@ class DWARFDebugAbbrev {
6464
mutable std::optional<DataExtractor> Data;
6565

6666
public:
67-
DWARFDebugAbbrev();
67+
DWARFDebugAbbrev(DataExtractor Data);
6868

6969
const DWARFAbbreviationDeclarationSet *
7070
getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const;
7171

7272
void dump(raw_ostream &OS) const;
7373
void parse() const;
74-
void extract(DataExtractor Data);
7574

7675
DWARFAbbreviationDeclarationSetMap::const_iterator begin() const {
7776
parse();
@@ -81,9 +80,6 @@ class DWARFDebugAbbrev {
8180
DWARFAbbreviationDeclarationSetMap::const_iterator end() const {
8281
return AbbrDeclSets.end();
8382
}
84-
85-
private:
86-
void clear();
8783
};
8884

8985
} // end namespace llvm

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -938,9 +938,7 @@ const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() {
938938
return Abbrev.get();
939939

940940
DataExtractor abbrData(DObj->getAbbrevSection(), isLittleEndian(), 0);
941-
942-
Abbrev.reset(new DWARFDebugAbbrev());
943-
Abbrev->extract(abbrData);
941+
Abbrev.reset(new DWARFDebugAbbrev(abbrData));
944942
return Abbrev.get();
945943
}
946944

@@ -949,8 +947,7 @@ const DWARFDebugAbbrev *DWARFContext::getDebugAbbrevDWO() {
949947
return AbbrevDWO.get();
950948

951949
DataExtractor abbrData(DObj->getAbbrevDWOSection(), isLittleEndian(), 0);
952-
AbbrevDWO.reset(new DWARFDebugAbbrev());
953-
AbbrevDWO->extract(abbrData);
950+
AbbrevDWO.reset(new DWARFDebugAbbrev(abbrData));
954951
return AbbrevDWO.get();
955952
}
956953

llvm/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,8 @@ std::string DWARFAbbreviationDeclarationSet::getCodeRange() const {
102102
return Buffer;
103103
}
104104

105-
DWARFDebugAbbrev::DWARFDebugAbbrev() { clear(); }
106-
107-
void DWARFDebugAbbrev::clear() {
108-
AbbrDeclSets.clear();
109-
PrevAbbrOffsetPos = AbbrDeclSets.end();
110-
}
111-
112-
void DWARFDebugAbbrev::extract(DataExtractor Data) {
113-
clear();
114-
this->Data = Data;
115-
}
105+
DWARFDebugAbbrev::DWARFDebugAbbrev(DataExtractor Data)
106+
: AbbrDeclSets(), PrevAbbrOffsetPos(AbbrDeclSets.end()), Data(Data) {}
116107

117108
void DWARFDebugAbbrev::parse() const {
118109
if (!Data)

0 commit comments

Comments
 (0)