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