llvm.org GIT mirror llvm / 6187547
[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 Jonas Devlieghere 7 months ago
7 changed file(s) with 168 addition(s) and 147 deletion(s). Raw diff Collapse all Expand all
4040 private:
4141 struct ValueType {
4242 ValueType() { uval = 0; }
43 ValueType(int64_t V) : sval(V) {}
44 ValueType(uint64_t V) : uval(V) {}
45 ValueType(const char *V) : cstr(V) {}
4346
4447 union {
4548 uint64_t uval;
5457 ValueType Value; /// Contains all data for the form.
5558 const DWARFUnit *U = nullptr; /// Remember the DWARFUnit at extract time.
5659 const DWARFContext *C = nullptr; /// Context for extract time.
60
61 DWARFFormValue(dwarf::Form F, ValueType V) : Form(F), Value(V) {}
62
5763 public:
5864 DWARFFormValue(dwarf::Form F = dwarf::Form(0)) : Form(F) {}
5965
66 static DWARFFormValue createFromSValue(dwarf::Form F, int64_t V);
67 static DWARFFormValue createFromUValue(dwarf::Form F, uint64_t V);
68 static DWARFFormValue createFromPValue(dwarf::Form F, const char *V);
69 static DWARFFormValue createFromBlockValue(dwarf::Form F,
70 ArrayRef D);
71 static DWARFFormValue createFromUnit(dwarf::Form F, const DWARFUnit *Unit,
72 uint32_t *OffsetPtr);
73
6074 dwarf::Form getForm() const { return Form; }
6175 uint64_t getRawUValue() const { return Value.uval; }
62 void setForm(dwarf::Form F) { Form = F; }
63 void setUValue(uint64_t V) { Value.uval = V; }
64 void setSValue(int64_t V) { Value.sval = V; }
65 void setPValue(const char *V) { Value.cstr = V; }
66
67 void setBlockValue(const ArrayRef &Data) {
68 Value.data = Data.data();
69 setUValue(Data.size());
70 }
7176
7277 bool isFormClass(FormClass FC) const;
7378 const DWARFUnit *getUnit() const { return U; }
162162 for (const auto &Spec : AttributeSpecs) {
163163 if (*MatchAttrIndex == AttrIndex) {
164164 // We have arrived at the attribute to extract, extract if from Offset.
165 if (Spec.isImplicitConst())
166 return DWARFFormValue::createFromSValue(Spec.Form,
167 Spec.getImplicitConstValue());
168
165169 DWARFFormValue FormValue(Spec.Form);
166 if (Spec.isImplicitConst()) {
167 FormValue.setSValue(Spec.getImplicitConstValue());
168 return FormValue;
169 }
170170 if (FormValue.extractValue(DebugInfoData, &Offset, U.getFormParams(), &U))
171171 return FormValue;
172172 }
143143 StringRef S = DebugLineData.getCStrRef(OffsetPtr);
144144 if (S.empty())
145145 break;
146 DWARFFormValue Dir(dwarf::DW_FORM_string);
147 Dir.setPValue(S.data());
146 DWARFFormValue Dir =
147 DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, S.data());
148148 IncludeDirectories.push_back(Dir);
149149 }
150150
153153 if (Name.empty())
154154 break;
155155 DWARFDebugLine::FileNameEntry FileEntry;
156 FileEntry.Name.setForm(dwarf::DW_FORM_string);
157 FileEntry.Name.setPValue(Name.data());
156 FileEntry.Name =
157 DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, Name.data());
158158 FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);
159159 FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);
160160 FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);
593593 {
594594 FileNameEntry FileEntry;
595595 const char *Name = DebugLineData.getCStr(OffsetPtr);
596 FileEntry.Name.setForm(dwarf::DW_FORM_string);
597 FileEntry.Name.setPValue(Name);
596 FileEntry.Name =
597 DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, Name);
598598 FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);
599599 FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);
600600 FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);
277277 OS << formatv(" [{0}]", Form);
278278
279279 DWARFUnit *U = Die.getDwarfUnit();
280 DWARFFormValue formValue(Form);
281
282 if (!formValue.extractValue(U->getDebugInfoExtractor(), OffsetPtr,
283 U->getFormParams(), U))
284 return;
280 DWARFFormValue FormValue = DWARFFormValue::createFromUnit(Form, U, OffsetPtr);
285281
286282 OS << "\t(";
287283
292288 Color = HighlightColor::String;
293289 if (const auto *LT = U->getContext().getLineTableForUnit(U))
294290 if (LT->getFileNameByIndex(
295 formValue.getAsUnsignedConstant().getValue(),
291 FormValue.getAsUnsignedConstant().getValue(),
296292 U->getCompilationDir(),
297293 DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, File)) {
298294 File = '"' + File + '"';
299295 Name = File;
300296 }
301 } else if (Optional Val = formValue.getAsUnsignedConstant())
297 } else if (Optional Val = FormValue.getAsUnsignedConstant())
302298 Name = AttributeValueString(Attr, *Val);
303299
304300 if (!Name.empty())
305301 WithColor(OS, Color) << Name;
306302 else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line)
307 OS << *formValue.getAsUnsignedConstant();
303 OS << *FormValue.getAsUnsignedConstant();
308304 else if (Attr == DW_AT_high_pc && !DumpOpts.ShowForm && !DumpOpts.Verbose &&
309 formValue.getAsUnsignedConstant()) {
305 FormValue.getAsUnsignedConstant()) {
310306 if (DumpOpts.ShowAddresses) {
311307 // Print the actual address rather than the offset.
312308 uint64_t LowPC, HighPC, Index;
313309 if (Die.getLowAndHighPC(LowPC, HighPC, Index))
314310 OS << format("0x%016" PRIx64, HighPC);
315311 else
316 formValue.dump(OS, DumpOpts);
312 FormValue.dump(OS, DumpOpts);
317313 }
318314 } else if (Attr == DW_AT_location || Attr == DW_AT_frame_base ||
319315 Attr == DW_AT_data_member_location ||
320316 Attr == DW_AT_GNU_call_site_value)
321 dumpLocation(OS, formValue, U, sizeof(BaseIndent) + Indent + 4, DumpOpts);
317 dumpLocation(OS, FormValue, U, sizeof(BaseIndent) + Indent + 4, DumpOpts);
322318 else
323 formValue.dump(OS, DumpOpts);
319 FormValue.dump(OS, DumpOpts);
324320
325321 std::string Space = DumpOpts.ShowAddresses ? " " : "";
326322
329325 // interesting. These attributes are handled below.
330326 if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) {
331327 if (const char *Name =
332 Die.getAttributeValueAsReferencedDie(formValue).getName(
328 Die.getAttributeValueAsReferencedDie(FormValue).getName(
333329 DINameKind::LinkageName))
334330 OS << Space << "\"" << Name << '\"';
335331 } else if (Attr == DW_AT_type) {
336332 OS << Space << "\"";
337 dumpTypeName(OS, Die.getAttributeValueAsReferencedDie(formValue));
333 dumpTypeName(OS, Die.getAttributeValueAsReferencedDie(FormValue));
338334 OS << '"';
339335 } else if (Attr == DW_AT_APPLE_property_attribute) {
340 if (Optional OptVal = formValue.getAsUnsignedConstant())
336 if (Optional OptVal = FormValue.getAsUnsignedConstant())
341337 dumpApplePropertyAttribute(OS, *OptVal);
342338 } else if (Attr == DW_AT_ranges) {
343339 const DWARFObject &Obj = Die.getDwarfUnit()->getContext().getDWARFObj();
344340 // For DW_FORM_rnglistx we need to dump the offset separately, since
345341 // we have only dumped the index so far.
346 if (formValue.getForm() == DW_FORM_rnglistx)
342 if (FormValue.getForm() == DW_FORM_rnglistx)
347343 if (auto RangeListOffset =
348 U->getRnglistOffset(*formValue.getAsSectionOffset())) {
349 DWARFFormValue FV(dwarf::DW_FORM_sec_offset);
350 FV.setUValue(*RangeListOffset);
344 U->getRnglistOffset(*FormValue.getAsSectionOffset())) {
345 DWARFFormValue FV = DWARFFormValue::createFromUValue(
346 dwarf::DW_FORM_sec_offset, *RangeListOffset);
351347 FV.dump(OS, DumpOpts);
352348 }
353349 if (auto RangesOrError = Die.getAddressRanges())
688684 AttrValue.Attr = AbbrDecl.getAttrByIndex(Index);
689685 // Add the previous byte size of any previous attribute value.
690686 AttrValue.Offset += AttrValue.ByteSize;
691 AttrValue.Value.setForm(AbbrDecl.getFormByIndex(Index));
692687 uint32_t ParseOffset = AttrValue.Offset;
693688 auto U = Die.getDwarfUnit();
694689 assert(U && "Die must have valid DWARF unit");
695 bool b = AttrValue.Value.extractValue(U->getDebugInfoExtractor(),
696 &ParseOffset, U->getFormParams(), U);
697 (void)b;
698 assert(b && "extractValue cannot fail on fully parsed DWARF");
690 AttrValue.Value = DWARFFormValue::createFromUnit(
691 AbbrDecl.getFormByIndex(Index), U, &ParseOffset);
699692 AttrValue.ByteSize = ParseOffset - AttrValue.Offset;
700693 } else {
701694 assert(Index == NumAttrs && "Indexes should be [0, NumAttrs) only");
7676
7777 };
7878
79 DWARFFormValue DWARFFormValue::createFromSValue(dwarf::Form F, int64_t V) {
80 return DWARFFormValue(F, ValueType(V));
81 }
82
83 DWARFFormValue DWARFFormValue::createFromUValue(dwarf::Form F, uint64_t V) {
84 return DWARFFormValue(F, ValueType(V));
85 }
86
87 DWARFFormValue DWARFFormValue::createFromPValue(dwarf::Form F, const char *V) {
88 return DWARFFormValue(F, ValueType(V));
89 }
90
91 DWARFFormValue DWARFFormValue::createFromBlockValue(dwarf::Form F,
92 ArrayRef D) {
93 ValueType V;
94 V.uval = D.size();
95 V.data = D.data();
96 return DWARFFormValue(F, V);
97 }
98
99 DWARFFormValue DWARFFormValue::createFromUnit(dwarf::Form F, const DWARFUnit *U,
100 uint32_t *OffsetPtr) {
101 DWARFFormValue FormValue(F);
102 FormValue.extractValue(U->getDebugInfoExtractor(), OffsetPtr,
103 U->getFormParams(), U);
104 return FormValue;
105 }
106
79107 bool DWARFFormValue::skipValue(dwarf::Form Form, DataExtractor DebugInfoData,
80108 uint32_t *OffsetPtr,
81109 const dwarf::FormParams Params) {
15541554 TEST(DWARFDebugInfo, TestDwarfToFunctions) {
15551555 // Test all of the dwarf::toXXX functions that take a
15561556 // Optional and extract the values from it.
1557 DWARFFormValue FormVal;
15581557 uint64_t InvalidU64 = 0xBADBADBADBADBADB;
15591558 int64_t InvalidS64 = 0xBADBADBADBADBADB;
1559
15601560 // First test that we don't get valid values back when using an optional with
15611561 // no value.
1562 Optional FormValOpt;
1563 EXPECT_FALSE(toString(FormValOpt).hasValue());
1564 EXPECT_FALSE(toUnsigned(FormValOpt).hasValue());
1565 EXPECT_FALSE(toReference(FormValOpt).hasValue());
1566 EXPECT_FALSE(toSigned(FormValOpt).hasValue());
1567 EXPECT_FALSE(toAddress(FormValOpt).hasValue());
1568 EXPECT_FALSE(toSectionOffset(FormValOpt).hasValue());
1569 EXPECT_FALSE(toBlock(FormValOpt).hasValue());
1570 EXPECT_EQ(nullptr, toString(FormValOpt, nullptr));
1571 EXPECT_EQ(InvalidU64, toUnsigned(FormValOpt, InvalidU64));
1572 EXPECT_EQ(InvalidU64, toReference(FormValOpt, InvalidU64));
1573 EXPECT_EQ(InvalidU64, toAddress(FormValOpt, InvalidU64));
1574 EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt, InvalidU64));
1575 EXPECT_EQ(InvalidS64, toSigned(FormValOpt, InvalidS64));
1562 Optional FormValOpt1 = DWARFFormValue();
1563 EXPECT_FALSE(toString(FormValOpt1).hasValue());
1564 EXPECT_FALSE(toUnsigned(FormValOpt1).hasValue());
1565 EXPECT_FALSE(toReference(FormValOpt1).hasValue());
1566 EXPECT_FALSE(toSigned(FormValOpt1).hasValue());
1567 EXPECT_FALSE(toAddress(FormValOpt1).hasValue());
1568 EXPECT_FALSE(toSectionOffset(FormValOpt1).hasValue());
1569 EXPECT_FALSE(toBlock(FormValOpt1).hasValue());
1570 EXPECT_EQ(nullptr, toString(FormValOpt1, nullptr));
1571 EXPECT_EQ(InvalidU64, toUnsigned(FormValOpt1, InvalidU64));
1572 EXPECT_EQ(InvalidU64, toReference(FormValOpt1, InvalidU64));
1573 EXPECT_EQ(InvalidU64, toAddress(FormValOpt1, InvalidU64));
1574 EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt1, InvalidU64));
1575 EXPECT_EQ(InvalidS64, toSigned(FormValOpt1, InvalidS64));
15761576
15771577 // Test successful and unsuccessful address decoding.
15781578 uint64_t Address = 0x100000000ULL;
1579 FormVal.setForm(DW_FORM_addr);
1580 FormVal.setUValue(Address);
1581 FormValOpt = FormVal;
1582
1583 EXPECT_FALSE(toString(FormValOpt).hasValue());
1584 EXPECT_FALSE(toUnsigned(FormValOpt).hasValue());
1585 EXPECT_FALSE(toReference(FormValOpt).hasValue());
1586 EXPECT_FALSE(toSigned(FormValOpt).hasValue());
1587 EXPECT_TRUE(toAddress(FormValOpt).hasValue());
1588 EXPECT_FALSE(toSectionOffset(FormValOpt).hasValue());
1589 EXPECT_FALSE(toBlock(FormValOpt).hasValue());
1590 EXPECT_EQ(nullptr, toString(FormValOpt, nullptr));
1591 EXPECT_EQ(InvalidU64, toUnsigned(FormValOpt, InvalidU64));
1592 EXPECT_EQ(InvalidU64, toReference(FormValOpt, InvalidU64));
1593 EXPECT_EQ(Address, toAddress(FormValOpt, InvalidU64));
1594 EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt, InvalidU64));
1595 EXPECT_EQ(InvalidS64, toSigned(FormValOpt, InvalidU64));
1579 Optional FormValOpt2 =
1580 DWARFFormValue::createFromUValue(DW_FORM_addr, Address);
1581
1582 EXPECT_FALSE(toString(FormValOpt2).hasValue());
1583 EXPECT_FALSE(toUnsigned(FormValOpt2).hasValue());
1584 EXPECT_FALSE(toReference(FormValOpt2).hasValue());
1585 EXPECT_FALSE(toSigned(FormValOpt2).hasValue());
1586 EXPECT_TRUE(toAddress(FormValOpt2).hasValue());
1587 EXPECT_FALSE(toSectionOffset(FormValOpt2).hasValue());
1588 EXPECT_FALSE(toBlock(FormValOpt2).hasValue());
1589 EXPECT_EQ(nullptr, toString(FormValOpt2, nullptr));
1590 EXPECT_EQ(InvalidU64, toUnsigned(FormValOpt2, InvalidU64));
1591 EXPECT_EQ(InvalidU64, toReference(FormValOpt2, InvalidU64));
1592 EXPECT_EQ(Address, toAddress(FormValOpt2, InvalidU64));
1593 EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt2, InvalidU64));
1594 EXPECT_EQ(InvalidS64, toSigned(FormValOpt2, InvalidU64));
15961595
15971596 // Test successful and unsuccessful unsigned constant decoding.
15981597 uint64_t UData8 = 0x1020304050607080ULL;
1599 FormVal.setForm(DW_FORM_udata);
1600 FormVal.setUValue(UData8);
1601 FormValOpt = FormVal;
1602
1603 EXPECT_FALSE(toString(FormValOpt).hasValue());
1604 EXPECT_TRUE(toUnsigned(FormValOpt).hasValue());
1605 EXPECT_FALSE(toReference(FormValOpt).hasValue());
1606 EXPECT_TRUE(toSigned(FormValOpt).hasValue());
1607 EXPECT_FALSE(toAddress(FormValOpt).hasValue());
1608 EXPECT_FALSE(toSectionOffset(FormValOpt).hasValue());
1609 EXPECT_FALSE(toBlock(FormValOpt).hasValue());
1610 EXPECT_EQ(nullptr, toString(FormValOpt, nullptr));
1611 EXPECT_EQ(UData8, toUnsigned(FormValOpt, InvalidU64));
1612 EXPECT_EQ(InvalidU64, toReference(FormValOpt, InvalidU64));
1613 EXPECT_EQ(InvalidU64, toAddress(FormValOpt, InvalidU64));
1614 EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt, InvalidU64));
1615 EXPECT_EQ((int64_t)UData8, toSigned(FormValOpt, InvalidU64));
1598 Optional FormValOpt3 =
1599 DWARFFormValue::createFromUValue(DW_FORM_udata, UData8);
1600
1601 EXPECT_FALSE(toString(FormValOpt3).hasValue());
1602 EXPECT_TRUE(toUnsigned(FormValOpt3).hasValue());
1603 EXPECT_FALSE(toReference(FormValOpt3).hasValue());
1604 EXPECT_TRUE(toSigned(FormValOpt3).hasValue());
1605 EXPECT_FALSE(toAddress(FormValOpt3).hasValue());
1606 EXPECT_FALSE(toSectionOffset(FormValOpt3).hasValue());
1607 EXPECT_FALSE(toBlock(FormValOpt3).hasValue());
1608 EXPECT_EQ(nullptr, toString(FormValOpt3, nullptr));
1609 EXPECT_EQ(UData8, toUnsigned(FormValOpt3, InvalidU64));
1610 EXPECT_EQ(InvalidU64, toReference(FormValOpt3, InvalidU64));
1611 EXPECT_EQ(InvalidU64, toAddress(FormValOpt3, InvalidU64));
1612 EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt3, InvalidU64));
1613 EXPECT_EQ((int64_t)UData8, toSigned(FormValOpt3, InvalidU64));
16161614
16171615 // Test successful and unsuccessful reference decoding.
16181616 uint32_t RefData = 0x11223344U;
1619 FormVal.setForm(DW_FORM_ref_addr);
1620 FormVal.setUValue(RefData);
1621 FormValOpt = FormVal;
1622
1623 EXPECT_FALSE(toString(FormValOpt).hasValue());
1624 EXPECT_FALSE(toUnsigned(FormValOpt).hasValue());
1625 EXPECT_TRUE(toReference(FormValOpt).hasValue());
1626 EXPECT_FALSE(toSigned(FormValOpt).hasValue());
1627 EXPECT_FALSE(toAddress(FormValOpt).hasValue());
1628 EXPECT_FALSE(toSectionOffset(FormValOpt).hasValue());
1629 EXPECT_FALSE(toBlock(FormValOpt).hasValue());
1630 EXPECT_EQ(nullptr, toString(FormValOpt, nullptr));
1631 EXPECT_EQ(InvalidU64, toUnsigned(FormValOpt, InvalidU64));
1632 EXPECT_EQ(RefData, toReference(FormValOpt, InvalidU64));
1633 EXPECT_EQ(InvalidU64, toAddress(FormValOpt, InvalidU64));
1634 EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt, InvalidU64));
1635 EXPECT_EQ(InvalidS64, toSigned(FormValOpt, InvalidU64));
1617 Optional FormValOpt4 =
1618 DWARFFormValue::createFromUValue(DW_FORM_ref_addr, RefData);
1619
1620 EXPECT_FALSE(toString(FormValOpt4).hasValue());
1621 EXPECT_FALSE(toUnsigned(FormValOpt4).hasValue());
1622 EXPECT_TRUE(toReference(FormValOpt4).hasValue());
1623 EXPECT_FALSE(toSigned(FormValOpt4).hasValue());
1624 EXPECT_FALSE(toAddress(FormValOpt4).hasValue());
1625 EXPECT_FALSE(toSectionOffset(FormValOpt4).hasValue());
1626 EXPECT_FALSE(toBlock(FormValOpt4).hasValue());
1627 EXPECT_EQ(nullptr, toString(FormValOpt4, nullptr));
1628 EXPECT_EQ(InvalidU64, toUnsigned(FormValOpt4, InvalidU64));
1629 EXPECT_EQ(RefData, toReference(FormValOpt4, InvalidU64));
1630 EXPECT_EQ(InvalidU64, toAddress(FormValOpt4, InvalidU64));
1631 EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt4, InvalidU64));
1632 EXPECT_EQ(InvalidS64, toSigned(FormValOpt4, InvalidU64));
16361633
16371634 // Test successful and unsuccessful signed constant decoding.
16381635 int64_t SData8 = 0x1020304050607080ULL;
1639 FormVal.setForm(DW_FORM_udata);
1640 FormVal.setSValue(SData8);
1641 FormValOpt = FormVal;
1642
1643 EXPECT_FALSE(toString(FormValOpt).hasValue());
1644 EXPECT_TRUE(toUnsigned(FormValOpt).hasValue());
1645 EXPECT_FALSE(toReference(FormValOpt).hasValue());
1646 EXPECT_TRUE(toSigned(FormValOpt).hasValue());
1647 EXPECT_FALSE(toAddress(FormValOpt).hasValue());
1648 EXPECT_FALSE(toSectionOffset(FormValOpt).hasValue());
1649 EXPECT_FALSE(toBlock(FormValOpt).hasValue());
1650 EXPECT_EQ(nullptr, toString(FormValOpt, nullptr));
1651 EXPECT_EQ((uint64_t)SData8, toUnsigned(FormValOpt, InvalidU64));
1652 EXPECT_EQ(InvalidU64, toReference(FormValOpt, InvalidU64));
1653 EXPECT_EQ(InvalidU64, toAddress(FormValOpt, InvalidU64));
1654 EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt, InvalidU64));
1655 EXPECT_EQ(SData8, toSigned(FormValOpt, InvalidU64));
1636 Optional FormValOpt5 =
1637 DWARFFormValue::createFromSValue(DW_FORM_udata, SData8);
1638
1639 EXPECT_FALSE(toString(FormValOpt5).hasValue());
1640 EXPECT_TRUE(toUnsigned(FormValOpt5).hasValue());
1641 EXPECT_FALSE(toReference(FormValOpt5).hasValue());
1642 EXPECT_TRUE(toSigned(FormValOpt5).hasValue());
1643 EXPECT_FALSE(toAddress(FormValOpt5).hasValue());
1644 EXPECT_FALSE(toSectionOffset(FormValOpt5).hasValue());
1645 EXPECT_FALSE(toBlock(FormValOpt5).hasValue());
1646 EXPECT_EQ(nullptr, toString(FormValOpt5, nullptr));
1647 EXPECT_EQ((uint64_t)SData8, toUnsigned(FormValOpt5, InvalidU64));
1648 EXPECT_EQ(InvalidU64, toReference(FormValOpt5, InvalidU64));
1649 EXPECT_EQ(InvalidU64, toAddress(FormValOpt5, InvalidU64));
1650 EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt5, InvalidU64));
1651 EXPECT_EQ(SData8, toSigned(FormValOpt5, InvalidU64));
16561652
16571653 // Test successful and unsuccessful block decoding.
16581654 uint8_t Data[] = { 2, 3, 4 };
16591655 ArrayRef Array(Data);
1660 FormVal.setForm(DW_FORM_block1);
1661 FormVal.setBlockValue(Array);
1662 FormValOpt = FormVal;
1663
1664 EXPECT_FALSE(toString(FormValOpt).hasValue());
1665 EXPECT_FALSE(toUnsigned(FormValOpt).hasValue());
1666 EXPECT_FALSE(toReference(FormValOpt).hasValue());
1667 EXPECT_FALSE(toSigned(FormValOpt).hasValue());
1668 EXPECT_FALSE(toAddress(FormValOpt).hasValue());
1669 EXPECT_FALSE(toSectionOffset(FormValOpt).hasValue());
1670 auto BlockOpt = toBlock(FormValOpt);
1656 Optional FormValOpt6 =
1657 DWARFFormValue::createFromBlockValue(DW_FORM_block1, Array);
1658
1659 EXPECT_FALSE(toString(FormValOpt6).hasValue());
1660 EXPECT_FALSE(toUnsigned(FormValOpt6).hasValue());
1661 EXPECT_FALSE(toReference(FormValOpt6).hasValue());
1662 EXPECT_FALSE(toSigned(FormValOpt6).hasValue());
1663 EXPECT_FALSE(toAddress(FormValOpt6).hasValue());
1664 EXPECT_FALSE(toSectionOffset(FormValOpt6).hasValue());
1665 auto BlockOpt = toBlock(FormValOpt6);
16711666 EXPECT_TRUE(BlockOpt.hasValue());
16721667 EXPECT_EQ(*BlockOpt, Array);
1673 EXPECT_EQ(nullptr, toString(FormValOpt, nullptr));
1674 EXPECT_EQ(InvalidU64, toUnsigned(FormValOpt, InvalidU64));
1675 EXPECT_EQ(InvalidU64, toReference(FormValOpt, InvalidU64));
1676 EXPECT_EQ(InvalidU64, toAddress(FormValOpt, InvalidU64));
1677 EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt, InvalidU64));
1678 EXPECT_EQ(InvalidS64, toSigned(FormValOpt, InvalidU64));
1668 EXPECT_EQ(nullptr, toString(FormValOpt6, nullptr));
1669 EXPECT_EQ(InvalidU64, toUnsigned(FormValOpt6, InvalidU64));
1670 EXPECT_EQ(InvalidU64, toReference(FormValOpt6, InvalidU64));
1671 EXPECT_EQ(InvalidU64, toAddress(FormValOpt6, InvalidU64));
1672 EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt6, InvalidU64));
1673 EXPECT_EQ(InvalidS64, toSigned(FormValOpt6, InvalidU64));
16791674
16801675 // Test
16811676 }
182182 P.LineRange = 14;
183183 P.OpcodeBase = 13;
184184 P.StandardOpcodeLengths = {0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1};
185 P.IncludeDirectories.push_back(DWARFFormValue(DW_FORM_string));
186 P.IncludeDirectories.back().setPValue("a dir");
185 P.IncludeDirectories.push_back(
186 DWARFFormValue::createFromPValue(DW_FORM_string, "a dir"));
187187 P.FileNames.push_back(DWARFDebugLine::FileNameEntry());
188 P.FileNames.back().Name.setPValue("a file");
189 P.FileNames.back().Name.setForm(DW_FORM_string);
188 P.FileNames.back().Name =
189 DWARFFormValue::createFromPValue(DW_FORM_string, "a file");
190190 return P;
191191 }
192192