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;
230 operator Value *() const { return const_cast<Value *>(Val); }
233 template <typename T>
234 T DIRef<T>::resolve(const DITypeIdentifierMap &Map) const {
238 if (const MDNode *MD = dyn_cast<MDNode>(Val))
241 const MDString *MS = cast<MDString>(Val);
242 // Find the corresponding MDNode.
243 DITypeIdentifierMap::const_iterator Iter = Map.find(MS);
244 assert(Iter != Map.end() && "Identifier not in the type map?");
245 assert(DIDescriptor(Iter->second).isType() &&
246 "MDNode in DITypeIdentifierMap should be a DIType.");
247 return T(Iter->second);
250 /// Specialize getFieldAs to handle fields that are references to DIScopes.
251 template <> DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const;
252 /// Specialize DIRef constructor for DIScopeRef.
253 template <> DIRef<DIScope>::DIRef(const Value *V);
255 /// Specialize getFieldAs to handle fields that are references to DITypes.
256 template <> DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const;
257 /// Specialize DIRef constructor for DITypeRef.
258 template <> DIRef<DIType>::DIRef(const Value *V);
260 /// DIType - This is a wrapper for a type.
261 /// FIXME: Types should be factored much better so that CV qualifiers and
262 /// others do not require a huge and empty descriptor full of zeros.
263 class DIType : public DIScope {
265 friend class DIDescriptor;
266 void printInternal(raw_ostream &OS) const;
269 DIType(const MDNode *N = 0) : DIScope(N) {}
271 /// Verify - Verify that a type descriptor is well formed.
274 DIScopeRef getContext() const { return getFieldAs<DIScopeRef>(2); }
275 StringRef getName() const { return getStringField(3); }
276 unsigned getLineNumber() const { return getUnsignedField(4); }
277 uint64_t getSizeInBits() const { return getUInt64Field(5); }
278 uint64_t getAlignInBits() const { return getUInt64Field(6); }
279 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
280 // carry this is just plain insane.
281 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
282 unsigned getFlags() const { return getUnsignedField(8); }
283 bool isPrivate() const { return (getFlags() & FlagPrivate) != 0; }
284 bool isProtected() const { return (getFlags() & FlagProtected) != 0; }
285 bool isForwardDecl() const { return (getFlags() & FlagFwdDecl) != 0; }
286 // isAppleBlock - Return true if this is the Apple Blocks extension.
287 bool isAppleBlockExtension() const {
288 return (getFlags() & FlagAppleBlock) != 0;
290 bool isBlockByrefStruct() const {
291 return (getFlags() & FlagBlockByrefStruct) != 0;
293 bool isVirtual() const { return (getFlags() & FlagVirtual) != 0; }
294 bool isArtificial() const { return (getFlags() & FlagArtificial) != 0; }
295 bool isObjectPointer() const { return (getFlags() & FlagObjectPointer) != 0; }
296 bool isObjcClassComplete() const {
297 return (getFlags() & FlagObjcClassComplete) != 0;
299 bool isVector() const { return (getFlags() & FlagVector) != 0; }
300 bool isStaticMember() const { return (getFlags() & FlagStaticMember) != 0; }
301 bool isValid() const { return DbgNode && isType(); }
303 /// isUnsignedDIType - Return true if type encoding is unsigned.
304 bool isUnsignedDIType();
306 /// replaceAllUsesWith - Replace all uses of debug info referenced by
308 void replaceAllUsesWith(DIDescriptor &D);
309 void replaceAllUsesWith(MDNode *D);
312 /// DIBasicType - A basic type, like 'int' or 'float'.
313 class DIBasicType : public DIType {
315 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
317 unsigned getEncoding() const { return getUnsignedField(9); }
319 /// Verify - Verify that a basic type descriptor is well formed.
323 /// DIDerivedType - A simple derived type, like a const qualified type,
324 /// a typedef, a pointer or reference, et cetera. Or, a data member of
325 /// a class/struct/union.
326 class DIDerivedType : public DIType {
327 friend class DIDescriptor;
328 void printInternal(raw_ostream &OS) const;
331 explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
333 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
335 /// getOriginalTypeSize - If this type is derived from a base type then
336 /// return base type size.
337 uint64_t getOriginalTypeSize() const;
339 /// getObjCProperty - Return property node, if this ivar is
340 /// associated with one.
341 MDNode *getObjCProperty() const;
343 DITypeRef getClassType() const {
344 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
345 return getFieldAs<DITypeRef>(10);
348 Constant *getConstant() const {
349 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
350 return getConstantField(10);
353 /// Verify - Verify that a derived type descriptor is well formed.
357 /// DICompositeType - This descriptor holds a type that can refer to multiple
358 /// other types, like a function or struct.
359 /// DICompositeType is derived from DIDerivedType because some
360 /// composite types (such as enums) can be derived from basic types
361 // FIXME: Make this derive from DIType directly & just store the
362 // base type in a single DIType field.
363 class DICompositeType : public DIDerivedType {
364 friend class DIDescriptor;
365 void printInternal(raw_ostream &OS) const;
368 explicit DICompositeType(const MDNode *N = 0) : DIDerivedType(N) {}
370 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
371 void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
372 void addMember(DIDescriptor D);
373 unsigned getRunTimeLang() const { return getUnsignedField(11); }
374 DITypeRef getContainingType() const { return getFieldAs<DITypeRef>(12); }
375 void setContainingType(DICompositeType ContainingType);
376 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
377 MDString *getIdentifier() const;
379 /// Verify - Verify that a composite type descriptor is well formed.
383 /// DIFile - This is a wrapper for a file.
384 class DIFile : public DIScope {
385 friend class DIDescriptor;
388 explicit DIFile(const MDNode *N = 0) : DIScope(N) {}
389 MDNode *getFileNode() const;
393 /// DICompileUnit - A wrapper for a compile unit.
394 class DICompileUnit : public DIScope {
395 friend class DIDescriptor;
396 void printInternal(raw_ostream &OS) const;
399 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
401 unsigned getLanguage() const { return getUnsignedField(2); }
402 StringRef getProducer() const { return getStringField(3); }
404 bool isOptimized() const { return getUnsignedField(4) != 0; }
405 StringRef getFlags() const { return getStringField(5); }
406 unsigned getRunTimeVersion() const { return getUnsignedField(6); }
408 DIArray getEnumTypes() const;
409 DIArray getRetainedTypes() const;
410 DIArray getSubprograms() const;
411 DIArray getGlobalVariables() const;
412 DIArray getImportedEntities() const;
414 StringRef getSplitDebugFilename() const { return getStringField(12); }
416 /// Verify - Verify that a compile unit is well formed.
420 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
421 class DISubprogram : public DIScope {
422 friend class DIDescriptor;
423 void printInternal(raw_ostream &OS) const;
426 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
428 DIScope getContext() const { return getFieldAs<DIScope>(2); }
429 StringRef getName() const { return getStringField(3); }
430 StringRef getDisplayName() const { return getStringField(4); }
431 StringRef getLinkageName() const { return getStringField(5); }
432 unsigned getLineNumber() const { return getUnsignedField(6); }
433 DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
435 /// isLocalToUnit - Return true if this subprogram is local to the current
436 /// compile unit, like 'static' in C.
437 unsigned isLocalToUnit() const { return getUnsignedField(8); }
438 unsigned isDefinition() const { return getUnsignedField(9); }
440 unsigned getVirtuality() const { return getUnsignedField(10); }
441 unsigned getVirtualIndex() const { return getUnsignedField(11); }
443 DITypeRef getContainingType() const { return getFieldAs<DITypeRef>(12); }
445 unsigned getFlags() const { return getUnsignedField(13); }
447 unsigned isArtificial() const {
448 return (getUnsignedField(13) & FlagArtificial) != 0;
450 /// isPrivate - Return true if this subprogram has "private"
451 /// access specifier.
452 bool isPrivate() const { return (getUnsignedField(13) & FlagPrivate) != 0; }
453 /// isProtected - Return true if this subprogram has "protected"
454 /// access specifier.
455 bool isProtected() const {
456 return (getUnsignedField(13) & FlagProtected) != 0;
458 /// isExplicit - Return true if this subprogram is marked as explicit.
459 bool isExplicit() const { return (getUnsignedField(13) & FlagExplicit) != 0; }
460 /// isPrototyped - Return true if this subprogram is prototyped.
461 bool isPrototyped() const {
462 return (getUnsignedField(13) & FlagPrototyped) != 0;
465 unsigned isOptimized() const;
467 /// Verify - Verify that a subprogram descriptor is well formed.
470 /// describes - Return true if this subprogram provides debugging
471 /// information for the function F.
472 bool describes(const Function *F);
474 Function *getFunction() const { return getFunctionField(15); }
475 void replaceFunction(Function *F) { replaceFunctionField(15, F); }
476 DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
477 DISubprogram getFunctionDeclaration() const {
478 return getFieldAs<DISubprogram>(17);
480 MDNode *getVariablesNodes() const;
481 DIArray getVariables() const;
483 /// getScopeLineNumber - Get the beginning of the scope of the
484 /// function, not necessarily where the name of the program
486 unsigned getScopeLineNumber() const { return getUnsignedField(19); }
489 /// DILexicalBlock - This is a wrapper for a lexical block.
490 class DILexicalBlock : public DIScope {
492 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
493 DIScope getContext() const { return getFieldAs<DIScope>(2); }
494 unsigned getLineNumber() const { return getUnsignedField(3); }
495 unsigned getColumnNumber() const { return getUnsignedField(4); }
499 /// DILexicalBlockFile - This is a wrapper for a lexical block with
500 /// a filename change.
501 class DILexicalBlockFile : public DIScope {
503 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
504 DIScope getContext() const {
505 if (getScope().isSubprogram())
507 return getScope().getContext();
509 unsigned getLineNumber() const { return getScope().getLineNumber(); }
510 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
511 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
515 /// DINameSpace - A wrapper for a C++ style name space.
516 class DINameSpace : public DIScope {
517 friend class DIDescriptor;
518 void printInternal(raw_ostream &OS) const;
521 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
522 DIScope getContext() const { return getFieldAs<DIScope>(2); }
523 StringRef getName() const { return getStringField(3); }
524 unsigned getLineNumber() const { return getUnsignedField(4); }
528 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
529 class DITemplateTypeParameter : public DIDescriptor {
531 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
533 DIScope getContext() const { return getFieldAs<DIScope>(1); }
534 StringRef getName() const { return getStringField(2); }
535 DIType getType() const { return getFieldAs<DIType>(3); }
536 StringRef getFilename() const { return getFieldAs<DIFile>(4).getFilename(); }
537 StringRef getDirectory() const {
538 return getFieldAs<DIFile>(4).getDirectory();
540 unsigned getLineNumber() const { return getUnsignedField(5); }
541 unsigned getColumnNumber() const { return getUnsignedField(6); }
545 /// DITemplateValueParameter - This is a wrapper for template value parameter.
546 class DITemplateValueParameter : public DIDescriptor {
548 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
550 DIScope getContext() const { return getFieldAs<DIScope>(1); }
551 StringRef getName() const { return getStringField(2); }
552 DIType getType() const { return getFieldAs<DIType>(3); }
553 Value *getValue() const;
554 StringRef getFilename() const { return getFieldAs<DIFile>(5).getFilename(); }
555 StringRef getDirectory() const {
556 return getFieldAs<DIFile>(5).getDirectory();
558 unsigned getLineNumber() const { return getUnsignedField(6); }
559 unsigned getColumnNumber() const { return getUnsignedField(7); }
563 /// DIGlobalVariable - This is a wrapper for a global variable.
564 class DIGlobalVariable : public DIDescriptor {
565 friend class DIDescriptor;
566 void printInternal(raw_ostream &OS) const;
569 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
571 DIScope getContext() const { return getFieldAs<DIScope>(2); }
572 StringRef getName() const { return getStringField(3); }
573 StringRef getDisplayName() const { return getStringField(4); }
574 StringRef getLinkageName() const { return getStringField(5); }
575 StringRef getFilename() const { return getFieldAs<DIFile>(6).getFilename(); }
576 StringRef getDirectory() const {
577 return getFieldAs<DIFile>(6).getDirectory();
580 unsigned getLineNumber() const { return getUnsignedField(7); }
581 DIType getType() const { return getFieldAs<DIType>(8); }
582 unsigned isLocalToUnit() const { return getUnsignedField(9); }
583 unsigned isDefinition() const { return getUnsignedField(10); }
585 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
586 Constant *getConstant() const { return getConstantField(11); }
587 DIDerivedType getStaticDataMemberDeclaration() const {
588 return getFieldAs<DIDerivedType>(12);
591 /// Verify - Verify that a global variable descriptor is well formed.
595 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
597 class DIVariable : public DIDescriptor {
598 friend class DIDescriptor;
599 void printInternal(raw_ostream &OS) const;
602 explicit DIVariable(const MDNode *N = 0) : DIDescriptor(N) {}
604 DIScope getContext() const { return getFieldAs<DIScope>(1); }
605 StringRef getName() const { return getStringField(2); }
606 DIFile getFile() const { return getFieldAs<DIFile>(3); }
607 unsigned getLineNumber() const { return (getUnsignedField(4) << 8) >> 8; }
608 unsigned getArgNumber() const {
609 unsigned L = getUnsignedField(4);
612 DIType getType() const { return getFieldAs<DIType>(5); }
614 /// isArtificial - Return true if this variable is marked as "artificial".
615 bool isArtificial() const {
616 return (getUnsignedField(6) & FlagArtificial) != 0;
619 bool isObjectPointer() const {
620 return (getUnsignedField(6) & FlagObjectPointer) != 0;
623 /// \brief Return true if this variable is represented as a pointer.
624 bool isIndirect() const {
625 return (getUnsignedField(6) & FlagIndirectVariable) != 0;
628 /// getInlinedAt - If this variable is inlined then return inline location.
629 MDNode *getInlinedAt() const;
631 /// Verify - Verify that a variable descriptor is well formed.
634 /// HasComplexAddr - Return true if the variable has a complex address.
635 bool hasComplexAddress() const { return getNumAddrElements() > 0; }
637 unsigned getNumAddrElements() const;
639 uint64_t getAddrElement(unsigned Idx) const {
640 return getUInt64Field(Idx + 8);
643 /// isBlockByrefVariable - Return true if the variable was declared as
644 /// a "__block" variable (Apple Blocks).
645 bool isBlockByrefVariable() const { return getType().isBlockByrefStruct(); }
647 /// isInlinedFnArgument - Return true if this variable provides debugging
648 /// information for an inlined function arguments.
649 bool isInlinedFnArgument(const Function *CurFn);
651 void printExtendedName(raw_ostream &OS) const;
654 /// DILocation - This object holds location information. This object
655 /// is not associated with any DWARF tag.
656 class DILocation : public DIDescriptor {
658 explicit DILocation(const MDNode *N) : DIDescriptor(N) {}
660 unsigned getLineNumber() const { return getUnsignedField(0); }
661 unsigned getColumnNumber() const { return getUnsignedField(1); }
662 DIScope getScope() const { return getFieldAs<DIScope>(2); }
663 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
664 StringRef getFilename() const { return getScope().getFilename(); }
665 StringRef getDirectory() const { return getScope().getDirectory(); }
669 class DIObjCProperty : public DIDescriptor {
670 friend class DIDescriptor;
671 void printInternal(raw_ostream &OS) const;
674 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) {}
676 StringRef getObjCPropertyName() const { return getStringField(1); }
677 DIFile getFile() const { return getFieldAs<DIFile>(2); }
678 unsigned getLineNumber() const { return getUnsignedField(3); }
680 StringRef getObjCPropertyGetterName() const { return getStringField(4); }
681 StringRef getObjCPropertySetterName() const { return getStringField(5); }
682 bool isReadOnlyObjCProperty() const {
683 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
685 bool isReadWriteObjCProperty() const {
686 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
688 bool isAssignObjCProperty() const {
689 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
691 bool isRetainObjCProperty() const {
692 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
694 bool isCopyObjCProperty() const {
695 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
697 bool isNonAtomicObjCProperty() const {
698 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
701 DIType getType() const { return getFieldAs<DIType>(7); }
703 /// Verify - Verify that a derived type descriptor is well formed.
707 /// \brief An imported module (C++ using directive or similar).
708 class DIImportedEntity : public DIDescriptor {
709 friend class DIDescriptor;
710 void printInternal(raw_ostream &OS) const;
713 explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) {}
714 DIScope getContext() const { return getFieldAs<DIScope>(1); }
715 DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
716 unsigned getLineNumber() const { return getUnsignedField(3); }
717 StringRef getName() const { return getStringField(4); }
721 /// getDISubprogram - Find subprogram that is enclosing this scope.
722 DISubprogram getDISubprogram(const MDNode *Scope);
724 /// getDICompositeType - Find underlying composite type.
725 DICompositeType getDICompositeType(DIType T);
727 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
728 /// to hold function specific information.
729 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
731 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
732 /// suitable to hold function specific information.
733 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
735 /// createInlinedVariable - Create a new inlined variable based on current
737 /// @param DV Current Variable.
738 /// @param InlinedScope Location at current variable is inlined.
739 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
740 LLVMContext &VMContext);
742 /// cleanseInlinedVariable - Remove inlined scope from the variable.
743 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
745 /// Construct DITypeIdentifierMap by going through retained types of each CU.
746 DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
748 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
749 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
750 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
751 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
752 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
754 class DebugInfoFinder {
756 /// processModule - Process entire module and collect debug info
758 void processModule(const Module &M);
760 /// processDeclare - Process DbgDeclareInst.
761 void processDeclare(const DbgDeclareInst *DDI);
762 /// Process DbgValueInst.
763 void processValue(const DbgValueInst *DVI);
764 /// processLocation - Process DILocation.
765 void processLocation(DILocation Loc);
771 /// processType - Process DIType.
772 void processType(DIType DT);
774 /// processLexicalBlock - Process DILexicalBlock.
775 void processLexicalBlock(DILexicalBlock LB);
777 /// processSubprogram - Process DISubprogram.
778 void processSubprogram(DISubprogram SP);
780 void processScope(DIScope Scope);
782 /// addCompileUnit - Add compile unit into CUs.
783 bool addCompileUnit(DICompileUnit CU);
785 /// addGlobalVariable - Add global variable into GVs.
786 bool addGlobalVariable(DIGlobalVariable DIG);
788 // addSubprogram - Add subprogram into SPs.
789 bool addSubprogram(DISubprogram SP);
791 /// addType - Add type into Tys.
792 bool addType(DIType DT);
794 bool addScope(DIScope Scope);
797 typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
798 iterator compile_unit_begin() const { return CUs.begin(); }
799 iterator compile_unit_end() const { return CUs.end(); }
800 iterator subprogram_begin() const { return SPs.begin(); }
801 iterator subprogram_end() const { return SPs.end(); }
802 iterator global_variable_begin() const { return GVs.begin(); }
803 iterator global_variable_end() const { return GVs.end(); }
804 iterator type_begin() const { return TYs.begin(); }
805 iterator type_end() const { return TYs.end(); }
806 iterator scope_begin() const { return Scopes.begin(); }
807 iterator scope_end() const { return Scopes.end(); }
809 unsigned compile_unit_count() const { return CUs.size(); }
810 unsigned global_variable_count() const { return GVs.size(); }
811 unsigned subprogram_count() const { return SPs.size(); }
812 unsigned type_count() const { return TYs.size(); }
813 unsigned scope_count() const { return Scopes.size(); }
816 SmallVector<MDNode *, 8> CUs; // Compile Units
817 SmallVector<MDNode *, 8> SPs; // Subprograms
818 SmallVector<MDNode *, 8> GVs; // Global Variables;
819 SmallVector<MDNode *, 8> TYs; // Types
820 SmallVector<MDNode *, 8> Scopes; // Scopes
821 SmallPtrSet<MDNode *, 64> NodesSeen;
822 DITypeIdentifierMap TypeIdentifierMap;
824 } // end namespace llvm