LLVM  3.7.0
DwarfUnit.cpp
Go to the documentation of this file.
1 //===-- llvm/CodeGen/DwarfUnit.cpp - Dwarf Type and Compile Units ---------===//
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 // This file contains support for constructing a dwarf compile unit.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "DwarfUnit.h"
15 #include "DwarfAccelTable.h"
16 #include "DwarfCompileUnit.h"
17 #include "DwarfDebug.h"
18 #include "DwarfExpression.h"
19 #include "llvm/ADT/APFloat.h"
21 #include "llvm/IR/Constants.h"
22 #include "llvm/IR/DIBuilder.h"
23 #include "llvm/IR/DataLayout.h"
24 #include "llvm/IR/GlobalVariable.h"
25 #include "llvm/IR/Instructions.h"
26 #include "llvm/IR/Mangler.h"
27 #include "llvm/MC/MCAsmInfo.h"
28 #include "llvm/MC/MCContext.h"
29 #include "llvm/MC/MCSection.h"
30 #include "llvm/MC/MCStreamer.h"
37 
38 using namespace llvm;
39 
40 #define DEBUG_TYPE "dwarfdebug"
41 
42 static cl::opt<bool>
43 GenerateDwarfTypeUnits("generate-type-units", cl::Hidden,
44  cl::desc("Generate DWARF4 type units."),
45  cl::init(false));
46 
48  DIELoc &DIE)
49  : DwarfExpression(*AP.MF->getSubtarget().getRegisterInfo(),
50  AP.getDwarfDebug()->getDwarfVersion()),
51  AP(AP), DU(DU), DIE(DIE) {}
52 
53 void DIEDwarfExpression::EmitOp(uint8_t Op, const char* Comment) {
55 }
57  DU.addSInt(DIE, dwarf::DW_FORM_sdata, Value);
58 }
60  DU.addUInt(DIE, dwarf::DW_FORM_udata, Value);
61 }
62 bool DIEDwarfExpression::isFrameRegister(unsigned MachineReg) {
63  return MachineReg == TRI.getFrameRegister(*AP.MF);
64 }
65 
66 DwarfUnit::DwarfUnit(unsigned UID, dwarf::Tag UnitTag,
67  const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW,
68  DwarfFile *DWU)
69  : UniqueID(UID), CUNode(Node),
70  UnitDie(*DIE::get(DIEValueAllocator, UnitTag)), DebugInfoOffset(0),
71  Asm(A), DD(DW), DU(DWU), IndexTyDie(nullptr), Section(nullptr) {
72  assert(UnitTag == dwarf::DW_TAG_compile_unit ||
73  UnitTag == dwarf::DW_TAG_type_unit);
74 }
75 
77  DwarfDebug *DW, DwarfFile *DWU,
78  MCDwarfDwoLineTable *SplitLineTable)
79  : DwarfUnit(UID, dwarf::DW_TAG_type_unit, CU.getCUNode(), A, DW, DWU),
80  CU(CU), SplitLineTable(SplitLineTable) {
81  if (SplitLineTable)
83 }
84 
86  for (unsigned j = 0, M = DIEBlocks.size(); j < M; ++j)
87  DIEBlocks[j]->~DIEBlock();
88  for (unsigned j = 0, M = DIELocs.size(); j < M; ++j)
89  DIELocs[j]->~DIELoc();
90 }
91 
92 int64_t DwarfUnit::getDefaultLowerBound() const {
93  switch (getLanguage()) {
94  default:
95  break;
96 
97  case dwarf::DW_LANG_C89:
98  case dwarf::DW_LANG_C99:
99  case dwarf::DW_LANG_C:
100  case dwarf::DW_LANG_C_plus_plus:
101  case dwarf::DW_LANG_ObjC:
102  case dwarf::DW_LANG_ObjC_plus_plus:
103  return 0;
104 
105  case dwarf::DW_LANG_Fortran77:
106  case dwarf::DW_LANG_Fortran90:
107  case dwarf::DW_LANG_Fortran95:
108  return 1;
109 
110  // The languages below have valid values only if the DWARF version >= 4.
111  case dwarf::DW_LANG_Java:
112  case dwarf::DW_LANG_Python:
113  case dwarf::DW_LANG_UPC:
114  case dwarf::DW_LANG_D:
115  if (dwarf::DWARF_VERSION >= 4)
116  return 0;
117  break;
118 
119  case dwarf::DW_LANG_Ada83:
120  case dwarf::DW_LANG_Ada95:
121  case dwarf::DW_LANG_Cobol74:
122  case dwarf::DW_LANG_Cobol85:
123  case dwarf::DW_LANG_Modula2:
124  case dwarf::DW_LANG_Pascal83:
125  case dwarf::DW_LANG_PLI:
126  if (dwarf::DWARF_VERSION >= 4)
127  return 1;
128  break;
129 
130  // The languages below have valid values only if the DWARF version >= 5.
131  case dwarf::DW_LANG_OpenCL:
132  case dwarf::DW_LANG_Go:
133  case dwarf::DW_LANG_Haskell:
134  case dwarf::DW_LANG_C_plus_plus_03:
135  case dwarf::DW_LANG_C_plus_plus_11:
136  case dwarf::DW_LANG_OCaml:
137  case dwarf::DW_LANG_Rust:
138  case dwarf::DW_LANG_C11:
139  case dwarf::DW_LANG_Swift:
140  case dwarf::DW_LANG_Dylan:
141  case dwarf::DW_LANG_C_plus_plus_14:
142  if (dwarf::DWARF_VERSION >= 5)
143  return 0;
144  break;
145 
146  case dwarf::DW_LANG_Modula3:
147  case dwarf::DW_LANG_Julia:
148  case dwarf::DW_LANG_Fortran03:
149  case dwarf::DW_LANG_Fortran08:
150  if (dwarf::DWARF_VERSION >= 5)
151  return 1;
152  break;
153  }
154 
155  return -1;
156 }
157 
158 /// Check whether the DIE for this MDNode can be shared across CUs.
159 static bool isShareableAcrossCUs(const DINode *D) {
160  // When the MDNode can be part of the type system, the DIE can be shared
161  // across CUs.
162  // Combining type units and cross-CU DIE sharing is lower value (since
163  // cross-CU DIE sharing is used in LTO and removes type redundancy at that
164  // level already) but may be implementable for some value in projects
165  // building multiple independent libraries with LTO and then linking those
166  // together.
167  return (isa<DIType>(D) ||
168  (isa<DISubprogram>(D) && !cast<DISubprogram>(D)->isDefinition())) &&
170 }
171 
172 DIE *DwarfUnit::getDIE(const DINode *D) const {
173  if (isShareableAcrossCUs(D))
174  return DU->getDIE(D);
175  return MDNodeToDieMap.lookup(D);
176 }
177 
178 void DwarfUnit::insertDIE(const DINode *Desc, DIE *D) {
179  if (isShareableAcrossCUs(Desc)) {
180  DU->insertDIE(Desc, D);
181  return;
182  }
183  MDNodeToDieMap.insert(std::make_pair(Desc, D));
184 }
185 
187  if (DD->getDwarfVersion() >= 4)
189  DIEInteger(1));
190  else
192  DIEInteger(1));
193 }
194 
196  Optional<dwarf::Form> Form, uint64_t Integer) {
197  if (!Form)
198  Form = DIEInteger::BestForm(false, Integer);
199  Die.addValue(DIEValueAllocator, Attribute, *Form, DIEInteger(Integer));
200 }
201 
202 void DwarfUnit::addUInt(DIE &Block, dwarf::Form Form, uint64_t Integer) {
203  addUInt(Block, (dwarf::Attribute)0, Form, Integer);
204 }
205 
207  Optional<dwarf::Form> Form, int64_t Integer) {
208  if (!Form)
209  Form = DIEInteger::BestForm(true, Integer);
210  Die.addValue(DIEValueAllocator, Attribute, *Form, DIEInteger(Integer));
211 }
212 
214  int64_t Integer) {
215  addSInt(Die, (dwarf::Attribute)0, Form, Integer);
216 }
217 
219  StringRef String) {
220  Die.addValue(DIEValueAllocator, Attribute,
222  DIEString(DU->getStringPool().getEntry(*Asm, String)));
223 }
224 
227  const MCSymbol *Label) {
228  return Die.addValue(DIEValueAllocator, Attribute, Form, DIELabel(Label));
229 }
230 
232  addLabel(Die, (dwarf::Attribute)0, Form, Label);
233 }
234 
236  uint64_t Integer) {
237  if (DD->getDwarfVersion() >= 4)
238  addUInt(Die, Attribute, dwarf::DW_FORM_sec_offset, Integer);
239  else
240  addUInt(Die, Attribute, dwarf::DW_FORM_data4, Integer);
241 }
242 
243 unsigned DwarfTypeUnit::getOrCreateSourceID(StringRef FileName, StringRef DirName) {
244  return SplitLineTable ? SplitLineTable->getFile(DirName, FileName)
245  : getCU().getOrCreateSourceID(FileName, DirName);
246 }
247 
248 void DwarfUnit::addOpAddress(DIELoc &Die, const MCSymbol *Sym) {
249  if (!DD->useSplitDwarf()) {
250  addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
251  addLabel(Die, dwarf::DW_FORM_udata, Sym);
252  } else {
253  addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index);
255  DD->getAddressPool().getIndex(Sym));
256  }
257 }
258 
260  const MCSymbol *Hi, const MCSymbol *Lo) {
262  new (DIEValueAllocator) DIEDelta(Hi, Lo));
263 }
264 
266  addDIEEntry(Die, Attribute, DIEEntry(Entry));
267 }
268 
270  // Flag the type unit reference as a declaration so that if it contains
271  // members (implicit special members, static data member definitions, member
272  // declarations for definitions in this CU, etc) consumers don't get confused
273  // and think this is a full definition.
275 
278 }
279 
281  DIEEntry Entry) {
282  const DIE *DieCU = Die.getUnitOrNull();
283  const DIE *EntryCU = Entry.getEntry().getUnitOrNull();
284  if (!DieCU)
285  // We assume that Die belongs to this CU, if it is not linked to any CU yet.
286  DieCU = &getUnitDie();
287  if (!EntryCU)
288  EntryCU = &getUnitDie();
289  Die.addValue(DIEValueAllocator, Attribute,
290  EntryCU == DieCU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,
291  Entry);
292 }
293 
294 DIE &DwarfUnit::createAndAddDIE(unsigned Tag, DIE &Parent, const DINode *N) {
295  assert(Tag != dwarf::DW_TAG_auto_variable &&
296  Tag != dwarf::DW_TAG_arg_variable);
297  DIE &Die = Parent.addChild(DIE::get(DIEValueAllocator, (dwarf::Tag)Tag));
298  if (N)
299  insertDIE(N, &Die);
300  return Die;
301 }
302 
304  Loc->ComputeSize(Asm);
305  DIELocs.push_back(Loc); // Memoize so we can call the destructor later on.
306  Die.addValue(DIEValueAllocator, Attribute,
307  Loc->BestForm(DD->getDwarfVersion()), Loc);
308 }
309 
311  DIEBlock *Block) {
312  Block->ComputeSize(Asm);
313  DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.
314  Die.addValue(DIEValueAllocator, Attribute, Block->BestForm(), Block);
315 }
316 
317 void DwarfUnit::addSourceLine(DIE &Die, unsigned Line, StringRef File,
318  StringRef Directory) {
319  if (Line == 0)
320  return;
321 
322  unsigned FileID = getOrCreateSourceID(File, Directory);
323  assert(FileID && "Invalid file id");
324  addUInt(Die, dwarf::DW_AT_decl_file, None, FileID);
325  addUInt(Die, dwarf::DW_AT_decl_line, None, Line);
326 }
327 
329  assert(V);
330 
331  addSourceLine(Die, V->getLine(), V->getScope()->getFilename(),
332  V->getScope()->getDirectory());
333 }
334 
336  assert(G);
337 
338  addSourceLine(Die, G->getLine(), G->getFilename(), G->getDirectory());
339 }
340 
342  assert(SP);
343 
344  addSourceLine(Die, SP->getLine(), SP->getFilename(), SP->getDirectory());
345 }
346 
347 void DwarfUnit::addSourceLine(DIE &Die, const DIType *Ty) {
348  assert(Ty);
349 
350  addSourceLine(Die, Ty->getLine(), Ty->getFilename(), Ty->getDirectory());
351 }
352 
354  assert(Ty);
355 
356  addSourceLine(Die, Ty->getLine(), Ty->getFilename(), Ty->getDirectory());
357 }
358 
359 void DwarfUnit::addSourceLine(DIE &Die, const DINamespace *NS) {
360  addSourceLine(Die, NS->getLine(), NS->getFilename(), NS->getDirectory());
361 }
362 
363 bool DwarfUnit::addRegisterOpPiece(DIELoc &TheDie, unsigned Reg,
364  unsigned SizeInBits, unsigned OffsetInBits) {
365  DIEDwarfExpression Expr(*Asm, *this, TheDie);
366  Expr.AddMachineRegPiece(Reg, SizeInBits, OffsetInBits);
367  return true;
368 }
369 
370 bool DwarfUnit::addRegisterOffset(DIELoc &TheDie, unsigned Reg,
371  int64_t Offset) {
372  DIEDwarfExpression Expr(*Asm, *this, TheDie);
373  return Expr.AddMachineRegIndirect(Reg, Offset);
374 }
375 
376 /* Byref variables, in Blocks, are declared by the programmer as "SomeType
377  VarName;", but the compiler creates a __Block_byref_x_VarName struct, and
378  gives the variable VarName either the struct, or a pointer to the struct, as
379  its type. This is necessary for various behind-the-scenes things the
380  compiler needs to do with by-reference variables in Blocks.
381 
382  However, as far as the original *programmer* is concerned, the variable
383  should still have type 'SomeType', as originally declared.
384 
385  The function getBlockByrefType dives into the __Block_byref_x_VarName
386  struct to find the original type of the variable, which is then assigned to
387  the variable's Debug Information Entry as its real type. So far, so good.
388  However now the debugger will expect the variable VarName to have the type
389  SomeType. So we need the location attribute for the variable to be an
390  expression that explains to the debugger how to navigate through the
391  pointers and struct to find the actual variable of type SomeType.
392 
393  The following function does just that. We start by getting
394  the "normal" location for the variable. This will be the location
395  of either the struct __Block_byref_x_VarName or the pointer to the
396  struct __Block_byref_x_VarName.
397 
398  The struct will look something like:
399 
400  struct __Block_byref_x_VarName {
401  ... <various fields>
402  struct __Block_byref_x_VarName *forwarding;
403  ... <various other fields>
404  SomeType VarName;
405  ... <maybe more fields>
406  };
407 
408  If we are given the struct directly (as our starting point) we
409  need to tell the debugger to:
410 
411  1). Add the offset of the forwarding field.
412 
413  2). Follow that pointer to get the real __Block_byref_x_VarName
414  struct to use (the real one may have been copied onto the heap).
415 
416  3). Add the offset for the field VarName, to find the actual variable.
417 
418  If we started with a pointer to the struct, then we need to
419  dereference that pointer first, before the other steps.
420  Translating this into DWARF ops, we will need to append the following
421  to the current location description for the variable:
422 
423  DW_OP_deref -- optional, if we start with a pointer
424  DW_OP_plus_uconst <forward_fld_offset>
425  DW_OP_deref
426  DW_OP_plus_uconst <varName_fld_offset>
427 
428  That is what this function does. */
429 
432  const MachineLocation &Location) {
433  const DIType *Ty = DV.getType();
434  const DIType *TmpTy = Ty;
435  uint16_t Tag = Ty->getTag();
436  bool isPointer = false;
437 
438  StringRef varName = DV.getName();
439 
440  if (Tag == dwarf::DW_TAG_pointer_type) {
441  auto *DTy = cast<DIDerivedType>(Ty);
442  TmpTy = resolve(DTy->getBaseType());
443  isPointer = true;
444  }
445 
446  // Find the __forwarding field and the variable field in the __Block_byref
447  // struct.
448  DINodeArray Fields = cast<DICompositeTypeBase>(TmpTy)->getElements();
449  const DIDerivedType *varField = nullptr;
450  const DIDerivedType *forwardingField = nullptr;
451 
452  for (unsigned i = 0, N = Fields.size(); i < N; ++i) {
453  auto *DT = cast<DIDerivedType>(Fields[i]);
454  StringRef fieldName = DT->getName();
455  if (fieldName == "__forwarding")
456  forwardingField = DT;
457  else if (fieldName == varName)
458  varField = DT;
459  }
460 
461  // Get the offsets for the forwarding field and the variable field.
462  unsigned forwardingFieldOffset = forwardingField->getOffsetInBits() >> 3;
463  unsigned varFieldOffset = varField->getOffsetInBits() >> 2;
464 
465  // Decode the original location, and use that as the start of the byref
466  // variable's location.
467  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
468 
469  bool validReg;
470  if (Location.isReg())
471  validReg = addRegisterOpPiece(*Loc, Location.getReg());
472  else
473  validReg = addRegisterOffset(*Loc, Location.getReg(), Location.getOffset());
474 
475  if (!validReg)
476  return;
477 
478  // If we started with a pointer to the __Block_byref... struct, then
479  // the first thing we need to do is dereference the pointer (DW_OP_deref).
480  if (isPointer)
481  addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
482 
483  // Next add the offset for the '__forwarding' field:
484  // DW_OP_plus_uconst ForwardingFieldOffset. Note there's no point in
485  // adding the offset if it's 0.
486  if (forwardingFieldOffset > 0) {
487  addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
488  addUInt(*Loc, dwarf::DW_FORM_udata, forwardingFieldOffset);
489  }
490 
491  // Now dereference the __forwarding field to get to the real __Block_byref
492  // struct: DW_OP_deref.
493  addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
494 
495  // Now that we've got the real __Block_byref... struct, add the offset
496  // for the variable's field to get to the location of the actual variable:
497  // DW_OP_plus_uconst varFieldOffset. Again, don't add if it's 0.
498  if (varFieldOffset > 0) {
499  addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
500  addUInt(*Loc, dwarf::DW_FORM_udata, varFieldOffset);
501  }
502 
503  // Now attach the location information to the DIE.
504  addBlock(Die, Attribute, Loc);
505 }
506 
507 /// Return true if type encoding is unsigned.
508 static bool isUnsignedDIType(DwarfDebug *DD, const DIType *Ty) {
509  if (auto *DTy = dyn_cast<DIDerivedTypeBase>(Ty)) {
510  dwarf::Tag T = (dwarf::Tag)Ty->getTag();
511  // Encode pointer constants as unsigned bytes. This is used at least for
512  // null pointer constant emission.
513  // (Pieces of) aggregate types that get hacked apart by SROA may also be
514  // represented by a constant. Encode them as unsigned bytes.
515  // FIXME: reference and rvalue_reference /probably/ shouldn't be allowed
516  // here, but accept them for now due to a bug in SROA producing bogus
517  // dbg.values.
518  if (T == dwarf::DW_TAG_array_type ||
519  T == dwarf::DW_TAG_class_type ||
520  T == dwarf::DW_TAG_pointer_type ||
521  T == dwarf::DW_TAG_ptr_to_member_type ||
522  T == dwarf::DW_TAG_reference_type ||
523  T == dwarf::DW_TAG_rvalue_reference_type ||
524  T == dwarf::DW_TAG_structure_type ||
525  T == dwarf::DW_TAG_union_type)
526  return true;
527  assert(T == dwarf::DW_TAG_typedef || T == dwarf::DW_TAG_const_type ||
528  T == dwarf::DW_TAG_volatile_type ||
529  T == dwarf::DW_TAG_restrict_type ||
530  T == dwarf::DW_TAG_enumeration_type);
531  if (DITypeRef Deriv = DTy->getBaseType())
532  return isUnsignedDIType(DD, DD->resolve(Deriv));
533  // FIXME: Enums without a fixed underlying type have unknown signedness
534  // here, leading to incorrectly emitted constants.
535  assert(DTy->getTag() == dwarf::DW_TAG_enumeration_type);
536  return false;
537  }
538 
539  auto *BTy = cast<DIBasicType>(Ty);
540  unsigned Encoding = BTy->getEncoding();
541  assert((Encoding == dwarf::DW_ATE_unsigned ||
542  Encoding == dwarf::DW_ATE_unsigned_char ||
543  Encoding == dwarf::DW_ATE_signed ||
544  Encoding == dwarf::DW_ATE_signed_char ||
545  Encoding == dwarf::DW_ATE_float || Encoding == dwarf::DW_ATE_UTF ||
546  Encoding == dwarf::DW_ATE_boolean ||
547  (Ty->getTag() == dwarf::DW_TAG_unspecified_type &&
548  Ty->getName() == "decltype(nullptr)")) &&
549  "Unsupported encoding");
550  return Encoding == dwarf::DW_ATE_unsigned ||
551  Encoding == dwarf::DW_ATE_unsigned_char ||
552  Encoding == dwarf::DW_ATE_UTF || Encoding == dwarf::DW_ATE_boolean ||
553  Ty->getTag() == dwarf::DW_TAG_unspecified_type;
554 }
555 
556 /// If this type is derived from a base type then return base type size.
557 static uint64_t getBaseTypeSize(DwarfDebug *DD, const DIDerivedType *Ty) {
558  unsigned Tag = Ty->getTag();
559 
560  if (Tag != dwarf::DW_TAG_member && Tag != dwarf::DW_TAG_typedef &&
561  Tag != dwarf::DW_TAG_const_type && Tag != dwarf::DW_TAG_volatile_type &&
562  Tag != dwarf::DW_TAG_restrict_type)
563  return Ty->getSizeInBits();
564 
565  auto *BaseType = DD->resolve(Ty->getBaseType());
566 
567  assert(BaseType && "Unexpected invalid base type");
568 
569  // If this is a derived type, go ahead and get the base type, unless it's a
570  // reference then it's just the size of the field. Pointer types have no need
571  // of this since they're a different type of qualification on the type.
572  if (BaseType->getTag() == dwarf::DW_TAG_reference_type ||
573  BaseType->getTag() == dwarf::DW_TAG_rvalue_reference_type)
574  return Ty->getSizeInBits();
575 
576  if (auto *DT = dyn_cast<DIDerivedType>(BaseType))
577  return getBaseTypeSize(DD, DT);
578 
579  return BaseType->getSizeInBits();
580 }
581 
583  assert(MO.isFPImm() && "Invalid machine operand!");
585  APFloat FPImm = MO.getFPImm()->getValueAPF();
586 
587  // Get the raw data form of the floating point.
588  const APInt FltVal = FPImm.bitcastToAPInt();
589  const char *FltPtr = (const char *)FltVal.getRawData();
590 
591  int NumBytes = FltVal.getBitWidth() / 8; // 8 bits per byte.
592  bool LittleEndian = Asm->getDataLayout().isLittleEndian();
593  int Incr = (LittleEndian ? 1 : -1);
594  int Start = (LittleEndian ? 0 : NumBytes - 1);
595  int Stop = (LittleEndian ? NumBytes : -1);
596 
597  // Output the constant to DWARF one byte at a time.
598  for (; Start != Stop; Start += Incr)
599  addUInt(*Block, dwarf::DW_FORM_data1, (unsigned char)0xFF & FltPtr[Start]);
600 
601  addBlock(Die, dwarf::DW_AT_const_value, Block);
602 }
603 
605  // Pass this down to addConstantValue as an unsigned bag of bits.
606  addConstantValue(Die, CFP->getValueAPF().bitcastToAPInt(), true);
607 }
608 
610  const DIType *Ty) {
611  addConstantValue(Die, CI->getValue(), Ty);
612 }
613 
615  const DIType *Ty) {
616  assert(MO.isImm() && "Invalid machine operand!");
617 
618  addConstantValue(Die, isUnsignedDIType(DD, Ty), MO.getImm());
619 }
620 
621 void DwarfUnit::addConstantValue(DIE &Die, bool Unsigned, uint64_t Val) {
622  // FIXME: This is a bit conservative/simple - it emits negative values always
623  // sign extended to 64 bits rather than minimizing the number of bytes.
625  Unsigned ? dwarf::DW_FORM_udata : dwarf::DW_FORM_sdata, Val);
626 }
627 
628 void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, const DIType *Ty) {
629  addConstantValue(Die, Val, isUnsignedDIType(DD, Ty));
630 }
631 
632 void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, bool Unsigned) {
633  unsigned CIBitWidth = Val.getBitWidth();
634  if (CIBitWidth <= 64) {
635  addConstantValue(Die, Unsigned,
636  Unsigned ? Val.getZExtValue() : Val.getSExtValue());
637  return;
638  }
639 
641 
642  // Get the raw data form of the large APInt.
643  const uint64_t *Ptr64 = Val.getRawData();
644 
645  int NumBytes = Val.getBitWidth() / 8; // 8 bits per byte.
646  bool LittleEndian = Asm->getDataLayout().isLittleEndian();
647 
648  // Output the constant to DWARF one byte at a time.
649  for (int i = 0; i < NumBytes; i++) {
650  uint8_t c;
651  if (LittleEndian)
652  c = Ptr64[i / 8] >> (8 * (i & 7));
653  else
654  c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7));
655  addUInt(*Block, dwarf::DW_FORM_data1, c);
656  }
657 
658  addBlock(Die, dwarf::DW_AT_const_value, Block);
659 }
660 
661 void DwarfUnit::addLinkageName(DIE &Die, StringRef LinkageName) {
662  if (!LinkageName.empty())
663  addString(Die,
666  GlobalValue::getRealLinkageName(LinkageName));
667 }
668 
669 void DwarfUnit::addTemplateParams(DIE &Buffer, DINodeArray TParams) {
670  // Add template parameters.
671  for (const auto *Element : TParams) {
672  if (auto *TTP = dyn_cast<DITemplateTypeParameter>(Element))
673  constructTemplateTypeParameterDIE(Buffer, TTP);
674  else if (auto *TVP = dyn_cast<DITemplateValueParameter>(Element))
675  constructTemplateValueParameterDIE(Buffer, TVP);
676  }
677 }
678 
680  if (!Context || isa<DIFile>(Context))
681  return &getUnitDie();
682  if (auto *T = dyn_cast<DIType>(Context))
683  return getOrCreateTypeDIE(T);
684  if (auto *NS = dyn_cast<DINamespace>(Context))
685  return getOrCreateNameSpace(NS);
686  if (auto *SP = dyn_cast<DISubprogram>(Context))
688  return getDIE(Context);
689 }
690 
692  auto *Context = resolve(Ty->getScope());
693  DIE *ContextDIE = getOrCreateContextDIE(Context);
694 
695  if (DIE *TyDIE = getDIE(Ty))
696  return TyDIE;
697 
698  // Create new type.
699  DIE &TyDIE = createAndAddDIE(Ty->getTag(), *ContextDIE, Ty);
700 
701  constructTypeDIE(TyDIE, cast<DICompositeType>(Ty));
702 
703  updateAcceleratorTables(Context, Ty, TyDIE);
704  return &TyDIE;
705 }
706 
708  if (!TyNode)
709  return nullptr;
710 
711  auto *Ty = cast<DIType>(TyNode);
712  assert(Ty == resolve(Ty->getRef()) &&
713  "type was not uniqued, possible ODR violation.");
714 
715  // DW_TAG_restrict_type is not supported in DWARF2
716  if (Ty->getTag() == dwarf::DW_TAG_restrict_type && DD->getDwarfVersion() <= 2)
717  return getOrCreateTypeDIE(resolve(cast<DIDerivedType>(Ty)->getBaseType()));
718 
719  // Construct the context before querying for the existence of the DIE in case
720  // such construction creates the DIE.
721  auto *Context = resolve(Ty->getScope());
722  DIE *ContextDIE = getOrCreateContextDIE(Context);
723  assert(ContextDIE);
724 
725  if (DIE *TyDIE = getDIE(Ty))
726  return TyDIE;
727 
728  // Create new type.
729  DIE &TyDIE = createAndAddDIE(Ty->getTag(), *ContextDIE, Ty);
730 
731  updateAcceleratorTables(Context, Ty, TyDIE);
732 
733  if (auto *BT = dyn_cast<DIBasicType>(Ty))
734  constructTypeDIE(TyDIE, BT);
735  else if (auto *STy = dyn_cast<DISubroutineType>(Ty))
736  constructTypeDIE(TyDIE, STy);
737  else if (auto *CTy = dyn_cast<DICompositeType>(Ty)) {
738  if (GenerateDwarfTypeUnits && !Ty->isForwardDecl())
739  if (MDString *TypeId = CTy->getRawIdentifier()) {
740  DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
741  // Skip updating the accelerator tables since this is not the full type.
742  return &TyDIE;
743  }
744  constructTypeDIE(TyDIE, CTy);
745  } else {
746  constructTypeDIE(TyDIE, cast<DIDerivedType>(Ty));
747  }
748 
749  return &TyDIE;
750 }
751 
752 void DwarfUnit::updateAcceleratorTables(const DIScope *Context,
753  const DIType *Ty, const DIE &TyDIE) {
754  if (!Ty->getName().empty() && !Ty->isForwardDecl()) {
755  bool IsImplementation = 0;
756  if (auto *CT = dyn_cast<DICompositeTypeBase>(Ty)) {
757  // A runtime language of 0 actually means C/C++ and that any
758  // non-negative value is some version of Objective-C/C++.
759  IsImplementation = CT->getRuntimeLang() == 0 || CT->isObjcClassComplete();
760  }
761  unsigned Flags = IsImplementation ? dwarf::DW_FLAG_type_implementation : 0;
762  DD->addAccelType(Ty->getName(), TyDIE, Flags);
763 
764  if (!Context || isa<DICompileUnit>(Context) || isa<DIFile>(Context) ||
765  isa<DINamespace>(Context))
766  addGlobalType(Ty, TyDIE, Context);
767  }
768 }
769 
770 void DwarfUnit::addType(DIE &Entity, const DIType *Ty,
772  assert(Ty && "Trying to add a type that doesn't exist?");
773  addDIEEntry(Entity, Attribute, DIEEntry(*getOrCreateTypeDIE(Ty)));
774 }
775 
776 std::string DwarfUnit::getParentContextString(const DIScope *Context) const {
777  if (!Context)
778  return "";
779 
780  // FIXME: Decide whether to implement this for non-C++ languages.
781  if (getLanguage() != dwarf::DW_LANG_C_plus_plus)
782  return "";
783 
784  std::string CS;
786  while (!isa<DICompileUnit>(Context)) {
787  Parents.push_back(Context);
788  if (Context->getScope())
789  Context = resolve(Context->getScope());
790  else
791  // Structure, etc types will have a NULL context if they're at the top
792  // level.
793  break;
794  }
795 
796  // Reverse iterate over our list to go from the outermost construct to the
797  // innermost.
798  for (auto I = Parents.rbegin(), E = Parents.rend(); I != E; ++I) {
799  const DIScope *Ctx = *I;
800  StringRef Name = Ctx->getName();
801  if (Name.empty() && isa<DINamespace>(Ctx))
802  Name = "(anonymous namespace)";
803  if (!Name.empty()) {
804  CS += Name;
805  CS += "::";
806  }
807  }
808  return CS;
809 }
810 
811 void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIBasicType *BTy) {
812  // Get core information.
813  StringRef Name = BTy->getName();
814  // Add name if not anonymous or intermediate type.
815  if (!Name.empty())
816  addString(Buffer, dwarf::DW_AT_name, Name);
817 
818  // An unspecified type only has a name attribute.
819  if (BTy->getTag() == dwarf::DW_TAG_unspecified_type)
820  return;
821 
823  BTy->getEncoding());
824 
825  uint64_t Size = BTy->getSizeInBits() >> 3;
826  addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
827 }
828 
829 void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy) {
830  // Get core information.
831  StringRef Name = DTy->getName();
832  uint64_t Size = DTy->getSizeInBits() >> 3;
833  uint16_t Tag = Buffer.getTag();
834 
835  // Map to main type, void will not have a type.
836  const DIType *FromTy = resolve(DTy->getBaseType());
837  if (FromTy)
838  addType(Buffer, FromTy);
839 
840  // Add name if not anonymous or intermediate type.
841  if (!Name.empty())
842  addString(Buffer, dwarf::DW_AT_name, Name);
843 
844  // Add size if non-zero (derived types might be zero-sized.)
845  if (Size && Tag != dwarf::DW_TAG_pointer_type
846  && Tag != dwarf::DW_TAG_ptr_to_member_type)
847  addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
848 
849  if (Tag == dwarf::DW_TAG_ptr_to_member_type)
850  addDIEEntry(
852  *getOrCreateTypeDIE(resolve(cast<DIDerivedType>(DTy)->getClassType())));
853  // Add source line info if available and TyDesc is not a forward declaration.
854  if (!DTy->isForwardDecl())
855  addSourceLine(Buffer, DTy);
856 }
857 
859  for (unsigned i = 1, N = Args.size(); i < N; ++i) {
860  const DIType *Ty = resolve(Args[i]);
861  if (!Ty) {
862  assert(i == N-1 && "Unspecified parameter must be the last argument");
863  createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, Buffer);
864  } else {
865  DIE &Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, Buffer);
866  addType(Arg, Ty);
867  if (Ty->isArtificial())
869  }
870  }
871 }
872 
873 void DwarfUnit::constructTypeDIE(DIE &Buffer, const DISubroutineType *CTy) {
874  // Add return type. A void return won't have a type.
875  auto Elements = cast<DISubroutineType>(CTy)->getTypeArray();
876  if (Elements.size())
877  if (auto RTy = resolve(Elements[0]))
878  addType(Buffer, RTy);
879 
880  bool isPrototyped = true;
881  if (Elements.size() == 2 && !Elements[1])
882  isPrototyped = false;
883 
884  constructSubprogramArguments(Buffer, Elements);
885 
886  // Add prototype flag if we're dealing with a C language and the function has
887  // been prototyped.
888  uint16_t Language = getLanguage();
889  if (isPrototyped &&
890  (Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
891  Language == dwarf::DW_LANG_ObjC))
893 
894  if (CTy->isLValueReference())
896 
897  if (CTy->isRValueReference())
899 }
900 
902  // Add name if not anonymous or intermediate type.
903  StringRef Name = CTy->getName();
904 
905  uint64_t Size = CTy->getSizeInBits() >> 3;
906  uint16_t Tag = Buffer.getTag();
907 
908  switch (Tag) {
909  case dwarf::DW_TAG_array_type:
910  constructArrayTypeDIE(Buffer, CTy);
911  break;
912  case dwarf::DW_TAG_enumeration_type:
913  constructEnumTypeDIE(Buffer, CTy);
914  break;
915  case dwarf::DW_TAG_structure_type:
916  case dwarf::DW_TAG_union_type:
917  case dwarf::DW_TAG_class_type: {
918  // Add elements to structure type.
919  DINodeArray Elements = CTy->getElements();
920  for (const auto *Element : Elements) {
921  if (!Element)
922  continue;
923  if (auto *SP = dyn_cast<DISubprogram>(Element))
925  else if (auto *DDTy = dyn_cast<DIDerivedType>(Element)) {
926  if (DDTy->getTag() == dwarf::DW_TAG_friend) {
927  DIE &ElemDie = createAndAddDIE(dwarf::DW_TAG_friend, Buffer);
928  addType(ElemDie, resolve(DDTy->getBaseType()), dwarf::DW_AT_friend);
929  } else if (DDTy->isStaticMember()) {
931  } else {
932  constructMemberDIE(Buffer, DDTy);
933  }
934  } else if (auto *Property = dyn_cast<DIObjCProperty>(Element)) {
935  DIE &ElemDie = createAndAddDIE(Property->getTag(), Buffer);
936  StringRef PropertyName = Property->getName();
937  addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);
938  if (Property->getType())
939  addType(ElemDie, resolve(Property->getType()));
940  addSourceLine(ElemDie, Property);
941  StringRef GetterName = Property->getGetterName();
942  if (!GetterName.empty())
943  addString(ElemDie, dwarf::DW_AT_APPLE_property_getter, GetterName);
944  StringRef SetterName = Property->getSetterName();
945  if (!SetterName.empty())
946  addString(ElemDie, dwarf::DW_AT_APPLE_property_setter, SetterName);
947  if (unsigned PropertyAttributes = Property->getAttributes())
949  PropertyAttributes);
950  }
951  }
952 
953  if (CTy->isAppleBlockExtension())
955 
956  // This is outside the DWARF spec, but GDB expects a DW_AT_containing_type
957  // inside C++ composite types to point to the base class with the vtable.
958  if (auto *ContainingType =
959  dyn_cast_or_null<DICompositeType>(resolve(CTy->getVTableHolder())))
961  *getOrCreateTypeDIE(ContainingType));
962 
963  if (CTy->isObjcClassComplete())
965 
966  // Add template parameters to a class, structure or union types.
967  // FIXME: The support isn't in the metadata for this yet.
968  if (Tag == dwarf::DW_TAG_class_type ||
969  Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type)
970  addTemplateParams(Buffer, CTy->getTemplateParams());
971 
972  break;
973  }
974  default:
975  break;
976  }
977 
978  // Add name if not anonymous or intermediate type.
979  if (!Name.empty())
980  addString(Buffer, dwarf::DW_AT_name, Name);
981 
982  if (Tag == dwarf::DW_TAG_enumeration_type ||
983  Tag == dwarf::DW_TAG_class_type || Tag == dwarf::DW_TAG_structure_type ||
984  Tag == dwarf::DW_TAG_union_type) {
985  // Add size if non-zero (derived types might be zero-sized.)
986  // TODO: Do we care about size for enum forward declarations?
987  if (Size)
988  addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
989  else if (!CTy->isForwardDecl())
990  // Add zero size if it is not a forward declaration.
991  addUInt(Buffer, dwarf::DW_AT_byte_size, None, 0);
992 
993  // If we're a forward decl, say so.
994  if (CTy->isForwardDecl())
996 
997  // Add source line info if available.
998  if (!CTy->isForwardDecl())
999  addSourceLine(Buffer, CTy);
1000 
1001  // No harm in adding the runtime language to the declaration.
1002  unsigned RLang = CTy->getRuntimeLang();
1003  if (RLang)
1005  RLang);
1006  }
1007 }
1008 
1009 void DwarfUnit::constructTemplateTypeParameterDIE(
1010  DIE &Buffer, const DITemplateTypeParameter *TP) {
1011  DIE &ParamDIE =
1012  createAndAddDIE(dwarf::DW_TAG_template_type_parameter, Buffer);
1013  // Add the type if it exists, it could be void and therefore no type.
1014  if (TP->getType())
1015  addType(ParamDIE, resolve(TP->getType()));
1016  if (!TP->getName().empty())
1017  addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
1018 }
1019 
1020 void DwarfUnit::constructTemplateValueParameterDIE(
1021  DIE &Buffer, const DITemplateValueParameter *VP) {
1022  DIE &ParamDIE = createAndAddDIE(VP->getTag(), Buffer);
1023 
1024  // Add the type if there is one, template template and template parameter
1025  // packs will not have a type.
1026  if (VP->getTag() == dwarf::DW_TAG_template_value_parameter)
1027  addType(ParamDIE, resolve(VP->getType()));
1028  if (!VP->getName().empty())
1029  addString(ParamDIE, dwarf::DW_AT_name, VP->getName());
1030  if (Metadata *Val = VP->getValue()) {
1031  if (ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Val))
1032  addConstantValue(ParamDIE, CI, resolve(VP->getType()));
1033  else if (GlobalValue *GV = mdconst::dyn_extract<GlobalValue>(Val)) {
1034  // For declaration non-type template parameters (such as global values and
1035  // functions)
1036  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1037  addOpAddress(*Loc, Asm->getSymbol(GV));
1038  // Emit DW_OP_stack_value to use the address as the immediate value of the
1039  // parameter, rather than a pointer to it.
1040  addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
1041  addBlock(ParamDIE, dwarf::DW_AT_location, Loc);
1042  } else if (VP->getTag() == dwarf::DW_TAG_GNU_template_template_param) {
1043  assert(isa<MDString>(Val));
1045  cast<MDString>(Val)->getString());
1046  } else if (VP->getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) {
1047  addTemplateParams(ParamDIE, cast<MDTuple>(Val));
1048  }
1049  }
1050 }
1051 
1053  // Construct the context before querying for the existence of the DIE in case
1054  // such construction creates the DIE.
1055  DIE *ContextDIE = getOrCreateContextDIE(NS->getScope());
1056 
1057  if (DIE *NDie = getDIE(NS))
1058  return NDie;
1059  DIE &NDie = createAndAddDIE(dwarf::DW_TAG_namespace, *ContextDIE, NS);
1060 
1061  StringRef Name = NS->getName();
1062  if (!Name.empty())
1063  addString(NDie, dwarf::DW_AT_name, NS->getName());
1064  else
1065  Name = "(anonymous namespace)";
1066  DD->addAccelNamespace(Name, NDie);
1067  addGlobalName(Name, NDie, NS->getScope());
1068  addSourceLine(NDie, NS);
1069  return &NDie;
1070 }
1071 
1073  // Construct the context before querying for the existence of the DIE in case
1074  // such construction creates the DIE.
1075  DIE *ContextDIE = getOrCreateContextDIE(M->getScope());
1076 
1077  if (DIE *MDie = getDIE(M))
1078  return MDie;
1079  DIE &MDie = createAndAddDIE(dwarf::DW_TAG_module, *ContextDIE, M);
1080 
1081  if (!M->getName().empty()) {
1082  addString(MDie, dwarf::DW_AT_name, M->getName());
1083  addGlobalName(M->getName(), MDie, M->getScope());
1084  }
1085  if (!M->getConfigurationMacros().empty())
1087  M->getConfigurationMacros());
1088  if (!M->getIncludePath().empty())
1090  if (!M->getISysRoot().empty())
1092 
1093  return &MDie;
1094 }
1095 
1097  // Construct the context before querying for the existence of the DIE in case
1098  // such construction creates the DIE (as is the case for member function
1099  // declarations).
1100  DIE *ContextDIE =
1101  Minimal ? &getUnitDie() : getOrCreateContextDIE(resolve(SP->getScope()));
1102 
1103  if (DIE *SPDie = getDIE(SP))
1104  return SPDie;
1105 
1106  if (auto *SPDecl = SP->getDeclaration()) {
1107  if (!Minimal) {
1108  // Add subprogram definitions to the CU die directly.
1109  ContextDIE = &getUnitDie();
1110  // Build the decl now to ensure it precedes the definition.
1111  getOrCreateSubprogramDIE(SPDecl);
1112  }
1113  }
1114 
1115  // DW_TAG_inlined_subroutine may refer to this DIE.
1116  DIE &SPDie = createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, SP);
1117 
1118  // Stop here and fill this in later, depending on whether or not this
1119  // subprogram turns out to have inlined instances or not.
1120  if (SP->isDefinition())
1121  return &SPDie;
1122 
1123  applySubprogramAttributes(SP, SPDie);
1124  return &SPDie;
1125 }
1126 
1128  DIE &SPDie) {
1129  DIE *DeclDie = nullptr;
1130  StringRef DeclLinkageName;
1131  if (auto *SPDecl = SP->getDeclaration()) {
1132  DeclDie = getDIE(SPDecl);
1133  assert(DeclDie && "This DIE should've already been constructed when the "
1134  "definition DIE was created in "
1135  "getOrCreateSubprogramDIE");
1136  DeclLinkageName = SPDecl->getLinkageName();
1137  }
1138 
1139  // Add function template parameters.
1140  addTemplateParams(SPDie, SP->getTemplateParams());
1141 
1142  // Add the linkage name if we have one and it isn't in the Decl.
1143  StringRef LinkageName = SP->getLinkageName();
1144  assert(((LinkageName.empty() || DeclLinkageName.empty()) ||
1145  LinkageName == DeclLinkageName) &&
1146  "decl has a linkage name and it is different");
1147  if (DeclLinkageName.empty())
1148  addLinkageName(SPDie, LinkageName);
1149 
1150  if (!DeclDie)
1151  return false;
1152 
1153  // Refer to the function declaration where all the other attributes will be
1154  // found.
1155  addDIEEntry(SPDie, dwarf::DW_AT_specification, *DeclDie);
1156  return true;
1157 }
1158 
1160  bool Minimal) {
1161  if (!Minimal)
1162  if (applySubprogramDefinitionAttributes(SP, SPDie))
1163  return;
1164 
1165  // Constructors and operators for anonymous aggregates do not have names.
1166  if (!SP->getName().empty())
1167  addString(SPDie, dwarf::DW_AT_name, SP->getName());
1168 
1169  // Skip the rest of the attributes under -gmlt to save space.
1170  if (Minimal)
1171  return;
1172 
1173  addSourceLine(SPDie, SP);
1174 
1175  // Add the prototype if we have a prototype and we have a C like
1176  // language.
1177  uint16_t Language = getLanguage();
1178  if (SP->isPrototyped() &&
1179  (Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
1180  Language == dwarf::DW_LANG_ObjC))
1182 
1183  const DISubroutineType *SPTy = SP->getType();
1184  assert(SPTy->getTag() == dwarf::DW_TAG_subroutine_type &&
1185  "the type of a subprogram should be a subroutine");
1186 
1187  auto Args = SPTy->getTypeArray();
1188  // Add a return type. If this is a type like a C/C++ void type we don't add a
1189  // return type.
1190  if (Args.size())
1191  if (auto Ty = resolve(Args[0]))
1192  addType(SPDie, Ty);
1193 
1194  unsigned VK = SP->getVirtuality();
1195  if (VK) {
1197  DIELoc *Block = getDIELoc();
1198  addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1199  addUInt(*Block, dwarf::DW_FORM_udata, SP->getVirtualIndex());
1201  ContainingTypeMap.insert(
1202  std::make_pair(&SPDie, resolve(SP->getContainingType())));
1203  }
1204 
1205  if (!SP->isDefinition()) {
1207 
1208  // Add arguments. Do not add arguments for subprogram definition. They will
1209  // be handled while processing variables.
1210  constructSubprogramArguments(SPDie, Args);
1211  }
1212 
1213  if (SP->isArtificial())
1215 
1216  if (!SP->isLocalToUnit())
1218 
1219  if (SP->isOptimized())
1221 
1222  if (unsigned isa = Asm->getISAEncoding())
1224 
1225  if (SP->isLValueReference())
1227 
1228  if (SP->isRValueReference())
1230 
1231  if (SP->isProtected())
1234  else if (SP->isPrivate())
1237  else if (SP->isPublic())
1240 
1241  if (SP->isExplicit())
1243 }
1244 
1245 void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR,
1246  DIE *IndexTy) {
1247  DIE &DW_Subrange = createAndAddDIE(dwarf::DW_TAG_subrange_type, Buffer);
1248  addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IndexTy);
1249 
1250  // The LowerBound value defines the lower bounds which is typically zero for
1251  // C/C++. The Count value is the number of elements. Values are 64 bit. If
1252  // Count == -1 then the array is unbounded and we do not emit
1253  // DW_AT_lower_bound and DW_AT_count attributes.
1254  int64_t LowerBound = SR->getLowerBound();
1255  int64_t DefaultLowerBound = getDefaultLowerBound();
1256  int64_t Count = SR->getCount();
1257 
1258  if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound)
1259  addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, None, LowerBound);
1260 
1261  if (Count != -1)
1262  // FIXME: An unbounded array should reference the expression that defines
1263  // the array.
1264  addUInt(DW_Subrange, dwarf::DW_AT_count, None, Count);
1265 }
1266 
1267 DIE *DwarfUnit::getIndexTyDie() {
1268  if (IndexTyDie)
1269  return IndexTyDie;
1270  // Construct an integer type to use for indexes.
1271  IndexTyDie = &createAndAddDIE(dwarf::DW_TAG_base_type, UnitDie);
1272  addString(*IndexTyDie, dwarf::DW_AT_name, "sizetype");
1273  addUInt(*IndexTyDie, dwarf::DW_AT_byte_size, None, sizeof(int64_t));
1275  dwarf::DW_ATE_unsigned);
1276  return IndexTyDie;
1277 }
1278 
1279 void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
1280  if (CTy->isVector())
1282 
1283  // Emit the element type.
1284  addType(Buffer, resolve(CTy->getBaseType()));
1285 
1286  // Get an anonymous type for index type.
1287  // FIXME: This type should be passed down from the front end
1288  // as different languages may have different sizes for indexes.
1289  DIE *IdxTy = getIndexTyDie();
1290 
1291  // Add subranges to array type.
1292  DINodeArray Elements = CTy->getElements();
1293  for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
1294  // FIXME: Should this really be such a loose cast?
1295  if (auto *Element = dyn_cast_or_null<DINode>(Elements[i]))
1296  if (Element->getTag() == dwarf::DW_TAG_subrange_type)
1297  constructSubrangeDIE(Buffer, cast<DISubrange>(Element), IdxTy);
1298  }
1299 }
1300 
1301 void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
1302  DINodeArray Elements = CTy->getElements();
1303 
1304  // Add enumerators to enumeration type.
1305  for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
1306  auto *Enum = dyn_cast_or_null<DIEnumerator>(Elements[i]);
1307  if (Enum) {
1308  DIE &Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer);
1309  StringRef Name = Enum->getName();
1310  addString(Enumerator, dwarf::DW_AT_name, Name);
1311  int64_t Value = Enum->getValue();
1313  Value);
1314  }
1315  }
1316  const DIType *DTy = resolve(CTy->getBaseType());
1317  if (DTy) {
1318  addType(Buffer, DTy);
1320  }
1321 }
1322 
1324  for (auto CI = ContainingTypeMap.begin(), CE = ContainingTypeMap.end();
1325  CI != CE; ++CI) {
1326  DIE &SPDie = *CI->first;
1327  const DINode *D = CI->second;
1328  if (!D)
1329  continue;
1330  DIE *NDie = getDIE(D);
1331  if (!NDie)
1332  continue;
1334  }
1335 }
1336 
1337 void DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
1338  DIE &MemberDie = createAndAddDIE(DT->getTag(), Buffer);
1339  StringRef Name = DT->getName();
1340  if (!Name.empty())
1341  addString(MemberDie, dwarf::DW_AT_name, Name);
1342 
1343  addType(MemberDie, resolve(DT->getBaseType()));
1344 
1345  addSourceLine(MemberDie, DT);
1346 
1347  if (DT->getTag() == dwarf::DW_TAG_inheritance && DT->isVirtual()) {
1348 
1349  // For C++, virtual base classes are not at fixed offset. Use following
1350  // expression to extract appropriate offset from vtable.
1351  // BaseAddr = ObAddr + *((*ObAddr) - Offset)
1352 
1353  DIELoc *VBaseLocationDie = new (DIEValueAllocator) DIELoc;
1354  addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_dup);
1355  addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1356  addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1357  addUInt(*VBaseLocationDie, dwarf::DW_FORM_udata, DT->getOffsetInBits());
1358  addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_minus);
1359  addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1360  addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
1361 
1362  addBlock(MemberDie, dwarf::DW_AT_data_member_location, VBaseLocationDie);
1363  } else {
1364  uint64_t Size = DT->getSizeInBits();
1365  uint64_t FieldSize = getBaseTypeSize(DD, DT);
1366  uint64_t OffsetInBytes;
1367 
1368  if (FieldSize && Size != FieldSize) {
1369  // Handle bitfield, assume bytes are 8 bits.
1370  addUInt(MemberDie, dwarf::DW_AT_byte_size, None, FieldSize/8);
1371  addUInt(MemberDie, dwarf::DW_AT_bit_size, None, Size);
1372  //
1373  // The DWARF 2 DW_AT_bit_offset is counting the bits between the most
1374  // significant bit of the aligned storage unit containing the bit field to
1375  // the most significan bit of the bit field.
1376  //
1377  // FIXME: DWARF 4 states that DW_AT_data_bit_offset (which
1378  // counts from the beginning, regardless of endianness) should
1379  // be used instead.
1380  //
1381  //
1382  // Struct Align Align Align
1383  // v v v v
1384  // +-----------+-----*-----+-----*-----+--
1385  // | ... |b1|b2|b3|b4|
1386  // +-----------+-----*-----+-----*-----+--
1387  // | | |<-- Size ->| |
1388  // |<---- Offset --->| |<--->|
1389  // | | | \_ DW_AT_bit_offset (little endian)
1390  // | |<--->|
1391  // |<--------->| \_ StartBitOffset = DW_AT_bit_offset (big endian)
1392  // \ = DW_AT_data_bit_offset (biendian)
1393  // \_ OffsetInBytes
1394  uint64_t Offset = DT->getOffsetInBits();
1395  uint64_t Align = DT->getAlignInBits() ? DT->getAlignInBits() : FieldSize;
1396  uint64_t AlignMask = ~(Align - 1);
1397  // The bits from the start of the storage unit to the start of the field.
1398  uint64_t StartBitOffset = Offset - (Offset & AlignMask);
1399  // The endian-dependent DWARF 2 offset.
1400  uint64_t DwarfBitOffset = Asm->getDataLayout().isLittleEndian()
1401  ? OffsetToAlignment(Offset + Size, Align)
1402  : StartBitOffset;
1403 
1404  // The byte offset of the field's aligned storage unit inside the struct.
1405  OffsetInBytes = (Offset - StartBitOffset) / 8;
1406  addUInt(MemberDie, dwarf::DW_AT_bit_offset, None, DwarfBitOffset);
1407  } else
1408  // This is not a bitfield.
1409  OffsetInBytes = DT->getOffsetInBits() / 8;
1410 
1411  if (DD->getDwarfVersion() <= 2) {
1412  DIELoc *MemLocationDie = new (DIEValueAllocator) DIELoc;
1413  addUInt(*MemLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
1414  addUInt(*MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes);
1415  addBlock(MemberDie, dwarf::DW_AT_data_member_location, MemLocationDie);
1416  } else
1418  OffsetInBytes);
1419  }
1420 
1421  if (DT->isProtected())
1424  else if (DT->isPrivate())
1427  // Otherwise C++ member and base classes are considered public.
1428  else if (DT->isPublic())
1431  if (DT->isVirtual())
1433  dwarf::DW_VIRTUALITY_virtual);
1434 
1435  // Objective-C properties.
1436  if (DINode *PNode = DT->getObjCProperty())
1437  if (DIE *PDie = getDIE(PNode))
1439  dwarf::DW_FORM_ref4, DIEEntry(*PDie));
1440 
1441  if (DT->isArtificial())
1442  addFlag(MemberDie, dwarf::DW_AT_artificial);
1443 }
1444 
1446  if (!DT)
1447  return nullptr;
1448 
1449  // Construct the context before querying for the existence of the DIE in case
1450  // such construction creates the DIE.
1451  DIE *ContextDIE = getOrCreateContextDIE(resolve(DT->getScope()));
1452  assert(dwarf::isType(ContextDIE->getTag()) &&
1453  "Static member should belong to a type.");
1454 
1455  if (DIE *StaticMemberDIE = getDIE(DT))
1456  return StaticMemberDIE;
1457 
1458  DIE &StaticMemberDIE = createAndAddDIE(DT->getTag(), *ContextDIE, DT);
1459 
1460  const DIType *Ty = resolve(DT->getBaseType());
1461 
1462  addString(StaticMemberDIE, dwarf::DW_AT_name, DT->getName());
1463  addType(StaticMemberDIE, Ty);
1464  addSourceLine(StaticMemberDIE, DT);
1465  addFlag(StaticMemberDIE, dwarf::DW_AT_external);
1466  addFlag(StaticMemberDIE, dwarf::DW_AT_declaration);
1467 
1468  // FIXME: We could omit private if the parent is a class_type, and
1469  // public if the parent is something else.
1470  if (DT->isProtected())
1473  else if (DT->isPrivate())
1476  else if (DT->isPublic())
1479 
1480  if (const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(DT->getConstant()))
1481  addConstantValue(StaticMemberDIE, CI, Ty);
1482  if (const ConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT->getConstant()))
1483  addConstantFPValue(StaticMemberDIE, CFP);
1484 
1485  return &StaticMemberDIE;
1486 }
1487 
1488 void DwarfUnit::emitHeader(bool UseOffsets) {
1489  // Emit size of content not including length itself
1490  Asm->OutStreamer->AddComment("Length of Unit");
1492 
1493  Asm->OutStreamer->AddComment("DWARF version number");
1495  Asm->OutStreamer->AddComment("Offset Into Abbrev. Section");
1496 
1497  // We share one abbreviations table across all units so it's always at the
1498  // start of the section. Use a relocatable offset where needed to ensure
1499  // linking doesn't invalidate that offset.
1502  UseOffsets);
1503 
1504  Asm->OutStreamer->AddComment("Address Size (in bytes)");
1506 }
1507 
1509  assert(!this->Section);
1510  this->Section = Section;
1511 }
1512 
1513 void DwarfTypeUnit::emitHeader(bool UseOffsets) {
1514  DwarfUnit::emitHeader(UseOffsets);
1515  Asm->OutStreamer->AddComment("Type Signature");
1516  Asm->OutStreamer->EmitIntValue(TypeSignature, sizeof(TypeSignature));
1517  Asm->OutStreamer->AddComment("Type DIE Offset");
1518  // In a skeleton type unit there is no type DIE so emit a zero offset.
1519  Asm->OutStreamer->EmitIntValue(Ty ? Ty->getOffset() : 0,
1520  sizeof(Ty->getOffset()));
1521 }
1522 
1523 bool DwarfTypeUnit::isDwoUnit() const {
1524  // Since there are no skeleton type units, all type units are dwo type units
1525  // when split DWARF is being used.
1526  return DD->useSplitDwarf();
1527 }
StringRef getName() const
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:48
bool isVector() const
static bool isUnsignedDIType(DwarfDebug *DD, const DIType *Ty)
Return true if type encoding is unsigned.
Definition: DwarfUnit.cpp:508
void addFlag(DIE &Die, dwarf::Attribute Attribute)
Add a flag that is true to the DIE.
Definition: DwarfUnit.cpp:186
MCSection * Section
The section this unit will be emitted in.
Definition: DwarfUnit.h:111
bool isArtificial() const
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1327
void addLabelDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
Add a label delta attribute data and value.
Definition: DwarfUnit.cpp:259
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:83
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:339
std::vector< DIELoc * > DIELocs
A list of all the DIELocs in use.
Definition: DwarfUnit.h:103
DIELoc - Represents an expression location.
Definition: DIE.h:748
DIE * getOrCreateStaticMemberDIE(const DIDerivedType *DT)
Create new static data member DIE.
Definition: DwarfUnit.cpp:1445
const ConstantFP * getFPImm() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:139
void EmitInt8(int Value) const
Emit a byte directive and value.
static bool isShareableAcrossCUs(const DINode *D)
Check whether the DIE for this MDNode can be shared across CUs.
Definition: DwarfUnit.cpp:159
DIE & getEntry() const
Definition: DIE.h:244
DILocalScope * getScope() const
Get the local scope for this variable.
bool isRValueReference() const
virtual void addGlobalType(const DIType *Ty, const DIE &Die, const DIScope *Context)
Add a new global type to the compile unit.
Definition: DwarfUnit.h:162
void insertDIE(const DINode *Desc, DIE *D)
Insert DIE into the map.
Definition: DwarfUnit.cpp:178
uint64_t getAlignInBits() const
int64_t getCount() const
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:207
const MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:86
Base class containing the logic for constructing DWARF expressions independently of whether they are ...
StringRef getDirectory() const
virtual ~DwarfUnit()
Definition: DwarfUnit.cpp:85
DIE & getUnitDie()
Definition: DwarfUnit.h:140
void EmitSigned(int64_t Value) override
Emit a raw signed value.
Definition: DwarfUnit.cpp:56
dwarf::Form BestForm(unsigned DwarfVersion) const
BestForm - Choose the best form for data.
Definition: DIE.h:760
StringRef getName() const
Metadata node.
Definition: Metadata.h:740
static StringRef getString(const MDString *S)
void EmitInt32(int Value) const
Emit a long directive and value.
DINodeArray getElements() const
Get the elements of the composite type.
StringRef getName() const
Definition: DwarfDebug.h:135
void initSection(MCSection *Section)
Definition: DwarfUnit.cpp:1508
void addType(DIE &Entity, const DIType *Ty, dwarf::Attribute Attribute=dwarf::DW_AT_type)
Add a new type attribute to the specified entity.
Definition: DwarfUnit.cpp:770
virtual DwarfCompileUnit & getCU()=0
AsmPrinter * Asm
Target of Dwarf emission.
Definition: DwarfUnit.h:86
Tagged DWARF-like metadata node.
DIE * getOrCreateTypeDIE(const MDNode *N)
Find existing DIE or create new DIE for the given type.
Definition: DwarfUnit.cpp:707
void addAccelNamespace(StringRef Name, const DIE &Die)
void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy)
Definition: DwarfUnit.cpp:901
virtual void addGlobalName(StringRef Name, DIE &Die, const DIScope *Context)
Add a new global name to the compile unit.
Definition: DwarfUnit.h:158
void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Block)
Add block data.
Definition: DwarfUnit.cpp:303
virtual void emitHeader(bool UseOffsets)
Emit the header for this unit, not including the initial length field.
Definition: DwarfUnit.cpp:1488
DIScope * getScope() const
StringRef getName() const
A signature reference to a type unit.
Definition: DIE.h:262
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:106
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
Array subrange.
void addSInt(DIE &Die, dwarf::Attribute Attribute, Optional< dwarf::Form > Form, int64_t Integer)
Add an signed integer attribute data and value.
Definition: DwarfUnit.cpp:206
virtual unsigned getOrCreateSourceID(StringRef File, StringRef Directory)=0
Look up the source ID with the given directory and source file names.
T * resolve(TypedDINodeRef< T > Ref) const
Look in the DwarfDebug map for the MDNode that corresponds to the reference.
Definition: DwarfUnit.h:344
static cl::opt< bool > GenerateDwarfTypeUnits("generate-type-units", cl::Hidden, cl::desc("Generate DWARF4 type units."), cl::init(false))
void addConstantFPValue(DIE &Die, const MachineOperand &MO)
Add constant value entry in variable DIE.
Definition: DwarfUnit.cpp:582
unsigned getLine() const
Reg
All possible values of the reg field in the ModR/M byte.
value_iterator addValue(BumpPtrAllocator &Alloc, DIEValue Value)
addValue - Add a value and attributes to a DIE.
Definition: DIE.h:716
bool addRegisterOffset(DIELoc &TheDie, unsigned Reg, int64_t Offset)
Add register offset.
Definition: DwarfUnit.cpp:370
bool isPrivate() const
void EmitOp(uint8_t Op, const char *Comment=nullptr) override
Output a dwarf operand and an optional assembler comment.
Definition: DwarfUnit.cpp:53
StringRef getFilename() const
bool isAppleBlockExtension() const
void constructContainingTypeDIEs()
Construct DIEs for types that contain vtables.
Definition: DwarfUnit.cpp:1323
Pointer union between a subclass of DINode and MDString.
virtual unsigned getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
DITypeRefArray getTypeArray() const
#define G(x, y, z)
Definition: MD5.cpp:52
DenseMap< DIE *, const DINode * > ContainingTypeMap
This map is used to keep track of subprogram DIEs that need DW_AT_containing_type attribute...
Definition: DwarfUnit.h:108
void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str)
Add a string attribute data and value.
Definition: DwarfUnit.cpp:218
AddressPool & getAddressPool()
Definition: DwarfDebug.h:613
unsigned size() const
Subprogram description.
DITemplateParameterArray getTemplateParams() const
This class is used to track local variable information.
Definition: DwarfDebug.h:81
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
void EmitInt16(int Value) const
Emit a short directive and value.
DwarfCompileUnit & getCU() override
Definition: DwarfUnit.h:404
bool isLittleEndian() const
Layout endianness...
Definition: DataLayout.h:217
DIScopeRef getScope() const
virtual unsigned getHeaderSize() const
Compute the size of a header for this unit, not including the initial length field.
Definition: DwarfUnit.h:321
DITypeRef getVTableHolder() const
StringRef getConfigurationMacros() const
int64_t getImm() const
DIE * getOrCreateNameSpace(const DINamespace *NS)
Definition: DwarfUnit.cpp:1052
bool addRegisterOpPiece(DIELoc &TheDie, unsigned Reg, unsigned SizeInBits=0, unsigned OffsetInBits=0)
Add register operand.
Definition: DwarfUnit.cpp:363
DIE & addChild(DIE *Child)
Add a child to the DIE.
Definition: DIE.h:726
dwarf::Tag getTag() const
Definition: DIE.h:663
DIScopeRef getScope() const
unsigned getLine() const
StringRef getDirectory() const
void addConstantValue(DIE &Die, const MachineOperand &MO, const DIType *Ty)
Add constant value entry in variable DIE.
Definition: DwarfUnit.cpp:614
bool isVirtual() const
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
Definition: DIE.h:657
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support...
Definition: DwarfDebug.h:573
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
Definition: APFloat.h:122
StringRef getIncludePath() const
This dwarf writer support class manages information associated with a source file.
Definition: DwarfUnit.h:68
DIEDwarfExpression(const AsmPrinter &AP, DwarfUnit &DU, DIELoc &DIE)
Definition: DwarfUnit.cpp:47
DwarfStringPool & getStringPool()
Returns the string pool.
Definition: DwarfFile.h:97
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:325
unsigned getFile(StringRef Directory, StringRef FileName)
Definition: MCDwarf.h:206
const DIType * getType() const
Definition: DwarfDebug.cpp:144
bool applySubprogramDefinitionAttributes(const DISubprogram *SP, DIE &SPDie)
Definition: DwarfUnit.cpp:1127
StringRef getName() const
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
void EmitUnsigned(uint64_t Value) override
Emit a raw unsigned value.
Definition: DwarfUnit.cpp:59
void addSourceLine(DIE &Die, unsigned Line, StringRef File, StringRef Directory)
Add location information to specified debug information entry.
Definition: DwarfUnit.cpp:317
const DIE * getUnitOrNull() const
Similar to getUnit, returns null when DIE is not added to an owner yet.
Definition: DIE.cpp:127
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1339
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DIE - A structured debug information entry.
Definition: DIE.h:623
DIELoc * getDIELoc()
Returns a fresh newly allocated DIELoc.
Definition: DwarfUnit.h:176
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:233
static dwarf::Form BestForm(bool IsSigned, uint64_t Int)
BestForm - Choose the best form for integer.
Definition: DIE.h:120
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:66
void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier, DIE &Die, const DICompositeType *CTy)
Add a DIE to the set of types that we're going to pull into type units.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
DenseMap< const MDNode *, DIE * > MDNodeToDieMap
Tracks the mapping of unit level debug information variables to debug information entries...
Definition: DwarfUnit.h:97
DIScope * getScope() const
T * resolve(TypedDINodeRef< T > Ref) const
Find the MDNode for the given reference.
Definition: DwarfDebug.h:594
unsigned getSize() const
Definition: DIE.h:665
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1273
void addAccelType(StringRef Name, const DIE &Die, char Flags)
DIELabel - A label DIE.
Definition: DIE.h:175
DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal=false)
Definition: DwarfUnit.cpp:1096
LLVM_ATTRIBUTE_UNUSED_RESULT bool isa(const Y &Val)
Definition: Casting.h:132
unsigned getEncoding() const
uint64_t getOffsetInBits() const
DITypeRef getBaseType() const
bool isLValueReference() const
DIEString - A container for string values.
Definition: DIE.h:214
static uint64_t getBaseTypeSize(DwarfDebug *DD, const DIDerivedType *Ty)
If this type is derived from a base type then return base type size.
Definition: DwarfUnit.cpp:557
DIE * IndexTyDie
An anonymous type for index type. Owned by UnitDie.
Definition: DwarfUnit.h:93
DIE * getDIE(const DINode *D) const
Returns the DIE map slot for the specified debug variable.
Definition: DwarfUnit.cpp:172
bool isProtected() const
Base class for scope-like contexts.
DIEDelta - A simple label difference DIE.
Definition: DIE.h:196
void insertDIE(const MDNode *TypeMD, DIE *Die)
Definition: DwarfFile.h:110
StringRef getDirectory() const
StringRef getFilename() const
StringRef getISysRoot() const
unsigned getOrCreateSourceID(StringRef FileName, StringRef DirName) override
Look up the source ID with the given directory and source file names.
bool AddMachineRegIndirect(unsigned MachineReg, int Offset=0)
Emit an indirect dwarf register operation for the given machine register.
unsigned getTag() const
Base class for types.
This is the shared class of boolean and integer constants.
Definition: Constants.h:47
uint16_t getLanguage() const
Definition: DwarfUnit.h:138
MachineOperand class - Representation of each machine instruction operand.
bool isPublic() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
bool isType(Tag T)
Definition: Dwarf.h:64
void addLinkageName(DIE &Die, StringRef LinkageName)
Add a linkage name, if it isn't empty.
Definition: DwarfUnit.cpp:661
MCSymbol * getBeginSymbol()
Definition: MCSection.h:113
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
void addTemplateParams(DIE &Buffer, DINodeArray TParams)
Add template parameters in buffer.
Definition: DwarfUnit.cpp:669
StringRef getFilename() const
bool isFPImm() const
isFPImm - Tests if this is a MO_FPImmediate operand.
DwarfDebug * DD
Definition: DwarfUnit.h:89
Class for arbitrary precision integers.
Definition: APInt.h:73
A (clang) module that has been imported by the compile unit.
bool isForwardDecl() const
APInt bitcastToAPInt() const
Definition: APFloat.cpp:3084
std::string getParentContextString(const DIScope *Context) const
Get string containing language specific context for a global name.
Definition: DwarfUnit.cpp:776
void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry)
Add a DIE attribute data and value.
Definition: DwarfUnit.cpp:265
DIE::value_iterator addLabel(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form, const MCSymbol *Label)
Add a Dwarf label attribute data and value.
Definition: DwarfUnit.cpp:225
DIE * getOrCreateContextDIE(const DIScope *Context)
Get context owner's DIE.
Definition: DwarfUnit.cpp:679
Type array for a subprogram.
unsigned getRuntimeLang() const
DIEInteger - An integer value DIE.
Definition: DIE.h:112
static StringRef getRealLinkageName(StringRef Name)
If special LLVM prefix that is used to inform the asm printer to not emit usual symbol prefix before ...
Definition: GlobalValue.h:306
dwarf::Form BestForm() const
BestForm - Choose the best form for data.
Definition: DIE.h:796
EntryRef getEntry(AsmPrinter &Asm, StringRef Str)
Get a reference to an entry in the string pool.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
Definition: APInt.h:573
DwarfTypeUnit(unsigned UID, DwarfCompileUnit &CU, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, MCDwarfDwoLineTable *SplitLineTable=nullptr)
Definition: DwarfUnit.cpp:76
DIE & createAndAddDIE(unsigned Tag, DIE &Parent, const DINode *N=nullptr)
Create a DIE with the given Tag, add the DIE to its parent, and call insertDIE if MD is not null...
Definition: DwarfUnit.cpp:294
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
DwarfUnit(unsigned UID, dwarf::Tag, const DICompileUnit *CU, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU)
Definition: DwarfUnit.cpp:66
DIE * getDIE(const MDNode *TypeMD)
Definition: DwarfFile.h:113
void emitHeader(bool UseOffsets) override
Emit the header for this unit, not including the initial length field.
Definition: DwarfUnit.cpp:1513
DIE * getOrCreateModule(const DIModule *M)
Definition: DwarfUnit.cpp:1072
uint64_t getSizeInBits() const
void addBlockByrefAddress(const DbgVariable &DV, DIE &Die, dwarf::Attribute Attribute, const MachineLocation &Location)
Start with the address based on the location provided, and generate the DWARF information necessary t...
Definition: DwarfUnit.cpp:430
DIE * createTypeDIE(const DICompositeType *Ty)
Get context owner's DIE.
Definition: DwarfUnit.cpp:691
virtual unsigned getISAEncoding()
Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.
Definition: AsmPrinter.h:435
void addSectionOffset(DIE &Die, dwarf::Attribute Attribute, uint64_t Integer)
Add an offset into a section attribute data and value.
Definition: DwarfUnit.cpp:235
DwarfExpression implementation for singular DW_AT_location.
bool isObjcClassComplete() const
const APFloat & getValueAPF() const
Definition: Constants.h:270
bool isFrameRegister(unsigned MachineReg) override
Return whether the given machine register is the frame register in the current function.
Definition: DwarfUnit.cpp:62
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:134
BumpPtrAllocator DIEValueAllocator
Definition: DwarfUnit.h:77
void addDIETypeSignature(DIE &Die, const DwarfTypeUnit &Type)
Definition: DwarfUnit.cpp:269
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
Definition: DIE.cpp:559
LLVM Value Representation.
Definition: Value.h:69
unsigned getLine() const
DIE & UnitDie
Unit debug information entry.
Definition: DwarfUnit.h:80
unsigned getLine() const
uint64_t OffsetToAlignment(uint64_t Value, uint64_t Align)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
Definition: MathExtras.h:616
std::vector< DIEBlock * > DIEBlocks
A list of all the DIEBlocks in use.
Definition: DwarfUnit.h:100
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
Definition: DIE.cpp:506
void addOpAddress(DIELoc &Die, const MCSymbol *Label)
Add a dwarf op address data and value using the form given and an op of either DW_FORM_addr or DW_FOR...
Definition: DwarfUnit.cpp:248
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
A single uniqued string.
Definition: Metadata.h:508
int64_t getLowerBound() const
DIEBlock - Represents a block of values.
Definition: DIE.h:784
MCSection * getDwarfAbbrevSection() const
DwarfFile * DU
Definition: DwarfUnit.h:90
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
Definition: DataLayout.cpp:593
void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, bool Minimal=false)
Definition: DwarfUnit.cpp:1159
unsigned getReg() const
void constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args)
Construct function argument DIEs.
Definition: DwarfUnit.cpp:858
unsigned getDwarfVersion() const
Returns the Dwarf Version.
Definition: DwarfDebug.h:576
Root of the metadata hierarchy.
Definition: Metadata.h:45
void addUInt(DIE &Die, dwarf::Attribute Attribute, Optional< dwarf::Form > Form, uint64_t Integer)
Add an unsigned integer attribute data and value.
Definition: DwarfUnit.cpp:195
const TargetRegisterInfo & TRI
bool AddMachineRegPiece(unsigned MachineReg, unsigned PieceSizeInBits=0, unsigned PieceOffsetInBits=0)
Emit a partial DWARF register operation.
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110
Basic type, like 'int' or 'float'.
unsigned getIndex(const MCSymbol *Sym, bool TLS=false)
Returns the index into the address pool with the given label/symbol.
Definition: AddressPool.cpp:19