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 getGnuPubNamesSection() = 0;
152 // Sections for DWARF5 split dwarf proposal.
153 virtual const Section &getInfoDWOSection() = 0;
154 virtual StringRef getAbbrevDWOSection() = 0;
155 virtual StringRef getStringDWOSection() = 0;
156 virtual StringRef getStringOffsetDWOSection() = 0;
157 virtual StringRef getRangeDWOSection() = 0;
158 virtual StringRef getAddrSection() = 0;
160 static bool isSupportedVersion(unsigned version) {
161 return version == 2 || version == 3 || version == 4;
164 /// Return the compile unit that includes an offset (relative to .debug_info).
165 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
167 /// Return the compile unit which contains instruction with provided
169 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
172 /// DWARFContextInMemory is the simplest possible implementation of a
173 /// DWARFContext. It assumes all content is available in memory and stores
175 class DWARFContextInMemory : public DWARFContext {
176 virtual void anchor();
180 std::map<object::SectionRef, Section> TypesSections;
181 StringRef AbbrevSection;
183 StringRef ARangeSection;
184 StringRef DebugFrameSection;
186 StringRef StringSection;
187 StringRef RangeSection;
188 StringRef PubNamesSection;
189 StringRef GnuPubNamesSection;
191 // Sections for DWARF5 split dwarf proposal.
192 Section InfoDWOSection;
193 StringRef AbbrevDWOSection;
194 StringRef StringDWOSection;
195 StringRef StringOffsetDWOSection;
196 StringRef RangeDWOSection;
197 StringRef AddrSection;
199 SmallVector<MemoryBuffer*, 4> UncompressedSections;
202 DWARFContextInMemory(object::ObjectFile *);
203 ~DWARFContextInMemory();
204 virtual bool isLittleEndian() const { return IsLittleEndian; }
205 virtual uint8_t getAddressSize() const { return AddressSize; }
206 virtual const Section &getInfoSection() { return InfoSection; }
207 virtual const std::map<object::SectionRef, Section> &getTypesSections() {
208 return TypesSections;
210 virtual StringRef getAbbrevSection() { return AbbrevSection; }
211 virtual const Section &getLocSection() { return LocSection; }
212 virtual StringRef getARangeSection() { return ARangeSection; }
213 virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
214 virtual const Section &getLineSection() { return LineSection; }
215 virtual StringRef getStringSection() { return StringSection; }
216 virtual StringRef getRangeSection() { return RangeSection; }
217 virtual StringRef getPubNamesSection() { return PubNamesSection; }
218 virtual StringRef getGnuPubNamesSection() { return GnuPubNamesSection; }
220 // Sections for DWARF5 split dwarf proposal.
221 virtual const Section &getInfoDWOSection() { return InfoDWOSection; }
222 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
223 virtual StringRef getStringDWOSection() { return StringDWOSection; }
224 virtual StringRef getStringOffsetDWOSection() {
225 return StringOffsetDWOSection;
227 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
228 virtual StringRef getAddrSection() {