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 "llvm/ADT/OwningPtr.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/DebugInfo/DIContext.h"
26 /// This data structure is the top level entity that deals with dwarf debug
27 /// information parsing. The actual data is supplied through pure virtual
28 /// methods that a concrete implementation provides.
29 class DWARFContext : public DIContext {
30 SmallVector<DWARFCompileUnit *, 1> CUs;
31 OwningPtr<DWARFDebugAbbrev> Abbrev;
32 OwningPtr<DWARFDebugLoc> Loc;
33 OwningPtr<DWARFDebugAranges> Aranges;
34 OwningPtr<DWARFDebugLine> Line;
35 OwningPtr<DWARFDebugFrame> DebugFrame;
37 SmallVector<DWARFCompileUnit *, 1> DWOCUs;
38 OwningPtr<DWARFDebugAbbrev> AbbrevDWO;
40 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
41 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
43 /// Read compile units from the debug_info section and store them in CUs.
44 void parseCompileUnits();
46 /// Read compile units from the debug_info.dwo section and store them in
48 void parseDWOCompileUnits();
51 DWARFContext() : DIContext(CK_DWARF) {}
52 virtual ~DWARFContext();
54 static bool classof(const DIContext *DICtx) {
55 return DICtx->getKind() == CK_DWARF;
58 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
60 /// Get the number of compile units in this context.
61 unsigned getNumCompileUnits() {
67 /// Get the number of compile units in the DWO context.
68 unsigned getNumDWOCompileUnits() {
70 parseDWOCompileUnits();
74 /// Get the compile unit at the specified index for this compile unit.
75 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
81 /// Get the compile unit at the specified index for the DWO compile units.
82 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
84 parseDWOCompileUnits();
88 /// Get a pointer to the parsed DebugAbbrev object.
89 const DWARFDebugAbbrev *getDebugAbbrev();
91 /// Get a pointer to the parsed DebugLoc object.
92 const DWARFDebugLoc *getDebugLoc();
94 /// Get a pointer to the parsed dwo abbreviations object.
95 const DWARFDebugAbbrev *getDebugAbbrevDWO();
97 /// Get a pointer to the parsed DebugAranges object.
98 const DWARFDebugAranges *getDebugAranges();
100 /// Get a pointer to the parsed frame information object.
101 const DWARFDebugFrame *getDebugFrame();
103 /// Get a pointer to a parsed line table corresponding to a compile unit.
104 const DWARFDebugLine::LineTable *
105 getLineTableForCompileUnit(DWARFCompileUnit *cu);
107 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
108 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
109 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
110 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
111 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
112 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
114 virtual bool isLittleEndian() const = 0;
115 virtual uint8_t getAddressSize() const = 0;
116 virtual const RelocAddrMap &infoRelocMap() const = 0;
117 virtual const RelocAddrMap &lineRelocMap() const = 0;
118 virtual const RelocAddrMap &locRelocMap() const = 0;
119 virtual StringRef getInfoSection() = 0;
120 virtual StringRef getAbbrevSection() = 0;
121 virtual StringRef getLocSection() = 0;
122 virtual StringRef getARangeSection() = 0;
123 virtual StringRef getDebugFrameSection() = 0;
124 virtual StringRef getLineSection() = 0;
125 virtual StringRef getStringSection() = 0;
126 virtual StringRef getRangeSection() = 0;
127 virtual StringRef getPubNamesSection() = 0;
128 virtual StringRef getGnuPubNamesSection() = 0;
130 // Sections for DWARF5 split dwarf proposal.
131 virtual StringRef getInfoDWOSection() = 0;
132 virtual StringRef getAbbrevDWOSection() = 0;
133 virtual StringRef getStringDWOSection() = 0;
134 virtual StringRef getStringOffsetDWOSection() = 0;
135 virtual StringRef getRangeDWOSection() = 0;
136 virtual StringRef getAddrSection() = 0;
137 virtual const RelocAddrMap &infoDWORelocMap() const = 0;
139 static bool isSupportedVersion(unsigned version) {
140 return version == 2 || version == 3 || version == 4;
143 /// Return the compile unit that includes an offset (relative to .debug_info).
144 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
146 /// Return the compile unit which contains instruction with provided
148 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
151 /// DWARFContextInMemory is the simplest possible implementation of a
152 /// DWARFContext. It assumes all content is available in memory and stores
154 class DWARFContextInMemory : public DWARFContext {
155 virtual void anchor();
158 RelocAddrMap InfoRelocMap;
159 RelocAddrMap LocRelocMap;
160 RelocAddrMap LineRelocMap;
161 StringRef InfoSection;
162 StringRef AbbrevSection;
163 StringRef LocSection;
164 StringRef ARangeSection;
165 StringRef DebugFrameSection;
166 StringRef LineSection;
167 StringRef StringSection;
168 StringRef RangeSection;
169 StringRef PubNamesSection;
170 StringRef GnuPubNamesSection;
172 // Sections for DWARF5 split dwarf proposal.
173 RelocAddrMap InfoDWORelocMap;
174 StringRef InfoDWOSection;
175 StringRef AbbrevDWOSection;
176 StringRef StringDWOSection;
177 StringRef StringOffsetDWOSection;
178 StringRef RangeDWOSection;
179 StringRef AddrSection;
181 SmallVector<MemoryBuffer*, 4> UncompressedSections;
184 DWARFContextInMemory(object::ObjectFile *);
185 ~DWARFContextInMemory();
186 virtual bool isLittleEndian() const { return IsLittleEndian; }
187 virtual uint8_t getAddressSize() const { return AddressSize; }
188 virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; }
189 virtual const RelocAddrMap &locRelocMap() const { return LocRelocMap; }
190 virtual const RelocAddrMap &lineRelocMap() const { return LineRelocMap; }
191 virtual StringRef getInfoSection() { return InfoSection; }
192 virtual StringRef getAbbrevSection() { return AbbrevSection; }
193 virtual StringRef getLocSection() { return LocSection; }
194 virtual StringRef getARangeSection() { return ARangeSection; }
195 virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
196 virtual StringRef getLineSection() { return LineSection; }
197 virtual StringRef getStringSection() { return StringSection; }
198 virtual StringRef getRangeSection() { return RangeSection; }
199 virtual StringRef getPubNamesSection() { return PubNamesSection; }
200 virtual StringRef getGnuPubNamesSection() { return GnuPubNamesSection; }
202 // Sections for DWARF5 split dwarf proposal.
203 virtual StringRef getInfoDWOSection() { return InfoDWOSection; }
204 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
205 virtual StringRef getStringDWOSection() { return StringDWOSection; }
206 virtual StringRef getStringOffsetDWOSection() {
207 return StringOffsetDWOSection;
209 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
210 virtual StringRef getAddrSection() {
213 virtual const RelocAddrMap &infoDWORelocMap() const {
214 return InfoDWORelocMap;