blob: 0c3eb30a64cae209e64f8cd7fbcb94246d62db95 [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;
109 virtual StringRef getRangeDWOSection() = 0;
110 virtual const RelocAddrMap &infoDWORelocMap() const = 0;
111
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000112 static bool isSupportedVersion(unsigned version) {
113 return version == 2 || version == 3;
114 }
Alexey Samsonov38a63812012-08-30 07:49:50 +0000115private:
116 /// Return the compile unit that includes an offset (relative to .debug_info).
117 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000118
Alexey Samsonov38a63812012-08-30 07:49:50 +0000119 /// Return the compile unit which contains instruction with provided
120 /// address.
121 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
Alexey Samsonov38a63812012-08-30 07:49:50 +0000122};
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000123
124/// DWARFContextInMemory is the simplest possible implementation of a
125/// DWARFContext. It assumes all content is available in memory and stores
126/// pointers to it.
127class DWARFContextInMemory : public DWARFContext {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000128 virtual void anchor();
Eric Christopherd1726a42012-11-12 21:40:38 +0000129 bool IsLittleEndian;
Eric Christopher82de10a2013-01-02 23:52:13 +0000130 RelocAddrMap InfoRelocMap;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000131 StringRef InfoSection;
132 StringRef AbbrevSection;
133 StringRef ARangeSection;
134 StringRef LineSection;
135 StringRef StringSection;
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000136 StringRef RangeSection;
Eric Christopher82de10a2013-01-02 23:52:13 +0000137
138 // Sections for DWARF5 split dwarf proposal.
139 RelocAddrMap InfoDWORelocMap;
140 StringRef InfoDWOSection;
141 StringRef AbbrevDWOSection;
142 StringRef StringDWOSection;
143 StringRef RangeDWOSection;
144
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000145public:
Eric Christopherd1726a42012-11-12 21:40:38 +0000146 DWARFContextInMemory(object::ObjectFile *);
147 virtual bool isLittleEndian() const { return IsLittleEndian; }
Eric Christopher82de10a2013-01-02 23:52:13 +0000148 virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000149 virtual StringRef getInfoSection() { return InfoSection; }
150 virtual StringRef getAbbrevSection() { return AbbrevSection; }
151 virtual StringRef getARangeSection() { return ARangeSection; }
152 virtual StringRef getLineSection() { return LineSection; }
153 virtual StringRef getStringSection() { return StringSection; }
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000154 virtual StringRef getRangeSection() { return RangeSection; }
Eric Christopher82de10a2013-01-02 23:52:13 +0000155
156 // Sections for DWARF5 split dwarf proposal.
157 virtual StringRef getInfoDWOSection() { return InfoDWOSection; }
158 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
159 virtual StringRef getStringDWOSection() { return StringDWOSection; }
160 virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
161 virtual const RelocAddrMap &infoDWORelocMap() const { return InfoDWORelocMap; }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000162};
163
164}
165
166#endif