diff options
author | Pavel Labath <pavel@labath.sk> | 2019-05-16 11:19:02 +0000 |
---|---|---|
committer | Pavel Labath <pavel@labath.sk> | 2019-05-16 11:19:02 +0000 |
commit | 1a8630ac2839d0e73fd3b15dc38501e4c6525a7e (patch) | |
tree | 31954e4bbf4b49b797cd48a7008bf2595a3227fa /lldb/source/Plugins/SymbolFile | |
parent | eff622b23cc5d64d7b6d07d34a3ad87420a75b05 (diff) | |
download | bcm5719-llvm-1a8630ac2839d0e73fd3b15dc38501e4c6525a7e.tar.gz bcm5719-llvm-1a8630ac2839d0e73fd3b15dc38501e4c6525a7e.zip |
DWARFContext: Return empty data extractors instead of null pointers
Summary:
There are several reasons for doing this:
- generally, there's no reason to differentiate between a section being
absent and it being present, but empty
- it matches more closely what llvm DWARF parser is doing (which also
doesn't differentiate the two cases)
- SymbolFileDWARF also doesn't differentiate the two cases, which makes
porting the rest of sections easier
- it fixes a bug in how the return-null-if-empty logic was implemented
(it returned nullptr only the second time we tried to get the
debug_aranges section), which meant that we hit an assert when trying
to parse an empty-but-present section
Reviewers: JDevlieghere, clayborg, aprantl
Subscribers: zturner, lldb-commits
Differential Revision: https://reviews.llvm.org/D61942
llvm-svn: 360874
Diffstat (limited to 'lldb/source/Plugins/SymbolFile')
4 files changed, 23 insertions, 27 deletions
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp index d8a44ccacb9..aba2979383d 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp @@ -13,31 +13,32 @@ using namespace lldb; using namespace lldb_private; -static const DWARFDataExtractor * -LoadOrGetSection(Module &module, SectionType section_type, - llvm::Optional<DWARFDataExtractor> &extractor) { - if (extractor.hasValue()) - return extractor->GetByteSize() > 0 ? extractor.getPointer() : nullptr; - - // Initialize to an empty extractor so that we always take the fast path going - // forward. - extractor.emplace(); - - const SectionList *section_list = module.GetSectionList(); +static DWARFDataExtractor LoadSection(Module &module, + SectionType section_type) { + SectionList *section_list = module.GetSectionList(); if (!section_list) - return nullptr; + return DWARFDataExtractor(); auto section_sp = section_list->FindSectionByType(section_type, true); if (!section_sp) - return nullptr; + return DWARFDataExtractor(); - section_sp->GetSectionData(*extractor); - return extractor.getPointer(); + DWARFDataExtractor data; + section_sp->GetSectionData(data); + return data; +} + +static const DWARFDataExtractor & +LoadOrGetSection(Module &module, SectionType section_type, + llvm::Optional<DWARFDataExtractor> &extractor) { + if (!extractor) + extractor = LoadSection(module, section_type); + return *extractor; } DWARFContext::DWARFContext(Module &module) : m_module(module) {} -const DWARFDataExtractor *DWARFContext::getOrLoadArangesData() { +const DWARFDataExtractor &DWARFContext::getOrLoadArangesData() { return LoadOrGetSection(m_module, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h index 02887838705..4059d048aaf 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h @@ -23,7 +23,7 @@ private: public: explicit DWARFContext(Module &module); - const DWARFDataExtractor *getOrLoadArangesData(); + const DWARFDataExtractor &getOrLoadArangesData(); }; } // namespace lldb_private diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp index fcacf59d8b8..4d22c825390 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp @@ -42,8 +42,6 @@ public: // Extract llvm::Error DWARFDebugAranges::extract(const DWARFDataExtractor &debug_aranges_data) { - assert(debug_aranges_data.ValidOffset(0)); - lldb::offset_t offset = 0; DWARFDebugArangeSet set; @@ -65,8 +63,8 @@ DWARFDebugAranges::extract(const DWARFDataExtractor &debug_aranges_data) { } } set.Clear(); - } - return llvm::ErrorSuccess(); + } + return llvm::ErrorSuccess(); } void DWARFDebugAranges::Dump(Log *log) const { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp index de4a48a2c06..0daf489f4d5 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -44,13 +44,10 @@ llvm::Expected<DWARFDebugAranges &> DWARFDebugInfo::GetCompileUnitAranges() { assert(m_dwarf2Data); m_cu_aranges_up = llvm::make_unique<DWARFDebugAranges>(); - const DWARFDataExtractor *debug_aranges_data = + const DWARFDataExtractor &debug_aranges_data = m_context.getOrLoadArangesData(); - if (debug_aranges_data) { - llvm::Error error = m_cu_aranges_up->extract(*debug_aranges_data); - if (error) - return std::move(error); - } + if (llvm::Error error = m_cu_aranges_up->extract(debug_aranges_data)) + return std::move(error); // Make a list of all CUs represented by the arange data in the file. std::set<dw_offset_t> cus_with_data; |