1//===- DWARFUnit.h ----------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DEBUGINFO_DWARF_DWARFUNIT_H
10#define LLVM_DEBUGINFO_DWARF_DWARFUNIT_H
11
12#include "llvm/ADT/DenseSet.h"
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/DWARFAddressRange.h"
20#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
21#include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
22#include "llvm/DebugInfo/DWARF/DWARFDie.h"
23#include "llvm/DebugInfo/DWARF/DWARFLocationExpression.h"
24#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
25#include "llvm/Support/DataExtractor.h"
26#include <cassert>
27#include <cstddef>
28#include <cstdint>
29#include <map>
30#include <memory>
31#include <set>
32#include <utility>
33#include <vector>
34
35namespace llvm {
36
37class DWARFAbbreviationDeclarationSet;
38class DWARFContext;
39class DWARFDebugAbbrev;
40class DWARFUnit;
41class DWARFDebugRangeList;
42class DWARFLocationTable;
43class DWARFObject;
44class raw_ostream;
45struct DIDumpOptions;
46struct DWARFSection;
47
48/// Base class describing the header of any kind of "unit." Some information
49/// is specific to certain unit types. We separate this class out so we can
50/// parse the header before deciding what specific kind of unit to construct.
51class DWARFUnitHeader {
52 // Offset within section.
53 uint64_t Offset = 0;
54 // Version, address size, and DWARF format.
55 dwarf::FormParams FormParams;
56 uint64_t Length = 0;
57 uint64_t AbbrOffset = 0;
58
59 // For DWO units only.
60 const DWARFUnitIndex::Entry *IndexEntry = nullptr;
61
62 // For type units only.
63 uint64_t TypeHash = 0;
64 uint64_t TypeOffset = 0;
65
66 // For v5 split or skeleton compile units only.
67 Optional<uint64_t> DWOId;
68
69 // Unit type as parsed, or derived from the section kind.
70 uint8_t UnitType = 0;
71
72 // Size as parsed. uint8_t for compactness.
73 uint8_t Size = 0;
74
75public:
76 /// Parse a unit header from \p debug_info starting at \p offset_ptr.
77 /// Note that \p SectionKind is used as a hint to guess the unit type
78 /// for DWARF formats prior to DWARFv5. In DWARFv5 the unit type is
79 /// explicitly defined in the header and the hint is ignored.
80 bool extract(DWARFContext &Context, const DWARFDataExtractor &debug_info,
81 uint64_t *offset_ptr, DWARFSectionKind SectionKind);
82 // For units in DWARF Package File, remember the index entry and update
83 // the abbreviation offset read by extract().
84 bool applyIndexEntry(const DWARFUnitIndex::Entry *Entry);
85 uint64_t getOffset() const { return Offset; }
86 const dwarf::FormParams &getFormParams() const { return FormParams; }
87 uint16_t getVersion() const { return FormParams.Version; }
88 dwarf::DwarfFormat getFormat() const { return FormParams.Format; }
89 uint8_t getAddressByteSize() const { return FormParams.AddrSize; }
90 uint8_t getRefAddrByteSize() const { return FormParams.getRefAddrByteSize(); }
91 uint8_t getDwarfOffsetByteSize() const {
92 return FormParams.getDwarfOffsetByteSize();
93 }
94 uint64_t getLength() const { return Length; }
95 uint64_t getAbbrOffset() const { return AbbrOffset; }
96 Optional<uint64_t> getDWOId() const { return DWOId; }
97 void setDWOId(uint64_t Id) {
98 assert((!DWOId || *DWOId == Id) && "setting DWOId to a different value");
99 DWOId = Id;
100 }
101 const DWARFUnitIndex::Entry *getIndexEntry() const { return IndexEntry; }
102 uint64_t getTypeHash() const { return TypeHash; }
103 uint64_t getTypeOffset() const { return TypeOffset; }
104 uint8_t getUnitType() const { return UnitType; }
105 bool isTypeUnit() const {
106 return UnitType == dwarf::DW_UT_type || UnitType == dwarf::DW_UT_split_type;
107 }
108 uint8_t getSize() const { return Size; }
109 uint8_t getUnitLengthFieldByteSize() const {
110 return dwarf::getUnitLengthFieldByteSize(FormParams.Format);
111 }
112 uint64_t getNextUnitOffset() const {
113 return Offset + Length + getUnitLengthFieldByteSize();
114 }
115};
116
117const DWARFUnitIndex &getDWARFUnitIndex(DWARFContext &Context,
118 DWARFSectionKind Kind);
119
120bool isCompileUnit(const std::unique_ptr<DWARFUnit> &U);
121
122/// Describe a collection of units. Intended to hold all units either from
123/// .debug_info and .debug_types, or from .debug_info.dwo and .debug_types.dwo.
124class DWARFUnitVector final : public SmallVector<std::unique_ptr<DWARFUnit>, 1> {
125 std::function<std::unique_ptr<DWARFUnit>(uint64_t, DWARFSectionKind,
126 const DWARFSection *,
127 const DWARFUnitIndex::Entry *)>
128 Parser;
129 int NumInfoUnits = -1;
130
131public:
132 using UnitVector = SmallVectorImpl<std::unique_ptr<DWARFUnit>>;
133 using iterator = typename UnitVector::iterator;
134 using iterator_range = llvm::iterator_range<typename UnitVector::iterator>;
135
136 using compile_unit_range =
137 decltype(make_filter_range(std::declval<iterator_range>(), isCompileUnit));
138
139 DWARFUnit *getUnitForOffset(uint64_t Offset) const;
140 DWARFUnit *getUnitForIndexEntry(const DWARFUnitIndex::Entry &E);
141
142 /// Read units from a .debug_info or .debug_types section. Calls made
143 /// before finishedInfoUnits() are assumed to be for .debug_info sections,
144 /// calls after finishedInfoUnits() are for .debug_types sections. Caller
145 /// must not mix calls to addUnitsForSection and addUnitsForDWOSection.
146 void addUnitsForSection(DWARFContext &C, const DWARFSection &Section,
147 DWARFSectionKind SectionKind);
148 /// Read units from a .debug_info.dwo or .debug_types.dwo section. Calls
149 /// made before finishedInfoUnits() are assumed to be for .debug_info.dwo
150 /// sections, calls after finishedInfoUnits() are for .debug_types.dwo
151 /// sections. Caller must not mix calls to addUnitsForSection and
152 /// addUnitsForDWOSection.
153 void addUnitsForDWOSection(DWARFContext &C, const DWARFSection &DWOSection,
154 DWARFSectionKind SectionKind, bool Lazy = false);
155
156 /// Add an existing DWARFUnit to this UnitVector. This is used by the DWARF
157 /// verifier to process unit separately.
158 DWARFUnit *addUnit(std::unique_ptr<DWARFUnit> Unit);
159
160 /// Returns number of all units held by this instance.
161 unsigned getNumUnits() const { return size(); }
162 /// Returns number of units from all .debug_info[.dwo] sections.
163 unsigned getNumInfoUnits() const {
164 return NumInfoUnits == -1 ? size() : NumInfoUnits;
165 }
166 /// Returns number of units from all .debug_types[.dwo] sections.
167 unsigned getNumTypesUnits() const { return size() - NumInfoUnits; }
168 /// Indicate that parsing .debug_info[.dwo] is done, and remaining units
169 /// will be from .debug_types[.dwo].
170 void finishedInfoUnits() { NumInfoUnits = size(); }
171
172private:
173 void addUnitsImpl(DWARFContext &Context, const DWARFObject &Obj,
174 const DWARFSection &Section, const DWARFDebugAbbrev *DA,
175 const DWARFSection *RS, const DWARFSection *LocSection,
176 StringRef SS, const DWARFSection &SOS,
177 const DWARFSection *AOS, const DWARFSection &LS, bool LE,
178 bool IsDWO, bool Lazy, DWARFSectionKind SectionKind);
179};
180
181/// Represents base address of the CU.
182/// Represents a unit's contribution to the string offsets table.
183struct StrOffsetsContributionDescriptor {
184 uint64_t Base = 0;
185 /// The contribution size not including the header.
186 uint64_t Size = 0;
187 /// Format and version.
188 dwarf::FormParams FormParams = {0, 0, dwarf::DwarfFormat::DWARF32};
189
190 StrOffsetsContributionDescriptor(uint64_t Base, uint64_t Size,
191 uint8_t Version, dwarf::DwarfFormat Format)
192 : Base(Base), Size(Size), FormParams({Version, 0, Format}) {}
193 StrOffsetsContributionDescriptor() = default;
194
195 uint8_t getVersion() const { return FormParams.Version; }
196 dwarf::DwarfFormat getFormat() const { return FormParams.Format; }
197 uint8_t getDwarfOffsetByteSize() const {
198 return FormParams.getDwarfOffsetByteSize();
199 }
200 /// Determine whether a contribution to the string offsets table is
201 /// consistent with the relevant section size and that its length is
202 /// a multiple of the size of one of its entries.
203 Expected<StrOffsetsContributionDescriptor>
204 validateContributionSize(DWARFDataExtractor &DA);
205};
206
207class DWARFUnit {
208 DWARFContext &Context;
209 /// Section containing this DWARFUnit.
210 const DWARFSection &InfoSection;
211
212 DWARFUnitHeader Header;
213 const DWARFDebugAbbrev *Abbrev;
214 const DWARFSection *RangeSection;
215 uint64_t RangeSectionBase;
216 uint64_t LocSectionBase;
217
218 /// Location table of this unit.
219 std::unique_ptr<DWARFLocationTable> LocTable;
220
221 const DWARFSection &LineSection;
222 StringRef StringSection;
223 const DWARFSection &StringOffsetSection;
224 const DWARFSection *AddrOffsetSection;
225 DWARFUnit *SU;
226 Optional<uint64_t> AddrOffsetSectionBase;
227 bool isLittleEndian;
228 bool IsDWO;
229 const DWARFUnitVector &UnitVector;
230
231 /// Start, length, and DWARF format of the unit's contribution to the string
232 /// offsets table (DWARF v5).
233 Optional<StrOffsetsContributionDescriptor> StringOffsetsTableContribution;
234
235 mutable const DWARFAbbreviationDeclarationSet *Abbrevs;
236 llvm::Optional<object::SectionedAddress> BaseAddr;
237 /// The compile unit debug information entry items.
238 std::vector<DWARFDebugInfoEntry> DieArray;
239
240 /// Map from range's start address to end address and corresponding DIE.
241 /// IntervalMap does not support range removal, as a result, we use the
242 /// std::map::upper_bound for address range lookup.
243 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> AddrDieMap;
244
245 /// Map from the location (interpreted DW_AT_location) of a DW_TAG_variable,
246 /// to the end address and the corresponding DIE.
247 std::map<uint64_t, std::pair<uint64_t, DWARFDie>> VariableDieMap;
248 DenseSet<uint64_t> RootsParsedForVariables;
249
250 using die_iterator_range =
251 iterator_range<std::vector<DWARFDebugInfoEntry>::iterator>;
252
253 std::shared_ptr<DWARFUnit> DWO;
254
255protected:
256 /// Return the index of a \p Die entry inside the unit's DIE vector.
257 ///
258 /// It is illegal to call this method with a DIE that hasn't be
259 /// created by this unit. In other word, it's illegal to call this
260 /// method on a DIE that isn't accessible by following
261 /// children/sibling links starting from this unit's getUnitDIE().
262 uint32_t getDIEIndex(const DWARFDebugInfoEntry *Die) const {
263 auto First = DieArray.data();
264 assert(Die >= First && Die < First + DieArray.size());
265 return Die - First;
266 }
267
268 /// Return DWARFDebugInfoEntry for the specified index \p Index.
269 const DWARFDebugInfoEntry *getDebugInfoEntry(unsigned Index) const {
270 assert(Index < DieArray.size());
271 return &DieArray[Index];
272 }
273
274 const DWARFDebugInfoEntry *
275 getParentEntry(const DWARFDebugInfoEntry *Die) const;
276 const DWARFDebugInfoEntry *
277 getSiblingEntry(const DWARFDebugInfoEntry *Die) const;
278 const DWARFDebugInfoEntry *
279 getPreviousSiblingEntry(const DWARFDebugInfoEntry *Die) const;
280 const DWARFDebugInfoEntry *
281 getFirstChildEntry(const DWARFDebugInfoEntry *Die) const;
282 const DWARFDebugInfoEntry *
283 getLastChildEntry(const DWARFDebugInfoEntry *Die) const;
284
285 const DWARFUnitHeader &getHeader() const { return Header; }
286
287 /// Find the unit's contribution to the string offsets table and determine its
288 /// length and form. The given offset is expected to be derived from the unit
289 /// DIE's DW_AT_str_offsets_base attribute.
290 Expected<Optional<StrOffsetsContributionDescriptor>>
291 determineStringOffsetsTableContribution(DWARFDataExtractor &DA);
292
293 /// Find the unit's contribution to the string offsets table and determine its
294 /// length and form. The given offset is expected to be 0 in a dwo file or,
295 /// in a dwp file, the start of the unit's contribution to the string offsets
296 /// table section (as determined by the index table).
297 Expected<Optional<StrOffsetsContributionDescriptor>>
298 determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA);
299
300public:
301 DWARFUnit(DWARFContext &Context, const DWARFSection &Section,
302 const DWARFUnitHeader &Header, const DWARFDebugAbbrev *DA,
303 const DWARFSection *RS, const DWARFSection *LocSection,
304 StringRef SS, const DWARFSection &SOS, const DWARFSection *AOS,
305 const DWARFSection &LS, bool LE, bool IsDWO,
306 const DWARFUnitVector &UnitVector);
307
308 virtual ~DWARFUnit();
309
310 bool isDWOUnit() const { return IsDWO; }
311 DWARFContext& getContext() const { return Context; }
312 const DWARFSection &getInfoSection() const { return InfoSection; }
313 uint64_t getOffset() const { return Header.getOffset(); }
314 const dwarf::FormParams &getFormParams() const {
315 return Header.getFormParams();
316 }
317 uint16_t getVersion() const { return Header.getVersion(); }
318 uint8_t getAddressByteSize() const { return Header.getAddressByteSize(); }
319 uint8_t getRefAddrByteSize() const { return Header.getRefAddrByteSize(); }
320 uint8_t getDwarfOffsetByteSize() const {
321 return Header.getDwarfOffsetByteSize();
322 }
323 /// Size in bytes of the parsed unit header.
324 uint32_t getHeaderSize() const { return Header.getSize(); }
325 uint64_t getLength() const { return Header.getLength(); }
326 dwarf::DwarfFormat getFormat() const { return Header.getFormat(); }
327 uint8_t getUnitType() const { return Header.getUnitType(); }
328 bool isTypeUnit() const { return Header.isTypeUnit(); }
329 uint64_t getAbbrOffset() const { return Header.getAbbrOffset(); }
330 uint64_t getNextUnitOffset() const { return Header.getNextUnitOffset(); }
331 const DWARFSection &getLineSection() const { return LineSection; }
332 StringRef getStringSection() const { return StringSection; }
333 const DWARFSection &getStringOffsetSection() const {
334 return StringOffsetSection;
335 }
336
337 void setSkeletonUnit(DWARFUnit *SU) { this->SU = SU; }
338 // Returns itself if not using Split DWARF, or if the unit is a skeleton unit
339 // - otherwise returns the split full unit's corresponding skeleton, if
340 // available.
341 DWARFUnit *getLinkedUnit() { return IsDWO ? SU : this; }
342
343 void setAddrOffsetSection(const DWARFSection *AOS, uint64_t Base) {
344 AddrOffsetSection = AOS;
345 AddrOffsetSectionBase = Base;
346 }
347
348 Optional<uint64_t> getAddrOffsetSectionBase() const {
349 return AddrOffsetSectionBase;
350 }
351
352 /// Recursively update address to Die map.
353 void updateAddressDieMap(DWARFDie Die);
354
355 /// Recursively update address to variable Die map.
356 void updateVariableDieMap(DWARFDie Die);
357
358 void setRangesSection(const DWARFSection *RS, uint64_t Base) {
359 RangeSection = RS;
360 RangeSectionBase = Base;
361 }
362
363 uint64_t getLocSectionBase() const {
364 return LocSectionBase;
365 }
366
367 Optional<object::SectionedAddress>
368 getAddrOffsetSectionItem(uint32_t Index) const;
369 Expected<uint64_t> getStringOffsetSectionItem(uint32_t Index) const;
370
371 DWARFDataExtractor getDebugInfoExtractor() const;
372
373 DataExtractor getStringExtractor() const {
374 return DataExtractor(StringSection, false, 0);
375 }
376
377 const DWARFLocationTable &getLocationTable() { return *LocTable; }
378
379 /// Extract the range list referenced by this compile unit from the
380 /// .debug_ranges section. If the extraction is unsuccessful, an error
381 /// is returned. Successful extraction requires that the compile unit
382 /// has already been extracted.
383 Error extractRangeList(uint64_t RangeListOffset,
384 DWARFDebugRangeList &RangeList) const;
385 void clear();
386
387 const Optional<StrOffsetsContributionDescriptor> &
388 getStringOffsetsTableContribution() const {
389 return StringOffsetsTableContribution;
390 }
391
392 uint8_t getDwarfStringOffsetsByteSize() const {
393 assert(StringOffsetsTableContribution);
394 return StringOffsetsTableContribution->getDwarfOffsetByteSize();
395 }
396
397 uint64_t getStringOffsetsBase() const {
398 assert(StringOffsetsTableContribution);
399 return StringOffsetsTableContribution->Base;
400 }
401
402 uint64_t getAbbreviationsOffset() const { return Header.getAbbrOffset(); }
403
404 const DWARFAbbreviationDeclarationSet *getAbbreviations() const;
405
406 static bool isMatchingUnitTypeAndTag(uint8_t UnitType, dwarf::Tag Tag) {
407 switch (UnitType) {
408 case dwarf::DW_UT_compile:
409 return Tag == dwarf::DW_TAG_compile_unit;
410 case dwarf::DW_UT_type:
411 return Tag == dwarf::DW_TAG_type_unit;
412 case dwarf::DW_UT_partial:
413 return Tag == dwarf::DW_TAG_partial_unit;
414 case dwarf::DW_UT_skeleton:
415 return Tag == dwarf::DW_TAG_skeleton_unit;
416 case dwarf::DW_UT_split_compile:
417 case dwarf::DW_UT_split_type:
418 return dwarf::isUnitType(Tag);
419 }
420 return false;
421 }
422
423 llvm::Optional<object::SectionedAddress> getBaseAddress();
424
425 DWARFDie getUnitDIE(bool ExtractUnitDIEOnly = true) {
426 extractDIEsIfNeeded(ExtractUnitDIEOnly);
427 if (DieArray.empty())
428 return DWARFDie();
429 return DWARFDie(this, &DieArray[0]);
430 }
431
432 DWARFDie getNonSkeletonUnitDIE(bool ExtractUnitDIEOnly = true) {
433 parseDWO();
434 if (DWO)
435 return DWO->getUnitDIE(ExtractUnitDIEOnly);
436 return getUnitDIE(ExtractUnitDIEOnly);
437 }
438
439 const char *getCompilationDir();
440 Optional<uint64_t> getDWOId() {
441 extractDIEsIfNeeded(/*CUDieOnly*/ true);
442 return getHeader().getDWOId();
443 }
444 void setDWOId(uint64_t NewID) { Header.setDWOId(NewID); }
445
446 /// Return a vector of address ranges resulting from a (possibly encoded)
447 /// range list starting at a given offset in the appropriate ranges section.
448 Expected<DWARFAddressRangesVector> findRnglistFromOffset(uint64_t Offset);
449
450 /// Return a vector of address ranges retrieved from an encoded range
451 /// list whose offset is found via a table lookup given an index (DWARF v5
452 /// and later).
453 Expected<DWARFAddressRangesVector> findRnglistFromIndex(uint32_t Index);
454
455 /// Return a rangelist's offset based on an index. The index designates
456 /// an entry in the rangelist table's offset array and is supplied by
457 /// DW_FORM_rnglistx.
458 Optional<uint64_t> getRnglistOffset(uint32_t Index);
459
460 Optional<uint64_t> getLoclistOffset(uint32_t Index);
461
462 Expected<DWARFAddressRangesVector> collectAddressRanges();
463
464 Expected<DWARFLocationExpressionsVector>
465 findLoclistFromOffset(uint64_t Offset);
466
467 /// Returns subprogram DIE with address range encompassing the provided
468 /// address. The pointer is alive as long as parsed compile unit DIEs are not
469 /// cleared.
470 DWARFDie getSubroutineForAddress(uint64_t Address);
471
472 /// Returns variable DIE for the address provided. The pointer is alive as
473 /// long as parsed compile unit DIEs are not cleared.
474 DWARFDie getVariableForAddress(uint64_t Address);
475
476 /// getInlinedChainForAddress - fetches inlined chain for a given address.
477 /// Returns empty chain if there is no subprogram containing address. The
478 /// chain is valid as long as parsed compile unit DIEs are not cleared.
479 void getInlinedChainForAddress(uint64_t Address,
480 SmallVectorImpl<DWARFDie> &InlinedChain);
481
482 /// Return the DWARFUnitVector containing this unit.
483 const DWARFUnitVector &getUnitVector() const { return UnitVector; }
484
485 /// Returns the number of DIEs in the unit. Parses the unit
486 /// if necessary.
487 unsigned getNumDIEs() {
488 extractDIEsIfNeeded(false);
489 return DieArray.size();
490 }
491
492 /// Return the index of a DIE inside the unit's DIE vector.
493 ///
494 /// It is illegal to call this method with a DIE that hasn't be
495 /// created by this unit. In other word, it's illegal to call this
496 /// method on a DIE that isn't accessible by following
497 /// children/sibling links starting from this unit's getUnitDIE().
498 uint32_t getDIEIndex(const DWARFDie &D) const {
499 return getDIEIndex(D.getDebugInfoEntry());
500 }
501
502 /// Return the DIE object at the given index \p Index.
503 DWARFDie getDIEAtIndex(unsigned Index) {
504 return DWARFDie(this, getDebugInfoEntry(Index));
505 }
506
507 DWARFDie getParent(const DWARFDebugInfoEntry *Die);
508 DWARFDie getSibling(const DWARFDebugInfoEntry *Die);
509 DWARFDie getPreviousSibling(const DWARFDebugInfoEntry *Die);
510 DWARFDie getFirstChild(const DWARFDebugInfoEntry *Die);
511 DWARFDie getLastChild(const DWARFDebugInfoEntry *Die);
512
513 /// Return the DIE object for a given offset \p Offset inside the
514 /// unit's DIE vector.
515 DWARFDie getDIEForOffset(uint64_t Offset) {
516 if (Optional<uint32_t> DieIdx = getDIEIndexForOffset(Offset))
517 return DWARFDie(this, &DieArray[*DieIdx]);
518
519 return DWARFDie();
520 }
521
522 /// Return the DIE index for a given offset \p Offset inside the
523 /// unit's DIE vector.
524 Optional<uint32_t> getDIEIndexForOffset(uint64_t Offset) {
525 extractDIEsIfNeeded(false);
526 auto It =
527 llvm::partition_point(DieArray, [=](const DWARFDebugInfoEntry &DIE) {
528 return DIE.getOffset() < Offset;
529 });
530 if (It != DieArray.end() && It->getOffset() == Offset)
531 return It - DieArray.begin();
532 return None;
533 }
534
535 uint32_t getLineTableOffset() const {
536 if (auto IndexEntry = Header.getIndexEntry())
537 if (const auto *Contrib = IndexEntry->getContribution(DW_SECT_LINE))
538 return Contrib->Offset;
539 return 0;
540 }
541
542 die_iterator_range dies() {
543 extractDIEsIfNeeded(false);
544 return die_iterator_range(DieArray.begin(), DieArray.end());
545 }
546
547 virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts) = 0;
548
549 Error tryExtractDIEsIfNeeded(bool CUDieOnly);
550
551private:
552 /// Size in bytes of the .debug_info data associated with this compile unit.
553 size_t getDebugInfoSize() const {
554 return Header.getLength() + Header.getUnitLengthFieldByteSize() -
555 getHeaderSize();
556 }
557
558 /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
559 /// hasn't already been done
560 void extractDIEsIfNeeded(bool CUDieOnly);
561
562 /// extractDIEsToVector - Appends all parsed DIEs to a vector.
563 void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs,
564 std::vector<DWARFDebugInfoEntry> &DIEs) const;
565
566 /// clearDIEs - Clear parsed DIEs to keep memory usage low.
567 void clearDIEs(bool KeepCUDie);
568
569 /// parseDWO - Parses .dwo file for current compile unit. Returns true if
570 /// it was actually constructed.
571 bool parseDWO();
572};
573
574inline bool isCompileUnit(const std::unique_ptr<DWARFUnit> &U) {
575 return !U->isTypeUnit();
576}
577
578} // end namespace llvm
579
580#endif // LLVM_DEBUGINFO_DWARF_DWARFUNIT_H
581

source code of llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h