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