LLVM  7.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 "DwarfStringPool.h"
14 #include "llvm/ADT/DenseMap.h"
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/CodeGen/DIE.h"
18 #include "llvm/IR/Metadata.h"
19 #include "llvm/Support/Allocator.h"
20 #include <map>
21 #include <memory>
22 #include <utility>
23 
24 namespace llvm {
25 
26 class AsmPrinter;
27 class DbgVariable;
28 class DwarfCompileUnit;
29 class DwarfUnit;
30 class LexicalScope;
31 class MCSection;
32 
33 class DwarfFile {
34  // Target of Dwarf emission, used for sizing of abbreviations.
35  AsmPrinter *Asm;
36 
37  BumpPtrAllocator AbbrevAllocator;
38 
39  // Used to uniquely define abbreviations.
40  DIEAbbrevSet Abbrevs;
41 
42  // A pointer to all units in the section.
44 
45  DwarfStringPool StrPool;
46 
47  /// DWARF v5: The symbol that designates the start of the contribution to
48  /// the string offsets table. The contribution is shared by all units.
49  MCSymbol *StringOffsetsStartSym = nullptr;
50 
51  /// DWARF v5: The symbol that designates the base of the range list table.
52  /// The table is shared by all units.
53  MCSymbol *RnglistsTableBaseSym = nullptr;
54 
55  /// The variables of a lexical scope.
56  struct ScopeVars {
57  /// We need to sort Args by ArgNo and check for duplicates. This could also
58  /// be implemented as a list or vector + std::lower_bound().
59  std::map<unsigned, DbgVariable *> Args;
61  };
62  /// Collection of DbgVariables of each lexical scope.
64 
65  // Collection of abstract subprogram DIEs.
66  DenseMap<const MDNode *, DIE *> AbstractSPDies;
68 
69  /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
70  /// be shared across CUs, that is why we keep the map here instead
71  /// of in DwarfCompileUnit.
72  DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
73 
74 public:
76 
78  return CUs;
79  }
80 
81  /// Compute the size and offset of a DIE given an incoming Offset.
82  unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
83 
84  /// Compute the size and offset of all the DIEs.
85  void computeSizeAndOffsets();
86 
87  /// Compute the size and offset of all the DIEs in the given unit.
88  /// \returns The size of the root DIE.
90 
91  /// Add a unit to the list of CUs.
92  void addUnit(std::unique_ptr<DwarfCompileUnit> U);
93 
94  /// Emit all of the units to the section listed with the given
95  /// abbreviation section.
96  void emitUnits(bool UseOffsets);
97 
98  /// Emit the given unit to its section.
99  void emitUnit(DwarfUnit *U, bool UseOffsets);
100 
101  /// Emit a set of abbreviations to the specific section.
102  void emitAbbrevs(MCSection *);
103 
104  /// Emit all of the strings to the section given. If OffsetSection is
105  /// non-null, emit a table of string offsets to it. If UseRelativeOffsets
106  /// is false, emit absolute offsets to the strings. Otherwise, emit
107  /// relocatable references to the strings if they are supported by the target.
108  void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr,
109  bool UseRelativeOffsets = false);
110 
111  /// Returns the string pool.
112  DwarfStringPool &getStringPool() { return StrPool; }
113 
114  MCSymbol *getStringOffsetsStartSym() const { return StringOffsetsStartSym; }
115 
116  void setStringOffsetsStartSym(MCSymbol *Sym) { StringOffsetsStartSym = Sym; }
117 
118  MCSymbol *getRnglistsTableBaseSym() const { return RnglistsTableBaseSym; }
119 
120  void setRnglistsTableBaseSym(MCSymbol *Sym) { RnglistsTableBaseSym = Sym; }
121 
122  /// \returns false if the variable was merged with a previous one.
124 
126  return ScopeVariables;
127  }
128 
130  return AbstractSPDies;
131  }
132 
134  return AbstractVariables;
135  }
136 
137  void insertDIE(const MDNode *TypeMD, DIE *Die) {
138  DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
139  }
140 
141  DIE *getDIE(const MDNode *TypeMD) {
142  return DITypeNodeToDieMap.lookup(TypeMD);
143  }
144 };
145 
146 } // end namespace llvm
147 
148 #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
void addUnit(std::unique_ptr< DwarfCompileUnit > U)
Add a unit to the list of CUs.
Definition: DwarfFile.cpp:27
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
void setRnglistsTableBaseSym(MCSymbol *Sym)
Definition: DwarfFile.h:120
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
unsigned computeSizeAndOffset(DIE &Die, unsigned Offset)
Compute the size and offset of a DIE given an incoming Offset.
Definition: DwarfFile.cpp:73
This file contains the declarations for metadata subclasses.
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.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:191
MCSymbol * getRnglistsTableBaseSym() const
Definition: DwarfFile.h:118
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
DenseMap< LexicalScope *, ScopeVars > & getScopeVariables()
Definition: DwarfFile.h:125
DenseMap< const MDNode *, DIE * > & getAbstractSPDies()
Definition: DwarfFile.h:129
This class is used to track local variable information.
Definition: DwarfDebug.h:76
const SmallVectorImpl< std::unique_ptr< DwarfCompileUnit > > & getUnits()
Definition: DwarfFile.h:77
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
Definition: DIE.h:135
unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU)
Compute the size and offset of all the DIEs in the given unit.
Definition: DwarfFile.cpp:61
MCSymbol * getStringOffsetsStartSym() const
Definition: DwarfFile.h:114
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:112
void emitUnit(DwarfUnit *U, bool UseOffsets)
Emit the given unit to its section.
Definition: DwarfFile.cpp:38
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:140
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:78
void computeSizeAndOffsets()
Compute the size and offset of all the DIEs.
Definition: DwarfFile.cpp:49
bool addScopeVariable(LexicalScope *LS, DbgVariable *Var)
Definition: DwarfFile.cpp:85
DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA)
Definition: DwarfFile.cpp:24
void insertDIE(const MDNode *TypeMD, DIE *Die)
Definition: DwarfFile.h:137
DenseMap< const MDNode *, std::unique_ptr< DbgVariable > > & getAbstractVariables()
Definition: DwarfFile.h:133
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
DIE * getDIE(const MDNode *TypeMD)
Definition: DwarfFile.h:141
void setStringOffsetsStartSym(MCSymbol *Sym)
Definition: DwarfFile.h:116
void emitStrings(MCSection *StrSection, MCSection *OffsetSection=nullptr, bool UseRelativeOffsets=false)
Emit all of the strings to the section given.
Definition: DwarfFile.cpp:80
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:181
void emitAbbrevs(MCSection *)
Emit a set of abbreviations to the specific section.
Definition: DwarfFile.cpp:77
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void emitUnits(bool UseOffsets)
Emit all of the units to the section listed with the given abbreviation section.
Definition: DwarfFile.cpp:33
constexpr char Args[]
Key for Kernel::Metadata::mArgs.