1 //===-- SymbolFileDWARFDwo.cpp ----------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "SymbolFileDWARFDwo.h"
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"
17 #include "DWARFCompileUnit.h"
18 #include "DWARFDebugInfo.h"
19 #include "DWARFUnit.h"
22 using namespace lldb_private;
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);
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 */);
37 SectionSP section_sp(section_list->FindSectionByType(sect_type, true));
40 if (m_obj_file->ReadSectionData(section_sp.get(), data) != 0)
47 SymbolFileDWARF::LoadSectionData(sect_type, data);
51 SymbolFileDWARFDwo::ParseCompileUnit(DWARFCompileUnit &dwarf_cu) {
52 assert(GetCompileUnit() == &dwarf_cu &&
53 "SymbolFileDWARFDwo::ParseCompileUnit called with incompatible "
55 return GetBaseSymbolFile().ParseCompileUnit(m_base_dwarf_cu);
58 DWARFCompileUnit *SymbolFileDWARFDwo::GetCompileUnit() {
60 m_cu = ComputeCompileUnit();
64 DWARFCompileUnit *SymbolFileDWARFDwo::ComputeCompileUnit() {
65 DWARFDebugInfo *debug_info = DebugInfo();
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));
74 // Otherwise, we have to run through all units, and find the compile unit that
76 DWARFCompileUnit *cu = nullptr;
77 for (size_t i = 0; i < debug_info->GetNumUnits(); ++i) {
79 llvm::dyn_cast<DWARFCompileUnit>(debug_info->GetUnitAtIndex(i))) {
81 return nullptr; // More that one CU found.
89 SymbolFileDWARFDwo::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) {
90 return GetCompileUnit();
93 SymbolFileDWARF::DIEToTypePtr &SymbolFileDWARFDwo::GetDIEToType() {
94 return GetBaseSymbolFile().GetDIEToType();
97 SymbolFileDWARF::DIEToVariableSP &SymbolFileDWARFDwo::GetDIEToVariable() {
98 return GetBaseSymbolFile().GetDIEToVariable();
101 SymbolFileDWARF::DIEToClangType &
102 SymbolFileDWARFDwo::GetForwardDeclDieToClangType() {
103 return GetBaseSymbolFile().GetForwardDeclDieToClangType();
106 SymbolFileDWARF::ClangTypeToDIE &
107 SymbolFileDWARFDwo::GetForwardDeclClangTypeToDie() {
108 return GetBaseSymbolFile().GetForwardDeclClangTypeToDie();
111 size_t SymbolFileDWARFDwo::GetObjCMethodDIEOffsets(
112 lldb_private::ConstString class_name, DIEArray &method_die_offsets) {
113 return GetBaseSymbolFile().GetObjCMethodDIEOffsets(class_name,
117 UniqueDWARFASTTypeMap &SymbolFileDWARFDwo::GetUniqueDWARFASTTypeMap() {
118 return GetBaseSymbolFile().GetUniqueDWARFASTTypeMap();
121 lldb::TypeSP SymbolFileDWARFDwo::FindDefinitionTypeForDWARFDeclContext(
122 const DWARFDeclContext &die_decl_ctx) {
123 return GetBaseSymbolFile().FindDefinitionTypeForDWARFDeclContext(
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);
134 SymbolFileDWARF &SymbolFileDWARFDwo::GetBaseSymbolFile() {
135 return m_base_dwarf_cu.GetSymbolFileDWARF();
138 DWARFExpression::LocationListFormat
139 SymbolFileDWARFDwo::GetLocationListFormat() const {
140 return DWARFExpression::SplitDwarfLocationList;
144 SymbolFileDWARFDwo::GetTypeSystemForLanguage(LanguageType language) {
145 return GetBaseSymbolFile().GetTypeSystemForLanguage(language);
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);