Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 1 | //===-- DWARFCompileUnit.cpp ----------------------------------------------===// |
| 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 "DWARFCompileUnit.h" |
| 11 | #include "DWARFContext.h" |
Alexey Samsonov | cd61455 | 2013-04-17 08:29:02 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/DWARFFormValue.h" |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 13 | #include "llvm/Support/Dwarf.h" |
| 14 | #include "llvm/Support/Format.h" |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 15 | #include "llvm/Support/Path.h" |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 16 | #include "llvm/Support/raw_ostream.h" |
| 17 | using namespace llvm; |
| 18 | using namespace dwarf; |
| 19 | |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 20 | bool DWARFCompileUnit::getAddrOffsetSectionItem(uint32_t Index, |
| 21 | uint64_t &Result) const { |
| 22 | uint32_t Offset = AddrOffsetSectionBase + Index * AddrSize; |
| 23 | if (AddrOffsetSection.size() < Offset + AddrSize) |
| 24 | return false; |
| 25 | DataExtractor DA(AddrOffsetSection, isLittleEndian, AddrSize); |
| 26 | Result = DA.getAddress(&Offset); |
| 27 | return true; |
| 28 | } |
| 29 | |
| 30 | bool DWARFCompileUnit::getStringOffsetSectionItem(uint32_t Index, |
| 31 | uint32_t &Result) const { |
| 32 | // FIXME: string offset section entries are 8-byte for DWARF64. |
| 33 | const uint32_t ItemSize = 4; |
| 34 | uint32_t Offset = Index * ItemSize; |
| 35 | if (StringOffsetSection.size() < Offset + ItemSize) |
| 36 | return false; |
| 37 | DataExtractor DA(StringOffsetSection, isLittleEndian, 0); |
| 38 | Result = DA.getU32(&Offset); |
| 39 | return true; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | bool DWARFCompileUnit::extract(DataExtractor debug_info, uint32_t *offset_ptr) { |
| 43 | clear(); |
| 44 | |
| 45 | Offset = *offset_ptr; |
| 46 | |
| 47 | if (debug_info.isValidOffset(*offset_ptr)) { |
| 48 | uint64_t abbrOffset; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 49 | Length = debug_info.getU32(offset_ptr); |
| 50 | Version = debug_info.getU16(offset_ptr); |
| 51 | abbrOffset = debug_info.getU32(offset_ptr); |
| 52 | AddrSize = debug_info.getU8(offset_ptr); |
| 53 | |
| 54 | bool lengthOK = debug_info.isValidOffset(getNextCompileUnitOffset()-1); |
| 55 | bool versionOK = DWARFContext::isSupportedVersion(Version); |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 56 | bool abbrOffsetOK = AbbrevSection.size() > abbrOffset; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 57 | bool addrSizeOK = AddrSize == 4 || AddrSize == 8; |
| 58 | |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 59 | if (lengthOK && versionOK && addrSizeOK && abbrOffsetOK && Abbrev != NULL) { |
| 60 | Abbrevs = Abbrev->getAbbreviationDeclarationSet(abbrOffset); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 61 | return true; |
| 62 | } |
| 63 | |
| 64 | // reset the offset to where we tried to parse from if anything went wrong |
| 65 | *offset_ptr = Offset; |
| 66 | } |
| 67 | |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | uint32_t |
| 72 | DWARFCompileUnit::extract(uint32_t offset, DataExtractor debug_info_data, |
| 73 | const DWARFAbbreviationDeclarationSet *abbrevs) { |
| 74 | clear(); |
| 75 | |
| 76 | Offset = offset; |
| 77 | |
| 78 | if (debug_info_data.isValidOffset(offset)) { |
| 79 | Length = debug_info_data.getU32(&offset); |
| 80 | Version = debug_info_data.getU16(&offset); |
| 81 | bool abbrevsOK = debug_info_data.getU32(&offset) == abbrevs->getOffset(); |
| 82 | Abbrevs = abbrevs; |
Eric Christopher | 5d04a3a | 2012-08-23 23:26:57 +0000 | [diff] [blame] | 83 | AddrSize = debug_info_data.getU8(&offset); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 84 | |
| 85 | bool versionOK = DWARFContext::isSupportedVersion(Version); |
| 86 | bool addrSizeOK = AddrSize == 4 || AddrSize == 8; |
| 87 | |
| 88 | if (versionOK && addrSizeOK && abbrevsOK && |
| 89 | debug_info_data.isValidOffset(offset)) |
| 90 | return offset; |
| 91 | } |
| 92 | return 0; |
| 93 | } |
| 94 | |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 95 | bool DWARFCompileUnit::extractRangeList(uint32_t RangeListOffset, |
| 96 | DWARFDebugRangeList &RangeList) const { |
| 97 | // Require that compile unit is extracted. |
| 98 | assert(DieArray.size() > 0); |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 99 | DataExtractor RangesData(RangeSection, isLittleEndian, AddrSize); |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 100 | uint32_t ActualRangeListOffset = RangeSectionBase + RangeListOffset; |
| 101 | return RangeList.extract(RangesData, &ActualRangeListOffset); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 104 | void DWARFCompileUnit::clear() { |
| 105 | Offset = 0; |
| 106 | Length = 0; |
| 107 | Version = 0; |
| 108 | Abbrevs = 0; |
| 109 | AddrSize = 0; |
| 110 | BaseAddr = 0; |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 111 | RangeSectionBase = 0; |
| 112 | AddrOffsetSectionBase = 0; |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 113 | clearDIEs(false); |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 114 | DWO.reset(); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | void DWARFCompileUnit::dump(raw_ostream &OS) { |
| 118 | OS << format("0x%08x", Offset) << ": Compile Unit:" |
| 119 | << " length = " << format("0x%08x", Length) |
| 120 | << " version = " << format("0x%04x", Version) |
| 121 | << " abbr_offset = " << format("0x%04x", Abbrevs->getOffset()) |
| 122 | << " addr_size = " << format("0x%02x", AddrSize) |
| 123 | << " (next CU at " << format("0x%08x", getNextCompileUnitOffset()) |
| 124 | << ")\n"; |
| 125 | |
Eric Christopher | fa76f22 | 2012-08-23 23:21:11 +0000 | [diff] [blame] | 126 | const DWARFDebugInfoEntryMinimal *CU = getCompileUnitDIE(false); |
| 127 | assert(CU && "Null Compile Unit?"); |
| 128 | CU->dump(OS, this, -1U); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Alexey Samsonov | 71d94f8 | 2012-07-19 07:03:58 +0000 | [diff] [blame] | 131 | const char *DWARFCompileUnit::getCompilationDir() { |
| 132 | extractDIEsIfNeeded(true); |
| 133 | if (DieArray.empty()) |
| 134 | return 0; |
| 135 | return DieArray[0].getAttributeValueAsString(this, DW_AT_comp_dir, 0); |
| 136 | } |
| 137 | |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 138 | uint64_t DWARFCompileUnit::getDWOId() { |
| 139 | extractDIEsIfNeeded(true); |
| 140 | const uint64_t FailValue = -1ULL; |
| 141 | if (DieArray.empty()) |
| 142 | return FailValue; |
| 143 | return DieArray[0] |
| 144 | .getAttributeValueAsUnsigned(this, DW_AT_GNU_dwo_id, FailValue); |
| 145 | } |
| 146 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 147 | void DWARFCompileUnit::setDIERelations() { |
| 148 | if (DieArray.empty()) |
| 149 | return; |
| 150 | DWARFDebugInfoEntryMinimal *die_array_begin = &DieArray.front(); |
| 151 | DWARFDebugInfoEntryMinimal *die_array_end = &DieArray.back(); |
| 152 | DWARFDebugInfoEntryMinimal *curr_die; |
| 153 | // We purposely are skipping the last element in the array in the loop below |
| 154 | // so that we can always have a valid next item |
| 155 | for (curr_die = die_array_begin; curr_die < die_array_end; ++curr_die) { |
| 156 | // Since our loop doesn't include the last element, we can always |
| 157 | // safely access the next die in the array. |
| 158 | DWARFDebugInfoEntryMinimal *next_die = curr_die + 1; |
| 159 | |
| 160 | const DWARFAbbreviationDeclaration *curr_die_abbrev = |
| 161 | curr_die->getAbbreviationDeclarationPtr(); |
| 162 | |
| 163 | if (curr_die_abbrev) { |
| 164 | // Normal DIE |
| 165 | if (curr_die_abbrev->hasChildren()) |
| 166 | next_die->setParent(curr_die); |
| 167 | else |
| 168 | curr_die->setSibling(next_die); |
| 169 | } else { |
| 170 | // NULL DIE that terminates a sibling chain |
| 171 | DWARFDebugInfoEntryMinimal *parent = curr_die->getParent(); |
| 172 | if (parent) |
| 173 | parent->setSibling(next_die); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // Since we skipped the last element, we need to fix it up! |
| 178 | if (die_array_begin < die_array_end) |
| 179 | curr_die->setParent(die_array_begin); |
| 180 | } |
| 181 | |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 182 | void DWARFCompileUnit::extractDIEsToVector( |
| 183 | bool AppendCUDie, bool AppendNonCUDies, |
| 184 | std::vector<DWARFDebugInfoEntryMinimal> &Dies) const { |
| 185 | if (!AppendCUDie && !AppendNonCUDies) |
| 186 | return; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 187 | |
| 188 | // Set the offset to that of the first DIE and calculate the start of the |
| 189 | // next compilation unit header. |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 190 | uint32_t Offset = getFirstDIEOffset(); |
| 191 | uint32_t NextCUOffset = getNextCompileUnitOffset(); |
| 192 | DWARFDebugInfoEntryMinimal DIE; |
| 193 | uint32_t Depth = 0; |
| 194 | const uint8_t *FixedFormSizes = |
Alexey Samsonov | 32a3e78 | 2013-04-09 14:09:42 +0000 | [diff] [blame] | 195 | DWARFFormValue::getFixedFormSizes(getAddressByteSize(), getVersion()); |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 196 | bool IsCUDie = true; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 197 | |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 198 | while (Offset < NextCUOffset && |
| 199 | DIE.extractFast(this, FixedFormSizes, &Offset)) { |
| 200 | if (IsCUDie) { |
| 201 | if (AppendCUDie) |
| 202 | Dies.push_back(DIE); |
| 203 | if (!AppendNonCUDies) |
| 204 | break; |
| 205 | // The average bytes per DIE entry has been seen to be |
| 206 | // around 14-20 so let's pre-reserve the needed memory for |
| 207 | // our DIE entries accordingly. |
| 208 | Dies.reserve(Dies.size() + getDebugInfoSize() / 14); |
| 209 | IsCUDie = false; |
| 210 | } else { |
| 211 | Dies.push_back(DIE); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 214 | const DWARFAbbreviationDeclaration *AbbrDecl = |
| 215 | DIE.getAbbreviationDeclarationPtr(); |
| 216 | if (AbbrDecl) { |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 217 | // Normal DIE |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 218 | if (AbbrDecl->hasChildren()) |
| 219 | ++Depth; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 220 | } else { |
| 221 | // NULL DIE. |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 222 | if (Depth > 0) |
| 223 | --Depth; |
| 224 | if (Depth == 0) |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 225 | break; // We are done with this compile unit! |
| 226 | } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | // Give a little bit of info if we encounter corrupt DWARF (our offset |
| 230 | // should always terminate at or before the start of the next compilation |
| 231 | // unit header). |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 232 | if (Offset > NextCUOffset) |
Eric Christopher | 642469f | 2013-01-04 18:30:36 +0000 | [diff] [blame] | 233 | fprintf(stderr, "warning: DWARF compile unit extends beyond its " |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 234 | "bounds cu 0x%8.8x at 0x%8.8x'\n", getOffset(), Offset); |
| 235 | } |
| 236 | |
| 237 | size_t DWARFCompileUnit::extractDIEsIfNeeded(bool CUDieOnly) { |
| 238 | if ((CUDieOnly && DieArray.size() > 0) || |
| 239 | DieArray.size() > 1) |
| 240 | return 0; // Already parsed. |
| 241 | |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 242 | bool HasCUDie = DieArray.size() > 0; |
| 243 | extractDIEsToVector(!HasCUDie, !CUDieOnly, DieArray); |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 244 | |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 245 | if (DieArray.empty()) |
| 246 | return 0; |
| 247 | |
| 248 | // If CU DIE was just parsed, copy several attribute values from it. |
| 249 | if (!HasCUDie) { |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 250 | uint64_t BaseAddr = |
| 251 | DieArray[0].getAttributeValueAsUnsigned(this, DW_AT_low_pc, -1U); |
| 252 | if (BaseAddr == -1U) |
| 253 | BaseAddr = DieArray[0].getAttributeValueAsUnsigned(this, DW_AT_entry_pc, 0); |
| 254 | setBaseAddress(BaseAddr); |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 255 | AddrOffsetSectionBase = |
| 256 | DieArray[0].getAttributeValueAsReference(this, DW_AT_GNU_addr_base, 0); |
| 257 | RangeSectionBase = |
| 258 | DieArray[0].getAttributeValueAsReference(this, DW_AT_GNU_ranges_base, 0); |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 259 | } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 260 | |
| 261 | setDIERelations(); |
| 262 | return DieArray.size(); |
| 263 | } |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 264 | |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 265 | DWARFCompileUnit::DWOHolder::DWOHolder(object::ObjectFile *DWOFile) |
| 266 | : DWOFile(DWOFile), |
| 267 | DWOContext(cast<DWARFContext>(DIContext::getDWARFContext(DWOFile))), |
| 268 | DWOCU(0) { |
| 269 | if (DWOContext->getNumDWOCompileUnits() > 0) |
| 270 | DWOCU = DWOContext->getDWOCompileUnitAtIndex(0); |
| 271 | } |
| 272 | |
| 273 | bool DWARFCompileUnit::parseDWO() { |
| 274 | if (DWO.get() != 0) |
| 275 | return false; |
| 276 | extractDIEsIfNeeded(true); |
| 277 | if (DieArray.empty()) |
| 278 | return false; |
| 279 | const char *DWOFileName = |
| 280 | DieArray[0].getAttributeValueAsString(this, DW_AT_GNU_dwo_name, 0); |
| 281 | if (DWOFileName == 0) |
| 282 | return false; |
| 283 | const char *CompilationDir = |
| 284 | DieArray[0].getAttributeValueAsString(this, DW_AT_comp_dir, 0); |
| 285 | SmallString<16> AbsolutePath; |
| 286 | if (sys::path::is_relative(DWOFileName) && CompilationDir != 0) { |
| 287 | sys::path::append(AbsolutePath, CompilationDir); |
| 288 | } |
| 289 | sys::path::append(AbsolutePath, DWOFileName); |
| 290 | object::ObjectFile *DWOFile = |
| 291 | object::ObjectFile::createObjectFile(AbsolutePath); |
| 292 | if (!DWOFile) |
| 293 | return false; |
| 294 | // Reset DWOHolder. |
| 295 | DWO.reset(new DWOHolder(DWOFile)); |
| 296 | DWARFCompileUnit *DWOCU = DWO->getCU(); |
| 297 | // Verify that compile unit in .dwo file is valid. |
| 298 | if (DWOCU == 0 || DWOCU->getDWOId() != getDWOId()) { |
| 299 | DWO.reset(); |
| 300 | return false; |
| 301 | } |
| 302 | // Share .debug_addr and .debug_ranges section with compile unit in .dwo |
| 303 | DWOCU->setAddrOffsetSection(AddrOffsetSection, AddrOffsetSectionBase); |
| 304 | DWOCU->setRangesSection(RangeSection, RangeSectionBase); |
| 305 | return true; |
| 306 | } |
| 307 | |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 308 | void DWARFCompileUnit::clearDIEs(bool KeepCUDie) { |
| 309 | if (DieArray.size() > (unsigned)KeepCUDie) { |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 310 | // std::vectors never get any smaller when resized to a smaller size, |
| 311 | // or when clear() or erase() are called, the size will report that it |
| 312 | // is smaller, but the memory allocated remains intact (call capacity() |
| 313 | // to see this). So we need to create a temporary vector and swap the |
| 314 | // contents which will cause just the internal pointers to be swapped |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 315 | // so that when temporary vector goes out of scope, it will destroy the |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 316 | // contents. |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 317 | std::vector<DWARFDebugInfoEntryMinimal> TmpArray; |
| 318 | DieArray.swap(TmpArray); |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 319 | // Save at least the compile unit DIE |
Alexey Samsonov | 40d8c69 | 2013-07-15 08:43:35 +0000 | [diff] [blame] | 320 | if (KeepCUDie) |
| 321 | DieArray.push_back(TmpArray.front()); |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| 325 | void |
| 326 | DWARFCompileUnit::buildAddressRangeTable(DWARFDebugAranges *debug_aranges, |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 327 | bool clear_dies_if_already_not_parsed, |
| 328 | uint32_t CUOffsetInAranges) { |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 329 | // This function is usually called if there in no .debug_aranges section |
| 330 | // in order to produce a compile unit level set of address ranges that |
| 331 | // is accurate. If the DIEs weren't parsed, then we don't want all dies for |
| 332 | // all compile units to stay loaded when they weren't needed. So we can end |
| 333 | // up parsing the DWARF and then throwing them all away to keep memory usage |
| 334 | // down. |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 335 | const bool clear_dies = extractDIEsIfNeeded(false) > 1 && |
| 336 | clear_dies_if_already_not_parsed; |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 337 | DieArray[0].buildAddressRangeTable(this, debug_aranges, CUOffsetInAranges); |
| 338 | bool DWOCreated = parseDWO(); |
| 339 | if (DWO.get()) { |
| 340 | // If there is a .dwo file for this compile unit, then skeleton CU DIE |
| 341 | // doesn't have children, and we should instead build address range table |
| 342 | // from DIEs in the .debug_info.dwo section of .dwo file. |
| 343 | DWO->getCU()->buildAddressRangeTable( |
| 344 | debug_aranges, clear_dies_if_already_not_parsed, CUOffsetInAranges); |
| 345 | } |
| 346 | if (DWOCreated && clear_dies_if_already_not_parsed) |
| 347 | DWO.reset(); |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 348 | |
| 349 | // Keep memory down by clearing DIEs if this generate function |
| 350 | // caused them to be parsed. |
| 351 | if (clear_dies) |
| 352 | clearDIEs(true); |
| 353 | } |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 354 | |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 355 | const DWARFDebugInfoEntryMinimal * |
| 356 | DWARFCompileUnit::getSubprogramForAddress(uint64_t Address) { |
| 357 | extractDIEsIfNeeded(false); |
| 358 | for (size_t i = 0, n = DieArray.size(); i != n; i++) |
| 359 | if (DieArray[i].isSubprogramDIE() && |
| 360 | DieArray[i].addressRangeContainsAddress(this, Address)) { |
| 361 | return &DieArray[i]; |
| 362 | } |
| 363 | return 0; |
| 364 | } |
| 365 | |
Alexey Samsonov | e664290 | 2013-08-06 10:49:15 +0000 | [diff] [blame] | 366 | DWARFDebugInfoEntryInlinedChain |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 367 | DWARFCompileUnit::getInlinedChainForAddress(uint64_t Address) { |
| 368 | // First, find a subprogram that contains the given address (the root |
| 369 | // of inlined chain). |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 370 | const DWARFCompileUnit *ChainCU = 0; |
| 371 | const DWARFDebugInfoEntryMinimal *SubprogramDIE = |
| 372 | getSubprogramForAddress(Address); |
| 373 | if (SubprogramDIE) { |
| 374 | ChainCU = this; |
| 375 | } else { |
| 376 | // Try to look for subprogram DIEs in the DWO file. |
| 377 | parseDWO(); |
| 378 | if (DWO.get()) { |
| 379 | SubprogramDIE = DWO->getCU()->getSubprogramForAddress(Address); |
| 380 | if (SubprogramDIE) |
| 381 | ChainCU = DWO->getCU(); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 382 | } |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 383 | } |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 384 | |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 385 | // Get inlined chain rooted at this subprogram DIE. |
| 386 | if (!SubprogramDIE) |
Alexey Samsonov | e664290 | 2013-08-06 10:49:15 +0000 | [diff] [blame] | 387 | return DWARFDebugInfoEntryInlinedChain(); |
Alexey Samsonov | 63fd2af | 2013-08-27 09:20:22 +0000 | [diff] [blame] | 388 | return SubprogramDIE->getInlinedChainForAddress(ChainCU, Address); |
| 389 | } |