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"
23 class DWARFCompileUnit {
24 DWARFContext &Context;
29 const DWARFAbbreviationDeclarationSet *Abbrevs;
32 // The compile unit debug information entry item.
33 std::vector<DWARFDebugInfoEntryMinimal> DieArray;
35 DWARFCompileUnit(DWARFContext &context) : Context(context) {
39 DWARFContext &getContext() const { return Context; }
40 DataExtractor getDebugInfoExtractor() const;
42 bool extract(DataExtractor debug_info, uint32_t* offset_ptr);
43 uint32_t extract(uint32_t offset, DataExtractor debug_info_data,
44 const DWARFAbbreviationDeclarationSet *abbrevs);
46 /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
47 /// hasn't already been done. Returns the number of DIEs parsed at this call.
48 size_t extractDIEsIfNeeded(bool cu_die_only);
49 /// extractRangeList - extracts the range list referenced by this compile
50 /// unit from .debug_ranges section. Returns true on success.
51 /// Requires that compile unit is already extracted.
52 bool extractRangeList(uint32_t RangeListOffset,
53 DWARFDebugRangeList &RangeList) const;
55 void dump(raw_ostream &OS);
56 uint32_t getOffset() const { return Offset; }
57 /// Size in bytes of the compile unit header.
58 uint32_t getSize() const { return 11; }
59 bool containsDIEOffset(uint32_t die_offset) const {
60 return die_offset >= getFirstDIEOffset() &&
61 die_offset < getNextCompileUnitOffset();
63 uint32_t getFirstDIEOffset() const { return Offset + getSize(); }
64 uint32_t getNextCompileUnitOffset() const { return Offset + Length + 4; }
65 /// Size in bytes of the .debug_info data associated with this compile unit.
66 size_t getDebugInfoSize() const { return Length + 4 - getSize(); }
67 uint32_t getLength() const { return Length; }
68 uint16_t getVersion() const { return Version; }
69 const DWARFAbbreviationDeclarationSet *getAbbreviations() const {
72 uint8_t getAddressByteSize() const { return AddrSize; }
73 uint64_t getBaseAddress() const { return BaseAddr; }
75 void setBaseAddress(uint64_t base_addr) {
79 const DWARFDebugInfoEntryMinimal *
80 getCompileUnitDIE(bool extract_cu_die_only = true) {
81 extractDIEsIfNeeded(extract_cu_die_only);
87 const char *getCompilationDir();
89 /// setDIERelations - We read in all of the DIE entries into our flat list
90 /// of DIE entries and now we need to go back through all of them and set the
91 /// parent, sibling and child pointers for quick DIE navigation.
92 void setDIERelations();
94 void addDIE(DWARFDebugInfoEntryMinimal &die) {
95 // The average bytes per DIE entry has been seen to be
96 // around 14-20 so lets pre-reserve the needed memory for
97 // our DIE entries accordingly. Search forward for "Compute
98 // average bytes per DIE" to see #if'ed out code that does
99 // that determination.
101 // Only reserve the memory if we are adding children of
102 // the main compile unit DIE. The compile unit DIE is always
103 // the first entry, so if our size is 1, then we are adding
104 // the first compile unit child DIE and should reserve
106 if (DieArray.empty())
107 DieArray.reserve(getDebugInfoSize() / 14);
108 DieArray.push_back(die);
111 void clearDIEs(bool keep_compile_unit_die);
113 void buildAddressRangeTable(DWARFDebugAranges *debug_aranges,
114 bool clear_dies_if_already_not_parsed);
116 /// getInlinedChainForAddress - fetches inlined chain for a given address.
117 /// Returns empty chain if there is no subprogram containing address.
118 DWARFDebugInfoEntryMinimal::InlinedChain getInlinedChainForAddress(