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,
81 FlagLValueReference = 1 << 14,
82 FlagRValueReference = 1 << 15
86 const MDNode *DbgNode;
88 StringRef getStringField(unsigned Elt) const;
89 unsigned getUnsignedField(unsigned Elt) const {
90 return (unsigned)getUInt64Field(Elt);
92 uint64_t getUInt64Field(unsigned Elt) const;
93 int64_t getInt64Field(unsigned Elt) const;
94 DIDescriptor getDescriptorField(unsigned Elt) const;
96 template <typename DescTy> DescTy getFieldAs(unsigned Elt) const {
97 return DescTy(getDescriptorField(Elt));
100 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
101 Constant *getConstantField(unsigned Elt) const;
102 Function *getFunctionField(unsigned Elt) const;
103 void replaceFunctionField(unsigned Elt, Function *F);
106 explicit DIDescriptor(const MDNode *N = 0) : DbgNode(N) {}
110 operator MDNode *() const { return const_cast<MDNode *>(DbgNode); }
111 MDNode *operator->() const { return const_cast<MDNode *>(DbgNode); }
113 // An explicit operator bool so that we can do testing of DI values
115 // FIXME: This operator bool isn't actually protecting anything at the
116 // moment due to the conversion operator above making DIDescriptor nodes
117 // implicitly convertable to bool.
118 LLVM_EXPLICIT operator bool() const { return DbgNode != 0; }
120 bool operator==(DIDescriptor Other) const { return DbgNode == Other.DbgNode; }
121 bool operator!=(DIDescriptor Other) const { return !operator==(Other); }
123 uint16_t getTag() const {
124 return getUnsignedField(0) & ~LLVMDebugVersionMask;
127 bool isDerivedType() const;
128 bool isCompositeType() const;
129 bool isBasicType() const;
130 bool isVariable() const;
131 bool isSubprogram() const;
132 bool isGlobalVariable() const;
133 bool isScope() const;
135 bool isCompileUnit() const;
136 bool isNameSpace() const;
137 bool isLexicalBlockFile() const;
138 bool isLexicalBlock() const;
139 bool isSubrange() const;
140 bool isEnumerator() const;
142 bool isUnspecifiedParameter() const;
143 bool isTemplateTypeParameter() const;
144 bool isTemplateValueParameter() const;
145 bool isObjCProperty() const;
146 bool isImportedEntity() const;
148 /// print - print descriptor.
149 void print(raw_ostream &OS) const;
151 /// dump - print descriptor to dbgs() with a newline.
155 /// DISubrange - This is used to represent ranges, for array bounds.
156 class DISubrange : public DIDescriptor {
157 friend class DIDescriptor;
158 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;
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> class DIRef;
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;
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> class DIRef {
223 template <typename DescTy>
224 friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;
225 friend DIScopeRef DIScope::getContext() const;
226 friend DIScopeRef DIScope::getRef() const;
228 /// Val can be either a MDNode or a MDString, in the latter,
229 /// MDString specifies the type identifier.
231 explicit DIRef(const Value *V);
234 T resolve(const DITypeIdentifierMap &Map) const;
235 StringRef getName() const;
236 operator Value *() const { return const_cast<Value *>(Val); }
239 template <typename T>
240 T DIRef<T>::resolve(const DITypeIdentifierMap &Map) const {
244 if (const MDNode *MD = dyn_cast<MDNode>(Val))
247 const MDString *MS = cast<MDString>(Val);
248 // Find the corresponding MDNode.
249 DITypeIdentifierMap::const_iterator Iter = Map.find(MS);
250 assert(Iter != Map.end() && "Identifier not in the type map?");
251 assert(DIDescriptor(Iter->second).isType() &&
252 "MDNode in DITypeIdentifierMap should be a DIType.");
253 return T(Iter->second);
256 template <typename T> StringRef DIRef<T>::getName() const {
260 if (const MDNode *MD = dyn_cast<MDNode>(Val))
261 return T(MD).getName();
263 const MDString *MS = cast<MDString>(Val);
264 return MS->getString();
267 /// Specialize getFieldAs to handle fields that are references to DIScopes.
268 template <> DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const;
269 /// Specialize DIRef constructor for DIScopeRef.
270 template <> DIRef<DIScope>::DIRef(const Value *V);
272 /// Specialize getFieldAs to handle fields that are references to DITypes.
273 template <> DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const;
274 /// Specialize DIRef constructor for DITypeRef.
275 template <> DIRef<DIType>::DIRef(const Value *V);
277 /// DIType - This is a wrapper for a type.
278 /// FIXME: Types should be factored much better so that CV qualifiers and
279 /// others do not require a huge and empty descriptor full of zeros.
280 class DIType : public DIScope {
282 friend class DIDescriptor;
283 void printInternal(raw_ostream &OS) const;
286 explicit DIType(const MDNode *N = 0) : DIScope(N) {}
288 /// Verify - Verify that a type descriptor is well formed.
291 DIScopeRef getContext() const { return getFieldAs<DIScopeRef>(2); }
292 StringRef getName() const { return getStringField(3); }
293 unsigned getLineNumber() const { return getUnsignedField(4); }
294 uint64_t getSizeInBits() const { return getUInt64Field(5); }
295 uint64_t getAlignInBits() const { return getUInt64Field(6); }
296 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
297 // carry this is just plain insane.
298 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
299 unsigned getFlags() const { return getUnsignedField(8); }
300 bool isPrivate() const { return (getFlags() & FlagPrivate) != 0; }
301 bool isProtected() const { return (getFlags() & FlagProtected) != 0; }
302 bool isForwardDecl() const { return (getFlags() & FlagFwdDecl) != 0; }
303 // isAppleBlock - Return true if this is the Apple Blocks extension.
304 bool isAppleBlockExtension() const {
305 return (getFlags() & FlagAppleBlock) != 0;
307 bool isBlockByrefStruct() const {
308 return (getFlags() & FlagBlockByrefStruct) != 0;
310 bool isVirtual() const { return (getFlags() & FlagVirtual) != 0; }
311 bool isArtificial() const { return (getFlags() & FlagArtificial) != 0; }
312 bool isObjectPointer() const { return (getFlags() & FlagObjectPointer) != 0; }
313 bool isObjcClassComplete() const {
314 return (getFlags() & FlagObjcClassComplete) != 0;
316 bool isVector() const { return (getFlags() & FlagVector) != 0; }
317 bool isStaticMember() const { return (getFlags() & FlagStaticMember) != 0; }
318 bool isLValueReference() const {
319 return (getFlags() & FlagLValueReference) != 0;
321 bool isRValueReference() const {
322 return (getFlags() & FlagRValueReference) != 0;
324 bool isValid() const { return DbgNode && isType(); }
326 /// replaceAllUsesWith - Replace all uses of debug info referenced by
328 void replaceAllUsesWith(DIDescriptor &D);
329 void replaceAllUsesWith(MDNode *D);
332 /// DIBasicType - A basic type, like 'int' or 'float'.
333 class DIBasicType : public DIType {
335 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
337 unsigned getEncoding() const { return getUnsignedField(9); }
339 /// Verify - Verify that a basic type descriptor is well formed.
343 /// DIDerivedType - A simple derived type, like a const qualified type,
344 /// a typedef, a pointer or reference, et cetera. Or, a data member of
345 /// a class/struct/union.
346 class DIDerivedType : public DIType {
347 friend class DIDescriptor;
348 void printInternal(raw_ostream &OS) const;
351 explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
353 DITypeRef getTypeDerivedFrom() const { return getFieldAs<DITypeRef>(9); }
355 /// getObjCProperty - Return property node, if this ivar is
356 /// associated with one.
357 MDNode *getObjCProperty() const;
359 DITypeRef getClassType() const {
360 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
361 return getFieldAs<DITypeRef>(10);
364 Constant *getConstant() const {
365 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
366 return getConstantField(10);
369 /// Verify - Verify that a derived type descriptor is well formed.
373 /// DICompositeType - This descriptor holds a type that can refer to multiple
374 /// other types, like a function or struct.
375 /// DICompositeType is derived from DIDerivedType because some
376 /// composite types (such as enums) can be derived from basic types
377 // FIXME: Make this derive from DIType directly & just store the
378 // base type in a single DIType field.
379 class DICompositeType : public DIDerivedType {
380 friend class DIDescriptor;
381 void printInternal(raw_ostream &OS) const;
384 explicit DICompositeType(const MDNode *N = 0) : DIDerivedType(N) {}
386 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
387 void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
388 void addMember(DIDescriptor D);
389 unsigned getRunTimeLang() const { return getUnsignedField(11); }
390 DITypeRef getContainingType() const { return getFieldAs<DITypeRef>(12); }
391 void setContainingType(DICompositeType ContainingType);
392 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
393 MDString *getIdentifier() const;
395 /// Verify - Verify that a composite type descriptor is well formed.
399 /// DIFile - This is a wrapper for a file.
400 class DIFile : public DIScope {
401 friend class DIDescriptor;
404 explicit DIFile(const MDNode *N = 0) : DIScope(N) {}
405 MDNode *getFileNode() const;
409 /// DICompileUnit - A wrapper for a compile unit.
410 class DICompileUnit : public DIScope {
411 friend class DIDescriptor;
412 void printInternal(raw_ostream &OS) const;
415 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
417 unsigned getLanguage() const { return getUnsignedField(2); }
418 StringRef getProducer() const { return getStringField(3); }
420 bool isOptimized() const { return getUnsignedField(4) != 0; }
421 StringRef getFlags() const { return getStringField(5); }
422 unsigned getRunTimeVersion() const { return getUnsignedField(6); }
424 DIArray getEnumTypes() const;
425 DIArray getRetainedTypes() const;
426 DIArray getSubprograms() const;
427 DIArray getGlobalVariables() const;
428 DIArray getImportedEntities() const;
430 StringRef getSplitDebugFilename() const { return getStringField(12); }
432 /// Verify - Verify that a compile unit is well formed.
436 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
437 class DISubprogram : public DIScope {
438 friend class DIDescriptor;
439 void printInternal(raw_ostream &OS) const;
442 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
444 DIScopeRef getContext() const { return getFieldAs<DIScopeRef>(2); }
445 StringRef getName() const { return getStringField(3); }
446 StringRef getDisplayName() const { return getStringField(4); }
447 StringRef getLinkageName() const { return getStringField(5); }
448 unsigned getLineNumber() const { return getUnsignedField(6); }
449 DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
451 /// isLocalToUnit - Return true if this subprogram is local to the current
452 /// compile unit, like 'static' in C.
453 unsigned isLocalToUnit() const { return getUnsignedField(8); }
454 unsigned isDefinition() const { return getUnsignedField(9); }
456 unsigned getVirtuality() const { return getUnsignedField(10); }
457 unsigned getVirtualIndex() const { return getUnsignedField(11); }
459 DITypeRef getContainingType() const { return getFieldAs<DITypeRef>(12); }
461 unsigned getFlags() const { return getUnsignedField(13); }
463 unsigned isArtificial() const {
464 return (getUnsignedField(13) & FlagArtificial) != 0;
466 /// isPrivate - Return true if this subprogram has "private"
467 /// access specifier.
468 bool isPrivate() const { return (getUnsignedField(13) & FlagPrivate) != 0; }
469 /// isProtected - Return true if this subprogram has "protected"
470 /// access specifier.
471 bool isProtected() const {
472 return (getUnsignedField(13) & FlagProtected) != 0;
474 /// isExplicit - Return true if this subprogram is marked as explicit.
475 bool isExplicit() const { return (getUnsignedField(13) & FlagExplicit) != 0; }
476 /// isPrototyped - Return true if this subprogram is prototyped.
477 bool isPrototyped() const {
478 return (getUnsignedField(13) & FlagPrototyped) != 0;
481 /// Return true if this subprogram is a C++11 reference-qualified
482 /// non-static member function (void foo() &).
483 unsigned isLValueReference() const {
484 return (getUnsignedField(13) & FlagLValueReference) != 0;
487 /// Return true if this subprogram is a C++11
488 /// rvalue-reference-qualified non-static member function
490 unsigned isRValueReference() const {
491 return (getUnsignedField(13) & FlagRValueReference) != 0;
494 unsigned isOptimized() const;
496 /// Verify - Verify that a subprogram descriptor is well formed.
499 /// describes - Return true if this subprogram provides debugging
500 /// information for the function F.
501 bool describes(const Function *F);
503 Function *getFunction() const { return getFunctionField(15); }
504 void replaceFunction(Function *F) { replaceFunctionField(15, F); }
505 DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
506 DISubprogram getFunctionDeclaration() const {
507 return getFieldAs<DISubprogram>(17);
509 MDNode *getVariablesNodes() const;
510 DIArray getVariables() const;
512 /// getScopeLineNumber - Get the beginning of the scope of the
513 /// function, not necessarily where the name of the program
515 unsigned getScopeLineNumber() const { return getUnsignedField(19); }
518 /// DILexicalBlock - This is a wrapper for a lexical block.
519 class DILexicalBlock : public DIScope {
521 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
522 DIScope getContext() const { return getFieldAs<DIScope>(2); }
523 unsigned getLineNumber() const { return getUnsignedField(3); }
524 unsigned getColumnNumber() const { return getUnsignedField(4); }
528 /// DILexicalBlockFile - This is a wrapper for a lexical block with
529 /// a filename change.
530 class DILexicalBlockFile : public DIScope {
532 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
533 DIScope getContext() const {
534 if (getScope().isSubprogram())
536 return getScope().getContext();
538 unsigned getLineNumber() const { return getScope().getLineNumber(); }
539 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
540 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
544 /// DINameSpace - A wrapper for a C++ style name space.
545 class DINameSpace : public DIScope {
546 friend class DIDescriptor;
547 void printInternal(raw_ostream &OS) const;
550 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
551 DIScope getContext() const { return getFieldAs<DIScope>(2); }
552 StringRef getName() const { return getStringField(3); }
553 unsigned getLineNumber() const { return getUnsignedField(4); }
557 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
558 class DITemplateTypeParameter : public DIDescriptor {
560 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
562 DIScopeRef getContext() const { return getFieldAs<DIScopeRef>(1); }
563 StringRef getName() const { return getStringField(2); }
564 DITypeRef getType() const { return getFieldAs<DITypeRef>(3); }
565 StringRef getFilename() const { return getFieldAs<DIFile>(4).getFilename(); }
566 StringRef getDirectory() const {
567 return getFieldAs<DIFile>(4).getDirectory();
569 unsigned getLineNumber() const { return getUnsignedField(5); }
570 unsigned getColumnNumber() const { return getUnsignedField(6); }
574 /// DITemplateValueParameter - This is a wrapper for template value parameter.
575 class DITemplateValueParameter : public DIDescriptor {
577 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
579 DIScopeRef getContext() const { return getFieldAs<DIScopeRef>(1); }
580 StringRef getName() const { return getStringField(2); }
581 DITypeRef getType() const { return getFieldAs<DITypeRef>(3); }
582 Value *getValue() const;
583 StringRef getFilename() const { return getFieldAs<DIFile>(5).getFilename(); }
584 StringRef getDirectory() const {
585 return getFieldAs<DIFile>(5).getDirectory();
587 unsigned getLineNumber() const { return getUnsignedField(6); }
588 unsigned getColumnNumber() const { return getUnsignedField(7); }
592 /// DIGlobalVariable - This is a wrapper for a global variable.
593 class DIGlobalVariable : public DIDescriptor {
594 friend class DIDescriptor;
595 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 { return getFieldAs<DIFile>(6).getFilename(); }
605 StringRef getDirectory() const {
606 return getFieldAs<DIFile>(6).getDirectory();
609 unsigned getLineNumber() const { return getUnsignedField(7); }
610 DIType getType() const { return getFieldAs<DIType>(8); }
611 unsigned isLocalToUnit() const { return getUnsignedField(9); }
612 unsigned isDefinition() const { return getUnsignedField(10); }
614 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
615 Constant *getConstant() const { return getConstantField(11); }
616 DIDerivedType getStaticDataMemberDeclaration() const {
617 return getFieldAs<DIDerivedType>(12);
620 /// Verify - Verify that a global variable descriptor is well formed.
624 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
626 class DIVariable : public DIDescriptor {
627 friend class DIDescriptor;
628 void printInternal(raw_ostream &OS) const;
631 explicit DIVariable(const MDNode *N = 0) : DIDescriptor(N) {}
633 DIScope getContext() const { return getFieldAs<DIScope>(1); }
634 StringRef getName() const { return getStringField(2); }
635 DIFile getFile() const { return getFieldAs<DIFile>(3); }
636 unsigned getLineNumber() const { return (getUnsignedField(4) << 8) >> 8; }
637 unsigned getArgNumber() const {
638 unsigned L = getUnsignedField(4);
641 DIType getType() const { return getFieldAs<DIType>(5); }
643 /// isArtificial - Return true if this variable is marked as "artificial".
644 bool isArtificial() const {
645 return (getUnsignedField(6) & FlagArtificial) != 0;
648 bool isObjectPointer() const {
649 return (getUnsignedField(6) & FlagObjectPointer) != 0;
652 /// \brief Return true if this variable is represented as a pointer.
653 bool isIndirect() const {
654 return (getUnsignedField(6) & FlagIndirectVariable) != 0;
657 /// getInlinedAt - If this variable is inlined then return inline location.
658 MDNode *getInlinedAt() const;
660 /// Verify - Verify that a variable descriptor is well formed.
663 /// HasComplexAddr - Return true if the variable has a complex address.
664 bool hasComplexAddress() const { return getNumAddrElements() > 0; }
666 unsigned getNumAddrElements() const;
668 uint64_t getAddrElement(unsigned Idx) const {
669 return getUInt64Field(Idx + 8);
672 /// isBlockByrefVariable - Return true if the variable was declared as
673 /// a "__block" variable (Apple Blocks).
674 bool isBlockByrefVariable() const { return getType().isBlockByrefStruct(); }
676 /// isInlinedFnArgument - Return true if this variable provides debugging
677 /// information for an inlined function arguments.
678 bool isInlinedFnArgument(const Function *CurFn);
680 void printExtendedName(raw_ostream &OS) const;
683 /// DILocation - This object holds location information. This object
684 /// is not associated with any DWARF tag.
685 class DILocation : public DIDescriptor {
687 explicit DILocation(const MDNode *N) : DIDescriptor(N) {}
689 unsigned getLineNumber() const { return getUnsignedField(0); }
690 unsigned getColumnNumber() const { return getUnsignedField(1); }
691 DIScope getScope() const { return getFieldAs<DIScope>(2); }
692 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
693 StringRef getFilename() const { return getScope().getFilename(); }
694 StringRef getDirectory() const { return getScope().getDirectory(); }
698 class DIObjCProperty : public DIDescriptor {
699 friend class DIDescriptor;
700 void printInternal(raw_ostream &OS) const;
703 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) {}
705 StringRef getObjCPropertyName() const { return getStringField(1); }
706 DIFile getFile() const { return getFieldAs<DIFile>(2); }
707 unsigned getLineNumber() const { return getUnsignedField(3); }
709 StringRef getObjCPropertyGetterName() const { return getStringField(4); }
710 StringRef getObjCPropertySetterName() const { return getStringField(5); }
711 bool isReadOnlyObjCProperty() const {
712 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
714 bool isReadWriteObjCProperty() const {
715 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
717 bool isAssignObjCProperty() const {
718 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
720 bool isRetainObjCProperty() const {
721 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
723 bool isCopyObjCProperty() const {
724 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
726 bool isNonAtomicObjCProperty() const {
727 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
730 DIType getType() const { return getFieldAs<DIType>(7); }
732 /// Verify - Verify that a derived type descriptor is well formed.
736 /// \brief An imported module (C++ using directive or similar).
737 class DIImportedEntity : public DIDescriptor {
738 friend class DIDescriptor;
739 void printInternal(raw_ostream &OS) const;
742 explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) {}
743 DIScope getContext() const { return getFieldAs<DIScope>(1); }
744 DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
745 unsigned getLineNumber() const { return getUnsignedField(3); }
746 StringRef getName() const { return getStringField(4); }
750 /// getDISubprogram - Find subprogram that is enclosing this scope.
751 DISubprogram getDISubprogram(const MDNode *Scope);
753 /// getDICompositeType - Find underlying composite type.
754 DICompositeType getDICompositeType(DIType T);
756 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
757 /// to hold function specific information.
758 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
760 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
761 /// suitable to hold function specific information.
762 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
764 /// createInlinedVariable - Create a new inlined variable based on current
766 /// @param DV Current Variable.
767 /// @param InlinedScope Location at current variable is inlined.
768 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
769 LLVMContext &VMContext);
771 /// cleanseInlinedVariable - Remove inlined scope from the variable.
772 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
774 /// Construct DITypeIdentifierMap by going through retained types of each CU.
775 DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
777 /// Strip debug info in the module if it exists.
778 /// To do this, we remove all calls to the debugger intrinsics and any named
779 /// metadata for debugging. We also remove debug locations for instructions.
780 /// Return true if module is modified.
781 bool StripDebugInfo(Module &M);
783 /// Return Debug Info Metadata Version by checking module flags.
784 unsigned getDebugMetadataVersionFromModule(const Module &M);
786 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
787 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
788 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
789 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
790 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
792 class DebugInfoFinder {
794 DebugInfoFinder() : TypeMapInitialized(false) {}
796 /// processModule - Process entire module and collect debug info
798 void processModule(const Module &M);
800 /// processDeclare - Process DbgDeclareInst.
801 void processDeclare(const Module &M, const DbgDeclareInst *DDI);
802 /// Process DbgValueInst.
803 void processValue(const Module &M, const DbgValueInst *DVI);
804 /// processLocation - Process DILocation.
805 void processLocation(const Module &M, DILocation Loc);
811 /// Initialize TypeIdentifierMap.
812 void InitializeTypeMap(const Module &M);
814 /// processType - Process DIType.
815 void processType(DIType DT);
817 /// processLexicalBlock - Process DILexicalBlock.
818 void processLexicalBlock(DILexicalBlock LB);
820 /// processSubprogram - Process DISubprogram.
821 void processSubprogram(DISubprogram SP);
823 void processScope(DIScope Scope);
825 /// addCompileUnit - Add compile unit into CUs.
826 bool addCompileUnit(DICompileUnit CU);
828 /// addGlobalVariable - Add global variable into GVs.
829 bool addGlobalVariable(DIGlobalVariable DIG);
831 // addSubprogram - Add subprogram into SPs.
832 bool addSubprogram(DISubprogram SP);
834 /// addType - Add type into Tys.
835 bool addType(DIType DT);
837 bool addScope(DIScope Scope);
840 typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
841 iterator compile_unit_begin() const { return CUs.begin(); }
842 iterator compile_unit_end() const { return CUs.end(); }
843 iterator subprogram_begin() const { return SPs.begin(); }
844 iterator subprogram_end() const { return SPs.end(); }
845 iterator global_variable_begin() const { return GVs.begin(); }
846 iterator global_variable_end() const { return GVs.end(); }
847 iterator type_begin() const { return TYs.begin(); }
848 iterator type_end() const { return TYs.end(); }
849 iterator scope_begin() const { return Scopes.begin(); }
850 iterator scope_end() const { return Scopes.end(); }
852 unsigned compile_unit_count() const { return CUs.size(); }
853 unsigned global_variable_count() const { return GVs.size(); }
854 unsigned subprogram_count() const { return SPs.size(); }
855 unsigned type_count() const { return TYs.size(); }
856 unsigned scope_count() const { return Scopes.size(); }
859 SmallVector<MDNode *, 8> CUs; // Compile Units
860 SmallVector<MDNode *, 8> SPs; // Subprograms
861 SmallVector<MDNode *, 8> GVs; // Global Variables;
862 SmallVector<MDNode *, 8> TYs; // Types
863 SmallVector<MDNode *, 8> Scopes; // Scopes
864 SmallPtrSet<MDNode *, 64> NodesSeen;
865 DITypeIdentifierMap TypeIdentifierMap;
866 /// Specify if TypeIdentifierMap is initialized.
867 bool TypeMapInitialized;
869 } // end namespace llvm