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>.
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
82 const MDNode *DbgNode;
84 StringRef getStringField(unsigned Elt) const;
85 unsigned getUnsignedField(unsigned Elt) const {
86 return (unsigned)getUInt64Field(Elt);
88 uint64_t getUInt64Field(unsigned Elt) const;
89 int64_t getInt64Field(unsigned Elt) const;
90 DIDescriptor getDescriptorField(unsigned Elt) const;
92 template <typename DescTy>
93 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 {
118 return DbgNode == Other.DbgNode;
120 bool operator!=(DIDescriptor Other) const {
121 return !operator==(Other);
124 uint16_t getTag() const {
125 return getUnsignedField(0) & ~LLVMDebugVersionMask;
128 bool isDerivedType() const;
129 bool isCompositeType() const;
130 bool isBasicType() const;
131 bool isVariable() const;
132 bool isSubprogram() const;
133 bool isGlobalVariable() const;
134 bool isScope() const;
136 bool isCompileUnit() const;
137 bool isNameSpace() const;
138 bool isLexicalBlockFile() const;
139 bool isLexicalBlock() const;
140 bool isSubrange() const;
141 bool isEnumerator() const;
143 bool isUnspecifiedParameter() const;
144 bool isTemplateTypeParameter() const;
145 bool isTemplateValueParameter() const;
146 bool isObjCProperty() const;
147 bool isImportedEntity() const;
149 /// print - print descriptor.
150 void print(raw_ostream &OS) const;
152 /// dump - print descriptor to dbgs() with a newline.
156 /// DISubrange - This is used to represent ranges, for array bounds.
157 class DISubrange : public DIDescriptor {
158 friend class DIDescriptor;
159 void printInternal(raw_ostream &OS) const;
161 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
163 int64_t getLo() const { return getInt64Field(1); }
164 int64_t getCount() const { return getInt64Field(2); }
168 /// DIArray - This descriptor holds an array of descriptors.
169 class DIArray : public DIDescriptor {
171 explicit DIArray(const MDNode *N = 0) : DIDescriptor(N) {}
173 unsigned getNumElements() const;
174 DIDescriptor getElement(unsigned Idx) const {
175 return getDescriptorField(Idx);
179 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
180 /// FIXME: it seems strange that this doesn't have either a reference to the
181 /// type/precision or a file/line pair for location info.
182 class DIEnumerator : public DIDescriptor {
183 friend class DIDescriptor;
184 void printInternal(raw_ostream &OS) const;
186 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
188 StringRef getName() const { return getStringField(1); }
189 int64_t getEnumValue() const { return getInt64Field(2); }
193 template <typename T>
195 typedef DIRef<DIScope> DIScopeRef;
196 typedef DIRef<DIType> DITypeRef;
198 /// DIScope - A base class for various scopes.
199 class DIScope : public DIDescriptor {
201 friend class DIDescriptor;
202 void printInternal(raw_ostream &OS) const;
204 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
206 /// Gets the parent scope for this scope node or returns a
207 /// default constructed scope.
208 DIScopeRef getContext() const;
209 StringRef getFilename() const;
210 StringRef getDirectory() const;
212 /// Generate a reference to this DIScope. Uses the type identifier instead
213 /// of the actual MDNode if possible, to help type uniquing.
214 DIScopeRef getRef() const;
217 /// Represents reference to a DIDescriptor, abstracts over direct and
218 /// identifier-based metadata references.
219 template <typename T>
221 template <typename DescTy>
222 friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;
223 friend DIScopeRef DIScope::getContext() const;
224 friend DIScopeRef DIScope::getRef() const;
226 /// Val can be either a MDNode or a MDString, in the latter,
227 /// MDString specifies the type identifier.
229 explicit DIRef(const Value *V);
231 T resolve(const DITypeIdentifierMap &Map) const {
235 if (const MDNode *MD = dyn_cast<MDNode>(Val))
238 const MDString *MS = cast<MDString>(Val);
239 // Find the corresponding MDNode.
240 DITypeIdentifierMap::const_iterator Iter = Map.find(MS);
241 assert(Iter != Map.end() && "Identifier not in the type map?");
242 assert(DIDescriptor(Iter->second).isType() &&
243 "MDNode in DITypeIdentifierMap should be a DIType.");
244 return T(Iter->second);
246 operator Value *() const { return const_cast<Value*>(Val); }
249 /// Specialize getFieldAs to handle fields that are references to DIScopes.
251 DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const;
252 /// Specialize DIRef constructor for DIScopeRef.
254 DIRef<DIScope>::DIRef(const Value *V);
256 /// Specialize getFieldAs to handle fields that are references to DITypes.
258 DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const;
259 /// Specialize DIRef constructor for DITypeRef.
261 DIRef<DIType>::DIRef(const Value *V);
263 /// DIType - This is a wrapper for a type.
264 /// FIXME: Types should be factored much better so that CV qualifiers and
265 /// others do not require a huge and empty descriptor full of zeros.
266 class DIType : public DIScope {
268 friend class DIDescriptor;
269 void printInternal(raw_ostream &OS) const;
272 DIType(const MDNode *N = 0) : DIScope(N) {}
274 /// Verify - Verify that a type descriptor is well formed.
277 DIScopeRef getContext() const { return getFieldAs<DIScopeRef>(2); }
278 StringRef getName() const { return getStringField(3); }
279 unsigned getLineNumber() const { return getUnsignedField(4); }
280 uint64_t getSizeInBits() const { return getUInt64Field(5); }
281 uint64_t getAlignInBits() const { return getUInt64Field(6); }
282 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
283 // carry this is just plain insane.
284 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
285 unsigned getFlags() const { return getUnsignedField(8); }
286 bool isPrivate() const {
287 return (getFlags() & FlagPrivate) != 0;
289 bool isProtected() const {
290 return (getFlags() & FlagProtected) != 0;
292 bool isForwardDecl() const {
293 return (getFlags() & FlagFwdDecl) != 0;
295 // isAppleBlock - Return true if this is the Apple Blocks extension.
296 bool isAppleBlockExtension() const {
297 return (getFlags() & FlagAppleBlock) != 0;
299 bool isBlockByrefStruct() const {
300 return (getFlags() & FlagBlockByrefStruct) != 0;
302 bool isVirtual() const {
303 return (getFlags() & FlagVirtual) != 0;
305 bool isArtificial() const {
306 return (getFlags() & FlagArtificial) != 0;
308 bool isObjectPointer() const {
309 return (getFlags() & FlagObjectPointer) != 0;
311 bool isObjcClassComplete() const {
312 return (getFlags() & FlagObjcClassComplete) != 0;
314 bool isVector() const {
315 return (getFlags() & FlagVector) != 0;
317 bool isStaticMember() const {
318 return (getFlags() & FlagStaticMember) != 0;
320 bool isValid() const {
321 return DbgNode && isType();
324 /// isUnsignedDIType - Return true if type encoding is unsigned.
325 bool isUnsignedDIType();
327 /// replaceAllUsesWith - Replace all uses of debug info referenced by
329 void replaceAllUsesWith(DIDescriptor &D);
330 void replaceAllUsesWith(MDNode *D);
333 /// DIBasicType - A basic type, like 'int' or 'float'.
334 class DIBasicType : public DIType {
336 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
338 unsigned getEncoding() const { return getUnsignedField(9); }
340 /// Verify - Verify that a basic type descriptor is well formed.
344 /// DIDerivedType - A simple derived type, like a const qualified type,
345 /// a typedef, a pointer or reference, et cetera. Or, a data member of
346 /// a class/struct/union.
347 class DIDerivedType : public DIType {
348 friend class DIDescriptor;
349 void printInternal(raw_ostream &OS) const;
352 explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
354 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
356 /// getOriginalTypeSize - If this type is derived from a base type then
357 /// return base type size.
358 uint64_t getOriginalTypeSize() const;
360 /// getObjCProperty - Return property node, if this ivar is
361 /// associated with one.
362 MDNode *getObjCProperty() const;
364 DITypeRef getClassType() const {
365 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
366 return getFieldAs<DITypeRef>(10);
369 Constant *getConstant() const {
370 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
371 return getConstantField(10);
374 /// Verify - Verify that a derived type descriptor is well formed.
378 /// DICompositeType - This descriptor holds a type that can refer to multiple
379 /// other types, like a function or struct.
380 /// DICompositeType is derived from DIDerivedType because some
381 /// composite types (such as enums) can be derived from basic types
382 // FIXME: Make this derive from DIType directly & just store the
383 // base type in a single DIType field.
384 class DICompositeType : public DIDerivedType {
385 friend class DIDescriptor;
386 void printInternal(raw_ostream &OS) const;
388 explicit DICompositeType(const MDNode *N = 0) : DIDerivedType(N) {}
390 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
391 void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
392 void addMember(DIDescriptor D);
393 unsigned getRunTimeLang() const { return getUnsignedField(11); }
394 DITypeRef getContainingType() const {
395 return getFieldAs<DITypeRef>(12);
397 void setContainingType(DICompositeType ContainingType);
398 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
399 MDString *getIdentifier() const;
401 /// Verify - Verify that a composite type descriptor is well formed.
405 /// DIFile - This is a wrapper for a file.
406 class DIFile : public DIScope {
407 friend class DIDescriptor;
409 explicit DIFile(const MDNode *N = 0) : DIScope(N) {}
410 MDNode *getFileNode() const;
414 /// DICompileUnit - A wrapper for a compile unit.
415 class DICompileUnit : public DIScope {
416 friend class DIDescriptor;
417 void printInternal(raw_ostream &OS) const;
419 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
421 unsigned getLanguage() const { return getUnsignedField(2); }
422 StringRef getProducer() const { return getStringField(3); }
424 bool isOptimized() const { return getUnsignedField(4) != 0; }
425 StringRef getFlags() const { return getStringField(5); }
426 unsigned getRunTimeVersion() const { return getUnsignedField(6); }
428 DIArray getEnumTypes() const;
429 DIArray getRetainedTypes() const;
430 DIArray getSubprograms() const;
431 DIArray getGlobalVariables() const;
432 DIArray getImportedEntities() const;
434 StringRef getSplitDebugFilename() const { return getStringField(12); }
436 /// Verify - Verify that a compile unit is well formed.
440 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
441 class DISubprogram : public DIScope {
442 friend class DIDescriptor;
443 void printInternal(raw_ostream &OS) const;
445 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
447 DIScope getContext() const { return getFieldAs<DIScope>(2); }
448 StringRef getName() const { return getStringField(3); }
449 StringRef getDisplayName() const { return getStringField(4); }
450 StringRef getLinkageName() const { return getStringField(5); }
451 unsigned getLineNumber() const { return getUnsignedField(6); }
452 DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
454 /// isLocalToUnit - Return true if this subprogram is local to the current
455 /// compile unit, like 'static' in C.
456 unsigned isLocalToUnit() const { return getUnsignedField(8); }
457 unsigned isDefinition() const { return getUnsignedField(9); }
459 unsigned getVirtuality() const { return getUnsignedField(10); }
460 unsigned getVirtualIndex() const { return getUnsignedField(11); }
462 DITypeRef getContainingType() const {
463 return getFieldAs<DITypeRef>(12);
466 unsigned getFlags() const {
467 return getUnsignedField(13);
470 unsigned isArtificial() const {
471 return (getUnsignedField(13) & FlagArtificial) != 0;
473 /// isPrivate - Return true if this subprogram has "private"
474 /// access specifier.
475 bool isPrivate() const {
476 return (getUnsignedField(13) & FlagPrivate) != 0;
478 /// isProtected - Return true if this subprogram has "protected"
479 /// access specifier.
480 bool isProtected() const {
481 return (getUnsignedField(13) & FlagProtected) != 0;
483 /// isExplicit - Return true if this subprogram is marked as explicit.
484 bool isExplicit() const {
485 return (getUnsignedField(13) & FlagExplicit) != 0;
487 /// isPrototyped - Return true if this subprogram is prototyped.
488 bool isPrototyped() const {
489 return (getUnsignedField(13) & FlagPrototyped) != 0;
492 unsigned isOptimized() const;
494 /// Verify - Verify that a subprogram descriptor is well formed.
497 /// describes - Return true if this subprogram provides debugging
498 /// information for the function F.
499 bool describes(const Function *F);
501 Function *getFunction() const { return getFunctionField(15); }
502 void replaceFunction(Function *F) { replaceFunctionField(15, F); }
503 DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
504 DISubprogram getFunctionDeclaration() const {
505 return getFieldAs<DISubprogram>(17);
507 MDNode *getVariablesNodes() const;
508 DIArray getVariables() const;
510 /// getScopeLineNumber - Get the beginning of the scope of the
511 /// function, not necessarily where the name of the program
513 unsigned getScopeLineNumber() const { return getUnsignedField(19); }
516 /// DILexicalBlock - This is a wrapper for a lexical block.
517 class DILexicalBlock : public DIScope {
519 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
520 DIScope getContext() const { return getFieldAs<DIScope>(2); }
521 unsigned getLineNumber() const { return getUnsignedField(3); }
522 unsigned getColumnNumber() const { return getUnsignedField(4); }
526 /// DILexicalBlockFile - This is a wrapper for a lexical block with
527 /// a filename change.
528 class DILexicalBlockFile : public DIScope {
530 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
531 DIScope getContext() const {
532 if (getScope().isSubprogram())
534 return getScope().getContext();
536 unsigned getLineNumber() const { return getScope().getLineNumber(); }
537 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
538 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
542 /// DINameSpace - A wrapper for a C++ style name space.
543 class DINameSpace : public DIScope {
544 friend class DIDescriptor;
545 void printInternal(raw_ostream &OS) const;
547 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
548 DIScope getContext() const { return getFieldAs<DIScope>(2); }
549 StringRef getName() const { return getStringField(3); }
550 unsigned getLineNumber() const { return getUnsignedField(4); }
554 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
555 class DITemplateTypeParameter : public DIDescriptor {
557 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
559 DIScope getContext() const { return getFieldAs<DIScope>(1); }
560 StringRef getName() const { return getStringField(2); }
561 DIType getType() const { return getFieldAs<DIType>(3); }
562 StringRef getFilename() const {
563 return getFieldAs<DIFile>(4).getFilename();
565 StringRef getDirectory() const {
566 return getFieldAs<DIFile>(4).getDirectory();
568 unsigned getLineNumber() const { return getUnsignedField(5); }
569 unsigned getColumnNumber() const { return getUnsignedField(6); }
573 /// DITemplateValueParameter - This is a wrapper for template value parameter.
574 class DITemplateValueParameter : public DIDescriptor {
576 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
578 DIScope getContext() const { return getFieldAs<DIScope>(1); }
579 StringRef getName() const { return getStringField(2); }
580 DIType getType() const { return getFieldAs<DIType>(3); }
581 Value *getValue() const;
582 StringRef getFilename() const {
583 return getFieldAs<DIFile>(5).getFilename();
585 StringRef getDirectory() const {
586 return getFieldAs<DIFile>(5).getDirectory();
588 unsigned getLineNumber() const { return getUnsignedField(6); }
589 unsigned getColumnNumber() const { return getUnsignedField(7); }
593 /// DIGlobalVariable - This is a wrapper for a global variable.
594 class DIGlobalVariable : public DIDescriptor {
595 friend class DIDescriptor;
596 void printInternal(raw_ostream &OS) const;
598 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
600 DIScope getContext() const { return getFieldAs<DIScope>(2); }
601 StringRef getName() const { return getStringField(3); }
602 StringRef getDisplayName() const { return getStringField(4); }
603 StringRef getLinkageName() const { return getStringField(5); }
604 StringRef getFilename() const {
605 return getFieldAs<DIFile>(6).getFilename();
607 StringRef getDirectory() const {
608 return getFieldAs<DIFile>(6).getDirectory();
612 unsigned getLineNumber() const { return getUnsignedField(7); }
613 DIType getType() const { return getFieldAs<DIType>(8); }
614 unsigned isLocalToUnit() const { return getUnsignedField(9); }
615 unsigned isDefinition() const { return getUnsignedField(10); }
617 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
618 Constant *getConstant() const { return getConstantField(11); }
619 DIDerivedType getStaticDataMemberDeclaration() const {
620 return getFieldAs<DIDerivedType>(12);
623 /// Verify - Verify that a global variable descriptor is well formed.
627 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
629 class DIVariable : public DIDescriptor {
630 friend class DIDescriptor;
631 void printInternal(raw_ostream &OS) const;
633 explicit DIVariable(const MDNode *N = 0) : DIDescriptor(N) {}
635 DIScope getContext() const { return getFieldAs<DIScope>(1); }
636 StringRef getName() const { return getStringField(2); }
637 DIFile getFile() const { return getFieldAs<DIFile>(3); }
638 unsigned getLineNumber() const {
639 return (getUnsignedField(4) << 8) >> 8;
641 unsigned getArgNumber() const {
642 unsigned L = getUnsignedField(4);
645 DIType getType() const { return getFieldAs<DIType>(5); }
647 /// isArtificial - Return true if this variable is marked as "artificial".
648 bool isArtificial() const {
649 return (getUnsignedField(6) & FlagArtificial) != 0;
652 bool isObjectPointer() const {
653 return (getUnsignedField(6) & FlagObjectPointer) != 0;
656 /// \brief Return true if this variable is represented as a pointer.
657 bool isIndirect() const {
658 return (getUnsignedField(6) & FlagIndirectVariable) != 0;
661 /// getInlinedAt - If this variable is inlined then return inline location.
662 MDNode *getInlinedAt() const;
664 /// Verify - Verify that a variable descriptor is well formed.
667 /// HasComplexAddr - Return true if the variable has a complex address.
668 bool hasComplexAddress() const {
669 return getNumAddrElements() > 0;
672 unsigned getNumAddrElements() const;
674 uint64_t getAddrElement(unsigned Idx) const {
675 return getUInt64Field(Idx+8);
678 /// isBlockByrefVariable - Return true if the variable was declared as
679 /// a "__block" variable (Apple Blocks).
680 bool isBlockByrefVariable() const {
681 return getType().isBlockByrefStruct();
684 /// isInlinedFnArgument - Return true if this variable provides debugging
685 /// information for an inlined function arguments.
686 bool isInlinedFnArgument(const Function *CurFn);
688 void printExtendedName(raw_ostream &OS) const;
691 /// DILocation - This object holds location information. This object
692 /// is not associated with any DWARF tag.
693 class DILocation : public DIDescriptor {
695 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
697 unsigned getLineNumber() const { return getUnsignedField(0); }
698 unsigned getColumnNumber() const { return getUnsignedField(1); }
699 DIScope getScope() const { return getFieldAs<DIScope>(2); }
700 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
701 StringRef getFilename() const { return getScope().getFilename(); }
702 StringRef getDirectory() const { return getScope().getDirectory(); }
706 class DIObjCProperty : public DIDescriptor {
707 friend class DIDescriptor;
708 void printInternal(raw_ostream &OS) const;
710 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
712 StringRef getObjCPropertyName() const { return getStringField(1); }
713 DIFile getFile() const { return getFieldAs<DIFile>(2); }
714 unsigned getLineNumber() const { return getUnsignedField(3); }
716 StringRef getObjCPropertyGetterName() const {
717 return getStringField(4);
719 StringRef getObjCPropertySetterName() const {
720 return getStringField(5);
722 bool isReadOnlyObjCProperty() const {
723 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
725 bool isReadWriteObjCProperty() const {
726 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
728 bool isAssignObjCProperty() const {
729 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
731 bool isRetainObjCProperty() const {
732 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
734 bool isCopyObjCProperty() const {
735 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
737 bool isNonAtomicObjCProperty() const {
738 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
741 DIType getType() const { return getFieldAs<DIType>(7); }
743 /// Verify - Verify that a derived type descriptor is well formed.
747 /// \brief An imported module (C++ using directive or similar).
748 class DIImportedEntity : public DIDescriptor {
749 friend class DIDescriptor;
750 void printInternal(raw_ostream &OS) const;
752 explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) { }
753 DIScope getContext() const { return getFieldAs<DIScope>(1); }
754 DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
755 unsigned getLineNumber() const { return getUnsignedField(3); }
756 StringRef getName() const { return getStringField(4); }
760 /// getDISubprogram - Find subprogram that is enclosing this scope.
761 DISubprogram getDISubprogram(const MDNode *Scope);
763 /// getDICompositeType - Find underlying composite type.
764 DICompositeType getDICompositeType(DIType T);
766 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
767 /// to hold function specific information.
768 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
770 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
771 /// suitable to hold function specific information.
772 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
774 /// createInlinedVariable - Create a new inlined variable based on current
776 /// @param DV Current Variable.
777 /// @param InlinedScope Location at current variable is inlined.
778 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
779 LLVMContext &VMContext);
781 /// cleanseInlinedVariable - Remove inlined scope from the variable.
782 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
784 /// Construct DITypeIdentifierMap by going through retained types of each CU.
785 DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
787 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
788 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
789 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
790 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
791 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
793 class DebugInfoFinder {
795 /// processModule - Process entire module and collect debug info
797 void processModule(const Module &M);
799 /// processDeclare - Process DbgDeclareInst.
800 void processDeclare(const DbgDeclareInst *DDI);
801 /// Process DbgValueInst.
802 void processValue(const DbgValueInst *DVI);
803 /// processLocation - Process DILocation.
804 void processLocation(DILocation Loc);
809 /// processType - Process DIType.
810 void processType(DIType DT);
812 /// processLexicalBlock - Process DILexicalBlock.
813 void processLexicalBlock(DILexicalBlock LB);
815 /// processSubprogram - Process DISubprogram.
816 void processSubprogram(DISubprogram SP);
818 void processScope(DIScope Scope);
820 /// addCompileUnit - Add compile unit into CUs.
821 bool addCompileUnit(DICompileUnit CU);
823 /// addGlobalVariable - Add global variable into GVs.
824 bool addGlobalVariable(DIGlobalVariable DIG);
826 // addSubprogram - Add subprogram into SPs.
827 bool addSubprogram(DISubprogram SP);
829 /// addType - Add type into Tys.
830 bool addType(DIType DT);
832 bool addScope(DIScope Scope);
835 typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
836 iterator compile_unit_begin() const { return CUs.begin(); }
837 iterator compile_unit_end() const { return CUs.end(); }
838 iterator subprogram_begin() const { return SPs.begin(); }
839 iterator subprogram_end() const { return SPs.end(); }
840 iterator global_variable_begin() const { return GVs.begin(); }
841 iterator global_variable_end() const { return GVs.end(); }
842 iterator type_begin() const { return TYs.begin(); }
843 iterator type_end() const { return TYs.end(); }
844 iterator scope_begin() const { return Scopes.begin(); }
845 iterator scope_end() const { return Scopes.end(); }
847 unsigned compile_unit_count() const { return CUs.size(); }
848 unsigned global_variable_count() const { return GVs.size(); }
849 unsigned subprogram_count() const { return SPs.size(); }
850 unsigned type_count() const { return TYs.size(); }
851 unsigned scope_count() const { return Scopes.size(); }
854 SmallVector<MDNode *, 8> CUs; // Compile Units
855 SmallVector<MDNode *, 8> SPs; // Subprograms
856 SmallVector<MDNode *, 8> GVs; // Global Variables;
857 SmallVector<MDNode *, 8> TYs; // Types
858 SmallVector<MDNode *, 8> Scopes; // Scopes
859 SmallPtrSet<MDNode *, 64> NodesSeen;
860 DITypeIdentifierMap TypeIdentifierMap;
862 } // end namespace llvm