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 
16 #include "DWARFUnit.h"
17 #include "DWARFDebugInfo.h"
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
22 SymbolFileDWARFDwo::SymbolFileDWARFDwo(ObjectFileSP objfile,
23                                        DWARFUnit *dwarf_cu)
24     : SymbolFileDWARF(objfile.get(), objfile->GetSectionList(
25                                          /*update_module_section_list*/ false)),
26       m_obj_file_sp(objfile), m_base_dwarf_cu(dwarf_cu) {
27   SetID(((lldb::user_id_t)dwarf_cu->GetID()) << 32);
28 }
29 
30 void SymbolFileDWARFDwo::LoadSectionData(lldb::SectionType sect_type,
31                                          DWARFDataExtractor &data) {
32   const SectionList *section_list =
33       m_obj_file->GetSectionList(false /* update_module_section_list */);
34   if (section_list) {
35     SectionSP section_sp(section_list->FindSectionByType(sect_type, true));
36     if (section_sp) {
37 
38       if (m_obj_file->ReadSectionData(section_sp.get(), data) != 0)
39         return;
40 
41       data.Clear();
42     }
43   }
44 
45   SymbolFileDWARF::LoadSectionData(sect_type, data);
46 }
47 
48 lldb::CompUnitSP SymbolFileDWARFDwo::ParseCompileUnit(DWARFUnit *dwarf_cu) {
49   assert(GetCompileUnit() == dwarf_cu && "SymbolFileDWARFDwo::ParseCompileUnit "
50                                          "called with incompatible compile "
51                                          "unit");
52   return GetBaseSymbolFile()->ParseCompileUnit(m_base_dwarf_cu);
53 }
54 
55 DWARFUnit *SymbolFileDWARFDwo::GetCompileUnit() {
56   // Only dwo files with 1 compile unit is supported
57   if (GetNumCompileUnits() == 1)
58     return DebugInfo()->GetUnitAtIndex(0);
59   else
60     return nullptr;
61 }
62 
63 DWARFUnit *
64 SymbolFileDWARFDwo::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) {
65   return GetCompileUnit();
66 }
67 
68 SymbolFileDWARF::DIEToTypePtr &SymbolFileDWARFDwo::GetDIEToType() {
69   return GetBaseSymbolFile()->GetDIEToType();
70 }
71 
72 SymbolFileDWARF::DIEToVariableSP &SymbolFileDWARFDwo::GetDIEToVariable() {
73   return GetBaseSymbolFile()->GetDIEToVariable();
74 }
75 
76 SymbolFileDWARF::DIEToClangType &
77 SymbolFileDWARFDwo::GetForwardDeclDieToClangType() {
78   return GetBaseSymbolFile()->GetForwardDeclDieToClangType();
79 }
80 
81 SymbolFileDWARF::ClangTypeToDIE &
82 SymbolFileDWARFDwo::GetForwardDeclClangTypeToDie() {
83   return GetBaseSymbolFile()->GetForwardDeclClangTypeToDie();
84 }
85 
86 size_t SymbolFileDWARFDwo::GetObjCMethodDIEOffsets(
87     lldb_private::ConstString class_name, DIEArray &method_die_offsets) {
88   return GetBaseSymbolFile()->GetObjCMethodDIEOffsets(
89       class_name, method_die_offsets);
90 }
91 
92 UniqueDWARFASTTypeMap &SymbolFileDWARFDwo::GetUniqueDWARFASTTypeMap() {
93   return GetBaseSymbolFile()->GetUniqueDWARFASTTypeMap();
94 }
95 
96 lldb::TypeSP SymbolFileDWARFDwo::FindDefinitionTypeForDWARFDeclContext(
97     const DWARFDeclContext &die_decl_ctx) {
98   return GetBaseSymbolFile()->FindDefinitionTypeForDWARFDeclContext(
99       die_decl_ctx);
100 }
101 
102 lldb::TypeSP SymbolFileDWARFDwo::FindCompleteObjCDefinitionTypeForDIE(
103     const DWARFDIE &die, lldb_private::ConstString type_name,
104     bool must_be_implementation) {
105   return GetBaseSymbolFile()->FindCompleteObjCDefinitionTypeForDIE(
106       die, type_name, must_be_implementation);
107 }
108 
109 DWARFUnit *SymbolFileDWARFDwo::GetBaseCompileUnit() {
110   return m_base_dwarf_cu;
111 }
112 
113 SymbolFileDWARF *SymbolFileDWARFDwo::GetBaseSymbolFile() {
114   return m_base_dwarf_cu->GetSymbolFileDWARF();
115 }
116 
117 DWARFExpression::LocationListFormat
118 SymbolFileDWARFDwo::GetLocationListFormat() const {
119   return DWARFExpression::SplitDwarfLocationList;
120 }
121 
122 TypeSystem *
123 SymbolFileDWARFDwo::GetTypeSystemForLanguage(LanguageType language) {
124   return GetBaseSymbolFile()->GetTypeSystemForLanguage(language);
125 }
126 
127 DWARFDIE
128 SymbolFileDWARFDwo::GetDIE(const DIERef &die_ref) {
129   lldbassert(die_ref.cu_offset == m_base_dwarf_cu->GetOffset() ||
130              die_ref.cu_offset == DW_INVALID_OFFSET);
131   return DebugInfo()->GetDIEForDIEOffset(die_ref.section, die_ref.die_offset);
132 }
133