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"
22 class DWARFCompileUnit {
23 DWARFContext &Context;
28 const DWARFAbbreviationDeclarationSet *Abbrevs;
31 // The compile unit debug information entry item.
32 std::vector<DWARFDebugInfoEntryMinimal> DieArray;
34 DWARFCompileUnit(DWARFContext &context) : Context(context) {
38 DWARFContext &getContext() const { return Context; }
39 DataExtractor getDebugInfoExtractor() const;
41 bool extract(DataExtractor debug_info, uint32_t* offset_ptr);
42 uint32_t extract(uint32_t offset, DataExtractor debug_info_data,
43 const DWARFAbbreviationDeclarationSet *abbrevs);
45 /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
46 /// hasn't already been done.
47 size_t extractDIEsIfNeeded(bool cu_die_only);
49 void dump(raw_ostream &OS);
50 uint32_t getOffset() const { return Offset; }
51 /// Size in bytes of the compile unit header.
52 uint32_t getSize() const { return 11; }
53 bool containsDIEOffset(uint32_t die_offset) const {
54 return die_offset >= getFirstDIEOffset() &&
55 die_offset < getNextCompileUnitOffset();
57 uint32_t getFirstDIEOffset() const { return Offset + getSize(); }
58 uint32_t getNextCompileUnitOffset() const { return Offset + Length + 4; }
59 /// Size in bytes of the .debug_info data associated with this compile unit.
60 size_t getDebugInfoSize() const { return Length + 4 - getSize(); }
61 uint32_t getLength() const { return Length; }
62 uint16_t getVersion() const { return Version; }
63 const DWARFAbbreviationDeclarationSet *getAbbreviations() const {
66 uint8_t getAddressByteSize() const { return AddrSize; }
67 uint64_t getBaseAddress() const { return BaseAddr; }
69 void setBaseAddress(uint64_t base_addr) {
73 /// setDIERelations - We read in all of the DIE entries into our flat list
74 /// of DIE entries and now we need to go back through all of them and set the
75 /// parent, sibling and child pointers for quick DIE navigation.
76 void setDIERelations();
78 void addDIE(DWARFDebugInfoEntryMinimal &die) {
79 // The average bytes per DIE entry has been seen to be
80 // around 14-20 so lets pre-reserve the needed memory for
81 // our DIE entries accordingly. Search forward for "Compute
82 // average bytes per DIE" to see #if'ed out code that does
83 // that determination.
85 // Only reserve the memory if we are adding children of
86 // the main compile unit DIE. The compile unit DIE is always
87 // the first entry, so if our size is 1, then we are adding
88 // the first compile unit child DIE and should reserve
91 DieArray.reserve(getDebugInfoSize() / 14);
92 DieArray.push_back(die);
95 void clearDIEs(bool keep_compile_unit_die);
97 void buildAddressRangeTable(DWARFDebugAranges *debug_aranges,
98 bool clear_dies_if_already_not_parsed);