blob: 0908504f000cad030ba5272fb576f99c8a7fd473 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- DWARFUnit.h ----------------------------------------------*- C++ -*-===//
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#ifndef LLVM_DEBUGINFO_DWARF_DWARFUNIT_H
11#define LLVM_DEBUGINFO_DWARF_DWARFUNIT_H
12
13#include "llvm/ADT/Optional.h"
14#include "llvm/ADT/STLExtras.h"
15#include "llvm/ADT/SmallVector.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/ADT/iterator_range.h"
18#include "llvm/BinaryFormat/Dwarf.h"
19#include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
20#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
Andrew Scullcdfcccc2018-10-05 20:58:37 +010021#include "llvm/DebugInfo/DWARF/DWARFDebugRnglists.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010022#include "llvm/DebugInfo/DWARF/DWARFDie.h"
23#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
24#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
25#include "llvm/DebugInfo/DWARF/DWARFSection.h"
26#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
27#include "llvm/Support/DataExtractor.h"
28#include <algorithm>
29#include <cassert>
30#include <cstddef>
31#include <cstdint>
32#include <map>
33#include <memory>
34#include <utility>
35#include <vector>
36
37namespace llvm {
38
39class DWARFAbbreviationDeclarationSet;
40class DWARFContext;
41class DWARFDebugAbbrev;
42class DWARFUnit;
43
Andrew Scullcdfcccc2018-10-05 20:58:37 +010044/// Base class describing the header of any kind of "unit." Some information
45/// is specific to certain unit types. We separate this class out so we can
46/// parse the header before deciding what specific kind of unit to construct.
47class DWARFUnitHeader {
48 // Offset within section.
49 uint32_t Offset = 0;
50 // Version, address size, and DWARF format.
51 dwarf::FormParams FormParams;
52 uint32_t Length = 0;
53 uint64_t AbbrOffset = 0;
54
55 // For DWO units only.
56 const DWARFUnitIndex::Entry *IndexEntry = nullptr;
57
58 // For type units only.
59 uint64_t TypeHash = 0;
60 uint32_t TypeOffset = 0;
61
62 // For v5 split or skeleton compile units only.
63 Optional<uint64_t> DWOId;
64
65 // Unit type as parsed, or derived from the section kind.
66 uint8_t UnitType = 0;
67
68 // Size as parsed. uint8_t for compactness.
69 uint8_t Size = 0;
70
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010071public:
Andrew Scullcdfcccc2018-10-05 20:58:37 +010072 /// Parse a unit header from \p debug_info starting at \p offset_ptr.
73 bool extract(DWARFContext &Context, const DWARFDataExtractor &debug_info,
74 uint32_t *offset_ptr, DWARFSectionKind Kind = DW_SECT_INFO,
75 const DWARFUnitIndex *Index = nullptr);
76 uint32_t getOffset() const { return Offset; }
77 const dwarf::FormParams &getFormParams() const { return FormParams; }
78 uint16_t getVersion() const { return FormParams.Version; }
79 dwarf::DwarfFormat getFormat() const { return FormParams.Format; }
80 uint8_t getAddressByteSize() const { return FormParams.AddrSize; }
81 uint8_t getRefAddrByteSize() const { return FormParams.getRefAddrByteSize(); }
82 uint8_t getDwarfOffsetByteSize() const {
83 return FormParams.getDwarfOffsetByteSize();
84 }
85 uint32_t getLength() const { return Length; }
86 uint64_t getAbbrOffset() const { return AbbrOffset; }
87 Optional<uint64_t> getDWOId() const { return DWOId; }
88 void setDWOId(uint64_t Id) {
89 assert((!DWOId || *DWOId == Id) && "setting DWOId to a different value");
90 DWOId = Id;
91 }
92 const DWARFUnitIndex::Entry *getIndexEntry() const { return IndexEntry; }
93 uint64_t getTypeHash() const { return TypeHash; }
94 uint32_t getTypeOffset() const { return TypeOffset; }
95 uint8_t getUnitType() const { return UnitType; }
96 bool isTypeUnit() const {
97 return UnitType == dwarf::DW_UT_type || UnitType == dwarf::DW_UT_split_type;
98 }
99 uint8_t getSize() const { return Size; }
100 // FIXME: Support DWARF64.
101 uint32_t getNextUnitOffset() const { return Offset + Length + 4; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100102};
103
104const DWARFUnitIndex &getDWARFUnitIndex(DWARFContext &Context,
105 DWARFSectionKind Kind);
106
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100107/// Describe a collection of units. Intended to hold all units either from
108/// .debug_info and .debug_types, or from .debug_info.dwo and .debug_types.dwo.
109class DWARFUnitVector final : public SmallVector<std::unique_ptr<DWARFUnit>, 1> {
110 std::function<std::unique_ptr<DWARFUnit>(uint32_t, DWARFSectionKind,
111 const DWARFSection *)>
112 Parser;
113 unsigned NumInfoUnits = 0;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100114
115public:
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100116 using UnitVector = SmallVectorImpl<std::unique_ptr<DWARFUnit>>;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100117 using iterator = typename UnitVector::iterator;
118 using iterator_range = llvm::iterator_range<typename UnitVector::iterator>;
119
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100120 DWARFUnit *getUnitForOffset(uint32_t Offset) const;
121 DWARFUnit *getUnitForIndexEntry(const DWARFUnitIndex::Entry &E);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100122
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100123 /// Read units from a .debug_info or .debug_types section. Calls made
124 /// before finishedInfoUnits() are assumed to be for .debug_info sections,
125 /// calls after finishedInfoUnits() are for .debug_types sections. Caller
126 /// must not mix calls to addUnitsForSection and addUnitsForDWOSection.
127 void addUnitsForSection(DWARFContext &C, const DWARFSection &Section,
128 DWARFSectionKind SectionKind);
129 /// Read units from a .debug_info.dwo or .debug_types.dwo section. Calls
130 /// made before finishedInfoUnits() are assumed to be for .debug_info.dwo
131 /// sections, calls after finishedInfoUnits() are for .debug_types.dwo
132 /// sections. Caller must not mix calls to addUnitsForSection and
133 /// addUnitsForDWOSection.
134 void addUnitsForDWOSection(DWARFContext &C, const DWARFSection &DWOSection,
135 DWARFSectionKind SectionKind, bool Lazy = false);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100136
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100137 /// Returns number of all units held by this instance.
138 unsigned getNumUnits() { return size(); }
139 /// Returns number of units from all .debug_info[.dwo] sections.
140 unsigned getNumInfoUnits() { return NumInfoUnits; }
141 /// Returns number of units from all .debug_types[.dwo] sections.
142 unsigned getNumTypesUnits() { return size() - NumInfoUnits; }
143 /// Indicate that parsing .debug_info[.dwo] is done, and remaining units
144 /// will be from .debug_types[.dwo].
145 void finishedInfoUnits() { NumInfoUnits = size(); }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100146
147private:
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100148 void addUnitsImpl(DWARFContext &Context, const DWARFObject &Obj,
149 const DWARFSection &Section, const DWARFDebugAbbrev *DA,
150 const DWARFSection *RS, StringRef SS,
151 const DWARFSection &SOS, const DWARFSection *AOS,
152 const DWARFSection &LS, bool LE, bool IsDWO, bool Lazy,
153 DWARFSectionKind SectionKind);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100154};
155
156/// Represents base address of the CU.
157struct BaseAddress {
158 uint64_t Address;
159 uint64_t SectionIndex;
160};
161
162/// Represents a unit's contribution to the string offsets table.
163struct StrOffsetsContributionDescriptor {
164 uint64_t Base = 0;
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100165 /// The contribution size not including the header.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100166 uint64_t Size = 0;
167 /// Format and version.
168 dwarf::FormParams FormParams = {0, 0, dwarf::DwarfFormat::DWARF32};
169
170 StrOffsetsContributionDescriptor(uint64_t Base, uint64_t Size,
171 uint8_t Version, dwarf::DwarfFormat Format)
172 : Base(Base), Size(Size), FormParams({Version, 0, Format}) {}
173
174 uint8_t getVersion() const { return FormParams.Version; }
175 dwarf::DwarfFormat getFormat() const { return FormParams.Format; }
176 uint8_t getDwarfOffsetByteSize() const {
177 return FormParams.getDwarfOffsetByteSize();
178 }
179 /// Determine whether a contribution to the string offsets table is
180 /// consistent with the relevant section size and that its length is
181 /// a multiple of the size of one of its entries.
182 Optional<StrOffsetsContributionDescriptor>
183 validateContributionSize(DWARFDataExtractor &DA);
184};
185
186class DWARFUnit {
187 DWARFContext &Context;
188 /// Section containing this DWARFUnit.
189 const DWARFSection &InfoSection;
190
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100191 DWARFUnitHeader Header;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100192 const DWARFDebugAbbrev *Abbrev;
193 const DWARFSection *RangeSection;
194 uint32_t RangeSectionBase;
195 const DWARFSection &LineSection;
196 StringRef StringSection;
197 const DWARFSection &StringOffsetSection;
198 const DWARFSection *AddrOffsetSection;
199 uint32_t AddrOffsetSectionBase = 0;
200 bool isLittleEndian;
201 bool isDWO;
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100202 const DWARFUnitVector &UnitVector;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100203
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100204 /// Start, length, and DWARF format of the unit's contribution to the string
205 /// offsets table (DWARF v5).
206 Optional<StrOffsetsContributionDescriptor> StringOffsetsTableContribution;
207
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100208 /// A table of range lists (DWARF v5 and later).
209 Optional<DWARFDebugRnglistTable> RngListTable;
210
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100211 mutable const DWARFAbbreviationDeclarationSet *Abbrevs;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100212 llvm::Optional<BaseAddress> BaseAddr;
213 /// The compile unit debug information entry items.
214 std::vector<DWARFDebugInfoEntry> DieArray;
215
216 /// Map from range's start address to end address and corresponding DIE.
217 /// IntervalMap does not support range removal, as a result, we use the
218 /// std::map::upper_bound for address range lookup.
219 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> AddrDieMap;
220
221 using die_iterator_range =
222 iterator_range<std::vector<DWARFDebugInfoEntry>::iterator>;
223
224 std::shared_ptr<DWARFUnit> DWO;
225
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100226 uint32_t getDIEIndex(const DWARFDebugInfoEntry *Die) {
227 auto First = DieArray.data();
228 assert(Die >= First && Die < First + DieArray.size());
229 return Die - First;
230 }
231
232protected:
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100233 const DWARFUnitHeader &getHeader() const { return Header; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100234
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100235 /// Size in bytes of the parsed unit header.
236 uint32_t getHeaderSize() const { return Header.getSize(); }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100237
238 /// Find the unit's contribution to the string offsets table and determine its
239 /// length and form. The given offset is expected to be derived from the unit
240 /// DIE's DW_AT_str_offsets_base attribute.
241 Optional<StrOffsetsContributionDescriptor>
242 determineStringOffsetsTableContribution(DWARFDataExtractor &DA,
243 uint64_t Offset);
244
245 /// Find the unit's contribution to the string offsets table and determine its
246 /// length and form. The given offset is expected to be 0 in a dwo file or,
247 /// in a dwp file, the start of the unit's contribution to the string offsets
248 /// table section (as determined by the index table).
249 Optional<StrOffsetsContributionDescriptor>
250 determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA,
251 uint64_t Offset);
252
253public:
254 DWARFUnit(DWARFContext &Context, const DWARFSection &Section,
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100255 const DWARFUnitHeader &Header,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100256 const DWARFDebugAbbrev *DA, const DWARFSection *RS, StringRef SS,
257 const DWARFSection &SOS, const DWARFSection *AOS,
258 const DWARFSection &LS, bool LE, bool IsDWO,
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100259 const DWARFUnitVector &UnitVector);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100260
261 virtual ~DWARFUnit();
262
263 DWARFContext& getContext() const { return Context; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100264 const DWARFSection &getInfoSection() const { return InfoSection; }
265 uint32_t getOffset() const { return Header.getOffset(); }
266 const dwarf::FormParams &getFormParams() const {
267 return Header.getFormParams();
268 }
269 uint16_t getVersion() const { return Header.getVersion(); }
270 uint8_t getAddressByteSize() const { return Header.getAddressByteSize(); }
271 uint8_t getRefAddrByteSize() const { return Header.getRefAddrByteSize(); }
272 uint8_t getDwarfOffsetByteSize() const {
273 return Header.getDwarfOffsetByteSize();
274 }
275 uint32_t getLength() const { return Header.getLength(); }
276 uint8_t getUnitType() const { return Header.getUnitType(); }
277 bool isTypeUnit() const { return Header.isTypeUnit(); }
278 uint32_t getNextUnitOffset() const { return Header.getNextUnitOffset(); }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100279 const DWARFSection &getLineSection() const { return LineSection; }
280 StringRef getStringSection() const { return StringSection; }
281 const DWARFSection &getStringOffsetSection() const {
282 return StringOffsetSection;
283 }
284
285 void setAddrOffsetSection(const DWARFSection *AOS, uint32_t Base) {
286 AddrOffsetSection = AOS;
287 AddrOffsetSectionBase = Base;
288 }
289
290 /// Recursively update address to Die map.
291 void updateAddressDieMap(DWARFDie Die);
292
293 void setRangesSection(const DWARFSection *RS, uint32_t Base) {
294 RangeSection = RS;
295 RangeSectionBase = Base;
296 }
297
298 bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
299 bool getStringOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
300
301 DWARFDataExtractor getDebugInfoExtractor() const;
302
303 DataExtractor getStringExtractor() const {
304 return DataExtractor(StringSection, false, 0);
305 }
306
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100307 /// Extract the range list referenced by this compile unit from the
308 /// .debug_ranges section. If the extraction is unsuccessful, an error
309 /// is returned. Successful extraction requires that the compile unit
310 /// has already been extracted.
311 Error extractRangeList(uint32_t RangeListOffset,
312 DWARFDebugRangeList &RangeList) const;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100313 void clear();
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100314
315 const Optional<StrOffsetsContributionDescriptor> &
316 getStringOffsetsTableContribution() const {
317 return StringOffsetsTableContribution;
318 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100319
320 uint8_t getDwarfStringOffsetsByteSize() const {
321 assert(StringOffsetsTableContribution);
322 return StringOffsetsTableContribution->getDwarfOffsetByteSize();
323 }
324
325 uint64_t getStringOffsetsBase() const {
326 assert(StringOffsetsTableContribution);
327 return StringOffsetsTableContribution->Base;
328 }
329
330 const DWARFAbbreviationDeclarationSet *getAbbreviations() const;
331
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100332 static bool isMatchingUnitTypeAndTag(uint8_t UnitType, dwarf::Tag Tag) {
333 switch (UnitType) {
334 case dwarf::DW_UT_compile:
335 return Tag == dwarf::DW_TAG_compile_unit;
336 case dwarf::DW_UT_type:
337 return Tag == dwarf::DW_TAG_type_unit;
338 case dwarf::DW_UT_partial:
339 return Tag == dwarf::DW_TAG_partial_unit;
340 case dwarf::DW_UT_skeleton:
341 return Tag == dwarf::DW_TAG_skeleton_unit;
342 case dwarf::DW_UT_split_compile:
343 case dwarf::DW_UT_split_type:
344 return dwarf::isUnitType(Tag);
345 }
346 return false;
347 }
348
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100349 /// Return the number of bytes for the header of a unit of
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100350 /// UnitType type.
351 ///
352 /// This function must be called with a valid unit type which in
353 /// DWARF5 is defined as one of the following six types.
354 static uint32_t getDWARF5HeaderSize(uint8_t UnitType) {
355 switch (UnitType) {
356 case dwarf::DW_UT_compile:
357 case dwarf::DW_UT_partial:
358 return 12;
359 case dwarf::DW_UT_skeleton:
360 case dwarf::DW_UT_split_compile:
361 return 20;
362 case dwarf::DW_UT_type:
363 case dwarf::DW_UT_split_type:
364 return 24;
365 }
366 llvm_unreachable("Invalid UnitType.");
367 }
368
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100369 llvm::Optional<BaseAddress> getBaseAddress();
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100370
371 DWARFDie getUnitDIE(bool ExtractUnitDIEOnly = true) {
372 extractDIEsIfNeeded(ExtractUnitDIEOnly);
373 if (DieArray.empty())
374 return DWARFDie();
375 return DWARFDie(this, &DieArray[0]);
376 }
377
378 const char *getCompilationDir();
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100379 Optional<uint64_t> getDWOId() {
380 extractDIEsIfNeeded(/*CUDieOnly*/ true);
381 return getHeader().getDWOId();
382 }
383 void setDWOId(uint64_t NewID) { Header.setDWOId(NewID); }
384
385 /// Return a vector of address ranges resulting from a (possibly encoded)
386 /// range list starting at a given offset in the appropriate ranges section.
387 Expected<DWARFAddressRangesVector> findRnglistFromOffset(uint32_t Offset);
388
389 /// Return a vector of address ranges retrieved from an encoded range
390 /// list whose offset is found via a table lookup given an index (DWARF v5
391 /// and later).
392 Expected<DWARFAddressRangesVector> findRnglistFromIndex(uint32_t Index);
393
394 /// Return a rangelist's offset based on an index. The index designates
395 /// an entry in the rangelist table's offset array and is supplied by
396 /// DW_FORM_rnglistx.
397 Optional<uint32_t> getRnglistOffset(uint32_t Index) {
398 if (RngListTable)
399 return RngListTable->getOffsetEntry(Index);
400 return None;
401 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100402
403 void collectAddressRanges(DWARFAddressRangesVector &CURanges);
404
405 /// Returns subprogram DIE with address range encompassing the provided
406 /// address. The pointer is alive as long as parsed compile unit DIEs are not
407 /// cleared.
408 DWARFDie getSubroutineForAddress(uint64_t Address);
409
410 /// getInlinedChainForAddress - fetches inlined chain for a given address.
411 /// Returns empty chain if there is no subprogram containing address. The
412 /// chain is valid as long as parsed compile unit DIEs are not cleared.
413 void getInlinedChainForAddress(uint64_t Address,
414 SmallVectorImpl<DWARFDie> &InlinedChain);
415
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100416 /// Return the DWARFUnitVector containing this unit.
417 const DWARFUnitVector &getUnitVector() const { return UnitVector; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100418
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100419 /// Returns the number of DIEs in the unit. Parses the unit
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100420 /// if necessary.
421 unsigned getNumDIEs() {
422 extractDIEsIfNeeded(false);
423 return DieArray.size();
424 }
425
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100426 /// Return the index of a DIE inside the unit's DIE vector.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100427 ///
428 /// It is illegal to call this method with a DIE that hasn't be
429 /// created by this unit. In other word, it's illegal to call this
430 /// method on a DIE that isn't accessible by following
431 /// children/sibling links starting from this unit's getUnitDIE().
432 uint32_t getDIEIndex(const DWARFDie &D) {
433 return getDIEIndex(D.getDebugInfoEntry());
434 }
435
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100436 /// Return the DIE object at the given index.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100437 DWARFDie getDIEAtIndex(unsigned Index) {
438 assert(Index < DieArray.size());
439 return DWARFDie(this, &DieArray[Index]);
440 }
441
442 DWARFDie getParent(const DWARFDebugInfoEntry *Die);
443 DWARFDie getSibling(const DWARFDebugInfoEntry *Die);
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100444 DWARFDie getPreviousSibling(const DWARFDebugInfoEntry *Die);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100445 DWARFDie getFirstChild(const DWARFDebugInfoEntry *Die);
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100446 DWARFDie getLastChild(const DWARFDebugInfoEntry *Die);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100447
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100448 /// Return the DIE object for a given offset inside the
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100449 /// unit's DIE vector.
450 ///
451 /// The unit needs to have its DIEs extracted for this method to work.
452 DWARFDie getDIEForOffset(uint32_t Offset) {
453 extractDIEsIfNeeded(false);
454 assert(!DieArray.empty());
455 auto it = std::lower_bound(
456 DieArray.begin(), DieArray.end(), Offset,
457 [](const DWARFDebugInfoEntry &LHS, uint32_t Offset) {
458 return LHS.getOffset() < Offset;
459 });
460 if (it != DieArray.end() && it->getOffset() == Offset)
461 return DWARFDie(this, &*it);
462 return DWARFDie();
463 }
464
465 uint32_t getLineTableOffset() const {
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100466 if (auto IndexEntry = Header.getIndexEntry())
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100467 if (const auto *Contrib = IndexEntry->getOffset(DW_SECT_LINE))
468 return Contrib->Offset;
469 return 0;
470 }
471
472 die_iterator_range dies() {
473 extractDIEsIfNeeded(false);
474 return die_iterator_range(DieArray.begin(), DieArray.end());
475 }
476
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100477 virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts) = 0;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100478private:
479 /// Size in bytes of the .debug_info data associated with this compile unit.
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100480 size_t getDebugInfoSize() const {
481 return Header.getLength() + 4 - getHeaderSize();
482 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100483
484 /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
485 /// hasn't already been done. Returns the number of DIEs parsed at this call.
486 size_t extractDIEsIfNeeded(bool CUDieOnly);
487
488 /// extractDIEsToVector - Appends all parsed DIEs to a vector.
489 void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs,
490 std::vector<DWARFDebugInfoEntry> &DIEs) const;
491
492 /// clearDIEs - Clear parsed DIEs to keep memory usage low.
493 void clearDIEs(bool KeepCUDie);
494
495 /// parseDWO - Parses .dwo file for current compile unit. Returns true if
496 /// it was actually constructed.
497 bool parseDWO();
498};
499
500} // end namespace llvm
501
502#endif // LLVM_DEBUGINFO_DWARF_DWARFUNIT_H