blob: 03863ab8b1e2a1d540a3653bb8b71b6e0178c268 [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"
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000020#include "llvm/ADT/OwningPtr.h"
21#include "llvm/ADT/SmallVector.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000022#include "llvm/DebugInfo/DIContext.h"
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000023
24namespace llvm {
25
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000026/// DWARFContext
27/// This data structure is the top level entity that deals with dwarf debug
28/// information parsing. The actual data is supplied through pure virtual
29/// methods that a concrete implementation provides.
30class DWARFContext : public DIContext {
Alexey Samsonova9debbf2013-08-23 06:56:01 +000031 SmallVector<DWARFCompileUnit *, 1> CUs;
David Blaikie03c089c2013-09-23 22:44:47 +000032 SmallVector<DWARFTypeUnit *, 1> TUs;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000033 OwningPtr<DWARFDebugAbbrev> Abbrev;
David Blaikie18e73502013-06-19 21:37:13 +000034 OwningPtr<DWARFDebugLoc> Loc;
Benjamin Kramera6002fd2011-09-14 01:09:52 +000035 OwningPtr<DWARFDebugAranges> Aranges;
Benjamin Kramer5acab502011-09-15 02:12:05 +000036 OwningPtr<DWARFDebugLine> Line;
Eli Benderskyfd08bc12013-02-05 23:30:58 +000037 OwningPtr<DWARFDebugFrame> DebugFrame;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000038
Alexey Samsonova9debbf2013-08-23 06:56:01 +000039 SmallVector<DWARFCompileUnit *, 1> DWOCUs;
Eric Christopherda4b2192013-01-02 23:52:13 +000040 OwningPtr<DWARFDebugAbbrev> AbbrevDWO;
41
Craig Topperb1d83e82012-09-18 02:01:41 +000042 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
43 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000044
45 /// Read compile units from the debug_info section and store them in CUs.
46 void parseCompileUnits();
Eric Christopher7370b552012-11-12 21:40:38 +000047
David Blaikie03c089c2013-09-23 22:44:47 +000048 /// Read type units from the debug_types sections and store them in CUs.
49 void parseTypeUnits();
50
Eric Christopherda4b2192013-01-02 23:52:13 +000051 /// Read compile units from the debug_info.dwo section and store them in
52 /// DWOCUs.
53 void parseDWOCompileUnits();
54
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000055public:
David Blaikie1b5ee5d2013-09-23 17:42:01 +000056 struct Section {
57 StringRef Data;
58 RelocAddrMap Relocs;
59 };
60
Alexey Samsonovc2e00872013-08-06 10:32:39 +000061 DWARFContext() : DIContext(CK_DWARF) {}
Alexey Samsonova9debbf2013-08-23 06:56:01 +000062 virtual ~DWARFContext();
Alexey Samsonovc2e00872013-08-06 10:32:39 +000063
64 static bool classof(const DIContext *DICtx) {
65 return DICtx->getKind() == CK_DWARF;
66 }
67
Eli Bendersky7a94daa2013-01-25 20:26:43 +000068 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
Eric Christopher7c678de2012-11-07 23:22:07 +000069
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000070 /// Get the number of compile units in this context.
71 unsigned getNumCompileUnits() {
72 if (CUs.empty())
73 parseCompileUnits();
74 return CUs.size();
75 }
Eric Christopherda4b2192013-01-02 23:52:13 +000076
David Blaikie03c089c2013-09-23 22:44:47 +000077 /// Get the number of compile units in this context.
78 unsigned getNumTypeUnits() {
79 if (TUs.empty())
80 parseTypeUnits();
81 return TUs.size();
82 }
83
Eric Christopherda4b2192013-01-02 23:52:13 +000084 /// Get the number of compile units in the DWO context.
85 unsigned getNumDWOCompileUnits() {
86 if (DWOCUs.empty())
87 parseDWOCompileUnits();
88 return DWOCUs.size();
89 }
90
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000091 /// Get the compile unit at the specified index for this compile unit.
92 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
93 if (CUs.empty())
94 parseCompileUnits();
Alexey Samsonova9debbf2013-08-23 06:56:01 +000095 return CUs[index];
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000096 }
97
David Blaikie03c089c2013-09-23 22:44:47 +000098 /// Get the type unit at the specified index for this compile unit.
99 DWARFTypeUnit *getTypeUnitAtIndex(unsigned index) {
100 if (TUs.empty())
101 parseTypeUnits();
102 return TUs[index];
103 }
104
Eric Christopherda4b2192013-01-02 23:52:13 +0000105 /// Get the compile unit at the specified index for the DWO compile units.
106 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
107 if (DWOCUs.empty())
108 parseDWOCompileUnits();
Alexey Samsonova9debbf2013-08-23 06:56:01 +0000109 return DWOCUs[index];
Eric Christopherda4b2192013-01-02 23:52:13 +0000110 }
111
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000112 /// Get a pointer to the parsed DebugAbbrev object.
113 const DWARFDebugAbbrev *getDebugAbbrev();
114
David Blaikie18e73502013-06-19 21:37:13 +0000115 /// Get a pointer to the parsed DebugLoc object.
116 const DWARFDebugLoc *getDebugLoc();
117
Eric Christopherda4b2192013-01-02 23:52:13 +0000118 /// Get a pointer to the parsed dwo abbreviations object.
119 const DWARFDebugAbbrev *getDebugAbbrevDWO();
120
Benjamin Kramera6002fd2011-09-14 01:09:52 +0000121 /// Get a pointer to the parsed DebugAranges object.
122 const DWARFDebugAranges *getDebugAranges();
123
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000124 /// Get a pointer to the parsed frame information object.
125 const DWARFDebugFrame *getDebugFrame();
126
Benjamin Kramer679e1752011-09-15 20:43:18 +0000127 /// Get a pointer to a parsed line table corresponding to a compile unit.
128 const DWARFDebugLine::LineTable *
129 getLineTableForCompileUnit(DWARFCompileUnit *cu);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000130
Alexey Samsonov45be7932012-08-30 07:49:50 +0000131 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
132 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000133 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
134 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000135 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
136 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Benjamin Kramer2602ca62011-09-15 20:43:22 +0000137
Eric Christopher7370b552012-11-12 21:40:38 +0000138 virtual bool isLittleEndian() const = 0;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000139 virtual uint8_t getAddressSize() const = 0;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000140 virtual const Section &getInfoSection() = 0;
David Blaikie03c089c2013-09-23 22:44:47 +0000141 virtual const std::map<object::SectionRef, Section> &getTypesSections() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000142 virtual StringRef getAbbrevSection() = 0;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000143 virtual const Section &getLocSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000144 virtual StringRef getARangeSection() = 0;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000145 virtual StringRef getDebugFrameSection() = 0;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000146 virtual const Section &getLineSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000147 virtual StringRef getStringSection() = 0;
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000148 virtual StringRef getRangeSection() = 0;
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000149 virtual StringRef getPubNamesSection() = 0;
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000150 virtual StringRef getPubTypesSection() = 0;
David Blaikie404d3042013-09-19 23:01:29 +0000151 virtual StringRef getGnuPubNamesSection() = 0;
David Blaikieecd21ff2013-09-24 19:50:00 +0000152 virtual StringRef getGnuPubTypesSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000153
Eric Christopherda4b2192013-01-02 23:52:13 +0000154 // Sections for DWARF5 split dwarf proposal.
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000155 virtual const Section &getInfoDWOSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000156 virtual StringRef getAbbrevDWOSection() = 0;
157 virtual StringRef getStringDWOSection() = 0;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000158 virtual StringRef getStringOffsetDWOSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000159 virtual StringRef getRangeDWOSection() = 0;
Eric Christopher962c9082013-01-15 23:56:56 +0000160 virtual StringRef getAddrSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000161
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000162 static bool isSupportedVersion(unsigned version) {
Eric Christopherf7d848d2013-08-06 01:38:27 +0000163 return version == 2 || version == 3 || version == 4;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000164 }
Alexey Samsonov45be7932012-08-30 07:49:50 +0000165private:
166 /// Return the compile unit that includes an offset (relative to .debug_info).
167 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000168
Alexey Samsonov45be7932012-08-30 07:49:50 +0000169 /// Return the compile unit which contains instruction with provided
170 /// address.
171 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
Alexey Samsonov45be7932012-08-30 07:49:50 +0000172};
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000173
174/// DWARFContextInMemory is the simplest possible implementation of a
175/// DWARFContext. It assumes all content is available in memory and stores
176/// pointers to it.
177class DWARFContextInMemory : public DWARFContext {
David Blaikiea379b1812011-12-20 02:50:00 +0000178 virtual void anchor();
Eric Christopher7370b552012-11-12 21:40:38 +0000179 bool IsLittleEndian;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000180 uint8_t AddressSize;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000181 Section InfoSection;
David Blaikie03c089c2013-09-23 22:44:47 +0000182 std::map<object::SectionRef, Section> TypesSections;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000183 StringRef AbbrevSection;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000184 Section LocSection;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000185 StringRef ARangeSection;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000186 StringRef DebugFrameSection;
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000187 Section LineSection;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000188 StringRef StringSection;
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000189 StringRef RangeSection;
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000190 StringRef PubNamesSection;
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000191 StringRef PubTypesSection;
David Blaikie404d3042013-09-19 23:01:29 +0000192 StringRef GnuPubNamesSection;
David Blaikieecd21ff2013-09-24 19:50:00 +0000193 StringRef GnuPubTypesSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000194
195 // Sections for DWARF5 split dwarf proposal.
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000196 Section InfoDWOSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000197 StringRef AbbrevDWOSection;
198 StringRef StringDWOSection;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000199 StringRef StringOffsetDWOSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000200 StringRef RangeDWOSection;
Eric Christopher962c9082013-01-15 23:56:56 +0000201 StringRef AddrSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000202
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000203 SmallVector<MemoryBuffer*, 4> UncompressedSections;
204
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000205public:
Eric Christopher7370b552012-11-12 21:40:38 +0000206 DWARFContextInMemory(object::ObjectFile *);
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000207 ~DWARFContextInMemory();
Eric Christopher7370b552012-11-12 21:40:38 +0000208 virtual bool isLittleEndian() const { return IsLittleEndian; }
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000209 virtual uint8_t getAddressSize() const { return AddressSize; }
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000210 virtual const Section &getInfoSection() { return InfoSection; }
David Blaikie03c089c2013-09-23 22:44:47 +0000211 virtual const std::map<object::SectionRef, Section> &getTypesSections() {
212 return TypesSections;
213 }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000214 virtual StringRef getAbbrevSection() { return AbbrevSection; }
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000215 virtual const Section &getLocSection() { return LocSection; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000216 virtual StringRef getARangeSection() { return ARangeSection; }
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000217 virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000218 virtual const Section &getLineSection() { return LineSection; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000219 virtual StringRef getStringSection() { return StringSection; }
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000220 virtual StringRef getRangeSection() { return RangeSection; }
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000221 virtual StringRef getPubNamesSection() { return PubNamesSection; }
Eric Christopher4c7e6ba2013-09-25 23:02:41 +0000222 virtual StringRef getPubTypesSection() { return PubTypesSection; }
David Blaikie404d3042013-09-19 23:01:29 +0000223 virtual StringRef getGnuPubNamesSection() { return GnuPubNamesSection; }
David Blaikieecd21ff2013-09-24 19:50:00 +0000224 virtual StringRef getGnuPubTypesSection() { return GnuPubTypesSection; }
Eric Christopherda4b2192013-01-02 23:52:13 +0000225
226 // Sections for DWARF5 split dwarf proposal.
David Blaikie1b5ee5d2013-09-23 17:42:01 +0000227 virtual const Section &getInfoDWOSection() { return InfoDWOSection; }
Eric Christopherda4b2192013-01-02 23:52:13 +0000228 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
229 virtual StringRef getStringDWOSection() { return StringDWOSection; }
Eric Christopher2cbd5762013-01-07 19:32:41 +0000230 virtual StringRef getStringOffsetDWOSection() {
231 return StringOffsetDWOSection;
232 }
Eric Christopherda4b2192013-01-02 23:52:13 +0000233 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
Eric Christopher962c9082013-01-15 23:56:56 +0000234 virtual StringRef getAddrSection() {
235 return AddrSection;
236 }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000237};
238
239}
240
241#endif