LLVM  9.0.0svn
DIE.cpp
Go to the documentation of this file.
1 //===--- lib/CodeGen/DIE.cpp - DWARF Info Entries -------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Data structures for DWARF info entries.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/CodeGen/DIE.h"
14 #include "DwarfCompileUnit.h"
15 #include "DwarfDebug.h"
16 #include "DwarfUnit.h"
17 #include "llvm/ADT/Twine.h"
19 #include "llvm/Config/llvm-config.h"
20 #include "llvm/IR/DataLayout.h"
21 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/MCStreamer.h"
24 #include "llvm/MC/MCSymbol.h"
25 #include "llvm/Support/Debug.h"
27 #include "llvm/Support/Format.h"
29 #include "llvm/Support/LEB128.h"
30 #include "llvm/Support/MD5.h"
32 using namespace llvm;
33 
34 #define DEBUG_TYPE "dwarfdebug"
35 
36 //===----------------------------------------------------------------------===//
37 // DIEAbbrevData Implementation
38 //===----------------------------------------------------------------------===//
39 
40 /// Profile - Used to gather unique data for the abbreviation folding set.
41 ///
43  // Explicitly cast to an integer type for which FoldingSetNodeID has
44  // overloads. Otherwise MSVC 2010 thinks this call is ambiguous.
45  ID.AddInteger(unsigned(Attribute));
46  ID.AddInteger(unsigned(Form));
47  if (Form == dwarf::DW_FORM_implicit_const)
48  ID.AddInteger(Value);
49 }
50 
51 //===----------------------------------------------------------------------===//
52 // DIEAbbrev Implementation
53 //===----------------------------------------------------------------------===//
54 
55 /// Profile - Used to gather unique data for the abbreviation folding set.
56 ///
58  ID.AddInteger(unsigned(Tag));
59  ID.AddInteger(unsigned(Children));
60 
61  // For each attribute description.
62  for (unsigned i = 0, N = Data.size(); i < N; ++i)
63  Data[i].Profile(ID);
64 }
65 
66 /// Emit - Print the abbreviation using the specified asm printer.
67 ///
68 void DIEAbbrev::Emit(const AsmPrinter *AP) const {
69  // Emit its Dwarf tag type.
70  AP->EmitULEB128(Tag, dwarf::TagString(Tag).data());
71 
72  // Emit whether it has children DIEs.
73  AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
74 
75  // For each attribute description.
76  for (unsigned i = 0, N = Data.size(); i < N; ++i) {
77  const DIEAbbrevData &AttrData = Data[i];
78 
79  // Emit attribute type.
80  AP->EmitULEB128(AttrData.getAttribute(),
81  dwarf::AttributeString(AttrData.getAttribute()).data());
82 
83  // Emit form type.
84 #ifndef NDEBUG
85  // Could be an assertion, but this way we can see the failing form code
86  // easily, which helps track down where it came from.
87  if (!dwarf::isValidFormForVersion(AttrData.getForm(),
88  AP->getDwarfVersion())) {
89  LLVM_DEBUG(dbgs() << "Invalid form " << format("0x%x", AttrData.getForm())
90  << " for DWARF version " << AP->getDwarfVersion()
91  << "\n");
92  llvm_unreachable("Invalid form for specified DWARF version");
93  }
94 #endif
95  AP->EmitULEB128(AttrData.getForm(),
96  dwarf::FormEncodingString(AttrData.getForm()).data());
97 
98  // Emit value for DW_FORM_implicit_const.
99  if (AttrData.getForm() == dwarf::DW_FORM_implicit_const)
100  AP->EmitSLEB128(AttrData.getValue());
101  }
102 
103  // Mark end of abbreviation.
104  AP->EmitULEB128(0, "EOM(1)");
105  AP->EmitULEB128(0, "EOM(2)");
106 }
107 
110  O << "Abbreviation @"
111  << format("0x%lx", (long)(intptr_t)this)
112  << " "
114  << " "
115  << dwarf::ChildrenString(Children)
116  << '\n';
117 
118  for (unsigned i = 0, N = Data.size(); i < N; ++i) {
119  O << " "
121  << " "
123 
124  if (Data[i].getForm() == dwarf::DW_FORM_implicit_const)
125  O << " " << Data[i].getValue();
126 
127  O << '\n';
128  }
129 }
130 
131 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
133  print(dbgs());
134 }
135 #endif
136 
137 //===----------------------------------------------------------------------===//
138 // DIEAbbrevSet Implementation
139 //===----------------------------------------------------------------------===//
140 
142  for (DIEAbbrev *Abbrev : Abbreviations)
143  Abbrev->~DIEAbbrev();
144 }
145 
147 
149  DIEAbbrev Abbrev = Die.generateAbbrev();
150  Abbrev.Profile(ID);
151 
152  void *InsertPos;
153  if (DIEAbbrev *Existing =
154  AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
155  Die.setAbbrevNumber(Existing->getNumber());
156  return *Existing;
157  }
158 
159  // Move the abbreviation to the heap and assign a number.
160  DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
161  Abbreviations.push_back(New);
162  New->setNumber(Abbreviations.size());
163  Die.setAbbrevNumber(Abbreviations.size());
164 
165  // Store it for lookup.
166  AbbreviationsSet.InsertNode(New, InsertPos);
167  return *New;
168 }
169 
171  if (!Abbreviations.empty()) {
172  // Start the debug abbrev section.
173  AP->OutStreamer->SwitchSection(Section);
174  AP->emitDwarfAbbrevs(Abbreviations);
175  }
176 }
177 
178 //===----------------------------------------------------------------------===//
179 // DIE Implementation
180 //===----------------------------------------------------------------------===//
181 
182 DIE *DIE::getParent() const {
183  return Owner.dyn_cast<DIE*>();
184 }
185 
187  DIEAbbrev Abbrev(Tag, hasChildren());
188  for (const DIEValue &V : values())
189  if (V.getForm() == dwarf::DW_FORM_implicit_const)
190  Abbrev.AddImplicitConstAttribute(V.getAttribute(),
191  V.getDIEInteger().getValue());
192  else
193  Abbrev.AddAttribute(V.getAttribute(), V.getForm());
194  return Abbrev;
195 }
196 
197 unsigned DIE::getDebugSectionOffset() const {
198  const DIEUnit *Unit = getUnit();
199  assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
200  return Unit->getDebugSectionOffset() + getOffset();
201 }
202 
203 const DIE *DIE::getUnitDie() const {
204  const DIE *p = this;
205  while (p) {
206  if (p->getTag() == dwarf::DW_TAG_compile_unit ||
207  p->getTag() == dwarf::DW_TAG_type_unit)
208  return p;
209  p = p->getParent();
210  }
211  return nullptr;
212 }
213 
215  const DIE *UnitDie = getUnitDie();
216  if (UnitDie)
217  return UnitDie->Owner.dyn_cast<DIEUnit*>();
218  return nullptr;
219 }
220 
222  // Iterate through all the attributes until we find the one we're
223  // looking for, if we can't find it return NULL.
224  for (const auto &V : values())
225  if (V.getAttribute() == Attribute)
226  return V;
227  return DIEValue();
228 }
229 
231 static void printValues(raw_ostream &O, const DIEValueList &Values,
232  StringRef Type, unsigned Size, unsigned IndentCount) {
233  O << Type << ": Size: " << Size << "\n";
234 
235  unsigned I = 0;
236  const std::string Indent(IndentCount, ' ');
237  for (const auto &V : Values.values()) {
238  O << Indent;
239  O << "Blk[" << I++ << "]";
240  O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
241  V.print(O);
242  O << "\n";
243  }
244 }
245 
247 void DIE::print(raw_ostream &O, unsigned IndentCount) const {
248  const std::string Indent(IndentCount, ' ');
249  O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this)
250  << ", Offset: " << Offset << ", Size: " << Size << "\n";
251 
252  O << Indent << dwarf::TagString(getTag()) << " "
253  << dwarf::ChildrenString(hasChildren()) << "\n";
254 
255  IndentCount += 2;
256  for (const auto &V : values()) {
257  O << Indent;
258  O << dwarf::AttributeString(V.getAttribute());
259  O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
260  V.print(O);
261  O << "\n";
262  }
263  IndentCount -= 2;
264 
265  for (const auto &Child : children())
266  Child.print(O, IndentCount + 4);
267 
268  O << "\n";
269 }
270 
271 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
273  print(dbgs());
274 }
275 #endif
276 
278  DIEAbbrevSet &AbbrevSet,
279  unsigned CUOffset) {
280  // Unique the abbreviation and fill in the abbreviation number so this DIE
281  // can be emitted.
282  const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
283 
284  // Set compile/type unit relative offset of this DIE.
285  setOffset(CUOffset);
286 
287  // Add the byte size of the abbreviation code.
288  CUOffset += getULEB128Size(getAbbrevNumber());
289 
290  // Add the byte size of all the DIE attribute values.
291  for (const auto &V : values())
292  CUOffset += V.SizeOf(AP);
293 
294  // Let the children compute their offsets and abbreviation numbers.
295  if (hasChildren()) {
296  (void)Abbrev;
297  assert(Abbrev.hasChildren() && "Children flag not set");
298 
299  for (auto &Child : children())
300  CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
301 
302  // Each child chain is terminated with a zero byte, adjust the offset.
303  CUOffset += sizeof(int8_t);
304  }
305 
306  // Compute the byte size of this DIE and all of its children correctly. This
307  // is needed so that top level DIE can help the compile unit set its length
308  // correctly.
309  setSize(CUOffset - getOffset());
310  return CUOffset;
311 }
312 
313 //===----------------------------------------------------------------------===//
314 // DIEUnit Implementation
315 //===----------------------------------------------------------------------===//
316 DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag)
317  : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V),
318  AddrSize(A)
319 {
320  Die.Owner = this;
321  assert((UnitTag == dwarf::DW_TAG_compile_unit ||
322  UnitTag == dwarf::DW_TAG_type_unit ||
323  UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG");
324 }
325 
326 void DIEValue::EmitValue(const AsmPrinter *AP) const {
327  switch (Ty) {
328  case isNone:
329  llvm_unreachable("Expected valid DIEValue");
330 #define HANDLE_DIEVALUE(T) \
331  case is##T: \
332  getDIE##T().EmitValue(AP, Form); \
333  break;
334 #include "llvm/CodeGen/DIEValue.def"
335  }
336 }
337 
338 unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
339  switch (Ty) {
340  case isNone:
341  llvm_unreachable("Expected valid DIEValue");
342 #define HANDLE_DIEVALUE(T) \
343  case is##T: \
344  return getDIE##T().SizeOf(AP, Form);
345 #include "llvm/CodeGen/DIEValue.def"
346  }
347  llvm_unreachable("Unknown DIE kind");
348 }
349 
352  switch (Ty) {
353  case isNone:
354  llvm_unreachable("Expected valid DIEValue");
355 #define HANDLE_DIEVALUE(T) \
356  case is##T: \
357  getDIE##T().print(O); \
358  break;
359 #include "llvm/CodeGen/DIEValue.def"
360  }
361 }
362 
363 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
365  print(dbgs());
366 }
367 #endif
368 
369 //===----------------------------------------------------------------------===//
370 // DIEInteger Implementation
371 //===----------------------------------------------------------------------===//
372 
373 /// EmitValue - Emit integer of appropriate size.
374 ///
376  switch (Form) {
377  case dwarf::DW_FORM_implicit_const:
378  case dwarf::DW_FORM_flag_present:
379  // Emit something to keep the lines and comments in sync.
380  // FIXME: Is there a better way to do this?
381  Asm->OutStreamer->AddBlankLine();
382  return;
383  case dwarf::DW_FORM_flag:
384  case dwarf::DW_FORM_ref1:
385  case dwarf::DW_FORM_data1:
386  case dwarf::DW_FORM_strx1:
387  case dwarf::DW_FORM_addrx1:
388  case dwarf::DW_FORM_ref2:
389  case dwarf::DW_FORM_data2:
390  case dwarf::DW_FORM_strx2:
391  case dwarf::DW_FORM_addrx2:
392  case dwarf::DW_FORM_strx3:
393  case dwarf::DW_FORM_strp:
394  case dwarf::DW_FORM_ref4:
395  case dwarf::DW_FORM_data4:
396  case dwarf::DW_FORM_ref_sup4:
397  case dwarf::DW_FORM_strx4:
398  case dwarf::DW_FORM_addrx4:
399  case dwarf::DW_FORM_ref8:
400  case dwarf::DW_FORM_ref_sig8:
401  case dwarf::DW_FORM_data8:
402  case dwarf::DW_FORM_ref_sup8:
403  case dwarf::DW_FORM_GNU_ref_alt:
404  case dwarf::DW_FORM_GNU_strp_alt:
405  case dwarf::DW_FORM_line_strp:
406  case dwarf::DW_FORM_sec_offset:
407  case dwarf::DW_FORM_strp_sup:
408  case dwarf::DW_FORM_addr:
409  case dwarf::DW_FORM_ref_addr:
410  Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form));
411  return;
412  case dwarf::DW_FORM_GNU_str_index:
413  case dwarf::DW_FORM_GNU_addr_index:
414  case dwarf::DW_FORM_ref_udata:
415  case dwarf::DW_FORM_strx:
416  case dwarf::DW_FORM_addrx:
417  case dwarf::DW_FORM_rnglistx:
418  case dwarf::DW_FORM_udata:
419  Asm->EmitULEB128(Integer);
420  return;
421  case dwarf::DW_FORM_sdata:
422  Asm->EmitSLEB128(Integer);
423  return;
424  default: llvm_unreachable("DIE Value form not supported yet");
425  }
426 }
427 
428 /// SizeOf - Determine size of integer value in bytes.
429 ///
430 unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
431  dwarf::FormParams Params = {0, 0, dwarf::DWARF32};
432  if (AP)
433  Params = {AP->getDwarfVersion(), uint8_t(AP->getPointerSize()),
434  AP->OutStreamer->getContext().getDwarfFormat()};
435 
436  if (Optional<uint8_t> FixedSize = dwarf::getFixedFormByteSize(Form, Params))
437  return *FixedSize;
438 
439  switch (Form) {
440  case dwarf::DW_FORM_GNU_str_index:
441  case dwarf::DW_FORM_GNU_addr_index:
442  case dwarf::DW_FORM_ref_udata:
443  case dwarf::DW_FORM_strx:
444  case dwarf::DW_FORM_addrx:
445  case dwarf::DW_FORM_rnglistx:
446  case dwarf::DW_FORM_udata:
447  return getULEB128Size(Integer);
448  case dwarf::DW_FORM_sdata:
449  return getSLEB128Size(Integer);
450  default: llvm_unreachable("DIE Value form not supported yet");
451  }
452 }
453 
456  O << "Int: " << (int64_t)Integer << " 0x";
457  O.write_hex(Integer);
458 }
459 
460 //===----------------------------------------------------------------------===//
461 // DIEExpr Implementation
462 //===----------------------------------------------------------------------===//
463 
464 /// EmitValue - Emit expression value.
465 ///
467  AP->EmitDebugValue(Expr, SizeOf(AP, Form));
468 }
469 
470 /// SizeOf - Determine size of expression value in bytes.
471 ///
472 unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
473  if (Form == dwarf::DW_FORM_data4) return 4;
474  if (Form == dwarf::DW_FORM_sec_offset) return 4;
475  if (Form == dwarf::DW_FORM_strp) return 4;
476  return AP->getPointerSize();
477 }
478 
480 void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
481 
482 //===----------------------------------------------------------------------===//
483 // DIELabel Implementation
484 //===----------------------------------------------------------------------===//
485 
486 /// EmitValue - Emit label value.
487 ///
489  AP->EmitLabelReference(Label, SizeOf(AP, Form),
490  Form == dwarf::DW_FORM_strp ||
491  Form == dwarf::DW_FORM_sec_offset ||
492  Form == dwarf::DW_FORM_ref_addr ||
493  Form == dwarf::DW_FORM_data4);
494 }
495 
496 /// SizeOf - Determine size of label value in bytes.
497 ///
498 unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
499  if (Form == dwarf::DW_FORM_data4) return 4;
500  if (Form == dwarf::DW_FORM_sec_offset) return 4;
501  if (Form == dwarf::DW_FORM_strp) return 4;
502  return AP->MAI->getCodePointerSize();
503 }
504 
506 void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
507 
508 //===----------------------------------------------------------------------===//
509 // DIEBaseTypeRef Implementation
510 //===----------------------------------------------------------------------===//
511 
513  uint64_t Offset = CU->ExprRefedBaseTypes[Index].Die->getOffset();
514  assert(Offset < (1ULL << (ULEB128PadSize * 7)) && "Offset wont fit");
515  AP->EmitULEB128(Offset, nullptr, ULEB128PadSize);
516 }
517 
518 unsigned DIEBaseTypeRef::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
519  return ULEB128PadSize;
520 }
521 
523 void DIEBaseTypeRef::print(raw_ostream &O) const { O << "BaseTypeRef: " << Index; }
524 
525 //===----------------------------------------------------------------------===//
526 // DIEDelta Implementation
527 //===----------------------------------------------------------------------===//
528 
529 /// EmitValue - Emit delta value.
530 ///
532  AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
533 }
534 
535 /// SizeOf - Determine size of delta value in bytes.
536 ///
537 unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
538  if (Form == dwarf::DW_FORM_data4) return 4;
539  if (Form == dwarf::DW_FORM_sec_offset) return 4;
540  if (Form == dwarf::DW_FORM_strp) return 4;
541  return AP->MAI->getCodePointerSize();
542 }
543 
546  O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
547 }
548 
549 //===----------------------------------------------------------------------===//
550 // DIEString Implementation
551 //===----------------------------------------------------------------------===//
552 
553 /// EmitValue - Emit string value.
554 ///
556  // Index of string in symbol table.
557  switch (Form) {
558  case dwarf::DW_FORM_GNU_str_index:
559  case dwarf::DW_FORM_strx:
560  case dwarf::DW_FORM_strx1:
561  case dwarf::DW_FORM_strx2:
562  case dwarf::DW_FORM_strx3:
563  case dwarf::DW_FORM_strx4:
564  DIEInteger(S.getIndex()).EmitValue(AP, Form);
565  return;
566  case dwarf::DW_FORM_strp:
568  DIELabel(S.getSymbol()).EmitValue(AP, Form);
569  else
570  DIEInteger(S.getOffset()).EmitValue(AP, Form);
571  return;
572  default:
573  llvm_unreachable("Expected valid string form");
574  }
575 }
576 
577 /// SizeOf - Determine size of delta value in bytes.
578 ///
579 unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
580  // Index of string in symbol table.
581  switch (Form) {
582  case dwarf::DW_FORM_GNU_str_index:
583  case dwarf::DW_FORM_strx:
584  case dwarf::DW_FORM_strx1:
585  case dwarf::DW_FORM_strx2:
586  case dwarf::DW_FORM_strx3:
587  case dwarf::DW_FORM_strx4:
588  return DIEInteger(S.getIndex()).SizeOf(AP, Form);
589  case dwarf::DW_FORM_strp:
591  return DIELabel(S.getSymbol()).SizeOf(AP, Form);
592  return DIEInteger(S.getOffset()).SizeOf(AP, Form);
593  default:
594  llvm_unreachable("Expected valid string form");
595  }
596 }
597 
600  O << "String: " << S.getString();
601 }
602 
603 //===----------------------------------------------------------------------===//
604 // DIEInlineString Implementation
605 //===----------------------------------------------------------------------===//
607  if (Form == dwarf::DW_FORM_string) {
608  AP->OutStreamer->EmitBytes(S);
609  AP->emitInt8(0);
610  return;
611  }
612  llvm_unreachable("Expected valid string form");
613 }
614 
616  // Emit string bytes + NULL byte.
617  return S.size() + 1;
618 }
619 
622  O << "InlineString: " << S;
623 }
624 
625 //===----------------------------------------------------------------------===//
626 // DIEEntry Implementation
627 //===----------------------------------------------------------------------===//
628 
629 /// EmitValue - Emit debug information entry offset.
630 ///
632 
633  switch (Form) {
634  case dwarf::DW_FORM_ref1:
635  case dwarf::DW_FORM_ref2:
636  case dwarf::DW_FORM_ref4:
637  case dwarf::DW_FORM_ref8:
638  AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
639  return;
640 
641  case dwarf::DW_FORM_ref_udata:
642  AP->EmitULEB128(Entry->getOffset());
643  return;
644 
645  case dwarf::DW_FORM_ref_addr: {
646  // Get the absolute offset for this DIE within the debug info/types section.
647  unsigned Addr = Entry->getDebugSectionOffset();
648  if (const MCSymbol *SectionSym =
649  Entry->getUnit()->getCrossSectionRelativeBaseAddress()) {
650  AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
651  return;
652  }
653 
654  AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
655  return;
656  }
657  default:
658  llvm_unreachable("Improper form for DIE reference");
659  }
660 }
661 
662 unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
663  switch (Form) {
664  case dwarf::DW_FORM_ref1:
665  return 1;
666  case dwarf::DW_FORM_ref2:
667  return 2;
668  case dwarf::DW_FORM_ref4:
669  return 4;
670  case dwarf::DW_FORM_ref8:
671  return 8;
672  case dwarf::DW_FORM_ref_udata:
673  return getULEB128Size(Entry->getOffset());
674  case dwarf::DW_FORM_ref_addr:
675  if (AP->getDwarfVersion() == 2)
676  return AP->MAI->getCodePointerSize();
677  switch (AP->OutStreamer->getContext().getDwarfFormat()) {
678  case dwarf::DWARF32:
679  return 4;
680  case dwarf::DWARF64:
681  return 8;
682  }
683  llvm_unreachable("Invalid DWARF format");
684 
685  default:
686  llvm_unreachable("Improper form for DIE reference");
687  }
688 }
689 
692  O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
693 }
694 
695 //===----------------------------------------------------------------------===//
696 // DIELoc Implementation
697 //===----------------------------------------------------------------------===//
698 
699 /// ComputeSize - calculate the size of the location expression.
700 ///
701 unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
702  if (!Size) {
703  for (const auto &V : values())
704  Size += V.SizeOf(AP);
705  }
706 
707  return Size;
708 }
709 
710 /// EmitValue - Emit location data.
711 ///
713  switch (Form) {
714  default: llvm_unreachable("Improper form for block");
715  case dwarf::DW_FORM_block1: Asm->emitInt8(Size); break;
716  case dwarf::DW_FORM_block2: Asm->emitInt16(Size); break;
717  case dwarf::DW_FORM_block4: Asm->emitInt32(Size); break;
718  case dwarf::DW_FORM_block:
719  case dwarf::DW_FORM_exprloc:
720  Asm->EmitULEB128(Size); break;
721  }
722 
723  for (const auto &V : values())
724  V.EmitValue(Asm);
725 }
726 
727 /// SizeOf - Determine size of location data in bytes.
728 ///
729 unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
730  switch (Form) {
731  case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
732  case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
733  case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
734  case dwarf::DW_FORM_block:
735  case dwarf::DW_FORM_exprloc:
736  return Size + getULEB128Size(Size);
737  default: llvm_unreachable("Improper form for block");
738  }
739 }
740 
743  printValues(O, *this, "ExprLoc", Size, 5);
744 }
745 
746 //===----------------------------------------------------------------------===//
747 // DIEBlock Implementation
748 //===----------------------------------------------------------------------===//
749 
750 /// ComputeSize - calculate the size of the block.
751 ///
752 unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
753  if (!Size) {
754  for (const auto &V : values())
755  Size += V.SizeOf(AP);
756  }
757 
758  return Size;
759 }
760 
761 /// EmitValue - Emit block data.
762 ///
764  switch (Form) {
765  default: llvm_unreachable("Improper form for block");
766  case dwarf::DW_FORM_block1: Asm->emitInt8(Size); break;
767  case dwarf::DW_FORM_block2: Asm->emitInt16(Size); break;
768  case dwarf::DW_FORM_block4: Asm->emitInt32(Size); break;
769  case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
770  case dwarf::DW_FORM_string: break;
771  case dwarf::DW_FORM_data16: break;
772  }
773 
774  for (const auto &V : values())
775  V.EmitValue(Asm);
776 }
777 
778 /// SizeOf - Determine size of block data in bytes.
779 ///
780 unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
781  switch (Form) {
782  case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
783  case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
784  case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
785  case dwarf::DW_FORM_block: return Size + getULEB128Size(Size);
786  case dwarf::DW_FORM_data16: return 16;
787  default: llvm_unreachable("Improper form for block");
788  }
789 }
790 
793  printValues(O, *this, "Blk", Size, 5);
794 }
795 
796 //===----------------------------------------------------------------------===//
797 // DIELocList Implementation
798 //===----------------------------------------------------------------------===//
799 
800 unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
801  if (Form == dwarf::DW_FORM_data4)
802  return 4;
803  if (Form == dwarf::DW_FORM_sec_offset)
804  return 4;
805  return AP->MAI->getCodePointerSize();
806 }
807 
808 /// EmitValue - Emit label value.
809 ///
811  DwarfDebug *DD = AP->getDwarfDebug();
812  MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
813  AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
814 }
815 
817 void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit debug information entry offset.
Definition: DIE.cpp:631
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:38
void EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit block data.
Definition: DIE.cpp:763
iterator_range< typename GraphTraits< GraphType >::ChildIteratorType > children(const typename GraphTraits< GraphType >::NodeRef &G)
Definition: GraphTraits.h:121
A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...
Definition: Dwarf.h:499
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of location data in bytes.
Definition: DIE.cpp:729
void print(raw_ostream &O) const
Definition: DIE.cpp:621
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:93
void EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit location data.
Definition: DIE.cpp:712
This class represents lattice values for constants.
Definition: AllocatorList.h:23
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:473
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
Attribute
Attributes.
Definition: Dwarf.h:114
const DebugLocStream & getDebugLocs() const
Returns the entries for the .debug_loc section.
Definition: DwarfDebug.h:683
uint16_t getDwarfVersion() const
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:270
void EmitValue(const AsmPrinter *AP) const
Emit value via the Dwarf writer.
Definition: DIE.cpp:326
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:123
unsigned getDebugSectionOffset() const
Definition: DIE.h:874
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form)
Adds another set of attribute information to the abbreviation.
Definition: DIE.h:109
void print(raw_ostream &O) const
Definition: DIE.cpp:742
void dump() const
Definition: DIE.cpp:272
virtual void EmitDebugValue(const MCExpr *Value, unsigned Size) const
Emit the directive and value for debug thread local expression.
Definition: AsmPrinter.cpp:644
void print(raw_ostream &O) const
Definition: DIE.cpp:109
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support...
Definition: DwarfDebug.h:661
int64_t getValue() const
Definition: DIE.h:69
Dwarf abbreviation data, describes one attribute of a Dwarf abbreviation.
Definition: DIE.h:49
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of delta value in bytes.
Definition: DIE.cpp:579
void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
Definition: DIE.cpp:57
void print(raw_ostream &O) const
Definition: DIE.cpp:506
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of the base type reference in bytes.
Definition: DIE.cpp:518
void AddImplicitConstAttribute(dwarf::Attribute Attribute, int64_t Value)
Adds attribute with DW_FORM_implicit_const value.
Definition: DIE.h:114
const DIE * getUnitDie() const
Climb up the parent chain to get the compile unit or type unit DIE that this DIE belongs to...
Definition: DIE.cpp:203
StringRef FormEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:105
void print(raw_ostream &O) const
Definition: DIE.cpp:455
dwarf::Form getForm() const
Definition: DIE.h:68
void AddInteger(signed I)
Definition: FoldingSet.cpp:60
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:800
DIEAbbrev generateAbbrev() const
Generate the abbreviation for this DIE.
Definition: DIE.cpp:186
void print(raw_ostream &O) const
Definition: DIE.cpp:792
unsigned getPointerSize() const
Return the pointer size from the TargetMachine.
Definition: AsmPrinter.cpp:222
StringRef AttributeString(unsigned Attribute)
Definition: Dwarf.cpp:72
void setNumber(unsigned N)
Definition: DIE.h:105
bool doesDwarfUseRelocationsAcrossSections() const
Definition: MCAsmInfo.h:596
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.
A list of DIE values.
Definition: DIE.h:627
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of block data in bytes.
Definition: DIE.cpp:780
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:662
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
Definition: DIE.h:135
void EmitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset, unsigned Size, bool IsSectionRelative=false) const
Emit something like ".long Label+Offset" where the size in bytes of the directive is specified by Siz...
void Emit(const AsmPrinter *AP) const
Print the abbreviation using the specified asm printer.
Definition: DIE.cpp:68
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:305
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit delta value.
Definition: DIE.cpp:531
void print(raw_ostream &O) const
Definition: DIE.cpp:351
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:84
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
void print(raw_ostream &O) const
Definition: DIE.cpp:817
void EmitULEB128(uint64_t Value, const char *Desc=nullptr, unsigned PadTo=0) const
Emit the specified unsigned leb128 value.
void dump() const
Definition: DIE.cpp:132
value_range values()
Definition: DIE.h:688
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:652
bool hasChildren() const
Definition: DIE.h:102
A structured debug information entry.
Definition: DIE.h:700
void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
Definition: DIE.cpp:42
DIEUnit * getUnit() const
Climb up the parent chain to get the compile unit or type unit that this DIE belongs to...
Definition: DIE.cpp:214
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:78
void print(raw_ostream &O) const
Definition: DIE.cpp:480
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit string value.
Definition: DIE.cpp:555
dwarf::Attribute getAttribute() const
Accessors.
Definition: DIE.h:67
static LLVM_DUMP_METHOD void printValues(raw_ostream &O, const DIEValueList &Values, StringRef Type, unsigned Size, unsigned IndentCount)
Definition: DIE.cpp:231
DwarfDebug * getDwarfDebug()
Definition: AsmPrinter.h:190
A label DIE.
Definition: DIE.h:218
void EmitLabelReference(const MCSymbol *Label, unsigned Size, bool IsSectionRelative=false) const
Emit something like ".long Label" where the size in bytes of the directive is specified by Size and L...
Definition: AsmPrinter.h:499
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
void print(raw_ostream &O) const
Definition: DIE.cpp:545
DIE * getParent() const
Definition: DIE.cpp:182
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned computeOffsetsAndAbbrevs(const AsmPrinter *AP, DIEAbbrevSet &AbbrevSet, unsigned CUOffset)
Compute the offset of this DIE and all its children.
Definition: DIE.cpp:277
unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
Definition: LEB128.cpp:19
unsigned SizeOf(const AsmPrinter *AP) const
Return the size of a value in bytes.
Definition: DIE.cpp:338
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of expression value in bytes.
Definition: DIE.cpp:472
void EmitSLEB128(int64_t Value, const char *Desc=nullptr) const
Emit the specified signed leb128 value.
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of label value in bytes.
Definition: DIE.cpp:498
DIEUnit(uint16_t Version, uint8_t AddrSize, dwarf::Tag UnitTag)
Definition: DIE.cpp:316
void dump() const
Definition: DIE.cpp:364
Represents a compile or type unit.
Definition: DIE.h:833
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit base type reference.
Definition: DIE.cpp:512
void print(raw_ostream &O) const
Definition: DIE.cpp:599
static Optional< unsigned > getTag(const TargetRegisterInfo *TRI, const MachineInstr &MI, const LoadInfo &LI)
void emitInt32(int Value) const
Emit a long directive and value.
const List & getList(size_t LI) const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
void emitDwarfAbbrevs(const T &Abbrevs) const
Emit Dwarf abbreviation table.
Definition: AsmPrinter.h:563
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of delta value in bytes.
Definition: DIE.cpp:537
dwarf::Tag getTag() const
Definition: DIE.h:736
static constexpr unsigned ULEB128PadSize
Definition: DwarfDebug.cpp:166
Optional< uint8_t > getFixedFormByteSize(dwarf::Form Form, FormParams Params)
Get the fixed byte size for a given form.
Definition: Dwarf.cpp:628
DIEAbbrev & uniqueAbbreviation(DIE &Die)
Generate the abbreviation declaration for a DIE and return a pointer to the generated abbreviation...
Definition: DIE.cpp:146
An integer value DIE.
Definition: DIE.h:163
Dwarf abbreviation, describes the organization of a debug information object.
Definition: DIE.h:79
void print(raw_ostream &O, unsigned IndentCount=0) const
Definition: DIE.cpp:247
StringRef TagString(unsigned Tag)
Definition: Dwarf.cpp:21
void print(raw_ostream &O) const
Definition: DIE.cpp:523
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
void EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) const
Emit something like ".long Hi-Lo" where the size in bytes of the directive is specified by Size and H...
uint32_t Size
Definition: Profile.cpp:46
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:606
unsigned getSLEB128Size(int64_t Value)
Utility function to get the size of the SLEB128-encoded value.
Definition: LEB128.cpp:29
StringRef ChildrenString(unsigned Children)
Definition: Dwarf.cpp:62
DIEValue findAttribute(dwarf::Attribute Attribute) const
Find a value in the DIE with the attribute given.
Definition: DIE.cpp:221
bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk=true)
Tells whether the specified form is defined in the specified version, or is an extension if extension...
Definition: Dwarf.cpp:715
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition: MCAsmInfo.h:396
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit expression value.
Definition: DIE.cpp:466
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void emitInt8(int Value) const
Emit a byte directive and value.
LLVM Value Representation.
Definition: Value.h:72
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
Definition: DIE.cpp:701
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of integer value in bytes.
Definition: DIE.cpp:430
void setAbbrevNumber(unsigned I)
Set the abbreviation number for this DIE.
Definition: DIE.h:764
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:615
unsigned getDebugSectionOffset() const
Get the absolute offset within the .debug_info or .debug_types section for this DIE.
Definition: DIE.cpp:197
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition: DIE.cpp:810
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
void Emit(const AsmPrinter *AP, MCSection *Section) const
Print all abbreviations using the specified asm printer.
Definition: DIE.cpp:170
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
Definition: DIE.cpp:752
void EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit integer of appropriate size.
Definition: DIE.cpp:375
#define LLVM_DEBUG(X)
Definition: Debug.h:122
const uint64_t Version
Definition: InstrProf.h:984
void print(raw_ostream &O) const
Definition: DIE.cpp:691
void emitInt16(int Value) const
Emit a short directive and value.
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition: DIE.cpp:488