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_ANALYSIS_DEBUGINFO_H
18 #define LLVM_ANALYSIS_DEBUGINFO_H
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/Dwarf.h"
46 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
47 /// This should not be stored in a container, because underly MDNode may
48 /// change in certain situations.
53 FlagProtected = 1 << 1,
55 FlagAppleBlock = 1 << 3,
56 FlagBlockByrefStruct = 1 << 4,
58 FlagArtificial = 1 << 6,
59 FlagExplicit = 1 << 7,
60 FlagPrototyped = 1 << 8,
61 FlagObjcClassComplete = 1 << 9
64 const MDNode *DbgNode;
66 StringRef getStringField(unsigned Elt) const;
67 unsigned getUnsignedField(unsigned Elt) const {
68 return (unsigned)getUInt64Field(Elt);
70 uint64_t getUInt64Field(unsigned Elt) const;
71 DIDescriptor getDescriptorField(unsigned Elt) const;
73 template <typename DescTy>
74 DescTy getFieldAs(unsigned Elt) const {
75 return DescTy(getDescriptorField(Elt));
78 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
79 Constant *getConstantField(unsigned Elt) const;
80 Function *getFunctionField(unsigned Elt) const;
83 explicit DIDescriptor() : DbgNode(0) {}
84 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
85 explicit DIDescriptor(const DIFile F);
86 explicit DIDescriptor(const DISubprogram F);
87 explicit DIDescriptor(const DILexicalBlock F);
88 explicit DIDescriptor(const DIVariable F);
89 explicit DIDescriptor(const DIType F);
91 bool Verify() const { return DbgNode != 0; }
93 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
94 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
96 unsigned getVersion() const {
97 return getUnsignedField(0) & LLVMDebugVersionMask;
100 unsigned getTag() const {
101 return getUnsignedField(0) & ~LLVMDebugVersionMask;
104 /// print - print descriptor.
105 void print(raw_ostream &OS) const;
107 /// dump - print descriptor to dbgs() with a newline.
110 bool isDerivedType() const;
111 bool isCompositeType() const;
112 bool isBasicType() const;
113 bool isVariable() const;
114 bool isSubprogram() const;
115 bool isGlobalVariable() const;
116 bool isScope() const;
118 bool isCompileUnit() const;
119 bool isNameSpace() const;
120 bool isLexicalBlock() const;
121 bool isSubrange() const;
122 bool isEnumerator() const;
124 bool isGlobal() const;
125 bool isUnspecifiedParameter() const;
126 bool isTemplateTypeParameter() const;
127 bool isTemplateValueParameter() const;
130 /// DISubrange - This is used to represent ranges, for array bounds.
131 class DISubrange : public DIDescriptor {
133 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
135 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
136 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
139 /// DIArray - This descriptor holds an array of descriptors.
140 class DIArray : public DIDescriptor {
142 explicit DIArray(const MDNode *N = 0)
145 unsigned getNumElements() const;
146 DIDescriptor getElement(unsigned Idx) const {
147 return getDescriptorField(Idx);
151 /// DIScope - A base class for various scopes.
152 class DIScope : public DIDescriptor {
154 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
155 virtual ~DIScope() {}
157 StringRef getFilename() const;
158 StringRef getDirectory() const;
161 /// DICompileUnit - A wrapper for a compile unit.
162 class DICompileUnit : public DIScope {
164 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
166 unsigned getLanguage() const { return getUnsignedField(2); }
167 StringRef getFilename() const { return getStringField(3); }
168 StringRef getDirectory() const { return getStringField(4); }
169 StringRef getProducer() const { return getStringField(5); }
171 /// isMain - Each input file is encoded as a separate compile unit in LLVM
172 /// debugging information output. However, many target specific tool chains
173 /// prefer to encode only one compile unit in an object file. In this
174 /// situation, the LLVM code generator will include debugging information
175 /// entities in the compile unit that is marked as main compile unit. The
176 /// code generator accepts maximum one main compile unit per module. If a
177 /// module does not contain any main compile unit then the code generator
178 /// will emit multiple compile units in the output object file.
180 bool isMain() const { return getUnsignedField(6) != 0; }
181 bool isOptimized() const { return getUnsignedField(7) != 0; }
182 StringRef getFlags() const { return getStringField(8); }
183 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
185 DIArray getEnumTypes() const;
186 DIArray getRetainedTypes() const;
187 DIArray getSubprograms() const;
188 DIArray getGlobalVariables() const;
190 /// Verify - Verify that a compile unit is well formed.
193 /// print - print compile unit.
194 void print(raw_ostream &OS) const;
196 /// dump - print compile unit to dbgs() with a newline.
200 /// DIFile - This is a wrapper for a file.
201 class DIFile : public DIScope {
203 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
204 if (DbgNode && !isFile())
207 StringRef getFilename() const { return getStringField(1); }
208 StringRef getDirectory() const { return getStringField(2); }
209 DICompileUnit getCompileUnit() const{
210 assert (getVersion() <= LLVMDebugVersion10 && "Invalid CompileUnit!");
211 return getFieldAs<DICompileUnit>(3);
215 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
216 /// FIXME: it seems strange that this doesn't have either a reference to the
217 /// type/precision or a file/line pair for location info.
218 class DIEnumerator : public DIDescriptor {
220 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
222 StringRef getName() const { return getStringField(1); }
223 uint64_t getEnumValue() const { return getUInt64Field(2); }
226 /// DIType - This is a wrapper for a type.
227 /// FIXME: Types should be factored much better so that CV qualifiers and
228 /// others do not require a huge and empty descriptor full of zeros.
229 class DIType : public DIScope {
232 // This ctor is used when the Tag has already been validated by a derived
234 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
238 /// Verify - Verify that a type descriptor is well formed.
241 explicit DIType(const MDNode *N);
245 DIScope getContext() const { return getFieldAs<DIScope>(1); }
246 StringRef getName() const { return getStringField(2); }
247 DICompileUnit getCompileUnit() const{
248 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
249 if (getVersion() == llvm::LLVMDebugVersion7)
250 return getFieldAs<DICompileUnit>(3);
252 return getFieldAs<DIFile>(3).getCompileUnit();
254 DIFile getFile() const { return getFieldAs<DIFile>(3); }
255 unsigned getLineNumber() const { return getUnsignedField(4); }
256 uint64_t getSizeInBits() const { return getUInt64Field(5); }
257 uint64_t getAlignInBits() const { return getUInt64Field(6); }
258 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
259 // carry this is just plain insane.
260 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
261 unsigned getFlags() const { return getUnsignedField(8); }
262 bool isPrivate() const {
263 return (getFlags() & FlagPrivate) != 0;
265 bool isProtected() const {
266 return (getFlags() & FlagProtected) != 0;
268 bool isForwardDecl() const {
269 return (getFlags() & FlagFwdDecl) != 0;
271 // isAppleBlock - Return true if this is the Apple Blocks extension.
272 bool isAppleBlockExtension() const {
273 return (getFlags() & FlagAppleBlock) != 0;
275 bool isBlockByrefStruct() const {
276 return (getFlags() & FlagBlockByrefStruct) != 0;
278 bool isVirtual() const {
279 return (getFlags() & FlagVirtual) != 0;
281 bool isArtificial() const {
282 return (getFlags() & FlagArtificial) != 0;
284 bool isObjcClassComplete() const {
285 return (getFlags() & FlagObjcClassComplete) != 0;
287 bool isValid() const {
288 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
290 StringRef getDirectory() const {
291 if (getVersion() == llvm::LLVMDebugVersion7)
292 return getCompileUnit().getDirectory();
294 return getFieldAs<DIFile>(3).getDirectory();
296 StringRef getFilename() const {
297 if (getVersion() == llvm::LLVMDebugVersion7)
298 return getCompileUnit().getFilename();
300 return getFieldAs<DIFile>(3).getFilename();
303 /// isUnsignedDIType - Return true if type encoding is unsigned.
304 bool isUnsignedDIType();
306 /// replaceAllUsesWith - Replace all uses of debug info referenced by
308 void replaceAllUsesWith(DIDescriptor &D);
309 void replaceAllUsesWith(MDNode *D);
311 /// print - print type.
312 void print(raw_ostream &OS) const;
314 /// dump - print type to dbgs() with a newline.
318 /// DIBasicType - A basic type, like 'int' or 'float'.
319 class DIBasicType : public DIType {
321 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
323 unsigned getEncoding() const { return getUnsignedField(9); }
325 /// Verify - Verify that a basic type descriptor is well formed.
328 /// print - print basic type.
329 void print(raw_ostream &OS) const;
331 /// dump - print basic type to dbgs() with a newline.
335 /// DIDerivedType - A simple derived type, like a const qualified type,
336 /// a typedef, a pointer or reference, etc.
337 class DIDerivedType : public DIType {
339 explicit DIDerivedType(const MDNode *N, bool, bool)
340 : DIType(N, true, true) {}
342 explicit DIDerivedType(const MDNode *N = 0)
343 : DIType(N, true, true) {}
345 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
347 /// getOriginalTypeSize - If this type is derived from a base type then
348 /// return base type size.
349 uint64_t getOriginalTypeSize() const;
351 StringRef getObjCPropertyName() const { return getStringField(10); }
352 StringRef getObjCPropertyGetterName() const {
353 return getStringField(11);
355 StringRef getObjCPropertySetterName() const {
356 return getStringField(12);
358 bool isReadOnlyObjCProperty() {
359 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
361 bool isReadWriteObjCProperty() {
362 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
364 bool isAssignObjCProperty() {
365 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
367 bool isRetainObjCProperty() {
368 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
370 bool isCopyObjCProperty() {
371 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
373 bool isNonAtomicObjCProperty() {
374 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
377 /// Verify - Verify that a derived type descriptor is well formed.
380 /// print - print derived type.
381 void print(raw_ostream &OS) const;
383 /// dump - print derived type to dbgs() with a newline.
387 /// DICompositeType - This descriptor holds a type that can refer to multiple
388 /// other types, like a function or struct.
389 /// FIXME: Why is this a DIDerivedType??
390 class DICompositeType : public DIDerivedType {
392 explicit DICompositeType(const MDNode *N = 0)
393 : DIDerivedType(N, true, true) {
394 if (N && !isCompositeType())
398 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
399 unsigned getRunTimeLang() const { return getUnsignedField(11); }
400 DICompositeType getContainingType() const {
401 return getFieldAs<DICompositeType>(12);
403 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
405 /// Verify - Verify that a composite type descriptor is well formed.
408 /// print - print composite type.
409 void print(raw_ostream &OS) const;
411 /// dump - print composite type to dbgs() with a newline.
415 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
416 class DITemplateTypeParameter : public DIDescriptor {
418 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
420 DIScope getContext() const { return getFieldAs<DIScope>(1); }
421 StringRef getName() const { return getStringField(2); }
422 DIType getType() const { return getFieldAs<DIType>(3); }
423 StringRef getFilename() const {
424 return getFieldAs<DIFile>(4).getFilename();
426 StringRef getDirectory() const {
427 return getFieldAs<DIFile>(4).getDirectory();
429 unsigned getLineNumber() const { return getUnsignedField(5); }
430 unsigned getColumnNumber() const { return getUnsignedField(6); }
433 /// DITemplateValueParameter - This is a wrapper for template value parameter.
434 class DITemplateValueParameter : public DIDescriptor {
436 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
438 DIScope getContext() const { return getFieldAs<DIScope>(1); }
439 StringRef getName() const { return getStringField(2); }
440 DIType getType() const { return getFieldAs<DIType>(3); }
441 uint64_t getValue() const { return getUInt64Field(4); }
442 StringRef getFilename() const {
443 return getFieldAs<DIFile>(5).getFilename();
445 StringRef getDirectory() const {
446 return getFieldAs<DIFile>(5).getDirectory();
448 unsigned getLineNumber() const { return getUnsignedField(6); }
449 unsigned getColumnNumber() const { return getUnsignedField(7); }
452 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
453 class DISubprogram : public DIScope {
455 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
457 DIScope getContext() const { return getFieldAs<DIScope>(2); }
458 StringRef getName() const { return getStringField(3); }
459 StringRef getDisplayName() const { return getStringField(4); }
460 StringRef getLinkageName() const { return getStringField(5); }
461 DICompileUnit getCompileUnit() const{
462 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
463 if (getVersion() == llvm::LLVMDebugVersion7)
464 return getFieldAs<DICompileUnit>(6);
466 return getFieldAs<DIFile>(6).getCompileUnit();
468 unsigned getLineNumber() const { return getUnsignedField(7); }
469 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
471 /// getReturnTypeName - Subprogram return types are encoded either as
472 /// DIType or as DICompositeType.
473 StringRef getReturnTypeName() const {
474 DICompositeType DCT(getFieldAs<DICompositeType>(8));
476 DIArray A = DCT.getTypeArray();
477 DIType T(A.getElement(0));
480 DIType T(getFieldAs<DIType>(8));
484 /// isLocalToUnit - Return true if this subprogram is local to the current
485 /// compile unit, like 'static' in C.
486 unsigned isLocalToUnit() const { return getUnsignedField(9); }
487 unsigned isDefinition() const { return getUnsignedField(10); }
489 unsigned getVirtuality() const { return getUnsignedField(11); }
490 unsigned getVirtualIndex() const { return getUnsignedField(12); }
492 DICompositeType getContainingType() const {
493 return getFieldAs<DICompositeType>(13);
495 unsigned isArtificial() const {
496 if (getVersion() <= llvm::LLVMDebugVersion8)
497 return getUnsignedField(14);
498 return (getUnsignedField(14) & FlagArtificial) != 0;
500 /// isPrivate - Return true if this subprogram has "private"
501 /// access specifier.
502 bool isPrivate() const {
503 if (getVersion() <= llvm::LLVMDebugVersion8)
505 return (getUnsignedField(14) & FlagPrivate) != 0;
507 /// isProtected - Return true if this subprogram has "protected"
508 /// access specifier.
509 bool isProtected() const {
510 if (getVersion() <= llvm::LLVMDebugVersion8)
512 return (getUnsignedField(14) & FlagProtected) != 0;
514 /// isExplicit - Return true if this subprogram is marked as explicit.
515 bool isExplicit() const {
516 if (getVersion() <= llvm::LLVMDebugVersion8)
518 return (getUnsignedField(14) & FlagExplicit) != 0;
520 /// isPrototyped - Return true if this subprogram is prototyped.
521 bool isPrototyped() const {
522 if (getVersion() <= llvm::LLVMDebugVersion8)
524 return (getUnsignedField(14) & FlagPrototyped) != 0;
527 unsigned isOptimized() const;
529 StringRef getFilename() const {
530 if (getVersion() == llvm::LLVMDebugVersion7)
531 return getCompileUnit().getFilename();
533 return getFieldAs<DIFile>(6).getFilename();
536 StringRef getDirectory() const {
537 if (getVersion() == llvm::LLVMDebugVersion7)
538 return getCompileUnit().getFilename();
540 return getFieldAs<DIFile>(6).getDirectory();
543 /// Verify - Verify that a subprogram descriptor is well formed.
546 /// print - print subprogram.
547 void print(raw_ostream &OS) const;
549 /// dump - print subprogram to dbgs() with a newline.
552 /// describes - Return true if this subprogram provides debugging
553 /// information for the function F.
554 bool describes(const Function *F);
556 Function *getFunction() const { return getFunctionField(16); }
557 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
558 DISubprogram getFunctionDeclaration() const {
559 return getFieldAs<DISubprogram>(18);
561 MDNode *getVariablesNodes() const;
562 DIArray getVariables() const;
565 /// DIGlobalVariable - This is a wrapper for a global variable.
566 class DIGlobalVariable : public DIDescriptor {
568 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
570 DIScope getContext() const { return getFieldAs<DIScope>(2); }
571 StringRef getName() const { return getStringField(3); }
572 StringRef getDisplayName() const { return getStringField(4); }
573 StringRef getLinkageName() const { return getStringField(5); }
574 DICompileUnit getCompileUnit() const{
575 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
576 if (getVersion() == llvm::LLVMDebugVersion7)
577 return getFieldAs<DICompileUnit>(6);
579 DIFile F = getFieldAs<DIFile>(6);
580 return F.getCompileUnit();
583 unsigned getLineNumber() const { return getUnsignedField(7); }
584 DIType getType() const { return getFieldAs<DIType>(8); }
585 unsigned isLocalToUnit() const { return getUnsignedField(9); }
586 unsigned isDefinition() const { return getUnsignedField(10); }
588 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
589 Constant *getConstant() const { return getConstantField(11); }
591 /// Verify - Verify that a global variable descriptor is well formed.
594 /// print - print global variable.
595 void print(raw_ostream &OS) const;
597 /// dump - print global variable to dbgs() with a newline.
601 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
603 class DIVariable : public DIDescriptor {
605 explicit DIVariable(const MDNode *N = 0)
608 DIScope getContext() const { return getFieldAs<DIScope>(1); }
609 StringRef getName() const { return getStringField(2); }
610 DICompileUnit getCompileUnit() const{
611 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
612 if (getVersion() == llvm::LLVMDebugVersion7)
613 return getFieldAs<DICompileUnit>(3);
615 DIFile F = getFieldAs<DIFile>(3);
616 return F.getCompileUnit();
618 unsigned getLineNumber() const {
619 return (getUnsignedField(4) << 8) >> 8;
621 unsigned getArgNumber() const {
622 unsigned L = getUnsignedField(4);
625 DIType getType() const { return getFieldAs<DIType>(5); }
627 /// isArtificial - Return true if this variable is marked as "artificial".
628 bool isArtificial() const {
629 if (getVersion() <= llvm::LLVMDebugVersion8)
631 return (getUnsignedField(6) & FlagArtificial) != 0;
634 /// getInlinedAt - If this variable is inlined then return inline location.
635 MDNode *getInlinedAt() const;
637 /// Verify - Verify that a variable descriptor is well formed.
640 /// HasComplexAddr - Return true if the variable has a complex address.
641 bool hasComplexAddress() const {
642 return getNumAddrElements() > 0;
645 unsigned getNumAddrElements() const;
647 uint64_t getAddrElement(unsigned Idx) const {
648 if (getVersion() <= llvm::LLVMDebugVersion8)
649 return getUInt64Field(Idx+6);
650 if (getVersion() == llvm::LLVMDebugVersion9)
651 return getUInt64Field(Idx+7);
652 return getUInt64Field(Idx+8);
655 /// isBlockByrefVariable - Return true if the variable was declared as
656 /// a "__block" variable (Apple Blocks).
657 bool isBlockByrefVariable() const {
658 return getType().isBlockByrefStruct();
661 /// isInlinedFnArgument - Return trule if this variable provides debugging
662 /// information for an inlined function arguments.
663 bool isInlinedFnArgument(const Function *CurFn);
665 /// print - print variable.
666 void print(raw_ostream &OS) const;
668 void printExtendedName(raw_ostream &OS) const;
670 /// dump - print variable to dbgs() with a newline.
674 /// DILexicalBlock - This is a wrapper for a lexical block.
675 class DILexicalBlock : public DIScope {
677 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
678 DIScope getContext() const { return getFieldAs<DIScope>(1); }
679 unsigned getLineNumber() const { return getUnsignedField(2); }
680 unsigned getColumnNumber() const { return getUnsignedField(3); }
681 StringRef getDirectory() const {
682 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
683 return !dir.empty() ? dir : getContext().getDirectory();
685 StringRef getFilename() const {
686 StringRef filename = getFieldAs<DIFile>(4).getFilename();
687 return !filename.empty() ? filename : getContext().getFilename();
691 /// DINameSpace - A wrapper for a C++ style name space.
692 class DINameSpace : public DIScope {
694 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
695 DIScope getContext() const { return getFieldAs<DIScope>(1); }
696 StringRef getName() const { return getStringField(2); }
697 StringRef getDirectory() const {
698 return getFieldAs<DIFile>(3).getDirectory();
700 StringRef getFilename() const {
701 return getFieldAs<DIFile>(3).getFilename();
703 DICompileUnit getCompileUnit() const{
704 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
705 if (getVersion() == llvm::LLVMDebugVersion7)
706 return getFieldAs<DICompileUnit>(3);
708 return getFieldAs<DIFile>(3).getCompileUnit();
710 unsigned getLineNumber() const { return getUnsignedField(4); }
714 /// DILocation - This object holds location information. This object
715 /// is not associated with any DWARF tag.
716 class DILocation : public DIDescriptor {
718 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
720 unsigned getLineNumber() const { return getUnsignedField(0); }
721 unsigned getColumnNumber() const { return getUnsignedField(1); }
722 DIScope getScope() const { return getFieldAs<DIScope>(2); }
723 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
724 StringRef getFilename() const { return getScope().getFilename(); }
725 StringRef getDirectory() const { return getScope().getDirectory(); }
729 /// getDISubprogram - Find subprogram that is enclosing this scope.
730 DISubprogram getDISubprogram(const MDNode *Scope);
732 /// getDICompositeType - Find underlying composite type.
733 DICompositeType getDICompositeType(DIType T);
735 /// isSubprogramContext - Return true if Context is either a subprogram
736 /// or another context nested inside a subprogram.
737 bool isSubprogramContext(const MDNode *Context);
739 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
740 /// to hold function specific information.
741 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
743 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
744 /// suitable to hold function specific information.
745 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
747 /// createInlinedVariable - Create a new inlined variable based on current
749 /// @param DV Current Variable.
750 /// @param InlinedScope Location at current variable is inlined.
751 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
752 LLVMContext &VMContext);
754 /// cleanseInlinedVariable - Remove inlined scope from the variable.
755 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
757 class DebugInfoFinder {
759 /// processModule - Process entire module and collect debug info
761 void processModule(Module &M);
764 /// processType - Process DIType.
765 void processType(DIType DT);
767 /// processLexicalBlock - Process DILexicalBlock.
768 void processLexicalBlock(DILexicalBlock LB);
770 /// processSubprogram - Process DISubprogram.
771 void processSubprogram(DISubprogram SP);
773 /// processDeclare - Process DbgDeclareInst.
774 void processDeclare(DbgDeclareInst *DDI);
776 /// processLocation - Process DILocation.
777 void processLocation(DILocation Loc);
779 /// addCompileUnit - Add compile unit into CUs.
780 bool addCompileUnit(DICompileUnit CU);
782 /// addGlobalVariable - Add global variable into GVs.
783 bool addGlobalVariable(DIGlobalVariable DIG);
785 // addSubprogram - Add subprgoram into SPs.
786 bool addSubprogram(DISubprogram SP);
788 /// addType - Add type into Tys.
789 bool addType(DIType DT);
792 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
793 iterator compile_unit_begin() const { return CUs.begin(); }
794 iterator compile_unit_end() const { return CUs.end(); }
795 iterator subprogram_begin() const { return SPs.begin(); }
796 iterator subprogram_end() const { return SPs.end(); }
797 iterator global_variable_begin() const { return GVs.begin(); }
798 iterator global_variable_end() const { return GVs.end(); }
799 iterator type_begin() const { return TYs.begin(); }
800 iterator type_end() const { return TYs.end(); }
802 unsigned compile_unit_count() const { return CUs.size(); }
803 unsigned global_variable_count() const { return GVs.size(); }
804 unsigned subprogram_count() const { return SPs.size(); }
805 unsigned type_count() const { return TYs.size(); }
808 SmallVector<MDNode *, 8> CUs; // Compile Units
809 SmallVector<MDNode *, 8> SPs; // Subprograms
810 SmallVector<MDNode *, 8> GVs; // Global Variables;
811 SmallVector<MDNode *, 8> TYs; // Types
812 SmallPtrSet<MDNode *, 64> NodesSeen;
814 } // end namespace llvm