blob: bb008ec557fc8e2973114da366c5582bfb1a672f [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
34//===----------------------------------------------------------------------===//
35// DIEAbbrevData Implementation
36//===----------------------------------------------------------------------===//
37
38/// Profile - Used to gather unique data for the abbreviation folding set.
39///
40void DIEAbbrevData::Profile(FoldingSetNodeID &ID) const {
Reid Klecknerad65f102013-10-21 19:18:31 +000041 // Explicitly cast to an integer type for which FoldingSetNodeID has
42 // overloads. Otherwise MSVC 2010 thinks this call is ambiguous.
43 ID.AddInteger(unsigned(Attribute));
44 ID.AddInteger(unsigned(Form));
Bill Wendling47054f32009-05-15 00:11:17 +000045}
46
47//===----------------------------------------------------------------------===//
48// DIEAbbrev Implementation
49//===----------------------------------------------------------------------===//
50
51/// Profile - Used to gather unique data for the abbreviation folding set.
52///
53void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
Reid Klecknerad65f102013-10-21 19:18:31 +000054 ID.AddInteger(unsigned(Tag));
Eric Christophere8f10722014-03-05 01:44:58 +000055 ID.AddInteger(unsigned(Children));
Bill Wendling47054f32009-05-15 00:11:17 +000056
57 // For each attribute description.
58 for (unsigned i = 0, N = Data.size(); i < N; ++i)
59 Data[i].Profile(ID);
60}
61
62/// Emit - Print the abbreviation using the specified asm printer.
63///
Frederic Risscd044342015-03-04 02:30:08 +000064void DIEAbbrev::Emit(const AsmPrinter *AP) const {
Bill Wendling47054f32009-05-15 00:11:17 +000065 // Emit its Dwarf tag type.
Mehdi Amini149f6ea2016-10-05 05:59:29 +000066 AP->EmitULEB128(Tag, dwarf::TagString(Tag).data());
Bill Wendling47054f32009-05-15 00:11:17 +000067
68 // Emit whether it has children DIEs.
Mehdi Amini149f6ea2016-10-05 05:59:29 +000069 AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
Bill Wendling47054f32009-05-15 00:11:17 +000070
71 // For each attribute description.
72 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
73 const DIEAbbrevData &AttrData = Data[i];
74
75 // Emit attribute type.
Chris Lattner3a383cb2010-04-05 00:13:49 +000076 AP->EmitULEB128(AttrData.getAttribute(),
Mehdi Amini149f6ea2016-10-05 05:59:29 +000077 dwarf::AttributeString(AttrData.getAttribute()).data());
Bill Wendling47054f32009-05-15 00:11:17 +000078
79 // Emit form type.
Chris Lattner3a383cb2010-04-05 00:13:49 +000080 AP->EmitULEB128(AttrData.getForm(),
Mehdi Amini149f6ea2016-10-05 05:59:29 +000081 dwarf::FormEncodingString(AttrData.getForm()).data());
Victor Leschukcbddae72017-01-10 21:18:26 +000082
83 // Emit value for DW_FORM_implicit_const.
84 if (AttrData.getForm() == dwarf::DW_FORM_implicit_const) {
85 assert(AP->getDwarfVersion() >= 5 &&
86 "DW_FORM_implicit_const is supported starting from DWARFv5");
87 AP->EmitSLEB128(AttrData.getValue());
88 }
Bill Wendling47054f32009-05-15 00:11:17 +000089 }
90
91 // Mark end of abbreviation.
Chris Lattner3a383cb2010-04-05 00:13:49 +000092 AP->EmitULEB128(0, "EOM(1)");
93 AP->EmitULEB128(0, "EOM(2)");
Bill Wendling47054f32009-05-15 00:11:17 +000094}
95
Davide Italianoc304a0d2015-11-24 02:21:43 +000096LLVM_DUMP_METHOD
Chris Lattner74725712009-08-23 01:01:17 +000097void DIEAbbrev::print(raw_ostream &O) {
Bill Wendling47054f32009-05-15 00:11:17 +000098 O << "Abbreviation @"
Chris Lattner74725712009-08-23 01:01:17 +000099 << format("0x%lx", (long)(intptr_t)this)
Bill Wendling47054f32009-05-15 00:11:17 +0000100 << " "
101 << dwarf::TagString(Tag)
102 << " "
Eric Christophere8f10722014-03-05 01:44:58 +0000103 << dwarf::ChildrenString(Children)
Chris Lattner74725712009-08-23 01:01:17 +0000104 << '\n';
Bill Wendling47054f32009-05-15 00:11:17 +0000105
106 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
107 O << " "
108 << dwarf::AttributeString(Data[i].getAttribute())
109 << " "
110 << dwarf::FormEncodingString(Data[i].getForm())
Chris Lattner74725712009-08-23 01:01:17 +0000111 << '\n';
Bill Wendling47054f32009-05-15 00:11:17 +0000112 }
113}
Davide Italianoc304a0d2015-11-24 02:21:43 +0000114
Matthias Braun8c209aa2017-01-28 02:02:38 +0000115#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
116LLVM_DUMP_METHOD void DIEAbbrev::dump() {
117 print(dbgs());
118}
119#endif
Bill Wendling47054f32009-05-15 00:11:17 +0000120
Greg Clayton3462a422016-12-08 01:03:48 +0000121//===----------------------------------------------------------------------===//
122// DIEAbbrevSet Implementation
123//===----------------------------------------------------------------------===//
124
125DIEAbbrevSet::~DIEAbbrevSet() {
126 for (DIEAbbrev *Abbrev : Abbreviations)
127 Abbrev->~DIEAbbrev();
128}
129
130DIEAbbrev &DIEAbbrevSet::uniqueAbbreviation(DIE &Die) {
131
132 FoldingSetNodeID ID;
133 DIEAbbrev Abbrev = Die.generateAbbrev();
134 Abbrev.Profile(ID);
135
136 void *InsertPos;
137 if (DIEAbbrev *Existing =
138 AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
139 Die.setAbbrevNumber(Existing->getNumber());
140 return *Existing;
141 }
142
143 // Move the abbreviation to the heap and assign a number.
144 DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
145 Abbreviations.push_back(New);
146 New->setNumber(Abbreviations.size());
147 Die.setAbbrevNumber(Abbreviations.size());
148
149 // Store it for lookup.
150 AbbreviationsSet.InsertNode(New, InsertPos);
151 return *New;
152}
153
154void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const {
155 if (!Abbreviations.empty()) {
156 // Start the debug abbrev section.
157 AP->OutStreamer->SwitchSection(Section);
158 AP->emitDwarfAbbrevs(Abbreviations);
159 }
160}
161
162//===----------------------------------------------------------------------===//
163// DIE Implementation
164//===----------------------------------------------------------------------===//
165
Greg Clayton35630c32016-12-01 18:56:29 +0000166DIE *DIE::getParent() const {
167 return Owner.dyn_cast<DIE*>();
168}
169
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +0000170DIEAbbrev DIE::generateAbbrev() const {
171 DIEAbbrev Abbrev(Tag, hasChildren());
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000172 for (const DIEValue &V : values())
Victor Leschukcbddae72017-01-10 21:18:26 +0000173 if (V.getForm() == dwarf::DW_FORM_implicit_const)
174 Abbrev.AddImplicitConstAttribute(V.getAttribute(),
175 V.getDIEInteger().getValue());
176 else
177 Abbrev.AddAttribute(V.getAttribute(), V.getForm());
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +0000178 return Abbrev;
179}
180
Greg Clayton35630c32016-12-01 18:56:29 +0000181unsigned DIE::getDebugSectionOffset() const {
182 const DIEUnit *Unit = getUnit();
183 assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
Benjamin Kramer6a8704c2016-12-01 19:10:10 +0000184 return Unit->getDebugSectionOffset() + getOffset();
Manman Ren4dbdc902013-10-31 17:54:35 +0000185}
186
Greg Clayton35630c32016-12-01 18:56:29 +0000187const DIE *DIE::getUnitDie() const {
Manman Rence20d462013-10-29 22:57:10 +0000188 const DIE *p = this;
189 while (p) {
David Blaikie409dd9c2013-11-19 23:08:21 +0000190 if (p->getTag() == dwarf::DW_TAG_compile_unit ||
191 p->getTag() == dwarf::DW_TAG_type_unit)
Manman Rence20d462013-10-29 22:57:10 +0000192 return p;
193 p = p->getParent();
194 }
Craig Topper353eda42014-04-24 06:44:33 +0000195 return nullptr;
Manman Rence20d462013-10-29 22:57:10 +0000196}
197
Greg Clayton35630c32016-12-01 18:56:29 +0000198const DIEUnit *DIE::getUnit() const {
199 const DIE *UnitDie = getUnitDie();
200 if (UnitDie)
201 return UnitDie->Owner.dyn_cast<DIEUnit*>();
202 return nullptr;
203}
204
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000205DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const {
Eric Christopher8552e222013-08-07 01:18:33 +0000206 // Iterate through all the attributes until we find the one we're
207 // looking for, if we can't find it return NULL.
Duncan P. N. Exon Smith88a8fc52015-05-27 22:44:06 +0000208 for (const auto &V : values())
209 if (V.getAttribute() == Attribute)
210 return V;
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000211 return DIEValue();
Eric Christopher8552e222013-08-07 01:18:33 +0000212}
213
Davide Italianoc304a0d2015-11-24 02:21:43 +0000214LLVM_DUMP_METHOD
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000215static void printValues(raw_ostream &O, const DIEValueList &Values,
216 StringRef Type, unsigned Size, unsigned IndentCount) {
217 O << Type << ": Size: " << Size << "\n";
218
219 unsigned I = 0;
220 const std::string Indent(IndentCount, ' ');
221 for (const auto &V : Values.values()) {
222 O << Indent;
223 O << "Blk[" << I++ << "]";
224 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
225 V.print(O);
226 O << "\n";
227 }
228}
229
Davide Italianoc304a0d2015-11-24 02:21:43 +0000230LLVM_DUMP_METHOD
Eric Christopher6c6de842013-05-06 17:50:50 +0000231void DIE::print(raw_ostream &O, unsigned IndentCount) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000232 const std::string Indent(IndentCount, ' ');
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000233 O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this)
234 << ", Offset: " << Offset << ", Size: " << Size << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000235
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000236 O << Indent << dwarf::TagString(getTag()) << " "
237 << dwarf::ChildrenString(hasChildren()) << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000238
Bill Wendling47054f32009-05-15 00:11:17 +0000239 IndentCount += 2;
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000240 for (const auto &V : values()) {
Bill Wendling47054f32009-05-15 00:11:17 +0000241 O << Indent;
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000242 O << dwarf::AttributeString(V.getAttribute());
Duncan P. N. Exon Smith4fb1f9c2015-06-25 23:46:41 +0000243 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
244 V.print(O);
Bill Wendling47054f32009-05-15 00:11:17 +0000245 O << "\n";
246 }
247 IndentCount -= 2;
248
Duncan P. N. Exon Smith827200c2015-06-25 23:52:10 +0000249 for (const auto &Child : children())
250 Child.print(O, IndentCount + 4);
Bill Wendling47054f32009-05-15 00:11:17 +0000251
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000252 O << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000253}
254
Matthias Braun8c209aa2017-01-28 02:02:38 +0000255#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
256LLVM_DUMP_METHOD void DIE::dump() {
David Greene8bc072c2009-12-24 00:27:55 +0000257 print(dbgs());
Bill Wendling47054f32009-05-15 00:11:17 +0000258}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000259#endif
Bill Wendling47054f32009-05-15 00:11:17 +0000260
Greg Clayton3462a422016-12-08 01:03:48 +0000261unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP,
262 DIEAbbrevSet &AbbrevSet,
263 unsigned CUOffset) {
264 // Unique the abbreviation and fill in the abbreviation number so this DIE
265 // can be emitted.
266 const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
267
268 // Set compile/type unit relative offset of this DIE.
269 setOffset(CUOffset);
270
271 // Add the byte size of the abbreviation code.
272 CUOffset += getULEB128Size(getAbbrevNumber());
273
274 // Add the byte size of all the DIE attribute values.
275 for (const auto &V : values())
276 CUOffset += V.SizeOf(AP);
277
278 // Let the children compute their offsets and abbreviation numbers.
279 if (hasChildren()) {
280 (void)Abbrev;
281 assert(Abbrev.hasChildren() && "Children flag not set");
282
283 for (auto &Child : children())
284 CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
285
286 // Each child chain is terminated with a zero byte, adjust the offset.
287 CUOffset += sizeof(int8_t);
288 }
289
290 // Compute the byte size of this DIE and all of its children correctly. This
291 // is needed so that top level DIE can help the compile unit set its length
292 // correctly.
293 setSize(CUOffset - getOffset());
294 return CUOffset;
295}
296
297//===----------------------------------------------------------------------===//
298// DIEUnit Implementation
299//===----------------------------------------------------------------------===//
Greg Clayton35630c32016-12-01 18:56:29 +0000300DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag)
301 : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V),
302 AddrSize(A)
303{
David Blaikiee40caae2016-12-01 21:59:09 +0000304 Die.Owner = this;
Greg Clayton35630c32016-12-01 18:56:29 +0000305 assert((UnitTag == dwarf::DW_TAG_compile_unit ||
306 UnitTag == dwarf::DW_TAG_type_unit ||
307 UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG");
308}
309
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000310void DIEValue::EmitValue(const AsmPrinter *AP) const {
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000311 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000312 case isNone:
313 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000314#define HANDLE_DIEVALUE(T) \
315 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000316 getDIE##T().EmitValue(AP, Form); \
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000317 break;
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000318#include "llvm/CodeGen/DIEValue.def"
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000319 }
320}
321
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000322unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000323 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000324 case isNone:
325 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000326#define HANDLE_DIEVALUE(T) \
327 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000328 return getDIE##T().SizeOf(AP, Form);
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000329#include "llvm/CodeGen/DIEValue.def"
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000330 }
Aaron Ballmanc681c3d2015-05-23 14:46:49 +0000331 llvm_unreachable("Unknown DIE kind");
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000332}
Bill Wendling47054f32009-05-15 00:11:17 +0000333
Davide Italianoc304a0d2015-11-24 02:21:43 +0000334LLVM_DUMP_METHOD
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000335void DIEValue::print(raw_ostream &O) const {
336 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000337 case isNone:
338 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000339#define HANDLE_DIEVALUE(T) \
340 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000341 getDIE##T().print(O); \
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000342 break;
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000343#include "llvm/CodeGen/DIEValue.def"
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000344 }
345}
346
Matthias Braun8c209aa2017-01-28 02:02:38 +0000347#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
348LLVM_DUMP_METHOD void DIEValue::dump() const {
David Greene8bc072c2009-12-24 00:27:55 +0000349 print(dbgs());
Bill Wendling47054f32009-05-15 00:11:17 +0000350}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000351#endif
Bill Wendling47054f32009-05-15 00:11:17 +0000352
353//===----------------------------------------------------------------------===//
354// DIEInteger Implementation
355//===----------------------------------------------------------------------===//
356
357/// EmitValue - Emit integer of appropriate size.
358///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000359void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000360 switch (Form) {
Victor Leschukcbddae72017-01-10 21:18:26 +0000361 case dwarf::DW_FORM_implicit_const:
362 LLVM_FALLTHROUGH;
Eric Christopherbb69a272012-08-24 01:14:27 +0000363 case dwarf::DW_FORM_flag_present:
364 // Emit something to keep the lines and comments in sync.
365 // FIXME: Is there a better way to do this?
Lang Hames9ff69c82015-04-24 19:11:51 +0000366 Asm->OutStreamer->AddBlankLine();
Eric Christopherbb69a272012-08-24 01:14:27 +0000367 return;
Greg Clayton3462a422016-12-08 01:03:48 +0000368 case dwarf::DW_FORM_flag:
369 LLVM_FALLTHROUGH;
370 case dwarf::DW_FORM_ref1:
371 LLVM_FALLTHROUGH;
372 case dwarf::DW_FORM_data1:
373 LLVM_FALLTHROUGH;
374 case dwarf::DW_FORM_ref2:
375 LLVM_FALLTHROUGH;
376 case dwarf::DW_FORM_data2:
377 LLVM_FALLTHROUGH;
378 case dwarf::DW_FORM_strp:
379 LLVM_FALLTHROUGH;
380 case dwarf::DW_FORM_ref4:
381 LLVM_FALLTHROUGH;
382 case dwarf::DW_FORM_data4:
383 LLVM_FALLTHROUGH;
384 case dwarf::DW_FORM_ref8:
385 LLVM_FALLTHROUGH;
386 case dwarf::DW_FORM_ref_sig8:
387 LLVM_FALLTHROUGH;
388 case dwarf::DW_FORM_data8:
389 LLVM_FALLTHROUGH;
390 case dwarf::DW_FORM_GNU_ref_alt:
391 LLVM_FALLTHROUGH;
392 case dwarf::DW_FORM_GNU_strp_alt:
393 LLVM_FALLTHROUGH;
394 case dwarf::DW_FORM_line_strp:
395 LLVM_FALLTHROUGH;
396 case dwarf::DW_FORM_sec_offset:
397 LLVM_FALLTHROUGH;
398 case dwarf::DW_FORM_strp_sup:
399 LLVM_FALLTHROUGH;
400 case dwarf::DW_FORM_ref_sup:
401 LLVM_FALLTHROUGH;
Eric Christophere8a7b1b2012-09-10 23:34:03 +0000402 case dwarf::DW_FORM_addr:
Greg Clayton3462a422016-12-08 01:03:48 +0000403 LLVM_FALLTHROUGH;
Frederic Rissee17fb9b2015-03-04 22:07:36 +0000404 case dwarf::DW_FORM_ref_addr:
Greg Clayton3462a422016-12-08 01:03:48 +0000405 Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form));
406 return;
407 case dwarf::DW_FORM_GNU_str_index:
408 LLVM_FALLTHROUGH;
409 case dwarf::DW_FORM_GNU_addr_index:
410 LLVM_FALLTHROUGH;
411 case dwarf::DW_FORM_ref_udata:
412 LLVM_FALLTHROUGH;
413 case dwarf::DW_FORM_udata:
414 Asm->EmitULEB128(Integer);
415 return;
416 case dwarf::DW_FORM_sdata:
417 Asm->EmitSLEB128(Integer);
418 return;
Torok Edwinfbcc6632009-07-14 16:55:14 +0000419 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling47054f32009-05-15 00:11:17 +0000420 }
421}
422
423/// SizeOf - Determine size of integer value in bytes.
424///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000425unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000426 switch (Form) {
Victor Leschukcbddae72017-01-10 21:18:26 +0000427 case dwarf::DW_FORM_implicit_const: LLVM_FALLTHROUGH;
Eric Christopher2a4e6162012-08-29 17:59:32 +0000428 case dwarf::DW_FORM_flag_present: return 0;
Justin Bognercd1d5aa2016-08-17 20:30:52 +0000429 case dwarf::DW_FORM_flag: LLVM_FALLTHROUGH;
430 case dwarf::DW_FORM_ref1: LLVM_FALLTHROUGH;
Bill Wendling47054f32009-05-15 00:11:17 +0000431 case dwarf::DW_FORM_data1: return sizeof(int8_t);
Justin Bognercd1d5aa2016-08-17 20:30:52 +0000432 case dwarf::DW_FORM_ref2: LLVM_FALLTHROUGH;
Bill Wendling47054f32009-05-15 00:11:17 +0000433 case dwarf::DW_FORM_data2: return sizeof(int16_t);
Justin Bognercd1d5aa2016-08-17 20:30:52 +0000434 case dwarf::DW_FORM_ref4: LLVM_FALLTHROUGH;
Bill Wendling47054f32009-05-15 00:11:17 +0000435 case dwarf::DW_FORM_data4: return sizeof(int32_t);
Justin Bognercd1d5aa2016-08-17 20:30:52 +0000436 case dwarf::DW_FORM_ref8: LLVM_FALLTHROUGH;
437 case dwarf::DW_FORM_ref_sig8: LLVM_FALLTHROUGH;
Bill Wendling47054f32009-05-15 00:11:17 +0000438 case dwarf::DW_FORM_data8: return sizeof(int64_t);
Frederic Rissee17fb9b2015-03-04 22:07:36 +0000439 case dwarf::DW_FORM_ref_addr:
Greg Claytone6543972016-11-23 23:30:37 +0000440 if (AP->getDwarfVersion() == 2)
Mehdi Amini1660cab2015-07-16 05:59:25 +0000441 return AP->getPointerSize();
Greg Clayton3462a422016-12-08 01:03:48 +0000442 LLVM_FALLTHROUGH;
443 case dwarf::DW_FORM_strp:
444 LLVM_FALLTHROUGH;
445 case dwarf::DW_FORM_GNU_ref_alt:
446 LLVM_FALLTHROUGH;
447 case dwarf::DW_FORM_GNU_strp_alt:
448 LLVM_FALLTHROUGH;
449 case dwarf::DW_FORM_line_strp:
450 LLVM_FALLTHROUGH;
451 case dwarf::DW_FORM_sec_offset:
452 LLVM_FALLTHROUGH;
453 case dwarf::DW_FORM_strp_sup:
454 LLVM_FALLTHROUGH;
455 case dwarf::DW_FORM_ref_sup:
456 switch (AP->OutStreamer->getContext().getDwarfFormat()) {
457 case dwarf::DWARF32:
458 return 4;
459 case dwarf::DWARF64:
460 return 8;
461 }
462 llvm_unreachable("Invalid DWARF format");
463 case dwarf::DW_FORM_GNU_str_index:
464 LLVM_FALLTHROUGH;
465 case dwarf::DW_FORM_GNU_addr_index:
466 LLVM_FALLTHROUGH;
467 case dwarf::DW_FORM_ref_udata:
468 LLVM_FALLTHROUGH;
469 case dwarf::DW_FORM_udata:
470 return getULEB128Size(Integer);
471 case dwarf::DW_FORM_sdata:
472 return getSLEB128Size(Integer);
473 case dwarf::DW_FORM_addr:
474 return AP->getPointerSize();
David Blaikie46a9f012012-01-20 21:51:11 +0000475 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling47054f32009-05-15 00:11:17 +0000476 }
Bill Wendling47054f32009-05-15 00:11:17 +0000477}
478
Davide Italianoc304a0d2015-11-24 02:21:43 +0000479LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000480void DIEInteger::print(raw_ostream &O) const {
Benjamin Kramerf3da5292011-11-05 08:57:40 +0000481 O << "Int: " << (int64_t)Integer << " 0x";
482 O.write_hex(Integer);
Bill Wendling47054f32009-05-15 00:11:17 +0000483}
Bill Wendling47054f32009-05-15 00:11:17 +0000484
485//===----------------------------------------------------------------------===//
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000486// DIEExpr Implementation
487//===----------------------------------------------------------------------===//
488
489/// EmitValue - Emit expression value.
490///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000491void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Simon Dardis2e8cdbd2017-02-08 19:03:46 +0000492 AP->EmitDebugThreadLocal(Expr, SizeOf(AP, Form));
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000493}
494
495/// SizeOf - Determine size of expression value in bytes.
496///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000497unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000498 if (Form == dwarf::DW_FORM_data4) return 4;
499 if (Form == dwarf::DW_FORM_sec_offset) return 4;
500 if (Form == dwarf::DW_FORM_strp) return 4;
Mehdi Amini1660cab2015-07-16 05:59:25 +0000501 return AP->getPointerSize();
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000502}
503
Davide Italianoc304a0d2015-11-24 02:21:43 +0000504LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000505void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000506
507//===----------------------------------------------------------------------===//
Chris Lattner8dcf41e2010-03-08 22:31:46 +0000508// DIELabel Implementation
Bill Wendling47054f32009-05-15 00:11:17 +0000509//===----------------------------------------------------------------------===//
510
511/// EmitValue - Emit label value.
512///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000513void DIELabel::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
David Blaikief2443192013-10-21 17:28:37 +0000514 AP->EmitLabelReference(Label, SizeOf(AP, Form),
515 Form == dwarf::DW_FORM_strp ||
516 Form == dwarf::DW_FORM_sec_offset ||
Keno Fischerf7d84ee2017-01-02 03:00:19 +0000517 Form == dwarf::DW_FORM_ref_addr ||
518 Form == dwarf::DW_FORM_data4);
Bill Wendling47054f32009-05-15 00:11:17 +0000519}
520
521/// SizeOf - Determine size of label value in bytes.
522///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000523unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000524 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher4c7765f2013-01-17 03:00:04 +0000525 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewyckyd59c0ca2011-10-27 06:44:11 +0000526 if (Form == dwarf::DW_FORM_strp) return 4;
Mehdi Amini1660cab2015-07-16 05:59:25 +0000527 return AP->getPointerSize();
Bill Wendling47054f32009-05-15 00:11:17 +0000528}
529
Davide Italianoc304a0d2015-11-24 02:21:43 +0000530LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000531void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
Bill Wendling47054f32009-05-15 00:11:17 +0000532
533//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000534// DIEDelta Implementation
535//===----------------------------------------------------------------------===//
536
537/// EmitValue - Emit delta value.
538///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000539void DIEDelta::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Chris Lattner5a00dea2010-04-05 00:18:22 +0000540 AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
Bill Wendling47054f32009-05-15 00:11:17 +0000541}
542
543/// SizeOf - Determine size of delta value in bytes.
544///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000545unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000546 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher33ff6972013-11-21 23:46:41 +0000547 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewyckyd59c0ca2011-10-27 06:44:11 +0000548 if (Form == dwarf::DW_FORM_strp) return 4;
Mehdi Amini1660cab2015-07-16 05:59:25 +0000549 return AP->getPointerSize();
Bill Wendling47054f32009-05-15 00:11:17 +0000550}
551
Davide Italianoc304a0d2015-11-24 02:21:43 +0000552LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000553void DIEDelta::print(raw_ostream &O) const {
Chris Lattnerbc9210c2010-03-08 22:23:36 +0000554 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
Bill Wendling47054f32009-05-15 00:11:17 +0000555}
Bill Wendling47054f32009-05-15 00:11:17 +0000556
557//===----------------------------------------------------------------------===//
Eric Christopher67646432013-07-26 17:02:41 +0000558// DIEString Implementation
559//===----------------------------------------------------------------------===//
560
561/// EmitValue - Emit string value.
562///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000563void DIEString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000564 assert(
565 (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
566 "Expected valid string form");
567
568 // Index of string in symbol table.
569 if (Form == dwarf::DW_FORM_GNU_str_index) {
570 DIEInteger(S.getIndex()).EmitValue(AP, Form);
571 return;
572 }
573
574 // Relocatable symbol.
575 assert(Form == dwarf::DW_FORM_strp);
576 if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
577 DIELabel(S.getSymbol()).EmitValue(AP, Form);
578 return;
579 }
580
581 // Offset into symbol table.
582 DIEInteger(S.getOffset()).EmitValue(AP, Form);
Eric Christopher67646432013-07-26 17:02:41 +0000583}
584
585/// SizeOf - Determine size of delta value in bytes.
586///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000587unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000588 assert(
589 (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
590 "Expected valid string form");
591
592 // Index of string in symbol table.
593 if (Form == dwarf::DW_FORM_GNU_str_index)
594 return DIEInteger(S.getIndex()).SizeOf(AP, Form);
595
596 // Relocatable symbol.
597 if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
598 return DIELabel(S.getSymbol()).SizeOf(AP, Form);
599
600 // Offset into symbol table.
601 return DIEInteger(S.getOffset()).SizeOf(AP, Form);
Eric Christopher67646432013-07-26 17:02:41 +0000602}
603
Davide Italianoc304a0d2015-11-24 02:21:43 +0000604LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000605void DIEString::print(raw_ostream &O) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000606 O << "String: " << S.getString();
Eric Christopher67646432013-07-26 17:02:41 +0000607}
Eric Christopher67646432013-07-26 17:02:41 +0000608
609//===----------------------------------------------------------------------===//
Greg Clayton3462a422016-12-08 01:03:48 +0000610// DIEInlineString Implementation
611//===----------------------------------------------------------------------===//
612void DIEInlineString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
613 if (Form == dwarf::DW_FORM_string) {
614 for (char ch : S)
615 AP->EmitInt8(ch);
616 AP->EmitInt8(0);
617 return;
618 }
619 llvm_unreachable("Expected valid string form");
620}
621
622unsigned DIEInlineString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
623 // Emit string bytes + NULL byte.
624 return S.size() + 1;
625}
626
627LLVM_DUMP_METHOD
628void DIEInlineString::print(raw_ostream &O) const {
Benjamin Kramereedc4052016-12-09 13:33:41 +0000629 O << "InlineString: " << S;
Greg Clayton3462a422016-12-08 01:03:48 +0000630}
631
632//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000633// DIEEntry Implementation
634//===----------------------------------------------------------------------===//
635
636/// EmitValue - Emit debug information entry offset.
637///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000638void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopherdd508382014-03-06 00:00:56 +0000639
Greg Clayton3462a422016-12-08 01:03:48 +0000640 switch (Form) {
641 case dwarf::DW_FORM_ref1:
642 case dwarf::DW_FORM_ref2:
643 case dwarf::DW_FORM_ref4:
644 case dwarf::DW_FORM_ref8:
645 AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
646 return;
647
648 case dwarf::DW_FORM_ref_udata:
649 AP->EmitULEB128(Entry->getOffset());
650 return;
651
652 case dwarf::DW_FORM_ref_addr: {
Greg Clayton35630c32016-12-01 18:56:29 +0000653 // Get the absolute offset for this DIE within the debug info/types section.
654 unsigned Addr = Entry->getDebugSectionOffset();
655 if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
656 const DwarfDebug *DD = AP->getDwarfDebug();
657 if (DD)
Greg Clayton3462a422016-12-08 01:03:48 +0000658 assert(!DD->useSplitDwarf() &&
659 "TODO: dwo files can't have relocations.");
Greg Clayton35630c32016-12-01 18:56:29 +0000660 const DIEUnit *Unit = Entry->getUnit();
661 assert(Unit && "CUDie should belong to a CU.");
662 MCSection *Section = Unit->getSection();
Greg Clayton3462a422016-12-08 01:03:48 +0000663 if (Section) {
664 const MCSymbol *SectionSym = Section->getBeginSymbol();
Keno Fischerf7d84ee2017-01-02 03:00:19 +0000665 AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
Greg Clayton3462a422016-12-08 01:03:48 +0000666 return;
667 }
668 }
669 AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
670 return;
671 }
672 default:
673 llvm_unreachable("Improper form for DIE reference");
674 }
Bill Wendling47054f32009-05-15 00:11:17 +0000675}
676
Greg Clayton3462a422016-12-08 01:03:48 +0000677unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
678 switch (Form) {
679 case dwarf::DW_FORM_ref1:
680 return 1;
681 case dwarf::DW_FORM_ref2:
682 return 2;
683 case dwarf::DW_FORM_ref4:
684 return 4;
685 case dwarf::DW_FORM_ref8:
686 return 8;
687 case dwarf::DW_FORM_ref_udata:
688 return getULEB128Size(Entry->getOffset());
689 case dwarf::DW_FORM_ref_addr:
690 if (AP->getDwarfVersion() == 2)
691 return AP->getPointerSize();
692 switch (AP->OutStreamer->getContext().getDwarfFormat()) {
693 case dwarf::DWARF32:
694 return 4;
695 case dwarf::DWARF64:
696 return 8;
697 }
698 llvm_unreachable("Invalid DWARF format");
699
700 default:
701 llvm_unreachable("Improper form for DIE reference");
702 }
Manman Renac8062b2013-07-02 23:40:10 +0000703}
704
Davide Italianoc304a0d2015-11-24 02:21:43 +0000705LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000706void DIEEntry::print(raw_ostream &O) const {
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000707 O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
Bill Wendling47054f32009-05-15 00:11:17 +0000708}
Bill Wendling47054f32009-05-15 00:11:17 +0000709
710//===----------------------------------------------------------------------===//
Eric Christopher4a741042014-02-16 08:46:55 +0000711// DIELoc Implementation
712//===----------------------------------------------------------------------===//
713
714/// ComputeSize - calculate the size of the location expression.
715///
Frederic Risscd044342015-03-04 02:30:08 +0000716unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
Eric Christopher8bdab432014-02-27 18:36:10 +0000717 if (!Size) {
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000718 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000719 Size += V.SizeOf(AP);
Eric Christopher8bdab432014-02-27 18:36:10 +0000720 }
Eric Christopher4a741042014-02-16 08:46:55 +0000721
Eric Christopher8bdab432014-02-27 18:36:10 +0000722 return Size;
Eric Christopher4a741042014-02-16 08:46:55 +0000723}
724
725/// EmitValue - Emit location data.
726///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000727void DIELoc::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Eric Christopher4a741042014-02-16 08:46:55 +0000728 switch (Form) {
729 default: llvm_unreachable("Improper form for block");
730 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
731 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
732 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
733 case dwarf::DW_FORM_block:
734 case dwarf::DW_FORM_exprloc:
735 Asm->EmitULEB128(Size); break;
736 }
737
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 V.EmitValue(Asm);
Eric Christopher4a741042014-02-16 08:46:55 +0000740}
741
742/// SizeOf - Determine size of location data in bytes.
743///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000744unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopher4a741042014-02-16 08:46:55 +0000745 switch (Form) {
746 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
747 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
748 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
749 case dwarf::DW_FORM_block:
750 case dwarf::DW_FORM_exprloc:
Logan Chien5b776b72014-02-22 14:00:39 +0000751 return Size + getULEB128Size(Size);
Eric Christopher4a741042014-02-16 08:46:55 +0000752 default: llvm_unreachable("Improper form for block");
753 }
754}
755
Davide Italianoc304a0d2015-11-24 02:21:43 +0000756LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000757void DIELoc::print(raw_ostream &O) const {
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000758 printValues(O, *this, "ExprLoc", Size, 5);
Eric Christopher4a741042014-02-16 08:46:55 +0000759}
Eric Christopher4a741042014-02-16 08:46:55 +0000760
761//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000762// DIEBlock Implementation
763//===----------------------------------------------------------------------===//
764
765/// ComputeSize - calculate the size of the block.
766///
Frederic Risscd044342015-03-04 02:30:08 +0000767unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
Eric Christopher8bdab432014-02-27 18:36:10 +0000768 if (!Size) {
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000769 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000770 Size += V.SizeOf(AP);
Eric Christopher8bdab432014-02-27 18:36:10 +0000771 }
Bill Wendling47054f32009-05-15 00:11:17 +0000772
Eric Christopher8bdab432014-02-27 18:36:10 +0000773 return Size;
Bill Wendling47054f32009-05-15 00:11:17 +0000774}
775
776/// EmitValue - Emit block data.
777///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000778void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000779 switch (Form) {
Craig Topperee4dab52012-02-05 08:31:47 +0000780 default: llvm_unreachable("Improper form for block");
Chris Lattner9efd1182010-04-04 19:09:29 +0000781 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
782 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
783 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
784 case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
Bill Wendling47054f32009-05-15 00:11:17 +0000785 }
786
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000787 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000788 V.EmitValue(Asm);
Bill Wendling47054f32009-05-15 00:11:17 +0000789}
790
791/// SizeOf - Determine size of block data in bytes.
792///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000793unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000794 switch (Form) {
795 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
796 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
797 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
Logan Chien5b776b72014-02-22 14:00:39 +0000798 case dwarf::DW_FORM_block: return Size + getULEB128Size(Size);
David Blaikie46a9f012012-01-20 21:51:11 +0000799 default: llvm_unreachable("Improper form for block");
Bill Wendling47054f32009-05-15 00:11:17 +0000800 }
Bill Wendling47054f32009-05-15 00:11:17 +0000801}
802
Davide Italianoc304a0d2015-11-24 02:21:43 +0000803LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000804void DIEBlock::print(raw_ostream &O) const {
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000805 printValues(O, *this, "Blk", Size, 5);
Bill Wendling47054f32009-05-15 00:11:17 +0000806}
Eric Christophera27220f2014-03-05 22:41:20 +0000807
808//===----------------------------------------------------------------------===//
809// DIELocList Implementation
810//===----------------------------------------------------------------------===//
811
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000812unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christophera27220f2014-03-05 22:41:20 +0000813 if (Form == dwarf::DW_FORM_data4)
814 return 4;
815 if (Form == dwarf::DW_FORM_sec_offset)
816 return 4;
Mehdi Amini1660cab2015-07-16 05:59:25 +0000817 return AP->getPointerSize();
Eric Christophera27220f2014-03-05 22:41:20 +0000818}
819
820/// EmitValue - Emit label value.
821///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000822void DIELocList::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
David Blaikie9c550ac2014-03-25 01:44:02 +0000823 DwarfDebug *DD = AP->getDwarfDebug();
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000824 MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
Rafael Espindola857546e2015-06-16 23:22:02 +0000825 AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
Eric Christophera27220f2014-03-05 22:41:20 +0000826}
827
Davide Italianoc304a0d2015-11-24 02:21:43 +0000828LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000829void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }