LLVM  5.0.0
DwarfFile.h
Go to the documentation of this file.
1 //===-- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework -------*- C++ -*--===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
11 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
12 
13 #include "AddressPool.h"
14 #include "DwarfStringPool.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/FoldingSet.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/StringMap.h"
19 #include "llvm/CodeGen/DIE.h"
20 #include "llvm/IR/Metadata.h"
21 #include "llvm/Support/Allocator.h"
22 #include <memory>
23 
24 namespace llvm {
25 class AsmPrinter;
26 class DbgVariable;
27 class DwarfCompileUnit;
28 class DwarfUnit;
29 class DIEAbbrev;
30 class MCSymbol;
31 class DIE;
32 class LexicalScope;
33 class StringRef;
34 class DwarfDebug;
35 class MCSection;
36 class MDNode;
37 class DwarfFile {
38  // Target of Dwarf emission, used for sizing of abbreviations.
39  AsmPrinter *Asm;
40 
41  BumpPtrAllocator AbbrevAllocator;
42 
43  // Used to uniquely define abbreviations.
44  DIEAbbrevSet Abbrevs;
45 
46  // A pointer to all units in the section.
48 
49  DwarfStringPool StrPool;
50 
51  // Collection of dbg variables of a scope.
53 
54  // Collection of abstract subprogram DIEs.
55  DenseMap<const MDNode *, DIE *> AbstractSPDies;
57 
58  /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
59  /// be shared across CUs, that is why we keep the map here instead
60  /// of in DwarfCompileUnit.
61  DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
62 
63 public:
65 
67  return CUs;
68  }
69 
70  /// \brief Compute the size and offset of a DIE given an incoming Offset.
71  unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
72 
73  /// \brief Compute the size and offset of all the DIEs.
74  void computeSizeAndOffsets();
75 
76  /// \brief Compute the size and offset of all the DIEs in the given unit.
77  /// \returns The size of the root DIE.
79 
80  /// \brief Add a unit to the list of CUs.
81  void addUnit(std::unique_ptr<DwarfCompileUnit> U);
82 
83  /// \brief Emit all of the units to the section listed with the given
84  /// abbreviation section.
85  void emitUnits(bool UseOffsets);
86 
87  /// \brief Emit the given unit to its section.
88  void emitUnit(DwarfUnit *U, bool UseOffsets);
89 
90  /// \brief Emit a set of abbreviations to the specific section.
91  void emitAbbrevs(MCSection *);
92 
93  /// \brief Emit all of the strings to the section given.
94  void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr);
95 
96  /// \brief Returns the string pool.
97  DwarfStringPool &getStringPool() { return StrPool; }
98 
99  /// \returns false if the variable was merged with a previous one.
101 
103  return ScopeVariables;
104  }
105 
107  return AbstractSPDies;
108  }
110  return AbstractVariables;
111  }
112 
113  void insertDIE(const MDNode *TypeMD, DIE *Die) {
114  DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
115  }
116  DIE *getDIE(const MDNode *TypeMD) {
117  return DITypeNodeToDieMap.lookup(TypeMD);
118  }
119 };
120 }
121 #endif
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
This file contains the declarations for metadata subclasses.
DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA)
Definition: DwarfFile.cpp:21
DenseMap< LexicalScope *, SmallVector< DbgVariable *, 8 > > & getScopeVariables()
Definition: DwarfFile.h:102
Metadata node.
Definition: Metadata.h:862
LexicalScope - This class is used to track scope information.
Definition: LexicalScopes.h:45
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
DenseMap< const MDNode *, DIE * > & getAbstractSPDies()
Definition: DwarfFile.h:106
This class is used to track local variable information.
Definition: DwarfDebug.h:64
const SmallVectorImpl< std::unique_ptr< DwarfCompileUnit > > & getUnits()
Definition: DwarfFile.h:66
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
Definition: DIE.h:135
void addUnit(std::unique_ptr< DwarfCompileUnit > U)
Add a unit to the list of CUs.
Definition: DwarfFile.cpp:24
This dwarf writer support class manages information associated with a source file.
Definition: DwarfUnit.h:68
DwarfStringPool & getStringPool()
Returns the string pool.
Definition: DwarfFile.h:97
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:138
A structured debug information entry.
Definition: DIE.h:662
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:76
void emitUnits(bool UseOffsets)
Emit all of the units to the section listed with the given abbreviation section.
Definition: DwarfFile.cpp:30
void insertDIE(const MDNode *TypeMD, DIE *Die)
Definition: DwarfFile.h:113
DenseMap< const MDNode *, std::unique_ptr< DbgVariable > > & getAbstractVariables()
Definition: DwarfFile.h:109
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
void computeSizeAndOffsets()
Compute the size and offset of all the DIEs.
Definition: DwarfFile.cpp:46
unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU)
Compute the size and offset of all the DIEs in the given unit.
Definition: DwarfFile.cpp:58
void emitUnit(DwarfUnit *U, bool UseOffsets)
Emit the given unit to its section.
Definition: DwarfFile.cpp:35
void emitAbbrevs(MCSection *)
Emit a set of abbreviations to the specific section.
Definition: DwarfFile.cpp:74
bool addScopeVariable(LexicalScope *LS, DbgVariable *Var)
Definition: DwarfFile.cpp:81
DIE * getDIE(const MDNode *TypeMD)
Definition: DwarfFile.h:116
unsigned computeSizeAndOffset(DIE &Die, unsigned Offset)
Compute the size and offset of a DIE given an incoming Offset.
Definition: DwarfFile.cpp:70
void emitStrings(MCSection *StrSection, MCSection *OffsetSection=nullptr)
Emit all of the strings to the section given.
Definition: DwarfFile.cpp:77
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49