Eugene Zelenko | e94042c | 2017-02-27 23:43:14 +0000 | [diff] [blame] | 1 | //===- DWARFDie.cpp -------------------------------------------------------===// |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 10 | #include "llvm/DebugInfo/DWARF/DWARFDie.h" |
Eugene Zelenko | e94042c | 2017-02-27 23:43:14 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/None.h" |
| 12 | #include "llvm/ADT/Optional.h" |
Jonas Devlieghere | 4bbcb5a | 2018-04-30 17:02:41 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/SmallSet.h" |
Eugene Zelenko | e94042c | 2017-02-27 23:43:14 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/StringRef.h" |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 15 | #include "llvm/BinaryFormat/Dwarf.h" |
Eugene Zelenko | e94042c | 2017-02-27 23:43:14 +0000 | [diff] [blame] | 16 | #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h" |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/DWARF/DWARFContext.h" |
Eugene Zelenko | e94042c | 2017-02-27 23:43:14 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h" |
Reid Kleckner | a058736 | 2017-08-29 21:41:21 +0000 | [diff] [blame] | 19 | #include "llvm/DebugInfo/DWARF/DWARFExpression.h" |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" |
Eugene Zelenko | e94042c | 2017-02-27 23:43:14 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/DWARF/DWARFUnit.h" |
George Rimar | 6957ab5 | 2017-08-15 12:32:54 +0000 | [diff] [blame] | 22 | #include "llvm/Object/ObjectFile.h" |
Eugene Zelenko | e94042c | 2017-02-27 23:43:14 +0000 | [diff] [blame] | 23 | #include "llvm/Support/DataExtractor.h" |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Format.h" |
Pavel Labath | 9025f95 | 2018-03-21 11:46:37 +0000 | [diff] [blame] | 25 | #include "llvm/Support/FormatVariadic.h" |
Eugene Zelenko | e94042c | 2017-02-27 23:43:14 +0000 | [diff] [blame] | 26 | #include "llvm/Support/MathExtras.h" |
Jonas Devlieghere | 6921753 | 2018-03-09 09:56:24 +0000 | [diff] [blame] | 27 | #include "llvm/Support/WithColor.h" |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 28 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | e94042c | 2017-02-27 23:43:14 +0000 | [diff] [blame] | 29 | #include <algorithm> |
| 30 | #include <cassert> |
| 31 | #include <cinttypes> |
| 32 | #include <cstdint> |
| 33 | #include <string> |
| 34 | #include <utility> |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 35 | |
| 36 | using namespace llvm; |
| 37 | using namespace dwarf; |
George Rimar | 6957ab5 | 2017-08-15 12:32:54 +0000 | [diff] [blame] | 38 | using namespace object; |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 39 | |
Eugene Zelenko | e94042c | 2017-02-27 23:43:14 +0000 | [diff] [blame] | 40 | static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val) { |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 41 | OS << " ("; |
| 42 | do { |
| 43 | uint64_t Shift = countTrailingZeros(Val); |
| 44 | assert(Shift < 64 && "undefined behavior"); |
| 45 | uint64_t Bit = 1ULL << Shift; |
| 46 | auto PropName = ApplePropertyString(Bit); |
| 47 | if (!PropName.empty()) |
| 48 | OS << PropName; |
| 49 | else |
| 50 | OS << format("DW_APPLE_PROPERTY_0x%" PRIx64, Bit); |
| 51 | if (!(Val ^= Bit)) |
| 52 | break; |
| 53 | OS << ", "; |
| 54 | } while (true); |
| 55 | OS << ")"; |
| 56 | } |
| 57 | |
George Rimar | 6957ab5 | 2017-08-15 12:32:54 +0000 | [diff] [blame] | 58 | static void dumpRanges(const DWARFObject &Obj, raw_ostream &OS, |
| 59 | const DWARFAddressRangesVector &Ranges, |
| 60 | unsigned AddressSize, unsigned Indent, |
| 61 | const DIDumpOptions &DumpOpts) { |
George Rimar | e1c30f7 | 2017-08-15 15:54:43 +0000 | [diff] [blame] | 62 | ArrayRef<SectionName> SectionNames; |
Jonas Devlieghere | 27476ce | 2017-09-13 09:43:05 +0000 | [diff] [blame] | 63 | if (DumpOpts.Verbose) |
George Rimar | e1c30f7 | 2017-08-15 15:54:43 +0000 | [diff] [blame] | 64 | SectionNames = Obj.getSectionNames(); |
George Rimar | 6957ab5 | 2017-08-15 12:32:54 +0000 | [diff] [blame] | 65 | |
Jonas Devlieghere | 6f24c87 | 2018-01-16 11:17:57 +0000 | [diff] [blame] | 66 | for (const DWARFAddressRange &R : Ranges) { |
George Rimar | 6957ab5 | 2017-08-15 12:32:54 +0000 | [diff] [blame] | 67 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 68 | OS << '\n'; |
| 69 | OS.indent(Indent); |
Jonas Devlieghere | 6f24c87 | 2018-01-16 11:17:57 +0000 | [diff] [blame] | 70 | R.dump(OS, AddressSize); |
George Rimar | 6957ab5 | 2017-08-15 12:32:54 +0000 | [diff] [blame] | 71 | |
| 72 | if (SectionNames.empty() || R.SectionIndex == -1ULL) |
| 73 | continue; |
| 74 | |
George Rimar | e1c30f7 | 2017-08-15 15:54:43 +0000 | [diff] [blame] | 75 | StringRef Name = SectionNames[R.SectionIndex].Name; |
| 76 | OS << " \"" << Name << '\"'; |
George Rimar | 6957ab5 | 2017-08-15 12:32:54 +0000 | [diff] [blame] | 77 | |
George Rimar | e1c30f7 | 2017-08-15 15:54:43 +0000 | [diff] [blame] | 78 | // Print section index if name is not unique. |
| 79 | if (!SectionNames[R.SectionIndex].IsNameUnique) |
George Rimar | e526943 | 2017-08-15 16:42:21 +0000 | [diff] [blame] | 80 | OS << format(" [%" PRIu64 "]", R.SectionIndex); |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
Reid Kleckner | a058736 | 2017-08-29 21:41:21 +0000 | [diff] [blame] | 84 | static void dumpLocation(raw_ostream &OS, DWARFFormValue &FormValue, |
Jonas Devlieghere | 27476ce | 2017-09-13 09:43:05 +0000 | [diff] [blame] | 85 | DWARFUnit *U, unsigned Indent, |
| 86 | DIDumpOptions DumpOpts) { |
Reid Kleckner | a058736 | 2017-08-29 21:41:21 +0000 | [diff] [blame] | 87 | DWARFContext &Ctx = U->getContext(); |
| 88 | const DWARFObject &Obj = Ctx.getDWARFObj(); |
| 89 | const MCRegisterInfo *MRI = Ctx.getRegisterInfo(); |
| 90 | if (FormValue.isFormClass(DWARFFormValue::FC_Block) || |
| 91 | FormValue.isFormClass(DWARFFormValue::FC_Exprloc)) { |
| 92 | ArrayRef<uint8_t> Expr = *FormValue.getAsBlock(); |
| 93 | DataExtractor Data(StringRef((const char *)Expr.data(), Expr.size()), |
| 94 | Ctx.isLittleEndian(), 0); |
| 95 | DWARFExpression(Data, U->getVersion(), U->getAddressByteSize()) |
| 96 | .print(OS, MRI); |
| 97 | return; |
| 98 | } |
| 99 | |
Jonas Devlieghere | 27476ce | 2017-09-13 09:43:05 +0000 | [diff] [blame] | 100 | FormValue.dump(OS, DumpOpts); |
Reid Kleckner | a058736 | 2017-08-29 21:41:21 +0000 | [diff] [blame] | 101 | if (FormValue.isFormClass(DWARFFormValue::FC_SectionOffset)) { |
| 102 | const DWARFSection &LocSection = Obj.getLocSection(); |
| 103 | const DWARFSection &LocDWOSection = Obj.getLocDWOSection(); |
| 104 | uint32_t Offset = *FormValue.getAsSectionOffset(); |
Reid Kleckner | a058736 | 2017-08-29 21:41:21 +0000 | [diff] [blame] | 105 | if (!LocSection.Data.empty()) { |
| 106 | DWARFDebugLoc DebugLoc; |
| 107 | DWARFDataExtractor Data(Obj, LocSection, Ctx.isLittleEndian(), |
| 108 | Obj.getAddressSize()); |
| 109 | auto LL = DebugLoc.parseOneLocationList(Data, &Offset); |
Jonas Devlieghere | c111382 | 2018-05-21 19:36:54 +0000 | [diff] [blame^] | 110 | if (LL) { |
| 111 | uint64_t BaseAddr = 0; |
| 112 | if (Optional<BaseAddress> BA = U->getBaseAddress()) |
| 113 | BaseAddr = BA->Address; |
| 114 | LL->dump(OS, Ctx.isLittleEndian(), Obj.getAddressSize(), MRI, BaseAddr, |
| 115 | Indent); |
| 116 | } else |
Reid Kleckner | a058736 | 2017-08-29 21:41:21 +0000 | [diff] [blame] | 117 | OS << "error extracting location list."; |
| 118 | } else if (!LocDWOSection.Data.empty()) { |
| 119 | DataExtractor Data(LocDWOSection.Data, Ctx.isLittleEndian(), 0); |
| 120 | auto LL = DWARFDebugLocDWO::parseOneLocationList(Data, &Offset); |
| 121 | if (LL) |
| 122 | LL->dump(OS, Ctx.isLittleEndian(), Obj.getAddressSize(), MRI, Indent); |
| 123 | else |
| 124 | OS << "error extracting location list."; |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | |
Jonas Devlieghere | aa6be82 | 2017-10-10 14:15:25 +0000 | [diff] [blame] | 129 | /// Dump the name encoded in the type tag. |
| 130 | static void dumpTypeTagName(raw_ostream &OS, dwarf::Tag T) { |
| 131 | StringRef TagStr = TagString(T); |
| 132 | if (!TagStr.startswith("DW_TAG_") || !TagStr.endswith("_type")) |
| 133 | return; |
| 134 | OS << TagStr.substr(7, TagStr.size() - 12) << " "; |
| 135 | } |
| 136 | |
| 137 | /// Recursively dump the DIE type name when applicable. |
| 138 | static void dumpTypeName(raw_ostream &OS, const DWARFDie &Die) { |
| 139 | DWARFDie D = Die.getAttributeValueAsReferencedDie(DW_AT_type); |
| 140 | |
| 141 | if (!D.isValid()) |
| 142 | return; |
| 143 | |
| 144 | if (const char *Name = D.getName(DINameKind::LinkageName)) { |
| 145 | OS << Name; |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | // FIXME: We should have pretty printers per language. Currently we print |
| 150 | // everything as if it was C++ and fall back to the TAG type name. |
| 151 | const dwarf::Tag T = D.getTag(); |
| 152 | switch (T) { |
| 153 | case DW_TAG_array_type: |
| 154 | case DW_TAG_pointer_type: |
| 155 | case DW_TAG_ptr_to_member_type: |
| 156 | case DW_TAG_reference_type: |
| 157 | case DW_TAG_rvalue_reference_type: |
| 158 | break; |
| 159 | default: |
| 160 | dumpTypeTagName(OS, T); |
| 161 | } |
| 162 | |
| 163 | // Follow the DW_AT_type if possible. |
| 164 | dumpTypeName(OS, D); |
| 165 | |
| 166 | switch (T) { |
| 167 | case DW_TAG_array_type: |
| 168 | OS << "[]"; |
| 169 | break; |
| 170 | case DW_TAG_pointer_type: |
| 171 | OS << '*'; |
| 172 | break; |
| 173 | case DW_TAG_ptr_to_member_type: |
| 174 | OS << '*'; |
| 175 | break; |
| 176 | case DW_TAG_reference_type: |
| 177 | OS << '&'; |
| 178 | break; |
| 179 | case DW_TAG_rvalue_reference_type: |
| 180 | OS << "&&"; |
| 181 | break; |
| 182 | default: |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 187 | static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, |
| 188 | uint32_t *OffsetPtr, dwarf::Attribute Attr, |
Adrian Prantl | 318d119 | 2017-06-06 23:28:45 +0000 | [diff] [blame] | 189 | dwarf::Form Form, unsigned Indent, |
| 190 | DIDumpOptions DumpOpts) { |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 191 | if (!Die.isValid()) |
| 192 | return; |
| 193 | const char BaseIndent[] = " "; |
| 194 | OS << BaseIndent; |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 195 | OS.indent(Indent + 2); |
Pavel Labath | 9025f95 | 2018-03-21 11:46:37 +0000 | [diff] [blame] | 196 | WithColor(OS, HighlightColor::Attribute) << formatv("{0}", Attr); |
Adrian Prantl | 318d119 | 2017-06-06 23:28:45 +0000 | [diff] [blame] | 197 | |
Pavel Labath | 9025f95 | 2018-03-21 11:46:37 +0000 | [diff] [blame] | 198 | if (DumpOpts.Verbose || DumpOpts.ShowForm) |
| 199 | OS << formatv(" [{0}]", Form); |
Adrian Prantl | 318d119 | 2017-06-06 23:28:45 +0000 | [diff] [blame] | 200 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 201 | DWARFUnit *U = Die.getDwarfUnit(); |
| 202 | DWARFFormValue formValue(Form); |
Jonas Devlieghere | a2faf7b | 2017-08-18 21:35:44 +0000 | [diff] [blame] | 203 | |
Paul Robinson | e5400f8 | 2017-11-07 19:57:12 +0000 | [diff] [blame] | 204 | if (!formValue.extractValue(U->getDebugInfoExtractor(), OffsetPtr, |
| 205 | U->getFormParams(), U)) |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 206 | return; |
Jonas Devlieghere | a2faf7b | 2017-08-18 21:35:44 +0000 | [diff] [blame] | 207 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 208 | OS << "\t("; |
Jonas Devlieghere | a2faf7b | 2017-08-18 21:35:44 +0000 | [diff] [blame] | 209 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 210 | StringRef Name; |
| 211 | std::string File; |
Jonas Devlieghere | 6921753 | 2018-03-09 09:56:24 +0000 | [diff] [blame] | 212 | auto Color = HighlightColor::Enumerator; |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 213 | if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) { |
Jonas Devlieghere | 6921753 | 2018-03-09 09:56:24 +0000 | [diff] [blame] | 214 | Color = HighlightColor::String; |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 215 | if (const auto *LT = U->getContext().getLineTableForUnit(U)) |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 216 | if (LT->getFileNameByIndex( |
| 217 | formValue.getAsUnsignedConstant().getValue(), |
| 218 | U->getCompilationDir(), |
| 219 | DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, File)) { |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 220 | File = '"' + File + '"'; |
| 221 | Name = File; |
| 222 | } |
| 223 | } else if (Optional<uint64_t> Val = formValue.getAsUnsignedConstant()) |
| 224 | Name = AttributeValueString(Attr, *Val); |
Jonas Devlieghere | a2faf7b | 2017-08-18 21:35:44 +0000 | [diff] [blame] | 225 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 226 | if (!Name.empty()) |
| 227 | WithColor(OS, Color) << Name; |
| 228 | else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line) |
| 229 | OS << *formValue.getAsUnsignedConstant(); |
Jonas Devlieghere | 6a9c592 | 2017-11-27 16:40:46 +0000 | [diff] [blame] | 230 | else if (Attr == DW_AT_high_pc && !DumpOpts.ShowForm && !DumpOpts.Verbose && |
| 231 | formValue.getAsUnsignedConstant()) { |
Adrian Prantl | 01fb31c | 2017-12-08 23:32:47 +0000 | [diff] [blame] | 232 | if (DumpOpts.ShowAddresses) { |
| 233 | // Print the actual address rather than the offset. |
| 234 | uint64_t LowPC, HighPC, Index; |
| 235 | if (Die.getLowAndHighPC(LowPC, HighPC, Index)) |
| 236 | OS << format("0x%016" PRIx64, HighPC); |
| 237 | else |
| 238 | formValue.dump(OS, DumpOpts); |
| 239 | } |
Jonas Devlieghere | 6a9c592 | 2017-11-27 16:40:46 +0000 | [diff] [blame] | 240 | } else if (Attr == DW_AT_location || Attr == DW_AT_frame_base || |
| 241 | Attr == DW_AT_data_member_location || |
| 242 | Attr == DW_AT_GNU_call_site_value) |
Jonas Devlieghere | 27476ce | 2017-09-13 09:43:05 +0000 | [diff] [blame] | 243 | dumpLocation(OS, formValue, U, sizeof(BaseIndent) + Indent + 4, DumpOpts); |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 244 | else |
Jonas Devlieghere | a2faf7b | 2017-08-18 21:35:44 +0000 | [diff] [blame] | 245 | formValue.dump(OS, DumpOpts); |
| 246 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 247 | // We have dumped the attribute raw value. For some attributes |
| 248 | // having both the raw value and the pretty-printed value is |
| 249 | // interesting. These attributes are handled below. |
Jonas Devlieghere | 4942a0b | 2017-08-22 21:59:46 +0000 | [diff] [blame] | 250 | if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) { |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 251 | if (const char *Name = Die.getAttributeValueAsReferencedDie(Attr).getName( |
| 252 | DINameKind::LinkageName)) |
| 253 | OS << " \"" << Name << '\"'; |
Jonas Devlieghere | aa6be82 | 2017-10-10 14:15:25 +0000 | [diff] [blame] | 254 | } else if (Attr == DW_AT_type) { |
| 255 | OS << " \""; |
| 256 | dumpTypeName(OS, Die); |
| 257 | OS << '"'; |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 258 | } else if (Attr == DW_AT_APPLE_property_attribute) { |
| 259 | if (Optional<uint64_t> OptVal = formValue.getAsUnsignedConstant()) |
| 260 | dumpApplePropertyAttribute(OS, *OptVal); |
| 261 | } else if (Attr == DW_AT_ranges) { |
George Rimar | 6957ab5 | 2017-08-15 12:32:54 +0000 | [diff] [blame] | 262 | const DWARFObject &Obj = Die.getDwarfUnit()->getContext().getDWARFObj(); |
Wolfgang Pieb | ad60559 | 2018-05-18 20:12:54 +0000 | [diff] [blame] | 263 | // For DW_FORM_rnglistx we need to dump the offset separately, since |
| 264 | // we have only dumped the index so far. |
| 265 | Optional<DWARFFormValue> Value = Die.find(DW_AT_ranges); |
| 266 | if (Value && Value->getForm() == DW_FORM_rnglistx) |
| 267 | if (auto RangeListOffset = |
| 268 | U->getRnglistOffset(*Value->getAsSectionOffset())) { |
| 269 | DWARFFormValue FV(dwarf::DW_FORM_sec_offset); |
| 270 | FV.setUValue(*RangeListOffset); |
| 271 | FV.dump(OS, DumpOpts); |
| 272 | } |
George Rimar | 6957ab5 | 2017-08-15 12:32:54 +0000 | [diff] [blame] | 273 | dumpRanges(Obj, OS, Die.getAddressRanges(), U->getAddressByteSize(), |
| 274 | sizeof(BaseIndent) + Indent + 4, DumpOpts); |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 275 | } |
George Rimar | 6957ab5 | 2017-08-15 12:32:54 +0000 | [diff] [blame] | 276 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 277 | OS << ")\n"; |
| 278 | } |
| 279 | |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 280 | bool DWARFDie::isSubprogramDIE() const { return getTag() == DW_TAG_subprogram; } |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 281 | |
| 282 | bool DWARFDie::isSubroutineDIE() const { |
| 283 | auto Tag = getTag(); |
| 284 | return Tag == DW_TAG_subprogram || Tag == DW_TAG_inlined_subroutine; |
| 285 | } |
| 286 | |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 287 | Optional<DWARFFormValue> DWARFDie::find(dwarf::Attribute Attr) const { |
Greg Clayton | 1cbf3fa | 2016-12-13 23:20:56 +0000 | [diff] [blame] | 288 | if (!isValid()) |
| 289 | return None; |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 290 | auto AbbrevDecl = getAbbreviationDeclarationPtr(); |
| 291 | if (AbbrevDecl) |
Greg Clayton | 1cbf3fa | 2016-12-13 23:20:56 +0000 | [diff] [blame] | 292 | return AbbrevDecl->getAttributeValue(getOffset(), Attr, *U); |
| 293 | return None; |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Greg Clayton | 97d2218 | 2017-01-13 21:08:18 +0000 | [diff] [blame] | 296 | Optional<DWARFFormValue> |
Greg Clayton | c109bbe | 2017-01-13 22:32:12 +0000 | [diff] [blame] | 297 | DWARFDie::find(ArrayRef<dwarf::Attribute> Attrs) const { |
| 298 | if (!isValid()) |
| 299 | return None; |
| 300 | auto AbbrevDecl = getAbbreviationDeclarationPtr(); |
| 301 | if (AbbrevDecl) { |
| 302 | for (auto Attr : Attrs) { |
| 303 | if (auto Value = AbbrevDecl->getAttributeValue(getOffset(), Attr, *U)) |
| 304 | return Value; |
| 305 | } |
| 306 | } |
| 307 | return None; |
| 308 | } |
| 309 | |
| 310 | Optional<DWARFFormValue> |
| 311 | DWARFDie::findRecursively(ArrayRef<dwarf::Attribute> Attrs) const { |
Jonas Devlieghere | 4bbcb5a | 2018-04-30 17:02:41 +0000 | [diff] [blame] | 312 | std::vector<DWARFDie> Worklist; |
| 313 | Worklist.push_back(*this); |
| 314 | |
| 315 | // Keep track if DIEs already seen to prevent infinite recursion. |
| 316 | // Empirically we rarely see a depth of more than 3 when dealing with valid |
| 317 | // DWARF. This corresponds to following the DW_AT_abstract_origin and |
| 318 | // DW_AT_specification just once. |
| 319 | SmallSet<DWARFDie, 3> Seen; |
| 320 | |
| 321 | while (!Worklist.empty()) { |
| 322 | DWARFDie Die = Worklist.back(); |
| 323 | Worklist.pop_back(); |
| 324 | |
| 325 | if (!Die.isValid()) |
| 326 | continue; |
| 327 | |
| 328 | if (Seen.count(Die)) |
| 329 | continue; |
| 330 | |
| 331 | Seen.insert(Die); |
| 332 | |
| 333 | if (auto Value = Die.find(Attrs)) |
Greg Clayton | d6b67eb | 2017-11-27 22:12:44 +0000 | [diff] [blame] | 334 | return Value; |
Jonas Devlieghere | 4bbcb5a | 2018-04-30 17:02:41 +0000 | [diff] [blame] | 335 | |
| 336 | if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin)) |
| 337 | Worklist.push_back(D); |
| 338 | |
| 339 | if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_specification)) |
| 340 | Worklist.push_back(D); |
Greg Clayton | d6b67eb | 2017-11-27 22:12:44 +0000 | [diff] [blame] | 341 | } |
Jonas Devlieghere | 4bbcb5a | 2018-04-30 17:02:41 +0000 | [diff] [blame] | 342 | |
Greg Clayton | c109bbe | 2017-01-13 22:32:12 +0000 | [diff] [blame] | 343 | return None; |
| 344 | } |
| 345 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 346 | DWARFDie |
| 347 | DWARFDie::getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const { |
Jonas Devlieghere | aa6be82 | 2017-10-10 14:15:25 +0000 | [diff] [blame] | 348 | if (auto SpecRef = toReference(find(Attr))) { |
| 349 | if (auto SpecUnit = U->getUnitSection().getUnitForOffset(*SpecRef)) |
Greg Clayton | 52fe1f6 | 2016-12-14 22:38:08 +0000 | [diff] [blame] | 350 | return SpecUnit->getDIEForOffset(*SpecRef); |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 351 | } |
| 352 | return DWARFDie(); |
| 353 | } |
| 354 | |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 355 | Optional<uint64_t> DWARFDie::getRangesBaseAttribute() const { |
Greg Clayton | c109bbe | 2017-01-13 22:32:12 +0000 | [diff] [blame] | 356 | return toSectionOffset(find({DW_AT_rnglists_base, DW_AT_GNU_ranges_base})); |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Greg Clayton | 2520c9e | 2016-12-19 20:36:41 +0000 | [diff] [blame] | 359 | Optional<uint64_t> DWARFDie::getHighPC(uint64_t LowPC) const { |
Greg Clayton | 97d2218 | 2017-01-13 21:08:18 +0000 | [diff] [blame] | 360 | if (auto FormValue = find(DW_AT_high_pc)) { |
Greg Clayton | 2520c9e | 2016-12-19 20:36:41 +0000 | [diff] [blame] | 361 | if (auto Address = FormValue->getAsAddress()) { |
| 362 | // High PC is an address. |
| 363 | return Address; |
| 364 | } |
| 365 | if (auto Offset = FormValue->getAsUnsignedConstant()) { |
| 366 | // High PC is an offset from LowPC. |
| 367 | return LowPC + *Offset; |
| 368 | } |
| 369 | } |
| 370 | return None; |
| 371 | } |
Greg Clayton | 52fe1f6 | 2016-12-14 22:38:08 +0000 | [diff] [blame] | 372 | |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 373 | bool DWARFDie::getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC, |
| 374 | uint64_t &SectionIndex) const { |
| 375 | auto F = find(DW_AT_low_pc); |
| 376 | auto LowPcAddr = toAddress(F); |
Greg Clayton | 2520c9e | 2016-12-19 20:36:41 +0000 | [diff] [blame] | 377 | if (!LowPcAddr) |
Greg Clayton | 52fe1f6 | 2016-12-14 22:38:08 +0000 | [diff] [blame] | 378 | return false; |
Greg Clayton | 2520c9e | 2016-12-19 20:36:41 +0000 | [diff] [blame] | 379 | if (auto HighPcAddr = getHighPC(*LowPcAddr)) { |
| 380 | LowPC = *LowPcAddr; |
| 381 | HighPC = *HighPcAddr; |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 382 | SectionIndex = F->getSectionIndex(); |
Greg Clayton | 2520c9e | 2016-12-19 20:36:41 +0000 | [diff] [blame] | 383 | return true; |
| 384 | } |
| 385 | return false; |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 388 | DWARFAddressRangesVector DWARFDie::getAddressRanges() const { |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 389 | if (isNULL()) |
| 390 | return DWARFAddressRangesVector(); |
| 391 | // Single range specified by low/high PC. |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 392 | uint64_t LowPC, HighPC, Index; |
| 393 | if (getLowAndHighPC(LowPC, HighPC, Index)) |
| 394 | return {{LowPC, HighPC, Index}}; |
George Rimar | 4671f2e | 2017-05-16 12:30:59 +0000 | [diff] [blame] | 395 | |
Wolfgang Pieb | ad60559 | 2018-05-18 20:12:54 +0000 | [diff] [blame] | 396 | Optional<DWARFFormValue> Value = find(DW_AT_ranges); |
| 397 | if (Value) { |
| 398 | if (Value->getForm() == DW_FORM_rnglistx) |
| 399 | return U->findRnglistFromIndex(*Value->getAsSectionOffset()); |
| 400 | return U->findRnglistFromOffset(*Value->getAsSectionOffset()); |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 401 | } |
| 402 | return DWARFAddressRangesVector(); |
| 403 | } |
| 404 | |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 405 | void DWARFDie::collectChildrenAddressRanges( |
| 406 | DWARFAddressRangesVector &Ranges) const { |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 407 | if (isNULL()) |
| 408 | return; |
| 409 | if (isSubprogramDIE()) { |
| 410 | const auto &DIERanges = getAddressRanges(); |
| 411 | Ranges.insert(Ranges.end(), DIERanges.begin(), DIERanges.end()); |
| 412 | } |
| 413 | |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 414 | for (auto Child : children()) |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 415 | Child.collectChildrenAddressRanges(Ranges); |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | bool DWARFDie::addressRangeContainsAddress(const uint64_t Address) const { |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 419 | for (const auto &R : getAddressRanges()) { |
George Rimar | 4671f2e | 2017-05-16 12:30:59 +0000 | [diff] [blame] | 420 | if (R.LowPC <= Address && Address < R.HighPC) |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 421 | return true; |
| 422 | } |
| 423 | return false; |
| 424 | } |
| 425 | |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 426 | const char *DWARFDie::getSubroutineName(DINameKind Kind) const { |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 427 | if (!isSubroutineDIE()) |
| 428 | return nullptr; |
| 429 | return getName(Kind); |
| 430 | } |
| 431 | |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 432 | const char *DWARFDie::getName(DINameKind Kind) const { |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 433 | if (!isValid() || Kind == DINameKind::None) |
| 434 | return nullptr; |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 435 | // Try to get mangled name only if it was asked for. |
| 436 | if (Kind == DINameKind::LinkageName) { |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 437 | if (auto Name = dwarf::toString( |
| 438 | findRecursively({DW_AT_MIPS_linkage_name, DW_AT_linkage_name}), |
| 439 | nullptr)) |
Greg Clayton | 97d2218 | 2017-01-13 21:08:18 +0000 | [diff] [blame] | 440 | return Name; |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 441 | } |
Greg Clayton | 97d2218 | 2017-01-13 21:08:18 +0000 | [diff] [blame] | 442 | if (auto Name = dwarf::toString(findRecursively(DW_AT_name), nullptr)) |
| 443 | return Name; |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 444 | return nullptr; |
| 445 | } |
| 446 | |
David Blaikie | efc4eba | 2017-02-06 20:19:02 +0000 | [diff] [blame] | 447 | uint64_t DWARFDie::getDeclLine() const { |
| 448 | return toUnsigned(findRecursively(DW_AT_decl_line), 0); |
| 449 | } |
| 450 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 451 | void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine, |
Dehao Chen | ef700d5 | 2017-04-17 20:10:39 +0000 | [diff] [blame] | 452 | uint32_t &CallColumn, |
| 453 | uint32_t &CallDiscriminator) const { |
Greg Clayton | 97d2218 | 2017-01-13 21:08:18 +0000 | [diff] [blame] | 454 | CallFile = toUnsigned(find(DW_AT_call_file), 0); |
| 455 | CallLine = toUnsigned(find(DW_AT_call_line), 0); |
| 456 | CallColumn = toUnsigned(find(DW_AT_call_column), 0); |
Dehao Chen | ef700d5 | 2017-04-17 20:10:39 +0000 | [diff] [blame] | 457 | CallDiscriminator = toUnsigned(find(DW_AT_GNU_discriminator), 0); |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Adrian Prantl | c2bc717 | 2017-09-18 21:27:44 +0000 | [diff] [blame] | 460 | /// Helper to dump a DIE with all of its parents, but no siblings. |
| 461 | static unsigned dumpParentChain(DWARFDie Die, raw_ostream &OS, unsigned Indent, |
| 462 | DIDumpOptions DumpOpts) { |
| 463 | if (!Die) |
| 464 | return Indent; |
| 465 | Indent = dumpParentChain(Die.getParent(), OS, Indent, DumpOpts); |
Adrian Prantl | d3f9f21 | 2017-09-20 17:44:00 +0000 | [diff] [blame] | 466 | Die.dump(OS, Indent, DumpOpts); |
Adrian Prantl | c2bc717 | 2017-09-18 21:27:44 +0000 | [diff] [blame] | 467 | return Indent + 2; |
| 468 | } |
| 469 | |
Adrian Prantl | d3f9f21 | 2017-09-20 17:44:00 +0000 | [diff] [blame] | 470 | void DWARFDie::dump(raw_ostream &OS, unsigned Indent, |
Adrian Prantl | 318d119 | 2017-06-06 23:28:45 +0000 | [diff] [blame] | 471 | DIDumpOptions DumpOpts) const { |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 472 | if (!isValid()) |
| 473 | return; |
Paul Robinson | 17536b9 | 2017-06-29 16:52:08 +0000 | [diff] [blame] | 474 | DWARFDataExtractor debug_info_data = U->getDebugInfoExtractor(); |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 475 | const uint32_t Offset = getOffset(); |
| 476 | uint32_t offset = Offset; |
Adrian Prantl | c2bc717 | 2017-09-18 21:27:44 +0000 | [diff] [blame] | 477 | if (DumpOpts.ShowParents) { |
| 478 | DumpOpts.ShowParents = false; |
| 479 | Indent = dumpParentChain(getParent(), OS, Indent, DumpOpts); |
| 480 | } |
Jonas Devlieghere | a2faf7b | 2017-08-18 21:35:44 +0000 | [diff] [blame] | 481 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 482 | if (debug_info_data.isValidOffset(offset)) { |
| 483 | uint32_t abbrCode = debug_info_data.getULEB128(&offset); |
Adrian Prantl | 01fb31c | 2017-12-08 23:32:47 +0000 | [diff] [blame] | 484 | if (DumpOpts.ShowAddresses) |
Jonas Devlieghere | 6921753 | 2018-03-09 09:56:24 +0000 | [diff] [blame] | 485 | WithColor(OS, HighlightColor::Address).get() |
| 486 | << format("\n0x%8.8x: ", Offset); |
Jonas Devlieghere | a2faf7b | 2017-08-18 21:35:44 +0000 | [diff] [blame] | 487 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 488 | if (abbrCode) { |
| 489 | auto AbbrevDecl = getAbbreviationDeclarationPtr(); |
| 490 | if (AbbrevDecl) { |
Pavel Labath | 9025f95 | 2018-03-21 11:46:37 +0000 | [diff] [blame] | 491 | WithColor(OS, HighlightColor::Tag).get().indent(Indent) |
| 492 | << formatv("{0}", getTag()); |
Jonas Devlieghere | 27476ce | 2017-09-13 09:43:05 +0000 | [diff] [blame] | 493 | if (DumpOpts.Verbose) |
Adrian Prantl | 318d119 | 2017-06-06 23:28:45 +0000 | [diff] [blame] | 494 | OS << format(" [%u] %c", abbrCode, |
| 495 | AbbrevDecl->hasChildren() ? '*' : ' '); |
| 496 | OS << '\n'; |
| 497 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 498 | // Dump all data in the DIE for the attributes. |
| 499 | for (const auto &AttrSpec : AbbrevDecl->attributes()) { |
Victor Leschuk | 96d9981 | 2017-02-25 13:15:57 +0000 | [diff] [blame] | 500 | if (AttrSpec.Form == DW_FORM_implicit_const) { |
| 501 | // We are dumping .debug_info section , |
| 502 | // implicit_const attribute values are not really stored here, |
| 503 | // but in .debug_abbrev section. So we just skip such attrs. |
| 504 | continue; |
| 505 | } |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 506 | dumpAttribute(OS, *this, &offset, AttrSpec.Attr, AttrSpec.Form, |
Adrian Prantl | 318d119 | 2017-06-06 23:28:45 +0000 | [diff] [blame] | 507 | Indent, DumpOpts); |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 508 | } |
Jonas Devlieghere | a2faf7b | 2017-08-18 21:35:44 +0000 | [diff] [blame] | 509 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 510 | DWARFDie child = getFirstChild(); |
Adrian Prantl | 5da51f4 | 2017-11-29 01:12:22 +0000 | [diff] [blame] | 511 | if (DumpOpts.ShowChildren && DumpOpts.RecurseDepth > 0 && child) { |
Adrian Prantl | d3f9f21 | 2017-09-20 17:44:00 +0000 | [diff] [blame] | 512 | DumpOpts.RecurseDepth--; |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 513 | while (child) { |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 514 | child.dump(OS, Indent + 2, DumpOpts); |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 515 | child = child.getSibling(); |
| 516 | } |
| 517 | } |
| 518 | } else { |
| 519 | OS << "Abbreviation code not found in 'debug_abbrev' class for code: " |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 520 | << abbrCode << '\n'; |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 521 | } |
| 522 | } else { |
| 523 | OS.indent(Indent) << "NULL\n"; |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | |
Adrian Prantl | 3d523a6 | 2017-08-16 17:43:01 +0000 | [diff] [blame] | 528 | LLVM_DUMP_METHOD void DWARFDie::dump() const { dump(llvm::errs(), 0); } |
| 529 | |
Greg Clayton | 78a07bf | 2016-12-21 21:37:06 +0000 | [diff] [blame] | 530 | DWARFDie DWARFDie::getParent() const { |
| 531 | if (isValid()) |
| 532 | return U->getParent(Die); |
| 533 | return DWARFDie(); |
| 534 | } |
| 535 | |
| 536 | DWARFDie DWARFDie::getSibling() const { |
| 537 | if (isValid()) |
| 538 | return U->getSibling(Die); |
| 539 | return DWARFDie(); |
| 540 | } |
Greg Clayton | 0e62ee7 | 2017-01-13 00:13:42 +0000 | [diff] [blame] | 541 | |
George Rimar | 0be860f | 2017-10-25 10:23:49 +0000 | [diff] [blame] | 542 | DWARFDie DWARFDie::getFirstChild() const { |
| 543 | if (isValid()) |
| 544 | return U->getFirstChild(Die); |
| 545 | return DWARFDie(); |
| 546 | } |
| 547 | |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 548 | iterator_range<DWARFDie::attribute_iterator> DWARFDie::attributes() const { |
Greg Clayton | 0e62ee7 | 2017-01-13 00:13:42 +0000 | [diff] [blame] | 549 | return make_range(attribute_iterator(*this, false), |
| 550 | attribute_iterator(*this, true)); |
| 551 | } |
| 552 | |
Adrian Prantl | b4a6790 | 2017-10-04 22:26:19 +0000 | [diff] [blame] | 553 | DWARFDie::attribute_iterator::attribute_iterator(DWARFDie D, bool End) |
| 554 | : Die(D), AttrValue(0), Index(0) { |
Greg Clayton | 0e62ee7 | 2017-01-13 00:13:42 +0000 | [diff] [blame] | 555 | auto AbbrDecl = Die.getAbbreviationDeclarationPtr(); |
| 556 | assert(AbbrDecl && "Must have abbreviation declaration"); |
| 557 | if (End) { |
| 558 | // This is the end iterator so we set the index to the attribute count. |
| 559 | Index = AbbrDecl->getNumAttributes(); |
| 560 | } else { |
| 561 | // This is the begin iterator so we extract the value for this->Index. |
| 562 | AttrValue.Offset = D.getOffset() + AbbrDecl->getCodeByteSize(); |
| 563 | updateForIndex(*AbbrDecl, 0); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | void DWARFDie::attribute_iterator::updateForIndex( |
| 568 | const DWARFAbbreviationDeclaration &AbbrDecl, uint32_t I) { |
| 569 | Index = I; |
Hiroshi Inoue | ddb34d8 | 2017-07-03 06:32:59 +0000 | [diff] [blame] | 570 | // AbbrDecl must be valid before calling this function. |
Greg Clayton | 0e62ee7 | 2017-01-13 00:13:42 +0000 | [diff] [blame] | 571 | auto NumAttrs = AbbrDecl.getNumAttributes(); |
| 572 | if (Index < NumAttrs) { |
| 573 | AttrValue.Attr = AbbrDecl.getAttrByIndex(Index); |
| 574 | // Add the previous byte size of any previous attribute value. |
| 575 | AttrValue.Offset += AttrValue.ByteSize; |
| 576 | AttrValue.Value.setForm(AbbrDecl.getFormByIndex(Index)); |
| 577 | uint32_t ParseOffset = AttrValue.Offset; |
| 578 | auto U = Die.getDwarfUnit(); |
| 579 | assert(U && "Die must have valid DWARF unit"); |
| 580 | bool b = AttrValue.Value.extractValue(U->getDebugInfoExtractor(), |
Paul Robinson | e5400f8 | 2017-11-07 19:57:12 +0000 | [diff] [blame] | 581 | &ParseOffset, U->getFormParams(), U); |
Greg Clayton | 0e62ee7 | 2017-01-13 00:13:42 +0000 | [diff] [blame] | 582 | (void)b; |
| 583 | assert(b && "extractValue cannot fail on fully parsed DWARF"); |
| 584 | AttrValue.ByteSize = ParseOffset - AttrValue.Offset; |
| 585 | } else { |
| 586 | assert(Index == NumAttrs && "Indexes should be [0, NumAttrs) only"); |
| 587 | AttrValue.clear(); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | DWARFDie::attribute_iterator &DWARFDie::attribute_iterator::operator++() { |
| 592 | if (auto AbbrDecl = Die.getAbbreviationDeclarationPtr()) |
| 593 | updateForIndex(*AbbrDecl, Index + 1); |
| 594 | return *this; |
| 595 | } |