47 #define DEBUG_TYPE "dwarfdebug" 53 void DIEDwarfExpression::emitOp(uint8_t
Op,
const char* Comment) {
54 CU.addUInt(getActiveDIE(), dwarf::DW_FORM_data1,
Op);
57 void DIEDwarfExpression::emitSigned(int64_t
Value) {
58 CU.addSInt(getActiveDIE(), dwarf::DW_FORM_sdata, Value);
61 void DIEDwarfExpression::emitUnsigned(uint64_t
Value) {
62 CU.addUInt(getActiveDIE(), dwarf::DW_FORM_udata, Value);
65 void DIEDwarfExpression::emitData1(uint8_t
Value) {
66 CU.addUInt(getActiveDIE(), dwarf::DW_FORM_data1, Value);
69 void DIEDwarfExpression::emitBaseTypeRef(uint64_t Idx) {
70 CU.addBaseTypeRef(getActiveDIE(), Idx);
73 void DIEDwarfExpression::enableTemporaryBuffer() {
74 assert(!IsBuffering &&
"Already buffering?");
78 void DIEDwarfExpression::disableTemporaryBuffer() { IsBuffering =
false; }
80 unsigned DIEDwarfExpression::getTemporaryBufferSize() {
84 void DIEDwarfExpression::commitTemporaryBuffer() { OutDIE.
takeValues(TmpDIE); }
87 unsigned MachineReg) {
93 :
DIEUnit(A->getDwarfVersion(), A->MAI->getCodePointerSize(), UnitTag),
94 CUNode(Node),
Asm(A), DD(DW), DU(DWU), IndexTyDie(nullptr) {
101 SplitLineTable(SplitLineTable) {
105 for (
unsigned j = 0, M =
DIEBlocks.size(); j < M; ++j)
107 for (
unsigned j = 0, M =
DIELocs.size(); j < M; ++j)
111 int64_t DwarfUnit::getDefaultLowerBound()
const {
117 case dwarf::DW_LANG_C:
118 case dwarf::DW_LANG_C89:
119 case dwarf::DW_LANG_C_plus_plus:
122 case dwarf::DW_LANG_Fortran77:
123 case dwarf::DW_LANG_Fortran90:
127 case dwarf::DW_LANG_C99:
128 case dwarf::DW_LANG_ObjC:
129 case dwarf::DW_LANG_ObjC_plus_plus:
134 case dwarf::DW_LANG_Fortran95:
140 case dwarf::DW_LANG_D:
141 case dwarf::DW_LANG_Java:
142 case dwarf::DW_LANG_Python:
143 case dwarf::DW_LANG_UPC:
148 case dwarf::DW_LANG_Ada83:
149 case dwarf::DW_LANG_Ada95:
150 case dwarf::DW_LANG_Cobol74:
151 case dwarf::DW_LANG_Cobol85:
152 case dwarf::DW_LANG_Modula2:
153 case dwarf::DW_LANG_Pascal83:
154 case dwarf::DW_LANG_PLI:
160 case dwarf::DW_LANG_BLISS:
161 case dwarf::DW_LANG_C11:
162 case dwarf::DW_LANG_C_plus_plus_03:
163 case dwarf::DW_LANG_C_plus_plus_11:
164 case dwarf::DW_LANG_C_plus_plus_14:
165 case dwarf::DW_LANG_Dylan:
166 case dwarf::DW_LANG_Go:
167 case dwarf::DW_LANG_Haskell:
168 case dwarf::DW_LANG_OCaml:
169 case dwarf::DW_LANG_OpenCL:
170 case dwarf::DW_LANG_RenderScript:
171 case dwarf::DW_LANG_Rust:
172 case dwarf::DW_LANG_Swift:
177 case dwarf::DW_LANG_Fortran03:
178 case dwarf::DW_LANG_Fortran08:
179 case dwarf::DW_LANG_Julia:
180 case dwarf::DW_LANG_Modula3:
200 return (isa<DIType>(D) ||
201 (isa<DISubprogram>(
D) && !cast<DISubprogram>(D)->isDefinition())) &&
236 assert(Form != dwarf::DW_FORM_implicit_const &&
237 "DW_FORM_implicit_const is used only for signed integers");
270 isDwoUnit() ? dwarf::DW_FORM_GNU_str_index : dwarf::DW_FORM_strp;
272 auto StringPoolEntry =
279 IxForm = dwarf::DW_FORM_strx1;
280 unsigned Index = StringPoolEntry.getIndex();
281 if (Index > 0xffffff)
282 IxForm = dwarf::DW_FORM_strx4;
283 else if (Index > 0xffff)
284 IxForm = dwarf::DW_FORM_strx3;
285 else if (Index > 0xff)
286 IxForm = dwarf::DW_FORM_strx2;
306 addUInt(Die, Attribute, dwarf::DW_FORM_sec_offset, Integer);
308 addUInt(Die, Attribute, dwarf::DW_FORM_data4, Integer);
322 std::string ChecksumString =
fromHex(Checksum->Value);
324 std::copy(ChecksumString.begin(), ChecksumString.end(), CKMem.
Bytes.data());
328 unsigned DwarfTypeUnit::getOrCreateSourceID(
const DIFile *
File) {
331 if (!UsedLineTable) {
332 UsedLineTable =
true;
344 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addrx);
350 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index);
351 addUInt(Die, dwarf::DW_FORM_GNU_addr_index,
356 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
357 addLabel(Die, dwarf::DW_FORM_udata, Sym);
375 addFlag(Die, dwarf::DW_AT_declaration);
378 dwarf::DW_FORM_ref_sig8,
DIEInteger(Signature));
391 EntryCU == CU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,
420 unsigned FileID = getOrCreateSourceID(File);
421 addUInt(Die, dwarf::DW_AT_decl_file,
None, FileID);
463 if (
auto *CTy = dyn_cast<DICompositeType>(Ty)) {
466 if (CTy->getTag() == dwarf::DW_TAG_enumeration_type)
474 if (
auto *DTy = dyn_cast<DIDerivedType>(Ty)) {
481 if (T == dwarf::DW_TAG_pointer_type ||
482 T == dwarf::DW_TAG_ptr_to_member_type ||
483 T == dwarf::DW_TAG_reference_type ||
484 T == dwarf::DW_TAG_rvalue_reference_type)
486 assert(T == dwarf::DW_TAG_typedef || T == dwarf::DW_TAG_const_type ||
487 T == dwarf::DW_TAG_volatile_type ||
488 T == dwarf::DW_TAG_restrict_type || T == dwarf::DW_TAG_atomic_type);
489 assert(DTy->getBaseType() &&
"Expected valid base type");
493 auto *BTy = cast<DIBasicType>(Ty);
494 unsigned Encoding = BTy->getEncoding();
495 assert((Encoding == dwarf::DW_ATE_unsigned ||
496 Encoding == dwarf::DW_ATE_unsigned_char ||
497 Encoding == dwarf::DW_ATE_signed ||
498 Encoding == dwarf::DW_ATE_signed_char ||
499 Encoding == dwarf::DW_ATE_float || Encoding == dwarf::DW_ATE_UTF ||
500 Encoding == dwarf::DW_ATE_boolean ||
501 (Ty->
getTag() == dwarf::DW_TAG_unspecified_type &&
502 Ty->
getName() ==
"decltype(nullptr)")) &&
503 "Unsupported encoding");
504 return Encoding == dwarf::DW_ATE_unsigned ||
505 Encoding == dwarf::DW_ATE_unsigned_char ||
506 Encoding == dwarf::DW_ATE_UTF || Encoding == dwarf::DW_ATE_boolean ||
507 Ty->
getTag() == dwarf::DW_TAG_unspecified_type;
517 const char *FltPtr = (
const char *)FltVal.
getRawData();
521 int Incr = (LittleEndian ? 1 : -1);
522 int Start = (LittleEndian ? 0 : NumBytes - 1);
523 int Stop = (LittleEndian ? NumBytes : -1);
526 for (; Start != Stop; Start += Incr)
527 addUInt(*Block, dwarf::DW_FORM_data1, (
unsigned char)0xFF & FltPtr[Start]);
529 addBlock(Die, dwarf::DW_AT_const_value, Block);
556 addUInt(Die, dwarf::DW_AT_const_value,
557 Unsigned ? dwarf::DW_FORM_udata : dwarf::DW_FORM_sdata, Val);
566 if (CIBitWidth <= 64) {
581 for (
int i = 0; i < NumBytes; i++) {
584 c = Ptr64[i / 8] >> (8 * (i & 7));
586 c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7));
587 addUInt(*Block, dwarf::DW_FORM_data1, c);
590 addBlock(Die, dwarf::DW_AT_const_value, Block);
594 if (!LinkageName.
empty())
597 : dwarf::DW_AT_MIPS_linkage_name,
603 for (
const auto *Element : TParams) {
604 if (
auto *TTP = dyn_cast<DITemplateTypeParameter>(Element))
605 constructTemplateTypeParameterDIE(Buffer, TTP);
606 else if (
auto *TVP = dyn_cast<DITemplateValueParameter>(Element))
607 constructTemplateValueParameterDIE(Buffer, TVP);
613 for (
const auto *Ty : ThrownTypes) {
620 if (!Context || isa<DIFile>(Context))
622 if (
auto *
T = dyn_cast<DIType>(Context))
624 if (
auto *NS = dyn_cast<DINamespace>(Context))
626 if (
auto *
SP = dyn_cast<DISubprogram>(Context))
628 if (
auto *M = dyn_cast<DIModule>(Context))
645 updateAcceleratorTables(
Context, Ty, TyDIE);
654 updateAcceleratorTables(Context, Ty, TyDIE);
656 if (
auto *
BT = dyn_cast<DIBasicType>(Ty))
658 else if (
auto *STy = dyn_cast<DISubroutineType>(Ty))
660 else if (
auto *CTy = dyn_cast<DICompositeType>(Ty)) {
662 (Ty->
getRawName() || CTy->getRawIdentifier())) {
664 if (
MDString *TypeId = CTy->getRawIdentifier())
668 finishNonUnitTypeDIE(TyDIE, CTy);
684 auto *Ty = cast<DIType>(TyNode);
696 auto *
Context = Ty->getScope();
710 bool IsImplementation =
false;
711 if (
auto *CT = dyn_cast<DICompositeType>(Ty)) {
714 IsImplementation = CT->getRuntimeLang() == 0 || CT->isObjcClassComplete();
719 if (!Context || isa<DICompileUnit>(Context) || isa<DIFile>(
Context) ||
720 isa<DINamespace>(Context) || isa<DICommonBlock>(
Context))
727 assert(Ty &&
"Trying to add a type that doesn't exist?");
741 while (!isa<DICompileUnit>(Context)) {
755 if (Name.
empty() && isa<DINamespace>(Ctx))
756 Name =
"(anonymous namespace)";
770 addString(Buffer, dwarf::DW_AT_name, Name);
773 if (BTy->
getTag() == dwarf::DW_TAG_unspecified_type)
776 addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
780 addUInt(Buffer, dwarf::DW_AT_byte_size,
None, Size);
783 addUInt(Buffer, dwarf::DW_AT_endianity,
None, dwarf::DW_END_big);
785 addUInt(Buffer, dwarf::DW_AT_endianity,
None, dwarf::DW_END_little);
795 const DIType *FromTy = DTy->getBaseType();
801 addString(Buffer, dwarf::DW_AT_name, Name);
807 if (AlignInBytes > 0)
808 addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
813 if (Size && Tag != dwarf::DW_TAG_pointer_type
814 && Tag != dwarf::DW_TAG_ptr_to_member_type
815 && Tag != dwarf::DW_TAG_reference_type
816 && Tag != dwarf::DW_TAG_rvalue_reference_type)
817 addUInt(Buffer, dwarf::DW_AT_byte_size,
None, Size);
819 if (Tag == dwarf::DW_TAG_ptr_to_member_type)
829 if (DTy->getDWARFAddressSpace())
830 addUInt(Buffer, dwarf::DW_AT_address_class, dwarf::DW_FORM_data4,
831 DTy->getDWARFAddressSpace().getValue());
835 for (
unsigned i = 1,
N = Args.
size(); i <
N; ++i) {
836 const DIType *Ty = Args[i];
838 assert(i == N-1 &&
"Unspecified parameter must be the last argument");
844 addFlag(Arg, dwarf::DW_AT_artificial);
851 auto Elements = cast<DISubroutineType>(CTy)->getTypeArray();
853 if (
auto RTy = Elements[0])
856 bool isPrototyped =
true;
857 if (Elements.size() == 2 && !Elements[1])
858 isPrototyped =
false;
866 (Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
867 Language == dwarf::DW_LANG_ObjC))
868 addFlag(Buffer, dwarf::DW_AT_prototyped);
871 if (CTy->
getCC() && CTy->
getCC() != dwarf::DW_CC_normal)
872 addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,
876 addFlag(Buffer, dwarf::DW_AT_reference);
879 addFlag(Buffer, dwarf::DW_AT_rvalue_reference);
890 case dwarf::DW_TAG_array_type:
891 constructArrayTypeDIE(Buffer, CTy);
893 case dwarf::DW_TAG_enumeration_type:
894 constructEnumTypeDIE(Buffer, CTy);
896 case dwarf::DW_TAG_variant_part:
897 case dwarf::DW_TAG_structure_type:
898 case dwarf::DW_TAG_union_type:
899 case dwarf::DW_TAG_class_type: {
902 if (Tag == dwarf::DW_TAG_variant_part) {
909 DIE &DiscMember = constructMemberDIE(Buffer, Discriminator);
910 addDIEEntry(Buffer, dwarf::DW_AT_discr, DiscMember);
916 for (
const auto *Element : Elements) {
919 if (
auto *
SP = dyn_cast<DISubprogram>(Element))
921 else if (
auto *DDTy = dyn_cast<DIDerivedType>(Element)) {
922 if (DDTy->getTag() == dwarf::DW_TAG_friend) {
924 addType(ElemDie, DDTy->getBaseType(), dwarf::DW_AT_friend);
925 }
else if (DDTy->isStaticMember()) {
927 }
else if (Tag == dwarf::DW_TAG_variant_part) {
932 dyn_cast_or_null<ConstantInt>(DDTy->getDiscriminantValue())) {
934 addUInt(Variant, dwarf::DW_AT_discr_value,
None, CI->getZExtValue());
936 addSInt(Variant, dwarf::DW_AT_discr_value,
None, CI->getSExtValue());
938 constructMemberDIE(Variant, DDTy);
940 constructMemberDIE(Buffer, DDTy);
942 }
else if (
auto *Property = dyn_cast<DIObjCProperty>(Element)) {
944 StringRef PropertyName = Property->getName();
945 addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);
946 if (Property->getType())
947 addType(ElemDie, Property->getType());
949 StringRef GetterName = Property->getGetterName();
950 if (!GetterName.
empty())
951 addString(ElemDie, dwarf::DW_AT_APPLE_property_getter, GetterName);
952 StringRef SetterName = Property->getSetterName();
953 if (!SetterName.
empty())
954 addString(ElemDie, dwarf::DW_AT_APPLE_property_setter, SetterName);
955 if (
unsigned PropertyAttributes = Property->getAttributes())
956 addUInt(ElemDie, dwarf::DW_AT_APPLE_property_attribute,
None,
958 }
else if (
auto *Composite = dyn_cast<DICompositeType>(Element)) {
959 if (Composite->getTag() == dwarf::DW_TAG_variant_part) {
967 addFlag(Buffer, dwarf::DW_AT_APPLE_block);
970 addFlag(Buffer, dwarf::DW_AT_export_symbols);
981 addFlag(Buffer, dwarf::DW_AT_APPLE_objc_complete_type);
985 if (Tag == dwarf::DW_TAG_class_type ||
986 Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type)
992 CC = dwarf::DW_CC_pass_by_value;
994 CC = dwarf::DW_CC_pass_by_reference;
996 addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,
1006 addString(Buffer, dwarf::DW_AT_name, Name);
1008 if (Tag == dwarf::DW_TAG_enumeration_type ||
1009 Tag == dwarf::DW_TAG_class_type || Tag == dwarf::DW_TAG_structure_type ||
1010 Tag == dwarf::DW_TAG_union_type) {
1014 addUInt(Buffer, dwarf::DW_AT_byte_size,
None, Size);
1021 addFlag(Buffer, dwarf::DW_AT_declaration);
1030 addUInt(Buffer, dwarf::DW_AT_APPLE_runtime_class, dwarf::DW_FORM_data1,
1035 addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1040 void DwarfUnit::constructTemplateTypeParameterDIE(
1051 void DwarfUnit::constructTemplateValueParameterDIE(
1057 if (VP->
getTag() == dwarf::DW_TAG_template_value_parameter)
1062 if (
ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Val))
1064 else if (
GlobalValue *GV = mdconst::dyn_extract<GlobalValue>(Val)) {
1067 if (!GV->hasDLLImportStorageClass()) {
1074 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
1075 addBlock(ParamDIE, dwarf::DW_AT_location, Loc);
1077 }
else if (VP->
getTag() == dwarf::DW_TAG_GNU_template_template_param) {
1078 assert(isa<MDString>(Val));
1079 addString(ParamDIE, dwarf::DW_AT_GNU_template_name,
1080 cast<MDString>(Val)->getString());
1081 }
else if (VP->
getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) {
1100 Name =
"(anonymous namespace)";
1104 addFlag(NDie, dwarf::DW_AT_export_symbols);
1122 addString(MDie, dwarf::DW_AT_LLVM_config_macros,
1142 if (
auto *SPDecl = SP->getDeclaration()) {
1156 if (SP->isDefinition())
1166 DIE *DeclDie =
nullptr;
1168 if (
auto *SPDecl = SP->getDeclaration()) {
1169 DeclDie =
getDIE(SPDecl);
1170 assert(DeclDie &&
"This DIE should've already been constructed when the " 1171 "definition DIE was created in " 1172 "getOrCreateSubprogramDIE");
1175 DeclLinkageName = SPDecl->getLinkageName();
1176 unsigned DeclID = getOrCreateSourceID(SPDecl->getFile());
1177 unsigned DefID = getOrCreateSourceID(SP->
getFile());
1178 if (DeclID != DefID)
1179 addUInt(SPDie, dwarf::DW_AT_decl_file,
None, DefID);
1181 if (SP->getLine() != SPDecl->getLine())
1182 addUInt(SPDie, dwarf::DW_AT_decl_line,
None, SP->getLine());
1190 assert(((LinkageName.empty() || DeclLinkageName.
empty()) ||
1191 LinkageName == DeclLinkageName) &&
1192 "decl has a linkage name and it is different");
1193 if (DeclLinkageName.
empty() &&
1203 addDIEEntry(SPDie, dwarf::DW_AT_specification, *DeclDie);
1208 bool SkipSPAttributes) {
1211 bool SkipSPSourceLocation = SkipSPAttributes &&
1213 if (!SkipSPSourceLocation)
1221 if (!SkipSPSourceLocation)
1225 if (SkipSPAttributes)
1231 if (SP->isPrototyped() &&
1232 (Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
1233 Language == dwarf::DW_LANG_ObjC))
1234 addFlag(SPDie, dwarf::DW_AT_prototyped);
1236 if (SP->isObjCDirect())
1237 addFlag(SPDie, dwarf::DW_AT_APPLE_objc_direct);
1242 Args = SPTy->getTypeArray();
1247 if (CC && CC != dwarf::DW_CC_normal)
1248 addUInt(SPDie, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1, CC);
1253 if (
auto Ty = Args[0])
1256 unsigned VK = SP->getVirtuality();
1258 addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK);
1259 if (SP->getVirtualIndex() != -1u) {
1261 addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1262 addUInt(*Block, dwarf::DW_FORM_udata, SP->getVirtualIndex());
1263 addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block);
1268 if (!SP->isDefinition()) {
1269 addFlag(SPDie, dwarf::DW_AT_declaration);
1278 if (SP->isArtificial())
1279 addFlag(SPDie, dwarf::DW_AT_artificial);
1281 if (!SP->isLocalToUnit())
1282 addFlag(SPDie, dwarf::DW_AT_external);
1285 if (SP->isOptimized())
1286 addFlag(SPDie, dwarf::DW_AT_APPLE_optimized);
1289 addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag,
isa);
1292 if (SP->isLValueReference())
1293 addFlag(SPDie, dwarf::DW_AT_reference);
1295 if (SP->isRValueReference())
1296 addFlag(SPDie, dwarf::DW_AT_rvalue_reference);
1298 if (SP->isNoReturn())
1299 addFlag(SPDie, dwarf::DW_AT_noreturn);
1301 if (SP->isProtected())
1302 addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1304 else if (SP->isPrivate())
1305 addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1307 else if (SP->isPublic())
1308 addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1311 if (SP->isExplicit())
1312 addFlag(SPDie, dwarf::DW_AT_explicit);
1314 if (SP->isMainSubprogram())
1315 addFlag(SPDie, dwarf::DW_AT_main_subprogram);
1317 addFlag(SPDie, dwarf::DW_AT_pure);
1318 if (SP->isElemental())
1319 addFlag(SPDie, dwarf::DW_AT_elemental);
1320 if (SP->isRecursive())
1321 addFlag(SPDie, dwarf::DW_AT_recursive);
1324 addFlag(SPDie, dwarf::DW_AT_deleted);
1327 void DwarfUnit::constructSubrangeDIE(
DIE &Buffer,
const DISubrange *SR,
1330 addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IndexTy);
1336 int64_t LowerBound = SR->getLowerBound();
1337 int64_t DefaultLowerBound = getDefaultLowerBound();
1340 Count = CI->getSExtValue();
1342 if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound)
1343 addUInt(DW_Subrange, dwarf::DW_AT_lower_bound,
None, LowerBound);
1346 if (
auto *CountVarDIE =
getDIE(CV))
1347 addDIEEntry(DW_Subrange, dwarf::DW_AT_count, *CountVarDIE);
1348 }
else if (Count != -1)
1349 addUInt(DW_Subrange, dwarf::DW_AT_count,
None, Count);
1352 DIE *DwarfUnit::getIndexTyDie() {
1361 dwarf::DW_ATE_unsigned);
1370 assert(CTy && CTy->
isVector() &&
"Composite type is not a vector");
1375 assert(BaseTy &&
"Unknown vector element type.");
1380 assert(Elements.size() == 1 &&
1381 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type &&
1382 "Invalid vector element array, expected one element of type subrange");
1383 const auto Subrange = cast<DISubrange>(Elements[0]);
1384 const auto CI = Subrange->getCount().get<
ConstantInt *>();
1389 assert(ActualSize >= (NumVecElements * ElementSize) &&
"Invalid vector size");
1390 return ActualSize != (NumVecElements * ElementSize);
1395 addFlag(Buffer, dwarf::DW_AT_GNU_vector);
1407 DIE *IdxTy = getIndexTyDie();
1411 for (
unsigned i = 0,
N = Elements.size(); i <
N; ++i) {
1413 if (
auto *Element = dyn_cast_or_null<DINode>(Elements[i]))
1414 if (Element->getTag() == dwarf::DW_TAG_subrange_type)
1415 constructSubrangeDIE(Buffer, cast<DISubrange>(Element), IdxTy);
1426 addFlag(Buffer, dwarf::DW_AT_enum_class);
1430 bool IndexEnumerators = !Context || isa<DICompileUnit>(
Context) || isa<DIFile>(Context) ||
1431 isa<DINamespace>(
Context) || isa<DICommonBlock>(Context);
1435 for (
unsigned i = 0,
N = Elements.size(); i <
N; ++i) {
1436 auto *Enum = dyn_cast_or_null<DIEnumerator>(Elements[i]);
1440 addString(Enumerator, dwarf::DW_AT_name, Name);
1441 auto Value =
static_cast<uint64_t
>(Enum->getValue());
1443 if (IndexEnumerators)
1452 DIE &SPDie = *CI->first;
1459 addDIEEntry(SPDie, dwarf::DW_AT_containing_type, *NDie);
1467 addString(MemberDie, dwarf::DW_AT_name, Name);
1469 if (
DIType *Resolved = DT->getBaseType())
1481 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_dup);
1482 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1483 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1485 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_minus);
1486 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1487 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
1489 addBlock(MemberDie, dwarf::DW_AT_data_member_location, VBaseLocationDie);
1494 uint64_t OffsetInBytes;
1496 bool IsBitfield = FieldSize && Size != FieldSize;
1500 addUInt(MemberDie, dwarf::DW_AT_byte_size,
None, FieldSize/8);
1501 addUInt(MemberDie, dwarf::DW_AT_bit_size,
None, Size);
1508 uint32_t AlignMask = ~(AlignInBits - 1);
1510 uint64_t StartBitOffset = Offset - (Offset & AlignMask);
1512 OffsetInBytes = (Offset - StartBitOffset) / 8;
1515 uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1516 uint64_t FieldOffset = (HiMark - FieldSize);
1517 Offset -= FieldOffset;
1521 Offset = FieldSize - (Offset + Size);
1523 addUInt(MemberDie, dwarf::DW_AT_bit_offset,
None, Offset);
1524 OffsetInBytes = FieldOffset >> 3;
1526 addUInt(MemberDie, dwarf::DW_AT_data_bit_offset,
None, Offset);
1532 addUInt(MemberDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1538 addUInt(*MemLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
1539 addUInt(*MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes);
1540 addBlock(MemberDie, dwarf::DW_AT_data_member_location, MemLocationDie);
1542 addUInt(MemberDie, dwarf::DW_AT_data_member_location,
None,
1547 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1550 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1554 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1557 addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1,
1558 dwarf::DW_VIRTUALITY_virtual);
1561 if (
DINode *PNode = DT->getObjCProperty())
1564 dwarf::DW_FORM_ref4,
DIEEntry(*PDie));
1567 addFlag(MemberDie, dwarf::DW_AT_artificial);
1580 "Static member should belong to a type.");
1583 return StaticMemberDIE;
1587 const DIType *Ty = DT->getBaseType();
1592 addFlag(StaticMemberDIE, dwarf::DW_AT_external);
1593 addFlag(StaticMemberDIE, dwarf::DW_AT_declaration);
1598 addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1601 addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1604 addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1607 if (
const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(DT->getConstant()))
1609 if (
const ConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT->getConstant()))
1613 addUInt(StaticMemberDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1616 return &StaticMemberDIE;
1663 : dwarf::DW_UT_type);
1665 Asm->
OutStreamer->EmitIntValue(TypeSignature,
sizeof(TypeSignature));
1669 sizeof(Ty->getOffset()));
1677 : dwarf::DW_FORM_data4,
1687 : dwarf::DW_FORM_data4,
1692 bool DwarfTypeUnit::isDwoUnit()
const {
1708 const MCSymbol *DwarfUnit::getCrossSectionRelativeBaseAddress()
const {
1725 "DW_AT_rnglists_base requires DWARF version 5 or later");
1729 TLOF.getDwarfRnglistsSection()->getBeginSymbol());
1733 addFlag(D, dwarf::DW_AT_declaration);
const DICompileUnit * getCUNode() const
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
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.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
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.
This class represents lattice values for constants.
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 ...
NonTypeUnitContext enterNonTypeUnitContext()
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
MCContext & OutContext
This is the context for the output file that we are streaming.
void push_back(const T &Elt)
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.
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 ...
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
uint16_t getDwarfVersion() 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.
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.
MCSymbol * getRnglistsTableBaseSym() const
bool isLValueReference() const
bool isDebugDirectivesOnly() 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.
StringRef getSysRoot() const
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
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.
DIType * getBaseType() const
StringRef getIncludePath() const
EntryRef getIndexedEntry(AsmPrinter &Asm, StringRef Str)
Same as getEntry, except that you can use EntryRef::getIndex to obtain a unique ID of this entry (e...
unsigned getRuntimeLang() const
DenseMap< const MDNode *, DIE * > & getAbstractSPDies()
MDString * getRawName() const
bool doesDwarfUseRelocationsAcrossSections() const
uint32_t getAlignInBytes() const
DwarfCompileUnit & getCU() override
const APInt & getValue() const
Return the constant as an APInt value reference.
bool isLittleEndian() const
Layout endianness...
MCSymbol * EndLabel
Emitted at the end of the CU and used to compute the CU Length field.
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)
void takeValues(DIEValueList &Other)
Take ownership of the nodes in Other, and append them to the back of the list.
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.
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.
bool applySubprogramDefinitionAttributes(const DISubprogram *SP, DIE &SPDie)
const MCAsmInfo * MAI
Target Asm Printer information.
Instrumentation for Order File
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].
DIEUnit * getUnit() const
Climb up the parent chain to get the compile unit or type unit that this DIE belongs to...
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.
DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal=false)
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
void addAccelType(const DICompileUnit &CU, StringRef Name, const DIE &Die, char Flags)
Base class for variables.
static uint64_t getBaseTypeSize(const DIType *Ty)
If this type is derived from a base type then return base type size.
bool isObjcClassComplete() const
DIEDwarfExpression(const AsmPrinter &AP, DwarfCompileUnit &CU, DIELoc &DIE)
DIScope * getScope() const
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
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.
bool isLittleEndian() const
bool useSectionsAsReferences() const
Returns whether to use sections as labels rather than temp symbols.
This is the shared class of boolean and integer constants.
void addAccelNamespace(const DICompileUnit &CU, StringRef Name, const DIE &Die)
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...
virtual Register getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
void addLinkageName(DIE &Die, StringRef LinkageName)
Add a linkage name, if it isn't empty.
DIScope * getScope() const
Represents a compile or type unit.
Optional< MD5::MD5Result > getMD5AsBytes(const DIFile *File) const
If the File has an MD5 checksum, return it as an MD5Result allocated in the MCContext.
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
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.
dwarf::Form BestForm(unsigned DwarfVersion) const
BestForm - Choose the best form for data.
DIType * getVTableHolder() const
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
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 EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) const
Emit something like ".long Hi-Lo" where the size in bytes of the directive is specified by Size and H...
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.
unsigned getFile(StringRef Directory, StringRef FileName, Optional< MD5::MD5Result > Checksum, uint16_t DwarfVersion, Optional< StringRef > Source)
bool getExportSymbols() const
void addSectionOffset(DIE &Die, dwarf::Attribute Attribute, uint64_t Integer)
Add an offset into a section attribute data and value.
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())
std::array< uint8_t, 16 > Bytes
DIE * createTypeDIE(const DIScope *Context, DIE &ContextDIE, const DIType *Ty)
Creates type DIE with specific context.
void emitInt8(int Value) const
Emit a byte directive and value.
LLVM Value Representation.
void addStringOffsetsStart()
Add the DW_AT_str_offsets_base attribute to the unit DIE.
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.
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 ...
OutputIt copy(R &&Range, OutputIt Out)
bool isCPlusPlus(SourceLanguage S)
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)
MCSymbol * createTempSymbol(const Twine &Name) 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.
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.