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) {}
53 static bool classof(const DIContext *DICtx) {
54 return DICtx->getKind() == CK_DWARF;
57 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
59 /// Get the number of compile units in this context.
60 unsigned getNumCompileUnits() {
66 /// Get the number of compile units in the DWO context.
67 unsigned getNumDWOCompileUnits() {
69 parseDWOCompileUnits();
73 /// Get the compile unit at the specified index for this compile unit.
74 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
80 /// Get the compile unit at the specified index for the DWO compile units.
81 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
83 parseDWOCompileUnits();
84 return &DWOCUs[index];
87 /// Get a pointer to the parsed DebugAbbrev object.
88 const DWARFDebugAbbrev *getDebugAbbrev();
90 /// Get a pointer to the parsed DebugLoc object.
91 const DWARFDebugLoc *getDebugLoc();
93 /// Get a pointer to the parsed dwo abbreviations object.
94 const DWARFDebugAbbrev *getDebugAbbrevDWO();
96 /// Get a pointer to the parsed DebugAranges object.
97 const DWARFDebugAranges *getDebugAranges();
99 /// Get a pointer to the parsed frame information object.
100 const DWARFDebugFrame *getDebugFrame();
102 /// Get a pointer to a parsed line table corresponding to a compile unit.
103 const DWARFDebugLine::LineTable *
104 getLineTableForCompileUnit(DWARFCompileUnit *cu);
106 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
107 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
108 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
109 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
110 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
111 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
113 virtual bool isLittleEndian() const = 0;
114 virtual uint8_t getAddressSize() const = 0;
115 virtual const RelocAddrMap &infoRelocMap() const = 0;
116 virtual const RelocAddrMap &lineRelocMap() const = 0;
117 virtual const RelocAddrMap &locRelocMap() const = 0;
118 virtual StringRef getInfoSection() = 0;
119 virtual StringRef getAbbrevSection() = 0;
120 virtual StringRef getLocSection() = 0;
121 virtual StringRef getARangeSection() = 0;
122 virtual StringRef getDebugFrameSection() = 0;
123 virtual StringRef getLineSection() = 0;
124 virtual StringRef getStringSection() = 0;
125 virtual StringRef getRangeSection() = 0;
126 virtual StringRef getPubNamesSection() = 0;
128 // Sections for DWARF5 split dwarf proposal.
129 virtual StringRef getInfoDWOSection() = 0;
130 virtual StringRef getAbbrevDWOSection() = 0;
131 virtual StringRef getStringDWOSection() = 0;
132 virtual StringRef getStringOffsetDWOSection() = 0;
133 virtual StringRef getRangeDWOSection() = 0;
134 virtual StringRef getAddrSection() = 0;
135 virtual const RelocAddrMap &infoDWORelocMap() const = 0;
137 static bool isSupportedVersion(unsigned version) {
138 return version == 2 || version == 3 || version == 4;
141 /// Return the compile unit that includes an offset (relative to .debug_info).
142 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
144 /// Return the compile unit which contains instruction with provided
146 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
149 /// DWARFContextInMemory is the simplest possible implementation of a
150 /// DWARFContext. It assumes all content is available in memory and stores
152 class DWARFContextInMemory : public DWARFContext {
153 virtual void anchor();
156 RelocAddrMap InfoRelocMap;
157 RelocAddrMap LocRelocMap;
158 RelocAddrMap LineRelocMap;
159 StringRef InfoSection;
160 StringRef AbbrevSection;
161 StringRef LocSection;
162 StringRef ARangeSection;
163 StringRef DebugFrameSection;
164 StringRef LineSection;
165 StringRef StringSection;
166 StringRef RangeSection;
167 StringRef PubNamesSection;
169 // Sections for DWARF5 split dwarf proposal.
170 RelocAddrMap InfoDWORelocMap;
171 StringRef InfoDWOSection;
172 StringRef AbbrevDWOSection;
173 StringRef StringDWOSection;
174 StringRef StringOffsetDWOSection;
175 StringRef RangeDWOSection;
176 StringRef AddrSection;
178 SmallVector<MemoryBuffer*, 4> UncompressedSections;
181 DWARFContextInMemory(object::ObjectFile *);
182 ~DWARFContextInMemory();
183 virtual bool isLittleEndian() const { return IsLittleEndian; }
184 virtual uint8_t getAddressSize() const { return AddressSize; }
185 virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; }
186 virtual const RelocAddrMap &locRelocMap() const { return LocRelocMap; }
187 virtual const RelocAddrMap &lineRelocMap() const { return LineRelocMap; }
188 virtual StringRef getInfoSection() { return InfoSection; }
189 virtual StringRef getAbbrevSection() { return AbbrevSection; }
190 virtual StringRef getLocSection() { return LocSection; }
191 virtual StringRef getARangeSection() { return ARangeSection; }
192 virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
193 virtual StringRef getLineSection() { return LineSection; }
194 virtual StringRef getStringSection() { return StringSection; }
195 virtual StringRef getRangeSection() { return RangeSection; }
196 virtual StringRef getPubNamesSection() { return PubNamesSection; }
198 // Sections for DWARF5 split dwarf proposal.
199 virtual StringRef getInfoDWOSection() { return InfoDWOSection; }
200 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
201 virtual StringRef getStringDWOSection() { return StringDWOSection; }
202 virtual StringRef getStringOffsetDWOSection() {
203 return StringOffsetDWOSection;
205 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
206 virtual StringRef getAddrSection() {
209 virtual const RelocAddrMap &infoDWORelocMap() const {
210 return InfoDWORelocMap;