Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 6187547

Browse files
committed
[DWARFFormValue] Cleanup DWARFFormValue interface. (NFC)
DWARFFormValues can be created from a data extractor or by passing its value directly. Until now this was done by member functions that modified an existing object's internal state. This patch replaces a subset of these methods with static method that return a new DWARFFormValue. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354941 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6596fa3 commit 6187547

File tree

7 files changed

+168
-147
lines changed

7 files changed

+168
-147
lines changed

include/llvm/DebugInfo/DWARF/DWARFFormValue.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class DWARFFormValue {
4141
private:
4242
struct ValueType {
4343
ValueType() { uval = 0; }
44+
ValueType(int64_t V) : sval(V) {}
45+
ValueType(uint64_t V) : uval(V) {}
46+
ValueType(const char *V) : cstr(V) {}
4447

4548
union {
4649
uint64_t uval;
@@ -55,20 +58,22 @@ class DWARFFormValue {
5558
ValueType Value; /// Contains all data for the form.
5659
const DWARFUnit *U = nullptr; /// Remember the DWARFUnit at extract time.
5760
const DWARFContext *C = nullptr; /// Context for extract time.
61+
62+
DWARFFormValue(dwarf::Form F, ValueType V) : Form(F), Value(V) {}
63+
5864
public:
5965
DWARFFormValue(dwarf::Form F = dwarf::Form(0)) : Form(F) {}
6066

67+
static DWARFFormValue createFromSValue(dwarf::Form F, int64_t V);
68+
static DWARFFormValue createFromUValue(dwarf::Form F, uint64_t V);
69+
static DWARFFormValue createFromPValue(dwarf::Form F, const char *V);
70+
static DWARFFormValue createFromBlockValue(dwarf::Form F,
71+
ArrayRef<uint8_t> D);
72+
static DWARFFormValue createFromUnit(dwarf::Form F, const DWARFUnit *Unit,
73+
uint32_t *OffsetPtr);
74+
6175
dwarf::Form getForm() const { return Form; }
6276
uint64_t getRawUValue() const { return Value.uval; }
63-
void setForm(dwarf::Form F) { Form = F; }
64-
void setUValue(uint64_t V) { Value.uval = V; }
65-
void setSValue(int64_t V) { Value.sval = V; }
66-
void setPValue(const char *V) { Value.cstr = V; }
67-
68-
void setBlockValue(const ArrayRef<uint8_t> &Data) {
69-
Value.data = Data.data();
70-
setUValue(Data.size());
71-
}
7277

7378
bool isFormClass(FormClass FC) const;
7479
const DWARFUnit *getUnit() const { return U; }

lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ Optional<DWARFFormValue> DWARFAbbreviationDeclaration::getAttributeValue(
163163
for (const auto &Spec : AttributeSpecs) {
164164
if (*MatchAttrIndex == AttrIndex) {
165165
// We have arrived at the attribute to extract, extract if from Offset.
166+
if (Spec.isImplicitConst())
167+
return DWARFFormValue::createFromSValue(Spec.Form,
168+
Spec.getImplicitConstValue());
169+
166170
DWARFFormValue FormValue(Spec.Form);
167-
if (Spec.isImplicitConst()) {
168-
FormValue.setSValue(Spec.getImplicitConstValue());
169-
return FormValue;
170-
}
171171
if (FormValue.extractValue(DebugInfoData, &Offset, U.getFormParams(), &U))
172172
return FormValue;
173173
}

lib/DebugInfo/DWARF/DWARFDebugLine.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ parseV2DirFileTables(const DWARFDataExtractor &DebugLineData,
144144
StringRef S = DebugLineData.getCStrRef(OffsetPtr);
145145
if (S.empty())
146146
break;
147-
DWARFFormValue Dir(dwarf::DW_FORM_string);
148-
Dir.setPValue(S.data());
147+
DWARFFormValue Dir =
148+
DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, S.data());
149149
IncludeDirectories.push_back(Dir);
150150
}
151151

@@ -154,8 +154,8 @@ parseV2DirFileTables(const DWARFDataExtractor &DebugLineData,
154154
if (Name.empty())
155155
break;
156156
DWARFDebugLine::FileNameEntry FileEntry;
157-
FileEntry.Name.setForm(dwarf::DW_FORM_string);
158-
FileEntry.Name.setPValue(Name.data());
157+
FileEntry.Name =
158+
DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, Name.data());
159159
FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);
160160
FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);
161161
FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);
@@ -594,8 +594,8 @@ Error DWARFDebugLine::LineTable::parse(
594594
{
595595
FileNameEntry FileEntry;
596596
const char *Name = DebugLineData.getCStr(OffsetPtr);
597-
FileEntry.Name.setForm(dwarf::DW_FORM_string);
598-
FileEntry.Name.setPValue(Name);
597+
FileEntry.Name =
598+
DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, Name);
599599
FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);
600600
FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);
601601
FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);

lib/DebugInfo/DWARF/DWARFDie.cpp

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,7 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
278278
OS << formatv(" [{0}]", Form);
279279

280280
DWARFUnit *U = Die.getDwarfUnit();
281-
DWARFFormValue formValue(Form);
282-
283-
if (!formValue.extractValue(U->getDebugInfoExtractor(), OffsetPtr,
284-
U->getFormParams(), U))
285-
return;
281+
DWARFFormValue FormValue = DWARFFormValue::createFromUnit(Form, U, OffsetPtr);
286282

287283
OS << "\t(";
288284

@@ -293,35 +289,35 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
293289
Color = HighlightColor::String;
294290
if (const auto *LT = U->getContext().getLineTableForUnit(U))
295291
if (LT->getFileNameByIndex(
296-
formValue.getAsUnsignedConstant().getValue(),
292+
FormValue.getAsUnsignedConstant().getValue(),
297293
U->getCompilationDir(),
298294
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, File)) {
299295
File = '"' + File + '"';
300296
Name = File;
301297
}
302-
} else if (Optional<uint64_t> Val = formValue.getAsUnsignedConstant())
298+
} else if (Optional<uint64_t> Val = FormValue.getAsUnsignedConstant())
303299
Name = AttributeValueString(Attr, *Val);
304300

305301
if (!Name.empty())
306302
WithColor(OS, Color) << Name;
307303
else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line)
308-
OS << *formValue.getAsUnsignedConstant();
304+
OS << *FormValue.getAsUnsignedConstant();
309305
else if (Attr == DW_AT_high_pc && !DumpOpts.ShowForm && !DumpOpts.Verbose &&
310-
formValue.getAsUnsignedConstant()) {
306+
FormValue.getAsUnsignedConstant()) {
311307
if (DumpOpts.ShowAddresses) {
312308
// Print the actual address rather than the offset.
313309
uint64_t LowPC, HighPC, Index;
314310
if (Die.getLowAndHighPC(LowPC, HighPC, Index))
315311
OS << format("0x%016" PRIx64, HighPC);
316312
else
317-
formValue.dump(OS, DumpOpts);
313+
FormValue.dump(OS, DumpOpts);
318314
}
319315
} else if (Attr == DW_AT_location || Attr == DW_AT_frame_base ||
320316
Attr == DW_AT_data_member_location ||
321317
Attr == DW_AT_GNU_call_site_value)
322-
dumpLocation(OS, formValue, U, sizeof(BaseIndent) + Indent + 4, DumpOpts);
318+
dumpLocation(OS, FormValue, U, sizeof(BaseIndent) + Indent + 4, DumpOpts);
323319
else
324-
formValue.dump(OS, DumpOpts);
320+
FormValue.dump(OS, DumpOpts);
325321

326322
std::string Space = DumpOpts.ShowAddresses ? " " : "";
327323

@@ -330,25 +326,25 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
330326
// interesting. These attributes are handled below.
331327
if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) {
332328
if (const char *Name =
333-
Die.getAttributeValueAsReferencedDie(formValue).getName(
329+
Die.getAttributeValueAsReferencedDie(FormValue).getName(
334330
DINameKind::LinkageName))
335331
OS << Space << "\"" << Name << '\"';
336332
} else if (Attr == DW_AT_type) {
337333
OS << Space << "\"";
338-
dumpTypeName(OS, Die.getAttributeValueAsReferencedDie(formValue));
334+
dumpTypeName(OS, Die.getAttributeValueAsReferencedDie(FormValue));
339335
OS << '"';
340336
} else if (Attr == DW_AT_APPLE_property_attribute) {
341-
if (Optional<uint64_t> OptVal = formValue.getAsUnsignedConstant())
337+
if (Optional<uint64_t> OptVal = FormValue.getAsUnsignedConstant())
342338
dumpApplePropertyAttribute(OS, *OptVal);
343339
} else if (Attr == DW_AT_ranges) {
344340
const DWARFObject &Obj = Die.getDwarfUnit()->getContext().getDWARFObj();
345341
// For DW_FORM_rnglistx we need to dump the offset separately, since
346342
// we have only dumped the index so far.
347-
if (formValue.getForm() == DW_FORM_rnglistx)
343+
if (FormValue.getForm() == DW_FORM_rnglistx)
348344
if (auto RangeListOffset =
349-
U->getRnglistOffset(*formValue.getAsSectionOffset())) {
350-
DWARFFormValue FV(dwarf::DW_FORM_sec_offset);
351-
FV.setUValue(*RangeListOffset);
345+
U->getRnglistOffset(*FormValue.getAsSectionOffset())) {
346+
DWARFFormValue FV = DWARFFormValue::createFromUValue(
347+
dwarf::DW_FORM_sec_offset, *RangeListOffset);
352348
FV.dump(OS, DumpOpts);
353349
}
354350
if (auto RangesOrError = Die.getAddressRanges())
@@ -689,14 +685,11 @@ void DWARFDie::attribute_iterator::updateForIndex(
689685
AttrValue.Attr = AbbrDecl.getAttrByIndex(Index);
690686
// Add the previous byte size of any previous attribute value.
691687
AttrValue.Offset += AttrValue.ByteSize;
692-
AttrValue.Value.setForm(AbbrDecl.getFormByIndex(Index));
693688
uint32_t ParseOffset = AttrValue.Offset;
694689
auto U = Die.getDwarfUnit();
695690
assert(U && "Die must have valid DWARF unit");
696-
bool b = AttrValue.Value.extractValue(U->getDebugInfoExtractor(),
697-
&ParseOffset, U->getFormParams(), U);
698-
(void)b;
699-
assert(b && "extractValue cannot fail on fully parsed DWARF");
691+
AttrValue.Value = DWARFFormValue::createFromUnit(
692+
AbbrDecl.getFormByIndex(Index), U, &ParseOffset);
700693
AttrValue.ByteSize = ParseOffset - AttrValue.Offset;
701694
} else {
702695
assert(Index == NumAttrs && "Indexes should be [0, NumAttrs) only");

lib/DebugInfo/DWARF/DWARFFormValue.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,34 @@ static const DWARFFormValue::FormClass DWARF5FormClasses[] = {
7777

7878
};
7979

80+
DWARFFormValue DWARFFormValue::createFromSValue(dwarf::Form F, int64_t V) {
81+
return DWARFFormValue(F, ValueType(V));
82+
}
83+
84+
DWARFFormValue DWARFFormValue::createFromUValue(dwarf::Form F, uint64_t V) {
85+
return DWARFFormValue(F, ValueType(V));
86+
}
87+
88+
DWARFFormValue DWARFFormValue::createFromPValue(dwarf::Form F, const char *V) {
89+
return DWARFFormValue(F, ValueType(V));
90+
}
91+
92+
DWARFFormValue DWARFFormValue::createFromBlockValue(dwarf::Form F,
93+
ArrayRef<uint8_t> D) {
94+
ValueType V;
95+
V.uval = D.size();
96+
V.data = D.data();
97+
return DWARFFormValue(F, V);
98+
}
99+
100+
DWARFFormValue DWARFFormValue::createFromUnit(dwarf::Form F, const DWARFUnit *U,
101+
uint32_t *OffsetPtr) {
102+
DWARFFormValue FormValue(F);
103+
FormValue.extractValue(U->getDebugInfoExtractor(), OffsetPtr,
104+
U->getFormParams(), U);
105+
return FormValue;
106+
}
107+
80108
bool DWARFFormValue::skipValue(dwarf::Form Form, DataExtractor DebugInfoData,
81109
uint32_t *OffsetPtr,
82110
const dwarf::FormParams Params) {

0 commit comments

Comments
 (0)