46 #define DEBUG_TYPE "dwarfdebug"
50 cl::desc(
"Generate DWARF4 type units."),
58 void DIEDwarfExpression::emitOp(uint8_t
Op,
const char* Comment) {
62 void DIEDwarfExpression::emitSigned(int64_t
Value) {
66 void DIEDwarfExpression::emitUnsigned(uint64_t Value) {
71 unsigned MachineReg) {
77 :
DIEUnit(A->getDwarfVersion(), A->MAI->getCodePointerSize(), UnitTag),
78 CUNode(Node),
Asm(A), DD(DW), DU(DWU), IndexTyDie(nullptr) {
84 :
DwarfUnit(dwarf::DW_TAG_type_unit, CU.getCUNode(), A, DW, DWU), CU(CU),
85 SplitLineTable(SplitLineTable) {
91 for (
unsigned j = 0, M =
DIEBlocks.size(); j < M; ++j)
93 for (
unsigned j = 0, M =
DIELocs.size(); j < M; ++j)
97 int64_t DwarfUnit::getDefaultLowerBound()
const {
103 case dwarf::DW_LANG_C:
104 case dwarf::DW_LANG_C89:
105 case dwarf::DW_LANG_C_plus_plus:
108 case dwarf::DW_LANG_Fortran77:
109 case dwarf::DW_LANG_Fortran90:
113 case dwarf::DW_LANG_C99:
114 case dwarf::DW_LANG_ObjC:
115 case dwarf::DW_LANG_ObjC_plus_plus:
120 case dwarf::DW_LANG_Fortran95:
126 case dwarf::DW_LANG_D:
127 case dwarf::DW_LANG_Java:
128 case dwarf::DW_LANG_Python:
129 case dwarf::DW_LANG_UPC:
134 case dwarf::DW_LANG_Ada83:
135 case dwarf::DW_LANG_Ada95:
136 case dwarf::DW_LANG_Cobol74:
137 case dwarf::DW_LANG_Cobol85:
138 case dwarf::DW_LANG_Modula2:
139 case dwarf::DW_LANG_Pascal83:
140 case dwarf::DW_LANG_PLI:
146 case dwarf::DW_LANG_BLISS:
147 case dwarf::DW_LANG_C11:
148 case dwarf::DW_LANG_C_plus_plus_03:
149 case dwarf::DW_LANG_C_plus_plus_11:
150 case dwarf::DW_LANG_C_plus_plus_14:
151 case dwarf::DW_LANG_Dylan:
152 case dwarf::DW_LANG_Go:
153 case dwarf::DW_LANG_Haskell:
154 case dwarf::DW_LANG_OCaml:
155 case dwarf::DW_LANG_OpenCL:
156 case dwarf::DW_LANG_RenderScript:
157 case dwarf::DW_LANG_Rust:
158 case dwarf::DW_LANG_Swift:
163 case dwarf::DW_LANG_Fortran03:
164 case dwarf::DW_LANG_Fortran08:
165 case dwarf::DW_LANG_Julia:
166 case dwarf::DW_LANG_Modula3:
186 return (isa<DIType>(D) ||
187 (isa<DISubprogram>(
D) && !cast<DISubprogram>(D)->isDefinition())) &&
218 assert(Form != dwarf::DW_FORM_implicit_const &&
219 "DW_FORM_implicit_const is used only for signed integers");
243 isDwoUnit() ? dwarf::DW_FORM_GNU_str_index : dwarf::DW_FORM_strp,
261 addUInt(Die, Attribute, dwarf::DW_FORM_sec_offset, Integer);
263 addUInt(Die, Attribute, dwarf::DW_FORM_data4, Integer);
267 return SplitLineTable ? SplitLineTable->
getFile(DirName, FileName)
273 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
274 addLabel(Die, dwarf::DW_FORM_udata, Sym);
276 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index);
277 addUInt(Die, dwarf::DW_FORM_GNU_addr_index,
297 addFlag(Die, dwarf::DW_AT_declaration);
300 dwarf::DW_FORM_ref_sig8,
DIEInteger(Signature));
313 EntryCU == CU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,
344 assert(FileID &&
"Invalid file id");
345 addUInt(Die, dwarf::DW_AT_decl_file,
None, FileID);
440 bool isPointer =
false;
444 if (Tag == dwarf::DW_TAG_pointer_type) {
445 auto *DTy = cast<DIDerivedType>(Ty);
446 TmpTy =
resolve(DTy->getBaseType());
452 DINodeArray Fields = cast<DICompositeType>(TmpTy)->getElements();
456 for (
unsigned i = 0,
N = Fields.size(); i <
N; ++i) {
457 auto *DT = cast<DIDerivedType>(Fields[i]);
459 if (fieldName ==
"__forwarding")
460 forwardingField = DT;
461 else if (fieldName == varName)
466 unsigned forwardingFieldOffset = forwardingField->
getOffsetInBits() >> 3;
489 if (forwardingFieldOffset > 0) {
501 if (varFieldOffset > 0) {
518 if (
auto *CTy = dyn_cast<DICompositeType>(Ty)) {
521 if (CTy->getTag() == dwarf::DW_TAG_enumeration_type)
529 if (
auto *DTy = dyn_cast<DIDerivedType>(Ty)) {
536 if (T == dwarf::DW_TAG_pointer_type ||
537 T == dwarf::DW_TAG_ptr_to_member_type ||
538 T == dwarf::DW_TAG_reference_type ||
539 T == dwarf::DW_TAG_rvalue_reference_type)
541 assert(T == dwarf::DW_TAG_typedef || T == dwarf::DW_TAG_const_type ||
542 T == dwarf::DW_TAG_volatile_type ||
543 T == dwarf::DW_TAG_restrict_type || T == dwarf::DW_TAG_atomic_type);
545 assert(Deriv &&
"Expected valid base type");
549 auto *BTy = cast<DIBasicType>(Ty);
550 unsigned Encoding = BTy->getEncoding();
551 assert((Encoding == dwarf::DW_ATE_unsigned ||
552 Encoding == dwarf::DW_ATE_unsigned_char ||
553 Encoding == dwarf::DW_ATE_signed ||
554 Encoding == dwarf::DW_ATE_signed_char ||
555 Encoding == dwarf::DW_ATE_float || Encoding == dwarf::DW_ATE_UTF ||
556 Encoding == dwarf::DW_ATE_boolean ||
557 (Ty->
getTag() == dwarf::DW_TAG_unspecified_type &&
558 Ty->
getName() ==
"decltype(nullptr)")) &&
559 "Unsupported encoding");
560 return Encoding == dwarf::DW_ATE_unsigned ||
561 Encoding == dwarf::DW_ATE_unsigned_char ||
562 Encoding == dwarf::DW_ATE_UTF || Encoding == dwarf::DW_ATE_boolean ||
563 Ty->
getTag() == dwarf::DW_TAG_unspecified_type;
573 const char *FltPtr = (
const char *)FltVal.
getRawData();
577 int Incr = (LittleEndian ? 1 : -1);
578 int Start = (LittleEndian ? 0 : NumBytes - 1);
579 int Stop = (LittleEndian ? NumBytes : -1);
582 for (; Start != Stop; Start += Incr)
583 addUInt(*Block, dwarf::DW_FORM_data1, (
unsigned char)0xFF & FltPtr[Start]);
585 addBlock(Die, dwarf::DW_AT_const_value, Block);
608 addUInt(Die, dwarf::DW_AT_const_value,
609 Unsigned ? dwarf::DW_FORM_udata : dwarf::DW_FORM_sdata, Val);
618 if (CIBitWidth <= 64) {
633 for (
int i = 0; i < NumBytes; i++) {
636 c = Ptr64[i / 8] >> (8 * (i & 7));
638 c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7));
639 addUInt(*Block, dwarf::DW_FORM_data1, c);
642 addBlock(Die, dwarf::DW_AT_const_value, Block);
646 if (!LinkageName.
empty())
649 : dwarf::DW_AT_MIPS_linkage_name,
655 for (
const auto *Element : TParams) {
656 if (
auto *TTP = dyn_cast<DITemplateTypeParameter>(Element))
657 constructTemplateTypeParameterDIE(Buffer, TTP);
658 else if (
auto *TVP = dyn_cast<DITemplateValueParameter>(Element))
659 constructTemplateValueParameterDIE(Buffer, TVP);
665 for (
const auto *Ty : ThrownTypes) {
672 if (!Context || isa<DIFile>(Context))
674 if (
auto *
T = dyn_cast<DIType>(Context))
676 if (
auto *NS = dyn_cast<DINamespace>(Context))
678 if (
auto *SP = dyn_cast<DISubprogram>(Context))
680 if (
auto *M = dyn_cast<DIModule>(Context))
705 auto *Ty = cast<DIType>(TyNode);
729 if (
auto *
BT = dyn_cast<DIBasicType>(Ty))
731 else if (
auto *STy = dyn_cast<DISubroutineType>(Ty))
733 else if (
auto *CTy = dyn_cast<DICompositeType>(Ty)) {
735 if (
MDString *TypeId = CTy->getRawIdentifier()) {
751 bool IsImplementation =
false;
752 if (
auto *CT = dyn_cast<DICompositeType>(Ty)) {
755 IsImplementation = CT->getRuntimeLang() == 0 || CT->isObjcClassComplete();
760 if (!Context || isa<DICompileUnit>(Context) || isa<DIFile>(
Context) ||
761 isa<DINamespace>(Context))
768 assert(Ty &&
"Trying to add a type that doesn't exist?");
782 while (!isa<DICompileUnit>(Context)) {
796 if (Name.
empty() && isa<DINamespace>(Ctx))
797 Name =
"(anonymous namespace)";
811 addString(Buffer, dwarf::DW_AT_name, Name);
814 if (BTy->
getTag() == dwarf::DW_TAG_unspecified_type)
817 addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
821 addUInt(Buffer, dwarf::DW_AT_byte_size,
None, Size);
837 addString(Buffer, dwarf::DW_AT_name, Name);
840 if (Size && Tag != dwarf::DW_TAG_pointer_type
841 && Tag != dwarf::DW_TAG_ptr_to_member_type
842 && Tag != dwarf::DW_TAG_reference_type
843 && Tag != dwarf::DW_TAG_rvalue_reference_type)
844 addUInt(Buffer, dwarf::DW_AT_byte_size,
None, Size);
846 if (Tag == dwarf::DW_TAG_ptr_to_member_type)
848 Buffer, dwarf::DW_AT_containing_type,
856 if (DTy->getDWARFAddressSpace() && (Tag == dwarf::DW_TAG_pointer_type ||
857 Tag == dwarf::DW_TAG_reference_type))
858 addUInt(Buffer, dwarf::DW_AT_address_class, dwarf::DW_FORM_data4,
859 DTy->getDWARFAddressSpace().getValue());
863 for (
unsigned i = 1,
N = Args.
size(); i <
N; ++i) {
866 assert(i == N-1 &&
"Unspecified parameter must be the last argument");
872 addFlag(Arg, dwarf::DW_AT_artificial);
879 auto Elements = cast<DISubroutineType>(CTy)->getTypeArray();
881 if (
auto RTy =
resolve(Elements[0]))
884 bool isPrototyped =
true;
885 if (Elements.size() == 2 && !Elements[1])
886 isPrototyped =
false;
894 (Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
895 Language == dwarf::DW_LANG_ObjC))
896 addFlag(Buffer, dwarf::DW_AT_prototyped);
899 if (CTy->
getCC() && CTy->
getCC() != dwarf::DW_CC_normal)
900 addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,
904 addFlag(Buffer, dwarf::DW_AT_reference);
907 addFlag(Buffer, dwarf::DW_AT_rvalue_reference);
915 uint16_t Tag = Buffer.
getTag();
918 case dwarf::DW_TAG_array_type:
919 constructArrayTypeDIE(Buffer, CTy);
921 case dwarf::DW_TAG_enumeration_type:
922 constructEnumTypeDIE(Buffer, CTy);
924 case dwarf::DW_TAG_structure_type:
925 case dwarf::DW_TAG_union_type:
926 case dwarf::DW_TAG_class_type: {
929 for (
const auto *Element : Elements) {
932 if (
auto *SP = dyn_cast<DISubprogram>(Element))
934 else if (
auto *DDTy = dyn_cast<DIDerivedType>(Element)) {
935 if (DDTy->getTag() == dwarf::DW_TAG_friend) {
937 addType(ElemDie,
resolve(DDTy->getBaseType()), dwarf::DW_AT_friend);
938 }
else if (DDTy->isStaticMember()) {
941 constructMemberDIE(Buffer, DDTy);
943 }
else if (
auto *Property = dyn_cast<DIObjCProperty>(Element)) {
945 StringRef PropertyName = Property->getName();
946 addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);
947 if (Property->getType())
950 StringRef GetterName = Property->getGetterName();
951 if (!GetterName.
empty())
952 addString(ElemDie, dwarf::DW_AT_APPLE_property_getter, GetterName);
953 StringRef SetterName = Property->getSetterName();
954 if (!SetterName.
empty())
955 addString(ElemDie, dwarf::DW_AT_APPLE_property_setter, SetterName);
956 if (
unsigned PropertyAttributes = Property->getAttributes())
957 addUInt(ElemDie, dwarf::DW_AT_APPLE_property_attribute,
None,
963 addFlag(Buffer, dwarf::DW_AT_APPLE_block);
967 if (
auto *ContainingType =
973 addFlag(Buffer, dwarf::DW_AT_APPLE_objc_complete_type);
977 if (Tag == dwarf::DW_TAG_class_type ||
978 Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type)
989 addString(Buffer, dwarf::DW_AT_name, Name);
991 if (Tag == dwarf::DW_TAG_enumeration_type ||
992 Tag == dwarf::DW_TAG_class_type || Tag == dwarf::DW_TAG_structure_type ||
993 Tag == dwarf::DW_TAG_union_type) {
997 addUInt(Buffer, dwarf::DW_AT_byte_size,
None, Size);
1004 addFlag(Buffer, dwarf::DW_AT_declaration);
1013 addUInt(Buffer, dwarf::DW_AT_APPLE_runtime_class, dwarf::DW_FORM_data1,
1018 addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1023 void DwarfUnit::constructTemplateTypeParameterDIE(
1034 void DwarfUnit::constructTemplateValueParameterDIE(
1040 if (VP->
getTag() == dwarf::DW_TAG_template_value_parameter)
1045 if (
ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Val))
1047 else if (
GlobalValue *GV = mdconst::dyn_extract<GlobalValue>(Val)) {
1050 if (!GV->hasDLLImportStorageClass()) {
1057 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
1058 addBlock(ParamDIE, dwarf::DW_AT_location, Loc);
1060 }
else if (VP->
getTag() == dwarf::DW_TAG_GNU_template_template_param) {
1061 assert(isa<MDString>(Val));
1062 addString(ParamDIE, dwarf::DW_AT_GNU_template_name,
1063 cast<MDString>(Val)->getString());
1064 }
else if (VP->
getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) {
1083 Name =
"(anonymous namespace)";
1087 addFlag(NDie, dwarf::DW_AT_export_symbols);
1105 addString(MDie, dwarf::DW_AT_LLVM_config_macros,
1125 if (
auto *SPDecl = SP->getDeclaration()) {
1139 if (SP->isDefinition())
1148 DIE *DeclDie =
nullptr;
1150 if (
auto *SPDecl = SP->getDeclaration()) {
1151 DeclDie =
getDIE(SPDecl);
1152 assert(DeclDie &&
"This DIE should've already been constructed when the "
1153 "definition DIE was created in "
1154 "getOrCreateSubprogramDIE");
1157 DeclLinkageName = SPDecl->getLinkageName();
1161 if (DeclID != DefID)
1162 addUInt(SPDie, dwarf::DW_AT_decl_file,
None, DefID);
1164 if (SP->getLine() != SPDecl->getLine())
1165 addUInt(SPDie, dwarf::DW_AT_decl_line,
None, SP->getLine());
1173 assert(((LinkageName.empty() || DeclLinkageName.
empty()) ||
1174 LinkageName == DeclLinkageName) &&
1175 "decl has a linkage name and it is different");
1176 if (DeclLinkageName.
empty() &&
1186 addDIEEntry(SPDie, dwarf::DW_AT_specification, *DeclDie);
1191 bool SkipSPAttributes) {
1194 bool SkipSPSourceLocation = SkipSPAttributes &&
1196 if (!SkipSPSourceLocation)
1204 if (!SkipSPSourceLocation)
1208 if (SkipSPAttributes)
1214 if (SP->isPrototyped() &&
1215 (Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
1216 Language == dwarf::DW_LANG_ObjC))
1217 addFlag(SPDie, dwarf::DW_AT_prototyped);
1222 Args = SPTy->getTypeArray();
1227 if (CC && CC != dwarf::DW_CC_normal)
1228 addUInt(SPDie, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1, CC);
1233 if (
auto Ty =
resolve(Args[0]))
1236 unsigned VK = SP->getVirtuality();
1238 addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK);
1239 if (SP->getVirtualIndex() != -1u) {
1241 addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1242 addUInt(*Block, dwarf::DW_FORM_udata, SP->getVirtualIndex());
1243 addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block);
1246 std::make_pair(&SPDie,
resolve(SP->getContainingType())));
1249 if (!SP->isDefinition()) {
1250 addFlag(SPDie, dwarf::DW_AT_declaration);
1259 if (SP->isArtificial())
1260 addFlag(SPDie, dwarf::DW_AT_artificial);
1262 if (!SP->isLocalToUnit())
1263 addFlag(SPDie, dwarf::DW_AT_external);
1266 if (SP->isOptimized())
1267 addFlag(SPDie, dwarf::DW_AT_APPLE_optimized);
1270 addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag,
isa);
1273 if (SP->isLValueReference())
1274 addFlag(SPDie, dwarf::DW_AT_reference);
1276 if (SP->isRValueReference())
1277 addFlag(SPDie, dwarf::DW_AT_rvalue_reference);
1279 if (SP->isNoReturn())
1280 addFlag(SPDie, dwarf::DW_AT_noreturn);
1282 if (SP->isProtected())
1283 addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1285 else if (SP->isPrivate())
1286 addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1288 else if (SP->isPublic())
1289 addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1292 if (SP->isExplicit())
1293 addFlag(SPDie, dwarf::DW_AT_explicit);
1295 if (SP->isMainSubprogram())
1296 addFlag(SPDie, dwarf::DW_AT_main_subprogram);
1299 void DwarfUnit::constructSubrangeDIE(
DIE &Buffer,
const DISubrange *SR,
1302 addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IndexTy);
1309 int64_t DefaultLowerBound = getDefaultLowerBound();
1312 if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound)
1313 addUInt(DW_Subrange, dwarf::DW_AT_lower_bound,
None, LowerBound);
1318 addUInt(DW_Subrange, dwarf::DW_AT_count,
None, Count);
1321 DIE *DwarfUnit::getIndexTyDie() {
1329 dwarf::DW_ATE_unsigned);
1335 addFlag(Buffer, dwarf::DW_AT_GNU_vector);
1343 DIE *IdxTy = getIndexTyDie();
1347 for (
unsigned i = 0,
N = Elements.size(); i <
N; ++i) {
1349 if (
auto *Element = dyn_cast_or_null<DINode>(Elements[i]))
1350 if (Element->getTag() == dwarf::DW_TAG_subrange_type)
1351 constructSubrangeDIE(Buffer, cast<DISubrange>(Element), IdxTy);
1359 for (
unsigned i = 0, N = Elements.size(); i <
N; ++i) {
1360 auto *
Enum = dyn_cast_or_null<DIEnumerator>(Elements[i]);
1364 addString(Enumerator, dwarf::DW_AT_name, Name);
1365 int64_t Value =
Enum->getValue();
1366 addSInt(Enumerator, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata,
1373 addFlag(Buffer, dwarf::DW_AT_enum_class);
1380 DIE &SPDie = *CI->first;
1387 addDIEEntry(SPDie, dwarf::DW_AT_containing_type, *NDie);
1395 addString(MemberDie, dwarf::DW_AT_name, Name);
1408 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_dup);
1409 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1410 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1412 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_minus);
1413 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1414 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
1416 addBlock(MemberDie, dwarf::DW_AT_data_member_location, VBaseLocationDie);
1421 uint64_t OffsetInBytes;
1423 bool IsBitfield = FieldSize && Size != FieldSize;
1427 addUInt(MemberDie, dwarf::DW_AT_byte_size,
None, FieldSize/8);
1428 addUInt(MemberDie, dwarf::DW_AT_bit_size,
None, Size);
1435 uint32_t AlignMask = ~(AlignInBits - 1);
1437 uint64_t StartBitOffset = Offset - (Offset & AlignMask);
1439 OffsetInBytes = (Offset - StartBitOffset) / 8;
1442 uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1443 uint64_t FieldOffset = (HiMark - FieldSize);
1444 Offset -= FieldOffset;
1448 Offset = FieldSize - (Offset + Size);
1450 addUInt(MemberDie, dwarf::DW_AT_bit_offset,
None, Offset);
1451 OffsetInBytes = FieldOffset >> 3;
1453 addUInt(MemberDie, dwarf::DW_AT_data_bit_offset,
None, Offset);
1459 addUInt(MemberDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1465 addUInt(*MemLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
1466 addUInt(*MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes);
1467 addBlock(MemberDie, dwarf::DW_AT_data_member_location, MemLocationDie);
1469 addUInt(MemberDie, dwarf::DW_AT_data_member_location,
None,
1474 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1477 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1481 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1484 addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1,
1485 dwarf::DW_VIRTUALITY_virtual);
1488 if (
DINode *PNode = DT->getObjCProperty())
1491 dwarf::DW_FORM_ref4,
DIEEntry(*PDie));
1494 addFlag(MemberDie, dwarf::DW_AT_artificial);
1505 "Static member should belong to a type.");
1508 return StaticMemberDIE;
1517 addFlag(StaticMemberDIE, dwarf::DW_AT_external);
1518 addFlag(StaticMemberDIE, dwarf::DW_AT_declaration);
1523 addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1526 addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1529 addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1532 if (
const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(DT->getConstant()))
1534 if (
const ConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT->getConstant()))
1538 addUInt(StaticMemberDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1541 return &StaticMemberDIE;
1581 : dwarf::DW_UT_type);
1583 Asm->
OutStreamer->EmitIntValue(TypeSignature,
sizeof(TypeSignature));
1595 : dwarf::DW_FORM_data4,
1605 : dwarf::DW_FORM_data4,
1610 bool DwarfTypeUnit::isDwoUnit()
const {
1626 const MCSymbol *DwarfUnit::getCrossSectionRelativeBaseAddress()
const {
void updateAcceleratorTables(const DIScope *Context, const DIType *Ty, const DIE &TyDIE)
If this is a named finished type then include it in the list of types for the accelerator tables...
StringRef getName() const
void push_back(const T &Elt)
DIE::value_iterator addSectionDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
addSectionDelta - Add a label delta attribute data and value.
static bool isUnsignedDIType(DwarfDebug *DD, const DIType *Ty)
Return true if type encoding is unsigned.
void addFlag(DIE &Die, dwarf::Attribute Attribute)
Add a flag that is true to the DIE.
StringRef getName() const
bool isArtificial() const
uint64_t getZExtValue() const
Get zero extended value.
void addLabelDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
Add a label delta attribute data and value.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
MCSymbol * getSymbol(const GlobalValue *GV) const
std::vector< DIELoc * > DIELocs
A list of all the DIELocs in use.
DIELoc - Represents an expression location.
bool useAppleExtensionAttributes() const
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
DITypeRef getType() const
DIE * getOrCreateStaticMemberDIE(const DIDerivedType *DT)
Create new static data member DIE.
const ConstantFP * getFPImm() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
const DataLayout & getDataLayout() const
Return information about data layout.
bool getDebugInfoForProfiling() const
void EmitInt8(int Value) const
Emit a byte directive and value.
void setMemoryLocationKind()
Lock this down to become a memory location description.
DILocalScope * getScope() const
Get the local scope for this variable.
bool isRValueReference() const
void addThrownTypes(DIE &Die, DINodeArray ThrownTypes)
Add thrown types.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
void insertDIE(const DINode *Desc, DIE *D)
Insert DIE into the map.
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
Collects and handles dwarf debug information.
DwarfTypeUnit(DwarfCompileUnit &CU, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, MCDwarfDwoLineTable *SplitLineTable=nullptr)
const MachineFunction * MF
The current machine function.
Base class containing the logic for constructing DWARF expressions independently of whether they are ...
StringRef getDirectory() const
static enum BaseType getBaseType(const Value *Val)
Return the baseType for Val which states whether Val is exclusively derived from constant/null, or not exclusively derived from constant.
dwarf::Form BestForm(unsigned DwarfVersion) const
BestForm - Choose the best form for data.
StringRef getName() const
DITypeRef getBaseType() const
void EmitInt32(int Value) const
Emit a long directive and value.
StringRef getName() const
DwarfUnit(dwarf::Tag, const DICompileUnit *CU, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU)
void addType(DIE &Entity, const DIType *Ty, dwarf::Attribute Attribute=dwarf::DW_AT_type)
Add a new type attribute to the specified entity.
DIE::value_iterator addSectionLabel(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label, const MCSymbol *Sec)
Add a Dwarf section label attribute data and value.
virtual DwarfCompileUnit & getCU()=0
AsmPrinter * Asm
Target of Dwarf emission.
Tagged DWARF-like metadata node.
DIE * getOrCreateTypeDIE(const MDNode *N)
Find existing DIE or create new DIE for the given type.
void addAccelNamespace(StringRef Name, const DIE &Die)
void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy)
bool useDWARF2Bitfields() const
Returns whether to use the DWARF2 format for bitfields instyead of the DWARF4 format.
void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Block)
Add block data.
DIScope * getScope() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
const APInt & getValue() const
Return the constant as an APInt value reference.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
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.
DINodeArray getElements() const
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.
uint32_t getAlignInBytes() const
APInt bitcastToAPInt() const
StringRef getFilename() const
bool isAppleBlockExtension() const
void constructContainingTypeDIEs()
Construct DIEs for types that contain vtables.
Holds a subclass of DINode.
virtual unsigned getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
Holds a DIExpression and keeps track of how many operands have been consumed so far.
bool getExportSymbols() const
This file implements a class to represent arbitrary precision integral constant values and operations...
DenseMap< DIE *, const DINode * > ContainingTypeMap
This map is used to keep track of subprogram DIEs that need DW_AT_containing_type attribute...
void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str)
Add a string attribute data and value.
AddressPool & getAddressPool()
DenseMap< const MDNode *, DIE * > & getAbstractSPDies()
This class is used to track local variable information.
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
bool isLittleEndian() const
Layout endianness...
DIScopeRef getScope() const
virtual unsigned getHeaderSize() const
Compute the size of a header for this unit, not including the initial length field.
StringRef getConfigurationMacros() const
bool shareAcrossDWOCUs() const
DIE * getOrCreateNameSpace(const DINamespace *NS)
DIE & addChild(DIE *Child)
Add a child to the DIE.
dwarf::Tag getTag() const
DIScopeRef getScope() const
StringRef getDirectory() const
void addGlobalNameForTypeUnit(StringRef Name, const DIScope *Context)
Add a new global name present in a type unit to this compile unit.
void addGlobalTypeUnitType(const DIType *Ty, const DIScope *Context)
Add a new global type present in a type unit to this compile unit.
void addConstantValue(DIE &Die, const MachineOperand &MO, const DIType *Ty)
Add constant value entry in variable DIE.
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
unsigned getRuntimeLang() const
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support...
void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, bool SkipSPAttributes=false)
void addGlobalName(StringRef Name, const DIE &Die, const DIScope *Context) override
Add a new global name to the compile unit.
A pointer to another debug information entry.
StringRef getIncludePath() const
This dwarf writer support class manages information associated with a source file.
DIEDwarfExpression(const AsmPrinter &AP, DwarfUnit &DU, DIELoc &DIE)
DwarfStringPool & getStringPool()
Returns the string pool.
DIEValueList::value_iterator addLabel(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, const MCSymbol *Label)
Add a Dwarf label attribute data and value.
initializer< Ty > init(const Ty &Val)
unsigned getFile(StringRef Directory, StringRef FileName)
const DIType * getType() const
bool applySubprogramDefinitionAttributes(const DISubprogram *SP, DIE &SPDie)
StringRef getName() const
const MCAsmInfo * MAI
Target Asm Printer information.
void addSourceLine(DIE &Die, unsigned Line, StringRef File, StringRef Directory)
Add location information to specified debug information entry.
int64_t getSExtValue() const
Get sign extended value.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
A structured debug information entry.
DIELoc * getDIELoc()
Returns a fresh newly allocated DIELoc.
ConstantFP - Floating Point Values [float, double].
static dwarf::Form BestForm(bool IsSigned, uint64_t Int)
Choose the best form for integer.
This class is intended to be used as a driving class for all asm writers.
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...
DIScope * getScope() const
T * resolve(TypedDINodeRef< T > Ref) const
Find the MDNode for the given reference.
void emitCommonHeader(bool UseOffsets, dwarf::UnitType UT)
Emit the common part of the header for this unit.
unsigned getBitWidth() const
Return the number of bits in the APInt.
void addAccelType(StringRef Name, const DIE &Die, char Flags)
DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal=false)
Metadata * getValue() const
unsigned getEncoding() const
uint64_t getOffsetInBits() const
bool isLValueReference() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
A container for string pool string values.
void addSInt(DIEValueList &Die, dwarf::Attribute Attribute, Optional< dwarf::Form > Form, int64_t Integer)
Add an signed integer attribute data and value.
bool isShareableAcrossCUs(const DINode *D) const
Check whether the DIE for this MDNode can be shared across CUs.
DIE * IndexTyDie
An anonymous type for index type. Owned by DIEUnit.
DIE * getDIE(const DINode *D) const
Returns the DIE map slot for the specified debug variable.
Base class for scope-like contexts.
A simple label difference DIE.
UnitType
Constants for unit types in DWARF v5.
void insertDIE(const MDNode *TypeMD, DIE *Die)
StringRef getDirectory() const
void addExpression(DIExpressionCursor &&Expr, unsigned FragmentOffsetInBits=0)
Emit all remaining operations in the DIExpressionCursor.
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
StringRef getFilename() const
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
StringRef getISysRoot() const
unsigned getOrCreateSourceID(StringRef FileName, StringRef DirName) override
Look up the source ID with the given directory and source file names.
This is the shared class of boolean and integer constants.
const DIEUnit * getUnit() const
Climb up the parent chain to get the compile unit or type unit that this DIE belongs to...
uint16_t getLanguage() const
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
void addLinkageName(DIE &Die, StringRef LinkageName)
Add a linkage name, if it isn't empty.
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
Represents a compile or type unit.
MCSymbol * getBeginSymbol()
void addGlobalType(const DIType *Ty, const DIE &Die, const DIScope *Context) override
Add a new global type to the compile unit.
LLVM_NODISCARD bool isa(const Y &Val)
void addTemplateParams(DIE &Buffer, DINodeArray TParams)
Add template parameters in buffer.
StringRef getFilename() const
bool isFPImm() const
isFPImm - Tests if this is a MO_FPImmediate operand.
Class for arbitrary precision integers.
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1', drop it.
A (clang) module that has been imported by the compile unit.
bool isForwardDecl() const
std::string getParentContextString(const DIScope *Context) const
Get string containing language specific context for a global name.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry)
Add a DIE attribute data and value.
bool useAllLinkageNames() const
Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
virtual void addGlobalType(const DIType *Ty, const DIE &Die, const DIScope *Context)=0
Add a new global type to the compile unit.
DIE * getOrCreateContextDIE(const DIScope *Context)
Get context owner's DIE.
Type array for a subprogram.
static std::vector< std::string > Flags
dwarf::Form BestForm() const
BestForm - Choose the best form for data.
EntryRef getEntry(AsmPrinter &Asm, StringRef Str)
Get a reference to an entry in the string pool.
DITemplateParameterArray getTemplateParams() const
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
virtual void addGlobalName(StringRef Name, const DIE &Die, const DIScope *Context)=0
Add a new global name to the compile unit.
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...
uint16_t getDwarfVersion() const
Returns the Dwarf Version.
DIE * getDIE(const MDNode *TypeMD)
void emitHeader(bool UseOffsets) override
Emit the header for this unit, not including the initial length field.
DIE * getOrCreateModule(const DIModule *M)
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...
const DICompileUnit * CUNode
MDNode for the compile unit.
virtual unsigned getISAEncoding()
Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.
DITypeRef getVTableHolder() const
void addSectionOffset(DIE &Die, dwarf::Attribute Attribute, uint64_t Integer)
Add an offset into a section attribute data and value.
DwarfExpression implementation for singular DW_AT_location.
void addDIETypeSignature(DIE &Die, uint64_t Signature)
Add a type's DW_AT_signature and set the declaration flag.
bool isObjcClassComplete() const
const APFloat & getValueAPF() const
MCSection * getSection() const
Return the section that this DIEUnit will be emitted into.
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
reverse_iterator rbegin()
BumpPtrAllocator DIEValueAllocator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
std::string DirName(const std::string &FileName)
LLVM Value Representation.
std::vector< DIEBlock * > DIEBlocks
A list of all the DIEBlocks in use.
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
void addUInt(DIEValueList &Die, dwarf::Attribute Attribute, Optional< dwarf::Form > Form, uint64_t Integer)
Add an unsigned integer attribute data and value.
static uint64_t getBaseTypeSize(const DITypeRef TyRef)
If this type is derived from a base type then return base type size.
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...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
StringRef - Represent a constant reference to a string, i.e.
int64_t getLowerBound() const
DIEBlock - Represents a block of values.
MCSection * getDwarfAbbrevSection() const
void constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args)
Construct function argument DIEs.
bool addMachineRegExpression(const TargetRegisterInfo &TRI, DIExpressionCursor &Expr, unsigned MachineReg, unsigned FragmentOffsetInBits=0)
Emit a machine register location.
bool doesDwarfUseRelocationsAcrossSections() const
value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V)
DIE * createTypeDIE(const DICompositeType *Ty)
Get context owner's DIE.
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.