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"
43 class DILexicalBlockFile;
47 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
48 /// This should not be stored in a container, because underly MDNode may
49 /// change in certain situations.
54 FlagProtected = 1 << 1,
56 FlagAppleBlock = 1 << 3,
57 FlagBlockByrefStruct = 1 << 4,
59 FlagArtificial = 1 << 6,
60 FlagExplicit = 1 << 7,
61 FlagPrototyped = 1 << 8,
62 FlagObjcClassComplete = 1 << 9
65 const MDNode *DbgNode;
67 StringRef getStringField(unsigned Elt) const;
68 unsigned getUnsignedField(unsigned Elt) const {
69 return (unsigned)getUInt64Field(Elt);
71 uint64_t getUInt64Field(unsigned Elt) const;
72 DIDescriptor getDescriptorField(unsigned Elt) const;
74 template <typename DescTy>
75 DescTy getFieldAs(unsigned Elt) const {
76 return DescTy(getDescriptorField(Elt));
79 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
80 Constant *getConstantField(unsigned Elt) const;
81 Function *getFunctionField(unsigned Elt) const;
84 explicit DIDescriptor() : DbgNode(0) {}
85 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
86 explicit DIDescriptor(const DIFile F);
87 explicit DIDescriptor(const DISubprogram F);
88 explicit DIDescriptor(const DILexicalBlockFile F);
89 explicit DIDescriptor(const DILexicalBlock F);
90 explicit DIDescriptor(const DIVariable F);
91 explicit DIDescriptor(const DIType F);
93 bool Verify() const { return DbgNode != 0; }
95 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
96 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
98 unsigned getVersion() const {
99 return getUnsignedField(0) & LLVMDebugVersionMask;
102 unsigned getTag() const {
103 return getUnsignedField(0) & ~LLVMDebugVersionMask;
106 /// print - print descriptor.
107 void print(raw_ostream &OS) const;
109 /// dump - print descriptor to dbgs() with a newline.
112 bool isDerivedType() const;
113 bool isCompositeType() const;
114 bool isBasicType() const;
115 bool isVariable() const;
116 bool isSubprogram() const;
117 bool isGlobalVariable() const;
118 bool isScope() const;
120 bool isCompileUnit() const;
121 bool isNameSpace() const;
122 bool isLexicalBlockFile() const;
123 bool isLexicalBlock() const;
124 bool isSubrange() const;
125 bool isEnumerator() const;
127 bool isGlobal() const;
128 bool isUnspecifiedParameter() const;
129 bool isTemplateTypeParameter() const;
130 bool isTemplateValueParameter() const;
133 /// DISubrange - This is used to represent ranges, for array bounds.
134 class DISubrange : public DIDescriptor {
136 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
138 uint64_t getLo() const { return getUInt64Field(1); }
139 uint64_t getHi() const { return getUInt64Field(2); }
142 /// DIArray - This descriptor holds an array of descriptors.
143 class DIArray : public DIDescriptor {
145 explicit DIArray(const MDNode *N = 0)
148 unsigned getNumElements() const;
149 DIDescriptor getElement(unsigned Idx) const {
150 return getDescriptorField(Idx);
154 /// DIScope - A base class for various scopes.
155 class DIScope : public DIDescriptor {
157 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
158 virtual ~DIScope() {}
160 StringRef getFilename() const;
161 StringRef getDirectory() const;
164 /// DICompileUnit - A wrapper for a compile unit.
165 class DICompileUnit : public DIScope {
167 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
169 unsigned getLanguage() const { return getUnsignedField(2); }
170 StringRef getFilename() const { return getStringField(3); }
171 StringRef getDirectory() const { return getStringField(4); }
172 StringRef getProducer() const { return getStringField(5); }
174 /// isMain - Each input file is encoded as a separate compile unit in LLVM
175 /// debugging information output. However, many target specific tool chains
176 /// prefer to encode only one compile unit in an object file. In this
177 /// situation, the LLVM code generator will include debugging information
178 /// entities in the compile unit that is marked as main compile unit. The
179 /// code generator accepts maximum one main compile unit per module. If a
180 /// module does not contain any main compile unit then the code generator
181 /// will emit multiple compile units in the output object file.
183 bool isMain() const { return getUnsignedField(6) != 0; }
184 bool isOptimized() const { return getUnsignedField(7) != 0; }
185 StringRef getFlags() const { return getStringField(8); }
186 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
188 DIArray getEnumTypes() const;
189 DIArray getRetainedTypes() const;
190 DIArray getSubprograms() const;
191 DIArray getGlobalVariables() const;
193 /// Verify - Verify that a compile unit is well formed.
196 /// print - print compile unit.
197 void print(raw_ostream &OS) const;
199 /// dump - print compile unit to dbgs() with a newline.
203 /// DIFile - This is a wrapper for a file.
204 class DIFile : public DIScope {
206 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
207 if (DbgNode && !isFile())
210 StringRef getFilename() const { return getStringField(1); }
211 StringRef getDirectory() const { return getStringField(2); }
212 DICompileUnit getCompileUnit() const{
213 assert (getVersion() <= LLVMDebugVersion10 && "Invalid CompileUnit!");
214 return getFieldAs<DICompileUnit>(3);
218 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
219 /// FIXME: it seems strange that this doesn't have either a reference to the
220 /// type/precision or a file/line pair for location info.
221 class DIEnumerator : public DIDescriptor {
223 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
225 StringRef getName() const { return getStringField(1); }
226 uint64_t getEnumValue() const { return getUInt64Field(2); }
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 {
235 // This ctor is used when the Tag has already been validated by a derived
237 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
241 /// Verify - Verify that a type descriptor is well formed.
244 explicit DIType(const MDNode *N);
248 DIScope getContext() const { return getFieldAs<DIScope>(1); }
249 StringRef getName() const { return getStringField(2); }
250 DICompileUnit getCompileUnit() const{
251 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
252 if (getVersion() == llvm::LLVMDebugVersion7)
253 return getFieldAs<DICompileUnit>(3);
255 return getFieldAs<DIFile>(3).getCompileUnit();
257 DIFile getFile() const { return getFieldAs<DIFile>(3); }
258 unsigned getLineNumber() const { return getUnsignedField(4); }
259 uint64_t getSizeInBits() const { return getUInt64Field(5); }
260 uint64_t getAlignInBits() const { return getUInt64Field(6); }
261 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
262 // carry this is just plain insane.
263 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
264 unsigned getFlags() const { return getUnsignedField(8); }
265 bool isPrivate() const {
266 return (getFlags() & FlagPrivate) != 0;
268 bool isProtected() const {
269 return (getFlags() & FlagProtected) != 0;
271 bool isForwardDecl() const {
272 return (getFlags() & FlagFwdDecl) != 0;
274 // isAppleBlock - Return true if this is the Apple Blocks extension.
275 bool isAppleBlockExtension() const {
276 return (getFlags() & FlagAppleBlock) != 0;
278 bool isBlockByrefStruct() const {
279 return (getFlags() & FlagBlockByrefStruct) != 0;
281 bool isVirtual() const {
282 return (getFlags() & FlagVirtual) != 0;
284 bool isArtificial() const {
285 return (getFlags() & FlagArtificial) != 0;
287 bool isObjcClassComplete() const {
288 return (getFlags() & FlagObjcClassComplete) != 0;
290 bool isValid() const {
291 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
293 StringRef getDirectory() const {
294 if (getVersion() == llvm::LLVMDebugVersion7)
295 return getCompileUnit().getDirectory();
297 return getFieldAs<DIFile>(3).getDirectory();
299 StringRef getFilename() const {
300 if (getVersion() == llvm::LLVMDebugVersion7)
301 return getCompileUnit().getFilename();
303 return getFieldAs<DIFile>(3).getFilename();
306 /// isUnsignedDIType - Return true if type encoding is unsigned.
307 bool isUnsignedDIType();
309 /// replaceAllUsesWith - Replace all uses of debug info referenced by
311 void replaceAllUsesWith(DIDescriptor &D);
312 void replaceAllUsesWith(MDNode *D);
314 /// print - print type.
315 void print(raw_ostream &OS) const;
317 /// dump - print type to dbgs() with a newline.
321 /// DIBasicType - A basic type, like 'int' or 'float'.
322 class DIBasicType : public DIType {
324 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
326 unsigned getEncoding() const { return getUnsignedField(9); }
328 /// Verify - Verify that a basic type descriptor is well formed.
331 /// print - print basic type.
332 void print(raw_ostream &OS) const;
334 /// dump - print basic type to dbgs() with a newline.
338 /// DIDerivedType - A simple derived type, like a const qualified type,
339 /// a typedef, a pointer or reference, etc.
340 class DIDerivedType : public DIType {
342 explicit DIDerivedType(const MDNode *N, bool, bool)
343 : DIType(N, true, true) {}
345 explicit DIDerivedType(const MDNode *N = 0)
346 : DIType(N, true, true) {}
348 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
350 /// getOriginalTypeSize - If this type is derived from a base type then
351 /// return base type size.
352 uint64_t getOriginalTypeSize() const;
354 StringRef getObjCPropertyName() const { return getStringField(10); }
355 StringRef getObjCPropertyGetterName() const {
356 return getStringField(11);
358 StringRef getObjCPropertySetterName() const {
359 return getStringField(12);
361 bool isReadOnlyObjCProperty() {
362 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
364 bool isReadWriteObjCProperty() {
365 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
367 bool isAssignObjCProperty() {
368 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
370 bool isRetainObjCProperty() {
371 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
373 bool isCopyObjCProperty() {
374 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
376 bool isNonAtomicObjCProperty() {
377 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
380 /// Verify - Verify that a derived type descriptor is well formed.
383 /// print - print derived type.
384 void print(raw_ostream &OS) const;
386 /// dump - print derived type to dbgs() with a newline.
390 /// DICompositeType - This descriptor holds a type that can refer to multiple
391 /// other types, like a function or struct.
392 /// FIXME: Why is this a DIDerivedType??
393 class DICompositeType : public DIDerivedType {
395 explicit DICompositeType(const MDNode *N = 0)
396 : DIDerivedType(N, true, true) {
397 if (N && !isCompositeType())
401 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
402 unsigned getRunTimeLang() const { return getUnsignedField(11); }
403 DICompositeType getContainingType() const {
404 return getFieldAs<DICompositeType>(12);
406 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
408 /// Verify - Verify that a composite type descriptor is well formed.
411 /// print - print composite type.
412 void print(raw_ostream &OS) const;
414 /// dump - print composite type to dbgs() with a newline.
418 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
419 class DITemplateTypeParameter : public DIDescriptor {
421 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
423 DIScope getContext() const { return getFieldAs<DIScope>(1); }
424 StringRef getName() const { return getStringField(2); }
425 DIType getType() const { return getFieldAs<DIType>(3); }
426 StringRef getFilename() const {
427 return getFieldAs<DIFile>(4).getFilename();
429 StringRef getDirectory() const {
430 return getFieldAs<DIFile>(4).getDirectory();
432 unsigned getLineNumber() const { return getUnsignedField(5); }
433 unsigned getColumnNumber() const { return getUnsignedField(6); }
436 /// DITemplateValueParameter - This is a wrapper for template value parameter.
437 class DITemplateValueParameter : public DIDescriptor {
439 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
441 DIScope getContext() const { return getFieldAs<DIScope>(1); }
442 StringRef getName() const { return getStringField(2); }
443 DIType getType() const { return getFieldAs<DIType>(3); }
444 uint64_t getValue() const { return getUInt64Field(4); }
445 StringRef getFilename() const {
446 return getFieldAs<DIFile>(5).getFilename();
448 StringRef getDirectory() const {
449 return getFieldAs<DIFile>(5).getDirectory();
451 unsigned getLineNumber() const { return getUnsignedField(6); }
452 unsigned getColumnNumber() const { return getUnsignedField(7); }
455 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
456 class DISubprogram : public DIScope {
458 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
460 DIScope getContext() const { return getFieldAs<DIScope>(2); }
461 StringRef getName() const { return getStringField(3); }
462 StringRef getDisplayName() const { return getStringField(4); }
463 StringRef getLinkageName() const { return getStringField(5); }
464 DICompileUnit getCompileUnit() const{
465 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
466 if (getVersion() == llvm::LLVMDebugVersion7)
467 return getFieldAs<DICompileUnit>(6);
469 return getFieldAs<DIFile>(6).getCompileUnit();
471 unsigned getLineNumber() const { return getUnsignedField(7); }
472 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
474 /// getReturnTypeName - Subprogram return types are encoded either as
475 /// DIType or as DICompositeType.
476 StringRef getReturnTypeName() const {
477 DICompositeType DCT(getFieldAs<DICompositeType>(8));
479 DIArray A = DCT.getTypeArray();
480 DIType T(A.getElement(0));
483 DIType T(getFieldAs<DIType>(8));
487 /// isLocalToUnit - Return true if this subprogram is local to the current
488 /// compile unit, like 'static' in C.
489 unsigned isLocalToUnit() const { return getUnsignedField(9); }
490 unsigned isDefinition() const { return getUnsignedField(10); }
492 unsigned getVirtuality() const { return getUnsignedField(11); }
493 unsigned getVirtualIndex() const { return getUnsignedField(12); }
495 DICompositeType getContainingType() const {
496 return getFieldAs<DICompositeType>(13);
498 unsigned isArtificial() const {
499 if (getVersion() <= llvm::LLVMDebugVersion8)
500 return getUnsignedField(14);
501 return (getUnsignedField(14) & FlagArtificial) != 0;
503 /// isPrivate - Return true if this subprogram has "private"
504 /// access specifier.
505 bool isPrivate() const {
506 if (getVersion() <= llvm::LLVMDebugVersion8)
508 return (getUnsignedField(14) & FlagPrivate) != 0;
510 /// isProtected - Return true if this subprogram has "protected"
511 /// access specifier.
512 bool isProtected() const {
513 if (getVersion() <= llvm::LLVMDebugVersion8)
515 return (getUnsignedField(14) & FlagProtected) != 0;
517 /// isExplicit - Return true if this subprogram is marked as explicit.
518 bool isExplicit() const {
519 if (getVersion() <= llvm::LLVMDebugVersion8)
521 return (getUnsignedField(14) & FlagExplicit) != 0;
523 /// isPrototyped - Return true if this subprogram is prototyped.
524 bool isPrototyped() const {
525 if (getVersion() <= llvm::LLVMDebugVersion8)
527 return (getUnsignedField(14) & FlagPrototyped) != 0;
530 unsigned isOptimized() const;
532 StringRef getFilename() const {
533 if (getVersion() == llvm::LLVMDebugVersion7)
534 return getCompileUnit().getFilename();
536 return getFieldAs<DIFile>(6).getFilename();
539 StringRef getDirectory() const {
540 if (getVersion() == llvm::LLVMDebugVersion7)
541 return getCompileUnit().getFilename();
543 return getFieldAs<DIFile>(6).getDirectory();
546 /// Verify - Verify that a subprogram descriptor is well formed.
549 /// print - print subprogram.
550 void print(raw_ostream &OS) const;
552 /// dump - print subprogram to dbgs() with a newline.
555 /// describes - Return true if this subprogram provides debugging
556 /// information for the function F.
557 bool describes(const Function *F);
559 Function *getFunction() const { return getFunctionField(16); }
560 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
561 DISubprogram getFunctionDeclaration() const {
562 return getFieldAs<DISubprogram>(18);
564 MDNode *getVariablesNodes() const;
565 DIArray getVariables() const;
568 /// DIGlobalVariable - This is a wrapper for a global variable.
569 class DIGlobalVariable : public DIDescriptor {
571 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
573 DIScope getContext() const { return getFieldAs<DIScope>(2); }
574 StringRef getName() const { return getStringField(3); }
575 StringRef getDisplayName() const { return getStringField(4); }
576 StringRef getLinkageName() const { return getStringField(5); }
577 DICompileUnit getCompileUnit() const{
578 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
579 if (getVersion() == llvm::LLVMDebugVersion7)
580 return getFieldAs<DICompileUnit>(6);
582 DIFile F = getFieldAs<DIFile>(6);
583 return F.getCompileUnit();
585 StringRef getFilename() const {
586 if (getVersion() <= llvm::LLVMDebugVersion10)
587 return getContext().getFilename();
588 return getFieldAs<DIFile>(6).getFilename();
590 StringRef getDirectory() const {
591 if (getVersion() <= llvm::LLVMDebugVersion10)
592 return getContext().getDirectory();
593 return getFieldAs<DIFile>(6).getDirectory();
597 unsigned getLineNumber() const { return getUnsignedField(7); }
598 DIType getType() const { return getFieldAs<DIType>(8); }
599 unsigned isLocalToUnit() const { return getUnsignedField(9); }
600 unsigned isDefinition() const { return getUnsignedField(10); }
602 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
603 Constant *getConstant() const { return getConstantField(11); }
605 /// Verify - Verify that a global variable descriptor is well formed.
608 /// print - print global variable.
609 void print(raw_ostream &OS) const;
611 /// dump - print global variable to dbgs() with a newline.
615 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
617 class DIVariable : public DIDescriptor {
619 explicit DIVariable(const MDNode *N = 0)
622 DIScope getContext() const { return getFieldAs<DIScope>(1); }
623 StringRef getName() const { return getStringField(2); }
624 DICompileUnit getCompileUnit() const {
625 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
626 if (getVersion() == llvm::LLVMDebugVersion7)
627 return getFieldAs<DICompileUnit>(3);
629 DIFile F = getFieldAs<DIFile>(3);
630 return F.getCompileUnit();
632 unsigned getLineNumber() const {
633 return (getUnsignedField(4) << 8) >> 8;
635 unsigned getArgNumber() const {
636 unsigned L = getUnsignedField(4);
639 DIType getType() const { return getFieldAs<DIType>(5); }
641 /// isArtificial - Return true if this variable is marked as "artificial".
642 bool isArtificial() const {
643 if (getVersion() <= llvm::LLVMDebugVersion8)
645 return (getUnsignedField(6) & FlagArtificial) != 0;
648 /// getInlinedAt - If this variable is inlined then return inline location.
649 MDNode *getInlinedAt() const;
651 /// Verify - Verify that a variable descriptor is well formed.
654 /// HasComplexAddr - Return true if the variable has a complex address.
655 bool hasComplexAddress() const {
656 return getNumAddrElements() > 0;
659 unsigned getNumAddrElements() const;
661 uint64_t getAddrElement(unsigned Idx) const {
662 if (getVersion() <= llvm::LLVMDebugVersion8)
663 return getUInt64Field(Idx+6);
664 if (getVersion() == llvm::LLVMDebugVersion9)
665 return getUInt64Field(Idx+7);
666 return getUInt64Field(Idx+8);
669 /// isBlockByrefVariable - Return true if the variable was declared as
670 /// a "__block" variable (Apple Blocks).
671 bool isBlockByrefVariable() const {
672 return getType().isBlockByrefStruct();
675 /// isInlinedFnArgument - Return trule if this variable provides debugging
676 /// information for an inlined function arguments.
677 bool isInlinedFnArgument(const Function *CurFn);
679 /// print - print variable.
680 void print(raw_ostream &OS) const;
682 void printExtendedName(raw_ostream &OS) const;
684 /// dump - print variable to dbgs() with a newline.
688 /// DILexicalBlock - This is a wrapper for a lexical block.
689 class DILexicalBlock : public DIScope {
691 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
692 DIScope getContext() const { return getFieldAs<DIScope>(1); }
693 unsigned getLineNumber() const { return getUnsignedField(2); }
694 unsigned getColumnNumber() const { return getUnsignedField(3); }
695 StringRef getDirectory() const {
696 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
697 return !dir.empty() ? dir : getContext().getDirectory();
699 StringRef getFilename() const {
700 StringRef filename = getFieldAs<DIFile>(4).getFilename();
701 return !filename.empty() ? filename : getContext().getFilename();
705 /// DILexicalBlockFile - This is a wrapper for a lexical block with
706 /// a filename change.
707 class DILexicalBlockFile : public DIScope {
709 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
710 DIScope getContext() const { return getScope().getContext(); }
711 unsigned getLineNumber() const { return getScope().getLineNumber(); }
712 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
713 StringRef getDirectory() const {
714 StringRef dir = getFieldAs<DIFile>(2).getDirectory();
715 return !dir.empty() ? dir : getContext().getDirectory();
717 StringRef getFilename() const {
718 StringRef filename = getFieldAs<DIFile>(2).getFilename();
719 assert(!filename.empty() && "Why'd you create this then?");
722 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
725 /// DINameSpace - A wrapper for a C++ style name space.
726 class DINameSpace : public DIScope {
728 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
729 DIScope getContext() const { return getFieldAs<DIScope>(1); }
730 StringRef getName() const { return getStringField(2); }
731 StringRef getDirectory() const {
732 return getFieldAs<DIFile>(3).getDirectory();
734 StringRef getFilename() const {
735 return getFieldAs<DIFile>(3).getFilename();
737 DICompileUnit getCompileUnit() const{
738 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
739 if (getVersion() == llvm::LLVMDebugVersion7)
740 return getFieldAs<DICompileUnit>(3);
742 return getFieldAs<DIFile>(3).getCompileUnit();
744 unsigned getLineNumber() const { return getUnsignedField(4); }
748 /// DILocation - This object holds location information. This object
749 /// is not associated with any DWARF tag.
750 class DILocation : public DIDescriptor {
752 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
754 unsigned getLineNumber() const { return getUnsignedField(0); }
755 unsigned getColumnNumber() const { return getUnsignedField(1); }
756 DIScope getScope() const { return getFieldAs<DIScope>(2); }
757 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
758 StringRef getFilename() const { return getScope().getFilename(); }
759 StringRef getDirectory() const { return getScope().getDirectory(); }
763 /// getDISubprogram - Find subprogram that is enclosing this scope.
764 DISubprogram getDISubprogram(const MDNode *Scope);
766 /// getDICompositeType - Find underlying composite type.
767 DICompositeType getDICompositeType(DIType T);
769 /// isSubprogramContext - Return true if Context is either a subprogram
770 /// or another context nested inside a subprogram.
771 bool isSubprogramContext(const MDNode *Context);
773 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
774 /// to hold function specific information.
775 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
777 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
778 /// suitable to hold function specific information.
779 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
781 /// createInlinedVariable - Create a new inlined variable based on current
783 /// @param DV Current Variable.
784 /// @param InlinedScope Location at current variable is inlined.
785 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
786 LLVMContext &VMContext);
788 /// cleanseInlinedVariable - Remove inlined scope from the variable.
789 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
791 class DebugInfoFinder {
793 /// processModule - Process entire module and collect debug info
795 void processModule(Module &M);
798 /// processType - Process DIType.
799 void processType(DIType DT);
801 /// processLexicalBlock - Process DILexicalBlock.
802 void processLexicalBlock(DILexicalBlock LB);
804 /// processSubprogram - Process DISubprogram.
805 void processSubprogram(DISubprogram SP);
807 /// processDeclare - Process DbgDeclareInst.
808 void processDeclare(DbgDeclareInst *DDI);
810 /// processLocation - Process DILocation.
811 void processLocation(DILocation Loc);
813 /// addCompileUnit - Add compile unit into CUs.
814 bool addCompileUnit(DICompileUnit CU);
816 /// addGlobalVariable - Add global variable into GVs.
817 bool addGlobalVariable(DIGlobalVariable DIG);
819 // addSubprogram - Add subprogram into SPs.
820 bool addSubprogram(DISubprogram SP);
822 /// addType - Add type into Tys.
823 bool addType(DIType DT);
826 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
827 iterator compile_unit_begin() const { return CUs.begin(); }
828 iterator compile_unit_end() const { return CUs.end(); }
829 iterator subprogram_begin() const { return SPs.begin(); }
830 iterator subprogram_end() const { return SPs.end(); }
831 iterator global_variable_begin() const { return GVs.begin(); }
832 iterator global_variable_end() const { return GVs.end(); }
833 iterator type_begin() const { return TYs.begin(); }
834 iterator type_end() const { return TYs.end(); }
836 unsigned compile_unit_count() const { return CUs.size(); }
837 unsigned global_variable_count() const { return GVs.size(); }
838 unsigned subprogram_count() const { return SPs.size(); }
839 unsigned type_count() const { return TYs.size(); }
842 SmallVector<MDNode *, 8> CUs; // Compile Units
843 SmallVector<MDNode *, 8> SPs; // Subprograms
844 SmallVector<MDNode *, 8> GVs; // Global Variables;
845 SmallVector<MDNode *, 8> TYs; // Types
846 SmallPtrSet<MDNode *, 64> NodesSeen;
848 } // end namespace llvm