diff options
author | Devang Patel <dpatel@apple.com> | 2010-01-19 00:00:59 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2010-01-19 00:00:59 +0000 |
commit | 428deb524a262709095d5e5a088e924b9fd47202 (patch) | |
tree | 4adec60ef26e8ab750a51910be364e49e13b45c7 /lib/CodeGen/CGDebugInfo.cpp | |
parent | f46034af49435a4d1a0085a4738343122aeb6521 (diff) |
Refactor.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93814 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 109 |
1 files changed, 60 insertions, 49 deletions
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index aa43261da0..b5c19eaa7f 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -460,6 +460,65 @@ llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty, return DbgTy; } +/// CollectRecordFields - A helper function to collect debug info for +/// record fields. This is used while creating debug info entry for a Record. +void CGDebugInfo:: +CollectRecordFields(const RecordDecl *Decl, + llvm::DICompileUnit Unit, + llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys) { + unsigned FieldNo = 0; + SourceManager &SM = CGM.getContext().getSourceManager(); + const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(Decl); + for (RecordDecl::field_iterator I = Decl->field_begin(), + E = Decl->field_end(); + I != E; ++I, ++FieldNo) { + FieldDecl *Field = *I; + llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit); + + llvm::StringRef FieldName = Field->getName(); + + // Ignore unnamed fields. + if (FieldName.empty()) + continue; + + // Get the location for the field. + SourceLocation FieldDefLoc = Field->getLocation(); + PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc); + llvm::DICompileUnit FieldDefUnit; + unsigned FieldLine = 0; + + if (!PLoc.isInvalid()) { + FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc); + FieldLine = PLoc.getLine(); + } + + QualType FType = Field->getType(); + uint64_t FieldSize = 0; + unsigned FieldAlign = 0; + if (!FType->isIncompleteArrayType()) { + + // Bit size, align and offset of the type. + FieldSize = CGM.getContext().getTypeSize(FType); + Expr *BitWidth = Field->getBitWidth(); + if (BitWidth) + FieldSize = BitWidth->EvaluateAsInt(CGM.getContext()).getZExtValue(); + + FieldAlign = CGM.getContext().getTypeAlign(FType); + } + + uint64_t FieldOffset = RL.getFieldOffset(FieldNo); + + // Create a DW_TAG_member node to remember the offset of this field in the + // struct. FIXME: This is an absolutely insane way to capture this + // information. When we gut debug info, this should be fixed. + FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, + FieldName, FieldDefUnit, + FieldLine, FieldSize, FieldAlign, + FieldOffset, 0, FieldTy); + EltTys.push_back(FieldTy); + } +} + /// CreateType - get structure or union type. llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty, llvm::DICompileUnit Unit) { @@ -509,57 +568,9 @@ llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty, // Convert all the elements. llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; - const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(Decl); - - unsigned FieldNo = 0; - for (RecordDecl::field_iterator I = Decl->field_begin(), - E = Decl->field_end(); - I != E; ++I, ++FieldNo) { - FieldDecl *Field = *I; - llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit); - - llvm::StringRef FieldName = Field->getName(); - - // Ignore unnamed fields. - if (FieldName.empty()) - continue; - // Get the location for the field. - SourceLocation FieldDefLoc = Field->getLocation(); - PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc); - llvm::DICompileUnit FieldDefUnit; - unsigned FieldLine = 0; - - if (!PLoc.isInvalid()) { - FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc); - FieldLine = PLoc.getLine(); - } - QualType FType = Field->getType(); - uint64_t FieldSize = 0; - unsigned FieldAlign = 0; - if (!FType->isIncompleteArrayType()) { - - // Bit size, align and offset of the type. - FieldSize = CGM.getContext().getTypeSize(FType); - Expr *BitWidth = Field->getBitWidth(); - if (BitWidth) - FieldSize = BitWidth->EvaluateAsInt(CGM.getContext()).getZExtValue(); - - FieldAlign = CGM.getContext().getTypeAlign(FType); - } - - uint64_t FieldOffset = RL.getFieldOffset(FieldNo); - - // Create a DW_TAG_member node to remember the offset of this field in the - // struct. FIXME: This is an absolutely insane way to capture this - // information. When we gut debug info, this should be fixed. - FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - FieldName, FieldDefUnit, - FieldLine, FieldSize, FieldAlign, - FieldOffset, 0, FieldTy); - EltTys.push_back(FieldTy); - } + CollectRecordFields(Decl, Unit, EltTys); llvm::DIArray Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |