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