1 //===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a bunch of datatypes that are useful for creating and
11 // walking debug info in LLVM IR form. They essentially provide wrappers around
12 // the information in the global variables that's needed when constructing the
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_DEBUGINFO_H
18 #define LLVM_DEBUGINFO_H
20 #include "llvm/Support/Casting.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/SmallPtrSet.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/Support/Dwarf.h"
47 class DILexicalBlockFile;
53 /// Maps from type identifier to the actual MDNode.
54 typedef DenseMap<const MDString *, MDNode *> DITypeIdentifierMap;
56 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
57 /// This should not be stored in a container, because the underlying MDNode
58 /// may change in certain situations.
60 // Befriends DIRef so DIRef can befriend the protected member
61 // function: getFieldAs<DIRef>.
62 template <typename T> friend class DIRef;
67 FlagProtected = 1 << 1,
69 FlagAppleBlock = 1 << 3,
70 FlagBlockByrefStruct = 1 << 4,
72 FlagArtificial = 1 << 6,
73 FlagExplicit = 1 << 7,
74 FlagPrototyped = 1 << 8,
75 FlagObjcClassComplete = 1 << 9,
76 FlagObjectPointer = 1 << 10,
78 FlagStaticMember = 1 << 12,
79 FlagIndirectVariable = 1 << 13
83 const MDNode *DbgNode;
85 StringRef getStringField(unsigned Elt) const;
86 unsigned getUnsignedField(unsigned Elt) const {
87 return (unsigned)getUInt64Field(Elt);
89 uint64_t getUInt64Field(unsigned Elt) const;
90 int64_t getInt64Field(unsigned Elt) const;
91 DIDescriptor getDescriptorField(unsigned Elt) const;
93 template <typename DescTy> DescTy getFieldAs(unsigned Elt) const {
94 return DescTy(getDescriptorField(Elt));
97 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
98 Constant *getConstantField(unsigned Elt) const;
99 Function *getFunctionField(unsigned Elt) const;
100 void replaceFunctionField(unsigned Elt, Function *F);
103 explicit DIDescriptor(const MDNode *N = 0) : DbgNode(N) {}
107 operator MDNode *() const { return const_cast<MDNode *>(DbgNode); }
108 MDNode *operator->() const { return const_cast<MDNode *>(DbgNode); }
110 // An explicit operator bool so that we can do testing of DI values
112 // FIXME: This operator bool isn't actually protecting anything at the
113 // moment due to the conversion operator above making DIDescriptor nodes
114 // implicitly convertable to bool.
115 LLVM_EXPLICIT operator bool() const { return DbgNode != 0; }
117 bool operator==(DIDescriptor Other) const { return DbgNode == Other.DbgNode; }
118 bool operator!=(DIDescriptor Other) const { return !operator==(Other); }
120 uint16_t getTag() const {
121 return getUnsignedField(0) & ~LLVMDebugVersionMask;
124 bool isDerivedType() const;
125 bool isCompositeType() const;
126 bool isBasicType() const;
127 bool isVariable() const;
128 bool isSubprogram() const;
129 bool isGlobalVariable() const;
130 bool isScope() const;
132 bool isCompileUnit() const;
133 bool isNameSpace() const;
134 bool isLexicalBlockFile() const;
135 bool isLexicalBlock() const;
136 bool isSubrange() const;
137 bool isEnumerator() const;
139 bool isUnspecifiedParameter() const;
140 bool isTemplateTypeParameter() const;
141 bool isTemplateValueParameter() const;
142 bool isObjCProperty() const;
143 bool isImportedEntity() const;
145 /// print - print descriptor.
146 void print(raw_ostream &OS) const;
148 /// dump - print descriptor to dbgs() with a newline.
152 /// DISubrange - This is used to represent ranges, for array bounds.
153 class DISubrange : public DIDescriptor {
154 friend class DIDescriptor;
155 void printInternal(raw_ostream &OS) const;
158 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
160 int64_t getLo() const { return getInt64Field(1); }
161 int64_t getCount() const { return getInt64Field(2); }
165 /// DIArray - This descriptor holds an array of descriptors.
166 class DIArray : public DIDescriptor {
168 explicit DIArray(const MDNode *N = 0) : DIDescriptor(N) {}
170 unsigned getNumElements() const;
171 DIDescriptor getElement(unsigned Idx) const {
172 return getDescriptorField(Idx);
176 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
177 /// FIXME: it seems strange that this doesn't have either a reference to the
178 /// type/precision or a file/line pair for location info.
179 class DIEnumerator : public DIDescriptor {
180 friend class DIDescriptor;
181 void printInternal(raw_ostream &OS) const;
184 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
186 StringRef getName() const { return getStringField(1); }
187 int64_t getEnumValue() const { return getInt64Field(2); }
191 template <typename T> class DIRef;
192 typedef DIRef<DIScope> DIScopeRef;
193 typedef DIRef<DIType> DITypeRef;
195 /// DIScope - A base class for various scopes.
196 class DIScope : public DIDescriptor {
198 friend class DIDescriptor;
199 void printInternal(raw_ostream &OS) const;
202 explicit DIScope(const MDNode *N = 0) : DIDescriptor(N) {}
204 /// Gets the parent scope for this scope node or returns a
205 /// default constructed scope.
206 DIScopeRef getContext() const;
207 StringRef getFilename() const;
208 StringRef getDirectory() const;
210 /// Generate a reference to this DIScope. Uses the type identifier instead
211 /// of the actual MDNode if possible, to help type uniquing.
212 DIScopeRef getRef() const;
215 /// Represents reference to a DIDescriptor, abstracts over direct and
216 /// identifier-based metadata references.
217 template <typename T> class DIRef {
218 template <typename DescTy>
219 friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;
220 friend DIScopeRef DIScope::getContext() const;
221 friend DIScopeRef DIScope::getRef() const;
223 /// Val can be either a MDNode or a MDString, in the latter,
224 /// MDString specifies the type identifier.
226 explicit DIRef(const Value *V);
229 T resolve(const DITypeIdentifierMap &Map) const {
233 if (const MDNode *MD = dyn_cast<MDNode>(Val))
236 const MDString *MS = cast<MDString>(Val);
237 // Find the corresponding MDNode.
238 DITypeIdentifierMap::const_iterator Iter = Map.find(MS);
239 assert(Iter != Map.end() && "Identifier not in the type map?");
240 assert(DIDescriptor(Iter->second).isType() &&
241 "MDNode in DITypeIdentifierMap should be a DIType.");
242 return T(Iter->second);
244 operator Value *() const { return const_cast<Value *>(Val); }
247 /// Specialize getFieldAs to handle fields that are references to DIScopes.
248 template <> DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const;
249 /// Specialize DIRef constructor for DIScopeRef.
250 template <> DIRef<DIScope>::DIRef(const Value *V);
252 /// Specialize getFieldAs to handle fields that are references to DITypes.
253 template <> DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const;
254 /// Specialize DIRef constructor for DITypeRef.
255 template <> DIRef<DIType>::DIRef(const Value *V);
257 /// DIType - This is a wrapper for a type.
258 /// FIXME: Types should be factored much better so that CV qualifiers and
259 /// others do not require a huge and empty descriptor full of zeros.
260 class DIType : public DIScope {
262 friend class DIDescriptor;
263 void printInternal(raw_ostream &OS) const;
266 DIType(const MDNode *N = 0) : DIScope(N) {}
268 /// Verify - Verify that a type descriptor is well formed.
271 DIScopeRef getContext() const { return getFieldAs<DIScopeRef>(2); }
272 StringRef getName() const { return getStringField(3); }
273 unsigned getLineNumber() const { return getUnsignedField(4); }
274 uint64_t getSizeInBits() const { return getUInt64Field(5); }
275 uint64_t getAlignInBits() const { return getUInt64Field(6); }
276 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
277 // carry this is just plain insane.
278 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
279 unsigned getFlags() const { return getUnsignedField(8); }
280 bool isPrivate() const { return (getFlags() & FlagPrivate) != 0; }
281 bool isProtected() const { return (getFlags() & FlagProtected) != 0; }
282 bool isForwardDecl() const { return (getFlags() & FlagFwdDecl) != 0; }
283 // isAppleBlock - Return true if this is the Apple Blocks extension.
284 bool isAppleBlockExtension() const {
285 return (getFlags() & FlagAppleBlock) != 0;
287 bool isBlockByrefStruct() const {
288 return (getFlags() & FlagBlockByrefStruct) != 0;
290 bool isVirtual() const { return (getFlags() & FlagVirtual) != 0; }
291 bool isArtificial() const { return (getFlags() & FlagArtificial) != 0; }
292 bool isObjectPointer() const { return (getFlags() & FlagObjectPointer) != 0; }
293 bool isObjcClassComplete() const {
294 return (getFlags() & FlagObjcClassComplete) != 0;
296 bool isVector() const { return (getFlags() & FlagVector) != 0; }
297 bool isStaticMember() const { return (getFlags() & FlagStaticMember) != 0; }
298 bool isValid() const { return DbgNode && isType(); }
300 /// isUnsignedDIType - Return true if type encoding is unsigned.
301 bool isUnsignedDIType();
303 /// replaceAllUsesWith - Replace all uses of debug info referenced by
305 void replaceAllUsesWith(DIDescriptor &D);
306 void replaceAllUsesWith(MDNode *D);
309 /// DIBasicType - A basic type, like 'int' or 'float'.
310 class DIBasicType : public DIType {
312 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
314 unsigned getEncoding() const { return getUnsignedField(9); }
316 /// Verify - Verify that a basic type descriptor is well formed.
320 /// DIDerivedType - A simple derived type, like a const qualified type,
321 /// a typedef, a pointer or reference, et cetera. Or, a data member of
322 /// a class/struct/union.
323 class DIDerivedType : public DIType {
324 friend class DIDescriptor;
325 void printInternal(raw_ostream &OS) const;
328 explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
330 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
332 /// getOriginalTypeSize - If this type is derived from a base type then
333 /// return base type size.
334 uint64_t getOriginalTypeSize() const;
336 /// getObjCProperty - Return property node, if this ivar is
337 /// associated with one.
338 MDNode *getObjCProperty() const;
340 DITypeRef getClassType() const {
341 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
342 return getFieldAs<DITypeRef>(10);
345 Constant *getConstant() const {
346 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
347 return getConstantField(10);
350 /// Verify - Verify that a derived type descriptor is well formed.
354 /// DICompositeType - This descriptor holds a type that can refer to multiple
355 /// other types, like a function or struct.
356 /// DICompositeType is derived from DIDerivedType because some
357 /// composite types (such as enums) can be derived from basic types
358 // FIXME: Make this derive from DIType directly & just store the
359 // base type in a single DIType field.
360 class DICompositeType : public DIDerivedType {
361 friend class DIDescriptor;
362 void printInternal(raw_ostream &OS) const;
365 explicit DICompositeType(const MDNode *N = 0) : DIDerivedType(N) {}
367 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
368 void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
369 void addMember(DIDescriptor D);
370 unsigned getRunTimeLang() const { return getUnsignedField(11); }
371 DITypeRef getContainingType() const { return getFieldAs<DITypeRef>(12); }
372 void setContainingType(DICompositeType ContainingType);
373 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
374 MDString *getIdentifier() const;
376 /// Verify - Verify that a composite type descriptor is well formed.
380 /// DIFile - This is a wrapper for a file.
381 class DIFile : public DIScope {
382 friend class DIDescriptor;
385 explicit DIFile(const MDNode *N = 0) : DIScope(N) {}
386 MDNode *getFileNode() const;
390 /// DICompileUnit - A wrapper for a compile unit.
391 class DICompileUnit : public DIScope {
392 friend class DIDescriptor;
393 void printInternal(raw_ostream &OS) const;
396 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
398 unsigned getLanguage() const { return getUnsignedField(2); }
399 StringRef getProducer() const { return getStringField(3); }
401 bool isOptimized() const { return getUnsignedField(4) != 0; }
402 StringRef getFlags() const { return getStringField(5); }
403 unsigned getRunTimeVersion() const { return getUnsignedField(6); }
405 DIArray getEnumTypes() const;
406 DIArray getRetainedTypes() const;
407 DIArray getSubprograms() const;
408 DIArray getGlobalVariables() const;
409 DIArray getImportedEntities() const;
411 StringRef getSplitDebugFilename() const { return getStringField(12); }
413 /// Verify - Verify that a compile unit is well formed.
417 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
418 class DISubprogram : public DIScope {
419 friend class DIDescriptor;
420 void printInternal(raw_ostream &OS) const;
423 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
425 DIScope getContext() const { return getFieldAs<DIScope>(2); }
426 StringRef getName() const { return getStringField(3); }
427 StringRef getDisplayName() const { return getStringField(4); }
428 StringRef getLinkageName() const { return getStringField(5); }
429 unsigned getLineNumber() const { return getUnsignedField(6); }
430 DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
432 /// isLocalToUnit - Return true if this subprogram is local to the current
433 /// compile unit, like 'static' in C.
434 unsigned isLocalToUnit() const { return getUnsignedField(8); }
435 unsigned isDefinition() const { return getUnsignedField(9); }
437 unsigned getVirtuality() const { return getUnsignedField(10); }
438 unsigned getVirtualIndex() const { return getUnsignedField(11); }
440 DITypeRef getContainingType() const { return getFieldAs<DITypeRef>(12); }
442 unsigned getFlags() const { return getUnsignedField(13); }
444 unsigned isArtificial() const {
445 return (getUnsignedField(13) & FlagArtificial) != 0;
447 /// isPrivate - Return true if this subprogram has "private"
448 /// access specifier.
449 bool isPrivate() const { return (getUnsignedField(13) & FlagPrivate) != 0; }
450 /// isProtected - Return true if this subprogram has "protected"
451 /// access specifier.
452 bool isProtected() const {
453 return (getUnsignedField(13) & FlagProtected) != 0;
455 /// isExplicit - Return true if this subprogram is marked as explicit.
456 bool isExplicit() const { return (getUnsignedField(13) & FlagExplicit) != 0; }
457 /// isPrototyped - Return true if this subprogram is prototyped.
458 bool isPrototyped() const {
459 return (getUnsignedField(13) & FlagPrototyped) != 0;
462 unsigned isOptimized() const;
464 /// Verify - Verify that a subprogram descriptor is well formed.
467 /// describes - Return true if this subprogram provides debugging
468 /// information for the function F.
469 bool describes(const Function *F);
471 Function *getFunction() const { return getFunctionField(15); }
472 void replaceFunction(Function *F) { replaceFunctionField(15, F); }
473 DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
474 DISubprogram getFunctionDeclaration() const {
475 return getFieldAs<DISubprogram>(17);
477 MDNode *getVariablesNodes() const;
478 DIArray getVariables() const;
480 /// getScopeLineNumber - Get the beginning of the scope of the
481 /// function, not necessarily where the name of the program
483 unsigned getScopeLineNumber() const { return getUnsignedField(19); }
486 /// DILexicalBlock - This is a wrapper for a lexical block.
487 class DILexicalBlock : public DIScope {
489 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
490 DIScope getContext() const { return getFieldAs<DIScope>(2); }
491 unsigned getLineNumber() const { return getUnsignedField(3); }
492 unsigned getColumnNumber() const { return getUnsignedField(4); }
496 /// DILexicalBlockFile - This is a wrapper for a lexical block with
497 /// a filename change.
498 class DILexicalBlockFile : public DIScope {
500 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
501 DIScope getContext() const {
502 if (getScope().isSubprogram())
504 return getScope().getContext();
506 unsigned getLineNumber() const { return getScope().getLineNumber(); }
507 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
508 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
512 /// DINameSpace - A wrapper for a C++ style name space.
513 class DINameSpace : public DIScope {
514 friend class DIDescriptor;
515 void printInternal(raw_ostream &OS) const;
518 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
519 DIScope getContext() const { return getFieldAs<DIScope>(2); }
520 StringRef getName() const { return getStringField(3); }
521 unsigned getLineNumber() const { return getUnsignedField(4); }
525 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
526 class DITemplateTypeParameter : public DIDescriptor {
528 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
530 DIScope getContext() const { return getFieldAs<DIScope>(1); }
531 StringRef getName() const { return getStringField(2); }
532 DIType getType() const { return getFieldAs<DIType>(3); }
533 StringRef getFilename() const { return getFieldAs<DIFile>(4).getFilename(); }
534 StringRef getDirectory() const {
535 return getFieldAs<DIFile>(4).getDirectory();
537 unsigned getLineNumber() const { return getUnsignedField(5); }
538 unsigned getColumnNumber() const { return getUnsignedField(6); }
542 /// DITemplateValueParameter - This is a wrapper for template value parameter.
543 class DITemplateValueParameter : public DIDescriptor {
545 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
547 DIScope getContext() const { return getFieldAs<DIScope>(1); }
548 StringRef getName() const { return getStringField(2); }
549 DIType getType() const { return getFieldAs<DIType>(3); }
550 Value *getValue() const;
551 StringRef getFilename() const { return getFieldAs<DIFile>(5).getFilename(); }
552 StringRef getDirectory() const {
553 return getFieldAs<DIFile>(5).getDirectory();
555 unsigned getLineNumber() const { return getUnsignedField(6); }
556 unsigned getColumnNumber() const { return getUnsignedField(7); }
560 /// DIGlobalVariable - This is a wrapper for a global variable.
561 class DIGlobalVariable : public DIDescriptor {
562 friend class DIDescriptor;
563 void printInternal(raw_ostream &OS) const;
566 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
568 DIScope getContext() const { return getFieldAs<DIScope>(2); }
569 StringRef getName() const { return getStringField(3); }
570 StringRef getDisplayName() const { return getStringField(4); }
571 StringRef getLinkageName() const { return getStringField(5); }
572 StringRef getFilename() const { return getFieldAs<DIFile>(6).getFilename(); }
573 StringRef getDirectory() const {
574 return getFieldAs<DIFile>(6).getDirectory();
577 unsigned getLineNumber() const { return getUnsignedField(7); }
578 DIType getType() const { return getFieldAs<DIType>(8); }
579 unsigned isLocalToUnit() const { return getUnsignedField(9); }
580 unsigned isDefinition() const { return getUnsignedField(10); }
582 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
583 Constant *getConstant() const { return getConstantField(11); }
584 DIDerivedType getStaticDataMemberDeclaration() const {
585 return getFieldAs<DIDerivedType>(12);
588 /// Verify - Verify that a global variable descriptor is well formed.
592 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
594 class DIVariable : public DIDescriptor {
595 friend class DIDescriptor;
596 void printInternal(raw_ostream &OS) const;
599 explicit DIVariable(const MDNode *N = 0) : DIDescriptor(N) {}
601 DIScope getContext() const { return getFieldAs<DIScope>(1); }
602 StringRef getName() const { return getStringField(2); }
603 DIFile getFile() const { return getFieldAs<DIFile>(3); }
604 unsigned getLineNumber() const { return (getUnsignedField(4) << 8) >> 8; }
605 unsigned getArgNumber() const {
606 unsigned L = getUnsignedField(4);
609 DIType getType() const { return getFieldAs<DIType>(5); }
611 /// isArtificial - Return true if this variable is marked as "artificial".
612 bool isArtificial() const {
613 return (getUnsignedField(6) & FlagArtificial) != 0;
616 bool isObjectPointer() const {
617 return (getUnsignedField(6) & FlagObjectPointer) != 0;
620 /// \brief Return true if this variable is represented as a pointer.
621 bool isIndirect() const {
622 return (getUnsignedField(6) & FlagIndirectVariable) != 0;
625 /// getInlinedAt - If this variable is inlined then return inline location.
626 MDNode *getInlinedAt() const;
628 /// Verify - Verify that a variable descriptor is well formed.
631 /// HasComplexAddr - Return true if the variable has a complex address.
632 bool hasComplexAddress() const { return getNumAddrElements() > 0; }
634 unsigned getNumAddrElements() const;
636 uint64_t getAddrElement(unsigned Idx) const {
637 return getUInt64Field(Idx + 8);
640 /// isBlockByrefVariable - Return true if the variable was declared as
641 /// a "__block" variable (Apple Blocks).
642 bool isBlockByrefVariable() const { return getType().isBlockByrefStruct(); }
644 /// isInlinedFnArgument - Return true if this variable provides debugging
645 /// information for an inlined function arguments.
646 bool isInlinedFnArgument(const Function *CurFn);
648 void printExtendedName(raw_ostream &OS) const;
651 /// DILocation - This object holds location information. This object
652 /// is not associated with any DWARF tag.
653 class DILocation : public DIDescriptor {
655 explicit DILocation(const MDNode *N) : DIDescriptor(N) {}
657 unsigned getLineNumber() const { return getUnsignedField(0); }
658 unsigned getColumnNumber() const { return getUnsignedField(1); }
659 DIScope getScope() const { return getFieldAs<DIScope>(2); }
660 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
661 StringRef getFilename() const { return getScope().getFilename(); }
662 StringRef getDirectory() const { return getScope().getDirectory(); }
666 class DIObjCProperty : public DIDescriptor {
667 friend class DIDescriptor;
668 void printInternal(raw_ostream &OS) const;
671 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) {}
673 StringRef getObjCPropertyName() const { return getStringField(1); }
674 DIFile getFile() const { return getFieldAs<DIFile>(2); }
675 unsigned getLineNumber() const { return getUnsignedField(3); }
677 StringRef getObjCPropertyGetterName() const { return getStringField(4); }
678 StringRef getObjCPropertySetterName() const { return getStringField(5); }
679 bool isReadOnlyObjCProperty() const {
680 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
682 bool isReadWriteObjCProperty() const {
683 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
685 bool isAssignObjCProperty() const {
686 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
688 bool isRetainObjCProperty() const {
689 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
691 bool isCopyObjCProperty() const {
692 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
694 bool isNonAtomicObjCProperty() const {
695 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
698 DIType getType() const { return getFieldAs<DIType>(7); }
700 /// Verify - Verify that a derived type descriptor is well formed.
704 /// \brief An imported module (C++ using directive or similar).
705 class DIImportedEntity : public DIDescriptor {
706 friend class DIDescriptor;
707 void printInternal(raw_ostream &OS) const;
710 explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) {}
711 DIScope getContext() const { return getFieldAs<DIScope>(1); }
712 DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
713 unsigned getLineNumber() const { return getUnsignedField(3); }
714 StringRef getName() const { return getStringField(4); }
718 /// getDISubprogram - Find subprogram that is enclosing this scope.
719 DISubprogram getDISubprogram(const MDNode *Scope);
721 /// getDICompositeType - Find underlying composite type.
722 DICompositeType getDICompositeType(DIType T);
724 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
725 /// to hold function specific information.
726 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
728 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
729 /// suitable to hold function specific information.
730 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
732 /// createInlinedVariable - Create a new inlined variable based on current
734 /// @param DV Current Variable.
735 /// @param InlinedScope Location at current variable is inlined.
736 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
737 LLVMContext &VMContext);
739 /// cleanseInlinedVariable - Remove inlined scope from the variable.
740 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
742 /// Construct DITypeIdentifierMap by going through retained types of each CU.
743 DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
745 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
746 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
747 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
748 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
749 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
751 class DebugInfoFinder {
753 /// processModule - Process entire module and collect debug info
755 void processModule(const Module &M);
757 /// processDeclare - Process DbgDeclareInst.
758 void processDeclare(const DbgDeclareInst *DDI);
759 /// Process DbgValueInst.
760 void processValue(const DbgValueInst *DVI);
761 /// processLocation - Process DILocation.
762 void processLocation(DILocation Loc);
768 /// processType - Process DIType.
769 void processType(DIType DT);
771 /// processLexicalBlock - Process DILexicalBlock.
772 void processLexicalBlock(DILexicalBlock LB);
774 /// processSubprogram - Process DISubprogram.
775 void processSubprogram(DISubprogram SP);
777 void processScope(DIScope Scope);
779 /// addCompileUnit - Add compile unit into CUs.
780 bool addCompileUnit(DICompileUnit CU);
782 /// addGlobalVariable - Add global variable into GVs.
783 bool addGlobalVariable(DIGlobalVariable DIG);
785 // addSubprogram - Add subprogram into SPs.
786 bool addSubprogram(DISubprogram SP);
788 /// addType - Add type into Tys.
789 bool addType(DIType DT);
791 bool addScope(DIScope Scope);
794 typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
795 iterator compile_unit_begin() const { return CUs.begin(); }
796 iterator compile_unit_end() const { return CUs.end(); }
797 iterator subprogram_begin() const { return SPs.begin(); }
798 iterator subprogram_end() const { return SPs.end(); }
799 iterator global_variable_begin() const { return GVs.begin(); }
800 iterator global_variable_end() const { return GVs.end(); }
801 iterator type_begin() const { return TYs.begin(); }
802 iterator type_end() const { return TYs.end(); }
803 iterator scope_begin() const { return Scopes.begin(); }
804 iterator scope_end() const { return Scopes.end(); }
806 unsigned compile_unit_count() const { return CUs.size(); }
807 unsigned global_variable_count() const { return GVs.size(); }
808 unsigned subprogram_count() const { return SPs.size(); }
809 unsigned type_count() const { return TYs.size(); }
810 unsigned scope_count() const { return Scopes.size(); }
813 SmallVector<MDNode *, 8> CUs; // Compile Units
814 SmallVector<MDNode *, 8> SPs; // Subprograms
815 SmallVector<MDNode *, 8> GVs; // Global Variables;
816 SmallVector<MDNode *, 8> TYs; // Types
817 SmallVector<MDNode *, 8> Scopes; // Scopes
818 SmallPtrSet<MDNode *, 64> NodesSeen;
819 DITypeIdentifierMap TypeIdentifierMap;
821 } // end namespace llvm