blob: 058476e34d376fb2c886a630ea0bbd243776cc52 [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"
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000019#include "llvm/ADT/OwningPtr.h"
20#include "llvm/ADT/SmallVector.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000021#include "llvm/DebugInfo/DIContext.h"
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000022
23namespace llvm {
24
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000025/// DWARFContext
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.
29class DWARFContext : public DIContext {
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000030 SmallVector<DWARFCompileUnit, 1> CUs;
31 OwningPtr<DWARFDebugAbbrev> Abbrev;
David Blaikie18e73502013-06-19 21:37:13 +000032 OwningPtr<DWARFDebugLoc> Loc;
Benjamin Kramera6002fd2011-09-14 01:09:52 +000033 OwningPtr<DWARFDebugAranges> Aranges;
Benjamin Kramer5acab502011-09-15 02:12:05 +000034 OwningPtr<DWARFDebugLine> Line;
Eli Benderskyfd08bc12013-02-05 23:30:58 +000035 OwningPtr<DWARFDebugFrame> DebugFrame;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000036
Eric Christopherda4b2192013-01-02 23:52:13 +000037 SmallVector<DWARFCompileUnit, 1> DWOCUs;
38 OwningPtr<DWARFDebugAbbrev> AbbrevDWO;
39
Craig Topperb1d83e82012-09-18 02:01:41 +000040 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
41 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000042
43 /// Read compile units from the debug_info section and store them in CUs.
44 void parseCompileUnits();
Eric Christopher7370b552012-11-12 21:40:38 +000045
Eric Christopherda4b2192013-01-02 23:52:13 +000046 /// Read compile units from the debug_info.dwo section and store them in
47 /// DWOCUs.
48 void parseDWOCompileUnits();
49
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000050public:
Eric Christopher7370b552012-11-12 21:40:38 +000051 DWARFContext() {}
Eli Bendersky7a94daa2013-01-25 20:26:43 +000052 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
Eric Christopher7c678de2012-11-07 23:22:07 +000053
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000054 /// Get the number of compile units in this context.
55 unsigned getNumCompileUnits() {
56 if (CUs.empty())
57 parseCompileUnits();
58 return CUs.size();
59 }
Eric Christopherda4b2192013-01-02 23:52:13 +000060
61 /// Get the number of compile units in the DWO context.
62 unsigned getNumDWOCompileUnits() {
63 if (DWOCUs.empty())
64 parseDWOCompileUnits();
65 return DWOCUs.size();
66 }
67
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000068 /// Get the compile unit at the specified index for this compile unit.
69 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
70 if (CUs.empty())
71 parseCompileUnits();
72 return &CUs[index];
73 }
74
Eric Christopherda4b2192013-01-02 23:52:13 +000075 /// Get the compile unit at the specified index for the DWO compile units.
76 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
77 if (DWOCUs.empty())
78 parseDWOCompileUnits();
79 return &DWOCUs[index];
80 }
81
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000082 /// Get a pointer to the parsed DebugAbbrev object.
83 const DWARFDebugAbbrev *getDebugAbbrev();
84
David Blaikie18e73502013-06-19 21:37:13 +000085 /// Get a pointer to the parsed DebugLoc object.
86 const DWARFDebugLoc *getDebugLoc();
87
Eric Christopherda4b2192013-01-02 23:52:13 +000088 /// Get a pointer to the parsed dwo abbreviations object.
89 const DWARFDebugAbbrev *getDebugAbbrevDWO();
90
Benjamin Kramera6002fd2011-09-14 01:09:52 +000091 /// Get a pointer to the parsed DebugAranges object.
92 const DWARFDebugAranges *getDebugAranges();
93
Eli Benderskyfd08bc12013-02-05 23:30:58 +000094 /// Get a pointer to the parsed frame information object.
95 const DWARFDebugFrame *getDebugFrame();
96
Benjamin Kramer679e1752011-09-15 20:43:18 +000097 /// Get a pointer to a parsed line table corresponding to a compile unit.
98 const DWARFDebugLine::LineTable *
99 getLineTableForCompileUnit(DWARFCompileUnit *cu);
Benjamin Kramer5acab502011-09-15 02:12:05 +0000100
Alexey Samsonov45be7932012-08-30 07:49:50 +0000101 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
102 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Andrew Kaylor9a8ff812013-01-26 00:28:05 +0000103 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
104 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000105 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
106 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Benjamin Kramer2602ca62011-09-15 20:43:22 +0000107
Eric Christopher7370b552012-11-12 21:40:38 +0000108 virtual bool isLittleEndian() const = 0;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000109 virtual uint8_t getAddressSize() const = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000110 virtual const RelocAddrMap &infoRelocMap() const = 0;
Andrew Kaylord55d7012013-01-25 22:50:58 +0000111 virtual const RelocAddrMap &lineRelocMap() const = 0;
David Blaikie18e73502013-06-19 21:37:13 +0000112 virtual const RelocAddrMap &locRelocMap() const = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000113 virtual StringRef getInfoSection() = 0;
114 virtual StringRef getAbbrevSection() = 0;
David Blaikie18e73502013-06-19 21:37:13 +0000115 virtual StringRef getLocSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000116 virtual StringRef getARangeSection() = 0;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000117 virtual StringRef getDebugFrameSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000118 virtual StringRef getLineSection() = 0;
119 virtual StringRef getStringSection() = 0;
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000120 virtual StringRef getRangeSection() = 0;
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000121 virtual StringRef getPubNamesSection() = 0;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000122
Eric Christopherda4b2192013-01-02 23:52:13 +0000123 // Sections for DWARF5 split dwarf proposal.
124 virtual StringRef getInfoDWOSection() = 0;
125 virtual StringRef getAbbrevDWOSection() = 0;
126 virtual StringRef getStringDWOSection() = 0;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000127 virtual StringRef getStringOffsetDWOSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000128 virtual StringRef getRangeDWOSection() = 0;
Eric Christopher962c9082013-01-15 23:56:56 +0000129 virtual StringRef getAddrSection() = 0;
Eric Christopherda4b2192013-01-02 23:52:13 +0000130 virtual const RelocAddrMap &infoDWORelocMap() const = 0;
131
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000132 static bool isSupportedVersion(unsigned version) {
Eric Christopherf7d848d2013-08-06 01:38:27 +0000133 return version == 2 || version == 3 || version == 4;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000134 }
Alexey Samsonov45be7932012-08-30 07:49:50 +0000135private:
136 /// Return the compile unit that includes an offset (relative to .debug_info).
137 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000138
Alexey Samsonov45be7932012-08-30 07:49:50 +0000139 /// Return the compile unit which contains instruction with provided
140 /// address.
141 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
Alexey Samsonov45be7932012-08-30 07:49:50 +0000142};
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000143
144/// DWARFContextInMemory is the simplest possible implementation of a
145/// DWARFContext. It assumes all content is available in memory and stores
146/// pointers to it.
147class DWARFContextInMemory : public DWARFContext {
David Blaikiea379b1812011-12-20 02:50:00 +0000148 virtual void anchor();
Eric Christopher7370b552012-11-12 21:40:38 +0000149 bool IsLittleEndian;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000150 uint8_t AddressSize;
Eric Christopherda4b2192013-01-02 23:52:13 +0000151 RelocAddrMap InfoRelocMap;
David Blaikie18e73502013-06-19 21:37:13 +0000152 RelocAddrMap LocRelocMap;
Andrew Kaylord55d7012013-01-25 22:50:58 +0000153 RelocAddrMap LineRelocMap;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000154 StringRef InfoSection;
155 StringRef AbbrevSection;
David Blaikie18e73502013-06-19 21:37:13 +0000156 StringRef LocSection;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000157 StringRef ARangeSection;
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000158 StringRef DebugFrameSection;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000159 StringRef LineSection;
160 StringRef StringSection;
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000161 StringRef RangeSection;
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000162 StringRef PubNamesSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000163
164 // Sections for DWARF5 split dwarf proposal.
165 RelocAddrMap InfoDWORelocMap;
166 StringRef InfoDWOSection;
167 StringRef AbbrevDWOSection;
168 StringRef StringDWOSection;
Eric Christopher2cbd5762013-01-07 19:32:41 +0000169 StringRef StringOffsetDWOSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000170 StringRef RangeDWOSection;
Eric Christopher962c9082013-01-15 23:56:56 +0000171 StringRef AddrSection;
Eric Christopherda4b2192013-01-02 23:52:13 +0000172
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000173 SmallVector<MemoryBuffer*, 4> UncompressedSections;
174
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000175public:
Eric Christopher7370b552012-11-12 21:40:38 +0000176 DWARFContextInMemory(object::ObjectFile *);
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000177 ~DWARFContextInMemory();
Eric Christopher7370b552012-11-12 21:40:38 +0000178 virtual bool isLittleEndian() const { return IsLittleEndian; }
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000179 virtual uint8_t getAddressSize() const { return AddressSize; }
Eric Christopherda4b2192013-01-02 23:52:13 +0000180 virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; }
David Blaikie18e73502013-06-19 21:37:13 +0000181 virtual const RelocAddrMap &locRelocMap() const { return LocRelocMap; }
Andrew Kaylord55d7012013-01-25 22:50:58 +0000182 virtual const RelocAddrMap &lineRelocMap() const { return LineRelocMap; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000183 virtual StringRef getInfoSection() { return InfoSection; }
184 virtual StringRef getAbbrevSection() { return AbbrevSection; }
David Blaikie18e73502013-06-19 21:37:13 +0000185 virtual StringRef getLocSection() { return LocSection; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000186 virtual StringRef getARangeSection() { return ARangeSection; }
Eli Benderskyfd08bc12013-02-05 23:30:58 +0000187 virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000188 virtual StringRef getLineSection() { return LineSection; }
189 virtual StringRef getStringSection() { return StringSection; }
Alexey Samsonov034e57a2012-08-27 07:17:47 +0000190 virtual StringRef getRangeSection() { return RangeSection; }
Krzysztof Parzyszek97438dc2013-02-12 16:20:28 +0000191 virtual StringRef getPubNamesSection() { return PubNamesSection; }
Eric Christopherda4b2192013-01-02 23:52:13 +0000192
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; }
Eric Christopher2cbd5762013-01-07 19:32:41 +0000197 virtual StringRef getStringOffsetDWOSection() {
198 return StringOffsetDWOSection;
199 }
Eric Christopherda4b2192013-01-02 23:52:13 +0000200 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
Eric Christopher962c9082013-01-15 23:56:56 +0000201 virtual StringRef getAddrSection() {
202 return AddrSection;
203 }
Eric Christopherb2120fd2013-01-07 22:40:48 +0000204 virtual const RelocAddrMap &infoDWORelocMap() const {
205 return InfoDWORelocMap;
206 }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000207};
208
209}
210
211#endif