1 //===-- SymbolFileDWARFDwo.cpp ----------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "SymbolFileDWARFDwo.h"
11 
12 #include "lldb/Core/Section.h"
13 #include "lldb/Expression/DWARFExpression.h"
14 #include "lldb/Symbol/ObjectFile.h"
15 #include "lldb/Utility/LLDBAssert.h"
16 
17 #include "DWARFUnit.h"
18 #include "DWARFDebugInfo.h"
19 
20 using namespace lldb;
21 using namespace lldb_private;
22 
SymbolFileDWARFDwo(ObjectFileSP objfile,DWARFUnit * dwarf_cu)23 SymbolFileDWARFDwo::SymbolFileDWARFDwo(ObjectFileSP objfile,
24                                        DWARFUnit *dwarf_cu)
25     : SymbolFileDWARF(objfile.get()), m_obj_file_sp(objfile),
26       m_base_dwarf_cu(dwarf_cu) {
27   SetID(((lldb::user_id_t)dwarf_cu->GetOffset()) << 32);
28 }
29 
LoadSectionData(lldb::SectionType sect_type,DWARFDataExtractor & data)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       // See if we memory mapped the DWARF segment?
38       if (m_dwarf_data.GetByteSize()) {
39         data.SetData(m_dwarf_data, section_sp->GetOffset(),
40                      section_sp->GetFileSize());
41         return;
42       }
43 
44       if (m_obj_file->ReadSectionData(section_sp.get(), data) != 0)
45         return;
46 
47       data.Clear();
48     }
49   }
50 
51   SymbolFileDWARF::LoadSectionData(sect_type, data);
52 }
53 
54 lldb::CompUnitSP
ParseCompileUnit(DWARFUnit * dwarf_cu,uint32_t cu_idx)55 SymbolFileDWARFDwo::ParseCompileUnit(DWARFUnit *dwarf_cu,
56                                      uint32_t cu_idx) {
57   assert(GetCompileUnit() == dwarf_cu && "SymbolFileDWARFDwo::ParseCompileUnit "
58                                          "called with incompatible compile "
59                                          "unit");
60   return GetBaseSymbolFile()->ParseCompileUnit(m_base_dwarf_cu, UINT32_MAX);
61 }
62 
GetCompileUnit()63 DWARFUnit *SymbolFileDWARFDwo::GetCompileUnit() {
64   // Only dwo files with 1 compile unit is supported
65   if (GetNumCompileUnits() == 1)
66     return DebugInfo()->GetCompileUnitAtIndex(0);
67   else
68     return nullptr;
69 }
70 
71 DWARFUnit *
GetDWARFCompileUnit(lldb_private::CompileUnit * comp_unit)72 SymbolFileDWARFDwo::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) {
73   return GetCompileUnit();
74 }
75 
GetDIEToType()76 SymbolFileDWARF::DIEToTypePtr &SymbolFileDWARFDwo::GetDIEToType() {
77   return GetBaseSymbolFile()->GetDIEToType();
78 }
79 
GetDIEToVariable()80 SymbolFileDWARF::DIEToVariableSP &SymbolFileDWARFDwo::GetDIEToVariable() {
81   return GetBaseSymbolFile()->GetDIEToVariable();
82 }
83 
84 SymbolFileDWARF::DIEToClangType &
GetForwardDeclDieToClangType()85 SymbolFileDWARFDwo::GetForwardDeclDieToClangType() {
86   return GetBaseSymbolFile()->GetForwardDeclDieToClangType();
87 }
88 
89 SymbolFileDWARF::ClangTypeToDIE &
GetForwardDeclClangTypeToDie()90 SymbolFileDWARFDwo::GetForwardDeclClangTypeToDie() {
91   return GetBaseSymbolFile()->GetForwardDeclClangTypeToDie();
92 }
93 
GetObjCMethodDIEOffsets(lldb_private::ConstString class_name,DIEArray & method_die_offsets)94 size_t SymbolFileDWARFDwo::GetObjCMethodDIEOffsets(
95     lldb_private::ConstString class_name, DIEArray &method_die_offsets) {
96   return GetBaseSymbolFile()->GetObjCMethodDIEOffsets(
97       class_name, method_die_offsets);
98 }
99 
GetUniqueDWARFASTTypeMap()100 UniqueDWARFASTTypeMap &SymbolFileDWARFDwo::GetUniqueDWARFASTTypeMap() {
101   return GetBaseSymbolFile()->GetUniqueDWARFASTTypeMap();
102 }
103 
FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext & die_decl_ctx)104 lldb::TypeSP SymbolFileDWARFDwo::FindDefinitionTypeForDWARFDeclContext(
105     const DWARFDeclContext &die_decl_ctx) {
106   return GetBaseSymbolFile()->FindDefinitionTypeForDWARFDeclContext(
107       die_decl_ctx);
108 }
109 
FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE & die,const lldb_private::ConstString & type_name,bool must_be_implementation)110 lldb::TypeSP SymbolFileDWARFDwo::FindCompleteObjCDefinitionTypeForDIE(
111     const DWARFDIE &die, const lldb_private::ConstString &type_name,
112     bool must_be_implementation) {
113   return GetBaseSymbolFile()->FindCompleteObjCDefinitionTypeForDIE(
114       die, type_name, must_be_implementation);
115 }
116 
GetBaseCompileUnit()117 DWARFUnit *SymbolFileDWARFDwo::GetBaseCompileUnit() {
118   return m_base_dwarf_cu;
119 }
120 
get_debug_abbrev_data()121 const DWARFDataExtractor &SymbolFileDWARFDwo::get_debug_abbrev_data() {
122   return GetCachedSectionData(eSectionTypeDWARFDebugAbbrevDwo,
123                               m_data_debug_abbrev);
124 }
125 
get_debug_addr_data()126 const DWARFDataExtractor &SymbolFileDWARFDwo::get_debug_addr_data() {
127   // For single file split dwarf case (when we have .dwo sections in a .o),
128   // we do not want to use the .debug_addr section from .o file,
129   // but want to get one from the final executable.
130   // For regular split debug case, .dwo file does not contain the
131   // .debug_addr, so we would always fall back to such lookup anyways.
132   llvm::call_once(m_data_debug_addr.m_flag, [this] {
133     SymbolFileDWARF::LoadSectionData(eSectionTypeDWARFDebugAddr,
134                                      std::ref(m_data_debug_addr.m_data));
135   });
136   return m_data_debug_addr.m_data;
137 }
138 
get_debug_info_data()139 const DWARFDataExtractor &SymbolFileDWARFDwo::get_debug_info_data() {
140   return GetCachedSectionData(eSectionTypeDWARFDebugInfoDwo, m_data_debug_info);
141 }
142 
get_debug_str_data()143 const DWARFDataExtractor &SymbolFileDWARFDwo::get_debug_str_data() {
144   return GetCachedSectionData(eSectionTypeDWARFDebugStrDwo, m_data_debug_str);
145 }
146 
get_debug_str_offsets_data()147 const DWARFDataExtractor &SymbolFileDWARFDwo::get_debug_str_offsets_data() {
148   return GetCachedSectionData(eSectionTypeDWARFDebugStrOffsetsDwo,
149                               m_data_debug_str_offsets);
150 }
151 
GetBaseSymbolFile()152 SymbolFileDWARF *SymbolFileDWARFDwo::GetBaseSymbolFile() {
153   return m_base_dwarf_cu->GetSymbolFileDWARF();
154 }
155 
156 DWARFExpression::LocationListFormat
GetLocationListFormat() const157 SymbolFileDWARFDwo::GetLocationListFormat() const {
158   return DWARFExpression::SplitDwarfLocationList;
159 }
160 
161 TypeSystem *
GetTypeSystemForLanguage(LanguageType language)162 SymbolFileDWARFDwo::GetTypeSystemForLanguage(LanguageType language) {
163   return GetBaseSymbolFile()->GetTypeSystemForLanguage(language);
164 }
165 
166 DWARFDIE
GetDIE(const DIERef & die_ref)167 SymbolFileDWARFDwo::GetDIE(const DIERef &die_ref) {
168   lldbassert(m_base_dwarf_cu->GetOffset() == die_ref.cu_offset);
169   return DebugInfo()->GetDIEForDIEOffset(die_ref.die_offset);
170 }
171