blob: b510e0ef36ac63e383e7491fbf4657410fb4ecb6 [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));
Victor Leschukd7bfa402017-03-01 22:13:42 +000045 if (Form == dwarf::DW_FORM_implicit_const)
46 ID.AddInteger(Value);
Bill Wendling47054f32009-05-15 00:11:17 +000047}
48
49//===----------------------------------------------------------------------===//
50// DIEAbbrev Implementation
51//===----------------------------------------------------------------------===//
52
53/// Profile - Used to gather unique data for the abbreviation folding set.
54///
55void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
Reid Klecknerad65f102013-10-21 19:18:31 +000056 ID.AddInteger(unsigned(Tag));
Eric Christophere8f10722014-03-05 01:44:58 +000057 ID.AddInteger(unsigned(Children));
Bill Wendling47054f32009-05-15 00:11:17 +000058
59 // For each attribute description.
60 for (unsigned i = 0, N = Data.size(); i < N; ++i)
61 Data[i].Profile(ID);
62}
63
64/// Emit - Print the abbreviation using the specified asm printer.
65///
Frederic Risscd044342015-03-04 02:30:08 +000066void DIEAbbrev::Emit(const AsmPrinter *AP) const {
Bill Wendling47054f32009-05-15 00:11:17 +000067 // Emit its Dwarf tag type.
Mehdi Amini149f6ea2016-10-05 05:59:29 +000068 AP->EmitULEB128(Tag, dwarf::TagString(Tag).data());
Bill Wendling47054f32009-05-15 00:11:17 +000069
70 // Emit whether it has children DIEs.
Mehdi Amini149f6ea2016-10-05 05:59:29 +000071 AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
Bill Wendling47054f32009-05-15 00:11:17 +000072
73 // For each attribute description.
74 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
75 const DIEAbbrevData &AttrData = Data[i];
76
77 // Emit attribute type.
Chris Lattner3a383cb2010-04-05 00:13:49 +000078 AP->EmitULEB128(AttrData.getAttribute(),
Mehdi Amini149f6ea2016-10-05 05:59:29 +000079 dwarf::AttributeString(AttrData.getAttribute()).data());
Bill Wendling47054f32009-05-15 00:11:17 +000080
81 // Emit form type.
Chris Lattner3a383cb2010-04-05 00:13:49 +000082 AP->EmitULEB128(AttrData.getForm(),
Mehdi Amini149f6ea2016-10-05 05:59:29 +000083 dwarf::FormEncodingString(AttrData.getForm()).data());
Victor Leschukcbddae72017-01-10 21:18:26 +000084
85 // Emit value for DW_FORM_implicit_const.
86 if (AttrData.getForm() == dwarf::DW_FORM_implicit_const) {
87 assert(AP->getDwarfVersion() >= 5 &&
88 "DW_FORM_implicit_const is supported starting from DWARFv5");
89 AP->EmitSLEB128(AttrData.getValue());
90 }
Bill Wendling47054f32009-05-15 00:11:17 +000091 }
92
93 // Mark end of abbreviation.
Chris Lattner3a383cb2010-04-05 00:13:49 +000094 AP->EmitULEB128(0, "EOM(1)");
95 AP->EmitULEB128(0, "EOM(2)");
Bill Wendling47054f32009-05-15 00:11:17 +000096}
97
Davide Italianoc304a0d2015-11-24 02:21:43 +000098LLVM_DUMP_METHOD
Chris Lattner74725712009-08-23 01:01:17 +000099void DIEAbbrev::print(raw_ostream &O) {
Bill Wendling47054f32009-05-15 00:11:17 +0000100 O << "Abbreviation @"
Chris Lattner74725712009-08-23 01:01:17 +0000101 << format("0x%lx", (long)(intptr_t)this)
Bill Wendling47054f32009-05-15 00:11:17 +0000102 << " "
103 << dwarf::TagString(Tag)
104 << " "
Eric Christophere8f10722014-03-05 01:44:58 +0000105 << dwarf::ChildrenString(Children)
Chris Lattner74725712009-08-23 01:01:17 +0000106 << '\n';
Bill Wendling47054f32009-05-15 00:11:17 +0000107
108 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
109 O << " "
110 << dwarf::AttributeString(Data[i].getAttribute())
111 << " "
Victor Leschukd7bfa402017-03-01 22:13:42 +0000112 << dwarf::FormEncodingString(Data[i].getForm());
113
114 if (Data[i].getForm() == dwarf::DW_FORM_implicit_const)
115 O << " " << Data[i].getValue();
116
117 O << '\n';
Bill Wendling47054f32009-05-15 00:11:17 +0000118 }
119}
Davide Italianoc304a0d2015-11-24 02:21:43 +0000120
Matthias Braun8c209aa2017-01-28 02:02:38 +0000121#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
122LLVM_DUMP_METHOD void DIEAbbrev::dump() {
123 print(dbgs());
124}
125#endif
Bill Wendling47054f32009-05-15 00:11:17 +0000126
Greg Clayton3462a422016-12-08 01:03:48 +0000127//===----------------------------------------------------------------------===//
128// DIEAbbrevSet Implementation
129//===----------------------------------------------------------------------===//
130
131DIEAbbrevSet::~DIEAbbrevSet() {
132 for (DIEAbbrev *Abbrev : Abbreviations)
133 Abbrev->~DIEAbbrev();
134}
135
136DIEAbbrev &DIEAbbrevSet::uniqueAbbreviation(DIE &Die) {
137
138 FoldingSetNodeID ID;
139 DIEAbbrev Abbrev = Die.generateAbbrev();
140 Abbrev.Profile(ID);
141
142 void *InsertPos;
143 if (DIEAbbrev *Existing =
144 AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
145 Die.setAbbrevNumber(Existing->getNumber());
146 return *Existing;
147 }
148
149 // Move the abbreviation to the heap and assign a number.
150 DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
151 Abbreviations.push_back(New);
152 New->setNumber(Abbreviations.size());
153 Die.setAbbrevNumber(Abbreviations.size());
154
155 // Store it for lookup.
156 AbbreviationsSet.InsertNode(New, InsertPos);
157 return *New;
158}
159
160void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const {
161 if (!Abbreviations.empty()) {
162 // Start the debug abbrev section.
163 AP->OutStreamer->SwitchSection(Section);
164 AP->emitDwarfAbbrevs(Abbreviations);
165 }
166}
167
168//===----------------------------------------------------------------------===//
169// DIE Implementation
170//===----------------------------------------------------------------------===//
171
Greg Clayton35630c32016-12-01 18:56:29 +0000172DIE *DIE::getParent() const {
173 return Owner.dyn_cast<DIE*>();
174}
175
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +0000176DIEAbbrev DIE::generateAbbrev() const {
177 DIEAbbrev Abbrev(Tag, hasChildren());
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000178 for (const DIEValue &V : values())
Victor Leschukcbddae72017-01-10 21:18:26 +0000179 if (V.getForm() == dwarf::DW_FORM_implicit_const)
180 Abbrev.AddImplicitConstAttribute(V.getAttribute(),
181 V.getDIEInteger().getValue());
182 else
183 Abbrev.AddAttribute(V.getAttribute(), V.getForm());
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +0000184 return Abbrev;
185}
186
Greg Clayton35630c32016-12-01 18:56:29 +0000187unsigned DIE::getDebugSectionOffset() const {
188 const DIEUnit *Unit = getUnit();
189 assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
Benjamin Kramer6a8704c2016-12-01 19:10:10 +0000190 return Unit->getDebugSectionOffset() + getOffset();
Manman Ren4dbdc902013-10-31 17:54:35 +0000191}
192
Greg Clayton35630c32016-12-01 18:56:29 +0000193const DIE *DIE::getUnitDie() const {
Manman Rence20d462013-10-29 22:57:10 +0000194 const DIE *p = this;
195 while (p) {
David Blaikie409dd9c2013-11-19 23:08:21 +0000196 if (p->getTag() == dwarf::DW_TAG_compile_unit ||
197 p->getTag() == dwarf::DW_TAG_type_unit)
Manman Rence20d462013-10-29 22:57:10 +0000198 return p;
199 p = p->getParent();
200 }
Craig Topper353eda42014-04-24 06:44:33 +0000201 return nullptr;
Manman Rence20d462013-10-29 22:57:10 +0000202}
203
Greg Clayton35630c32016-12-01 18:56:29 +0000204const DIEUnit *DIE::getUnit() const {
205 const DIE *UnitDie = getUnitDie();
206 if (UnitDie)
207 return UnitDie->Owner.dyn_cast<DIEUnit*>();
208 return nullptr;
209}
210
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000211DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const {
Eric Christopher8552e222013-08-07 01:18:33 +0000212 // Iterate through all the attributes until we find the one we're
213 // looking for, if we can't find it return NULL.
Duncan P. N. Exon Smith88a8fc52015-05-27 22:44:06 +0000214 for (const auto &V : values())
215 if (V.getAttribute() == Attribute)
216 return V;
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000217 return DIEValue();
Eric Christopher8552e222013-08-07 01:18:33 +0000218}
219
Davide Italianoc304a0d2015-11-24 02:21:43 +0000220LLVM_DUMP_METHOD
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000221static void printValues(raw_ostream &O, const DIEValueList &Values,
222 StringRef Type, unsigned Size, unsigned IndentCount) {
223 O << Type << ": Size: " << Size << "\n";
224
225 unsigned I = 0;
226 const std::string Indent(IndentCount, ' ');
227 for (const auto &V : Values.values()) {
228 O << Indent;
229 O << "Blk[" << I++ << "]";
230 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
231 V.print(O);
232 O << "\n";
233 }
234}
235
Davide Italianoc304a0d2015-11-24 02:21:43 +0000236LLVM_DUMP_METHOD
Eric Christopher6c6de842013-05-06 17:50:50 +0000237void DIE::print(raw_ostream &O, unsigned IndentCount) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000238 const std::string Indent(IndentCount, ' ');
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000239 O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this)
240 << ", Offset: " << Offset << ", Size: " << Size << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000241
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000242 O << Indent << dwarf::TagString(getTag()) << " "
243 << dwarf::ChildrenString(hasChildren()) << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000244
Bill Wendling47054f32009-05-15 00:11:17 +0000245 IndentCount += 2;
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000246 for (const auto &V : values()) {
Bill Wendling47054f32009-05-15 00:11:17 +0000247 O << Indent;
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000248 O << dwarf::AttributeString(V.getAttribute());
Duncan P. N. Exon Smith4fb1f9c2015-06-25 23:46:41 +0000249 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
250 V.print(O);
Bill Wendling47054f32009-05-15 00:11:17 +0000251 O << "\n";
252 }
253 IndentCount -= 2;
254
Duncan P. N. Exon Smith827200c2015-06-25 23:52:10 +0000255 for (const auto &Child : children())
256 Child.print(O, IndentCount + 4);
Bill Wendling47054f32009-05-15 00:11:17 +0000257
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000258 O << "\n";
Bill Wendling47054f32009-05-15 00:11:17 +0000259}
260
Matthias Braun8c209aa2017-01-28 02:02:38 +0000261#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
262LLVM_DUMP_METHOD void DIE::dump() {
David Greene8bc072c2009-12-24 00:27:55 +0000263 print(dbgs());
Bill Wendling47054f32009-05-15 00:11:17 +0000264}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000265#endif
Bill Wendling47054f32009-05-15 00:11:17 +0000266
Greg Clayton3462a422016-12-08 01:03:48 +0000267unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP,
268 DIEAbbrevSet &AbbrevSet,
269 unsigned CUOffset) {
270 // Unique the abbreviation and fill in the abbreviation number so this DIE
271 // can be emitted.
272 const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
273
274 // Set compile/type unit relative offset of this DIE.
275 setOffset(CUOffset);
276
277 // Add the byte size of the abbreviation code.
278 CUOffset += getULEB128Size(getAbbrevNumber());
279
280 // Add the byte size of all the DIE attribute values.
281 for (const auto &V : values())
282 CUOffset += V.SizeOf(AP);
283
284 // Let the children compute their offsets and abbreviation numbers.
285 if (hasChildren()) {
286 (void)Abbrev;
287 assert(Abbrev.hasChildren() && "Children flag not set");
288
289 for (auto &Child : children())
290 CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
291
292 // Each child chain is terminated with a zero byte, adjust the offset.
293 CUOffset += sizeof(int8_t);
294 }
295
296 // Compute the byte size of this DIE and all of its children correctly. This
297 // is needed so that top level DIE can help the compile unit set its length
298 // correctly.
299 setSize(CUOffset - getOffset());
300 return CUOffset;
301}
302
303//===----------------------------------------------------------------------===//
304// DIEUnit Implementation
305//===----------------------------------------------------------------------===//
Greg Clayton35630c32016-12-01 18:56:29 +0000306DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag)
307 : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V),
308 AddrSize(A)
309{
David Blaikiee40caae2016-12-01 21:59:09 +0000310 Die.Owner = this;
Greg Clayton35630c32016-12-01 18:56:29 +0000311 assert((UnitTag == dwarf::DW_TAG_compile_unit ||
312 UnitTag == dwarf::DW_TAG_type_unit ||
313 UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG");
314}
315
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000316void DIEValue::EmitValue(const AsmPrinter *AP) const {
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000317 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000318 case isNone:
319 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000320#define HANDLE_DIEVALUE(T) \
321 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000322 getDIE##T().EmitValue(AP, Form); \
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000323 break;
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000324#include "llvm/CodeGen/DIEValue.def"
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000325 }
326}
327
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000328unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000329 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000330 case isNone:
331 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000332#define HANDLE_DIEVALUE(T) \
333 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000334 return getDIE##T().SizeOf(AP, Form);
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 }
Aaron Ballmanc681c3d2015-05-23 14:46:49 +0000337 llvm_unreachable("Unknown DIE kind");
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000338}
Bill Wendling47054f32009-05-15 00:11:17 +0000339
Davide Italianoc304a0d2015-11-24 02:21:43 +0000340LLVM_DUMP_METHOD
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000341void DIEValue::print(raw_ostream &O) const {
342 switch (Ty) {
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000343 case isNone:
344 llvm_unreachable("Expected valid DIEValue");
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000345#define HANDLE_DIEVALUE(T) \
346 case is##T: \
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000347 getDIE##T().print(O); \
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000348 break;
Duncan P. N. Exon Smithff189272015-05-27 21:15:43 +0000349#include "llvm/CodeGen/DIEValue.def"
Duncan P. N. Exon Smith68b3f302015-05-23 01:45:07 +0000350 }
351}
352
Matthias Braun8c209aa2017-01-28 02:02:38 +0000353#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
354LLVM_DUMP_METHOD void DIEValue::dump() const {
David Greene8bc072c2009-12-24 00:27:55 +0000355 print(dbgs());
Bill Wendling47054f32009-05-15 00:11:17 +0000356}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000357#endif
Bill Wendling47054f32009-05-15 00:11:17 +0000358
359//===----------------------------------------------------------------------===//
360// DIEInteger Implementation
361//===----------------------------------------------------------------------===//
362
363/// EmitValue - Emit integer of appropriate size.
364///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000365void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000366 switch (Form) {
Victor Leschukcbddae72017-01-10 21:18:26 +0000367 case dwarf::DW_FORM_implicit_const:
Eric Christopherbb69a272012-08-24 01:14:27 +0000368 case dwarf::DW_FORM_flag_present:
369 // Emit something to keep the lines and comments in sync.
370 // FIXME: Is there a better way to do this?
Lang Hames9ff69c82015-04-24 19:11:51 +0000371 Asm->OutStreamer->AddBlankLine();
Eric Christopherbb69a272012-08-24 01:14:27 +0000372 return;
Greg Clayton3462a422016-12-08 01:03:48 +0000373 case dwarf::DW_FORM_flag:
Greg Clayton3462a422016-12-08 01:03:48 +0000374 case dwarf::DW_FORM_ref1:
Greg Clayton3462a422016-12-08 01:03:48 +0000375 case dwarf::DW_FORM_data1:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000376 case dwarf::DW_FORM_strx1:
377 case dwarf::DW_FORM_addrx1:
Greg Clayton3462a422016-12-08 01:03:48 +0000378 case dwarf::DW_FORM_ref2:
Greg Clayton3462a422016-12-08 01:03:48 +0000379 case dwarf::DW_FORM_data2:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000380 case dwarf::DW_FORM_strx2:
381 case dwarf::DW_FORM_addrx2:
Greg Clayton3462a422016-12-08 01:03:48 +0000382 case dwarf::DW_FORM_strp:
Greg Clayton3462a422016-12-08 01:03:48 +0000383 case dwarf::DW_FORM_ref4:
Greg Clayton3462a422016-12-08 01:03:48 +0000384 case dwarf::DW_FORM_data4:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000385 case dwarf::DW_FORM_ref_sup4:
386 case dwarf::DW_FORM_strx4:
387 case dwarf::DW_FORM_addrx4:
Greg Clayton3462a422016-12-08 01:03:48 +0000388 case dwarf::DW_FORM_ref8:
Greg Clayton3462a422016-12-08 01:03:48 +0000389 case dwarf::DW_FORM_ref_sig8:
Greg Clayton3462a422016-12-08 01:03:48 +0000390 case dwarf::DW_FORM_data8:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000391 case dwarf::DW_FORM_ref_sup8:
Greg Clayton3462a422016-12-08 01:03:48 +0000392 case dwarf::DW_FORM_GNU_ref_alt:
Greg Clayton3462a422016-12-08 01:03:48 +0000393 case dwarf::DW_FORM_GNU_strp_alt:
Greg Clayton3462a422016-12-08 01:03:48 +0000394 case dwarf::DW_FORM_line_strp:
Greg Clayton3462a422016-12-08 01:03:48 +0000395 case dwarf::DW_FORM_sec_offset:
Greg Clayton3462a422016-12-08 01:03:48 +0000396 case dwarf::DW_FORM_strp_sup:
Eric Christophere8a7b1b2012-09-10 23:34:03 +0000397 case dwarf::DW_FORM_addr:
Frederic Rissee17fb9b2015-03-04 22:07:36 +0000398 case dwarf::DW_FORM_ref_addr:
Greg Clayton3462a422016-12-08 01:03:48 +0000399 Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form));
400 return;
401 case dwarf::DW_FORM_GNU_str_index:
Greg Clayton3462a422016-12-08 01:03:48 +0000402 case dwarf::DW_FORM_GNU_addr_index:
Greg Clayton3462a422016-12-08 01:03:48 +0000403 case dwarf::DW_FORM_ref_udata:
Greg Clayton3462a422016-12-08 01:03:48 +0000404 case dwarf::DW_FORM_udata:
405 Asm->EmitULEB128(Integer);
406 return;
407 case dwarf::DW_FORM_sdata:
408 Asm->EmitSLEB128(Integer);
409 return;
Torok Edwinfbcc6632009-07-14 16:55:14 +0000410 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling47054f32009-05-15 00:11:17 +0000411 }
412}
413
414/// SizeOf - Determine size of integer value in bytes.
415///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000416unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000417 switch (Form) {
Paul Robinsona94f76b2017-03-01 23:59:11 +0000418 case dwarf::DW_FORM_implicit_const:
419 case dwarf::DW_FORM_flag_present:
420 return 0;
421 case dwarf::DW_FORM_flag:
422 case dwarf::DW_FORM_ref1:
423 case dwarf::DW_FORM_data1:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000424 case dwarf::DW_FORM_strx1:
425 case dwarf::DW_FORM_addrx1:
Paul Robinsona94f76b2017-03-01 23:59:11 +0000426 return sizeof(int8_t);
427 case dwarf::DW_FORM_ref2:
428 case dwarf::DW_FORM_data2:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000429 case dwarf::DW_FORM_strx2:
430 case dwarf::DW_FORM_addrx2:
Paul Robinsona94f76b2017-03-01 23:59:11 +0000431 return sizeof(int16_t);
432 case dwarf::DW_FORM_ref4:
433 case dwarf::DW_FORM_data4:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000434 case dwarf::DW_FORM_ref_sup4:
435 case dwarf::DW_FORM_strx4:
436 case dwarf::DW_FORM_addrx4:
Paul Robinsona94f76b2017-03-01 23:59:11 +0000437 return sizeof(int32_t);
438 case dwarf::DW_FORM_ref8:
439 case dwarf::DW_FORM_ref_sig8:
440 case dwarf::DW_FORM_data8:
Paul Robinsonf96e21a2017-03-06 22:20:03 +0000441 case dwarf::DW_FORM_ref_sup8:
Paul Robinsona94f76b2017-03-01 23:59:11 +0000442 return sizeof(int64_t);
Frederic Rissee17fb9b2015-03-04 22:07:36 +0000443 case dwarf::DW_FORM_ref_addr:
Greg Claytone6543972016-11-23 23:30:37 +0000444 if (AP->getDwarfVersion() == 2)
Mehdi Amini1660cab2015-07-16 05:59:25 +0000445 return AP->getPointerSize();
Greg Clayton3462a422016-12-08 01:03:48 +0000446 LLVM_FALLTHROUGH;
447 case dwarf::DW_FORM_strp:
Greg Clayton3462a422016-12-08 01:03:48 +0000448 case dwarf::DW_FORM_GNU_ref_alt:
Greg Clayton3462a422016-12-08 01:03:48 +0000449 case dwarf::DW_FORM_GNU_strp_alt:
Greg Clayton3462a422016-12-08 01:03:48 +0000450 case dwarf::DW_FORM_line_strp:
Greg Clayton3462a422016-12-08 01:03:48 +0000451 case dwarf::DW_FORM_sec_offset:
Greg Clayton3462a422016-12-08 01:03:48 +0000452 case dwarf::DW_FORM_strp_sup:
Greg Clayton3462a422016-12-08 01:03:48 +0000453 switch (AP->OutStreamer->getContext().getDwarfFormat()) {
454 case dwarf::DWARF32:
455 return 4;
456 case dwarf::DWARF64:
457 return 8;
458 }
459 llvm_unreachable("Invalid DWARF format");
460 case dwarf::DW_FORM_GNU_str_index:
Greg Clayton3462a422016-12-08 01:03:48 +0000461 case dwarf::DW_FORM_GNU_addr_index:
Greg Clayton3462a422016-12-08 01:03:48 +0000462 case dwarf::DW_FORM_ref_udata:
Greg Clayton3462a422016-12-08 01:03:48 +0000463 case dwarf::DW_FORM_udata:
464 return getULEB128Size(Integer);
465 case dwarf::DW_FORM_sdata:
466 return getSLEB128Size(Integer);
467 case dwarf::DW_FORM_addr:
468 return AP->getPointerSize();
David Blaikie46a9f012012-01-20 21:51:11 +0000469 default: llvm_unreachable("DIE Value form not supported yet");
Bill Wendling47054f32009-05-15 00:11:17 +0000470 }
Bill Wendling47054f32009-05-15 00:11:17 +0000471}
472
Davide Italianoc304a0d2015-11-24 02:21:43 +0000473LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000474void DIEInteger::print(raw_ostream &O) const {
Benjamin Kramerf3da5292011-11-05 08:57:40 +0000475 O << "Int: " << (int64_t)Integer << " 0x";
476 O.write_hex(Integer);
Bill Wendling47054f32009-05-15 00:11:17 +0000477}
Bill Wendling47054f32009-05-15 00:11:17 +0000478
479//===----------------------------------------------------------------------===//
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000480// DIEExpr Implementation
481//===----------------------------------------------------------------------===//
482
483/// EmitValue - Emit expression value.
484///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000485void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Simon Dardis2e8cdbd2017-02-08 19:03:46 +0000486 AP->EmitDebugThreadLocal(Expr, SizeOf(AP, Form));
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000487}
488
489/// SizeOf - Determine size of expression value in bytes.
490///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000491unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000492 if (Form == dwarf::DW_FORM_data4) return 4;
493 if (Form == dwarf::DW_FORM_sec_offset) return 4;
494 if (Form == dwarf::DW_FORM_strp) return 4;
Mehdi Amini1660cab2015-07-16 05:59:25 +0000495 return AP->getPointerSize();
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000496}
497
Davide Italianoc304a0d2015-11-24 02:21:43 +0000498LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000499void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000500
501//===----------------------------------------------------------------------===//
Chris Lattner8dcf41e2010-03-08 22:31:46 +0000502// DIELabel Implementation
Bill Wendling47054f32009-05-15 00:11:17 +0000503//===----------------------------------------------------------------------===//
504
505/// EmitValue - Emit label value.
506///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000507void DIELabel::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
David Blaikief2443192013-10-21 17:28:37 +0000508 AP->EmitLabelReference(Label, SizeOf(AP, Form),
509 Form == dwarf::DW_FORM_strp ||
510 Form == dwarf::DW_FORM_sec_offset ||
Keno Fischerf7d84ee2017-01-02 03:00:19 +0000511 Form == dwarf::DW_FORM_ref_addr ||
512 Form == dwarf::DW_FORM_data4);
Bill Wendling47054f32009-05-15 00:11:17 +0000513}
514
515/// SizeOf - Determine size of label value in bytes.
516///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000517unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000518 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher4c7765f2013-01-17 03:00:04 +0000519 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewyckyd59c0ca2011-10-27 06:44:11 +0000520 if (Form == dwarf::DW_FORM_strp) return 4;
Mehdi Amini1660cab2015-07-16 05:59:25 +0000521 return AP->getPointerSize();
Bill Wendling47054f32009-05-15 00:11:17 +0000522}
523
Davide Italianoc304a0d2015-11-24 02:21:43 +0000524LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000525void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
Bill Wendling47054f32009-05-15 00:11:17 +0000526
527//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000528// DIEDelta Implementation
529//===----------------------------------------------------------------------===//
530
531/// EmitValue - Emit delta value.
532///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000533void DIEDelta::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Chris Lattner5a00dea2010-04-05 00:18:22 +0000534 AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
Bill Wendling47054f32009-05-15 00:11:17 +0000535}
536
537/// SizeOf - Determine size of delta value in bytes.
538///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000539unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000540 if (Form == dwarf::DW_FORM_data4) return 4;
Eric Christopher33ff6972013-11-21 23:46:41 +0000541 if (Form == dwarf::DW_FORM_sec_offset) return 4;
Nick Lewyckyd59c0ca2011-10-27 06:44:11 +0000542 if (Form == dwarf::DW_FORM_strp) return 4;
Mehdi Amini1660cab2015-07-16 05:59:25 +0000543 return AP->getPointerSize();
Bill Wendling47054f32009-05-15 00:11:17 +0000544}
545
Davide Italianoc304a0d2015-11-24 02:21:43 +0000546LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000547void DIEDelta::print(raw_ostream &O) const {
Chris Lattnerbc9210c2010-03-08 22:23:36 +0000548 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
Bill Wendling47054f32009-05-15 00:11:17 +0000549}
Bill Wendling47054f32009-05-15 00:11:17 +0000550
551//===----------------------------------------------------------------------===//
Eric Christopher67646432013-07-26 17:02:41 +0000552// DIEString Implementation
553//===----------------------------------------------------------------------===//
554
555/// EmitValue - Emit string value.
556///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000557void DIEString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000558 assert(
559 (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
560 "Expected valid string form");
561
562 // Index of string in symbol table.
563 if (Form == dwarf::DW_FORM_GNU_str_index) {
564 DIEInteger(S.getIndex()).EmitValue(AP, Form);
565 return;
566 }
567
568 // Relocatable symbol.
569 assert(Form == dwarf::DW_FORM_strp);
570 if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
571 DIELabel(S.getSymbol()).EmitValue(AP, Form);
572 return;
573 }
574
575 // Offset into symbol table.
576 DIEInteger(S.getOffset()).EmitValue(AP, Form);
Eric Christopher67646432013-07-26 17:02:41 +0000577}
578
579/// SizeOf - Determine size of delta value in bytes.
580///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000581unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000582 assert(
583 (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
584 "Expected valid string form");
585
586 // Index of string in symbol table.
587 if (Form == dwarf::DW_FORM_GNU_str_index)
588 return DIEInteger(S.getIndex()).SizeOf(AP, Form);
589
590 // Relocatable symbol.
591 if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
592 return DIELabel(S.getSymbol()).SizeOf(AP, Form);
593
594 // Offset into symbol table.
595 return DIEInteger(S.getOffset()).SizeOf(AP, Form);
Eric Christopher67646432013-07-26 17:02:41 +0000596}
597
Davide Italianoc304a0d2015-11-24 02:21:43 +0000598LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000599void DIEString::print(raw_ostream &O) const {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000600 O << "String: " << S.getString();
Eric Christopher67646432013-07-26 17:02:41 +0000601}
Eric Christopher67646432013-07-26 17:02:41 +0000602
603//===----------------------------------------------------------------------===//
Greg Clayton3462a422016-12-08 01:03:48 +0000604// DIEInlineString Implementation
605//===----------------------------------------------------------------------===//
606void DIEInlineString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
607 if (Form == dwarf::DW_FORM_string) {
608 for (char ch : S)
609 AP->EmitInt8(ch);
610 AP->EmitInt8(0);
611 return;
612 }
613 llvm_unreachable("Expected valid string form");
614}
615
616unsigned DIEInlineString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
617 // Emit string bytes + NULL byte.
618 return S.size() + 1;
619}
620
621LLVM_DUMP_METHOD
622void DIEInlineString::print(raw_ostream &O) const {
Benjamin Kramereedc4052016-12-09 13:33:41 +0000623 O << "InlineString: " << S;
Greg Clayton3462a422016-12-08 01:03:48 +0000624}
625
626//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000627// DIEEntry Implementation
628//===----------------------------------------------------------------------===//
629
630/// EmitValue - Emit debug information entry offset.
631///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000632void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopherdd508382014-03-06 00:00:56 +0000633
Greg Clayton3462a422016-12-08 01:03:48 +0000634 switch (Form) {
635 case dwarf::DW_FORM_ref1:
636 case dwarf::DW_FORM_ref2:
637 case dwarf::DW_FORM_ref4:
638 case dwarf::DW_FORM_ref8:
639 AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
640 return;
641
642 case dwarf::DW_FORM_ref_udata:
643 AP->EmitULEB128(Entry->getOffset());
644 return;
645
646 case dwarf::DW_FORM_ref_addr: {
Greg Clayton35630c32016-12-01 18:56:29 +0000647 // Get the absolute offset for this DIE within the debug info/types section.
648 unsigned Addr = Entry->getDebugSectionOffset();
649 if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
650 const DwarfDebug *DD = AP->getDwarfDebug();
651 if (DD)
Greg Clayton3462a422016-12-08 01:03:48 +0000652 assert(!DD->useSplitDwarf() &&
653 "TODO: dwo files can't have relocations.");
Greg Clayton35630c32016-12-01 18:56:29 +0000654 const DIEUnit *Unit = Entry->getUnit();
655 assert(Unit && "CUDie should belong to a CU.");
656 MCSection *Section = Unit->getSection();
Greg Clayton3462a422016-12-08 01:03:48 +0000657 if (Section) {
658 const MCSymbol *SectionSym = Section->getBeginSymbol();
Keno Fischerf7d84ee2017-01-02 03:00:19 +0000659 AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
Greg Clayton3462a422016-12-08 01:03:48 +0000660 return;
661 }
662 }
663 AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
664 return;
665 }
666 default:
667 llvm_unreachable("Improper form for DIE reference");
668 }
Bill Wendling47054f32009-05-15 00:11:17 +0000669}
670
Greg Clayton3462a422016-12-08 01:03:48 +0000671unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
672 switch (Form) {
673 case dwarf::DW_FORM_ref1:
674 return 1;
675 case dwarf::DW_FORM_ref2:
676 return 2;
677 case dwarf::DW_FORM_ref4:
678 return 4;
679 case dwarf::DW_FORM_ref8:
680 return 8;
681 case dwarf::DW_FORM_ref_udata:
682 return getULEB128Size(Entry->getOffset());
683 case dwarf::DW_FORM_ref_addr:
684 if (AP->getDwarfVersion() == 2)
685 return AP->getPointerSize();
686 switch (AP->OutStreamer->getContext().getDwarfFormat()) {
687 case dwarf::DWARF32:
688 return 4;
689 case dwarf::DWARF64:
690 return 8;
691 }
692 llvm_unreachable("Invalid DWARF format");
693
694 default:
695 llvm_unreachable("Improper form for DIE reference");
696 }
Manman Renac8062b2013-07-02 23:40:10 +0000697}
698
Davide Italianoc304a0d2015-11-24 02:21:43 +0000699LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000700void DIEEntry::print(raw_ostream &O) const {
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000701 O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
Bill Wendling47054f32009-05-15 00:11:17 +0000702}
Bill Wendling47054f32009-05-15 00:11:17 +0000703
704//===----------------------------------------------------------------------===//
Eric Christopher4a741042014-02-16 08:46:55 +0000705// DIELoc Implementation
706//===----------------------------------------------------------------------===//
707
708/// ComputeSize - calculate the size of the location expression.
709///
Frederic Risscd044342015-03-04 02:30:08 +0000710unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
Eric Christopher8bdab432014-02-27 18:36:10 +0000711 if (!Size) {
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000712 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000713 Size += V.SizeOf(AP);
Eric Christopher8bdab432014-02-27 18:36:10 +0000714 }
Eric Christopher4a741042014-02-16 08:46:55 +0000715
Eric Christopher8bdab432014-02-27 18:36:10 +0000716 return Size;
Eric Christopher4a741042014-02-16 08:46:55 +0000717}
718
719/// EmitValue - Emit location data.
720///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000721void DIELoc::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Eric Christopher4a741042014-02-16 08:46:55 +0000722 switch (Form) {
723 default: llvm_unreachable("Improper form for block");
724 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
725 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
726 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
727 case dwarf::DW_FORM_block:
728 case dwarf::DW_FORM_exprloc:
729 Asm->EmitULEB128(Size); break;
730 }
731
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000732 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000733 V.EmitValue(Asm);
Eric Christopher4a741042014-02-16 08:46:55 +0000734}
735
736/// SizeOf - Determine size of location data in bytes.
737///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000738unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopher4a741042014-02-16 08:46:55 +0000739 switch (Form) {
740 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
741 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
742 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
743 case dwarf::DW_FORM_block:
744 case dwarf::DW_FORM_exprloc:
Logan Chien5b776b72014-02-22 14:00:39 +0000745 return Size + getULEB128Size(Size);
Eric Christopher4a741042014-02-16 08:46:55 +0000746 default: llvm_unreachable("Improper form for block");
747 }
748}
749
Davide Italianoc304a0d2015-11-24 02:21:43 +0000750LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000751void DIELoc::print(raw_ostream &O) const {
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000752 printValues(O, *this, "ExprLoc", Size, 5);
Eric Christopher4a741042014-02-16 08:46:55 +0000753}
Eric Christopher4a741042014-02-16 08:46:55 +0000754
755//===----------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000756// DIEBlock Implementation
757//===----------------------------------------------------------------------===//
758
759/// ComputeSize - calculate the size of the block.
760///
Frederic Risscd044342015-03-04 02:30:08 +0000761unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
Eric Christopher8bdab432014-02-27 18:36:10 +0000762 if (!Size) {
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000763 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000764 Size += V.SizeOf(AP);
Eric Christopher8bdab432014-02-27 18:36:10 +0000765 }
Bill Wendling47054f32009-05-15 00:11:17 +0000766
Eric Christopher8bdab432014-02-27 18:36:10 +0000767 return Size;
Bill Wendling47054f32009-05-15 00:11:17 +0000768}
769
770/// EmitValue - Emit block data.
771///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000772void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000773 switch (Form) {
Craig Topperee4dab52012-02-05 08:31:47 +0000774 default: llvm_unreachable("Improper form for block");
Chris Lattner9efd1182010-04-04 19:09:29 +0000775 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
776 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
777 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
778 case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
Bill Wendling47054f32009-05-15 00:11:17 +0000779 }
780
Duncan P. N. Exon Smith1ad5ebc2015-08-02 20:42:45 +0000781 for (const auto &V : values())
Duncan P. N. Exon Smith9dbb5012015-06-24 18:48:11 +0000782 V.EmitValue(Asm);
Bill Wendling47054f32009-05-15 00:11:17 +0000783}
784
785/// SizeOf - Determine size of block data in bytes.
786///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000787unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Bill Wendling47054f32009-05-15 00:11:17 +0000788 switch (Form) {
789 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
790 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
791 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
Logan Chien5b776b72014-02-22 14:00:39 +0000792 case dwarf::DW_FORM_block: return Size + getULEB128Size(Size);
David Blaikie46a9f012012-01-20 21:51:11 +0000793 default: llvm_unreachable("Improper form for block");
Bill Wendling47054f32009-05-15 00:11:17 +0000794 }
Bill Wendling47054f32009-05-15 00:11:17 +0000795}
796
Davide Italianoc304a0d2015-11-24 02:21:43 +0000797LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000798void DIEBlock::print(raw_ostream &O) const {
Duncan P. N. Exon Smithc5821142015-08-02 20:46:49 +0000799 printValues(O, *this, "Blk", Size, 5);
Bill Wendling47054f32009-05-15 00:11:17 +0000800}
Eric Christophera27220f2014-03-05 22:41:20 +0000801
802//===----------------------------------------------------------------------===//
803// DIELocList Implementation
804//===----------------------------------------------------------------------===//
805
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000806unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
Eric Christophera27220f2014-03-05 22:41:20 +0000807 if (Form == dwarf::DW_FORM_data4)
808 return 4;
809 if (Form == dwarf::DW_FORM_sec_offset)
810 return 4;
Mehdi Amini1660cab2015-07-16 05:59:25 +0000811 return AP->getPointerSize();
Eric Christophera27220f2014-03-05 22:41:20 +0000812}
813
814/// EmitValue - Emit label value.
815///
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000816void DIELocList::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
David Blaikie9c550ac2014-03-25 01:44:02 +0000817 DwarfDebug *DD = AP->getDwarfDebug();
Duncan P. N. Exon Smith364a3002015-04-17 21:34:47 +0000818 MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
Rafael Espindola857546e2015-06-16 23:22:02 +0000819 AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
Eric Christophera27220f2014-03-05 22:41:20 +0000820}
821
Davide Italianoc304a0d2015-11-24 02:21:43 +0000822LLVM_DUMP_METHOD
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000823void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }