llvm.org GIT mirror llvm / 39f62fa
Merge DWARFDIE::extractFast and DWARFDIE::extract into one function. Complicated CU-DIE-specific logic in the latter was never used, and it makes sense to have safety checks for broken dwarf in the former. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193563 91177308-0d34-0410-b5e6-96231b3b80d8 Alexey Samsonov 5 years ago
2 changed file(s) with 10 addition(s) and 56 deletion(s). Raw diff Collapse all Expand all
9595 uint32_t *OffsetPtr) {
9696 Offset = *OffsetPtr;
9797 DataExtractor DebugInfoData = U->getDebugInfoExtractor();
98 uint32_t UEndOffset = U->getNextUnitOffset();
99 if (Offset >= UEndOffset || !DebugInfoData.isValidOffset(Offset))
100 return false;
98101 uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
99102 if (0 == AbbrCode) {
100103 // NULL debug tag entry.
102105 return true;
103106 }
104107 AbbrevDecl = U->getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
105 assert(AbbrevDecl);
108 if (0 == AbbrevDecl) {
109 // Restore the original offset.
110 *OffsetPtr = Offset;
111 return false;
112 }
106113 ArrayRef FixedFormSizes = DWARFFormValue::getFixedFormSizes(
107114 U->getAddressByteSize(), U->getVersion());
108115 assert(FixedFormSizes.size() > 0);
116123 if (FixedFormSize)
117124 *OffsetPtr += FixedFormSize;
118125 else if (!DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, U)) {
119 // Restore the original offset.
120 *OffsetPtr = Offset;
121 return false;
122 }
123 }
124 return true;
125 }
126
127 bool DWARFDebugInfoEntryMinimal::extract(const DWARFUnit *U,
128 uint32_t *OffsetPtr) {
129 DataExtractor DebugInfoData = U->getDebugInfoExtractor();
130 const uint32_t UEndOffset = U->getNextUnitOffset();
131 Offset = *OffsetPtr;
132 if ((Offset >= UEndOffset) || !DebugInfoData.isValidOffset(Offset))
133 return false;
134 uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
135 if (0 == AbbrCode) {
136 // NULL debug tag entry.
137 AbbrevDecl = NULL;
138 return true;
139 }
140 AbbrevDecl = U->getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
141 if (0 == AbbrevDecl) {
142 // Restore the original offset.
143 *OffsetPtr = Offset;
144 return false;
145 }
146 bool IsCompileUnitTag = (AbbrevDecl->getTag() == DW_TAG_compile_unit);
147 if (IsCompileUnitTag)
148 const_cast(U)->setBaseAddress(0);
149
150 // Skip all data in the .debug_info for the attributes
151 for (uint32_t i = 0, n = AbbrevDecl->getNumAttributes(); i < n; ++i) {
152 uint16_t Attr = AbbrevDecl->getAttrByIndex(i);
153 uint16_t Form = AbbrevDecl->getFormByIndex(i);
154
155 if (IsCompileUnitTag &&
156 ((Attr == DW_AT_entry_pc) || (Attr == DW_AT_low_pc))) {
157 DWARFFormValue FormValue(Form);
158 if (FormValue.extractValue(DebugInfoData, OffsetPtr, U)) {
159 if (Attr == DW_AT_low_pc || Attr == DW_AT_entry_pc) {
160 Optional BaseAddr = FormValue.getAsAddress(U);
161 if (BaseAddr.hasValue())
162 const_cast(U)->setBaseAddress(BaseAddr.getValue());
163 }
164 }
165 } else if (!DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, U)) {
166126 // Restore the original offset.
167127 *OffsetPtr = Offset;
168128 return false;
322282 getAttributeValueAsReference(U, DW_AT_specification, -1U);
323283 if (spec_ref != -1U) {
324284 DWARFDebugInfoEntryMinimal spec_die;
325 if (spec_die.extract(U, &spec_ref)) {
285 if (spec_die.extractFast(U, &spec_ref)) {
326286 if (const char *name = spec_die.getSubroutineName(U))
327287 return name;
328288 }
332292 getAttributeValueAsReference(U, DW_AT_abstract_origin, -1U);
333293 if (abs_origin_ref != -1U) {
334294 DWARFDebugInfoEntryMinimal abs_origin_die;
335 if (abs_origin_die.extract(U, &abs_origin_ref)) {
295 if (abs_origin_die.extractFast(U, &abs_origin_ref)) {
336296 if (const char *name = abs_origin_die.getSubroutineName(U))
337297 return name;
338298 }
4848 /// starting at a given offset. If DIE can't be extracted, returns false and
4949 /// doesn't change OffsetPtr.
5050 bool extractFast(const DWARFUnit *U, uint32_t *OffsetPtr);
51
52 /// Extract a debug info entry for a given compile unit from the
53 /// .debug_info and .debug_abbrev data starting at the given offset.
54 /// If compile unit can't be parsed, returns false and doesn't change
55 /// OffsetPtr.
56 bool extract(const DWARFUnit *U, uint32_t *OffsetPtr);
5751
5852 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
5953 bool isNULL() const { return AbbrevDecl == 0; }