LLVM API Documentation
00001 //===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines a bunch of datatypes that are useful for creating and 00011 // walking debug info in LLVM IR form. They essentially provide wrappers around 00012 // the information in the global variables that's needed when constructing the 00013 // DWARF information. 00014 // 00015 //===----------------------------------------------------------------------===// 00016 00017 #ifndef LLVM_DEBUGINFO_H 00018 #define LLVM_DEBUGINFO_H 00019 00020 #include "llvm/ADT/SmallPtrSet.h" 00021 #include "llvm/ADT/SmallVector.h" 00022 #include "llvm/ADT/StringRef.h" 00023 #include "llvm/Support/Dwarf.h" 00024 00025 namespace llvm { 00026 class BasicBlock; 00027 class Constant; 00028 class Function; 00029 class GlobalVariable; 00030 class Module; 00031 class Type; 00032 class Value; 00033 class DbgDeclareInst; 00034 class Instruction; 00035 class MDNode; 00036 class NamedMDNode; 00037 class LLVMContext; 00038 class raw_ostream; 00039 00040 class DIFile; 00041 class DISubprogram; 00042 class DILexicalBlock; 00043 class DILexicalBlockFile; 00044 class DIVariable; 00045 class DIType; 00046 class DIObjCProperty; 00047 00048 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info. 00049 /// This should not be stored in a container, because the underlying MDNode 00050 /// may change in certain situations. 00051 class DIDescriptor { 00052 public: 00053 enum { 00054 FlagPrivate = 1 << 0, 00055 FlagProtected = 1 << 1, 00056 FlagFwdDecl = 1 << 2, 00057 FlagAppleBlock = 1 << 3, 00058 FlagBlockByrefStruct = 1 << 4, 00059 FlagVirtual = 1 << 5, 00060 FlagArtificial = 1 << 6, 00061 FlagExplicit = 1 << 7, 00062 FlagPrototyped = 1 << 8, 00063 FlagObjcClassComplete = 1 << 9, 00064 FlagObjectPointer = 1 << 10, 00065 FlagVector = 1 << 11, 00066 FlagStaticMember = 1 << 12 00067 }; 00068 protected: 00069 const MDNode *DbgNode; 00070 00071 StringRef getStringField(unsigned Elt) const; 00072 unsigned getUnsignedField(unsigned Elt) const { 00073 return (unsigned)getUInt64Field(Elt); 00074 } 00075 uint64_t getUInt64Field(unsigned Elt) const; 00076 int64_t getInt64Field(unsigned Elt) const; 00077 DIDescriptor getDescriptorField(unsigned Elt) const; 00078 00079 template <typename DescTy> 00080 DescTy getFieldAs(unsigned Elt) const { 00081 return DescTy(getDescriptorField(Elt)); 00082 } 00083 00084 GlobalVariable *getGlobalVariableField(unsigned Elt) const; 00085 Constant *getConstantField(unsigned Elt) const; 00086 Function *getFunctionField(unsigned Elt) const; 00087 void replaceFunctionField(unsigned Elt, Function *F); 00088 00089 public: 00090 explicit DIDescriptor() : DbgNode(0) {} 00091 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {} 00092 explicit DIDescriptor(const DIFile F); 00093 explicit DIDescriptor(const DISubprogram F); 00094 explicit DIDescriptor(const DILexicalBlockFile F); 00095 explicit DIDescriptor(const DILexicalBlock F); 00096 explicit DIDescriptor(const DIVariable F); 00097 explicit DIDescriptor(const DIType F); 00098 00099 bool Verify() const; 00100 00101 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); } 00102 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); } 00103 00104 unsigned getTag() const { 00105 return getUnsignedField(0) & ~LLVMDebugVersionMask; 00106 } 00107 00108 bool isDerivedType() const; 00109 bool isCompositeType() const; 00110 bool isBasicType() const; 00111 bool isVariable() const; 00112 bool isSubprogram() const; 00113 bool isGlobalVariable() const; 00114 bool isScope() const; 00115 bool isFile() const; 00116 bool isCompileUnit() const; 00117 bool isNameSpace() const; 00118 bool isLexicalBlockFile() const; 00119 bool isLexicalBlock() const; 00120 bool isSubrange() const; 00121 bool isEnumerator() const; 00122 bool isType() const; 00123 bool isGlobal() const; 00124 bool isUnspecifiedParameter() const; 00125 bool isTemplateTypeParameter() const; 00126 bool isTemplateValueParameter() const; 00127 bool isObjCProperty() const; 00128 bool isImportedEntity() const; 00129 00130 /// print - print descriptor. 00131 void print(raw_ostream &OS) const; 00132 00133 /// dump - print descriptor to dbgs() with a newline. 00134 void dump() const; 00135 }; 00136 00137 /// DISubrange - This is used to represent ranges, for array bounds. 00138 class DISubrange : public DIDescriptor { 00139 friend class DIDescriptor; 00140 void printInternal(raw_ostream &OS) const; 00141 public: 00142 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {} 00143 00144 int64_t getLo() const { return getInt64Field(1); } 00145 int64_t getCount() const { return getInt64Field(2); } 00146 bool Verify() const; 00147 }; 00148 00149 /// DIArray - This descriptor holds an array of descriptors. 00150 class DIArray : public DIDescriptor { 00151 public: 00152 explicit DIArray(const MDNode *N = 0) 00153 : DIDescriptor(N) {} 00154 00155 unsigned getNumElements() const; 00156 DIDescriptor getElement(unsigned Idx) const { 00157 return getDescriptorField(Idx); 00158 } 00159 }; 00160 00161 /// DIScope - A base class for various scopes. 00162 class DIScope : public DIDescriptor { 00163 protected: 00164 friend class DIDescriptor; 00165 void printInternal(raw_ostream &OS) const; 00166 public: 00167 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {} 00168 00169 /// Set the filename by allocating a new string MDNode for 00170 /// it and attaching it to the underlying node. 00171 void setFilename(StringRef Name, LLVMContext &Context); 00172 StringRef getFilename() const; 00173 StringRef getDirectory() const; 00174 }; 00175 00176 /// DIFile - This is a wrapper for a file. 00177 class DIFile : public DIScope { 00178 friend class DIDescriptor; 00179 public: 00180 explicit DIFile(const MDNode *N = 0) : DIScope(N) { 00181 if (DbgNode && !isFile()) 00182 DbgNode = 0; 00183 } 00184 MDNode *getFileNode() const; 00185 bool Verify() const; 00186 }; 00187 00188 /// DICompileUnit - A wrapper for a compile unit. 00189 class DICompileUnit : public DIScope { 00190 friend class DIDescriptor; 00191 void printInternal(raw_ostream &OS) const; 00192 public: 00193 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {} 00194 00195 unsigned getLanguage() const { return getUnsignedField(2); } 00196 StringRef getProducer() const { return getStringField(3); } 00197 00198 bool isOptimized() const { return getUnsignedField(4) != 0; } 00199 StringRef getFlags() const { return getStringField(5); } 00200 unsigned getRunTimeVersion() const { return getUnsignedField(6); } 00201 00202 DIArray getEnumTypes() const; 00203 DIArray getRetainedTypes() const; 00204 DIArray getSubprograms() const; 00205 DIArray getGlobalVariables() const; 00206 DIArray getImportedEntities() const; 00207 00208 StringRef getSplitDebugFilename() const { return getStringField(12); } 00209 00210 /// Verify - Verify that a compile unit is well formed. 00211 bool Verify() const; 00212 }; 00213 00214 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}'). 00215 /// FIXME: it seems strange that this doesn't have either a reference to the 00216 /// type/precision or a file/line pair for location info. 00217 class DIEnumerator : public DIDescriptor { 00218 friend class DIDescriptor; 00219 void printInternal(raw_ostream &OS) const; 00220 public: 00221 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {} 00222 00223 StringRef getName() const { return getStringField(1); } 00224 uint64_t getEnumValue() const { return getUInt64Field(2); } 00225 bool Verify() const; 00226 }; 00227 00228 /// DIType - This is a wrapper for a type. 00229 /// FIXME: Types should be factored much better so that CV qualifiers and 00230 /// others do not require a huge and empty descriptor full of zeros. 00231 class DIType : public DIScope { 00232 protected: 00233 friend class DIDescriptor; 00234 void printInternal(raw_ostream &OS) const; 00235 // This ctor is used when the Tag has already been validated by a derived 00236 // ctor. 00237 DIType(const MDNode *N, bool, bool) : DIScope(N) {} 00238 public: 00239 /// Verify - Verify that a type descriptor is well formed. 00240 bool Verify() const; 00241 explicit DIType(const MDNode *N); 00242 explicit DIType() {} 00243 00244 DIScope getContext() const { return getFieldAs<DIScope>(2); } 00245 StringRef getName() const { return getStringField(3); } 00246 unsigned getLineNumber() const { return getUnsignedField(4); } 00247 uint64_t getSizeInBits() const { return getUInt64Field(5); } 00248 uint64_t getAlignInBits() const { return getUInt64Field(6); } 00249 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type 00250 // carry this is just plain insane. 00251 uint64_t getOffsetInBits() const { return getUInt64Field(7); } 00252 unsigned getFlags() const { return getUnsignedField(8); } 00253 bool isPrivate() const { 00254 return (getFlags() & FlagPrivate) != 0; 00255 } 00256 bool isProtected() const { 00257 return (getFlags() & FlagProtected) != 0; 00258 } 00259 bool isForwardDecl() const { 00260 return (getFlags() & FlagFwdDecl) != 0; 00261 } 00262 // isAppleBlock - Return true if this is the Apple Blocks extension. 00263 bool isAppleBlockExtension() const { 00264 return (getFlags() & FlagAppleBlock) != 0; 00265 } 00266 bool isBlockByrefStruct() const { 00267 return (getFlags() & FlagBlockByrefStruct) != 0; 00268 } 00269 bool isVirtual() const { 00270 return (getFlags() & FlagVirtual) != 0; 00271 } 00272 bool isArtificial() const { 00273 return (getFlags() & FlagArtificial) != 0; 00274 } 00275 bool isObjectPointer() const { 00276 return (getFlags() & FlagObjectPointer) != 0; 00277 } 00278 bool isObjcClassComplete() const { 00279 return (getFlags() & FlagObjcClassComplete) != 0; 00280 } 00281 bool isVector() const { 00282 return (getFlags() & FlagVector) != 0; 00283 } 00284 bool isStaticMember() const { 00285 return (getFlags() & FlagStaticMember) != 0; 00286 } 00287 bool isValid() const { 00288 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType()); 00289 } 00290 00291 /// isUnsignedDIType - Return true if type encoding is unsigned. 00292 bool isUnsignedDIType(); 00293 00294 /// replaceAllUsesWith - Replace all uses of debug info referenced by 00295 /// this descriptor. 00296 void replaceAllUsesWith(DIDescriptor &D); 00297 void replaceAllUsesWith(MDNode *D); 00298 }; 00299 00300 /// DIBasicType - A basic type, like 'int' or 'float'. 00301 class DIBasicType : public DIType { 00302 public: 00303 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {} 00304 00305 unsigned getEncoding() const { return getUnsignedField(9); } 00306 00307 /// Verify - Verify that a basic type descriptor is well formed. 00308 bool Verify() const; 00309 }; 00310 00311 /// DIDerivedType - A simple derived type, like a const qualified type, 00312 /// a typedef, a pointer or reference, et cetera. Or, a data member of 00313 /// a class/struct/union. 00314 class DIDerivedType : public DIType { 00315 friend class DIDescriptor; 00316 void printInternal(raw_ostream &OS) const; 00317 protected: 00318 explicit DIDerivedType(const MDNode *N, bool, bool) 00319 : DIType(N, true, true) {} 00320 public: 00321 explicit DIDerivedType(const MDNode *N = 0) 00322 : DIType(N, true, true) {} 00323 00324 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); } 00325 00326 /// getOriginalTypeSize - If this type is derived from a base type then 00327 /// return base type size. 00328 uint64_t getOriginalTypeSize() const; 00329 00330 /// getObjCProperty - Return property node, if this ivar is 00331 /// associated with one. 00332 MDNode *getObjCProperty() const; 00333 00334 DIType getClassType() const { 00335 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type); 00336 return getFieldAs<DIType>(10); 00337 } 00338 00339 Constant *getConstant() const { 00340 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember()); 00341 return getConstantField(10); 00342 } 00343 00344 /// Verify - Verify that a derived type descriptor is well formed. 00345 bool Verify() const; 00346 }; 00347 00348 /// DICompositeType - This descriptor holds a type that can refer to multiple 00349 /// other types, like a function or struct. 00350 /// DICompositeType is derived from DIDerivedType because some 00351 /// composite types (such as enums) can be derived from basic types 00352 // FIXME: Make this derive from DIType directly & just store the 00353 // base type in a single DIType field. 00354 class DICompositeType : public DIDerivedType { 00355 friend class DIDescriptor; 00356 void printInternal(raw_ostream &OS) const; 00357 public: 00358 explicit DICompositeType(const MDNode *N = 0) 00359 : DIDerivedType(N, true, true) { 00360 if (N && !isCompositeType()) 00361 DbgNode = 0; 00362 } 00363 00364 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); } 00365 void setTypeArray(DIArray Elements, DIArray TParams = DIArray()); 00366 unsigned getRunTimeLang() const { return getUnsignedField(11); } 00367 DICompositeType getContainingType() const { 00368 return getFieldAs<DICompositeType>(12); 00369 } 00370 void setContainingType(DICompositeType ContainingType); 00371 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); } 00372 00373 /// Verify - Verify that a composite type descriptor is well formed. 00374 bool Verify() const; 00375 }; 00376 00377 /// DITemplateTypeParameter - This is a wrapper for template type parameter. 00378 class DITemplateTypeParameter : public DIDescriptor { 00379 public: 00380 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {} 00381 00382 DIScope getContext() const { return getFieldAs<DIScope>(1); } 00383 StringRef getName() const { return getStringField(2); } 00384 DIType getType() const { return getFieldAs<DIType>(3); } 00385 StringRef getFilename() const { 00386 return getFieldAs<DIFile>(4).getFilename(); 00387 } 00388 StringRef getDirectory() const { 00389 return getFieldAs<DIFile>(4).getDirectory(); 00390 } 00391 unsigned getLineNumber() const { return getUnsignedField(5); } 00392 unsigned getColumnNumber() const { return getUnsignedField(6); } 00393 bool Verify() const; 00394 }; 00395 00396 /// DITemplateValueParameter - This is a wrapper for template value parameter. 00397 class DITemplateValueParameter : public DIDescriptor { 00398 public: 00399 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {} 00400 00401 DIScope getContext() const { return getFieldAs<DIScope>(1); } 00402 StringRef getName() const { return getStringField(2); } 00403 DIType getType() const { return getFieldAs<DIType>(3); } 00404 Value *getValue() const; 00405 StringRef getFilename() const { 00406 return getFieldAs<DIFile>(5).getFilename(); 00407 } 00408 StringRef getDirectory() const { 00409 return getFieldAs<DIFile>(5).getDirectory(); 00410 } 00411 unsigned getLineNumber() const { return getUnsignedField(6); } 00412 unsigned getColumnNumber() const { return getUnsignedField(7); } 00413 bool Verify() const; 00414 }; 00415 00416 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function). 00417 class DISubprogram : public DIScope { 00418 friend class DIDescriptor; 00419 void printInternal(raw_ostream &OS) const; 00420 public: 00421 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {} 00422 00423 DIScope getContext() const { return getFieldAs<DIScope>(2); } 00424 StringRef getName() const { return getStringField(3); } 00425 StringRef getDisplayName() const { return getStringField(4); } 00426 StringRef getLinkageName() const { return getStringField(5); } 00427 unsigned getLineNumber() const { return getUnsignedField(6); } 00428 DICompositeType getType() const { return getFieldAs<DICompositeType>(7); } 00429 00430 /// isLocalToUnit - Return true if this subprogram is local to the current 00431 /// compile unit, like 'static' in C. 00432 unsigned isLocalToUnit() const { return getUnsignedField(8); } 00433 unsigned isDefinition() const { return getUnsignedField(9); } 00434 00435 unsigned getVirtuality() const { return getUnsignedField(10); } 00436 unsigned getVirtualIndex() const { return getUnsignedField(11); } 00437 00438 DICompositeType getContainingType() const { 00439 return getFieldAs<DICompositeType>(12); 00440 } 00441 00442 unsigned getFlags() const { 00443 return getUnsignedField(13); 00444 } 00445 00446 unsigned isArtificial() const { 00447 return (getUnsignedField(13) & FlagArtificial) != 0; 00448 } 00449 /// isPrivate - Return true if this subprogram has "private" 00450 /// access specifier. 00451 bool isPrivate() const { 00452 return (getUnsignedField(13) & FlagPrivate) != 0; 00453 } 00454 /// isProtected - Return true if this subprogram has "protected" 00455 /// access specifier. 00456 bool isProtected() const { 00457 return (getUnsignedField(13) & FlagProtected) != 0; 00458 } 00459 /// isExplicit - Return true if this subprogram is marked as explicit. 00460 bool isExplicit() const { 00461 return (getUnsignedField(13) & FlagExplicit) != 0; 00462 } 00463 /// isPrototyped - Return true if this subprogram is prototyped. 00464 bool isPrototyped() const { 00465 return (getUnsignedField(13) & FlagPrototyped) != 0; 00466 } 00467 00468 unsigned isOptimized() const; 00469 00470 /// getScopeLineNumber - Get the beginning of the scope of the 00471 /// function, not necessarily where the name of the program 00472 /// starts. 00473 unsigned getScopeLineNumber() const { return getUnsignedField(19); } 00474 00475 /// Verify - Verify that a subprogram descriptor is well formed. 00476 bool Verify() const; 00477 00478 /// describes - Return true if this subprogram provides debugging 00479 /// information for the function F. 00480 bool describes(const Function *F); 00481 00482 Function *getFunction() const { return getFunctionField(15); } 00483 void replaceFunction(Function *F) { replaceFunctionField(15, F); } 00484 DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); } 00485 DISubprogram getFunctionDeclaration() const { 00486 return getFieldAs<DISubprogram>(17); 00487 } 00488 MDNode *getVariablesNodes() const; 00489 DIArray getVariables() const; 00490 }; 00491 00492 /// DIGlobalVariable - This is a wrapper for a global variable. 00493 class DIGlobalVariable : public DIDescriptor { 00494 friend class DIDescriptor; 00495 void printInternal(raw_ostream &OS) const; 00496 public: 00497 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {} 00498 00499 DIScope getContext() const { return getFieldAs<DIScope>(2); } 00500 StringRef getName() const { return getStringField(3); } 00501 StringRef getDisplayName() const { return getStringField(4); } 00502 StringRef getLinkageName() const { return getStringField(5); } 00503 StringRef getFilename() const { 00504 return getFieldAs<DIFile>(6).getFilename(); 00505 } 00506 StringRef getDirectory() const { 00507 return getFieldAs<DIFile>(6).getDirectory(); 00508 00509 } 00510 00511 unsigned getLineNumber() const { return getUnsignedField(7); } 00512 DIType getType() const { return getFieldAs<DIType>(8); } 00513 unsigned isLocalToUnit() const { return getUnsignedField(9); } 00514 unsigned isDefinition() const { return getUnsignedField(10); } 00515 00516 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); } 00517 Constant *getConstant() const { return getConstantField(11); } 00518 DIDerivedType getStaticDataMemberDeclaration() const { 00519 return getFieldAs<DIDerivedType>(12); 00520 } 00521 00522 /// Verify - Verify that a global variable descriptor is well formed. 00523 bool Verify() const; 00524 }; 00525 00526 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local, 00527 /// global etc). 00528 class DIVariable : public DIDescriptor { 00529 friend class DIDescriptor; 00530 void printInternal(raw_ostream &OS) const; 00531 public: 00532 explicit DIVariable(const MDNode *N = 0) 00533 : DIDescriptor(N) {} 00534 00535 DIScope getContext() const { return getFieldAs<DIScope>(1); } 00536 StringRef getName() const { return getStringField(2); } 00537 DIFile getFile() const { return getFieldAs<DIFile>(3); } 00538 unsigned getLineNumber() const { 00539 return (getUnsignedField(4) << 8) >> 8; 00540 } 00541 unsigned getArgNumber() const { 00542 unsigned L = getUnsignedField(4); 00543 return L >> 24; 00544 } 00545 DIType getType() const { return getFieldAs<DIType>(5); } 00546 00547 /// isArtificial - Return true if this variable is marked as "artificial". 00548 bool isArtificial() const { 00549 return (getUnsignedField(6) & FlagArtificial) != 0; 00550 } 00551 00552 bool isObjectPointer() const { 00553 return (getUnsignedField(6) & FlagObjectPointer) != 0; 00554 } 00555 00556 /// getInlinedAt - If this variable is inlined then return inline location. 00557 MDNode *getInlinedAt() const; 00558 00559 /// Verify - Verify that a variable descriptor is well formed. 00560 bool Verify() const; 00561 00562 /// HasComplexAddr - Return true if the variable has a complex address. 00563 bool hasComplexAddress() const { 00564 return getNumAddrElements() > 0; 00565 } 00566 00567 unsigned getNumAddrElements() const; 00568 00569 uint64_t getAddrElement(unsigned Idx) const { 00570 return getUInt64Field(Idx+8); 00571 } 00572 00573 /// isBlockByrefVariable - Return true if the variable was declared as 00574 /// a "__block" variable (Apple Blocks). 00575 bool isBlockByrefVariable() const { 00576 return getType().isBlockByrefStruct(); 00577 } 00578 00579 /// isInlinedFnArgument - Return true if this variable provides debugging 00580 /// information for an inlined function arguments. 00581 bool isInlinedFnArgument(const Function *CurFn); 00582 00583 void printExtendedName(raw_ostream &OS) const; 00584 }; 00585 00586 /// DILexicalBlock - This is a wrapper for a lexical block. 00587 class DILexicalBlock : public DIScope { 00588 public: 00589 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {} 00590 DIScope getContext() const { return getFieldAs<DIScope>(2); } 00591 unsigned getLineNumber() const { return getUnsignedField(3); } 00592 unsigned getColumnNumber() const { return getUnsignedField(4); } 00593 bool Verify() const; 00594 }; 00595 00596 /// DILexicalBlockFile - This is a wrapper for a lexical block with 00597 /// a filename change. 00598 class DILexicalBlockFile : public DIScope { 00599 public: 00600 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {} 00601 DIScope getContext() const { if (getScope().isSubprogram()) return getScope(); return getScope().getContext(); } 00602 unsigned getLineNumber() const { return getScope().getLineNumber(); } 00603 unsigned getColumnNumber() const { return getScope().getColumnNumber(); } 00604 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); } 00605 bool Verify() const; 00606 }; 00607 00608 /// DINameSpace - A wrapper for a C++ style name space. 00609 class DINameSpace : public DIScope { 00610 friend class DIDescriptor; 00611 void printInternal(raw_ostream &OS) const; 00612 public: 00613 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {} 00614 DIScope getContext() const { return getFieldAs<DIScope>(2); } 00615 StringRef getName() const { return getStringField(3); } 00616 unsigned getLineNumber() const { return getUnsignedField(4); } 00617 bool Verify() const; 00618 }; 00619 00620 /// DILocation - This object holds location information. This object 00621 /// is not associated with any DWARF tag. 00622 class DILocation : public DIDescriptor { 00623 public: 00624 explicit DILocation(const MDNode *N) : DIDescriptor(N) { } 00625 00626 unsigned getLineNumber() const { return getUnsignedField(0); } 00627 unsigned getColumnNumber() const { return getUnsignedField(1); } 00628 DIScope getScope() const { return getFieldAs<DIScope>(2); } 00629 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); } 00630 StringRef getFilename() const { return getScope().getFilename(); } 00631 StringRef getDirectory() const { return getScope().getDirectory(); } 00632 bool Verify() const; 00633 }; 00634 00635 class DIObjCProperty : public DIDescriptor { 00636 friend class DIDescriptor; 00637 void printInternal(raw_ostream &OS) const; 00638 public: 00639 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { } 00640 00641 StringRef getObjCPropertyName() const { return getStringField(1); } 00642 DIFile getFile() const { return getFieldAs<DIFile>(2); } 00643 unsigned getLineNumber() const { return getUnsignedField(3); } 00644 00645 StringRef getObjCPropertyGetterName() const { 00646 return getStringField(4); 00647 } 00648 StringRef getObjCPropertySetterName() const { 00649 return getStringField(5); 00650 } 00651 bool isReadOnlyObjCProperty() { 00652 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0; 00653 } 00654 bool isReadWriteObjCProperty() { 00655 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0; 00656 } 00657 bool isAssignObjCProperty() { 00658 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0; 00659 } 00660 bool isRetainObjCProperty() { 00661 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0; 00662 } 00663 bool isCopyObjCProperty() { 00664 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0; 00665 } 00666 bool isNonAtomicObjCProperty() { 00667 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0; 00668 } 00669 00670 DIType getType() const { return getFieldAs<DIType>(7); } 00671 00672 /// Verify - Verify that a derived type descriptor is well formed. 00673 bool Verify() const; 00674 }; 00675 00676 /// \brief An imported module (C++ using directive or similar). 00677 class DIImportedEntity : public DIDescriptor { 00678 friend class DIDescriptor; 00679 void printInternal(raw_ostream &OS) const; 00680 public: 00681 explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) { } 00682 DIScope getContext() const { return getFieldAs<DIScope>(1); } 00683 DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); } 00684 unsigned getLineNumber() const { return getUnsignedField(3); } 00685 StringRef getName() const { return getStringField(4); } 00686 bool Verify() const; 00687 }; 00688 00689 /// getDISubprogram - Find subprogram that is enclosing this scope. 00690 DISubprogram getDISubprogram(const MDNode *Scope); 00691 00692 /// getDICompositeType - Find underlying composite type. 00693 DICompositeType getDICompositeType(DIType T); 00694 00695 /// isSubprogramContext - Return true if Context is either a subprogram 00696 /// or another context nested inside a subprogram. 00697 bool isSubprogramContext(const MDNode *Context); 00698 00699 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable 00700 /// to hold function specific information. 00701 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP); 00702 00703 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is 00704 /// suitable to hold function specific information. 00705 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP); 00706 00707 /// createInlinedVariable - Create a new inlined variable based on current 00708 /// variable. 00709 /// @param DV Current Variable. 00710 /// @param InlinedScope Location at current variable is inlined. 00711 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope, 00712 LLVMContext &VMContext); 00713 00714 /// cleanseInlinedVariable - Remove inlined scope from the variable. 00715 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext); 00716 00717 class DebugInfoFinder { 00718 public: 00719 /// processModule - Process entire module and collect debug info 00720 /// anchors. 00721 void processModule(const Module &M); 00722 00723 private: 00724 /// processType - Process DIType. 00725 void processType(DIType DT); 00726 00727 /// processLexicalBlock - Process DILexicalBlock. 00728 void processLexicalBlock(DILexicalBlock LB); 00729 00730 /// processSubprogram - Process DISubprogram. 00731 void processSubprogram(DISubprogram SP); 00732 00733 /// processDeclare - Process DbgDeclareInst. 00734 void processDeclare(const DbgDeclareInst *DDI); 00735 00736 /// processLocation - Process DILocation. 00737 void processLocation(DILocation Loc); 00738 00739 /// addCompileUnit - Add compile unit into CUs. 00740 bool addCompileUnit(DICompileUnit CU); 00741 00742 /// addGlobalVariable - Add global variable into GVs. 00743 bool addGlobalVariable(DIGlobalVariable DIG); 00744 00745 // addSubprogram - Add subprogram into SPs. 00746 bool addSubprogram(DISubprogram SP); 00747 00748 /// addType - Add type into Tys. 00749 bool addType(DIType DT); 00750 00751 public: 00752 typedef SmallVector<MDNode *, 8>::const_iterator iterator; 00753 iterator compile_unit_begin() const { return CUs.begin(); } 00754 iterator compile_unit_end() const { return CUs.end(); } 00755 iterator subprogram_begin() const { return SPs.begin(); } 00756 iterator subprogram_end() const { return SPs.end(); } 00757 iterator global_variable_begin() const { return GVs.begin(); } 00758 iterator global_variable_end() const { return GVs.end(); } 00759 iterator type_begin() const { return TYs.begin(); } 00760 iterator type_end() const { return TYs.end(); } 00761 00762 unsigned compile_unit_count() const { return CUs.size(); } 00763 unsigned global_variable_count() const { return GVs.size(); } 00764 unsigned subprogram_count() const { return SPs.size(); } 00765 unsigned type_count() const { return TYs.size(); } 00766 00767 private: 00768 SmallVector<MDNode *, 8> CUs; // Compile Units 00769 SmallVector<MDNode *, 8> SPs; // Subprograms 00770 SmallVector<MDNode *, 8> GVs; // Global Variables; 00771 SmallVector<MDNode *, 8> TYs; // Types 00772 SmallPtrSet<MDNode *, 64> NodesSeen; 00773 }; 00774 } // end namespace llvm 00775 00776 #endif