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/DebugInfo/DIContext.h"
27 /// This data structure is the top level entity that deals with dwarf debug
28 /// information parsing. The actual data is supplied through pure virtual
29 /// methods that a concrete implementation provides.
30 class DWARFContext : public DIContext {
31 SmallVector<DWARFCompileUnit *, 1> CUs;
32 SmallVector<DWARFTypeUnit *, 1> TUs;
33 OwningPtr<DWARFDebugAbbrev> Abbrev;
34 OwningPtr<DWARFDebugLoc> Loc;
35 OwningPtr<DWARFDebugAranges> Aranges;
36 OwningPtr<DWARFDebugLine> Line;
37 OwningPtr<DWARFDebugFrame> DebugFrame;
39 SmallVector<DWARFCompileUnit *, 1> DWOCUs;
40 OwningPtr<DWARFDebugAbbrev> AbbrevDWO;
42 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
43 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
45 /// Read compile units from the debug_info section and store them in CUs.
46 void parseCompileUnits();
48 /// Read type units from the debug_types sections and store them in CUs.
49 void parseTypeUnits();
51 /// Read compile units from the debug_info.dwo section and store them in
53 void parseDWOCompileUnits();
61 DWARFContext() : DIContext(CK_DWARF) {}
62 virtual ~DWARFContext();
64 static bool classof(const DIContext *DICtx) {
65 return DICtx->getKind() == CK_DWARF;
68 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
70 /// Get the number of compile units in this context.
71 unsigned getNumCompileUnits() {
77 /// Get the number of compile units in this context.
78 unsigned getNumTypeUnits() {
84 /// Get the number of compile units in the DWO context.
85 unsigned getNumDWOCompileUnits() {
87 parseDWOCompileUnits();
91 /// Get the compile unit at the specified index for this compile unit.
92 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
98 /// Get the type unit at the specified index for this compile unit.
99 DWARFTypeUnit *getTypeUnitAtIndex(unsigned index) {
105 /// Get the compile unit at the specified index for the DWO compile units.
106 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
108 parseDWOCompileUnits();
109 return DWOCUs[index];
112 /// Get a pointer to the parsed DebugAbbrev object.
113 const DWARFDebugAbbrev *getDebugAbbrev();
115 /// Get a pointer to the parsed DebugLoc object.
116 const DWARFDebugLoc *getDebugLoc();
118 /// Get a pointer to the parsed dwo abbreviations object.
119 const DWARFDebugAbbrev *getDebugAbbrevDWO();
121 /// Get a pointer to the parsed DebugAranges object.
122 const DWARFDebugAranges *getDebugAranges();
124 /// Get a pointer to the parsed frame information object.
125 const DWARFDebugFrame *getDebugFrame();
127 /// Get a pointer to a parsed line table corresponding to a compile unit.
128 const DWARFDebugLine::LineTable *
129 getLineTableForCompileUnit(DWARFCompileUnit *cu);
131 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
132 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
133 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
134 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
135 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
136 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
138 virtual bool isLittleEndian() const = 0;
139 virtual uint8_t getAddressSize() const = 0;
140 virtual const Section &getInfoSection() = 0;
141 virtual const std::map<object::SectionRef, Section> &getTypesSections() = 0;
142 virtual StringRef getAbbrevSection() = 0;
143 virtual const Section &getLocSection() = 0;
144 virtual StringRef getARangeSection() = 0;
145 virtual StringRef getDebugFrameSection() = 0;
146 virtual const Section &getLineSection() = 0;
147 virtual StringRef getStringSection() = 0;
148 virtual StringRef getRangeSection() = 0;
149 virtual StringRef getPubNamesSection() = 0;
150 virtual StringRef getPubTypesSection() = 0;
151 virtual StringRef getGnuPubNamesSection() = 0;
152 virtual StringRef getGnuPubTypesSection() = 0;
154 // Sections for DWARF5 split dwarf proposal.
155 virtual const Section &getInfoDWOSection() = 0;
156 virtual StringRef getAbbrevDWOSection() = 0;
157 virtual StringRef getStringDWOSection() = 0;
158 virtual StringRef getStringOffsetDWOSection() = 0;
159 virtual StringRef getRangeDWOSection() = 0;
160 virtual StringRef getAddrSection() = 0;
162 static bool isSupportedVersion(unsigned version) {
163 return version == 2 || version == 3 || version == 4;
166 /// Return the compile unit that includes an offset (relative to .debug_info).
167 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
169 /// Return the compile unit which contains instruction with provided
171 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
174 /// DWARFContextInMemory is the simplest possible implementation of a
175 /// DWARFContext. It assumes all content is available in memory and stores
177 class DWARFContextInMemory : public DWARFContext {
178 virtual void anchor();
182 std::map<object::SectionRef, Section> TypesSections;
183 StringRef AbbrevSection;
185 StringRef ARangeSection;
186 StringRef DebugFrameSection;
188 StringRef StringSection;
189 StringRef RangeSection;
190 StringRef PubNamesSection;
191 StringRef PubTypesSection;
192 StringRef GnuPubNamesSection;
193 StringRef GnuPubTypesSection;
195 // Sections for DWARF5 split dwarf proposal.
196 Section InfoDWOSection;
197 StringRef AbbrevDWOSection;
198 StringRef StringDWOSection;
199 StringRef StringOffsetDWOSection;
200 StringRef RangeDWOSection;
201 StringRef AddrSection;
203 SmallVector<MemoryBuffer*, 4> UncompressedSections;
206 DWARFContextInMemory(object::ObjectFile *);
207 ~DWARFContextInMemory();
208 virtual bool isLittleEndian() const { return IsLittleEndian; }
209 virtual uint8_t getAddressSize() const { return AddressSize; }
210 virtual const Section &getInfoSection() { return InfoSection; }
211 virtual const std::map<object::SectionRef, Section> &getTypesSections() {
212 return TypesSections;
214 virtual StringRef getAbbrevSection() { return AbbrevSection; }
215 virtual const Section &getLocSection() { return LocSection; }
216 virtual StringRef getARangeSection() { return ARangeSection; }
217 virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
218 virtual const Section &getLineSection() { return LineSection; }
219 virtual StringRef getStringSection() { return StringSection; }
220 virtual StringRef getRangeSection() { return RangeSection; }
221 virtual StringRef getPubNamesSection() { return PubNamesSection; }
222 virtual StringRef getPubTypesSection() { return PubTypesSection; }
223 virtual StringRef getGnuPubNamesSection() { return GnuPubNamesSection; }
224 virtual StringRef getGnuPubTypesSection() { return GnuPubTypesSection; }
226 // Sections for DWARF5 split dwarf proposal.
227 virtual const Section &getInfoDWOSection() { return InfoDWOSection; }
228 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
229 virtual StringRef getStringDWOSection() { return StringDWOSection; }
230 virtual StringRef getStringOffsetDWOSection() {
231 return StringOffsetDWOSection;
233 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
234 virtual StringRef getAddrSection() {