1//===-- llvm/CodeGen/DwarfUnit.cpp - Dwarf Type and Compile Units ---------===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 9// This file contains support for constructing a dwarf compile unit. 11//===----------------------------------------------------------------------===// 39#define DEBUG_TYPE "dwarfdebug" 45void DIEDwarfExpression::emitOp(
uint8_tOp,
constchar* Comment) {
46CU.addUInt(getActiveDIE(), dwarf::DW_FORM_data1,
Op);
49void DIEDwarfExpression::emitSigned(int64_t
Value) {
50CU.addSInt(getActiveDIE(), dwarf::DW_FORM_sdata,
Value);
54CU.addUInt(getActiveDIE(), dwarf::DW_FORM_udata,
Value);
58CU.addUInt(getActiveDIE(), dwarf::DW_FORM_data1,
Value);
61void DIEDwarfExpression::emitBaseTypeRef(
uint64_tIdx) {
62CU.addBaseTypeRef(getActiveDIE(),
Idx);
65void DIEDwarfExpression::enableTemporaryBuffer() {
66assert(!IsBuffering &&
"Already buffering?");
70void DIEDwarfExpression::disableTemporaryBuffer() { IsBuffering =
false; }
72unsigned DIEDwarfExpression::getTemporaryBufferSize() {
76void DIEDwarfExpression::commitTemporaryBuffer() { OutDIE.
takeValues(TmpDIE); }
80return MachineReg ==
TRI.getFrameRegister(*AP.
MF);
86 :
DIEUnit(UnitTag), UniqueID(UniqueID), CUNode(Node), Asm(
A), DD(DW),
92 :
DwarfUnit(dwarf::DW_TAG_type_unit,
CU.getCUNode(),
A, DW, DWU, UniqueID),
93CU(
CU), SplitLineTable(SplitLineTable) {}
102int64_t DwarfUnit::getDefaultLowerBound()
const{
107// The languages below have valid values in all DWARF versions. 108case dwarf::DW_LANG_C:
109case dwarf::DW_LANG_C89:
110case dwarf::DW_LANG_C_plus_plus:
113case dwarf::DW_LANG_Fortran77:
114case dwarf::DW_LANG_Fortran90:
117// The languages below have valid values only if the DWARF version >= 3. 118case dwarf::DW_LANG_C99:
119case dwarf::DW_LANG_ObjC:
120case dwarf::DW_LANG_ObjC_plus_plus:
125case dwarf::DW_LANG_Fortran95:
130// Starting with DWARF v4, all defined languages have valid values. 131case dwarf::DW_LANG_D:
132case dwarf::DW_LANG_Java:
133case dwarf::DW_LANG_Python:
134case dwarf::DW_LANG_UPC:
139case dwarf::DW_LANG_Ada83:
140case dwarf::DW_LANG_Ada95:
141case dwarf::DW_LANG_Cobol74:
142case dwarf::DW_LANG_Cobol85:
143case dwarf::DW_LANG_Modula2:
144case dwarf::DW_LANG_Pascal83:
145case dwarf::DW_LANG_PLI:
150// The languages below are new in DWARF v5. 151case dwarf::DW_LANG_BLISS:
152case dwarf::DW_LANG_C11:
153case dwarf::DW_LANG_C_plus_plus_03:
154case dwarf::DW_LANG_C_plus_plus_11:
155case dwarf::DW_LANG_C_plus_plus_14:
156case dwarf::DW_LANG_Dylan:
157case dwarf::DW_LANG_Go:
158case dwarf::DW_LANG_Haskell:
159case dwarf::DW_LANG_OCaml:
160case dwarf::DW_LANG_OpenCL:
161case dwarf::DW_LANG_RenderScript:
162case dwarf::DW_LANG_Rust:
163case dwarf::DW_LANG_Swift:
168case dwarf::DW_LANG_Fortran03:
169case dwarf::DW_LANG_Fortran08:
170case dwarf::DW_LANG_Julia:
171case dwarf::DW_LANG_Modula3:
180/// Check whether the DIE for this MDNode can be shared across CUs. 182// When the MDNode can be part of the type system, the DIE can be shared 184// Combining type units and cross-CU DIE sharing is lower value (since 185// cross-CU DIE sharing is used in LTO and removes type redundancy at that 186// level already) but may be implementable for some value in projects 187// building multiple independent libraries with LTO and then linking those 191return (isa<DIType>(
D) ||
192 (isa<DISubprogram>(
D) && !cast<DISubprogram>(
D)->isDefinition())) &&
225assert(Form != dwarf::DW_FORM_implicit_const &&
226"DW_FORM_implicit_const is used only for signed integers");
236 std::optional<dwarf::Form> Form, int64_t
Integer) {
259 isDwoUnit() ? dwarf::DW_FORM_GNU_str_index : dwarf::DW_FORM_strp;
261auto StringPoolEntry =
266// For DWARF v5 and beyond, use the smallest strx? form possible. 268 IxForm = dwarf::DW_FORM_strx1;
269unsigned Index = StringPoolEntry.getIndex();
271 IxForm = dwarf::DW_FORM_strx4;
272elseif (Index > 0xffff)
273 IxForm = dwarf::DW_FORM_strx3;
275 IxForm = dwarf::DW_FORM_strx2;
294unsigned DwarfTypeUnit::getOrCreateSourceID(
constDIFile *File) {
299// This is a split type unit that needs a line table. 308bool UseAddrOffsetFormOrExpressions =
312if (Label->isInSection() && UseAddrOffsetFormOrExpressions)
318addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addrx);
319addUInt(Die, dwarf::DW_FORM_addrx, Index);
321addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index);
322addUInt(Die, dwarf::DW_FORM_GNU_addr_index, Index);
326addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_const4u);
328addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
343addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
358// Flag the type unit reference as a declaration so that if it contains 359// members (implicit special members, static data member definitions, member 360// declarations for definitions in this CU, etc) consumers don't get confused 361// and think this is a full definition. 362addFlag(Die, dwarf::DW_AT_declaration);
364addAttribute(Die, dwarf::DW_AT_signature, dwarf::DW_FORM_ref_sig8,
371constDIEUnit *EntryCU = Entry.getEntry().getUnit();
373// We assume that Die belongs to this CU, if it is not linked to any CU yet. 380 EntryCU ==
CU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,
393DIELocs.push_back(Loc);
// Memoize so we can call the destructor later on. 400DIEBlocks.push_back(
Block);
// Memoize so we can call the destructor later on. 414addUInt(Die, dwarf::DW_AT_decl_file, std::nullopt, FileID);
415addUInt(Die, dwarf::DW_AT_decl_line, std::nullopt, Line);
455// Pass this down to addConstantValue as an unsigned bag of bits. 469// FIXME: This is a bit conservative/simple - it emits negative values always 470// sign extended to 64 bits rather than minimizing the number of bytes. 471addUInt(Die, dwarf::DW_AT_const_value,
472Unsigned ? dwarf::DW_FORM_udata : dwarf::DW_FORM_sdata, Val);
481if (CIBitWidth <= 64) {
489// Get the raw data form of the large APInt. 492int NumBytes = Val.
getBitWidth() / 8;
// 8 bits per byte. 495// Output the constant to DWARF one byte at a time. 496for (
int i = 0; i < NumBytes; i++) {
499 c = Ptr64[i / 8] >> (8 * (i & 7));
501 c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7));
512 : dwarf::DW_AT_MIPS_linkage_name,
517// Add template parameters. 518for (
constauto *Element : TParams) {
519if (
auto *TTP = dyn_cast<DITemplateTypeParameter>(Element))
520 constructTemplateTypeParameterDIE(Buffer, TTP);
521elseif (
auto *TVP = dyn_cast<DITemplateValueParameter>(Element))
522 constructTemplateValueParameterDIE(Buffer, TVP);
528for (
constauto *Ty : ThrownTypes) {
536addUInt(Die, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
539addUInt(Die, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
542addUInt(Die, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
547if (!Context || isa<DIFile>(Context) || isa<DICompileUnit>(Context))
549if (
auto *
T = dyn_cast<DIType>(Context))
551if (
auto *NS = dyn_cast<DINamespace>(Context))
553if (
auto *SP = dyn_cast<DISubprogram>(Context))
555if (
auto *M = dyn_cast<DIModule>(Context))
581auto construct = [&](
constauto *Ty) {
586if (
auto *CTy = dyn_cast<DICompositeType>(Ty)) {
588 (Ty->
getRawName() || CTy->getRawIdentifier())) {
589// Skip updating the accelerator tables since this is not the full type. 590if (
MDString *TypeId = CTy->getRawIdentifier()) {
595 finishNonUnitTypeDIE(TyDIE, CTy);
600 }
elseif (
auto *
BT = dyn_cast<DIBasicType>(Ty))
602elseif (
auto *ST = dyn_cast<DIStringType>(Ty))
604elseif (
auto *STy = dyn_cast<DISubroutineType>(Ty))
607 construct(cast<DIDerivedType>(Ty));
616auto *Ty = cast<DIType>(TyNode);
618// DW_TAG_restrict_type is not supported in DWARF2 622// DW_TAG_atomic_type is not supported in DWARF < 5 626// Construct the context before querying for the existence of the DIE in case 627// such construction creates the DIE. 628auto *Context = Ty->getScope();
646// add temporary record for this type to be added later 649if (
auto *CT = dyn_cast<DICompositeType>(Ty)) {
650// A runtime language of 0 actually means C/C++ and that any 651// non-negative value is some version of Objective-C/C++. 652if (CT->getRuntimeLang() == 0 || CT->isObjcClassComplete())
659if (
auto *CT = dyn_cast<DICompositeType>(Ty))
660if (Ty->
getName() != CT->getIdentifier() &&
661 CT->getRuntimeLang() == dwarf::DW_LANG_Swift)
670if (!Context || isa<DICompileUnit>(Context) || isa<DIFile>(Context) ||
671 isa<DINamespace>(Context) || isa<DICommonBlock>(Context))
677assert(Ty &&
"Trying to add a type that doesn't exist?");
685// FIXME: Decide whether to implement this for non-C++ languages. 691while (!isa<DICompileUnit>(Context)) {
692 Parents.push_back(Context);
696// Structure, etc types will have a NULL context if they're at the top 701// Reverse iterate over our list to go from the outermost construct to the 705if (
Name.empty() && isa<DINamespace>(Ctx))
706Name =
"(anonymous namespace)";
716// Get core information. 718// Add name if not anonymous or intermediate type. 722// An unspecified type only has a name attribute. 723if (BTy->
getTag() == dwarf::DW_TAG_unspecified_type)
726if (BTy->
getTag() != dwarf::DW_TAG_string_type)
727addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
731addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt,
Size);
734addUInt(Buffer, dwarf::DW_AT_endianity, std::nullopt, dwarf::DW_END_big);
736addUInt(Buffer, dwarf::DW_AT_endianity, std::nullopt, dwarf::DW_END_little);
739addUInt(Buffer, dwarf::DW_AT_LLVM_num_extra_inhabitants, std::nullopt,
740 NumExtraInhabitants);
744// Get core information. 746// Add name if not anonymous or intermediate type. 751if (
auto *VarDIE =
getDIE(Var))
752addDIEEntry(Buffer, dwarf::DW_AT_string_length, *VarDIE);
756// This is to describe the memory location of the 757// length of a Fortran deferred length string, so 758// lock it down as such. 759 DwarfExpr.setMemoryLocationKind();
760 DwarfExpr.addExpression(Expr);
761addBlock(Buffer, dwarf::DW_AT_string_length, DwarfExpr.finalize());
764addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt,
Size);
770// This is to describe the memory location of the 771// string, so lock it down as such. 772 DwarfExpr.setMemoryLocationKind();
773 DwarfExpr.addExpression(Expr);
774addBlock(Buffer, dwarf::DW_AT_data_location, DwarfExpr.finalize());
778// For eventual Unicode support. 779addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
785// Get core information. 790// Map to main type, void will not have a type. 791constDIType *FromTy = DTy->getBaseType();
795// Add name if not anonymous or intermediate type. 801// If alignment is specified for a typedef , create and insert DW_AT_alignment 802// attribute in DW_TAG_typedef DIE. 806addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
810// Add size if non-zero (derived types might be zero-sized.) 811if (
Size &&
Tag != dwarf::DW_TAG_pointer_type
812 &&
Tag != dwarf::DW_TAG_ptr_to_member_type
813 &&
Tag != dwarf::DW_TAG_reference_type
814 &&
Tag != dwarf::DW_TAG_rvalue_reference_type)
815addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt,
Size);
817if (
Tag == dwarf::DW_TAG_ptr_to_member_type)
823// Add source line info if available and TyDesc is not a forward declaration. 827// If DWARF address space value is other than None, add it. The IR 828// verifier checks that DWARF address space only exists for pointer 829// or reference types. 830if (DTy->getDWARFAddressSpace())
831addUInt(Buffer, dwarf::DW_AT_address_class, dwarf::DW_FORM_data4,
832 *DTy->getDWARFAddressSpace());
834// Add template alias template parameters. 835if (
Tag == dwarf::DW_TAG_template_alias)
838if (
auto PtrAuthData = DTy->getPtrAuthData()) {
839addUInt(Buffer, dwarf::DW_AT_LLVM_ptrauth_key, dwarf::DW_FORM_data1,
841if (PtrAuthData->isAddressDiscriminated())
842addFlag(Buffer, dwarf::DW_AT_LLVM_ptrauth_address_discriminated);
843addUInt(Buffer, dwarf::DW_AT_LLVM_ptrauth_extra_discriminator,
844 dwarf::DW_FORM_data2, PtrAuthData->extraDiscriminator());
845if (PtrAuthData->isaPointer())
846addFlag(Buffer, dwarf::DW_AT_LLVM_ptrauth_isa_pointer);
847if (PtrAuthData->authenticatesNullValues())
848addFlag(Buffer, dwarf::DW_AT_LLVM_ptrauth_authenticates_null_values);
853// Args[0] is the return type. 854DIE *ObjectPointer =
nullptr;
855for (
unsigned i = 1,
N = Args.size(); i <
N; ++i) {
858assert(i ==
N-1 &&
"Unspecified parameter must be the last argument");
864addFlag(Arg, dwarf::DW_AT_artificial);
866assert(!ObjectPointer &&
"Can't have more than one object pointer");
867 ObjectPointer = &Arg;
876// Add return type. A void return won't have a type. 877auto Elements = cast<DISubroutineType>(CTy)->getTypeArray();
879if (
auto RTy = Elements[0])
882bool isPrototyped =
true;
883if (Elements.size() == 2 && !Elements[1])
888// Add prototype flag if we're dealing with a C language and the function has 891addFlag(Buffer, dwarf::DW_AT_prototyped);
893// Add a DW_AT_calling_convention if this has an explicit convention. 894if (CTy->
getCC() && CTy->
getCC() != dwarf::DW_CC_normal)
895addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,
899addFlag(Buffer, dwarf::DW_AT_reference);
902addFlag(Buffer, dwarf::DW_AT_rvalue_reference);
910constMDNode *MD = cast<MDNode>(Annotation);
915addString(AnnotationDie, dwarf::DW_AT_name,
Name->getString());
916if (
constauto *
Data = dyn_cast<MDString>(
Value))
917addString(AnnotationDie, dwarf::DW_AT_const_value,
Data->getString());
918elseif (
constauto *
Data = dyn_cast<ConstantAsMetadata>(
Value))
922assert(
false &&
"Unsupported annotation value type");
927// Add name if not anonymous or intermediate type. 934case dwarf::DW_TAG_array_type:
935 constructArrayTypeDIE(Buffer, CTy);
937case dwarf::DW_TAG_enumeration_type:
938 constructEnumTypeDIE(Buffer, CTy);
940case dwarf::DW_TAG_variant_part:
941case dwarf::DW_TAG_structure_type:
942case dwarf::DW_TAG_union_type:
943case dwarf::DW_TAG_class_type:
944case dwarf::DW_TAG_namelist: {
945// Emit the discriminator for a variant part. 947if (
Tag == dwarf::DW_TAG_variant_part) {
951// If the variant part has a discriminant, the discriminant is 952// represented by a separate debugging information entry which is 953// a child of the variant part entry. 954DIE &DiscMember = constructMemberDIE(Buffer, Discriminator);
955addDIEEntry(Buffer, dwarf::DW_AT_discr, DiscMember);
959// Add template parameters to a class, structure or union types. 960if (
Tag == dwarf::DW_TAG_class_type ||
961Tag == dwarf::DW_TAG_structure_type ||
Tag == dwarf::DW_TAG_union_type)
964// Add elements to structure type. 966for (
constauto *Element : Elements) {
969if (
auto *SP = dyn_cast<DISubprogram>(Element))
971elseif (
auto *DDTy = dyn_cast<DIDerivedType>(Element)) {
972if (DDTy->getTag() == dwarf::DW_TAG_friend) {
974addType(ElemDie, DDTy->getBaseType(), dwarf::DW_AT_friend);
975 }
elseif (DDTy->isStaticMember()) {
977 }
elseif (
Tag == dwarf::DW_TAG_variant_part) {
978// When emitting a variant part, wrap each member in 982 dyn_cast_or_null<ConstantInt>(DDTy->getDiscriminantValue())) {
984addUInt(Variant, dwarf::DW_AT_discr_value, std::nullopt,
987addSInt(Variant, dwarf::DW_AT_discr_value, std::nullopt,
990 constructMemberDIE(Variant, DDTy);
992 constructMemberDIE(Buffer, DDTy);
994 }
elseif (
auto *Property = dyn_cast<DIObjCProperty>(Element)) {
996StringRef PropertyName = Property->getName();
997addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);
998if (Property->getType())
999addType(ElemDie, Property->getType());
1001StringRef GetterName = Property->getGetterName();
1002if (!GetterName.
empty())
1003addString(ElemDie, dwarf::DW_AT_APPLE_property_getter, GetterName);
1004StringRef SetterName = Property->getSetterName();
1005if (!SetterName.
empty())
1006addString(ElemDie, dwarf::DW_AT_APPLE_property_setter, SetterName);
1007if (
unsigned PropertyAttributes = Property->getAttributes())
1008addUInt(ElemDie, dwarf::DW_AT_APPLE_property_attribute, std::nullopt,
1009 PropertyAttributes);
1010 }
elseif (
auto *Composite = dyn_cast<DICompositeType>(Element)) {
1011if (Composite->getTag() == dwarf::DW_TAG_variant_part) {
1015 }
elseif (
Tag == dwarf::DW_TAG_namelist) {
1016auto *Var = dyn_cast<DINode>(Element);
1017auto *VarDIE =
getDIE(Var);
1020addDIEEntry(ItemDie, dwarf::DW_AT_namelist_item, *VarDIE);
1026addFlag(Buffer, dwarf::DW_AT_APPLE_block);
1029addFlag(Buffer, dwarf::DW_AT_export_symbols);
1031// This is outside the DWARF spec, but GDB expects a DW_AT_containing_type 1032// inside C++ composite types to point to the base class with the vtable. 1033// Rust uses DW_AT_containing_type to link a vtable to the type 1034// for which it was created. 1040addFlag(Buffer, dwarf::DW_AT_APPLE_objc_complete_type);
1042// Add the type's non-standard calling convention. 1043// DW_CC_pass_by_value/DW_CC_pass_by_reference are introduced in DWARF 5. 1047CC = dwarf::DW_CC_pass_by_value;
1049CC = dwarf::DW_CC_pass_by_reference;
1051addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,
1065// Add name if not anonymous or intermediate type. 1069// For Swift, mangled names are put into DW_AT_linkage_name. 1075if (
Tag == dwarf::DW_TAG_enumeration_type ||
1076Tag == dwarf::DW_TAG_class_type ||
Tag == dwarf::DW_TAG_structure_type ||
1077Tag == dwarf::DW_TAG_union_type) {
1078// Add size if non-zero (derived types might be zero-sized.) 1079// Ignore the size if it's a non-enum forward decl. 1080// TODO: Do we care about size for enum forward declarations? 1083addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt,
Size);
1085// Add zero size if it is not a forward declaration. 1086addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, 0);
1088// If we're a forward decl, say so. 1090addFlag(Buffer, dwarf::DW_AT_declaration);
1092// Add accessibility info if available. 1095// Add source line info if available. 1099// No harm in adding the runtime language to the declaration. 1102addUInt(Buffer, dwarf::DW_AT_APPLE_runtime_class, dwarf::DW_FORM_data1,
1105// Add align info if available. 1107addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1111addUInt(Buffer, dwarf::DW_AT_LLVM_num_extra_inhabitants, std::nullopt,
1112 NumExtraInhabitants);
1116void DwarfUnit::constructTemplateTypeParameterDIE(
1120// Add the type if it exists, it could be void and therefore no type. 1125if (TP->
isDefault() && isCompatibleWithVersion(5))
1126addFlag(ParamDIE, dwarf::DW_AT_default_value);
1129void DwarfUnit::constructTemplateValueParameterDIE(
1133// Add the type if there is one, template template and template parameter 1134// packs will not have a type. 1135if (VP->
getTag() == dwarf::DW_TAG_template_value_parameter)
1139if (VP->
isDefault() && isCompatibleWithVersion(5))
1140addFlag(ParamDIE, dwarf::DW_AT_default_value);
1142if (
ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Val))
1144elseif (
GlobalValue *GV = mdconst::dyn_extract<GlobalValue>(Val)) {
1145// We cannot describe the location of dllimport'd entities: the 1146// computation of their address requires loads from the IAT. 1147if (!GV->hasDLLImportStorageClass()) {
1148// For declaration non-type template parameters (such as global values 1152// Emit DW_OP_stack_value to use the address as the immediate value of 1153// the parameter, rather than a pointer to it. 1154addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
1155addBlock(ParamDIE, dwarf::DW_AT_location, Loc);
1157 }
elseif (VP->
getTag() == dwarf::DW_TAG_GNU_template_template_param) {
1158assert(isa<MDString>(Val));
1159addString(ParamDIE, dwarf::DW_AT_GNU_template_name,
1160 cast<MDString>(Val)->getString());
1161 }
elseif (VP->
getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) {
1168// Construct the context before querying for the existence of the DIE in case 1169// such construction creates the DIE. 1180Name =
"(anonymous namespace)";
1184addFlag(NDie, dwarf::DW_AT_export_symbols);
1189// Construct the context before querying for the existence of the DIE in case 1190// such construction creates the DIE. 1197if (!M->getName().empty()) {
1198addString(MDie, dwarf::DW_AT_name, M->getName());
1201if (!M->getConfigurationMacros().empty())
1202addString(MDie, dwarf::DW_AT_LLVM_config_macros,
1203 M->getConfigurationMacros());
1204if (!M->getIncludePath().empty())
1205addString(MDie, dwarf::DW_AT_LLVM_include_path, M->getIncludePath());
1206if (!M->getAPINotesFile().empty())
1207addString(MDie, dwarf::DW_AT_LLVM_apinotes, M->getAPINotesFile());
1209addUInt(MDie, dwarf::DW_AT_decl_file, std::nullopt,
1212addUInt(MDie, dwarf::DW_AT_decl_line, std::nullopt, M->getLineNo());
1214addFlag(MDie, dwarf::DW_AT_declaration);
1220// Construct the context before querying for the existence of the DIE in case 1221// such construction creates the DIE (as is the case for member function 1229if (
auto *SPDecl = SP->getDeclaration()) {
1231// Add subprogram definitions to the CU die directly. 1233// Build the decl now to ensure it precedes the definition. 1238// DW_TAG_inlined_subroutine may refer to this DIE. 1241// Stop here and fill this in later, depending on whether or not this 1242// subprogram turns out to have inlined instances or not. 1243if (SP->isDefinition())
1252DIE &SPDie,
bool Minimal) {
1253DIE *DeclDie =
nullptr;
1255if (
auto *SPDecl = SP->getDeclaration()) {
1258 DeclArgs = SPDecl->getType()->getTypeArray();
1259 DefinitionArgs = SP->getType()->getTypeArray();
1261if (DeclArgs.
size() && DefinitionArgs.
size())
1262if (DefinitionArgs[0] !=
nullptr && DeclArgs[0] != DefinitionArgs[0])
1263addType(SPDie, DefinitionArgs[0]);
1266assert(DeclDie &&
"This DIE should've already been constructed when the " 1267"definition DIE was created in " 1268"getOrCreateSubprogramDIE");
1269// Look at the Decl's linkage name only if we emitted it. 1271 DeclLinkageName = SPDecl->getLinkageName();
1275addUInt(SPDie, dwarf::DW_AT_decl_file, std::nullopt, DefID);
1277if (SP->getLine() != SPDecl->getLine())
1278addUInt(SPDie, dwarf::DW_AT_decl_line, std::nullopt, SP->getLine());
1282// Add function template parameters. 1285// Add the linkage name if we have one and it isn't in the Decl. 1289"decl has a linkage name and it is different");
1290if (DeclLinkageName.
empty() &&
1291// Always emit it for abstract subprograms. 1298// Refer to the function declaration where all the other attributes will be 1300addDIEEntry(SPDie, dwarf::DW_AT_specification, *DeclDie);
1305bool SkipSPAttributes) {
1306// If -fdebug-info-for-profiling is enabled, need to emit the subprogram 1307// and its source location. 1308bool SkipSPSourceLocation = SkipSPAttributes &&
1310if (!SkipSPSourceLocation)
1314// Constructors and operators for anonymous aggregates do not have names. 1320if (!SkipSPSourceLocation)
1323// Skip the rest of the attributes under -gmlt to save space. 1324if (SkipSPAttributes)
1327// Add the prototype if we have a prototype and we have a C like 1330addFlag(SPDie, dwarf::DW_AT_prototyped);
1332if (SP->isObjCDirect())
1333addFlag(SPDie, dwarf::DW_AT_APPLE_objc_direct);
1338 Args = SPTy->getTypeArray();
1342// Add a DW_AT_calling_convention if this has an explicit convention. 1343if (
CC &&
CC != dwarf::DW_CC_normal)
1344addUInt(SPDie, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,
CC);
1346// Add a return type. If this is a type like a C/C++ void type we don't add a 1349if (
auto Ty = Args[0])
1352unsigned VK = SP->getVirtuality();
1354addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK);
1355if (SP->getVirtualIndex() != -1u) {
1357addUInt(*
Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1358addUInt(*
Block, dwarf::DW_FORM_udata, SP->getVirtualIndex());
1364if (!SP->isDefinition()) {
1365addFlag(SPDie, dwarf::DW_AT_declaration);
1367// Add arguments. Do not add arguments for subprogram definition. They will 1368// be handled while processing variables. 1370addDIEEntry(SPDie, dwarf::DW_AT_object_pointer, *ObjectPointer);
1375if (SP->isArtificial())
1376addFlag(SPDie, dwarf::DW_AT_artificial);
1378if (!SP->isLocalToUnit())
1379addFlag(SPDie, dwarf::DW_AT_external);
1382if (SP->isOptimized())
1383addFlag(SPDie, dwarf::DW_AT_APPLE_optimized);
1386addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag,
isa);
1389if (SP->isLValueReference())
1390addFlag(SPDie, dwarf::DW_AT_reference);
1392if (SP->isRValueReference())
1393addFlag(SPDie, dwarf::DW_AT_rvalue_reference);
1395if (SP->isNoReturn())
1396addFlag(SPDie, dwarf::DW_AT_noreturn);
1400if (SP->isExplicit())
1401addFlag(SPDie, dwarf::DW_AT_explicit);
1403if (SP->isMainSubprogram())
1404addFlag(SPDie, dwarf::DW_AT_main_subprogram);
1406addFlag(SPDie, dwarf::DW_AT_pure);
1407if (SP->isElemental())
1408addFlag(SPDie, dwarf::DW_AT_elemental);
1409if (SP->isRecursive())
1410addFlag(SPDie, dwarf::DW_AT_recursive);
1412if (!SP->getTargetFuncName().empty())
1413addString(SPDie, dwarf::DW_AT_trampoline, SP->getTargetFuncName());
1416addFlag(SPDie, dwarf::DW_AT_deleted);
1419void DwarfUnit::constructSubrangeDIE(
DIE &Buffer,
constDISubrange *SR,
1422addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IndexTy);
1424// The LowerBound value defines the lower bounds which is typically zero for 1425// C/C++. The Count value is the number of elements. Values are 64 bit. If 1426// Count == -1 then the array is unbounded and we do not emit 1427// DW_AT_lower_bound and DW_AT_count attributes. 1428 int64_t DefaultLowerBound = getDefaultLowerBound();
1431 DISubrange::BoundType Bound) ->
void {
1432if (
auto *BV = dyn_cast_if_present<DIVariable *>(Bound)) {
1433if (
auto *VarDIE =
getDIE(BV))
1435 }
elseif (
auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {
1438 DwarfExpr.setMemoryLocationKind();
1439 DwarfExpr.addExpression(BE);
1440addBlock(DW_Subrange, Attr, DwarfExpr.finalize());
1441 }
elseif (
auto *BI = dyn_cast_if_present<ConstantInt *>(Bound)) {
1442if (Attr == dwarf::DW_AT_count) {
1443if (BI->getSExtValue() != -1)
1444addUInt(DW_Subrange, Attr, std::nullopt, BI->getSExtValue());
1445 }
elseif (Attr != dwarf::DW_AT_lower_bound || DefaultLowerBound == -1 ||
1446 BI->getSExtValue() != DefaultLowerBound)
1447addSInt(DW_Subrange, Attr, dwarf::DW_FORM_sdata, BI->getSExtValue());
1451 AddBoundTypeEntry(dwarf::DW_AT_lower_bound, SR->
getLowerBound());
1453 AddBoundTypeEntry(dwarf::DW_AT_count, SR->
getCount());
1455 AddBoundTypeEntry(dwarf::DW_AT_upper_bound, SR->
getUpperBound());
1457 AddBoundTypeEntry(dwarf::DW_AT_byte_stride, SR->
getStride());
1460void DwarfUnit::constructGenericSubrangeDIE(
DIE &Buffer,
1463DIE &DwGenericSubrange =
1465addDIEEntry(DwGenericSubrange, dwarf::DW_AT_type, *IndexTy);
1467 int64_t DefaultLowerBound = getDefaultLowerBound();
1471if (
auto *BV = dyn_cast_if_present<DIVariable *>(Bound)) {
1472if (
auto *VarDIE =
getDIE(BV))
1474 }
elseif (
auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {
1475if (BE->isConstant() &&
1477 *BE->isConstant()) {
1478if (Attr != dwarf::DW_AT_lower_bound || DefaultLowerBound == -1 ||
1479static_cast<int64_t
>(BE->getElement(1)) != DefaultLowerBound)
1480addSInt(DwGenericSubrange, Attr, dwarf::DW_FORM_sdata,
1485 DwarfExpr.setMemoryLocationKind();
1486 DwarfExpr.addExpression(BE);
1487addBlock(DwGenericSubrange, Attr, DwarfExpr.finalize());
1492 AddBoundTypeEntry(dwarf::DW_AT_lower_bound, GSR->
getLowerBound());
1493 AddBoundTypeEntry(dwarf::DW_AT_count, GSR->
getCount());
1494 AddBoundTypeEntry(dwarf::DW_AT_upper_bound, GSR->
getUpperBound());
1495 AddBoundTypeEntry(dwarf::DW_AT_byte_stride, GSR->
getStride());
1498DIE *DwarfUnit::getIndexTyDie() {
1501// Construct an integer type to use for indexes. 1514/// Returns true if the vector's size differs from the sum of sizes of elements 1515/// the user specified. This can occur if the vector has been rounded up to 1516/// fit memory alignment constraints. 1518assert(CTy && CTy->
isVector() &&
"Composite type is not a vector");
1521// Obtain the size of each element in the vector. 1526// Locate the number of elements in the vector. 1528assert(Elements.size() == 1 &&
1529 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type &&
1530"Invalid vector element array, expected one element of type subrange");
1531constauto Subrange = cast<DISubrange>(Elements[0]);
1532constauto NumVecElements =
1533 Subrange->getCount()
1534 ? cast<ConstantInt *>(Subrange->getCount())->getSExtValue()
1537// Ensure we found the element count and that the actual size is wide 1538// enough to contain the requested size. 1539assert(ActualSize >= (NumVecElements * ElementSize) &&
"Invalid vector size");
1540return ActualSize != (NumVecElements * ElementSize);
1545addFlag(Buffer, dwarf::DW_AT_GNU_vector);
1547addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt,
1552if (
auto *VarDIE =
getDIE(Var))
1553addDIEEntry(Buffer, dwarf::DW_AT_data_location, *VarDIE);
1557 DwarfExpr.setMemoryLocationKind();
1558 DwarfExpr.addExpression(Expr);
1559addBlock(Buffer, dwarf::DW_AT_data_location, DwarfExpr.finalize());
1563if (
auto *VarDIE =
getDIE(Var))
1564addDIEEntry(Buffer, dwarf::DW_AT_associated, *VarDIE);
1568 DwarfExpr.setMemoryLocationKind();
1569 DwarfExpr.addExpression(Expr);
1570addBlock(Buffer, dwarf::DW_AT_associated, DwarfExpr.finalize());
1574if (
auto *VarDIE =
getDIE(Var))
1575addDIEEntry(Buffer, dwarf::DW_AT_allocated, *VarDIE);
1579 DwarfExpr.setMemoryLocationKind();
1580 DwarfExpr.addExpression(Expr);
1581addBlock(Buffer, dwarf::DW_AT_allocated, DwarfExpr.finalize());
1585addSInt(Buffer, dwarf::DW_AT_rank, dwarf::DW_FORM_sdata,
1586 RankConst->getSExtValue());
1587 }
elseif (
auto *RankExpr = CTy->
getRankExp()) {
1590 DwarfExpr.setMemoryLocationKind();
1591 DwarfExpr.addExpression(RankExpr);
1592addBlock(Buffer, dwarf::DW_AT_rank, DwarfExpr.finalize());
1595// Emit the element type. 1598// Get an anonymous type for index type. 1599// FIXME: This type should be passed down from the front end 1600// as different languages may have different sizes for indexes. 1601DIE *IdxTy = getIndexTyDie();
1603// Add subranges to array type. 1605for (
DINode *E : Elements) {
1606// FIXME: Should this really be such a loose cast? 1607if (
auto *Element = dyn_cast_or_null<DINode>(E)) {
1608if (Element->getTag() == dwarf::DW_TAG_subrange_type)
1609 constructSubrangeDIE(Buffer, cast<DISubrange>(Element), IdxTy);
1610elseif (Element->getTag() == dwarf::DW_TAG_generic_subrange)
1611 constructGenericSubrangeDIE(Buffer, cast<DIGenericSubrange>(Element),
1624addFlag(Buffer, dwarf::DW_AT_enum_class);
1628bool IndexEnumerators = !Context || isa<DICompileUnit>(Context) || isa<DIFile>(Context) ||
1629 isa<DINamespace>(Context) || isa<DICommonBlock>(Context);
1632// Add enumerators to enumeration type. 1633for (
constDINode *E : Elements) {
1634auto *
Enum = dyn_cast_or_null<DIEnumerator>(E);
1640if (IndexEnumerators)
1648DIE &SPDie = *
P.first;
1655addDIEEntry(SPDie, dwarf::DW_AT_containing_type, *NDie);
1667if (
DIType *Resolved = DT->getBaseType())
1672if (DT->getTag() == dwarf::DW_TAG_inheritance && DT->isVirtual()) {
1674// For C++, virtual base classes are not at fixed offset. Use following 1675// expression to extract appropriate offset from vtable. 1676// BaseAddr = ObAddr + *((*ObAddr) - Offset) 1679addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_dup);
1680addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1681addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1682addUInt(*VBaseLocationDie, dwarf::DW_FORM_udata, DT->getOffsetInBits());
1683addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_minus);
1684addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1685addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
1687addBlock(MemberDie, dwarf::DW_AT_data_member_location, VBaseLocationDie);
1691uint32_t AlignInBytes = DT->getAlignInBytes();
1694bool IsBitfield = DT->isBitField();
1696// Handle bitfield, assume bytes are 8 bits. 1698addUInt(MemberDie, dwarf::DW_AT_byte_size, std::nullopt, FieldSize / 8);
1699addUInt(MemberDie, dwarf::DW_AT_bit_size, std::nullopt,
Size);
1701assert(DT->getOffsetInBits() <=
1702 (
uint64_t)std::numeric_limits<int64_t>::max());
1703 int64_t Offset = DT->getOffsetInBits();
1704// We can't use DT->getAlignInBits() here: AlignInBits for member type 1705// is non-zero if and only if alignment was forced (e.g. _Alignas()), 1706// which can't be done with bitfields. Thus we use FieldSize here. 1708uint32_t AlignMask = ~(AlignInBits - 1);
1709// The bits from the start of the storage unit to the start of the field. 1710uint64_t StartBitOffset = Offset - (Offset & AlignMask);
1711// The byte offset of the field's aligned storage unit inside the struct. 1712 OffsetInBytes = (Offset - StartBitOffset) / 8;
1715uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1716uint64_t FieldOffset = (HiMark - FieldSize);
1717 Offset -= FieldOffset;
1719// Maybe we need to work from the other end. 1721 Offset = FieldSize - (Offset +
Size);
1724addSInt(MemberDie, dwarf::DW_AT_bit_offset, dwarf::DW_FORM_sdata,
1727addUInt(MemberDie, dwarf::DW_AT_bit_offset, std::nullopt,
1729 OffsetInBytes = FieldOffset >> 3;
1731addUInt(MemberDie, dwarf::DW_AT_data_bit_offset, std::nullopt, Offset);
1734// This is not a bitfield. 1735 OffsetInBytes = DT->getOffsetInBits() / 8;
1737addUInt(MemberDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1743addUInt(*MemLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
1744addUInt(*MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes);
1745addBlock(MemberDie, dwarf::DW_AT_data_member_location, MemLocationDie);
1747// In DWARF v3, DW_FORM_data4/8 in DW_AT_data_member_location are 1748// interpreted as location-list pointers. Interpreting constants as 1749// pointers is not expected, so we use DW_FORM_udata to encode the 1752addUInt(MemberDie, dwarf::DW_AT_data_member_location,
1753 dwarf::DW_FORM_udata, OffsetInBytes);
1755addUInt(MemberDie, dwarf::DW_AT_data_member_location, std::nullopt,
1763addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1,
1764 dwarf::DW_VIRTUALITY_virtual);
1766// Objective-C properties. 1767if (
DINode *PNode = DT->getObjCProperty())
1770 dwarf::DW_FORM_ref4,
DIEEntry(*PDie));
1772if (DT->isArtificial())
1773addFlag(MemberDie, dwarf::DW_AT_artificial);
1782// Construct the context before querying for the existence of the DIE in case 1783// such construction creates the DIE. 1786"Static member should belong to a type.");
1789return StaticMemberDIE;
1793constDIType *Ty = DT->getBaseType();
1795addString(StaticMemberDIE, dwarf::DW_AT_name, DT->getName());
1798addFlag(StaticMemberDIE, dwarf::DW_AT_external);
1799addFlag(StaticMemberDIE, dwarf::DW_AT_declaration);
1801// Consider the case when the static member was created by the compiler. 1802if (DT->isArtificial())
1803addFlag(StaticMemberDIE, dwarf::DW_AT_artificial);
1805// FIXME: We could omit private if the parent is a class_type, and 1806// public if the parent is something else. 1807addAccess(StaticMemberDIE, DT->getFlags());
1809if (
constConstantInt *CI = dyn_cast_or_null<ConstantInt>(DT->getConstant()))
1811if (
constConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT->getConstant()))
1814if (
uint32_t AlignInBytes = DT->getAlignInBytes())
1815addUInt(StaticMemberDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1818return &StaticMemberDIE;
1822// Emit size of content not including length itself 1825 isDwoUnit() ?
"debug_info_dwo" :
"debug_info",
"Length of Unit");
1834// DWARF v5 reorders the address size and adds a unit type. 1842// We share one abbreviations table across all units so it's always at the 1843// start of the section. Use a relocatable offset where needed to ensure 1844// linking doesn't invalidate that offset. 1866 : dwarf::DW_UT_type);
1868Asm->
OutStreamer->emitIntValue(TypeSignature,
sizeof(TypeSignature));
1870// In a skeleton type unit there is no type DIE so emit a zero offset. 1888bool DwarfTypeUnit::isDwoUnit()
const{
1889// Since there are no skeleton type units, all type units are dwo type units 1890// when split DWARF is being used. 1904constMCSymbol *DwarfUnit::getCrossSectionRelativeBaseAddress()
const{
1921"DW_AT_rnglists_base requires DWARF version 5 or later");
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static bool hasVectorBeenPadded(const DICompositeType *CTy)
Returns true if the vector's size differs from the sum of sizes of elements the user specified.
unsigned const TargetRegisterInfo * TRI
This file contains the declarations for metadata subclasses.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static enum BaseType getBaseType(const Value *Val)
Return the baseType for Val which states whether Val is exclusively derived from constant/null,...
static unsigned getSize(unsigned Kind)
APInt bitcastToAPInt() const
Class for arbitrary precision integers.
uint64_t getZExtValue() const
Get zero extended value.
unsigned getBitWidth() const
Return the number of bits in the APInt.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
int64_t getSExtValue() const
Get sign extended value.
unsigned getIndex(const MCSymbol *Sym, bool TLS=false)
Returns the index into the address pool with the given label/symbol.
void resetUsedFlag(bool HasBeenUsed=false)
Annotations lets you mark points and ranges inside source code, for tests:
This class is intended to be used as a driving class for all asm writers.
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
MCSymbol * getSymbol(const GlobalValue *GV) const
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
void emitDwarfLengthOrOffset(uint64_t Value) const
Emit 32- or 64-bit value depending on the DWARF format.
TargetMachine & TM
Target machine description.
const MCAsmInfo * MAI
Target Asm Printer information.
MachineFunction * MF
The current machine function.
void emitInt8(int Value) const
Emit a byte directive and value.
void emitDwarfUnitLength(uint64_t Length, const Twine &Comment) const
Emit a unit length field.
MCContext & OutContext
This is the context for the output file that we are streaming.
MCSymbol * createTempSymbol(const Twine &Name) const
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
virtual unsigned getISAEncoding()
Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.
void emitInt16(int Value) const
Emit a short directive and value.
const DataLayout & getDataLayout() const
Return information about data layout.
dwarf::FormParams getDwarfFormParams() const
Returns information about the byte size of DW_FORM values.
bool doesDwarfUseRelocationsAcrossSections() const
ConstantFP - Floating Point Values [float, double].
const APFloat & getValueAPF() const
This is the shared class of boolean and integer constants.
const APInt & getValue() const
Return the constant as an APInt value reference.
Basic type, like 'int' or 'float'.
unsigned getEncoding() const
bool getDebugInfoForProfiling() const
bool isDebugDirectivesOnly() const
static std::optional< DebugNameTableKind > getNameTableKind(StringRef Str)
DIExpression * getRankExp() const
DIExpression * getAssociatedExp() const
DIVariable * getAllocated() const
DIExpression * getDataLocationExp() const
DIVariable * getAssociated() const
DIDerivedType * getDiscriminator() const
DIVariable * getDataLocation() const
unsigned getRuntimeLang() const
DIType * getSpecification() const
StringRef getIdentifier() const
DINodeArray getElements() const
DITemplateParameterArray getTemplateParams() const
DIExpression * getAllocatedExp() const
DIType * getVTableHolder() const
DINodeArray getAnnotations() const
ConstantInt * getRankConst() const
MDString * getRawIdentifier() const
DIType * getBaseType() const
DINodeArray getAnnotations() const
Get annotations associated with this derived type.
DITemplateParameterArray getTemplateParams() const
Get the template parameters from a template alias.
DIEBlock - Represents a block of values.
A simple label difference DIE.
DwarfExpression implementation for singular DW_AT_location.
DIEDwarfExpression(const AsmPrinter &AP, DwarfCompileUnit &CU, DIELoc &DIE)
A pointer to another debug information entry.
A container for inline string values.
static dwarf::Form BestForm(bool IsSigned, uint64_t Int)
Choose the best form for integer.
DIELoc - Represents an expression location.
unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
dwarf::Form BestForm(unsigned DwarfVersion) const
BestForm - Choose the best form for data.
A container for string pool string values.
Represents a compile or type unit.
MCSection * getSection() const
Return the section that this DIEUnit will be emitted into.
void takeValues(DIEValueList &Other)
Take ownership of the nodes in Other, and append them to the back of the list.
A structured debug information entry.
DIE & addChild(DIE *Child)
Add a child to the DIE.
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
DIEUnit * getUnit() const
Climb up the parent chain to get the compile unit or type unit that this DIE belongs to.
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
dwarf::Tag getTag() const
BoundType getLowerBound() const
BoundType getCount() const
BoundType getUpperBound() const
BoundType getStride() const
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
DIScope * getScope() const
StringRef getName() const
bool getExportSymbols() const
Tagged DWARF-like metadata node.
dwarf::Tag getTag() const
Base class for scope-like contexts.
StringRef getName() const
DIScope * getScope() const
String type, Fortran CHARACTER(n)
unsigned getEncoding() const
DIExpression * getStringLengthExp() const
DIVariable * getStringLength() const
DIExpression * getStringLocationExp() const
BoundType getUpperBound() const
BoundType getStride() const
BoundType getLowerBound() const
BoundType getCount() const
Type array for a subprogram.
StringRef getName() const
Metadata * getValue() const
bool isLittleEndian() const
uint32_t getNumExtraInhabitants() const
bool isLValueReference() const
bool isObjcClassComplete() const
MDString * getRawName() const
bool isAppleBlockExtension() const
bool isObjectPointer() const
StringRef getName() const
bool isForwardDecl() const
bool isTypePassByValue() const
uint64_t getSizeInBits() const
uint32_t getAlignInBytes() const
bool isRValueReference() const
bool isArtificial() const
bool getExportSymbols() const
DIScope * getScope() const
bool isTypePassByReference() const
Base class for variables.
This class represents an Operation in the Expression.
bool isLittleEndian() const
Layout endianness...
static bool isUnsignedDIType(const DIType *Ty)
Return true if type encoding is unsigned.
static uint64_t getBaseTypeSize(const DIType *Ty)
If this type is derived from a base type then return base type size.
void addGlobalNameForTypeUnit(StringRef Name, const DIScope *Context)
Add a new global name present in a type unit to this compile unit.
unsigned getOrCreateSourceID(const DIFile *File) override
Look up the source ID for the given file.
void addGlobalTypeUnitType(const DIType *Ty, const DIScope *Context)
Add a new global type present in a type unit to this compile unit.
Collects and handles dwarf debug information.
std::optional< MD5::MD5Result > getMD5AsBytes(const DIFile *File) const
If the File has an MD5 checksum, return it as an MD5Result allocated in the MCContext.
bool useAddrOffsetForm() const
uint16_t getDwarfVersion() const
Returns the Dwarf Version.
void addAccelNamespace(const DwarfUnit &Unit, const DICompileUnit::DebugNameTableKind NameTableKind, StringRef Name, const DIE &Die)
bool useAllLinkageNames() const
Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
dwarf::Form getDwarfSectionOffsetForm() const
Returns a suitable DWARF form to represent a section offset, i.e.
bool useAppleExtensionAttributes() const
bool useInlineStrings() const
Returns whether to use inline strings.
bool generateTypeUnits() const
Returns whether to generate DWARF v4 type units.
AddressPool & getAddressPool()
bool useSectionsAsReferences() const
Returns whether to use sections as labels rather than temp symbols.
bool shareAcrossDWOCUs() const
const MCSymbol * getSectionLabel(const MCSection *S)
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support.
bool useDWARF2Bitfields() const
Returns whether to use the DWARF2 format for bitfields instyead of the DWARF4 format.
bool useAddrOffsetExpressions() const
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.
void addAccelType(const DwarfUnit &Unit, const DICompileUnit::DebugNameTableKind NameTableKind, StringRef Name, const DIE &Die, char Flags)
Base class containing the logic for constructing DWARF expressions independently of whether they are ...
MCSymbol * getStringOffsetsStartSym() const
MCSymbol * getRnglistsTableBaseSym() const
DwarfStringPool & getStringPool()
Returns the string pool.
DenseMap< const DILocalScope *, DIE * > & getAbstractScopeDIEs()
void insertDIE(const MDNode *TypeMD, DIE *Die)
DIE * getDIE(const MDNode *TypeMD)
EntryRef getEntry(AsmPrinter &Asm, StringRef Str)
Get a reference to an entry in the string pool.
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....
DwarfTypeUnit(DwarfCompileUnit &CU, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, unsigned UniqueID, MCDwarfDwoLineTable *SplitLineTable=nullptr)
void addGlobalTypeImpl(const DIType *Ty, const DIE &Die, const DIScope *Context) override
Add a new global type to the compile unit.
DwarfCompileUnit & getCU() override
void emitHeader(bool UseOffsets) override
Emit the header for this unit, not including the initial length field.
void addGlobalName(StringRef Name, const DIE &Die, const DIScope *Context) override
Add a new global name to the compile unit.
This dwarf writer support class manages information associated with a source file.
virtual DIE * getOrCreateTypeDIE(const MDNode *TyNode)
Find existing DIE or create new DIE for the given type.
void addThrownTypes(DIE &Die, DINodeArray ThrownTypes)
Add thrown types.
void addStringOffsetsStart()
Add the DW_AT_str_offsets_base attribute to the unit DIE.
void addAnnotation(DIE &Buffer, DINodeArray Annotations)
Add DW_TAG_LLVM_annotation.
std::vector< DIEBlock * > DIEBlocks
A list of all the DIEBlocks in use.
std::vector< DIELoc * > DIELocs
A list of all the DIELocs in use.
uint16_t getLanguage() const
void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc)
Add block data.
void addTemplateParams(DIE &Buffer, DINodeArray TParams)
Add template parameters in buffer.
virtual DIE * getOrCreateContextDIE(const DIScope *Context)
Get context owner's DIE.
bool useSegmentedStringOffsetsTable() const
bool applySubprogramDefinitionAttributes(const DISubprogram *SP, DIE &SPDie, bool Minimal)
DIELoc * getDIELoc()
Returns a fresh newly allocated DIELoc.
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.
void addAttribute(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, T &&Value)
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...
void addUInt(DIEValueList &Die, dwarf::Attribute Attribute, std::optional< dwarf::Form > Form, uint64_t Integer)
Add an unsigned integer attribute data and value.
void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str)
Add a string attribute data and value.
void addConstantValue(DIE &Die, const ConstantInt *CI, const DIType *Ty)
Add constant value entry in variable DIE.
DIE * getOrCreateNameSpace(const DINamespace *NS)
void insertDIE(const DINode *Desc, DIE *D)
Insert DIE into the map.
void addAccess(DIE &Die, DINode::DIFlags Flags)
Add the accessibility attribute.
void addSectionDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
addSectionDelta - Add a label delta attribute data and value.
void addGlobalType(const DIType *Ty, const DIE &Die, const DIScope *Context)
DIE * createTypeDIE(const DIScope *Context, DIE &ContextDIE, const DIType *Ty)
Creates type DIE with specific context.
DenseMap< DIE *, const DINode * > ContainingTypeMap
This map is used to keep track of subprogram DIEs that need DW_AT_containing_type attribute.
const DICompileUnit * CUNode
MDNode for the compile unit.
virtual unsigned getOrCreateSourceID(const DIFile *File)=0
Look up the source ID for the given file.
virtual void addGlobalTypeImpl(const DIType *Ty, const DIE &Die, const DIScope *Context)=0
Add a new global type to the compile unit.
void addDIETypeSignature(DIE &Die, uint64_t Signature)
Add a type's DW_AT_signature and set the declaration flag.
virtual DwarfCompileUnit & getCU()=0
DIE * getDIE(const DINode *D) const
Returns the DIE map slot for the specified debug variable.
virtual unsigned getHeaderSize() const
Compute the size of a header for this unit, not including the initial length field.
MCSymbol * LabelBegin
The start of the unit within its section.
void addSInt(DIEValueList &Die, dwarf::Attribute Attribute, std::optional< dwarf::Form > Form, int64_t Integer)
Add an signed integer attribute data and value.
DwarfUnit(dwarf::Tag, const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, unsigned UniqueID=0)
void addLabelDelta(DIEValueList &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
Add a label delta attribute data and value.
void addLinkageName(DIE &Die, StringRef LinkageName)
Add a linkage name, if it isn't empty.
std::string getParentContextString(const DIScope *Context) const
Get string containing language specific context for a global name.
void addSourceLine(DIE &Die, unsigned Line, const DIFile *File)
Add location information to specified debug information entry.
void emitCommonHeader(bool UseOffsets, dwarf::UnitType UT)
Emit the common part of the header for this unit.
BumpPtrAllocator DIEValueAllocator
DIE * IndexTyDie
An anonymous type for index type. Owned by DIEUnit.
void addRnglistsBase()
Add the DW_AT_rnglists_base attribute to the unit DIE.
DIE * constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args)
Construct function argument DIEs.
DIE * getOrCreateModule(const DIModule *M)
DIE & createAndAddDIE(dwarf::Tag 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.
void addSectionOffset(DIE &Die, dwarf::Attribute Attribute, uint64_t Integer)
Add an offset into a section attribute data and value.
DIE * getOrCreateStaticMemberDIE(const DIDerivedType *DT)
Create new static data member DIE.
void addLabel(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, const MCSymbol *Label)
Add a Dwarf label attribute data and value.
void addConstantFPValue(DIE &Die, const ConstantFP *CFP)
Add constant value entry in variable DIE.
void constructContainingTypeDIEs()
Construct DIEs for types that contain vtables.
DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal=false)
void addSectionLabel(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label, const MCSymbol *Sec)
Add a Dwarf section label attribute data and value.
bool isShareableAcrossCUs(const DINode *D) const
Check whether the DIE for this MDNode can be shared across CUs.
void addPoolOpAddress(DIEValueList &Die, const MCSymbol *Label)
DenseMap< const MDNode *, DIE * > MDNodeToDieMap
Tracks the mapping of unit level debug information variables to debug information entries.
void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy)
virtual void addGlobalName(StringRef Name, const DIE &Die, const DIScope *Context)=0
Add a new global name to the compile unit.
MCSymbol * EndLabel
Emitted at the end of the CU and used to compute the CU Length field.
void addFlag(DIE &Die, dwarf::Attribute Attribute)
Add a flag that is true to the DIE.
AsmPrinter * Asm
Target of Dwarf emission.
void addType(DIE &Entity, const DIType *Ty, dwarf::Attribute Attribute=dwarf::DW_AT_type)
Add a new type attribute to the specified entity.
void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, bool SkipSPAttributes=false)
void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry)
Add a DIE attribute data and value.
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
uint16_t getDwarfVersion() const
unsigned getFile(StringRef Directory, StringRef FileName, std::optional< MD5::MD5Result > Checksum, uint16_t DwarfVersion, std::optional< StringRef > Source)
MCSection * getDwarfStrOffSection() const
MCSection * getDwarfRnglistsSection() const
MCSection * getDwarfAbbrevSection() const
MCSymbol * getBeginSymbol()
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
const MDOperand & getOperand(unsigned I) const
Root of the metadata hierarchy.
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Wrapper class representing virtual and physical registers.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
unsigned DebugStrictDwarf
When set to true, don't use DWARF extensions in later DWARF versions.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
LLVM Value Representation.
UnitType
Constants for unit types in DWARF v5.
bool isCPlusPlus(SourceLanguage S)
TypeKind getArrayIndexTypeEncoding(SourceLanguage S)
@ DW_FLAG_type_implementation
bool isC(SourceLanguage S)
This is an optimization pass for GlobalISel generic memory operations.
auto reverse(ContainerTy &&C)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Description of the encoding of one expression Op.