LLVM  8.0.1
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 DbgEntity;
28 class DbgVariable;
29 class DbgLabel;
30 class DwarfCompileUnit;
31 class DwarfUnit;
32 class LexicalScope;
33 class MCSection;
34 
35 // Data structure to hold a range for range lists.
36 class RangeSpan {
37 public:
38  RangeSpan(MCSymbol *S, MCSymbol *E) : Start(S), End(E) {}
39  const MCSymbol *getStart() const { return Start; }
40  const MCSymbol *getEnd() const { return End; }
41  void setEnd(const MCSymbol *E) { End = E; }
42 
43 private:
44  const MCSymbol *Start, *End;
45 };
46 
48 private:
49  // Index for locating within the debug_range section this particular span.
50  MCSymbol *RangeSym;
51  const DwarfCompileUnit *CU;
52  // List of ranges.
54 
55 public:
58  : RangeSym(Sym), CU(&CU), Ranges(std::move(Ranges)) {}
59  MCSymbol *getSym() const { return RangeSym; }
60  const DwarfCompileUnit &getCU() const { return *CU; }
61  const SmallVectorImpl<RangeSpan> &getRanges() const { return Ranges; }
62  void addRange(RangeSpan Range) { Ranges.push_back(Range); }
63 };
64 
65 class DwarfFile {
66  // Target of Dwarf emission, used for sizing of abbreviations.
67  AsmPrinter *Asm;
68 
69  BumpPtrAllocator AbbrevAllocator;
70 
71  // Used to uniquely define abbreviations.
72  DIEAbbrevSet Abbrevs;
73 
74  // A pointer to all units in the section.
76 
77  DwarfStringPool StrPool;
78 
79  // List of range lists for a given compile unit, separate from the ranges for
80  // the CU itself.
81  SmallVector<RangeSpanList, 1> CURangeLists;
82 
83  /// DWARF v5: The symbol that designates the start of the contribution to
84  /// the string offsets table. The contribution is shared by all units.
85  MCSymbol *StringOffsetsStartSym = nullptr;
86 
87  /// DWARF v5: The symbol that designates the base of the range list table.
88  /// The table is shared by all units.
89  MCSymbol *RnglistsTableBaseSym = nullptr;
90 
91  /// DWARF v5: The symbol that designates the base of the locations list table.
92  /// The table is shared by all units.
93  MCSymbol *LoclistsTableBaseSym = nullptr;
94 
95  /// The variables of a lexical scope.
96  struct ScopeVars {
97  /// We need to sort Args by ArgNo and check for duplicates. This could also
98  /// be implemented as a list or vector + std::lower_bound().
99  std::map<unsigned, DbgVariable *> Args;
101  };
102  /// Collection of DbgVariables of each lexical scope.
104 
105  /// Collection of DbgLabels of each lexical scope.
108 
109  // Collection of abstract subprogram DIEs.
110  DenseMap<const MDNode *, DIE *> AbstractSPDies;
112 
113  /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
114  /// be shared across CUs, that is why we keep the map here instead
115  /// of in DwarfCompileUnit.
116  DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
117 
118 public:
120 
122  return CUs;
123  }
124 
125  std::pair<uint32_t, RangeSpanList *> addRange(const DwarfCompileUnit &CU,
127 
128  /// getRangeLists - Get the vector of range lists.
130  return CURangeLists;
131  }
132 
133  /// Compute the size and offset of a DIE given an incoming Offset.
134  unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
135 
136  /// Compute the size and offset of all the DIEs.
137  void computeSizeAndOffsets();
138 
139  /// Compute the size and offset of all the DIEs in the given unit.
140  /// \returns The size of the root DIE.
141  unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU);
142 
143  /// Add a unit to the list of CUs.
144  void addUnit(std::unique_ptr<DwarfCompileUnit> U);
145 
146  /// Emit all of the units to the section listed with the given
147  /// abbreviation section.
148  void emitUnits(bool UseOffsets);
149 
150  /// Emit the given unit to its section.
151  void emitUnit(DwarfUnit *U, bool UseOffsets);
152 
153  /// Emit a set of abbreviations to the specific section.
154  void emitAbbrevs(MCSection *);
155 
156  /// Emit all of the strings to the section given. If OffsetSection is
157  /// non-null, emit a table of string offsets to it. If UseRelativeOffsets
158  /// is false, emit absolute offsets to the strings. Otherwise, emit
159  /// relocatable references to the strings if they are supported by the target.
160  void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr,
161  bool UseRelativeOffsets = false);
162 
163  /// Returns the string pool.
164  DwarfStringPool &getStringPool() { return StrPool; }
165 
166  MCSymbol *getStringOffsetsStartSym() const { return StringOffsetsStartSym; }
167  void setStringOffsetsStartSym(MCSymbol *Sym) { StringOffsetsStartSym = Sym; }
168 
169  MCSymbol *getRnglistsTableBaseSym() const { return RnglistsTableBaseSym; }
170  void setRnglistsTableBaseSym(MCSymbol *Sym) { RnglistsTableBaseSym = Sym; }
171 
172  MCSymbol *getLoclistsTableBaseSym() const { return LoclistsTableBaseSym; }
173  void setLoclistsTableBaseSym(MCSymbol *Sym) { LoclistsTableBaseSym = Sym; }
174 
175  /// \returns false if the variable was merged with a previous one.
176  bool addScopeVariable(LexicalScope *LS, DbgVariable *Var);
177 
178  void addScopeLabel(LexicalScope *LS, DbgLabel *Label);
179 
181  return ScopeVariables;
182  }
183 
185  return ScopeLabels;
186  }
187 
189  return AbstractSPDies;
190  }
191 
193  return AbstractEntities;
194  }
195 
196  void insertDIE(const MDNode *TypeMD, DIE *Die) {
197  DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
198  }
199 
200  DIE *getDIE(const MDNode *TypeMD) {
201  return DITypeNodeToDieMap.lookup(TypeMD);
202  }
203 };
204 
205 } // end namespace llvm
206 
207 #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
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void setRnglistsTableBaseSym(MCSymbol *Sym)
Definition: DwarfFile.h:170
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
const SmallVectorImpl< RangeSpanList > & getRangeLists() const
getRangeLists - Get the vector of range lists.
Definition: DwarfFile.h:129
This file contains the declarations for metadata subclasses.
Metadata node.
Definition: Metadata.h:864
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:221
MCSymbol * getRnglistsTableBaseSym() const
Definition: DwarfFile.h:169
Definition: BitVector.h:938
MCSymbol * getLoclistsTableBaseSym() const
Definition: DwarfFile.h:172
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:180
const SmallVectorImpl< RangeSpan > & getRanges() const
Definition: DwarfFile.h:61
DenseMap< const MDNode *, DIE * > & getAbstractSPDies()
Definition: DwarfFile.h:188
This class is used to track local variable information.
Definition: DwarfDebug.h:117
const SmallVectorImpl< std::unique_ptr< DwarfCompileUnit > > & getUnits()
Definition: DwarfFile.h:121
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
Definition: DIE.h:135
This class is used to track label information.
Definition: DwarfDebug.h:233
MCSymbol * getStringOffsetsStartSym() const
Definition: DwarfFile.h:166
This dwarf writer support class manages information associated with a source file.
Definition: DwarfUnit.h:41
DwarfStringPool & getStringPool()
Returns the string pool.
Definition: DwarfFile.h:164
MCSymbol * getSym() const
Definition: DwarfFile.h:59
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:141
RangeSpanList(MCSymbol *Sym, const DwarfCompileUnit &CU, SmallVector< RangeSpan, 2 > Ranges)
Definition: DwarfFile.h:56
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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:79
void setEnd(const MCSymbol *E)
Definition: DwarfFile.h:41
DenseMap< const DINode *, std::unique_ptr< DbgEntity > > & getAbstractEntities()
Definition: DwarfFile.h:192
const DwarfCompileUnit & getCU() const
Definition: DwarfFile.h:60
const MCSymbol * getStart() const
Definition: DwarfFile.h:39
void insertDIE(const MDNode *TypeMD, DIE *Die)
Definition: DwarfFile.h:196
DenseMap< LexicalScope *, LabelList > & getScopeLabels()
Definition: DwarfFile.h:184
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
void setLoclistsTableBaseSym(MCSymbol *Sym)
Definition: DwarfFile.h:173
RangeSpan(MCSymbol *S, MCSymbol *E)
Definition: DwarfFile.h:38
DIE * getDIE(const MDNode *TypeMD)
Definition: DwarfFile.h:200
void setStringOffsetsStartSym(MCSymbol *Sym)
Definition: DwarfFile.h:167
void addRange(RangeSpan Range)
Definition: DwarfFile.h:62
static void addRange(SmallVectorImpl< ConstantInt *> &EndPoints, ConstantInt *Low, ConstantInt *High)
Definition: Metadata.cpp:968
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:211
const MCSymbol * getEnd() const
Definition: DwarfFile.h:40
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
constexpr char Args[]
Key for Kernel::Metadata::mArgs.