1 //===-- SymbolFileDWARFDwo.cpp --------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "SymbolFileDWARFDwo.h" 10 11 #include "lldb/Core/Section.h" 12 #include "lldb/Expression/DWARFExpression.h" 13 #include "lldb/Symbol/ObjectFile.h" 14 #include "lldb/Utility/LLDBAssert.h" 15 #include "llvm/Support/Casting.h" 16 17 #include "DWARFCompileUnit.h" 18 #include "DWARFDebugInfo.h" 19 #include "DWARFUnit.h" 20 21 using namespace lldb; 22 using namespace lldb_private; 23 24 char SymbolFileDWARFDwo::ID; 25 26 SymbolFileDWARFDwo::SymbolFileDWARFDwo(SymbolFileDWARF &base_symbol_file, 27 ObjectFileSP objfile, uint32_t id) 28 : SymbolFileDWARF(objfile, objfile->GetSectionList( 29 /*update_module_section_list*/ false)), 30 m_base_symbol_file(base_symbol_file) { 31 SetID(user_id_t(id) << 32); 32 } 33 34 void SymbolFileDWARFDwo::LoadSectionData(lldb::SectionType sect_type, 35 DWARFDataExtractor &data) { 36 const SectionList *section_list = 37 m_objfile_sp->GetSectionList(false /* update_module_section_list */); 38 if (section_list) { 39 SectionSP section_sp(section_list->FindSectionByType(sect_type, true)); 40 if (section_sp) { 41 42 if (m_objfile_sp->ReadSectionData(section_sp.get(), data) != 0) 43 return; 44 45 data.Clear(); 46 } 47 } 48 49 SymbolFileDWARF::LoadSectionData(sect_type, data); 50 } 51 52 DWARFCompileUnit *SymbolFileDWARFDwo::GetCompileUnit() { 53 if (!m_cu) 54 m_cu = ComputeCompileUnit(); 55 return m_cu; 56 } 57 58 DWARFCompileUnit *SymbolFileDWARFDwo::ComputeCompileUnit() { 59 DWARFDebugInfo *debug_info = DebugInfo(); 60 if (!debug_info) 61 return nullptr; 62 63 // Right now we only support dwo files with one compile unit. If we don't have 64 // type units, we can just check for the unit count. 65 if (!debug_info->ContainsTypeUnits() && debug_info->GetNumUnits() == 1) 66 return llvm::cast<DWARFCompileUnit>(debug_info->GetUnitAtIndex(0)); 67 68 // Otherwise, we have to run through all units, and find the compile unit that 69 // way. 70 DWARFCompileUnit *cu = nullptr; 71 for (size_t i = 0; i < debug_info->GetNumUnits(); ++i) { 72 if (auto *candidate = 73 llvm::dyn_cast<DWARFCompileUnit>(debug_info->GetUnitAtIndex(i))) { 74 if (cu) 75 return nullptr; // More that one CU found. 76 cu = candidate; 77 } 78 } 79 return cu; 80 } 81 82 DWARFUnit * 83 SymbolFileDWARFDwo::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) { 84 return GetCompileUnit(); 85 } 86 87 SymbolFileDWARF::DIEToTypePtr &SymbolFileDWARFDwo::GetDIEToType() { 88 return GetBaseSymbolFile().GetDIEToType(); 89 } 90 91 SymbolFileDWARF::DIEToVariableSP &SymbolFileDWARFDwo::GetDIEToVariable() { 92 return GetBaseSymbolFile().GetDIEToVariable(); 93 } 94 95 SymbolFileDWARF::DIEToClangType & 96 SymbolFileDWARFDwo::GetForwardDeclDieToClangType() { 97 return GetBaseSymbolFile().GetForwardDeclDieToClangType(); 98 } 99 100 SymbolFileDWARF::ClangTypeToDIE & 101 SymbolFileDWARFDwo::GetForwardDeclClangTypeToDie() { 102 return GetBaseSymbolFile().GetForwardDeclClangTypeToDie(); 103 } 104 105 size_t SymbolFileDWARFDwo::GetObjCMethodDIEOffsets( 106 lldb_private::ConstString class_name, DIEArray &method_die_offsets) { 107 return GetBaseSymbolFile().GetObjCMethodDIEOffsets(class_name, 108 method_die_offsets); 109 } 110 111 UniqueDWARFASTTypeMap &SymbolFileDWARFDwo::GetUniqueDWARFASTTypeMap() { 112 return GetBaseSymbolFile().GetUniqueDWARFASTTypeMap(); 113 } 114 115 lldb::TypeSP SymbolFileDWARFDwo::FindDefinitionTypeForDWARFDeclContext( 116 const DWARFDeclContext &die_decl_ctx) { 117 return GetBaseSymbolFile().FindDefinitionTypeForDWARFDeclContext( 118 die_decl_ctx); 119 } 120 121 lldb::TypeSP SymbolFileDWARFDwo::FindCompleteObjCDefinitionTypeForDIE( 122 const DWARFDIE &die, lldb_private::ConstString type_name, 123 bool must_be_implementation) { 124 return GetBaseSymbolFile().FindCompleteObjCDefinitionTypeForDIE( 125 die, type_name, must_be_implementation); 126 } 127 128 llvm::Expected<TypeSystem &> 129 SymbolFileDWARFDwo::GetTypeSystemForLanguage(LanguageType language) { 130 return GetBaseSymbolFile().GetTypeSystemForLanguage(language); 131 } 132 133 DWARFDIE 134 SymbolFileDWARFDwo::GetDIE(const DIERef &die_ref) { 135 if (*die_ref.dwo_num() == GetDwoNum()) 136 return DebugInfo()->GetDIE(die_ref); 137 return GetBaseSymbolFile().GetDIE(die_ref); 138 } 139