llvm.org GIT mirror llvm / 6faff48
DWARF parser: Use ArrayRef to represent form sizes and simplify DWARFDIE::extractFast() interface. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193560 91177308-0d34-0410-b5e6-96231b3b80d8 Alexey Samsonov 5 years ago
6 changed file(s) with 16 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
99 #ifndef LLVM_DEBUGINFO_DWARFFORMVALUE_H
1010 #define LLVM_DEBUGINFO_DWARFFORMVALUE_H
1111
12 #include "llvm/ADT/ArrayRef.h"
1213 #include "llvm/ADT/Optional.h"
1314 #include "llvm/Support/DataExtractor.h"
1415
7475 static bool skipValue(uint16_t form, DataExtractor debug_info_data,
7576 uint32_t *offset_ptr, const DWARFUnit *u);
7677
77 static const uint8_t *getFixedFormSizes(uint8_t AddrSize, uint16_t Version);
78 static ArrayRef getFixedFormSizes(uint8_t AddrSize,
79 uint16_t Version);
7880 };
7981
8082 }
9292 }
9393
9494 bool DWARFDebugInfoEntryMinimal::extractFast(const DWARFUnit *U,
95 const uint8_t *FixedFormSizes,
9695 uint32_t *OffsetPtr) {
9796 Offset = *OffsetPtr;
9897 DataExtractor DebugInfoData = U->getDebugInfoExtractor();
104103 }
105104 AbbrevDecl = U->getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
106105 assert(AbbrevDecl);
107 assert(FixedFormSizes); // For best performance this should be specified!
106 ArrayRef FixedFormSizes = DWARFFormValue::getFixedFormSizes(
107 U->getAddressByteSize(), U->getVersion());
108 assert(FixedFormSizes.size() > 0);
108109
109110 // Skip all data in the .debug_info for the attributes
110111 for (uint32_t i = 0, n = AbbrevDecl->getNumAttributes(); i < n; ++i) {
111112 uint16_t Form = AbbrevDecl->getFormByIndex(i);
112113
113 // FIXME: Currently we're checking if this is less than the last
114 // entry in the fixed_form_sizes table, but this should be changed
115 // to use dynamic dispatch.
116114 uint8_t FixedFormSize =
117 (Form < DW_FORM_ref_sig8) ? FixedFormSizes[Form] : 0;
115 (Form < FixedFormSizes.size()) ? FixedFormSizes[Form] : 0;
118116 if (FixedFormSize)
119117 *OffsetPtr += FixedFormSize;
120 else if (!DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr,
121 U)) {
118 else if (!DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, U)) {
122119 // Restore the original offset.
123120 *OffsetPtr = Offset;
124121 return false;
4444 void dumpAttribute(raw_ostream &OS, const DWARFUnit *u, uint32_t *offset_ptr,
4545 uint16_t attr, uint16_t form, unsigned indent = 0) const;
4646
47 /// Extracts a debug info entry, which is a child of a given compile unit,
47 /// Extracts a debug info entry, which is a child of a given unit,
4848 /// starting at a given offset. If DIE can't be extracted, returns false and
4949 /// doesn't change OffsetPtr.
50 bool extractFast(const DWARFUnit *U, const uint8_t *FixedFormSizes,
51 uint32_t *OffsetPtr);
50 bool extractFast(const DWARFUnit *U, uint32_t *OffsetPtr);
5251
5352 /// Extract a debug info entry for a given compile unit from the
5453 /// .debug_info and .debug_abbrev data starting at the given offset.
6161 return (Version == 2) ? AddrSize : 4;
6262 }
6363
64 const uint8_t *
65 DWARFFormValue::getFixedFormSizes(uint8_t AddrSize, uint16_t Version) {
64 ArrayRef DWARFFormValue::getFixedFormSizes(uint8_t AddrSize,
65 uint16_t Version) {
6666 uint8_t RefAddrSize = getRefAddrSize(AddrSize, Version);
6767 if (AddrSize == 4 && RefAddrSize == 4)
6868 return FixedFormSizes<4, 4>::sizes;
7272 return FixedFormSizes<8, 4>::sizes;
7373 if (AddrSize == 8 && RefAddrSize == 8)
7474 return FixedFormSizes<8, 8>::sizes;
75 return 0;
75 return None;
7676 }
7777
7878 static const DWARFFormValue::FormClass DWARF4FormClasses[] = {
193193 uint32_t NextCUOffset = getNextUnitOffset();
194194 DWARFDebugInfoEntryMinimal DIE;
195195 uint32_t Depth = 0;
196 const uint8_t *FixedFormSizes =
197 DWARFFormValue::getFixedFormSizes(getAddressByteSize(), getVersion());
198196 bool IsCUDie = true;
199197
200 while (Offset < NextCUOffset &&
201 DIE.extractFast(this, FixedFormSizes, &Offset)) {
198 while (Offset < NextCUOffset && DIE.extractFast(this, &Offset)) {
202199 if (IsCUDie) {
203200 if (AppendCUDie)
204201 Dies.push_back(DIE);
1717 TEST(DWARFFormValue, FixedFormSizes) {
1818 // Size of DW_FORM_addr and DW_FORM_ref_addr are equal in DWARF2,
1919 // DW_FORM_ref_addr is always 4 bytes in DWARF32 starting from DWARF3.
20 const uint8_t *sizes = DWARFFormValue::getFixedFormSizes(4, 2);
20 ArrayRef sizes = DWARFFormValue::getFixedFormSizes(4, 2);
2121 EXPECT_EQ(sizes[DW_FORM_addr], sizes[DW_FORM_ref_addr]);
2222 sizes = DWARFFormValue::getFixedFormSizes(8, 2);
2323 EXPECT_EQ(sizes[DW_FORM_addr], sizes[DW_FORM_ref_addr]);
2424 sizes = DWARFFormValue::getFixedFormSizes(8, 3);
2525 EXPECT_EQ(4, sizes[DW_FORM_ref_addr]);
2626 // Check that we don't have fixed form sizes for weird address sizes.
27 EXPECT_EQ(0, DWARFFormValue::getFixedFormSizes(16, 2));
27 EXPECT_EQ(0U, DWARFFormValue::getFixedFormSizes(16, 2).size());
2828 }
2929
3030 bool isFormClass(uint16_t Form, DWARFFormValue::FormClass FC) {