blob: e74b5baaa0a32b977ad61f1179fd91382ce30d4c [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;
Eric Christopherda4b2192013-01-02 23:52:13 +000041 OwningPtr<DWARFDebugAbbrev> AbbrevDWO;
42
Craig Topperb1d83e82012-09-18 02:01:41 +000043 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
44 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000045
46 /// Read compile units from the debug_info section and store them in CUs.
47 void parseCompileUnits();
Eric Christopher7370b552012-11-12 21:40:38 +000048
David Blaikie03c089c2013-09-23 22:44:47 +000049 /// Read type units from the debug_types sections and store them in CUs.
50 void parseTypeUnits();
51
Eric Christopherda4b2192013-01-02 23:52:13 +000052 /// Read compile units from the debug_info.dwo section and store them in
53 /// DWOCUs.
54 void parseDWOCompileUnits();
55
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000056public:
David Blaikie1b5ee5d2013-09-23 17:42:01 +000057 struct Section {
58 StringRef Data;
59 RelocAddrMap Relocs;
60 };
61
Alexey Samsonovc2e00872013-08-06 10:32:39 +000062 DWARFContext() : DIContext(CK_DWARF) {}
Alexey Samsonova9debbf2013-08-23 06:56:01 +000063 virtual ~DWARFContext();
Alexey Samsonovc2e00872013-08-06 10:32:39 +000064
65 static bool classof(const DIContext *DICtx) {
66 return DICtx->getKind() == CK_DWARF;
67 }
68
Eli Bendersky7a94daa2013-01-25 20:26:43 +000069 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
Eric Christopher7c678de2012-11-07 23:22:07 +000070
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000071 /// Get the number of compile units in this context.
72 unsigned getNumCompileUnits() {
73 if (CUs.empty())
74 parseCompileUnits();
75 return CUs.size();
76 }
Eric Christopherda4b2192013-01-02 23:52:13 +000077
David Blaikie03c089c2013-09-23 22:44:47 +000078 /// Get the number of compile units in this context.
79 unsigned getNumTypeUnits() {
80 if (TUs.empty())
81 parseTypeUnits();
82 return TUs.size();
83 }
84
Eric Christopherda4b2192013-01-02 23:52:13 +000085 /// Get the number of compile units in the DWO context.
86 unsigned getNumDWOCompileUnits() {
87 if (DWOCUs.empty())
88 parseDWOCompileUnits();
89 return DWOCUs.size();
90 }
91
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000092 /// Get the compile unit at the specified index for this compile unit.
93 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
94 if (CUs.empty())
95 parseCompileUnits();
Alexey Samsonova9debbf2013-08-23 06:56:01 +000096 return CUs[index];
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000097 }
98
David Blaikie03c089c2013-09-23 22:44:47 +000099 /// Get the type unit at the specified index for this compile unit.
100 DWARFTypeUnit *getTypeUnitAtIndex(unsigned index) {
101 if (TUs.empty())
102 parseTypeUnits();
103 return TUs[index];
104 }
105
Eric Christopherda4b2192013-01-02 23:52:13 +0000106 /// Get the compile unit at the specified index for the DWO compile units.
107 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
108 if (DWOCUs.empty())
109 parseDWOCompileUnits();
Alexey Samsonova9debbf2013-08-23 06:56:01 +0000110 return DWOCUs[index];
Eric Christopherda4b2192013-01-02 23:52:13 +0000111 }
112
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000113 /// Get a pointer to the parsed DebugAbbrev object.
114 const DWARFDebugAbbrev *getDebugAbbrev();
115
David Blaikie18e73502013-06-19 21:37:13 +0000116 /// Get a pointer to the parsed DebugLoc object.
117 const DWARFDebugLoc *getDebugLoc();
118
Eric Christopherda4b2192013-01-02 23:52:13 +0000119 /// Get a pointer to the parsed dwo abbreviations object.
120 const DWARFDebugAbbrev *getDebugAbbrevDWO();
121
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000122 /// Get a pointer to the parsed DebugAranges object.
123 const DWARFDebugAranges *getDebugAranges();
124
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000125 /// Get a pointer to the parsed frame information object.
126 const DWARFDebugFrame *getDebugFrame();
127
Benjamin Kramer679e1752011-09-15 20:43:18 +0000128 /// Get a pointer to a parsed line table corresponding to a compile unit.
129 const DWARFDebugLine::LineTable *
130 getLineTableForCompileUnit(DWARFCompileUnit *cu);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000131
Alexey Samsonov45be7932012-08-30 07:49:50 +0000132 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
133 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000134 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
135 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000136 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
137 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Benjamin Kramer2602ca62011-09-15 20:43:22 +0000138
Eric Christopher7370b552012-11-12 21:40:38 +0000139 virtual bool isLittleEndian() const = 0;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000140 virtual uint8_t getAddressSize() const = 0;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000141 virtual const Section &getInfoSection() = 0;
David Blaikiebc563272013-12-13 21:33:40 +0000142 typedef MapVector<object::SectionRef, Section,
143 std::map<object::SectionRef, unsigned> > TypeSectionMap;
144 virtual const TypeSectionMap &getTypesSections() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000145 virtual StringRef getAbbrevSection() = 0;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000146 virtual const Section &getLocSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000147 virtual StringRef getARangeSection() = 0;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000148 virtual StringRef getDebugFrameSection() = 0;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000149 virtual const Section &getLineSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000150 virtual StringRef getStringSection() = 0;
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000151 virtual StringRef getRangeSection() = 0;
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000152 virtual StringRef getPubNamesSection() = 0;
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000153 virtual StringRef getPubTypesSection() = 0;
David Blaikie404d3042013-09-19 23:01:29 +0000154 virtual StringRef getGnuPubNamesSection() = 0;
David Blaikieecd21ff2013-09-24 19:50:00 +0000155 virtual StringRef getGnuPubTypesSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000156
Eric Christopherda4b2192013-01-02 23:52:13 +0000157 // Sections for DWARF5 split dwarf proposal.
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000158 virtual const Section &getInfoDWOSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000159 virtual StringRef getAbbrevDWOSection() = 0;
160 virtual StringRef getStringDWOSection() = 0;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000161 virtual StringRef getStringOffsetDWOSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000162 virtual StringRef getRangeDWOSection() = 0;
Eric Christopher962c9082013-01-15 23:56:56 +0000163 virtual StringRef getAddrSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000164
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000165 static bool isSupportedVersion(unsigned version) {
Eric Christopherf7d848d2013-08-06 01:38:27 +0000166 return version == 2 || version == 3 || version == 4;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000167 }
Alexey Samsonov45be7932012-08-30 07:49:50 +0000168private:
169 /// Return the compile unit that includes an offset (relative to .debug_info).
170 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000171
Alexey Samsonov45be7932012-08-30 07:49:50 +0000172 /// Return the compile unit which contains instruction with provided
173 /// address.
174 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
Alexey Samsonov45be7932012-08-30 07:49:50 +0000175};
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000176
177/// DWARFContextInMemory is the simplest possible implementation of a
178/// DWARFContext. It assumes all content is available in memory and stores
179/// pointers to it.
180class DWARFContextInMemory : public DWARFContext {
David Blaikiea379b1812011-12-20 02:50:00 +0000181 virtual void anchor();
Eric Christopher7370b552012-11-12 21:40:38 +0000182 bool IsLittleEndian;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000183 uint8_t AddressSize;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000184 Section InfoSection;
David Blaikiebc563272013-12-13 21:33:40 +0000185 TypeSectionMap TypesSections;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000186 StringRef AbbrevSection;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000187 Section LocSection;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000188 StringRef ARangeSection;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000189 StringRef DebugFrameSection;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000190 Section LineSection;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000191 StringRef StringSection;
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000192 StringRef RangeSection;
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000193 StringRef PubNamesSection;
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000194 StringRef PubTypesSection;
David Blaikie404d3042013-09-19 23:01:29 +0000195 StringRef GnuPubNamesSection;
David Blaikieecd21ff2013-09-24 19:50:00 +0000196 StringRef GnuPubTypesSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000197
198 // Sections for DWARF5 split dwarf proposal.
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000199 Section InfoDWOSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000200 StringRef AbbrevDWOSection;
201 StringRef StringDWOSection;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000202 StringRef StringOffsetDWOSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000203 StringRef RangeDWOSection;
Eric Christopher962c9082013-01-15 23:56:56 +0000204 StringRef AddrSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000205
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000206 SmallVector<MemoryBuffer*, 4> UncompressedSections;
207
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000208public:
Eric Christopher7370b552012-11-12 21:40:38 +0000209 DWARFContextInMemory(object::ObjectFile *);
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000210 ~DWARFContextInMemory();
Eric Christopher7370b552012-11-12 21:40:38 +0000211 virtual bool isLittleEndian() const { return IsLittleEndian; }
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000212 virtual uint8_t getAddressSize() const { return AddressSize; }
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000213 virtual const Section &getInfoSection() { return InfoSection; }
David Blaikiebc563272013-12-13 21:33:40 +0000214 virtual const TypeSectionMap &getTypesSections() { return TypesSections; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000215 virtual StringRef getAbbrevSection() { return AbbrevSection; }
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000216 virtual const Section &getLocSection() { return LocSection; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000217 virtual StringRef getARangeSection() { return ARangeSection; }
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000218 virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000219 virtual const Section &getLineSection() { return LineSection; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000220 virtual StringRef getStringSection() { return StringSection; }
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000221 virtual StringRef getRangeSection() { return RangeSection; }
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000222 virtual StringRef getPubNamesSection() { return PubNamesSection; }
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000223 virtual StringRef getPubTypesSection() { return PubTypesSection; }
David Blaikie404d3042013-09-19 23:01:29 +0000224 virtual StringRef getGnuPubNamesSection() { return GnuPubNamesSection; }
David Blaikieecd21ff2013-09-24 19:50:00 +0000225 virtual StringRef getGnuPubTypesSection() { return GnuPubTypesSection; }
Eric Christopherda4b2192013-01-02 23:52:13 +0000226
227 // Sections for DWARF5 split dwarf proposal.
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000228 virtual const Section &getInfoDWOSection() { return InfoDWOSection; }
Eric Christopherda4b2192013-01-02 23:52:13 +0000229 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
230 virtual StringRef getStringDWOSection() { return StringDWOSection; }
Eric Christopher2cbd5762013-01-07 19:32:41 +0000231 virtual StringRef getStringOffsetDWOSection() {
232 return StringOffsetDWOSection;
233 }
Eric Christopherda4b2192013-01-02 23:52:13 +0000234 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
Eric Christopher962c9082013-01-15 23:56:56 +0000235 virtual StringRef getAddrSection() {
236 return AddrSection;
237 }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000238};
239
240}
241
242#endif