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