LLVM  10.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 };
62 
63 class DwarfFile {
64  // Target of Dwarf emission, used for sizing of abbreviations.
65  AsmPrinter *Asm;
66 
67  BumpPtrAllocator AbbrevAllocator;
68 
69  // Used to uniquely define abbreviations.
70  DIEAbbrevSet Abbrevs;
71 
72  // A pointer to all units in the section.
74 
75  DwarfStringPool StrPool;
76 
77  // List of range lists for a given compile unit, separate from the ranges for
78  // the CU itself.
79  SmallVector<RangeSpanList, 1> CURangeLists;
80 
81  /// DWARF v5: The symbol that designates the start of the contribution to
82  /// the string offsets table. The contribution is shared by all units.
83  MCSymbol *StringOffsetsStartSym = nullptr;
84 
85  /// DWARF v5: The symbol that designates the base of the range list table.
86  /// The table is shared by all units.
87  MCSymbol *RnglistsTableBaseSym = nullptr;
88 
89  /// DWARF v5: The symbol that designates the base of the locations list table.
90  /// The table is shared by all units.
91  MCSymbol *LoclistsTableBaseSym = nullptr;
92 
93  /// The variables of a lexical scope.
94  struct ScopeVars {
95  /// We need to sort Args by ArgNo and check for duplicates. This could also
96  /// be implemented as a list or vector + std::lower_bound().
97  std::map<unsigned, DbgVariable *> Args;
99  };
100  /// Collection of DbgVariables of each lexical scope.
102 
103  /// Collection of DbgLabels of each lexical scope.
106 
107  // Collection of abstract subprogram DIEs.
108  DenseMap<const MDNode *, DIE *> AbstractSPDies;
110 
111  /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
112  /// be shared across CUs, that is why we keep the map here instead
113  /// of in DwarfCompileUnit.
114  DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
115 
116 public:
118 
120  return CUs;
121  }
122 
123  std::pair<uint32_t, RangeSpanList *> addRange(const DwarfCompileUnit &CU,
125 
126  /// getRangeLists - Get the vector of range lists.
128  return CURangeLists;
129  }
130 
131  /// Compute the size and offset of a DIE given an incoming Offset.
132  unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
133 
134  /// Compute the size and offset of all the DIEs.
135  void computeSizeAndOffsets();
136 
137  /// Compute the size and offset of all the DIEs in the given unit.
138  /// \returns The size of the root DIE.
139  unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU);
140 
141  /// Add a unit to the list of CUs.
142  void addUnit(std::unique_ptr<DwarfCompileUnit> U);
143 
144  /// Emit all of the units to the section listed with the given
145  /// abbreviation section.
146  void emitUnits(bool UseOffsets);
147 
148  /// Emit the given unit to its section.
149  void emitUnit(DwarfUnit *TheU, bool UseOffsets);
150 
151  /// Emit a set of abbreviations to the specific section.
152  void emitAbbrevs(MCSection *);
153 
154  /// Emit all of the strings to the section given. If OffsetSection is
155  /// non-null, emit a table of string offsets to it. If UseRelativeOffsets
156  /// is false, emit absolute offsets to the strings. Otherwise, emit
157  /// relocatable references to the strings if they are supported by the target.
158  void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr,
159  bool UseRelativeOffsets = false);
160 
161  /// Returns the string pool.
162  DwarfStringPool &getStringPool() { return StrPool; }
163 
164  MCSymbol *getStringOffsetsStartSym() const { return StringOffsetsStartSym; }
165  void setStringOffsetsStartSym(MCSymbol *Sym) { StringOffsetsStartSym = Sym; }
166 
167  MCSymbol *getRnglistsTableBaseSym() const { return RnglistsTableBaseSym; }
168  void setRnglistsTableBaseSym(MCSymbol *Sym) { RnglistsTableBaseSym = Sym; }
169 
170  MCSymbol *getLoclistsTableBaseSym() const { return LoclistsTableBaseSym; }
171  void setLoclistsTableBaseSym(MCSymbol *Sym) { LoclistsTableBaseSym = Sym; }
172 
173  /// \returns false if the variable was merged with a previous one.
174  bool addScopeVariable(LexicalScope *LS, DbgVariable *Var);
175 
176  void addScopeLabel(LexicalScope *LS, DbgLabel *Label);
177 
179  return ScopeVariables;
180  }
181 
183  return ScopeLabels;
184  }
185 
187  return AbstractSPDies;
188  }
189 
191  return AbstractEntities;
192  }
193 
194  void insertDIE(const MDNode *TypeMD, DIE *Die) {
195  DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
196  }
197 
198  DIE *getDIE(const MDNode *TypeMD) {
199  return DITypeNodeToDieMap.lookup(TypeMD);
200  }
201 };
202 
203 } // end namespace llvm
204 
205 #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:23
void setRnglistsTableBaseSym(MCSymbol *Sym)
Definition: DwarfFile.h:168
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:127
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:195
MCSymbol * getRnglistsTableBaseSym() const
Definition: DwarfFile.h:167
Definition: BitVector.h:937
MCSymbol * getLoclistsTableBaseSym() const
Definition: DwarfFile.h:170
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:178
const SmallVectorImpl< RangeSpan > & getRanges() const
Definition: DwarfFile.h:60
DenseMap< const MDNode *, DIE * > & getAbstractSPDies()
Definition: DwarfFile.h:186
This class is used to track local variable information.
Definition: DwarfDebug.h:118
const SmallVectorImpl< std::unique_ptr< DwarfCompileUnit > > & getUnits()
Definition: DwarfFile.h:119
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
Definition: DIE.h:135
This class is used to track label information.
Definition: DwarfDebug.h:230
MCSymbol * getStringOffsetsStartSym() const
Definition: DwarfFile.h:164
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:162
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:700
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:190
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:194
DenseMap< LexicalScope *, LabelList > & getScopeLabels()
Definition: DwarfFile.h:182
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
void setLoclistsTableBaseSym(MCSymbol *Sym)
Definition: DwarfFile.h:171
RangeSpan(MCSymbol *S, MCSymbol *E)
Definition: DwarfFile.h:37
DIE * getDIE(const MDNode *TypeMD)
Definition: DwarfFile.h:198
void setStringOffsetsStartSym(MCSymbol *Sym)
Definition: DwarfFile.h:165
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:185
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.