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/ADT/DenseMap.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Support/Dwarf.h"
46 class DILexicalBlockFile;
52 /// Maps from type identifier to the actual MDNode.
53 typedef DenseMap<const MDString *, MDNode*> DITypeIdentifierMap;
55 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
56 /// This should not be stored in a container, because the underlying MDNode
57 /// may change in certain situations.
59 // Befriends DITypeRef so DITypeRef can befriend the protected member
60 // function: getFieldAs<DITypeRef>.
61 friend class DITypeRef;
65 FlagProtected = 1 << 1,
67 FlagAppleBlock = 1 << 3,
68 FlagBlockByrefStruct = 1 << 4,
70 FlagArtificial = 1 << 6,
71 FlagExplicit = 1 << 7,
72 FlagPrototyped = 1 << 8,
73 FlagObjcClassComplete = 1 << 9,
74 FlagObjectPointer = 1 << 10,
76 FlagStaticMember = 1 << 12,
77 FlagIndirectVariable = 1 << 13
80 const MDNode *DbgNode;
82 StringRef getStringField(unsigned Elt) const;
83 unsigned getUnsignedField(unsigned Elt) const {
84 return (unsigned)getUInt64Field(Elt);
86 uint64_t getUInt64Field(unsigned Elt) const;
87 int64_t getInt64Field(unsigned Elt) const;
88 DIDescriptor getDescriptorField(unsigned Elt) const;
90 template <typename DescTy>
91 DescTy getFieldAs(unsigned Elt) const {
92 return DescTy(getDescriptorField(Elt));
95 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
96 Constant *getConstantField(unsigned Elt) const;
97 Function *getFunctionField(unsigned Elt) const;
98 void replaceFunctionField(unsigned Elt, Function *F);
101 explicit DIDescriptor(const MDNode *N = 0) : DbgNode(N) {}
105 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
106 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
108 // An explicit operator bool so that we can do testing of DI values
110 // FIXME: This operator bool isn't actually protecting anything at the
111 // moment due to the conversion operator above making DIDescriptor nodes
112 // implicitly convertable to bool.
113 LLVM_EXPLICIT operator bool() const { return DbgNode != 0; }
115 bool operator==(DIDescriptor Other) const {
116 return DbgNode == Other.DbgNode;
118 bool operator!=(DIDescriptor Other) const {
119 return !operator==(Other);
122 uint16_t getTag() const {
123 return getUnsignedField(0) & ~LLVMDebugVersionMask;
126 bool isDerivedType() const;
127 bool isCompositeType() const;
128 bool isBasicType() const;
129 bool isVariable() const;
130 bool isSubprogram() const;
131 bool isGlobalVariable() const;
132 bool isScope() const;
134 bool isCompileUnit() const;
135 bool isNameSpace() const;
136 bool isLexicalBlockFile() const;
137 bool isLexicalBlock() const;
138 bool isSubrange() const;
139 bool isEnumerator() const;
141 bool isUnspecifiedParameter() const;
142 bool isTemplateTypeParameter() const;
143 bool isTemplateValueParameter() const;
144 bool isObjCProperty() const;
145 bool isImportedEntity() const;
147 /// print - print descriptor.
148 void print(raw_ostream &OS) const;
150 /// dump - print descriptor to dbgs() with a newline.
154 /// Specialize getFieldAs to handle fields that are references to DITypes.
156 DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const;
158 /// Represents reference to a DIType, abstracts over direct and
159 /// identifier-based metadata type references.
161 template <typename DescTy>
162 friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;
164 /// TypeVal can be either a MDNode or a MDString, in the latter,
165 /// MDString specifies the type identifier.
166 const Value *TypeVal;
167 explicit DITypeRef(const Value *V);
169 DIType resolve(const DITypeIdentifierMap &Map) const;
172 /// DISubrange - This is used to represent ranges, for array bounds.
173 class DISubrange : public DIDescriptor {
174 friend class DIDescriptor;
175 void printInternal(raw_ostream &OS) const;
177 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
179 int64_t getLo() const { return getInt64Field(1); }
180 int64_t getCount() const { return getInt64Field(2); }
184 /// DIArray - This descriptor holds an array of descriptors.
185 class DIArray : public DIDescriptor {
187 explicit DIArray(const MDNode *N = 0) : DIDescriptor(N) {}
189 unsigned getNumElements() const;
190 DIDescriptor getElement(unsigned Idx) const {
191 return getDescriptorField(Idx);
195 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
196 /// FIXME: it seems strange that this doesn't have either a reference to the
197 /// type/precision or a file/line pair for location info.
198 class DIEnumerator : public DIDescriptor {
199 friend class DIDescriptor;
200 void printInternal(raw_ostream &OS) const;
202 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
204 StringRef getName() const { return getStringField(1); }
205 int64_t getEnumValue() const { return getInt64Field(2); }
209 /// DIScope - A base class for various scopes.
210 class DIScope : public DIDescriptor {
212 friend class DIDescriptor;
213 void printInternal(raw_ostream &OS) const;
215 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
217 /// Gets the parent scope for this scope node or returns a
218 /// default constructed scope.
219 DIScope getContext() const;
220 StringRef getFilename() const;
221 StringRef getDirectory() const;
224 /// DIType - This is a wrapper for a type.
225 /// FIXME: Types should be factored much better so that CV qualifiers and
226 /// others do not require a huge and empty descriptor full of zeros.
227 class DIType : public DIScope {
229 friend class DIDescriptor;
230 void printInternal(raw_ostream &OS) const;
233 DIType(const MDNode *N = 0) : DIScope(N) {}
235 /// Verify - Verify that a type descriptor is well formed.
238 DIScope getContext() const { return getFieldAs<DIScope>(2); }
239 StringRef getName() const { return getStringField(3); }
240 unsigned getLineNumber() const { return getUnsignedField(4); }
241 uint64_t getSizeInBits() const { return getUInt64Field(5); }
242 uint64_t getAlignInBits() const { return getUInt64Field(6); }
243 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
244 // carry this is just plain insane.
245 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
246 unsigned getFlags() const { return getUnsignedField(8); }
247 bool isPrivate() const {
248 return (getFlags() & FlagPrivate) != 0;
250 bool isProtected() const {
251 return (getFlags() & FlagProtected) != 0;
253 bool isForwardDecl() const {
254 return (getFlags() & FlagFwdDecl) != 0;
256 // isAppleBlock - Return true if this is the Apple Blocks extension.
257 bool isAppleBlockExtension() const {
258 return (getFlags() & FlagAppleBlock) != 0;
260 bool isBlockByrefStruct() const {
261 return (getFlags() & FlagBlockByrefStruct) != 0;
263 bool isVirtual() const {
264 return (getFlags() & FlagVirtual) != 0;
266 bool isArtificial() const {
267 return (getFlags() & FlagArtificial) != 0;
269 bool isObjectPointer() const {
270 return (getFlags() & FlagObjectPointer) != 0;
272 bool isObjcClassComplete() const {
273 return (getFlags() & FlagObjcClassComplete) != 0;
275 bool isVector() const {
276 return (getFlags() & FlagVector) != 0;
278 bool isStaticMember() const {
279 return (getFlags() & FlagStaticMember) != 0;
281 bool isValid() const {
282 return DbgNode && isType();
285 /// isUnsignedDIType - Return true if type encoding is unsigned.
286 bool isUnsignedDIType();
288 /// replaceAllUsesWith - Replace all uses of debug info referenced by
290 void replaceAllUsesWith(DIDescriptor &D);
291 void replaceAllUsesWith(MDNode *D);
294 /// DIBasicType - A basic type, like 'int' or 'float'.
295 class DIBasicType : public DIType {
297 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
299 unsigned getEncoding() const { return getUnsignedField(9); }
301 /// Verify - Verify that a basic type descriptor is well formed.
305 /// DIDerivedType - A simple derived type, like a const qualified type,
306 /// a typedef, a pointer or reference, et cetera. Or, a data member of
307 /// a class/struct/union.
308 class DIDerivedType : public DIType {
309 friend class DIDescriptor;
310 void printInternal(raw_ostream &OS) const;
313 explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
315 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
317 /// getOriginalTypeSize - If this type is derived from a base type then
318 /// return base type size.
319 uint64_t getOriginalTypeSize() const;
321 /// getObjCProperty - Return property node, if this ivar is
322 /// associated with one.
323 MDNode *getObjCProperty() const;
325 DITypeRef getClassType() const {
326 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
327 return getFieldAs<DITypeRef>(10);
330 Constant *getConstant() const {
331 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
332 return getConstantField(10);
335 /// Verify - Verify that a derived type descriptor is well formed.
339 /// DICompositeType - This descriptor holds a type that can refer to multiple
340 /// other types, like a function or struct.
341 /// DICompositeType is derived from DIDerivedType because some
342 /// composite types (such as enums) can be derived from basic types
343 // FIXME: Make this derive from DIType directly & just store the
344 // base type in a single DIType field.
345 class DICompositeType : public DIDerivedType {
346 friend class DIDescriptor;
347 void printInternal(raw_ostream &OS) const;
349 explicit DICompositeType(const MDNode *N = 0) : DIDerivedType(N) {}
351 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
352 void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
353 void addMember(DIDescriptor D);
354 unsigned getRunTimeLang() const { return getUnsignedField(11); }
355 DICompositeType getContainingType() const {
356 return getFieldAs<DICompositeType>(12);
358 void setContainingType(DICompositeType ContainingType);
359 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
360 MDString *getIdentifier() const;
362 /// Verify - Verify that a composite type descriptor is well formed.
366 /// DIFile - This is a wrapper for a file.
367 class DIFile : public DIScope {
368 friend class DIDescriptor;
370 explicit DIFile(const MDNode *N = 0) : DIScope(N) {}
371 MDNode *getFileNode() const;
375 /// DICompileUnit - A wrapper for a compile unit.
376 class DICompileUnit : public DIScope {
377 friend class DIDescriptor;
378 void printInternal(raw_ostream &OS) const;
380 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
382 unsigned getLanguage() const { return getUnsignedField(2); }
383 StringRef getProducer() const { return getStringField(3); }
385 bool isOptimized() const { return getUnsignedField(4) != 0; }
386 StringRef getFlags() const { return getStringField(5); }
387 unsigned getRunTimeVersion() const { return getUnsignedField(6); }
389 DIArray getEnumTypes() const;
390 DIArray getRetainedTypes() const;
391 DIArray getSubprograms() const;
392 DIArray getGlobalVariables() const;
393 DIArray getImportedEntities() const;
395 StringRef getSplitDebugFilename() const { return getStringField(12); }
397 /// Verify - Verify that a compile unit is well formed.
401 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
402 class DISubprogram : public DIScope {
403 friend class DIDescriptor;
404 void printInternal(raw_ostream &OS) const;
406 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
408 DIScope getContext() const { return getFieldAs<DIScope>(2); }
409 StringRef getName() const { return getStringField(3); }
410 StringRef getDisplayName() const { return getStringField(4); }
411 StringRef getLinkageName() const { return getStringField(5); }
412 unsigned getLineNumber() const { return getUnsignedField(6); }
413 DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
415 /// isLocalToUnit - Return true if this subprogram is local to the current
416 /// compile unit, like 'static' in C.
417 unsigned isLocalToUnit() const { return getUnsignedField(8); }
418 unsigned isDefinition() const { return getUnsignedField(9); }
420 unsigned getVirtuality() const { return getUnsignedField(10); }
421 unsigned getVirtualIndex() const { return getUnsignedField(11); }
423 DICompositeType getContainingType() const {
424 return getFieldAs<DICompositeType>(12);
427 unsigned getFlags() const {
428 return getUnsignedField(13);
431 unsigned isArtificial() const {
432 return (getUnsignedField(13) & FlagArtificial) != 0;
434 /// isPrivate - Return true if this subprogram has "private"
435 /// access specifier.
436 bool isPrivate() const {
437 return (getUnsignedField(13) & FlagPrivate) != 0;
439 /// isProtected - Return true if this subprogram has "protected"
440 /// access specifier.
441 bool isProtected() const {
442 return (getUnsignedField(13) & FlagProtected) != 0;
444 /// isExplicit - Return true if this subprogram is marked as explicit.
445 bool isExplicit() const {
446 return (getUnsignedField(13) & FlagExplicit) != 0;
448 /// isPrototyped - Return true if this subprogram is prototyped.
449 bool isPrototyped() const {
450 return (getUnsignedField(13) & FlagPrototyped) != 0;
453 unsigned isOptimized() const;
455 /// Verify - Verify that a subprogram descriptor is well formed.
458 /// describes - Return true if this subprogram provides debugging
459 /// information for the function F.
460 bool describes(const Function *F);
462 Function *getFunction() const { return getFunctionField(15); }
463 void replaceFunction(Function *F) { replaceFunctionField(15, F); }
464 DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
465 DISubprogram getFunctionDeclaration() const {
466 return getFieldAs<DISubprogram>(17);
468 MDNode *getVariablesNodes() const;
469 DIArray getVariables() const;
471 /// getScopeLineNumber - Get the beginning of the scope of the
472 /// function, not necessarily where the name of the program
474 unsigned getScopeLineNumber() const { return getUnsignedField(19); }
477 /// DILexicalBlock - This is a wrapper for a lexical block.
478 class DILexicalBlock : public DIScope {
480 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
481 DIScope getContext() const { return getFieldAs<DIScope>(2); }
482 unsigned getLineNumber() const { return getUnsignedField(3); }
483 unsigned getColumnNumber() const { return getUnsignedField(4); }
487 /// DILexicalBlockFile - This is a wrapper for a lexical block with
488 /// a filename change.
489 class DILexicalBlockFile : public DIScope {
491 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
492 DIScope getContext() const {
493 if (getScope().isSubprogram())
495 return getScope().getContext();
497 unsigned getLineNumber() const { return getScope().getLineNumber(); }
498 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
499 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
503 /// DINameSpace - A wrapper for a C++ style name space.
504 class DINameSpace : public DIScope {
505 friend class DIDescriptor;
506 void printInternal(raw_ostream &OS) const;
508 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
509 DIScope getContext() const { return getFieldAs<DIScope>(2); }
510 StringRef getName() const { return getStringField(3); }
511 unsigned getLineNumber() const { return getUnsignedField(4); }
515 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
516 class DITemplateTypeParameter : public DIDescriptor {
518 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
520 DIScope getContext() const { return getFieldAs<DIScope>(1); }
521 StringRef getName() const { return getStringField(2); }
522 DIType getType() const { return getFieldAs<DIType>(3); }
523 StringRef getFilename() const {
524 return getFieldAs<DIFile>(4).getFilename();
526 StringRef getDirectory() const {
527 return getFieldAs<DIFile>(4).getDirectory();
529 unsigned getLineNumber() const { return getUnsignedField(5); }
530 unsigned getColumnNumber() const { return getUnsignedField(6); }
534 /// DITemplateValueParameter - This is a wrapper for template value parameter.
535 class DITemplateValueParameter : public DIDescriptor {
537 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
539 DIScope getContext() const { return getFieldAs<DIScope>(1); }
540 StringRef getName() const { return getStringField(2); }
541 DIType getType() const { return getFieldAs<DIType>(3); }
542 Value *getValue() const;
543 StringRef getFilename() const {
544 return getFieldAs<DIFile>(5).getFilename();
546 StringRef getDirectory() const {
547 return getFieldAs<DIFile>(5).getDirectory();
549 unsigned getLineNumber() const { return getUnsignedField(6); }
550 unsigned getColumnNumber() const { return getUnsignedField(7); }
554 /// DIGlobalVariable - This is a wrapper for a global variable.
555 class DIGlobalVariable : public DIDescriptor {
556 friend class DIDescriptor;
557 void printInternal(raw_ostream &OS) const;
559 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
561 DIScope getContext() const { return getFieldAs<DIScope>(2); }
562 StringRef getName() const { return getStringField(3); }
563 StringRef getDisplayName() const { return getStringField(4); }
564 StringRef getLinkageName() const { return getStringField(5); }
565 StringRef getFilename() const {
566 return getFieldAs<DIFile>(6).getFilename();
568 StringRef getDirectory() const {
569 return getFieldAs<DIFile>(6).getDirectory();
573 unsigned getLineNumber() const { return getUnsignedField(7); }
574 DIType getType() const { return getFieldAs<DIType>(8); }
575 unsigned isLocalToUnit() const { return getUnsignedField(9); }
576 unsigned isDefinition() const { return getUnsignedField(10); }
578 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
579 Constant *getConstant() const { return getConstantField(11); }
580 DIDerivedType getStaticDataMemberDeclaration() const {
581 return getFieldAs<DIDerivedType>(12);
584 /// Verify - Verify that a global variable descriptor is well formed.
588 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
590 class DIVariable : public DIDescriptor {
591 friend class DIDescriptor;
592 void printInternal(raw_ostream &OS) const;
594 explicit DIVariable(const MDNode *N = 0) : DIDescriptor(N) {}
596 DIScope getContext() const { return getFieldAs<DIScope>(1); }
597 StringRef getName() const { return getStringField(2); }
598 DIFile getFile() const { return getFieldAs<DIFile>(3); }
599 unsigned getLineNumber() const {
600 return (getUnsignedField(4) << 8) >> 8;
602 unsigned getArgNumber() const {
603 unsigned L = getUnsignedField(4);
606 DIType getType() const { return getFieldAs<DIType>(5); }
608 /// isArtificial - Return true if this variable is marked as "artificial".
609 bool isArtificial() const {
610 return (getUnsignedField(6) & FlagArtificial) != 0;
613 bool isObjectPointer() const {
614 return (getUnsignedField(6) & FlagObjectPointer) != 0;
617 /// \brief Return true if this variable is represented as a pointer.
618 bool isIndirect() const {
619 return (getUnsignedField(6) & FlagIndirectVariable) != 0;
622 /// getInlinedAt - If this variable is inlined then return inline location.
623 MDNode *getInlinedAt() const;
625 /// Verify - Verify that a variable descriptor is well formed.
628 /// HasComplexAddr - Return true if the variable has a complex address.
629 bool hasComplexAddress() const {
630 return getNumAddrElements() > 0;
633 unsigned getNumAddrElements() const;
635 uint64_t getAddrElement(unsigned Idx) const {
636 return getUInt64Field(Idx+8);
639 /// isBlockByrefVariable - Return true if the variable was declared as
640 /// a "__block" variable (Apple Blocks).
641 bool isBlockByrefVariable() const {
642 return getType().isBlockByrefStruct();
645 /// isInlinedFnArgument - Return true if this variable provides debugging
646 /// information for an inlined function arguments.
647 bool isInlinedFnArgument(const Function *CurFn);
649 void printExtendedName(raw_ostream &OS) const;
652 /// DILocation - This object holds location information. This object
653 /// is not associated with any DWARF tag.
654 class DILocation : public DIDescriptor {
656 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
658 unsigned getLineNumber() const { return getUnsignedField(0); }
659 unsigned getColumnNumber() const { return getUnsignedField(1); }
660 DIScope getScope() const { return getFieldAs<DIScope>(2); }
661 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
662 StringRef getFilename() const { return getScope().getFilename(); }
663 StringRef getDirectory() const { return getScope().getDirectory(); }
667 class DIObjCProperty : public DIDescriptor {
668 friend class DIDescriptor;
669 void printInternal(raw_ostream &OS) const;
671 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
673 StringRef getObjCPropertyName() const { return getStringField(1); }
674 DIFile getFile() const { return getFieldAs<DIFile>(2); }
675 unsigned getLineNumber() const { return getUnsignedField(3); }
677 StringRef getObjCPropertyGetterName() const {
678 return getStringField(4);
680 StringRef getObjCPropertySetterName() const {
681 return getStringField(5);
683 bool isReadOnlyObjCProperty() const {
684 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
686 bool isReadWriteObjCProperty() const {
687 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
689 bool isAssignObjCProperty() const {
690 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
692 bool isRetainObjCProperty() const {
693 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
695 bool isCopyObjCProperty() const {
696 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
698 bool isNonAtomicObjCProperty() const {
699 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
702 DIType getType() const { return getFieldAs<DIType>(7); }
704 /// Verify - Verify that a derived type descriptor is well formed.
708 /// \brief An imported module (C++ using directive or similar).
709 class DIImportedEntity : public DIDescriptor {
710 friend class DIDescriptor;
711 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 /// isSubprogramContext - Return true if Context is either a subprogram
728 /// or another context nested inside a subprogram.
729 bool isSubprogramContext(const MDNode *Context);
731 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
732 /// to hold function specific information.
733 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
735 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
736 /// suitable to hold function specific information.
737 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
739 /// createInlinedVariable - Create a new inlined variable based on current
741 /// @param DV Current Variable.
742 /// @param InlinedScope Location at current variable is inlined.
743 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
744 LLVMContext &VMContext);
746 /// cleanseInlinedVariable - Remove inlined scope from the variable.
747 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
749 /// Construct DITypeIdentifierMap by going through retained types of each CU.
750 DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
752 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
753 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
754 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
755 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
756 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
758 class DebugInfoFinder {
760 /// processModule - Process entire module and collect debug info
762 void processModule(const Module &M);
764 /// processDeclare - Process DbgDeclareInst.
765 void processDeclare(const DbgDeclareInst *DDI);
766 /// Process DbgValueInst.
767 void processValue(const DbgValueInst *DVI);
768 /// processLocation - Process DILocation.
769 void processLocation(DILocation Loc);
774 /// processType - Process DIType.
775 void processType(DIType DT);
777 /// processLexicalBlock - Process DILexicalBlock.
778 void processLexicalBlock(DILexicalBlock LB);
780 /// processSubprogram - Process DISubprogram.
781 void processSubprogram(DISubprogram SP);
783 void processScope(DIScope Scope);
785 /// addCompileUnit - Add compile unit into CUs.
786 bool addCompileUnit(DICompileUnit CU);
788 /// addGlobalVariable - Add global variable into GVs.
789 bool addGlobalVariable(DIGlobalVariable DIG);
791 // addSubprogram - Add subprogram into SPs.
792 bool addSubprogram(DISubprogram SP);
794 /// addType - Add type into Tys.
795 bool addType(DIType DT);
797 bool addScope(DIScope Scope);
800 typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
801 iterator compile_unit_begin() const { return CUs.begin(); }
802 iterator compile_unit_end() const { return CUs.end(); }
803 iterator subprogram_begin() const { return SPs.begin(); }
804 iterator subprogram_end() const { return SPs.end(); }
805 iterator global_variable_begin() const { return GVs.begin(); }
806 iterator global_variable_end() const { return GVs.end(); }
807 iterator type_begin() const { return TYs.begin(); }
808 iterator type_end() const { return TYs.end(); }
809 iterator scope_begin() const { return Scopes.begin(); }
810 iterator scope_end() const { return Scopes.end(); }
812 unsigned compile_unit_count() const { return CUs.size(); }
813 unsigned global_variable_count() const { return GVs.size(); }
814 unsigned subprogram_count() const { return SPs.size(); }
815 unsigned type_count() const { return TYs.size(); }
816 unsigned scope_count() const { return Scopes.size(); }
819 SmallVector<MDNode *, 8> CUs; // Compile Units
820 SmallVector<MDNode *, 8> SPs; // Subprograms
821 SmallVector<MDNode *, 8> GVs; // Global Variables;
822 SmallVector<MDNode *, 8> TYs; // Types
823 SmallVector<MDNode *, 8> Scopes; // Scopes
824 SmallPtrSet<MDNode *, 64> NodesSeen;
826 } // end namespace llvm