llvm.org GIT mirror llvm / 7f76d29
DebugInfo: Gut DIType and subclasses Continuing PR23080, gut `DIType` and its various subclasses, leaving behind thin wrappers around the pointer types in the new debug info hierarchy. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235064 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 5 years ago
10 changed file(s) with 204 addition(s) and 263 deletion(s). Raw diff Collapse all Expand all
236236
237237 DIScopeRef DIScope::getContext() const { return get()->getScope(); }
238238
239 /// \brief This is a wrapper for a type.
240 ///
241 /// FIXME: Types should be factored much better so that CV qualifiers and
242 /// others do not require a huge and empty descriptor full of zeros.
243 class DIType : public DIScope {
244 public:
245 DIType() = default;
246 DIType(const MDType *N) : DIScope(N) {}
247
248 MDType *get() const { return cast_or_null(DIDescriptor::get()); }
249 operator MDType *() const { return get(); }
250 MDType *operator->() const { return get(); }
251 MDType &operator*() const { return *get(); }
252
253 DIScopeRef getContext() const { return get()->getScope(); }
254 StringRef getName() const { return get()->getName(); }
255 unsigned getLineNumber() const { return get()->getLine(); }
256 uint64_t getSizeInBits() const { return get()->getSizeInBits(); }
257 uint64_t getAlignInBits() const { return get()->getAlignInBits(); }
258 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
259 // carry this is just plain insane.
260 uint64_t getOffsetInBits() const { return get()->getOffsetInBits(); }
261 unsigned getFlags() const { return get()->getFlags(); }
262
263 bool isPrivate() const { return get()->isPrivate(); }
264 bool isProtected() const { return get()->isProtected(); }
265 bool isPublic() const { return get()->isPublic(); }
266 bool isForwardDecl() const { return get()->isForwardDecl(); }
267 bool isAppleBlockExtension() const { return get()->isAppleBlockExtension(); }
268 bool isBlockByrefStruct() const { return get()->isBlockByrefStruct(); }
269 bool isVirtual() const { return get()->isVirtual(); }
270 bool isArtificial() const { return get()->isArtificial(); }
271 bool isObjectPointer() const { return get()->isObjectPointer(); }
272 bool isObjcClassComplete() const { return get()->isObjcClassComplete(); }
273 bool isVector() const { return get()->isVector(); }
274 bool isStaticMember() const { return get()->isStaticMember(); }
275 bool isLValueReference() const { return get()->isLValueReference(); }
276 bool isRValueReference() const { return get()->isRValueReference(); }
277 };
278
279 /// \brief A basic type, like 'int' or 'float'.
280 class DIBasicType : public DIType {
281 public:
282 DIBasicType() = default;
283 DIBasicType(const MDBasicType *N) : DIType(N) {}
284
285 MDBasicType *get() const {
286 return cast_or_null(DIDescriptor::get());
287 }
288 operator MDBasicType *() const { return get(); }
289 MDBasicType *operator->() const { return get(); }
290 MDBasicType &operator*() const { return *get(); }
291
292 unsigned getEncoding() const { return get()->getEncoding(); }
293 };
294
295 /// \brief A simple derived type
296 ///
297 /// Like a const qualified type, a typedef, a pointer or reference, et cetera.
298 /// Or, a data member of a class/struct/union.
299 class DIDerivedType : public DIType {
300 public:
301 DIDerivedType() = default;
302 DIDerivedType(const MDDerivedTypeBase *N) : DIType(N) {}
303
304 MDDerivedTypeBase *get() const {
305 return cast_or_null(DIDescriptor::get());
306 }
307 operator MDDerivedTypeBase *() const { return get(); }
308 MDDerivedTypeBase *operator->() const { return get(); }
309 MDDerivedTypeBase &operator*() const { return *get(); }
310
311 DITypeRef getTypeDerivedFrom() const { return get()->getBaseType(); }
312 };
313
314 /// \brief Types that refer to multiple other types.
315 ///
316 /// This descriptor holds a type that can refer to multiple other types, like a
317 /// function or struct.
318 ///
319 /// DICompositeType is derived from DIDerivedType because some
320 /// composite types (such as enums) can be derived from basic types
321 // FIXME: Make this derive from DIType directly & just store the
322 // base type in a single DIType field.
323 class DICompositeType : public DIDerivedType {
324 friend class DIBuilder;
325
326 public:
327 DICompositeType() = default;
328 DICompositeType(const MDCompositeTypeBase *N) : DIDerivedType(N) {}
329
330 MDCompositeTypeBase *get() const {
331 return cast_or_null(DIDescriptor::get());
332 }
333 operator MDCompositeTypeBase *() const { return get(); }
334 MDCompositeTypeBase *operator->() const { return get(); }
335 MDCompositeTypeBase &operator*() const { return *get(); }
336
337 DIArray getElements() const { return get()->getElements(); }
338
339 unsigned getRunTimeLang() const { return get()->getRuntimeLang(); }
340 DITypeRef getContainingType() const { return get()->getVTableHolder(); }
341
342 DIArray getTemplateParams() const { return get()->getTemplateParams(); }
343 MDString *getIdentifier() const { return get()->getRawIdentifier(); }
344 };
345
346 class DISubroutineType : public DICompositeType {
347 public:
348 DISubroutineType() = default;
349 DISubroutineType(const MDSubroutineType *N) : DICompositeType(N) {}
350
351 MDSubroutineType *get() const {
352 return cast_or_null(DIDescriptor::get());
353 }
354 operator MDSubroutineType *() const { return get(); }
355 MDSubroutineType *operator->() const { return get(); }
356 MDSubroutineType &operator*() const { return *get(); }
357
358 MDTypeRefArray getTypeArray() const { return get()->getTypeArray(); }
239 class DIType {
240 MDType *N;
241
242 public:
243 DIType(const MDType *N = nullptr) : N(const_cast(N)) {}
244
245 operator DIDescriptor() const { return N; }
246 operator DIScope() const { return N; }
247 operator MDType *() const { return N; }
248 MDType *operator->() const { return N; }
249 MDType &operator*() const { return *N; }
250 };
251
252 class DIBasicType {
253 MDBasicType *N;
254
255 public:
256 DIBasicType(const MDBasicType *N = nullptr)
257 : N(const_cast(N)) {}
258
259 operator DIDescriptor() const { return N; }
260 operator DIType() const { return N; }
261 operator MDBasicType *() const { return N; }
262 MDBasicType *operator->() const { return N; }
263 MDBasicType &operator*() const { return *N; }
264 };
265
266 class DIDerivedType {
267 MDDerivedTypeBase *N;
268
269 public:
270 DIDerivedType(const MDDerivedTypeBase *N = nullptr)
271 : N(const_cast(N)) {}
272
273 operator DIDescriptor() const { return N; }
274 operator DIType() const { return N; }
275 operator MDDerivedTypeBase *() const { return N; }
276 MDDerivedTypeBase *operator->() const { return N; }
277 MDDerivedTypeBase &operator*() const { return *N; }
278 };
279
280 class DICompositeType {
281 MDCompositeTypeBase *N;
282
283 public:
284 DICompositeType(const MDCompositeTypeBase *N = nullptr)
285 : N(const_cast(N)) {}
286
287 operator DIDescriptor() const { return N; }
288 operator DIType() const { return N; }
289 operator MDCompositeTypeBase *() const { return N; }
290 MDCompositeTypeBase *operator->() const { return N; }
291 MDCompositeTypeBase &operator*() const { return *N; }
292 };
293
294 class DISubroutineType {
295 MDSubroutineType *N;
296
297 public:
298 DISubroutineType(const MDSubroutineType *N = nullptr)
299 : N(const_cast(N)) {}
300
301 operator DIDescriptor() const { return N; }
302 operator DIType() const { return N; }
303 operator DICompositeType() const { return N; }
304 operator MDSubroutineType *() const { return N; }
305 MDSubroutineType *operator->() const { return N; }
306 MDSubroutineType &operator*() const { return *N; }
359307 };
360308
361309 class DIFile {
593593 }
594594 };
595595
596 /// \brief Basic type.
596 /// \brief Basic type, like 'int' or 'float'.
597597 ///
598598 /// TODO: Split out DW_TAG_unspecified_type.
599599 /// TODO: Drop unused accessors.
9797 O << '\n';
9898 }
9999
100 for (DIType T : Finder.types()) {
100 for (const MDType *T : Finder.types()) {
101101 O << "Type:";
102 if (!T.getName().empty())
103 O << ' ' << T.getName();
104 printFile(O, T.getFilename(), T.getDirectory(), T.getLineNumber());
105 if (DIBasicType BT = dyn_cast(T)) {
102 if (!T->getName().empty())
103 O << ' ' << T->getName();
104 printFile(O, T->getFilename(), T->getDirectory(), T->getLine());
105 if (auto *BT = dyn_cast(T)) {
106106 O << " ";
107107 if (const char *Encoding =
108 dwarf::AttributeEncodingString(BT.getEncoding()))
108 dwarf::AttributeEncodingString(BT->getEncoding()))
109109 O << Encoding;
110110 else
111 O << "unknown-encoding(" << BT.getEncoding() << ')';
111 O << "unknown-encoding(" << BT->getEncoding() << ')';
112112 } else {
113113 O << ' ';
114 if (const char *Tag = dwarf::TagString(T.getTag()))
114 if (const char *Tag = dwarf::TagString(T->getTag()))
115115 O << Tag;
116116 else
117 O << "unknown-tag(" << T.getTag() << ")";
117 O << "unknown-tag(" << T->getTag() << ")";
118118 }
119 if (DICompositeType CT = dyn_cast(T)) {
120 if (auto *S = CT.getIdentifier())
119 if (auto *CT = dyn_cast(T)) {
120 if (auto *S = CT->getRawIdentifier())
121121 O << " (identifier: '" << S->getString() << "')";
122122 }
123123 O << '\n';
113113 DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV);
114114 DIScope DeclContext;
115115
116 if (DIDerivedType SDMDecl = GV->getStaticDataMemberDeclaration()) {
117 DeclContext = resolve(SDMDecl.getContext());
118 assert(SDMDecl.isStaticMember() && "Expected static member decl");
116 if (auto *SDMDecl = GV->getStaticDataMemberDeclaration()) {
117 DeclContext = resolve(SDMDecl->getScope());
118 assert(SDMDecl->isStaticMember() && "Expected static member decl");
119119 assert(GV->isDefinition());
120120 // We need the declaration DIE that is in the static member's class.
121121 DIE *VariableSpecDIE = getOrCreateStaticMemberDIE(SDMDecl);
719719 DIScope Context) {
720720 if (includeMinimalInlineScopes())
721721 return;
722 std::string FullName = getParentContextString(Context) + Ty.getName().str();
722 std::string FullName = getParentContextString(Context) + Ty->getName().str();
723723 GlobalTypes[FullName] = &Die;
724724 }
725725
140140 }
141141
142142 DIType DbgVariable::getType() const {
143 DIType Ty = Var->getType().resolve(DD->getTypeIdentifierMap());
143 MDType *Ty = Var->getType().resolve(DD->getTypeIdentifierMap());
144144 // FIXME: isBlockByrefVariable should be reformulated in terms of complex
145145 // addresses instead.
146146 if (Ty->isBlockByrefStruct()) {
168168 have a DW_AT_location that tells the debugger how to unwind through
169169 the pointers and __Block_byref_x_VarName struct to find the actual
170170 value of the variable. The function addBlockByrefType does this. */
171 DIType subType = Ty;
172 uint16_t tag = Ty.getTag();
171 MDType *subType = Ty;
172 uint16_t tag = Ty->getTag();
173173
174174 if (tag == dwarf::DW_TAG_pointer_type)
175175 subType = resolve(DITypeRef(cast(Ty)->getBaseType()));
176176
177 DIArray Elements(cast(subType)->getElements());
177 auto Elements = cast(subType)->getElements();
178178 for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
179 DIDerivedType DT = cast(Elements[i]);
180 if (getName() == DT.getName())
181 return (resolve(DT.getTypeDerivedFrom()));
179 auto *DT = cast(Elements[i]);
180 if (getName() == DT->getName())
181 return resolve(DITypeRef(DT->getBaseType()));
182182 }
183183 }
184184 return Ty;
305305 return false;
306306 if (isa(Context))
307307 return true;
308 if (DIType T = dyn_cast(Context))
309 return isSubprogramContext(resolve(T.getContext()));
308 if (auto *T = dyn_cast(Context))
309 return isSubprogramContext(resolve(T->getScope()));
310310 return false;
311311 }
312312
460460 for (DIType Ty : CUNode->getEnumTypes()) {
461461 // The enum types array by design contains pointers to
462462 // MDNodes rather than DIRefs. Unique them here.
463 DIType UniqueTy = cast(resolve(Ty.getRef()));
463 DIType UniqueTy = cast(resolve(Ty->getRef()));
464464 CU.getOrCreateTypeDIE(UniqueTy);
465465 }
466466 for (DIType Ty : CUNode->getRetainedTypes()) {
467467 // The retained types array by design contains pointers to
468468 // MDNodes rather than DIRefs. Unique them here.
469 DIType UniqueTy = cast(resolve(Ty.getRef()));
469 DIType UniqueTy = cast(resolve(Ty->getRef()));
470470 CU.getOrCreateTypeDIE(UniqueTy);
471471 }
472472 // Emit imported_modules last so that the relevant context is already
147147 bool isArtificial() const {
148148 if (Var->isArtificial())
149149 return true;
150 if (getType().isArtificial())
150 if (getType()->isArtificial())
151151 return true;
152152 return false;
153153 }
155155 bool isObjectPointer() const {
156156 if (Var->isObjectPointer())
157157 return true;
158 if (getType().isObjectPointer())
158 if (getType()->isObjectPointer())
159159 return true;
160160 return false;
161161 }
423423 void DwarfUnit::addSourceLine(DIE &Die, DIType Ty) {
424424 assert(Ty);
425425
426 addSourceLine(Die, Ty.getLineNumber(), Ty.getFilename(), Ty.getDirectory());
426 addSourceLine(Die, Ty->getLine(), Ty->getFilename(), Ty->getDirectory());
427427 }
428428
429429 /// addSourceLine - Add location information to specified debug information
520520 const MachineLocation &Location) {
521521 DIType Ty = DV.getType();
522522 DIType TmpTy = Ty;
523 uint16_t Tag = Ty.getTag();
523 uint16_t Tag = Ty->getTag();
524524 bool isPointer = false;
525525
526526 StringRef varName = DV.getName();
527527
528528 if (Tag == dwarf::DW_TAG_pointer_type) {
529529 DIDerivedType DTy = cast(Ty);
530 TmpTy = resolve(DTy.getTypeDerivedFrom());
530 TmpTy = resolve(DTy->getBaseType());
531531 isPointer = true;
532532 }
533
534 DICompositeType blockStruct = cast(TmpTy);
535533
536534 // Find the __forwarding field and the variable field in the __Block_byref
537535 // struct.
538 DIArray Fields = blockStruct.getElements();
536 DIArray Fields = cast(TmpTy)->getElements();
539537 DIDerivedType varField;
540538 DIDerivedType forwardingField;
541539
542540 for (unsigned i = 0, N = Fields.size(); i < N; ++i) {
543541 DIDerivedType DT = cast(Fields[i]);
544 StringRef fieldName = DT.getName();
542 StringRef fieldName = DT->getName();
545543 if (fieldName == "__forwarding")
546544 forwardingField = DT;
547545 else if (fieldName == varName)
549547 }
550548
551549 // Get the offsets for the forwarding field and the variable field.
552 unsigned forwardingFieldOffset = forwardingField.getOffsetInBits() >> 3;
553 unsigned varFieldOffset = varField.getOffsetInBits() >> 2;
550 unsigned forwardingFieldOffset = forwardingField->getOffsetInBits() >> 3;
551 unsigned varFieldOffset = varField->getOffsetInBits() >> 2;
554552
555553 // Decode the original location, and use that as the start of the byref
556554 // variable's location.
597595 /// Return true if type encoding is unsigned.
598596 static bool isUnsignedDIType(DwarfDebug *DD, DIType Ty) {
599597 if (DIDerivedType DTy = dyn_cast(Ty)) {
600 dwarf::Tag T = (dwarf::Tag)Ty.getTag();
598 dwarf::Tag T = (dwarf::Tag)Ty->getTag();
601599 // Encode pointer constants as unsigned bytes. This is used at least for
602600 // null pointer constant emission.
603601 // (Pieces of) aggregate types that get hacked apart by SROA may also be
618616 T == dwarf::DW_TAG_volatile_type ||
619617 T == dwarf::DW_TAG_restrict_type ||
620618 T == dwarf::DW_TAG_enumeration_type);
621 if (DITypeRef Deriv = DTy.getTypeDerivedFrom())
619 if (DITypeRef Deriv = DTy->getBaseType())
622620 return isUnsignedDIType(DD, DD->resolve(Deriv));
623621 // FIXME: Enums without a fixed underlying type have unknown signedness
624622 // here, leading to incorrectly emitted constants.
625 assert(DTy.getTag() == dwarf::DW_TAG_enumeration_type);
623 assert(DTy->getTag() == dwarf::DW_TAG_enumeration_type);
626624 return false;
627625 }
628626
629627 DIBasicType BTy = cast(Ty);
630 unsigned Encoding = BTy.getEncoding();
628 unsigned Encoding = BTy->getEncoding();
631629 assert((Encoding == dwarf::DW_ATE_unsigned ||
632630 Encoding == dwarf::DW_ATE_unsigned_char ||
633631 Encoding == dwarf::DW_ATE_signed ||
634632 Encoding == dwarf::DW_ATE_signed_char ||
635 Encoding == dwarf::DW_ATE_float ||
636 Encoding == dwarf::DW_ATE_UTF || Encoding == dwarf::DW_ATE_boolean ||
637 (Ty.getTag() == dwarf::DW_TAG_unspecified_type &&
638 Ty.getName() == "decltype(nullptr)")) &&
633 Encoding == dwarf::DW_ATE_float || Encoding == dwarf::DW_ATE_UTF ||
634 Encoding == dwarf::DW_ATE_boolean ||
635 (Ty->getTag() == dwarf::DW_TAG_unspecified_type &&
636 Ty->getName() == "decltype(nullptr)")) &&
639637 "Unsupported encoding");
640 return (Encoding == dwarf::DW_ATE_unsigned ||
641 Encoding == dwarf::DW_ATE_unsigned_char ||
642 Encoding == dwarf::DW_ATE_UTF || Encoding == dwarf::DW_ATE_boolean ||
643 Ty.getTag() == dwarf::DW_TAG_unspecified_type);
638 return Encoding == dwarf::DW_ATE_unsigned ||
639 Encoding == dwarf::DW_ATE_unsigned_char ||
640 Encoding == dwarf::DW_ATE_UTF || Encoding == dwarf::DW_ATE_boolean ||
641 Ty->getTag() == dwarf::DW_TAG_unspecified_type;
644642 }
645643
646644 /// If this type is derived from a base type then return base type size.
647645 static uint64_t getBaseTypeSize(DwarfDebug *DD, DIDerivedType Ty) {
648 unsigned Tag = Ty.getTag();
646 unsigned Tag = Ty->getTag();
649647
650648 if (Tag != dwarf::DW_TAG_member && Tag != dwarf::DW_TAG_typedef &&
651649 Tag != dwarf::DW_TAG_const_type && Tag != dwarf::DW_TAG_volatile_type &&
652650 Tag != dwarf::DW_TAG_restrict_type)
653 return Ty.getSizeInBits();
654
655 DIType BaseType = DD->resolve(Ty.getTypeDerivedFrom());
651 return Ty->getSizeInBits();
652
653 auto *BaseType = DD->resolve(Ty->getBaseType());
656654
657655 assert(BaseType && "Unexpected invalid base type");
658656
659657 // If this is a derived type, go ahead and get the base type, unless it's a
660658 // reference then it's just the size of the field. Pointer types have no need
661659 // of this since they're a different type of qualification on the type.
662 if (BaseType.getTag() == dwarf::DW_TAG_reference_type ||
663 BaseType.getTag() == dwarf::DW_TAG_rvalue_reference_type)
664 return Ty.getSizeInBits();
660 if (BaseType->getTag() == dwarf::DW_TAG_reference_type ||
661 BaseType->getTag() == dwarf::DW_TAG_rvalue_reference_type)
662 return Ty->getSizeInBits();
665663
666664 if (auto *DT = dyn_cast(BaseType))
667665 return getBaseTypeSize(DD, DT);
668666
669 return BaseType.getSizeInBits();
667 return BaseType->getSizeInBits();
670668 }
671669
672670 /// addConstantFPValue - Add constant value entry in variable DIE.
787785 }
788786
789787 DIE *DwarfUnit::createTypeDIE(DICompositeType Ty) {
790 DIScope Context = resolve(Ty.getContext());
788 DIScope Context = resolve(Ty->getScope());
791789 DIE *ContextDIE = getOrCreateContextDIE(Context);
792790
793791 if (DIE *TyDIE = getDIE(Ty))
794792 return TyDIE;
795793
796794 // Create new type.
797 DIE &TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty);
795 DIE &TyDIE = createAndAddDIE(Ty->getTag(), *ContextDIE, Ty);
798796
799797 constructTypeDIE(TyDIE, Ty);
800798
808806 if (!TyNode)
809807 return nullptr;
810808
811 DIType Ty = cast(TyNode);
812 assert(Ty == resolve(Ty.getRef()) &&
809 auto *Ty = cast(TyNode);
810 assert(Ty == resolve(Ty->getRef()) &&
813811 "type was not uniqued, possible ODR violation.");
814812
815813 // DW_TAG_restrict_type is not supported in DWARF2
816 if (Ty.getTag() == dwarf::DW_TAG_restrict_type && DD->getDwarfVersion() <= 2)
814 if (Ty->getTag() == dwarf::DW_TAG_restrict_type && DD->getDwarfVersion() <= 2)
817815 return getOrCreateTypeDIE(
818816 resolve(DITypeRef(cast(Ty)->getBaseType())));
819817
820818 // Construct the context before querying for the existence of the DIE in case
821819 // such construction creates the DIE.
822 DIScope Context = resolve(Ty.getContext());
820 DIScope Context = resolve(Ty->getScope());
823821 DIE *ContextDIE = getOrCreateContextDIE(Context);
824822 assert(ContextDIE);
825823
827825 return TyDIE;
828826
829827 // Create new type.
830 DIE &TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty);
828 DIE &TyDIE = createAndAddDIE(Ty->getTag(), *ContextDIE, Ty);
831829
832830 updateAcceleratorTables(Context, Ty, TyDIE);
833831
834832 if (auto *BT = dyn_cast(Ty))
835833 constructTypeDIE(TyDIE, BT);
836834 else if (DICompositeType CTy = dyn_cast(Ty)) {
837 if (GenerateDwarfTypeUnits && !Ty.isForwardDecl())
838 if (MDString *TypeId = CTy.getIdentifier()) {
835 if (GenerateDwarfTypeUnits && !Ty->isForwardDecl())
836 if (MDString *TypeId = CTy->getRawIdentifier()) {
839837 DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
840838 // Skip updating the accelerator tables since this is not the full type.
841839 return &TyDIE;
850848
851849 void DwarfUnit::updateAcceleratorTables(DIScope Context, DIType Ty,
852850 const DIE &TyDIE) {
853 if (!Ty.getName().empty() && !Ty.isForwardDecl()) {
851 if (!Ty->getName().empty() && !Ty->isForwardDecl()) {
854852 bool IsImplementation = 0;
855 if (DICompositeType CT = dyn_cast(Ty)) {
853 if (auto *CT = dyn_cast(Ty)) {
856854 // A runtime language of 0 actually means C/C++ and that any
857855 // non-negative value is some version of Objective-C/C++.
858 IsImplementation = (CT.getRunTimeLang() == 0) || CT.isObjcClassComplete();
856 IsImplementation = CT->getRuntimeLang() == 0 || CT->isObjcClassComplete();
859857 }
860858 unsigned Flags = IsImplementation ? dwarf::DW_FLAG_type_implementation : 0;
861 DD->addAccelType(Ty.getName(), TyDIE, Flags);
859 DD->addAccelType(Ty->getName(), TyDIE, Flags);
862860
863861 if (!Context || isa(Context) || isa(Context) ||
864862 isa(Context))
932930 /// constructTypeDIE - Construct basic type die from DIBasicType.
933931 void DwarfUnit::constructTypeDIE(DIE &Buffer, DIBasicType BTy) {
934932 // Get core information.
935 StringRef Name = BTy.getName();
933 StringRef Name = BTy->getName();
936934 // Add name if not anonymous or intermediate type.
937935 if (!Name.empty())
938936 addString(Buffer, dwarf::DW_AT_name, Name);
939937
940938 // An unspecified type only has a name attribute.
941 if (BTy.getTag() == dwarf::DW_TAG_unspecified_type)
939 if (BTy->getTag() == dwarf::DW_TAG_unspecified_type)
942940 return;
943941
944942 addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
945 BTy.getEncoding());
946
947 uint64_t Size = BTy.getSizeInBits() >> 3;
943 BTy->getEncoding());
944
945 uint64_t Size = BTy->getSizeInBits() >> 3;
948946 addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
949947 }
950948
951949 /// constructTypeDIE - Construct derived type die from DIDerivedType.
952950 void DwarfUnit::constructTypeDIE(DIE &Buffer, DIDerivedType DTy) {
953951 // Get core information.
954 StringRef Name = DTy.getName();
955 uint64_t Size = DTy.getSizeInBits() >> 3;
952 StringRef Name = DTy->getName();
953 uint64_t Size = DTy->getSizeInBits() >> 3;
956954 uint16_t Tag = Buffer.getTag();
957955
958956 // Map to main type, void will not have a type.
959 DIType FromTy = resolve(DTy.getTypeDerivedFrom());
957 DIType FromTy = resolve(DTy->getBaseType());
960958 if (FromTy)
961959 addType(Buffer, FromTy);
962960
974972 Buffer, dwarf::DW_AT_containing_type,
975973 *getOrCreateTypeDIE(resolve(cast(DTy)->getClassType())));
976974 // Add source line info if available and TyDesc is not a forward declaration.
977 if (!DTy.isForwardDecl())
975 if (!DTy->isForwardDecl())
978976 addSourceLine(Buffer, DTy);
979977 }
980978
988986 } else {
989987 DIE &Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, Buffer);
990988 addType(Arg, Ty);
991 if (Ty.isArtificial())
989 if (Ty->isArtificial())
992990 addFlag(Arg, dwarf::DW_AT_artificial);
993991 }
994992 }
997995 /// constructTypeDIE - Construct type DIE from DICompositeType.
998996 void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
999997 // Add name if not anonymous or intermediate type.
1000 StringRef Name = CTy.getName();
1001
1002 uint64_t Size = CTy.getSizeInBits() >> 3;
998 StringRef Name = CTy->getName();
999
1000 uint64_t Size = CTy->getSizeInBits() >> 3;
10031001 uint16_t Tag = Buffer.getTag();
10041002
10051003 switch (Tag) {
10301028 Language == dwarf::DW_LANG_ObjC))
10311029 addFlag(Buffer, dwarf::DW_AT_prototyped);
10321030
1033 if (CTy.isLValueReference())
1031 if (CTy->isLValueReference())
10341032 addFlag(Buffer, dwarf::DW_AT_reference);
10351033
1036 if (CTy.isRValueReference())
1034 if (CTy->isRValueReference())
10371035 addFlag(Buffer, dwarf::DW_AT_rvalue_reference);
10381036 } break;
10391037 case dwarf::DW_TAG_structure_type:
10401038 case dwarf::DW_TAG_union_type:
10411039 case dwarf::DW_TAG_class_type: {
10421040 // Add elements to structure type.
1043 DIArray Elements = CTy.getElements();
1041 DIArray Elements = CTy->getElements();
10441042 for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
10451043 DIDescriptor Element = Elements[i];
10461044 if (!Element)
10481046 if (auto *SP = dyn_cast(Element))
10491047 getOrCreateSubprogramDIE(SP);
10501048 else if (DIDerivedType DDTy = dyn_cast(Element)) {
1051 if (DDTy.getTag() == dwarf::DW_TAG_friend) {
1049 if (DDTy->getTag() == dwarf::DW_TAG_friend) {
10521050 DIE &ElemDie = createAndAddDIE(dwarf::DW_TAG_friend, Buffer);
1053 addType(ElemDie, resolve(DDTy.getTypeDerivedFrom()),
1054 dwarf::DW_AT_friend);
1055 } else if (DDTy.isStaticMember()) {
1051 addType(ElemDie, resolve(DDTy->getBaseType()), dwarf::DW_AT_friend);
1052 } else if (DDTy->isStaticMember()) {
10561053 getOrCreateStaticMemberDIE(DDTy);
10571054 } else {
10581055 constructMemberDIE(Buffer, DDTy);
10821079 }
10831080 }
10841081
1085 if (CTy.isAppleBlockExtension())
1082 if (CTy->isAppleBlockExtension())
10861083 addFlag(Buffer, dwarf::DW_AT_APPLE_block);
10871084
10881085 // This is outside the DWARF spec, but GDB expects a DW_AT_containing_type
10891086 // inside C++ composite types to point to the base class with the vtable.
10901087 if (DICompositeType ContainingType =
1091 dyn_cast_or_null(resolve(CTy.getContainingType())))
1088 dyn_cast_or_null(resolve(CTy->getVTableHolder())))
10921089 addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
10931090 *getOrCreateTypeDIE(ContainingType));
10941091
1095 if (CTy.isObjcClassComplete())
1092 if (CTy->isObjcClassComplete())
10961093 addFlag(Buffer, dwarf::DW_AT_APPLE_objc_complete_type);
10971094
10981095 // Add template parameters to a class, structure or union types.
10991096 // FIXME: The support isn't in the metadata for this yet.
11001097 if (Tag == dwarf::DW_TAG_class_type ||
11011098 Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type)
1102 addTemplateParams(Buffer, CTy.getTemplateParams());
1099 addTemplateParams(Buffer, CTy->getTemplateParams());
11031100
11041101 break;
11051102 }
11181115 // TODO: Do we care about size for enum forward declarations?
11191116 if (Size)
11201117 addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
1121 else if (!CTy.isForwardDecl())
1118 else if (!CTy->isForwardDecl())
11221119 // Add zero size if it is not a forward declaration.
11231120 addUInt(Buffer, dwarf::DW_AT_byte_size, None, 0);
11241121
11251122 // If we're a forward decl, say so.
1126 if (CTy.isForwardDecl())
1123 if (CTy->isForwardDecl())
11271124 addFlag(Buffer, dwarf::DW_AT_declaration);
11281125
11291126 // Add source line info if available.
1130 if (!CTy.isForwardDecl())
1127 if (!CTy->isForwardDecl())
11311128 addSourceLine(Buffer, CTy);
11321129
11331130 // No harm in adding the runtime language to the declaration.
1134 unsigned RLang = CTy.getRunTimeLang();
1131 unsigned RLang = CTy->getRuntimeLang();
11351132 if (RLang)
11361133 addUInt(Buffer, dwarf::DW_AT_APPLE_runtime_class, dwarf::DW_FORM_data1,
11371134 RLang);
12961293 addFlag(SPDie, dwarf::DW_AT_prototyped);
12971294
12981295 DISubroutineType SPTy = SP->getType();
1299 assert(SPTy.getTag() == dwarf::DW_TAG_subroutine_type &&
1296 assert(SPTy->getTag() == dwarf::DW_TAG_subroutine_type &&
13001297 "the type of a subprogram should be a subroutine");
13011298
1302 auto Args = SPTy.getTypeArray();
1299 auto Args = SPTy->getTypeArray();
13031300 // Add a return type. If this is a type like a C/C++ void type we don't add a
13041301 // return type.
13051302 if (Args.size())
13931390
13941391 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
13951392 void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy) {
1396 if (CTy.isVector())
1393 if (CTy->isVector())
13971394 addFlag(Buffer, dwarf::DW_AT_GNU_vector);
13981395
13991396 // Emit the element type.
1400 addType(Buffer, resolve(CTy.getTypeDerivedFrom()));
1397 addType(Buffer, resolve(CTy->getBaseType()));
14011398
14021399 // Get an anonymous type for index type.
14031400 // FIXME: This type should be passed down from the front end
14051402 DIE *IdxTy = getIndexTyDie();
14061403
14071404 // Add subranges to array type.
1408 DIArray Elements = CTy.getElements();
1405 DIArray Elements = CTy->getElements();
14091406 for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
14101407 DIDescriptor Element = Elements[i];
14111408 if (Element.getTag() == dwarf::DW_TAG_subrange_type)
14151412
14161413 /// constructEnumTypeDIE - Construct an enum type DIE from DICompositeType.
14171414 void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy) {
1418 DIArray Elements = CTy.getElements();
1415 DIArray Elements = CTy->getElements();
14191416
14201417 // Add enumerators to enumeration type.
14211418 for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
14291426 Value);
14301427 }
14311428 }
1432 DIType DTy = resolve(CTy.getTypeDerivedFrom());
1429 DIType DTy = resolve(CTy->getBaseType());
14331430 if (DTy) {
14341431 addType(Buffer, DTy);
14351432 addFlag(Buffer, dwarf::DW_AT_enum_class);
486486 auto *R =
487487 MDCompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0,
488488 nullptr, MDTypeRef::get(Ty), Size, AlignInBits, 0,
489 DIType::FlagVector, Subscripts, 0, nullptr);
489 DebugNode::FlagVector, Subscripts, 0, nullptr);
490490 trackIfUnresolved(R);
491491 return R;
492492 }
500500
501501 DIType DIBuilder::createArtificialType(DIType Ty) {
502502 // FIXME: Restrict this to the nodes where it's valid.
503 if (Ty.isArtificial())
503 if (Ty->isArtificial())
504504 return Ty;
505 return createTypeWithFlags(VMContext, Ty, DIType::FlagArtificial);
505 return createTypeWithFlags(VMContext, Ty, DebugNode::FlagArtificial);
506506 }
507507
508508 DIType DIBuilder::createObjectPointerType(DIType Ty) {
509509 // FIXME: Restrict this to the nodes where it's valid.
510 if (Ty.isObjectPointer())
510 if (Ty->isObjectPointer())
511511 return Ty;
512 unsigned Flags = DIType::FlagObjectPointer | DIType::FlagArtificial;
512 unsigned Flags = DebugNode::FlagObjectPointer | DebugNode::FlagArtificial;
513513 return createTypeWithFlags(VMContext, Ty, Flags);
514514 }
515515
516516 void DIBuilder::retainType(DIType T) {
517 assert(T.get() && "Expected non-null type");
517 assert(T && "Expected non-null type");
518518 AllRetainTypes.emplace_back(T);
519519 }
520520
521 DIBasicType DIBuilder::createUnspecifiedParameter() {
522 return DIBasicType();
523 }
521 DIBasicType DIBuilder::createUnspecifiedParameter() { return nullptr; }
524522
525523 DICompositeType
526524 DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
578576
579577 static void checkGlobalVariableScope(DIDescriptor Context) {
580578 #ifndef NDEBUG
581 if (DICompositeType CT =
579 if (auto *CT =
582580 dyn_cast_or_null(getNonCompileUnitScope(Context)))
583 assert(!CT.getIdentifier() &&
581 assert(CT->getIdentifier().empty() &&
584582 "Context of a global variable should not be a type with identifier");
585583 #endif
586584 }
674672 unsigned ScopeLine, unsigned Flags,
675673 bool isOptimized, Function *Fn,
676674 MDNode *TParams, MDNode *Decl) {
677 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
675 assert(Ty->getTag() == dwarf::DW_TAG_subroutine_type &&
678676 "function types should be subroutines");
679677 auto *Node = MDSubprogram::get(
680678 VMContext, MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))),
681 Name, LinkageName, File, LineNo, cast_or_null(Ty.get()),
679 Name, LinkageName, File, LineNo, cast_or_null(Ty),
682680 isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized,
683681 Fn, cast_or_null(TParams), cast_or_null(Decl),
684682 MDTuple::getTemporary(VMContext, None).release());
700698 return MDSubprogram::getTemporary(
701699 VMContext,
702700 MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))), Name,
703 LinkageName, File, LineNo,
704 cast_or_null(Ty.get()), isLocalToUnit,
705 isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized, Fn,
706 cast_or_null(TParams), cast_or_null(Decl),
707 nullptr)
701 LinkageName, File, LineNo, cast_or_null(Ty),
702 isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags,
703 isOptimized, Fn, cast_or_null(TParams),
704 cast_or_null(Decl), nullptr)
708705 .release();
709706 }
710707
716713 DIType VTableHolder, unsigned Flags,
717714 bool isOptimized, Function *Fn,
718715 MDNode *TParam) {
719 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
716 assert(Ty->getTag() == dwarf::DW_TAG_subroutine_type &&
720717 "function types should be subroutines");
721718 assert(getNonCompileUnitScope(Context) &&
722719 "Methods should have both a Context and a context that isn't "
724721 // FIXME: Do we want to use different scope/lines?
725722 auto *SP = MDSubprogram::get(
726723 VMContext, MDScopeRef::get(cast(Context)), Name, LinkageName, F,
727 LineNo, cast_or_null(Ty.get()), isLocalToUnit,
728 isDefinition, LineNo, MDTypeRef::get(VTableHolder), VK, VIndex, Flags,
729 isOptimized, Fn, cast_or_null(TParam), nullptr, nullptr);
724 LineNo, cast_or_null(Ty), isLocalToUnit, isDefinition,
725 LineNo, MDTypeRef::get(VTableHolder), VK, VIndex, Flags, isOptimized, Fn,
726 cast_or_null(TParam), nullptr, nullptr);
730727
731728 if (isDefinition)
732729 AllSubprograms.push_back(SP);
6666 // not generate identifier for types, so using an empty map to resolve
6767 // DerivedFrom should be fine.
6868 DITypeIdentifierMap EmptyMap;
69 return getDICompositeType(
70 DIDerivedType(D).getTypeDerivedFrom().resolve(EmptyMap));
69 return getDICompositeType(D->getBaseType().resolve(EmptyMap));
7170 }
7271
7372 return nullptr;
8281 for (unsigned Ti = 0, Te = Retain.size(); Ti != Te; ++Ti) {
8382 if (!isa(Retain[Ti]))
8483 continue;
85 DICompositeType Ty = cast(Retain[Ti]);
86 if (MDString *TypeId = Ty.getIdentifier()) {
84 auto *Ty = cast(Retain[Ti]);
85 if (MDString *TypeId = Ty->getRawIdentifier()) {
8786 // Definition has priority over declaration.
8887 // Try to insert (TypeId, Ty) to Map.
8988 std::pair P =
9089 Map.insert(std::make_pair(TypeId, Ty));
9190 // If TypeId already exists in Map and this is a definition, replace
9291 // whatever we had (declaration or definition) with the definition.
93 if (!P.second && !Ty.isForwardDecl())
92 if (!P.second && !Ty->isForwardDecl())
9493 P.first->second = Ty;
9594 }
9695 }
163162 void DebugInfoFinder::processType(DIType DT) {
164163 if (!addType(DT))
165164 return;
166 processScope(DT.getContext().resolve(TypeIdentifierMap));
167 if (DICompositeType DCT = dyn_cast(DT)) {
168 processType(DCT.getTypeDerivedFrom().resolve(TypeIdentifierMap));
169 if (DISubroutineType ST = dyn_cast(DCT)) {
165 processScope(DT->getScope().resolve(TypeIdentifierMap));
166 if (auto *DCT = dyn_cast(DT)) {
167 processType(DCT->getBaseType().resolve(TypeIdentifierMap));
168 if (auto *ST = dyn_cast(DCT)) {
170169 for (MDTypeRef Ref : ST->getTypeArray())
171170 processType(Ref.resolve(TypeIdentifierMap));
172171 return;
173172 }
174173 for (Metadata *D : DCT->getElements()) {
175 if (DIType T = dyn_cast(D))
174 if (auto *T = dyn_cast(D))
176175 processType(T);
177176 else if (DISubprogram SP = dyn_cast(D))
178177 processSubprogram(SP);
179178 }
180 } else if (DIDerivedType DDT = dyn_cast(DT)) {
181 processType(DDT.getTypeDerivedFrom().resolve(TypeIdentifierMap));
179 } else if (auto *DDT = dyn_cast(DT)) {
180 processType(DDT->getBaseType().resolve(TypeIdentifierMap));
182181 }
183182 }
184183
3535 N = N + NS->getName().str() + "::";
3636 }
3737 } else if (DIType TY = dyn_cast(Context)) {
38 if (!TY.getName().empty()) {
39 getContextName(TY.getContext().resolve(TypeIdentifierMap), N);
40 N = N + TY.getName().str() + "::";
38 if (!TY->getName().empty()) {
39 getContextName(TY->getScope().resolve(TypeIdentifierMap), N);
40 N = N + TY->getName().str() + "::";
4141 }
4242 }
4343 }