blob: 9ff094bd484d4099e0b614cd56762927a83af7ba [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"
Benjamin Kramerb848e972011-09-15 02:12:05 +000015#include "DWARFDebugLine.h"
Alexey Samsonoveceb5b92012-08-27 07:17:47 +000016#include "DWARFDebugRangeList.h"
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000017#include "llvm/ADT/OwningPtr.h"
18#include "llvm/ADT/SmallVector.h"
Chandler Carrutha1514e22012-12-04 07:12:27 +000019#include "llvm/DebugInfo/DIContext.h"
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000020
21namespace llvm {
22
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000023/// DWARFContext
24/// This data structure is the top level entity that deals with dwarf debug
25/// information parsing. The actual data is supplied through pure virtual
26/// methods that a concrete implementation provides.
27class DWARFContext : public DIContext {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000028 SmallVector<DWARFCompileUnit, 1> CUs;
29 OwningPtr<DWARFDebugAbbrev> Abbrev;
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000030 OwningPtr<DWARFDebugAranges> Aranges;
Benjamin Kramerb848e972011-09-15 02:12:05 +000031 OwningPtr<DWARFDebugLine> Line;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000032
Eric Christopher82de10a2013-01-02 23:52:13 +000033 SmallVector<DWARFCompileUnit, 1> DWOCUs;
34 OwningPtr<DWARFDebugAbbrev> AbbrevDWO;
35
Craig Topperc2945e42012-09-18 02:01:41 +000036 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
37 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000038
39 /// Read compile units from the debug_info section and store them in CUs.
40 void parseCompileUnits();
Eric Christopherd1726a42012-11-12 21:40:38 +000041
Eric Christopher82de10a2013-01-02 23:52:13 +000042 /// Read compile units from the debug_info.dwo section and store them in
43 /// DWOCUs.
44 void parseDWOCompileUnits();
45
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000046public:
Eric Christopherd1726a42012-11-12 21:40:38 +000047 DWARFContext() {}
Eli Bendersky939a4e82013-01-25 20:26:43 +000048 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
Eric Christopher806e03d2012-11-07 23:22:07 +000049
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000050 /// Get the number of compile units in this context.
51 unsigned getNumCompileUnits() {
52 if (CUs.empty())
53 parseCompileUnits();
54 return CUs.size();
55 }
Eric Christopher82de10a2013-01-02 23:52:13 +000056
57 /// Get the number of compile units in the DWO context.
58 unsigned getNumDWOCompileUnits() {
59 if (DWOCUs.empty())
60 parseDWOCompileUnits();
61 return DWOCUs.size();
62 }
63
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000064 /// Get the compile unit at the specified index for this compile unit.
65 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
66 if (CUs.empty())
67 parseCompileUnits();
68 return &CUs[index];
69 }
70
Eric Christopher82de10a2013-01-02 23:52:13 +000071 /// Get the compile unit at the specified index for the DWO compile units.
72 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
73 if (DWOCUs.empty())
74 parseDWOCompileUnits();
75 return &DWOCUs[index];
76 }
77
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000078 /// Get a pointer to the parsed DebugAbbrev object.
79 const DWARFDebugAbbrev *getDebugAbbrev();
80
Eric Christopher82de10a2013-01-02 23:52:13 +000081 /// Get a pointer to the parsed dwo abbreviations object.
82 const DWARFDebugAbbrev *getDebugAbbrevDWO();
83
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000084 /// Get a pointer to the parsed DebugAranges object.
85 const DWARFDebugAranges *getDebugAranges();
86
Benjamin Kramerc26ed9b2011-09-15 20:43:18 +000087 /// Get a pointer to a parsed line table corresponding to a compile unit.
88 const DWARFDebugLine::LineTable *
89 getLineTableForCompileUnit(DWARFCompileUnit *cu);
Benjamin Kramerb848e972011-09-15 02:12:05 +000090
Alexey Samsonov38a63812012-08-30 07:49:50 +000091 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
92 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Andrew Kaylore27a7872013-01-26 00:28:05 +000093 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
94 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Alexey Samsonov5eae90d2012-09-04 08:12:33 +000095 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
96 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Benjamin Kramer101b1c52011-09-15 20:43:22 +000097
Eric Christopherd1726a42012-11-12 21:40:38 +000098 virtual bool isLittleEndian() const = 0;
Eric Christopher82de10a2013-01-02 23:52:13 +000099 virtual const RelocAddrMap &infoRelocMap() const = 0;
Andrew Kayloree7c0d22013-01-25 22:50:58 +0000100 virtual const RelocAddrMap &lineRelocMap() const = 0;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000101 virtual StringRef getInfoSection() = 0;
102 virtual StringRef getAbbrevSection() = 0;
103 virtual StringRef getARangeSection() = 0;
104 virtual StringRef getLineSection() = 0;
105 virtual StringRef getStringSection() = 0;
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000106 virtual StringRef getRangeSection() = 0;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000107
Eric Christopher82de10a2013-01-02 23:52:13 +0000108 // Sections for DWARF5 split dwarf proposal.
109 virtual StringRef getInfoDWOSection() = 0;
110 virtual StringRef getAbbrevDWOSection() = 0;
111 virtual StringRef getStringDWOSection() = 0;
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000112 virtual StringRef getStringOffsetDWOSection() = 0;
Eric Christopher82de10a2013-01-02 23:52:13 +0000113 virtual StringRef getRangeDWOSection() = 0;
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000114 virtual StringRef getAddrSection() = 0;
Eric Christopher82de10a2013-01-02 23:52:13 +0000115 virtual const RelocAddrMap &infoDWORelocMap() const = 0;
116
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000117 static bool isSupportedVersion(unsigned version) {
118 return version == 2 || version == 3;
119 }
Alexey Samsonov38a63812012-08-30 07:49:50 +0000120private:
121 /// Return the compile unit that includes an offset (relative to .debug_info).
122 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000123
Alexey Samsonov38a63812012-08-30 07:49:50 +0000124 /// Return the compile unit which contains instruction with provided
125 /// address.
126 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
Alexey Samsonov38a63812012-08-30 07:49:50 +0000127};
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000128
129/// DWARFContextInMemory is the simplest possible implementation of a
130/// DWARFContext. It assumes all content is available in memory and stores
131/// pointers to it.
132class DWARFContextInMemory : public DWARFContext {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000133 virtual void anchor();
Eric Christopherd1726a42012-11-12 21:40:38 +0000134 bool IsLittleEndian;
Eric Christopher82de10a2013-01-02 23:52:13 +0000135 RelocAddrMap InfoRelocMap;
Andrew Kayloree7c0d22013-01-25 22:50:58 +0000136 RelocAddrMap LineRelocMap;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000137 StringRef InfoSection;
138 StringRef AbbrevSection;
139 StringRef ARangeSection;
140 StringRef LineSection;
141 StringRef StringSection;
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000142 StringRef RangeSection;
Eric Christopher82de10a2013-01-02 23:52:13 +0000143
144 // Sections for DWARF5 split dwarf proposal.
145 RelocAddrMap InfoDWORelocMap;
146 StringRef InfoDWOSection;
147 StringRef AbbrevDWOSection;
148 StringRef StringDWOSection;
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000149 StringRef StringOffsetDWOSection;
Eric Christopher82de10a2013-01-02 23:52:13 +0000150 StringRef RangeDWOSection;
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000151 StringRef AddrSection;
Eric Christopher82de10a2013-01-02 23:52:13 +0000152
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000153public:
Eric Christopherd1726a42012-11-12 21:40:38 +0000154 DWARFContextInMemory(object::ObjectFile *);
155 virtual bool isLittleEndian() const { return IsLittleEndian; }
Eric Christopher82de10a2013-01-02 23:52:13 +0000156 virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; }
Andrew Kayloree7c0d22013-01-25 22:50:58 +0000157 virtual const RelocAddrMap &lineRelocMap() const { return LineRelocMap; }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000158 virtual StringRef getInfoSection() { return InfoSection; }
159 virtual StringRef getAbbrevSection() { return AbbrevSection; }
160 virtual StringRef getARangeSection() { return ARangeSection; }
161 virtual StringRef getLineSection() { return LineSection; }
162 virtual StringRef getStringSection() { return StringSection; }
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000163 virtual StringRef getRangeSection() { return RangeSection; }
Eric Christopher82de10a2013-01-02 23:52:13 +0000164
165 // Sections for DWARF5 split dwarf proposal.
166 virtual StringRef getInfoDWOSection() { return InfoDWOSection; }
167 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
168 virtual StringRef getStringDWOSection() { return StringDWOSection; }
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000169 virtual StringRef getStringOffsetDWOSection() {
170 return StringOffsetDWOSection;
171 }
Eric Christopher82de10a2013-01-02 23:52:13 +0000172 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000173 virtual StringRef getAddrSection() {
174 return AddrSection;
175 }
Eric Christophere7285c72013-01-07 22:40:48 +0000176 virtual const RelocAddrMap &infoDWORelocMap() const {
177 return InfoDWORelocMap;
178 }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000179};
180
181}
182
183#endif