DebugInfo.cpp revision 003f5519129e5413768b3d6a309f36389f425ced
1//===--- DebugInfo.cpp - Debug Information Helper Classes -----------------===// 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 implements the helper classes used to build and interpret debug 11// information in LLVM IR form. 12// 13//===----------------------------------------------------------------------===// 14 15#include "llvm/DebugInfo.h" 16#include "llvm/ADT/STLExtras.h" 17#include "llvm/ADT/SmallPtrSet.h" 18#include "llvm/ADT/SmallString.h" 19#include "llvm/Analysis/ValueTracking.h" 20#include "llvm/IR/Constants.h" 21#include "llvm/IR/DerivedTypes.h" 22#include "llvm/IR/Instructions.h" 23#include "llvm/IR/IntrinsicInst.h" 24#include "llvm/IR/Intrinsics.h" 25#include "llvm/IR/Module.h" 26#include "llvm/Support/Debug.h" 27#include "llvm/Support/Dwarf.h" 28#include "llvm/Support/ValueHandle.h" 29#include "llvm/Support/raw_ostream.h" 30using namespace llvm; 31using namespace llvm::dwarf; 32 33//===----------------------------------------------------------------------===// 34// DIDescriptor 35//===----------------------------------------------------------------------===// 36 37bool DIDescriptor::Verify() const { 38 return DbgNode && 39 (DIDerivedType(DbgNode).Verify() || 40 DICompositeType(DbgNode).Verify() || DIBasicType(DbgNode).Verify() || 41 DIVariable(DbgNode).Verify() || DISubprogram(DbgNode).Verify() || 42 DIGlobalVariable(DbgNode).Verify() || DIFile(DbgNode).Verify() || 43 DICompileUnit(DbgNode).Verify() || DINameSpace(DbgNode).Verify() || 44 DILexicalBlock(DbgNode).Verify() || 45 DILexicalBlockFile(DbgNode).Verify() || 46 DISubrange(DbgNode).Verify() || DIEnumerator(DbgNode).Verify() || 47 DIObjCProperty(DbgNode).Verify() || 48 DITemplateTypeParameter(DbgNode).Verify() || 49 DITemplateValueParameter(DbgNode).Verify() || 50 DIImportedEntity(DbgNode).Verify()); 51} 52 53static Value *getField(const MDNode *DbgNode, unsigned Elt) { 54 if (DbgNode == 0 || Elt >= DbgNode->getNumOperands()) 55 return 0; 56 return DbgNode->getOperand(Elt); 57} 58 59static MDNode *getNodeField(const MDNode *DbgNode, unsigned Elt) { 60 return dyn_cast_or_null<MDNode>(getField(DbgNode, Elt)); 61} 62 63static StringRef getStringField(const MDNode *DbgNode, unsigned Elt) { 64 if (MDString *MDS = dyn_cast_or_null<MDString>(getField(DbgNode, Elt))) 65 return MDS->getString(); 66 return StringRef(); 67} 68 69StringRef DIDescriptor::getStringField(unsigned Elt) const { 70 return ::getStringField(DbgNode, Elt); 71} 72 73uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const { 74 if (DbgNode == 0) 75 return 0; 76 77 if (Elt < DbgNode->getNumOperands()) 78 if (ConstantInt *CI 79 = dyn_cast_or_null<ConstantInt>(DbgNode->getOperand(Elt))) 80 return CI->getZExtValue(); 81 82 return 0; 83} 84 85int64_t DIDescriptor::getInt64Field(unsigned Elt) const { 86 if (DbgNode == 0) 87 return 0; 88 89 if (Elt < DbgNode->getNumOperands()) 90 if (ConstantInt *CI 91 = dyn_cast_or_null<ConstantInt>(DbgNode->getOperand(Elt))) 92 return CI->getSExtValue(); 93 94 return 0; 95} 96 97DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const { 98 MDNode *Field = getNodeField(DbgNode, Elt); 99 return DIDescriptor(Field); 100} 101 102GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const { 103 if (DbgNode == 0) 104 return 0; 105 106 if (Elt < DbgNode->getNumOperands()) 107 return dyn_cast_or_null<GlobalVariable>(DbgNode->getOperand(Elt)); 108 return 0; 109} 110 111Constant *DIDescriptor::getConstantField(unsigned Elt) const { 112 if (DbgNode == 0) 113 return 0; 114 115 if (Elt < DbgNode->getNumOperands()) 116 return dyn_cast_or_null<Constant>(DbgNode->getOperand(Elt)); 117 return 0; 118} 119 120Function *DIDescriptor::getFunctionField(unsigned Elt) const { 121 if (DbgNode == 0) 122 return 0; 123 124 if (Elt < DbgNode->getNumOperands()) 125 return dyn_cast_or_null<Function>(DbgNode->getOperand(Elt)); 126 return 0; 127} 128 129void DIDescriptor::replaceFunctionField(unsigned Elt, Function *F) { 130 if (DbgNode == 0) 131 return; 132 133 if (Elt < DbgNode->getNumOperands()) { 134 MDNode *Node = const_cast<MDNode*>(DbgNode); 135 Node->replaceOperandWith(Elt, F); 136 } 137} 138 139unsigned DIVariable::getNumAddrElements() const { 140 return DbgNode->getNumOperands()-8; 141} 142 143/// getInlinedAt - If this variable is inlined then return inline location. 144MDNode *DIVariable::getInlinedAt() const { 145 return getNodeField(DbgNode, 7); 146} 147 148//===----------------------------------------------------------------------===// 149// Predicates 150//===----------------------------------------------------------------------===// 151 152/// isBasicType - Return true if the specified tag is legal for 153/// DIBasicType. 154bool DIDescriptor::isBasicType() const { 155 if (!DbgNode) return false; 156 switch (getTag()) { 157 case dwarf::DW_TAG_base_type: 158 case dwarf::DW_TAG_unspecified_type: 159 return true; 160 default: 161 return false; 162 } 163} 164 165/// isDerivedType - Return true if the specified tag is legal for DIDerivedType. 166bool DIDescriptor::isDerivedType() const { 167 if (!DbgNode) return false; 168 switch (getTag()) { 169 case dwarf::DW_TAG_typedef: 170 case dwarf::DW_TAG_pointer_type: 171 case dwarf::DW_TAG_ptr_to_member_type: 172 case dwarf::DW_TAG_reference_type: 173 case dwarf::DW_TAG_rvalue_reference_type: 174 case dwarf::DW_TAG_const_type: 175 case dwarf::DW_TAG_volatile_type: 176 case dwarf::DW_TAG_restrict_type: 177 case dwarf::DW_TAG_member: 178 case dwarf::DW_TAG_inheritance: 179 case dwarf::DW_TAG_friend: 180 return true; 181 default: 182 // CompositeTypes are currently modelled as DerivedTypes. 183 return isCompositeType(); 184 } 185} 186 187/// isCompositeType - Return true if the specified tag is legal for 188/// DICompositeType. 189bool DIDescriptor::isCompositeType() const { 190 if (!DbgNode) return false; 191 switch (getTag()) { 192 case dwarf::DW_TAG_array_type: 193 case dwarf::DW_TAG_structure_type: 194 case dwarf::DW_TAG_union_type: 195 case dwarf::DW_TAG_enumeration_type: 196 case dwarf::DW_TAG_subroutine_type: 197 case dwarf::DW_TAG_class_type: 198 return true; 199 default: 200 return false; 201 } 202} 203 204/// isVariable - Return true if the specified tag is legal for DIVariable. 205bool DIDescriptor::isVariable() const { 206 if (!DbgNode) return false; 207 switch (getTag()) { 208 case dwarf::DW_TAG_auto_variable: 209 case dwarf::DW_TAG_arg_variable: 210 return true; 211 default: 212 return false; 213 } 214} 215 216/// isType - Return true if the specified tag is legal for DIType. 217bool DIDescriptor::isType() const { 218 return isBasicType() || isCompositeType() || isDerivedType(); 219} 220 221/// isSubprogram - Return true if the specified tag is legal for 222/// DISubprogram. 223bool DIDescriptor::isSubprogram() const { 224 return DbgNode && getTag() == dwarf::DW_TAG_subprogram; 225} 226 227/// isGlobalVariable - Return true if the specified tag is legal for 228/// DIGlobalVariable. 229bool DIDescriptor::isGlobalVariable() const { 230 return DbgNode && (getTag() == dwarf::DW_TAG_variable || 231 getTag() == dwarf::DW_TAG_constant); 232} 233 234/// isUnspecifiedParmeter - Return true if the specified tag is 235/// DW_TAG_unspecified_parameters. 236bool DIDescriptor::isUnspecifiedParameter() const { 237 return DbgNode && getTag() == dwarf::DW_TAG_unspecified_parameters; 238} 239 240/// isScope - Return true if the specified tag is one of the scope 241/// related tag. 242bool DIDescriptor::isScope() const { 243 if (!DbgNode) return false; 244 switch (getTag()) { 245 case dwarf::DW_TAG_compile_unit: 246 case dwarf::DW_TAG_lexical_block: 247 case dwarf::DW_TAG_subprogram: 248 case dwarf::DW_TAG_namespace: 249 return true; 250 default: 251 break; 252 } 253 return false; 254} 255 256/// isTemplateTypeParameter - Return true if the specified tag is 257/// DW_TAG_template_type_parameter. 258bool DIDescriptor::isTemplateTypeParameter() const { 259 return DbgNode && getTag() == dwarf::DW_TAG_template_type_parameter; 260} 261 262/// isTemplateValueParameter - Return true if the specified tag is 263/// DW_TAG_template_value_parameter. 264bool DIDescriptor::isTemplateValueParameter() const { 265 return DbgNode && (getTag() == dwarf::DW_TAG_template_value_parameter || 266 getTag() == dwarf::DW_TAG_GNU_template_template_param || 267 getTag() == dwarf::DW_TAG_GNU_template_parameter_pack); 268} 269 270/// isCompileUnit - Return true if the specified tag is DW_TAG_compile_unit. 271bool DIDescriptor::isCompileUnit() const { 272 return DbgNode && getTag() == dwarf::DW_TAG_compile_unit; 273} 274 275/// isFile - Return true if the specified tag is DW_TAG_file_type. 276bool DIDescriptor::isFile() const { 277 return DbgNode && getTag() == dwarf::DW_TAG_file_type; 278} 279 280/// isNameSpace - Return true if the specified tag is DW_TAG_namespace. 281bool DIDescriptor::isNameSpace() const { 282 return DbgNode && getTag() == dwarf::DW_TAG_namespace; 283} 284 285/// isLexicalBlockFile - Return true if the specified descriptor is a 286/// lexical block with an extra file. 287bool DIDescriptor::isLexicalBlockFile() const { 288 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block && 289 (DbgNode->getNumOperands() == 3); 290} 291 292/// isLexicalBlock - Return true if the specified tag is DW_TAG_lexical_block. 293bool DIDescriptor::isLexicalBlock() const { 294 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block && 295 (DbgNode->getNumOperands() > 3); 296} 297 298/// isSubrange - Return true if the specified tag is DW_TAG_subrange_type. 299bool DIDescriptor::isSubrange() const { 300 return DbgNode && getTag() == dwarf::DW_TAG_subrange_type; 301} 302 303/// isEnumerator - Return true if the specified tag is DW_TAG_enumerator. 304bool DIDescriptor::isEnumerator() const { 305 return DbgNode && getTag() == dwarf::DW_TAG_enumerator; 306} 307 308/// isObjCProperty - Return true if the specified tag is DW_TAG_APPLE_property. 309bool DIDescriptor::isObjCProperty() const { 310 return DbgNode && getTag() == dwarf::DW_TAG_APPLE_property; 311} 312 313/// \brief Return true if the specified tag is DW_TAG_imported_module or 314/// DW_TAG_imported_declaration. 315bool DIDescriptor::isImportedEntity() const { 316 return DbgNode && (getTag() == dwarf::DW_TAG_imported_module || 317 getTag() == dwarf::DW_TAG_imported_declaration); 318} 319 320//===----------------------------------------------------------------------===// 321// Simple Descriptor Constructors and other Methods 322//===----------------------------------------------------------------------===// 323 324unsigned DIArray::getNumElements() const { 325 if (!DbgNode) 326 return 0; 327 return DbgNode->getNumOperands(); 328} 329 330/// replaceAllUsesWith - Replace all uses of the MDNode used by this 331/// type with the one in the passed descriptor. 332void DIType::replaceAllUsesWith(DIDescriptor &D) { 333 334 assert(DbgNode && "Trying to replace an unverified type!"); 335 336 // Since we use a TrackingVH for the node, its easy for clients to manufacture 337 // legitimate situations where they want to replaceAllUsesWith() on something 338 // which, due to uniquing, has merged with the source. We shield clients from 339 // this detail by allowing a value to be replaced with replaceAllUsesWith() 340 // itself. 341 if (DbgNode != D) { 342 MDNode *Node = const_cast<MDNode*>(DbgNode); 343 const MDNode *DN = D; 344 const Value *V = cast_or_null<Value>(DN); 345 Node->replaceAllUsesWith(const_cast<Value*>(V)); 346 MDNode::deleteTemporary(Node); 347 } 348} 349 350/// replaceAllUsesWith - Replace all uses of the MDNode used by this 351/// type with the one in D. 352void DIType::replaceAllUsesWith(MDNode *D) { 353 354 assert(DbgNode && "Trying to replace an unverified type!"); 355 356 // Since we use a TrackingVH for the node, its easy for clients to manufacture 357 // legitimate situations where they want to replaceAllUsesWith() on something 358 // which, due to uniquing, has merged with the source. We shield clients from 359 // this detail by allowing a value to be replaced with replaceAllUsesWith() 360 // itself. 361 if (DbgNode != D) { 362 MDNode *Node = const_cast<MDNode*>(DbgNode); 363 const MDNode *DN = D; 364 const Value *V = cast_or_null<Value>(DN); 365 Node->replaceAllUsesWith(const_cast<Value*>(V)); 366 MDNode::deleteTemporary(Node); 367 } 368} 369 370/// isUnsignedDIType - Return true if type encoding is unsigned. 371bool DIType::isUnsignedDIType() { 372 DIDerivedType DTy(DbgNode); 373 if (DTy.Verify()) 374 return DTy.getTypeDerivedFrom().isUnsignedDIType(); 375 376 DIBasicType BTy(DbgNode); 377 if (BTy.Verify()) { 378 unsigned Encoding = BTy.getEncoding(); 379 if (Encoding == dwarf::DW_ATE_unsigned || 380 Encoding == dwarf::DW_ATE_unsigned_char || 381 Encoding == dwarf::DW_ATE_boolean) 382 return true; 383 } 384 return false; 385} 386 387/// Verify - Verify that a compile unit is well formed. 388bool DICompileUnit::Verify() const { 389 if (!isCompileUnit()) 390 return false; 391 392 // Don't bother verifying the compilation directory or producer string 393 // as those could be empty. 394 if (getFilename().empty()) 395 return false; 396 397 return DbgNode->getNumOperands() == 13; 398} 399 400/// Verify - Verify that an ObjC property is well formed. 401bool DIObjCProperty::Verify() const { 402 if (!isObjCProperty()) 403 return false; 404 405 // Don't worry about the rest of the strings for now. 406 return DbgNode->getNumOperands() == 8; 407} 408 409/// Check if a field at position Elt of a MDNode is a MDNode. 410/// We currently allow an empty string and an integer. 411/// But we don't allow a non-empty string in a MDNode field. 412static bool fieldIsMDNode(const MDNode *DbgNode, unsigned Elt) { 413 // FIXME: This function should return true, if the field is null or the field 414 // is indeed a MDNode: return !Fld || isa<MDNode>(Fld). 415 Value *Fld = getField(DbgNode, Elt); 416 if (Fld && isa<MDString>(Fld) && 417 !cast<MDString>(Fld)->getString().empty()) 418 return false; 419 return true; 420} 421 422/// Verify - Verify that a type descriptor is well formed. 423bool DIType::Verify() const { 424 if (!isType()) 425 return false; 426 // Make sure Context @ field 2 is MDNode. 427 if (!fieldIsMDNode(DbgNode, 2)) 428 return false; 429 430 // FIXME: Sink this into the various subclass verifies. 431 uint16_t Tag = getTag(); 432 if (!isBasicType() && Tag != dwarf::DW_TAG_const_type && 433 Tag != dwarf::DW_TAG_volatile_type && Tag != dwarf::DW_TAG_pointer_type && 434 Tag != dwarf::DW_TAG_ptr_to_member_type && 435 Tag != dwarf::DW_TAG_reference_type && 436 Tag != dwarf::DW_TAG_rvalue_reference_type && 437 Tag != dwarf::DW_TAG_restrict_type && Tag != dwarf::DW_TAG_array_type && 438 Tag != dwarf::DW_TAG_enumeration_type && 439 Tag != dwarf::DW_TAG_subroutine_type && 440 Tag != dwarf::DW_TAG_inheritance && Tag != dwarf::DW_TAG_friend && 441 getFilename().empty()) 442 return false; 443 // DIType is abstract, it should be a BasicType, a DerivedType or 444 // a CompositeType. 445 if (isBasicType()) 446 DIBasicType(DbgNode).Verify(); 447 else if (isCompositeType()) 448 DICompositeType(DbgNode).Verify(); 449 else if (isDerivedType()) 450 DIDerivedType(DbgNode).Verify(); 451 else 452 return false; 453 return true; 454} 455 456/// Verify - Verify that a basic type descriptor is well formed. 457bool DIBasicType::Verify() const { 458 return isBasicType() && DbgNode->getNumOperands() == 10; 459} 460 461/// Verify - Verify that a derived type descriptor is well formed. 462bool DIDerivedType::Verify() const { 463 // Make sure DerivedFrom @ field 9 is MDNode. 464 if (!fieldIsMDNode(DbgNode, 9)) 465 return false; 466 if (getTag() == dwarf::DW_TAG_ptr_to_member_type) 467 // Make sure ClassType @ field 10 is MDNode. 468 if (!fieldIsMDNode(DbgNode, 10)) 469 return false; 470 471 return isDerivedType() && DbgNode->getNumOperands() >= 10 && 472 DbgNode->getNumOperands() <= 14; 473} 474 475/// Verify - Verify that a composite type descriptor is well formed. 476bool DICompositeType::Verify() const { 477 if (!isCompositeType()) 478 return false; 479 480 // Make sure DerivedFrom @ field 9 and ContainingType @ field 12 are MDNodes. 481 if (!fieldIsMDNode(DbgNode, 9)) 482 return false; 483 if (!fieldIsMDNode(DbgNode, 12)) 484 return false; 485 486 // If this is an array type verify that we have a DIType in the derived type 487 // field as that's the type of our element. 488 if (getTag() == dwarf::DW_TAG_array_type) 489 if (!DIType(getTypeDerivedFrom())) 490 return false; 491 492 return DbgNode->getNumOperands() >= 10 && DbgNode->getNumOperands() <= 14; 493} 494 495/// Verify - Verify that a subprogram descriptor is well formed. 496bool DISubprogram::Verify() const { 497 if (!isSubprogram()) 498 return false; 499 500 // Make sure context @ field 2 and type @ field 7 are MDNodes. 501 if (!fieldIsMDNode(DbgNode, 2)) 502 return false; 503 if (!fieldIsMDNode(DbgNode, 7)) 504 return false; 505 // Containing type @ field 12. 506 if (!fieldIsMDNode(DbgNode, 12)) 507 return false; 508 return DbgNode->getNumOperands() == 20; 509} 510 511/// Verify - Verify that a global variable descriptor is well formed. 512bool DIGlobalVariable::Verify() const { 513 if (!isGlobalVariable()) 514 return false; 515 516 if (getDisplayName().empty()) 517 return false; 518 // Make sure context @ field 2 and type @ field 8 are MDNodes. 519 if (!fieldIsMDNode(DbgNode, 2)) 520 return false; 521 if (!fieldIsMDNode(DbgNode, 8)) 522 return false; 523 // Make sure StaticDataMemberDeclaration @ field 12 is MDNode. 524 if (!fieldIsMDNode(DbgNode, 12)) 525 return false; 526 527 return DbgNode->getNumOperands() == 13; 528} 529 530/// Verify - Verify that a variable descriptor is well formed. 531bool DIVariable::Verify() const { 532 if (!isVariable()) 533 return false; 534 535 // Make sure context @ field 1 and type @ field 5 are MDNodes. 536 if (!fieldIsMDNode(DbgNode, 1)) 537 return false; 538 if (!fieldIsMDNode(DbgNode, 5)) 539 return false; 540 return DbgNode->getNumOperands() >= 8; 541} 542 543/// Verify - Verify that a location descriptor is well formed. 544bool DILocation::Verify() const { 545 if (!DbgNode) 546 return false; 547 548 return DbgNode->getNumOperands() == 4; 549} 550 551/// Verify - Verify that a namespace descriptor is well formed. 552bool DINameSpace::Verify() const { 553 if (!isNameSpace()) 554 return false; 555 return DbgNode->getNumOperands() == 5; 556} 557 558/// \brief Retrieve the MDNode for the directory/file pair. 559MDNode *DIFile::getFileNode() const { 560 return getNodeField(DbgNode, 1); 561} 562 563/// \brief Verify that the file descriptor is well formed. 564bool DIFile::Verify() const { 565 return isFile() && DbgNode->getNumOperands() == 2; 566} 567 568/// \brief Verify that the enumerator descriptor is well formed. 569bool DIEnumerator::Verify() const { 570 return isEnumerator() && DbgNode->getNumOperands() == 3; 571} 572 573/// \brief Verify that the subrange descriptor is well formed. 574bool DISubrange::Verify() const { 575 return isSubrange() && DbgNode->getNumOperands() == 3; 576} 577 578/// \brief Verify that the lexical block descriptor is well formed. 579bool DILexicalBlock::Verify() const { 580 return isLexicalBlock() && DbgNode->getNumOperands() == 6; 581} 582 583/// \brief Verify that the file-scoped lexical block descriptor is well formed. 584bool DILexicalBlockFile::Verify() const { 585 return isLexicalBlockFile() && DbgNode->getNumOperands() == 3; 586} 587 588/// \brief Verify that the template type parameter descriptor is well formed. 589bool DITemplateTypeParameter::Verify() const { 590 return isTemplateTypeParameter() && DbgNode->getNumOperands() == 7; 591} 592 593/// \brief Verify that the template value parameter descriptor is well formed. 594bool DITemplateValueParameter::Verify() const { 595 return isTemplateValueParameter() && DbgNode->getNumOperands() == 8; 596} 597 598/// \brief Verify that the imported module descriptor is well formed. 599bool DIImportedEntity::Verify() const { 600 return isImportedEntity() && 601 (DbgNode->getNumOperands() == 4 || DbgNode->getNumOperands() == 5); 602} 603 604/// getOriginalTypeSize - If this type is derived from a base type then 605/// return base type size. 606uint64_t DIDerivedType::getOriginalTypeSize() const { 607 uint16_t Tag = getTag(); 608 609 if (Tag != dwarf::DW_TAG_member && Tag != dwarf::DW_TAG_typedef && 610 Tag != dwarf::DW_TAG_const_type && Tag != dwarf::DW_TAG_volatile_type && 611 Tag != dwarf::DW_TAG_restrict_type) 612 return getSizeInBits(); 613 614 DIType BaseType = getTypeDerivedFrom(); 615 616 // If this type is not derived from any type then take conservative approach. 617 if (!BaseType.isValid()) 618 return getSizeInBits(); 619 620 // If this is a derived type, go ahead and get the base type, unless it's a 621 // reference then it's just the size of the field. Pointer types have no need 622 // of this since they're a different type of qualification on the type. 623 if (BaseType.getTag() == dwarf::DW_TAG_reference_type || 624 BaseType.getTag() == dwarf::DW_TAG_rvalue_reference_type) 625 return getSizeInBits(); 626 627 if (BaseType.isDerivedType()) 628 return DIDerivedType(BaseType).getOriginalTypeSize(); 629 630 return BaseType.getSizeInBits(); 631} 632 633/// getObjCProperty - Return property node, if this ivar is associated with one. 634MDNode *DIDerivedType::getObjCProperty() const { 635 return getNodeField(DbgNode, 10); 636} 637 638/// \brief Set the array of member DITypes. 639void DICompositeType::setTypeArray(DIArray Elements, DIArray TParams) { 640 assert((!TParams || DbgNode->getNumOperands() == 14) && 641 "If you're setting the template parameters this should include a slot " 642 "for that!"); 643 TrackingVH<MDNode> N(*this); 644 N->replaceOperandWith(10, Elements); 645 if (TParams) 646 N->replaceOperandWith(13, TParams); 647 DbgNode = N; 648} 649 650void DICompositeType::addMember(DIDescriptor D) { 651 SmallVector<llvm::Value *, 16> M; 652 DIArray OrigM = getTypeArray(); 653 unsigned Elements = OrigM.getNumElements(); 654 if (Elements == 1 && !OrigM.getElement(0)) 655 Elements = 0; 656 M.reserve(Elements + 1); 657 for (unsigned i = 0; i != Elements; ++i) 658 M.push_back(OrigM.getElement(i)); 659 M.push_back(D); 660 setTypeArray(DIArray(MDNode::get(DbgNode->getContext(), M))); 661} 662 663/// \brief Set the containing type. 664void DICompositeType::setContainingType(DICompositeType ContainingType) { 665 TrackingVH<MDNode> N(*this); 666 N->replaceOperandWith(12, ContainingType); 667 DbgNode = N; 668} 669 670/// isInlinedFnArgument - Return true if this variable provides debugging 671/// information for an inlined function arguments. 672bool DIVariable::isInlinedFnArgument(const Function *CurFn) { 673 assert(CurFn && "Invalid function"); 674 if (!getContext().isSubprogram()) 675 return false; 676 // This variable is not inlined function argument if its scope 677 // does not describe current function. 678 return !DISubprogram(getContext()).describes(CurFn); 679} 680 681/// describes - Return true if this subprogram provides debugging 682/// information for the function F. 683bool DISubprogram::describes(const Function *F) { 684 assert(F && "Invalid function"); 685 if (F == getFunction()) 686 return true; 687 StringRef Name = getLinkageName(); 688 if (Name.empty()) 689 Name = getName(); 690 if (F->getName() == Name) 691 return true; 692 return false; 693} 694 695unsigned DISubprogram::isOptimized() const { 696 assert (DbgNode && "Invalid subprogram descriptor!"); 697 if (DbgNode->getNumOperands() == 15) 698 return getUnsignedField(14); 699 return 0; 700} 701 702MDNode *DISubprogram::getVariablesNodes() const { 703 return getNodeField(DbgNode, 18); 704} 705 706DIArray DISubprogram::getVariables() const { 707 return DIArray(getNodeField(DbgNode, 18)); 708} 709 710Value *DITemplateValueParameter::getValue() const { 711 return getField(DbgNode, 4); 712} 713 714// If the current node has a parent scope then return that, 715// else return an empty scope. 716DIScope DIScope::getContext() const { 717 718 if (isType()) 719 return DIType(DbgNode).getContext(); 720 721 if (isSubprogram()) 722 return DISubprogram(DbgNode).getContext(); 723 724 if (isLexicalBlock()) 725 return DILexicalBlock(DbgNode).getContext(); 726 727 if (isLexicalBlockFile()) 728 return DILexicalBlockFile(DbgNode).getContext(); 729 730 if (isNameSpace()) 731 return DINameSpace(DbgNode).getContext(); 732 733 assert((isFile() || isCompileUnit()) && "Unhandled type of scope."); 734 return DIScope(); 735} 736 737StringRef DIScope::getFilename() const { 738 if (!DbgNode) 739 return StringRef(); 740 return ::getStringField(getNodeField(DbgNode, 1), 0); 741} 742 743StringRef DIScope::getDirectory() const { 744 if (!DbgNode) 745 return StringRef(); 746 return ::getStringField(getNodeField(DbgNode, 1), 1); 747} 748 749DIArray DICompileUnit::getEnumTypes() const { 750 if (!DbgNode || DbgNode->getNumOperands() < 13) 751 return DIArray(); 752 753 return DIArray(getNodeField(DbgNode, 7)); 754} 755 756DIArray DICompileUnit::getRetainedTypes() const { 757 if (!DbgNode || DbgNode->getNumOperands() < 13) 758 return DIArray(); 759 760 return DIArray(getNodeField(DbgNode, 8)); 761} 762 763DIArray DICompileUnit::getSubprograms() const { 764 if (!DbgNode || DbgNode->getNumOperands() < 13) 765 return DIArray(); 766 767 return DIArray(getNodeField(DbgNode, 9)); 768} 769 770 771DIArray DICompileUnit::getGlobalVariables() const { 772 if (!DbgNode || DbgNode->getNumOperands() < 13) 773 return DIArray(); 774 775 return DIArray(getNodeField(DbgNode, 10)); 776} 777 778DIArray DICompileUnit::getImportedEntities() const { 779 if (!DbgNode || DbgNode->getNumOperands() < 13) 780 return DIArray(); 781 782 return DIArray(getNodeField(DbgNode, 11)); 783} 784 785/// fixupSubprogramName - Replace contains special characters used 786/// in a typical Objective-C names with '.' in a given string. 787static void fixupSubprogramName(DISubprogram Fn, SmallVectorImpl<char> &Out) { 788 StringRef FName = 789 Fn.getFunction() ? Fn.getFunction()->getName() : Fn.getName(); 790 FName = Function::getRealLinkageName(FName); 791 792 StringRef Prefix("llvm.dbg.lv."); 793 Out.reserve(FName.size() + Prefix.size()); 794 Out.append(Prefix.begin(), Prefix.end()); 795 796 bool isObjCLike = false; 797 for (size_t i = 0, e = FName.size(); i < e; ++i) { 798 char C = FName[i]; 799 if (C == '[') 800 isObjCLike = true; 801 802 if (isObjCLike && (C == '[' || C == ']' || C == ' ' || C == ':' || 803 C == '+' || C == '(' || C == ')')) 804 Out.push_back('.'); 805 else 806 Out.push_back(C); 807 } 808} 809 810/// getFnSpecificMDNode - Return a NameMDNode, if available, that is 811/// suitable to hold function specific information. 812NamedMDNode *llvm::getFnSpecificMDNode(const Module &M, DISubprogram Fn) { 813 SmallString<32> Name; 814 fixupSubprogramName(Fn, Name); 815 return M.getNamedMetadata(Name.str()); 816} 817 818/// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable 819/// to hold function specific information. 820NamedMDNode *llvm::getOrInsertFnSpecificMDNode(Module &M, DISubprogram Fn) { 821 SmallString<32> Name; 822 fixupSubprogramName(Fn, Name); 823 return M.getOrInsertNamedMetadata(Name.str()); 824} 825 826/// createInlinedVariable - Create a new inlined variable based on current 827/// variable. 828/// @param DV Current Variable. 829/// @param InlinedScope Location at current variable is inlined. 830DIVariable llvm::createInlinedVariable(MDNode *DV, MDNode *InlinedScope, 831 LLVMContext &VMContext) { 832 SmallVector<Value *, 16> Elts; 833 // Insert inlined scope as 7th element. 834 for (unsigned i = 0, e = DV->getNumOperands(); i != e; ++i) 835 i == 7 ? Elts.push_back(InlinedScope) : 836 Elts.push_back(DV->getOperand(i)); 837 return DIVariable(MDNode::get(VMContext, Elts)); 838} 839 840/// cleanseInlinedVariable - Remove inlined scope from the variable. 841DIVariable llvm::cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext) { 842 SmallVector<Value *, 16> Elts; 843 // Insert inlined scope as 7th element. 844 for (unsigned i = 0, e = DV->getNumOperands(); i != e; ++i) 845 i == 7 ? 846 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext))): 847 Elts.push_back(DV->getOperand(i)); 848 return DIVariable(MDNode::get(VMContext, Elts)); 849} 850 851/// getDISubprogram - Find subprogram that is enclosing this scope. 852DISubprogram llvm::getDISubprogram(const MDNode *Scope) { 853 DIDescriptor D(Scope); 854 if (D.isSubprogram()) 855 return DISubprogram(Scope); 856 857 if (D.isLexicalBlockFile()) 858 return getDISubprogram(DILexicalBlockFile(Scope).getContext()); 859 860 if (D.isLexicalBlock()) 861 return getDISubprogram(DILexicalBlock(Scope).getContext()); 862 863 return DISubprogram(); 864} 865 866/// getDICompositeType - Find underlying composite type. 867DICompositeType llvm::getDICompositeType(DIType T) { 868 if (T.isCompositeType()) 869 return DICompositeType(T); 870 871 if (T.isDerivedType()) 872 return getDICompositeType(DIDerivedType(T).getTypeDerivedFrom()); 873 874 return DICompositeType(); 875} 876 877/// isSubprogramContext - Return true if Context is either a subprogram 878/// or another context nested inside a subprogram. 879bool llvm::isSubprogramContext(const MDNode *Context) { 880 if (!Context) 881 return false; 882 DIDescriptor D(Context); 883 if (D.isSubprogram()) 884 return true; 885 if (D.isType()) 886 return isSubprogramContext(DIType(Context).getContext()); 887 return false; 888} 889 890//===----------------------------------------------------------------------===// 891// DebugInfoFinder implementations. 892//===----------------------------------------------------------------------===// 893 894void DebugInfoFinder::reset() { 895 CUs.clear(); 896 SPs.clear(); 897 GVs.clear(); 898 TYs.clear(); 899 Scopes.clear(); 900 NodesSeen.clear(); 901} 902 903/// processModule - Process entire module and collect debug info. 904void DebugInfoFinder::processModule(const Module &M) { 905 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) { 906 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) { 907 DICompileUnit CU(CU_Nodes->getOperand(i)); 908 addCompileUnit(CU); 909 DIArray GVs = CU.getGlobalVariables(); 910 for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i) { 911 DIGlobalVariable DIG(GVs.getElement(i)); 912 if (addGlobalVariable(DIG)) { 913 processScope(DIG.getContext()); 914 processType(DIG.getType()); 915 } 916 } 917 DIArray SPs = CU.getSubprograms(); 918 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) 919 processSubprogram(DISubprogram(SPs.getElement(i))); 920 DIArray EnumTypes = CU.getEnumTypes(); 921 for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i) 922 processType(DIType(EnumTypes.getElement(i))); 923 DIArray RetainedTypes = CU.getRetainedTypes(); 924 for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i) 925 processType(DIType(RetainedTypes.getElement(i))); 926 // FIXME: We really shouldn't be bailing out after visiting just one CU 927 return; 928 } 929 } 930} 931 932/// processLocation - Process DILocation. 933void DebugInfoFinder::processLocation(DILocation Loc) { 934 if (!Loc) return; 935 processScope(Loc.getScope()); 936 processLocation(Loc.getOrigLocation()); 937} 938 939/// processType - Process DIType. 940void DebugInfoFinder::processType(DIType DT) { 941 if (!addType(DT)) 942 return; 943 processScope(DT.getContext()); 944 if (DT.isCompositeType()) { 945 DICompositeType DCT(DT); 946 processType(DCT.getTypeDerivedFrom()); 947 DIArray DA = DCT.getTypeArray(); 948 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) { 949 DIDescriptor D = DA.getElement(i); 950 if (D.isType()) 951 processType(DIType(D)); 952 else if (D.isSubprogram()) 953 processSubprogram(DISubprogram(D)); 954 } 955 } else if (DT.isDerivedType()) { 956 DIDerivedType DDT(DT); 957 processType(DDT.getTypeDerivedFrom()); 958 } 959} 960 961void DebugInfoFinder::processScope(DIScope Scope) { 962 if (Scope.isType()) { 963 DIType Ty(Scope); 964 processType(Ty); 965 return; 966 } 967 if (Scope.isCompileUnit()) { 968 addCompileUnit(DICompileUnit(Scope)); 969 return; 970 } 971 if (Scope.isSubprogram()) { 972 processSubprogram(DISubprogram(Scope)); 973 return; 974 } 975 if (!addScope(Scope)) 976 return; 977 if (Scope.isLexicalBlock()) { 978 DILexicalBlock LB(Scope); 979 processScope(LB.getContext()); 980 } else if (Scope.isLexicalBlockFile()) { 981 DILexicalBlockFile LBF = DILexicalBlockFile(Scope); 982 processScope(LBF.getScope()); 983 } else if (Scope.isNameSpace()) { 984 DINameSpace NS(Scope); 985 processScope(NS.getContext()); 986 } 987} 988 989/// processLexicalBlock 990void DebugInfoFinder::processLexicalBlock(DILexicalBlock LB) { 991 DIScope Context = LB.getContext(); 992 if (Context.isLexicalBlock()) 993 return processLexicalBlock(DILexicalBlock(Context)); 994 else if (Context.isLexicalBlockFile()) { 995 DILexicalBlockFile DBF = DILexicalBlockFile(Context); 996 return processLexicalBlock(DILexicalBlock(DBF.getScope())); 997 } 998 else 999 return processSubprogram(DISubprogram(Context)); 1000} 1001 1002/// processSubprogram - Process DISubprogram. 1003void DebugInfoFinder::processSubprogram(DISubprogram SP) { 1004 if (!addSubprogram(SP)) 1005 return; 1006 processScope(SP.getContext()); 1007 processType(SP.getType()); 1008 DIArray TParams = SP.getTemplateParams(); 1009 for (unsigned I = 0, E = TParams.getNumElements(); I != E; ++I) { 1010 DIDescriptor Element = TParams.getElement(I); 1011 if (Element.isTemplateTypeParameter()) { 1012 DITemplateTypeParameter TType(Element); 1013 processScope(TType.getContext()); 1014 processType(TType.getType()); 1015 } else if (Element.isTemplateValueParameter()) { 1016 DITemplateValueParameter TVal(Element); 1017 processScope(TVal.getContext()); 1018 processType(TVal.getType()); 1019 } 1020 } 1021} 1022 1023/// processDeclare - Process DbgDeclareInst. 1024void DebugInfoFinder::processDeclare(const DbgDeclareInst *DDI) { 1025 MDNode *N = dyn_cast<MDNode>(DDI->getVariable()); 1026 if (!N) return; 1027 1028 DIDescriptor DV(N); 1029 if (!DV.isVariable()) 1030 return; 1031 1032 if (!NodesSeen.insert(DV)) 1033 return; 1034 processScope(DIVariable(N).getContext()); 1035 processType(DIVariable(N).getType()); 1036} 1037 1038void DebugInfoFinder::processValue(const DbgValueInst *DVI) { 1039 MDNode *N = dyn_cast<MDNode>(DVI->getVariable()); 1040 if (!N) return; 1041 1042 DIDescriptor DV(N); 1043 if (!DV.isVariable()) 1044 return; 1045 1046 if (!NodesSeen.insert(DV)) 1047 return; 1048 processScope(DIVariable(N).getContext()); 1049 processType(DIVariable(N).getType()); 1050} 1051 1052/// addType - Add type into Tys. 1053bool DebugInfoFinder::addType(DIType DT) { 1054 if (!DT) 1055 return false; 1056 1057 if (!NodesSeen.insert(DT)) 1058 return false; 1059 1060 TYs.push_back(DT); 1061 return true; 1062} 1063 1064/// addCompileUnit - Add compile unit into CUs. 1065bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) { 1066 if (!CU) 1067 return false; 1068 if (!NodesSeen.insert(CU)) 1069 return false; 1070 1071 CUs.push_back(CU); 1072 return true; 1073} 1074 1075/// addGlobalVariable - Add global variable into GVs. 1076bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) { 1077 if (!DIG) 1078 return false; 1079 1080 if (!NodesSeen.insert(DIG)) 1081 return false; 1082 1083 GVs.push_back(DIG); 1084 return true; 1085} 1086 1087// addSubprogram - Add subprgoram into SPs. 1088bool DebugInfoFinder::addSubprogram(DISubprogram SP) { 1089 if (!SP) 1090 return false; 1091 1092 if (!NodesSeen.insert(SP)) 1093 return false; 1094 1095 SPs.push_back(SP); 1096 return true; 1097} 1098 1099bool DebugInfoFinder::addScope(DIScope Scope) { 1100 if (!Scope) 1101 return false; 1102 // FIXME: Ocaml binding generates a scope with no content, we treat it 1103 // as null for now. 1104 if (Scope->getNumOperands() == 0) 1105 return false; 1106 if (!NodesSeen.insert(Scope)) 1107 return false; 1108 Scopes.push_back(Scope); 1109 return true; 1110} 1111 1112//===----------------------------------------------------------------------===// 1113// DIDescriptor: dump routines for all descriptors. 1114//===----------------------------------------------------------------------===// 1115 1116/// dump - Print descriptor to dbgs() with a newline. 1117void DIDescriptor::dump() const { 1118 print(dbgs()); dbgs() << '\n'; 1119} 1120 1121/// print - Print descriptor. 1122void DIDescriptor::print(raw_ostream &OS) const { 1123 if (!DbgNode) return; 1124 1125 if (const char *Tag = dwarf::TagString(getTag())) 1126 OS << "[ " << Tag << " ]"; 1127 1128 if (this->isSubrange()) { 1129 DISubrange(DbgNode).printInternal(OS); 1130 } else if (this->isCompileUnit()) { 1131 DICompileUnit(DbgNode).printInternal(OS); 1132 } else if (this->isFile()) { 1133 DIFile(DbgNode).printInternal(OS); 1134 } else if (this->isEnumerator()) { 1135 DIEnumerator(DbgNode).printInternal(OS); 1136 } else if (this->isBasicType()) { 1137 DIType(DbgNode).printInternal(OS); 1138 } else if (this->isDerivedType()) { 1139 DIDerivedType(DbgNode).printInternal(OS); 1140 } else if (this->isCompositeType()) { 1141 DICompositeType(DbgNode).printInternal(OS); 1142 } else if (this->isSubprogram()) { 1143 DISubprogram(DbgNode).printInternal(OS); 1144 } else if (this->isGlobalVariable()) { 1145 DIGlobalVariable(DbgNode).printInternal(OS); 1146 } else if (this->isVariable()) { 1147 DIVariable(DbgNode).printInternal(OS); 1148 } else if (this->isObjCProperty()) { 1149 DIObjCProperty(DbgNode).printInternal(OS); 1150 } else if (this->isNameSpace()) { 1151 DINameSpace(DbgNode).printInternal(OS); 1152 } else if (this->isScope()) { 1153 DIScope(DbgNode).printInternal(OS); 1154 } 1155} 1156 1157void DISubrange::printInternal(raw_ostream &OS) const { 1158 int64_t Count = getCount(); 1159 if (Count != -1) 1160 OS << " [" << getLo() << ", " << Count - 1 << ']'; 1161 else 1162 OS << " [unbounded]"; 1163} 1164 1165void DIScope::printInternal(raw_ostream &OS) const { 1166 OS << " [" << getDirectory() << "/" << getFilename() << ']'; 1167} 1168 1169void DICompileUnit::printInternal(raw_ostream &OS) const { 1170 DIScope::printInternal(OS); 1171 OS << " ["; 1172 unsigned Lang = getLanguage(); 1173 if (const char *LangStr = dwarf::LanguageString(Lang)) 1174 OS << LangStr; 1175 else 1176 (OS << "lang 0x").write_hex(Lang); 1177 OS << ']'; 1178} 1179 1180void DIEnumerator::printInternal(raw_ostream &OS) const { 1181 OS << " [" << getName() << " :: " << getEnumValue() << ']'; 1182} 1183 1184void DIType::printInternal(raw_ostream &OS) const { 1185 if (!DbgNode) return; 1186 1187 StringRef Res = getName(); 1188 if (!Res.empty()) 1189 OS << " [" << Res << "]"; 1190 1191 // TODO: Print context? 1192 1193 OS << " [line " << getLineNumber() 1194 << ", size " << getSizeInBits() 1195 << ", align " << getAlignInBits() 1196 << ", offset " << getOffsetInBits(); 1197 if (isBasicType()) 1198 if (const char *Enc = 1199 dwarf::AttributeEncodingString(DIBasicType(DbgNode).getEncoding())) 1200 OS << ", enc " << Enc; 1201 OS << "]"; 1202 1203 if (isPrivate()) 1204 OS << " [private]"; 1205 else if (isProtected()) 1206 OS << " [protected]"; 1207 1208 if (isArtificial()) 1209 OS << " [artificial]"; 1210 1211 if (isForwardDecl()) 1212 OS << " [decl]"; 1213 else if (getTag() == dwarf::DW_TAG_structure_type || 1214 getTag() == dwarf::DW_TAG_union_type || 1215 getTag() == dwarf::DW_TAG_enumeration_type || 1216 getTag() == dwarf::DW_TAG_class_type) 1217 OS << " [def]"; 1218 if (isVector()) 1219 OS << " [vector]"; 1220 if (isStaticMember()) 1221 OS << " [static]"; 1222} 1223 1224void DIDerivedType::printInternal(raw_ostream &OS) const { 1225 DIType::printInternal(OS); 1226 OS << " [from " << getTypeDerivedFrom().getName() << ']'; 1227} 1228 1229void DICompositeType::printInternal(raw_ostream &OS) const { 1230 DIType::printInternal(OS); 1231 DIArray A = getTypeArray(); 1232 OS << " [" << A.getNumElements() << " elements]"; 1233} 1234 1235void DINameSpace::printInternal(raw_ostream &OS) const { 1236 StringRef Name = getName(); 1237 if (!Name.empty()) 1238 OS << " [" << Name << ']'; 1239 1240 OS << " [line " << getLineNumber() << ']'; 1241} 1242 1243void DISubprogram::printInternal(raw_ostream &OS) const { 1244 // TODO : Print context 1245 OS << " [line " << getLineNumber() << ']'; 1246 1247 if (isLocalToUnit()) 1248 OS << " [local]"; 1249 1250 if (isDefinition()) 1251 OS << " [def]"; 1252 1253 if (getScopeLineNumber() != getLineNumber()) 1254 OS << " [scope " << getScopeLineNumber() << "]"; 1255 1256 if (isPrivate()) 1257 OS << " [private]"; 1258 else if (isProtected()) 1259 OS << " [protected]"; 1260 1261 StringRef Res = getName(); 1262 if (!Res.empty()) 1263 OS << " [" << Res << ']'; 1264} 1265 1266void DIGlobalVariable::printInternal(raw_ostream &OS) const { 1267 StringRef Res = getName(); 1268 if (!Res.empty()) 1269 OS << " [" << Res << ']'; 1270 1271 OS << " [line " << getLineNumber() << ']'; 1272 1273 // TODO : Print context 1274 1275 if (isLocalToUnit()) 1276 OS << " [local]"; 1277 1278 if (isDefinition()) 1279 OS << " [def]"; 1280} 1281 1282void DIVariable::printInternal(raw_ostream &OS) const { 1283 StringRef Res = getName(); 1284 if (!Res.empty()) 1285 OS << " [" << Res << ']'; 1286 1287 OS << " [line " << getLineNumber() << ']'; 1288} 1289 1290void DIObjCProperty::printInternal(raw_ostream &OS) const { 1291 StringRef Name = getObjCPropertyName(); 1292 if (!Name.empty()) 1293 OS << " [" << Name << ']'; 1294 1295 OS << " [line " << getLineNumber() 1296 << ", properties " << getUnsignedField(6) << ']'; 1297} 1298 1299static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS, 1300 const LLVMContext &Ctx) { 1301 if (!DL.isUnknown()) { // Print source line info. 1302 DIScope Scope(DL.getScope(Ctx)); 1303 assert(Scope.isScope() && 1304 "Scope of a DebugLoc should be a DIScope."); 1305 // Omit the directory, because it's likely to be long and uninteresting. 1306 CommentOS << Scope.getFilename(); 1307 CommentOS << ':' << DL.getLine(); 1308 if (DL.getCol() != 0) 1309 CommentOS << ':' << DL.getCol(); 1310 DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(DL.getInlinedAt(Ctx)); 1311 if (!InlinedAtDL.isUnknown()) { 1312 CommentOS << " @[ "; 1313 printDebugLoc(InlinedAtDL, CommentOS, Ctx); 1314 CommentOS << " ]"; 1315 } 1316 } 1317} 1318 1319void DIVariable::printExtendedName(raw_ostream &OS) const { 1320 const LLVMContext &Ctx = DbgNode->getContext(); 1321 StringRef Res = getName(); 1322 if (!Res.empty()) 1323 OS << Res << "," << getLineNumber(); 1324 if (MDNode *InlinedAt = getInlinedAt()) { 1325 DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(InlinedAt); 1326 if (!InlinedAtDL.isUnknown()) { 1327 OS << " @["; 1328 printDebugLoc(InlinedAtDL, OS, Ctx); 1329 OS << "]"; 1330 } 1331 } 1332} 1333