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 const DWARFDebugAbbrev *Abbrev;
27 StringRef InfoSection;
28 StringRef AbbrevSection;
29 StringRef RangeSection;
30 StringRef StringSection;
31 StringRef StringOffsetSection;
32 StringRef AddrOffsetSection;
33 const RelocAddrMap *RelocMap;
39 const DWARFAbbreviationDeclarationSet *Abbrevs;
42 // The compile unit debug information entry items.
43 std::vector<DWARFDebugInfoEntryMinimal> DieArray;
46 DWARFCompileUnit(const DWARFDebugAbbrev *DA, StringRef IS, StringRef AS,
47 StringRef RS, StringRef SS, StringRef SOS, StringRef AOS,
48 const RelocAddrMap *M, bool LE) :
49 Abbrev(DA), InfoSection(IS), AbbrevSection(AS),
50 RangeSection(RS), StringSection(SS), StringOffsetSection(SOS),
51 AddrOffsetSection(AOS), RelocMap(M), isLittleEndian(LE) {
55 StringRef getStringSection() const { return StringSection; }
56 StringRef getStringOffsetSection() const { return StringOffsetSection; }
57 StringRef getAddrOffsetSection() const { return AddrOffsetSection; }
58 const RelocAddrMap *getRelocMap() const { return RelocMap; }
59 DataExtractor getDebugInfoExtractor() const;
61 bool extract(DataExtractor debug_info, uint32_t* offset_ptr);
62 uint32_t extract(uint32_t offset, DataExtractor debug_info_data,
63 const DWARFAbbreviationDeclarationSet *abbrevs);
65 /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
66 /// hasn't already been done. Returns the number of DIEs parsed at this call.
67 size_t extractDIEsIfNeeded(bool CUDieOnly);
68 /// extractRangeList - extracts the range list referenced by this compile
69 /// unit from .debug_ranges section. Returns true on success.
70 /// Requires that compile unit is already extracted.
71 bool extractRangeList(uint32_t RangeListOffset,
72 DWARFDebugRangeList &RangeList) const;
74 void dump(raw_ostream &OS);
75 uint32_t getOffset() const { return Offset; }
76 /// Size in bytes of the compile unit header.
77 uint32_t getSize() const { return 11; }
78 bool containsDIEOffset(uint32_t die_offset) const {
79 return die_offset >= getFirstDIEOffset() &&
80 die_offset < getNextCompileUnitOffset();
82 uint32_t getFirstDIEOffset() const { return Offset + getSize(); }
83 uint32_t getNextCompileUnitOffset() const { return Offset + Length + 4; }
84 /// Size in bytes of the .debug_info data associated with this compile unit.
85 size_t getDebugInfoSize() const { return Length + 4 - getSize(); }
86 uint32_t getLength() const { return Length; }
87 uint16_t getVersion() const { return Version; }
88 const DWARFAbbreviationDeclarationSet *getAbbreviations() const {
91 uint8_t getAddressByteSize() const { return AddrSize; }
92 uint64_t getBaseAddress() const { return BaseAddr; }
94 void setBaseAddress(uint64_t base_addr) {
98 const DWARFDebugInfoEntryMinimal *
99 getCompileUnitDIE(bool extract_cu_die_only = true) {
100 extractDIEsIfNeeded(extract_cu_die_only);
101 return DieArray.empty() ? NULL : &DieArray[0];
104 const char *getCompilationDir();
106 /// setDIERelations - We read in all of the DIE entries into our flat list
107 /// of DIE entries and now we need to go back through all of them and set the
108 /// parent, sibling and child pointers for quick DIE navigation.
109 void setDIERelations();
111 void buildAddressRangeTable(DWARFDebugAranges *debug_aranges,
112 bool clear_dies_if_already_not_parsed);
114 /// getInlinedChainForAddress - fetches inlined chain for a given address.
115 /// Returns empty chain if there is no subprogram containing address.
116 DWARFDebugInfoEntryMinimal::InlinedChain getInlinedChainForAddress(
120 /// extractDIEsToVector - Appends all parsed DIEs to a vector.
121 void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs,
122 std::vector<DWARFDebugInfoEntryMinimal> &DIEs) const;
123 /// clearDIEs - Clear parsed DIEs to keep memory usage low.
124 void clearDIEs(bool KeepCUDie);