blob: 823e98a6b31e64960c0f1f888fa28a3fd2e4bc7d [file] [log] [blame]
Benjamin Krameraa2f78f2011-09-13 19:42:23 +00001//===-- DWARFContext.h ------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===/
9
10#ifndef LLVM_DEBUGINFO_DWARFCONTEXT_H
11#define LLVM_DEBUGINFO_DWARFCONTEXT_H
12
13#include "DWARFCompileUnit.h"
Benjamin Kramera6002fd2011-09-14 01:09:52 +000014#include "DWARFDebugAranges.h"
Eli Benderskyfd08bc12013-02-05 23:30:58 +000015#include "DWARFDebugFrame.h"
Benjamin Kramer5acab502011-09-15 02:12:05 +000016#include "DWARFDebugLine.h"
David Blaikie18e73502013-06-19 21:37:13 +000017#include "DWARFDebugLoc.h"
Alexey Samsonov034e57a2012-08-27 07:17:47 +000018#include "DWARFDebugRangeList.h"
David Blaikie03c089c2013-09-23 22:44:47 +000019#include "DWARFTypeUnit.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000020#include "llvm/ADT/MapVector.h"
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000021#include "llvm/ADT/OwningPtr.h"
22#include "llvm/ADT/SmallVector.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000023#include "llvm/DebugInfo/DIContext.h"
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000024
25namespace llvm {
26
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000027/// DWARFContext
28/// This data structure is the top level entity that deals with dwarf debug
29/// information parsing. The actual data is supplied through pure virtual
30/// methods that a concrete implementation provides.
31class DWARFContext : public DIContext {
Alexey Samsonova9debbf2013-08-23 06:56:01 +000032 SmallVector<DWARFCompileUnit *, 1> CUs;
David Blaikie03c089c2013-09-23 22:44:47 +000033 SmallVector<DWARFTypeUnit *, 1> TUs;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000034 OwningPtr<DWARFDebugAbbrev> Abbrev;
David Blaikie18e73502013-06-19 21:37:13 +000035 OwningPtr<DWARFDebugLoc> Loc;
Benjamin Kramera6002fd2011-09-14 01:09:52 +000036 OwningPtr<DWARFDebugAranges> Aranges;
Benjamin Kramer5acab502011-09-15 02:12:05 +000037 OwningPtr<DWARFDebugLine> Line;
Eli Benderskyfd08bc12013-02-05 23:30:58 +000038 OwningPtr<DWARFDebugFrame> DebugFrame;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000039
Alexey Samsonova9debbf2013-08-23 06:56:01 +000040 SmallVector<DWARFCompileUnit *, 1> DWOCUs;
David Blaikie92d9d622014-01-09 05:08:24 +000041 SmallVector<DWARFTypeUnit *, 1> DWOTUs;
Eric Christopherda4b2192013-01-02 23:52:13 +000042 OwningPtr<DWARFDebugAbbrev> AbbrevDWO;
43
Craig Topperb1d83e82012-09-18 02:01:41 +000044 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
45 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000046
47 /// Read compile units from the debug_info section and store them in CUs.
48 void parseCompileUnits();
Eric Christopher7370b552012-11-12 21:40:38 +000049
David Blaikie03c089c2013-09-23 22:44:47 +000050 /// Read type units from the debug_types sections and store them in CUs.
51 void parseTypeUnits();
52
Eric Christopherda4b2192013-01-02 23:52:13 +000053 /// Read compile units from the debug_info.dwo section and store them in
54 /// DWOCUs.
55 void parseDWOCompileUnits();
56
David Blaikie92d9d622014-01-09 05:08:24 +000057 /// Read type units from the debug_types.dwo section and store them in
58 /// DWOTUs.
59 void parseDWOTypeUnits();
60
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000061public:
David Blaikie1b5ee5d2013-09-23 17:42:01 +000062 struct Section {
63 StringRef Data;
64 RelocAddrMap Relocs;
65 };
66
Alexey Samsonovc2e00872013-08-06 10:32:39 +000067 DWARFContext() : DIContext(CK_DWARF) {}
Alexey Samsonova9debbf2013-08-23 06:56:01 +000068 virtual ~DWARFContext();
Alexey Samsonovc2e00872013-08-06 10:32:39 +000069
70 static bool classof(const DIContext *DICtx) {
71 return DICtx->getKind() == CK_DWARF;
72 }
73
Craig Topper85482992014-03-05 07:52:44 +000074 void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) override;
Eric Christopher7c678de2012-11-07 23:22:07 +000075
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000076 /// Get the number of compile units in this context.
77 unsigned getNumCompileUnits() {
78 if (CUs.empty())
79 parseCompileUnits();
80 return CUs.size();
81 }
Eric Christopherda4b2192013-01-02 23:52:13 +000082
David Blaikie03c089c2013-09-23 22:44:47 +000083 /// Get the number of compile units in this context.
84 unsigned getNumTypeUnits() {
85 if (TUs.empty())
86 parseTypeUnits();
87 return TUs.size();
88 }
89
Eric Christopherda4b2192013-01-02 23:52:13 +000090 /// Get the number of compile units in the DWO context.
91 unsigned getNumDWOCompileUnits() {
92 if (DWOCUs.empty())
93 parseDWOCompileUnits();
94 return DWOCUs.size();
95 }
96
David Blaikie92d9d622014-01-09 05:08:24 +000097 /// Get the number of compile units in the DWO context.
98 unsigned getNumDWOTypeUnits() {
99 if (DWOTUs.empty())
100 parseDWOTypeUnits();
101 return DWOTUs.size();
102 }
103
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000104 /// Get the compile unit at the specified index for this compile unit.
105 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
106 if (CUs.empty())
107 parseCompileUnits();
Alexey Samsonova9debbf2013-08-23 06:56:01 +0000108 return CUs[index];
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000109 }
110
David Blaikie03c089c2013-09-23 22:44:47 +0000111 /// Get the type unit at the specified index for this compile unit.
112 DWARFTypeUnit *getTypeUnitAtIndex(unsigned index) {
113 if (TUs.empty())
114 parseTypeUnits();
115 return TUs[index];
116 }
117
Eric Christopherda4b2192013-01-02 23:52:13 +0000118 /// Get the compile unit at the specified index for the DWO compile units.
119 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
120 if (DWOCUs.empty())
121 parseDWOCompileUnits();
Alexey Samsonova9debbf2013-08-23 06:56:01 +0000122 return DWOCUs[index];
Eric Christopherda4b2192013-01-02 23:52:13 +0000123 }
124
David Blaikie92d9d622014-01-09 05:08:24 +0000125 /// Get the type unit at the specified index for the DWO type units.
126 DWARFTypeUnit *getDWOTypeUnitAtIndex(unsigned index) {
127 if (DWOTUs.empty())
128 parseDWOTypeUnits();
129 return DWOTUs[index];
130 }
131
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000132 /// Get a pointer to the parsed DebugAbbrev object.
133 const DWARFDebugAbbrev *getDebugAbbrev();
134
David Blaikie18e73502013-06-19 21:37:13 +0000135 /// Get a pointer to the parsed DebugLoc object.
136 const DWARFDebugLoc *getDebugLoc();
137
Eric Christopherda4b2192013-01-02 23:52:13 +0000138 /// Get a pointer to the parsed dwo abbreviations object.
139 const DWARFDebugAbbrev *getDebugAbbrevDWO();
140
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000141 /// Get a pointer to the parsed DebugAranges object.
142 const DWARFDebugAranges *getDebugAranges();
143
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000144 /// Get a pointer to the parsed frame information object.
145 const DWARFDebugFrame *getDebugFrame();
146
Benjamin Kramer679e1752011-09-15 20:43:18 +0000147 /// Get a pointer to a parsed line table corresponding to a compile unit.
148 const DWARFDebugLine::LineTable *
149 getLineTableForCompileUnit(DWARFCompileUnit *cu);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000150
Craig Topper85482992014-03-05 07:52:44 +0000151 DILineInfo getLineInfoForAddress(uint64_t Address,
152 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
153 DILineInfoTable getLineInfoForAddressRange(uint64_t Address, uint64_t Size,
154 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
155 DIInliningInfo getInliningInfoForAddress(uint64_t Address,
156 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
Benjamin Kramer2602ca62011-09-15 20:43:22 +0000157
Eric Christopher7370b552012-11-12 21:40:38 +0000158 virtual bool isLittleEndian() const = 0;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000159 virtual uint8_t getAddressSize() const = 0;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000160 virtual const Section &getInfoSection() = 0;
David Blaikiebc563272013-12-13 21:33:40 +0000161 typedef MapVector<object::SectionRef, Section,
162 std::map<object::SectionRef, unsigned> > TypeSectionMap;
163 virtual const TypeSectionMap &getTypesSections() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000164 virtual StringRef getAbbrevSection() = 0;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000165 virtual const Section &getLocSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000166 virtual StringRef getARangeSection() = 0;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000167 virtual StringRef getDebugFrameSection() = 0;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000168 virtual const Section &getLineSection() = 0;
David Blaikie1d4736e2014-02-24 23:58:54 +0000169 virtual const Section &getLineDWOSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000170 virtual StringRef getStringSection() = 0;
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000171 virtual StringRef getRangeSection() = 0;
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000172 virtual StringRef getPubNamesSection() = 0;
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000173 virtual StringRef getPubTypesSection() = 0;
David Blaikie404d3042013-09-19 23:01:29 +0000174 virtual StringRef getGnuPubNamesSection() = 0;
David Blaikieecd21ff2013-09-24 19:50:00 +0000175 virtual StringRef getGnuPubTypesSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000176
Eric Christopherda4b2192013-01-02 23:52:13 +0000177 // Sections for DWARF5 split dwarf proposal.
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000178 virtual const Section &getInfoDWOSection() = 0;
David Blaikie92d9d622014-01-09 05:08:24 +0000179 virtual const TypeSectionMap &getTypesDWOSections() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000180 virtual StringRef getAbbrevDWOSection() = 0;
181 virtual StringRef getStringDWOSection() = 0;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000182 virtual StringRef getStringOffsetDWOSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000183 virtual StringRef getRangeDWOSection() = 0;
Eric Christopher962c9082013-01-15 23:56:56 +0000184 virtual StringRef getAddrSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000185
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000186 static bool isSupportedVersion(unsigned version) {
Eric Christopherf7d848d2013-08-06 01:38:27 +0000187 return version == 2 || version == 3 || version == 4;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000188 }
Alexey Samsonov45be7932012-08-30 07:49:50 +0000189private:
190 /// Return the compile unit that includes an offset (relative to .debug_info).
191 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000192
Alexey Samsonov45be7932012-08-30 07:49:50 +0000193 /// Return the compile unit which contains instruction with provided
194 /// address.
195 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
Alexey Samsonov45be7932012-08-30 07:49:50 +0000196};
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000197
198/// DWARFContextInMemory is the simplest possible implementation of a
199/// DWARFContext. It assumes all content is available in memory and stores
200/// pointers to it.
201class DWARFContextInMemory : public DWARFContext {
David Blaikiea379b1812011-12-20 02:50:00 +0000202 virtual void anchor();
Eric Christopher7370b552012-11-12 21:40:38 +0000203 bool IsLittleEndian;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000204 uint8_t AddressSize;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000205 Section InfoSection;
David Blaikiebc563272013-12-13 21:33:40 +0000206 TypeSectionMap TypesSections;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000207 StringRef AbbrevSection;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000208 Section LocSection;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000209 StringRef ARangeSection;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000210 StringRef DebugFrameSection;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000211 Section LineSection;
David Blaikie1d4736e2014-02-24 23:58:54 +0000212 Section LineDWOSection;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000213 StringRef StringSection;
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000214 StringRef RangeSection;
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000215 StringRef PubNamesSection;
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000216 StringRef PubTypesSection;
David Blaikie404d3042013-09-19 23:01:29 +0000217 StringRef GnuPubNamesSection;
David Blaikieecd21ff2013-09-24 19:50:00 +0000218 StringRef GnuPubTypesSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000219
220 // Sections for DWARF5 split dwarf proposal.
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000221 Section InfoDWOSection;
David Blaikie92d9d622014-01-09 05:08:24 +0000222 TypeSectionMap TypesDWOSections;
Eric Christopherda4b2192013-01-02 23:52:13 +0000223 StringRef AbbrevDWOSection;
224 StringRef StringDWOSection;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000225 StringRef StringOffsetDWOSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000226 StringRef RangeDWOSection;
Eric Christopher962c9082013-01-15 23:56:56 +0000227 StringRef AddrSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000228
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000229 SmallVector<MemoryBuffer*, 4> UncompressedSections;
230
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000231public:
Eric Christopher7370b552012-11-12 21:40:38 +0000232 DWARFContextInMemory(object::ObjectFile *);
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000233 ~DWARFContextInMemory();
Craig Topper85482992014-03-05 07:52:44 +0000234 bool isLittleEndian() const override { return IsLittleEndian; }
235 uint8_t getAddressSize() const override { return AddressSize; }
236 const Section &getInfoSection() override { return InfoSection; }
237 const TypeSectionMap &getTypesSections() override { return TypesSections; }
238 StringRef getAbbrevSection() override { return AbbrevSection; }
239 const Section &getLocSection() override { return LocSection; }
240 StringRef getARangeSection() override { return ARangeSection; }
241 StringRef getDebugFrameSection() override { return DebugFrameSection; }
242 const Section &getLineSection() override { return LineSection; }
243 const Section &getLineDWOSection() override { return LineDWOSection; }
244 StringRef getStringSection() override { return StringSection; }
245 StringRef getRangeSection() override { return RangeSection; }
246 StringRef getPubNamesSection() override { return PubNamesSection; }
247 StringRef getPubTypesSection() override { return PubTypesSection; }
248 StringRef getGnuPubNamesSection() override { return GnuPubNamesSection; }
249 StringRef getGnuPubTypesSection() override { return GnuPubTypesSection; }
Eric Christopherda4b2192013-01-02 23:52:13 +0000250
251 // Sections for DWARF5 split dwarf proposal.
Craig Topper85482992014-03-05 07:52:44 +0000252 const Section &getInfoDWOSection() override { return InfoDWOSection; }
253 const TypeSectionMap &getTypesDWOSections() override {
David Blaikie92d9d622014-01-09 05:08:24 +0000254 return TypesDWOSections;
255 }
Craig Topper85482992014-03-05 07:52:44 +0000256 StringRef getAbbrevDWOSection() override { return AbbrevDWOSection; }
257 StringRef getStringDWOSection() override { return StringDWOSection; }
258 StringRef getStringOffsetDWOSection() override {
Eric Christopher2cbd5762013-01-07 19:32:41 +0000259 return StringOffsetDWOSection;
260 }
Craig Topper85482992014-03-05 07:52:44 +0000261 StringRef getRangeDWOSection() override { return RangeDWOSection; }
262 StringRef getAddrSection() override {
Eric Christopher962c9082013-01-15 23:56:56 +0000263 return AddrSection;
264 }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000265};
266
267}
268
269#endif