DWARFUnit.h 20 KB

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