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