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 DIScopeRef so DIScopeRef can befriend the protected member
60 // function: getFieldAs<DIScopeRef>.
61 friend class DIScopeRef;
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 /// npecialize getFieldAs to handle fields that are references to DIScopes.
156 DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const;
158 /// DISubrange - This is used to represent ranges, for array bounds.
159 class DISubrange : public DIDescriptor {
160 friend class DIDescriptor;
161 void printInternal(raw_ostream &OS) const;
163 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
165 int64_t getLo() const { return getInt64Field(1); }
166 int64_t getCount() const { return getInt64Field(2); }
170 /// DIArray - This descriptor holds an array of descriptors.
171 class DIArray : public DIDescriptor {
173 explicit DIArray(const MDNode *N = 0) : DIDescriptor(N) {}
175 unsigned getNumElements() const;
176 DIDescriptor getElement(unsigned Idx) const {
177 return getDescriptorField(Idx);
181 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
182 /// FIXME: it seems strange that this doesn't have either a reference to the
183 /// type/precision or a file/line pair for location info.
184 class DIEnumerator : public DIDescriptor {
185 friend class DIDescriptor;
186 void printInternal(raw_ostream &OS) const;
188 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
190 StringRef getName() const { return getStringField(1); }
191 int64_t getEnumValue() const { return getInt64Field(2); }
195 /// DIScope - A base class for various scopes.
196 class DIScope : public DIDescriptor {
198 friend class DIDescriptor;
199 void printInternal(raw_ostream &OS) const;
201 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
203 /// Gets the parent scope for this scope node or returns a
204 /// default constructed scope.
205 DIScope getContext() const;
206 StringRef getFilename() const;
207 StringRef getDirectory() const;
209 /// Generate a reference to this DIScope. Uses the type identifier instead
210 /// of the actual MDNode if possible, to help type uniquing.
211 Value *generateRef();
214 /// Represents reference to a DIScope, abstracts over direct and
215 /// identifier-based metadata scope references.
217 template <typename DescTy>
218 friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;
220 /// Val can be either a MDNode or a MDString, in the latter,
221 /// MDString specifies the type identifier.
223 explicit DIScopeRef(const Value *V);
225 DIScope resolve(const DITypeIdentifierMap &Map) const;
226 operator Value *() const { return const_cast<Value*>(Val); }
229 /// DIType - This is a wrapper for a type.
230 /// FIXME: Types should be factored much better so that CV qualifiers and
231 /// others do not require a huge and empty descriptor full of zeros.
232 class DIType : public DIScope {
234 friend class DIDescriptor;
235 void printInternal(raw_ostream &OS) const;
238 DIType(const MDNode *N = 0) : DIScope(N) {}
240 /// Verify - Verify that a type descriptor is well formed.
243 DIScope getContext() const { return getFieldAs<DIScope>(2); }
244 StringRef getName() const { return getStringField(3); }
245 unsigned getLineNumber() const { return getUnsignedField(4); }
246 uint64_t getSizeInBits() const { return getUInt64Field(5); }
247 uint64_t getAlignInBits() const { return getUInt64Field(6); }
248 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
249 // carry this is just plain insane.
250 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
251 unsigned getFlags() const { return getUnsignedField(8); }
252 bool isPrivate() const {
253 return (getFlags() & FlagPrivate) != 0;
255 bool isProtected() const {
256 return (getFlags() & FlagProtected) != 0;
258 bool isForwardDecl() const {
259 return (getFlags() & FlagFwdDecl) != 0;
261 // isAppleBlock - Return true if this is the Apple Blocks extension.
262 bool isAppleBlockExtension() const {
263 return (getFlags() & FlagAppleBlock) != 0;
265 bool isBlockByrefStruct() const {
266 return (getFlags() & FlagBlockByrefStruct) != 0;
268 bool isVirtual() const {
269 return (getFlags() & FlagVirtual) != 0;
271 bool isArtificial() const {
272 return (getFlags() & FlagArtificial) != 0;
274 bool isObjectPointer() const {
275 return (getFlags() & FlagObjectPointer) != 0;
277 bool isObjcClassComplete() const {
278 return (getFlags() & FlagObjcClassComplete) != 0;
280 bool isVector() const {
281 return (getFlags() & FlagVector) != 0;
283 bool isStaticMember() const {
284 return (getFlags() & FlagStaticMember) != 0;
286 bool isValid() const {
287 return DbgNode && isType();
290 /// isUnsignedDIType - Return true if type encoding is unsigned.
291 bool isUnsignedDIType();
293 /// replaceAllUsesWith - Replace all uses of debug info referenced by
295 void replaceAllUsesWith(DIDescriptor &D);
296 void replaceAllUsesWith(MDNode *D);
299 /// DIBasicType - A basic type, like 'int' or 'float'.
300 class DIBasicType : public DIType {
302 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
304 unsigned getEncoding() const { return getUnsignedField(9); }
306 /// Verify - Verify that a basic type descriptor is well formed.
310 /// DIDerivedType - A simple derived type, like a const qualified type,
311 /// a typedef, a pointer or reference, et cetera. Or, a data member of
312 /// a class/struct/union.
313 class DIDerivedType : public DIType {
314 friend class DIDescriptor;
315 void printInternal(raw_ostream &OS) const;
318 explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
320 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
322 /// getOriginalTypeSize - If this type is derived from a base type then
323 /// return base type size.
324 uint64_t getOriginalTypeSize() const;
326 /// getObjCProperty - Return property node, if this ivar is
327 /// associated with one.
328 MDNode *getObjCProperty() const;
330 DIScopeRef getClassType() const {
331 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
332 return getFieldAs<DIScopeRef>(10);
335 Constant *getConstant() const {
336 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
337 return getConstantField(10);
340 /// Verify - Verify that a derived type descriptor is well formed.
344 /// DICompositeType - This descriptor holds a type that can refer to multiple
345 /// other types, like a function or struct.
346 /// DICompositeType is derived from DIDerivedType because some
347 /// composite types (such as enums) can be derived from basic types
348 // FIXME: Make this derive from DIType directly & just store the
349 // base type in a single DIType field.
350 class DICompositeType : public DIDerivedType {
351 friend class DIDescriptor;
352 void printInternal(raw_ostream &OS) const;
354 explicit DICompositeType(const MDNode *N = 0) : DIDerivedType(N) {}
356 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
357 void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
358 void addMember(DIDescriptor D);
359 unsigned getRunTimeLang() const { return getUnsignedField(11); }
360 DIScopeRef getContainingType() const {
361 return getFieldAs<DIScopeRef>(12);
363 void setContainingType(DICompositeType ContainingType);
364 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
365 MDString *getIdentifier() const;
367 /// Verify - Verify that a composite type descriptor is well formed.
371 /// DIFile - This is a wrapper for a file.
372 class DIFile : public DIScope {
373 friend class DIDescriptor;
375 explicit DIFile(const MDNode *N = 0) : DIScope(N) {}
376 MDNode *getFileNode() const;
380 /// DICompileUnit - A wrapper for a compile unit.
381 class DICompileUnit : public DIScope {
382 friend class DIDescriptor;
383 void printInternal(raw_ostream &OS) const;
385 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
387 unsigned getLanguage() const { return getUnsignedField(2); }
388 StringRef getProducer() const { return getStringField(3); }
390 bool isOptimized() const { return getUnsignedField(4) != 0; }
391 StringRef getFlags() const { return getStringField(5); }
392 unsigned getRunTimeVersion() const { return getUnsignedField(6); }
394 DIArray getEnumTypes() const;
395 DIArray getRetainedTypes() const;
396 DIArray getSubprograms() const;
397 DIArray getGlobalVariables() const;
398 DIArray getImportedEntities() const;
400 StringRef getSplitDebugFilename() const { return getStringField(12); }
402 /// Verify - Verify that a compile unit is well formed.
406 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
407 class DISubprogram : public DIScope {
408 friend class DIDescriptor;
409 void printInternal(raw_ostream &OS) const;
411 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
413 DIScope getContext() const { return getFieldAs<DIScope>(2); }
414 StringRef getName() const { return getStringField(3); }
415 StringRef getDisplayName() const { return getStringField(4); }
416 StringRef getLinkageName() const { return getStringField(5); }
417 unsigned getLineNumber() const { return getUnsignedField(6); }
418 DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
420 /// isLocalToUnit - Return true if this subprogram is local to the current
421 /// compile unit, like 'static' in C.
422 unsigned isLocalToUnit() const { return getUnsignedField(8); }
423 unsigned isDefinition() const { return getUnsignedField(9); }
425 unsigned getVirtuality() const { return getUnsignedField(10); }
426 unsigned getVirtualIndex() const { return getUnsignedField(11); }
428 DIScopeRef getContainingType() const {
429 return getFieldAs<DIScopeRef>(12);
432 unsigned getFlags() const {
433 return getUnsignedField(13);
436 unsigned isArtificial() const {
437 return (getUnsignedField(13) & FlagArtificial) != 0;
439 /// isPrivate - Return true if this subprogram has "private"
440 /// access specifier.
441 bool isPrivate() const {
442 return (getUnsignedField(13) & FlagPrivate) != 0;
444 /// isProtected - Return true if this subprogram has "protected"
445 /// access specifier.
446 bool isProtected() const {
447 return (getUnsignedField(13) & FlagProtected) != 0;
449 /// isExplicit - Return true if this subprogram is marked as explicit.
450 bool isExplicit() const {
451 return (getUnsignedField(13) & FlagExplicit) != 0;
453 /// isPrototyped - Return true if this subprogram is prototyped.
454 bool isPrototyped() const {
455 return (getUnsignedField(13) & FlagPrototyped) != 0;
458 unsigned isOptimized() const;
460 /// Verify - Verify that a subprogram descriptor is well formed.
463 /// describes - Return true if this subprogram provides debugging
464 /// information for the function F.
465 bool describes(const Function *F);
467 Function *getFunction() const { return getFunctionField(15); }
468 void replaceFunction(Function *F) { replaceFunctionField(15, F); }
469 DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
470 DISubprogram getFunctionDeclaration() const {
471 return getFieldAs<DISubprogram>(17);
473 MDNode *getVariablesNodes() const;
474 DIArray getVariables() const;
476 /// getScopeLineNumber - Get the beginning of the scope of the
477 /// function, not necessarily where the name of the program
479 unsigned getScopeLineNumber() const { return getUnsignedField(19); }
482 /// DILexicalBlock - This is a wrapper for a lexical block.
483 class DILexicalBlock : public DIScope {
485 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
486 DIScope getContext() const { return getFieldAs<DIScope>(2); }
487 unsigned getLineNumber() const { return getUnsignedField(3); }
488 unsigned getColumnNumber() const { return getUnsignedField(4); }
492 /// DILexicalBlockFile - This is a wrapper for a lexical block with
493 /// a filename change.
494 class DILexicalBlockFile : public DIScope {
496 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
497 DIScope getContext() const {
498 if (getScope().isSubprogram())
500 return getScope().getContext();
502 unsigned getLineNumber() const { return getScope().getLineNumber(); }
503 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
504 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
508 /// DINameSpace - A wrapper for a C++ style name space.
509 class DINameSpace : public DIScope {
510 friend class DIDescriptor;
511 void printInternal(raw_ostream &OS) const;
513 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
514 DIScope getContext() const { return getFieldAs<DIScope>(2); }
515 StringRef getName() const { return getStringField(3); }
516 unsigned getLineNumber() const { return getUnsignedField(4); }
520 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
521 class DITemplateTypeParameter : public DIDescriptor {
523 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
525 DIScope getContext() const { return getFieldAs<DIScope>(1); }
526 StringRef getName() const { return getStringField(2); }
527 DIType getType() const { return getFieldAs<DIType>(3); }
528 StringRef getFilename() const {
529 return getFieldAs<DIFile>(4).getFilename();
531 StringRef getDirectory() const {
532 return getFieldAs<DIFile>(4).getDirectory();
534 unsigned getLineNumber() const { return getUnsignedField(5); }
535 unsigned getColumnNumber() const { return getUnsignedField(6); }
539 /// DITemplateValueParameter - This is a wrapper for template value parameter.
540 class DITemplateValueParameter : public DIDescriptor {
542 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
544 DIScope getContext() const { return getFieldAs<DIScope>(1); }
545 StringRef getName() const { return getStringField(2); }
546 DIType getType() const { return getFieldAs<DIType>(3); }
547 Value *getValue() const;
548 StringRef getFilename() const {
549 return getFieldAs<DIFile>(5).getFilename();
551 StringRef getDirectory() const {
552 return getFieldAs<DIFile>(5).getDirectory();
554 unsigned getLineNumber() const { return getUnsignedField(6); }
555 unsigned getColumnNumber() const { return getUnsignedField(7); }
559 /// DIGlobalVariable - This is a wrapper for a global variable.
560 class DIGlobalVariable : public DIDescriptor {
561 friend class DIDescriptor;
562 void printInternal(raw_ostream &OS) const;
564 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
566 DIScope getContext() const { return getFieldAs<DIScope>(2); }
567 StringRef getName() const { return getStringField(3); }
568 StringRef getDisplayName() const { return getStringField(4); }
569 StringRef getLinkageName() const { return getStringField(5); }
570 StringRef getFilename() const {
571 return getFieldAs<DIFile>(6).getFilename();
573 StringRef getDirectory() const {
574 return getFieldAs<DIFile>(6).getDirectory();
578 unsigned getLineNumber() const { return getUnsignedField(7); }
579 DIType getType() const { return getFieldAs<DIType>(8); }
580 unsigned isLocalToUnit() const { return getUnsignedField(9); }
581 unsigned isDefinition() const { return getUnsignedField(10); }
583 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
584 Constant *getConstant() const { return getConstantField(11); }
585 DIDerivedType getStaticDataMemberDeclaration() const {
586 return getFieldAs<DIDerivedType>(12);
589 /// Verify - Verify that a global variable descriptor is well formed.
593 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
595 class DIVariable : public DIDescriptor {
596 friend class DIDescriptor;
597 void printInternal(raw_ostream &OS) const;
599 explicit DIVariable(const MDNode *N = 0) : DIDescriptor(N) {}
601 DIScope getContext() const { return getFieldAs<DIScope>(1); }
602 StringRef getName() const { return getStringField(2); }
603 DIFile getFile() const { return getFieldAs<DIFile>(3); }
604 unsigned getLineNumber() const {
605 return (getUnsignedField(4) << 8) >> 8;
607 unsigned getArgNumber() const {
608 unsigned L = getUnsignedField(4);
611 DIType getType() const { return getFieldAs<DIType>(5); }
613 /// isArtificial - Return true if this variable is marked as "artificial".
614 bool isArtificial() const {
615 return (getUnsignedField(6) & FlagArtificial) != 0;
618 bool isObjectPointer() const {
619 return (getUnsignedField(6) & FlagObjectPointer) != 0;
622 /// \brief Return true if this variable is represented as a pointer.
623 bool isIndirect() const {
624 return (getUnsignedField(6) & FlagIndirectVariable) != 0;
627 /// getInlinedAt - If this variable is inlined then return inline location.
628 MDNode *getInlinedAt() const;
630 /// Verify - Verify that a variable descriptor is well formed.
633 /// HasComplexAddr - Return true if the variable has a complex address.
634 bool hasComplexAddress() const {
635 return getNumAddrElements() > 0;
638 unsigned getNumAddrElements() const;
640 uint64_t getAddrElement(unsigned Idx) const {
641 return getUInt64Field(Idx+8);
644 /// isBlockByrefVariable - Return true if the variable was declared as
645 /// a "__block" variable (Apple Blocks).
646 bool isBlockByrefVariable() const {
647 return getType().isBlockByrefStruct();
650 /// isInlinedFnArgument - Return true if this variable provides debugging
651 /// information for an inlined function arguments.
652 bool isInlinedFnArgument(const Function *CurFn);
654 void printExtendedName(raw_ostream &OS) const;
657 /// DILocation - This object holds location information. This object
658 /// is not associated with any DWARF tag.
659 class DILocation : public DIDescriptor {
661 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
663 unsigned getLineNumber() const { return getUnsignedField(0); }
664 unsigned getColumnNumber() const { return getUnsignedField(1); }
665 DIScope getScope() const { return getFieldAs<DIScope>(2); }
666 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
667 StringRef getFilename() const { return getScope().getFilename(); }
668 StringRef getDirectory() const { return getScope().getDirectory(); }
672 class DIObjCProperty : public DIDescriptor {
673 friend class DIDescriptor;
674 void printInternal(raw_ostream &OS) const;
676 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
678 StringRef getObjCPropertyName() const { return getStringField(1); }
679 DIFile getFile() const { return getFieldAs<DIFile>(2); }
680 unsigned getLineNumber() const { return getUnsignedField(3); }
682 StringRef getObjCPropertyGetterName() const {
683 return getStringField(4);
685 StringRef getObjCPropertySetterName() const {
686 return getStringField(5);
688 bool isReadOnlyObjCProperty() const {
689 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
691 bool isReadWriteObjCProperty() const {
692 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
694 bool isAssignObjCProperty() const {
695 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
697 bool isRetainObjCProperty() const {
698 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
700 bool isCopyObjCProperty() const {
701 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
703 bool isNonAtomicObjCProperty() const {
704 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
707 DIType getType() const { return getFieldAs<DIType>(7); }
709 /// Verify - Verify that a derived type descriptor is well formed.
713 /// \brief An imported module (C++ using directive or similar).
714 class DIImportedEntity : public DIDescriptor {
715 friend class DIDescriptor;
716 void printInternal(raw_ostream &OS) const;
718 explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) { }
719 DIScope getContext() const { return getFieldAs<DIScope>(1); }
720 DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
721 unsigned getLineNumber() const { return getUnsignedField(3); }
722 StringRef getName() const { return getStringField(4); }
726 /// getDISubprogram - Find subprogram that is enclosing this scope.
727 DISubprogram getDISubprogram(const MDNode *Scope);
729 /// getDICompositeType - Find underlying composite type.
730 DICompositeType getDICompositeType(DIType T);
732 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
733 /// to hold function specific information.
734 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
736 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
737 /// suitable to hold function specific information.
738 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
740 /// createInlinedVariable - Create a new inlined variable based on current
742 /// @param DV Current Variable.
743 /// @param InlinedScope Location at current variable is inlined.
744 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
745 LLVMContext &VMContext);
747 /// cleanseInlinedVariable - Remove inlined scope from the variable.
748 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
750 /// Construct DITypeIdentifierMap by going through retained types of each CU.
751 DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
753 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
754 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
755 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
756 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
757 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
759 class DebugInfoFinder {
761 /// processModule - Process entire module and collect debug info
763 void processModule(const Module &M);
765 /// processDeclare - Process DbgDeclareInst.
766 void processDeclare(const DbgDeclareInst *DDI);
767 /// Process DbgValueInst.
768 void processValue(const DbgValueInst *DVI);
769 /// processLocation - Process DILocation.
770 void processLocation(DILocation Loc);
775 /// processType - Process DIType.
776 void processType(DIType DT);
778 /// processLexicalBlock - Process DILexicalBlock.
779 void processLexicalBlock(DILexicalBlock LB);
781 /// processSubprogram - Process DISubprogram.
782 void processSubprogram(DISubprogram SP);
784 void processScope(DIScope Scope);
786 /// addCompileUnit - Add compile unit into CUs.
787 bool addCompileUnit(DICompileUnit CU);
789 /// addGlobalVariable - Add global variable into GVs.
790 bool addGlobalVariable(DIGlobalVariable DIG);
792 // addSubprogram - Add subprogram into SPs.
793 bool addSubprogram(DISubprogram SP);
795 /// addType - Add type into Tys.
796 bool addType(DIType DT);
798 bool addScope(DIScope Scope);
801 typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
802 iterator compile_unit_begin() const { return CUs.begin(); }
803 iterator compile_unit_end() const { return CUs.end(); }
804 iterator subprogram_begin() const { return SPs.begin(); }
805 iterator subprogram_end() const { return SPs.end(); }
806 iterator global_variable_begin() const { return GVs.begin(); }
807 iterator global_variable_end() const { return GVs.end(); }
808 iterator type_begin() const { return TYs.begin(); }
809 iterator type_end() const { return TYs.end(); }
810 iterator scope_begin() const { return Scopes.begin(); }
811 iterator scope_end() const { return Scopes.end(); }
813 unsigned compile_unit_count() const { return CUs.size(); }
814 unsigned global_variable_count() const { return GVs.size(); }
815 unsigned subprogram_count() const { return SPs.size(); }
816 unsigned type_count() const { return TYs.size(); }
817 unsigned scope_count() const { return Scopes.size(); }
820 SmallVector<MDNode *, 8> CUs; // Compile Units
821 SmallVector<MDNode *, 8> SPs; // Subprograms
822 SmallVector<MDNode *, 8> GVs; // Global Variables;
823 SmallVector<MDNode *, 8> TYs; // Types
824 SmallVector<MDNode *, 8> Scopes; // Scopes
825 SmallPtrSet<MDNode *, 64> NodesSeen;
827 } // end namespace llvm