blob: 622e4dc92586596fd025c063a8cad523a485e892 [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());
Bill Wendling47054f32009-05-15 00:11:17 +000082 }
83
84 // Mark end of abbreviation.
Chris Lattner3a383cb2010-04-05 00:13:49 +000085 AP->EmitULEB128(0, "EOM(1)");
86 AP->EmitULEB128(0, "EOM(2)");
Bill Wendling47054f32009-05-15 00:11:17 +000087}
88
Davide Italianoc304a0d2015-11-24 02:21:43 +000089LLVM_DUMP_METHOD
Chris Lattner74725712009-08-23 01:01:17 +000090void DIEAbbrev::print(raw_ostream &O) {
Bill Wendling47054f32009-05-15 00:11:17 +000091 O << "Abbreviation @"
Chris Lattner74725712009-08-23 01:01:17 +000092 << format("0x%lx", (long)(intptr_t)this)
Bill Wendling47054f32009-05-15 00:11:17 +000093 << " "
94 << dwarf::TagString(Tag)
95 << " "
Eric Christophere8f10722014-03-05 01:44:58 +000096 << dwarf::ChildrenString(Children)
Chris Lattner74725712009-08-23 01:01:17 +000097 << '\n';
Bill Wendling47054f32009-05-15 00:11:17 +000098
99 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
100 O << " "
101 << dwarf::AttributeString(Data[i].getAttribute())
102 << " "
103 << dwarf::FormEncodingString(Data[i].getForm())
Chris Lattner74725712009-08-23 01:01:17 +0000104 << '\n';
Bill Wendling47054f32009-05-15 00:11:17 +0000105 }
106}
Davide Italianoc304a0d2015-11-24 02:21:43 +0000107
108LLVM_DUMP_METHOD
David Greene8bc072c2009-12-24 00:27:55 +0000109void DIEAbbrev::dump() { print(dbgs()); }
Bill Wendling47054f32009-05-15 00:11:17 +0000110
Greg Clayton3462a422016-12-08 01:03:48 +0000111//===----------------------------------------------------------------------===//
112// DIEAbbrevSet Implementation
113//===----------------------------------------------------------------------===//
114
115DIEAbbrevSet::~DIEAbbrevSet() {
116 for (DIEAbbrev *Abbrev : Abbreviations)
117 Abbrev->~DIEAbbrev();
118}
119
120DIEAbbrev &DIEAbbrevSet::uniqueAbbreviation(DIE &Die) {
121
122 FoldingSetNodeID ID;
123 DIEAbbrev Abbrev = Die.generateAbbrev();
124 Abbrev.Profile(ID);
125
126 void *InsertPos;
127 if (DIEAbbrev *Existing =
128 AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
129 Die.setAbbrevNumber(Existing->getNumber());
130 return *Existing;
131 }
132
133 // Move the abbreviation to the heap and assign a number.
134 DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
135 Abbreviations.push_back(New);
136 New->setNumber(Abbreviations.size());
137 Die.setAbbrevNumber(Abbreviations.size());
138
139 // Store it for lookup.
140 AbbreviationsSet.InsertNode(New, InsertPos);
141 return *New;
142}
143
144void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const {
145 if (!Abbreviations.empty()) {
146 // Start the debug abbrev section.
147 AP->OutStreamer->SwitchSection(Section);
148 AP->emitDwarfAbbrevs(Abbreviations);
149 }
150}
151
152//===----------------------------------------------------------------------===//
153// DIE Implementation
154//===----------------------------------------------------------------------===//
155
Greg Clayton35630c32016-12-01 18:56:29 +0000156DIE *DIE::getParent() const {
157 return Owner.dyn_cast<DIE*>();
158}
159
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +0000160DIEAbbrev DIE::generateAbbrev() const {
161 DIEAbbrev Abbrev(Tag, hasChildren());
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000162 for (const DIEValue &V : values())
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +0000163 Abbrev.AddAttribute(V.getAttribute(), V.getForm());
164 return Abbrev;
165}
166
Greg Clayton35630c32016-12-01 18:56:29 +0000167unsigned DIE::getDebugSectionOffset() const {
168 const DIEUnit *Unit = getUnit();
169 assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
Benjamin Kramer6a8704c2016-12-01 19:10:10 +0000170 return Unit->getDebugSectionOffset() + getOffset();
Manman Ren4dbdc902013-10-31 17:54:35 +0000171}
172
Greg Clayton35630c32016-12-01 18:56:29 +0000173const DIE *DIE::getUnitDie() const {
Manman Rence20d462013-10-29 22:57:10 +0000174 const DIE *p = this;
175 while (p) {
David Blaikie409dd9c2013-11-19 23:08:21 +0000176 if (p->getTag() == dwarf::DW_TAG_compile_unit ||
177 p->getTag() == dwarf::DW_TAG_type_unit)
Manman Rence20d462013-10-29 22:57:10 +0000178 return p;
179 p = p->getParent();
180 }
Craig Topper353eda42014-04-24 06:44:33 +0000181 return nullptr;
Manman Rence20d462013-10-29 22:57:10 +0000182}
183
Greg Clayton35630c32016-12-01 18:56:29 +0000184const DIEUnit *DIE::getUnit() const {
185 const DIE *UnitDie = getUnitDie();
186 if (UnitDie)
187 return UnitDie->Owner.dyn_cast<DIEUnit*>();
188 return nullptr;
189}
190
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000191DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const {
Eric Christopher8552e222013-08-07 01:18:33 +0000192 // Iterate through all the attributes until we find the one we're
193 // looking for, if we can't find it return NULL.
Duncan P. N. Exon Smith88a8fc52015-05-27 22:44:06 +0000194 for (const auto &V : values())
195 if (V.getAttribute() == Attribute)
196 return V;
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000197 return DIEValue();
Eric Christopher8552e222013-08-07 01:18:33 +0000198}
199
Davide Italianoc304a0d2015-11-24 02:21:43 +0000200LLVM_DUMP_METHOD
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000201static void printValues(raw_ostream &O, const DIEValueList &Values,
202 StringRef Type, unsigned Size, unsigned IndentCount) {
203 O << Type << ": Size: " << Size << "\n";
204
205 unsigned I = 0;
206 const std::string Indent(IndentCount, ' ');
207 for (const auto &V : Values.values()) {
208 O << Indent;
209 O << "Blk[" << I++ << "]";
210 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
211 V.print(O);
212 O << "\n";
213 }
214}
215
Davide Italianoc304a0d2015-11-24 02:21:43 +0000216LLVM_DUMP_METHOD
Eric Christopher6c6de842013-05-06 17:50:50 +0000217void DIE::print(raw_ostream &O, unsigned IndentCount) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000218 const std::string Indent(IndentCount, ' ');
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000219 O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this)
220 << ", Offset: " << Offset << ", Size: " << Size << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000221
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000222 O << Indent << dwarf::TagString(getTag()) << " "
223 << dwarf::ChildrenString(hasChildren()) << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000224
Bill Wendling47054f32009-05-15 00:11:17 +0000225 IndentCount += 2;
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000226 for (const auto &V : values()) {
Bill Wendling47054f32009-05-15 00:11:17 +0000227 O << Indent;
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000228 O << dwarf::AttributeString(V.getAttribute());
Duncan P. N. Exon Smith4fb1f9c2015-06-25 23:46:41 +0000229 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
230 V.print(O);
Bill Wendling47054f32009-05-15 00:11:17 +0000231 O << "\n";
232 }
233 IndentCount -= 2;
234
Duncan P. N. Exon Smith827200c2015-06-25 23:52:10 +0000235 for (const auto &Child : children())
236 Child.print(O, IndentCount + 4);
Bill Wendling47054f32009-05-15 00:11:17 +0000237
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000238 O << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000239}
240
Davide Italianoc304a0d2015-11-24 02:21:43 +0000241LLVM_DUMP_METHOD
Bill Wendling47054f32009-05-15 00:11:17 +0000242void DIE::dump() {
David Greene8bc072c2009-12-24 00:27:55 +0000243 print(dbgs());
Bill Wendling47054f32009-05-15 00:11:17 +0000244}
Bill Wendling47054f32009-05-15 00:11:17 +0000245
Greg Clayton3462a422016-12-08 01:03:48 +0000246unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP,
247 DIEAbbrevSet &AbbrevSet,
248 unsigned CUOffset) {
249 // Unique the abbreviation and fill in the abbreviation number so this DIE
250 // can be emitted.
251 const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
252
253 // Set compile/type unit relative offset of this DIE.
254 setOffset(CUOffset);
255
256 // Add the byte size of the abbreviation code.
257 CUOffset += getULEB128Size(getAbbrevNumber());
258
259 // Add the byte size of all the DIE attribute values.
260 for (const auto &V : values())
261 CUOffset += V.SizeOf(AP);
262
263 // Let the children compute their offsets and abbreviation numbers.
264 if (hasChildren()) {
265 (void)Abbrev;
266 assert(Abbrev.hasChildren() && "Children flag not set");
267
268 for (auto &Child : children())
269 CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
270
271 // Each child chain is terminated with a zero byte, adjust the offset.
272 CUOffset += sizeof(int8_t);
273 }
274
275 // Compute the byte size of this DIE and all of its children correctly. This
276 // is needed so that top level DIE can help the compile unit set its length
277 // correctly.
278 setSize(CUOffset - getOffset());
279 return CUOffset;
280}
281
282//===----------------------------------------------------------------------===//
283// DIEUnit Implementation
284//===----------------------------------------------------------------------===//
Greg Clayton35630c32016-12-01 18:56:29 +0000285DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag)
286 : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V),
287 AddrSize(A)
288{
David Blaikiee40caae2016-12-01 21:59:09 +0000289 Die.Owner = this;
Greg Clayton35630c32016-12-01 18:56:29 +0000290 assert((UnitTag == dwarf::DW_TAG_compile_unit ||
291 UnitTag == dwarf::DW_TAG_type_unit ||
292 UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG");
293}
294
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000295void DIEValue::EmitValue(const AsmPrinter *AP) const {
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000296 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000297 case isNone:
298 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000299#define HANDLE_DIEVALUE(T) \
300 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000301 getDIE##T().EmitValue(AP, Form); \
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000302 break;
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000303#include "llvm/CodeGen/DIEValue.def"
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000304 }
305}
306
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000307unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000308 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000309 case isNone:
310 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000311#define HANDLE_DIEVALUE(T) \
312 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000313 return getDIE##T().SizeOf(AP, Form);
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000314#include "llvm/CodeGen/DIEValue.def"
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000315 }
Aaron Ballmanc681c3d2015-05-23 14:46:49 +0000316 llvm_unreachable("Unknown DIE kind");
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000317}
Bill Wendling47054f32009-05-15 00:11:17 +0000318
Davide Italianoc304a0d2015-11-24 02:21:43 +0000319LLVM_DUMP_METHOD
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000320void DIEValue::print(raw_ostream &O) const {
321 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000322 case isNone:
323 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000324#define HANDLE_DIEVALUE(T) \
325 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000326 getDIE##T().print(O); \
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000327 break;
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000328#include "llvm/CodeGen/DIEValue.def"
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000329 }
330}
331
Davide Italianoc304a0d2015-11-24 02:21:43 +0000332LLVM_DUMP_METHOD
Eric Christopher65ac02a2013-05-31 22:50:40 +0000333void DIEValue::dump() const {
David Greene8bc072c2009-12-24 00:27:55 +0000334 print(dbgs());
Bill Wendling47054f32009-05-15 00:11:17 +0000335}
Bill Wendling47054f32009-05-15 00:11:17 +0000336
337//===----------------------------------------------------------------------===//
338// DIEInteger Implementation
339//===----------------------------------------------------------------------===//
340
341/// EmitValue - Emit integer of appropriate size.
342///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000343void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000344 switch (Form) {
Eric Christopherbb69a272012-08-24 01:14:27 +0000345 case dwarf::DW_FORM_flag_present:
346 // Emit something to keep the lines and comments in sync.
347 // FIXME: Is there a better way to do this?
Lang Hames9ff69c82015-04-24 19:11:51 +0000348 Asm->OutStreamer->AddBlankLine();
Eric Christopherbb69a272012-08-24 01:14:27 +0000349 return;
Greg Clayton3462a422016-12-08 01:03:48 +0000350 case dwarf::DW_FORM_flag:
351 LLVM_FALLTHROUGH;
352 case dwarf::DW_FORM_ref1:
353 LLVM_FALLTHROUGH;
354 case dwarf::DW_FORM_data1:
355 LLVM_FALLTHROUGH;
356 case dwarf::DW_FORM_ref2:
357 LLVM_FALLTHROUGH;
358 case dwarf::DW_FORM_data2:
359 LLVM_FALLTHROUGH;
360 case dwarf::DW_FORM_strp:
361 LLVM_FALLTHROUGH;
362 case dwarf::DW_FORM_ref4:
363 LLVM_FALLTHROUGH;
364 case dwarf::DW_FORM_data4:
365 LLVM_FALLTHROUGH;
366 case dwarf::DW_FORM_ref8:
367 LLVM_FALLTHROUGH;
368 case dwarf::DW_FORM_ref_sig8:
369 LLVM_FALLTHROUGH;
370 case dwarf::DW_FORM_data8:
371 LLVM_FALLTHROUGH;
372 case dwarf::DW_FORM_GNU_ref_alt:
373 LLVM_FALLTHROUGH;
374 case dwarf::DW_FORM_GNU_strp_alt:
375 LLVM_FALLTHROUGH;
376 case dwarf::DW_FORM_line_strp:
377 LLVM_FALLTHROUGH;
378 case dwarf::DW_FORM_sec_offset:
379 LLVM_FALLTHROUGH;
380 case dwarf::DW_FORM_strp_sup:
381 LLVM_FALLTHROUGH;
382 case dwarf::DW_FORM_ref_sup:
383 LLVM_FALLTHROUGH;
Eric Christophere8a7b1b2012-09-10 23:34:03 +0000384 case dwarf::DW_FORM_addr:
Greg Clayton3462a422016-12-08 01:03:48 +0000385 LLVM_FALLTHROUGH;
Frederic Rissee17fb9b2015-03-04 22:07:36 +0000386 case dwarf::DW_FORM_ref_addr:
Greg Clayton3462a422016-12-08 01:03:48 +0000387 Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form));
388 return;
389 case dwarf::DW_FORM_GNU_str_index:
390 LLVM_FALLTHROUGH;
391 case dwarf::DW_FORM_GNU_addr_index:
392 LLVM_FALLTHROUGH;
393 case dwarf::DW_FORM_ref_udata:
394 LLVM_FALLTHROUGH;
395 case dwarf::DW_FORM_udata:
396 Asm->EmitULEB128(Integer);
397 return;
398 case dwarf::DW_FORM_sdata:
399 Asm->EmitSLEB128(Integer);
400 return;
Torok Edwinfbcc6632009-07-14 16:55:14 +0000401 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling47054f32009-05-15 00:11:17 +0000402 }
403}
404
405/// SizeOf - Determine size of integer value in bytes.
406///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000407unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000408 switch (Form) {
Eric Christopher2a4e6162012-08-29 17:59:32 +0000409 case dwarf::DW_FORM_flag_present: return 0;
Justin Bognercd1d5aa2016-08-17 20:30:52 +0000410 case dwarf::DW_FORM_flag: LLVM_FALLTHROUGH;
411 case dwarf::DW_FORM_ref1: LLVM_FALLTHROUGH;
Bill Wendling47054f32009-05-15 00:11:17 +0000412 case dwarf::DW_FORM_data1: return sizeof(int8_t);
Justin Bognercd1d5aa2016-08-17 20:30:52 +0000413 case dwarf::DW_FORM_ref2: LLVM_FALLTHROUGH;
Bill Wendling47054f32009-05-15 00:11:17 +0000414 case dwarf::DW_FORM_data2: return sizeof(int16_t);
Justin Bognercd1d5aa2016-08-17 20:30:52 +0000415 case dwarf::DW_FORM_ref4: LLVM_FALLTHROUGH;
Bill Wendling47054f32009-05-15 00:11:17 +0000416 case dwarf::DW_FORM_data4: return sizeof(int32_t);
Justin Bognercd1d5aa2016-08-17 20:30:52 +0000417 case dwarf::DW_FORM_ref8: LLVM_FALLTHROUGH;
418 case dwarf::DW_FORM_ref_sig8: LLVM_FALLTHROUGH;
Bill Wendling47054f32009-05-15 00:11:17 +0000419 case dwarf::DW_FORM_data8: return sizeof(int64_t);
Frederic Rissee17fb9b2015-03-04 22:07:36 +0000420 case dwarf::DW_FORM_ref_addr:
Greg Claytone6543972016-11-23 23:30:37 +0000421 if (AP->getDwarfVersion() == 2)
Mehdi Amini1660cab2015-07-16 05:59:25 +0000422 return AP->getPointerSize();
Greg Clayton3462a422016-12-08 01:03:48 +0000423 LLVM_FALLTHROUGH;
424 case dwarf::DW_FORM_strp:
425 LLVM_FALLTHROUGH;
426 case dwarf::DW_FORM_GNU_ref_alt:
427 LLVM_FALLTHROUGH;
428 case dwarf::DW_FORM_GNU_strp_alt:
429 LLVM_FALLTHROUGH;
430 case dwarf::DW_FORM_line_strp:
431 LLVM_FALLTHROUGH;
432 case dwarf::DW_FORM_sec_offset:
433 LLVM_FALLTHROUGH;
434 case dwarf::DW_FORM_strp_sup:
435 LLVM_FALLTHROUGH;
436 case dwarf::DW_FORM_ref_sup:
437 switch (AP->OutStreamer->getContext().getDwarfFormat()) {
438 case dwarf::DWARF32:
439 return 4;
440 case dwarf::DWARF64:
441 return 8;
442 }
443 llvm_unreachable("Invalid DWARF format");
444 case dwarf::DW_FORM_GNU_str_index:
445 LLVM_FALLTHROUGH;
446 case dwarf::DW_FORM_GNU_addr_index:
447 LLVM_FALLTHROUGH;
448 case dwarf::DW_FORM_ref_udata:
449 LLVM_FALLTHROUGH;
450 case dwarf::DW_FORM_udata:
451 return getULEB128Size(Integer);
452 case dwarf::DW_FORM_sdata:
453 return getSLEB128Size(Integer);
454 case dwarf::DW_FORM_addr:
455 return AP->getPointerSize();
David Blaikie46a9f012012-01-20 21:51:11 +0000456 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling47054f32009-05-15 00:11:17 +0000457 }
Bill Wendling47054f32009-05-15 00:11:17 +0000458}
459
Davide Italianoc304a0d2015-11-24 02:21:43 +0000460LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000461void DIEInteger::print(raw_ostream &O) const {
Benjamin Kramerf3da5292011-11-05 08:57:40 +0000462 O << "Int: " << (int64_t)Integer << " 0x";
463 O.write_hex(Integer);
Bill Wendling47054f32009-05-15 00:11:17 +0000464}
Bill Wendling47054f32009-05-15 00:11:17 +0000465
466//===----------------------------------------------------------------------===//
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000467// DIEExpr Implementation
468//===----------------------------------------------------------------------===//
469
470/// EmitValue - Emit expression value.
471///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000472void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Lang Hames9ff69c82015-04-24 19:11:51 +0000473 AP->OutStreamer->EmitValue(Expr, SizeOf(AP, Form));
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000474}
475
476/// SizeOf - Determine size of expression value in bytes.
477///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000478unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000479 if (Form == dwarf::DW_FORM_data4) return 4;
480 if (Form == dwarf::DW_FORM_sec_offset) return 4;
481 if (Form == dwarf::DW_FORM_strp) return 4;
Mehdi Amini1660cab2015-07-16 05:59:25 +0000482 return AP->getPointerSize();
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000483}
484
Davide Italianoc304a0d2015-11-24 02:21:43 +0000485LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000486void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000487
488//===----------------------------------------------------------------------===//
Chris Lattner8dcf41e2010-03-08 22:31:46 +0000489// DIELabel Implementation
Bill Wendling47054f32009-05-15 00:11:17 +0000490//===----------------------------------------------------------------------===//
491
492/// EmitValue - Emit label value.
493///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000494void DIELabel::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
David Blaikief2443192013-10-21 17:28:37 +0000495 AP->EmitLabelReference(Label, SizeOf(AP, Form),
496 Form == dwarf::DW_FORM_strp ||
497 Form == dwarf::DW_FORM_sec_offset ||
498 Form == dwarf::DW_FORM_ref_addr);
Bill Wendling47054f32009-05-15 00:11:17 +0000499}
500
501/// SizeOf - Determine size of label value in bytes.
502///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000503unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000504 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher4c7765f2013-01-17 03:00:04 +0000505 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewyckyd59c0ca2011-10-27 06:44:11 +0000506 if (Form == dwarf::DW_FORM_strp) return 4;
Mehdi Amini1660cab2015-07-16 05:59:25 +0000507 return AP->getPointerSize();
Bill Wendling47054f32009-05-15 00:11:17 +0000508}
509
Davide Italianoc304a0d2015-11-24 02:21:43 +0000510LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000511void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
Bill Wendling47054f32009-05-15 00:11:17 +0000512
513//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000514// DIEDelta Implementation
515//===----------------------------------------------------------------------===//
516
517/// EmitValue - Emit delta value.
518///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000519void DIEDelta::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Chris Lattner5a00dea2010-04-05 00:18:22 +0000520 AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
Bill Wendling47054f32009-05-15 00:11:17 +0000521}
522
523/// SizeOf - Determine size of delta value in bytes.
524///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000525unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000526 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher33ff6972013-11-21 23:46:41 +0000527 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewyckyd59c0ca2011-10-27 06:44:11 +0000528 if (Form == dwarf::DW_FORM_strp) return 4;
Mehdi Amini1660cab2015-07-16 05:59:25 +0000529 return AP->getPointerSize();
Bill Wendling47054f32009-05-15 00:11:17 +0000530}
531
Davide Italianoc304a0d2015-11-24 02:21:43 +0000532LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000533void DIEDelta::print(raw_ostream &O) const {
Chris Lattnerbc9210c2010-03-08 22:23:36 +0000534 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
Bill Wendling47054f32009-05-15 00:11:17 +0000535}
Bill Wendling47054f32009-05-15 00:11:17 +0000536
537//===----------------------------------------------------------------------===//
Eric Christopher67646432013-07-26 17:02:41 +0000538// DIEString Implementation
539//===----------------------------------------------------------------------===//
540
541/// EmitValue - Emit string value.
542///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000543void DIEString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000544 assert(
545 (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
546 "Expected valid string form");
547
548 // Index of string in symbol table.
549 if (Form == dwarf::DW_FORM_GNU_str_index) {
550 DIEInteger(S.getIndex()).EmitValue(AP, Form);
551 return;
552 }
553
554 // Relocatable symbol.
555 assert(Form == dwarf::DW_FORM_strp);
556 if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
557 DIELabel(S.getSymbol()).EmitValue(AP, Form);
558 return;
559 }
560
561 // Offset into symbol table.
562 DIEInteger(S.getOffset()).EmitValue(AP, Form);
Eric Christopher67646432013-07-26 17:02:41 +0000563}
564
565/// SizeOf - Determine size of delta value in bytes.
566///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000567unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000568 assert(
569 (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
570 "Expected valid string form");
571
572 // Index of string in symbol table.
573 if (Form == dwarf::DW_FORM_GNU_str_index)
574 return DIEInteger(S.getIndex()).SizeOf(AP, Form);
575
576 // Relocatable symbol.
577 if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
578 return DIELabel(S.getSymbol()).SizeOf(AP, Form);
579
580 // Offset into symbol table.
581 return DIEInteger(S.getOffset()).SizeOf(AP, Form);
Eric Christopher67646432013-07-26 17:02:41 +0000582}
583
Davide Italianoc304a0d2015-11-24 02:21:43 +0000584LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000585void DIEString::print(raw_ostream &O) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000586 O << "String: " << S.getString();
Eric Christopher67646432013-07-26 17:02:41 +0000587}
Eric Christopher67646432013-07-26 17:02:41 +0000588
589//===----------------------------------------------------------------------===//
Greg Clayton3462a422016-12-08 01:03:48 +0000590// DIEInlineString Implementation
591//===----------------------------------------------------------------------===//
592void DIEInlineString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
593 if (Form == dwarf::DW_FORM_string) {
594 for (char ch : S)
595 AP->EmitInt8(ch);
596 AP->EmitInt8(0);
597 return;
598 }
599 llvm_unreachable("Expected valid string form");
600}
601
602unsigned DIEInlineString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
603 // Emit string bytes + NULL byte.
604 return S.size() + 1;
605}
606
607LLVM_DUMP_METHOD
608void DIEInlineString::print(raw_ostream &O) const {
Benjamin Kramereedc4052016-12-09 13:33:41 +0000609 O << "InlineString: " << S;
Greg Clayton3462a422016-12-08 01:03:48 +0000610}
611
612//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000613// DIEEntry Implementation
614//===----------------------------------------------------------------------===//
615
616/// EmitValue - Emit debug information entry offset.
617///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000618void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopherdd508382014-03-06 00:00:56 +0000619
Greg Clayton3462a422016-12-08 01:03:48 +0000620 switch (Form) {
621 case dwarf::DW_FORM_ref1:
622 case dwarf::DW_FORM_ref2:
623 case dwarf::DW_FORM_ref4:
624 case dwarf::DW_FORM_ref8:
625 AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
626 return;
627
628 case dwarf::DW_FORM_ref_udata:
629 AP->EmitULEB128(Entry->getOffset());
630 return;
631
632 case dwarf::DW_FORM_ref_addr: {
Greg Clayton35630c32016-12-01 18:56:29 +0000633 // Get the absolute offset for this DIE within the debug info/types section.
634 unsigned Addr = Entry->getDebugSectionOffset();
635 if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
636 const DwarfDebug *DD = AP->getDwarfDebug();
637 if (DD)
Greg Clayton3462a422016-12-08 01:03:48 +0000638 assert(!DD->useSplitDwarf() &&
639 "TODO: dwo files can't have relocations.");
Greg Clayton35630c32016-12-01 18:56:29 +0000640 const DIEUnit *Unit = Entry->getUnit();
641 assert(Unit && "CUDie should belong to a CU.");
642 MCSection *Section = Unit->getSection();
Greg Clayton3462a422016-12-08 01:03:48 +0000643 if (Section) {
644 const MCSymbol *SectionSym = Section->getBeginSymbol();
Keno Fischerd4ea4c12016-12-08 01:56:23 +0000645 AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form));
Greg Clayton3462a422016-12-08 01:03:48 +0000646 return;
647 }
648 }
649 AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
650 return;
651 }
652 default:
653 llvm_unreachable("Improper form for DIE reference");
654 }
Bill Wendling47054f32009-05-15 00:11:17 +0000655}
656
Greg Clayton3462a422016-12-08 01:03:48 +0000657unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
658 switch (Form) {
659 case dwarf::DW_FORM_ref1:
660 return 1;
661 case dwarf::DW_FORM_ref2:
662 return 2;
663 case dwarf::DW_FORM_ref4:
664 return 4;
665 case dwarf::DW_FORM_ref8:
666 return 8;
667 case dwarf::DW_FORM_ref_udata:
668 return getULEB128Size(Entry->getOffset());
669 case dwarf::DW_FORM_ref_addr:
670 if (AP->getDwarfVersion() == 2)
671 return AP->getPointerSize();
672 switch (AP->OutStreamer->getContext().getDwarfFormat()) {
673 case dwarf::DWARF32:
674 return 4;
675 case dwarf::DWARF64:
676 return 8;
677 }
678 llvm_unreachable("Invalid DWARF format");
679
680 default:
681 llvm_unreachable("Improper form for DIE reference");
682 }
Manman Renac8062b2013-07-02 23:40:10 +0000683}
684
Davide Italianoc304a0d2015-11-24 02:21:43 +0000685LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000686void DIEEntry::print(raw_ostream &O) const {
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000687 O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
Bill Wendling47054f32009-05-15 00:11:17 +0000688}
Bill Wendling47054f32009-05-15 00:11:17 +0000689
690//===----------------------------------------------------------------------===//
Eric Christopher4a741042014-02-16 08:46:55 +0000691// DIELoc Implementation
692//===----------------------------------------------------------------------===//
693
694/// ComputeSize - calculate the size of the location expression.
695///
Frederic Risscd044342015-03-04 02:30:08 +0000696unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
Eric Christopher8bdab432014-02-27 18:36:10 +0000697 if (!Size) {
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000698 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000699 Size += V.SizeOf(AP);
Eric Christopher8bdab432014-02-27 18:36:10 +0000700 }
Eric Christopher4a741042014-02-16 08:46:55 +0000701
Eric Christopher8bdab432014-02-27 18:36:10 +0000702 return Size;
Eric Christopher4a741042014-02-16 08:46:55 +0000703}
704
705/// EmitValue - Emit location data.
706///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000707void DIELoc::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Eric Christopher4a741042014-02-16 08:46:55 +0000708 switch (Form) {
709 default: llvm_unreachable("Improper form for block");
710 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
711 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
712 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
713 case dwarf::DW_FORM_block:
714 case dwarf::DW_FORM_exprloc:
715 Asm->EmitULEB128(Size); break;
716 }
717
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 V.EmitValue(Asm);
Eric Christopher4a741042014-02-16 08:46:55 +0000720}
721
722/// SizeOf - Determine size of location data in bytes.
723///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000724unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopher4a741042014-02-16 08:46:55 +0000725 switch (Form) {
726 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
727 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
728 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
729 case dwarf::DW_FORM_block:
730 case dwarf::DW_FORM_exprloc:
Logan Chien5b776b72014-02-22 14:00:39 +0000731 return Size + getULEB128Size(Size);
Eric Christopher4a741042014-02-16 08:46:55 +0000732 default: llvm_unreachable("Improper form for block");
733 }
734}
735
Davide Italianoc304a0d2015-11-24 02:21:43 +0000736LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000737void DIELoc::print(raw_ostream &O) const {
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000738 printValues(O, *this, "ExprLoc", Size, 5);
Eric Christopher4a741042014-02-16 08:46:55 +0000739}
Eric Christopher4a741042014-02-16 08:46:55 +0000740
741//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000742// DIEBlock Implementation
743//===----------------------------------------------------------------------===//
744
745/// ComputeSize - calculate the size of the block.
746///
Frederic Risscd044342015-03-04 02:30:08 +0000747unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
Eric Christopher8bdab432014-02-27 18:36:10 +0000748 if (!Size) {
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000749 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000750 Size += V.SizeOf(AP);
Eric Christopher8bdab432014-02-27 18:36:10 +0000751 }
Bill Wendling47054f32009-05-15 00:11:17 +0000752
Eric Christopher8bdab432014-02-27 18:36:10 +0000753 return Size;
Bill Wendling47054f32009-05-15 00:11:17 +0000754}
755
756/// EmitValue - Emit block data.
757///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000758void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000759 switch (Form) {
Craig Topperee4dab52012-02-05 08:31:47 +0000760 default: llvm_unreachable("Improper form for block");
Chris Lattner9efd1182010-04-04 19:09:29 +0000761 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
762 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
763 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
764 case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
Bill Wendling47054f32009-05-15 00:11:17 +0000765 }
766
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000767 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000768 V.EmitValue(Asm);
Bill Wendling47054f32009-05-15 00:11:17 +0000769}
770
771/// SizeOf - Determine size of block data in bytes.
772///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000773unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000774 switch (Form) {
775 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
776 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
777 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
Logan Chien5b776b72014-02-22 14:00:39 +0000778 case dwarf::DW_FORM_block: return Size + getULEB128Size(Size);
David Blaikie46a9f012012-01-20 21:51:11 +0000779 default: llvm_unreachable("Improper form for block");
Bill Wendling47054f32009-05-15 00:11:17 +0000780 }
Bill Wendling47054f32009-05-15 00:11:17 +0000781}
782
Davide Italianoc304a0d2015-11-24 02:21:43 +0000783LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000784void DIEBlock::print(raw_ostream &O) const {
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000785 printValues(O, *this, "Blk", Size, 5);
Bill Wendling47054f32009-05-15 00:11:17 +0000786}
Eric Christophera27220f2014-03-05 22:41:20 +0000787
788//===----------------------------------------------------------------------===//
789// DIELocList Implementation
790//===----------------------------------------------------------------------===//
791
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000792unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christophera27220f2014-03-05 22:41:20 +0000793 if (Form == dwarf::DW_FORM_data4)
794 return 4;
795 if (Form == dwarf::DW_FORM_sec_offset)
796 return 4;
Mehdi Amini1660cab2015-07-16 05:59:25 +0000797 return AP->getPointerSize();
Eric Christophera27220f2014-03-05 22:41:20 +0000798}
799
800/// EmitValue - Emit label value.
801///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000802void DIELocList::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
David Blaikie9c550ac2014-03-25 01:44:02 +0000803 DwarfDebug *DD = AP->getDwarfDebug();
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000804 MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
Rafael Espindola857546e2015-06-16 23:22:02 +0000805 AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
Eric Christophera27220f2014-03-05 22:41:20 +0000806}
807
Davide Italianoc304a0d2015-11-24 02:21:43 +0000808LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000809void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }