blob: d6314b87c334f111c5bf11bc96e7c9da0404017f [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());
Alexey Samsonov5eae90d2012-09-04 08:12:33 +000093 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
94 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Benjamin Kramer101b1c52011-09-15 20:43:22 +000095
Eric Christopherd1726a42012-11-12 21:40:38 +000096 virtual bool isLittleEndian() const = 0;
Eric Christopher82de10a2013-01-02 23:52:13 +000097 virtual const RelocAddrMap &infoRelocMap() const = 0;
Andrew Kayloree7c0d22013-01-25 22:50:58 +000098 virtual const RelocAddrMap &lineRelocMap() const = 0;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000099 virtual StringRef getInfoSection() = 0;
100 virtual StringRef getAbbrevSection() = 0;
101 virtual StringRef getARangeSection() = 0;
102 virtual StringRef getLineSection() = 0;
103 virtual StringRef getStringSection() = 0;
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000104 virtual StringRef getRangeSection() = 0;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000105
Eric Christopher82de10a2013-01-02 23:52:13 +0000106 // Sections for DWARF5 split dwarf proposal.
107 virtual StringRef getInfoDWOSection() = 0;
108 virtual StringRef getAbbrevDWOSection() = 0;
109 virtual StringRef getStringDWOSection() = 0;
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000110 virtual StringRef getStringOffsetDWOSection() = 0;
Eric Christopher82de10a2013-01-02 23:52:13 +0000111 virtual StringRef getRangeDWOSection() = 0;
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000112 virtual StringRef getAddrSection() = 0;
Eric Christopher82de10a2013-01-02 23:52:13 +0000113 virtual const RelocAddrMap &infoDWORelocMap() const = 0;
114
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000115 static bool isSupportedVersion(unsigned version) {
116 return version == 2 || version == 3;
117 }
Alexey Samsonov38a63812012-08-30 07:49:50 +0000118private:
119 /// Return the compile unit that includes an offset (relative to .debug_info).
120 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000121
Alexey Samsonov38a63812012-08-30 07:49:50 +0000122 /// Return the compile unit which contains instruction with provided
123 /// address.
124 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
Alexey Samsonov38a63812012-08-30 07:49:50 +0000125};
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000126
127/// DWARFContextInMemory is the simplest possible implementation of a
128/// DWARFContext. It assumes all content is available in memory and stores
129/// pointers to it.
130class DWARFContextInMemory : public DWARFContext {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000131 virtual void anchor();
Eric Christopherd1726a42012-11-12 21:40:38 +0000132 bool IsLittleEndian;
Eric Christopher82de10a2013-01-02 23:52:13 +0000133 RelocAddrMap InfoRelocMap;
Andrew Kayloree7c0d22013-01-25 22:50:58 +0000134 RelocAddrMap LineRelocMap;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000135 StringRef InfoSection;
136 StringRef AbbrevSection;
137 StringRef ARangeSection;
138 StringRef LineSection;
139 StringRef StringSection;
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000140 StringRef RangeSection;
Eric Christopher82de10a2013-01-02 23:52:13 +0000141
142 // Sections for DWARF5 split dwarf proposal.
143 RelocAddrMap InfoDWORelocMap;
144 StringRef InfoDWOSection;
145 StringRef AbbrevDWOSection;
146 StringRef StringDWOSection;
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000147 StringRef StringOffsetDWOSection;
Eric Christopher82de10a2013-01-02 23:52:13 +0000148 StringRef RangeDWOSection;
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000149 StringRef AddrSection;
Eric Christopher82de10a2013-01-02 23:52:13 +0000150
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000151public:
Eric Christopherd1726a42012-11-12 21:40:38 +0000152 DWARFContextInMemory(object::ObjectFile *);
153 virtual bool isLittleEndian() const { return IsLittleEndian; }
Eric Christopher82de10a2013-01-02 23:52:13 +0000154 virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; }
Andrew Kayloree7c0d22013-01-25 22:50:58 +0000155 virtual const RelocAddrMap &lineRelocMap() const { return LineRelocMap; }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000156 virtual StringRef getInfoSection() { return InfoSection; }
157 virtual StringRef getAbbrevSection() { return AbbrevSection; }
158 virtual StringRef getARangeSection() { return ARangeSection; }
159 virtual StringRef getLineSection() { return LineSection; }
160 virtual StringRef getStringSection() { return StringSection; }
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000161 virtual StringRef getRangeSection() { return RangeSection; }
Eric Christopher82de10a2013-01-02 23:52:13 +0000162
163 // Sections for DWARF5 split dwarf proposal.
164 virtual StringRef getInfoDWOSection() { return InfoDWOSection; }
165 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
166 virtual StringRef getStringDWOSection() { return StringDWOSection; }
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000167 virtual StringRef getStringOffsetDWOSection() {
168 return StringOffsetDWOSection;
169 }
Eric Christopher82de10a2013-01-02 23:52:13 +0000170 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
Eric Christopher72f7bfb2013-01-15 23:56:56 +0000171 virtual StringRef getAddrSection() {
172 return AddrSection;
173 }
Eric Christophere7285c72013-01-07 22:40:48 +0000174 virtual const RelocAddrMap &infoDWORelocMap() const {
175 return InfoDWORelocMap;
176 }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000177};
178
179}
180
181#endif