1 //===- DIBuilder.h - Debug Information Builder ------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines a DIBuilder that is useful for creating debugging 11 // information entries in LLVM IR form. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_IR_DIBUILDER_H 16 #define LLVM_IR_DIBUILDER_H 17 18 #include "llvm/ADT/ArrayRef.h" 19 #include "llvm/ADT/DenseMap.h" 20 #include "llvm/ADT/MapVector.h" 21 #include "llvm/ADT/None.h" 22 #include "llvm/ADT/SetVector.h" 23 #include "llvm/ADT/SmallVector.h" 24 #include "llvm/ADT/StringRef.h" 25 #include "llvm/IR/DebugInfo.h" 26 #include "llvm/IR/DebugInfoMetadata.h" 27 #include "llvm/IR/TrackingMDRef.h" 28 #include "llvm/Support/Casting.h" 29 #include <algorithm> 30 #include <cstdint> 31 32 namespace llvm { 33 34 class BasicBlock; 35 class Constant; 36 class Function; 37 class Instruction; 38 class LLVMContext; 39 class Module; 40 class Value; 41 42 class DIBuilder { 43 Module &M; 44 LLVMContext &VMContext; 45 46 DICompileUnit *CUNode; ///< The one compile unit created by this DIBuiler. 47 Function *DeclareFn; ///< llvm.dbg.declare 48 Function *ValueFn; ///< llvm.dbg.value 49 50 SmallVector<Metadata *, 4> AllEnumTypes; 51 /// Track the RetainTypes, since they can be updated later on. 52 SmallVector<TrackingMDNodeRef, 4> AllRetainTypes; 53 SmallVector<Metadata *, 4> AllSubprograms; 54 SmallVector<Metadata *, 4> AllGVs; 55 SmallVector<TrackingMDNodeRef, 4> AllImportedModules; 56 /// Map Macro parent (which can be DIMacroFile or nullptr) to a list of 57 /// Metadata all of type DIMacroNode. 58 /// DIMacroNode's with nullptr parent are DICompileUnit direct children. 59 MapVector<MDNode *, SetVector<Metadata *>> AllMacrosPerParent; 60 61 /// Track nodes that may be unresolved. 62 SmallVector<TrackingMDNodeRef, 4> UnresolvedNodes; 63 bool AllowUnresolvedNodes; 64 65 /// Each subprogram's preserved local variables. 66 /// 67 /// Do not use a std::vector. Some versions of libc++ apparently copy 68 /// instead of move on grow operations, and TrackingMDRef is expensive to 69 /// copy. 70 DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> PreservedVariables; 71 72 /// Create a temporary. 73 /// 74 /// Create an \a temporary node and track it in \a UnresolvedNodes. 75 void trackIfUnresolved(MDNode *N); 76 77 public: 78 /// Construct a builder for a module. 79 /// 80 /// If \c AllowUnresolved, collect unresolved nodes attached to the module 81 /// in order to resolve cycles during \a finalize(). 82 explicit DIBuilder(Module &M, bool AllowUnresolved = true); 83 DIBuilder(const DIBuilder &) = delete; 84 DIBuilder &operator=(const DIBuilder &) = delete; 85 86 /// Construct any deferred debug info descriptors. 87 void finalize(); 88 89 /// A CompileUnit provides an anchor for all debugging 90 /// information generated during this instance of compilation. 91 /// \param Lang Source programming language, eg. dwarf::DW_LANG_C99 92 /// \param File File info. 93 /// \param Producer Identify the producer of debugging information 94 /// and code. Usually this is a compiler 95 /// version string. 96 /// \param isOptimized A boolean flag which indicates whether optimization 97 /// is enabled or not. 98 /// \param Flags This string lists command line options. This 99 /// string is directly embedded in debug info 100 /// output which may be used by a tool 101 /// analyzing generated debugging information. 102 /// \param RV This indicates runtime version for languages like 103 /// Objective-C. 104 /// \param SplitName The name of the file that we'll split debug info 105 /// out into. 106 /// \param Kind The kind of debug information to generate. 107 /// \param DWOId The DWOId if this is a split skeleton compile unit. 108 /// \param SplitDebugInlining Whether to emit inline debug info. 109 /// \param DebugInfoForProfiling Whether to emit extra debug info for 110 /// profile collection. 111 DICompileUnit * 112 createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer, 113 bool isOptimized, StringRef Flags, unsigned RV, 114 StringRef SplitName = StringRef(), 115 DICompileUnit::DebugEmissionKind Kind = 116 DICompileUnit::DebugEmissionKind::FullDebug, 117 uint64_t DWOId = 0, bool SplitDebugInlining = true, 118 bool DebugInfoForProfiling = false); 119 120 /// Create a file descriptor to hold debugging information for a file. 121 /// \param Filename File name. 122 /// \param Directory Directory. 123 /// \param CSKind Checksum kind (e.g. CSK_None, CSK_MD5, CSK_SHA1, etc.). 124 /// \param Checksum Checksum data. 125 DIFile *createFile(StringRef Filename, StringRef Directory, 126 DIFile::ChecksumKind CSKind = DIFile::CSK_None, 127 StringRef Checksum = StringRef()); 128 129 /// Create debugging information entry for a macro. 130 /// \param Parent Macro parent (could be nullptr). 131 /// \param Line Source line number where the macro is defined. 132 /// \param MacroType DW_MACINFO_define or DW_MACINFO_undef. 133 /// \param Name Macro name. 134 /// \param Value Macro value. 135 DIMacro *createMacro(DIMacroFile *Parent, unsigned Line, unsigned MacroType, 136 StringRef Name, StringRef Value = StringRef()); 137 138 /// Create debugging information temporary entry for a macro file. 139 /// List of macro node direct children will be calculated by DIBuilder, 140 /// using the \p Parent relationship. 141 /// \param Parent Macro file parent (could be nullptr). 142 /// \param Line Source line number where the macro file is included. 143 /// \param File File descriptor containing the name of the macro file. 144 DIMacroFile *createTempMacroFile(DIMacroFile *Parent, unsigned Line, 145 DIFile *File); 146 147 /// Create a single enumerator value. 148 DIEnumerator *createEnumerator(StringRef Name, int64_t Val); 149 150 /// Create a DWARF unspecified type. 151 DIBasicType *createUnspecifiedType(StringRef Name); 152 153 /// Create C++11 nullptr type. 154 DIBasicType *createNullPtrType(); 155 156 /// Create debugging information entry for a basic 157 /// type. 158 /// \param Name Type name. 159 /// \param SizeInBits Size of the type. 160 /// \param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float. 161 DIBasicType *createBasicType(StringRef Name, uint64_t SizeInBits, 162 unsigned Encoding); 163 164 /// Create debugging information entry for a qualified 165 /// type, e.g. 'const int'. 166 /// \param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type 167 /// \param FromTy Base Type. 168 DIDerivedType *createQualifiedType(unsigned Tag, DIType *FromTy); 169 170 /// Create debugging information entry for a pointer. 171 /// \param PointeeTy Type pointed by this pointer. 172 /// \param SizeInBits Size. 173 /// \param AlignInBits Alignment. (optional) 174 /// \param DWARFAddressSpace DWARF address space. (optional) 175 /// \param Name Pointer type name. (optional) 176 DIDerivedType *createPointerType(DIType *PointeeTy, uint64_t SizeInBits, 177 uint32_t AlignInBits = 0, 178 Optional<unsigned> DWARFAddressSpace = 179 None, 180 StringRef Name = ""); 181 182 /// Create debugging information entry for a pointer to member. 183 /// \param PointeeTy Type pointed to by this pointer. 184 /// \param SizeInBits Size. 185 /// \param AlignInBits Alignment. (optional) 186 /// \param Class Type for which this pointer points to members of. 187 DIDerivedType * 188 createMemberPointerType(DIType *PointeeTy, DIType *Class, 189 uint64_t SizeInBits, uint32_t AlignInBits = 0, 190 DINode::DIFlags Flags = DINode::FlagZero); 191 192 /// Create debugging information entry for a c++ 193 /// style reference or rvalue reference type. 194 DIDerivedType *createReferenceType(unsigned Tag, DIType *RTy, 195 uint64_t SizeInBits = 0, 196 uint32_t AlignInBits = 0, 197 Optional<unsigned> DWARFAddressSpace = 198 None); 199 200 /// Create debugging information entry for a typedef. 201 /// \param Ty Original type. 202 /// \param Name Typedef name. 203 /// \param File File where this type is defined. 204 /// \param LineNo Line number. 205 /// \param Context The surrounding context for the typedef. 206 DIDerivedType *createTypedef(DIType *Ty, StringRef Name, DIFile *File, 207 unsigned LineNo, DIScope *Context); 208 209 /// Create debugging information entry for a 'friend'. 210 DIDerivedType *createFriend(DIType *Ty, DIType *FriendTy); 211 212 /// Create debugging information entry to establish 213 /// inheritance relationship between two types. 214 /// \param Ty Original type. 215 /// \param BaseTy Base type. Ty is inherits from base. 216 /// \param BaseOffset Base offset. 217 /// \param Flags Flags to describe inheritance attribute, 218 /// e.g. private 219 DIDerivedType *createInheritance(DIType *Ty, DIType *BaseTy, 220 uint64_t BaseOffset, 221 DINode::DIFlags Flags); 222 223 /// Create debugging information entry for a member. 224 /// \param Scope Member scope. 225 /// \param Name Member name. 226 /// \param File File where this member is defined. 227 /// \param LineNo Line number. 228 /// \param SizeInBits Member size. 229 /// \param AlignInBits Member alignment. 230 /// \param OffsetInBits Member offset. 231 /// \param Flags Flags to encode member attribute, e.g. private 232 /// \param Ty Parent type. 233 DIDerivedType *createMemberType(DIScope *Scope, StringRef Name, 234 DIFile *File, unsigned LineNo, 235 uint64_t SizeInBits, 236 uint32_t AlignInBits, 237 uint64_t OffsetInBits, 238 DINode::DIFlags Flags, DIType *Ty); 239 240 /// Create debugging information entry for a bit field member. 241 /// \param Scope Member scope. 242 /// \param Name Member name. 243 /// \param File File where this member is defined. 244 /// \param LineNo Line number. 245 /// \param SizeInBits Member size. 246 /// \param OffsetInBits Member offset. 247 /// \param StorageOffsetInBits Member storage offset. 248 /// \param Flags Flags to encode member attribute. 249 /// \param Ty Parent type. 250 DIDerivedType *createBitFieldMemberType( 251 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, 252 uint64_t SizeInBits, uint64_t OffsetInBits, 253 uint64_t StorageOffsetInBits, DINode::DIFlags Flags, DIType *Ty); 254 255 /// Create debugging information entry for a 256 /// C++ static data member. 257 /// \param Scope Member scope. 258 /// \param Name Member name. 259 /// \param File File where this member is declared. 260 /// \param LineNo Line number. 261 /// \param Ty Type of the static member. 262 /// \param Flags Flags to encode member attribute, e.g. private. 263 /// \param Val Const initializer of the member. 264 /// \param AlignInBits Member alignment. 265 DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name, 266 DIFile *File, unsigned LineNo, 267 DIType *Ty, DINode::DIFlags Flags, 268 Constant *Val, 269 uint32_t AlignInBits = 0); 270 271 /// Create debugging information entry for Objective-C 272 /// instance variable. 273 /// \param Name Member name. 274 /// \param File File where this member is defined. 275 /// \param LineNo Line number. 276 /// \param SizeInBits Member size. 277 /// \param AlignInBits Member alignment. 278 /// \param OffsetInBits Member offset. 279 /// \param Flags Flags to encode member attribute, e.g. private 280 /// \param Ty Parent type. 281 /// \param PropertyNode Property associated with this ivar. 282 DIDerivedType *createObjCIVar(StringRef Name, DIFile *File, unsigned LineNo, 283 uint64_t SizeInBits, uint32_t AlignInBits, 284 uint64_t OffsetInBits, DINode::DIFlags Flags, 285 DIType *Ty, MDNode *PropertyNode); 286 287 /// Create debugging information entry for Objective-C 288 /// property. 289 /// \param Name Property name. 290 /// \param File File where this property is defined. 291 /// \param LineNumber Line number. 292 /// \param GetterName Name of the Objective C property getter selector. 293 /// \param SetterName Name of the Objective C property setter selector. 294 /// \param PropertyAttributes Objective C property attributes. 295 /// \param Ty Type. 296 DIObjCProperty *createObjCProperty(StringRef Name, DIFile *File, 297 unsigned LineNumber, 298 StringRef GetterName, 299 StringRef SetterName, 300 unsigned PropertyAttributes, DIType *Ty); 301 302 /// Create debugging information entry for a class. 303 /// \param Scope Scope in which this class is defined. 304 /// \param Name class name. 305 /// \param File File where this member is defined. 306 /// \param LineNumber Line number. 307 /// \param SizeInBits Member size. 308 /// \param AlignInBits Member alignment. 309 /// \param OffsetInBits Member offset. 310 /// \param Flags Flags to encode member attribute, e.g. private 311 /// \param Elements class members. 312 /// \param VTableHolder Debug info of the base class that contains vtable 313 /// for this type. This is used in 314 /// DW_AT_containing_type. See DWARF documentation 315 /// for more info. 316 /// \param TemplateParms Template type parameters. 317 /// \param UniqueIdentifier A unique identifier for the class. 318 DICompositeType *createClassType( 319 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, 320 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, 321 DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements, 322 DIType *VTableHolder = nullptr, MDNode *TemplateParms = nullptr, 323 StringRef UniqueIdentifier = ""); 324 325 /// Create debugging information entry for a struct. 326 /// \param Scope Scope in which this struct is defined. 327 /// \param Name Struct name. 328 /// \param File File where this member is defined. 329 /// \param LineNumber Line number. 330 /// \param SizeInBits Member size. 331 /// \param AlignInBits Member alignment. 332 /// \param Flags Flags to encode member attribute, e.g. private 333 /// \param Elements Struct elements. 334 /// \param RunTimeLang Optional parameter, Objective-C runtime version. 335 /// \param UniqueIdentifier A unique identifier for the struct. 336 DICompositeType *createStructType( 337 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, 338 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, 339 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang = 0, 340 DIType *VTableHolder = nullptr, StringRef UniqueIdentifier = ""); 341 342 /// Create debugging information entry for an union. 343 /// \param Scope Scope in which this union is defined. 344 /// \param Name Union name. 345 /// \param File File where this member is defined. 346 /// \param LineNumber Line number. 347 /// \param SizeInBits Member size. 348 /// \param AlignInBits Member alignment. 349 /// \param Flags Flags to encode member attribute, e.g. private 350 /// \param Elements Union elements. 351 /// \param RunTimeLang Optional parameter, Objective-C runtime version. 352 /// \param UniqueIdentifier A unique identifier for the union. 353 DICompositeType *createUnionType(DIScope *Scope, StringRef Name, 354 DIFile *File, unsigned LineNumber, 355 uint64_t SizeInBits, uint32_t AlignInBits, 356 DINode::DIFlags Flags, 357 DINodeArray Elements, 358 unsigned RunTimeLang = 0, 359 StringRef UniqueIdentifier = ""); 360 361 /// Create debugging information for template 362 /// type parameter. 363 /// \param Scope Scope in which this type is defined. 364 /// \param Name Type parameter name. 365 /// \param Ty Parameter type. 366 DITemplateTypeParameter * 367 createTemplateTypeParameter(DIScope *Scope, StringRef Name, DIType *Ty); 368 369 /// Create debugging information for template 370 /// value parameter. 371 /// \param Scope Scope in which this type is defined. 372 /// \param Name Value parameter name. 373 /// \param Ty Parameter type. 374 /// \param Val Constant parameter value. 375 DITemplateValueParameter *createTemplateValueParameter(DIScope *Scope, 376 StringRef Name, 377 DIType *Ty, 378 Constant *Val); 379 380 /// Create debugging information for a template template parameter. 381 /// \param Scope Scope in which this type is defined. 382 /// \param Name Value parameter name. 383 /// \param Ty Parameter type. 384 /// \param Val The fully qualified name of the template. 385 DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope, 386 StringRef Name, 387 DIType *Ty, 388 StringRef Val); 389 390 /// Create debugging information for a template parameter pack. 391 /// \param Scope Scope in which this type is defined. 392 /// \param Name Value parameter name. 393 /// \param Ty Parameter type. 394 /// \param Val An array of types in the pack. 395 DITemplateValueParameter *createTemplateParameterPack(DIScope *Scope, 396 StringRef Name, 397 DIType *Ty, 398 DINodeArray Val); 399 400 /// Create debugging information entry for an array. 401 /// \param Size Array size. 402 /// \param AlignInBits Alignment. 403 /// \param Ty Element type. 404 /// \param Subscripts Subscripts. 405 DICompositeType *createArrayType(uint64_t Size, uint32_t AlignInBits, 406 DIType *Ty, DINodeArray Subscripts); 407 408 /// Create debugging information entry for a vector type. 409 /// \param Size Array size. 410 /// \param AlignInBits Alignment. 411 /// \param Ty Element type. 412 /// \param Subscripts Subscripts. 413 DICompositeType *createVectorType(uint64_t Size, uint32_t AlignInBits, 414 DIType *Ty, DINodeArray Subscripts); 415 416 /// Create debugging information entry for an 417 /// enumeration. 418 /// \param Scope Scope in which this enumeration is defined. 419 /// \param Name Union name. 420 /// \param File File where this member is defined. 421 /// \param LineNumber Line number. 422 /// \param SizeInBits Member size. 423 /// \param AlignInBits Member alignment. 424 /// \param Elements Enumeration elements. 425 /// \param UnderlyingType Underlying type of a C++11/ObjC fixed enum. 426 /// \param UniqueIdentifier A unique identifier for the enum. 427 DICompositeType *createEnumerationType( 428 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, 429 uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements, 430 DIType *UnderlyingType, StringRef UniqueIdentifier = ""); 431 432 /// Create subroutine type. 433 /// \param ParameterTypes An array of subroutine parameter types. This 434 /// includes return type at 0th index. 435 /// \param Flags E.g.: LValueReference. 436 /// These flags are used to emit dwarf attributes. 437 /// \param CC Calling convention, e.g. dwarf::DW_CC_normal 438 DISubroutineType * 439 createSubroutineType(DITypeRefArray ParameterTypes, 440 DINode::DIFlags Flags = DINode::FlagZero, 441 unsigned CC = 0); 442 443 /// Create a new DIType* with "artificial" flag set. 444 DIType *createArtificialType(DIType *Ty); 445 446 /// Create a new DIType* with the "object pointer" 447 /// flag set. 448 DIType *createObjectPointerType(DIType *Ty); 449 450 /// Create a permanent forward-declared type. 451 DICompositeType *createForwardDecl(unsigned Tag, StringRef Name, 452 DIScope *Scope, DIFile *F, unsigned Line, 453 unsigned RuntimeLang = 0, 454 uint64_t SizeInBits = 0, 455 uint32_t AlignInBits = 0, 456 StringRef UniqueIdentifier = ""); 457 458 /// Create a temporary forward-declared type. 459 DICompositeType *createReplaceableCompositeType( 460 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line, 461 unsigned RuntimeLang = 0, uint64_t SizeInBits = 0, 462 uint32_t AlignInBits = 0, DINode::DIFlags Flags = DINode::FlagFwdDecl, 463 StringRef UniqueIdentifier = ""); 464 465 /// Retain DIScope* in a module even if it is not referenced 466 /// through debug info anchors. 467 void retainType(DIScope *T); 468 469 /// Create unspecified parameter type 470 /// for a subroutine type. 471 DIBasicType *createUnspecifiedParameter(); 472 473 /// Get a DINodeArray, create one if required. 474 DINodeArray getOrCreateArray(ArrayRef<Metadata *> Elements); 475 476 /// Get a DIMacroNodeArray, create one if required. 477 DIMacroNodeArray getOrCreateMacroArray(ArrayRef<Metadata *> Elements); 478 479 /// Get a DITypeRefArray, create one if required. 480 DITypeRefArray getOrCreateTypeArray(ArrayRef<Metadata *> Elements); 481 482 /// Create a descriptor for a value range. This 483 /// implicitly uniques the values returned. 484 DISubrange *getOrCreateSubrange(int64_t Lo, int64_t Count); 485 486 /// Create a new descriptor for the specified variable. 487 /// \param Context Variable scope. 488 /// \param Name Name of the variable. 489 /// \param LinkageName Mangled name of the variable. 490 /// \param File File where this variable is defined. 491 /// \param LineNo Line number. 492 /// \param Ty Variable Type. 493 /// \param isLocalToUnit Boolean flag indicate whether this variable is 494 /// externally visible or not. 495 /// \param Expr The location of the global relative to the attached 496 /// GlobalVariable. 497 /// \param Decl Reference to the corresponding declaration. 498 /// \param AlignInBits Variable alignment(or 0 if no alignment attr was 499 /// specified) 500 DIGlobalVariableExpression *createGlobalVariableExpression( 501 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, 502 unsigned LineNo, DIType *Ty, bool isLocalToUnit, 503 DIExpression *Expr = nullptr, MDNode *Decl = nullptr, 504 uint32_t AlignInBits = 0); 505 506 /// Identical to createGlobalVariable 507 /// except that the resulting DbgNode is temporary and meant to be RAUWed. 508 DIGlobalVariable *createTempGlobalVariableFwdDecl( 509 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, 510 unsigned LineNo, DIType *Ty, bool isLocalToUnit, MDNode *Decl = nullptr, 511 uint32_t AlignInBits = 0); 512 513 /// Create a new descriptor for an auto variable. This is a local variable 514 /// that is not a subprogram parameter. 515 /// 516 /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually 517 /// leads to a \a DISubprogram. 518 /// 519 /// If \c AlwaysPreserve, this variable will be referenced from its 520 /// containing subprogram, and will survive some optimizations. 521 DILocalVariable * 522 createAutoVariable(DIScope *Scope, StringRef Name, DIFile *File, 523 unsigned LineNo, DIType *Ty, bool AlwaysPreserve = false, 524 DINode::DIFlags Flags = DINode::FlagZero, 525 uint32_t AlignInBits = 0); 526 527 /// Create a new descriptor for a parameter variable. 528 /// 529 /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually 530 /// leads to a \a DISubprogram. 531 /// 532 /// \c ArgNo is the index (starting from \c 1) of this variable in the 533 /// subprogram parameters. \c ArgNo should not conflict with other 534 /// parameters of the same subprogram. 535 /// 536 /// If \c AlwaysPreserve, this variable will be referenced from its 537 /// containing subprogram, and will survive some optimizations. 538 DILocalVariable * 539 createParameterVariable(DIScope *Scope, StringRef Name, unsigned ArgNo, 540 DIFile *File, unsigned LineNo, DIType *Ty, 541 bool AlwaysPreserve = false, 542 DINode::DIFlags Flags = DINode::FlagZero); 543 544 /// Create a new descriptor for the specified 545 /// variable which has a complex address expression for its address. 546 /// \param Addr An array of complex address operations. 547 DIExpression *createExpression(ArrayRef<uint64_t> Addr = None); 548 DIExpression *createExpression(ArrayRef<int64_t> Addr); 549 550 /// Create a descriptor to describe one part 551 /// of aggregate variable that is fragmented across multiple Values. 552 /// 553 /// \param OffsetInBits Offset of the piece in bits. 554 /// \param SizeInBits Size of the piece in bits. 555 DIExpression *createFragmentExpression(unsigned OffsetInBits, 556 unsigned SizeInBits); 557 558 /// Create an expression for a variable that does not have an address, but 559 /// does have a constant value. 560 DIExpression *createConstantValueExpression(uint64_t Val) { 561 return DIExpression::get( 562 VMContext, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_stack_value}); 563 } 564 565 /// Create a new descriptor for the specified subprogram. 566 /// See comments in DISubprogram* for descriptions of these fields. 567 /// \param Scope Function scope. 568 /// \param Name Function name. 569 /// \param LinkageName Mangled function name. 570 /// \param File File where this variable is defined. 571 /// \param LineNo Line number. 572 /// \param Ty Function type. 573 /// \param isLocalToUnit True if this function is not externally visible. 574 /// \param isDefinition True if this is a function definition. 575 /// \param ScopeLine Set to the beginning of the scope this starts 576 /// \param Flags e.g. is this function prototyped or not. 577 /// These flags are used to emit dwarf attributes. 578 /// \param isOptimized True if optimization is ON. 579 /// \param TParams Function template parameters. 580 DISubprogram *createFunction(DIScope *Scope, StringRef Name, 581 StringRef LinkageName, DIFile *File, 582 unsigned LineNo, DISubroutineType *Ty, 583 bool isLocalToUnit, bool isDefinition, 584 unsigned ScopeLine, 585 DINode::DIFlags Flags = DINode::FlagZero, 586 bool isOptimized = false, 587 DITemplateParameterArray TParams = nullptr, 588 DISubprogram *Decl = nullptr); 589 590 /// Identical to createFunction, 591 /// except that the resulting DbgNode is meant to be RAUWed. 592 DISubprogram *createTempFunctionFwdDecl( 593 DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, 594 unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, 595 bool isDefinition, unsigned ScopeLine, 596 DINode::DIFlags Flags = DINode::FlagZero, bool isOptimized = false, 597 DITemplateParameterArray TParams = nullptr, 598 DISubprogram *Decl = nullptr); 599 600 /// Create a new descriptor for the specified C++ method. 601 /// See comments in \a DISubprogram* for descriptions of these fields. 602 /// \param Scope Function scope. 603 /// \param Name Function name. 604 /// \param LinkageName Mangled function name. 605 /// \param File File where this variable is defined. 606 /// \param LineNo Line number. 607 /// \param Ty Function type. 608 /// \param isLocalToUnit True if this function is not externally visible.. 609 /// \param isDefinition True if this is a function definition. 610 /// \param Virtuality Attributes describing virtualness. e.g. pure 611 /// virtual function. 612 /// \param VTableIndex Index no of this method in virtual table, or -1u if 613 /// unrepresentable. 614 /// \param ThisAdjustment 615 /// MS ABI-specific adjustment of 'this' that occurs 616 /// in the prologue. 617 /// \param VTableHolder Type that holds vtable. 618 /// \param Flags e.g. is this function prototyped or not. 619 /// This flags are used to emit dwarf attributes. 620 /// \param isOptimized True if optimization is ON. 621 /// \param TParams Function template parameters. 622 DISubprogram *createMethod( 623 DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, 624 unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, 625 bool isDefinition, unsigned Virtuality = 0, unsigned VTableIndex = 0, 626 int ThisAdjustment = 0, DIType *VTableHolder = nullptr, 627 DINode::DIFlags Flags = DINode::FlagZero, bool isOptimized = false, 628 DITemplateParameterArray TParams = nullptr); 629 630 /// This creates new descriptor for a namespace with the specified 631 /// parent scope. 632 /// \param Scope Namespace scope 633 /// \param Name Name of this namespace 634 /// \param File Source file 635 /// \param LineNo Line number 636 /// \param ExportSymbols True for C++ inline namespaces. 637 DINamespace *createNameSpace(DIScope *Scope, StringRef Name, DIFile *File, 638 unsigned LineNo, bool ExportSymbols); 639 640 /// This creates new descriptor for a module with the specified 641 /// parent scope. 642 /// \param Scope Parent scope 643 /// \param Name Name of this module 644 /// \param ConfigurationMacros 645 /// A space-separated shell-quoted list of -D macro 646 /// definitions as they would appear on a command line. 647 /// \param IncludePath The path to the module map file. 648 /// \param ISysRoot The clang system root (value of -isysroot). 649 DIModule *createModule(DIScope *Scope, StringRef Name, 650 StringRef ConfigurationMacros, 651 StringRef IncludePath, 652 StringRef ISysRoot); 653 654 /// This creates a descriptor for a lexical block with a new file 655 /// attached. This merely extends the existing 656 /// lexical block as it crosses a file. 657 /// \param Scope Lexical block. 658 /// \param File Source file. 659 /// \param Discriminator DWARF path discriminator value. 660 DILexicalBlockFile *createLexicalBlockFile(DIScope *Scope, DIFile *File, 661 unsigned Discriminator = 0); 662 663 /// This creates a descriptor for a lexical block with the 664 /// specified parent context. 665 /// \param Scope Parent lexical scope. 666 /// \param File Source file. 667 /// \param Line Line number. 668 /// \param Col Column number. 669 DILexicalBlock *createLexicalBlock(DIScope *Scope, DIFile *File, 670 unsigned Line, unsigned Col); 671 672 /// Create a descriptor for an imported module. 673 /// \param Context The scope this module is imported into 674 /// \param NS The namespace being imported here 675 /// \param Line Line number 676 DIImportedEntity *createImportedModule(DIScope *Context, DINamespace *NS, 677 unsigned Line); 678 679 /// Create a descriptor for an imported module. 680 /// \param Context The scope this module is imported into 681 /// \param NS An aliased namespace 682 /// \param Line Line number 683 DIImportedEntity *createImportedModule(DIScope *Context, 684 DIImportedEntity *NS, unsigned Line); 685 686 /// Create a descriptor for an imported module. 687 /// \param Context The scope this module is imported into 688 /// \param M The module being imported here 689 /// \param Line Line number 690 DIImportedEntity *createImportedModule(DIScope *Context, DIModule *M, 691 unsigned Line); 692 693 /// Create a descriptor for an imported function. 694 /// \param Context The scope this module is imported into 695 /// \param Decl The declaration (or definition) of a function, type, or 696 /// variable 697 /// \param Line Line number 698 DIImportedEntity *createImportedDeclaration(DIScope *Context, DINode *Decl, 699 unsigned Line, 700 StringRef Name = ""); 701 702 /// Insert a new llvm.dbg.declare intrinsic call. 703 /// \param Storage llvm::Value of the variable 704 /// \param VarInfo Variable's debug info descriptor. 705 /// \param Expr A complex location expression. 706 /// \param DL Debug info location. 707 /// \param InsertAtEnd Location for the new intrinsic. 708 Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo, 709 DIExpression *Expr, const DILocation *DL, 710 BasicBlock *InsertAtEnd); 711 712 /// Insert a new llvm.dbg.declare intrinsic call. 713 /// \param Storage llvm::Value of the variable 714 /// \param VarInfo Variable's debug info descriptor. 715 /// \param Expr A complex location expression. 716 /// \param DL Debug info location. 717 /// \param InsertBefore Location for the new intrinsic. 718 Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo, 719 DIExpression *Expr, const DILocation *DL, 720 Instruction *InsertBefore); 721 722 /// Insert a new llvm.dbg.value intrinsic call. 723 /// \param Val llvm::Value of the variable 724 /// \param Offset Offset 725 /// \param VarInfo Variable's debug info descriptor. 726 /// \param Expr A complex location expression. 727 /// \param DL Debug info location. 728 /// \param InsertAtEnd Location for the new intrinsic. 729 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset, 730 DILocalVariable *VarInfo, 731 DIExpression *Expr, 732 const DILocation *DL, 733 BasicBlock *InsertAtEnd); 734 735 /// Insert a new llvm.dbg.value intrinsic call. 736 /// \param Val llvm::Value of the variable 737 /// \param Offset Offset 738 /// \param VarInfo Variable's debug info descriptor. 739 /// \param Expr A complex location expression. 740 /// \param DL Debug info location. 741 /// \param InsertBefore Location for the new intrinsic. 742 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset, 743 DILocalVariable *VarInfo, 744 DIExpression *Expr, 745 const DILocation *DL, 746 Instruction *InsertBefore); 747 748 /// Replace the vtable holder in the given composite type. 749 /// 750 /// If this creates a self reference, it may orphan some unresolved cycles 751 /// in the operands of \c T, so \a DIBuilder needs to track that. 752 void replaceVTableHolder(DICompositeType *&T, 753 DICompositeType *VTableHolder); 754 755 /// Replace arrays on a composite type. 756 /// 757 /// If \c T is resolved, but the arrays aren't -- which can happen if \c T 758 /// has a self-reference -- \a DIBuilder needs to track the array to 759 /// resolve cycles. 760 void replaceArrays(DICompositeType *&T, DINodeArray Elements, 761 DINodeArray TParams = DINodeArray()); 762 763 /// Replace a temporary node. 764 /// 765 /// Call \a MDNode::replaceAllUsesWith() on \c N, replacing it with \c 766 /// Replacement. 767 /// 768 /// If \c Replacement is the same as \c N.get(), instead call \a 769 /// MDNode::replaceWithUniqued(). In this case, the uniqued node could 770 /// have a different address, so we return the final address. 771 template <class NodeTy> 772 NodeTy *replaceTemporary(TempMDNode &&N, NodeTy *Replacement) { 773 if (N.get() == Replacement) 774 return cast<NodeTy>(MDNode::replaceWithUniqued(std::move(N))); 775 776 N->replaceAllUsesWith(Replacement); 777 return Replacement; 778 } 779 }; 780 781 } // end namespace llvm 782 783 #endif // LLVM_IR_DIBUILDER_H 784