labath created this revision. labath added reviewers: aprantl, clayborg, JDevlieghere.
The previous attempt and moving section handling over to DWARFContext (D59611 <https://reviews.llvm.org/D59611>) failed because it did not take into account the dwo sections correctly. All DWARFContexts (even those in SymbolFileDWARFDwo) used the main module for loading the sections, but in the dwo scenario some sections should come from the dwo file. This patch fixes that by making the DWARFContext aware of whether it a dwo context or a regular one. A dwo context gets two sections lists, and it knows where to look for a particular type of a section. This isn't fully consistent with how the llvm DWARFContext behaves, because that one leaves it up to the user to know whether it should ask for a dwo section or not. However, for the time being, it seems useful to have a single entity which knows how to peice together the debug info in dwo and non-dwo scenarios. The rough roadmap for the future is: - port over the rest of the sections to DWARFContext - find a way to get rid of SymbolFileDWARFDwo/Dwp/DwpDwo. This will likely involve adding the ability for the DWARFContext to spawn dwo sub-contexts, similarly to how it's done in llvm. - get rid of the special handling of the "dwo" contexts by making sure everything knows whether it should ask for the .dwo version of the section or not (similarly to how llvm's DWARFUnits do that) To demonstrate how the DWARFContext should behave in this new world, I port the debug_info section (which is debug_info.dwo in the dwo file) handling to DWARFContext. The rest of the sections will come in subsequent patches. https://reviews.llvm.org/D62012 Files: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp source/Plugins/SymbolFile/DWARF/DWARFContext.cpp source/Plugins/SymbolFile/DWARF/DWARFContext.h source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h @@ -47,7 +47,6 @@ const lldb_private::DWARFDataExtractor &get_debug_abbrev_data() override; const lldb_private::DWARFDataExtractor &get_debug_addr_data() override; - const lldb_private::DWARFDataExtractor &get_debug_info_data() override; const lldb_private::DWARFDataExtractor &get_debug_str_data() override; const lldb_private::DWARFDataExtractor &get_debug_str_offsets_data() override; Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp @@ -21,8 +21,9 @@ SymbolFileDWARFDwo::SymbolFileDWARFDwo(ObjectFileSP objfile, DWARFUnit *dwarf_cu) - : SymbolFileDWARF(objfile.get()), m_obj_file_sp(objfile), - m_base_dwarf_cu(dwarf_cu) { + : SymbolFileDWARF(objfile.get(), objfile->GetSectionList( + /*update_module_section_list*/ false)), + m_obj_file_sp(objfile), m_base_dwarf_cu(dwarf_cu) { SetID(((lldb::user_id_t)dwarf_cu->GetID()) << 32); } @@ -129,10 +130,6 @@ return m_data_debug_addr.m_data; } -const DWARFDataExtractor &SymbolFileDWARFDwo::get_debug_info_data() { - return GetCachedSectionData(eSectionTypeDWARFDebugInfoDwo, m_data_debug_info); -} - const DWARFDataExtractor &SymbolFileDWARFDwo::get_debug_str_data() { return GetCachedSectionData(eSectionTypeDWARFDebugStrDwo, m_data_debug_str); } Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -84,7 +84,8 @@ // Constructors and Destructors - SymbolFileDWARF(lldb_private::ObjectFile *ofile); + SymbolFileDWARF(lldb_private::ObjectFile *ofile, + lldb_private::SectionList *dwo_section_list); ~SymbolFileDWARF() override; @@ -214,7 +215,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_frame_data(); - virtual const lldb_private::DWARFDataExtractor &get_debug_info_data(); const lldb_private::DWARFDataExtractor &get_debug_line_data(); const lldb_private::DWARFDataExtractor &get_debug_line_str_data(); const lldb_private::DWARFDataExtractor &get_debug_macro_data(); @@ -315,6 +315,8 @@ void DumpClangAST(lldb_private::Stream &s) override; + lldb_private::DWARFContext &GetDWARFContext() { return m_context; } + protected: typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *> DIEToTypePtr; Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -200,7 +200,8 @@ } SymbolFile *SymbolFileDWARF::CreateInstance(ObjectFile *obj_file) { - return new SymbolFileDWARF(obj_file); + return new SymbolFileDWARF(obj_file, + /*dwo_section_list*/ nullptr); } TypeList *SymbolFileDWARF::GetTypeList() { @@ -348,18 +349,19 @@ return DWARFDIE(); } -SymbolFileDWARF::SymbolFileDWARF(ObjectFile *objfile) +SymbolFileDWARF::SymbolFileDWARF(ObjectFile *objfile, + SectionList *dwo_section_list) : SymbolFile(objfile), UserID(0x7fffffff00000000), // 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_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_context(objfile->GetModule()->GetSectionList(), dwo_section_list), + 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() {} @@ -563,10 +565,6 @@ return GetCachedSectionData(eSectionTypeDWARFDebugFrame, m_data_debug_frame); } -const DWARFDataExtractor &SymbolFileDWARF::get_debug_info_data() { - return GetCachedSectionData(eSectionTypeDWARFDebugInfo, m_data_debug_info); -} - const DWARFDataExtractor &SymbolFileDWARF::get_debug_line_data() { return GetCachedSectionData(eSectionTypeDWARFDebugLine, m_data_debug_line); } @@ -670,7 +668,7 @@ static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION, static_cast<void *>(this)); - if (get_debug_info_data().GetByteSize() > 0) { + if (m_context.getOrLoadDebugInfoData().GetByteSize() > 0) { m_info = llvm::make_unique<DWARFDebugInfo>(m_context); m_info->SetDwarfData(this); } Index: source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp @@ -8,7 +8,9 @@ #include <assert.h> +#include "lldb/Core/Module.h" #include "lldb/Core/dwarf.h" +#include "lldb/Symbol/ObjectFile.h" #include "lldb/Utility/Stream.h" #include "DWARFDebugInfo.h" Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -80,7 +80,7 @@ return; lldb::offset_t offset = 0; - const auto &debug_info_data = m_dwarf2Data->get_debug_info_data(); + const auto &debug_info_data = m_context.getOrLoadDebugInfoData(); while (debug_info_data.ValidOffset(offset)) { llvm::Expected<DWARFUnitSP> cu_sp = DWARFCompileUnit::extract( Index: source/Plugins/SymbolFile/DWARF/DWARFContext.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFContext.h +++ source/Plugins/SymbolFile/DWARF/DWARFContext.h @@ -10,20 +10,29 @@ #define LLDB_PLUGINS_SYMBOLFILE_DWARF_DWARFCONTEXT_H #include "DWARFDataExtractor.h" -#include "lldb/Core/Module.h" +#include "lldb/Core/Section.h" #include "llvm/ADT/Optional.h" #include <memory> namespace lldb_private { class DWARFContext { private: - Module &m_module; + SectionList *m_main_section_list; + SectionList *m_dwo_section_list; + llvm::Optional<DWARFDataExtractor> m_data_debug_aranges; + llvm::Optional<DWARFDataExtractor> m_data_debug_info; + + bool isDwo() { return m_dwo_section_list != nullptr; } public: - explicit DWARFContext(Module &module); + explicit DWARFContext(SectionList *main_section_list, + SectionList *dwo_section_list) + : m_main_section_list(main_section_list), + m_dwo_section_list(dwo_section_list) {} const DWARFDataExtractor &getOrLoadArangesData(); + const DWARFDataExtractor &getOrLoadDebugInfoData(); }; } // namespace lldb_private Index: source/Plugins/SymbolFile/DWARF/DWARFContext.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFContext.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFContext.cpp @@ -13,9 +13,8 @@ using namespace lldb; using namespace lldb_private; -static DWARFDataExtractor LoadSection(Module &module, +static DWARFDataExtractor LoadSection(SectionList *section_list, SectionType section_type) { - SectionList *section_list = module.GetSectionList(); if (!section_list) return DWARFDataExtractor(); @@ -29,16 +28,23 @@ } static const DWARFDataExtractor & -LoadOrGetSection(Module &module, SectionType section_type, +LoadOrGetSection(SectionList *section_list, SectionType section_type, llvm::Optional<DWARFDataExtractor> &extractor) { if (!extractor) - extractor = LoadSection(module, section_type); + extractor = LoadSection(section_list, section_type); return *extractor; } -DWARFContext::DWARFContext(Module &module) : m_module(module) {} - const DWARFDataExtractor &DWARFContext::getOrLoadArangesData() { - return LoadOrGetSection(m_module, eSectionTypeDWARFDebugAranges, + return LoadOrGetSection(m_main_section_list, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); } + +const DWARFDataExtractor &DWARFContext::getOrLoadDebugInfoData() { + if (isDwo()) + return LoadOrGetSection(m_dwo_section_list, eSectionTypeDWARFDebugInfoDwo, + m_data_debug_info); + else + return LoadOrGetSection(m_main_section_list, eSectionTypeDWARFDebugInfo, + m_data_debug_info); +} Index: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp @@ -106,5 +106,5 @@ } const lldb_private::DWARFDataExtractor &DWARFCompileUnit::GetData() const { - return m_dwarf->get_debug_info_data(); + return m_dwarf->GetDWARFContext().getOrLoadDebugInfoData(); }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits