1 //===-- DWARFContext.h ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===/
10 #ifndef LLVM_DEBUGINFO_DWARFCONTEXT_H
11 #define LLVM_DEBUGINFO_DWARFCONTEXT_H
13 #include "DWARFCompileUnit.h"
14 #include "DWARFDebugAranges.h"
15 #include "DWARFDebugFrame.h"
16 #include "DWARFDebugLine.h"
17 #include "DWARFDebugLoc.h"
18 #include "DWARFDebugRangeList.h"
19 #include "DWARFTypeUnit.h"
20 #include "llvm/ADT/MapVector.h"
21 #include "llvm/ADT/OwningPtr.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/DebugInfo/DIContext.h"
28 /// This data structure is the top level entity that deals with dwarf debug
29 /// information parsing. The actual data is supplied through pure virtual
30 /// methods that a concrete implementation provides.
31 class DWARFContext : public DIContext {
32 SmallVector<DWARFCompileUnit *, 1> CUs;
33 SmallVector<DWARFTypeUnit *, 1> TUs;
34 OwningPtr<DWARFDebugAbbrev> Abbrev;
35 OwningPtr<DWARFDebugLoc> Loc;
36 OwningPtr<DWARFDebugAranges> Aranges;
37 OwningPtr<DWARFDebugLine> Line;
38 OwningPtr<DWARFDebugFrame> DebugFrame;
40 SmallVector<DWARFCompileUnit *, 1> DWOCUs;
41 SmallVector<DWARFTypeUnit *, 1> DWOTUs;
42 OwningPtr<DWARFDebugAbbrev> AbbrevDWO;
44 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
45 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
47 /// Read compile units from the debug_info section and store them in CUs.
48 void parseCompileUnits();
50 /// Read type units from the debug_types sections and store them in CUs.
51 void parseTypeUnits();
53 /// Read compile units from the debug_info.dwo section and store them in
55 void parseDWOCompileUnits();
57 /// Read type units from the debug_types.dwo section and store them in
59 void parseDWOTypeUnits();
67 DWARFContext() : DIContext(CK_DWARF) {}
68 virtual ~DWARFContext();
70 static bool classof(const DIContext *DICtx) {
71 return DICtx->getKind() == CK_DWARF;
74 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
76 /// Get the number of compile units in this context.
77 unsigned getNumCompileUnits() {
83 /// Get the number of compile units in this context.
84 unsigned getNumTypeUnits() {
90 /// Get the number of compile units in the DWO context.
91 unsigned getNumDWOCompileUnits() {
93 parseDWOCompileUnits();
97 /// Get the number of compile units in the DWO context.
98 unsigned getNumDWOTypeUnits() {
101 return DWOTUs.size();
104 /// Get the compile unit at the specified index for this compile unit.
105 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
111 /// Get the type unit at the specified index for this compile unit.
112 DWARFTypeUnit *getTypeUnitAtIndex(unsigned index) {
118 /// Get the compile unit at the specified index for the DWO compile units.
119 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
121 parseDWOCompileUnits();
122 return DWOCUs[index];
125 /// Get the type unit at the specified index for the DWO type units.
126 DWARFTypeUnit *getDWOTypeUnitAtIndex(unsigned index) {
129 return DWOTUs[index];
132 /// Get a pointer to the parsed DebugAbbrev object.
133 const DWARFDebugAbbrev *getDebugAbbrev();
135 /// Get a pointer to the parsed DebugLoc object.
136 const DWARFDebugLoc *getDebugLoc();
138 /// Get a pointer to the parsed dwo abbreviations object.
139 const DWARFDebugAbbrev *getDebugAbbrevDWO();
141 /// Get a pointer to the parsed DebugAranges object.
142 const DWARFDebugAranges *getDebugAranges();
144 /// Get a pointer to the parsed frame information object.
145 const DWARFDebugFrame *getDebugFrame();
147 /// Get a pointer to a parsed line table corresponding to a compile unit.
148 const DWARFDebugLine::LineTable *
149 getLineTableForCompileUnit(DWARFCompileUnit *cu);
151 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
152 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
153 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
154 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
155 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
156 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
158 virtual bool isLittleEndian() const = 0;
159 virtual uint8_t getAddressSize() const = 0;
160 virtual const Section &getInfoSection() = 0;
161 typedef MapVector<object::SectionRef, Section,
162 std::map<object::SectionRef, unsigned> > TypeSectionMap;
163 virtual const TypeSectionMap &getTypesSections() = 0;
164 virtual StringRef getAbbrevSection() = 0;
165 virtual const Section &getLocSection() = 0;
166 virtual StringRef getARangeSection() = 0;
167 virtual StringRef getDebugFrameSection() = 0;
168 virtual const Section &getLineSection() = 0;
169 virtual StringRef getStringSection() = 0;
170 virtual StringRef getRangeSection() = 0;
171 virtual StringRef getPubNamesSection() = 0;
172 virtual StringRef getPubTypesSection() = 0;
173 virtual StringRef getGnuPubNamesSection() = 0;
174 virtual StringRef getGnuPubTypesSection() = 0;
176 // Sections for DWARF5 split dwarf proposal.
177 virtual const Section &getInfoDWOSection() = 0;
178 virtual const TypeSectionMap &getTypesDWOSections() = 0;
179 virtual StringRef getAbbrevDWOSection() = 0;
180 virtual StringRef getStringDWOSection() = 0;
181 virtual StringRef getStringOffsetDWOSection() = 0;
182 virtual StringRef getRangeDWOSection() = 0;
183 virtual StringRef getAddrSection() = 0;
185 static bool isSupportedVersion(unsigned version) {
186 return version == 2 || version == 3 || version == 4;
189 /// Return the compile unit that includes an offset (relative to .debug_info).
190 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
192 /// Return the compile unit which contains instruction with provided
194 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
197 /// DWARFContextInMemory is the simplest possible implementation of a
198 /// DWARFContext. It assumes all content is available in memory and stores
200 class DWARFContextInMemory : public DWARFContext {
201 virtual void anchor();
205 TypeSectionMap TypesSections;
206 StringRef AbbrevSection;
208 StringRef ARangeSection;
209 StringRef DebugFrameSection;
211 StringRef StringSection;
212 StringRef RangeSection;
213 StringRef PubNamesSection;
214 StringRef PubTypesSection;
215 StringRef GnuPubNamesSection;
216 StringRef GnuPubTypesSection;
218 // Sections for DWARF5 split dwarf proposal.
219 Section InfoDWOSection;
220 TypeSectionMap TypesDWOSections;
221 StringRef AbbrevDWOSection;
222 StringRef StringDWOSection;
223 StringRef StringOffsetDWOSection;
224 StringRef RangeDWOSection;
225 StringRef AddrSection;
227 SmallVector<MemoryBuffer*, 4> UncompressedSections;
230 DWARFContextInMemory(object::ObjectFile *);
231 ~DWARFContextInMemory();
232 virtual bool isLittleEndian() const { return IsLittleEndian; }
233 virtual uint8_t getAddressSize() const { return AddressSize; }
234 virtual const Section &getInfoSection() { return InfoSection; }
235 virtual const TypeSectionMap &getTypesSections() { return TypesSections; }
236 virtual StringRef getAbbrevSection() { return AbbrevSection; }
237 virtual const Section &getLocSection() { return LocSection; }
238 virtual StringRef getARangeSection() { return ARangeSection; }
239 virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
240 virtual const Section &getLineSection() { return LineSection; }
241 virtual StringRef getStringSection() { return StringSection; }
242 virtual StringRef getRangeSection() { return RangeSection; }
243 virtual StringRef getPubNamesSection() { return PubNamesSection; }
244 virtual StringRef getPubTypesSection() { return PubTypesSection; }
245 virtual StringRef getGnuPubNamesSection() { return GnuPubNamesSection; }
246 virtual StringRef getGnuPubTypesSection() { return GnuPubTypesSection; }
248 // Sections for DWARF5 split dwarf proposal.
249 virtual const Section &getInfoDWOSection() { return InfoDWOSection; }
250 virtual const TypeSectionMap &getTypesDWOSections() {
251 return TypesDWOSections;
253 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
254 virtual StringRef getStringDWOSection() { return StringDWOSection; }
255 virtual StringRef getStringOffsetDWOSection() {
256 return StringOffsetDWOSection;
258 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
259 virtual StringRef getAddrSection() {