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