blob: 0832544c0d65071da9375989cc60511ea830cf3b [file] [log] [blame]
Bill Wendling47054f32009-05-15 00:11:17 +00001//===--- lib/CodeGen/DIE.cpp - DWARF Info Entries -------------------------===//
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// Data structures for DWARF info entries.
Eric Christopherb800ff72013-01-07 22:40:45 +000011//
Bill Wendling47054f32009-05-15 00:11:17 +000012//===----------------------------------------------------------------------===//
13
Frederic Risse541e0b2015-01-05 21:29:41 +000014#include "llvm/CodeGen/DIE.h"
David Blaikie37c52312014-10-04 15:49:50 +000015#include "DwarfCompileUnit.h"
Manman Renac8062b2013-07-02 23:40:10 +000016#include "DwarfDebug.h"
David Blaikie47f615e2013-12-17 23:32:35 +000017#include "DwarfUnit.h"
Benjamin Kramer4d128a22010-01-17 07:46:39 +000018#include "llvm/ADT/Twine.h"
Bill Wendling47054f32009-05-15 00:11:17 +000019#include "llvm/CodeGen/AsmPrinter.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000020#include "llvm/IR/DataLayout.h"
Chris Lattner7b26fce2009-08-22 20:48:53 +000021#include "llvm/MC/MCAsmInfo.h"
Rafael Espindola74dd8542014-10-21 00:25:49 +000022#include "llvm/MC/MCContext.h"
Chris Lattner71601e82010-01-20 07:41:15 +000023#include "llvm/MC/MCStreamer.h"
Chris Lattner06d45f62010-01-16 18:50:28 +000024#include "llvm/MC/MCSymbol.h"
David Greene8bc072c2009-12-24 00:27:55 +000025#include "llvm/Support/Debug.h"
Torok Edwin56d06592009-07-11 20:10:48 +000026#include "llvm/Support/ErrorHandling.h"
Chris Lattner74725712009-08-23 01:01:17 +000027#include "llvm/Support/Format.h"
Chris Lattnerf5c834f2010-01-22 22:09:00 +000028#include "llvm/Support/FormattedStream.h"
Logan Chien5b776b72014-02-22 14:00:39 +000029#include "llvm/Support/LEB128.h"
Eric Christopher67646432013-07-26 17:02:41 +000030#include "llvm/Support/MD5.h"
Benjamin Kramer799003b2015-03-23 19:32:43 +000031#include "llvm/Support/raw_ostream.h"
Bill Wendling47054f32009-05-15 00:11:17 +000032using namespace llvm;
33
Paul Robinson70b34532017-04-20 19:16:51 +000034#define DEBUG_TYPE "dwarfdebug"
35
Bill Wendling47054f32009-05-15 00:11:17 +000036//===----------------------------------------------------------------------===//
37// DIEAbbrevData Implementation
38//===----------------------------------------------------------------------===//
39
40/// Profile - Used to gather unique data for the abbreviation folding set.
41///
42void DIEAbbrevData::Profile(FoldingSetNodeID &ID) const {
Reid Klecknerad65f102013-10-21 19:18:31 +000043 // Explicitly cast to an integer type for which FoldingSetNodeID has
44 // overloads. Otherwise MSVC 2010 thinks this call is ambiguous.
45 ID.AddInteger(unsigned(Attribute));
46 ID.AddInteger(unsigned(Form));
Victor Leschukd7bfa402017-03-01 22:13:42 +000047 if (Form == dwarf::DW_FORM_implicit_const)
48 ID.AddInteger(Value);
Bill Wendling47054f32009-05-15 00:11:17 +000049}
50
51//===----------------------------------------------------------------------===//
52// DIEAbbrev Implementation
53//===----------------------------------------------------------------------===//
54
55/// Profile - Used to gather unique data for the abbreviation folding set.
56///
57void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
Reid Klecknerad65f102013-10-21 19:18:31 +000058 ID.AddInteger(unsigned(Tag));
Eric Christophere8f10722014-03-05 01:44:58 +000059 ID.AddInteger(unsigned(Children));
Bill Wendling47054f32009-05-15 00:11:17 +000060
61 // For each attribute description.
62 for (unsigned i = 0, N = Data.size(); i < N; ++i)
63 Data[i].Profile(ID);
64}
65
66/// Emit - Print the abbreviation using the specified asm printer.
67///
Frederic Risscd044342015-03-04 02:30:08 +000068void DIEAbbrev::Emit(const AsmPrinter *AP) const {
Bill Wendling47054f32009-05-15 00:11:17 +000069 // Emit its Dwarf tag type.
Mehdi Amini149f6ea2016-10-05 05:59:29 +000070 AP->EmitULEB128(Tag, dwarf::TagString(Tag).data());
Bill Wendling47054f32009-05-15 00:11:17 +000071
72 // Emit whether it has children DIEs.
Mehdi Amini149f6ea2016-10-05 05:59:29 +000073 AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
Bill Wendling47054f32009-05-15 00:11:17 +000074
75 // For each attribute description.
76 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
77 const DIEAbbrevData &AttrData = Data[i];
78
79 // Emit attribute type.
Chris Lattner3a383cb2010-04-05 00:13:49 +000080 AP->EmitULEB128(AttrData.getAttribute(),
Mehdi Amini149f6ea2016-10-05 05:59:29 +000081 dwarf::AttributeString(AttrData.getAttribute()).data());
Bill Wendling47054f32009-05-15 00:11:17 +000082
83 // Emit form type.
Paul Robinson70b34532017-04-20 19:16:51 +000084#ifndef NDEBUG
85 // Could be an assertion, but this way we can see the failing form code
86 // easily, which helps track down where it came from.
87 if (!dwarf::isValidFormForVersion(AttrData.getForm(),
88 AP->getDwarfVersion())) {
89 DEBUG(dbgs() << "Invalid form " << format("0x%x", AttrData.getForm())
90 << " for DWARF version " << AP->getDwarfVersion() << "\n");
91 llvm_unreachable("Invalid form for specified DWARF version");
92 }
93#endif
Chris Lattner3a383cb2010-04-05 00:13:49 +000094 AP->EmitULEB128(AttrData.getForm(),
Mehdi Amini149f6ea2016-10-05 05:59:29 +000095 dwarf::FormEncodingString(AttrData.getForm()).data());
Victor Leschukcbddae72017-01-10 21:18:26 +000096
97 // Emit value for DW_FORM_implicit_const.
Paul Robinson70b34532017-04-20 19:16:51 +000098 if (AttrData.getForm() == dwarf::DW_FORM_implicit_const)
Victor Leschukcbddae72017-01-10 21:18:26 +000099 AP->EmitSLEB128(AttrData.getValue());
Bill Wendling47054f32009-05-15 00:11:17 +0000100 }
101
102 // Mark end of abbreviation.
Chris Lattner3a383cb2010-04-05 00:13:49 +0000103 AP->EmitULEB128(0, "EOM(1)");
104 AP->EmitULEB128(0, "EOM(2)");
Bill Wendling47054f32009-05-15 00:11:17 +0000105}
106
Davide Italianoc304a0d2015-11-24 02:21:43 +0000107LLVM_DUMP_METHOD
Sam Clegg705f7982017-06-21 22:19:17 +0000108void DIEAbbrev::print(raw_ostream &O) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000109 O << "Abbreviation @"
Chris Lattner74725712009-08-23 01:01:17 +0000110 << format("0x%lx", (long)(intptr_t)this)
Bill Wendling47054f32009-05-15 00:11:17 +0000111 << " "
112 << dwarf::TagString(Tag)
113 << " "
Eric Christophere8f10722014-03-05 01:44:58 +0000114 << dwarf::ChildrenString(Children)
Chris Lattner74725712009-08-23 01:01:17 +0000115 << '\n';
Bill Wendling47054f32009-05-15 00:11:17 +0000116
117 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
118 O << " "
119 << dwarf::AttributeString(Data[i].getAttribute())
120 << " "
Victor Leschukd7bfa402017-03-01 22:13:42 +0000121 << dwarf::FormEncodingString(Data[i].getForm());
122
123 if (Data[i].getForm() == dwarf::DW_FORM_implicit_const)
124 O << " " << Data[i].getValue();
125
126 O << '\n';
Bill Wendling47054f32009-05-15 00:11:17 +0000127 }
128}
Davide Italianoc304a0d2015-11-24 02:21:43 +0000129
Aaron Ballman615eb472017-10-15 14:32:27 +0000130#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Sam Clegg705f7982017-06-21 22:19:17 +0000131LLVM_DUMP_METHOD void DIEAbbrev::dump() const {
Matthias Braun8c209aa2017-01-28 02:02:38 +0000132 print(dbgs());
133}
134#endif
Bill Wendling47054f32009-05-15 00:11:17 +0000135
Greg Clayton3462a422016-12-08 01:03:48 +0000136//===----------------------------------------------------------------------===//
137// DIEAbbrevSet Implementation
138//===----------------------------------------------------------------------===//
139
140DIEAbbrevSet::~DIEAbbrevSet() {
141 for (DIEAbbrev *Abbrev : Abbreviations)
142 Abbrev->~DIEAbbrev();
143}
144
145DIEAbbrev &DIEAbbrevSet::uniqueAbbreviation(DIE &Die) {
146
147 FoldingSetNodeID ID;
148 DIEAbbrev Abbrev = Die.generateAbbrev();
149 Abbrev.Profile(ID);
150
151 void *InsertPos;
152 if (DIEAbbrev *Existing =
153 AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
154 Die.setAbbrevNumber(Existing->getNumber());
155 return *Existing;
156 }
157
158 // Move the abbreviation to the heap and assign a number.
159 DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
160 Abbreviations.push_back(New);
161 New->setNumber(Abbreviations.size());
162 Die.setAbbrevNumber(Abbreviations.size());
163
164 // Store it for lookup.
165 AbbreviationsSet.InsertNode(New, InsertPos);
166 return *New;
167}
168
169void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const {
170 if (!Abbreviations.empty()) {
171 // Start the debug abbrev section.
172 AP->OutStreamer->SwitchSection(Section);
173 AP->emitDwarfAbbrevs(Abbreviations);
174 }
175}
176
177//===----------------------------------------------------------------------===//
178// DIE Implementation
179//===----------------------------------------------------------------------===//
180
Greg Clayton35630c32016-12-01 18:56:29 +0000181DIE *DIE::getParent() const {
182 return Owner.dyn_cast<DIE*>();
183}
184
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +0000185DIEAbbrev DIE::generateAbbrev() const {
186 DIEAbbrev Abbrev(Tag, hasChildren());
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000187 for (const DIEValue &V : values())
Victor Leschukcbddae72017-01-10 21:18:26 +0000188 if (V.getForm() == dwarf::DW_FORM_implicit_const)
189 Abbrev.AddImplicitConstAttribute(V.getAttribute(),
190 V.getDIEInteger().getValue());
191 else
192 Abbrev.AddAttribute(V.getAttribute(), V.getForm());
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +0000193 return Abbrev;
194}
195
Greg Clayton35630c32016-12-01 18:56:29 +0000196unsigned DIE::getDebugSectionOffset() const {
197 const DIEUnit *Unit = getUnit();
198 assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
Benjamin Kramer6a8704c2016-12-01 19:10:10 +0000199 return Unit->getDebugSectionOffset() + getOffset();
Manman Ren4dbdc902013-10-31 17:54:35 +0000200}
201
Greg Clayton35630c32016-12-01 18:56:29 +0000202const DIE *DIE::getUnitDie() const {
Manman Rence20d462013-10-29 22:57:10 +0000203 const DIE *p = this;
204 while (p) {
David Blaikie409dd9c2013-11-19 23:08:21 +0000205 if (p->getTag() == dwarf::DW_TAG_compile_unit ||
206 p->getTag() == dwarf::DW_TAG_type_unit)
Manman Rence20d462013-10-29 22:57:10 +0000207 return p;
208 p = p->getParent();
209 }
Craig Topper353eda42014-04-24 06:44:33 +0000210 return nullptr;
Manman Rence20d462013-10-29 22:57:10 +0000211}
212
Greg Clayton35630c32016-12-01 18:56:29 +0000213const DIEUnit *DIE::getUnit() const {
214 const DIE *UnitDie = getUnitDie();
215 if (UnitDie)
216 return UnitDie->Owner.dyn_cast<DIEUnit*>();
217 return nullptr;
218}
219
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000220DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const {
Eric Christopher8552e222013-08-07 01:18:33 +0000221 // Iterate through all the attributes until we find the one we're
222 // looking for, if we can't find it return NULL.
Duncan P. N. Exon Smith88a8fc52015-05-27 22:44:06 +0000223 for (const auto &V : values())
224 if (V.getAttribute() == Attribute)
225 return V;
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000226 return DIEValue();
Eric Christopher8552e222013-08-07 01:18:33 +0000227}
228
Davide Italianoc304a0d2015-11-24 02:21:43 +0000229LLVM_DUMP_METHOD
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000230static void printValues(raw_ostream &O, const DIEValueList &Values,
231 StringRef Type, unsigned Size, unsigned IndentCount) {
232 O << Type << ": Size: " << Size << "\n";
233
234 unsigned I = 0;
235 const std::string Indent(IndentCount, ' ');
236 for (const auto &V : Values.values()) {
237 O << Indent;
238 O << "Blk[" << I++ << "]";
239 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
240 V.print(O);
241 O << "\n";
242 }
243}
244
Davide Italianoc304a0d2015-11-24 02:21:43 +0000245LLVM_DUMP_METHOD
Eric Christopher6c6de842013-05-06 17:50:50 +0000246void DIE::print(raw_ostream &O, unsigned IndentCount) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000247 const std::string Indent(IndentCount, ' ');
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000248 O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this)
249 << ", Offset: " << Offset << ", Size: " << Size << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000250
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000251 O << Indent << dwarf::TagString(getTag()) << " "
252 << dwarf::ChildrenString(hasChildren()) << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000253
Bill Wendling47054f32009-05-15 00:11:17 +0000254 IndentCount += 2;
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000255 for (const auto &V : values()) {
Bill Wendling47054f32009-05-15 00:11:17 +0000256 O << Indent;
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000257 O << dwarf::AttributeString(V.getAttribute());
Duncan P. N. Exon Smith4fb1f9c2015-06-25 23:46:41 +0000258 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
259 V.print(O);
Bill Wendling47054f32009-05-15 00:11:17 +0000260 O << "\n";
261 }
262 IndentCount -= 2;
263
Duncan P. N. Exon Smith827200c2015-06-25 23:52:10 +0000264 for (const auto &Child : children())
265 Child.print(O, IndentCount + 4);
Bill Wendling47054f32009-05-15 00:11:17 +0000266
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000267 O << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000268}
269
Aaron Ballman615eb472017-10-15 14:32:27 +0000270#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Sam Clegg705f7982017-06-21 22:19:17 +0000271LLVM_DUMP_METHOD void DIE::dump() const {
David Greene8bc072c2009-12-24 00:27:55 +0000272 print(dbgs());
Bill Wendling47054f32009-05-15 00:11:17 +0000273}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000274#endif
Bill Wendling47054f32009-05-15 00:11:17 +0000275
Greg Clayton3462a422016-12-08 01:03:48 +0000276unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP,
277 DIEAbbrevSet &AbbrevSet,
278 unsigned CUOffset) {
279 // Unique the abbreviation and fill in the abbreviation number so this DIE
280 // can be emitted.
281 const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
282
283 // Set compile/type unit relative offset of this DIE.
284 setOffset(CUOffset);
285
286 // Add the byte size of the abbreviation code.
287 CUOffset += getULEB128Size(getAbbrevNumber());
288
289 // Add the byte size of all the DIE attribute values.
290 for (const auto &V : values())
291 CUOffset += V.SizeOf(AP);
292
293 // Let the children compute their offsets and abbreviation numbers.
294 if (hasChildren()) {
295 (void)Abbrev;
296 assert(Abbrev.hasChildren() && "Children flag not set");
297
298 for (auto &Child : children())
299 CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
300
301 // Each child chain is terminated with a zero byte, adjust the offset.
302 CUOffset += sizeof(int8_t);
303 }
304
305 // Compute the byte size of this DIE and all of its children correctly. This
306 // is needed so that top level DIE can help the compile unit set its length
307 // correctly.
308 setSize(CUOffset - getOffset());
309 return CUOffset;
310}
311
312//===----------------------------------------------------------------------===//
313// DIEUnit Implementation
314//===----------------------------------------------------------------------===//
Greg Clayton35630c32016-12-01 18:56:29 +0000315DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag)
316 : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V),
317 AddrSize(A)
318{
David Blaikiee40caae2016-12-01 21:59:09 +0000319 Die.Owner = this;
Greg Clayton35630c32016-12-01 18:56:29 +0000320 assert((UnitTag == dwarf::DW_TAG_compile_unit ||
321 UnitTag == dwarf::DW_TAG_type_unit ||
322 UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG");
323}
324
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000325void DIEValue::EmitValue(const AsmPrinter *AP) const {
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000326 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000327 case isNone:
328 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000329#define HANDLE_DIEVALUE(T) \
330 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000331 getDIE##T().EmitValue(AP, Form); \
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000332 break;
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000333#include "llvm/CodeGen/DIEValue.def"
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000334 }
335}
336
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000337unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000338 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000339 case isNone:
340 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000341#define HANDLE_DIEVALUE(T) \
342 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000343 return getDIE##T().SizeOf(AP, Form);
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000344#include "llvm/CodeGen/DIEValue.def"
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000345 }
Aaron Ballmanc681c3d2015-05-23 14:46:49 +0000346 llvm_unreachable("Unknown DIE kind");
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000347}
Bill Wendling47054f32009-05-15 00:11:17 +0000348
Davide Italianoc304a0d2015-11-24 02:21:43 +0000349LLVM_DUMP_METHOD
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000350void DIEValue::print(raw_ostream &O) const {
351 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000352 case isNone:
353 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000354#define HANDLE_DIEVALUE(T) \
355 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000356 getDIE##T().print(O); \
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000357 break;
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000358#include "llvm/CodeGen/DIEValue.def"
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000359 }
360}
361
Aaron Ballman615eb472017-10-15 14:32:27 +0000362#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Matthias Braun8c209aa2017-01-28 02:02:38 +0000363LLVM_DUMP_METHOD void DIEValue::dump() const {
David Greene8bc072c2009-12-24 00:27:55 +0000364 print(dbgs());
Bill Wendling47054f32009-05-15 00:11:17 +0000365}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000366#endif
Bill Wendling47054f32009-05-15 00:11:17 +0000367
368//===----------------------------------------------------------------------===//
369// DIEInteger Implementation
370//===----------------------------------------------------------------------===//
371
372/// EmitValue - Emit integer of appropriate size.
373///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000374void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000375 switch (Form) {
Victor Leschukcbddae72017-01-10 21:18:26 +0000376 case dwarf::DW_FORM_implicit_const:
Eric Christopherbb69a272012-08-24 01:14:27 +0000377 case dwarf::DW_FORM_flag_present:
378 // Emit something to keep the lines and comments in sync.
379 // FIXME: Is there a better way to do this?
Lang Hames9ff69c82015-04-24 19:11:51 +0000380 Asm->OutStreamer->AddBlankLine();
Eric Christopherbb69a272012-08-24 01:14:27 +0000381 return;
Greg Clayton3462a422016-12-08 01:03:48 +0000382 case dwarf::DW_FORM_flag:
Greg Clayton3462a422016-12-08 01:03:48 +0000383 case dwarf::DW_FORM_ref1:
Greg Clayton3462a422016-12-08 01:03:48 +0000384 case dwarf::DW_FORM_data1:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000385 case dwarf::DW_FORM_strx1:
386 case dwarf::DW_FORM_addrx1:
Greg Clayton3462a422016-12-08 01:03:48 +0000387 case dwarf::DW_FORM_ref2:
Greg Clayton3462a422016-12-08 01:03:48 +0000388 case dwarf::DW_FORM_data2:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000389 case dwarf::DW_FORM_strx2:
390 case dwarf::DW_FORM_addrx2:
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000391 case dwarf::DW_FORM_strx3:
Greg Clayton3462a422016-12-08 01:03:48 +0000392 case dwarf::DW_FORM_strp:
Greg Clayton3462a422016-12-08 01:03:48 +0000393 case dwarf::DW_FORM_ref4:
Greg Clayton3462a422016-12-08 01:03:48 +0000394 case dwarf::DW_FORM_data4:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000395 case dwarf::DW_FORM_ref_sup4:
396 case dwarf::DW_FORM_strx4:
397 case dwarf::DW_FORM_addrx4:
Greg Clayton3462a422016-12-08 01:03:48 +0000398 case dwarf::DW_FORM_ref8:
Greg Clayton3462a422016-12-08 01:03:48 +0000399 case dwarf::DW_FORM_ref_sig8:
Greg Clayton3462a422016-12-08 01:03:48 +0000400 case dwarf::DW_FORM_data8:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000401 case dwarf::DW_FORM_ref_sup8:
Greg Clayton3462a422016-12-08 01:03:48 +0000402 case dwarf::DW_FORM_GNU_ref_alt:
Greg Clayton3462a422016-12-08 01:03:48 +0000403 case dwarf::DW_FORM_GNU_strp_alt:
Greg Clayton3462a422016-12-08 01:03:48 +0000404 case dwarf::DW_FORM_line_strp:
Greg Clayton3462a422016-12-08 01:03:48 +0000405 case dwarf::DW_FORM_sec_offset:
Greg Clayton3462a422016-12-08 01:03:48 +0000406 case dwarf::DW_FORM_strp_sup:
Eric Christophere8a7b1b2012-09-10 23:34:03 +0000407 case dwarf::DW_FORM_addr:
Frederic Rissee17fb9b2015-03-04 22:07:36 +0000408 case dwarf::DW_FORM_ref_addr:
Greg Clayton3462a422016-12-08 01:03:48 +0000409 Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form));
410 return;
411 case dwarf::DW_FORM_GNU_str_index:
Greg Clayton3462a422016-12-08 01:03:48 +0000412 case dwarf::DW_FORM_GNU_addr_index:
Greg Clayton3462a422016-12-08 01:03:48 +0000413 case dwarf::DW_FORM_ref_udata:
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000414 case dwarf::DW_FORM_strx:
Greg Clayton3462a422016-12-08 01:03:48 +0000415 case dwarf::DW_FORM_udata:
416 Asm->EmitULEB128(Integer);
417 return;
418 case dwarf::DW_FORM_sdata:
419 Asm->EmitSLEB128(Integer);
420 return;
Torok Edwinfbcc6632009-07-14 16:55:14 +0000421 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling47054f32009-05-15 00:11:17 +0000422 }
423}
424
425/// SizeOf - Determine size of integer value in bytes.
426///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000427unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000428 switch (Form) {
Paul Robinsona94f76b2017-03-01 23:59:11 +0000429 case dwarf::DW_FORM_implicit_const:
430 case dwarf::DW_FORM_flag_present:
431 return 0;
432 case dwarf::DW_FORM_flag:
433 case dwarf::DW_FORM_ref1:
434 case dwarf::DW_FORM_data1:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000435 case dwarf::DW_FORM_strx1:
436 case dwarf::DW_FORM_addrx1:
Paul Robinsona94f76b2017-03-01 23:59:11 +0000437 return sizeof(int8_t);
438 case dwarf::DW_FORM_ref2:
439 case dwarf::DW_FORM_data2:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000440 case dwarf::DW_FORM_strx2:
441 case dwarf::DW_FORM_addrx2:
Paul Robinsona94f76b2017-03-01 23:59:11 +0000442 return sizeof(int16_t);
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000443 case dwarf::DW_FORM_strx3:
444 return 3;
Paul Robinsona94f76b2017-03-01 23:59:11 +0000445 case dwarf::DW_FORM_ref4:
446 case dwarf::DW_FORM_data4:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000447 case dwarf::DW_FORM_ref_sup4:
448 case dwarf::DW_FORM_strx4:
449 case dwarf::DW_FORM_addrx4:
Paul Robinsona94f76b2017-03-01 23:59:11 +0000450 return sizeof(int32_t);
451 case dwarf::DW_FORM_ref8:
452 case dwarf::DW_FORM_ref_sig8:
453 case dwarf::DW_FORM_data8:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000454 case dwarf::DW_FORM_ref_sup8:
Paul Robinsona94f76b2017-03-01 23:59:11 +0000455 return sizeof(int64_t);
Frederic Rissee17fb9b2015-03-04 22:07:36 +0000456 case dwarf::DW_FORM_ref_addr:
Greg Claytone6543972016-11-23 23:30:37 +0000457 if (AP->getDwarfVersion() == 2)
Mehdi Amini1660cab2015-07-16 05:59:25 +0000458 return AP->getPointerSize();
Greg Clayton3462a422016-12-08 01:03:48 +0000459 LLVM_FALLTHROUGH;
460 case dwarf::DW_FORM_strp:
Greg Clayton3462a422016-12-08 01:03:48 +0000461 case dwarf::DW_FORM_GNU_ref_alt:
Greg Clayton3462a422016-12-08 01:03:48 +0000462 case dwarf::DW_FORM_GNU_strp_alt:
Greg Clayton3462a422016-12-08 01:03:48 +0000463 case dwarf::DW_FORM_line_strp:
Greg Clayton3462a422016-12-08 01:03:48 +0000464 case dwarf::DW_FORM_sec_offset:
Greg Clayton3462a422016-12-08 01:03:48 +0000465 case dwarf::DW_FORM_strp_sup:
Greg Clayton3462a422016-12-08 01:03:48 +0000466 switch (AP->OutStreamer->getContext().getDwarfFormat()) {
467 case dwarf::DWARF32:
468 return 4;
469 case dwarf::DWARF64:
470 return 8;
471 }
472 llvm_unreachable("Invalid DWARF format");
473 case dwarf::DW_FORM_GNU_str_index:
Greg Clayton3462a422016-12-08 01:03:48 +0000474 case dwarf::DW_FORM_GNU_addr_index:
Greg Clayton3462a422016-12-08 01:03:48 +0000475 case dwarf::DW_FORM_ref_udata:
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000476 case dwarf::DW_FORM_strx:
Greg Clayton3462a422016-12-08 01:03:48 +0000477 case dwarf::DW_FORM_udata:
478 return getULEB128Size(Integer);
479 case dwarf::DW_FORM_sdata:
480 return getSLEB128Size(Integer);
481 case dwarf::DW_FORM_addr:
482 return AP->getPointerSize();
David Blaikie46a9f012012-01-20 21:51:11 +0000483 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling47054f32009-05-15 00:11:17 +0000484 }
Bill Wendling47054f32009-05-15 00:11:17 +0000485}
486
Davide Italianoc304a0d2015-11-24 02:21:43 +0000487LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000488void DIEInteger::print(raw_ostream &O) const {
Benjamin Kramerf3da5292011-11-05 08:57:40 +0000489 O << "Int: " << (int64_t)Integer << " 0x";
490 O.write_hex(Integer);
Bill Wendling47054f32009-05-15 00:11:17 +0000491}
Bill Wendling47054f32009-05-15 00:11:17 +0000492
493//===----------------------------------------------------------------------===//
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000494// DIEExpr Implementation
495//===----------------------------------------------------------------------===//
496
497/// EmitValue - Emit expression value.
498///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000499void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Simon Dardis2e8cdbd2017-02-08 19:03:46 +0000500 AP->EmitDebugThreadLocal(Expr, SizeOf(AP, Form));
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000501}
502
503/// SizeOf - Determine size of expression value in bytes.
504///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000505unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000506 if (Form == dwarf::DW_FORM_data4) return 4;
507 if (Form == dwarf::DW_FORM_sec_offset) return 4;
508 if (Form == dwarf::DW_FORM_strp) return 4;
Mehdi Amini1660cab2015-07-16 05:59:25 +0000509 return AP->getPointerSize();
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000510}
511
Davide Italianoc304a0d2015-11-24 02:21:43 +0000512LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000513void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000514
515//===----------------------------------------------------------------------===//
Chris Lattner8dcf41e2010-03-08 22:31:46 +0000516// DIELabel Implementation
Bill Wendling47054f32009-05-15 00:11:17 +0000517//===----------------------------------------------------------------------===//
518
519/// EmitValue - Emit label value.
520///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000521void DIELabel::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
David Blaikief2443192013-10-21 17:28:37 +0000522 AP->EmitLabelReference(Label, SizeOf(AP, Form),
523 Form == dwarf::DW_FORM_strp ||
524 Form == dwarf::DW_FORM_sec_offset ||
Keno Fischerf7d84ee2017-01-02 03:00:19 +0000525 Form == dwarf::DW_FORM_ref_addr ||
526 Form == dwarf::DW_FORM_data4);
Bill Wendling47054f32009-05-15 00:11:17 +0000527}
528
529/// SizeOf - Determine size of label value in bytes.
530///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000531unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000532 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher4c7765f2013-01-17 03:00:04 +0000533 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewyckyd59c0ca2011-10-27 06:44:11 +0000534 if (Form == dwarf::DW_FORM_strp) return 4;
Konstantin Zhuravlyovdc77b2e2017-04-17 17:41:25 +0000535 return AP->MAI->getCodePointerSize();
Bill Wendling47054f32009-05-15 00:11:17 +0000536}
537
Davide Italianoc304a0d2015-11-24 02:21:43 +0000538LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000539void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
Bill Wendling47054f32009-05-15 00:11:17 +0000540
541//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000542// DIEDelta Implementation
543//===----------------------------------------------------------------------===//
544
545/// EmitValue - Emit delta value.
546///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000547void DIEDelta::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Chris Lattner5a00dea2010-04-05 00:18:22 +0000548 AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
Bill Wendling47054f32009-05-15 00:11:17 +0000549}
550
551/// SizeOf - Determine size of delta value in bytes.
552///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000553unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000554 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher33ff6972013-11-21 23:46:41 +0000555 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewyckyd59c0ca2011-10-27 06:44:11 +0000556 if (Form == dwarf::DW_FORM_strp) return 4;
Konstantin Zhuravlyovdc77b2e2017-04-17 17:41:25 +0000557 return AP->MAI->getCodePointerSize();
Bill Wendling47054f32009-05-15 00:11:17 +0000558}
559
Davide Italianoc304a0d2015-11-24 02:21:43 +0000560LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000561void DIEDelta::print(raw_ostream &O) const {
Chris Lattnerbc9210c2010-03-08 22:23:36 +0000562 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
Bill Wendling47054f32009-05-15 00:11:17 +0000563}
Bill Wendling47054f32009-05-15 00:11:17 +0000564
565//===----------------------------------------------------------------------===//
Eric Christopher67646432013-07-26 17:02:41 +0000566// DIEString Implementation
567//===----------------------------------------------------------------------===//
568
569/// EmitValue - Emit string value.
570///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000571void DIEString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000572 // Index of string in symbol table.
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000573 switch (Form) {
574 case dwarf::DW_FORM_GNU_str_index:
575 case dwarf::DW_FORM_strx:
576 case dwarf::DW_FORM_strx1:
577 case dwarf::DW_FORM_strx2:
578 case dwarf::DW_FORM_strx3:
579 case dwarf::DW_FORM_strx4:
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000580 DIEInteger(S.getIndex()).EmitValue(AP, Form);
581 return;
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000582 case dwarf::DW_FORM_strp:
583 if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
584 DIELabel(S.getSymbol()).EmitValue(AP, Form);
585 else
586 DIEInteger(S.getOffset()).EmitValue(AP, Form);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000587 return;
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000588 default:
589 llvm_unreachable("Expected valid string form");
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000590 }
Eric Christopher67646432013-07-26 17:02:41 +0000591}
592
593/// SizeOf - Determine size of delta value in bytes.
594///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000595unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000596 // Index of string in symbol table.
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000597 switch (Form) {
598 case dwarf::DW_FORM_GNU_str_index:
599 case dwarf::DW_FORM_strx:
600 case dwarf::DW_FORM_strx1:
601 case dwarf::DW_FORM_strx2:
602 case dwarf::DW_FORM_strx3:
603 case dwarf::DW_FORM_strx4:
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000604 return DIEInteger(S.getIndex()).SizeOf(AP, Form);
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000605 case dwarf::DW_FORM_strp:
606 if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
607 return DIELabel(S.getSymbol()).SizeOf(AP, Form);
608 return DIEInteger(S.getOffset()).SizeOf(AP, Form);
609 default:
610 llvm_unreachable("Expected valid string form");
611 }
Eric Christopher67646432013-07-26 17:02:41 +0000612}
613
Davide Italianoc304a0d2015-11-24 02:21:43 +0000614LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000615void DIEString::print(raw_ostream &O) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000616 O << "String: " << S.getString();
Eric Christopher67646432013-07-26 17:02:41 +0000617}
Eric Christopher67646432013-07-26 17:02:41 +0000618
619//===----------------------------------------------------------------------===//
Greg Clayton3462a422016-12-08 01:03:48 +0000620// DIEInlineString Implementation
621//===----------------------------------------------------------------------===//
622void DIEInlineString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
623 if (Form == dwarf::DW_FORM_string) {
624 for (char ch : S)
625 AP->EmitInt8(ch);
626 AP->EmitInt8(0);
627 return;
628 }
629 llvm_unreachable("Expected valid string form");
630}
631
632unsigned DIEInlineString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
633 // Emit string bytes + NULL byte.
634 return S.size() + 1;
635}
636
637LLVM_DUMP_METHOD
638void DIEInlineString::print(raw_ostream &O) const {
Benjamin Kramereedc4052016-12-09 13:33:41 +0000639 O << "InlineString: " << S;
Greg Clayton3462a422016-12-08 01:03:48 +0000640}
641
642//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000643// DIEEntry Implementation
644//===----------------------------------------------------------------------===//
645
646/// EmitValue - Emit debug information entry offset.
647///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000648void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopherdd508382014-03-06 00:00:56 +0000649
Greg Clayton3462a422016-12-08 01:03:48 +0000650 switch (Form) {
651 case dwarf::DW_FORM_ref1:
652 case dwarf::DW_FORM_ref2:
653 case dwarf::DW_FORM_ref4:
654 case dwarf::DW_FORM_ref8:
655 AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
656 return;
657
658 case dwarf::DW_FORM_ref_udata:
659 AP->EmitULEB128(Entry->getOffset());
660 return;
661
662 case dwarf::DW_FORM_ref_addr: {
Greg Clayton35630c32016-12-01 18:56:29 +0000663 // Get the absolute offset for this DIE within the debug info/types section.
664 unsigned Addr = Entry->getDebugSectionOffset();
David Blaikie85366ac2017-04-22 07:53:44 +0000665 if (const MCSymbol *SectionSym =
666 Entry->getUnit()->getCrossSectionRelativeBaseAddress()) {
667 AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
668 return;
Greg Clayton3462a422016-12-08 01:03:48 +0000669 }
David Blaikie85366ac2017-04-22 07:53:44 +0000670
Greg Clayton3462a422016-12-08 01:03:48 +0000671 AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
672 return;
673 }
674 default:
675 llvm_unreachable("Improper form for DIE reference");
676 }
Bill Wendling47054f32009-05-15 00:11:17 +0000677}
678
Greg Clayton3462a422016-12-08 01:03:48 +0000679unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
680 switch (Form) {
681 case dwarf::DW_FORM_ref1:
682 return 1;
683 case dwarf::DW_FORM_ref2:
684 return 2;
685 case dwarf::DW_FORM_ref4:
686 return 4;
687 case dwarf::DW_FORM_ref8:
688 return 8;
689 case dwarf::DW_FORM_ref_udata:
690 return getULEB128Size(Entry->getOffset());
691 case dwarf::DW_FORM_ref_addr:
692 if (AP->getDwarfVersion() == 2)
Konstantin Zhuravlyovdc77b2e2017-04-17 17:41:25 +0000693 return AP->MAI->getCodePointerSize();
Greg Clayton3462a422016-12-08 01:03:48 +0000694 switch (AP->OutStreamer->getContext().getDwarfFormat()) {
695 case dwarf::DWARF32:
696 return 4;
697 case dwarf::DWARF64:
698 return 8;
699 }
700 llvm_unreachable("Invalid DWARF format");
701
702 default:
703 llvm_unreachable("Improper form for DIE reference");
704 }
Manman Renac8062b2013-07-02 23:40:10 +0000705}
706
Davide Italianoc304a0d2015-11-24 02:21:43 +0000707LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000708void DIEEntry::print(raw_ostream &O) const {
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000709 O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
Bill Wendling47054f32009-05-15 00:11:17 +0000710}
Bill Wendling47054f32009-05-15 00:11:17 +0000711
712//===----------------------------------------------------------------------===//
Eric Christopher4a741042014-02-16 08:46:55 +0000713// DIELoc Implementation
714//===----------------------------------------------------------------------===//
715
716/// ComputeSize - calculate the size of the location expression.
717///
Frederic Risscd044342015-03-04 02:30:08 +0000718unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
Eric Christopher8bdab432014-02-27 18:36:10 +0000719 if (!Size) {
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000720 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000721 Size += V.SizeOf(AP);
Eric Christopher8bdab432014-02-27 18:36:10 +0000722 }
Eric Christopher4a741042014-02-16 08:46:55 +0000723
Eric Christopher8bdab432014-02-27 18:36:10 +0000724 return Size;
Eric Christopher4a741042014-02-16 08:46:55 +0000725}
726
727/// EmitValue - Emit location data.
728///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000729void DIELoc::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Eric Christopher4a741042014-02-16 08:46:55 +0000730 switch (Form) {
731 default: llvm_unreachable("Improper form for block");
732 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
733 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
734 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
735 case dwarf::DW_FORM_block:
736 case dwarf::DW_FORM_exprloc:
737 Asm->EmitULEB128(Size); break;
738 }
739
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000740 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000741 V.EmitValue(Asm);
Eric Christopher4a741042014-02-16 08:46:55 +0000742}
743
744/// SizeOf - Determine size of location data in bytes.
745///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000746unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopher4a741042014-02-16 08:46:55 +0000747 switch (Form) {
748 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
749 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
750 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
751 case dwarf::DW_FORM_block:
752 case dwarf::DW_FORM_exprloc:
Logan Chien5b776b72014-02-22 14:00:39 +0000753 return Size + getULEB128Size(Size);
Eric Christopher4a741042014-02-16 08:46:55 +0000754 default: llvm_unreachable("Improper form for block");
755 }
756}
757
Davide Italianoc304a0d2015-11-24 02:21:43 +0000758LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000759void DIELoc::print(raw_ostream &O) const {
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000760 printValues(O, *this, "ExprLoc", Size, 5);
Eric Christopher4a741042014-02-16 08:46:55 +0000761}
Eric Christopher4a741042014-02-16 08:46:55 +0000762
763//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000764// DIEBlock Implementation
765//===----------------------------------------------------------------------===//
766
767/// ComputeSize - calculate the size of the block.
768///
Frederic Risscd044342015-03-04 02:30:08 +0000769unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
Eric Christopher8bdab432014-02-27 18:36:10 +0000770 if (!Size) {
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000771 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000772 Size += V.SizeOf(AP);
Eric Christopher8bdab432014-02-27 18:36:10 +0000773 }
Bill Wendling47054f32009-05-15 00:11:17 +0000774
Eric Christopher8bdab432014-02-27 18:36:10 +0000775 return Size;
Bill Wendling47054f32009-05-15 00:11:17 +0000776}
777
778/// EmitValue - Emit block data.
779///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000780void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000781 switch (Form) {
Craig Topperee4dab52012-02-05 08:31:47 +0000782 default: llvm_unreachable("Improper form for block");
Chris Lattner9efd1182010-04-04 19:09:29 +0000783 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
784 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
785 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
786 case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
Paul Robinsona06f8dc2017-12-18 19:08:35 +0000787 case dwarf::DW_FORM_data16: break;
Bill Wendling47054f32009-05-15 00:11:17 +0000788 }
789
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000790 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000791 V.EmitValue(Asm);
Bill Wendling47054f32009-05-15 00:11:17 +0000792}
793
794/// SizeOf - Determine size of block data in bytes.
795///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000796unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000797 switch (Form) {
798 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
799 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
800 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
Logan Chien5b776b72014-02-22 14:00:39 +0000801 case dwarf::DW_FORM_block: return Size + getULEB128Size(Size);
Paul Robinsona06f8dc2017-12-18 19:08:35 +0000802 case dwarf::DW_FORM_data16: return 16;
David Blaikie46a9f012012-01-20 21:51:11 +0000803 default: llvm_unreachable("Improper form for block");
Bill Wendling47054f32009-05-15 00:11:17 +0000804 }
Bill Wendling47054f32009-05-15 00:11:17 +0000805}
806
Davide Italianoc304a0d2015-11-24 02:21:43 +0000807LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000808void DIEBlock::print(raw_ostream &O) const {
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000809 printValues(O, *this, "Blk", Size, 5);
Bill Wendling47054f32009-05-15 00:11:17 +0000810}
Eric Christophera27220f2014-03-05 22:41:20 +0000811
812//===----------------------------------------------------------------------===//
813// DIELocList Implementation
814//===----------------------------------------------------------------------===//
815
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000816unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christophera27220f2014-03-05 22:41:20 +0000817 if (Form == dwarf::DW_FORM_data4)
818 return 4;
819 if (Form == dwarf::DW_FORM_sec_offset)
820 return 4;
Konstantin Zhuravlyovdc77b2e2017-04-17 17:41:25 +0000821 return AP->MAI->getCodePointerSize();
Eric Christophera27220f2014-03-05 22:41:20 +0000822}
823
824/// EmitValue - Emit label value.
825///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000826void DIELocList::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
David Blaikie9c550ac2014-03-25 01:44:02 +0000827 DwarfDebug *DD = AP->getDwarfDebug();
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000828 MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
Rafael Espindola857546e2015-06-16 23:22:02 +0000829 AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
Eric Christophera27220f2014-03-05 22:41:20 +0000830}
831
Davide Italianoc304a0d2015-11-24 02:21:43 +0000832LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000833void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }