llvm.org GIT mirror llvm / 1188a75
Split out DwarfFile from DwarfDebug into its own .h/.cpp files. Some of these types (DwarfDebug in particular) are quite large to begin with (and I keep forgetting whether DwarfFile is in DwarfDebug or DwarfUnit... ) so having a few smaller files seems like goodness. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207010 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 5 years ago
5 changed file(s) with 367 addition(s) and 320 deletion(s). Raw diff Collapse all Expand all
88 DwarfCFIException.cpp
99 DwarfDebug.cpp
1010 DwarfException.cpp
11 DwarfFile.cpp
1112 DwarfUnit.cpp
1213 ErlangGCPrinter.cpp
1314 OcamlGCPrinter.cpp
107107
108108 //===----------------------------------------------------------------------===//
109109
110 namespace llvm {
111
112110 /// resolve - Look in the DwarfDebug map for the MDNode that
113111 /// corresponds to the reference.
114112 template T DbgVariable::resolve(DIRef Ref) const {
166164 return Ty;
167165 }
168166
169 } // end llvm namespace
170
171167 DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
172168 : Asm(A), MMI(Asm->MMI), FirstCU(0), PrevLabel(NULL), GlobalRangeCount(0),
173169 InfoHolder(A, "info_string", DIEValueAllocator),
222218 MCSymbol *TmpSym = Asm->GetTempSymbol(SymbolStem);
223219 Asm->OutStreamer.EmitLabel(TmpSym);
224220 return TmpSym;
225 }
226
227 DwarfFile::DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
228 : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref) {}
229 DwarfFile::~DwarfFile() {
230 }
231
232 MCSymbol *DwarfFile::getStringPoolSym() {
233 return Asm->GetTempSymbol(StringPref);
234 }
235
236 MCSymbol *DwarfFile::getStringPoolEntry(StringRef Str) {
237 std::pair &Entry =
238 StringPool.GetOrCreateValue(Str).getValue();
239 if (Entry.first)
240 return Entry.first;
241
242 Entry.second = NextStringPoolNumber++;
243 return Entry.first = Asm->GetTempSymbol(StringPref, Entry.second);
244 }
245
246 unsigned DwarfFile::getStringPoolIndex(StringRef Str) {
247 std::pair &Entry =
248 StringPool.GetOrCreateValue(Str).getValue();
249 if (Entry.first)
250 return Entry.second;
251
252 Entry.second = NextStringPoolNumber++;
253 Entry.first = Asm->GetTempSymbol(StringPref, Entry.second);
254 return Entry.second;
255 }
256
257 unsigned DwarfFile::getAddrPoolIndex(const MCSymbol *Sym, bool TLS) {
258 std::pair P = AddressPool.insert(
259 std::make_pair(Sym, AddressPoolEntry(AddressPool.size(), TLS)));
260 return P.first->second.Number;
261 }
262
263 // Define a unique number for the abbreviation.
264 //
265 void DwarfFile::assignAbbrevNumber(DIEAbbrev &Abbrev) {
266 // Check the set for priors.
267 DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev);
268
269 // If it's newly added.
270 if (InSet == &Abbrev) {
271 // Add to abbreviation list.
272 Abbreviations.push_back(&Abbrev);
273
274 // Assign the vector position + 1 as its number.
275 Abbrev.setNumber(Abbreviations.size());
276 } else {
277 // Assign existing abbreviation number.
278 Abbrev.setNumber(InSet->getNumber());
279 }
280 }
281
282 void DwarfFile::addUnit(std::unique_ptr U) {
283 CUs.push_back(std::move(U));
284221 }
285222
286223 static bool isObjCClass(StringRef Name) {
17891726 // Emit Methods
17901727 //===----------------------------------------------------------------------===//
17911728
1792 // Compute the size and offset of a DIE. The offset is relative to start of the
1793 // CU. It returns the offset after laying out the DIE.
1794 unsigned DwarfFile::computeSizeAndOffset(DIE &Die, unsigned Offset) {
1795 // Record the abbreviation.
1796 assignAbbrevNumber(Die.getAbbrev());
1797
1798 // Get the abbreviation for this DIE.
1799 const DIEAbbrev &Abbrev = Die.getAbbrev();
1800
1801 // Set DIE offset
1802 Die.setOffset(Offset);
1803
1804 // Start the size with the size of abbreviation code.
1805 Offset += getULEB128Size(Die.getAbbrevNumber());
1806
1807 const SmallVectorImpl &Values = Die.getValues();
1808 const SmallVectorImpl &AbbrevData = Abbrev.getData();
1809
1810 // Size the DIE attribute values.
1811 for (unsigned i = 0, N = Values.size(); i < N; ++i)
1812 // Size attribute value.
1813 Offset += Values[i]->SizeOf(Asm, AbbrevData[i].getForm());
1814
1815 // Get the children.
1816 const auto &Children = Die.getChildren();
1817
1818 // Size the DIE children if any.
1819 if (!Children.empty()) {
1820 assert(Abbrev.hasChildren() && "Children flag not set");
1821
1822 for (auto &Child : Children)
1823 Offset = computeSizeAndOffset(*Child, Offset);
1824
1825 // End of children marker.
1826 Offset += sizeof(int8_t);
1827 }
1828
1829 Die.setSize(Offset - Die.getOffset());
1830 return Offset;
1831 }
1832
1833 // Compute the size and offset for each DIE.
1834 void DwarfFile::computeSizeAndOffsets() {
1835 // Offset from the first CU in the debug info section is 0 initially.
1836 unsigned SecOffset = 0;
1837
1838 // Iterate over each compile unit and set the size and offsets for each
1839 // DIE within each compile unit. All offsets are CU relative.
1840 for (const auto &TheU : CUs) {
1841 TheU->setDebugInfoOffset(SecOffset);
1842
1843 // CU-relative offset is reset to 0 here.
1844 unsigned Offset = sizeof(int32_t) + // Length of Unit Info
1845 TheU->getHeaderSize(); // Unit-specific headers
1846
1847 // EndOffset here is CU-relative, after laying out
1848 // all of the CU DIE.
1849 unsigned EndOffset = computeSizeAndOffset(*TheU->getUnitDie(), Offset);
1850 SecOffset += EndOffset;
1851 }
1852 }
1853
18541729 // Emit initial Dwarf sections with a label at the start of each one.
18551730 void DwarfDebug::emitSectionLabels() {
18561731 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
19401815 }
19411816 }
19421817
1943 // Emit the various dwarf units to the unit section USection with
1944 // the abbreviations going into ASection.
1945 void DwarfFile::emitUnits(DwarfDebug *DD, const MCSymbol *ASectionSym) {
1946 for (const auto &TheU : CUs) {
1947 DIE *Die = TheU->getUnitDie();
1948 const MCSection *USection = TheU->getSection();
1949 Asm->OutStreamer.SwitchSection(USection);
1950
1951 // Emit the compile units header.
1952 Asm->OutStreamer.EmitLabel(TheU->getLabelBegin());
1953
1954 // Emit size of content not including length itself
1955 Asm->OutStreamer.AddComment("Length of Unit");
1956 Asm->EmitInt32(TheU->getHeaderSize() + Die->getSize());
1957
1958 TheU->emitHeader(ASectionSym);
1959
1960 DD->emitDIE(*Die);
1961 Asm->OutStreamer.EmitLabel(TheU->getLabelEnd());
1962 }
1963 }
1964
19651818 // Emit the debug info section.
19661819 void DwarfDebug::emitDebugInfo() {
19671820 DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
19741827 DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
19751828
19761829 Holder.emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevSection());
1977 }
1978
1979 void DwarfFile::emitAbbrevs(const MCSection *Section) {
1980 // Check to see if it is worth the effort.
1981 if (!Abbreviations.empty()) {
1982 // Start the debug abbrev section.
1983 Asm->OutStreamer.SwitchSection(Section);
1984
1985 // For each abbrevation.
1986 for (const DIEAbbrev *Abbrev : Abbreviations) {
1987 // Emit the abbrevations code (base 1 index.)
1988 Asm->EmitULEB128(Abbrev->getNumber(), "Abbreviation Code");
1989
1990 // Emit the abbreviations data.
1991 Abbrev->Emit(Asm);
1992 }
1993
1994 // Mark end of abbreviations.
1995 Asm->EmitULEB128(0, "EOM(3)");
1996 }
19971830 }
19981831
19991832 // Emit the last address of the section and the end of the line matrix.
22492082 : Asm->getObjFileLowering().getDwarfPubTypesSection();
22502083
22512084 emitDebugPubSection(GnuStyle, PSec, "Types", &DwarfUnit::getGlobalTypes);
2252 }
2253
2254 // Emit strings into a string section.
2255 void DwarfFile::emitStrings(const MCSection *StrSection,
2256 const MCSection *OffsetSection = NULL,
2257 const MCSymbol *StrSecSym = NULL) {
2258
2259 if (StringPool.empty())
2260 return;
2261
2262 // Start the dwarf str section.
2263 Asm->OutStreamer.SwitchSection(StrSection);
2264
2265 // Get all of the string pool entries and put them in an array by their ID so
2266 // we can sort them.
2267 SmallVector, 64 > Entries;
2268
2269 for (const auto &I : StringPool)
2270 Entries.push_back(std::make_pair(I.second.second, &I));
2271
2272 array_pod_sort(Entries.begin(), Entries.end());
2273
2274 for (const auto &Entry : Entries) {
2275 // Emit a label for reference from debug information entries.
2276 Asm->OutStreamer.EmitLabel(Entry.second->getValue().first);
2277
2278 // Emit the string itself with a terminating null byte.
2279 Asm->OutStreamer.EmitBytes(StringRef(Entry.second->getKeyData(),
2280 Entry.second->getKeyLength() + 1));
2281 }
2282
2283 // If we've got an offset section go ahead and emit that now as well.
2284 if (OffsetSection) {
2285 Asm->OutStreamer.SwitchSection(OffsetSection);
2286 unsigned offset = 0;
2287 unsigned size = 4; // FIXME: DWARF64 is 8.
2288 for (const auto &Entry : Entries) {
2289 Asm->OutStreamer.EmitIntValue(offset, size);
2290 offset += Entry.second->getKeyLength() + 1;
2291 }
2292 }
2293 }
2294
2295 // Emit addresses into the section given.
2296 void DwarfFile::emitAddresses(const MCSection *AddrSection) {
2297
2298 if (AddressPool.empty())
2299 return;
2300
2301 // Start the dwarf addr section.
2302 Asm->OutStreamer.SwitchSection(AddrSection);
2303
2304 // Order the address pool entries by ID
2305 SmallVector Entries(AddressPool.size());
2306
2307 for (const auto &I : AddressPool)
2308 Entries[I.second.Number] =
2309 I.second.TLS
2310 ? Asm->getObjFileLowering().getDebugThreadLocalSymbol(I.first)
2311 : MCSymbolRefExpr::Create(I.first, Asm->OutContext);
2312
2313 for (const MCExpr *Entry : Entries)
2314 Asm->OutStreamer.EmitValue(Entry, Asm->getDataLayout().getPointerSize());
23152085 }
23162086
23172087 // Emit visible names into a debug str section.
1313 #ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__
1414 #define CODEGEN_ASMPRINTER_DWARFDEBUG_H__
1515
16 #include "DwarfFile.h"
1617 #include "AsmPrinterHandler.h"
1718 #include "DIE.h"
1819 #include "DebugLocEntry.h"
132133 template T resolve(DIRef Ref) const;
133134 };
134135
135 /// \brief Collects and handles information specific to a particular
136 /// collection of units. This collection represents all of the units
137 /// that will be ultimately output into a single object file.
138 class DwarfFile {
139 // Target of Dwarf emission, used for sizing of abbreviations.
140 AsmPrinter *Asm;
141
142 // Used to uniquely define abbreviations.
143 FoldingSet AbbreviationsSet;
144
145 // A list of all the unique abbreviations in use.
146 std::vector Abbreviations;
147
148 // A pointer to all units in the section.
149 SmallVector, 1> CUs;
150
151 // Collection of strings for this unit and assorted symbols.
152 // A String->Symbol mapping of strings used by indirect
153 // references.
154 typedef StringMap, BumpPtrAllocator &>
155 StrPool;
156 StrPool StringPool;
157 unsigned NextStringPoolNumber;
158 std::string StringPref;
159
160 struct AddressPoolEntry {
161 unsigned Number;
162 bool TLS;
163 AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
164 };
165 // Collection of addresses for this unit and assorted labels.
166 // A Symbol->unsigned mapping of addresses used by indirect
167 // references.
168 typedef DenseMap AddrPool;
169 AddrPool AddressPool;
170
171 public:
172 DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA);
173
174 ~DwarfFile();
175
176 const SmallVectorImpl> &getUnits() { return CUs; }
177
178 /// \brief Compute the size and offset of a DIE given an incoming Offset.
179 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
180
181 /// \brief Compute the size and offset of all the DIEs.
182 void computeSizeAndOffsets();
183
184 /// \brief Define a unique number for the abbreviation.
185 void assignAbbrevNumber(DIEAbbrev &Abbrev);
186
187 /// \brief Add a unit to the list of CUs.
188 void addUnit(std::unique_ptr U);
189
190 /// \brief Emit all of the units to the section listed with the given
191 /// abbreviation section.
192 void emitUnits(DwarfDebug *DD, const MCSymbol *ASectionSym);
193
194 /// \brief Emit a set of abbreviations to the specific section.
195 void emitAbbrevs(const MCSection *);
196
197 /// \brief Emit all of the strings to the section given.
198 void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection,
199 const MCSymbol *StrSecSym);
200
201 /// \brief Emit all of the addresses to the section given.
202 void emitAddresses(const MCSection *AddrSection);
203
204 /// \brief Returns the entry into the start of the pool.
205 MCSymbol *getStringPoolSym();
206
207 /// \brief Returns an entry into the string pool with the given
208 /// string text.
209 MCSymbol *getStringPoolEntry(StringRef Str);
210
211 /// \brief Returns the index into the string pool with the given
212 /// string text.
213 unsigned getStringPoolIndex(StringRef Str);
214
215 /// \brief Returns the string pool.
216 StrPool *getStringPool() { return &StringPool; }
217
218 /// \brief Returns the index into the address pool with the given
219 /// label/symbol.
220 unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false);
221
222 /// \brief Returns the address pool.
223 AddrPool *getAddrPool() { return &AddressPool; }
224 };
225136
226137 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
227138 struct SymbolCU {
0 //===-- llvm/CodeGen/DwarfFile.cpp - Dwarf Debug Framework ----------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "DwarfFile.h"
10
11 #include "DwarfDebug.h"
12 #include "DwarfUnit.h"
13 #include "llvm/MC/MCStreamer.h"
14 #include "llvm/Support/LEB128.h"
15 #include "llvm/IR/DataLayout.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/Target/TargetLoweringObjectFile.h"
18
19 namespace llvm {
20 DwarfFile::DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
21 : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref) {}
22
23 DwarfFile::~DwarfFile() {
24 }
25
26 MCSymbol *DwarfFile::getStringPoolSym() {
27 return Asm->GetTempSymbol(StringPref);
28 }
29
30 MCSymbol *DwarfFile::getStringPoolEntry(StringRef Str) {
31 std::pair &Entry =
32 StringPool.GetOrCreateValue(Str).getValue();
33 if (Entry.first)
34 return Entry.first;
35
36 Entry.second = NextStringPoolNumber++;
37 return Entry.first = Asm->GetTempSymbol(StringPref, Entry.second);
38 }
39
40 unsigned DwarfFile::getStringPoolIndex(StringRef Str) {
41 std::pair &Entry =
42 StringPool.GetOrCreateValue(Str).getValue();
43 if (Entry.first)
44 return Entry.second;
45
46 Entry.second = NextStringPoolNumber++;
47 Entry.first = Asm->GetTempSymbol(StringPref, Entry.second);
48 return Entry.second;
49 }
50
51 unsigned DwarfFile::getAddrPoolIndex(const MCSymbol *Sym, bool TLS) {
52 std::pair P = AddressPool.insert(
53 std::make_pair(Sym, AddressPoolEntry(AddressPool.size(), TLS)));
54 return P.first->second.Number;
55 }
56
57 // Define a unique number for the abbreviation.
58 //
59 void DwarfFile::assignAbbrevNumber(DIEAbbrev &Abbrev) {
60 // Check the set for priors.
61 DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev);
62
63 // If it's newly added.
64 if (InSet == &Abbrev) {
65 // Add to abbreviation list.
66 Abbreviations.push_back(&Abbrev);
67
68 // Assign the vector position + 1 as its number.
69 Abbrev.setNumber(Abbreviations.size());
70 } else {
71 // Assign existing abbreviation number.
72 Abbrev.setNumber(InSet->getNumber());
73 }
74 }
75
76 void DwarfFile::addUnit(std::unique_ptr U) {
77 CUs.push_back(std::move(U));
78 }
79
80 // Emit the various dwarf units to the unit section USection with
81 // the abbreviations going into ASection.
82 void DwarfFile::emitUnits(DwarfDebug *DD, const MCSymbol *ASectionSym) {
83 for (const auto &TheU : CUs) {
84 DIE *Die = TheU->getUnitDie();
85 const MCSection *USection = TheU->getSection();
86 Asm->OutStreamer.SwitchSection(USection);
87
88 // Emit the compile units header.
89 Asm->OutStreamer.EmitLabel(TheU->getLabelBegin());
90
91 // Emit size of content not including length itself
92 Asm->OutStreamer.AddComment("Length of Unit");
93 Asm->EmitInt32(TheU->getHeaderSize() + Die->getSize());
94
95 TheU->emitHeader(ASectionSym);
96
97 DD->emitDIE(*Die);
98 Asm->OutStreamer.EmitLabel(TheU->getLabelEnd());
99 }
100 }
101 // Compute the size and offset for each DIE.
102 void DwarfFile::computeSizeAndOffsets() {
103 // Offset from the first CU in the debug info section is 0 initially.
104 unsigned SecOffset = 0;
105
106 // Iterate over each compile unit and set the size and offsets for each
107 // DIE within each compile unit. All offsets are CU relative.
108 for (const auto &TheU : CUs) {
109 TheU->setDebugInfoOffset(SecOffset);
110
111 // CU-relative offset is reset to 0 here.
112 unsigned Offset = sizeof(int32_t) + // Length of Unit Info
113 TheU->getHeaderSize(); // Unit-specific headers
114
115 // EndOffset here is CU-relative, after laying out
116 // all of the CU DIE.
117 unsigned EndOffset = computeSizeAndOffset(*TheU->getUnitDie(), Offset);
118 SecOffset += EndOffset;
119 }
120 }
121 // Compute the size and offset of a DIE. The offset is relative to start of the
122 // CU. It returns the offset after laying out the DIE.
123 unsigned DwarfFile::computeSizeAndOffset(DIE &Die, unsigned Offset) {
124 // Record the abbreviation.
125 assignAbbrevNumber(Die.getAbbrev());
126
127 // Get the abbreviation for this DIE.
128 const DIEAbbrev &Abbrev = Die.getAbbrev();
129
130 // Set DIE offset
131 Die.setOffset(Offset);
132
133 // Start the size with the size of abbreviation code.
134 Offset += getULEB128Size(Die.getAbbrevNumber());
135
136 const SmallVectorImpl &Values = Die.getValues();
137 const SmallVectorImpl &AbbrevData = Abbrev.getData();
138
139 // Size the DIE attribute values.
140 for (unsigned i = 0, N = Values.size(); i < N; ++i)
141 // Size attribute value.
142 Offset += Values[i]->SizeOf(Asm, AbbrevData[i].getForm());
143
144 // Get the children.
145 const auto &Children = Die.getChildren();
146
147 // Size the DIE children if any.
148 if (!Children.empty()) {
149 assert(Abbrev.hasChildren() && "Children flag not set");
150
151 for (auto &Child : Children)
152 Offset = computeSizeAndOffset(*Child, Offset);
153
154 // End of children marker.
155 Offset += sizeof(int8_t);
156 }
157
158 Die.setSize(Offset - Die.getOffset());
159 return Offset;
160 }
161 void DwarfFile::emitAbbrevs(const MCSection *Section) {
162 // Check to see if it is worth the effort.
163 if (!Abbreviations.empty()) {
164 // Start the debug abbrev section.
165 Asm->OutStreamer.SwitchSection(Section);
166
167 // For each abbrevation.
168 for (const DIEAbbrev *Abbrev : Abbreviations) {
169 // Emit the abbrevations code (base 1 index.)
170 Asm->EmitULEB128(Abbrev->getNumber(), "Abbreviation Code");
171
172 // Emit the abbreviations data.
173 Abbrev->Emit(Asm);
174 }
175
176 // Mark end of abbreviations.
177 Asm->EmitULEB128(0, "EOM(3)");
178 }
179 }
180
181 // Emit strings into a string section.
182 void DwarfFile::emitStrings(const MCSection *StrSection,
183 const MCSection *OffsetSection,
184 const MCSymbol *StrSecSym) {
185
186 if (StringPool.empty())
187 return;
188
189 // Start the dwarf str section.
190 Asm->OutStreamer.SwitchSection(StrSection);
191
192 // Get all of the string pool entries and put them in an array by their ID so
193 // we can sort them.
194 SmallVector, 64 > Entries;
195
196 for (const auto &I : StringPool)
197 Entries.push_back(std::make_pair(I.second.second, &I));
198
199 array_pod_sort(Entries.begin(), Entries.end());
200
201 for (const auto &Entry : Entries) {
202 // Emit a label for reference from debug information entries.
203 Asm->OutStreamer.EmitLabel(Entry.second->getValue().first);
204
205 // Emit the string itself with a terminating null byte.
206 Asm->OutStreamer.EmitBytes(StringRef(Entry.second->getKeyData(),
207 Entry.second->getKeyLength() + 1));
208 }
209
210 // If we've got an offset section go ahead and emit that now as well.
211 if (OffsetSection) {
212 Asm->OutStreamer.SwitchSection(OffsetSection);
213 unsigned offset = 0;
214 unsigned size = 4; // FIXME: DWARF64 is 8.
215 for (const auto &Entry : Entries) {
216 Asm->OutStreamer.EmitIntValue(offset, size);
217 offset += Entry.second->getKeyLength() + 1;
218 }
219 }
220 }
221
222 // Emit addresses into the section given.
223 void DwarfFile::emitAddresses(const MCSection *AddrSection) {
224
225 if (AddressPool.empty())
226 return;
227
228 // Start the dwarf addr section.
229 Asm->OutStreamer.SwitchSection(AddrSection);
230
231 // Order the address pool entries by ID
232 SmallVector Entries(AddressPool.size());
233
234 for (const auto &I : AddressPool)
235 Entries[I.second.Number] =
236 I.second.TLS
237 ? Asm->getObjFileLowering().getDebugThreadLocalSymbol(I.first)
238 : MCSymbolRefExpr::Create(I.first, Asm->OutContext);
239
240 for (const MCExpr *Entry : Entries)
241 Asm->OutStreamer.EmitValue(Entry, Asm->getDataLayout().getPointerSize());
242 }
243 }
0 //===-- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework -------*- C++ -*--===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef CODEGEN_ASMPRINTER_DWARFFILE_H__
10 #define CODEGEN_ASMPRINTER_DWARFFILE_H__
11
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/FoldingSet.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringMap.h"
16 #include "llvm/Support/Allocator.h"
17
18 #include
19 #include
20 #include
21
22 namespace llvm {
23 class AsmPrinter;
24 class DwarfUnit;
25 class DIEAbbrev;
26 class MCSymbol;
27 class DIE;
28 class StringRef;
29 class DwarfDebug;
30 class MCSection;
31 class DwarfFile {
32 // Target of Dwarf emission, used for sizing of abbreviations.
33 AsmPrinter *Asm;
34
35 // Used to uniquely define abbreviations.
36 FoldingSet AbbreviationsSet;
37
38 // A list of all the unique abbreviations in use.
39 std::vector Abbreviations;
40
41 // A pointer to all units in the section.
42 SmallVector, 1> CUs;
43
44 // Collection of strings for this unit and assorted symbols.
45 // A String->Symbol mapping of strings used by indirect
46 // references.
47 typedef StringMap, BumpPtrAllocator &>
48 StrPool;
49 StrPool StringPool;
50 unsigned NextStringPoolNumber;
51 std::string StringPref;
52
53 struct AddressPoolEntry {
54 unsigned Number;
55 bool TLS;
56 AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
57 };
58 // Collection of addresses for this unit and assorted labels.
59 // A Symbol->unsigned mapping of addresses used by indirect
60 // references.
61 typedef DenseMap AddrPool;
62 AddrPool AddressPool;
63
64 public:
65 DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA);
66
67 ~DwarfFile();
68
69 const SmallVectorImpl> &getUnits() { return CUs; }
70
71 /// \brief Compute the size and offset of a DIE given an incoming Offset.
72 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
73
74 /// \brief Compute the size and offset of all the DIEs.
75 void computeSizeAndOffsets();
76
77 /// \brief Define a unique number for the abbreviation.
78 void assignAbbrevNumber(DIEAbbrev &Abbrev);
79
80 /// \brief Add a unit to the list of CUs.
81 void addUnit(std::unique_ptr U);
82
83 /// \brief Emit all of the units to the section listed with the given
84 /// abbreviation section.
85 void emitUnits(DwarfDebug *DD, const MCSymbol *ASectionSym);
86
87 /// \brief Emit a set of abbreviations to the specific section.
88 void emitAbbrevs(const MCSection *);
89
90 /// \brief Emit all of the strings to the section given.
91 void emitStrings(const MCSection *StrSection,
92 const MCSection *OffsetSection = nullptr,
93 const MCSymbol *StrSecSym = nullptr);
94
95 /// \brief Emit all of the addresses to the section given.
96 void emitAddresses(const MCSection *AddrSection);
97
98 /// \brief Returns the entry into the start of the pool.
99 MCSymbol *getStringPoolSym();
100
101 /// \brief Returns an entry into the string pool with the given
102 /// string text.
103 MCSymbol *getStringPoolEntry(StringRef Str);
104
105 /// \brief Returns the index into the string pool with the given
106 /// string text.
107 unsigned getStringPoolIndex(StringRef Str);
108
109 /// \brief Returns the string pool.
110 StrPool *getStringPool() { return &StringPool; }
111
112 /// \brief Returns the index into the address pool with the given
113 /// label/symbol.
114 unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false);
115
116 /// \brief Returns the address pool.
117 AddrPool *getAddrPool() { return &AddressPool; }
118 };
119 }
120 #endif