1 //===-- DWARFCompileUnit.h --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_DWARFCOMPILEUNIT_H
11 #define LLVM_DEBUGINFO_DWARFCOMPILEUNIT_H
13 #include "DWARFDebugAbbrev.h"
14 #include "DWARFDebugInfoEntry.h"
15 #include "DWARFDebugRangeList.h"
16 #include "DWARFRelocMap.h"
21 class DWARFDebugAbbrev;
25 class DWARFCompileUnit {
26 DWARFCompileUnit(DWARFCompileUnit const &) LLVM_DELETED_FUNCTION;
27 DWARFCompileUnit &operator=(DWARFCompileUnit const &) LLVM_DELETED_FUNCTION;
29 const DWARFDebugAbbrev *Abbrev;
30 StringRef InfoSection;
31 StringRef AbbrevSection;
32 StringRef RangeSection;
33 StringRef StringSection;
34 StringRef StringOffsetSection;
35 StringRef AddrOffsetSection;
36 const RelocAddrMap *RelocMap;
42 const DWARFAbbreviationDeclarationSet *Abbrevs;
45 // The compile unit debug information entry items.
46 std::vector<DWARFDebugInfoEntryMinimal> DieArray;
49 DWARFCompileUnit(const DWARFDebugAbbrev *DA, StringRef IS, StringRef AS,
50 StringRef RS, StringRef SS, StringRef SOS, StringRef AOS,
51 const RelocAddrMap *M, bool LE) :
52 Abbrev(DA), InfoSection(IS), AbbrevSection(AS),
53 RangeSection(RS), StringSection(SS), StringOffsetSection(SOS),
54 AddrOffsetSection(AOS), RelocMap(M), isLittleEndian(LE) {
58 StringRef getStringSection() const { return StringSection; }
59 StringRef getStringOffsetSection() const { return StringOffsetSection; }
60 StringRef getAddrOffsetSection() const { return AddrOffsetSection; }
61 const RelocAddrMap *getRelocMap() const { return RelocMap; }
62 DataExtractor getDebugInfoExtractor() const;
64 bool extract(DataExtractor debug_info, uint32_t* offset_ptr);
65 uint32_t extract(uint32_t offset, DataExtractor debug_info_data,
66 const DWARFAbbreviationDeclarationSet *abbrevs);
68 /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
69 /// hasn't already been done. Returns the number of DIEs parsed at this call.
70 size_t extractDIEsIfNeeded(bool CUDieOnly);
71 /// extractRangeList - extracts the range list referenced by this compile
72 /// unit from .debug_ranges section. Returns true on success.
73 /// Requires that compile unit is already extracted.
74 bool extractRangeList(uint32_t RangeListOffset,
75 DWARFDebugRangeList &RangeList) const;
77 void dump(raw_ostream &OS);
78 uint32_t getOffset() const { return Offset; }
79 /// Size in bytes of the compile unit header.
80 uint32_t getSize() const { return 11; }
81 bool containsDIEOffset(uint32_t die_offset) const {
82 return die_offset >= getFirstDIEOffset() &&
83 die_offset < getNextCompileUnitOffset();
85 uint32_t getFirstDIEOffset() const { return Offset + getSize(); }
86 uint32_t getNextCompileUnitOffset() const { return Offset + Length + 4; }
87 /// Size in bytes of the .debug_info data associated with this compile unit.
88 size_t getDebugInfoSize() const { return Length + 4 - getSize(); }
89 uint32_t getLength() const { return Length; }
90 uint16_t getVersion() const { return Version; }
91 const DWARFAbbreviationDeclarationSet *getAbbreviations() const {
94 uint8_t getAddressByteSize() const { return AddrSize; }
95 uint64_t getBaseAddress() const { return BaseAddr; }
97 void setBaseAddress(uint64_t base_addr) {
101 const DWARFDebugInfoEntryMinimal *
102 getCompileUnitDIE(bool extract_cu_die_only = true) {
103 extractDIEsIfNeeded(extract_cu_die_only);
104 return DieArray.empty() ? NULL : &DieArray[0];
107 const char *getCompilationDir();
109 /// setDIERelations - We read in all of the DIE entries into our flat list
110 /// of DIE entries and now we need to go back through all of them and set the
111 /// parent, sibling and child pointers for quick DIE navigation.
112 void setDIERelations();
114 void buildAddressRangeTable(DWARFDebugAranges *debug_aranges,
115 bool clear_dies_if_already_not_parsed);
117 /// getInlinedChainForAddress - fetches inlined chain for a given address.
118 /// Returns empty chain if there is no subprogram containing address. The
119 /// chain is valid as long as parsed compile unit DIEs are not cleared.
120 DWARFDebugInfoEntryInlinedChain getInlinedChainForAddress(uint64_t Address);
123 /// extractDIEsToVector - Appends all parsed DIEs to a vector.
124 void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs,
125 std::vector<DWARFDebugInfoEntryMinimal> &DIEs) const;
126 /// clearDIEs - Clear parsed DIEs to keep memory usage low.
127 void clearDIEs(bool KeepCUDie);