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/IR/Metadata.h"
26 #include "llvm/Support/Dwarf.h"
48 class DILexicalBlockFile;
54 /// Maps from type identifier to the actual MDNode.
55 typedef DenseMap<const MDString *, MDNode*> DITypeIdentifierMap;
57 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
58 /// This should not be stored in a container, because the underlying MDNode
59 /// may change in certain situations.
61 // Befriends DIRef so DIRef can befriend the protected member
62 // function: getFieldAs<DIRef>.
68 FlagProtected = 1 << 1,
70 FlagAppleBlock = 1 << 3,
71 FlagBlockByrefStruct = 1 << 4,
73 FlagArtificial = 1 << 6,
74 FlagExplicit = 1 << 7,
75 FlagPrototyped = 1 << 8,
76 FlagObjcClassComplete = 1 << 9,
77 FlagObjectPointer = 1 << 10,
79 FlagStaticMember = 1 << 12,
80 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>
94 DescTy getFieldAs(unsigned Elt) const {
95 return DescTy(getDescriptorField(Elt));
98 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
99 Constant *getConstantField(unsigned Elt) const;
100 Function *getFunctionField(unsigned Elt) const;
101 void replaceFunctionField(unsigned Elt, Function *F);
104 explicit DIDescriptor(const MDNode *N = 0) : DbgNode(N) {}
108 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
109 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
111 // An explicit operator bool so that we can do testing of DI values
113 // FIXME: This operator bool isn't actually protecting anything at the
114 // moment due to the conversion operator above making DIDescriptor nodes
115 // implicitly convertable to bool.
116 LLVM_EXPLICIT operator bool() const { return DbgNode != 0; }
118 bool operator==(DIDescriptor Other) const {
119 return DbgNode == Other.DbgNode;
121 bool operator!=(DIDescriptor Other) const {
122 return !operator==(Other);
125 uint16_t getTag() const {
126 return getUnsignedField(0) & ~LLVMDebugVersionMask;
129 bool isDerivedType() const;
130 bool isCompositeType() const;
131 bool isBasicType() const;
132 bool isVariable() const;
133 bool isSubprogram() const;
134 bool isGlobalVariable() const;
135 bool isScope() const;
137 bool isCompileUnit() const;
138 bool isNameSpace() const;
139 bool isLexicalBlockFile() const;
140 bool isLexicalBlock() const;
141 bool isSubrange() const;
142 bool isEnumerator() const;
144 bool isUnspecifiedParameter() const;
145 bool isTemplateTypeParameter() const;
146 bool isTemplateValueParameter() const;
147 bool isObjCProperty() const;
148 bool isImportedEntity() const;
150 /// print - print descriptor.
151 void print(raw_ostream &OS) const;
153 /// dump - print descriptor to dbgs() with a newline.
157 /// DISubrange - This is used to represent ranges, for array bounds.
158 class DISubrange : public DIDescriptor {
159 friend class DIDescriptor;
160 void printInternal(raw_ostream &OS) const;
162 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
164 int64_t getLo() const { return getInt64Field(1); }
165 int64_t getCount() const { return getInt64Field(2); }
169 /// DIArray - This descriptor holds an array of descriptors.
170 class DIArray : public DIDescriptor {
172 explicit DIArray(const MDNode *N = 0) : DIDescriptor(N) {}
174 unsigned getNumElements() const;
175 DIDescriptor getElement(unsigned Idx) const {
176 return getDescriptorField(Idx);
180 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
181 /// FIXME: it seems strange that this doesn't have either a reference to the
182 /// type/precision or a file/line pair for location info.
183 class DIEnumerator : public DIDescriptor {
184 friend class DIDescriptor;
185 void printInternal(raw_ostream &OS) const;
187 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
189 StringRef getName() const { return getStringField(1); }
190 int64_t getEnumValue() const { return getInt64Field(2); }
194 template <typename T>
196 typedef DIRef<DIScope> DIScopeRef;
197 typedef DIRef<DIType> DITypeRef;
199 /// DIScope - A base class for various scopes.
200 class DIScope : public DIDescriptor {
202 friend class DIDescriptor;
203 void printInternal(raw_ostream &OS) const;
205 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
207 /// Gets the parent scope for this scope node or returns a
208 /// default constructed scope.
209 DIScopeRef getContext() const;
210 /// If the scope node has a name, return that, else return an empty string.
211 StringRef getName() const;
212 StringRef getFilename() const;
213 StringRef getDirectory() const;
215 /// Generate a reference to this DIScope. Uses the type identifier instead
216 /// of the actual MDNode if possible, to help type uniquing.
217 DIScopeRef getRef() const;
220 /// Represents reference to a DIDescriptor, abstracts over direct and
221 /// identifier-based metadata references.
222 template <typename T>
224 template <typename DescTy>
225 friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;
226 friend DIScopeRef DIScope::getContext() const;
227 friend DIScopeRef DIScope::getRef() const;
229 /// Val can be either a MDNode or a MDString, in the latter,
230 /// MDString specifies the type identifier.
232 explicit DIRef(const Value *V);
234 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);
249 StringRef getName() const {
253 if (const MDNode *MD = dyn_cast<MDNode>(Val))
254 return T(MD).getName();
256 const MDString *MS = cast<MDString>(Val);
257 return MS->getString();
259 operator Value *() const { return const_cast<Value*>(Val); }
262 /// Specialize getFieldAs to handle fields that are references to DIScopes.
264 DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const;
265 /// Specialize DIRef constructor for DIScopeRef.
267 DIRef<DIScope>::DIRef(const Value *V);
269 /// Specialize getFieldAs to handle fields that are references to DITypes.
271 DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const;
272 /// Specialize DIRef constructor for DITypeRef.
274 DIRef<DIType>::DIRef(const Value *V);
276 /// DIType - This is a wrapper for a type.
277 /// FIXME: Types should be factored much better so that CV qualifiers and
278 /// others do not require a huge and empty descriptor full of zeros.
279 class DIType : public DIScope {
281 friend class DIDescriptor;
282 void printInternal(raw_ostream &OS) const;
285 DIType(const MDNode *N = 0) : DIScope(N) {}
287 /// Verify - Verify that a type descriptor is well formed.
290 DIScopeRef getContext() const { return getFieldAs<DIScopeRef>(2); }
291 StringRef getName() const { return getStringField(3); }
292 unsigned getLineNumber() const { return getUnsignedField(4); }
293 uint64_t getSizeInBits() const { return getUInt64Field(5); }
294 uint64_t getAlignInBits() const { return getUInt64Field(6); }
295 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
296 // carry this is just plain insane.
297 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
298 unsigned getFlags() const { return getUnsignedField(8); }
299 bool isPrivate() const {
300 return (getFlags() & FlagPrivate) != 0;
302 bool isProtected() const {
303 return (getFlags() & FlagProtected) != 0;
305 bool isForwardDecl() const {
306 return (getFlags() & FlagFwdDecl) != 0;
308 // isAppleBlock - Return true if this is the Apple Blocks extension.
309 bool isAppleBlockExtension() const {
310 return (getFlags() & FlagAppleBlock) != 0;
312 bool isBlockByrefStruct() const {
313 return (getFlags() & FlagBlockByrefStruct) != 0;
315 bool isVirtual() const {
316 return (getFlags() & FlagVirtual) != 0;
318 bool isArtificial() const {
319 return (getFlags() & FlagArtificial) != 0;
321 bool isObjectPointer() const {
322 return (getFlags() & FlagObjectPointer) != 0;
324 bool isObjcClassComplete() const {
325 return (getFlags() & FlagObjcClassComplete) != 0;
327 bool isVector() const {
328 return (getFlags() & FlagVector) != 0;
330 bool isStaticMember() const {
331 return (getFlags() & FlagStaticMember) != 0;
333 bool isValid() const {
334 return DbgNode && isType();
337 /// replaceAllUsesWith - Replace all uses of debug info referenced by
339 void replaceAllUsesWith(DIDescriptor &D);
340 void replaceAllUsesWith(MDNode *D);
343 /// DIBasicType - A basic type, like 'int' or 'float'.
344 class DIBasicType : public DIType {
346 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
348 unsigned getEncoding() const { return getUnsignedField(9); }
350 /// Verify - Verify that a basic type descriptor is well formed.
354 /// DIDerivedType - A simple derived type, like a const qualified type,
355 /// a typedef, a pointer or reference, et cetera. Or, a data member of
356 /// a class/struct/union.
357 class DIDerivedType : public DIType {
358 friend class DIDescriptor;
359 void printInternal(raw_ostream &OS) const;
362 explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
364 DITypeRef getTypeDerivedFrom() const { return getFieldAs<DITypeRef>(9); }
366 /// getObjCProperty - Return property node, if this ivar is
367 /// associated with one.
368 MDNode *getObjCProperty() const;
370 DITypeRef getClassType() const {
371 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
372 return getFieldAs<DITypeRef>(10);
375 Constant *getConstant() const {
376 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
377 return getConstantField(10);
380 /// Verify - Verify that a derived type descriptor is well formed.
384 /// DICompositeType - This descriptor holds a type that can refer to multiple
385 /// other types, like a function or struct.
386 /// DICompositeType is derived from DIDerivedType because some
387 /// composite types (such as enums) can be derived from basic types
388 // FIXME: Make this derive from DIType directly & just store the
389 // base type in a single DIType field.
390 class DICompositeType : public DIDerivedType {
391 friend class DIDescriptor;
392 void printInternal(raw_ostream &OS) const;
394 explicit DICompositeType(const MDNode *N = 0) : DIDerivedType(N) {}
396 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
397 void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
398 void addMember(DIDescriptor D);
399 unsigned getRunTimeLang() const { return getUnsignedField(11); }
400 DITypeRef getContainingType() const {
401 return getFieldAs<DITypeRef>(12);
403 void setContainingType(DICompositeType ContainingType);
404 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
405 MDString *getIdentifier() const;
407 /// Verify - Verify that a composite type descriptor is well formed.
411 /// DIFile - This is a wrapper for a file.
412 class DIFile : public DIScope {
413 friend class DIDescriptor;
415 explicit DIFile(const MDNode *N = 0) : DIScope(N) {}
416 MDNode *getFileNode() const;
420 /// DICompileUnit - A wrapper for a compile unit.
421 class DICompileUnit : public DIScope {
422 friend class DIDescriptor;
423 void printInternal(raw_ostream &OS) const;
425 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
427 unsigned getLanguage() const { return getUnsignedField(2); }
428 StringRef getProducer() const { return getStringField(3); }
430 bool isOptimized() const { return getUnsignedField(4) != 0; }
431 StringRef getFlags() const { return getStringField(5); }
432 unsigned getRunTimeVersion() const { return getUnsignedField(6); }
434 DIArray getEnumTypes() const;
435 DIArray getRetainedTypes() const;
436 DIArray getSubprograms() const;
437 DIArray getGlobalVariables() const;
438 DIArray getImportedEntities() const;
440 StringRef getSplitDebugFilename() const { return getStringField(12); }
442 /// Verify - Verify that a compile unit is well formed.
446 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
447 class DISubprogram : public DIScope {
448 friend class DIDescriptor;
449 void printInternal(raw_ostream &OS) const;
451 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
453 DIScope getContext() const { return getFieldAs<DIScope>(2); }
454 StringRef getName() const { return getStringField(3); }
455 StringRef getDisplayName() const { return getStringField(4); }
456 StringRef getLinkageName() const { return getStringField(5); }
457 unsigned getLineNumber() const { return getUnsignedField(6); }
458 DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
460 /// isLocalToUnit - Return true if this subprogram is local to the current
461 /// compile unit, like 'static' in C.
462 unsigned isLocalToUnit() const { return getUnsignedField(8); }
463 unsigned isDefinition() const { return getUnsignedField(9); }
465 unsigned getVirtuality() const { return getUnsignedField(10); }
466 unsigned getVirtualIndex() const { return getUnsignedField(11); }
468 DITypeRef getContainingType() const {
469 return getFieldAs<DITypeRef>(12);
472 unsigned getFlags() const {
473 return getUnsignedField(13);
476 unsigned isArtificial() const {
477 return (getUnsignedField(13) & FlagArtificial) != 0;
479 /// isPrivate - Return true if this subprogram has "private"
480 /// access specifier.
481 bool isPrivate() const {
482 return (getUnsignedField(13) & FlagPrivate) != 0;
484 /// isProtected - Return true if this subprogram has "protected"
485 /// access specifier.
486 bool isProtected() const {
487 return (getUnsignedField(13) & FlagProtected) != 0;
489 /// isExplicit - Return true if this subprogram is marked as explicit.
490 bool isExplicit() const {
491 return (getUnsignedField(13) & FlagExplicit) != 0;
493 /// isPrototyped - Return true if this subprogram is prototyped.
494 bool isPrototyped() const {
495 return (getUnsignedField(13) & FlagPrototyped) != 0;
498 unsigned isOptimized() const;
500 /// Verify - Verify that a subprogram descriptor is well formed.
503 /// describes - Return true if this subprogram provides debugging
504 /// information for the function F.
505 bool describes(const Function *F);
507 Function *getFunction() const { return getFunctionField(15); }
508 void replaceFunction(Function *F) { replaceFunctionField(15, F); }
509 DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
510 DISubprogram getFunctionDeclaration() const {
511 return getFieldAs<DISubprogram>(17);
513 MDNode *getVariablesNodes() const;
514 DIArray getVariables() const;
516 /// getScopeLineNumber - Get the beginning of the scope of the
517 /// function, not necessarily where the name of the program
519 unsigned getScopeLineNumber() const { return getUnsignedField(19); }
522 /// DILexicalBlock - This is a wrapper for a lexical block.
523 class DILexicalBlock : public DIScope {
525 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
526 DIScope getContext() const { return getFieldAs<DIScope>(2); }
527 unsigned getLineNumber() const { return getUnsignedField(3); }
528 unsigned getColumnNumber() const { return getUnsignedField(4); }
532 /// DILexicalBlockFile - This is a wrapper for a lexical block with
533 /// a filename change.
534 class DILexicalBlockFile : public DIScope {
536 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
537 DIScope getContext() const {
538 if (getScope().isSubprogram())
540 return getScope().getContext();
542 unsigned getLineNumber() const { return getScope().getLineNumber(); }
543 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
544 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
548 /// DINameSpace - A wrapper for a C++ style name space.
549 class DINameSpace : public DIScope {
550 friend class DIDescriptor;
551 void printInternal(raw_ostream &OS) const;
553 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
554 DIScope getContext() const { return getFieldAs<DIScope>(2); }
555 StringRef getName() const { return getStringField(3); }
556 unsigned getLineNumber() const { return getUnsignedField(4); }
560 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
561 class DITemplateTypeParameter : public DIDescriptor {
563 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
565 DIScope getContext() const { return getFieldAs<DIScope>(1); }
566 StringRef getName() const { return getStringField(2); }
567 DIType getType() const { return getFieldAs<DIType>(3); }
568 StringRef getFilename() const {
569 return getFieldAs<DIFile>(4).getFilename();
571 StringRef getDirectory() const {
572 return getFieldAs<DIFile>(4).getDirectory();
574 unsigned getLineNumber() const { return getUnsignedField(5); }
575 unsigned getColumnNumber() const { return getUnsignedField(6); }
579 /// DITemplateValueParameter - This is a wrapper for template value parameter.
580 class DITemplateValueParameter : public DIDescriptor {
582 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
584 DIScope getContext() const { return getFieldAs<DIScope>(1); }
585 StringRef getName() const { return getStringField(2); }
586 DIType getType() const { return getFieldAs<DIType>(3); }
587 Value *getValue() const;
588 StringRef getFilename() const {
589 return getFieldAs<DIFile>(5).getFilename();
591 StringRef getDirectory() const {
592 return getFieldAs<DIFile>(5).getDirectory();
594 unsigned getLineNumber() const { return getUnsignedField(6); }
595 unsigned getColumnNumber() const { return getUnsignedField(7); }
599 /// DIGlobalVariable - This is a wrapper for a global variable.
600 class DIGlobalVariable : public DIDescriptor {
601 friend class DIDescriptor;
602 void printInternal(raw_ostream &OS) const;
604 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
606 DIScope getContext() const { return getFieldAs<DIScope>(2); }
607 StringRef getName() const { return getStringField(3); }
608 StringRef getDisplayName() const { return getStringField(4); }
609 StringRef getLinkageName() const { return getStringField(5); }
610 StringRef getFilename() const {
611 return getFieldAs<DIFile>(6).getFilename();
613 StringRef getDirectory() const {
614 return getFieldAs<DIFile>(6).getDirectory();
618 unsigned getLineNumber() const { return getUnsignedField(7); }
619 DIType getType() const { return getFieldAs<DIType>(8); }
620 unsigned isLocalToUnit() const { return getUnsignedField(9); }
621 unsigned isDefinition() const { return getUnsignedField(10); }
623 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
624 Constant *getConstant() const { return getConstantField(11); }
625 DIDerivedType getStaticDataMemberDeclaration() const {
626 return getFieldAs<DIDerivedType>(12);
629 /// Verify - Verify that a global variable descriptor is well formed.
633 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
635 class DIVariable : public DIDescriptor {
636 friend class DIDescriptor;
637 void printInternal(raw_ostream &OS) const;
639 explicit DIVariable(const MDNode *N = 0) : DIDescriptor(N) {}
641 DIScope getContext() const { return getFieldAs<DIScope>(1); }
642 StringRef getName() const { return getStringField(2); }
643 DIFile getFile() const { return getFieldAs<DIFile>(3); }
644 unsigned getLineNumber() const {
645 return (getUnsignedField(4) << 8) >> 8;
647 unsigned getArgNumber() const {
648 unsigned L = getUnsignedField(4);
651 DIType getType() const { return getFieldAs<DIType>(5); }
653 /// isArtificial - Return true if this variable is marked as "artificial".
654 bool isArtificial() const {
655 return (getUnsignedField(6) & FlagArtificial) != 0;
658 bool isObjectPointer() const {
659 return (getUnsignedField(6) & FlagObjectPointer) != 0;
662 /// \brief Return true if this variable is represented as a pointer.
663 bool isIndirect() const {
664 return (getUnsignedField(6) & FlagIndirectVariable) != 0;
667 /// getInlinedAt - If this variable is inlined then return inline location.
668 MDNode *getInlinedAt() const;
670 /// Verify - Verify that a variable descriptor is well formed.
673 /// HasComplexAddr - Return true if the variable has a complex address.
674 bool hasComplexAddress() const {
675 return getNumAddrElements() > 0;
678 unsigned getNumAddrElements() const;
680 uint64_t getAddrElement(unsigned Idx) const {
681 return getUInt64Field(Idx+8);
684 /// isBlockByrefVariable - Return true if the variable was declared as
685 /// a "__block" variable (Apple Blocks).
686 bool isBlockByrefVariable() const {
687 return getType().isBlockByrefStruct();
690 /// isInlinedFnArgument - Return true if this variable provides debugging
691 /// information for an inlined function arguments.
692 bool isInlinedFnArgument(const Function *CurFn);
694 void printExtendedName(raw_ostream &OS) const;
697 /// DILocation - This object holds location information. This object
698 /// is not associated with any DWARF tag.
699 class DILocation : public DIDescriptor {
701 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
703 unsigned getLineNumber() const { return getUnsignedField(0); }
704 unsigned getColumnNumber() const { return getUnsignedField(1); }
705 DIScope getScope() const { return getFieldAs<DIScope>(2); }
706 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
707 StringRef getFilename() const { return getScope().getFilename(); }
708 StringRef getDirectory() const { return getScope().getDirectory(); }
712 class DIObjCProperty : public DIDescriptor {
713 friend class DIDescriptor;
714 void printInternal(raw_ostream &OS) const;
716 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
718 StringRef getObjCPropertyName() const { return getStringField(1); }
719 DIFile getFile() const { return getFieldAs<DIFile>(2); }
720 unsigned getLineNumber() const { return getUnsignedField(3); }
722 StringRef getObjCPropertyGetterName() const {
723 return getStringField(4);
725 StringRef getObjCPropertySetterName() const {
726 return getStringField(5);
728 bool isReadOnlyObjCProperty() const {
729 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
731 bool isReadWriteObjCProperty() const {
732 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
734 bool isAssignObjCProperty() const {
735 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
737 bool isRetainObjCProperty() const {
738 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
740 bool isCopyObjCProperty() const {
741 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
743 bool isNonAtomicObjCProperty() const {
744 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
747 DIType getType() const { return getFieldAs<DIType>(7); }
749 /// Verify - Verify that a derived type descriptor is well formed.
753 /// \brief An imported module (C++ using directive or similar).
754 class DIImportedEntity : public DIDescriptor {
755 friend class DIDescriptor;
756 void printInternal(raw_ostream &OS) const;
758 explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) { }
759 DIScope getContext() const { return getFieldAs<DIScope>(1); }
760 DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
761 unsigned getLineNumber() const { return getUnsignedField(3); }
762 StringRef getName() const { return getStringField(4); }
766 /// getDISubprogram - Find subprogram that is enclosing this scope.
767 DISubprogram getDISubprogram(const MDNode *Scope);
769 /// getDICompositeType - Find underlying composite type.
770 DICompositeType getDICompositeType(DIType T);
772 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
773 /// to hold function specific information.
774 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
776 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
777 /// suitable to hold function specific information.
778 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
780 /// createInlinedVariable - Create a new inlined variable based on current
782 /// @param DV Current Variable.
783 /// @param InlinedScope Location at current variable is inlined.
784 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
785 LLVMContext &VMContext);
787 /// cleanseInlinedVariable - Remove inlined scope from the variable.
788 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
790 /// Construct DITypeIdentifierMap by going through retained types of each CU.
791 DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
793 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
794 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
795 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
796 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
797 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
799 class DebugInfoFinder {
801 /// processModule - Process entire module and collect debug info
803 void processModule(const Module &M);
805 /// processDeclare - Process DbgDeclareInst.
806 void processDeclare(const DbgDeclareInst *DDI);
807 /// Process DbgValueInst.
808 void processValue(const DbgValueInst *DVI);
809 /// processLocation - Process DILocation.
810 void processLocation(DILocation Loc);
815 /// processType - Process DIType.
816 void processType(DIType DT);
818 /// processLexicalBlock - Process DILexicalBlock.
819 void processLexicalBlock(DILexicalBlock LB);
821 /// processSubprogram - Process DISubprogram.
822 void processSubprogram(DISubprogram SP);
824 void processScope(DIScope Scope);
826 /// addCompileUnit - Add compile unit into CUs.
827 bool addCompileUnit(DICompileUnit CU);
829 /// addGlobalVariable - Add global variable into GVs.
830 bool addGlobalVariable(DIGlobalVariable DIG);
832 // addSubprogram - Add subprogram into SPs.
833 bool addSubprogram(DISubprogram SP);
835 /// addType - Add type into Tys.
836 bool addType(DIType DT);
838 bool addScope(DIScope Scope);
841 typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
842 iterator compile_unit_begin() const { return CUs.begin(); }
843 iterator compile_unit_end() const { return CUs.end(); }
844 iterator subprogram_begin() const { return SPs.begin(); }
845 iterator subprogram_end() const { return SPs.end(); }
846 iterator global_variable_begin() const { return GVs.begin(); }
847 iterator global_variable_end() const { return GVs.end(); }
848 iterator type_begin() const { return TYs.begin(); }
849 iterator type_end() const { return TYs.end(); }
850 iterator scope_begin() const { return Scopes.begin(); }
851 iterator scope_end() const { return Scopes.end(); }
853 unsigned compile_unit_count() const { return CUs.size(); }
854 unsigned global_variable_count() const { return GVs.size(); }
855 unsigned subprogram_count() const { return SPs.size(); }
856 unsigned type_count() const { return TYs.size(); }
857 unsigned scope_count() const { return Scopes.size(); }
860 SmallVector<MDNode *, 8> CUs; // Compile Units
861 SmallVector<MDNode *, 8> SPs; // Subprograms
862 SmallVector<MDNode *, 8> GVs; // Global Variables;
863 SmallVector<MDNode *, 8> TYs; // Types
864 SmallVector<MDNode *, 8> Scopes; // Scopes
865 SmallPtrSet<MDNode *, 64> NodesSeen;
866 DITypeIdentifierMap TypeIdentifierMap;
868 } // end namespace llvm