LLVM 18.0.0git
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"
15#include "llvm/ADT/StringRef.h"
16#include "llvm/CodeGen/DIE.h"
18#include <map>
19#include <memory>
20#include <utility>
21
22namespace llvm {
23
24class AsmPrinter;
25class DbgEntity;
26class DbgVariable;
27class DbgLabel;
28class DINode;
29class DILocalScope;
30class DwarfCompileUnit;
31class DwarfTypeUnit;
32class DwarfUnit;
33class LexicalScope;
34class MCSection;
35class MDNode;
36
37// Data structure to hold a range for range lists.
38struct RangeSpan {
40 const MCSymbol *End;
41};
42
44 // Index for locating within the debug_range section this particular span.
47 // List of ranges.
49};
50
51class DwarfFile {
52 // Target of Dwarf emission, used for sizing of abbreviations.
53 AsmPrinter *Asm;
54
55 BumpPtrAllocator AbbrevAllocator;
56
57 // Used to uniquely define abbreviations.
58 DIEAbbrevSet Abbrevs;
59
60 // A pointer to all units in the section.
62
63 DwarfStringPool StrPool;
64
65 // List of range lists for a given compile unit, separate from the ranges for
66 // the CU itself.
68
69 /// DWARF v5: The symbol that designates the start of the contribution to
70 /// the string offsets table. The contribution is shared by all units.
71 MCSymbol *StringOffsetsStartSym = nullptr;
72
73 /// DWARF v5: The symbol that designates the base of the range list table.
74 /// The table is shared by all units.
75 MCSymbol *RnglistsTableBaseSym = nullptr;
76
77 /// The variables of a lexical scope.
78 struct ScopeVars {
79 /// We need to sort Args by ArgNo and check for duplicates. This could also
80 /// be implemented as a list or vector + std::lower_bound().
81 std::map<unsigned, DbgVariable *> Args;
83 };
84 /// Collection of DbgVariables of each lexical scope.
86
87 /// Collection of DbgLabels of each lexical scope.
90
91 // Collection of abstract subprogram DIEs.
92 DenseMap<const DILocalScope *, DIE *> AbstractLocalScopeDIEs;
94
95 /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
96 /// be shared across CUs, that is why we keep the map here instead
97 /// of in DwarfCompileUnit.
98 DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
99
100public:
102
104 return CUs;
105 }
106
107 std::pair<uint32_t, RangeSpanList *> addRange(const DwarfCompileUnit &CU,
109
110 /// getRangeLists - Get the vector of range lists.
112 return CURangeLists;
113 }
114
115 /// Compute the size and offset of a DIE given an incoming Offset.
116 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
117
118 /// Compute the size and offset of all the DIEs.
120
121 /// Compute the size and offset of all the DIEs in the given unit.
122 /// \returns The size of the root DIE.
124
125 /// Add a unit to the list of CUs.
126 void addUnit(std::unique_ptr<DwarfCompileUnit> U);
127
128 /// Emit all of the units to the section listed with the given
129 /// abbreviation section.
130 void emitUnits(bool UseOffsets);
131
132 /// Emit the given unit to its section.
133 void emitUnit(DwarfUnit *TheU, bool UseOffsets);
134
135 /// Emit a set of abbreviations to the specific section.
136 void emitAbbrevs(MCSection *);
137
138 /// Emit all of the strings to the section given. If OffsetSection is
139 /// non-null, emit a table of string offsets to it. If UseRelativeOffsets
140 /// is false, emit absolute offsets to the strings. Otherwise, emit
141 /// relocatable references to the strings if they are supported by the target.
142 void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr,
143 bool UseRelativeOffsets = false);
144
145 /// Returns the string pool.
146 DwarfStringPool &getStringPool() { return StrPool; }
147
148 MCSymbol *getStringOffsetsStartSym() const { return StringOffsetsStartSym; }
149 void setStringOffsetsStartSym(MCSymbol *Sym) { StringOffsetsStartSym = Sym; }
150
151 MCSymbol *getRnglistsTableBaseSym() const { return RnglistsTableBaseSym; }
152 void setRnglistsTableBaseSym(MCSymbol *Sym) { RnglistsTableBaseSym = Sym; }
153
155
156 void addScopeLabel(LexicalScope *LS, DbgLabel *Label);
157
159 return ScopeVariables;
160 }
161
163 return ScopeLabels;
164 }
165
167 return AbstractLocalScopeDIEs;
168 }
169
171 return AbstractEntities;
172 }
173
174 void insertDIE(const MDNode *TypeMD, DIE *Die) {
175 DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
176 }
177
178 DIE *getDIE(const MDNode *TypeMD) {
179 return DITypeNodeToDieMap.lookup(TypeMD);
180 }
181};
182
183} // end namespace llvm
184
185#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
This file defines the BumpPtrAllocator interface.
This file defines the DenseMap class.
Symbol * Sym
Definition: ELF_riscv.cpp:477
This file defines the SmallVector class.
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:84
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
Definition: DIE.h:140
A structured debug information entry.
Definition: DIE.h:819
This class is used to track label information.
Definition: DwarfDebug.h:289
This class is used to track local variable information.
Definition: DwarfDebug.h:214
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:202
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:220
unsigned computeSizeAndOffset(DIE &Die, unsigned Offset)
Compute the size and offset of a DIE given an incoming Offset.
Definition: DwarfFile.cpp:92
void addScopeLabel(LexicalScope *LS, DbgLabel *Label)
Definition: DwarfFile.cpp:117
void addUnit(std::unique_ptr< DwarfCompileUnit > U)
Add a unit to the list of CUs.
Definition: DwarfFile.cpp:23
void computeSizeAndOffsets()
Compute the size and offset of all the DIEs.
Definition: DwarfFile.cpp:57
void setRnglistsTableBaseSym(MCSymbol *Sym)
Definition: DwarfFile.h:152
DenseMap< LexicalScope *, ScopeVars > & getScopeVariables()
Definition: DwarfFile.h:158
DenseMap< const DINode *, std::unique_ptr< DbgEntity > > & getAbstractEntities()
Definition: DwarfFile.h:170
unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU)
Compute the size and offset of all the DIEs in the given unit.
Definition: DwarfFile.cpp:80
void emitUnits(bool UseOffsets)
Emit all of the units to the section listed with the given abbreviation section.
Definition: DwarfFile.cpp:29
void emitUnit(DwarfUnit *TheU, bool UseOffsets)
Emit the given unit to its section.
Definition: DwarfFile.cpp:34
const SmallVectorImpl< RangeSpanList > & getRangeLists() const
getRangeLists - Get the vector of range lists.
Definition: DwarfFile.h:111
MCSymbol * getStringOffsetsStartSym() const
Definition: DwarfFile.h:148
MCSymbol * getRnglistsTableBaseSym() const
Definition: DwarfFile.h:151
DwarfStringPool & getStringPool()
Returns the string pool.
Definition: DwarfFile.h:146
void emitAbbrevs(MCSection *)
Emit a set of abbreviations to the specific section.
Definition: DwarfFile.cpp:97
void emitStrings(MCSection *StrSection, MCSection *OffsetSection=nullptr, bool UseRelativeOffsets=false)
Emit all of the strings to the section given.
Definition: DwarfFile.cpp:100
DenseMap< LexicalScope *, LabelList > & getScopeLabels()
Definition: DwarfFile.h:162
void addScopeVariable(LexicalScope *LS, DbgVariable *Var)
Definition: DwarfFile.cpp:105
std::pair< uint32_t, RangeSpanList * > addRange(const DwarfCompileUnit &CU, SmallVector< RangeSpan, 2 > R)
Definition: DwarfFile.cpp:123
DenseMap< const DILocalScope *, DIE * > & getAbstractScopeDIEs()
Definition: DwarfFile.h:166
void setStringOffsetsStartSym(MCSymbol *Sym)
Definition: DwarfFile.h:149
const SmallVectorImpl< std::unique_ptr< DwarfCompileUnit > > & getUnits()
Definition: DwarfFile.h:103
void insertDIE(const MDNode *TypeMD, DIE *Die)
Definition: DwarfFile.h:174
DIE * getDIE(const MDNode *TypeMD)
Definition: DwarfFile.h:178
This dwarf writer support class manages information associated with a source file.
Definition: DwarfUnit.h:35
LexicalScope - This class is used to track scope information.
Definition: LexicalScopes.h:44
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
Metadata node.
Definition: Metadata.h:1037
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:456
const DwarfCompileUnit * CU
Definition: DwarfFile.h:46
SmallVector< RangeSpan, 2 > Ranges
Definition: DwarfFile.h:48
MCSymbol * Label
Definition: DwarfFile.h:45
const MCSymbol * End
Definition: DwarfFile.h:40
const MCSymbol * Begin
Definition: DwarfFile.h:39