Index: lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt +++ lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt @@ -7,6 +7,7 @@ DWARFAttribute.cpp DWARFBaseDIE.cpp DWARFCompileUnit.cpp + DWARFContext.cpp DWARFDataExtractor.cpp DWARFDebugAbbrev.cpp DWARFDebugAranges.cpp Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h =================================================================== --- /dev/null +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h @@ -0,0 +1,36 @@ +//===-- DWARFContext.h ------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_PLUGINS_SYMBOLFILE_DWARF_DWARFCONTEXT_H +#define LLDB_PLUGINS_SYMBOLFILE_DWARF_DWARFCONTEXT_H + +#include "DWARFDataExtractor.h" +#include "lldb/Core/Module.h" +#include "llvm/ADT/Optional.h" +#include + +namespace lldb_private { +class DWARFContext { +private: + Module &m_module; + llvm::Optional m_dwarf_data; + + llvm::Optional m_data_debug_aranges; + +public: + explicit DWARFContext(Module &module); + + void SetDwarfData(const DWARFDataExtractor &dwarf); + + const DWARFDataExtractor *maybeLoadArangesData(); + + const DWARFDataExtractor *getArangesData() const; +}; +} // namespace lldb_private + +#endif Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp =================================================================== --- /dev/null +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp @@ -0,0 +1,52 @@ +#include "DWARFContext.h" + +#include "lldb/Core/Section.h" + +using namespace lldb; +using namespace lldb_private; + +static const DWARFDataExtractor *LoadOrGetSection( + Module &module, const llvm::Optional &mapped_dwarf_data, + SectionType section_type, llvm::Optional &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(); + if (!section_list) + return nullptr; + + auto section_sp = section_list->FindSectionByType(section_type, true); + if (!section_sp) + return nullptr; + + if (mapped_dwarf_data.hasValue()) { + extractor->SetData(*mapped_dwarf_data, section_sp->GetOffset(), + section_sp->GetFileSize()); + return extractor.getPointer(); + } + + module.GetObjectFile()->ReadSectionData(section_sp.get(), *extractor); + return extractor.getPointer(); +} + +DWARFContext::DWARFContext(Module &module) : m_module(module) {} + +void DWARFContext::SetDwarfData(const DWARFDataExtractor &dwarf) { + m_dwarf_data = dwarf; +} + +const DWARFDataExtractor *DWARFContext::maybeLoadArangesData() { + return LoadOrGetSection(m_module, m_dwarf_data, eSectionTypeDWARFDebugAranges, + m_data_debug_aranges); +} + +const DWARFDataExtractor *DWARFContext::getArangesData() const { + if (!m_data_debug_aranges.hasValue()) + return nullptr; + + return m_data_debug_aranges.getPointer(); +} Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h @@ -19,6 +19,10 @@ #include "lldb/lldb-private.h" #include "llvm/Support/Error.h" +namespace lldb_private { +class DWARFContext; +} + typedef std::multimap CStringToDIEMap; typedef CStringToDIEMap::iterator CStringToDIEMapIter; @@ -33,7 +37,8 @@ const uint32_t depth, void *userData); DWARFDebugInfo(); - void SetDwarfData(SymbolFileDWARF *dwarf2Data); + void SetDwarfData(SymbolFileDWARF *dwarf2Data, + lldb_private::DWARFContext *dwarf_context); size_t GetNumCompileUnits(); DWARFUnit *GetCompileUnitAtIndex(uint32_t idx); @@ -62,6 +67,7 @@ // Member variables //---------------------------------------------------------------------- SymbolFileDWARF *m_dwarf2Data; + lldb_private::DWARFContext *m_dwarf_context; CompileUnitColl m_compile_units; std::unique_ptr m_cu_aranges_up; // A quick address to compile unit table Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -17,7 +17,7 @@ #include "lldb/Utility/Stream.h" #include "DWARFCompileUnit.h" -#include "DWARFDebugAranges.h" +#include "DWARFContext.h" #include "DWARFDebugAranges.h" #include "DWARFDebugInfo.h" #include "DWARFDebugInfoEntry.h" @@ -36,8 +36,10 @@ //---------------------------------------------------------------------- // SetDwarfData //---------------------------------------------------------------------- -void DWARFDebugInfo::SetDwarfData(SymbolFileDWARF *dwarf2Data) { +void DWARFDebugInfo::SetDwarfData(SymbolFileDWARF *dwarf2Data, + lldb_private::DWARFContext *dwarf_context) { m_dwarf2Data = dwarf2Data; + m_dwarf_context = dwarf_context; m_compile_units.clear(); } @@ -48,10 +50,10 @@ assert(m_dwarf2Data); m_cu_aranges_up = llvm::make_unique(); - const DWARFDataExtractor &debug_aranges_data = - m_dwarf2Data->get_debug_aranges_data(); - if (debug_aranges_data.GetByteSize() > 0) { - llvm::Error error = m_cu_aranges_up->extract(debug_aranges_data); + const DWARFDataExtractor *debug_aranges_data = + m_dwarf_context->maybeLoadArangesData(); + if (debug_aranges_data) { + llvm::Error error = m_cu_aranges_up->extract(*debug_aranges_data); if (error) return std::move(error); } Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -30,6 +30,7 @@ #include "lldb/Utility/RangeMap.h" #include "lldb/lldb-private.h" +#include "DWARFContext.h" #include "DWARFDataExtractor.h" #include "DWARFDefines.h" #include "DWARFIndex.h" @@ -227,7 +228,6 @@ virtual const lldb_private::DWARFDataExtractor &get_debug_abbrev_data(); virtual const lldb_private::DWARFDataExtractor &get_debug_addr_data(); - const lldb_private::DWARFDataExtractor &get_debug_aranges_data(); const lldb_private::DWARFDataExtractor &get_debug_frame_data(); virtual const lldb_private::DWARFDataExtractor &get_debug_info_data(); const lldb_private::DWARFDataExtractor &get_debug_line_data(); @@ -458,11 +458,11 @@ llvm::once_flag m_dwp_symfile_once_flag; std::unique_ptr m_dwp_symfile; + lldb_private::DWARFContext m_dwarf_context; lldb_private::DWARFDataExtractor m_dwarf_data; DWARFDataSegment m_data_debug_abbrev; DWARFDataSegment m_data_debug_addr; - DWARFDataSegment m_data_debug_aranges; DWARFDataSegment m_data_debug_frame; DWARFDataSegment m_data_debug_info; DWARFDataSegment m_data_debug_line; Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -355,12 +355,13 @@ << 32), // Used by SymbolFileDWARFDebugMap to // when this class parses .o files to // contain the .o file index/ID - m_debug_map_module_wp(), m_debug_map_symfile(NULL), m_data_debug_abbrev(), - m_data_debug_aranges(), m_data_debug_frame(), m_data_debug_info(), - m_data_debug_line(), m_data_debug_macro(), m_data_debug_loc(), - m_data_debug_ranges(), m_data_debug_rnglists(), m_data_debug_str(), - m_data_apple_names(), m_data_apple_types(), m_data_apple_namespaces(), - m_abbr(), m_info(), m_line(), m_fetched_external_modules(false), + m_debug_map_module_wp(), m_debug_map_symfile(NULL), + m_dwarf_context(*objfile->GetModule()), m_data_debug_abbrev(), + m_data_debug_frame(), m_data_debug_info(), m_data_debug_line(), + m_data_debug_macro(), m_data_debug_loc(), m_data_debug_ranges(), + m_data_debug_rnglists(), m_data_debug_str(), m_data_apple_names(), + m_data_apple_types(), m_data_apple_namespaces(), m_abbr(), m_info(), + m_line(), m_fetched_external_modules(false), m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate), m_ranges(), m_unique_ast_type_map() {} @@ -400,8 +401,10 @@ Section *section = section_list->FindSectionByName(GetDWARFMachOSegmentName()).get(); - if (section) + if (section) { m_obj_file->ReadSectionData(section, m_dwarf_data); + m_dwarf_context.SetDwarfData(m_dwarf_data); + } } if (!GetGlobalPluginProperties()->IgnoreFileIndexes()) { @@ -573,11 +576,6 @@ return GetCachedSectionData(eSectionTypeDWARFDebugAddr, m_data_debug_addr); } -const DWARFDataExtractor &SymbolFileDWARF::get_debug_aranges_data() { - return GetCachedSectionData(eSectionTypeDWARFDebugAranges, - m_data_debug_aranges); -} - const DWARFDataExtractor &SymbolFileDWARF::get_debug_frame_data() { return GetCachedSectionData(eSectionTypeDWARFDebugFrame, m_data_debug_frame); } @@ -692,7 +690,7 @@ if (get_debug_info_data().GetByteSize() > 0) { m_info.reset(new DWARFDebugInfo()); if (m_info) { - m_info->SetDwarfData(this); + m_info->SetDwarfData(this, &m_dwarf_context); } } }