Skip to content

Commit 03d6005

Browse files
bulbazordadrian-prantl
authored andcommitted
[lldb] Modify the DWARFDebugAbbrev interface to be closer to LLVM's (llvm#67190)
I want to work towards unifying the implementations. It would be a lot easier to do if LLDB's DWARFDebugAbbrev looked more similar to LLVM's implementation, so this change moves in that direction. (cherry picked from commit d3505c2)
1 parent 4a194b3 commit 03d6005

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,30 @@ using namespace lldb;
1515
using namespace lldb_private;
1616

1717
// DWARFDebugAbbrev constructor
18-
DWARFDebugAbbrev::DWARFDebugAbbrev()
19-
: m_abbrevCollMap(), m_prev_abbr_offset_pos(m_abbrevCollMap.end()) {}
18+
DWARFDebugAbbrev::DWARFDebugAbbrev(const DWARFDataExtractor &data)
19+
: m_abbrevCollMap(), m_prev_abbr_offset_pos(m_abbrevCollMap.end()),
20+
m_data(data.GetAsLLVM()) {}
2021

2122
// DWARFDebugAbbrev::Parse()
22-
llvm::Error DWARFDebugAbbrev::parse(const DWARFDataExtractor &data) {
23-
llvm::DataExtractor llvm_data = data.GetAsLLVM();
23+
llvm::Error DWARFDebugAbbrev::parse() {
24+
if (!m_data)
25+
return llvm::Error::success();
26+
2427
lldb::offset_t offset = 0;
2528

26-
while (llvm_data.isValidOffset(offset)) {
29+
while (m_data->isValidOffset(offset)) {
2730
uint32_t initial_cu_offset = offset;
2831
DWARFAbbreviationDeclarationSet abbrevDeclSet;
2932

30-
llvm::Error error = abbrevDeclSet.extract(llvm_data, &offset);
31-
if (error)
33+
llvm::Error error = abbrevDeclSet.extract(*m_data, &offset);
34+
if (error) {
35+
m_data = std::nullopt;
3236
return error;
37+
}
3338

3439
m_abbrevCollMap[initial_cu_offset] = abbrevDeclSet;
3540
}
41+
m_data = std::nullopt;
3642
m_prev_abbr_offset_pos = m_abbrevCollMap.end();
3743
return llvm::ErrorSuccess();
3844
}

lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@ typedef DWARFAbbreviationDeclarationCollMap::const_iterator
2929

3030
class DWARFDebugAbbrev {
3131
public:
32-
DWARFDebugAbbrev();
32+
DWARFDebugAbbrev(const lldb_private::DWARFDataExtractor &data);
3333
const DWARFAbbreviationDeclarationSet *
3434
GetAbbreviationDeclarationSet(dw_offset_t cu_abbr_offset) const;
3535
/// Extract all abbreviations for a particular compile unit. Returns
3636
/// llvm::ErrorSuccess() on success, and an appropriate llvm::Error object
3737
/// otherwise.
38-
llvm::Error parse(const lldb_private::DWARFDataExtractor &data);
38+
llvm::Error parse();
3939
void GetUnsupportedForms(std::set<dw_form_t> &invalid_forms) const;
4040

4141
protected:
4242
DWARFAbbreviationDeclarationCollMap m_abbrevCollMap;
4343
mutable DWARFAbbreviationDeclarationCollMapConstIter m_prev_abbr_offset_pos;
44+
mutable std::optional<llvm::DataExtractor> m_data;
4445
};
4546

4647
#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGABBREV_H

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,8 @@ DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() {
624624
if (debug_abbrev_data.GetByteSize() == 0)
625625
return nullptr;
626626

627-
auto abbr = std::make_unique<DWARFDebugAbbrev>();
628-
llvm::Error error = abbr->parse(debug_abbrev_data);
627+
auto abbr = std::make_unique<DWARFDebugAbbrev>(debug_abbrev_data);
628+
llvm::Error error = abbr->parse();
629629
if (error) {
630630
Log *log = GetLog(DWARFLog::DebugInfo);
631631
LLDB_LOG_ERROR(log, std::move(error),

0 commit comments

Comments
 (0)