1 //===-- SymbolFileDWARFDwo.cpp ----------------------------------*- C++ -*-===// 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 SymbolFileDWARFDwo::SymbolFileDWARFDwo(ObjectFileSP objfile, 25 DWARFCompileUnit &dwarf_cu) 26 : SymbolFileDWARF(objfile.get(), objfile->GetSectionList( 27 /*update_module_section_list*/ false)), 28 m_obj_file_sp(objfile), m_base_dwarf_cu(dwarf_cu) { 29 SetID(((lldb::user_id_t)dwarf_cu.GetID()) << 32); 30 } 31 32 void SymbolFileDWARFDwo::LoadSectionData(lldb::SectionType sect_type, 33 DWARFDataExtractor &data) { 34 const SectionList *section_list = 35 m_obj_file->GetSectionList(false /* update_module_section_list */); 36 if (section_list) { 37 SectionSP section_sp(section_list->FindSectionByType(sect_type, true)); 38 if (section_sp) { 39 40 if (m_obj_file->ReadSectionData(section_sp.get(), data) != 0) 41 return; 42 43 data.Clear(); 44 } 45 } 46 47 SymbolFileDWARF::LoadSectionData(sect_type, data); 48 } 49 50 lldb::CompUnitSP 51 SymbolFileDWARFDwo::ParseCompileUnit(DWARFCompileUnit &dwarf_cu) { 52 assert(GetCompileUnit() == &dwarf_cu && 53 "SymbolFileDWARFDwo::ParseCompileUnit called with incompatible " 54 "compile unit"); 55 return GetBaseSymbolFile().ParseCompileUnit(m_base_dwarf_cu); 56 } 57 58 DWARFCompileUnit *SymbolFileDWARFDwo::GetCompileUnit() { 59 if (!m_cu) 60 m_cu = ComputeCompileUnit(); 61 return m_cu; 62 } 63 64 DWARFCompileUnit *SymbolFileDWARFDwo::ComputeCompileUnit() { 65 DWARFDebugInfo *debug_info = DebugInfo(); 66 if (!debug_info) 67 return nullptr; 68 69 // Right now we only support dwo files with one compile unit. If we don't have 70 // type units, we can just check for the unit count. 71 if (!debug_info->ContainsTypeUnits() && debug_info->GetNumUnits() == 1) 72 return llvm::cast<DWARFCompileUnit>(debug_info->GetUnitAtIndex(0)); 73 74 // Otherwise, we have to run through all units, and find the compile unit that 75 // way. 76 DWARFCompileUnit *cu = nullptr; 77 for (size_t i = 0; i < debug_info->GetNumUnits(); ++i) { 78 if (auto *candidate = 79 llvm::dyn_cast<DWARFCompileUnit>(debug_info->GetUnitAtIndex(i))) { 80 if (cu) 81 return nullptr; // More that one CU found. 82 cu = candidate; 83 } 84 } 85 return cu; 86 } 87 88 DWARFUnit * 89 SymbolFileDWARFDwo::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) { 90 return GetCompileUnit(); 91 } 92 93 SymbolFileDWARF::DIEToTypePtr &SymbolFileDWARFDwo::GetDIEToType() { 94 return GetBaseSymbolFile().GetDIEToType(); 95 } 96 97 SymbolFileDWARF::DIEToVariableSP &SymbolFileDWARFDwo::GetDIEToVariable() { 98 return GetBaseSymbolFile().GetDIEToVariable(); 99 } 100 101 SymbolFileDWARF::DIEToClangType & 102 SymbolFileDWARFDwo::GetForwardDeclDieToClangType() { 103 return GetBaseSymbolFile().GetForwardDeclDieToClangType(); 104 } 105 106 SymbolFileDWARF::ClangTypeToDIE & 107 SymbolFileDWARFDwo::GetForwardDeclClangTypeToDie() { 108 return GetBaseSymbolFile().GetForwardDeclClangTypeToDie(); 109 } 110 111 size_t SymbolFileDWARFDwo::GetObjCMethodDIEOffsets( 112 lldb_private::ConstString class_name, DIEArray &method_die_offsets) { 113 return GetBaseSymbolFile().GetObjCMethodDIEOffsets(class_name, 114 method_die_offsets); 115 } 116 117 UniqueDWARFASTTypeMap &SymbolFileDWARFDwo::GetUniqueDWARFASTTypeMap() { 118 return GetBaseSymbolFile().GetUniqueDWARFASTTypeMap(); 119 } 120 121 lldb::TypeSP SymbolFileDWARFDwo::FindDefinitionTypeForDWARFDeclContext( 122 const DWARFDeclContext &die_decl_ctx) { 123 return GetBaseSymbolFile().FindDefinitionTypeForDWARFDeclContext( 124 die_decl_ctx); 125 } 126 127 lldb::TypeSP SymbolFileDWARFDwo::FindCompleteObjCDefinitionTypeForDIE( 128 const DWARFDIE &die, lldb_private::ConstString type_name, 129 bool must_be_implementation) { 130 return GetBaseSymbolFile().FindCompleteObjCDefinitionTypeForDIE( 131 die, type_name, must_be_implementation); 132 } 133 134 SymbolFileDWARF &SymbolFileDWARFDwo::GetBaseSymbolFile() { 135 return m_base_dwarf_cu.GetSymbolFileDWARF(); 136 } 137 138 DWARFExpression::LocationListFormat 139 SymbolFileDWARFDwo::GetLocationListFormat() const { 140 return DWARFExpression::SplitDwarfLocationList; 141 } 142 143 TypeSystem * 144 SymbolFileDWARFDwo::GetTypeSystemForLanguage(LanguageType language) { 145 return GetBaseSymbolFile().GetTypeSystemForLanguage(language); 146 } 147 148 DWARFDIE 149 SymbolFileDWARFDwo::GetDIE(const DIERef &die_ref) { 150 if (*die_ref.dwo_num() == GetDwoNum()) 151 return DebugInfo()->GetDIE(die_ref); 152 return GetBaseSymbolFile().GetDIE(die_ref); 153 } 154