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>.
63 template <typename T> friend class 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
84 const MDNode *DbgNode;
86 StringRef getStringField(unsigned Elt) const;
87 unsigned getUnsignedField(unsigned Elt) const {
88 return (unsigned)getUInt64Field(Elt);
90 uint64_t getUInt64Field(unsigned Elt) const;
91 int64_t getInt64Field(unsigned Elt) const;
92 DIDescriptor getDescriptorField(unsigned Elt) const;
94 template <typename DescTy> 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 { return DbgNode == Other.DbgNode; }
119 bool operator!=(DIDescriptor Other) const { return !operator==(Other); }
121 uint16_t getTag() const {
122 return getUnsignedField(0) & ~LLVMDebugVersionMask;
125 bool isDerivedType() const;
126 bool isCompositeType() const;
127 bool isBasicType() const;
128 bool isVariable() const;
129 bool isSubprogram() const;
130 bool isGlobalVariable() const;
131 bool isScope() const;
133 bool isCompileUnit() const;
134 bool isNameSpace() const;
135 bool isLexicalBlockFile() const;
136 bool isLexicalBlock() const;
137 bool isSubrange() const;
138 bool isEnumerator() const;
140 bool isUnspecifiedParameter() const;
141 bool isTemplateTypeParameter() const;
142 bool isTemplateValueParameter() const;
143 bool isObjCProperty() const;
144 bool isImportedEntity() const;
146 /// print - print descriptor.
147 void print(raw_ostream &OS) const;
149 /// dump - print descriptor to dbgs() with a newline.
153 /// DISubrange - This is used to represent ranges, for array bounds.
154 class DISubrange : public DIDescriptor {
155 friend class DIDescriptor;
156 void printInternal(raw_ostream &OS) const;
159 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
161 int64_t getLo() const { return getInt64Field(1); }
162 int64_t getCount() const { return getInt64Field(2); }
166 /// DIArray - This descriptor holds an array of descriptors.
167 class DIArray : public DIDescriptor {
169 explicit DIArray(const MDNode *N = 0) : DIDescriptor(N) {}
171 unsigned getNumElements() const;
172 DIDescriptor getElement(unsigned Idx) const {
173 return getDescriptorField(Idx);
177 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
178 /// FIXME: it seems strange that this doesn't have either a reference to the
179 /// type/precision or a file/line pair for location info.
180 class DIEnumerator : public DIDescriptor {
181 friend class DIDescriptor;
182 void printInternal(raw_ostream &OS) const;
185 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
187 StringRef getName() const { return getStringField(1); }
188 int64_t getEnumValue() const { return getInt64Field(2); }
192 template <typename T> class DIRef;
193 typedef DIRef<DIScope> DIScopeRef;
194 typedef DIRef<DIType> DITypeRef;
196 /// DIScope - A base class for various scopes.
197 class DIScope : public DIDescriptor {
199 friend class DIDescriptor;
200 void printInternal(raw_ostream &OS) const;
203 explicit DIScope(const MDNode *N = 0) : DIDescriptor(N) {}
205 /// Gets the parent scope for this scope node or returns a
206 /// default constructed scope.
207 DIScopeRef getContext() const;
208 /// If the scope node has a name, return that, else return an empty string.
209 StringRef getName() const;
210 StringRef getFilename() const;
211 StringRef getDirectory() const;
213 /// Generate a reference to this DIScope. Uses the type identifier instead
214 /// of the actual MDNode if possible, to help type uniquing.
215 DIScopeRef getRef() const;
218 /// Represents reference to a DIDescriptor, abstracts over direct and
219 /// identifier-based metadata references.
220 template <typename T> class DIRef {
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);
232 T resolve(const DITypeIdentifierMap &Map) const;
233 StringRef getName() const;
234 operator Value *() const { return const_cast<Value *>(Val); }
237 template <typename T>
238 T DIRef<T>::resolve(const DITypeIdentifierMap &Map) const {
242 if (const MDNode *MD = dyn_cast<MDNode>(Val))
245 const MDString *MS = cast<MDString>(Val);
246 // Find the corresponding MDNode.
247 DITypeIdentifierMap::const_iterator Iter = Map.find(MS);
248 assert(Iter != Map.end() && "Identifier not in the type map?");
249 assert(DIDescriptor(Iter->second).isType() &&
250 "MDNode in DITypeIdentifierMap should be a DIType.");
251 return T(Iter->second);
254 template <typename T>
255 StringRef DIRef<T>::getName() const {
259 if (const MDNode *MD = dyn_cast<MDNode>(Val))
260 return T(MD).getName();
262 const MDString *MS = cast<MDString>(Val);
263 return MS->getString();
266 /// Specialize getFieldAs to handle fields that are references to DIScopes.
267 template <> DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const;
268 /// Specialize DIRef constructor for DIScopeRef.
269 template <> DIRef<DIScope>::DIRef(const Value *V);
271 /// Specialize getFieldAs to handle fields that are references to DITypes.
272 template <> DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const;
273 /// Specialize DIRef constructor for DITypeRef.
274 template <> 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 { return (getFlags() & FlagPrivate) != 0; }
300 bool isProtected() const { return (getFlags() & FlagProtected) != 0; }
301 bool isForwardDecl() const { return (getFlags() & FlagFwdDecl) != 0; }
302 // isAppleBlock - Return true if this is the Apple Blocks extension.
303 bool isAppleBlockExtension() const {
304 return (getFlags() & FlagAppleBlock) != 0;
306 bool isBlockByrefStruct() const {
307 return (getFlags() & FlagBlockByrefStruct) != 0;
309 bool isVirtual() const { return (getFlags() & FlagVirtual) != 0; }
310 bool isArtificial() const { return (getFlags() & FlagArtificial) != 0; }
311 bool isObjectPointer() const { return (getFlags() & FlagObjectPointer) != 0; }
312 bool isObjcClassComplete() const {
313 return (getFlags() & FlagObjcClassComplete) != 0;
315 bool isVector() const { return (getFlags() & FlagVector) != 0; }
316 bool isStaticMember() const { return (getFlags() & FlagStaticMember) != 0; }
317 bool isValid() const { return DbgNode && isType(); }
319 /// replaceAllUsesWith - Replace all uses of debug info referenced by
321 void replaceAllUsesWith(DIDescriptor &D);
322 void replaceAllUsesWith(MDNode *D);
325 /// DIBasicType - A basic type, like 'int' or 'float'.
326 class DIBasicType : public DIType {
328 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
330 unsigned getEncoding() const { return getUnsignedField(9); }
332 /// Verify - Verify that a basic type descriptor is well formed.
336 /// DIDerivedType - A simple derived type, like a const qualified type,
337 /// a typedef, a pointer or reference, et cetera. Or, a data member of
338 /// a class/struct/union.
339 class DIDerivedType : public DIType {
340 friend class DIDescriptor;
341 void printInternal(raw_ostream &OS) const;
344 explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
346 DITypeRef getTypeDerivedFrom() const { return getFieldAs<DITypeRef>(9); }
348 /// getObjCProperty - Return property node, if this ivar is
349 /// associated with one.
350 MDNode *getObjCProperty() const;
352 DITypeRef getClassType() const {
353 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
354 return getFieldAs<DITypeRef>(10);
357 Constant *getConstant() const {
358 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
359 return getConstantField(10);
362 /// Verify - Verify that a derived type descriptor is well formed.
366 /// DICompositeType - This descriptor holds a type that can refer to multiple
367 /// other types, like a function or struct.
368 /// DICompositeType is derived from DIDerivedType because some
369 /// composite types (such as enums) can be derived from basic types
370 // FIXME: Make this derive from DIType directly & just store the
371 // base type in a single DIType field.
372 class DICompositeType : public DIDerivedType {
373 friend class DIDescriptor;
374 void printInternal(raw_ostream &OS) const;
377 explicit DICompositeType(const MDNode *N = 0) : DIDerivedType(N) {}
379 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
380 void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
381 void addMember(DIDescriptor D);
382 unsigned getRunTimeLang() const { return getUnsignedField(11); }
383 DITypeRef getContainingType() const { return getFieldAs<DITypeRef>(12); }
384 void setContainingType(DICompositeType ContainingType);
385 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
386 MDString *getIdentifier() const;
388 /// Verify - Verify that a composite type descriptor is well formed.
392 /// DIFile - This is a wrapper for a file.
393 class DIFile : public DIScope {
394 friend class DIDescriptor;
397 explicit DIFile(const MDNode *N = 0) : DIScope(N) {}
398 MDNode *getFileNode() const;
402 /// DICompileUnit - A wrapper for a compile unit.
403 class DICompileUnit : public DIScope {
404 friend class DIDescriptor;
405 void printInternal(raw_ostream &OS) const;
408 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
410 unsigned getLanguage() const { return getUnsignedField(2); }
411 StringRef getProducer() const { return getStringField(3); }
413 bool isOptimized() const { return getUnsignedField(4) != 0; }
414 StringRef getFlags() const { return getStringField(5); }
415 unsigned getRunTimeVersion() const { return getUnsignedField(6); }
417 DIArray getEnumTypes() const;
418 DIArray getRetainedTypes() const;
419 DIArray getSubprograms() const;
420 DIArray getGlobalVariables() const;
421 DIArray getImportedEntities() const;
423 StringRef getSplitDebugFilename() const { return getStringField(12); }
425 /// Verify - Verify that a compile unit is well formed.
429 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
430 class DISubprogram : public DIScope {
431 friend class DIDescriptor;
432 void printInternal(raw_ostream &OS) const;
435 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
437 DIScope getContext() const { return getFieldAs<DIScope>(2); }
438 StringRef getName() const { return getStringField(3); }
439 StringRef getDisplayName() const { return getStringField(4); }
440 StringRef getLinkageName() const { return getStringField(5); }
441 unsigned getLineNumber() const { return getUnsignedField(6); }
442 DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
444 /// isLocalToUnit - Return true if this subprogram is local to the current
445 /// compile unit, like 'static' in C.
446 unsigned isLocalToUnit() const { return getUnsignedField(8); }
447 unsigned isDefinition() const { return getUnsignedField(9); }
449 unsigned getVirtuality() const { return getUnsignedField(10); }
450 unsigned getVirtualIndex() const { return getUnsignedField(11); }
452 DITypeRef getContainingType() const { return getFieldAs<DITypeRef>(12); }
454 unsigned getFlags() const { return getUnsignedField(13); }
456 unsigned isArtificial() const {
457 return (getUnsignedField(13) & FlagArtificial) != 0;
459 /// isPrivate - Return true if this subprogram has "private"
460 /// access specifier.
461 bool isPrivate() const { return (getUnsignedField(13) & FlagPrivate) != 0; }
462 /// isProtected - Return true if this subprogram has "protected"
463 /// access specifier.
464 bool isProtected() const {
465 return (getUnsignedField(13) & FlagProtected) != 0;
467 /// isExplicit - Return true if this subprogram is marked as explicit.
468 bool isExplicit() const { return (getUnsignedField(13) & FlagExplicit) != 0; }
469 /// isPrototyped - Return true if this subprogram is prototyped.
470 bool isPrototyped() const {
471 return (getUnsignedField(13) & FlagPrototyped) != 0;
474 unsigned isOptimized() const;
476 /// Verify - Verify that a subprogram descriptor is well formed.
479 /// describes - Return true if this subprogram provides debugging
480 /// information for the function F.
481 bool describes(const Function *F);
483 Function *getFunction() const { return getFunctionField(15); }
484 void replaceFunction(Function *F) { replaceFunctionField(15, F); }
485 DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
486 DISubprogram getFunctionDeclaration() const {
487 return getFieldAs<DISubprogram>(17);
489 MDNode *getVariablesNodes() const;
490 DIArray getVariables() const;
492 /// getScopeLineNumber - Get the beginning of the scope of the
493 /// function, not necessarily where the name of the program
495 unsigned getScopeLineNumber() const { return getUnsignedField(19); }
498 /// DILexicalBlock - This is a wrapper for a lexical block.
499 class DILexicalBlock : public DIScope {
501 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
502 DIScope getContext() const { return getFieldAs<DIScope>(2); }
503 unsigned getLineNumber() const { return getUnsignedField(3); }
504 unsigned getColumnNumber() const { return getUnsignedField(4); }
508 /// DILexicalBlockFile - This is a wrapper for a lexical block with
509 /// a filename change.
510 class DILexicalBlockFile : public DIScope {
512 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
513 DIScope getContext() const {
514 if (getScope().isSubprogram())
516 return getScope().getContext();
518 unsigned getLineNumber() const { return getScope().getLineNumber(); }
519 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
520 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
524 /// DINameSpace - A wrapper for a C++ style name space.
525 class DINameSpace : public DIScope {
526 friend class DIDescriptor;
527 void printInternal(raw_ostream &OS) const;
530 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
531 DIScope getContext() const { return getFieldAs<DIScope>(2); }
532 StringRef getName() const { return getStringField(3); }
533 unsigned getLineNumber() const { return getUnsignedField(4); }
537 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
538 class DITemplateTypeParameter : public DIDescriptor {
540 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
542 DIScope getContext() const { return getFieldAs<DIScope>(1); }
543 StringRef getName() const { return getStringField(2); }
544 DIType getType() const { return getFieldAs<DIType>(3); }
545 StringRef getFilename() const { return getFieldAs<DIFile>(4).getFilename(); }
546 StringRef getDirectory() const {
547 return getFieldAs<DIFile>(4).getDirectory();
549 unsigned getLineNumber() const { return getUnsignedField(5); }
550 unsigned getColumnNumber() const { return getUnsignedField(6); }
554 /// DITemplateValueParameter - This is a wrapper for template value parameter.
555 class DITemplateValueParameter : public DIDescriptor {
557 explicit DITemplateValueParameter(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 Value *getValue() const;
563 StringRef getFilename() const { return getFieldAs<DIFile>(5).getFilename(); }
564 StringRef getDirectory() const {
565 return getFieldAs<DIFile>(5).getDirectory();
567 unsigned getLineNumber() const { return getUnsignedField(6); }
568 unsigned getColumnNumber() const { return getUnsignedField(7); }
572 /// DIGlobalVariable - This is a wrapper for a global variable.
573 class DIGlobalVariable : public DIDescriptor {
574 friend class DIDescriptor;
575 void printInternal(raw_ostream &OS) const;
578 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
580 DIScope getContext() const { return getFieldAs<DIScope>(2); }
581 StringRef getName() const { return getStringField(3); }
582 StringRef getDisplayName() const { return getStringField(4); }
583 StringRef getLinkageName() const { return getStringField(5); }
584 StringRef getFilename() const { return getFieldAs<DIFile>(6).getFilename(); }
585 StringRef getDirectory() const {
586 return getFieldAs<DIFile>(6).getDirectory();
589 unsigned getLineNumber() const { return getUnsignedField(7); }
590 DIType getType() const { return getFieldAs<DIType>(8); }
591 unsigned isLocalToUnit() const { return getUnsignedField(9); }
592 unsigned isDefinition() const { return getUnsignedField(10); }
594 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
595 Constant *getConstant() const { return getConstantField(11); }
596 DIDerivedType getStaticDataMemberDeclaration() const {
597 return getFieldAs<DIDerivedType>(12);
600 /// Verify - Verify that a global variable descriptor is well formed.
604 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
606 class DIVariable : public DIDescriptor {
607 friend class DIDescriptor;
608 void printInternal(raw_ostream &OS) const;
611 explicit DIVariable(const MDNode *N = 0) : DIDescriptor(N) {}
613 DIScope getContext() const { return getFieldAs<DIScope>(1); }
614 StringRef getName() const { return getStringField(2); }
615 DIFile getFile() const { return getFieldAs<DIFile>(3); }
616 unsigned getLineNumber() const { return (getUnsignedField(4) << 8) >> 8; }
617 unsigned getArgNumber() const {
618 unsigned L = getUnsignedField(4);
621 DIType getType() const { return getFieldAs<DIType>(5); }
623 /// isArtificial - Return true if this variable is marked as "artificial".
624 bool isArtificial() const {
625 return (getUnsignedField(6) & FlagArtificial) != 0;
628 bool isObjectPointer() const {
629 return (getUnsignedField(6) & FlagObjectPointer) != 0;
632 /// \brief Return true if this variable is represented as a pointer.
633 bool isIndirect() const {
634 return (getUnsignedField(6) & FlagIndirectVariable) != 0;
637 /// getInlinedAt - If this variable is inlined then return inline location.
638 MDNode *getInlinedAt() const;
640 /// Verify - Verify that a variable descriptor is well formed.
643 /// HasComplexAddr - Return true if the variable has a complex address.
644 bool hasComplexAddress() const { return getNumAddrElements() > 0; }
646 unsigned getNumAddrElements() const;
648 uint64_t getAddrElement(unsigned Idx) const {
649 return getUInt64Field(Idx + 8);
652 /// isBlockByrefVariable - Return true if the variable was declared as
653 /// a "__block" variable (Apple Blocks).
654 bool isBlockByrefVariable() const { return getType().isBlockByrefStruct(); }
656 /// isInlinedFnArgument - Return true if this variable provides debugging
657 /// information for an inlined function arguments.
658 bool isInlinedFnArgument(const Function *CurFn);
660 void printExtendedName(raw_ostream &OS) const;
663 /// DILocation - This object holds location information. This object
664 /// is not associated with any DWARF tag.
665 class DILocation : public DIDescriptor {
667 explicit DILocation(const MDNode *N) : DIDescriptor(N) {}
669 unsigned getLineNumber() const { return getUnsignedField(0); }
670 unsigned getColumnNumber() const { return getUnsignedField(1); }
671 DIScope getScope() const { return getFieldAs<DIScope>(2); }
672 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
673 StringRef getFilename() const { return getScope().getFilename(); }
674 StringRef getDirectory() const { return getScope().getDirectory(); }
678 class DIObjCProperty : public DIDescriptor {
679 friend class DIDescriptor;
680 void printInternal(raw_ostream &OS) const;
683 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) {}
685 StringRef getObjCPropertyName() const { return getStringField(1); }
686 DIFile getFile() const { return getFieldAs<DIFile>(2); }
687 unsigned getLineNumber() const { return getUnsignedField(3); }
689 StringRef getObjCPropertyGetterName() const { return getStringField(4); }
690 StringRef getObjCPropertySetterName() const { return getStringField(5); }
691 bool isReadOnlyObjCProperty() const {
692 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
694 bool isReadWriteObjCProperty() const {
695 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
697 bool isAssignObjCProperty() const {
698 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
700 bool isRetainObjCProperty() const {
701 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
703 bool isCopyObjCProperty() const {
704 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
706 bool isNonAtomicObjCProperty() const {
707 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
710 DIType getType() const { return getFieldAs<DIType>(7); }
712 /// Verify - Verify that a derived type descriptor is well formed.
716 /// \brief An imported module (C++ using directive or similar).
717 class DIImportedEntity : public DIDescriptor {
718 friend class DIDescriptor;
719 void printInternal(raw_ostream &OS) const;
722 explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) {}
723 DIScope getContext() const { return getFieldAs<DIScope>(1); }
724 DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
725 unsigned getLineNumber() const { return getUnsignedField(3); }
726 StringRef getName() const { return getStringField(4); }
730 /// getDISubprogram - Find subprogram that is enclosing this scope.
731 DISubprogram getDISubprogram(const MDNode *Scope);
733 /// getDICompositeType - Find underlying composite type.
734 DICompositeType getDICompositeType(DIType T);
736 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
737 /// to hold function specific information.
738 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
740 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
741 /// suitable to hold function specific information.
742 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
744 /// createInlinedVariable - Create a new inlined variable based on current
746 /// @param DV Current Variable.
747 /// @param InlinedScope Location at current variable is inlined.
748 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
749 LLVMContext &VMContext);
751 /// cleanseInlinedVariable - Remove inlined scope from the variable.
752 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
754 /// Construct DITypeIdentifierMap by going through retained types of each CU.
755 DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
757 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
758 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
759 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
760 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
761 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
763 class DebugInfoFinder {
765 /// processModule - Process entire module and collect debug info
767 void processModule(const Module &M);
769 /// processDeclare - Process DbgDeclareInst.
770 void processDeclare(const DbgDeclareInst *DDI);
771 /// Process DbgValueInst.
772 void processValue(const DbgValueInst *DVI);
773 /// processLocation - Process DILocation.
774 void processLocation(DILocation Loc);
780 /// processType - Process DIType.
781 void processType(DIType DT);
783 /// processLexicalBlock - Process DILexicalBlock.
784 void processLexicalBlock(DILexicalBlock LB);
786 /// processSubprogram - Process DISubprogram.
787 void processSubprogram(DISubprogram SP);
789 void processScope(DIScope Scope);
791 /// addCompileUnit - Add compile unit into CUs.
792 bool addCompileUnit(DICompileUnit CU);
794 /// addGlobalVariable - Add global variable into GVs.
795 bool addGlobalVariable(DIGlobalVariable DIG);
797 // addSubprogram - Add subprogram into SPs.
798 bool addSubprogram(DISubprogram SP);
800 /// addType - Add type into Tys.
801 bool addType(DIType DT);
803 bool addScope(DIScope Scope);
806 typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
807 iterator compile_unit_begin() const { return CUs.begin(); }
808 iterator compile_unit_end() const { return CUs.end(); }
809 iterator subprogram_begin() const { return SPs.begin(); }
810 iterator subprogram_end() const { return SPs.end(); }
811 iterator global_variable_begin() const { return GVs.begin(); }
812 iterator global_variable_end() const { return GVs.end(); }
813 iterator type_begin() const { return TYs.begin(); }
814 iterator type_end() const { return TYs.end(); }
815 iterator scope_begin() const { return Scopes.begin(); }
816 iterator scope_end() const { return Scopes.end(); }
818 unsigned compile_unit_count() const { return CUs.size(); }
819 unsigned global_variable_count() const { return GVs.size(); }
820 unsigned subprogram_count() const { return SPs.size(); }
821 unsigned type_count() const { return TYs.size(); }
822 unsigned scope_count() const { return Scopes.size(); }
825 SmallVector<MDNode *, 8> CUs; // Compile Units
826 SmallVector<MDNode *, 8> SPs; // Subprograms
827 SmallVector<MDNode *, 8> GVs; // Global Variables;
828 SmallVector<MDNode *, 8> TYs; // Types
829 SmallVector<MDNode *, 8> Scopes; // Scopes
830 SmallPtrSet<MDNode *, 64> NodesSeen;
831 DITypeIdentifierMap TypeIdentifierMap;
833 } // end namespace llvm