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();
56 DWARFContext() : DIContext(CK_DWARF) {}
57 virtual ~DWARFContext();
59 static bool classof(const DIContext *DICtx) {
60 return DICtx->getKind() == CK_DWARF;
63 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
65 /// Get the number of compile units in this context.
66 unsigned getNumCompileUnits() {
72 /// Get the number of compile units in the DWO context.
73 unsigned getNumDWOCompileUnits() {
75 parseDWOCompileUnits();
79 /// Get the compile unit at the specified index for this compile unit.
80 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
86 /// Get the compile unit at the specified index for the DWO compile units.
87 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
89 parseDWOCompileUnits();
93 /// Get a pointer to the parsed DebugAbbrev object.
94 const DWARFDebugAbbrev *getDebugAbbrev();
96 /// Get a pointer to the parsed DebugLoc object.
97 const DWARFDebugLoc *getDebugLoc();
99 /// Get a pointer to the parsed dwo abbreviations object.
100 const DWARFDebugAbbrev *getDebugAbbrevDWO();
102 /// Get a pointer to the parsed DebugAranges object.
103 const DWARFDebugAranges *getDebugAranges();
105 /// Get a pointer to the parsed frame information object.
106 const DWARFDebugFrame *getDebugFrame();
108 /// Get a pointer to a parsed line table corresponding to a compile unit.
109 const DWARFDebugLine::LineTable *
110 getLineTableForCompileUnit(DWARFCompileUnit *cu);
112 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
113 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
114 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
115 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
116 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
117 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
119 virtual bool isLittleEndian() const = 0;
120 virtual uint8_t getAddressSize() const = 0;
121 virtual const Section &getInfoSection() = 0;
122 virtual StringRef getAbbrevSection() = 0;
123 virtual const Section &getLocSection() = 0;
124 virtual StringRef getARangeSection() = 0;
125 virtual StringRef getDebugFrameSection() = 0;
126 virtual const Section &getLineSection() = 0;
127 virtual StringRef getStringSection() = 0;
128 virtual StringRef getRangeSection() = 0;
129 virtual StringRef getPubNamesSection() = 0;
130 virtual StringRef getGnuPubNamesSection() = 0;
132 // Sections for DWARF5 split dwarf proposal.
133 virtual const Section &getInfoDWOSection() = 0;
134 virtual StringRef getAbbrevDWOSection() = 0;
135 virtual StringRef getStringDWOSection() = 0;
136 virtual StringRef getStringOffsetDWOSection() = 0;
137 virtual StringRef getRangeDWOSection() = 0;
138 virtual StringRef getAddrSection() = 0;
140 static bool isSupportedVersion(unsigned version) {
141 return version == 2 || version == 3 || version == 4;
144 /// Return the compile unit that includes an offset (relative to .debug_info).
145 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
147 /// Return the compile unit which contains instruction with provided
149 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
152 /// DWARFContextInMemory is the simplest possible implementation of a
153 /// DWARFContext. It assumes all content is available in memory and stores
155 class DWARFContextInMemory : public DWARFContext {
156 virtual void anchor();
160 StringRef AbbrevSection;
162 StringRef ARangeSection;
163 StringRef DebugFrameSection;
165 StringRef StringSection;
166 StringRef RangeSection;
167 StringRef PubNamesSection;
168 StringRef GnuPubNamesSection;
170 // Sections for DWARF5 split dwarf proposal.
171 Section 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 Section &getInfoSection() { return InfoSection; }
186 virtual StringRef getAbbrevSection() { return AbbrevSection; }
187 virtual const Section &getLocSection() { return LocSection; }
188 virtual StringRef getARangeSection() { return ARangeSection; }
189 virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
190 virtual const Section &getLineSection() { return LineSection; }
191 virtual StringRef getStringSection() { return StringSection; }
192 virtual StringRef getRangeSection() { return RangeSection; }
193 virtual StringRef getPubNamesSection() { return PubNamesSection; }
194 virtual StringRef getGnuPubNamesSection() { return GnuPubNamesSection; }
196 // Sections for DWARF5 split dwarf proposal.
197 virtual const Section &getInfoDWOSection() { return InfoDWOSection; }
198 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
199 virtual StringRef getStringDWOSection() { return StringDWOSection; }
200 virtual StringRef getStringOffsetDWOSection() {
201 return StringOffsetDWOSection;
203 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
204 virtual StringRef getAddrSection() {