CGDebugInfo.cpp (207632) | CGDebugInfo.cpp (208600) |
---|---|
1//===--- CGDebugInfo.cpp - Emit Debug Information for a Module ------------===// 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//===----------------------------------------------------------------------===// --- 50 unchanged lines hidden (view full) --- 59 llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator 60 I = RegionMap.find(Context); 61 if (I != RegionMap.end()) 62 return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(I->second)); 63 64 // Check namespace. 65 if (const NamespaceDecl *NSDecl = dyn_cast<NamespaceDecl>(Context)) 66 return llvm::DIDescriptor(getOrCreateNameSpace(NSDecl, CompileUnit)); | 1//===--- CGDebugInfo.cpp - Emit Debug Information for a Module ------------===// 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//===----------------------------------------------------------------------===// --- 50 unchanged lines hidden (view full) --- 59 llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator 60 I = RegionMap.find(Context); 61 if (I != RegionMap.end()) 62 return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(I->second)); 63 64 // Check namespace. 65 if (const NamespaceDecl *NSDecl = dyn_cast<NamespaceDecl>(Context)) 66 return llvm::DIDescriptor(getOrCreateNameSpace(NSDecl, CompileUnit)); |
67 | 67 68 if (const RecordDecl *RDecl = dyn_cast<RecordDecl>(Context)) { 69 if (!RDecl->isDependentType()) { 70 llvm::DIType Ty = getOrCreateType(CGM.getContext().getTypeDeclType(RDecl), 71 llvm::DIFile(CompileUnit)); 72 return llvm::DIDescriptor(Ty); 73 } 74 } |
68 return CompileUnit; 69} 70 71/// getFunctionName - Get function name for the given FunctionDecl. If the 72/// name is constructred on demand (e.g. C++ destructor) then the name 73/// is stored on the side. 74llvm::StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) { 75 assert (FD && "Invalid FunctionDecl!"); --- 33 unchanged lines hidden (view full) --- 109 // FIXME: We shouldn't even need to call 'makeAbsolute()' in the cases 110 // where we can consult the FileEntry. 111 llvm::sys::Path AbsFileName(PLoc.getFilename()); 112 AbsFileName.makeAbsolute(); 113 114 llvm::DIFile F = DebugFactory.CreateFile(AbsFileName.getLast(), 115 AbsFileName.getDirname(), TheCU); 116 | 75 return CompileUnit; 76} 77 78/// getFunctionName - Get function name for the given FunctionDecl. If the 79/// name is constructred on demand (e.g. C++ destructor) then the name 80/// is stored on the side. 81llvm::StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) { 82 assert (FD && "Invalid FunctionDecl!"); --- 33 unchanged lines hidden (view full) --- 116 // FIXME: We shouldn't even need to call 'makeAbsolute()' in the cases 117 // where we can consult the FileEntry. 118 llvm::sys::Path AbsFileName(PLoc.getFilename()); 119 AbsFileName.makeAbsolute(); 120 121 llvm::DIFile F = DebugFactory.CreateFile(AbsFileName.getLast(), 122 AbsFileName.getDirname(), TheCU); 123 |
117 DIFileCache[fname] = F.getNode(); | 124 DIFileCache[fname] = F; |
118 return F; 119 120} | 125 return F; 126 127} |
128 129/// getLineNumber - Get line number for the location. If location is invalid 130/// then use current location. 131unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) { 132 assert (CurLoc.isValid() && "Invalid current location!"); 133 SourceManager &SM = CGM.getContext().getSourceManager(); 134 PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc); 135 return PLoc.getLine(); 136} 137 138/// getColumnNumber - Get column number for the location. If location is 139/// invalid then use current location. 140unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc) { 141 assert (CurLoc.isValid() && "Invalid current location!"); 142 SourceManager &SM = CGM.getContext().getSourceManager(); 143 PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc); 144 return PLoc.getColumn(); 145} 146 |
|
121/// CreateCompileUnit - Create new compile unit. 122void CGDebugInfo::CreateCompileUnit() { 123 124 // Get absolute path name. 125 SourceManager &SM = CGM.getContext().getSourceManager(); 126 std::string MainFileName = CGM.getCodeGenOpts().MainFileName; 127 if (MainFileName.empty()) 128 MainFileName = "<unknown>"; --- 193 unchanged lines hidden (view full) --- 322 FType = CGM.getContext().UnsignedLongTy; 323 EltTys.push_back(CreateMemberType(Unit, FType, "reserved", &FieldOffset)); 324 EltTys.push_back(CreateMemberType(Unit, FType, "Size", &FieldOffset)); 325 326 Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); 327 EltTys.clear(); 328 329 unsigned Flags = llvm::DIType::FlagAppleBlock; | 147/// CreateCompileUnit - Create new compile unit. 148void CGDebugInfo::CreateCompileUnit() { 149 150 // Get absolute path name. 151 SourceManager &SM = CGM.getContext().getSourceManager(); 152 std::string MainFileName = CGM.getCodeGenOpts().MainFileName; 153 if (MainFileName.empty()) 154 MainFileName = "<unknown>"; --- 193 unchanged lines hidden (view full) --- 348 FType = CGM.getContext().UnsignedLongTy; 349 EltTys.push_back(CreateMemberType(Unit, FType, "reserved", &FieldOffset)); 350 EltTys.push_back(CreateMemberType(Unit, FType, "Size", &FieldOffset)); 351 352 Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); 353 EltTys.clear(); 354 355 unsigned Flags = llvm::DIType::FlagAppleBlock; |
356 unsigned LineNo = getLineNumber(CurLoc); |
|
330 331 EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_descriptor", | 357 358 EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_descriptor", |
332 Unit, 0, FieldOffset, 0, 0, Flags, 333 llvm::DIType(), Elements); | 359 Unit, LineNo, FieldOffset, 0, 0, 360 Flags, llvm::DIType(), Elements); |
334 335 // Bit size, align and offset of the type. 336 uint64_t Size = CGM.getContext().getTypeSize(Ty); 337 uint64_t Align = CGM.getContext().getTypeAlign(Ty); 338 339 DescTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, 340 Unit, "", Unit, | 361 362 // Bit size, align and offset of the type. 363 uint64_t Size = CGM.getContext().getTypeSize(Ty); 364 uint64_t Align = CGM.getContext().getTypeAlign(Ty); 365 366 DescTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, 367 Unit, "", Unit, |
341 0, Size, Align, 0, 0, EltTy); | 368 LineNo, Size, Align, 0, 0, EltTy); |
342 343 FieldOffset = 0; 344 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); 345 EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset)); 346 FType = CGM.getContext().IntTy; 347 EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset)); 348 EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset)); 349 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); 350 EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset)); 351 352 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); 353 FieldTy = DescTy; 354 FieldSize = CGM.getContext().getTypeSize(Ty); 355 FieldAlign = CGM.getContext().getTypeAlign(Ty); 356 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, 357 "__descriptor", Unit, | 369 370 FieldOffset = 0; 371 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); 372 EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset)); 373 FType = CGM.getContext().IntTy; 374 EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset)); 375 EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset)); 376 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); 377 EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset)); 378 379 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); 380 FieldTy = DescTy; 381 FieldSize = CGM.getContext().getTypeSize(Ty); 382 FieldAlign = CGM.getContext().getTypeAlign(Ty); 383 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, 384 "__descriptor", Unit, |
358 0, FieldSize, FieldAlign, | 385 LineNo, FieldSize, FieldAlign, |
359 FieldOffset, 0, FieldTy); 360 EltTys.push_back(FieldTy); 361 362 FieldOffset += FieldSize; 363 Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); 364 365 EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_literal_generic", | 386 FieldOffset, 0, FieldTy); 387 EltTys.push_back(FieldTy); 388 389 FieldOffset += FieldSize; 390 Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); 391 392 EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_literal_generic", |
366 Unit, 0, FieldOffset, 0, 0, Flags, 367 llvm::DIType(), Elements); | 393 Unit, LineNo, FieldOffset, 0, 0, 394 Flags, llvm::DIType(), Elements); |
368 369 BlockLiteralGenericSet = true; 370 BlockLiteralGeneric 371 = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit, 372 "", Unit, | 395 396 BlockLiteralGenericSet = true; 397 BlockLiteralGeneric 398 = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit, 399 "", Unit, |
373 0, Size, Align, 0, 0, EltTy); | 400 LineNo, Size, Align, 0, 0, EltTy); |
374 return BlockLiteralGeneric; 375} 376 377llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty, 378 llvm::DIFile Unit) { 379 // Typedefs are derived from some other type. If we have a typedef of a 380 // typedef, make sure to emit the whole chain. 381 llvm::DIType Src = getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit); 382 383 // We don't set size information, but do specify where the typedef was 384 // declared. | 401 return BlockLiteralGeneric; 402} 403 404llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty, 405 llvm::DIFile Unit) { 406 // Typedefs are derived from some other type. If we have a typedef of a 407 // typedef, make sure to emit the whole chain. 408 llvm::DIType Src = getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit); 409 410 // We don't set size information, but do specify where the typedef was 411 // declared. |
385 SourceManager &SM = CGM.getContext().getSourceManager(); 386 PresumedLoc PLoc = SM.getPresumedLoc(Ty->getDecl()->getLocation()); 387 unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); | 412 unsigned Line = getLineNumber(Ty->getDecl()->getLocation()); |
388 389 llvm::DIDescriptor TyContext 390 = getContextDescriptor(dyn_cast<Decl>(Ty->getDecl()->getDeclContext()), 391 Unit); 392 llvm::DIType DbgTy = 393 DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_typedef, 394 TyContext, 395 Ty->getDecl()->getName(), Unit, --- 29 unchanged lines hidden (view full) --- 425} 426 427/// CollectRecordFields - A helper function to collect debug info for 428/// record fields. This is used while creating debug info entry for a Record. 429void CGDebugInfo:: 430CollectRecordFields(const RecordDecl *RD, llvm::DIFile Unit, 431 llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys) { 432 unsigned FieldNo = 0; | 413 414 llvm::DIDescriptor TyContext 415 = getContextDescriptor(dyn_cast<Decl>(Ty->getDecl()->getDeclContext()), 416 Unit); 417 llvm::DIType DbgTy = 418 DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_typedef, 419 TyContext, 420 Ty->getDecl()->getName(), Unit, --- 29 unchanged lines hidden (view full) --- 450} 451 452/// CollectRecordFields - A helper function to collect debug info for 453/// record fields. This is used while creating debug info entry for a Record. 454void CGDebugInfo:: 455CollectRecordFields(const RecordDecl *RD, llvm::DIFile Unit, 456 llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys) { 457 unsigned FieldNo = 0; |
433 SourceManager &SM = CGM.getContext().getSourceManager(); | |
434 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); 435 for (RecordDecl::field_iterator I = RD->field_begin(), 436 E = RD->field_end(); 437 I != E; ++I, ++FieldNo) { 438 FieldDecl *Field = *I; 439 llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit); 440 441 llvm::StringRef FieldName = Field->getName(); 442 443 // Ignore unnamed fields. Do not ignore unnamed records. 444 if (FieldName.empty() && !isa<RecordType>(Field->getType())) 445 continue; 446 447 // Get the location for the field. | 458 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); 459 for (RecordDecl::field_iterator I = RD->field_begin(), 460 E = RD->field_end(); 461 I != E; ++I, ++FieldNo) { 462 FieldDecl *Field = *I; 463 llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit); 464 465 llvm::StringRef FieldName = Field->getName(); 466 467 // Ignore unnamed fields. Do not ignore unnamed records. 468 if (FieldName.empty() && !isa<RecordType>(Field->getType())) 469 continue; 470 471 // Get the location for the field. |
448 SourceLocation FieldDefLoc = Field->getLocation(); 449 PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc); 450 llvm::DIFile FieldDefUnit; 451 unsigned FieldLine = 0; 452 453 if (!PLoc.isInvalid()) { 454 FieldDefUnit = getOrCreateFile(FieldDefLoc); 455 FieldLine = PLoc.getLine(); 456 } 457 | 472 llvm::DIFile FieldDefUnit = getOrCreateFile(Field->getLocation()); 473 unsigned FieldLine = getLineNumber(Field->getLocation()); |
458 QualType FType = Field->getType(); 459 uint64_t FieldSize = 0; 460 unsigned FieldAlign = 0; 461 if (!FType->isIncompleteArrayType()) { 462 463 // Bit size, align and offset of the type. 464 FieldSize = CGM.getContext().getTypeSize(FType); 465 Expr *BitWidth = Field->getBitWidth(); --- 35 unchanged lines hidden (view full) --- 501 Unit); 502 503 // Static methods do not need "this" pointer argument. 504 if (Method->isStatic()) 505 return FnTy; 506 507 // Add "this" pointer. 508 | 474 QualType FType = Field->getType(); 475 uint64_t FieldSize = 0; 476 unsigned FieldAlign = 0; 477 if (!FType->isIncompleteArrayType()) { 478 479 // Bit size, align and offset of the type. 480 FieldSize = CGM.getContext().getTypeSize(FType); 481 Expr *BitWidth = Field->getBitWidth(); --- 35 unchanged lines hidden (view full) --- 517 Unit); 518 519 // Static methods do not need "this" pointer argument. 520 if (Method->isStatic()) 521 return FnTy; 522 523 // Add "this" pointer. 524 |
509 llvm::DIArray Args = llvm::DICompositeType(FnTy.getNode()).getTypeArray(); | 525 llvm::DIArray Args = llvm::DICompositeType(FnTy).getTypeArray(); |
510 assert (Args.getNumElements() && "Invalid number of arguments!"); 511 512 llvm::SmallVector<llvm::DIDescriptor, 16> Elts; 513 514 // First element is always return type. For 'void' functions it is NULL. 515 Elts.push_back(Args.getElement(0)); 516 517 // "this" pointer is always first argument. 518 ASTContext &Context = CGM.getContext(); 519 QualType ThisPtr = 520 Context.getPointerType(Context.getTagDeclType(Method->getParent())); 521 llvm::DIType ThisPtrType = 522 DebugFactory.CreateArtificialType(getOrCreateType(ThisPtr, Unit)); | 526 assert (Args.getNumElements() && "Invalid number of arguments!"); 527 528 llvm::SmallVector<llvm::DIDescriptor, 16> Elts; 529 530 // First element is always return type. For 'void' functions it is NULL. 531 Elts.push_back(Args.getElement(0)); 532 533 // "this" pointer is always first argument. 534 ASTContext &Context = CGM.getContext(); 535 QualType ThisPtr = 536 Context.getPointerType(Context.getTagDeclType(Method->getParent())); 537 llvm::DIType ThisPtrType = 538 DebugFactory.CreateArtificialType(getOrCreateType(ThisPtr, Unit)); |
523 TypeCache[ThisPtr.getAsOpaquePtr()] = ThisPtrType.getNode(); | 539 TypeCache[ThisPtr.getAsOpaquePtr()] = ThisPtrType; |
524 Elts.push_back(ThisPtrType); 525 526 // Copy rest of the arguments. 527 for (unsigned i = 1, e = Args.getNumElements(); i != e; ++i) 528 Elts.push_back(Args.getElement(i)); 529 530 llvm::DIArray EltTypeArray = 531 DebugFactory.GetOrCreateArray(Elts.data(), Elts.size()); --- 18 unchanged lines hidden (view full) --- 550 llvm::DIType MethodTy = getOrCreateMethodType(Method, Unit); 551 552 // Since a single ctor/dtor corresponds to multiple functions, it doesn't 553 // make sense to give a single ctor/dtor a linkage name. 554 MangleBuffer MethodLinkageName; 555 if (!IsCtorOrDtor) 556 CGM.getMangledName(MethodLinkageName, Method); 557 | 540 Elts.push_back(ThisPtrType); 541 542 // Copy rest of the arguments. 543 for (unsigned i = 1, e = Args.getNumElements(); i != e; ++i) 544 Elts.push_back(Args.getElement(i)); 545 546 llvm::DIArray EltTypeArray = 547 DebugFactory.GetOrCreateArray(Elts.data(), Elts.size()); --- 18 unchanged lines hidden (view full) --- 566 llvm::DIType MethodTy = getOrCreateMethodType(Method, Unit); 567 568 // Since a single ctor/dtor corresponds to multiple functions, it doesn't 569 // make sense to give a single ctor/dtor a linkage name. 570 MangleBuffer MethodLinkageName; 571 if (!IsCtorOrDtor) 572 CGM.getMangledName(MethodLinkageName, Method); 573 |
558 SourceManager &SM = CGM.getContext().getSourceManager(); 559 | |
560 // Get the location for the method. | 574 // Get the location for the method. |
561 SourceLocation MethodDefLoc = Method->getLocation(); 562 PresumedLoc PLoc = SM.getPresumedLoc(MethodDefLoc); 563 llvm::DIFile MethodDefUnit; 564 unsigned MethodLine = 0; | 575 llvm::DIFile MethodDefUnit = getOrCreateFile(Method->getLocation()); 576 unsigned MethodLine = getLineNumber(Method->getLocation()); |
565 | 577 |
566 if (!PLoc.isInvalid()) { 567 MethodDefUnit = getOrCreateFile(MethodDefLoc); 568 MethodLine = PLoc.getLine(); 569 } 570 | |
571 // Collect virtual method info. 572 llvm::DIType ContainingType; 573 unsigned Virtuality = 0; 574 unsigned VIndex = 0; 575 576 if (Method->isVirtual()) { 577 if (Method->isPure()) 578 Virtuality = llvm::dwarf::DW_VIRTUALITY_pure_virtual; --- 13 unchanged lines hidden (view full) --- 592 MethodDefUnit, MethodLine, 593 MethodTy, /*isLocalToUnit=*/false, 594 Method->isThisDeclarationADefinition(), 595 Virtuality, VIndex, ContainingType); 596 597 // Don't cache ctors or dtors since we have to emit multiple functions for 598 // a single ctor or dtor. 599 if (!IsCtorOrDtor && Method->isThisDeclarationADefinition()) | 578 // Collect virtual method info. 579 llvm::DIType ContainingType; 580 unsigned Virtuality = 0; 581 unsigned VIndex = 0; 582 583 if (Method->isVirtual()) { 584 if (Method->isPure()) 585 Virtuality = llvm::dwarf::DW_VIRTUALITY_pure_virtual; --- 13 unchanged lines hidden (view full) --- 599 MethodDefUnit, MethodLine, 600 MethodTy, /*isLocalToUnit=*/false, 601 Method->isThisDeclarationADefinition(), 602 Virtuality, VIndex, ContainingType); 603 604 // Don't cache ctors or dtors since we have to emit multiple functions for 605 // a single ctor or dtor. 606 if (!IsCtorOrDtor && Method->isThisDeclarationADefinition()) |
600 SPCache[Method] = llvm::WeakVH(SP.getNode()); | 607 SPCache[Method] = llvm::WeakVH(SP); |
601 602 return SP; 603} 604 605/// CollectCXXMemberFunctions - A helper function to collect debug info for 606/// C++ member functions.This is used while creating debug info entry for 607/// a Record. 608void CGDebugInfo:: --- 127 unchanged lines hidden (view full) --- 736 Tag = llvm::dwarf::DW_TAG_structure_type; 737 else if (RD->isUnion()) 738 Tag = llvm::dwarf::DW_TAG_union_type; 739 else { 740 assert(RD->isClass() && "Unknown RecordType!"); 741 Tag = llvm::dwarf::DW_TAG_class_type; 742 } 743 | 608 609 return SP; 610} 611 612/// CollectCXXMemberFunctions - A helper function to collect debug info for 613/// C++ member functions.This is used while creating debug info entry for 614/// a Record. 615void CGDebugInfo:: --- 127 unchanged lines hidden (view full) --- 743 Tag = llvm::dwarf::DW_TAG_structure_type; 744 else if (RD->isUnion()) 745 Tag = llvm::dwarf::DW_TAG_union_type; 746 else { 747 assert(RD->isClass() && "Unknown RecordType!"); 748 Tag = llvm::dwarf::DW_TAG_class_type; 749 } 750 |
744 SourceManager &SM = CGM.getContext().getSourceManager(); 745 | |
746 // Get overall information about the record type for the debug info. | 751 // Get overall information about the record type for the debug info. |
747 PresumedLoc PLoc = SM.getPresumedLoc(RD->getLocation()); 748 llvm::DIFile DefUnit; 749 unsigned Line = 0; 750 if (!PLoc.isInvalid()) { 751 DefUnit = getOrCreateFile(RD->getLocation()); 752 Line = PLoc.getLine(); 753 } | 752 llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation()); 753 unsigned Line = getLineNumber(RD->getLocation()); |
754 755 // Records and classes and unions can all be recursive. To handle them, we 756 // first generate a debug descriptor for the struct as a forward declaration. 757 // Then (if it is a definition) we go through and get debug info for all of 758 // its members. Finally, we create a descriptor for the complete type (which 759 // may refer to the forward decl if the struct is recursive) and replace all 760 // uses of the forward declaration with the final definition. 761 --- 7 unchanged lines hidden (view full) --- 769 DebugFactory.CreateCompositeType(Tag, FDContext, FwdDeclName, 770 DefUnit, Line, 0, 0, 0, 0, 771 llvm::DIType(), llvm::DIArray()); 772 773 // If this is just a forward declaration, return it. 774 if (!RD->getDefinition()) 775 return FwdDecl; 776 | 754 755 // Records and classes and unions can all be recursive. To handle them, we 756 // first generate a debug descriptor for the struct as a forward declaration. 757 // Then (if it is a definition) we go through and get debug info for all of 758 // its members. Finally, we create a descriptor for the complete type (which 759 // may refer to the forward decl if the struct is recursive) and replace all 760 // uses of the forward declaration with the final definition. 761 --- 7 unchanged lines hidden (view full) --- 769 DebugFactory.CreateCompositeType(Tag, FDContext, FwdDeclName, 770 DefUnit, Line, 0, 0, 0, 0, 771 llvm::DIType(), llvm::DIArray()); 772 773 // If this is just a forward declaration, return it. 774 if (!RD->getDefinition()) 775 return FwdDecl; 776 |
777 llvm::TrackingVH<llvm::MDNode> FwdDeclNode = FwdDecl.getNode(); | 777 llvm::MDNode *MN = FwdDecl; 778 llvm::TrackingVH<llvm::MDNode> FwdDeclNode = MN; |
778 // Otherwise, insert it into the TypeCache so that recursive uses will find 779 // it. | 779 // Otherwise, insert it into the TypeCache so that recursive uses will find 780 // it. |
780 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl.getNode(); | 781 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl; |
781 // Push the struct on region stack. | 782 // Push the struct on region stack. |
782 RegionStack.push_back(FwdDecl.getNode()); 783 RegionMap[Ty->getDecl()] = llvm::WeakVH(FwdDecl.getNode()); | 783 RegionStack.push_back(FwdDeclNode); 784 RegionMap[Ty->getDecl()] = llvm::WeakVH(FwdDecl); |
784 785 // Convert all the elements. 786 llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; 787 788 const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(RD); 789 if (CXXDecl) { 790 CollectCXXBases(CXXDecl, Unit, EltTys, FwdDecl); 791 CollectVTableInfo(CXXDecl, Unit, EltTys); 792 } 793 CollectRecordFields(RD, Unit, EltTys); 794 llvm::MDNode *ContainingType = NULL; 795 if (CXXDecl) { 796 CollectCXXMemberFunctions(CXXDecl, Unit, EltTys, FwdDecl); 797 798 // A class's primary base or the class itself contains the vtable. 799 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); 800 if (const CXXRecordDecl *PBase = RL.getPrimaryBase()) 801 ContainingType = | 785 786 // Convert all the elements. 787 llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; 788 789 const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(RD); 790 if (CXXDecl) { 791 CollectCXXBases(CXXDecl, Unit, EltTys, FwdDecl); 792 CollectVTableInfo(CXXDecl, Unit, EltTys); 793 } 794 CollectRecordFields(RD, Unit, EltTys); 795 llvm::MDNode *ContainingType = NULL; 796 if (CXXDecl) { 797 CollectCXXMemberFunctions(CXXDecl, Unit, EltTys, FwdDecl); 798 799 // A class's primary base or the class itself contains the vtable. 800 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); 801 if (const CXXRecordDecl *PBase = RL.getPrimaryBase()) 802 ContainingType = |
802 getOrCreateType(QualType(PBase->getTypeForDecl(), 0), Unit).getNode(); | 803 getOrCreateType(QualType(PBase->getTypeForDecl(), 0), Unit); |
803 else if (CXXDecl->isDynamicClass()) | 804 else if (CXXDecl->isDynamicClass()) |
804 ContainingType = FwdDecl.getNode(); | 805 ContainingType = FwdDecl; |
805 } 806 807 llvm::DIArray Elements = 808 DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); 809 810 // Bit size, align and offset of the type. 811 uint64_t Size = CGM.getContext().getTypeSize(Ty); 812 uint64_t Align = CGM.getContext().getTypeAlign(Ty); --- 11 unchanged lines hidden (view full) --- 824 RD->getName(), 825 DefUnit, Line, Size, Align, 0, 0, 826 llvm::DIType(), Elements, 827 0, ContainingType); 828 829 // Now that we have a real decl for the struct, replace anything using the 830 // old decl with the new one. This will recursively update the debug info. 831 llvm::DIDerivedType(FwdDeclNode).replaceAllUsesWith(RealDecl); | 806 } 807 808 llvm::DIArray Elements = 809 DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); 810 811 // Bit size, align and offset of the type. 812 uint64_t Size = CGM.getContext().getTypeSize(Ty); 813 uint64_t Align = CGM.getContext().getTypeAlign(Ty); --- 11 unchanged lines hidden (view full) --- 825 RD->getName(), 826 DefUnit, Line, Size, Align, 0, 0, 827 llvm::DIType(), Elements, 828 0, ContainingType); 829 830 // Now that we have a real decl for the struct, replace anything using the 831 // old decl with the new one. This will recursively update the debug info. 832 llvm::DIDerivedType(FwdDeclNode).replaceAllUsesWith(RealDecl); |
832 RegionMap[RD] = llvm::WeakVH(RealDecl.getNode()); | 833 RegionMap[RD] = llvm::WeakVH(RealDecl); |
833 return RealDecl; 834} 835 | 834 return RealDecl; 835} 836 |
837/// CreateType - get objective-c object type. 838llvm::DIType CGDebugInfo::CreateType(const ObjCObjectType *Ty, 839 llvm::DIFile Unit) { 840 // Ignore protocols. 841 return getOrCreateType(Ty->getBaseType(), Unit); 842} 843 |
|
836/// CreateType - get objective-c interface type. 837llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, 838 llvm::DIFile Unit) { 839 ObjCInterfaceDecl *ID = Ty->getDecl(); | 844/// CreateType - get objective-c interface type. 845llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, 846 llvm::DIFile Unit) { 847 ObjCInterfaceDecl *ID = Ty->getDecl(); |
840 | |
841 unsigned Tag = llvm::dwarf::DW_TAG_structure_type; | 848 unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
842 SourceManager &SM = CGM.getContext().getSourceManager(); | |
843 844 // Get overall information about the record type for the debug info. 845 llvm::DIFile DefUnit = getOrCreateFile(ID->getLocation()); | 849 850 // Get overall information about the record type for the debug info. 851 llvm::DIFile DefUnit = getOrCreateFile(ID->getLocation()); |
846 PresumedLoc PLoc = SM.getPresumedLoc(ID->getLocation()); 847 unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); 848 849 | 852 unsigned Line = getLineNumber(ID->getLocation()); |
850 unsigned RuntimeLang = TheCU.getLanguage(); 851 852 // To handle recursive interface, we 853 // first generate a debug descriptor for the struct as a forward declaration. 854 // Then (if it is a definition) we go through and get debug info for all of 855 // its members. Finally, we create a descriptor for the complete type (which 856 // may refer to the forward decl if the struct is recursive) and replace all 857 // uses of the forward declaration with the final definition. 858 llvm::DICompositeType FwdDecl = 859 DebugFactory.CreateCompositeType(Tag, Unit, ID->getName(), 860 DefUnit, Line, 0, 0, 0, 0, 861 llvm::DIType(), llvm::DIArray(), 862 RuntimeLang); 863 864 // If this is just a forward declaration, return it. 865 if (ID->isForwardDecl()) 866 return FwdDecl; 867 | 853 unsigned RuntimeLang = TheCU.getLanguage(); 854 855 // To handle recursive interface, we 856 // first generate a debug descriptor for the struct as a forward declaration. 857 // Then (if it is a definition) we go through and get debug info for all of 858 // its members. Finally, we create a descriptor for the complete type (which 859 // may refer to the forward decl if the struct is recursive) and replace all 860 // uses of the forward declaration with the final definition. 861 llvm::DICompositeType FwdDecl = 862 DebugFactory.CreateCompositeType(Tag, Unit, ID->getName(), 863 DefUnit, Line, 0, 0, 0, 0, 864 llvm::DIType(), llvm::DIArray(), 865 RuntimeLang); 866 867 // If this is just a forward declaration, return it. 868 if (ID->isForwardDecl()) 869 return FwdDecl; 870 |
868 llvm::TrackingVH<llvm::MDNode> FwdDeclNode = FwdDecl.getNode(); | 871 llvm::MDNode *MN = FwdDecl; 872 llvm::TrackingVH<llvm::MDNode> FwdDeclNode = MN; |
869 // Otherwise, insert it into the TypeCache so that recursive uses will find 870 // it. | 873 // Otherwise, insert it into the TypeCache so that recursive uses will find 874 // it. |
871 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl.getNode(); | 875 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl; |
872 // Push the struct on region stack. | 876 // Push the struct on region stack. |
873 RegionStack.push_back(FwdDecl.getNode()); 874 RegionMap[Ty->getDecl()] = llvm::WeakVH(FwdDecl.getNode()); | 877 RegionStack.push_back(FwdDeclNode); 878 RegionMap[Ty->getDecl()] = llvm::WeakVH(FwdDecl); |
875 876 // Convert all the elements. 877 llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; 878 879 ObjCInterfaceDecl *SClass = ID->getSuperClass(); 880 if (SClass) { 881 llvm::DIType SClassTy = 882 getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit); --- 14 unchanged lines hidden (view full) --- 897 898 llvm::StringRef FieldName = Field->getName(); 899 900 // Ignore unnamed fields. 901 if (FieldName.empty()) 902 continue; 903 904 // Get the location for the field. | 879 880 // Convert all the elements. 881 llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; 882 883 ObjCInterfaceDecl *SClass = ID->getSuperClass(); 884 if (SClass) { 885 llvm::DIType SClassTy = 886 getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit); --- 14 unchanged lines hidden (view full) --- 901 902 llvm::StringRef FieldName = Field->getName(); 903 904 // Ignore unnamed fields. 905 if (FieldName.empty()) 906 continue; 907 908 // Get the location for the field. |
905 SourceLocation FieldDefLoc = Field->getLocation(); 906 llvm::DIFile FieldDefUnit = getOrCreateFile(FieldDefLoc); 907 PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc); 908 unsigned FieldLine = PLoc.isInvalid() ? 0 : PLoc.getLine(); 909 910 | 909 llvm::DIFile FieldDefUnit = getOrCreateFile(Field->getLocation()); 910 unsigned FieldLine = getLineNumber(Field->getLocation()); |
911 QualType FType = Field->getType(); 912 uint64_t FieldSize = 0; 913 unsigned FieldAlign = 0; 914 915 if (!FType->isIncompleteArrayType()) { 916 917 // Bit size, align and offset of the type. 918 FieldSize = CGM.getContext().getTypeSize(FType); --- 38 unchanged lines hidden (view full) --- 957 llvm::DICompositeType RealDecl = 958 DebugFactory.CreateCompositeType(Tag, Unit, ID->getName(), DefUnit, 959 Line, Size, Align, 0, 0, llvm::DIType(), 960 Elements, RuntimeLang); 961 962 // Now that we have a real decl for the struct, replace anything using the 963 // old decl with the new one. This will recursively update the debug info. 964 llvm::DIDerivedType(FwdDeclNode).replaceAllUsesWith(RealDecl); | 911 QualType FType = Field->getType(); 912 uint64_t FieldSize = 0; 913 unsigned FieldAlign = 0; 914 915 if (!FType->isIncompleteArrayType()) { 916 917 // Bit size, align and offset of the type. 918 FieldSize = CGM.getContext().getTypeSize(FType); --- 38 unchanged lines hidden (view full) --- 957 llvm::DICompositeType RealDecl = 958 DebugFactory.CreateCompositeType(Tag, Unit, ID->getName(), DefUnit, 959 Line, Size, Align, 0, 0, llvm::DIType(), 960 Elements, RuntimeLang); 961 962 // Now that we have a real decl for the struct, replace anything using the 963 // old decl with the new one. This will recursively update the debug info. 964 llvm::DIDerivedType(FwdDeclNode).replaceAllUsesWith(RealDecl); |
965 RegionMap[ID] = llvm::WeakVH(RealDecl.getNode()); | 965 RegionMap[ID] = llvm::WeakVH(RealDecl); |
966 967 return RealDecl; 968} 969 970llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty, 971 llvm::DIFile Unit) { 972 EnumDecl *ED = Ty->getDecl(); 973 --- 6 unchanged lines hidden (view full) --- 980 Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getName(), 981 Enum->getInitVal().getZExtValue())); 982 } 983 984 // Return a CompositeType for the enum itself. 985 llvm::DIArray EltArray = 986 DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size()); 987 | 966 967 return RealDecl; 968} 969 970llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty, 971 llvm::DIFile Unit) { 972 EnumDecl *ED = Ty->getDecl(); 973 --- 6 unchanged lines hidden (view full) --- 980 Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getName(), 981 Enum->getInitVal().getZExtValue())); 982 } 983 984 // Return a CompositeType for the enum itself. 985 llvm::DIArray EltArray = 986 DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size()); 987 |
988 SourceLocation DefLoc = ED->getLocation(); 989 llvm::DIFile DefUnit = getOrCreateFile(DefLoc); 990 SourceManager &SM = CGM.getContext().getSourceManager(); 991 PresumedLoc PLoc = SM.getPresumedLoc(DefLoc); 992 unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); | 988 llvm::DIFile DefUnit = getOrCreateFile(ED->getLocation()); 989 unsigned Line = getLineNumber(ED->getLocation()); |
993 | 990 |
994 | |
995 // Size and align of the type. 996 uint64_t Size = 0; 997 unsigned Align = 0; 998 if (!Ty->isIncompleteType()) { 999 Size = CGM.getContext().getTypeSize(Ty); 1000 Align = CGM.getContext().getTypeAlign(Ty); 1001 } 1002 --- 144 unchanged lines hidden (view full) --- 1147 break; 1148 } 1149 case Type::TypeOf: 1150 T = cast<TypeOfType>(T)->getUnderlyingType(); 1151 break; 1152 case Type::Decltype: 1153 T = cast<DecltypeType>(T)->getUnderlyingType(); 1154 break; | 991 // Size and align of the type. 992 uint64_t Size = 0; 993 unsigned Align = 0; 994 if (!Ty->isIncompleteType()) { 995 Size = CGM.getContext().getTypeSize(Ty); 996 Align = CGM.getContext().getTypeAlign(Ty); 997 } 998 --- 144 unchanged lines hidden (view full) --- 1143 break; 1144 } 1145 case Type::TypeOf: 1146 T = cast<TypeOfType>(T)->getUnderlyingType(); 1147 break; 1148 case Type::Decltype: 1149 T = cast<DecltypeType>(T)->getUnderlyingType(); 1150 break; |
1155 case Type::QualifiedName: 1156 T = cast<QualifiedNameType>(T)->getNamedType(); | 1151 case Type::Elaborated: 1152 T = cast<ElaboratedType>(T)->getNamedType(); |
1157 break; 1158 case Type::SubstTemplateTypeParm: 1159 T = cast<SubstTemplateTypeParmType>(T)->getReplacementType(); 1160 break; | 1153 break; 1154 case Type::SubstTemplateTypeParm: 1155 T = cast<SubstTemplateTypeParmType>(T)->getReplacementType(); 1156 break; |
1161 case Type::Elaborated: 1162 T = cast<ElaboratedType>(T)->getUnderlyingType(); 1163 break; | |
1164 } 1165 1166 assert(T != LastT && "Type unwrapping failed to unwrap!"); 1167 if (T == LastT) 1168 return T; 1169 } while (true); 1170 1171 return T; --- 17 unchanged lines hidden (view full) --- 1189 if (&*it->second) 1190 return llvm::DIType(cast<llvm::MDNode>(it->second)); 1191 } 1192 1193 // Otherwise create the type. 1194 llvm::DIType Res = CreateTypeNode(Ty, Unit); 1195 1196 // And update the type cache. | 1157 } 1158 1159 assert(T != LastT && "Type unwrapping failed to unwrap!"); 1160 if (T == LastT) 1161 return T; 1162 } while (true); 1163 1164 return T; --- 17 unchanged lines hidden (view full) --- 1182 if (&*it->second) 1183 return llvm::DIType(cast<llvm::MDNode>(it->second)); 1184 } 1185 1186 // Otherwise create the type. 1187 llvm::DIType Res = CreateTypeNode(Ty, Unit); 1188 1189 // And update the type cache. |
1197 TypeCache[Ty.getAsOpaquePtr()] = Res.getNode(); | 1190 TypeCache[Ty.getAsOpaquePtr()] = Res; |
1198 return Res; 1199} 1200 1201/// CreateTypeNode - Create a new debug type node. 1202llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty, 1203 llvm::DIFile Unit) { 1204 // Handle qualifiers, which recursively handles what they refer to. 1205 if (Ty.hasLocalQualifiers()) --- 13 unchanged lines hidden (view full) --- 1219 // FIXME: Handle these. 1220 case Type::ExtVector: 1221 return llvm::DIType(); 1222 1223 case Type::Vector: 1224 return CreateType(cast<VectorType>(Ty), Unit); 1225 case Type::ObjCObjectPointer: 1226 return CreateType(cast<ObjCObjectPointerType>(Ty), Unit); | 1191 return Res; 1192} 1193 1194/// CreateTypeNode - Create a new debug type node. 1195llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty, 1196 llvm::DIFile Unit) { 1197 // Handle qualifiers, which recursively handles what they refer to. 1198 if (Ty.hasLocalQualifiers()) --- 13 unchanged lines hidden (view full) --- 1212 // FIXME: Handle these. 1213 case Type::ExtVector: 1214 return llvm::DIType(); 1215 1216 case Type::Vector: 1217 return CreateType(cast<VectorType>(Ty), Unit); 1218 case Type::ObjCObjectPointer: 1219 return CreateType(cast<ObjCObjectPointerType>(Ty), Unit); |
1220 case Type::ObjCObject: 1221 return CreateType(cast<ObjCObjectType>(Ty), Unit); |
|
1227 case Type::ObjCInterface: 1228 return CreateType(cast<ObjCInterfaceType>(Ty), Unit); 1229 case Type::Builtin: return CreateType(cast<BuiltinType>(Ty), Unit); 1230 case Type::Complex: return CreateType(cast<ComplexType>(Ty), Unit); 1231 case Type::Pointer: return CreateType(cast<PointerType>(Ty), Unit); 1232 case Type::BlockPointer: 1233 return CreateType(cast<BlockPointerType>(Ty), Unit); 1234 case Type::Typedef: return CreateType(cast<TypedefType>(Ty), Unit); --- 11 unchanged lines hidden (view full) --- 1246 case Type::LValueReference: 1247 return CreateType(cast<LValueReferenceType>(Ty), Unit); 1248 1249 case Type::MemberPointer: 1250 return CreateType(cast<MemberPointerType>(Ty), Unit); 1251 1252 case Type::TemplateSpecialization: 1253 case Type::Elaborated: | 1222 case Type::ObjCInterface: 1223 return CreateType(cast<ObjCInterfaceType>(Ty), Unit); 1224 case Type::Builtin: return CreateType(cast<BuiltinType>(Ty), Unit); 1225 case Type::Complex: return CreateType(cast<ComplexType>(Ty), Unit); 1226 case Type::Pointer: return CreateType(cast<PointerType>(Ty), Unit); 1227 case Type::BlockPointer: 1228 return CreateType(cast<BlockPointerType>(Ty), Unit); 1229 case Type::Typedef: return CreateType(cast<TypedefType>(Ty), Unit); --- 11 unchanged lines hidden (view full) --- 1241 case Type::LValueReference: 1242 return CreateType(cast<LValueReferenceType>(Ty), Unit); 1243 1244 case Type::MemberPointer: 1245 return CreateType(cast<MemberPointerType>(Ty), Unit); 1246 1247 case Type::TemplateSpecialization: 1248 case Type::Elaborated: |
1254 case Type::QualifiedName: | |
1255 case Type::SubstTemplateTypeParm: 1256 case Type::TypeOfExpr: 1257 case Type::TypeOf: 1258 case Type::Decltype: 1259 llvm_unreachable("type should have been unwrapped!"); 1260 return llvm::DIType(); 1261 1262 case Type::RValueReference: --- 36 unchanged lines hidden (view full) --- 1299 1300 const Decl *D = GD.getDecl(); 1301 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 1302 // If there is a DISubprogram for this function available then use it. 1303 llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator 1304 FI = SPCache.find(FD); 1305 if (FI != SPCache.end()) { 1306 llvm::DIDescriptor SP(dyn_cast_or_null<llvm::MDNode>(FI->second)); | 1249 case Type::SubstTemplateTypeParm: 1250 case Type::TypeOfExpr: 1251 case Type::TypeOf: 1252 case Type::Decltype: 1253 llvm_unreachable("type should have been unwrapped!"); 1254 return llvm::DIType(); 1255 1256 case Type::RValueReference: --- 36 unchanged lines hidden (view full) --- 1293 1294 const Decl *D = GD.getDecl(); 1295 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 1296 // If there is a DISubprogram for this function available then use it. 1297 llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator 1298 FI = SPCache.find(FD); 1299 if (FI != SPCache.end()) { 1300 llvm::DIDescriptor SP(dyn_cast_or_null<llvm::MDNode>(FI->second)); |
1307 if (SP.isSubprogram() && llvm::DISubprogram(SP.getNode()).isDefinition()) { 1308 RegionStack.push_back(SP.getNode()); 1309 RegionMap[D] = llvm::WeakVH(SP.getNode()); | 1301 if (SP.isSubprogram() && llvm::DISubprogram(SP).isDefinition()) { 1302 llvm::MDNode *SPN = SP; 1303 RegionStack.push_back(SPN); 1304 RegionMap[D] = llvm::WeakVH(SP); |
1310 return; 1311 } 1312 } 1313 Name = getFunctionName(FD); 1314 // Use mangled name as linkage name for c/c++ functions. 1315 CGM.getMangledName(LinkageName, GD); 1316 } else { 1317 // Use llvm function name as linkage name. 1318 Name = Fn->getName(); 1319 LinkageName.setString(Name); 1320 } 1321 if (!Name.empty() && Name[0] == '\01') 1322 Name = Name.substr(1); 1323 1324 // It is expected that CurLoc is set before using EmitFunctionStart. 1325 // Usually, CurLoc points to the left bracket location of compound 1326 // statement representing function body. 1327 llvm::DIFile Unit = getOrCreateFile(CurLoc); | 1305 return; 1306 } 1307 } 1308 Name = getFunctionName(FD); 1309 // Use mangled name as linkage name for c/c++ functions. 1310 CGM.getMangledName(LinkageName, GD); 1311 } else { 1312 // Use llvm function name as linkage name. 1313 Name = Fn->getName(); 1314 LinkageName.setString(Name); 1315 } 1316 if (!Name.empty() && Name[0] == '\01') 1317 Name = Name.substr(1); 1318 1319 // It is expected that CurLoc is set before using EmitFunctionStart. 1320 // Usually, CurLoc points to the left bracket location of compound 1321 // statement representing function body. 1322 llvm::DIFile Unit = getOrCreateFile(CurLoc); |
1328 SourceManager &SM = CGM.getContext().getSourceManager(); 1329 unsigned LineNo = SM.getPresumedLoc(CurLoc).getLine(); | 1323 unsigned LineNo = getLineNumber(CurLoc); |
1330 1331 llvm::DISubprogram SP = 1332 DebugFactory.CreateSubprogram(Unit, Name, Name, LinkageName, Unit, LineNo, 1333 getOrCreateType(FnType, Unit), 1334 Fn->hasInternalLinkage(), true/*definition*/); 1335 1336 // Push function on region stack. | 1324 1325 llvm::DISubprogram SP = 1326 DebugFactory.CreateSubprogram(Unit, Name, Name, LinkageName, Unit, LineNo, 1327 getOrCreateType(FnType, Unit), 1328 Fn->hasInternalLinkage(), true/*definition*/); 1329 1330 // Push function on region stack. |
1337 RegionStack.push_back(SP.getNode()); 1338 RegionMap[D] = llvm::WeakVH(SP.getNode()); | 1331 llvm::MDNode *SPN = SP; 1332 RegionStack.push_back(SPN); 1333 RegionMap[D] = llvm::WeakVH(SP); |
1339} 1340 1341 1342void CGDebugInfo::EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder) { 1343 if (CurLoc.isInvalid() || CurLoc.isMacroID()) return; 1344 1345 // Don't bother if things are the same as last time. 1346 SourceManager &SM = CGM.getContext().getSourceManager(); 1347 if (CurLoc == PrevLoc 1348 || (SM.getInstantiationLineNumber(CurLoc) == 1349 SM.getInstantiationLineNumber(PrevLoc) 1350 && SM.isFromSameFile(CurLoc, PrevLoc))) 1351 // New Builder may not be in sync with CGDebugInfo. 1352 if (!Builder.getCurrentDebugLocation().isUnknown()) 1353 return; 1354 1355 // Update last state. 1356 PrevLoc = CurLoc; 1357 | 1334} 1335 1336 1337void CGDebugInfo::EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder) { 1338 if (CurLoc.isInvalid() || CurLoc.isMacroID()) return; 1339 1340 // Don't bother if things are the same as last time. 1341 SourceManager &SM = CGM.getContext().getSourceManager(); 1342 if (CurLoc == PrevLoc 1343 || (SM.getInstantiationLineNumber(CurLoc) == 1344 SM.getInstantiationLineNumber(PrevLoc) 1345 && SM.isFromSameFile(CurLoc, PrevLoc))) 1346 // New Builder may not be in sync with CGDebugInfo. 1347 if (!Builder.getCurrentDebugLocation().isUnknown()) 1348 return; 1349 1350 // Update last state. 1351 PrevLoc = CurLoc; 1352 |
1358 // Get the appropriate compile unit. 1359 llvm::DIFile Unit = getOrCreateFile(CurLoc); 1360 PresumedLoc PLoc = SM.getPresumedLoc(CurLoc); 1361 | |
1362 llvm::MDNode *Scope = RegionStack.back(); | 1353 llvm::MDNode *Scope = RegionStack.back(); |
1363 Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(PLoc.getLine(), 1364 PLoc.getColumn(), | 1354 Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(getLineNumber(CurLoc), 1355 getColumnNumber(CurLoc), |
1365 Scope)); 1366} 1367 1368/// EmitRegionStart- Constructs the debug code for entering a declarative 1369/// region - "llvm.dbg.region.start.". 1370void CGDebugInfo::EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder) { | 1356 Scope)); 1357} 1358 1359/// EmitRegionStart- Constructs the debug code for entering a declarative 1360/// region - "llvm.dbg.region.start.". 1361void CGDebugInfo::EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder) { |
1371 SourceManager &SM = CGM.getContext().getSourceManager(); 1372 PresumedLoc PLoc = SM.getPresumedLoc(CurLoc); | |
1373 llvm::DIDescriptor D = 1374 DebugFactory.CreateLexicalBlock(RegionStack.empty() ? 1375 llvm::DIDescriptor() : 1376 llvm::DIDescriptor(RegionStack.back()), | 1362 llvm::DIDescriptor D = 1363 DebugFactory.CreateLexicalBlock(RegionStack.empty() ? 1364 llvm::DIDescriptor() : 1365 llvm::DIDescriptor(RegionStack.back()), |
1377 PLoc.getLine(), PLoc.getColumn()); 1378 RegionStack.push_back(D.getNode()); | 1366 getLineNumber(CurLoc), 1367 getColumnNumber(CurLoc)); 1368 llvm::MDNode *DN = D; 1369 RegionStack.push_back(DN); |
1379} 1380 1381/// EmitRegionEnd - Constructs the debug code for exiting a declarative 1382/// region - "llvm.dbg.region.end." 1383void CGDebugInfo::EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder) { 1384 assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); 1385 1386 // Provide an region stop point. --- 81 unchanged lines hidden (view full) --- 1468 llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); 1469 llvm::DIType Ty; 1470 uint64_t XOffset = 0; 1471 if (VD->hasAttr<BlocksAttr>()) 1472 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset); 1473 else 1474 Ty = getOrCreateType(VD->getType(), Unit); 1475 | 1370} 1371 1372/// EmitRegionEnd - Constructs the debug code for exiting a declarative 1373/// region - "llvm.dbg.region.end." 1374void CGDebugInfo::EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder) { 1375 assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); 1376 1377 // Provide an region stop point. --- 81 unchanged lines hidden (view full) --- 1459 llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); 1460 llvm::DIType Ty; 1461 uint64_t XOffset = 0; 1462 if (VD->hasAttr<BlocksAttr>()) 1463 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset); 1464 else 1465 Ty = getOrCreateType(VD->getType(), Unit); 1466 |
1467 // If there is not any debug info for type then do not emit debug info 1468 // for this variable. 1469 if (!Ty) 1470 return; 1471 |
|
1476 // Get location information. | 1472 // Get location information. |
1477 SourceManager &SM = CGM.getContext().getSourceManager(); 1478 PresumedLoc PLoc = SM.getPresumedLoc(VD->getLocation()); 1479 unsigned Line = 0; 1480 unsigned Column = 0; 1481 if (PLoc.isInvalid()) 1482 PLoc = SM.getPresumedLoc(CurLoc); 1483 if (PLoc.isValid()) { 1484 Line = PLoc.getLine(); 1485 Column = PLoc.getColumn(); 1486 Unit = getOrCreateFile(CurLoc); 1487 } else { 1488 Unit = llvm::DIFile(); 1489 } | 1473 unsigned Line = getLineNumber(VD->getLocation()); 1474 unsigned Column = getColumnNumber(VD->getLocation()); |
1490 1491 // Create the descriptor for the variable. 1492 llvm::DIVariable D = 1493 DebugFactory.CreateVariable(Tag, llvm::DIDescriptor(RegionStack.back()), 1494 VD->getName(), 1495 Unit, Line, Ty); 1496 // Insert an llvm.dbg.declare into the current block. 1497 llvm::Instruction *Call = --- 17 unchanged lines hidden (view full) --- 1515 llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); 1516 llvm::DIType Ty; 1517 if (VD->hasAttr<BlocksAttr>()) 1518 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset); 1519 else 1520 Ty = getOrCreateType(VD->getType(), Unit); 1521 1522 // Get location information. | 1475 1476 // Create the descriptor for the variable. 1477 llvm::DIVariable D = 1478 DebugFactory.CreateVariable(Tag, llvm::DIDescriptor(RegionStack.back()), 1479 VD->getName(), 1480 Unit, Line, Ty); 1481 // Insert an llvm.dbg.declare into the current block. 1482 llvm::Instruction *Call = --- 17 unchanged lines hidden (view full) --- 1500 llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); 1501 llvm::DIType Ty; 1502 if (VD->hasAttr<BlocksAttr>()) 1503 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset); 1504 else 1505 Ty = getOrCreateType(VD->getType(), Unit); 1506 1507 // Get location information. |
1523 SourceManager &SM = CGM.getContext().getSourceManager(); 1524 PresumedLoc PLoc = SM.getPresumedLoc(VD->getLocation()); 1525 unsigned Line = 0; 1526 if (!PLoc.isInvalid()) 1527 Line = PLoc.getLine(); 1528 else 1529 Unit = llvm::DIFile(); | 1508 unsigned Line = getLineNumber(VD->getLocation()); 1509 unsigned Column = getColumnNumber(VD->getLocation()); |
1530 1531 CharUnits offset = CGF->BlockDecls[VD]; 1532 llvm::SmallVector<llvm::Value *, 9> addr; 1533 const llvm::Type *Int64Ty = llvm::Type::getInt64Ty(CGM.getLLVMContext()); 1534 addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpDeref)); 1535 addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpPlus)); 1536 addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity())); 1537 if (BDRE->isByRef()) { --- 15 unchanged lines hidden (view full) --- 1553 llvm::DIDescriptor(RegionStack.back()), 1554 VD->getName(), Unit, Line, Ty, 1555 addr); 1556 // Insert an llvm.dbg.declare into the current block. 1557 llvm::Instruction *Call = 1558 DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertBlock()); 1559 1560 llvm::MDNode *Scope = RegionStack.back(); | 1510 1511 CharUnits offset = CGF->BlockDecls[VD]; 1512 llvm::SmallVector<llvm::Value *, 9> addr; 1513 const llvm::Type *Int64Ty = llvm::Type::getInt64Ty(CGM.getLLVMContext()); 1514 addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpDeref)); 1515 addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpPlus)); 1516 addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity())); 1517 if (BDRE->isByRef()) { --- 15 unchanged lines hidden (view full) --- 1533 llvm::DIDescriptor(RegionStack.back()), 1534 VD->getName(), Unit, Line, Ty, 1535 addr); 1536 // Insert an llvm.dbg.declare into the current block. 1537 llvm::Instruction *Call = 1538 DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertBlock()); 1539 1540 llvm::MDNode *Scope = RegionStack.back(); |
1561 Call->setDebugLoc(llvm::DebugLoc::get(Line, PLoc.getColumn(), Scope)); | 1541 Call->setDebugLoc(llvm::DebugLoc::get(Line, Column, Scope)); |
1562} 1563 1564void CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *VD, 1565 llvm::Value *Storage, 1566 CGBuilderTy &Builder) { 1567 EmitDeclare(VD, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder); 1568} 1569 --- 13 unchanged lines hidden (view full) --- 1583 1584 1585/// EmitGlobalVariable - Emit information about a global variable. 1586void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, 1587 const VarDecl *D) { 1588 1589 // Create global variable debug descriptor. 1590 llvm::DIFile Unit = getOrCreateFile(D->getLocation()); | 1542} 1543 1544void CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *VD, 1545 llvm::Value *Storage, 1546 CGBuilderTy &Builder) { 1547 EmitDeclare(VD, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder); 1548} 1549 --- 13 unchanged lines hidden (view full) --- 1563 1564 1565/// EmitGlobalVariable - Emit information about a global variable. 1566void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, 1567 const VarDecl *D) { 1568 1569 // Create global variable debug descriptor. 1570 llvm::DIFile Unit = getOrCreateFile(D->getLocation()); |
1591 SourceManager &SM = CGM.getContext().getSourceManager(); 1592 PresumedLoc PLoc = SM.getPresumedLoc(D->getLocation()); 1593 unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); | 1571 unsigned LineNo = getLineNumber(D->getLocation()); |
1594 1595 QualType T = D->getType(); 1596 if (T->isIncompleteArrayType()) { 1597 1598 // CodeGen turns int[] into int[1] so we'll do the same here. 1599 llvm::APSInt ConstVal(32); 1600 1601 ConstVal = 1; 1602 QualType ET = CGM.getContext().getAsArrayType(T)->getElementType(); 1603 1604 T = CGM.getContext().getConstantArrayType(ET, ConstVal, 1605 ArrayType::Normal, 0); 1606 } 1607 llvm::StringRef DeclName = D->getName(); | 1572 1573 QualType T = D->getType(); 1574 if (T->isIncompleteArrayType()) { 1575 1576 // CodeGen turns int[] into int[1] so we'll do the same here. 1577 llvm::APSInt ConstVal(32); 1578 1579 ConstVal = 1; 1580 QualType ET = CGM.getContext().getAsArrayType(T)->getElementType(); 1581 1582 T = CGM.getContext().getConstantArrayType(ET, ConstVal, 1583 ArrayType::Normal, 0); 1584 } 1585 llvm::StringRef DeclName = D->getName(); |
1586 llvm::StringRef LinkageName; 1587 if (D->getDeclContext() && !isa<FunctionDecl>(D->getDeclContext())) 1588 LinkageName = Var->getName(); |
|
1608 llvm::DIDescriptor DContext = 1609 getContextDescriptor(dyn_cast<Decl>(D->getDeclContext()), Unit); | 1589 llvm::DIDescriptor DContext = 1590 getContextDescriptor(dyn_cast<Decl>(D->getDeclContext()), Unit); |
1610 DebugFactory.CreateGlobalVariable(DContext, DeclName, 1611 DeclName, llvm::StringRef(), Unit, LineNo, 1612 getOrCreateType(T, Unit), | 1591 DebugFactory.CreateGlobalVariable(DContext, DeclName, DeclName, LinkageName, 1592 Unit, LineNo, getOrCreateType(T, Unit), |
1613 Var->hasInternalLinkage(), 1614 true/*definition*/, Var); 1615} 1616 1617/// EmitGlobalVariable - Emit information about an objective-c interface. 1618void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, 1619 ObjCInterfaceDecl *ID) { 1620 // Create global variable debug descriptor. 1621 llvm::DIFile Unit = getOrCreateFile(ID->getLocation()); | 1593 Var->hasInternalLinkage(), 1594 true/*definition*/, Var); 1595} 1596 1597/// EmitGlobalVariable - Emit information about an objective-c interface. 1598void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, 1599 ObjCInterfaceDecl *ID) { 1600 // Create global variable debug descriptor. 1601 llvm::DIFile Unit = getOrCreateFile(ID->getLocation()); |
1622 SourceManager &SM = CGM.getContext().getSourceManager(); 1623 PresumedLoc PLoc = SM.getPresumedLoc(ID->getLocation()); 1624 unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); | 1602 unsigned LineNo = getLineNumber(ID->getLocation()); |
1625 1626 llvm::StringRef Name = ID->getName(); 1627 1628 QualType T = CGM.getContext().getObjCInterfaceType(ID); 1629 if (T->isIncompleteArrayType()) { 1630 1631 // CodeGen turns int[] into int[1] so we'll do the same here. 1632 llvm::APSInt ConstVal(32); --- 16 unchanged lines hidden (view full) --- 1649llvm::DINameSpace 1650CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl, 1651 llvm::DIDescriptor Unit) { 1652 llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH>::iterator I = 1653 NameSpaceCache.find(NSDecl); 1654 if (I != NameSpaceCache.end()) 1655 return llvm::DINameSpace(cast<llvm::MDNode>(I->second)); 1656 | 1603 1604 llvm::StringRef Name = ID->getName(); 1605 1606 QualType T = CGM.getContext().getObjCInterfaceType(ID); 1607 if (T->isIncompleteArrayType()) { 1608 1609 // CodeGen turns int[] into int[1] so we'll do the same here. 1610 llvm::APSInt ConstVal(32); --- 16 unchanged lines hidden (view full) --- 1627llvm::DINameSpace 1628CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl, 1629 llvm::DIDescriptor Unit) { 1630 llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH>::iterator I = 1631 NameSpaceCache.find(NSDecl); 1632 if (I != NameSpaceCache.end()) 1633 return llvm::DINameSpace(cast<llvm::MDNode>(I->second)); 1634 |
1657 SourceManager &SM = CGM.getContext().getSourceManager(); 1658 PresumedLoc PLoc = SM.getPresumedLoc(NSDecl->getLocation()); 1659 unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); | 1635 unsigned LineNo = getLineNumber(NSDecl->getLocation()); |
1660 1661 llvm::DIDescriptor Context = 1662 getContextDescriptor(dyn_cast<Decl>(NSDecl->getDeclContext()), Unit); 1663 llvm::DINameSpace NS = 1664 DebugFactory.CreateNameSpace(Context, NSDecl->getName(), | 1636 1637 llvm::DIDescriptor Context = 1638 getContextDescriptor(dyn_cast<Decl>(NSDecl->getDeclContext()), Unit); 1639 llvm::DINameSpace NS = 1640 DebugFactory.CreateNameSpace(Context, NSDecl->getName(), |
1665 llvm::DIFile(Unit.getNode()), LineNo); 1666 NameSpaceCache[NSDecl] = llvm::WeakVH(NS.getNode()); | 1641 llvm::DIFile(Unit), LineNo); 1642 NameSpaceCache[NSDecl] = llvm::WeakVH(NS); |
1667 return NS; 1668} | 1643 return NS; 1644} |