llvm.org GIT mirror llvm / 50418a0
Move DebugInfo to DebugInfo/DWARF. In preparation for adding PDB support to LLVM, this moves the DWARF parsing code to its own subdirectory under DebugInfo, and renames LLVMDebugInfo to LLVMDebugInfoDWARF. This is purely a mechanical / build system change. Differential Revision: http://reviews.llvm.org/D7269 Reviewed by: Eric Christopher git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227586 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 5 years ago
106 changed file(s) with 6047 addition(s) and 6006 deletion(s). Raw diff Collapse all Expand all
+0
-150
include/llvm/DebugInfo/DIContext.h less more
None //===-- DIContext.h ---------------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines DIContext, an abstract data structure that holds
10 // debug information data.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_DEBUGINFO_DICONTEXT_H
15 #define LLVM_DEBUGINFO_DICONTEXT_H
16
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/Object/ObjectFile.h"
20 #include "llvm/Object/RelocVisitor.h"
21 #include "llvm/Support/Casting.h"
22 #include "llvm/Support/DataTypes.h"
23 #include
24
25 namespace llvm {
26
27 class raw_ostream;
28
29 /// DILineInfo - a format-neutral container for source line information.
30 struct DILineInfo {
31 std::string FileName;
32 std::string FunctionName;
33 uint32_t Line;
34 uint32_t Column;
35
36 DILineInfo()
37 : FileName(""), FunctionName(""), Line(0), Column(0) {}
38
39 bool operator==(const DILineInfo &RHS) const {
40 return Line == RHS.Line && Column == RHS.Column &&
41 FileName == RHS.FileName && FunctionName == RHS.FunctionName;
42 }
43 bool operator!=(const DILineInfo &RHS) const {
44 return !(*this == RHS);
45 }
46 };
47
48 typedef SmallVector, 16> DILineInfoTable;
49
50 /// DIInliningInfo - a format-neutral container for inlined code description.
51 class DIInliningInfo {
52 SmallVector Frames;
53 public:
54 DIInliningInfo() {}
55 DILineInfo getFrame(unsigned Index) const {
56 assert(Index < Frames.size());
57 return Frames[Index];
58 }
59 uint32_t getNumberOfFrames() const {
60 return Frames.size();
61 }
62 void addFrame(const DILineInfo &Frame) {
63 Frames.push_back(Frame);
64 }
65 };
66
67 /// A DINameKind is passed to name search methods to specify a
68 /// preference regarding the type of name resolution the caller wants.
69 enum class DINameKind { None, ShortName, LinkageName };
70
71 /// DILineInfoSpecifier - controls which fields of DILineInfo container
72 /// should be filled with data.
73 struct DILineInfoSpecifier {
74 enum class FileLineInfoKind { None, Default, AbsoluteFilePath };
75 typedef DINameKind FunctionNameKind;
76
77 FileLineInfoKind FLIKind;
78 FunctionNameKind FNKind;
79
80 DILineInfoSpecifier(FileLineInfoKind FLIKind = FileLineInfoKind::Default,
81 FunctionNameKind FNKind = FunctionNameKind::None)
82 : FLIKind(FLIKind), FNKind(FNKind) {}
83 };
84
85 /// Selects which debug sections get dumped.
86 enum DIDumpType {
87 DIDT_Null,
88 DIDT_All,
89 DIDT_Abbrev,
90 DIDT_AbbrevDwo,
91 DIDT_Aranges,
92 DIDT_Frames,
93 DIDT_Info,
94 DIDT_InfoDwo,
95 DIDT_Types,
96 DIDT_TypesDwo,
97 DIDT_Line,
98 DIDT_LineDwo,
99 DIDT_Loc,
100 DIDT_LocDwo,
101 DIDT_Ranges,
102 DIDT_Pubnames,
103 DIDT_Pubtypes,
104 DIDT_GnuPubnames,
105 DIDT_GnuPubtypes,
106 DIDT_Str,
107 DIDT_StrDwo,
108 DIDT_StrOffsetsDwo,
109 DIDT_AppleNames,
110 DIDT_AppleTypes,
111 DIDT_AppleNamespaces,
112 DIDT_AppleObjC
113 };
114
115 // In place of applying the relocations to the data we've read from disk we use
116 // a separate mapping table to the side and checking that at locations in the
117 // dwarf where we expect relocated values. This adds a bit of complexity to the
118 // dwarf parsing/extraction at the benefit of not allocating memory for the
119 // entire size of the debug info sections.
120 typedef DenseMap > RelocAddrMap;
121
122 class DIContext {
123 public:
124 enum DIContextKind {
125 CK_DWARF
126 };
127 DIContextKind getKind() const { return Kind; }
128
129 DIContext(DIContextKind K) : Kind(K) {}
130 virtual ~DIContext();
131
132 /// getDWARFContext - get a context for binary DWARF data.
133 static DIContext *getDWARFContext(const object::ObjectFile &Obj);
134
135 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) = 0;
136
137 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
138 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
139 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
140 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
141 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
142 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
143 private:
144 const DIContextKind Kind;
145 };
146
147 }
148
149 #endif
0 //===-- DIContext.h ---------------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines DIContext, an abstract data structure that holds
10 // debug information data.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_DEBUGINFO_DICONTEXT_H
15 #define LLVM_DEBUGINFO_DICONTEXT_H
16
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/Object/ObjectFile.h"
20 #include "llvm/Object/RelocVisitor.h"
21 #include "llvm/Support/Casting.h"
22 #include "llvm/Support/DataTypes.h"
23 #include
24
25 namespace llvm {
26
27 class raw_ostream;
28
29 /// DILineInfo - a format-neutral container for source line information.
30 struct DILineInfo {
31 std::string FileName;
32 std::string FunctionName;
33 uint32_t Line;
34 uint32_t Column;
35
36 DILineInfo()
37 : FileName(""), FunctionName(""), Line(0), Column(0) {}
38
39 bool operator==(const DILineInfo &RHS) const {
40 return Line == RHS.Line && Column == RHS.Column &&
41 FileName == RHS.FileName && FunctionName == RHS.FunctionName;
42 }
43 bool operator!=(const DILineInfo &RHS) const {
44 return !(*this == RHS);
45 }
46 };
47
48 typedef SmallVector, 16> DILineInfoTable;
49
50 /// DIInliningInfo - a format-neutral container for inlined code description.
51 class DIInliningInfo {
52 SmallVector Frames;
53 public:
54 DIInliningInfo() {}
55 DILineInfo getFrame(unsigned Index) const {
56 assert(Index < Frames.size());
57 return Frames[Index];
58 }
59 uint32_t getNumberOfFrames() const {
60 return Frames.size();
61 }
62 void addFrame(const DILineInfo &Frame) {
63 Frames.push_back(Frame);
64 }
65 };
66
67 /// A DINameKind is passed to name search methods to specify a
68 /// preference regarding the type of name resolution the caller wants.
69 enum class DINameKind { None, ShortName, LinkageName };
70
71 /// DILineInfoSpecifier - controls which fields of DILineInfo container
72 /// should be filled with data.
73 struct DILineInfoSpecifier {
74 enum class FileLineInfoKind { None, Default, AbsoluteFilePath };
75 typedef DINameKind FunctionNameKind;
76
77 FileLineInfoKind FLIKind;
78 FunctionNameKind FNKind;
79
80 DILineInfoSpecifier(FileLineInfoKind FLIKind = FileLineInfoKind::Default,
81 FunctionNameKind FNKind = FunctionNameKind::None)
82 : FLIKind(FLIKind), FNKind(FNKind) {}
83 };
84
85 /// Selects which debug sections get dumped.
86 enum DIDumpType {
87 DIDT_Null,
88 DIDT_All,
89 DIDT_Abbrev,
90 DIDT_AbbrevDwo,
91 DIDT_Aranges,
92 DIDT_Frames,
93 DIDT_Info,
94 DIDT_InfoDwo,
95 DIDT_Types,
96 DIDT_TypesDwo,
97 DIDT_Line,
98 DIDT_LineDwo,
99 DIDT_Loc,
100 DIDT_LocDwo,
101 DIDT_Ranges,
102 DIDT_Pubnames,
103 DIDT_Pubtypes,
104 DIDT_GnuPubnames,
105 DIDT_GnuPubtypes,
106 DIDT_Str,
107 DIDT_StrDwo,
108 DIDT_StrOffsetsDwo,
109 DIDT_AppleNames,
110 DIDT_AppleTypes,
111 DIDT_AppleNamespaces,
112 DIDT_AppleObjC
113 };
114
115 // In place of applying the relocations to the data we've read from disk we use
116 // a separate mapping table to the side and checking that at locations in the
117 // dwarf where we expect relocated values. This adds a bit of complexity to the
118 // dwarf parsing/extraction at the benefit of not allocating memory for the
119 // entire size of the debug info sections.
120 typedef DenseMap > RelocAddrMap;
121
122 class DIContext {
123 public:
124 enum DIContextKind {
125 CK_DWARF
126 };
127 DIContextKind getKind() const { return Kind; }
128
129 DIContext(DIContextKind K) : Kind(K) {}
130 virtual ~DIContext();
131
132 /// getDWARFContext - get a context for binary DWARF data.
133 static DIContext *getDWARFContext(const object::ObjectFile &Obj);
134
135 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) = 0;
136
137 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
138 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
139 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
140 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
141 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
142 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
143 private:
144 const DIContextKind Kind;
145 };
146
147 }
148
149 #endif
0 //===-- DWARFAbbreviationDeclaration.h --------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
10 #define LLVM_LIB_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
11
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/Support/DataExtractor.h"
14
15 namespace llvm {
16
17 class raw_ostream;
18
19 class DWARFAbbreviationDeclaration {
20 uint32_t Code;
21 uint32_t Tag;
22 bool HasChildren;
23
24 struct AttributeSpec {
25 AttributeSpec(uint16_t Attr, uint16_t Form) : Attr(Attr), Form(Form) {}
26 uint16_t Attr;
27 uint16_t Form;
28 };
29 typedef SmallVector AttributeSpecVector;
30 AttributeSpecVector AttributeSpecs;
31 public:
32 DWARFAbbreviationDeclaration();
33
34 uint32_t getCode() const { return Code; }
35 uint32_t getTag() const { return Tag; }
36 bool hasChildren() const { return HasChildren; }
37
38 typedef iterator_range
39 attr_iterator_range;
40
41 attr_iterator_range attributes() const {
42 return attr_iterator_range(AttributeSpecs.begin(), AttributeSpecs.end());
43 }
44
45 uint16_t getFormByIndex(uint32_t idx) const {
46 return idx < AttributeSpecs.size() ? AttributeSpecs[idx].Form : 0;
47 }
48
49 uint32_t findAttributeIndex(uint16_t attr) const;
50 bool extract(DataExtractor Data, uint32_t* OffsetPtr);
51 void dump(raw_ostream &OS) const;
52
53 private:
54 void clear();
55 };
56
57 }
58
59 #endif
0 //===--- DWARFAcceleratorTable.h --------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/ADT/SmallVector.h"
10 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
11 #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
12 #include
13
14 namespace llvm {
15
16 class DWARFAcceleratorTable {
17
18 struct Header {
19 uint32_t Magic;
20 uint16_t Version;
21 uint16_t HashFunction;
22 uint32_t NumBuckets;
23 uint32_t NumHashes;
24 uint32_t HeaderDataLength;
25 };
26
27 struct HeaderData {
28 typedef uint16_t AtomType;
29 typedef uint16_t Form;
30 uint32_t DIEOffsetBase;
31 SmallVector, 3> Atoms;
32 };
33
34 struct Header Hdr;
35 struct HeaderData HdrData;
36 DataExtractor AccelSection;
37 DataExtractor StringSection;
38 const RelocAddrMap& Relocs;
39 public:
40 DWARFAcceleratorTable(DataExtractor AccelSection, DataExtractor StringSection,
41 const RelocAddrMap &Relocs)
42 : AccelSection(AccelSection), StringSection(StringSection), Relocs(Relocs) {}
43
44 bool extract();
45 void dump(raw_ostream &OS) const;
46 };
47
48 }
0 //===-- DWARFCompileUnit.h --------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFCOMPILEUNIT_H
10 #define LLVM_LIB_DEBUGINFO_DWARFCOMPILEUNIT_H
11
12 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
13
14 namespace llvm {
15
16 class DWARFCompileUnit : public DWARFUnit {
17 public:
18 DWARFCompileUnit(DWARFContext &Context, const DWARFSection &Section,
19 const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
20 StringRef SOS, StringRef AOS, bool LE,
21 const DWARFUnitSectionBase &UnitSection)
22 : DWARFUnit(Context, Section, DA, RS, SS, SOS, AOS, LE, UnitSection) {}
23 void dump(raw_ostream &OS);
24 // VTable anchor.
25 ~DWARFCompileUnit() override;
26 };
27
28 }
29
30 #endif
0 //===-- DWARFContext.h ------------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===/
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFCONTEXT_H
10 #define LLVM_LIB_DEBUGINFO_DWARFCONTEXT_H
11
12 #include "llvm/ADT/MapVector.h"
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/DebugInfo/DWARF/DIContext.h"
15 #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
16 #include "llvm/DebugInfo/DWARF/DWARFDebugAranges.h"
17 #include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
18 #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
19 #include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
20 #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
21 #include "llvm/DebugInfo/DWARF/DWARFSection.h"
22 #include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
23 #include
24
25 namespace llvm {
26
27 /// DWARFContext
28 /// This data structure is the top level entity that deals with dwarf debug
29 /// information parsing. The actual data is supplied through pure virtual
30 /// methods that a concrete implementation provides.
31 class DWARFContext : public DIContext {
32
33 DWARFUnitSection CUs;
34 std::vector> TUs;
35 std::unique_ptr Abbrev;
36 std::unique_ptr Loc;
37 std::unique_ptr Aranges;
38 std::unique_ptr Line;
39 std::unique_ptr DebugFrame;
40
41 DWARFUnitSection DWOCUs;
42 std::vector> DWOTUs;
43 std::unique_ptr AbbrevDWO;
44 std::unique_ptr LocDWO;
45
46 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
47 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
48
49 /// Read compile units from the debug_info section (if necessary)
50 /// and store them in CUs.
51 void parseCompileUnits();
52
53 /// Read type units from the debug_types sections (if necessary)
54 /// and store them in TUs.
55 void parseTypeUnits();
56
57 /// Read compile units from the debug_info.dwo section (if necessary)
58 /// and store them in DWOCUs.
59 void parseDWOCompileUnits();
60
61 /// Read type units from the debug_types.dwo section (if necessary)
62 /// and store them in DWOTUs.
63 void parseDWOTypeUnits();
64
65 public:
66 DWARFContext() : DIContext(CK_DWARF) {}
67
68 static bool classof(const DIContext *DICtx) {
69 return DICtx->getKind() == CK_DWARF;
70 }
71
72 void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) override;
73
74 typedef DWARFUnitSection::iterator_range cu_iterator_range;
75 typedef DWARFUnitSection::iterator_range tu_iterator_range;
76 typedef iterator_range>::iterator> tu_section_iterator_range;
77
78 /// Get compile units in this context.
79 cu_iterator_range compile_units() {
80 parseCompileUnits();
81 return cu_iterator_range(CUs.begin(), CUs.end());
82 }
83
84 /// Get type units in this context.
85 tu_section_iterator_range type_unit_sections() {
86 parseTypeUnits();
87 return tu_section_iterator_range(TUs.begin(), TUs.end());
88 }
89
90 /// Get compile units in the DWO context.
91 cu_iterator_range dwo_compile_units() {
92 parseDWOCompileUnits();
93 return cu_iterator_range(DWOCUs.begin(), DWOCUs.end());
94 }
95
96 /// Get type units in the DWO context.
97 tu_section_iterator_range dwo_type_unit_sections() {
98 parseDWOTypeUnits();
99 return tu_section_iterator_range(DWOTUs.begin(), DWOTUs.end());
100 }
101
102 /// Get the number of compile units in this context.
103 unsigned getNumCompileUnits() {
104 parseCompileUnits();
105 return CUs.size();
106 }
107
108 /// Get the number of compile units in this context.
109 unsigned getNumTypeUnits() {
110 parseTypeUnits();
111 return TUs.size();
112 }
113
114 /// Get the number of compile units in the DWO context.
115 unsigned getNumDWOCompileUnits() {
116 parseDWOCompileUnits();
117 return DWOCUs.size();
118 }
119
120 /// Get the number of compile units in the DWO context.
121 unsigned getNumDWOTypeUnits() {
122 parseDWOTypeUnits();
123 return DWOTUs.size();
124 }
125
126 /// Get the compile unit at the specified index for this compile unit.
127 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
128 parseCompileUnits();
129 return CUs[index].get();
130 }
131
132 /// Get the compile unit at the specified index for the DWO compile units.
133 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
134 parseDWOCompileUnits();
135 return DWOCUs[index].get();
136 }
137
138 /// Get a pointer to the parsed DebugAbbrev object.
139 const DWARFDebugAbbrev *getDebugAbbrev();
140
141 /// Get a pointer to the parsed DebugLoc object.
142 const DWARFDebugLoc *getDebugLoc();
143
144 /// Get a pointer to the parsed dwo abbreviations object.
145 const DWARFDebugAbbrev *getDebugAbbrevDWO();
146
147 /// Get a pointer to the parsed DebugLoc object.
148 const DWARFDebugLocDWO *getDebugLocDWO();
149
150 /// Get a pointer to the parsed DebugAranges object.
151 const DWARFDebugAranges *getDebugAranges();
152
153 /// Get a pointer to the parsed frame information object.
154 const DWARFDebugFrame *getDebugFrame();
155
156 /// Get a pointer to a parsed line table corresponding to a compile unit.
157 const DWARFDebugLine::LineTable *getLineTableForUnit(DWARFUnit *cu);
158
159 DILineInfo getLineInfoForAddress(uint64_t Address,
160 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
161 DILineInfoTable getLineInfoForAddressRange(uint64_t Address, uint64_t Size,
162 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
163 DIInliningInfo getInliningInfoForAddress(uint64_t Address,
164 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
165
166 virtual bool isLittleEndian() const = 0;
167 virtual uint8_t getAddressSize() const = 0;
168 virtual const DWARFSection &getInfoSection() = 0;
169 typedef MapVector
170 std::map> TypeSectionMap;
171 virtual const TypeSectionMap &getTypesSections() = 0;
172 virtual StringRef getAbbrevSection() = 0;
173 virtual const DWARFSection &getLocSection() = 0;
174 virtual StringRef getARangeSection() = 0;
175 virtual StringRef getDebugFrameSection() = 0;
176 virtual const DWARFSection &getLineSection() = 0;
177 virtual StringRef getStringSection() = 0;
178 virtual StringRef getRangeSection() = 0;
179 virtual StringRef getPubNamesSection() = 0;
180 virtual StringRef getPubTypesSection() = 0;
181 virtual StringRef getGnuPubNamesSection() = 0;
182 virtual StringRef getGnuPubTypesSection() = 0;
183
184 // Sections for DWARF5 split dwarf proposal.
185 virtual const DWARFSection &getInfoDWOSection() = 0;
186 virtual const TypeSectionMap &getTypesDWOSections() = 0;
187 virtual StringRef getAbbrevDWOSection() = 0;
188 virtual const DWARFSection &getLineDWOSection() = 0;
189 virtual const DWARFSection &getLocDWOSection() = 0;
190 virtual StringRef getStringDWOSection() = 0;
191 virtual StringRef getStringOffsetDWOSection() = 0;
192 virtual StringRef getRangeDWOSection() = 0;
193 virtual StringRef getAddrSection() = 0;
194 virtual const DWARFSection& getAppleNamesSection() = 0;
195 virtual const DWARFSection& getAppleTypesSection() = 0;
196 virtual const DWARFSection& getAppleNamespacesSection() = 0;
197 virtual const DWARFSection& getAppleObjCSection() = 0;
198
199 static bool isSupportedVersion(unsigned version) {
200 return version == 2 || version == 3 || version == 4;
201 }
202 private:
203 /// Return the compile unit that includes an offset (relative to .debug_info).
204 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
205
206 /// Return the compile unit which contains instruction with provided
207 /// address.
208 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
209 };
210
211 /// DWARFContextInMemory is the simplest possible implementation of a
212 /// DWARFContext. It assumes all content is available in memory and stores
213 /// pointers to it.
214 class DWARFContextInMemory : public DWARFContext {
215 virtual void anchor();
216 bool IsLittleEndian;
217 uint8_t AddressSize;
218 DWARFSection InfoSection;
219 TypeSectionMap TypesSections;
220 StringRef AbbrevSection;
221 DWARFSection LocSection;
222 StringRef ARangeSection;
223 StringRef DebugFrameSection;
224 DWARFSection LineSection;
225 StringRef StringSection;
226 StringRef RangeSection;
227 StringRef PubNamesSection;
228 StringRef PubTypesSection;
229 StringRef GnuPubNamesSection;
230 StringRef GnuPubTypesSection;
231
232 // Sections for DWARF5 split dwarf proposal.
233 DWARFSection InfoDWOSection;
234 TypeSectionMap TypesDWOSections;
235 StringRef AbbrevDWOSection;
236 DWARFSection LineDWOSection;
237 DWARFSection LocDWOSection;
238 StringRef StringDWOSection;
239 StringRef StringOffsetDWOSection;
240 StringRef RangeDWOSection;
241 StringRef AddrSection;
242 DWARFSection AppleNamesSection;
243 DWARFSection AppleTypesSection;
244 DWARFSection AppleNamespacesSection;
245 DWARFSection AppleObjCSection;
246
247 SmallVector, 4> UncompressedSections;
248
249 public:
250 DWARFContextInMemory(const object::ObjectFile &Obj);
251 bool isLittleEndian() const override { return IsLittleEndian; }
252 uint8_t getAddressSize() const override { return AddressSize; }
253 const DWARFSection &getInfoSection() override { return InfoSection; }
254 const TypeSectionMap &getTypesSections() override { return TypesSections; }
255 StringRef getAbbrevSection() override { return AbbrevSection; }
256 const DWARFSection &getLocSection() override { return LocSection; }
257 StringRef getARangeSection() override { return ARangeSection; }
258 StringRef getDebugFrameSection() override { return DebugFrameSection; }
259 const DWARFSection &getLineSection() override { return LineSection; }
260 StringRef getStringSection() override { return StringSection; }
261 StringRef getRangeSection() override { return RangeSection; }
262 StringRef getPubNamesSection() override { return PubNamesSection; }
263 StringRef getPubTypesSection() override { return PubTypesSection; }
264 StringRef getGnuPubNamesSection() override { return GnuPubNamesSection; }
265 StringRef getGnuPubTypesSection() override { return GnuPubTypesSection; }
266 const DWARFSection& getAppleNamesSection() override { return AppleNamesSection; }
267 const DWARFSection& getAppleTypesSection() override { return AppleTypesSection; }
268 const DWARFSection& getAppleNamespacesSection() override { return AppleNamespacesSection; }
269 const DWARFSection& getAppleObjCSection() override { return AppleObjCSection; }
270
271 // Sections for DWARF5 split dwarf proposal.
272 const DWARFSection &getInfoDWOSection() override { return InfoDWOSection; }
273 const TypeSectionMap &getTypesDWOSections() override {
274 return TypesDWOSections;
275 }
276 StringRef getAbbrevDWOSection() override { return AbbrevDWOSection; }
277 const DWARFSection &getLineDWOSection() override { return LineDWOSection; }
278 const DWARFSection &getLocDWOSection() override { return LocDWOSection; }
279 StringRef getStringDWOSection() override { return StringDWOSection; }
280 StringRef getStringOffsetDWOSection() override {
281 return StringOffsetDWOSection;
282 }
283 StringRef getRangeDWOSection() override { return RangeDWOSection; }
284 StringRef getAddrSection() override {
285 return AddrSection;
286 }
287 };
288
289 }
290
291 #endif
0 //===-- DWARFDebugAbbrev.h --------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGABBREV_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGABBREV_H
11
12 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
13 #include
14 #include
15 #include
16
17 namespace llvm {
18
19 class DWARFAbbreviationDeclarationSet {
20 uint32_t Offset;
21 /// Code of the first abbreviation, if all abbreviations in the set have
22 /// consecutive codes. UINT32_MAX otherwise.
23 uint32_t FirstAbbrCode;
24 std::vector Decls;
25
26 public:
27 DWARFAbbreviationDeclarationSet();
28
29 uint32_t getOffset() const { return Offset; }
30 void dump(raw_ostream &OS) const;
31 bool extract(DataExtractor Data, uint32_t *OffsetPtr);
32
33 const DWARFAbbreviationDeclaration *
34 getAbbreviationDeclaration(uint32_t AbbrCode) const;
35
36 private:
37 void clear();
38 };
39
40 class DWARFDebugAbbrev {
41 typedef std::map
42 DWARFAbbreviationDeclarationSetMap;
43
44 DWARFAbbreviationDeclarationSetMap AbbrDeclSets;
45 mutable DWARFAbbreviationDeclarationSetMap::const_iterator PrevAbbrOffsetPos;
46
47 public:
48 DWARFDebugAbbrev();
49
50 const DWARFAbbreviationDeclarationSet *
51 getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const;
52
53 void dump(raw_ostream &OS) const;
54 void extract(DataExtractor Data);
55
56 private:
57 void clear();
58 };
59
60 }
61
62 #endif
0 //===-- DWARFDebugArangeSet.h -----------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGESET_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGESET_H
11
12 #include "llvm/ADT/iterator_range.h"
13 #include "llvm/Support/DataExtractor.h"
14 #include
15
16 namespace llvm {
17
18 class raw_ostream;
19
20 class DWARFDebugArangeSet {
21 public:
22 struct Header {
23 // The total length of the entries for that set, not including the length
24 // field itself.
25 uint32_t Length;
26 // The offset from the beginning of the .debug_info section of the
27 // compilation unit entry referenced by the table.
28 uint32_t CuOffset;
29 // The DWARF version number.
30 uint16_t Version;
31 // The size in bytes of an address on the target architecture. For segmented
32 // addressing, this is the size of the offset portion of the address.
33 uint8_t AddrSize;
34 // The size in bytes of a segment descriptor on the target architecture.
35 // If the target system uses a flat address space, this value is 0.
36 uint8_t SegSize;
37 };
38
39 struct Descriptor {
40 uint64_t Address;
41 uint64_t Length;
42 uint64_t getEndAddress() const { return Address + Length; }
43 };
44
45 private:
46 typedef std::vector DescriptorColl;
47 typedef iterator_range desc_iterator_range;
48
49 uint32_t Offset;
50 Header HeaderData;
51 DescriptorColl ArangeDescriptors;
52
53 public:
54 DWARFDebugArangeSet() { clear(); }
55 void clear();
56 bool extract(DataExtractor data, uint32_t *offset_ptr);
57 void dump(raw_ostream &OS) const;
58
59 uint32_t getCompileUnitDIEOffset() const { return HeaderData.CuOffset; }
60
61 desc_iterator_range descriptors() const {
62 return desc_iterator_range(ArangeDescriptors.begin(),
63 ArangeDescriptors.end());
64 }
65 };
66
67 }
68
69 #endif
0 //===-- DWARFDebugAranges.h -------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGES_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGES_H
11
12 #include "llvm/ADT/DenseSet.h"
13 #include "llvm/Support/DataExtractor.h"
14 #include
15
16 namespace llvm {
17
18 class DWARFContext;
19
20 class DWARFDebugAranges {
21 public:
22 void generate(DWARFContext *CTX);
23 uint32_t findAddress(uint64_t Address) const;
24
25 private:
26 void clear();
27 void extract(DataExtractor DebugArangesData);
28
29 // Call appendRange multiple times and then call construct.
30 void appendRange(uint32_t CUOffset, uint64_t LowPC, uint64_t HighPC);
31 void construct();
32
33 struct Range {
34 explicit Range(uint64_t LowPC = -1ULL, uint64_t HighPC = -1ULL,
35 uint32_t CUOffset = -1U)
36 : LowPC(LowPC), Length(HighPC - LowPC), CUOffset(CUOffset) {}
37
38 void setHighPC(uint64_t HighPC) {
39 if (HighPC == -1ULL || HighPC <= LowPC)
40 Length = 0;
41 else
42 Length = HighPC - LowPC;
43 }
44 uint64_t HighPC() const {
45 if (Length)
46 return LowPC + Length;
47 return -1ULL;
48 }
49
50 bool containsAddress(uint64_t Address) const {
51 return LowPC <= Address && Address < HighPC();
52 }
53 bool operator<(const Range &other) const {
54 return LowPC < other.LowPC;
55 }
56
57 uint64_t LowPC; // Start of address range.
58 uint32_t Length; // End of address range (not including this address).
59 uint32_t CUOffset; // Offset of the compile unit or die.
60 };
61
62 struct RangeEndpoint {
63 uint64_t Address;
64 uint32_t CUOffset;
65 bool IsRangeStart;
66
67 RangeEndpoint(uint64_t Address, uint32_t CUOffset, bool IsRangeStart)
68 : Address(Address), CUOffset(CUOffset), IsRangeStart(IsRangeStart) {}
69
70 bool operator<(const RangeEndpoint &Other) const {
71 return Address < Other.Address;
72 }
73 };
74
75
76 typedef std::vector RangeColl;
77 typedef RangeColl::const_iterator RangeCollIterator;
78
79 std::vector Endpoints;
80 RangeColl Aranges;
81 DenseSet ParsedCUOffsets;
82 };
83
84 }
85
86 #endif
0 //===-- DWARFDebugFrame.h - Parsing of .debug_frame -------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGFRAME_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGFRAME_H
11
12 #include "llvm/Support/DataExtractor.h"
13 #include "llvm/Support/raw_ostream.h"
14 #include
15 #include
16
17 namespace llvm {
18
19 class FrameEntry;
20
21 /// \brief A parsed .debug_frame section
22 ///
23 class DWARFDebugFrame {
24 public:
25 DWARFDebugFrame();
26 ~DWARFDebugFrame();
27
28 /// \brief Dump the section data into the given stream.
29 void dump(raw_ostream &OS) const;
30
31 /// \brief Parse the section from raw data.
32 /// data is assumed to be pointing to the beginning of the section.
33 void parse(DataExtractor Data);
34
35 private:
36 std::vector> Entries;
37 };
38
39
40 } // namespace llvm
41
42 #endif
0 //===-- DWARFDebugInfoEntry.h -----------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGINFOENTRY_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGINFOENTRY_H
11
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/DebugInfo/DWARF/DIContext.h"
14 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
15 #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
16 #include "llvm/Support/DataTypes.h"
17
18 namespace llvm {
19
20 class DWARFDebugAranges;
21 class DWARFCompileUnit;
22 class DWARFUnit;
23 class DWARFContext;
24 class DWARFFormValue;
25 struct DWARFDebugInfoEntryInlinedChain;
26
27 /// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
28 class DWARFDebugInfoEntryMinimal {
29 /// Offset within the .debug_info of the start of this entry.
30 uint32_t Offset;
31
32 /// How many to add to "this" to get the sibling.
33 uint32_t SiblingIdx;
34
35 const DWARFAbbreviationDeclaration *AbbrevDecl;
36 public:
37 DWARFDebugInfoEntryMinimal()
38 : Offset(0), SiblingIdx(0), AbbrevDecl(nullptr) {}
39
40 void dump(raw_ostream &OS, DWARFUnit *u, unsigned recurseDepth,
41 unsigned indent = 0) const;
42 void dumpAttribute(raw_ostream &OS, DWARFUnit *u, uint32_t *offset_ptr,
43 uint16_t attr, uint16_t form, unsigned indent = 0) const;
44
45 /// Extracts a debug info entry, which is a child of a given unit,
46 /// starting at a given offset. If DIE can't be extracted, returns false and
47 /// doesn't change OffsetPtr.
48 bool extractFast(const DWARFUnit *U, uint32_t *OffsetPtr);
49
50 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
51 bool isNULL() const { return AbbrevDecl == nullptr; }
52
53 /// Returns true if DIE represents a subprogram (not inlined).
54 bool isSubprogramDIE() const;
55 /// Returns true if DIE represents a subprogram or an inlined
56 /// subroutine.
57 bool isSubroutineDIE() const;
58
59 uint32_t getOffset() const { return Offset; }
60 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
61
62 // We know we are kept in a vector of contiguous entries, so we know
63 // our sibling will be some index after "this".
64 const DWARFDebugInfoEntryMinimal *getSibling() const {
65 return SiblingIdx > 0 ? this + SiblingIdx : nullptr;
66 }
67
68 // We know we are kept in a vector of contiguous entries, so we know
69 // we don't need to store our child pointer, if we have a child it will
70 // be the next entry in the list...
71 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
72 return hasChildren() ? this + 1 : nullptr;
73 }
74
75 void setSibling(const DWARFDebugInfoEntryMinimal *Sibling) {
76 if (Sibling) {
77 // We know we are kept in a vector of contiguous entries, so we know
78 // our sibling will be some index after "this".
79 SiblingIdx = Sibling - this;
80 } else
81 SiblingIdx = 0;
82 }
83
84 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
85 return AbbrevDecl;
86 }
87
88 bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr,
89 DWARFFormValue &FormValue) const;
90
91 const char *getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr,
92 const char *FailValue) const;
93
94 uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr,
95 uint64_t FailValue) const;
96
97 uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U,
98 const uint16_t Attr,
99 uint64_t FailValue) const;
100
101 uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr,
102 uint64_t FailValue) const;
103
104 uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U,
105 const uint16_t Attr,
106 uint64_t FailValue) const;
107
108 uint64_t getRangesBaseAttribute(const DWARFUnit *U, uint64_t FailValue) const;
109
110 /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
111 /// Returns true if both attributes are present.
112 bool getLowAndHighPC(const DWARFUnit *U, uint64_t &LowPC,
113 uint64_t &HighPC) const;
114
115 DWARFAddressRangesVector getAddressRanges(const DWARFUnit *U) const;
116
117 void collectChildrenAddressRanges(const DWARFUnit *U,
118 DWARFAddressRangesVector &Ranges) const;
119
120 bool addressRangeContainsAddress(const DWARFUnit *U,
121 const uint64_t Address) const;
122
123 /// If a DIE represents a subprogram (or inlined subroutine),
124 /// returns its mangled name (or short name, if mangled is missing).
125 /// This name may be fetched from specification or abstract origin
126 /// for this subprogram. Returns null if no name is found.
127 const char *getSubroutineName(const DWARFUnit *U, DINameKind Kind) const;
128
129 /// Return the DIE name resolving DW_AT_sepcification or
130 /// DW_AT_abstract_origin references if necessary.
131 /// Returns null if no name is found.
132 const char *getName(const DWARFUnit *U, DINameKind Kind) const;
133
134 /// Retrieves values of DW_AT_call_file, DW_AT_call_line and
135 /// DW_AT_call_column from DIE (or zeroes if they are missing).
136 void getCallerFrame(const DWARFUnit *U, uint32_t &CallFile,
137 uint32_t &CallLine, uint32_t &CallColumn) const;
138
139 /// Get inlined chain for a given address, rooted at the current DIE.
140 /// Returns empty chain if address is not contained in address range
141 /// of current DIE.
142 DWARFDebugInfoEntryInlinedChain
143 getInlinedChainForAddress(const DWARFUnit *U, const uint64_t Address) const;
144 };
145
146 /// DWARFDebugInfoEntryInlinedChain - represents a chain of inlined_subroutine
147 /// DIEs, (possibly ending with subprogram DIE), all of which are contained
148 /// in some concrete inlined instance tree. Address range for each DIE
149 /// (except the last DIE) in this chain is contained in address
150 /// range for next DIE in the chain.
151 struct DWARFDebugInfoEntryInlinedChain {
152 DWARFDebugInfoEntryInlinedChain() : U(nullptr) {}
153 SmallVector DIEs;
154 const DWARFUnit *U;
155 };
156
157 }
158
159 #endif
0 //===-- DWARFDebugLine.h ----------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGLINE_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGLINE_H
11
12 #include "llvm/DebugInfo/DWARF/DIContext.h"
13 #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
14 #include "llvm/Support/DataExtractor.h"
15 #include
16 #include
17 #include
18
19 namespace llvm {
20
21 class raw_ostream;
22
23 class DWARFDebugLine {
24 public:
25 DWARFDebugLine(const RelocAddrMap* LineInfoRelocMap) : RelocMap(LineInfoRelocMap) {}
26 struct FileNameEntry {
27 FileNameEntry() : Name(nullptr), DirIdx(0), ModTime(0), Length(0) {}
28
29 const char *Name;
30 uint64_t DirIdx;
31 uint64_t ModTime;
32 uint64_t Length;
33 };
34
35 struct Prologue {
36 Prologue();
37
38 // The size in bytes of the statement information for this compilation unit
39 // (not including the total_length field itself).
40 uint32_t TotalLength;
41 // Version identifier for the statement information format.
42 uint16_t Version;
43 // The number of bytes following the prologue_length field to the beginning
44 // of the first byte of the statement program itself.
45 uint32_t PrologueLength;
46 // The size in bytes of the smallest target machine instruction. Statement
47 // program opcodes that alter the address register first multiply their
48 // operands by this value.
49 uint8_t MinInstLength;
50 // The maximum number of individual operations that may be encoded in an
51 // instruction.
52 uint8_t MaxOpsPerInst;
53 // The initial value of theis_stmtregister.
54 uint8_t DefaultIsStmt;
55 // This parameter affects the meaning of the special opcodes. See below.
56 int8_t LineBase;
57 // This parameter affects the meaning of the special opcodes. See below.
58 uint8_t LineRange;
59 // The number assigned to the first special opcode.
60 uint8_t OpcodeBase;
61 std::vector StandardOpcodeLengths;
62 std::vector IncludeDirectories;
63 std::vector FileNames;
64
65 // Length of the prologue in bytes.
66 uint32_t getLength() const {
67 return PrologueLength + sizeof(TotalLength) + sizeof(Version) +
68 sizeof(PrologueLength);
69 }
70 // Length of the line table data in bytes (not including the prologue).
71 uint32_t getStatementTableLength() const {
72 return TotalLength + sizeof(TotalLength) - getLength();
73 }
74 int32_t getMaxLineIncrementForSpecialOpcode() const {
75 return LineBase + (int8_t)LineRange - 1;
76 }
77
78 void clear();
79 void dump(raw_ostream &OS) const;
80 bool parse(DataExtractor debug_line_data, uint32_t *offset_ptr);
81 };
82
83 // Standard .debug_line state machine structure.
84 struct Row {
85 explicit Row(bool default_is_stmt = false);
86
87 /// Called after a row is appended to the matrix.
88 void postAppend();
89 void reset(bool default_is_stmt);
90 void dump(raw_ostream &OS) const;
91
92 static bool orderByAddress(const Row& LHS, const Row& RHS) {
93 return LHS.Address < RHS.Address;
94 }
95
96 // The program-counter value corresponding to a machine instruction
97 // generated by the compiler.
98 uint64_t Address;
99 // An unsigned integer indicating a source line number. Lines are numbered
100 // beginning at 1. The compiler may emit the value 0 in cases where an
101 // instruction cannot be attributed to any source line.
102 uint32_t Line;
103 // An unsigned integer indicating a column number within a source line.
104 // Columns are numbered beginning at 1. The value 0 is reserved to indicate
105 // that a statement begins at the 'left edge' of the line.
106 uint16_t Column;
107 // An unsigned integer indicating the identity of the source file
108 // corresponding to a machine instruction.
109 uint16_t File;
110 // An unsigned integer whose value encodes the applicable instruction set
111 // architecture for the current instruction.
112 uint8_t Isa;
113 // An unsigned integer representing the DWARF path discriminator value
114 // for this location.
115 uint32_t Discriminator;
116 // A boolean indicating that the current instruction is the beginning of a
117 // statement.
118 uint8_t IsStmt:1,
119 // A boolean indicating that the current instruction is the
120 // beginning of a basic block.
121 BasicBlock:1,
122 // A boolean indicating that the current address is that of the
123 // first byte after the end of a sequence of target machine
124 // instructions.
125 EndSequence:1,
126 // A boolean indicating that the current address is one (of possibly
127 // many) where execution should be suspended for an entry breakpoint
128 // of a function.
129 PrologueEnd:1,
130 // A boolean indicating that the current address is one (of possibly
131 // many) where execution should be suspended for an exit breakpoint
132 // of a function.
133 EpilogueBegin:1;
134 };
135
136 // Represents a series of contiguous machine instructions. Line table for each
137 // compilation unit may consist of multiple sequences, which are not
138 // guaranteed to be in the order of ascending instruction address.
139 struct Sequence {
140 // Sequence describes instructions at address range [LowPC, HighPC)
141 // and is described by line table rows [FirstRowIndex, LastRowIndex).
142 uint64_t LowPC;
143 uint64_t HighPC;
144 unsigned FirstRowIndex;
145 unsigned LastRowIndex;
146 bool Empty;
147
148 Sequence();
149 void reset();
150
151 static bool orderByLowPC(const Sequence& LHS, const Sequence& RHS) {
152 return LHS.LowPC < RHS.LowPC;
153 }
154 bool isValid() const {
155 return !Empty && (LowPC < HighPC) && (FirstRowIndex < LastRowIndex);
156 }
157 bool containsPC(uint64_t pc) const {
158 return (LowPC <= pc && pc < HighPC);
159 }
160 };
161
162 struct LineTable {
163 LineTable();
164
165 void appendRow(const DWARFDebugLine::Row &R) {
166 Rows.push_back(R);
167 }
168 void appendSequence(const DWARFDebugLine::Sequence &S) {
169 Sequences.push_back(S);
170 }
171
172 // Returns the index of the row with file/line info for a given address,
173 // or -1 if there is no such row.
174 uint32_t lookupAddress(uint64_t address) const;
175
176 bool lookupAddressRange(uint64_t address, uint64_t size,
177 std::vector &result) const;
178
179 // Extracts filename by its index in filename table in prologue.
180 // Returns true on success.
181 bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir,
182 DILineInfoSpecifier::FileLineInfoKind Kind,
183 std::string &Result) const;
184
185 // Fills the Result argument with the file and line information
186 // corresponding to Address. Returns true on success.
187 bool getFileLineInfoForAddress(uint64_t Address, const char *CompDir,
188 DILineInfoSpecifier::FileLineInfoKind Kind,
189 DILineInfo &Result) const;
190
191 void dump(raw_ostream &OS) const;
192 void clear();
193
194 /// Parse prologue and all rows.
195 bool parse(DataExtractor debug_line_data, const RelocAddrMap *RMap,
196 uint32_t *offset_ptr);
197
198 struct Prologue Prologue;
199 typedef std::vector RowVector;
200 typedef RowVector::const_iterator RowIter;
201 typedef std::vector SequenceVector;
202 typedef SequenceVector::const_iterator SequenceIter;
203 RowVector Rows;
204 SequenceVector Sequences;
205 };
206
207 const LineTable *getLineTable(uint32_t offset) const;
208 const LineTable *getOrParseLineTable(DataExtractor debug_line_data,
209 uint32_t offset);
210
211 private:
212 struct ParsingState {
213 ParsingState(struct LineTable *LT);
214
215 void resetRowAndSequence();
216 void appendRowToMatrix(uint32_t offset);
217
218 // Line table we're currently parsing.
219 struct LineTable *LineTable;
220 // The row number that starts at zero for the prologue, and increases for
221 // each row added to the matrix.
222 unsigned RowNumber;
223 struct Row Row;
224 struct Sequence Sequence;
225 };
226
227 typedef std::map LineTableMapTy;
228 typedef LineTableMapTy::iterator LineTableIter;
229 typedef LineTableMapTy::const_iterator LineTableConstIter;
230
231 const RelocAddrMap *RelocMap;
232 LineTableMapTy LineTableMap;
233 };
234
235 }
236
237 #endif
0 //===-- DWARFDebugLoc.h -----------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGLOC_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGLOC_H
11
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
14 #include "llvm/Support/DataExtractor.h"
15
16 namespace llvm {
17
18 class raw_ostream;
19
20 class DWARFDebugLoc {
21 /// A single location within a location list.
22 struct Entry {
23 /// The beginning address of the instruction range.
24 uint64_t Begin;
25 /// The ending address of the instruction range.
26 uint64_t End;
27 /// The location of the variable within the specified range.
28 SmallVector Loc;
29 };
30
31 /// A list of locations that contain one variable.
32 struct LocationList {
33 /// The beginning offset where this location list is stored in the debug_loc
34 /// section.
35 unsigned Offset;
36 /// All the locations in which the variable is stored.
37 SmallVector Entries;
38 };
39
40 typedef SmallVector LocationLists;
41
42 /// A list of all the variables in the debug_loc section, each one describing
43 /// the locations in which the variable is stored.
44 LocationLists Locations;
45
46 /// A map used to resolve binary relocations.
47 const RelocAddrMap &RelocMap;
48
49 public:
50 DWARFDebugLoc(const RelocAddrMap &LocRelocMap) : RelocMap(LocRelocMap) {}
51 /// Print the location lists found within the debug_loc section.
52 void dump(raw_ostream &OS) const;
53 /// Parse the debug_loc section accessible via the 'data' parameter using the
54 /// specified address size to interpret the address ranges.
55 void parse(DataExtractor data, unsigned AddressSize);
56 };
57
58 class DWARFDebugLocDWO {
59 struct Entry {
60 uint64_t Start;
61 uint32_t Length;
62 SmallVector Loc;
63 };
64
65 struct LocationList {
66 unsigned Offset;
67 SmallVector Entries;
68 };
69
70 typedef SmallVector LocationLists;
71
72 LocationLists Locations;
73
74 public:
75 void parse(DataExtractor data);
76 void dump(raw_ostream &OS) const;
77 };
78 }
79
80 #endif
0 //===-- DWARFDebugRangeList.h -----------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGRANGELIST_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGRANGELIST_H
11
12 #include "llvm/Support/DataExtractor.h"
13 #include
14
15 namespace llvm {
16
17 class raw_ostream;
18
19 /// DWARFAddressRangesVector - represents a set of absolute address ranges.
20 typedef std::vector> DWARFAddressRangesVector;
21
22 class DWARFDebugRangeList {
23 public:
24 struct RangeListEntry {
25 // A beginning address offset. This address offset has the size of an
26 // address and is relative to the applicable base address of the
27 // compilation unit referencing this range list. It marks the beginning
28 // of an address range.
29 uint64_t StartAddress;
30 // An ending address offset. This address offset again has the size of
31 // an address and is relative to the applicable base address of the
32 // compilation unit referencing this range list. It marks the first
33 // address past the end of the address range. The ending address must
34 // be greater than or equal to the beginning address.
35 uint64_t EndAddress;
36 // The end of any given range list is marked by an end of list entry,
37 // which consists of a 0 for the beginning address offset
38 // and a 0 for the ending address offset.
39 bool isEndOfListEntry() const {
40 return (StartAddress == 0) && (EndAddress == 0);
41 }
42 // A base address selection entry consists of:
43 // 1. The value of the largest representable address offset
44 // (for example, 0xffffffff when the size of an address is 32 bits).
45 // 2. An address, which defines the appropriate base address for
46 // use in interpreting the beginning and ending address offsets of
47 // subsequent entries of the location list.
48 bool isBaseAddressSelectionEntry(uint8_t AddressSize) const {
49 assert(AddressSize == 4 || AddressSize == 8);
50 if (AddressSize == 4)
51 return StartAddress == -1U;
52 else
53 return StartAddress == -1ULL;
54 }
55 };
56
57 private:
58 // Offset in .debug_ranges section.
59 uint32_t Offset;
60 uint8_t AddressSize;
61 std::vector Entries;
62
63 public:
64 DWARFDebugRangeList() { clear(); }
65 void clear();
66 void dump(raw_ostream &OS) const;
67 bool extract(DataExtractor data, uint32_t *offset_ptr);
68 /// getAbsoluteRanges - Returns absolute address ranges defined by this range
69 /// list. Has to be passed base address of the compile unit referencing this
70 /// range list.
71 DWARFAddressRangesVector getAbsoluteRanges(uint64_t BaseAddress) const;
72 };
73
74 } // namespace llvm
75
76 #endif // LLVM_DEBUGINFO_DWARFDEBUGRANGELIST_H
0 //===-- DWARFFormValue.h ----------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_DEBUGINFO_DWARFFORMVALUE_H
10 #define LLVM_DEBUGINFO_DWARFFORMVALUE_H
11
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/Support/DataExtractor.h"
15
16 namespace llvm {
17
18 class DWARFUnit;
19 class raw_ostream;
20
21 class DWARFFormValue {
22 public:
23 enum FormClass {
24 FC_Unknown,
25 FC_Address,
26 FC_Block,
27 FC_Constant,
28 FC_String,
29 FC_Flag,
30 FC_Reference,
31 FC_Indirect,
32 FC_SectionOffset,
33 FC_Exprloc
34 };
35
36 private:
37 struct ValueType {
38 ValueType() : data(nullptr) {
39 uval = 0;
40 }
41
42 union {
43 uint64_t uval;
44 int64_t sval;
45 const char* cstr;
46 };
47 const uint8_t* data;
48 };
49
50 uint16_t Form; // Form for this value.
51 ValueType Value; // Contains all data for the form.
52
53 public:
54 DWARFFormValue(uint16_t Form = 0) : Form(Form) {}
55 uint16_t getForm() const { return Form; }
56 bool isFormClass(FormClass FC) const;
57
58 void dump(raw_ostream &OS, const DWARFUnit *U) const;
59
60 /// \brief extracts a value in data at offset *offset_ptr.
61 ///
62 /// The passed DWARFUnit is allowed to be nullptr, in which
63 /// case no relocation processing will be performed and some
64 /// kind of forms that depend on Unit information are disallowed.
65 /// \returns wether the extraction succeeded.
66 bool extractValue(DataExtractor data, uint32_t *offset_ptr,
67 const DWARFUnit *u);
68 bool isInlinedCStr() const {
69 return Value.data != nullptr && Value.data == (const uint8_t*)Value.cstr;
70 }
71
72 /// getAsFoo functions below return the extracted value as Foo if only
73 /// DWARFFormValue has form class is suitable for representing Foo.
74 Optional getAsReference(const DWARFUnit *U) const;
75 Optional getAsUnsignedConstant() const;
76 Optional getAsCString(const DWARFUnit *U) const;
77 Optional getAsAddress(const DWARFUnit *U) const;
78 Optional getAsSectionOffset() const;
79 Optional> getAsBlock() const;
80
81 bool skipValue(DataExtractor debug_info_data, uint32_t *offset_ptr,
82 const DWARFUnit *u) const;
83 static bool skipValue(uint16_t form, DataExtractor debug_info_data,
84 uint32_t *offset_ptr, const DWARFUnit *u);
85
86 static ArrayRef getFixedFormSizes(uint8_t AddrSize,
87 uint16_t Version);
88 };
89
90 }
91
92 #endif
0 //===-- DWARFRelocMap.h -----------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFRELOCMAP_H
10 #define LLVM_LIB_DEBUGINFO_DWARFRELOCMAP_H
11
12 #include "llvm/ADT/DenseMap.h"
13
14 namespace llvm {
15
16 typedef DenseMap > RelocAddrMap;
17
18 } // namespace llvm
19
20 #endif
21
0 //===-- DWARFSection.h ------------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFSECTION_H
10 #define LLVM_LIB_DEBUGINFO_DWARFSECTION_H
11
12 #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
13
14 namespace llvm {
15
16 struct DWARFSection {
17 StringRef Data;
18 RelocAddrMap Relocs;
19 };
20
21 }
22
23 #endif
0 //===-- DWARFTypeUnit.h -----------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFTYPEUNIT_H
10 #define LLVM_LIB_DEBUGINFO_DWARFTYPEUNIT_H
11
12 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
13
14 namespace llvm {
15
16 class DWARFTypeUnit : public DWARFUnit {
17 private:
18 uint64_t TypeHash;
19 uint32_t TypeOffset;
20 public:
21 DWARFTypeUnit(DWARFContext &Context, const DWARFSection &Section,
22 const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
23 StringRef SOS, StringRef AOS, bool LE,
24 const DWARFUnitSectionBase &UnitSection)
25 : DWARFUnit(Context, Section, DA, RS, SS, SOS, AOS, LE, UnitSection) {}
26 uint32_t getHeaderSize() const override {
27 return DWARFUnit::getHeaderSize() + 12;
28 }
29 void dump(raw_ostream &OS);
30 protected:
31 bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr) override;
32 };
33
34 }
35
36 #endif
37
0 //===-- DWARFUnit.h ---------------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFUNIT_H
10 #define LLVM_LIB_DEBUGINFO_DWARFUNIT_H
11
12 #include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
13 #include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
14 #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
15 #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
16 #include "llvm/DebugInfo/DWARF/DWARFSection.h"
17 #include
18
19 namespace llvm {
20
21 namespace object {
22 class ObjectFile;
23 }
24
25 class DWARFContext;
26 class DWARFDebugAbbrev;
27 class DWARFUnit;
28 class StringRef;
29 class raw_ostream;
30
31 /// Base class for all DWARFUnitSection classes. This provides the
32 /// functionality common to all unit types.
33 class DWARFUnitSectionBase {
34 public:
35 /// Returns the Unit that contains the given section offset in the
36 /// same section this Unit originated from.
37 virtual DWARFUnit *getUnitForOffset(uint32_t Offset) const = 0;
38
39 void parse(DWARFContext &C, const DWARFSection &Section);
40 void parseDWO(DWARFContext &C, const DWARFSection &DWOSection);
41
42 protected:
43 virtual void parseImpl(DWARFContext &Context, const DWARFSection &Section,
44 const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
45 StringRef SOS, StringRef AOS, bool isLittleEndian) = 0;
46
47 ~DWARFUnitSectionBase() {}
48 };
49
50 /// Concrete instance of DWARFUnitSection, specialized for one Unit type.
51 template
52 class DWARFUnitSection final : public SmallVector, 1>,
53 public DWARFUnitSectionBase {
54
55 struct UnitOffsetComparator {
56 bool operator()(uint32_t LHS,
57 const std::unique_ptr &RHS) const {
58 return LHS < RHS->getNextUnitOffset();
59 }
60 };
61
62 bool Parsed;
63
64 public:
65 DWARFUnitSection() : Parsed(false) {}
66 DWARFUnitSection(DWARFUnitSection &&DUS) :
67 SmallVector, 1>(std::move(DUS)), Parsed(DUS.Parsed) {}
68
69 typedef llvm::SmallVectorImpl> UnitVector;
70 typedef typename UnitVector::iterator iterator;
71 typedef llvm::iterator_range iterator_range;
72
73 UnitType *getUnitForOffset(uint32_t Offset) const override {
74 auto *CU = std::upper_bound(this->begin(), this->end(), Offset,
75 UnitOffsetComparator());
76 if (CU != this->end())
77 return CU->get();
78 return nullptr;
79 }
80
81 private:
82 void parseImpl(DWARFContext &Context, const DWARFSection &Section,
83 const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
84 StringRef SOS, StringRef AOS, bool LE) override {
85 if (Parsed)
86 return;
87 DataExtractor Data(Section.Data, LE, 0);
88 uint32_t Offset = 0;
89 while (Data.isValidOffset(Offset)) {
90 auto U = llvm::make_unique(Context, Section, DA, RS, SS, SOS,
91 AOS, LE, *this);
92 if (!U->extract(Data, &Offset))
93 break;
94 this->push_back(std::move(U));
95 Offset = this->back()->getNextUnitOffset();
96 }
97 Parsed = true;
98 }
99 };
100
101 class DWARFUnit {
102 DWARFContext &Context;
103 // Section containing this DWARFUnit.
104 const DWARFSection &InfoSection;
105
106 const DWARFDebugAbbrev *Abbrev;
107 StringRef RangeSection;
108 uint32_t RangeSectionBase;
109 StringRef StringSection;
110 StringRef StringOffsetSection;
111 StringRef AddrOffsetSection;
112 uint32_t AddrOffsetSectionBase;
113 bool isLittleEndian;
114 const DWARFUnitSectionBase &UnitSection;
115
116 uint32_t Offset;
117 uint32_t Length;
118 uint16_t Version;
119 const DWARFAbbreviationDeclarationSet *Abbrevs;
120 uint8_t AddrSize;
121 uint64_t BaseAddr;
122 // The compile unit debug information entry items.
123 std::vector DieArray;
124
125 class DWOHolder {
126 object::OwningBinary DWOFile;
127 std::unique_ptr DWOContext;
128 DWARFUnit *DWOU;
129 public:
130 DWOHolder(StringRef DWOPath);
131 DWARFUnit *getUnit() const { return DWOU; }
132 };
133 std::unique_ptr DWO;
134
135 protected:
136 virtual bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr);
137 /// Size in bytes of the unit header.
138 virtual uint32_t getHeaderSize() const { return 11; }
139
140 public:
141 DWARFUnit(DWARFContext &Context, const DWARFSection &Section,
142 const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
143 StringRef SOS, StringRef AOS, bool LE,
144 const DWARFUnitSectionBase &UnitSection);
145
146 virtual ~DWARFUnit();
147
148 DWARFContext& getContext() const { return Context; }
149
150 StringRef getStringSection() const { return StringSection; }
151 StringRef getStringOffsetSection() const { return StringOffsetSection; }
152 void setAddrOffsetSection(StringRef AOS, uint32_t Base) {
153 AddrOffsetSection = AOS;
154 AddrOffsetSectionBase = Base;
155 }
156 void setRangesSection(StringRef RS, uint32_t Base) {
157 RangeSection = RS;
158 RangeSectionBase = Base;
159 }
160
161 bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
162 // FIXME: Result should be uint64_t in DWARF64.
163 bool getStringOffsetSectionItem(uint32_t Index, uint32_t &Result) const;
164
165 DataExtractor getDebugInfoExtractor() const {
166 return DataExtractor(InfoSection.Data, isLittleEndian, AddrSize);
167 }
168 DataExtractor getStringExtractor() const {
169 return DataExtractor(StringSection, false, 0);
170 }
171
172 const RelocAddrMap *getRelocMap() const { return &InfoSection.Relocs; }
173
174 bool extract(DataExtractor debug_info, uint32_t* offset_ptr);
175
176 /// extractRangeList - extracts the range list referenced by this compile
177 /// unit from .debug_ranges section. Returns true on success.
178 /// Requires that compile unit is already extracted.
179 bool extractRangeList(uint32_t RangeListOffset,
180 DWARFDebugRangeList &RangeList) const;
181 void clear();
182 uint32_t getOffset() const { return Offset; }
183 uint32_t getNextUnitOffset() const { return Offset + Length + 4; }
184 uint32_t getLength() const { return Length; }
185 uint16_t getVersion() const { return Version; }
186 const DWARFAbbreviationDeclarationSet *getAbbreviations() const {
187 return Abbrevs;
188 }
189 uint8_t getAddressByteSize() const { return AddrSize; }
190 uint64_t getBaseAddress() const { return BaseAddr; }
191
192 void setBaseAddress(uint64_t base_addr) {
193 BaseAddr = base_addr;
194 }
195
196 const DWARFDebugInfoEntryMinimal *
197 getCompileUnitDIE(bool extract_cu_die_only = true) {
198 extractDIEsIfNeeded(extract_cu_die_only);
199 return DieArray.empty() ? nullptr : &DieArray[0];
200 }
201
202 const char *getCompilationDir();
203 uint64_t getDWOId();
204
205 void collectAddressRanges(DWARFAddressRangesVector &CURanges);
206
207 /// getInlinedChainForAddress - fetches inlined chain for a given address.
208 /// Returns empty chain if there is no subprogram containing address. The
209 /// chain is valid as long as parsed compile unit DIEs are not cleared.
210 DWARFDebugInfoEntryInlinedChain getInlinedChainForAddress(uint64_t Address);
211
212 /// getUnitSection - Return the DWARFUnitSection containing this unit.
213 const DWARFUnitSectionBase &getUnitSection() const { return UnitSection; }
214
215 /// \brief Returns the number of DIEs in the unit. Parses the unit
216 /// if necessary.
217 unsigned getNumDIEs() {
218 extractDIEsIfNeeded(false);
219 return DieArray.size();
220 }
221
222 /// \brief Return the index of a DIE inside the unit's DIE vector.
223 ///
224 /// It is illegal to call this method with a DIE that hasn't be
225 /// created by this unit. In other word, it's illegal to call this
226 /// method on a DIE that isn't accessible by following
227 /// children/sibling links starting from this unit's
228 /// getCompileUnitDIE().
229 uint32_t getDIEIndex(const DWARFDebugInfoEntryMinimal *DIE) {
230 assert(!DieArray.empty() && DIE >= &DieArray[0] &&
231 DIE < &DieArray[0] + DieArray.size());
232 return DIE - &DieArray[0];
233 }
234
235 private:
236 /// Size in bytes of the .debug_info data associated with this compile unit.
237 size_t getDebugInfoSize() const { return Length + 4 - getHeaderSize(); }
238
239 /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
240 /// hasn't already been done. Returns the number of DIEs parsed at this call.
241 size_t extractDIEsIfNeeded(bool CUDieOnly);
242 /// extractDIEsToVector - Appends all parsed DIEs to a vector.
243 void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs,
244 std::vector &DIEs) const;
245 /// setDIERelations - We read in all of the DIE entries into our flat list
246 /// of DIE entries and now we need to go back through all of them and set the
247 /// parent, sibling and child pointers for quick DIE navigation.
248 void setDIERelations();
249 /// clearDIEs - Clear parsed DIEs to keep memory usage low.
250 void clearDIEs(bool KeepCUDie);
251
252 /// parseDWO - Parses .dwo file for current compile unit. Returns true if
253 /// it was actually constructed.
254 bool parseDWO();
255
256 /// getSubprogramForAddress - Returns subprogram DIE with address range
257 /// encompassing the provided address. The pointer is alive as long as parsed
258 /// compile unit DIEs are not cleared.
259 const DWARFDebugInfoEntryMinimal *getSubprogramForAddress(uint64_t Address);
260 };
261
262 }
263
264 #endif
+0
-60
include/llvm/DebugInfo/DWARFAbbreviationDeclaration.h less more
None //===-- DWARFAbbreviationDeclaration.h --------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
10 #define LLVM_LIB_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
11
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/Support/DataExtractor.h"
14
15 namespace llvm {
16
17 class raw_ostream;
18
19 class DWARFAbbreviationDeclaration {
20 uint32_t Code;
21 uint32_t Tag;
22 bool HasChildren;
23
24 struct AttributeSpec {
25 AttributeSpec(uint16_t Attr, uint16_t Form) : Attr(Attr), Form(Form) {}
26 uint16_t Attr;
27 uint16_t Form;
28 };
29 typedef SmallVector AttributeSpecVector;
30 AttributeSpecVector AttributeSpecs;
31 public:
32 DWARFAbbreviationDeclaration();
33
34 uint32_t getCode() const { return Code; }
35 uint32_t getTag() const { return Tag; }
36 bool hasChildren() const { return HasChildren; }
37
38 typedef iterator_range
39 attr_iterator_range;
40
41 attr_iterator_range attributes() const {
42 return attr_iterator_range(AttributeSpecs.begin(), AttributeSpecs.end());
43 }
44
45 uint16_t getFormByIndex(uint32_t idx) const {
46 return idx < AttributeSpecs.size() ? AttributeSpecs[idx].Form : 0;
47 }
48
49 uint32_t findAttributeIndex(uint16_t attr) const;
50 bool extract(DataExtractor Data, uint32_t* OffsetPtr);
51 void dump(raw_ostream &OS) const;
52
53 private:
54 void clear();
55 };
56
57 }
58
59 #endif
+0
-49
include/llvm/DebugInfo/DWARFAcceleratorTable.h less more
None //===--- DWARFAcceleratorTable.h --------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/ADT/SmallVector.h"
10 #include "llvm/DebugInfo/DWARFFormValue.h"
11 #include "llvm/DebugInfo/DWARFRelocMap.h"
12 #include
13
14 namespace llvm {
15
16 class DWARFAcceleratorTable {
17
18 struct Header {
19 uint32_t Magic;
20 uint16_t Version;
21 uint16_t HashFunction;
22 uint32_t NumBuckets;
23 uint32_t NumHashes;
24 uint32_t HeaderDataLength;
25 };
26
27 struct HeaderData {
28 typedef uint16_t AtomType;
29 typedef uint16_t Form;
30 uint32_t DIEOffsetBase;
31 SmallVector, 3> Atoms;
32 };
33
34 struct Header Hdr;
35 struct HeaderData HdrData;
36 DataExtractor AccelSection;
37 DataExtractor StringSection;
38 const RelocAddrMap& Relocs;
39 public:
40 DWARFAcceleratorTable(DataExtractor AccelSection, DataExtractor StringSection,
41 const RelocAddrMap &Relocs)
42 : AccelSection(AccelSection), StringSection(StringSection), Relocs(Relocs) {}
43
44 bool extract();
45 void dump(raw_ostream &OS) const;
46 };
47
48 }
+0
-31
include/llvm/DebugInfo/DWARFCompileUnit.h less more
None //===-- DWARFCompileUnit.h --------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFCOMPILEUNIT_H
10 #define LLVM_LIB_DEBUGINFO_DWARFCOMPILEUNIT_H
11
12 #include "llvm/DebugInfo/DWARFUnit.h"
13
14 namespace llvm {
15
16 class DWARFCompileUnit : public DWARFUnit {
17 public:
18 DWARFCompileUnit(DWARFContext &Context, const DWARFSection &Section,
19 const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
20 StringRef SOS, StringRef AOS, bool LE,
21 const DWARFUnitSectionBase &UnitSection)
22 : DWARFUnit(Context, Section, DA, RS, SS, SOS, AOS, LE, UnitSection) {}
23 void dump(raw_ostream &OS);
24 // VTable anchor.
25 ~DWARFCompileUnit() override;
26 };
27
28 }
29
30 #endif
+0
-292
include/llvm/DebugInfo/DWARFContext.h less more
None //===-- DWARFContext.h ------------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===/
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFCONTEXT_H
10 #define LLVM_LIB_DEBUGINFO_DWARFCONTEXT_H
11
12 #include "llvm/ADT/MapVector.h"
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/DebugInfo/DIContext.h"
15 #include "llvm/DebugInfo/DWARFCompileUnit.h"
16 #include "llvm/DebugInfo/DWARFDebugAranges.h"
17 #include "llvm/DebugInfo/DWARFDebugFrame.h"
18 #include "llvm/DebugInfo/DWARFDebugLine.h"
19 #include "llvm/DebugInfo/DWARFDebugLoc.h"
20 #include "llvm/DebugInfo/DWARFDebugRangeList.h"
21 #include "llvm/DebugInfo/DWARFSection.h"
22 #include "llvm/DebugInfo/DWARFTypeUnit.h"
23 #include
24
25 namespace llvm {
26
27 /// DWARFContext
28 /// This data structure is the top level entity that deals with dwarf debug
29 /// information parsing. The actual data is supplied through pure virtual
30 /// methods that a concrete implementation provides.
31 class DWARFContext : public DIContext {
32
33 DWARFUnitSection CUs;
34 std::vector> TUs;
35 std::unique_ptr Abbrev;
36 std::unique_ptr Loc;
37 std::unique_ptr Aranges;
38 std::unique_ptr Line;
39 std::unique_ptr DebugFrame;
40
41 DWARFUnitSection DWOCUs;
42 std::vector> DWOTUs;
43 std::unique_ptr AbbrevDWO;
44 std::unique_ptr LocDWO;
45
46 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
47 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
48
49 /// Read compile units from the debug_info section (if necessary)
50 /// and store them in CUs.
51 void parseCompileUnits();
52
53 /// Read type units from the debug_types sections (if necessary)
54 /// and store them in TUs.
55 void parseTypeUnits();
56
57 /// Read compile units from the debug_info.dwo section (if necessary)
58 /// and store them in DWOCUs.
59 void parseDWOCompileUnits();
60
61 /// Read type units from the debug_types.dwo section (if necessary)
62 /// and store them in DWOTUs.
63 void parseDWOTypeUnits();
64
65 public:
66 DWARFContext() : DIContext(CK_DWARF) {}
67
68 static bool classof(const DIContext *DICtx) {
69 return DICtx->getKind() == CK_DWARF;
70 }
71
72 void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) override;
73
74 typedef DWARFUnitSection::iterator_range cu_iterator_range;
75 typedef DWARFUnitSection::iterator_range tu_iterator_range;
76 typedef iterator_range>::iterator> tu_section_iterator_range;
77
78 /// Get compile units in this context.
79 cu_iterator_range compile_units() {
80 parseCompileUnits();
81 return cu_iterator_range(CUs.begin(), CUs.end());
82 }
83
84 /// Get type units in this context.
85 tu_section_iterator_range type_unit_sections() {
86 parseTypeUnits();
87 return tu_section_iterator_range(TUs.begin(), TUs.end());
88 }
89
90 /// Get compile units in the DWO context.
91 cu_iterator_range dwo_compile_units() {
92 parseDWOCompileUnits();
93 return cu_iterator_range(DWOCUs.begin(), DWOCUs.end());
94 }
95
96 /// Get type units in the DWO context.
97 tu_section_iterator_range dwo_type_unit_sections() {
98 parseDWOTypeUnits();
99 return tu_section_iterator_range(DWOTUs.begin(), DWOTUs.end());
100 }
101
102 /// Get the number of compile units in this context.
103 unsigned getNumCompileUnits() {
104 parseCompileUnits();
105 return CUs.size();
106 }
107
108 /// Get the number of compile units in this context.
109 unsigned getNumTypeUnits() {
110 parseTypeUnits();
111 return TUs.size();
112 }
113
114 /// Get the number of compile units in the DWO context.
115 unsigned getNumDWOCompileUnits() {
116 parseDWOCompileUnits();
117 return DWOCUs.size();
118 }
119
120 /// Get the number of compile units in the DWO context.
121 unsigned getNumDWOTypeUnits() {
122 parseDWOTypeUnits();
123 return DWOTUs.size();
124 }
125
126 /// Get the compile unit at the specified index for this compile unit.
127 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
128 parseCompileUnits();
129 return CUs[index].get();
130 }
131
132 /// Get the compile unit at the specified index for the DWO compile units.
133 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
134 parseDWOCompileUnits();
135 return DWOCUs[index].get();
136 }
137
138 /// Get a pointer to the parsed DebugAbbrev object.
139 const DWARFDebugAbbrev *getDebugAbbrev();
140
141 /// Get a pointer to the parsed DebugLoc object.
142 const DWARFDebugLoc *getDebugLoc();
143
144 /// Get a pointer to the parsed dwo abbreviations object.
145 const DWARFDebugAbbrev *getDebugAbbrevDWO();
146
147 /// Get a pointer to the parsed DebugLoc object.
148 const DWARFDebugLocDWO *getDebugLocDWO();
149
150 /// Get a pointer to the parsed DebugAranges object.
151 const DWARFDebugAranges *getDebugAranges();
152
153 /// Get a pointer to the parsed frame information object.
154 const DWARFDebugFrame *getDebugFrame();
155
156 /// Get a pointer to a parsed line table corresponding to a compile unit.
157 const DWARFDebugLine::LineTable *getLineTableForUnit(DWARFUnit *cu);
158
159 DILineInfo getLineInfoForAddress(uint64_t Address,
160 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
161 DILineInfoTable getLineInfoForAddressRange(uint64_t Address, uint64_t Size,
162 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
163 DIInliningInfo getInliningInfoForAddress(uint64_t Address,
164 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
165
166 virtual bool isLittleEndian() const = 0;
167 virtual uint8_t getAddressSize() const = 0;
168 virtual const DWARFSection &getInfoSection() = 0;
169 typedef MapVector
170 std::map> TypeSectionMap;
171 virtual const TypeSectionMap &getTypesSections() = 0;
172 virtual StringRef getAbbrevSection() = 0;
173 virtual const DWARFSection &getLocSection() = 0;
174 virtual StringRef getARangeSection() = 0;
175 virtual StringRef getDebugFrameSection() = 0;
176 virtual const DWARFSection &getLineSection() = 0;
177 virtual StringRef getStringSection() = 0;
178 virtual StringRef getRangeSection() = 0;
179 virtual StringRef getPubNamesSection() = 0;
180 virtual StringRef getPubTypesSection() = 0;
181 virtual StringRef getGnuPubNamesSection() = 0;
182 virtual StringRef getGnuPubTypesSection() = 0;
183
184 // Sections for DWARF5 split dwarf proposal.
185 virtual const DWARFSection &getInfoDWOSection() = 0;
186 virtual const TypeSectionMap &getTypesDWOSections() = 0;
187 virtual StringRef getAbbrevDWOSection() = 0;
188 virtual const DWARFSection &getLineDWOSection() = 0;
189 virtual const DWARFSection &getLocDWOSection() = 0;
190 virtual StringRef getStringDWOSection() = 0;
191 virtual StringRef getStringOffsetDWOSection() = 0;
192 virtual StringRef getRangeDWOSection() = 0;
193 virtual StringRef getAddrSection() = 0;
194 virtual const DWARFSection& getAppleNamesSection() = 0;
195 virtual const DWARFSection& getAppleTypesSection() = 0;
196 virtual const DWARFSection& getAppleNamespacesSection() = 0;
197 virtual const DWARFSection& getAppleObjCSection() = 0;
198
199 static bool isSupportedVersion(unsigned version) {
200 return version == 2 || version == 3 || version == 4;
201 }
202 private:
203 /// Return the compile unit that includes an offset (relative to .debug_info).
204 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
205
206 /// Return the compile unit which contains instruction with provided
207 /// address.
208 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
209 };
210
211 /// DWARFContextInMemory is the simplest possible implementation of a
212 /// DWARFContext. It assumes all content is available in memory and stores
213 /// pointers to it.
214 class DWARFContextInMemory : public DWARFContext {
215 virtual void anchor();
216 bool IsLittleEndian;
217 uint8_t AddressSize;
218 DWARFSection InfoSection;
219 TypeSectionMap TypesSections;
220 StringRef AbbrevSection;
221 DWARFSection LocSection;
222 StringRef ARangeSection;
223 StringRef DebugFrameSection;
224 DWARFSection LineSection;
225 StringRef StringSection;
226 StringRef RangeSection;
227 StringRef PubNamesSection;
228 StringRef PubTypesSection;
229 StringRef GnuPubNamesSection;
230 StringRef GnuPubTypesSection;
231
232 // Sections for DWARF5 split dwarf proposal.
233 DWARFSection InfoDWOSection;
234 TypeSectionMap TypesDWOSections;
235 StringRef AbbrevDWOSection;
236 DWARFSection LineDWOSection;
237 DWARFSection LocDWOSection;
238 StringRef StringDWOSection;
239 StringRef StringOffsetDWOSection;
240 StringRef RangeDWOSection;
241 StringRef AddrSection;
242 DWARFSection AppleNamesSection;
243 DWARFSection AppleTypesSection;
244 DWARFSection AppleNamespacesSection;
245 DWARFSection AppleObjCSection;
246
247 SmallVector, 4> UncompressedSections;
248
249 public:
250 DWARFContextInMemory(const object::ObjectFile &Obj);
251 bool isLittleEndian() const override { return IsLittleEndian; }
252 uint8_t getAddressSize() const override { return AddressSize; }
253 const DWARFSection &getInfoSection() override { return InfoSection; }
254 const TypeSectionMap &getTypesSections() override { return TypesSections; }
255 StringRef getAbbrevSection() override { return AbbrevSection; }
256 const DWARFSection &getLocSection() override { return LocSection; }
257 StringRef getARangeSection() override { return ARangeSection; }
258 StringRef getDebugFrameSection() override { return DebugFrameSection; }
259 const DWARFSection &getLineSection() override { return LineSection; }
260 StringRef getStringSection() override { return StringSection; }
261 StringRef getRangeSection() override { return RangeSection; }
262 StringRef getPubNamesSection() override { return PubNamesSection; }
263 StringRef getPubTypesSection() override { return PubTypesSection; }
264 StringRef getGnuPubNamesSection() override { return GnuPubNamesSection; }
265 StringRef getGnuPubTypesSection() override { return GnuPubTypesSection; }
266 const DWARFSection& getAppleNamesSection() override { return AppleNamesSection; }
267 const DWARFSection& getAppleTypesSection() override { return AppleTypesSection; }
268 const DWARFSection& getAppleNamespacesSection() override { return AppleNamespacesSection; }
269 const DWARFSection& getAppleObjCSection() override { return AppleObjCSection; }
270
271 // Sections for DWARF5 split dwarf proposal.
272 const DWARFSection &getInfoDWOSection() override { return InfoDWOSection; }
273 const TypeSectionMap &getTypesDWOSections() override {
274 return TypesDWOSections;
275 }
276 StringRef getAbbrevDWOSection() override { return AbbrevDWOSection; }
277 const DWARFSection &getLineDWOSection() override { return LineDWOSection; }
278 const DWARFSection &getLocDWOSection() override { return LocDWOSection; }
279 StringRef getStringDWOSection() override { return StringDWOSection; }
280 StringRef getStringOffsetDWOSection() override {
281 return StringOffsetDWOSection;
282 }
283 StringRef getRangeDWOSection() override { return RangeDWOSection; }
284 StringRef getAddrSection() override {
285 return AddrSection;
286 }
287 };
288
289 }
290
291 #endif
+0
-63
include/llvm/DebugInfo/DWARFDebugAbbrev.h less more
None //===-- DWARFDebugAbbrev.h --------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGABBREV_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGABBREV_H
11
12 #include "llvm/DebugInfo/DWARFAbbreviationDeclaration.h"
13 #include
14 #include
15 #include
16
17 namespace llvm {
18
19 class DWARFAbbreviationDeclarationSet {
20 uint32_t Offset;
21 /// Code of the first abbreviation, if all abbreviations in the set have
22 /// consecutive codes. UINT32_MAX otherwise.
23 uint32_t FirstAbbrCode;
24 std::vector Decls;
25
26 public:
27 DWARFAbbreviationDeclarationSet();
28
29 uint32_t getOffset() const { return Offset; }
30 void dump(raw_ostream &OS) const;
31 bool extract(DataExtractor Data, uint32_t *OffsetPtr);
32
33 const DWARFAbbreviationDeclaration *
34 getAbbreviationDeclaration(uint32_t AbbrCode) const;
35
36 private:
37 void clear();
38 };
39
40 class DWARFDebugAbbrev {
41 typedef std::map
42 DWARFAbbreviationDeclarationSetMap;
43
44 DWARFAbbreviationDeclarationSetMap AbbrDeclSets;
45 mutable DWARFAbbreviationDeclarationSetMap::const_iterator PrevAbbrOffsetPos;
46
47 public:
48 DWARFDebugAbbrev();
49
50 const DWARFAbbreviationDeclarationSet *
51 getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const;
52
53 void dump(raw_ostream &OS) const;
54 void extract(DataExtractor Data);
55
56 private:
57 void clear();
58 };
59
60 }
61
62 #endif
+0
-70
include/llvm/DebugInfo/DWARFDebugArangeSet.h less more
None //===-- DWARFDebugArangeSet.h -----------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGESET_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGESET_H
11
12 #include "llvm/ADT/iterator_range.h"
13 #include "llvm/Support/DataExtractor.h"
14 #include
15
16 namespace llvm {
17
18 class raw_ostream;
19
20 class DWARFDebugArangeSet {
21 public:
22 struct Header {
23 // The total length of the entries for that set, not including the length
24 // field itself.
25 uint32_t Length;
26 // The offset from the beginning of the .debug_info section of the
27 // compilation unit entry referenced by the table.
28 uint32_t CuOffset;
29 // The DWARF version number.
30 uint16_t Version;
31 // The size in bytes of an address on the target architecture. For segmented
32 // addressing, this is the size of the offset portion of the address.
33 uint8_t AddrSize;
34 // The size in bytes of a segment descriptor on the target architecture.
35 // If the target system uses a flat address space, this value is 0.
36 uint8_t SegSize;
37 };
38
39 struct Descriptor {
40 uint64_t Address;
41 uint64_t Length;
42 uint64_t getEndAddress() const { return Address + Length; }
43 };
44
45 private:
46 typedef std::vector DescriptorColl;
47 typedef iterator_range desc_iterator_range;
48
49 uint32_t Offset;
50 Header HeaderData;
51 DescriptorColl ArangeDescriptors;
52
53 public:
54 DWARFDebugArangeSet() { clear(); }
55 void clear();
56 bool extract(DataExtractor data, uint32_t *offset_ptr);
57 void dump(raw_ostream &OS) const;
58
59 uint32_t getCompileUnitDIEOffset() const { return HeaderData.CuOffset; }
60
61 desc_iterator_range descriptors() const {
62 return desc_iterator_range(ArangeDescriptors.begin(),
63 ArangeDescriptors.end());
64 }
65 };
66
67 }
68
69 #endif
+0
-87
include/llvm/DebugInfo/DWARFDebugAranges.h less more
None //===-- DWARFDebugAranges.h -------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGES_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGES_H
11
12 #include "llvm/ADT/DenseSet.h"
13 #include "llvm/Support/DataExtractor.h"
14 #include
15
16 namespace llvm {
17
18 class DWARFContext;
19
20 class DWARFDebugAranges {
21 public:
22 void generate(DWARFContext *CTX);
23 uint32_t findAddress(uint64_t Address) const;
24
25 private:
26 void clear();
27 void extract(DataExtractor DebugArangesData);
28
29 // Call appendRange multiple times and then call construct.
30 void appendRange(uint32_t CUOffset, uint64_t LowPC, uint64_t HighPC);
31 void construct();
32
33 struct Range {
34 explicit Range(uint64_t LowPC = -1ULL, uint64_t HighPC = -1ULL,
35 uint32_t CUOffset = -1U)
36 : LowPC(LowPC), Length(HighPC - LowPC), CUOffset(CUOffset) {}
37
38 void setHighPC(uint64_t HighPC) {
39 if (HighPC == -1ULL || HighPC <= LowPC)
40 Length = 0;
41 else
42 Length = HighPC - LowPC;
43 }
44 uint64_t HighPC() const {
45 if (Length)
46 return LowPC + Length;
47 return -1ULL;
48 }
49
50 bool containsAddress(uint64_t Address) const {
51 return LowPC <= Address && Address < HighPC();
52 }
53 bool operator<(const Range &other) const {
54 return LowPC < other.LowPC;
55 }
56
57 uint64_t LowPC; // Start of address range.
58 uint32_t Length; // End of address range (not including this address).
59 uint32_t CUOffset; // Offset of the compile unit or die.
60 };
61
62 struct RangeEndpoint {
63 uint64_t Address;
64 uint32_t CUOffset;
65 bool IsRangeStart;
66
67 RangeEndpoint(uint64_t Address, uint32_t CUOffset, bool IsRangeStart)
68 : Address(Address), CUOffset(CUOffset), IsRangeStart(IsRangeStart) {}
69
70 bool operator<(const RangeEndpoint &Other) const {
71 return Address < Other.Address;
72 }
73 };
74
75
76 typedef std::vector RangeColl;
77 typedef RangeColl::const_iterator RangeCollIterator;
78
79 std::vector Endpoints;
80 RangeColl Aranges;
81 DenseSet ParsedCUOffsets;
82 };
83
84 }
85
86 #endif
+0
-43
include/llvm/DebugInfo/DWARFDebugFrame.h less more
None //===-- DWARFDebugFrame.h - Parsing of .debug_frame -------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGFRAME_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGFRAME_H
11
12 #include "llvm/Support/DataExtractor.h"
13 #include "llvm/Support/raw_ostream.h"
14 #include
15 #include
16
17 namespace llvm {
18
19 class FrameEntry;
20
21 /// \brief A parsed .debug_frame section
22 ///
23 class DWARFDebugFrame {
24 public:
25 DWARFDebugFrame();
26 ~DWARFDebugFrame();
27
28 /// \brief Dump the section data into the given stream.
29 void dump(raw_ostream &OS) const;
30
31 /// \brief Parse the section from raw data.
32 /// data is assumed to be pointing to the beginning of the section.
33 void parse(DataExtractor Data);
34
35 private:
36 std::vector> Entries;
37 };
38
39
40 } // namespace llvm
41
42 #endif
+0
-160
include/llvm/DebugInfo/DWARFDebugInfoEntry.h less more
None //===-- DWARFDebugInfoEntry.h -----------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGINFOENTRY_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGINFOENTRY_H
11
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/DebugInfo/DIContext.h"
14 #include "llvm/DebugInfo/DWARFAbbreviationDeclaration.h"
15 #include "llvm/DebugInfo/DWARFDebugRangeList.h"
16 #include "llvm/Support/DataTypes.h"
17
18 namespace llvm {
19
20 class DWARFDebugAranges;
21 class DWARFCompileUnit;
22 class DWARFUnit;
23 class DWARFContext;
24 class DWARFFormValue;
25 struct DWARFDebugInfoEntryInlinedChain;
26
27 /// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
28 class DWARFDebugInfoEntryMinimal {
29 /// Offset within the .debug_info of the start of this entry.
30 uint32_t Offset;
31
32 /// How many to add to "this" to get the sibling.
33 uint32_t SiblingIdx;
34
35 const DWARFAbbreviationDeclaration *AbbrevDecl;
36 public:
37 DWARFDebugInfoEntryMinimal()
38 : Offset(0), SiblingIdx(0), AbbrevDecl(nullptr) {}
39
40 void dump(raw_ostream &OS, DWARFUnit *u, unsigned recurseDepth,
41 unsigned indent = 0) const;
42 void dumpAttribute(raw_ostream &OS, DWARFUnit *u, uint32_t *offset_ptr,
43 uint16_t attr, uint16_t form, unsigned indent = 0) const;
44
45 /// Extracts a debug info entry, which is a child of a given unit,
46 /// starting at a given offset. If DIE can't be extracted, returns false and
47 /// doesn't change OffsetPtr.
48 bool extractFast(const DWARFUnit *U, uint32_t *OffsetPtr);
49
50 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
51 bool isNULL() const { return AbbrevDecl == nullptr; }
52
53 /// Returns true if DIE represents a subprogram (not inlined).
54 bool isSubprogramDIE() const;
55 /// Returns true if DIE represents a subprogram or an inlined
56 /// subroutine.
57 bool isSubroutineDIE() const;
58
59 uint32_t getOffset() const { return Offset; }
60 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
61
62 // We know we are kept in a vector of contiguous entries, so we know
63 // our sibling will be some index after "this".
64 const DWARFDebugInfoEntryMinimal *getSibling() const {
65 return SiblingIdx > 0 ? this + SiblingIdx : nullptr;
66 }
67
68 // We know we are kept in a vector of contiguous entries, so we know
69 // we don't need to store our child pointer, if we have a child it will
70 // be the next entry in the list...
71 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
72 return hasChildren() ? this + 1 : nullptr;
73 }
74
75 void setSibling(const DWARFDebugInfoEntryMinimal *Sibling) {
76 if (Sibling) {
77 // We know we are kept in a vector of contiguous entries, so we know
78 // our sibling will be some index after "this".
79 SiblingIdx = Sibling - this;
80 } else
81 SiblingIdx = 0;
82 }
83
84 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
85 return AbbrevDecl;
86 }
87
88 bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr,
89 DWARFFormValue &FormValue) const;
90
91 const char *getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr,
92 const char *FailValue) const;
93
94 uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr,
95 uint64_t FailValue) const;
96
97 uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U,
98 const uint16_t Attr,
99 uint64_t FailValue) const;
100
101 uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr,
102 uint64_t FailValue) const;
103
104 uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U,
105 const uint16_t Attr,
106 uint64_t FailValue) const;
107
108 uint64_t getRangesBaseAttribute(const DWARFUnit *U, uint64_t FailValue) const;
109
110 /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
111 /// Returns true if both attributes are present.
112 bool getLowAndHighPC(const DWARFUnit *U, uint64_t &LowPC,
113 uint64_t &HighPC) const;
114
115 DWARFAddressRangesVector getAddressRanges(const DWARFUnit *U) const;
116
117 void collectChildrenAddressRanges(const DWARFUnit *U,
118 DWARFAddressRangesVector &Ranges) const;
119
120 bool addressRangeContainsAddress(const DWARFUnit *U,
121 const uint64_t Address) const;
122
123 /// If a DIE represents a subprogram (or inlined subroutine),
124 /// returns its mangled name (or short name, if mangled is missing).
125 /// This name may be fetched from specification or abstract origin
126 /// for this subprogram. Returns null if no name is found.
127 const char *getSubroutineName(const DWARFUnit *U, DINameKind Kind) const;
128
129 /// Return the DIE name resolving DW_AT_sepcification or
130 /// DW_AT_abstract_origin references if necessary.
131 /// Returns null if no name is found.
132 const char *getName(const DWARFUnit *U, DINameKind Kind) const;
133
134 /// Retrieves values of DW_AT_call_file, DW_AT_call_line and
135 /// DW_AT_call_column from DIE (or zeroes if they are missing).
136 void getCallerFrame(const DWARFUnit *U, uint32_t &CallFile,
137 uint32_t &CallLine, uint32_t &CallColumn) const;
138
139 /// Get inlined chain for a given address, rooted at the current DIE.
140 /// Returns empty chain if address is not contained in address range
141 /// of current DIE.
142 DWARFDebugInfoEntryInlinedChain
143 getInlinedChainForAddress(const DWARFUnit *U, const uint64_t Address) const;
144 };
145
146 /// DWARFDebugInfoEntryInlinedChain - represents a chain of inlined_subroutine
147 /// DIEs, (possibly ending with subprogram DIE), all of which are contained
148 /// in some concrete inlined instance tree. Address range for each DIE
149 /// (except the last DIE) in this chain is contained in address
150 /// range for next DIE in the chain.
151 struct DWARFDebugInfoEntryInlinedChain {
152 DWARFDebugInfoEntryInlinedChain() : U(nullptr) {}
153 SmallVector DIEs;
154 const DWARFUnit *U;
155 };
156
157 }
158
159 #endif
+0
-238
include/llvm/DebugInfo/DWARFDebugLine.h less more
None //===-- DWARFDebugLine.h ----------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGLINE_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGLINE_H
11
12 #include "llvm/DebugInfo/DIContext.h"
13 #include "llvm/DebugInfo/DWARFRelocMap.h"
14 #include "llvm/Support/DataExtractor.h"
15 #include
16 #include
17 #include
18
19 namespace llvm {
20
21 class raw_ostream;
22
23 class DWARFDebugLine {
24 public:
25 DWARFDebugLine(const RelocAddrMap* LineInfoRelocMap) : RelocMap(LineInfoRelocMap) {}
26 struct FileNameEntry {
27 FileNameEntry() : Name(nullptr), DirIdx(0), ModTime(0), Length(0) {}
28
29 const char *Name;
30 uint64_t DirIdx;
31 uint64_t ModTime;
32 uint64_t Length;
33 };
34
35 struct Prologue {
36 Prologue();
37
38 // The size in bytes of the statement information for this compilation unit
39 // (not including the total_length field itself).
40 uint32_t TotalLength;
41 // Version identifier for the statement information format.
42 uint16_t Version;
43 // The number of bytes following the prologue_length field to the beginning
44 // of the first byte of the statement program itself.
45 uint32_t PrologueLength;
46 // The size in bytes of the smallest target machine instruction. Statement
47 // program opcodes that alter the address register first multiply their
48 // operands by this value.
49 uint8_t MinInstLength;
50 // The maximum number of individual operations that may be encoded in an
51 // instruction.
52 uint8_t MaxOpsPerInst;
53 // The initial value of theis_stmtregister.
54 uint8_t DefaultIsStmt;
55 // This parameter affects the meaning of the special opcodes. See below.
56 int8_t LineBase;
57 // This parameter affects the meaning of the special opcodes. See below.
58 uint8_t LineRange;
59 // The number assigned to the first special opcode.
60 uint8_t OpcodeBase;
61 std::vector StandardOpcodeLengths;
62 std::vector IncludeDirectories;
63 std::vector FileNames;
64
65 // Length of the prologue in bytes.
66 uint32_t getLength() const {
67 return PrologueLength + sizeof(TotalLength) + sizeof(Version) +
68 sizeof(PrologueLength);
69 }
70 // Length of the line table data in bytes (not including the prologue).
71 uint32_t getStatementTableLength() const {
72 return TotalLength + sizeof(TotalLength) - getLength();
73 }
74 int32_t getMaxLineIncrementForSpecialOpcode() const {
75 return LineBase + (int8_t)LineRange - 1;
76 }
77
78 void clear();
79 void dump(raw_ostream &OS) const;
80 bool parse(DataExtractor debug_line_data, uint32_t *offset_ptr);
81 };
82
83 // Standard .debug_line state machine structure.
84 struct Row {
85 explicit Row(bool default_is_stmt = false);
86
87 /// Called after a row is appended to the matrix.
88 void postAppend();
89 void reset(bool default_is_stmt);
90 void dump(raw_ostream &OS) const;
91
92 static bool orderByAddress(const Row& LHS, const Row& RHS) {
93 return LHS.Address < RHS.Address;
94 }
95
96 // The program-counter value corresponding to a machine instruction
97 // generated by the compiler.
98 uint64_t Address;
99 // An unsigned integer indicating a source line number. Lines are numbered
100 // beginning at 1. The compiler may emit the value 0 in cases where an
101 // instruction cannot be attributed to any source line.
102 uint32_t Line;
103 // An unsigned integer indicating a column number within a source line.
104 // Columns are numbered beginning at 1. The value 0 is reserved to indicate
105 // that a statement begins at the 'left edge' of the line.
106 uint16_t Column;
107 // An unsigned integer indicating the identity of the source file
108 // corresponding to a machine instruction.
109 uint16_t File;
110 // An unsigned integer whose value encodes the applicable instruction set
111 // architecture for the current instruction.
112 uint8_t Isa;
113 // An unsigned integer representing the DWARF path discriminator value
114 // for this location.
115 uint32_t Discriminator;
116 // A boolean indicating that the current instruction is the beginning of a
117 // statement.
118 uint8_t IsStmt:1,
119 // A boolean indicating that the current instruction is the
120 // beginning of a basic block.
121 BasicBlock:1,
122 // A boolean indicating that the current address is that of the
123 // first byte after the end of a sequence of target machine
124 // instructions.
125 EndSequence:1,
126 // A boolean indicating that the current address is one (of possibly
127 // many) where execution should be suspended for an entry breakpoint
128 // of a function.
129 PrologueEnd:1,
130 // A boolean indicating that the current address is one (of possibly
131 // many) where execution should be suspended for an exit breakpoint
132 // of a function.
133 EpilogueBegin:1;
134 };
135
136 // Represents a series of contiguous machine instructions. Line table for each
137 // compilation unit may consist of multiple sequences, which are not
138 // guaranteed to be in the order of ascending instruction address.
139 struct Sequence {
140 // Sequence describes instructions at address range [LowPC, HighPC)
141 // and is described by line table rows [FirstRowIndex, LastRowIndex).
142 uint64_t LowPC;
143 uint64_t HighPC;
144 unsigned FirstRowIndex;
145 unsigned LastRowIndex;
146 bool Empty;
147
148 Sequence();
149 void reset();
150
151 static bool orderByLowPC(const Sequence& LHS, const Sequence& RHS) {
152 return LHS.LowPC < RHS.LowPC;
153 }
154 bool isValid() const {
155 return !Empty && (LowPC < HighPC) && (FirstRowIndex < LastRowIndex);
156 }
157 bool containsPC(uint64_t pc) const {
158 return (LowPC <= pc && pc < HighPC);
159 }
160 };
161
162 struct LineTable {
163 LineTable();
164
165 void appendRow(const DWARFDebugLine::Row &R) {
166 Rows.push_back(R);
167 }
168 void appendSequence(const DWARFDebugLine::Sequence &S) {
169 Sequences.push_back(S);
170 }
171
172 // Returns the index of the row with file/line info for a given address,
173 // or -1 if there is no such row.
174 uint32_t lookupAddress(uint64_t address) const;
175
176 bool lookupAddressRange(uint64_t address, uint64_t size,
177 std::vector &result) const;
178
179 // Extracts filename by its index in filename table in prologue.
180 // Returns true on success.
181 bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir,
182 DILineInfoSpecifier::FileLineInfoKind Kind,
183 std::string &Result) const;
184
185 // Fills the Result argument with the file and line information
186 // corresponding to Address. Returns true on success.
187 bool getFileLineInfoForAddress(uint64_t Address, const char *CompDir,
188 DILineInfoSpecifier::FileLineInfoKind Kind,
189 DILineInfo &Result) const;
190
191 void dump(raw_ostream &OS) const;
192 void clear();
193
194 /// Parse prologue and all rows.
195 bool parse(DataExtractor debug_line_data, const RelocAddrMap *RMap,
196 uint32_t *offset_ptr);
197
198 struct Prologue Prologue;
199 typedef std::vector RowVector;
200 typedef RowVector::const_iterator RowIter;
201 typedef std::vector SequenceVector;
202 typedef SequenceVector::const_iterator SequenceIter;
203 RowVector Rows;
204 SequenceVector Sequences;
205 };
206
207 const LineTable *getLineTable(uint32_t offset) const;
208 const LineTable *getOrParseLineTable(DataExtractor debug_line_data,
209 uint32_t offset);
210
211 private:
212 struct ParsingState {
213 ParsingState(struct LineTable *LT);
214
215 void resetRowAndSequence();
216 void appendRowToMatrix(uint32_t offset);
217
218 // Line table we're currently parsing.
219 struct LineTable *LineTable;
220 // The row number that starts at zero for the prologue, and increases for
221 // each row added to the matrix.
222 unsigned RowNumber;
223 struct Row Row;
224 struct Sequence Sequence;
225 };
226
227 typedef std::map LineTableMapTy;
228 typedef LineTableMapTy::iterator LineTableIter;
229 typedef LineTableMapTy::const_iterator LineTableConstIter;
230
231 const RelocAddrMap *RelocMap;
232 LineTableMapTy LineTableMap;
233 };
234
235 }
236
237 #endif
+0
-81
include/llvm/DebugInfo/DWARFDebugLoc.h less more
None //===-- DWARFDebugLoc.h -----------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGLOC_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGLOC_H
11
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/DebugInfo/DWARFRelocMap.h"
14 #include "llvm/Support/DataExtractor.h"
15
16 namespace llvm {
17
18 class raw_ostream;
19
20 class DWARFDebugLoc {
21 /// A single location within a location list.
22 struct Entry {
23 /// The beginning address of the instruction range.
24 uint64_t Begin;
25 /// The ending address of the instruction range.
26 uint64_t End;
27 /// The location of the variable within the specified range.
28 SmallVector Loc;
29 };
30
31 /// A list of locations that contain one variable.
32 struct LocationList {
33 /// The beginning offset where this location list is stored in the debug_loc
34 /// section.
35 unsigned Offset;
36 /// All the locations in which the variable is stored.
37 SmallVector Entries;
38 };
39
40 typedef SmallVector LocationLists;
41
42 /// A list of all the variables in the debug_loc section, each one describing
43 /// the locations in which the variable is stored.
44 LocationLists Locations;
45
46 /// A map used to resolve binary relocations.
47 const RelocAddrMap &RelocMap;
48
49 public:
50 DWARFDebugLoc(const RelocAddrMap &LocRelocMap) : RelocMap(LocRelocMap) {}
51 /// Print the location lists found within the debug_loc section.
52 void dump(raw_ostream &OS) const;
53 /// Parse the debug_loc section accessible via the 'data' parameter using the
54 /// specified address size to interpret the address ranges.
55 void parse(DataExtractor data, unsigned AddressSize);
56 };
57
58 class DWARFDebugLocDWO {
59 struct Entry {
60 uint64_t Start;
61 uint32_t Length;
62 SmallVector Loc;
63 };
64
65 struct LocationList {
66 unsigned Offset;
67 SmallVector Entries;
68 };
69
70 typedef SmallVector LocationLists;
71
72 LocationLists Locations;
73
74 public:
75 void parse(DataExtractor data);
76 void dump(raw_ostream &OS) const;
77 };
78 }
79
80 #endif
+0
-77
include/llvm/DebugInfo/DWARFDebugRangeList.h less more
None //===-- DWARFDebugRangeList.h -----------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGRANGELIST_H
10 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGRANGELIST_H
11
12 #include "llvm/Support/DataExtractor.h"
13 #include
14
15 namespace llvm {
16
17 class raw_ostream;
18
19 /// DWARFAddressRangesVector - represents a set of absolute address ranges.
20 typedef std::vector> DWARFAddressRangesVector;
21
22 class DWARFDebugRangeList {
23 public:
24 struct RangeListEntry {
25 // A beginning address offset. This address offset has the size of an
26 // address and is relative to the applicable base address of the
27 // compilation unit referencing this range list. It marks the beginning
28 // of an address range.
29 uint64_t StartAddress;
30 // An ending address offset. This address offset again has the size of
31 // an address and is relative to the applicable base address of the
32 // compilation unit referencing this range list. It marks the first
33 // address past the end of the address range. The ending address must
34 // be greater than or equal to the beginning address.
35 uint64_t EndAddress;
36 // The end of any given range list is marked by an end of list entry,
37 // which consists of a 0 for the beginning address offset
38 // and a 0 for the ending address offset.
39 bool isEndOfListEntry() const {
40 return (StartAddress == 0) && (EndAddress == 0);
41 }
42 // A base address selection entry consists of:
43 // 1. The value of the largest representable address offset
44 // (for example, 0xffffffff when the size of an address is 32 bits).
45 // 2. An address, which defines the appropriate base address for
46 // use in interpreting the beginning and ending address offsets of
47 // subsequent entries of the location list.
48 bool isBaseAddressSelectionEntry(uint8_t AddressSize) const {
49 assert(AddressSize == 4 || AddressSize == 8);
50 if (AddressSize == 4)
51 return StartAddress == -1U;
52 else
53 return StartAddress == -1ULL;
54 }
55 };
56
57 private:
58 // Offset in .debug_ranges section.
59 uint32_t Offset;
60 uint8_t AddressSize;
61 std::vector Entries;
62
63 public:
64 DWARFDebugRangeList() { clear(); }
65 void clear();
66 void dump(raw_ostream &OS) const;
67 bool extract(DataExtractor data, uint32_t *offset_ptr);
68 /// getAbsoluteRanges - Returns absolute address ranges defined by this range
69 /// list. Has to be passed base address of the compile unit referencing this
70 /// range list.
71 DWARFAddressRangesVector getAbsoluteRanges(uint64_t BaseAddress) const;
72 };
73
74 } // namespace llvm
75
76 #endif // LLVM_DEBUGINFO_DWARFDEBUGRANGELIST_H
+0
-93
include/llvm/DebugInfo/DWARFFormValue.h less more
None //===-- DWARFFormValue.h ----------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_DEBUGINFO_DWARFFORMVALUE_H
10 #define LLVM_DEBUGINFO_DWARFFORMVALUE_H
11
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/Support/DataExtractor.h"
15
16 namespace llvm {
17
18 class DWARFUnit;
19 class raw_ostream;
20
21 class DWARFFormValue {
22 public:
23 enum FormClass {
24 FC_Unknown,
25 FC_Address,
26 FC_Block,
27 FC_Constant,
28 FC_String,
29 FC_Flag,
30 FC_Reference,
31 FC_Indirect,
32 FC_SectionOffset,
33 FC_Exprloc
34 };
35
36 private:
37 struct ValueType {
38 ValueType() : data(nullptr) {
39 uval = 0;
40 }
41
42 union {
43 uint64_t uval;
44 int64_t sval;
45 const char* cstr;
46 };
47 const uint8_t* data;
48 };
49
50 uint16_t Form; // Form for this value.
51 ValueType Value; // Contains all data for the form.
52
53 public:
54 DWARFFormValue(uint16_t Form = 0) : Form(Form) {}
55 uint16_t getForm() const { return Form; }
56 bool isFormClass(FormClass FC) const;
57
58 void dump(raw_ostream &OS, const DWARFUnit *U) const;
59
60 /// \brief extracts a value in data at offset *offset_ptr.
61 ///
62 /// The passed DWARFUnit is allowed to be nullptr, in which
63 /// case no relocation processing will be performed and some
64 /// kind of forms that depend on Unit information are disallowed.
65 /// \returns wether the extraction succeeded.
66 bool extractValue(DataExtractor data, uint32_t *offset_ptr,
67 const DWARFUnit *u);
68 bool isInlinedCStr() const {
69 return Value.data != nullptr && Value.data == (const uint8_t*)Value.cstr;
70 }
71
72 /// getAsFoo functions below return the extracted value as Foo if only
73 /// DWARFFormValue has form class is suitable for representing Foo.
74 Optional getAsReference(const DWARFUnit *U) const;
75 Optional getAsUnsignedConstant() const;
76 Optional getAsCString(const DWARFUnit *U) const;
77 Optional getAsAddress(const DWARFUnit *U) const;
78 Optional getAsSectionOffset() const;
79 Optional> getAsBlock() const;
80
81 bool skipValue(DataExtractor debug_info_data, uint32_t *offset_ptr,
82 const DWARFUnit *u) const;
83 static bool skipValue(uint16_t form, DataExtractor debug_info_data,
84 uint32_t *offset_ptr, const DWARFUnit *u);
85
86 static ArrayRef getFixedFormSizes(uint8_t AddrSize,
87 uint16_t Version);
88 };
89
90 }
91
92 #endif
+0
-22
include/llvm/DebugInfo/DWARFRelocMap.h less more
None //===-- DWARFRelocMap.h -----------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFRELOCMAP_H
10 #define LLVM_LIB_DEBUGINFO_DWARFRELOCMAP_H
11
12 #include "llvm/ADT/DenseMap.h"
13
14 namespace llvm {
15
16 typedef DenseMap > RelocAddrMap;
17
18 } // namespace llvm
19
20 #endif
21
+0
-24
include/llvm/DebugInfo/DWARFSection.h less more
None //===-- DWARFSection.h ------------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFSECTION_H
10 #define LLVM_LIB_DEBUGINFO_DWARFSECTION_H
11
12 #include "llvm/DebugInfo/DWARFRelocMap.h"
13
14 namespace llvm {
15
16 struct DWARFSection {
17 StringRef Data;
18 RelocAddrMap Relocs;
19 };
20
21 }
22
23 #endif
+0
-38
include/llvm/DebugInfo/DWARFTypeUnit.h less more
None //===-- DWARFTypeUnit.h -----------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFTYPEUNIT_H
10 #define LLVM_LIB_DEBUGINFO_DWARFTYPEUNIT_H
11
12 #include "llvm/DebugInfo/DWARFUnit.h"
13
14 namespace llvm {
15
16 class DWARFTypeUnit : public DWARFUnit {
17 private:
18 uint64_t TypeHash;
19 uint32_t TypeOffset;
20 public:
21 DWARFTypeUnit(DWARFContext &Context, const DWARFSection &Section,
22 const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
23 StringRef SOS, StringRef AOS, bool LE,
24 const DWARFUnitSectionBase &UnitSection)
25 : DWARFUnit(Context, Section, DA, RS, SS, SOS, AOS, LE, UnitSection) {}
26 uint32_t getHeaderSize() const override {
27 return DWARFUnit::getHeaderSize() + 12;
28 }
29 void dump(raw_ostream &OS);
30 protected:
31 bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr) override;
32 };
33
34 }
35
36 #endif
37
+0
-265
include/llvm/DebugInfo/DWARFUnit.h less more
None //===-- DWARFUnit.h ---------------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIB_DEBUGINFO_DWARFUNIT_H
10 #define LLVM_LIB_DEBUGINFO_DWARFUNIT_H
11
12 #include "llvm/DebugInfo/DWARFDebugAbbrev.h"
13 #include "llvm/DebugInfo/DWARFDebugInfoEntry.h"
14 #include "llvm/DebugInfo/DWARFDebugRangeList.h"
15 #include "llvm/DebugInfo/DWARFRelocMap.h"
16 #include "llvm/DebugInfo/DWARFSection.h"
17 #include
18
19 namespace llvm {
20
21 namespace object {
22 class ObjectFile;
23 }
24
25 class DWARFContext;
26 class DWARFDebugAbbrev;
27 class DWARFUnit;
28 class StringRef;
29 class raw_ostream;
30
31 /// Base class for all DWARFUnitSection classes. This provides the
32 /// functionality common to all unit types.
33 class DWARFUnitSectionBase {
34 public:
35 /// Returns the Unit that contains the given section offset in the
36 /// same section this Unit originated from.
37 virtual DWARFUnit *getUnitForOffset(uint32_t Offset) const = 0;
38
39 void parse(DWARFContext &C, const DWARFSection &Section);
40 void parseDWO(DWARFContext &C, const DWARFSection &DWOSection);
41
42 protected:
43 virtual void parseImpl(DWARFContext &Context, const DWARFSection &Section,
44 const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
45 StringRef SOS, StringRef AOS, bool isLittleEndian) = 0;
46
47 ~DWARFUnitSectionBase() {}
48 };
49
50 /// Concrete instance of DWARFUnitSection, specialized for one Unit type.
51 template
52 class DWARFUnitSection final : public SmallVector, 1>,
53 public DWARFUnitSectionBase {
54
55 struct UnitOffsetComparator {
56 bool operator()(uint32_t LHS,
57 const std::unique_ptr &RHS) const {
58 return LHS < RHS->getNextUnitOffset();
59 }
60 };
61
62 bool Parsed;
63
64 public:
65 DWARFUnitSection() : Parsed(false) {}
66 DWARFUnitSection(DWARFUnitSection &&DUS) :
67 SmallVector, 1>(std::move(DUS)), Parsed(DUS.Parsed) {}
68
69 typedef llvm::SmallVectorImpl> UnitVector;
70 typedef typename UnitVector::iterator iterator;
71 typedef llvm::iterator_range iterator_range;
72
73 UnitType *getUnitForOffset(uint32_t Offset) const override {
74 auto *CU = std::upper_bound(this->begin(), this->end(), Offset,
75 UnitOffsetComparator());
76 if (CU != this->end())
77 return CU->get();
78 return nullptr;
79 }
80
81 private:
82 void parseImpl(DWARFContext &Context, const DWARFSection &Section,
83 const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
84 StringRef SOS, StringRef AOS, bool LE) override {
85 if (Parsed)
86 return;
87 DataExtractor Data(Section.Data, LE, 0);
88 uint32_t Offset = 0;
89 while (Data.isValidOffset(Offset)) {
90 auto U = llvm::make_unique(Context, Section, DA, RS, SS, SOS,
91 AOS, LE, *this);
92 if (!U->extract(Data, &Offset))
93 break;
94 this->push_back(std::move(U));
95 Offset = this->back()->getNextUnitOffset();
96 }
97 Parsed = true;
98 }
99 };
100
101 class DWARFUnit {
102 DWARFContext &Context;
103 // Section containing this DWARFUnit.
104 const DWARFSection &InfoSection;
105
106 const DWARFDebugAbbrev *Abbrev;
107 StringRef RangeSection;
108 uint32_t RangeSectionBase;
109 StringRef StringSection;
110 StringRef StringOffsetSection;
111 StringRef AddrOffsetSection;
112 uint32_t AddrOffsetSectionBase;
113 bool isLittleEndian;
114 const DWARFUnitSectionBase &UnitSection;
115
116 uint32_t Offset;
117 uint32_t Length;
118 uint16_t Version;
119 const DWARFAbbreviationDeclarationSet *Abbrevs;
120 uint8_t AddrSize;
121 uint64_t BaseAddr;
122 // The compile unit debug information entry items.
123 std::vector DieArray;
124
125 class DWOHolder {
126 object::OwningBinary DWOFile;
127 std::unique_ptr DWOContext;
128 DWARFUnit *DWOU;
129 public:
130 DWOHolder(StringRef DWOPath);
131