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;
48 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
49 /// This should not be stored in a container, because the underlying MDNode
50 /// may change in certain situations.
55 FlagProtected = 1 << 1,
57 FlagAppleBlock = 1 << 3,
58 FlagBlockByrefStruct = 1 << 4,
60 FlagArtificial = 1 << 6,
61 FlagExplicit = 1 << 7,
62 FlagPrototyped = 1 << 8,
63 FlagObjcClassComplete = 1 << 9,
64 FlagObjectPointer = 1 << 10
67 const MDNode *DbgNode;
69 StringRef getStringField(unsigned Elt) const;
70 unsigned getUnsignedField(unsigned Elt) const {
71 return (unsigned)getUInt64Field(Elt);
73 uint64_t getUInt64Field(unsigned Elt) const;
74 DIDescriptor getDescriptorField(unsigned Elt) const;
76 template <typename DescTy>
77 DescTy getFieldAs(unsigned Elt) const {
78 return DescTy(getDescriptorField(Elt));
81 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
82 Constant *getConstantField(unsigned Elt) const;
83 Function *getFunctionField(unsigned Elt) const;
84 void replaceFunctionField(unsigned Elt, Function *F);
87 explicit DIDescriptor() : DbgNode(0) {}
88 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
89 explicit DIDescriptor(const DIFile F);
90 explicit DIDescriptor(const DISubprogram F);
91 explicit DIDescriptor(const DILexicalBlockFile F);
92 explicit DIDescriptor(const DILexicalBlock F);
93 explicit DIDescriptor(const DIVariable F);
94 explicit DIDescriptor(const DIType F);
96 bool Verify() const { return DbgNode != 0; }
98 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
99 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
101 unsigned getVersion() const {
102 return getUnsignedField(0) & LLVMDebugVersionMask;
105 unsigned getTag() const {
106 return getUnsignedField(0) & ~LLVMDebugVersionMask;
109 bool isDerivedType() const;
110 bool isCompositeType() const;
111 bool isBasicType() const;
112 bool isVariable() const;
113 bool isSubprogram() const;
114 bool isGlobalVariable() const;
115 bool isScope() const;
117 bool isCompileUnit() const;
118 bool isNameSpace() const;
119 bool isLexicalBlockFile() 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;
128 bool isObjCProperty() const;
130 /// print - print descriptor.
131 void print(raw_ostream &OS) const;
133 /// dump - print descriptor to dbgs() with a newline.
137 /// DISubrange - This is used to represent ranges, for array bounds.
138 class DISubrange : public DIDescriptor {
139 friend class DIDescriptor;
140 void printInternal(raw_ostream &OS) const;
142 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
144 uint64_t getLo() const { return getUInt64Field(1); }
145 uint64_t getHi() const { return getUInt64Field(2); }
148 /// DIArray - This descriptor holds an array of descriptors.
149 class DIArray : public DIDescriptor {
151 explicit DIArray(const MDNode *N = 0)
154 unsigned getNumElements() const;
155 DIDescriptor getElement(unsigned Idx) const {
156 return getDescriptorField(Idx);
160 /// DIScope - A base class for various scopes.
161 class DIScope : public DIDescriptor {
163 friend class DIDescriptor;
164 void printInternal(raw_ostream &OS) const;
166 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
168 StringRef getFilename() const;
169 StringRef getDirectory() const;
172 /// DICompileUnit - A wrapper for a compile unit.
173 class DICompileUnit : public DIScope {
174 friend class DIDescriptor;
175 void printInternal(raw_ostream &OS) const;
177 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
179 unsigned getLanguage() const { return getUnsignedField(2); }
180 StringRef getFilename() const { return getStringField(3); }
181 StringRef getDirectory() const { return getStringField(4); }
182 StringRef getProducer() const { return getStringField(5); }
184 /// isMain - Each input file is encoded as a separate compile unit in LLVM
185 /// debugging information output. However, many target specific tool chains
186 /// prefer to encode only one compile unit in an object file. In this
187 /// situation, the LLVM code generator will include debugging information
188 /// entities in the compile unit that is marked as main compile unit. The
189 /// code generator accepts maximum one main compile unit per module. If a
190 /// module does not contain any main compile unit then the code generator
191 /// will emit multiple compile units in the output object file.
193 bool isMain() const { return getUnsignedField(6) != 0; }
194 bool isOptimized() const { return getUnsignedField(7) != 0; }
195 StringRef getFlags() const { return getStringField(8); }
196 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
198 DIArray getEnumTypes() const;
199 DIArray getRetainedTypes() const;
200 DIArray getSubprograms() const;
201 DIArray getGlobalVariables() const;
203 /// Verify - Verify that a compile unit is well formed.
207 /// DIFile - This is a wrapper for a file.
208 class DIFile : public DIScope {
209 friend class DIDescriptor;
210 void printInternal(raw_ostream &OS) const {} // FIXME: Output something?
212 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
213 if (DbgNode && !isFile())
216 StringRef getFilename() const { return getStringField(1); }
217 StringRef getDirectory() const { return getStringField(2); }
218 DICompileUnit getCompileUnit() const{
219 assert (getVersion() <= LLVMDebugVersion10 && "Invalid CompileUnit!");
220 return getFieldAs<DICompileUnit>(3);
224 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
225 /// FIXME: it seems strange that this doesn't have either a reference to the
226 /// type/precision or a file/line pair for location info.
227 class DIEnumerator : public DIDescriptor {
228 friend class DIDescriptor;
229 void printInternal(raw_ostream &OS) const;
231 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
233 StringRef getName() const { return getStringField(1); }
234 uint64_t getEnumValue() const { return getUInt64Field(2); }
237 /// DIType - This is a wrapper for a type.
238 /// FIXME: Types should be factored much better so that CV qualifiers and
239 /// others do not require a huge and empty descriptor full of zeros.
240 class DIType : public DIScope {
242 friend class DIDescriptor;
243 void printInternal(raw_ostream &OS) const;
244 // This ctor is used when the Tag has already been validated by a derived
246 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
248 /// Verify - Verify that a type descriptor is well formed.
250 explicit DIType(const MDNode *N);
253 DIScope getContext() const { return getFieldAs<DIScope>(1); }
254 StringRef getName() const { return getStringField(2); }
255 DICompileUnit getCompileUnit() const{
256 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
257 if (getVersion() == llvm::LLVMDebugVersion7)
258 return getFieldAs<DICompileUnit>(3);
260 return getFieldAs<DIFile>(3).getCompileUnit();
262 DIFile getFile() const { return getFieldAs<DIFile>(3); }
263 unsigned getLineNumber() const { return getUnsignedField(4); }
264 uint64_t getSizeInBits() const { return getUInt64Field(5); }
265 uint64_t getAlignInBits() const { return getUInt64Field(6); }
266 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
267 // carry this is just plain insane.
268 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
269 unsigned getFlags() const { return getUnsignedField(8); }
270 bool isPrivate() const {
271 return (getFlags() & FlagPrivate) != 0;
273 bool isProtected() const {
274 return (getFlags() & FlagProtected) != 0;
276 bool isForwardDecl() const {
277 return (getFlags() & FlagFwdDecl) != 0;
279 // isAppleBlock - Return true if this is the Apple Blocks extension.
280 bool isAppleBlockExtension() const {
281 return (getFlags() & FlagAppleBlock) != 0;
283 bool isBlockByrefStruct() const {
284 return (getFlags() & FlagBlockByrefStruct) != 0;
286 bool isVirtual() const {
287 return (getFlags() & FlagVirtual) != 0;
289 bool isArtificial() const {
290 return (getFlags() & FlagArtificial) != 0;
292 bool isObjectPointer() const {
293 return (getFlags() & FlagObjectPointer) != 0;
295 bool isObjcClassComplete() const {
296 return (getFlags() & FlagObjcClassComplete) != 0;
298 bool isValid() const {
299 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
301 StringRef getDirectory() const {
302 if (getVersion() == llvm::LLVMDebugVersion7)
303 return getCompileUnit().getDirectory();
305 return getFieldAs<DIFile>(3).getDirectory();
307 StringRef getFilename() const {
308 if (getVersion() == llvm::LLVMDebugVersion7)
309 return getCompileUnit().getFilename();
311 return getFieldAs<DIFile>(3).getFilename();
314 /// isUnsignedDIType - Return true if type encoding is unsigned.
315 bool isUnsignedDIType();
317 /// replaceAllUsesWith - Replace all uses of debug info referenced by
319 void replaceAllUsesWith(DIDescriptor &D);
320 void replaceAllUsesWith(MDNode *D);
323 /// DIBasicType - A basic type, like 'int' or 'float'.
324 class DIBasicType : public DIType {
326 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
328 unsigned getEncoding() const { return getUnsignedField(9); }
330 /// Verify - Verify that a basic type descriptor is well formed.
334 /// DIDerivedType - A simple derived type, like a const qualified type,
335 /// a typedef, a pointer or reference, etc.
336 class DIDerivedType : public DIType {
337 friend class DIDescriptor;
338 void printInternal(raw_ostream &OS) const;
340 explicit DIDerivedType(const MDNode *N, bool, bool)
341 : DIType(N, true, true) {}
343 explicit DIDerivedType(const MDNode *N = 0)
344 : DIType(N, true, true) {}
346 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
348 /// getOriginalTypeSize - If this type is derived from a base type then
349 /// return base type size.
350 uint64_t getOriginalTypeSize() const;
352 /// getObjCProperty - Return property node, if this ivar is
353 /// associated with one.
354 MDNode *getObjCProperty() const;
356 StringRef getObjCPropertyName() const {
357 if (getVersion() > LLVMDebugVersion11)
359 return getStringField(10);
361 StringRef getObjCPropertyGetterName() const {
362 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
363 return getStringField(11);
365 StringRef getObjCPropertySetterName() const {
366 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
367 return getStringField(12);
369 bool isReadOnlyObjCProperty() {
370 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
371 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
373 bool isReadWriteObjCProperty() {
374 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
375 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
377 bool isAssignObjCProperty() {
378 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
379 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
381 bool isRetainObjCProperty() {
382 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
383 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
385 bool isCopyObjCProperty() {
386 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
387 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
389 bool isNonAtomicObjCProperty() {
390 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
391 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
394 /// Verify - Verify that a derived type descriptor is well formed.
398 /// DICompositeType - This descriptor holds a type that can refer to multiple
399 /// other types, like a function or struct.
400 /// FIXME: Why is this a DIDerivedType??
401 class DICompositeType : public DIDerivedType {
402 friend class DIDescriptor;
403 void printInternal(raw_ostream &OS) const;
405 explicit DICompositeType(const MDNode *N = 0)
406 : DIDerivedType(N, true, true) {
407 if (N && !isCompositeType())
411 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
412 unsigned getRunTimeLang() const { return getUnsignedField(11); }
413 DICompositeType getContainingType() const {
414 return getFieldAs<DICompositeType>(12);
416 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
418 /// Verify - Verify that a composite type descriptor is well formed.
422 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
423 class DITemplateTypeParameter : public DIDescriptor {
425 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
427 DIScope getContext() const { return getFieldAs<DIScope>(1); }
428 StringRef getName() const { return getStringField(2); }
429 DIType getType() const { return getFieldAs<DIType>(3); }
430 StringRef getFilename() const {
431 return getFieldAs<DIFile>(4).getFilename();
433 StringRef getDirectory() const {
434 return getFieldAs<DIFile>(4).getDirectory();
436 unsigned getLineNumber() const { return getUnsignedField(5); }
437 unsigned getColumnNumber() const { return getUnsignedField(6); }
440 /// DITemplateValueParameter - This is a wrapper for template value parameter.
441 class DITemplateValueParameter : public DIDescriptor {
443 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
445 DIScope getContext() const { return getFieldAs<DIScope>(1); }
446 StringRef getName() const { return getStringField(2); }
447 DIType getType() const { return getFieldAs<DIType>(3); }
448 uint64_t getValue() const { return getUInt64Field(4); }
449 StringRef getFilename() const {
450 return getFieldAs<DIFile>(5).getFilename();
452 StringRef getDirectory() const {
453 return getFieldAs<DIFile>(5).getDirectory();
455 unsigned getLineNumber() const { return getUnsignedField(6); }
456 unsigned getColumnNumber() const { return getUnsignedField(7); }
459 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
460 class DISubprogram : public DIScope {
461 friend class DIDescriptor;
462 void printInternal(raw_ostream &OS) const;
464 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
466 DIScope getContext() const { return getFieldAs<DIScope>(2); }
467 StringRef getName() const { return getStringField(3); }
468 StringRef getDisplayName() const { return getStringField(4); }
469 StringRef getLinkageName() const { return getStringField(5); }
470 DICompileUnit getCompileUnit() const{
471 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
472 if (getVersion() == llvm::LLVMDebugVersion7)
473 return getFieldAs<DICompileUnit>(6);
475 return getFieldAs<DIFile>(6).getCompileUnit();
477 unsigned getLineNumber() const { return getUnsignedField(7); }
478 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
480 /// getReturnTypeName - Subprogram return types are encoded either as
481 /// DIType or as DICompositeType.
482 StringRef getReturnTypeName() const {
483 DICompositeType DCT(getFieldAs<DICompositeType>(8));
485 DIArray A = DCT.getTypeArray();
486 DIType T(A.getElement(0));
489 DIType T(getFieldAs<DIType>(8));
493 /// isLocalToUnit - Return true if this subprogram is local to the current
494 /// compile unit, like 'static' in C.
495 unsigned isLocalToUnit() const { return getUnsignedField(9); }
496 unsigned isDefinition() const { return getUnsignedField(10); }
498 unsigned getVirtuality() const { return getUnsignedField(11); }
499 unsigned getVirtualIndex() const { return getUnsignedField(12); }
501 DICompositeType getContainingType() const {
502 return getFieldAs<DICompositeType>(13);
505 unsigned isArtificial() const {
506 if (getVersion() <= llvm::LLVMDebugVersion8)
507 return getUnsignedField(14);
508 return (getUnsignedField(14) & FlagArtificial) != 0;
510 /// isPrivate - Return true if this subprogram has "private"
511 /// access specifier.
512 bool isPrivate() const {
513 if (getVersion() <= llvm::LLVMDebugVersion8)
515 return (getUnsignedField(14) & FlagPrivate) != 0;
517 /// isProtected - Return true if this subprogram has "protected"
518 /// access specifier.
519 bool isProtected() const {
520 if (getVersion() <= llvm::LLVMDebugVersion8)
522 return (getUnsignedField(14) & FlagProtected) != 0;
524 /// isExplicit - Return true if this subprogram is marked as explicit.
525 bool isExplicit() const {
526 if (getVersion() <= llvm::LLVMDebugVersion8)
528 return (getUnsignedField(14) & FlagExplicit) != 0;
530 /// isPrototyped - Return true if this subprogram is prototyped.
531 bool isPrototyped() const {
532 if (getVersion() <= llvm::LLVMDebugVersion8)
534 return (getUnsignedField(14) & FlagPrototyped) != 0;
537 unsigned isOptimized() const;
539 StringRef getFilename() const {
540 if (getVersion() == llvm::LLVMDebugVersion7)
541 return getCompileUnit().getFilename();
543 return getFieldAs<DIFile>(6).getFilename();
546 StringRef getDirectory() const {
547 if (getVersion() == llvm::LLVMDebugVersion7)
548 return getCompileUnit().getFilename();
550 return getFieldAs<DIFile>(6).getDirectory();
553 /// getScopeLineNumber - Get the beginning of the scope of the
554 /// function, not necessarily where the name of the program
556 unsigned getScopeLineNumber() const { return getUnsignedField(20); }
558 /// Verify - Verify that a subprogram descriptor is well formed.
561 /// describes - Return true if this subprogram provides debugging
562 /// information for the function F.
563 bool describes(const Function *F);
565 Function *getFunction() const { return getFunctionField(16); }
566 void replaceFunction(Function *F) { replaceFunctionField(16, F); }
567 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
568 DISubprogram getFunctionDeclaration() const {
569 return getFieldAs<DISubprogram>(18);
571 MDNode *getVariablesNodes() const;
572 DIArray getVariables() const;
575 /// DIGlobalVariable - This is a wrapper for a global variable.
576 class DIGlobalVariable : public DIDescriptor {
577 friend class DIDescriptor;
578 void printInternal(raw_ostream &OS) const;
580 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
582 DIScope getContext() const { return getFieldAs<DIScope>(2); }
583 StringRef getName() const { return getStringField(3); }
584 StringRef getDisplayName() const { return getStringField(4); }
585 StringRef getLinkageName() const { return getStringField(5); }
586 DICompileUnit getCompileUnit() const{
587 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
588 if (getVersion() == llvm::LLVMDebugVersion7)
589 return getFieldAs<DICompileUnit>(6);
591 DIFile F = getFieldAs<DIFile>(6);
592 return F.getCompileUnit();
594 StringRef getFilename() const {
595 if (getVersion() <= llvm::LLVMDebugVersion10)
596 return getContext().getFilename();
597 return getFieldAs<DIFile>(6).getFilename();
599 StringRef getDirectory() const {
600 if (getVersion() <= llvm::LLVMDebugVersion10)
601 return getContext().getDirectory();
602 return getFieldAs<DIFile>(6).getDirectory();
606 unsigned getLineNumber() const { return getUnsignedField(7); }
607 DIType getType() const { return getFieldAs<DIType>(8); }
608 unsigned isLocalToUnit() const { return getUnsignedField(9); }
609 unsigned isDefinition() const { return getUnsignedField(10); }
611 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
612 Constant *getConstant() const { return getConstantField(11); }
614 /// Verify - Verify that a global variable descriptor is well formed.
618 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
620 class DIVariable : public DIDescriptor {
621 friend class DIDescriptor;
622 void printInternal(raw_ostream &OS) const;
624 explicit DIVariable(const MDNode *N = 0)
627 DIScope getContext() const { return getFieldAs<DIScope>(1); }
628 StringRef getName() const { return getStringField(2); }
629 DICompileUnit getCompileUnit() const {
630 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
631 if (getVersion() == llvm::LLVMDebugVersion7)
632 return getFieldAs<DICompileUnit>(3);
634 DIFile F = getFieldAs<DIFile>(3);
635 return F.getCompileUnit();
637 unsigned getLineNumber() const {
638 return (getUnsignedField(4) << 8) >> 8;
640 unsigned getArgNumber() const {
641 unsigned L = getUnsignedField(4);
644 DIType getType() const { return getFieldAs<DIType>(5); }
646 /// isArtificial - Return true if this variable is marked as "artificial".
647 bool isArtificial() const {
648 if (getVersion() <= llvm::LLVMDebugVersion8)
650 return (getUnsignedField(6) & FlagArtificial) != 0;
653 bool isObjectPointer() const {
654 return (getUnsignedField(6) & FlagObjectPointer) != 0;
657 /// getInlinedAt - If this variable is inlined then return inline location.
658 MDNode *getInlinedAt() const;
660 /// Verify - Verify that a variable descriptor is well formed.
663 /// HasComplexAddr - Return true if the variable has a complex address.
664 bool hasComplexAddress() const {
665 return getNumAddrElements() > 0;
668 unsigned getNumAddrElements() const;
670 uint64_t getAddrElement(unsigned Idx) const {
671 if (getVersion() <= llvm::LLVMDebugVersion8)
672 return getUInt64Field(Idx+6);
673 if (getVersion() == llvm::LLVMDebugVersion9)
674 return getUInt64Field(Idx+7);
675 return getUInt64Field(Idx+8);
678 /// isBlockByrefVariable - Return true if the variable was declared as
679 /// a "__block" variable (Apple Blocks).
680 bool isBlockByrefVariable() const {
681 return getType().isBlockByrefStruct();
684 /// isInlinedFnArgument - Return trule if this variable provides debugging
685 /// information for an inlined function arguments.
686 bool isInlinedFnArgument(const Function *CurFn);
688 void printExtendedName(raw_ostream &OS) const;
691 /// DILexicalBlock - This is a wrapper for a lexical block.
692 class DILexicalBlock : public DIScope {
694 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
695 DIScope getContext() const { return getFieldAs<DIScope>(1); }
696 unsigned getLineNumber() const { return getUnsignedField(2); }
697 unsigned getColumnNumber() const { return getUnsignedField(3); }
698 StringRef getDirectory() const {
699 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
700 return !dir.empty() ? dir : getContext().getDirectory();
702 StringRef getFilename() const {
703 StringRef filename = getFieldAs<DIFile>(4).getFilename();
704 return !filename.empty() ? filename : getContext().getFilename();
708 /// DILexicalBlockFile - This is a wrapper for a lexical block with
709 /// a filename change.
710 class DILexicalBlockFile : public DIScope {
712 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
713 DIScope getContext() const { return getScope().getContext(); }
714 unsigned getLineNumber() const { return getScope().getLineNumber(); }
715 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
716 StringRef getDirectory() const {
717 StringRef dir = getFieldAs<DIFile>(2).getDirectory();
718 return !dir.empty() ? dir : getContext().getDirectory();
720 StringRef getFilename() const {
721 StringRef filename = getFieldAs<DIFile>(2).getFilename();
722 assert(!filename.empty() && "Why'd you create this then?");
725 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
728 /// DINameSpace - A wrapper for a C++ style name space.
729 class DINameSpace : public DIScope {
731 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
732 DIScope getContext() const { return getFieldAs<DIScope>(1); }
733 StringRef getName() const { return getStringField(2); }
734 StringRef getDirectory() const {
735 return getFieldAs<DIFile>(3).getDirectory();
737 StringRef getFilename() const {
738 return getFieldAs<DIFile>(3).getFilename();
740 DICompileUnit getCompileUnit() const{
741 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
742 if (getVersion() == llvm::LLVMDebugVersion7)
743 return getFieldAs<DICompileUnit>(3);
745 return getFieldAs<DIFile>(3).getCompileUnit();
747 unsigned getLineNumber() const { return getUnsignedField(4); }
751 /// DILocation - This object holds location information. This object
752 /// is not associated with any DWARF tag.
753 class DILocation : public DIDescriptor {
755 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
757 unsigned getLineNumber() const { return getUnsignedField(0); }
758 unsigned getColumnNumber() const { return getUnsignedField(1); }
759 DIScope getScope() const { return getFieldAs<DIScope>(2); }
760 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
761 StringRef getFilename() const { return getScope().getFilename(); }
762 StringRef getDirectory() const { return getScope().getDirectory(); }
766 class DIObjCProperty : public DIDescriptor {
767 friend class DIDescriptor;
768 void printInternal(raw_ostream &OS) const;
770 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
772 StringRef getObjCPropertyName() const { return getStringField(1); }
773 DIFile getFile() const { return getFieldAs<DIFile>(2); }
774 unsigned getLineNumber() const { return getUnsignedField(3); }
776 StringRef getObjCPropertyGetterName() const {
777 return getStringField(4);
779 StringRef getObjCPropertySetterName() const {
780 return getStringField(5);
782 bool isReadOnlyObjCProperty() {
783 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
785 bool isReadWriteObjCProperty() {
786 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
788 bool isAssignObjCProperty() {
789 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
791 bool isRetainObjCProperty() {
792 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
794 bool isCopyObjCProperty() {
795 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
797 bool isNonAtomicObjCProperty() {
798 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
801 DIType getType() const { return getFieldAs<DIType>(7); }
803 /// Verify - Verify that a derived type descriptor is well formed.
807 /// getDISubprogram - Find subprogram that is enclosing this scope.
808 DISubprogram getDISubprogram(const MDNode *Scope);
810 /// getDICompositeType - Find underlying composite type.
811 DICompositeType getDICompositeType(DIType T);
813 /// isSubprogramContext - Return true if Context is either a subprogram
814 /// or another context nested inside a subprogram.
815 bool isSubprogramContext(const MDNode *Context);
817 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
818 /// to hold function specific information.
819 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
821 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
822 /// suitable to hold function specific information.
823 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
825 /// createInlinedVariable - Create a new inlined variable based on current
827 /// @param DV Current Variable.
828 /// @param InlinedScope Location at current variable is inlined.
829 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
830 LLVMContext &VMContext);
832 /// cleanseInlinedVariable - Remove inlined scope from the variable.
833 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
835 class DebugInfoFinder {
837 /// processModule - Process entire module and collect debug info
839 void processModule(Module &M);
842 /// processType - Process DIType.
843 void processType(DIType DT);
845 /// processLexicalBlock - Process DILexicalBlock.
846 void processLexicalBlock(DILexicalBlock LB);
848 /// processSubprogram - Process DISubprogram.
849 void processSubprogram(DISubprogram SP);
851 /// processDeclare - Process DbgDeclareInst.
852 void processDeclare(DbgDeclareInst *DDI);
854 /// processLocation - Process DILocation.
855 void processLocation(DILocation Loc);
857 /// addCompileUnit - Add compile unit into CUs.
858 bool addCompileUnit(DICompileUnit CU);
860 /// addGlobalVariable - Add global variable into GVs.
861 bool addGlobalVariable(DIGlobalVariable DIG);
863 // addSubprogram - Add subprogram into SPs.
864 bool addSubprogram(DISubprogram SP);
866 /// addType - Add type into Tys.
867 bool addType(DIType DT);
870 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
871 iterator compile_unit_begin() const { return CUs.begin(); }
872 iterator compile_unit_end() const { return CUs.end(); }
873 iterator subprogram_begin() const { return SPs.begin(); }
874 iterator subprogram_end() const { return SPs.end(); }
875 iterator global_variable_begin() const { return GVs.begin(); }
876 iterator global_variable_end() const { return GVs.end(); }
877 iterator type_begin() const { return TYs.begin(); }
878 iterator type_end() const { return TYs.end(); }
880 unsigned compile_unit_count() const { return CUs.size(); }
881 unsigned global_variable_count() const { return GVs.size(); }
882 unsigned subprogram_count() const { return SPs.size(); }
883 unsigned type_count() const { return TYs.size(); }
886 SmallVector<MDNode *, 8> CUs; // Compile Units
887 SmallVector<MDNode *, 8> SPs; // Subprograms
888 SmallVector<MDNode *, 8> GVs; // Global Variables;
889 SmallVector<MDNode *, 8> TYs; // Types
890 SmallPtrSet<MDNode *, 64> NodesSeen;
892 } // end namespace llvm