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/OwningPtr.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/MapVector.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 OwningPtr<DWARFDebugAbbrev> AbbrevDWO;
43 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
44 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
46 /// Read compile units from the debug_info section and store them in CUs.
47 void parseCompileUnits();
49 /// Read type units from the debug_types sections and store them in CUs.
50 void parseTypeUnits();
52 /// Read compile units from the debug_info.dwo section and store them in
54 void parseDWOCompileUnits();
62 DWARFContext() : DIContext(CK_DWARF) {}
63 virtual ~DWARFContext();
65 static bool classof(const DIContext *DICtx) {
66 return DICtx->getKind() == CK_DWARF;
69 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
71 /// Get the number of compile units in this context.
72 unsigned getNumCompileUnits() {
78 /// Get the number of compile units in this context.
79 unsigned getNumTypeUnits() {
85 /// Get the number of compile units in the DWO context.
86 unsigned getNumDWOCompileUnits() {
88 parseDWOCompileUnits();
92 /// Get the compile unit at the specified index for this compile unit.
93 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
99 /// Get the type unit at the specified index for this compile unit.
100 DWARFTypeUnit *getTypeUnitAtIndex(unsigned index) {
106 /// Get the compile unit at the specified index for the DWO compile units.
107 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
109 parseDWOCompileUnits();
110 return DWOCUs[index];
113 /// Get a pointer to the parsed DebugAbbrev object.
114 const DWARFDebugAbbrev *getDebugAbbrev();
116 /// Get a pointer to the parsed DebugLoc object.
117 const DWARFDebugLoc *getDebugLoc();
119 /// Get a pointer to the parsed dwo abbreviations object.
120 const DWARFDebugAbbrev *getDebugAbbrevDWO();
122 /// Get a pointer to the parsed DebugAranges object.
123 const DWARFDebugAranges *getDebugAranges();
125 /// Get a pointer to the parsed frame information object.
126 const DWARFDebugFrame *getDebugFrame();
128 /// Get a pointer to a parsed line table corresponding to a compile unit.
129 const DWARFDebugLine::LineTable *
130 getLineTableForCompileUnit(DWARFCompileUnit *cu);
132 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
133 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
134 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
135 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
136 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
137 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
139 virtual bool isLittleEndian() const = 0;
140 virtual uint8_t getAddressSize() const = 0;
141 virtual const Section &getInfoSection() = 0;
142 typedef MapVector<object::SectionRef, Section,
143 std::map<object::SectionRef, unsigned> > TypeSectionMap;
144 virtual const TypeSectionMap &getTypesSections() = 0;
145 virtual StringRef getAbbrevSection() = 0;
146 virtual const Section &getLocSection() = 0;
147 virtual StringRef getARangeSection() = 0;
148 virtual StringRef getDebugFrameSection() = 0;
149 virtual const Section &getLineSection() = 0;
150 virtual StringRef getStringSection() = 0;
151 virtual StringRef getRangeSection() = 0;
152 virtual StringRef getPubNamesSection() = 0;
153 virtual StringRef getPubTypesSection() = 0;
154 virtual StringRef getGnuPubNamesSection() = 0;
155 virtual StringRef getGnuPubTypesSection() = 0;
157 // Sections for DWARF5 split dwarf proposal.
158 virtual const Section &getInfoDWOSection() = 0;
159 virtual StringRef getAbbrevDWOSection() = 0;
160 virtual StringRef getStringDWOSection() = 0;
161 virtual StringRef getStringOffsetDWOSection() = 0;
162 virtual StringRef getRangeDWOSection() = 0;
163 virtual StringRef getAddrSection() = 0;
165 static bool isSupportedVersion(unsigned version) {
166 return version == 2 || version == 3 || version == 4;
169 /// Return the compile unit that includes an offset (relative to .debug_info).
170 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
172 /// Return the compile unit which contains instruction with provided
174 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
177 /// DWARFContextInMemory is the simplest possible implementation of a
178 /// DWARFContext. It assumes all content is available in memory and stores
180 class DWARFContextInMemory : public DWARFContext {
181 virtual void anchor();
185 TypeSectionMap TypesSections;
186 StringRef AbbrevSection;
188 StringRef ARangeSection;
189 StringRef DebugFrameSection;
191 StringRef StringSection;
192 StringRef RangeSection;
193 StringRef PubNamesSection;
194 StringRef PubTypesSection;
195 StringRef GnuPubNamesSection;
196 StringRef GnuPubTypesSection;
198 // Sections for DWARF5 split dwarf proposal.
199 Section InfoDWOSection;
200 StringRef AbbrevDWOSection;
201 StringRef StringDWOSection;
202 StringRef StringOffsetDWOSection;
203 StringRef RangeDWOSection;
204 StringRef AddrSection;
206 SmallVector<MemoryBuffer*, 4> UncompressedSections;
209 DWARFContextInMemory(object::ObjectFile *);
210 ~DWARFContextInMemory();
211 virtual bool isLittleEndian() const { return IsLittleEndian; }
212 virtual uint8_t getAddressSize() const { return AddressSize; }
213 virtual const Section &getInfoSection() { return InfoSection; }
214 virtual const TypeSectionMap &getTypesSections() { return TypesSections; }
215 virtual StringRef getAbbrevSection() { return AbbrevSection; }
216 virtual const Section &getLocSection() { return LocSection; }
217 virtual StringRef getARangeSection() { return ARangeSection; }
218 virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
219 virtual const Section &getLineSection() { return LineSection; }
220 virtual StringRef getStringSection() { return StringSection; }
221 virtual StringRef getRangeSection() { return RangeSection; }
222 virtual StringRef getPubNamesSection() { return PubNamesSection; }
223 virtual StringRef getPubTypesSection() { return PubTypesSection; }
224 virtual StringRef getGnuPubNamesSection() { return GnuPubNamesSection; }
225 virtual StringRef getGnuPubTypesSection() { return GnuPubTypesSection; }
227 // Sections for DWARF5 split dwarf proposal.
228 virtual const Section &getInfoDWOSection() { return InfoDWOSection; }
229 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
230 virtual StringRef getStringDWOSection() { return StringDWOSection; }
231 virtual StringRef getStringOffsetDWOSection() {
232 return StringOffsetDWOSection;
234 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
235 virtual StringRef getAddrSection() {