blob: caa3694a29d339d1d95a0acbb949b220c0c621f6 [file] [log] [blame]
David Blaikie07e22442013-09-23 22:44:40 +00001//===-- 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
Eugene Zelenko570e39a2016-11-23 23:16:32 +000010#include "llvm/ADT/SmallString.h"
11#include "llvm/ADT/STLExtras.h"
12#include "llvm/ADT/StringRef.h"
13#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
Zachary Turner82af9432015-01-30 18:07:45 +000014#include "llvm/DebugInfo/DWARF/DWARFContext.h"
Eugene Zelenko570e39a2016-11-23 23:16:32 +000015#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
16#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
17#include "llvm/Object/ObjectFile.h"
18#include "llvm/Support/Casting.h"
19#include "llvm/Support/DataExtractor.h"
David Blaikie07e22442013-09-23 22:44:40 +000020#include "llvm/Support/Path.h"
Eugene Zelenko570e39a2016-11-23 23:16:32 +000021#include <algorithm>
22#include <cassert>
23#include <cstdint>
David Blaikie8de5e982013-09-23 23:15:57 +000024#include <cstdio>
Eugene Zelenko570e39a2016-11-23 23:16:32 +000025#include <vector>
David Blaikie07e22442013-09-23 22:44:40 +000026
David Blaikie82641be2015-11-17 00:39:55 +000027namespace llvm {
Eugene Zelenko570e39a2016-11-23 23:16:32 +000028
David Blaikie07e22442013-09-23 22:44:40 +000029using namespace dwarf;
30
Alexey Samsonov8cd4c9d2014-10-08 00:07:53 +000031void DWARFUnitSectionBase::parse(DWARFContext &C, const DWARFSection &Section) {
32 parseImpl(C, Section, C.getDebugAbbrev(), C.getRangeSection(),
33 C.getStringSection(), StringRef(), C.getAddrSection(),
David Blaikiee438cff2016-04-22 22:50:56 +000034 C.getLineSection().Data, C.isLittleEndian(), false);
Frederic Riss6005dbd2014-10-06 03:36:18 +000035}
36
Alexey Samsonov8cd4c9d2014-10-08 00:07:53 +000037void DWARFUnitSectionBase::parseDWO(DWARFContext &C,
David Blaikie82641be2015-11-17 00:39:55 +000038 const DWARFSection &DWOSection,
39 DWARFUnitIndex *Index) {
Alexey Samsonov8cd4c9d2014-10-08 00:07:53 +000040 parseImpl(C, DWOSection, C.getDebugAbbrevDWO(), C.getRangeDWOSection(),
Frederic Riss6005dbd2014-10-06 03:36:18 +000041 C.getStringDWOSection(), C.getStringOffsetDWOSection(),
David Blaikiee438cff2016-04-22 22:50:56 +000042 C.getAddrSection(), C.getLineDWOSection().Data, C.isLittleEndian(),
43 true);
Frederic Riss6005dbd2014-10-06 03:36:18 +000044}
45
Alexey Samsonov4b4d64b2014-10-08 00:24:41 +000046DWARFUnit::DWARFUnit(DWARFContext &DC, const DWARFSection &Section,
47 const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS,
David Blaikiec4e2bed2015-11-17 21:08:05 +000048 StringRef SOS, StringRef AOS, StringRef LS, bool LE,
David Blaikiee438cff2016-04-22 22:50:56 +000049 bool IsDWO, const DWARFUnitSectionBase &UnitSection,
David Blaikie82641be2015-11-17 00:39:55 +000050 const DWARFUnitIndex::Entry *IndexEntry)
Alexey Samsonov4b4d64b2014-10-08 00:24:41 +000051 : Context(DC), InfoSection(Section), Abbrev(DA), RangeSection(RS),
David Blaikie35c2eeb2015-11-17 22:39:23 +000052 LineSection(LS), StringSection(SS), StringOffsetSection([&]() {
David Blaikie4689ef52015-11-17 22:39:26 +000053 if (IndexEntry)
54 if (const auto *C = IndexEntry->getOffset(DW_SECT_STR_OFFSETS))
55 return SOS.slice(C->Offset, C->Offset + C->Length);
David Blaikie35c2eeb2015-11-17 22:39:23 +000056 return SOS;
57 }()),
David Blaikiee438cff2016-04-22 22:50:56 +000058 AddrOffsetSection(AOS), isLittleEndian(LE), isDWO(IsDWO),
59 UnitSection(UnitSection), IndexEntry(IndexEntry) {
David Blaikie07e22442013-09-23 22:44:40 +000060 clear();
61}
62
Eugene Zelenko570e39a2016-11-23 23:16:32 +000063DWARFUnit::~DWARFUnit() = default;
David Blaikie07e22442013-09-23 22:44:40 +000064
65bool DWARFUnit::getAddrOffsetSectionItem(uint32_t Index,
66 uint64_t &Result) const {
67 uint32_t Offset = AddrOffsetSectionBase + Index * AddrSize;
68 if (AddrOffsetSection.size() < Offset + AddrSize)
69 return false;
70 DataExtractor DA(AddrOffsetSection, isLittleEndian, AddrSize);
71 Result = DA.getAddress(&Offset);
72 return true;
73}
74
75bool DWARFUnit::getStringOffsetSectionItem(uint32_t Index,
76 uint32_t &Result) const {
77 // FIXME: string offset section entries are 8-byte for DWARF64.
78 const uint32_t ItemSize = 4;
79 uint32_t Offset = Index * ItemSize;
80 if (StringOffsetSection.size() < Offset + ItemSize)
81 return false;
82 DataExtractor DA(StringOffsetSection, isLittleEndian, 0);
83 Result = DA.getU32(&Offset);
84 return true;
85}
86
87bool DWARFUnit::extractImpl(DataExtractor debug_info, uint32_t *offset_ptr) {
88 Length = debug_info.getU32(offset_ptr);
89 Version = debug_info.getU16(offset_ptr);
Alexey Samsonov7682f812014-04-24 22:51:03 +000090 uint64_t AbbrOffset = debug_info.getU32(offset_ptr);
David Blaikie82641be2015-11-17 00:39:55 +000091 if (IndexEntry) {
92 if (AbbrOffset)
93 return false;
94 auto *UnitContrib = IndexEntry->getOffset();
95 if (!UnitContrib || UnitContrib->Length != (Length + 4))
96 return false;
97 auto *AbbrEntry = IndexEntry->getOffset(DW_SECT_ABBREV);
98 if (!AbbrEntry)
99 return false;
100 AbbrOffset = AbbrEntry->Offset;
101 }
David Blaikie07e22442013-09-23 22:44:40 +0000102 AddrSize = debug_info.getU8(offset_ptr);
103
Alexey Samsonov7682f812014-04-24 22:51:03 +0000104 bool LengthOK = debug_info.isValidOffset(getNextUnitOffset() - 1);
105 bool VersionOK = DWARFContext::isSupportedVersion(Version);
106 bool AddrSizeOK = AddrSize == 4 || AddrSize == 8;
David Blaikie07e22442013-09-23 22:44:40 +0000107
Alexey Samsonov7682f812014-04-24 22:51:03 +0000108 if (!LengthOK || !VersionOK || !AddrSizeOK)
David Blaikie07e22442013-09-23 22:44:40 +0000109 return false;
110
Alexey Samsonov7682f812014-04-24 22:51:03 +0000111 Abbrevs = Abbrev->getAbbreviationDeclarationSet(AbbrOffset);
Benjamin Kramer68a29562015-05-25 13:28:03 +0000112 return Abbrevs != nullptr;
David Blaikie07e22442013-09-23 22:44:40 +0000113}
114
115bool DWARFUnit::extract(DataExtractor debug_info, uint32_t *offset_ptr) {
116 clear();
117
118 Offset = *offset_ptr;
119
120 if (debug_info.isValidOffset(*offset_ptr)) {
121 if (extractImpl(debug_info, offset_ptr))
122 return true;
123
124 // reset the offset to where we tried to parse from if anything went wrong
125 *offset_ptr = Offset;
126 }
127
128 return false;
129}
130
David Blaikie07e22442013-09-23 22:44:40 +0000131bool DWARFUnit::extractRangeList(uint32_t RangeListOffset,
132 DWARFDebugRangeList &RangeList) const {
133 // Require that compile unit is extracted.
Eugene Zelenko570e39a2016-11-23 23:16:32 +0000134 assert(!DieArray.empty());
David Blaikie07e22442013-09-23 22:44:40 +0000135 DataExtractor RangesData(RangeSection, isLittleEndian, AddrSize);
136 uint32_t ActualRangeListOffset = RangeSectionBase + RangeListOffset;
137 return RangeList.extract(RangesData, &ActualRangeListOffset);
138}
139
140void DWARFUnit::clear() {
141 Offset = 0;
142 Length = 0;
143 Version = 0;
Craig Topper2617dcc2014-04-15 06:32:26 +0000144 Abbrevs = nullptr;
David Blaikie07e22442013-09-23 22:44:40 +0000145 AddrSize = 0;
146 BaseAddr = 0;
147 RangeSectionBase = 0;
148 AddrOffsetSectionBase = 0;
149 clearDIEs(false);
150 DWO.reset();
151}
152
153const char *DWARFUnit::getCompilationDir() {
154 extractDIEsIfNeeded(true);
155 if (DieArray.empty())
Craig Topper2617dcc2014-04-15 06:32:26 +0000156 return nullptr;
157 return DieArray[0].getAttributeValueAsString(this, DW_AT_comp_dir, nullptr);
David Blaikie07e22442013-09-23 22:44:40 +0000158}
159
160uint64_t DWARFUnit::getDWOId() {
161 extractDIEsIfNeeded(true);
162 const uint64_t FailValue = -1ULL;
163 if (DieArray.empty())
164 return FailValue;
165 return DieArray[0]
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000166 .getAttributeValueAsUnsignedConstant(this, DW_AT_GNU_dwo_id, FailValue);
David Blaikie07e22442013-09-23 22:44:40 +0000167}
168
169void DWARFUnit::setDIERelations() {
Alexey Samsonov8e4cf3b2014-04-29 17:12:42 +0000170 if (DieArray.size() <= 1)
David Blaikie07e22442013-09-23 22:44:40 +0000171 return;
David Blaikie07e22442013-09-23 22:44:40 +0000172
Alexey Samsonov8e4cf3b2014-04-29 17:12:42 +0000173 std::vector<DWARFDebugInfoEntryMinimal *> ParentChain;
174 DWARFDebugInfoEntryMinimal *SiblingChain = nullptr;
175 for (auto &DIE : DieArray) {
176 if (SiblingChain) {
177 SiblingChain->setSibling(&DIE);
178 }
179 if (const DWARFAbbreviationDeclaration *AbbrDecl =
180 DIE.getAbbreviationDeclarationPtr()) {
181 // Normal DIE.
182 if (AbbrDecl->hasChildren()) {
183 ParentChain.push_back(&DIE);
184 SiblingChain = nullptr;
185 } else {
186 SiblingChain = &DIE;
187 }
David Blaikie07e22442013-09-23 22:44:40 +0000188 } else {
Alexey Samsonov8e4cf3b2014-04-29 17:12:42 +0000189 // NULL entry terminates the sibling chain.
190 SiblingChain = ParentChain.back();
191 ParentChain.pop_back();
David Blaikie07e22442013-09-23 22:44:40 +0000192 }
193 }
Alexey Samsonov8e4cf3b2014-04-29 17:12:42 +0000194 assert(SiblingChain == nullptr || SiblingChain == &DieArray[0]);
195 assert(ParentChain.empty());
David Blaikie07e22442013-09-23 22:44:40 +0000196}
197
198void DWARFUnit::extractDIEsToVector(
199 bool AppendCUDie, bool AppendNonCUDies,
200 std::vector<DWARFDebugInfoEntryMinimal> &Dies) const {
201 if (!AppendCUDie && !AppendNonCUDies)
202 return;
203
204 // Set the offset to that of the first DIE and calculate the start of the
205 // next compilation unit header.
Alexey Samsonov19f76f22014-04-24 23:08:56 +0000206 uint32_t DIEOffset = Offset + getHeaderSize();
David Blaikie07e22442013-09-23 22:44:40 +0000207 uint32_t NextCUOffset = getNextUnitOffset();
208 DWARFDebugInfoEntryMinimal DIE;
Greg Clayton6f6e4db2016-11-15 01:23:06 +0000209 DataExtractor DebugInfoData = getDebugInfoExtractor();
David Blaikie07e22442013-09-23 22:44:40 +0000210 uint32_t Depth = 0;
David Blaikie07e22442013-09-23 22:44:40 +0000211 bool IsCUDie = true;
212
Greg Clayton6f6e4db2016-11-15 01:23:06 +0000213 while (DIE.extractFast(*this, &DIEOffset, DebugInfoData, NextCUOffset)) {
David Blaikie07e22442013-09-23 22:44:40 +0000214 if (IsCUDie) {
215 if (AppendCUDie)
216 Dies.push_back(DIE);
217 if (!AppendNonCUDies)
218 break;
219 // The average bytes per DIE entry has been seen to be
220 // around 14-20 so let's pre-reserve the needed memory for
221 // our DIE entries accordingly.
222 Dies.reserve(Dies.size() + getDebugInfoSize() / 14);
223 IsCUDie = false;
224 } else {
225 Dies.push_back(DIE);
226 }
227
Alexey Samsonov8e4cf3b2014-04-29 17:12:42 +0000228 if (const DWARFAbbreviationDeclaration *AbbrDecl =
229 DIE.getAbbreviationDeclarationPtr()) {
David Blaikie07e22442013-09-23 22:44:40 +0000230 // Normal DIE
231 if (AbbrDecl->hasChildren())
232 ++Depth;
233 } else {
234 // NULL DIE.
235 if (Depth > 0)
236 --Depth;
237 if (Depth == 0)
238 break; // We are done with this compile unit!
239 }
240 }
241
242 // Give a little bit of info if we encounter corrupt DWARF (our offset
243 // should always terminate at or before the start of the next compilation
244 // unit header).
Alexey Samsonov19f76f22014-04-24 23:08:56 +0000245 if (DIEOffset > NextCUOffset)
David Blaikie07e22442013-09-23 22:44:40 +0000246 fprintf(stderr, "warning: DWARF compile unit extends beyond its "
Alexey Samsonov19f76f22014-04-24 23:08:56 +0000247 "bounds cu 0x%8.8x at 0x%8.8x'\n", getOffset(), DIEOffset);
David Blaikie07e22442013-09-23 22:44:40 +0000248}
249
250size_t DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) {
Eugene Zelenko570e39a2016-11-23 23:16:32 +0000251 if ((CUDieOnly && !DieArray.empty()) ||
David Blaikie07e22442013-09-23 22:44:40 +0000252 DieArray.size() > 1)
253 return 0; // Already parsed.
254
Eugene Zelenko570e39a2016-11-23 23:16:32 +0000255 bool HasCUDie = !DieArray.empty();
David Blaikie07e22442013-09-23 22:44:40 +0000256 extractDIEsToVector(!HasCUDie, !CUDieOnly, DieArray);
257
258 if (DieArray.empty())
259 return 0;
260
261 // If CU DIE was just parsed, copy several attribute values from it.
262 if (!HasCUDie) {
263 uint64_t BaseAddr =
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000264 DieArray[0].getAttributeValueAsAddress(this, DW_AT_low_pc, -1ULL);
265 if (BaseAddr == -1ULL)
266 BaseAddr = DieArray[0].getAttributeValueAsAddress(this, DW_AT_entry_pc, 0);
David Blaikie07e22442013-09-23 22:44:40 +0000267 setBaseAddress(BaseAddr);
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000268 AddrOffsetSectionBase = DieArray[0].getAttributeValueAsSectionOffset(
269 this, DW_AT_GNU_addr_base, 0);
Alexey Samsonovaa909982014-06-13 22:31:03 +0000270 RangeSectionBase = DieArray[0].getAttributeValueAsSectionOffset(
Adrian Prantlc4fbbcf2016-10-28 17:59:50 +0000271 this, DW_AT_rnglists_base, 0);
Alexey Samsonovaa909982014-06-13 22:31:03 +0000272 // Don't fall back to DW_AT_GNU_ranges_base: it should be ignored for
273 // skeleton CU DIE, so that DWARF users not aware of it are not broken.
David Blaikie07e22442013-09-23 22:44:40 +0000274 }
275
276 setDIERelations();
277 return DieArray.size();
278}
279
Alexey Samsonovd3e12132014-09-05 19:29:45 +0000280DWARFUnit::DWOHolder::DWOHolder(StringRef DWOPath)
Eugene Zelenko570e39a2016-11-23 23:16:32 +0000281 : DWOU(nullptr) {
Alexey Samsonovd3e12132014-09-05 19:29:45 +0000282 auto Obj = object::ObjectFile::createObjectFile(DWOPath);
Kevin Enderby3fcdf6a2016-04-06 22:14:09 +0000283 if (!Obj) {
284 // TODO: Actually report errors helpfully.
285 consumeError(Obj.takeError());
Alexey Samsonovd3e12132014-09-05 19:29:45 +0000286 return;
Kevin Enderby3fcdf6a2016-04-06 22:14:09 +0000287 }
Alexey Samsonovd3e12132014-09-05 19:29:45 +0000288 DWOFile = std::move(Obj.get());
289 DWOContext.reset(
Zachary Turner6489d7b2015-04-23 17:37:47 +0000290 cast<DWARFContext>(new DWARFContextInMemory(*DWOFile.getBinary())));
David Blaikie07e22442013-09-23 22:44:40 +0000291 if (DWOContext->getNumDWOCompileUnits() > 0)
292 DWOU = DWOContext->getDWOCompileUnitAtIndex(0);
293}
294
295bool DWARFUnit::parseDWO() {
David Blaikiee438cff2016-04-22 22:50:56 +0000296 if (isDWO)
297 return false;
Craig Topper2617dcc2014-04-15 06:32:26 +0000298 if (DWO.get())
David Blaikie07e22442013-09-23 22:44:40 +0000299 return false;
300 extractDIEsIfNeeded(true);
301 if (DieArray.empty())
302 return false;
303 const char *DWOFileName =
Craig Topper2617dcc2014-04-15 06:32:26 +0000304 DieArray[0].getAttributeValueAsString(this, DW_AT_GNU_dwo_name, nullptr);
305 if (!DWOFileName)
David Blaikie07e22442013-09-23 22:44:40 +0000306 return false;
307 const char *CompilationDir =
Craig Topper2617dcc2014-04-15 06:32:26 +0000308 DieArray[0].getAttributeValueAsString(this, DW_AT_comp_dir, nullptr);
David Blaikie07e22442013-09-23 22:44:40 +0000309 SmallString<16> AbsolutePath;
Craig Topper2617dcc2014-04-15 06:32:26 +0000310 if (sys::path::is_relative(DWOFileName) && CompilationDir != nullptr) {
David Blaikie07e22442013-09-23 22:44:40 +0000311 sys::path::append(AbsolutePath, CompilationDir);
312 }
313 sys::path::append(AbsolutePath, DWOFileName);
Alexey Samsonovd3e12132014-09-05 19:29:45 +0000314 DWO = llvm::make_unique<DWOHolder>(AbsolutePath);
David Blaikie07e22442013-09-23 22:44:40 +0000315 DWARFUnit *DWOCU = DWO->getUnit();
316 // Verify that compile unit in .dwo file is valid.
Craig Topper2617dcc2014-04-15 06:32:26 +0000317 if (!DWOCU || DWOCU->getDWOId() != getDWOId()) {
David Blaikie07e22442013-09-23 22:44:40 +0000318 DWO.reset();
319 return false;
320 }
321 // Share .debug_addr and .debug_ranges section with compile unit in .dwo
322 DWOCU->setAddrOffsetSection(AddrOffsetSection, AddrOffsetSectionBase);
Alexey Samsonovaa909982014-06-13 22:31:03 +0000323 uint32_t DWORangesBase = DieArray[0].getRangesBaseAttribute(this, 0);
Alexey Samsonovf0e40342014-06-12 18:52:35 +0000324 DWOCU->setRangesSection(RangeSection, DWORangesBase);
David Blaikie07e22442013-09-23 22:44:40 +0000325 return true;
326}
327
328void DWARFUnit::clearDIEs(bool KeepCUDie) {
329 if (DieArray.size() > (unsigned)KeepCUDie) {
330 // std::vectors never get any smaller when resized to a smaller size,
331 // or when clear() or erase() are called, the size will report that it
332 // is smaller, but the memory allocated remains intact (call capacity()
333 // to see this). So we need to create a temporary vector and swap the
334 // contents which will cause just the internal pointers to be swapped
335 // so that when temporary vector goes out of scope, it will destroy the
336 // contents.
337 std::vector<DWARFDebugInfoEntryMinimal> TmpArray;
338 DieArray.swap(TmpArray);
339 // Save at least the compile unit DIE
340 if (KeepCUDie)
341 DieArray.push_back(TmpArray.front());
342 }
343}
344
Alexey Samsonov762343d2014-04-18 17:25:46 +0000345void DWARFUnit::collectAddressRanges(DWARFAddressRangesVector &CURanges) {
Alexey Samsonov7a18c062015-05-19 21:54:32 +0000346 const auto *U = getUnitDIE();
347 if (U == nullptr)
348 return;
349 // First, check if unit DIE describes address ranges for the whole unit.
350 const auto &CUDIERanges = U->getAddressRanges(this);
Alexey Samsonov84e24232014-04-18 20:30:27 +0000351 if (!CUDIERanges.empty()) {
352 CURanges.insert(CURanges.end(), CUDIERanges.begin(), CUDIERanges.end());
353 return;
354 }
355
David Blaikie07e22442013-09-23 22:44:40 +0000356 // This function is usually called if there in no .debug_aranges section
357 // in order to produce a compile unit level set of address ranges that
358 // is accurate. If the DIEs weren't parsed, then we don't want all dies for
359 // all compile units to stay loaded when they weren't needed. So we can end
360 // up parsing the DWARF and then throwing them all away to keep memory usage
361 // down.
Alexey Samsonov762343d2014-04-18 17:25:46 +0000362 const bool ClearDIEs = extractDIEsIfNeeded(false) > 1;
363 DieArray[0].collectChildrenAddressRanges(this, CURanges);
364
365 // Collect address ranges from DIEs in .dwo if necessary.
David Blaikie07e22442013-09-23 22:44:40 +0000366 bool DWOCreated = parseDWO();
Alexey Samsonov762343d2014-04-18 17:25:46 +0000367 if (DWO.get())
368 DWO->getUnit()->collectAddressRanges(CURanges);
369 if (DWOCreated)
David Blaikie07e22442013-09-23 22:44:40 +0000370 DWO.reset();
371
372 // Keep memory down by clearing DIEs if this generate function
373 // caused them to be parsed.
Alexey Samsonov762343d2014-04-18 17:25:46 +0000374 if (ClearDIEs)
David Blaikie07e22442013-09-23 22:44:40 +0000375 clearDIEs(true);
376}
377
378const DWARFDebugInfoEntryMinimal *
379DWARFUnit::getSubprogramForAddress(uint64_t Address) {
380 extractDIEsIfNeeded(false);
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000381 for (const DWARFDebugInfoEntryMinimal &DIE : DieArray) {
382 if (DIE.isSubprogramDIE() &&
383 DIE.addressRangeContainsAddress(this, Address)) {
384 return &DIE;
David Blaikie07e22442013-09-23 22:44:40 +0000385 }
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000386 }
Craig Topper2617dcc2014-04-15 06:32:26 +0000387 return nullptr;
David Blaikie07e22442013-09-23 22:44:40 +0000388}
389
390DWARFDebugInfoEntryInlinedChain
391DWARFUnit::getInlinedChainForAddress(uint64_t Address) {
392 // First, find a subprogram that contains the given address (the root
393 // of inlined chain).
Craig Topper2617dcc2014-04-15 06:32:26 +0000394 const DWARFUnit *ChainCU = nullptr;
David Blaikie9a4f3cb2016-04-22 21:32:59 +0000395 const DWARFDebugInfoEntryMinimal *SubprogramDIE;
396 // Try to look for subprogram DIEs in the DWO file.
397 parseDWO();
398 if (DWO) {
399 if ((SubprogramDIE = DWO->getUnit()->getSubprogramForAddress(Address)))
400 ChainCU = DWO->getUnit();
401 } else if ((SubprogramDIE = getSubprogramForAddress(Address)))
David Blaikie07e22442013-09-23 22:44:40 +0000402 ChainCU = this;
David Blaikie07e22442013-09-23 22:44:40 +0000403
404 // Get inlined chain rooted at this subprogram DIE.
405 if (!SubprogramDIE)
406 return DWARFDebugInfoEntryInlinedChain();
407 return SubprogramDIE->getInlinedChainForAddress(ChainCU, Address);
408}
David Blaikie82641be2015-11-17 00:39:55 +0000409
410const DWARFUnitIndex &getDWARFUnitIndex(DWARFContext &Context,
411 DWARFSectionKind Kind) {
412 if (Kind == DW_SECT_INFO)
413 return Context.getCUIndex();
414 assert(Kind == DW_SECT_TYPES);
415 return Context.getTUIndex();
416}
Eugene Zelenko570e39a2016-11-23 23:16:32 +0000417
418} // end namespace llvm