blob: 9bac69d6e5225ccada077d2cec1334f131f20c13 [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
Eli Bendersky7a94daa2013-01-25 20:26:43 +000074 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
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
Alexey Samsonov45be7932012-08-30 07:49:50 +0000151 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
152 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000153 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
154 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000155 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
156 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
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;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000169 virtual StringRef getStringSection() = 0;
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000170 virtual StringRef getRangeSection() = 0;
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000171 virtual StringRef getPubNamesSection() = 0;
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000172 virtual StringRef getPubTypesSection() = 0;
David Blaikie404d3042013-09-19 23:01:29 +0000173 virtual StringRef getGnuPubNamesSection() = 0;
David Blaikieecd21ff2013-09-24 19:50:00 +0000174 virtual StringRef getGnuPubTypesSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000175
Eric Christopherda4b2192013-01-02 23:52:13 +0000176 // Sections for DWARF5 split dwarf proposal.
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000177 virtual const Section &getInfoDWOSection() = 0;
David Blaikie92d9d622014-01-09 05:08:24 +0000178 virtual const TypeSectionMap &getTypesDWOSections() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000179 virtual StringRef getAbbrevDWOSection() = 0;
180 virtual StringRef getStringDWOSection() = 0;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000181 virtual StringRef getStringOffsetDWOSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000182 virtual StringRef getRangeDWOSection() = 0;
Eric Christopher962c9082013-01-15 23:56:56 +0000183 virtual StringRef getAddrSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000184
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000185 static bool isSupportedVersion(unsigned version) {
Eric Christopherf7d848d2013-08-06 01:38:27 +0000186 return version == 2 || version == 3 || version == 4;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000187 }
Alexey Samsonov45be7932012-08-30 07:49:50 +0000188private:
189 /// Return the compile unit that includes an offset (relative to .debug_info).
190 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000191
Alexey Samsonov45be7932012-08-30 07:49:50 +0000192 /// Return the compile unit which contains instruction with provided
193 /// address.
194 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
Alexey Samsonov45be7932012-08-30 07:49:50 +0000195};
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000196
197/// DWARFContextInMemory is the simplest possible implementation of a
198/// DWARFContext. It assumes all content is available in memory and stores
199/// pointers to it.
200class DWARFContextInMemory : public DWARFContext {
David Blaikiea379b1812011-12-20 02:50:00 +0000201 virtual void anchor();
Eric Christopher7370b552012-11-12 21:40:38 +0000202 bool IsLittleEndian;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000203 uint8_t AddressSize;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000204 Section InfoSection;
David Blaikiebc563272013-12-13 21:33:40 +0000205 TypeSectionMap TypesSections;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000206 StringRef AbbrevSection;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000207 Section LocSection;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000208 StringRef ARangeSection;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000209 StringRef DebugFrameSection;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000210 Section LineSection;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000211 StringRef StringSection;
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000212 StringRef RangeSection;
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000213 StringRef PubNamesSection;
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000214 StringRef PubTypesSection;
David Blaikie404d3042013-09-19 23:01:29 +0000215 StringRef GnuPubNamesSection;
David Blaikieecd21ff2013-09-24 19:50:00 +0000216 StringRef GnuPubTypesSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000217
218 // Sections for DWARF5 split dwarf proposal.
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000219 Section InfoDWOSection;
David Blaikie92d9d622014-01-09 05:08:24 +0000220 TypeSectionMap TypesDWOSections;
Eric Christopherda4b2192013-01-02 23:52:13 +0000221 StringRef AbbrevDWOSection;
222 StringRef StringDWOSection;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000223 StringRef StringOffsetDWOSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000224 StringRef RangeDWOSection;
Eric Christopher962c9082013-01-15 23:56:56 +0000225 StringRef AddrSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000226
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000227 SmallVector<MemoryBuffer*, 4> UncompressedSections;
228
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000229public:
Eric Christopher7370b552012-11-12 21:40:38 +0000230 DWARFContextInMemory(object::ObjectFile *);
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000231 ~DWARFContextInMemory();
Eric Christopher7370b552012-11-12 21:40:38 +0000232 virtual bool isLittleEndian() const { return IsLittleEndian; }
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000233 virtual uint8_t getAddressSize() const { return AddressSize; }
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000234 virtual const Section &getInfoSection() { return InfoSection; }
David Blaikiebc563272013-12-13 21:33:40 +0000235 virtual const TypeSectionMap &getTypesSections() { return TypesSections; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000236 virtual StringRef getAbbrevSection() { return AbbrevSection; }
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000237 virtual const Section &getLocSection() { return LocSection; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000238 virtual StringRef getARangeSection() { return ARangeSection; }
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000239 virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000240 virtual const Section &getLineSection() { return LineSection; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000241 virtual StringRef getStringSection() { return StringSection; }
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000242 virtual StringRef getRangeSection() { return RangeSection; }
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000243 virtual StringRef getPubNamesSection() { return PubNamesSection; }
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000244 virtual StringRef getPubTypesSection() { return PubTypesSection; }
David Blaikie404d3042013-09-19 23:01:29 +0000245 virtual StringRef getGnuPubNamesSection() { return GnuPubNamesSection; }
David Blaikieecd21ff2013-09-24 19:50:00 +0000246 virtual StringRef getGnuPubTypesSection() { return GnuPubTypesSection; }
Eric Christopherda4b2192013-01-02 23:52:13 +0000247
248 // Sections for DWARF5 split dwarf proposal.
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000249 virtual const Section &getInfoDWOSection() { return InfoDWOSection; }
David Blaikie92d9d622014-01-09 05:08:24 +0000250 virtual const TypeSectionMap &getTypesDWOSections() {
251 return TypesDWOSections;
252 }
Eric Christopherda4b2192013-01-02 23:52:13 +0000253 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
254 virtual StringRef getStringDWOSection() { return StringDWOSection; }
Eric Christopher2cbd5762013-01-07 19:32:41 +0000255 virtual StringRef getStringOffsetDWOSection() {
256 return StringOffsetDWOSection;
257 }
Eric Christopherda4b2192013-01-02 23:52:13 +0000258 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
Eric Christopher962c9082013-01-15 23:56:56 +0000259 virtual StringRef getAddrSection() {
260 return AddrSection;
261 }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000262};
263
264}
265
266#endif