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();
52 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
54 /// Get the number of compile units in this context.
55 unsigned getNumCompileUnits() {
61 /// Get the number of compile units in the DWO context.
62 unsigned getNumDWOCompileUnits() {
64 parseDWOCompileUnits();
68 /// Get the compile unit at the specified index for this compile unit.
69 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
75 /// Get the compile unit at the specified index for the DWO compile units.
76 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
78 parseDWOCompileUnits();
79 return &DWOCUs[index];
82 /// Get a pointer to the parsed DebugAbbrev object.
83 const DWARFDebugAbbrev *getDebugAbbrev();
85 /// Get a pointer to the parsed DebugLoc object.
86 const DWARFDebugLoc *getDebugLoc();
88 /// Get a pointer to the parsed dwo abbreviations object.
89 const DWARFDebugAbbrev *getDebugAbbrevDWO();
91 /// Get a pointer to the parsed DebugAranges object.
92 const DWARFDebugAranges *getDebugAranges();
94 /// Get a pointer to the parsed frame information object.
95 const DWARFDebugFrame *getDebugFrame();
97 /// Get a pointer to a parsed line table corresponding to a compile unit.
98 const DWARFDebugLine::LineTable *
99 getLineTableForCompileUnit(DWARFCompileUnit *cu);
101 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
102 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
103 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
104 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
105 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
106 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
108 virtual bool isLittleEndian() const = 0;
109 virtual uint8_t getAddressSize() const = 0;
110 virtual const RelocAddrMap &infoRelocMap() const = 0;
111 virtual const RelocAddrMap &lineRelocMap() const = 0;
112 virtual const RelocAddrMap &locRelocMap() const = 0;
113 virtual StringRef getInfoSection() = 0;
114 virtual StringRef getAbbrevSection() = 0;
115 virtual StringRef getLocSection() = 0;
116 virtual StringRef getARangeSection() = 0;
117 virtual StringRef getDebugFrameSection() = 0;
118 virtual StringRef getLineSection() = 0;
119 virtual StringRef getStringSection() = 0;
120 virtual StringRef getRangeSection() = 0;
121 virtual StringRef getPubNamesSection() = 0;
123 // Sections for DWARF5 split dwarf proposal.
124 virtual StringRef getInfoDWOSection() = 0;
125 virtual StringRef getAbbrevDWOSection() = 0;
126 virtual StringRef getStringDWOSection() = 0;
127 virtual StringRef getStringOffsetDWOSection() = 0;
128 virtual StringRef getRangeDWOSection() = 0;
129 virtual StringRef getAddrSection() = 0;
130 virtual const RelocAddrMap &infoDWORelocMap() const = 0;
132 static bool isSupportedVersion(unsigned version) {
133 return version == 2 || version == 3;
136 /// Return the compile unit that includes an offset (relative to .debug_info).
137 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
139 /// Return the compile unit which contains instruction with provided
141 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
144 /// DWARFContextInMemory is the simplest possible implementation of a
145 /// DWARFContext. It assumes all content is available in memory and stores
147 class DWARFContextInMemory : public DWARFContext {
148 virtual void anchor();
151 RelocAddrMap InfoRelocMap;
152 RelocAddrMap LocRelocMap;
153 RelocAddrMap LineRelocMap;
154 StringRef InfoSection;
155 StringRef AbbrevSection;
156 StringRef LocSection;
157 StringRef ARangeSection;
158 StringRef DebugFrameSection;
159 StringRef LineSection;
160 StringRef StringSection;
161 StringRef RangeSection;
162 StringRef PubNamesSection;
164 // Sections for DWARF5 split dwarf proposal.
165 RelocAddrMap InfoDWORelocMap;
166 StringRef InfoDWOSection;
167 StringRef AbbrevDWOSection;
168 StringRef StringDWOSection;
169 StringRef StringOffsetDWOSection;
170 StringRef RangeDWOSection;
171 StringRef AddrSection;
173 SmallVector<MemoryBuffer*, 4> UncompressedSections;
176 DWARFContextInMemory(object::ObjectFile *);
177 ~DWARFContextInMemory();
178 virtual bool isLittleEndian() const { return IsLittleEndian; }
179 virtual uint8_t getAddressSize() const { return AddressSize; }
180 virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; }
181 virtual const RelocAddrMap &locRelocMap() const { return LocRelocMap; }
182 virtual const RelocAddrMap &lineRelocMap() const { return LineRelocMap; }
183 virtual StringRef getInfoSection() { return InfoSection; }
184 virtual StringRef getAbbrevSection() { return AbbrevSection; }
185 virtual StringRef getLocSection() { return LocSection; }
186 virtual StringRef getARangeSection() { return ARangeSection; }
187 virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
188 virtual StringRef getLineSection() { return LineSection; }
189 virtual StringRef getStringSection() { return StringSection; }
190 virtual StringRef getRangeSection() { return RangeSection; }
191 virtual StringRef getPubNamesSection() { return PubNamesSection; }
193 // Sections for DWARF5 split dwarf proposal.
194 virtual StringRef getInfoDWOSection() { return InfoDWOSection; }
195 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
196 virtual StringRef getStringDWOSection() { return StringDWOSection; }
197 virtual StringRef getStringOffsetDWOSection() {
198 return StringOffsetDWOSection;
200 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
201 virtual StringRef getAddrSection() {
204 virtual const RelocAddrMap &infoDWORelocMap() const {
205 return InfoDWORelocMap;