David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 1 | //===-- DWARFUnit.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 "DWARFUnit.h" |
| 11 | #include "DWARFContext.h" |
| 12 | #include "llvm/DebugInfo/DWARFFormValue.h" |
| 13 | #include "llvm/Support/Dwarf.h" |
| 14 | #include "llvm/Support/Path.h" |
David Blaikie | 262f548 | 2013-09-23 23:15:57 +0000 | [diff] [blame] | 15 | #include <cstdio> |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 16 | |
| 17 | using namespace llvm; |
| 18 | using namespace dwarf; |
| 19 | |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 20 | DWARFUnit::DWARFUnit(const DWARFDebugAbbrev *DA, StringRef IS, StringRef RS, |
| 21 | StringRef SS, StringRef SOS, StringRef AOS, |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 22 | const RelocAddrMap *M, bool LE) |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 23 | : Abbrev(DA), InfoSection(IS), RangeSection(RS), StringSection(SS), |
| 24 | StringOffsetSection(SOS), AddrOffsetSection(AOS), RelocMap(M), |
| 25 | isLittleEndian(LE) { |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 26 | clear(); |
| 27 | } |
| 28 | |
| 29 | DWARFUnit::~DWARFUnit() { |
| 30 | } |
| 31 | |
| 32 | bool DWARFUnit::getAddrOffsetSectionItem(uint32_t Index, |
| 33 | uint64_t &Result) const { |
| 34 | uint32_t Offset = AddrOffsetSectionBase + Index * AddrSize; |
| 35 | if (AddrOffsetSection.size() < Offset + AddrSize) |
| 36 | return false; |
| 37 | DataExtractor DA(AddrOffsetSection, isLittleEndian, AddrSize); |
| 38 | Result = DA.getAddress(&Offset); |
| 39 | return true; |
| 40 | } |
| 41 | |
| 42 | bool DWARFUnit::getStringOffsetSectionItem(uint32_t Index, |
| 43 | uint32_t &Result) const { |
| 44 | // FIXME: string offset section entries are 8-byte for DWARF64. |
| 45 | const uint32_t ItemSize = 4; |
| 46 | uint32_t Offset = Index * ItemSize; |
| 47 | if (StringOffsetSection.size() < Offset + ItemSize) |
| 48 | return false; |
| 49 | DataExtractor DA(StringOffsetSection, isLittleEndian, 0); |
| 50 | Result = DA.getU32(&Offset); |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | bool DWARFUnit::extractImpl(DataExtractor debug_info, uint32_t *offset_ptr) { |
| 55 | Length = debug_info.getU32(offset_ptr); |
| 56 | Version = debug_info.getU16(offset_ptr); |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 57 | uint64_t AbbrOffset = debug_info.getU32(offset_ptr); |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 58 | AddrSize = debug_info.getU8(offset_ptr); |
| 59 | |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 60 | bool LengthOK = debug_info.isValidOffset(getNextUnitOffset() - 1); |
| 61 | bool VersionOK = DWARFContext::isSupportedVersion(Version); |
| 62 | bool AddrSizeOK = AddrSize == 4 || AddrSize == 8; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 63 | |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 64 | if (!LengthOK || !VersionOK || !AddrSizeOK) |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 65 | return false; |
| 66 | |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 67 | Abbrevs = Abbrev->getAbbreviationDeclarationSet(AbbrOffset); |
| 68 | if (Abbrevs == nullptr) |
| 69 | return false; |
| 70 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 71 | return true; |
| 72 | } |
| 73 | |
| 74 | bool DWARFUnit::extract(DataExtractor debug_info, uint32_t *offset_ptr) { |
| 75 | clear(); |
| 76 | |
| 77 | Offset = *offset_ptr; |
| 78 | |
| 79 | if (debug_info.isValidOffset(*offset_ptr)) { |
| 80 | if (extractImpl(debug_info, offset_ptr)) |
| 81 | return true; |
| 82 | |
| 83 | // reset the offset to where we tried to parse from if anything went wrong |
| 84 | *offset_ptr = Offset; |
| 85 | } |
| 86 | |
| 87 | return false; |
| 88 | } |
| 89 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 90 | bool DWARFUnit::extractRangeList(uint32_t RangeListOffset, |
| 91 | DWARFDebugRangeList &RangeList) const { |
| 92 | // Require that compile unit is extracted. |
| 93 | assert(DieArray.size() > 0); |
| 94 | DataExtractor RangesData(RangeSection, isLittleEndian, AddrSize); |
| 95 | uint32_t ActualRangeListOffset = RangeSectionBase + RangeListOffset; |
| 96 | return RangeList.extract(RangesData, &ActualRangeListOffset); |
| 97 | } |
| 98 | |
| 99 | void DWARFUnit::clear() { |
| 100 | Offset = 0; |
| 101 | Length = 0; |
| 102 | Version = 0; |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 103 | Abbrevs = nullptr; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 104 | AddrSize = 0; |
| 105 | BaseAddr = 0; |
| 106 | RangeSectionBase = 0; |
| 107 | AddrOffsetSectionBase = 0; |
| 108 | clearDIEs(false); |
| 109 | DWO.reset(); |
| 110 | } |
| 111 | |
| 112 | const char *DWARFUnit::getCompilationDir() { |
| 113 | extractDIEsIfNeeded(true); |
| 114 | if (DieArray.empty()) |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 115 | return nullptr; |
| 116 | return DieArray[0].getAttributeValueAsString(this, DW_AT_comp_dir, nullptr); |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | uint64_t DWARFUnit::getDWOId() { |
| 120 | extractDIEsIfNeeded(true); |
| 121 | const uint64_t FailValue = -1ULL; |
| 122 | if (DieArray.empty()) |
| 123 | return FailValue; |
| 124 | return DieArray[0] |
Alexey Samsonov | c525323 | 2013-10-28 23:01:48 +0000 | [diff] [blame] | 125 | .getAttributeValueAsUnsignedConstant(this, DW_AT_GNU_dwo_id, FailValue); |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void DWARFUnit::setDIERelations() { |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 129 | if (DieArray.size() <= 1) |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 130 | return; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 131 | |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 132 | std::vector<DWARFDebugInfoEntryMinimal *> ParentChain; |
| 133 | DWARFDebugInfoEntryMinimal *SiblingChain = nullptr; |
| 134 | for (auto &DIE : DieArray) { |
| 135 | if (SiblingChain) { |
| 136 | SiblingChain->setSibling(&DIE); |
| 137 | } |
| 138 | if (const DWARFAbbreviationDeclaration *AbbrDecl = |
| 139 | DIE.getAbbreviationDeclarationPtr()) { |
| 140 | // Normal DIE. |
| 141 | if (AbbrDecl->hasChildren()) { |
| 142 | ParentChain.push_back(&DIE); |
| 143 | SiblingChain = nullptr; |
| 144 | } else { |
| 145 | SiblingChain = &DIE; |
| 146 | } |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 147 | } else { |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 148 | // NULL entry terminates the sibling chain. |
| 149 | SiblingChain = ParentChain.back(); |
| 150 | ParentChain.pop_back(); |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 151 | } |
| 152 | } |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 153 | assert(SiblingChain == nullptr || SiblingChain == &DieArray[0]); |
| 154 | assert(ParentChain.empty()); |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | void DWARFUnit::extractDIEsToVector( |
| 158 | bool AppendCUDie, bool AppendNonCUDies, |
| 159 | std::vector<DWARFDebugInfoEntryMinimal> &Dies) const { |
| 160 | if (!AppendCUDie && !AppendNonCUDies) |
| 161 | return; |
| 162 | |
| 163 | // Set the offset to that of the first DIE and calculate the start of the |
| 164 | // next compilation unit header. |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 165 | uint32_t DIEOffset = Offset + getHeaderSize(); |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 166 | uint32_t NextCUOffset = getNextUnitOffset(); |
| 167 | DWARFDebugInfoEntryMinimal DIE; |
| 168 | uint32_t Depth = 0; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 169 | bool IsCUDie = true; |
| 170 | |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 171 | while (DIEOffset < NextCUOffset && DIE.extractFast(this, &DIEOffset)) { |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 172 | if (IsCUDie) { |
| 173 | if (AppendCUDie) |
| 174 | Dies.push_back(DIE); |
| 175 | if (!AppendNonCUDies) |
| 176 | break; |
| 177 | // The average bytes per DIE entry has been seen to be |
| 178 | // around 14-20 so let's pre-reserve the needed memory for |
| 179 | // our DIE entries accordingly. |
| 180 | Dies.reserve(Dies.size() + getDebugInfoSize() / 14); |
| 181 | IsCUDie = false; |
| 182 | } else { |
| 183 | Dies.push_back(DIE); |
| 184 | } |
| 185 | |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 186 | if (const DWARFAbbreviationDeclaration *AbbrDecl = |
| 187 | DIE.getAbbreviationDeclarationPtr()) { |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 188 | // Normal DIE |
| 189 | if (AbbrDecl->hasChildren()) |
| 190 | ++Depth; |
| 191 | } else { |
| 192 | // NULL DIE. |
| 193 | if (Depth > 0) |
| 194 | --Depth; |
| 195 | if (Depth == 0) |
| 196 | break; // We are done with this compile unit! |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | // Give a little bit of info if we encounter corrupt DWARF (our offset |
| 201 | // should always terminate at or before the start of the next compilation |
| 202 | // unit header). |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 203 | if (DIEOffset > NextCUOffset) |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 204 | fprintf(stderr, "warning: DWARF compile unit extends beyond its " |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 205 | "bounds cu 0x%8.8x at 0x%8.8x'\n", getOffset(), DIEOffset); |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | size_t DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) { |
| 209 | if ((CUDieOnly && DieArray.size() > 0) || |
| 210 | DieArray.size() > 1) |
| 211 | return 0; // Already parsed. |
| 212 | |
| 213 | bool HasCUDie = DieArray.size() > 0; |
| 214 | extractDIEsToVector(!HasCUDie, !CUDieOnly, DieArray); |
| 215 | |
| 216 | if (DieArray.empty()) |
| 217 | return 0; |
| 218 | |
| 219 | // If CU DIE was just parsed, copy several attribute values from it. |
| 220 | if (!HasCUDie) { |
| 221 | uint64_t BaseAddr = |
Alexey Samsonov | c525323 | 2013-10-28 23:01:48 +0000 | [diff] [blame] | 222 | DieArray[0].getAttributeValueAsAddress(this, DW_AT_low_pc, -1ULL); |
| 223 | if (BaseAddr == -1ULL) |
| 224 | BaseAddr = DieArray[0].getAttributeValueAsAddress(this, DW_AT_entry_pc, 0); |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 225 | setBaseAddress(BaseAddr); |
Alexey Samsonov | c525323 | 2013-10-28 23:01:48 +0000 | [diff] [blame] | 226 | AddrOffsetSectionBase = DieArray[0].getAttributeValueAsSectionOffset( |
| 227 | this, DW_AT_GNU_addr_base, 0); |
| 228 | RangeSectionBase = DieArray[0].getAttributeValueAsSectionOffset( |
Stephen Hines | c6a4f5e | 2014-07-21 00:45:20 -0700 | [diff] [blame] | 229 | this, DW_AT_ranges_base, 0); |
| 230 | // Don't fall back to DW_AT_GNU_ranges_base: it should be ignored for |
| 231 | // skeleton CU DIE, so that DWARF users not aware of it are not broken. |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | setDIERelations(); |
| 235 | return DieArray.size(); |
| 236 | } |
| 237 | |
| 238 | DWARFUnit::DWOHolder::DWOHolder(object::ObjectFile *DWOFile) |
| 239 | : DWOFile(DWOFile), |
| 240 | DWOContext(cast<DWARFContext>(DIContext::getDWARFContext(DWOFile))), |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 241 | DWOU(nullptr) { |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 242 | if (DWOContext->getNumDWOCompileUnits() > 0) |
| 243 | DWOU = DWOContext->getDWOCompileUnitAtIndex(0); |
| 244 | } |
| 245 | |
| 246 | bool DWARFUnit::parseDWO() { |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 247 | if (DWO.get()) |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 248 | return false; |
| 249 | extractDIEsIfNeeded(true); |
| 250 | if (DieArray.empty()) |
| 251 | return false; |
| 252 | const char *DWOFileName = |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 253 | DieArray[0].getAttributeValueAsString(this, DW_AT_GNU_dwo_name, nullptr); |
| 254 | if (!DWOFileName) |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 255 | return false; |
| 256 | const char *CompilationDir = |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 257 | DieArray[0].getAttributeValueAsString(this, DW_AT_comp_dir, nullptr); |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 258 | SmallString<16> AbsolutePath; |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 259 | if (sys::path::is_relative(DWOFileName) && CompilationDir != nullptr) { |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 260 | sys::path::append(AbsolutePath, CompilationDir); |
| 261 | } |
| 262 | sys::path::append(AbsolutePath, DWOFileName); |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 263 | ErrorOr<object::ObjectFile *> DWOFile = |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 264 | object::ObjectFile::createObjectFile(AbsolutePath); |
| 265 | if (!DWOFile) |
| 266 | return false; |
| 267 | // Reset DWOHolder. |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 268 | DWO.reset(new DWOHolder(DWOFile.get())); |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 269 | DWARFUnit *DWOCU = DWO->getUnit(); |
| 270 | // Verify that compile unit in .dwo file is valid. |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 271 | if (!DWOCU || DWOCU->getDWOId() != getDWOId()) { |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 272 | DWO.reset(); |
| 273 | return false; |
| 274 | } |
| 275 | // Share .debug_addr and .debug_ranges section with compile unit in .dwo |
| 276 | DWOCU->setAddrOffsetSection(AddrOffsetSection, AddrOffsetSectionBase); |
Stephen Hines | c6a4f5e | 2014-07-21 00:45:20 -0700 | [diff] [blame] | 277 | uint32_t DWORangesBase = DieArray[0].getRangesBaseAttribute(this, 0); |
| 278 | DWOCU->setRangesSection(RangeSection, DWORangesBase); |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 279 | return true; |
| 280 | } |
| 281 | |
| 282 | void DWARFUnit::clearDIEs(bool KeepCUDie) { |
| 283 | if (DieArray.size() > (unsigned)KeepCUDie) { |
| 284 | // std::vectors never get any smaller when resized to a smaller size, |
| 285 | // or when clear() or erase() are called, the size will report that it |
| 286 | // is smaller, but the memory allocated remains intact (call capacity() |
| 287 | // to see this). So we need to create a temporary vector and swap the |
| 288 | // contents which will cause just the internal pointers to be swapped |
| 289 | // so that when temporary vector goes out of scope, it will destroy the |
| 290 | // contents. |
| 291 | std::vector<DWARFDebugInfoEntryMinimal> TmpArray; |
| 292 | DieArray.swap(TmpArray); |
| 293 | // Save at least the compile unit DIE |
| 294 | if (KeepCUDie) |
| 295 | DieArray.push_back(TmpArray.front()); |
| 296 | } |
| 297 | } |
| 298 | |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 299 | void DWARFUnit::collectAddressRanges(DWARFAddressRangesVector &CURanges) { |
| 300 | // First, check if CU DIE describes address ranges for the unit. |
| 301 | const auto &CUDIERanges = getCompileUnitDIE()->getAddressRanges(this); |
| 302 | if (!CUDIERanges.empty()) { |
| 303 | CURanges.insert(CURanges.end(), CUDIERanges.begin(), CUDIERanges.end()); |
| 304 | return; |
| 305 | } |
| 306 | |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 307 | // This function is usually called if there in no .debug_aranges section |
| 308 | // in order to produce a compile unit level set of address ranges that |
| 309 | // is accurate. If the DIEs weren't parsed, then we don't want all dies for |
| 310 | // all compile units to stay loaded when they weren't needed. So we can end |
| 311 | // up parsing the DWARF and then throwing them all away to keep memory usage |
| 312 | // down. |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 313 | const bool ClearDIEs = extractDIEsIfNeeded(false) > 1; |
| 314 | DieArray[0].collectChildrenAddressRanges(this, CURanges); |
| 315 | |
| 316 | // Collect address ranges from DIEs in .dwo if necessary. |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 317 | bool DWOCreated = parseDWO(); |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 318 | if (DWO.get()) |
| 319 | DWO->getUnit()->collectAddressRanges(CURanges); |
| 320 | if (DWOCreated) |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 321 | DWO.reset(); |
| 322 | |
| 323 | // Keep memory down by clearing DIEs if this generate function |
| 324 | // caused them to be parsed. |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 325 | if (ClearDIEs) |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 326 | clearDIEs(true); |
| 327 | } |
| 328 | |
| 329 | const DWARFDebugInfoEntryMinimal * |
| 330 | DWARFUnit::getSubprogramForAddress(uint64_t Address) { |
| 331 | extractDIEsIfNeeded(false); |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 332 | for (const DWARFDebugInfoEntryMinimal &DIE : DieArray) { |
| 333 | if (DIE.isSubprogramDIE() && |
| 334 | DIE.addressRangeContainsAddress(this, Address)) { |
| 335 | return &DIE; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 336 | } |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 337 | } |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 338 | return nullptr; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | DWARFDebugInfoEntryInlinedChain |
| 342 | DWARFUnit::getInlinedChainForAddress(uint64_t Address) { |
| 343 | // First, find a subprogram that contains the given address (the root |
| 344 | // of inlined chain). |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 345 | const DWARFUnit *ChainCU = nullptr; |
David Blaikie | cd7c498 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 346 | const DWARFDebugInfoEntryMinimal *SubprogramDIE = |
| 347 | getSubprogramForAddress(Address); |
| 348 | if (SubprogramDIE) { |
| 349 | ChainCU = this; |
| 350 | } else { |
| 351 | // Try to look for subprogram DIEs in the DWO file. |
| 352 | parseDWO(); |
| 353 | if (DWO.get()) { |
| 354 | SubprogramDIE = DWO->getUnit()->getSubprogramForAddress(Address); |
| 355 | if (SubprogramDIE) |
| 356 | ChainCU = DWO->getUnit(); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | // Get inlined chain rooted at this subprogram DIE. |
| 361 | if (!SubprogramDIE) |
| 362 | return DWARFDebugInfoEntryInlinedChain(); |
| 363 | return SubprogramDIE->getInlinedChainForAddress(ChainCU, Address); |
| 364 | } |