48 #define DEBUG_TYPE "dwarfdebug" 55 void DIEDwarfExpression::emitOp(uint8_t
Op,
const char* Comment) {
59 void DIEDwarfExpression::emitSigned(int64_t
Value) {
63 void DIEDwarfExpression::emitUnsigned(uint64_t
Value) {
68 unsigned MachineReg) {
74 :
DIEUnit(A->getDwarfVersion(), A->MAI->getCodePointerSize(), UnitTag),
75 CUNode(Node),
Asm(A), DD(DW), DU(DWU), IndexTyDie(nullptr) {
82 SplitLineTable(SplitLineTable) {
86 for (
unsigned j = 0, M =
DIEBlocks.size(); j < M; ++j)
88 for (
unsigned j = 0, M =
DIELocs.size(); j < M; ++j)
92 int64_t DwarfUnit::getDefaultLowerBound()
const {
98 case dwarf::DW_LANG_C:
99 case dwarf::DW_LANG_C89:
100 case dwarf::DW_LANG_C_plus_plus:
103 case dwarf::DW_LANG_Fortran77:
104 case dwarf::DW_LANG_Fortran90:
108 case dwarf::DW_LANG_C99:
109 case dwarf::DW_LANG_ObjC:
110 case dwarf::DW_LANG_ObjC_plus_plus:
115 case dwarf::DW_LANG_Fortran95:
121 case dwarf::DW_LANG_D:
122 case dwarf::DW_LANG_Java:
123 case dwarf::DW_LANG_Python:
124 case dwarf::DW_LANG_UPC:
129 case dwarf::DW_LANG_Ada83:
130 case dwarf::DW_LANG_Ada95:
131 case dwarf::DW_LANG_Cobol74:
132 case dwarf::DW_LANG_Cobol85:
133 case dwarf::DW_LANG_Modula2:
134 case dwarf::DW_LANG_Pascal83:
135 case dwarf::DW_LANG_PLI:
141 case dwarf::DW_LANG_BLISS:
142 case dwarf::DW_LANG_C11:
143 case dwarf::DW_LANG_C_plus_plus_03:
144 case dwarf::DW_LANG_C_plus_plus_11:
145 case dwarf::DW_LANG_C_plus_plus_14:
146 case dwarf::DW_LANG_Dylan:
147 case dwarf::DW_LANG_Go:
148 case dwarf::DW_LANG_Haskell:
149 case dwarf::DW_LANG_OCaml:
150 case dwarf::DW_LANG_OpenCL:
151 case dwarf::DW_LANG_RenderScript:
152 case dwarf::DW_LANG_Rust:
153 case dwarf::DW_LANG_Swift:
158 case dwarf::DW_LANG_Fortran03:
159 case dwarf::DW_LANG_Fortran08:
160 case dwarf::DW_LANG_Julia:
161 case dwarf::DW_LANG_Modula3:
181 return (isa<DIType>(D) ||
182 (isa<DISubprogram>(
D) && !cast<DISubprogram>(D)->isDefinition())) &&
213 assert(Form != dwarf::DW_FORM_implicit_const &&
214 "DW_FORM_implicit_const is used only for signed integers");
245 isDwoUnit() ? dwarf::DW_FORM_GNU_str_index : dwarf::DW_FORM_strp;
248 IxForm = dwarf::DW_FORM_strx1;
249 unsigned Index = StringPoolEntry.getIndex();
250 if (Index > 0xffffff)
251 IxForm = dwarf::DW_FORM_strx4;
252 else if (Index > 0xffff)
253 IxForm = dwarf::DW_FORM_strx3;
254 else if (Index > 0xff)
255 IxForm = dwarf::DW_FORM_strx2;
275 addUInt(Die, Attribute, dwarf::DW_FORM_sec_offset, Integer);
277 addUInt(Die, Attribute, dwarf::DW_FORM_data4, Integer);
291 std::string ChecksumString =
fromHex(Checksum->Value);
293 memcpy(CKMem, ChecksumString.data(), 16);
297 unsigned DwarfTypeUnit::getOrCreateSourceID(
const DIFile *
File) {
300 if (!UsedLineTable) {
301 UsedLineTable =
true;
311 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
312 addLabel(Die, dwarf::DW_FORM_udata, Sym);
314 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index);
315 addUInt(Die, dwarf::DW_FORM_GNU_addr_index,
335 addFlag(Die, dwarf::DW_AT_declaration);
338 dwarf::DW_FORM_ref_sig8,
DIEInteger(Signature));
351 EntryCU == CU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,
380 unsigned FileID = getOrCreateSourceID(File);
381 assert(FileID &&
"Invalid file id");
382 addUInt(Die, dwarf::DW_AT_decl_file,
None, FileID);
476 bool isPointer =
false;
480 if (Tag == dwarf::DW_TAG_pointer_type) {
481 auto *DTy = cast<DIDerivedType>(Ty);
482 TmpTy =
resolve(DTy->getBaseType());
488 DINodeArray Fields = cast<DICompositeType>(TmpTy)->getElements();
492 for (
unsigned i = 0,
N = Fields.size(); i <
N; ++i) {
493 auto *DT = cast<DIDerivedType>(Fields[i]);
495 if (fieldName ==
"__forwarding")
496 forwardingField = DT;
497 else if (fieldName == varName)
502 unsigned forwardingFieldOffset = forwardingField->
getOffsetInBits() >> 3;
521 if (forwardingFieldOffset > 0) {
533 if (varFieldOffset > 0) {
550 if (
auto *CTy = dyn_cast<DICompositeType>(Ty)) {
553 if (CTy->getTag() == dwarf::DW_TAG_enumeration_type)
561 if (
auto *DTy = dyn_cast<DIDerivedType>(Ty)) {
568 if (T == dwarf::DW_TAG_pointer_type ||
569 T == dwarf::DW_TAG_ptr_to_member_type ||
570 T == dwarf::DW_TAG_reference_type ||
571 T == dwarf::DW_TAG_rvalue_reference_type)
573 assert(T == dwarf::DW_TAG_typedef || T == dwarf::DW_TAG_const_type ||
574 T == dwarf::DW_TAG_volatile_type ||
575 T == dwarf::DW_TAG_restrict_type || T == dwarf::DW_TAG_atomic_type);
577 assert(Deriv &&
"Expected valid base type");
581 auto *BTy = cast<DIBasicType>(Ty);
582 unsigned Encoding = BTy->getEncoding();
583 assert((Encoding == dwarf::DW_ATE_unsigned ||
584 Encoding == dwarf::DW_ATE_unsigned_char ||
585 Encoding == dwarf::DW_ATE_signed ||
586 Encoding == dwarf::DW_ATE_signed_char ||
587 Encoding == dwarf::DW_ATE_float || Encoding == dwarf::DW_ATE_UTF ||
588 Encoding == dwarf::DW_ATE_boolean ||
589 (Ty->
getTag() == dwarf::DW_TAG_unspecified_type &&
590 Ty->
getName() ==
"decltype(nullptr)")) &&
591 "Unsupported encoding");
592 return Encoding == dwarf::DW_ATE_unsigned ||
593 Encoding == dwarf::DW_ATE_unsigned_char ||
594 Encoding == dwarf::DW_ATE_UTF || Encoding == dwarf::DW_ATE_boolean ||
595 Ty->
getTag() == dwarf::DW_TAG_unspecified_type;
605 const char *FltPtr = (
const char *)FltVal.
getRawData();
609 int Incr = (LittleEndian ? 1 : -1);
610 int Start = (LittleEndian ? 0 : NumBytes - 1);
611 int Stop = (LittleEndian ? NumBytes : -1);
614 for (; Start != Stop; Start += Incr)
615 addUInt(*Block, dwarf::DW_FORM_data1, (
unsigned char)0xFF & FltPtr[Start]);
617 addBlock(Die, dwarf::DW_AT_const_value, Block);
640 addUInt(Die, dwarf::DW_AT_const_value,
641 Unsigned ? dwarf::DW_FORM_udata : dwarf::DW_FORM_sdata, Val);
650 if (CIBitWidth <= 64) {
665 for (
int i = 0; i < NumBytes; i++) {
668 c = Ptr64[i / 8] >> (8 * (i & 7));
670 c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7));
671 addUInt(*Block, dwarf::DW_FORM_data1, c);
674 addBlock(Die, dwarf::DW_AT_const_value, Block);
678 if (!LinkageName.
empty())
681 : dwarf::DW_AT_MIPS_linkage_name,
687 for (
const auto *Element : TParams) {
688 if (
auto *TTP = dyn_cast<DITemplateTypeParameter>(Element))
689 constructTemplateTypeParameterDIE(Buffer, TTP);
690 else if (
auto *TVP = dyn_cast<DITemplateValueParameter>(Element))
691 constructTemplateValueParameterDIE(Buffer, TVP);
697 for (
const auto *Ty : ThrownTypes) {
704 if (!Context || isa<DIFile>(Context))
706 if (
auto *
T = dyn_cast<DIType>(Context))
708 if (
auto *NS = dyn_cast<DINamespace>(Context))
710 if (
auto *
SP = dyn_cast<DISubprogram>(Context))
712 if (
auto *M = dyn_cast<DIModule>(Context))
737 auto *Ty = cast<DIType>(TyNode);
761 if (
auto *
BT = dyn_cast<DIBasicType>(Ty))
763 else if (
auto *STy = dyn_cast<DISubroutineType>(Ty))
765 else if (
auto *CTy = dyn_cast<DICompositeType>(Ty)) {
767 if (
MDString *TypeId = CTy->getRawIdentifier()) {
783 bool IsImplementation =
false;
784 if (
auto *CT = dyn_cast<DICompositeType>(Ty)) {
787 IsImplementation = CT->getRuntimeLang() == 0 || CT->isObjcClassComplete();
792 if (!Context || isa<DICompileUnit>(Context) || isa<DIFile>(
Context) ||
793 isa<DINamespace>(Context))
800 assert(Ty &&
"Trying to add a type that doesn't exist?");
814 while (!isa<DICompileUnit>(Context)) {
828 if (Name.
empty() && isa<DINamespace>(Ctx))
829 Name =
"(anonymous namespace)";
843 addString(Buffer, dwarf::DW_AT_name, Name);
846 if (BTy->
getTag() == dwarf::DW_TAG_unspecified_type)
849 addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
853 addUInt(Buffer, dwarf::DW_AT_byte_size,
None, Size);
869 addString(Buffer, dwarf::DW_AT_name, Name);
872 if (Size && Tag != dwarf::DW_TAG_pointer_type
873 && Tag != dwarf::DW_TAG_ptr_to_member_type
874 && Tag != dwarf::DW_TAG_reference_type
875 && Tag != dwarf::DW_TAG_rvalue_reference_type)
876 addUInt(Buffer, dwarf::DW_AT_byte_size,
None, Size);
878 if (Tag == dwarf::DW_TAG_ptr_to_member_type)
880 Buffer, dwarf::DW_AT_containing_type,
888 if (DTy->getDWARFAddressSpace() && (Tag == dwarf::DW_TAG_pointer_type ||
889 Tag == dwarf::DW_TAG_reference_type))
890 addUInt(Buffer, dwarf::DW_AT_address_class, dwarf::DW_FORM_data4,
891 DTy->getDWARFAddressSpace().getValue());
895 for (
unsigned i = 1,
N = Args.
size(); i <
N; ++i) {
898 assert(i == N-1 &&
"Unspecified parameter must be the last argument");
904 addFlag(Arg, dwarf::DW_AT_artificial);
911 auto Elements = cast<DISubroutineType>(CTy)->getTypeArray();
913 if (
auto RTy =
resolve(Elements[0]))
916 bool isPrototyped =
true;
917 if (Elements.size() == 2 && !Elements[1])
918 isPrototyped =
false;
926 (Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
927 Language == dwarf::DW_LANG_ObjC))
928 addFlag(Buffer, dwarf::DW_AT_prototyped);
931 if (CTy->
getCC() && CTy->
getCC() != dwarf::DW_CC_normal)
932 addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,
936 addFlag(Buffer, dwarf::DW_AT_reference);
939 addFlag(Buffer, dwarf::DW_AT_rvalue_reference);
950 case dwarf::DW_TAG_array_type:
951 constructArrayTypeDIE(Buffer, CTy);
953 case dwarf::DW_TAG_enumeration_type:
954 constructEnumTypeDIE(Buffer, CTy);
956 case dwarf::DW_TAG_variant_part:
957 case dwarf::DW_TAG_structure_type:
958 case dwarf::DW_TAG_union_type:
959 case dwarf::DW_TAG_class_type: {
962 if (Tag == dwarf::DW_TAG_variant_part) {
969 DIE &DiscMember = constructMemberDIE(Buffer, Discriminator);
970 addDIEEntry(Buffer, dwarf::DW_AT_discr, DiscMember);
976 for (
const auto *Element : Elements) {
979 if (
auto *
SP = dyn_cast<DISubprogram>(Element))
981 else if (
auto *DDTy = dyn_cast<DIDerivedType>(Element)) {
982 if (DDTy->getTag() == dwarf::DW_TAG_friend) {
984 addType(ElemDie,
resolve(DDTy->getBaseType()), dwarf::DW_AT_friend);
985 }
else if (DDTy->isStaticMember()) {
987 }
else if (Tag == dwarf::DW_TAG_variant_part) {
992 dyn_cast_or_null<ConstantInt>(DDTy->getDiscriminantValue())) {
994 addUInt(Variant, dwarf::DW_AT_discr_value,
None, CI->getZExtValue());
996 addSInt(Variant, dwarf::DW_AT_discr_value,
None, CI->getSExtValue());
998 constructMemberDIE(Variant, DDTy);
1000 constructMemberDIE(Buffer, DDTy);
1002 }
else if (
auto *Property = dyn_cast<DIObjCProperty>(Element)) {
1004 StringRef PropertyName = Property->getName();
1005 addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);
1006 if (Property->getType())
1009 StringRef GetterName = Property->getGetterName();
1010 if (!GetterName.
empty())
1011 addString(ElemDie, dwarf::DW_AT_APPLE_property_getter, GetterName);
1012 StringRef SetterName = Property->getSetterName();
1013 if (!SetterName.
empty())
1014 addString(ElemDie, dwarf::DW_AT_APPLE_property_setter, SetterName);
1015 if (
unsigned PropertyAttributes = Property->getAttributes())
1016 addUInt(ElemDie, dwarf::DW_AT_APPLE_property_attribute,
None,
1017 PropertyAttributes);
1018 }
else if (
auto *Composite = dyn_cast<DICompositeType>(Element)) {
1019 if (Composite->getTag() == dwarf::DW_TAG_variant_part) {
1027 addFlag(Buffer, dwarf::DW_AT_APPLE_block);
1038 addFlag(Buffer, dwarf::DW_AT_APPLE_objc_complete_type);
1042 if (Tag == dwarf::DW_TAG_class_type ||
1043 Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type)
1049 CC = dwarf::DW_CC_pass_by_value;
1051 CC = dwarf::DW_CC_pass_by_reference;
1053 addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,
1063 addString(Buffer, dwarf::DW_AT_name, Name);
1065 if (Tag == dwarf::DW_TAG_enumeration_type ||
1066 Tag == dwarf::DW_TAG_class_type || Tag == dwarf::DW_TAG_structure_type ||
1067 Tag == dwarf::DW_TAG_union_type) {
1071 addUInt(Buffer, dwarf::DW_AT_byte_size,
None, Size);
1078 addFlag(Buffer, dwarf::DW_AT_declaration);
1087 addUInt(Buffer, dwarf::DW_AT_APPLE_runtime_class, dwarf::DW_FORM_data1,
1092 addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1097 void DwarfUnit::constructTemplateTypeParameterDIE(
1108 void DwarfUnit::constructTemplateValueParameterDIE(
1114 if (VP->
getTag() == dwarf::DW_TAG_template_value_parameter)
1119 if (
ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Val))
1121 else if (
GlobalValue *GV = mdconst::dyn_extract<GlobalValue>(Val)) {
1124 if (!GV->hasDLLImportStorageClass()) {
1131 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
1132 addBlock(ParamDIE, dwarf::DW_AT_location, Loc);
1134 }
else if (VP->
getTag() == dwarf::DW_TAG_GNU_template_template_param) {
1135 assert(isa<MDString>(Val));
1136 addString(ParamDIE, dwarf::DW_AT_GNU_template_name,
1137 cast<MDString>(Val)->getString());
1138 }
else if (VP->
getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) {
1157 Name =
"(anonymous namespace)";
1161 addFlag(NDie, dwarf::DW_AT_export_symbols);
1179 addString(MDie, dwarf::DW_AT_LLVM_config_macros,
1199 if (
auto *SPDecl = SP->getDeclaration()) {
1213 if (SP->isDefinition())
1222 DIE *DeclDie =
nullptr;
1224 if (
auto *SPDecl = SP->getDeclaration()) {
1225 DeclDie =
getDIE(SPDecl);
1226 assert(DeclDie &&
"This DIE should've already been constructed when the " 1227 "definition DIE was created in " 1228 "getOrCreateSubprogramDIE");
1231 DeclLinkageName = SPDecl->getLinkageName();
1232 unsigned DeclID = getOrCreateSourceID(SPDecl->getFile());
1233 unsigned DefID = getOrCreateSourceID(SP->
getFile());
1234 if (DeclID != DefID)
1235 addUInt(SPDie, dwarf::DW_AT_decl_file,
None, DefID);
1237 if (SP->getLine() != SPDecl->getLine())
1238 addUInt(SPDie, dwarf::DW_AT_decl_line,
None, SP->getLine());
1246 assert(((LinkageName.empty() || DeclLinkageName.
empty()) ||
1247 LinkageName == DeclLinkageName) &&
1248 "decl has a linkage name and it is different");
1249 if (DeclLinkageName.
empty() &&
1259 addDIEEntry(SPDie, dwarf::DW_AT_specification, *DeclDie);
1264 bool SkipSPAttributes) {
1267 bool SkipSPSourceLocation = SkipSPAttributes &&
1269 if (!SkipSPSourceLocation)
1277 if (!SkipSPSourceLocation)
1281 if (SkipSPAttributes)
1287 if (SP->isPrototyped() &&
1288 (Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
1289 Language == dwarf::DW_LANG_ObjC))
1290 addFlag(SPDie, dwarf::DW_AT_prototyped);
1295 Args = SPTy->getTypeArray();
1300 if (CC && CC != dwarf::DW_CC_normal)
1301 addUInt(SPDie, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1, CC);
1306 if (
auto Ty =
resolve(Args[0]))
1309 unsigned VK = SP->getVirtuality();
1311 addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK);
1312 if (SP->getVirtualIndex() != -1u) {
1314 addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1315 addUInt(*Block, dwarf::DW_FORM_udata, SP->getVirtualIndex());
1316 addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block);
1319 std::make_pair(&SPDie,
resolve(SP->getContainingType())));
1322 if (!SP->isDefinition()) {
1323 addFlag(SPDie, dwarf::DW_AT_declaration);
1332 if (SP->isArtificial())
1333 addFlag(SPDie, dwarf::DW_AT_artificial);
1335 if (!SP->isLocalToUnit())
1336 addFlag(SPDie, dwarf::DW_AT_external);
1339 if (SP->isOptimized())
1340 addFlag(SPDie, dwarf::DW_AT_APPLE_optimized);
1343 addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag,
isa);
1346 if (SP->isLValueReference())
1347 addFlag(SPDie, dwarf::DW_AT_reference);
1349 if (SP->isRValueReference())
1350 addFlag(SPDie, dwarf::DW_AT_rvalue_reference);
1352 if (SP->isNoReturn())
1353 addFlag(SPDie, dwarf::DW_AT_noreturn);
1355 if (SP->isProtected())
1356 addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1358 else if (SP->isPrivate())
1359 addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1361 else if (SP->isPublic())
1362 addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1365 if (SP->isExplicit())
1366 addFlag(SPDie, dwarf::DW_AT_explicit);
1368 if (SP->isMainSubprogram())
1369 addFlag(SPDie, dwarf::DW_AT_main_subprogram);
1372 void DwarfUnit::constructSubrangeDIE(
DIE &Buffer,
const DISubrange *SR,
1375 addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IndexTy);
1381 int64_t LowerBound = SR->getLowerBound();
1382 int64_t DefaultLowerBound = getDefaultLowerBound();
1385 Count = CI->getSExtValue();
1387 if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound)
1388 addUInt(DW_Subrange, dwarf::DW_AT_lower_bound,
None, LowerBound);
1391 if (
auto *CountVarDIE =
getDIE(CV))
1392 addDIEEntry(DW_Subrange, dwarf::DW_AT_count, *CountVarDIE);
1393 }
else if (Count != -1)
1394 addUInt(DW_Subrange, dwarf::DW_AT_count,
None, Count);
1397 DIE *DwarfUnit::getIndexTyDie() {
1406 dwarf::DW_ATE_unsigned);
1415 assert(CTy && CTy->
isVector() &&
"Composite type is not a vector");
1420 assert(BaseTy &&
"Unknown vector element type.");
1425 assert(Elements.size() == 1 &&
1426 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type &&
1427 "Invalid vector element array, expected one element of type subrange");
1428 const auto Subrange = cast<DISubrange>(Elements[0]);
1429 const auto CI = Subrange->getCount().get<
ConstantInt *>();
1434 assert(ActualSize >= (NumVecElements * ElementSize) &&
"Invalid vector size");
1435 return ActualSize != (NumVecElements * ElementSize);
1440 addFlag(Buffer, dwarf::DW_AT_GNU_vector);
1452 DIE *IdxTy = getIndexTyDie();
1456 for (
unsigned i = 0,
N = Elements.size(); i <
N; ++i) {
1458 if (
auto *Element = dyn_cast_or_null<DINode>(Elements[i]))
1459 if (Element->getTag() == dwarf::DW_TAG_subrange_type)
1460 constructSubrangeDIE(Buffer, cast<DISubrange>(Element), IdxTy);
1471 addFlag(Buffer, dwarf::DW_AT_enum_class);
1477 for (
unsigned i = 0,
N = Elements.size(); i <
N; ++i) {
1478 auto *Enum = dyn_cast_or_null<DIEnumerator>(Elements[i]);
1482 addString(Enumerator, dwarf::DW_AT_name, Name);
1483 auto Value =
static_cast<uint64_t
>(Enum->getValue());
1492 DIE &SPDie = *CI->first;
1499 addDIEEntry(SPDie, dwarf::DW_AT_containing_type, *NDie);
1507 addString(MemberDie, dwarf::DW_AT_name, Name);
1521 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_dup);
1522 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1523 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1525 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_minus);
1526 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1527 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
1529 addBlock(MemberDie, dwarf::DW_AT_data_member_location, VBaseLocationDie);
1534 uint64_t OffsetInBytes;
1536 bool IsBitfield = FieldSize && Size != FieldSize;
1540 addUInt(MemberDie, dwarf::DW_AT_byte_size,
None, FieldSize/8);
1541 addUInt(MemberDie, dwarf::DW_AT_bit_size,
None, Size);
1548 uint32_t AlignMask = ~(AlignInBits - 1);
1550 uint64_t StartBitOffset = Offset - (Offset & AlignMask);
1552 OffsetInBytes = (Offset - StartBitOffset) / 8;
1555 uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1556 uint64_t FieldOffset = (HiMark - FieldSize);
1557 Offset -= FieldOffset;
1561 Offset = FieldSize - (Offset + Size);
1563 addUInt(MemberDie, dwarf::DW_AT_bit_offset,
None, Offset);
1564 OffsetInBytes = FieldOffset >> 3;
1566 addUInt(MemberDie, dwarf::DW_AT_data_bit_offset,
None, Offset);
1572 addUInt(MemberDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1578 addUInt(*MemLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
1579 addUInt(*MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes);
1580 addBlock(MemberDie, dwarf::DW_AT_data_member_location, MemLocationDie);
1582 addUInt(MemberDie, dwarf::DW_AT_data_member_location,
None,
1587 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1590 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1594 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1597 addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1,
1598 dwarf::DW_VIRTUALITY_virtual);
1601 if (
DINode *PNode = DT->getObjCProperty())
1604 dwarf::DW_FORM_ref4,
DIEEntry(*PDie));
1607 addFlag(MemberDie, dwarf::DW_AT_artificial);
1620 "Static member should belong to a type.");
1623 return StaticMemberDIE;
1632 addFlag(StaticMemberDIE, dwarf::DW_AT_external);
1633 addFlag(StaticMemberDIE, dwarf::DW_AT_declaration);
1638 addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1641 addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1644 addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1647 if (
const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(DT->getConstant()))
1649 if (
const ConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT->getConstant()))
1653 addUInt(StaticMemberDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1656 return &StaticMemberDIE;
1696 : dwarf::DW_UT_type);
1698 Asm->
OutStreamer->EmitIntValue(TypeSignature,
sizeof(TypeSignature));
1710 : dwarf::DW_FORM_data4,
1720 : dwarf::DW_FORM_data4,
1725 bool DwarfTypeUnit::isDwoUnit()
const {
1741 const MCSymbol *DwarfUnit::getCrossSectionRelativeBaseAddress()
const {
1758 "DW_AT_rnglists_base requires DWARF version 5 or later");
1762 TLOF.getDwarfRnglistsSection()->getBeginSymbol());
const DICompileUnit * getCUNode() 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...
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
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.
MCSection * getDwarfStrOffSection() const
static bool isUnsignedDIType(DwarfDebug *DD, const DIType *Ty)
Return true if type encoding is unsigned.
uint64_t getOffsetInBits() const
void addFlag(DIE &Die, dwarf::Attribute Attribute)
Add a flag that is true to the DIE.
bool isTypePassByValue() 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.
StringRef getName() const
std::vector< DIELoc * > DIELocs
A list of all the DIELocs in use.
DIELoc - Represents an expression location.
Compute iterated dominance frontiers using a linear time algorithm.
StringRef getName() const
DIE * getOrCreateStaticMemberDIE(const DIDerivedType *DT)
Create new static data member DIE.
void addOpAddress(DIELoc &Die, const MCSymbol *Sym)
Add a dwarf op address data and value using the form given and an op of either DW_FORM_addr or DW_FOR...
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
void setMemoryLocationKind()
Lock this down to become a memory location description.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
const DIType * getType() 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.
DITypeRef getBaseType() const
Collects and handles dwarf debug information.
DwarfTypeUnit(DwarfCompileUnit &CU, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, MCDwarfDwoLineTable *SplitLineTable=nullptr)
Base class containing the logic for constructing DWARF expressions independently of whether they are ...
MD5::MD5Result * getMD5AsBytes(const DIFile *File) const
If the File has an MD5 checksum, return it as an MD5Result allocated in the MCContext.
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.
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
unsigned const TargetRegisterInfo * TRI
static bool hasVectorBeenPadded(const DICompositeType *CTy)
Returns true if the vector's size differs from the sum of sizes of elements the user specified...
MachineFunction * MF
The current machine function.
StringRef getConfigurationMacros() const
bool useSegmentedStringOffsetsTable() const
bool isForwardDecl() const
bool getDebugInfoForProfiling() const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
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.
StringRef getName() const
AsmPrinter * Asm
Target of Dwarf emission.
Tagged DWARF-like metadata node.
unsigned getBitWidth() const
Return the number of bits in the APInt.
std::string fromHex(StringRef Input)
Convert hexadecimal string Input to its binary representation.
void addAccelNamespace(StringRef Name, const DIE &Die)
DINodeArray getElements() const
void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy)
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support...
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
DIE * getDIE(const DINode *D) const
Returns the DIE map slot for the specified debug variable.
T * resolve(TypedDINodeRef< T > Ref) const
Look in the DwarfDebug map for the MDNode that corresponds to the reference.
MCSymbol * getRnglistsTableBaseSym() const
bool isLValueReference() const
const ConstantFP * getFPImm() const
bool isShareableAcrossCUs(const DINode *D) const
Check whether the DIE for this MDNode can be shared across CUs.
void addConstantFPValue(DIE &Die, const MachineOperand &MO)
Add constant value entry in variable DIE.
void addGlobalTypeUnitType(const DIType *Ty, const DIScope *Context)
Add a new global type present in a type unit to this compile unit.
uint64_t getSizeInBits() 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.
DITypeRef getVTableHolder() const
StringRef getFilename() const
This file implements a class to represent arbitrary precision integral constant values and operations...
DIE * getOrCreateTypeDIE(const MDNode *TyNode)
Find existing DIE or create new DIE for the given type.
void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc)
Add block data.
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.
bool getExportSymbols() const
AddressPool & getAddressPool()
int64_t getSExtValue() const
Get sign extended value.
StringRef getIncludePath() const
unsigned getRuntimeLang() const
DenseMap< const MDNode *, DIE * > & getAbstractSPDies()
unsigned getFile(StringRef Directory, StringRef FileName, MD5::MD5Result *Checksum, Optional< StringRef > Source)
This class is used to track local variable information.
bool doesDwarfUseRelocationsAcrossSections() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
uint32_t getAlignInBytes() const
DwarfCompileUnit & getCU() override
const APInt & getValue() const
Return the constant as an APInt value reference.
bool isLittleEndian() const
Layout endianness...
bool isFPImm() const
isFPImm - Tests if this is a MO_FPImmediate operand.
void addGlobalNameForTypeUnit(StringRef Name, const DIScope *Context)
Add a new global name present in a type unit to this compile unit.
DIE * getOrCreateNameSpace(const DINamespace *NS)
DIE & addChild(DIE *Child)
Add a child to the DIE.
MCSection * getDwarfAbbrevSection() const
void addConstantValue(DIE &Die, const MachineOperand &MO, const DIType *Ty)
Add constant value entry in variable DIE.
MCSymbol * getStringOffsetsStartSym() const
DIScope * getScope() const
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
Metadata * getValue() const
void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, bool SkipSPAttributes=false)
void addSourceLine(DIE &Die, unsigned Line, const DIFile *File)
Add location information to specified debug information entry.
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.
DITemplateParameterArray getTemplateParams() 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.
const DIEUnit * getUnit() const
Climb up the parent chain to get the compile unit or type unit that this DIE belongs to...
bool applySubprogramDefinitionAttributes(const DISubprogram *SP, DIE &SPDie)
const MCAsmInfo * MAI
Target Asm Printer information.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
CountType getCount() const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
A container for inline string values.
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.
unsigned getOrCreateSourceID(const DIFile *File) override
Look up the source ID for the given file.
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...
bool useDWARF2Bitfields() const
Returns whether to use the DWARF2 format for bitfields instyead of the DWARF4 format.
void emitCommonHeader(bool UseOffsets, dwarf::UnitType UT)
Emit the common part of the header for this unit.
void addAccelType(StringRef Name, const DIE &Die, char Flags)
DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal=false)
Base class for variables.
bool isObjcClassComplete() const
T * resolve(TypedDINodeRef< T > Ref) const
Find the MDNode for the given reference.
StringRef getDirectory() const
bool useAllLinkageNames() const
Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
A container for string pool string values.
bool isRValueReference() const
void addSInt(DIEValueList &Die, dwarf::Attribute Attribute, Optional< dwarf::Form > Form, int64_t Integer)
Add an signed integer attribute data and value.
DIE * IndexTyDie
An anonymous type for index type. Owned by DIEUnit.
Base class for scope-like contexts.
A simple label difference DIE.
std::string getParentContextString(const DIScope *Context) const
Get string containing language specific context for a global name.
UnitType
Constants for unit types in DWARF v5.
void insertDIE(const MDNode *TypeMD, DIE *Die)
const APFloat & getValueAPF() const
void addExpression(DIExpressionCursor &&Expr, unsigned FragmentOffsetInBits=0)
Emit all remaining operations in the DIExpressionCursor.
uint16_t getLanguage() const
unsigned getHeaderSize() const override
Compute the size of a header for this unit, not including the initial length field.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
This is the shared class of boolean and integer constants.
StringRef getName() const
MCSection * getSection() const
Return the section that this DIEUnit will be emitted into.
MCSymbol * getSymbol(const GlobalValue *GV) 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.
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.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
LLVM_NODISCARD bool isa(const Y &Val)
bool useAppleExtensionAttributes() const
DITypeRef getType() const
void emitInt32(int Value) const
Emit a long directive and value.
void addRnglistsBase()
Add the DW_AT_rnglists_base attribute to the unit DIE.
void addTemplateParams(DIE &Buffer, DINodeArray TParams)
Add template parameters in buffer.
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.
StringRef getName() const
dwarf::Form BestForm(unsigned DwarfVersion) const
BestForm - Choose the best form for data.
A (clang) module that has been imported by the compile unit.
void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry)
Add a DIE attribute data and value.
dwarf::Tag getTag() const
amdgpu Simplify well known AMD library false Value Value * Arg
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
DIE * getOrCreateContextDIE(const DIScope *Context)
Get context owner's DIE.
Type array for a subprogram.
StringRef getName() const
bool isArtificial() const
unsigned getEncoding() const
EntryRef getEntry(AsmPrinter &Asm, StringRef Str)
Get a reference to an entry in the string pool.
dwarf::Form BestForm() const
BestForm - Choose the best form for data.
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...
bool shareAcrossDWOCUs() const
DIE * getDIE(const MDNode *TypeMD)
void emitHeader(bool UseOffsets) override
Emit the header for this unit, not including the initial length field.
Optional< StringRef > getSource() const
DIE * getOrCreateModule(const DIModule *M)
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.
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.
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
reverse_iterator rbegin()
BumpPtrAllocator DIEValueAllocator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void emitInt8(int Value) const
Emit a byte directive and value.
LLVM Value Representation.
DIScopeRef getScope() const
void addStringOffsetsStart()
Add the DW_AT_str_offsets_base attribute to the unit DIE.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
DIScope * getScope() const
std::vector< DIEBlock * > DIEBlocks
A list of all the DIEBlocks in use.
uint16_t getDwarfVersion() const
Returns the Dwarf Version.
bool isAppleBlockExtension() const
DIDerivedType * getDiscriminator() const
void addUInt(DIEValueList &Die, dwarf::Attribute Attribute, Optional< dwarf::Form > Form, uint64_t Integer)
Add an unsigned integer attribute data and value.
const DataLayout & getDataLayout() const
Return information about data layout.
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
static uint64_t getBaseTypeSize(const DITypeRef TyRef)
If this type is derived from a base type then return base type size.
StringRef - Represent a constant reference to a string, i.e.
APInt bitcastToAPInt() const
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
DIEBlock - Represents a block of values.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
void constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args)
Construct function argument DIEs.
bool generateTypeUnits() const
Returns whether to generate DWARF v4 type units.
DwarfUnit(dwarf::Tag, const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU)
bool addMachineRegExpression(const TargetRegisterInfo &TRI, DIExpressionCursor &Expr, unsigned MachineReg, unsigned FragmentOffsetInBits=0)
Emit a machine register location.
StringRef getISysRoot() const
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V)
bool isTypePassByReference() const
void emitInt16(int Value) const
Emit a short directive and value.
bool useInlineStrings() const
Returns whether to use inline strings.
DIE * createTypeDIE(const DICompositeType *Ty)
Get context owner's DIE.
Basic type, like 'int' or 'float'.
DIScopeRef getScope() const
unsigned getIndex(const MCSymbol *Sym, bool TLS=false)
Returns the index into the address pool with the given label/symbol.