blob: e27659494f08125d0125ed860fed1435037c0d2f [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"
Nico Weber432a3882018-04-30 14:59:11 +000020#include "llvm/Config/llvm-config.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000021#include "llvm/IR/DataLayout.h"
Chris Lattner7b26fce2009-08-22 20:48:53 +000022#include "llvm/MC/MCAsmInfo.h"
Rafael Espindola74dd8542014-10-21 00:25:49 +000023#include "llvm/MC/MCContext.h"
Chris Lattner71601e82010-01-20 07:41:15 +000024#include "llvm/MC/MCStreamer.h"
Chris Lattner06d45f62010-01-16 18:50:28 +000025#include "llvm/MC/MCSymbol.h"
David Greene8bc072c2009-12-24 00:27:55 +000026#include "llvm/Support/Debug.h"
Torok Edwin56d06592009-07-11 20:10:48 +000027#include "llvm/Support/ErrorHandling.h"
Chris Lattner74725712009-08-23 01:01:17 +000028#include "llvm/Support/Format.h"
Chris Lattnerf5c834f2010-01-22 22:09:00 +000029#include "llvm/Support/FormattedStream.h"
Logan Chien5b776b72014-02-22 14:00:39 +000030#include "llvm/Support/LEB128.h"
Eric Christopher67646432013-07-26 17:02:41 +000031#include "llvm/Support/MD5.h"
Benjamin Kramer799003b2015-03-23 19:32:43 +000032#include "llvm/Support/raw_ostream.h"
Bill Wendling47054f32009-05-15 00:11:17 +000033using namespace llvm;
34
Paul Robinson70b34532017-04-20 19:16:51 +000035#define DEBUG_TYPE "dwarfdebug"
36
Bill Wendling47054f32009-05-15 00:11:17 +000037//===----------------------------------------------------------------------===//
38// DIEAbbrevData Implementation
39//===----------------------------------------------------------------------===//
40
41/// Profile - Used to gather unique data for the abbreviation folding set.
42///
43void DIEAbbrevData::Profile(FoldingSetNodeID &ID) const {
Reid Klecknerad65f102013-10-21 19:18:31 +000044 // Explicitly cast to an integer type for which FoldingSetNodeID has
45 // overloads. Otherwise MSVC 2010 thinks this call is ambiguous.
46 ID.AddInteger(unsigned(Attribute));
47 ID.AddInteger(unsigned(Form));
Victor Leschukd7bfa402017-03-01 22:13:42 +000048 if (Form == dwarf::DW_FORM_implicit_const)
49 ID.AddInteger(Value);
Bill Wendling47054f32009-05-15 00:11:17 +000050}
51
52//===----------------------------------------------------------------------===//
53// DIEAbbrev Implementation
54//===----------------------------------------------------------------------===//
55
56/// Profile - Used to gather unique data for the abbreviation folding set.
57///
58void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
Reid Klecknerad65f102013-10-21 19:18:31 +000059 ID.AddInteger(unsigned(Tag));
Eric Christophere8f10722014-03-05 01:44:58 +000060 ID.AddInteger(unsigned(Children));
Bill Wendling47054f32009-05-15 00:11:17 +000061
62 // For each attribute description.
63 for (unsigned i = 0, N = Data.size(); i < N; ++i)
64 Data[i].Profile(ID);
65}
66
67/// Emit - Print the abbreviation using the specified asm printer.
68///
Frederic Risscd044342015-03-04 02:30:08 +000069void DIEAbbrev::Emit(const AsmPrinter *AP) const {
Bill Wendling47054f32009-05-15 00:11:17 +000070 // Emit its Dwarf tag type.
Mehdi Amini149f6ea2016-10-05 05:59:29 +000071 AP->EmitULEB128(Tag, dwarf::TagString(Tag).data());
Bill Wendling47054f32009-05-15 00:11:17 +000072
73 // Emit whether it has children DIEs.
Mehdi Amini149f6ea2016-10-05 05:59:29 +000074 AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
Bill Wendling47054f32009-05-15 00:11:17 +000075
76 // For each attribute description.
77 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
78 const DIEAbbrevData &AttrData = Data[i];
79
80 // Emit attribute type.
Chris Lattner3a383cb2010-04-05 00:13:49 +000081 AP->EmitULEB128(AttrData.getAttribute(),
Mehdi Amini149f6ea2016-10-05 05:59:29 +000082 dwarf::AttributeString(AttrData.getAttribute()).data());
Bill Wendling47054f32009-05-15 00:11:17 +000083
84 // Emit form type.
Paul Robinson70b34532017-04-20 19:16:51 +000085#ifndef NDEBUG
86 // Could be an assertion, but this way we can see the failing form code
87 // easily, which helps track down where it came from.
88 if (!dwarf::isValidFormForVersion(AttrData.getForm(),
89 AP->getDwarfVersion())) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +000090 LLVM_DEBUG(dbgs() << "Invalid form " << format("0x%x", AttrData.getForm())
91 << " for DWARF version " << AP->getDwarfVersion()
92 << "\n");
Paul Robinson70b34532017-04-20 19:16:51 +000093 llvm_unreachable("Invalid form for specified DWARF version");
94 }
95#endif
Chris Lattner3a383cb2010-04-05 00:13:49 +000096 AP->EmitULEB128(AttrData.getForm(),
Mehdi Amini149f6ea2016-10-05 05:59:29 +000097 dwarf::FormEncodingString(AttrData.getForm()).data());
Victor Leschukcbddae72017-01-10 21:18:26 +000098
99 // Emit value for DW_FORM_implicit_const.
Paul Robinson70b34532017-04-20 19:16:51 +0000100 if (AttrData.getForm() == dwarf::DW_FORM_implicit_const)
Victor Leschukcbddae72017-01-10 21:18:26 +0000101 AP->EmitSLEB128(AttrData.getValue());
Bill Wendling47054f32009-05-15 00:11:17 +0000102 }
103
104 // Mark end of abbreviation.
Chris Lattner3a383cb2010-04-05 00:13:49 +0000105 AP->EmitULEB128(0, "EOM(1)");
106 AP->EmitULEB128(0, "EOM(2)");
Bill Wendling47054f32009-05-15 00:11:17 +0000107}
108
Davide Italianoc304a0d2015-11-24 02:21:43 +0000109LLVM_DUMP_METHOD
Sam Clegg705f7982017-06-21 22:19:17 +0000110void DIEAbbrev::print(raw_ostream &O) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000111 O << "Abbreviation @"
Chris Lattner74725712009-08-23 01:01:17 +0000112 << format("0x%lx", (long)(intptr_t)this)
Bill Wendling47054f32009-05-15 00:11:17 +0000113 << " "
114 << dwarf::TagString(Tag)
115 << " "
Eric Christophere8f10722014-03-05 01:44:58 +0000116 << dwarf::ChildrenString(Children)
Chris Lattner74725712009-08-23 01:01:17 +0000117 << '\n';
Bill Wendling47054f32009-05-15 00:11:17 +0000118
119 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
120 O << " "
121 << dwarf::AttributeString(Data[i].getAttribute())
122 << " "
Victor Leschukd7bfa402017-03-01 22:13:42 +0000123 << dwarf::FormEncodingString(Data[i].getForm());
124
125 if (Data[i].getForm() == dwarf::DW_FORM_implicit_const)
126 O << " " << Data[i].getValue();
127
128 O << '\n';
Bill Wendling47054f32009-05-15 00:11:17 +0000129 }
130}
Davide Italianoc304a0d2015-11-24 02:21:43 +0000131
Aaron Ballman615eb472017-10-15 14:32:27 +0000132#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Sam Clegg705f7982017-06-21 22:19:17 +0000133LLVM_DUMP_METHOD void DIEAbbrev::dump() const {
Matthias Braun8c209aa2017-01-28 02:02:38 +0000134 print(dbgs());
135}
136#endif
Bill Wendling47054f32009-05-15 00:11:17 +0000137
Greg Clayton3462a422016-12-08 01:03:48 +0000138//===----------------------------------------------------------------------===//
139// DIEAbbrevSet Implementation
140//===----------------------------------------------------------------------===//
141
142DIEAbbrevSet::~DIEAbbrevSet() {
143 for (DIEAbbrev *Abbrev : Abbreviations)
144 Abbrev->~DIEAbbrev();
145}
146
147DIEAbbrev &DIEAbbrevSet::uniqueAbbreviation(DIE &Die) {
148
149 FoldingSetNodeID ID;
150 DIEAbbrev Abbrev = Die.generateAbbrev();
151 Abbrev.Profile(ID);
152
153 void *InsertPos;
154 if (DIEAbbrev *Existing =
155 AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
156 Die.setAbbrevNumber(Existing->getNumber());
157 return *Existing;
158 }
159
160 // Move the abbreviation to the heap and assign a number.
161 DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
162 Abbreviations.push_back(New);
163 New->setNumber(Abbreviations.size());
164 Die.setAbbrevNumber(Abbreviations.size());
165
166 // Store it for lookup.
167 AbbreviationsSet.InsertNode(New, InsertPos);
168 return *New;
169}
170
171void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const {
172 if (!Abbreviations.empty()) {
173 // Start the debug abbrev section.
174 AP->OutStreamer->SwitchSection(Section);
175 AP->emitDwarfAbbrevs(Abbreviations);
176 }
177}
178
179//===----------------------------------------------------------------------===//
180// DIE Implementation
181//===----------------------------------------------------------------------===//
182
Greg Clayton35630c32016-12-01 18:56:29 +0000183DIE *DIE::getParent() const {
184 return Owner.dyn_cast<DIE*>();
185}
186
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +0000187DIEAbbrev DIE::generateAbbrev() const {
188 DIEAbbrev Abbrev(Tag, hasChildren());
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000189 for (const DIEValue &V : values())
Victor Leschukcbddae72017-01-10 21:18:26 +0000190 if (V.getForm() == dwarf::DW_FORM_implicit_const)
191 Abbrev.AddImplicitConstAttribute(V.getAttribute(),
192 V.getDIEInteger().getValue());
193 else
194 Abbrev.AddAttribute(V.getAttribute(), V.getForm());
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +0000195 return Abbrev;
196}
197
Greg Clayton35630c32016-12-01 18:56:29 +0000198unsigned DIE::getDebugSectionOffset() const {
199 const DIEUnit *Unit = getUnit();
200 assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
Benjamin Kramer6a8704c2016-12-01 19:10:10 +0000201 return Unit->getDebugSectionOffset() + getOffset();
Manman Ren4dbdc902013-10-31 17:54:35 +0000202}
203
Greg Clayton35630c32016-12-01 18:56:29 +0000204const DIE *DIE::getUnitDie() const {
Manman Rence20d462013-10-29 22:57:10 +0000205 const DIE *p = this;
206 while (p) {
David Blaikie409dd9c2013-11-19 23:08:21 +0000207 if (p->getTag() == dwarf::DW_TAG_compile_unit ||
208 p->getTag() == dwarf::DW_TAG_type_unit)
Manman Rence20d462013-10-29 22:57:10 +0000209 return p;
210 p = p->getParent();
211 }
Craig Topper353eda42014-04-24 06:44:33 +0000212 return nullptr;
Manman Rence20d462013-10-29 22:57:10 +0000213}
214
Greg Clayton35630c32016-12-01 18:56:29 +0000215const DIEUnit *DIE::getUnit() const {
216 const DIE *UnitDie = getUnitDie();
217 if (UnitDie)
218 return UnitDie->Owner.dyn_cast<DIEUnit*>();
219 return nullptr;
220}
221
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000222DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const {
Eric Christopher8552e222013-08-07 01:18:33 +0000223 // Iterate through all the attributes until we find the one we're
224 // looking for, if we can't find it return NULL.
Duncan P. N. Exon Smith88a8fc52015-05-27 22:44:06 +0000225 for (const auto &V : values())
226 if (V.getAttribute() == Attribute)
227 return V;
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000228 return DIEValue();
Eric Christopher8552e222013-08-07 01:18:33 +0000229}
230
Davide Italianoc304a0d2015-11-24 02:21:43 +0000231LLVM_DUMP_METHOD
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000232static void printValues(raw_ostream &O, const DIEValueList &Values,
233 StringRef Type, unsigned Size, unsigned IndentCount) {
234 O << Type << ": Size: " << Size << "\n";
235
236 unsigned I = 0;
237 const std::string Indent(IndentCount, ' ');
238 for (const auto &V : Values.values()) {
239 O << Indent;
240 O << "Blk[" << I++ << "]";
241 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
242 V.print(O);
243 O << "\n";
244 }
245}
246
Davide Italianoc304a0d2015-11-24 02:21:43 +0000247LLVM_DUMP_METHOD
Eric Christopher6c6de842013-05-06 17:50:50 +0000248void DIE::print(raw_ostream &O, unsigned IndentCount) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000249 const std::string Indent(IndentCount, ' ');
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000250 O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this)
251 << ", Offset: " << Offset << ", Size: " << Size << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000252
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000253 O << Indent << dwarf::TagString(getTag()) << " "
254 << dwarf::ChildrenString(hasChildren()) << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000255
Bill Wendling47054f32009-05-15 00:11:17 +0000256 IndentCount += 2;
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000257 for (const auto &V : values()) {
Bill Wendling47054f32009-05-15 00:11:17 +0000258 O << Indent;
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000259 O << dwarf::AttributeString(V.getAttribute());
Duncan P. N. Exon Smith4fb1f9c2015-06-25 23:46:41 +0000260 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
261 V.print(O);
Bill Wendling47054f32009-05-15 00:11:17 +0000262 O << "\n";
263 }
264 IndentCount -= 2;
265
Duncan P. N. Exon Smith827200c2015-06-25 23:52:10 +0000266 for (const auto &Child : children())
267 Child.print(O, IndentCount + 4);
Bill Wendling47054f32009-05-15 00:11:17 +0000268
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000269 O << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000270}
271
Aaron Ballman615eb472017-10-15 14:32:27 +0000272#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Sam Clegg705f7982017-06-21 22:19:17 +0000273LLVM_DUMP_METHOD void DIE::dump() const {
David Greene8bc072c2009-12-24 00:27:55 +0000274 print(dbgs());
Bill Wendling47054f32009-05-15 00:11:17 +0000275}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000276#endif
Bill Wendling47054f32009-05-15 00:11:17 +0000277
Greg Clayton3462a422016-12-08 01:03:48 +0000278unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP,
279 DIEAbbrevSet &AbbrevSet,
280 unsigned CUOffset) {
281 // Unique the abbreviation and fill in the abbreviation number so this DIE
282 // can be emitted.
283 const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
284
285 // Set compile/type unit relative offset of this DIE.
286 setOffset(CUOffset);
287
288 // Add the byte size of the abbreviation code.
289 CUOffset += getULEB128Size(getAbbrevNumber());
290
291 // Add the byte size of all the DIE attribute values.
292 for (const auto &V : values())
293 CUOffset += V.SizeOf(AP);
294
295 // Let the children compute their offsets and abbreviation numbers.
296 if (hasChildren()) {
297 (void)Abbrev;
298 assert(Abbrev.hasChildren() && "Children flag not set");
299
300 for (auto &Child : children())
301 CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
302
303 // Each child chain is terminated with a zero byte, adjust the offset.
304 CUOffset += sizeof(int8_t);
305 }
306
307 // Compute the byte size of this DIE and all of its children correctly. This
308 // is needed so that top level DIE can help the compile unit set its length
309 // correctly.
310 setSize(CUOffset - getOffset());
311 return CUOffset;
312}
313
314//===----------------------------------------------------------------------===//
315// DIEUnit Implementation
316//===----------------------------------------------------------------------===//
Greg Clayton35630c32016-12-01 18:56:29 +0000317DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag)
318 : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V),
319 AddrSize(A)
320{
David Blaikiee40caae2016-12-01 21:59:09 +0000321 Die.Owner = this;
Greg Clayton35630c32016-12-01 18:56:29 +0000322 assert((UnitTag == dwarf::DW_TAG_compile_unit ||
323 UnitTag == dwarf::DW_TAG_type_unit ||
324 UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG");
325}
326
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000327void DIEValue::EmitValue(const AsmPrinter *AP) const {
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000328 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000329 case isNone:
330 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000331#define HANDLE_DIEVALUE(T) \
332 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000333 getDIE##T().EmitValue(AP, Form); \
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000334 break;
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000335#include "llvm/CodeGen/DIEValue.def"
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000336 }
337}
338
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000339unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000340 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000341 case isNone:
342 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000343#define HANDLE_DIEVALUE(T) \
344 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000345 return getDIE##T().SizeOf(AP, Form);
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000346#include "llvm/CodeGen/DIEValue.def"
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000347 }
Aaron Ballmanc681c3d2015-05-23 14:46:49 +0000348 llvm_unreachable("Unknown DIE kind");
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000349}
Bill Wendling47054f32009-05-15 00:11:17 +0000350
Davide Italianoc304a0d2015-11-24 02:21:43 +0000351LLVM_DUMP_METHOD
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000352void DIEValue::print(raw_ostream &O) const {
353 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000354 case isNone:
355 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000356#define HANDLE_DIEVALUE(T) \
357 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000358 getDIE##T().print(O); \
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000359 break;
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000360#include "llvm/CodeGen/DIEValue.def"
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000361 }
362}
363
Aaron Ballman615eb472017-10-15 14:32:27 +0000364#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Matthias Braun8c209aa2017-01-28 02:02:38 +0000365LLVM_DUMP_METHOD void DIEValue::dump() const {
David Greene8bc072c2009-12-24 00:27:55 +0000366 print(dbgs());
Bill Wendling47054f32009-05-15 00:11:17 +0000367}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000368#endif
Bill Wendling47054f32009-05-15 00:11:17 +0000369
370//===----------------------------------------------------------------------===//
371// DIEInteger Implementation
372//===----------------------------------------------------------------------===//
373
374/// EmitValue - Emit integer of appropriate size.
375///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000376void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000377 switch (Form) {
Victor Leschukcbddae72017-01-10 21:18:26 +0000378 case dwarf::DW_FORM_implicit_const:
Eric Christopherbb69a272012-08-24 01:14:27 +0000379 case dwarf::DW_FORM_flag_present:
380 // Emit something to keep the lines and comments in sync.
381 // FIXME: Is there a better way to do this?
Lang Hames9ff69c82015-04-24 19:11:51 +0000382 Asm->OutStreamer->AddBlankLine();
Eric Christopherbb69a272012-08-24 01:14:27 +0000383 return;
Greg Clayton3462a422016-12-08 01:03:48 +0000384 case dwarf::DW_FORM_flag:
Greg Clayton3462a422016-12-08 01:03:48 +0000385 case dwarf::DW_FORM_ref1:
Greg Clayton3462a422016-12-08 01:03:48 +0000386 case dwarf::DW_FORM_data1:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000387 case dwarf::DW_FORM_strx1:
388 case dwarf::DW_FORM_addrx1:
Greg Clayton3462a422016-12-08 01:03:48 +0000389 case dwarf::DW_FORM_ref2:
Greg Clayton3462a422016-12-08 01:03:48 +0000390 case dwarf::DW_FORM_data2:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000391 case dwarf::DW_FORM_strx2:
392 case dwarf::DW_FORM_addrx2:
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000393 case dwarf::DW_FORM_strx3:
Greg Clayton3462a422016-12-08 01:03:48 +0000394 case dwarf::DW_FORM_strp:
Greg Clayton3462a422016-12-08 01:03:48 +0000395 case dwarf::DW_FORM_ref4:
Greg Clayton3462a422016-12-08 01:03:48 +0000396 case dwarf::DW_FORM_data4:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000397 case dwarf::DW_FORM_ref_sup4:
398 case dwarf::DW_FORM_strx4:
399 case dwarf::DW_FORM_addrx4:
Greg Clayton3462a422016-12-08 01:03:48 +0000400 case dwarf::DW_FORM_ref8:
Greg Clayton3462a422016-12-08 01:03:48 +0000401 case dwarf::DW_FORM_ref_sig8:
Greg Clayton3462a422016-12-08 01:03:48 +0000402 case dwarf::DW_FORM_data8:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000403 case dwarf::DW_FORM_ref_sup8:
Greg Clayton3462a422016-12-08 01:03:48 +0000404 case dwarf::DW_FORM_GNU_ref_alt:
Greg Clayton3462a422016-12-08 01:03:48 +0000405 case dwarf::DW_FORM_GNU_strp_alt:
Greg Clayton3462a422016-12-08 01:03:48 +0000406 case dwarf::DW_FORM_line_strp:
Greg Clayton3462a422016-12-08 01:03:48 +0000407 case dwarf::DW_FORM_sec_offset:
Greg Clayton3462a422016-12-08 01:03:48 +0000408 case dwarf::DW_FORM_strp_sup:
Eric Christophere8a7b1b2012-09-10 23:34:03 +0000409 case dwarf::DW_FORM_addr:
Frederic Rissee17fb9b2015-03-04 22:07:36 +0000410 case dwarf::DW_FORM_ref_addr:
Greg Clayton3462a422016-12-08 01:03:48 +0000411 Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form));
412 return;
413 case dwarf::DW_FORM_GNU_str_index:
Greg Clayton3462a422016-12-08 01:03:48 +0000414 case dwarf::DW_FORM_GNU_addr_index:
Greg Clayton3462a422016-12-08 01:03:48 +0000415 case dwarf::DW_FORM_ref_udata:
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000416 case dwarf::DW_FORM_strx:
David Blaikie161dd3c2018-10-20 06:02:15 +0000417 case dwarf::DW_FORM_addrx:
David Blaikiec4af8bf2018-10-20 07:36:39 +0000418 case dwarf::DW_FORM_rnglistx:
Greg Clayton3462a422016-12-08 01:03:48 +0000419 case dwarf::DW_FORM_udata:
420 Asm->EmitULEB128(Integer);
421 return;
422 case dwarf::DW_FORM_sdata:
423 Asm->EmitSLEB128(Integer);
424 return;
Torok Edwinfbcc6632009-07-14 16:55:14 +0000425 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling47054f32009-05-15 00:11:17 +0000426 }
427}
428
429/// SizeOf - Determine size of integer value in bytes.
430///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000431unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Pavel Labath8ed6582b2018-03-14 11:31:17 +0000432 dwarf::FormParams Params = {0, 0, dwarf::DWARF32};
Pavel Labath322711f2018-03-14 09:39:54 +0000433 if (AP)
434 Params = {AP->getDwarfVersion(), uint8_t(AP->getPointerSize()),
435 AP->OutStreamer->getContext().getDwarfFormat()};
436
437 if (Optional<uint8_t> FixedSize = dwarf::getFixedFormByteSize(Form, Params))
438 return *FixedSize;
439
Bill Wendling47054f32009-05-15 00:11:17 +0000440 switch (Form) {
Greg Clayton3462a422016-12-08 01:03:48 +0000441 case dwarf::DW_FORM_GNU_str_index:
Greg Clayton3462a422016-12-08 01:03:48 +0000442 case dwarf::DW_FORM_GNU_addr_index:
Greg Clayton3462a422016-12-08 01:03:48 +0000443 case dwarf::DW_FORM_ref_udata:
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000444 case dwarf::DW_FORM_strx:
David Blaikie161dd3c2018-10-20 06:02:15 +0000445 case dwarf::DW_FORM_addrx:
David Blaikiec4af8bf2018-10-20 07:36:39 +0000446 case dwarf::DW_FORM_rnglistx:
Greg Clayton3462a422016-12-08 01:03:48 +0000447 case dwarf::DW_FORM_udata:
448 return getULEB128Size(Integer);
449 case dwarf::DW_FORM_sdata:
450 return getSLEB128Size(Integer);
David Blaikie46a9f012012-01-20 21:51:11 +0000451 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling47054f32009-05-15 00:11:17 +0000452 }
Bill Wendling47054f32009-05-15 00:11:17 +0000453}
454
Davide Italianoc304a0d2015-11-24 02:21:43 +0000455LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000456void DIEInteger::print(raw_ostream &O) const {
Benjamin Kramerf3da5292011-11-05 08:57:40 +0000457 O << "Int: " << (int64_t)Integer << " 0x";
458 O.write_hex(Integer);
Bill Wendling47054f32009-05-15 00:11:17 +0000459}
Bill Wendling47054f32009-05-15 00:11:17 +0000460
461//===----------------------------------------------------------------------===//
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000462// DIEExpr Implementation
463//===----------------------------------------------------------------------===//
464
465/// EmitValue - Emit expression value.
466///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000467void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Simon Atanasyanaf860d42018-11-28 11:48:07 +0000468 AP->EmitDebugValue(Expr, SizeOf(AP, Form));
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000469}
470
471/// SizeOf - Determine size of expression value in bytes.
472///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000473unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000474 if (Form == dwarf::DW_FORM_data4) return 4;
475 if (Form == dwarf::DW_FORM_sec_offset) return 4;
476 if (Form == dwarf::DW_FORM_strp) return 4;
Mehdi Amini1660cab2015-07-16 05:59:25 +0000477 return AP->getPointerSize();
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000478}
479
Davide Italianoc304a0d2015-11-24 02:21:43 +0000480LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000481void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000482
483//===----------------------------------------------------------------------===//
Chris Lattner8dcf41e2010-03-08 22:31:46 +0000484// DIELabel Implementation
Bill Wendling47054f32009-05-15 00:11:17 +0000485//===----------------------------------------------------------------------===//
486
487/// EmitValue - Emit label value.
488///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000489void DIELabel::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
David Blaikief2443192013-10-21 17:28:37 +0000490 AP->EmitLabelReference(Label, SizeOf(AP, Form),
491 Form == dwarf::DW_FORM_strp ||
492 Form == dwarf::DW_FORM_sec_offset ||
Keno Fischerf7d84ee2017-01-02 03:00:19 +0000493 Form == dwarf::DW_FORM_ref_addr ||
494 Form == dwarf::DW_FORM_data4);
Bill Wendling47054f32009-05-15 00:11:17 +0000495}
496
497/// SizeOf - Determine size of label value in bytes.
498///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000499unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000500 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher4c7765f2013-01-17 03:00:04 +0000501 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewyckyd59c0ca2011-10-27 06:44:11 +0000502 if (Form == dwarf::DW_FORM_strp) return 4;
Konstantin Zhuravlyovdc77b2e2017-04-17 17:41:25 +0000503 return AP->MAI->getCodePointerSize();
Bill Wendling47054f32009-05-15 00:11:17 +0000504}
505
Davide Italianoc304a0d2015-11-24 02:21:43 +0000506LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000507void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
Bill Wendling47054f32009-05-15 00:11:17 +0000508
509//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000510// DIEDelta Implementation
511//===----------------------------------------------------------------------===//
512
513/// EmitValue - Emit delta value.
514///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000515void DIEDelta::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Chris Lattner5a00dea2010-04-05 00:18:22 +0000516 AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
Bill Wendling47054f32009-05-15 00:11:17 +0000517}
518
519/// SizeOf - Determine size of delta value in bytes.
520///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000521unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000522 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher33ff6972013-11-21 23:46:41 +0000523 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewyckyd59c0ca2011-10-27 06:44:11 +0000524 if (Form == dwarf::DW_FORM_strp) return 4;
Konstantin Zhuravlyovdc77b2e2017-04-17 17:41:25 +0000525 return AP->MAI->getCodePointerSize();
Bill Wendling47054f32009-05-15 00:11:17 +0000526}
527
Davide Italianoc304a0d2015-11-24 02:21:43 +0000528LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000529void DIEDelta::print(raw_ostream &O) const {
Chris Lattnerbc9210c2010-03-08 22:23:36 +0000530 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
Bill Wendling47054f32009-05-15 00:11:17 +0000531}
Bill Wendling47054f32009-05-15 00:11:17 +0000532
533//===----------------------------------------------------------------------===//
Eric Christopher67646432013-07-26 17:02:41 +0000534// DIEString Implementation
535//===----------------------------------------------------------------------===//
536
537/// EmitValue - Emit string value.
538///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000539void DIEString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000540 // Index of string in symbol table.
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000541 switch (Form) {
542 case dwarf::DW_FORM_GNU_str_index:
543 case dwarf::DW_FORM_strx:
544 case dwarf::DW_FORM_strx1:
545 case dwarf::DW_FORM_strx2:
546 case dwarf::DW_FORM_strx3:
547 case dwarf::DW_FORM_strx4:
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000548 DIEInteger(S.getIndex()).EmitValue(AP, Form);
549 return;
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000550 case dwarf::DW_FORM_strp:
551 if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
552 DIELabel(S.getSymbol()).EmitValue(AP, Form);
553 else
554 DIEInteger(S.getOffset()).EmitValue(AP, Form);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000555 return;
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000556 default:
557 llvm_unreachable("Expected valid string form");
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000558 }
Eric Christopher67646432013-07-26 17:02:41 +0000559}
560
561/// SizeOf - Determine size of delta value in bytes.
562///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000563unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000564 // Index of string in symbol table.
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000565 switch (Form) {
566 case dwarf::DW_FORM_GNU_str_index:
567 case dwarf::DW_FORM_strx:
568 case dwarf::DW_FORM_strx1:
569 case dwarf::DW_FORM_strx2:
570 case dwarf::DW_FORM_strx3:
571 case dwarf::DW_FORM_strx4:
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000572 return DIEInteger(S.getIndex()).SizeOf(AP, Form);
Wolfgang Pieb456b5552018-01-26 18:52:58 +0000573 case dwarf::DW_FORM_strp:
574 if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
575 return DIELabel(S.getSymbol()).SizeOf(AP, Form);
576 return DIEInteger(S.getOffset()).SizeOf(AP, Form);
577 default:
578 llvm_unreachable("Expected valid string form");
579 }
Eric Christopher67646432013-07-26 17:02:41 +0000580}
581
Davide Italianoc304a0d2015-11-24 02:21:43 +0000582LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000583void DIEString::print(raw_ostream &O) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000584 O << "String: " << S.getString();
Eric Christopher67646432013-07-26 17:02:41 +0000585}
Eric Christopher67646432013-07-26 17:02:41 +0000586
587//===----------------------------------------------------------------------===//
Greg Clayton3462a422016-12-08 01:03:48 +0000588// DIEInlineString Implementation
589//===----------------------------------------------------------------------===//
590void DIEInlineString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
591 if (Form == dwarf::DW_FORM_string) {
Alexey Bataevc15c8532018-10-24 14:04:00 +0000592 AP->OutStreamer->EmitBytes(S);
Rafael Espindola4b4d85f2018-03-29 23:32:54 +0000593 AP->emitInt8(0);
Greg Clayton3462a422016-12-08 01:03:48 +0000594 return;
595 }
596 llvm_unreachable("Expected valid string form");
597}
598
599unsigned DIEInlineString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
600 // Emit string bytes + NULL byte.
601 return S.size() + 1;
602}
603
604LLVM_DUMP_METHOD
605void DIEInlineString::print(raw_ostream &O) const {
Benjamin Kramereedc4052016-12-09 13:33:41 +0000606 O << "InlineString: " << S;
Greg Clayton3462a422016-12-08 01:03:48 +0000607}
608
609//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000610// DIEEntry Implementation
611//===----------------------------------------------------------------------===//
612
613/// EmitValue - Emit debug information entry offset.
614///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000615void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopherdd508382014-03-06 00:00:56 +0000616
Greg Clayton3462a422016-12-08 01:03:48 +0000617 switch (Form) {
618 case dwarf::DW_FORM_ref1:
619 case dwarf::DW_FORM_ref2:
620 case dwarf::DW_FORM_ref4:
621 case dwarf::DW_FORM_ref8:
622 AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
623 return;
624
625 case dwarf::DW_FORM_ref_udata:
626 AP->EmitULEB128(Entry->getOffset());
627 return;
628
629 case dwarf::DW_FORM_ref_addr: {
Greg Clayton35630c32016-12-01 18:56:29 +0000630 // Get the absolute offset for this DIE within the debug info/types section.
631 unsigned Addr = Entry->getDebugSectionOffset();
David Blaikie85366ac2017-04-22 07:53:44 +0000632 if (const MCSymbol *SectionSym =
633 Entry->getUnit()->getCrossSectionRelativeBaseAddress()) {
634 AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
635 return;
Greg Clayton3462a422016-12-08 01:03:48 +0000636 }
David Blaikie85366ac2017-04-22 07:53:44 +0000637
Greg Clayton3462a422016-12-08 01:03:48 +0000638 AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
639 return;
640 }
641 default:
642 llvm_unreachable("Improper form for DIE reference");
643 }
Bill Wendling47054f32009-05-15 00:11:17 +0000644}
645
Greg Clayton3462a422016-12-08 01:03:48 +0000646unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
647 switch (Form) {
648 case dwarf::DW_FORM_ref1:
649 return 1;
650 case dwarf::DW_FORM_ref2:
651 return 2;
652 case dwarf::DW_FORM_ref4:
653 return 4;
654 case dwarf::DW_FORM_ref8:
655 return 8;
656 case dwarf::DW_FORM_ref_udata:
657 return getULEB128Size(Entry->getOffset());
658 case dwarf::DW_FORM_ref_addr:
659 if (AP->getDwarfVersion() == 2)
Konstantin Zhuravlyovdc77b2e2017-04-17 17:41:25 +0000660 return AP->MAI->getCodePointerSize();
Greg Clayton3462a422016-12-08 01:03:48 +0000661 switch (AP->OutStreamer->getContext().getDwarfFormat()) {
662 case dwarf::DWARF32:
663 return 4;
664 case dwarf::DWARF64:
665 return 8;
666 }
667 llvm_unreachable("Invalid DWARF format");
668
669 default:
670 llvm_unreachable("Improper form for DIE reference");
671 }
Manman Renac8062b2013-07-02 23:40:10 +0000672}
673
Davide Italianoc304a0d2015-11-24 02:21:43 +0000674LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000675void DIEEntry::print(raw_ostream &O) const {
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000676 O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
Bill Wendling47054f32009-05-15 00:11:17 +0000677}
Bill Wendling47054f32009-05-15 00:11:17 +0000678
679//===----------------------------------------------------------------------===//
Eric Christopher4a741042014-02-16 08:46:55 +0000680// DIELoc Implementation
681//===----------------------------------------------------------------------===//
682
683/// ComputeSize - calculate the size of the location expression.
684///
Frederic Risscd044342015-03-04 02:30:08 +0000685unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
Eric Christopher8bdab432014-02-27 18:36:10 +0000686 if (!Size) {
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000687 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000688 Size += V.SizeOf(AP);
Eric Christopher8bdab432014-02-27 18:36:10 +0000689 }
Eric Christopher4a741042014-02-16 08:46:55 +0000690
Eric Christopher8bdab432014-02-27 18:36:10 +0000691 return Size;
Eric Christopher4a741042014-02-16 08:46:55 +0000692}
693
694/// EmitValue - Emit location data.
695///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000696void DIELoc::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Eric Christopher4a741042014-02-16 08:46:55 +0000697 switch (Form) {
698 default: llvm_unreachable("Improper form for block");
Rafael Espindola4b4d85f2018-03-29 23:32:54 +0000699 case dwarf::DW_FORM_block1: Asm->emitInt8(Size); break;
700 case dwarf::DW_FORM_block2: Asm->emitInt16(Size); break;
701 case dwarf::DW_FORM_block4: Asm->emitInt32(Size); break;
Eric Christopher4a741042014-02-16 08:46:55 +0000702 case dwarf::DW_FORM_block:
703 case dwarf::DW_FORM_exprloc:
704 Asm->EmitULEB128(Size); break;
705 }
706
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000707 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000708 V.EmitValue(Asm);
Eric Christopher4a741042014-02-16 08:46:55 +0000709}
710
711/// SizeOf - Determine size of location data in bytes.
712///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000713unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopher4a741042014-02-16 08:46:55 +0000714 switch (Form) {
715 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
716 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
717 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
718 case dwarf::DW_FORM_block:
719 case dwarf::DW_FORM_exprloc:
Logan Chien5b776b72014-02-22 14:00:39 +0000720 return Size + getULEB128Size(Size);
Eric Christopher4a741042014-02-16 08:46:55 +0000721 default: llvm_unreachable("Improper form for block");
722 }
723}
724
Davide Italianoc304a0d2015-11-24 02:21:43 +0000725LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000726void DIELoc::print(raw_ostream &O) const {
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000727 printValues(O, *this, "ExprLoc", Size, 5);
Eric Christopher4a741042014-02-16 08:46:55 +0000728}
Eric Christopher4a741042014-02-16 08:46:55 +0000729
730//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000731// DIEBlock Implementation
732//===----------------------------------------------------------------------===//
733
734/// ComputeSize - calculate the size of the block.
735///
Frederic Risscd044342015-03-04 02:30:08 +0000736unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
Eric Christopher8bdab432014-02-27 18:36:10 +0000737 if (!Size) {
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000738 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000739 Size += V.SizeOf(AP);
Eric Christopher8bdab432014-02-27 18:36:10 +0000740 }
Bill Wendling47054f32009-05-15 00:11:17 +0000741
Eric Christopher8bdab432014-02-27 18:36:10 +0000742 return Size;
Bill Wendling47054f32009-05-15 00:11:17 +0000743}
744
745/// EmitValue - Emit block data.
746///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000747void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000748 switch (Form) {
Craig Topperee4dab52012-02-05 08:31:47 +0000749 default: llvm_unreachable("Improper form for block");
Rafael Espindola4b4d85f2018-03-29 23:32:54 +0000750 case dwarf::DW_FORM_block1: Asm->emitInt8(Size); break;
751 case dwarf::DW_FORM_block2: Asm->emitInt16(Size); break;
752 case dwarf::DW_FORM_block4: Asm->emitInt32(Size); break;
Chris Lattner9efd1182010-04-04 19:09:29 +0000753 case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
Jonas Devlieghere9e3e7a92018-04-02 10:40:43 +0000754 case dwarf::DW_FORM_string: break;
Paul Robinsona06f8dc2017-12-18 19:08:35 +0000755 case dwarf::DW_FORM_data16: break;
Bill Wendling47054f32009-05-15 00:11:17 +0000756 }
757
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000758 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000759 V.EmitValue(Asm);
Bill Wendling47054f32009-05-15 00:11:17 +0000760}
761
762/// SizeOf - Determine size of block data in bytes.
763///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000764unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000765 switch (Form) {
766 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
767 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
768 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
Logan Chien5b776b72014-02-22 14:00:39 +0000769 case dwarf::DW_FORM_block: return Size + getULEB128Size(Size);
Paul Robinsona06f8dc2017-12-18 19:08:35 +0000770 case dwarf::DW_FORM_data16: return 16;
David Blaikie46a9f012012-01-20 21:51:11 +0000771 default: llvm_unreachable("Improper form for block");
Bill Wendling47054f32009-05-15 00:11:17 +0000772 }
Bill Wendling47054f32009-05-15 00:11:17 +0000773}
774
Davide Italianoc304a0d2015-11-24 02:21:43 +0000775LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000776void DIEBlock::print(raw_ostream &O) const {
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000777 printValues(O, *this, "Blk", Size, 5);
Bill Wendling47054f32009-05-15 00:11:17 +0000778}
Eric Christophera27220f2014-03-05 22:41:20 +0000779
780//===----------------------------------------------------------------------===//
781// DIELocList Implementation
782//===----------------------------------------------------------------------===//
783
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000784unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christophera27220f2014-03-05 22:41:20 +0000785 if (Form == dwarf::DW_FORM_data4)
786 return 4;
787 if (Form == dwarf::DW_FORM_sec_offset)
788 return 4;
Konstantin Zhuravlyovdc77b2e2017-04-17 17:41:25 +0000789 return AP->MAI->getCodePointerSize();
Eric Christophera27220f2014-03-05 22:41:20 +0000790}
791
792/// EmitValue - Emit label value.
793///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000794void DIELocList::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
David Blaikie9c550ac2014-03-25 01:44:02 +0000795 DwarfDebug *DD = AP->getDwarfDebug();
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000796 MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
Rafael Espindola857546e2015-06-16 23:22:02 +0000797 AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
Eric Christophera27220f2014-03-05 22:41:20 +0000798}
799
Davide Italianoc304a0d2015-11-24 02:21:43 +0000800LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000801void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }