blob: 78c18e61680a70128cceacbfe9d32f2468545bfe [file] [log] [blame]
Benjamin Kramer72c0d7f2011-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 Kramer358f4fd2011-09-14 01:09:52 +000014#include "DWARFDebugAranges.h"
Eli Bendersky60bdc5b2013-02-05 23:30:58 +000015#include "DWARFDebugFrame.h"
Benjamin Kramerb848e972011-09-15 02:12:05 +000016#include "DWARFDebugLine.h"
Alexey Samsonoveceb5b92012-08-27 07:17:47 +000017#include "DWARFDebugRangeList.h"
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000018#include "llvm/ADT/OwningPtr.h"
19#include "llvm/ADT/SmallVector.h"
Chandler Carrutha1514e22012-12-04 07:12:27 +000020#include "llvm/DebugInfo/DIContext.h"
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000021
22namespace llvm {
23
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000024/// DWARFContext
25/// This data structure is the top level entity that deals with dwarf debug
26/// information parsing. The actual data is supplied through pure virtual
27/// methods that a concrete implementation provides.
28class DWARFContext : public DIContext {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000029 SmallVector<DWARFCompileUnit, 1> CUs;
30 OwningPtr<DWARFDebugAbbrev> Abbrev;
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000031 OwningPtr<DWARFDebugAranges> Aranges;
Benjamin Kramerb848e972011-09-15 02:12:05 +000032 OwningPtr<DWARFDebugLine> Line;
Eli Bendersky60bdc5b2013-02-05 23:30:58 +000033 OwningPtr<DWARFDebugFrame> DebugFrame;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000034
Eric Christopher82de10a2013-01-02 23:52:13 +000035 SmallVector<DWARFCompileUnit, 1> DWOCUs;
36 OwningPtr<DWARFDebugAbbrev> AbbrevDWO;
37
Craig Topperc2945e42012-09-18 02:01:41 +000038 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
39 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000040
41 /// Read compile units from the debug_info section and store them in CUs.
42 void parseCompileUnits();
Eric Christopherd1726a42012-11-12 21:40:38 +000043
Eric Christopher82de10a2013-01-02 23:52:13 +000044 /// Read compile units from the debug_info.dwo section and store them in
45 /// DWOCUs.
46 void parseDWOCompileUnits();
47
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000048public:
Eric Christopherd1726a42012-11-12 21:40:38 +000049 DWARFContext() {}
Eli Bendersky939a4e82013-01-25 20:26:43 +000050 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
Eric Christopher806e03d2012-11-07 23:22:07 +000051
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000052 /// Get the number of compile units in this context.
53 unsigned getNumCompileUnits() {
54 if (CUs.empty())
55 parseCompileUnits();
56 return CUs.size();
57 }
Eric Christopher82de10a2013-01-02 23:52:13 +000058
59 /// Get the number of compile units in the DWO context.
60 unsigned getNumDWOCompileUnits() {
61 if (DWOCUs.empty())
62 parseDWOCompileUnits();
63 return DWOCUs.size();
64 }
65
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000066 /// Get the compile unit at the specified index for this compile unit.
67 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
68 if (CUs.empty())
69 parseCompileUnits();
70 return &CUs[index];
71 }
72
Eric Christopher82de10a2013-01-02 23:52:13 +000073 /// Get the compile unit at the specified index for the DWO compile units.
74 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
75 if (DWOCUs.empty())
76 parseDWOCompileUnits();
77 return &DWOCUs[index];
78 }
79
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000080 /// Get a pointer to the parsed DebugAbbrev object.
81 const DWARFDebugAbbrev *getDebugAbbrev();
82
Eric Christopher82de10a2013-01-02 23:52:13 +000083 /// Get a pointer to the parsed dwo abbreviations object.
84 const DWARFDebugAbbrev *getDebugAbbrevDWO();
85
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000086 /// Get a pointer to the parsed DebugAranges object.
87 const DWARFDebugAranges *getDebugAranges();
88
Eli Bendersky60bdc5b2013-02-05 23:30:58 +000089 /// Get a pointer to the parsed frame information object.
90 const DWARFDebugFrame *getDebugFrame();
91
Benjamin Kramerc26ed9b2011-09-15 20:43:18 +000092 /// Get a pointer to a parsed line table corresponding to a compile unit.
93 const DWARFDebugLine::LineTable *
94 getLineTableForCompileUnit(DWARFCompileUnit *cu);
Benjamin Kramerb848e972011-09-15 02:12:05 +000095
Alexey Samsonov38a63812012-08-30 07:49:50 +000096 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
97 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Andrew Kaylore27a7872013-01-26 00:28:05 +000098 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
99 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000100 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
101 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Benjamin Kramer101b1c52011-09-15 20:43:22 +0000102
Eric Christopherd1726a42012-11-12 21:40:38 +0000103 virtual bool isLittleEndian() const = 0;
Eli Bendersky60bdc5b2013-02-05 23:30:58 +0000104 virtual uint8_t getAddressSize() const = 0;
Eric Christopher82de10a2013-01-02 23:52:13 +0000105 virtual const RelocAddrMap &infoRelocMap() const = 0;
Andrew Kayloree7c0d22013-01-25 22:50:58 +0000106 virtual const RelocAddrMap &lineRelocMap() const = 0;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000107 virtual StringRef getInfoSection() = 0;
108 virtual StringRef getAbbrevSection() = 0;
109 virtual StringRef getARangeSection() = 0;
Eli Bendersky60bdc5b2013-02-05 23:30:58 +0000110 virtual StringRef getDebugFrameSection() = 0;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000111 virtual StringRef getLineSection() = 0;
112 virtual StringRef getStringSection() = 0;
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000113 virtual StringRef getRangeSection() = 0;
Krzysztof Parzyszeke38825f2013-02-12 16:20:28 +0000114 virtual StringRef getPubNamesSection() = 0;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000115
Eric Christopher82de10a2013-01-02 23:52:13 +0000116 // Sections for DWARF5 split dwarf proposal.
117 virtual StringRef getInfoDWOSection() = 0;
118 virtual StringRef getAbbrevDWOSection() = 0;
119 virtual StringRef getStringDWOSection() = 0;
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000120 virtual StringRef getStringOffsetDWOSection() = 0;
Eric Christopher82de10a2013-01-02 23:52:13 +0000121 virtual StringRef getRangeDWOSection() = 0;
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000122 virtual StringRef getAddrSection() = 0;
Eric Christopher82de10a2013-01-02 23:52:13 +0000123 virtual const RelocAddrMap &infoDWORelocMap() const = 0;
124
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000125 static bool isSupportedVersion(unsigned version) {
126 return version == 2 || version == 3;
127 }
Alexey Samsonov38a63812012-08-30 07:49:50 +0000128private:
129 /// Return the compile unit that includes an offset (relative to .debug_info).
130 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000131
Alexey Samsonov38a63812012-08-30 07:49:50 +0000132 /// Return the compile unit which contains instruction with provided
133 /// address.
134 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
Alexey Samsonov38a63812012-08-30 07:49:50 +0000135};
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000136
137/// DWARFContextInMemory is the simplest possible implementation of a
138/// DWARFContext. It assumes all content is available in memory and stores
139/// pointers to it.
140class DWARFContextInMemory : public DWARFContext {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000141 virtual void anchor();
Eric Christopherd1726a42012-11-12 21:40:38 +0000142 bool IsLittleEndian;
Eli Bendersky60bdc5b2013-02-05 23:30:58 +0000143 uint8_t AddressSize;
Eric Christopher82de10a2013-01-02 23:52:13 +0000144 RelocAddrMap InfoRelocMap;
Andrew Kayloree7c0d22013-01-25 22:50:58 +0000145 RelocAddrMap LineRelocMap;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000146 StringRef InfoSection;
147 StringRef AbbrevSection;
148 StringRef ARangeSection;
Eli Bendersky60bdc5b2013-02-05 23:30:58 +0000149 StringRef DebugFrameSection;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000150 StringRef LineSection;
151 StringRef StringSection;
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000152 StringRef RangeSection;
Krzysztof Parzyszeke38825f2013-02-12 16:20:28 +0000153 StringRef PubNamesSection;
Eric Christopher82de10a2013-01-02 23:52:13 +0000154
155 // Sections for DWARF5 split dwarf proposal.
156 RelocAddrMap InfoDWORelocMap;
157 StringRef InfoDWOSection;
158 StringRef AbbrevDWOSection;
159 StringRef StringDWOSection;
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000160 StringRef StringOffsetDWOSection;
Eric Christopher82de10a2013-01-02 23:52:13 +0000161 StringRef RangeDWOSection;
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000162 StringRef AddrSection;
Eric Christopher82de10a2013-01-02 23:52:13 +0000163
Alexey Samsonov005159e2013-04-23 10:17:34 +0000164 SmallVector<MemoryBuffer*, 4> UncompressedSections;
165
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000166public:
Eric Christopherd1726a42012-11-12 21:40:38 +0000167 DWARFContextInMemory(object::ObjectFile *);
Alexey Samsonov005159e2013-04-23 10:17:34 +0000168 ~DWARFContextInMemory();
Eric Christopherd1726a42012-11-12 21:40:38 +0000169 virtual bool isLittleEndian() const { return IsLittleEndian; }
Eli Bendersky60bdc5b2013-02-05 23:30:58 +0000170 virtual uint8_t getAddressSize() const { return AddressSize; }
Eric Christopher82de10a2013-01-02 23:52:13 +0000171 virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; }
Andrew Kayloree7c0d22013-01-25 22:50:58 +0000172 virtual const RelocAddrMap &lineRelocMap() const { return LineRelocMap; }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000173 virtual StringRef getInfoSection() { return InfoSection; }
174 virtual StringRef getAbbrevSection() { return AbbrevSection; }
175 virtual StringRef getARangeSection() { return ARangeSection; }
Eli Bendersky60bdc5b2013-02-05 23:30:58 +0000176 virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000177 virtual StringRef getLineSection() { return LineSection; }
178 virtual StringRef getStringSection() { return StringSection; }
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000179 virtual StringRef getRangeSection() { return RangeSection; }
Krzysztof Parzyszeke38825f2013-02-12 16:20:28 +0000180 virtual StringRef getPubNamesSection() { return PubNamesSection; }
Eric Christopher82de10a2013-01-02 23:52:13 +0000181
182 // Sections for DWARF5 split dwarf proposal.
183 virtual StringRef getInfoDWOSection() { return InfoDWOSection; }
184 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
185 virtual StringRef getStringDWOSection() { return StringDWOSection; }
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000186 virtual StringRef getStringOffsetDWOSection() {
187 return StringOffsetDWOSection;
188 }
Eric Christopher82de10a2013-01-02 23:52:13 +0000189 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000190 virtual StringRef getAddrSection() {
191 return AddrSection;
192 }
Eric Christophere7285c72013-01-07 22:40:48 +0000193 virtual const RelocAddrMap &infoDWORelocMap() const {
194 return InfoDWORelocMap;
195 }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000196};
197
198}
199
200#endif