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 | d6b89ef | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 163 | if (Attr == DW_AT_low_pc || Attr == DW_AT_entry_pc) |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 164 | const_cast<DWARFUnit *>(U)->setBaseAddress(FormValue.getUnsigned()); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 165 | } |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 166 | } else if (!DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, U)) { |
Alexey Samsonov | d6b89ef | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 167 | // Restore the original offset. |
| 168 | *OffsetPtr = Offset; |
| 169 | return false; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 170 | } |
| 171 | } |
Alexey Samsonov | d6b89ef | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 172 | return true; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 175 | bool DWARFDebugInfoEntryMinimal::isSubprogramDIE() const { |
| 176 | return getTag() == DW_TAG_subprogram; |
| 177 | } |
| 178 | |
| 179 | bool DWARFDebugInfoEntryMinimal::isSubroutineDIE() const { |
| 180 | uint32_t Tag = getTag(); |
| 181 | return Tag == DW_TAG_subprogram || |
| 182 | Tag == DW_TAG_inlined_subroutine; |
| 183 | } |
| 184 | |
Alexey Samsonov | 2e56d57 | 2013-10-17 13:28:16 +0000 | [diff] [blame] | 185 | bool DWARFDebugInfoEntryMinimal::getAttributeValue( |
| 186 | const DWARFUnit *U, const uint16_t Attr, DWARFFormValue &FormValue) const { |
| 187 | if (!AbbrevDecl) |
| 188 | return false; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 189 | |
Alexey Samsonov | 2e56d57 | 2013-10-17 13:28:16 +0000 | [diff] [blame] | 190 | uint32_t AttrIdx = AbbrevDecl->findAttributeIndex(Attr); |
| 191 | if (AttrIdx == -1U) |
| 192 | return false; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 193 | |
Alexey Samsonov | 2e56d57 | 2013-10-17 13:28:16 +0000 | [diff] [blame] | 194 | DataExtractor DebugInfoData = U->getDebugInfoExtractor(); |
| 195 | uint32_t DebugInfoOffset = getOffset(); |
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 | // Skip the abbreviation code so we are at the data for the attributes |
| 198 | DebugInfoData.getULEB128(&DebugInfoOffset); |
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 preceding attribute values. |
| 201 | for (uint32_t i = 0; i < AttrIdx; ++i) { |
| 202 | DWARFFormValue::skipValue(AbbrevDecl->getFormByIndex(i), |
| 203 | DebugInfoData, &DebugInfoOffset, U); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Alexey Samsonov | 2e56d57 | 2013-10-17 13:28:16 +0000 | [diff] [blame] | 206 | FormValue = DWARFFormValue(AbbrevDecl->getFormByIndex(AttrIdx)); |
| 207 | return FormValue.extractValue(DebugInfoData, &DebugInfoOffset, U); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 210 | const char *DWARFDebugInfoEntryMinimal::getAttributeValueAsString( |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 211 | const DWARFUnit *U, const uint16_t Attr, const char *FailValue) const { |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 212 | DWARFFormValue FormValue; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 213 | if (getAttributeValue(U, Attr, FormValue)) |
| 214 | return FormValue.getAsCString(U); |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 215 | return FailValue; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 218 | uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsAddress( |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 219 | const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const { |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 220 | DWARFFormValue FormValue; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 221 | if (getAttributeValue(U, Attr, FormValue)) |
| 222 | return FormValue.getAsAddress(U); |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 223 | return FailValue; |
| 224 | } |
| 225 | |
| 226 | uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsUnsigned( |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 227 | const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const { |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 228 | DWARFFormValue FormValue; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 229 | if (getAttributeValue(U, Attr, FormValue)) |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 230 | return FormValue.getUnsigned(); |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 231 | return FailValue; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 232 | } |
| 233 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 234 | uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsReference( |
Alexey Samsonov | 2e56d57 | 2013-10-17 13:28:16 +0000 | [diff] [blame] | 235 | const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const { |
| 236 | DWARFFormValue FormValue; |
| 237 | if (getAttributeValue(U, Attr, FormValue)) |
| 238 | return FormValue.getReference(U); |
| 239 | return FailValue; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 240 | } |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 241 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 242 | bool DWARFDebugInfoEntryMinimal::getLowAndHighPC(const DWARFUnit *U, |
Eric Christopher | 203e6f6 | 2012-10-30 21:36:43 +0000 | [diff] [blame] | 243 | uint64_t &LowPC, |
| 244 | uint64_t &HighPC) const { |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 245 | HighPC = -1ULL; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 246 | LowPC = getAttributeValueAsAddress(U, DW_AT_low_pc, -1ULL); |
Alexey Samsonov | 2e56d57 | 2013-10-17 13:28:16 +0000 | [diff] [blame] | 247 | // FIXME: Check if HighPC is of class constant (it has different semantics). |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 248 | if (LowPC != -1ULL) |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 249 | HighPC = getAttributeValueAsAddress(U, DW_AT_high_pc, -1ULL); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 250 | return (HighPC != -1ULL); |
| 251 | } |
| 252 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 253 | void DWARFDebugInfoEntryMinimal::buildAddressRangeTable( |
| 254 | const DWARFUnit *U, DWARFDebugAranges *DebugAranges, |
| 255 | uint32_t UOffsetInAranges) const { |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 256 | if (AbbrevDecl) { |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 257 | if (isSubprogramDIE()) { |
| 258 | uint64_t LowPC, HighPC; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 259 | if (getLowAndHighPC(U, LowPC, HighPC)) |
| 260 | DebugAranges->appendRange(UOffsetInAranges, LowPC, HighPC); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 261 | // FIXME: try to append ranges from .debug_ranges section. |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 264 | const DWARFDebugInfoEntryMinimal *Child = getFirstChild(); |
| 265 | while (Child) { |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 266 | Child->buildAddressRangeTable(U, DebugAranges, UOffsetInAranges); |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 267 | Child = Child->getSibling(); |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | } |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 271 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 272 | bool DWARFDebugInfoEntryMinimal::addressRangeContainsAddress( |
| 273 | const DWARFUnit *U, const uint64_t Address) const { |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 274 | if (isNULL()) |
| 275 | return false; |
| 276 | uint64_t LowPC, HighPC; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 277 | if (getLowAndHighPC(U, LowPC, HighPC)) |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 278 | return (LowPC <= Address && Address <= HighPC); |
| 279 | // Try to get address ranges from .debug_ranges section. |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 280 | uint32_t RangesOffset = getAttributeValueAsReference(U, DW_AT_ranges, -1U); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 281 | if (RangesOffset != -1U) { |
| 282 | DWARFDebugRangeList RangeList; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 283 | if (U->extractRangeList(RangesOffset, RangeList)) |
| 284 | return RangeList.containsAddress(U->getBaseAddress(), Address); |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 285 | } |
| 286 | return false; |
| 287 | } |
| 288 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 289 | const char * |
| 290 | DWARFDebugInfoEntryMinimal::getSubroutineName(const DWARFUnit *U) const { |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 291 | if (!isSubroutineDIE()) |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 292 | return 0; |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 293 | // Try to get mangled name if possible. |
| 294 | if (const char *name = |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 295 | getAttributeValueAsString(U, DW_AT_MIPS_linkage_name, 0)) |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 296 | return name; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 297 | if (const char *name = getAttributeValueAsString(U, DW_AT_linkage_name, 0)) |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 298 | return name; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 299 | if (const char *name = getAttributeValueAsString(U, DW_AT_name, 0)) |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 300 | return name; |
| 301 | // Try to get name from specification DIE. |
| 302 | uint32_t spec_ref = |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 303 | getAttributeValueAsReference(U, DW_AT_specification, -1U); |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 304 | if (spec_ref != -1U) { |
| 305 | DWARFDebugInfoEntryMinimal spec_die; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 306 | if (spec_die.extract(U, &spec_ref)) { |
| 307 | if (const char *name = spec_die.getSubroutineName(U)) |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 308 | return name; |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 309 | } |
| 310 | } |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 311 | // Try to get name from abstract origin DIE. |
| 312 | uint32_t abs_origin_ref = |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 313 | getAttributeValueAsReference(U, DW_AT_abstract_origin, -1U); |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 314 | if (abs_origin_ref != -1U) { |
| 315 | DWARFDebugInfoEntryMinimal abs_origin_die; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 316 | if (abs_origin_die.extract(U, &abs_origin_ref)) { |
| 317 | if (const char *name = abs_origin_die.getSubroutineName(U)) |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 318 | return name; |
| 319 | } |
| 320 | } |
| 321 | return 0; |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 322 | } |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 323 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 324 | void DWARFDebugInfoEntryMinimal::getCallerFrame(const DWARFUnit *U, |
Eric Christopher | 203e6f6 | 2012-10-30 21:36:43 +0000 | [diff] [blame] | 325 | uint32_t &CallFile, |
| 326 | uint32_t &CallLine, |
| 327 | uint32_t &CallColumn) const { |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 328 | CallFile = getAttributeValueAsUnsigned(U, DW_AT_call_file, 0); |
| 329 | CallLine = getAttributeValueAsUnsigned(U, DW_AT_call_line, 0); |
| 330 | CallColumn = getAttributeValueAsUnsigned(U, DW_AT_call_column, 0); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Alexey Samsonov | e664290 | 2013-08-06 10:49:15 +0000 | [diff] [blame] | 333 | DWARFDebugInfoEntryInlinedChain |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 334 | DWARFDebugInfoEntryMinimal::getInlinedChainForAddress( |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 335 | const DWARFUnit *U, const uint64_t Address) const { |
Alexey Samsonov | e664290 | 2013-08-06 10:49:15 +0000 | [diff] [blame] | 336 | DWARFDebugInfoEntryInlinedChain InlinedChain; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 337 | InlinedChain.U = U; |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 338 | if (isNULL()) |
| 339 | return InlinedChain; |
| 340 | for (const DWARFDebugInfoEntryMinimal *DIE = this; DIE; ) { |
| 341 | // Append current DIE to inlined chain only if it has correct tag |
| 342 | // (e.g. it is not a lexical block). |
| 343 | if (DIE->isSubroutineDIE()) { |
Alexey Samsonov | e664290 | 2013-08-06 10:49:15 +0000 | [diff] [blame] | 344 | InlinedChain.DIEs.push_back(*DIE); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 345 | } |
| 346 | // Try to get child which also contains provided address. |
| 347 | const DWARFDebugInfoEntryMinimal *Child = DIE->getFirstChild(); |
| 348 | while (Child) { |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 349 | if (Child->addressRangeContainsAddress(U, Address)) { |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 350 | // Assume there is only one such child. |
| 351 | break; |
| 352 | } |
| 353 | Child = Child->getSibling(); |
| 354 | } |
| 355 | DIE = Child; |
| 356 | } |
| 357 | // Reverse the obtained chain to make the root of inlined chain last. |
Alexey Samsonov | e664290 | 2013-08-06 10:49:15 +0000 | [diff] [blame] | 358 | std::reverse(InlinedChain.DIEs.begin(), InlinedChain.DIEs.end()); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 359 | return InlinedChain; |
| 360 | } |