LLVM: lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
10
18#include
19#include
20
21using namespace llvm;
22using namespace dwarf;
23
24void DWARFAbbreviationDeclaration::clear() {
25 Code = 0;
26 Tag = DW_TAG_null;
27 CodeByteSize = 0;
28 HasChildren = false;
29 AttributeSpecs.clear();
30 FixedAttributeSize.reset();
31}
32
36
39 clear();
42 Code = Data.getULEB128(OffsetPtr, &Err);
43 if (Err)
44 return std::move(Err);
45
46 if (Code == 0)
48
49 CodeByteSize = *OffsetPtr - Offset;
51 if (Err)
52 return std::move(Err);
53
54 if (Tag == DW_TAG_null) {
55 clear();
57 "abbreviation declaration requires a non-null tag");
58 }
59 uint8_t ChildrenByte = Data.getU8(OffsetPtr, &Err);
60 if (Err)
61 return std::move(Err);
62
64
65
66
67 FixedAttributeSize = FixedSizeInfo();
68
69
70 while (Data.isValidOffset(*OffsetPtr)) {
71 auto A = static_cast<Attribute>(Data.getULEB128(OffsetPtr, &Err));
72 if (Err)
73 return std::move(Err);
74
75 auto F = static_cast<Form>(Data.getULEB128(OffsetPtr, &Err));
76 if (Err)
77 return std::move(Err);
78
79
80
81
82 if ( &&
)
84
85 if ( ||
) {
86
87
88
89
90 clear();
92 "malformed abbreviation declaration attribute. Either the attribute "
93 "or the form is zero while the other is not");
94 }
95
96 bool IsImplicitConst = (F == DW_FORM_implicit_const);
97 if (IsImplicitConst) {
98 int64_t V = Data.getSLEB128(OffsetPtr);
100 continue;
101 }
102 std::optional<uint8_t> ByteSize;
103
104
105 switch (F) {
106 case DW_FORM_addr:
107 if (FixedAttributeSize)
108 ++FixedAttributeSize->NumAddrs;
109 break;
110
111 case DW_FORM_ref_addr:
112 if (FixedAttributeSize)
113 ++FixedAttributeSize->NumRefAddrs;
114 break;
115
116 case DW_FORM_strp:
117 case DW_FORM_GNU_ref_alt:
118 case DW_FORM_GNU_strp_alt:
119 case DW_FORM_line_strp:
120 case DW_FORM_sec_offset:
121 case DW_FORM_strp_sup:
122 if (FixedAttributeSize)
123 ++FixedAttributeSize->NumDwarfOffsets;
124 break;
125
126 default:
127
128
130 if (FixedAttributeSize)
131 FixedAttributeSize->NumBytes += *ByteSize;
132 break;
133 }
134
135
136
137 FixedAttributeSize.reset();
138 break;
139 }
140
142 }
144 "abbreviation declaration attribute list was not terminated with a null "
145 "entry");
146}
147
149 OS << '[' << getCode() << "] ";
151 OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n';
154 if (Spec.isImplicitConst())
155 OS << '\t' << Spec.getImplicitConstValue();
156 OS << '\n';
157 }
158 OS << '\n';
159}
160
161std::optional<uint32_t>
163 for (uint32_t i = 0, e = AttributeSpecs.size(); i != e; ++i) {
164 if (AttributeSpecs[i].Attr == Attr)
165 return i;
166 }
167 return std::nullopt;
168}
169
173
174
175
177 for (uint32_t CurAttrIdx = 0; CurAttrIdx != AttrIndex; ++CurAttrIdx)
178
179 if (auto FixedSize = AttributeSpecs[CurAttrIdx].getByteSize(U))
180 Offset += *FixedSize;
181 else
183 &Offset, U.getFormParams());
185}
186
187std::optional
190 assert(AttributeSpecs.size() > AttrIndex &&
191 "Attribute Index is out of bounds.");
192
193
195 if (Spec.isImplicitConst())
197 Spec.getImplicitConstValue());
198
201 if (FormValue.extractValue(DebugInfoData, &Offset, U.getFormParams(), &U))
202 return FormValue;
203 return std::nullopt;
204}
205
206std::optional
210
211
213 if (!MatchAttrIndex)
214 return std::nullopt;
215
217
219}
220
221size_t DWARFAbbreviationDeclaration::FixedSizeInfo::getByteSize(
223 size_t ByteSize = NumBytes;
224 if (NumAddrs)
225 ByteSize += NumAddrs * U.getAddressByteSize();
226 if (NumRefAddrs)
227 ByteSize += NumRefAddrs * U.getRefAddrByteSize();
228 if (NumDwarfOffsets)
229 ByteSize += NumDwarfOffsets * U.getDwarfOffsetByteSize();
230 return ByteSize;
231}
232
236 return 0;
239 std::optional<int64_t> S;
241 if (FixedByteSize)
242 S = *FixedByteSize;
243 return S;
244}
245
248 if (FixedAttributeSize)
249 return FixedAttributeSize->getByteSize(U);
250 return std::nullopt;
251}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains constants used for implementing Dwarf debug support.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
LLVM_ABI llvm::Expected< ExtractState > extract(DataExtractor Data, uint64_t *OffsetPtr)
Definition DWARFAbbreviationDeclaration.cpp:38
LLVM_ABI uint64_t getAttributeOffsetFromIndex(uint32_t AttrIndex, uint64_t DIEOffset, const DWARFUnit &U) const
Compute an offset from a DIE specified by DIE offset and attribute index.
Definition DWARFAbbreviationDeclaration.cpp:170
dwarf::Tag getTag() const
LLVM_ABI std::optional< uint32_t > findAttributeIndex(dwarf::Attribute attr) const
Get the index of the specified attribute.
Definition DWARFAbbreviationDeclaration.cpp:162
LLVM_ABI std::optional< DWARFFormValue > getAttributeValue(const uint64_t DIEOffset, const dwarf::Attribute Attr, const DWARFUnit &U) const
Extract a DWARF form value from a DIE specified by DIE offset.
Definition DWARFAbbreviationDeclaration.cpp:207
LLVM_ABI std::optional< size_t > getFixedAttributesByteSize(const DWARFUnit &U) const
Definition DWARFAbbreviationDeclaration.cpp:246
LLVM_ABI void dump(raw_ostream &OS) const
Definition DWARFAbbreviationDeclaration.cpp:148
LLVM_ABI std::optional< DWARFFormValue > getAttributeValueFromOffset(uint32_t AttrIndex, uint64_t Offset, const DWARFUnit &U) const
Extract a DWARF form value from a DIE speccified by attribute index and its offset.
Definition DWARFAbbreviationDeclaration.cpp:188
LLVM_ABI DWARFAbbreviationDeclaration()
Definition DWARFAbbreviationDeclaration.cpp:33
LLVM_ABI bool extractValue(const DWARFDataExtractor &Data, uint64_t *OffsetPtr, dwarf::FormParams FormParams, const DWARFContext *Context=nullptr, const DWARFUnit *Unit=nullptr)
Extracts a value in Data at offset *OffsetPtr.
static LLVM_ABI DWARFFormValue createFromSValue(dwarf::Form F, int64_t V)
bool skipValue(DataExtractor DebugInfoData, uint64_t *OffsetPtr, const dwarf::FormParams Params) const
Skip a form's value in DebugInfoData at the offset specified by OffsetPtr.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
This class implements an extremely fast bulk output stream that can only output to a stream.
Calculates the starting offsets for various sections within the .debug_names section.
LLVM_ABI std::optional< uint8_t > getFixedFormByteSize(dwarf::Form Form, FormParams Params)
Get the fixed byte size for a given form.
This is an optimization pass for GlobalISel generic memory operations.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
LLVM_ABI std::optional< int64_t > getByteSize(const DWARFUnit &U) const
Get the fixed byte size of this Form if possible.
Definition DWARFAbbreviationDeclaration.cpp:233
bool isImplicitConst() const
A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...