blob: 687ff93b0799e33fedca2a2a01f93e1ba5ba34bd [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() {}
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000048 virtual void dump(raw_ostream &OS);
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;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000098 virtual StringRef getInfoSection() = 0;
99 virtual StringRef getAbbrevSection() = 0;
100 virtual StringRef getARangeSection() = 0;
101 virtual StringRef getLineSection() = 0;
102 virtual StringRef getStringSection() = 0;
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000103 virtual StringRef getRangeSection() = 0;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000104
Eric Christopher82de10a2013-01-02 23:52:13 +0000105 // Sections for DWARF5 split dwarf proposal.
106 virtual StringRef getInfoDWOSection() = 0;
107 virtual StringRef getAbbrevDWOSection() = 0;
108 virtual StringRef getStringDWOSection() = 0;
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000109 virtual StringRef getStringOffsetDWOSection() = 0;
Eric Christopher82de10a2013-01-02 23:52:13 +0000110 virtual StringRef getRangeDWOSection() = 0;
111 virtual const RelocAddrMap &infoDWORelocMap() const = 0;
112
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000113 static bool isSupportedVersion(unsigned version) {
114 return version == 2 || version == 3;
115 }
Alexey Samsonov38a63812012-08-30 07:49:50 +0000116private:
117 /// Return the compile unit that includes an offset (relative to .debug_info).
118 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000119
Alexey Samsonov38a63812012-08-30 07:49:50 +0000120 /// Return the compile unit which contains instruction with provided
121 /// address.
122 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
Alexey Samsonov38a63812012-08-30 07:49:50 +0000123};
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000124
125/// DWARFContextInMemory is the simplest possible implementation of a
126/// DWARFContext. It assumes all content is available in memory and stores
127/// pointers to it.
128class DWARFContextInMemory : public DWARFContext {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000129 virtual void anchor();
Eric Christopherd1726a42012-11-12 21:40:38 +0000130 bool IsLittleEndian;
Eric Christopher82de10a2013-01-02 23:52:13 +0000131 RelocAddrMap InfoRelocMap;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000132 StringRef InfoSection;
133 StringRef AbbrevSection;
134 StringRef ARangeSection;
135 StringRef LineSection;
136 StringRef StringSection;
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000137 StringRef RangeSection;
Eric Christopher82de10a2013-01-02 23:52:13 +0000138
139 // Sections for DWARF5 split dwarf proposal.
140 RelocAddrMap InfoDWORelocMap;
141 StringRef InfoDWOSection;
142 StringRef AbbrevDWOSection;
143 StringRef StringDWOSection;
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000144 StringRef StringOffsetDWOSection;
Eric Christopher82de10a2013-01-02 23:52:13 +0000145 StringRef RangeDWOSection;
146
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000147public:
Eric Christopherd1726a42012-11-12 21:40:38 +0000148 DWARFContextInMemory(object::ObjectFile *);
149 virtual bool isLittleEndian() const { return IsLittleEndian; }
Eric Christopher82de10a2013-01-02 23:52:13 +0000150 virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000151 virtual StringRef getInfoSection() { return InfoSection; }
152 virtual StringRef getAbbrevSection() { return AbbrevSection; }
153 virtual StringRef getARangeSection() { return ARangeSection; }
154 virtual StringRef getLineSection() { return LineSection; }
155 virtual StringRef getStringSection() { return StringSection; }
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000156 virtual StringRef getRangeSection() { return RangeSection; }
Eric Christopher82de10a2013-01-02 23:52:13 +0000157
158 // Sections for DWARF5 split dwarf proposal.
159 virtual StringRef getInfoDWOSection() { return InfoDWOSection; }
160 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
161 virtual StringRef getStringDWOSection() { return StringDWOSection; }
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000162 virtual StringRef getStringOffsetDWOSection() {
163 return StringOffsetDWOSection;
164 }
Eric Christopher82de10a2013-01-02 23:52:13 +0000165 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
Eric Christophere7285c72013-01-07 22:40:48 +0000166 virtual const RelocAddrMap &infoDWORelocMap() const {
167 return InfoDWORelocMap;
168 }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000169};
170
171}
172
173#endif