Eric Christopher | bd5bc21 | 2012-08-23 00:52:51 +0000 | [diff] [blame] | 1 | //===-- DWARFDebugInfoEntry.cpp -------------------------------------------===// |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +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 | |
| 10 | #include "DWARFDebugInfoEntry.h" |
| 11 | #include "DWARFCompileUnit.h" |
| 12 | #include "DWARFContext.h" |
| 13 | #include "DWARFDebugAbbrev.h" |
Alexey Samsonov | cd61455 | 2013-04-17 08:29:02 +0000 | [diff] [blame] | 14 | #include "llvm/DebugInfo/DWARFFormValue.h" |
Eric Christopher | dd8e9f3 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 15 | #include "llvm/Support/Debug.h" |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 16 | #include "llvm/Support/Dwarf.h" |
| 17 | #include "llvm/Support/Format.h" |
| 18 | #include "llvm/Support/raw_ostream.h" |
| 19 | using namespace llvm; |
| 20 | using namespace dwarf; |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 21 | typedef DILineInfoSpecifier::FunctionNameKind FunctionNameKind; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 22 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 23 | void DWARFDebugInfoEntryMinimal::dump(raw_ostream &OS, const DWARFUnit *u, |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 24 | unsigned recurseDepth, |
| 25 | unsigned indent) const { |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 26 | DataExtractor debug_info_data = u->getDebugInfoExtractor(); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 27 | uint32_t offset = Offset; |
| 28 | |
| 29 | if (debug_info_data.isValidOffset(offset)) { |
Benjamin Kramer | 80cc259 | 2011-11-05 15:35:00 +0000 | [diff] [blame] | 30 | uint32_t abbrCode = debug_info_data.getULEB128(&offset); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 31 | |
Benjamin Kramer | 0942255 | 2011-09-14 17:54:56 +0000 | [diff] [blame] | 32 | OS << format("\n0x%8.8x: ", Offset); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 33 | if (abbrCode) { |
| 34 | if (AbbrevDecl) { |
Benjamin Kramer | 75c6308 | 2011-09-15 05:43:00 +0000 | [diff] [blame] | 35 | const char *tagString = TagString(getTag()); |
| 36 | if (tagString) |
| 37 | OS.indent(indent) << tagString; |
| 38 | else |
| 39 | OS.indent(indent) << format("DW_TAG_Unknown_%x", getTag()); |
| 40 | OS << format(" [%u] %c\n", abbrCode, |
| 41 | AbbrevDecl->hasChildren() ? '*' : ' '); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 42 | |
Eric Christopher | e5ef305 | 2013-01-07 03:27:58 +0000 | [diff] [blame] | 43 | // Dump all data in the DIE for the attributes. |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 44 | for (const auto &AttrSpec : AbbrevDecl->attributes()) { |
| 45 | dumpAttribute(OS, u, &offset, AttrSpec.Attr, AttrSpec.Form, indent); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | const DWARFDebugInfoEntryMinimal *child = getFirstChild(); |
| 49 | if (recurseDepth > 0 && child) { |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 50 | while (child) { |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 51 | child->dump(OS, u, recurseDepth-1, indent+2); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 52 | child = child->getSibling(); |
| 53 | } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 54 | } |
| 55 | } else { |
| 56 | OS << "Abbreviation code not found in 'debug_abbrev' class for code: " |
| 57 | << abbrCode << '\n'; |
| 58 | } |
| 59 | } else { |
Benjamin Kramer | 0942255 | 2011-09-14 17:54:56 +0000 | [diff] [blame] | 60 | OS.indent(indent) << "NULL\n"; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS, |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 66 | const DWARFUnit *u, |
| 67 | uint32_t *offset_ptr, |
| 68 | uint16_t attr, uint16_t form, |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 69 | unsigned indent) const { |
David Blaikie | a9b6979 | 2013-08-19 03:36:23 +0000 | [diff] [blame] | 70 | OS << " "; |
Benjamin Kramer | 75c6308 | 2011-09-15 05:43:00 +0000 | [diff] [blame] | 71 | OS.indent(indent+2); |
| 72 | const char *attrString = AttributeString(attr); |
| 73 | if (attrString) |
| 74 | OS << attrString; |
| 75 | else |
| 76 | OS << format("DW_AT_Unknown_%x", attr); |
| 77 | const char *formString = FormEncodingString(form); |
| 78 | if (formString) |
| 79 | OS << " [" << formString << ']'; |
| 80 | else |
| 81 | OS << format(" [DW_FORM_Unknown_%x]", form); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 82 | |
| 83 | DWARFFormValue formValue(form); |
| 84 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 85 | if (!formValue.extractValue(u->getDebugInfoExtractor(), offset_ptr, u)) |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 86 | return; |
| 87 | |
| 88 | OS << "\t("; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 89 | formValue.dump(OS, u); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 90 | OS << ")\n"; |
| 91 | } |
| 92 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 93 | bool DWARFDebugInfoEntryMinimal::extractFast(const DWARFUnit *U, |
Alexey Samsonov | d6b89ef | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 94 | uint32_t *OffsetPtr) { |
| 95 | Offset = *OffsetPtr; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 96 | DataExtractor DebugInfoData = U->getDebugInfoExtractor(); |
Alexey Samsonov | 39f62fa | 2013-10-28 23:58:58 +0000 | [diff] [blame] | 97 | uint32_t UEndOffset = U->getNextUnitOffset(); |
| 98 | if (Offset >= UEndOffset || !DebugInfoData.isValidOffset(Offset)) |
Alexey Samsonov | d6b89ef | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 99 | return false; |
| 100 | uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr); |
| 101 | if (0 == AbbrCode) { |
| 102 | // NULL debug tag entry. |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 103 | AbbrevDecl = nullptr; |
Alexey Samsonov | d6b89ef | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 104 | return true; |
| 105 | } |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 106 | AbbrevDecl = U->getAbbreviations()->getAbbreviationDeclaration(AbbrCode); |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 107 | if (nullptr == AbbrevDecl) { |
Alexey Samsonov | d6b89ef | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 108 | // Restore the original offset. |
| 109 | *OffsetPtr = Offset; |
| 110 | return false; |
| 111 | } |
Alexey Samsonov | 39f62fa | 2013-10-28 23:58:58 +0000 | [diff] [blame] | 112 | ArrayRef<uint8_t> FixedFormSizes = DWARFFormValue::getFixedFormSizes( |
| 113 | U->getAddressByteSize(), U->getVersion()); |
| 114 | assert(FixedFormSizes.size() > 0); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 115 | |
Alexey Samsonov | d6b89ef | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 116 | // Skip all data in the .debug_info for the attributes |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 117 | for (const auto &AttrSpec : AbbrevDecl->attributes()) { |
| 118 | uint16_t Form = AttrSpec.Form; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 119 | |
Alexey Samsonov | 39f62fa | 2013-10-28 23:58:58 +0000 | [diff] [blame] | 120 | uint8_t FixedFormSize = |
| 121 | (Form < FixedFormSizes.size()) ? FixedFormSizes[Form] : 0; |
| 122 | if (FixedFormSize) |
| 123 | *OffsetPtr += FixedFormSize; |
| 124 | else if (!DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, U)) { |
Alexey Samsonov | d6b89ef | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 125 | // Restore the original offset. |
| 126 | *OffsetPtr = Offset; |
| 127 | return false; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 128 | } |
| 129 | } |
Alexey Samsonov | d6b89ef | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 130 | return true; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 133 | bool DWARFDebugInfoEntryMinimal::isSubprogramDIE() const { |
| 134 | return getTag() == DW_TAG_subprogram; |
| 135 | } |
| 136 | |
| 137 | bool DWARFDebugInfoEntryMinimal::isSubroutineDIE() const { |
| 138 | uint32_t Tag = getTag(); |
| 139 | return Tag == DW_TAG_subprogram || |
| 140 | Tag == DW_TAG_inlined_subroutine; |
| 141 | } |
| 142 | |
Alexey Samsonov | 2e56d57 | 2013-10-17 13:28:16 +0000 | [diff] [blame] | 143 | bool DWARFDebugInfoEntryMinimal::getAttributeValue( |
| 144 | const DWARFUnit *U, const uint16_t Attr, DWARFFormValue &FormValue) const { |
| 145 | if (!AbbrevDecl) |
| 146 | return false; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 147 | |
Alexey Samsonov | 2e56d57 | 2013-10-17 13:28:16 +0000 | [diff] [blame] | 148 | uint32_t AttrIdx = AbbrevDecl->findAttributeIndex(Attr); |
| 149 | if (AttrIdx == -1U) |
| 150 | return false; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 151 | |
Alexey Samsonov | 2e56d57 | 2013-10-17 13:28:16 +0000 | [diff] [blame] | 152 | DataExtractor DebugInfoData = U->getDebugInfoExtractor(); |
| 153 | uint32_t DebugInfoOffset = getOffset(); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 154 | |
Alexey Samsonov | 2e56d57 | 2013-10-17 13:28:16 +0000 | [diff] [blame] | 155 | // Skip the abbreviation code so we are at the data for the attributes |
| 156 | DebugInfoData.getULEB128(&DebugInfoOffset); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 157 | |
Alexey Samsonov | 2e56d57 | 2013-10-17 13:28:16 +0000 | [diff] [blame] | 158 | // Skip preceding attribute values. |
| 159 | for (uint32_t i = 0; i < AttrIdx; ++i) { |
| 160 | DWARFFormValue::skipValue(AbbrevDecl->getFormByIndex(i), |
| 161 | DebugInfoData, &DebugInfoOffset, U); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Alexey Samsonov | 2e56d57 | 2013-10-17 13:28:16 +0000 | [diff] [blame] | 164 | FormValue = DWARFFormValue(AbbrevDecl->getFormByIndex(AttrIdx)); |
| 165 | return FormValue.extractValue(DebugInfoData, &DebugInfoOffset, U); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 168 | const char *DWARFDebugInfoEntryMinimal::getAttributeValueAsString( |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 169 | const DWARFUnit *U, const uint16_t Attr, const char *FailValue) const { |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 170 | DWARFFormValue FormValue; |
Alexey Samsonov | c525323 | 2013-10-28 23:01:48 +0000 | [diff] [blame] | 171 | if (!getAttributeValue(U, Attr, FormValue)) |
| 172 | return FailValue; |
| 173 | Optional<const char *> Result = FormValue.getAsCString(U); |
| 174 | return Result.hasValue() ? Result.getValue() : FailValue; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 177 | uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsAddress( |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 178 | const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const { |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 179 | DWARFFormValue FormValue; |
Alexey Samsonov | c525323 | 2013-10-28 23:01:48 +0000 | [diff] [blame] | 180 | if (!getAttributeValue(U, Attr, FormValue)) |
| 181 | return FailValue; |
| 182 | Optional<uint64_t> Result = FormValue.getAsAddress(U); |
| 183 | return Result.hasValue() ? Result.getValue() : FailValue; |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Alexey Samsonov | c525323 | 2013-10-28 23:01:48 +0000 | [diff] [blame] | 186 | uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsUnsignedConstant( |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 187 | const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const { |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 188 | DWARFFormValue FormValue; |
Alexey Samsonov | c525323 | 2013-10-28 23:01:48 +0000 | [diff] [blame] | 189 | if (!getAttributeValue(U, Attr, FormValue)) |
| 190 | return FailValue; |
| 191 | Optional<uint64_t> Result = FormValue.getAsUnsignedConstant(); |
| 192 | return Result.hasValue() ? Result.getValue() : FailValue; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 193 | } |
| 194 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 195 | uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsReference( |
Alexey Samsonov | 2e56d57 | 2013-10-17 13:28:16 +0000 | [diff] [blame] | 196 | const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const { |
| 197 | DWARFFormValue FormValue; |
Alexey Samsonov | c525323 | 2013-10-28 23:01:48 +0000 | [diff] [blame] | 198 | if (!getAttributeValue(U, Attr, FormValue)) |
| 199 | return FailValue; |
| 200 | Optional<uint64_t> Result = FormValue.getAsReference(U); |
| 201 | return Result.hasValue() ? Result.getValue() : FailValue; |
| 202 | } |
| 203 | |
| 204 | uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsSectionOffset( |
| 205 | const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const { |
| 206 | DWARFFormValue FormValue; |
| 207 | if (!getAttributeValue(U, Attr, FormValue)) |
| 208 | return FailValue; |
| 209 | Optional<uint64_t> Result = FormValue.getAsSectionOffset(); |
| 210 | return Result.hasValue() ? Result.getValue() : FailValue; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 211 | } |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 212 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 213 | bool DWARFDebugInfoEntryMinimal::getLowAndHighPC(const DWARFUnit *U, |
Eric Christopher | 203e6f6 | 2012-10-30 21:36:43 +0000 | [diff] [blame] | 214 | uint64_t &LowPC, |
| 215 | uint64_t &HighPC) const { |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 216 | LowPC = getAttributeValueAsAddress(U, DW_AT_low_pc, -1ULL); |
Alexey Samsonov | d2d54e2 | 2013-10-28 23:15:15 +0000 | [diff] [blame] | 217 | if (LowPC == -1ULL) |
| 218 | return false; |
| 219 | HighPC = getAttributeValueAsAddress(U, DW_AT_high_pc, -1ULL); |
| 220 | if (HighPC == -1ULL) { |
| 221 | // Since DWARF4, DW_AT_high_pc may also be of class constant, in which case |
| 222 | // it represents function size. |
| 223 | HighPC = getAttributeValueAsUnsignedConstant(U, DW_AT_high_pc, -1ULL); |
| 224 | if (HighPC != -1ULL) |
| 225 | HighPC += LowPC; |
| 226 | } |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 227 | return (HighPC != -1ULL); |
| 228 | } |
| 229 | |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 230 | DWARFAddressRangesVector |
| 231 | DWARFDebugInfoEntryMinimal::getAddressRanges(const DWARFUnit *U) const { |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 232 | if (isNULL()) |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 233 | return DWARFAddressRangesVector(); |
| 234 | // Single range specified by low/high PC. |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 235 | uint64_t LowPC, HighPC; |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 236 | if (getLowAndHighPC(U, LowPC, HighPC)) { |
| 237 | return DWARFAddressRangesVector(1, std::make_pair(LowPC, HighPC)); |
| 238 | } |
| 239 | // Multiple ranges from .debug_ranges section. |
Alexey Samsonov | c525323 | 2013-10-28 23:01:48 +0000 | [diff] [blame] | 240 | uint32_t RangesOffset = |
| 241 | getAttributeValueAsSectionOffset(U, DW_AT_ranges, -1U); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 242 | if (RangesOffset != -1U) { |
| 243 | DWARFDebugRangeList RangeList; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 244 | if (U->extractRangeList(RangesOffset, RangeList)) |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 245 | return RangeList.getAbsoluteRanges(U->getBaseAddress()); |
| 246 | } |
| 247 | return DWARFAddressRangesVector(); |
| 248 | } |
| 249 | |
| 250 | void DWARFDebugInfoEntryMinimal::collectChildrenAddressRanges( |
| 251 | const DWARFUnit *U, DWARFAddressRangesVector& Ranges) const { |
| 252 | if (isNULL()) |
| 253 | return; |
| 254 | if (isSubprogramDIE()) { |
| 255 | const auto &DIERanges = getAddressRanges(U); |
| 256 | Ranges.insert(Ranges.end(), DIERanges.begin(), DIERanges.end()); |
| 257 | } |
| 258 | |
| 259 | const DWARFDebugInfoEntryMinimal *Child = getFirstChild(); |
| 260 | while (Child) { |
| 261 | Child->collectChildrenAddressRanges(U, Ranges); |
| 262 | Child = Child->getSibling(); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | bool DWARFDebugInfoEntryMinimal::addressRangeContainsAddress( |
| 267 | const DWARFUnit *U, const uint64_t Address) const { |
| 268 | for (const auto& R : getAddressRanges(U)) { |
| 269 | if (R.first <= Address && Address < R.second) |
| 270 | return true; |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 271 | } |
| 272 | return false; |
| 273 | } |
| 274 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 275 | const char * |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 276 | DWARFDebugInfoEntryMinimal::getSubroutineName(const DWARFUnit *U, |
| 277 | FunctionNameKind Kind) const { |
| 278 | if (!isSubroutineDIE() || Kind == FunctionNameKind::None) |
| 279 | return nullptr; |
| 280 | // Try to get mangled name only if it was asked for. |
| 281 | if (Kind == FunctionNameKind::LinkageName) { |
| 282 | if (const char *name = |
| 283 | getAttributeValueAsString(U, DW_AT_MIPS_linkage_name, nullptr)) |
| 284 | return name; |
| 285 | if (const char *name = |
| 286 | getAttributeValueAsString(U, DW_AT_linkage_name, nullptr)) |
| 287 | return name; |
| 288 | } |
| 289 | if (const char *name = getAttributeValueAsString(U, DW_AT_name, nullptr)) |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 290 | return name; |
| 291 | // Try to get name from specification DIE. |
| 292 | uint32_t spec_ref = |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 293 | getAttributeValueAsReference(U, DW_AT_specification, -1U); |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 294 | if (spec_ref != -1U) { |
| 295 | DWARFDebugInfoEntryMinimal spec_die; |
Alexey Samsonov | 39f62fa | 2013-10-28 23:58:58 +0000 | [diff] [blame] | 296 | if (spec_die.extractFast(U, &spec_ref)) { |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 297 | if (const char *name = spec_die.getSubroutineName(U, Kind)) |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 298 | return name; |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 299 | } |
| 300 | } |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 301 | // Try to get name from abstract origin DIE. |
| 302 | uint32_t abs_origin_ref = |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 303 | getAttributeValueAsReference(U, DW_AT_abstract_origin, -1U); |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 304 | if (abs_origin_ref != -1U) { |
| 305 | DWARFDebugInfoEntryMinimal abs_origin_die; |
Alexey Samsonov | 39f62fa | 2013-10-28 23:58:58 +0000 | [diff] [blame] | 306 | if (abs_origin_die.extractFast(U, &abs_origin_ref)) { |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 307 | if (const char *name = abs_origin_die.getSubroutineName(U, Kind)) |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 308 | return name; |
| 309 | } |
| 310 | } |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 311 | return nullptr; |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 312 | } |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 313 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 314 | void DWARFDebugInfoEntryMinimal::getCallerFrame(const DWARFUnit *U, |
Eric Christopher | 203e6f6 | 2012-10-30 21:36:43 +0000 | [diff] [blame] | 315 | uint32_t &CallFile, |
| 316 | uint32_t &CallLine, |
| 317 | uint32_t &CallColumn) const { |
Alexey Samsonov | c525323 | 2013-10-28 23:01:48 +0000 | [diff] [blame] | 318 | CallFile = getAttributeValueAsUnsignedConstant(U, DW_AT_call_file, 0); |
| 319 | CallLine = getAttributeValueAsUnsignedConstant(U, DW_AT_call_line, 0); |
| 320 | CallColumn = getAttributeValueAsUnsignedConstant(U, DW_AT_call_column, 0); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Alexey Samsonov | e664290 | 2013-08-06 10:49:15 +0000 | [diff] [blame] | 323 | DWARFDebugInfoEntryInlinedChain |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 324 | DWARFDebugInfoEntryMinimal::getInlinedChainForAddress( |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 325 | const DWARFUnit *U, const uint64_t Address) const { |
Alexey Samsonov | e664290 | 2013-08-06 10:49:15 +0000 | [diff] [blame] | 326 | DWARFDebugInfoEntryInlinedChain InlinedChain; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 327 | InlinedChain.U = U; |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 328 | if (isNULL()) |
| 329 | return InlinedChain; |
| 330 | for (const DWARFDebugInfoEntryMinimal *DIE = this; DIE; ) { |
| 331 | // Append current DIE to inlined chain only if it has correct tag |
| 332 | // (e.g. it is not a lexical block). |
| 333 | if (DIE->isSubroutineDIE()) { |
Alexey Samsonov | e664290 | 2013-08-06 10:49:15 +0000 | [diff] [blame] | 334 | InlinedChain.DIEs.push_back(*DIE); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 335 | } |
| 336 | // Try to get child which also contains provided address. |
| 337 | const DWARFDebugInfoEntryMinimal *Child = DIE->getFirstChild(); |
| 338 | while (Child) { |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 339 | if (Child->addressRangeContainsAddress(U, Address)) { |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 340 | // Assume there is only one such child. |
| 341 | break; |
| 342 | } |
| 343 | Child = Child->getSibling(); |
| 344 | } |
| 345 | DIE = Child; |
| 346 | } |
| 347 | // Reverse the obtained chain to make the root of inlined chain last. |
Alexey Samsonov | e664290 | 2013-08-06 10:49:15 +0000 | [diff] [blame] | 348 | std::reverse(InlinedChain.DIEs.begin(), InlinedChain.DIEs.end()); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 349 | return InlinedChain; |
| 350 | } |