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/SmallPtrSet.h"
21 #include "llvm/ADT/SmallVector.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,
66 FlagStaticMember = 1 << 12
69 const MDNode *DbgNode;
71 StringRef getStringField(unsigned Elt) const;
72 unsigned getUnsignedField(unsigned Elt) const {
73 return (unsigned)getUInt64Field(Elt);
75 uint64_t getUInt64Field(unsigned Elt) const;
76 int64_t getInt64Field(unsigned Elt) const;
77 DIDescriptor getDescriptorField(unsigned Elt) const;
79 template <typename DescTy>
80 DescTy getFieldAs(unsigned Elt) const {
81 return DescTy(getDescriptorField(Elt));
84 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
85 Constant *getConstantField(unsigned Elt) const;
86 Function *getFunctionField(unsigned Elt) const;
87 void replaceFunctionField(unsigned Elt, Function *F);
90 explicit DIDescriptor() : DbgNode(0) {}
91 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
92 explicit DIDescriptor(const DIFile F);
93 explicit DIDescriptor(const DISubprogram F);
94 explicit DIDescriptor(const DILexicalBlockFile F);
95 explicit DIDescriptor(const DILexicalBlock F);
96 explicit DIDescriptor(const DIVariable F);
97 explicit DIDescriptor(const DIType F);
99 bool Verify() const { return DbgNode != 0; }
101 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
102 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
104 unsigned getVersion() const {
105 return getUnsignedField(0) & LLVMDebugVersionMask;
108 unsigned getTag() const {
109 return getUnsignedField(0) & ~LLVMDebugVersionMask;
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;
131 bool isObjCProperty() const;
133 /// print - print descriptor.
134 void print(raw_ostream &OS) const;
136 /// dump - print descriptor to dbgs() with a newline.
140 /// DISubrange - This is used to represent ranges, for array bounds.
141 class DISubrange : public DIDescriptor {
142 friend class DIDescriptor;
143 void printInternal(raw_ostream &OS) const;
145 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
147 int64_t getLo() const { return getInt64Field(1); }
148 int64_t getCount() const { return getInt64Field(2); }
151 /// DIArray - This descriptor holds an array of descriptors.
152 class DIArray : public DIDescriptor {
154 explicit DIArray(const MDNode *N = 0)
157 unsigned getNumElements() const;
158 DIDescriptor getElement(unsigned Idx) const {
159 return getDescriptorField(Idx);
163 /// DIScope - A base class for various scopes.
164 class DIScope : public DIDescriptor {
166 friend class DIDescriptor;
167 void printInternal(raw_ostream &OS) const;
169 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
171 StringRef getFilename() const;
172 StringRef getDirectory() const;
175 /// DICompileUnit - A wrapper for a compile unit.
176 class DICompileUnit : public DIScope {
177 friend class DIDescriptor;
178 void printInternal(raw_ostream &OS) const;
180 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
182 unsigned getLanguage() const { return getUnsignedField(2); }
183 StringRef getFilename() const { return getStringField(3); }
184 StringRef getDirectory() const { return getStringField(4); }
185 StringRef getProducer() const { return getStringField(5); }
187 /// isMain - Each input file is encoded as a separate compile unit in LLVM
188 /// debugging information output. However, many target specific tool chains
189 /// prefer to encode only one compile unit in an object file. In this
190 /// situation, the LLVM code generator will include debugging information
191 /// entities in the compile unit that is marked as main compile unit. The
192 /// code generator accepts maximum one main compile unit per module. If a
193 /// module does not contain any main compile unit then the code generator
194 /// will emit multiple compile units in the output object file.
196 bool isMain() const { return getUnsignedField(6) != 0; }
197 bool isOptimized() const { return getUnsignedField(7) != 0; }
198 StringRef getFlags() const { return getStringField(8); }
199 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
201 DIArray getEnumTypes() const;
202 DIArray getRetainedTypes() const;
203 DIArray getSubprograms() const;
204 DIArray getGlobalVariables() const;
206 /// Verify - Verify that a compile unit is well formed.
210 /// DIFile - This is a wrapper for a file.
211 class DIFile : public DIScope {
212 friend class DIDescriptor;
213 void printInternal(raw_ostream &OS) const {} // FIXME: Output something?
215 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
216 if (DbgNode && !isFile())
219 StringRef getFilename() const { return getStringField(1); }
220 StringRef getDirectory() const { return getStringField(2); }
221 DICompileUnit getCompileUnit() const{
222 assert (getVersion() <= LLVMDebugVersion10 && "Invalid CompileUnit!");
223 return getFieldAs<DICompileUnit>(3);
227 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
228 /// FIXME: it seems strange that this doesn't have either a reference to the
229 /// type/precision or a file/line pair for location info.
230 class DIEnumerator : public DIDescriptor {
231 friend class DIDescriptor;
232 void printInternal(raw_ostream &OS) const;
234 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
236 StringRef getName() const { return getStringField(1); }
237 uint64_t getEnumValue() const { return getUInt64Field(2); }
240 /// DIType - This is a wrapper for a type.
241 /// FIXME: Types should be factored much better so that CV qualifiers and
242 /// others do not require a huge and empty descriptor full of zeros.
243 class DIType : public DIScope {
245 friend class DIDescriptor;
246 void printInternal(raw_ostream &OS) const;
247 // This ctor is used when the Tag has already been validated by a derived
249 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
251 /// Verify - Verify that a type descriptor is well formed.
253 explicit DIType(const MDNode *N);
256 DIScope getContext() const { return getFieldAs<DIScope>(1); }
257 StringRef getName() const { return getStringField(2); }
258 DICompileUnit getCompileUnit() const{
259 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
260 if (getVersion() == llvm::LLVMDebugVersion7)
261 return getFieldAs<DICompileUnit>(3);
263 return getFieldAs<DIFile>(3).getCompileUnit();
265 DIFile getFile() const { return getFieldAs<DIFile>(3); }
266 unsigned getLineNumber() const { return getUnsignedField(4); }
267 uint64_t getSizeInBits() const { return getUInt64Field(5); }
268 uint64_t getAlignInBits() const { return getUInt64Field(6); }
269 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
270 // carry this is just plain insane.
271 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
272 unsigned getFlags() const { return getUnsignedField(8); }
273 bool isPrivate() const {
274 return (getFlags() & FlagPrivate) != 0;
276 bool isProtected() const {
277 return (getFlags() & FlagProtected) != 0;
279 bool isForwardDecl() const {
280 return (getFlags() & FlagFwdDecl) != 0;
282 // isAppleBlock - Return true if this is the Apple Blocks extension.
283 bool isAppleBlockExtension() const {
284 return (getFlags() & FlagAppleBlock) != 0;
286 bool isBlockByrefStruct() const {
287 return (getFlags() & FlagBlockByrefStruct) != 0;
289 bool isVirtual() const {
290 return (getFlags() & FlagVirtual) != 0;
292 bool isArtificial() const {
293 return (getFlags() & FlagArtificial) != 0;
295 bool isObjectPointer() const {
296 return (getFlags() & FlagObjectPointer) != 0;
298 bool isObjcClassComplete() const {
299 return (getFlags() & FlagObjcClassComplete) != 0;
301 bool isVector() const {
302 return (getFlags() & FlagVector) != 0;
304 bool isStaticMember() const {
305 return (getFlags() & FlagStaticMember) != 0;
307 bool isValid() const {
308 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
310 StringRef getDirectory() const {
311 if (getVersion() == llvm::LLVMDebugVersion7)
312 return getCompileUnit().getDirectory();
314 return getFieldAs<DIFile>(3).getDirectory();
316 StringRef getFilename() const {
317 if (getVersion() == llvm::LLVMDebugVersion7)
318 return getCompileUnit().getFilename();
320 return getFieldAs<DIFile>(3).getFilename();
323 /// isUnsignedDIType - Return true if type encoding is unsigned.
324 bool isUnsignedDIType();
326 /// replaceAllUsesWith - Replace all uses of debug info referenced by
328 void replaceAllUsesWith(DIDescriptor &D);
329 void replaceAllUsesWith(MDNode *D);
332 /// DIBasicType - A basic type, like 'int' or 'float'.
333 class DIBasicType : public DIType {
335 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
337 unsigned getEncoding() const { return getUnsignedField(9); }
339 /// Verify - Verify that a basic type descriptor is well formed.
343 /// DIDerivedType - A simple derived type, like a const qualified type,
344 /// a typedef, a pointer or reference, et cetera. Or, a data member of
345 /// a class/struct/union.
346 class DIDerivedType : public DIType {
347 friend class DIDescriptor;
348 void printInternal(raw_ostream &OS) const;
350 explicit DIDerivedType(const MDNode *N, bool, bool)
351 : DIType(N, true, true) {}
353 explicit DIDerivedType(const MDNode *N = 0)
354 : DIType(N, true, true) {}
356 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
358 /// getOriginalTypeSize - If this type is derived from a base type then
359 /// return base type size.
360 uint64_t getOriginalTypeSize() const;
362 /// getObjCProperty - Return property node, if this ivar is
363 /// associated with one.
364 MDNode *getObjCProperty() const;
366 DIType getClassType() const {
367 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
368 return getFieldAs<DIType>(10);
371 Constant *getConstant() const {
372 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
373 return getConstantField(10);
376 StringRef getObjCPropertyName() const {
377 if (getVersion() > LLVMDebugVersion11)
379 return getStringField(10);
381 StringRef getObjCPropertyGetterName() const {
382 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
383 return getStringField(11);
385 StringRef getObjCPropertySetterName() const {
386 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
387 return getStringField(12);
389 bool isReadOnlyObjCProperty() {
390 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
391 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
393 bool isReadWriteObjCProperty() {
394 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
395 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
397 bool isAssignObjCProperty() {
398 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
399 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
401 bool isRetainObjCProperty() {
402 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
403 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
405 bool isCopyObjCProperty() {
406 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
407 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
409 bool isNonAtomicObjCProperty() {
410 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
411 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
414 /// Verify - Verify that a derived type descriptor is well formed.
418 /// DICompositeType - This descriptor holds a type that can refer to multiple
419 /// other types, like a function or struct.
420 /// FIXME: Why is this a DIDerivedType??
421 class DICompositeType : public DIDerivedType {
422 friend class DIDescriptor;
423 void printInternal(raw_ostream &OS) const;
425 explicit DICompositeType(const MDNode *N = 0)
426 : DIDerivedType(N, true, true) {
427 if (N && !isCompositeType())
431 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
432 unsigned getRunTimeLang() const { return getUnsignedField(11); }
433 DICompositeType getContainingType() const {
434 return getFieldAs<DICompositeType>(12);
436 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
438 /// Verify - Verify that a composite type descriptor is well formed.
442 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
443 class DITemplateTypeParameter : public DIDescriptor {
445 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
447 DIScope getContext() const { return getFieldAs<DIScope>(1); }
448 StringRef getName() const { return getStringField(2); }
449 DIType getType() const { return getFieldAs<DIType>(3); }
450 StringRef getFilename() const {
451 return getFieldAs<DIFile>(4).getFilename();
453 StringRef getDirectory() const {
454 return getFieldAs<DIFile>(4).getDirectory();
456 unsigned getLineNumber() const { return getUnsignedField(5); }
457 unsigned getColumnNumber() const { return getUnsignedField(6); }
460 /// DITemplateValueParameter - This is a wrapper for template value parameter.
461 class DITemplateValueParameter : public DIDescriptor {
463 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
465 DIScope getContext() const { return getFieldAs<DIScope>(1); }
466 StringRef getName() const { return getStringField(2); }
467 DIType getType() const { return getFieldAs<DIType>(3); }
468 uint64_t getValue() const { return getUInt64Field(4); }
469 StringRef getFilename() const {
470 return getFieldAs<DIFile>(5).getFilename();
472 StringRef getDirectory() const {
473 return getFieldAs<DIFile>(5).getDirectory();
475 unsigned getLineNumber() const { return getUnsignedField(6); }
476 unsigned getColumnNumber() const { return getUnsignedField(7); }
479 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
480 class DISubprogram : public DIScope {
481 friend class DIDescriptor;
482 void printInternal(raw_ostream &OS) const;
484 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
486 DIScope getContext() const { return getFieldAs<DIScope>(2); }
487 StringRef getName() const { return getStringField(3); }
488 StringRef getDisplayName() const { return getStringField(4); }
489 StringRef getLinkageName() const { return getStringField(5); }
490 DICompileUnit getCompileUnit() const{
491 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
492 if (getVersion() == llvm::LLVMDebugVersion7)
493 return getFieldAs<DICompileUnit>(6);
495 return getFieldAs<DIFile>(6).getCompileUnit();
497 unsigned getLineNumber() const { return getUnsignedField(7); }
498 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
500 /// getReturnTypeName - Subprogram return types are encoded either as
501 /// DIType or as DICompositeType.
502 StringRef getReturnTypeName() const {
503 DICompositeType DCT(getFieldAs<DICompositeType>(8));
505 DIArray A = DCT.getTypeArray();
506 DIType T(A.getElement(0));
509 DIType T(getFieldAs<DIType>(8));
513 /// isLocalToUnit - Return true if this subprogram is local to the current
514 /// compile unit, like 'static' in C.
515 unsigned isLocalToUnit() const { return getUnsignedField(9); }
516 unsigned isDefinition() const { return getUnsignedField(10); }
518 unsigned getVirtuality() const { return getUnsignedField(11); }
519 unsigned getVirtualIndex() const { return getUnsignedField(12); }
521 DICompositeType getContainingType() const {
522 return getFieldAs<DICompositeType>(13);
525 unsigned isArtificial() const {
526 if (getVersion() <= llvm::LLVMDebugVersion8)
527 return getUnsignedField(14);
528 return (getUnsignedField(14) & FlagArtificial) != 0;
530 /// isPrivate - Return true if this subprogram has "private"
531 /// access specifier.
532 bool isPrivate() const {
533 if (getVersion() <= llvm::LLVMDebugVersion8)
535 return (getUnsignedField(14) & FlagPrivate) != 0;
537 /// isProtected - Return true if this subprogram has "protected"
538 /// access specifier.
539 bool isProtected() const {
540 if (getVersion() <= llvm::LLVMDebugVersion8)
542 return (getUnsignedField(14) & FlagProtected) != 0;
544 /// isExplicit - Return true if this subprogram is marked as explicit.
545 bool isExplicit() const {
546 if (getVersion() <= llvm::LLVMDebugVersion8)
548 return (getUnsignedField(14) & FlagExplicit) != 0;
550 /// isPrototyped - Return true if this subprogram is prototyped.
551 bool isPrototyped() const {
552 if (getVersion() <= llvm::LLVMDebugVersion8)
554 return (getUnsignedField(14) & FlagPrototyped) != 0;
557 unsigned isOptimized() const;
559 StringRef getFilename() const {
560 if (getVersion() == llvm::LLVMDebugVersion7)
561 return getCompileUnit().getFilename();
563 return getFieldAs<DIFile>(6).getFilename();
566 StringRef getDirectory() const {
567 if (getVersion() == llvm::LLVMDebugVersion7)
568 return getCompileUnit().getFilename();
570 return getFieldAs<DIFile>(6).getDirectory();
573 /// getScopeLineNumber - Get the beginning of the scope of the
574 /// function, not necessarily where the name of the program
576 unsigned getScopeLineNumber() const { return getUnsignedField(20); }
578 /// Verify - Verify that a subprogram descriptor is well formed.
581 /// describes - Return true if this subprogram provides debugging
582 /// information for the function F.
583 bool describes(const Function *F);
585 Function *getFunction() const { return getFunctionField(16); }
586 void replaceFunction(Function *F) { replaceFunctionField(16, F); }
587 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
588 DISubprogram getFunctionDeclaration() const {
589 return getFieldAs<DISubprogram>(18);
591 MDNode *getVariablesNodes() const;
592 DIArray getVariables() const;
595 /// DIGlobalVariable - This is a wrapper for a global variable.
596 class DIGlobalVariable : public DIDescriptor {
597 friend class DIDescriptor;
598 void printInternal(raw_ostream &OS) const;
600 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
602 DIScope getContext() const { return getFieldAs<DIScope>(2); }
603 StringRef getName() const { return getStringField(3); }
604 StringRef getDisplayName() const { return getStringField(4); }
605 StringRef getLinkageName() const { return getStringField(5); }
606 DICompileUnit getCompileUnit() const{
607 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
608 if (getVersion() == llvm::LLVMDebugVersion7)
609 return getFieldAs<DICompileUnit>(6);
611 DIFile F = getFieldAs<DIFile>(6);
612 return F.getCompileUnit();
614 StringRef getFilename() const {
615 if (getVersion() <= llvm::LLVMDebugVersion10)
616 return getContext().getFilename();
617 return getFieldAs<DIFile>(6).getFilename();
619 StringRef getDirectory() const {
620 if (getVersion() <= llvm::LLVMDebugVersion10)
621 return getContext().getDirectory();
622 return getFieldAs<DIFile>(6).getDirectory();
626 unsigned getLineNumber() const { return getUnsignedField(7); }
627 DIType getType() const { return getFieldAs<DIType>(8); }
628 unsigned isLocalToUnit() const { return getUnsignedField(9); }
629 unsigned isDefinition() const { return getUnsignedField(10); }
631 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
632 Constant *getConstant() const { return getConstantField(11); }
633 DIDerivedType getStaticDataMemberDeclaration() const {
634 return getFieldAs<DIDerivedType>(12);
637 /// Verify - Verify that a global variable descriptor is well formed.
641 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
643 class DIVariable : public DIDescriptor {
644 friend class DIDescriptor;
645 void printInternal(raw_ostream &OS) const;
647 explicit DIVariable(const MDNode *N = 0)
650 DIScope getContext() const { return getFieldAs<DIScope>(1); }
651 StringRef getName() const { return getStringField(2); }
652 DICompileUnit getCompileUnit() const {
653 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
654 if (getVersion() == llvm::LLVMDebugVersion7)
655 return getFieldAs<DICompileUnit>(3);
657 DIFile F = getFieldAs<DIFile>(3);
658 return F.getCompileUnit();
660 DIFile getFile() const { return getFieldAs<DIFile>(3); }
661 unsigned getLineNumber() const {
662 return (getUnsignedField(4) << 8) >> 8;
664 unsigned getArgNumber() const {
665 unsigned L = getUnsignedField(4);
668 DIType getType() const { return getFieldAs<DIType>(5); }
670 /// isArtificial - Return true if this variable is marked as "artificial".
671 bool isArtificial() const {
672 if (getVersion() <= llvm::LLVMDebugVersion8)
674 return (getUnsignedField(6) & FlagArtificial) != 0;
677 bool isObjectPointer() const {
678 return (getUnsignedField(6) & FlagObjectPointer) != 0;
681 /// getInlinedAt - If this variable is inlined then return inline location.
682 MDNode *getInlinedAt() const;
684 /// Verify - Verify that a variable descriptor is well formed.
687 /// HasComplexAddr - Return true if the variable has a complex address.
688 bool hasComplexAddress() const {
689 return getNumAddrElements() > 0;
692 unsigned getNumAddrElements() const;
694 uint64_t getAddrElement(unsigned Idx) const {
695 if (getVersion() <= llvm::LLVMDebugVersion8)
696 return getUInt64Field(Idx+6);
697 if (getVersion() == llvm::LLVMDebugVersion9)
698 return getUInt64Field(Idx+7);
699 return getUInt64Field(Idx+8);
702 /// isBlockByrefVariable - Return true if the variable was declared as
703 /// a "__block" variable (Apple Blocks).
704 bool isBlockByrefVariable() const {
705 return getType().isBlockByrefStruct();
708 /// isInlinedFnArgument - Return true if this variable provides debugging
709 /// information for an inlined function arguments.
710 bool isInlinedFnArgument(const Function *CurFn);
712 void printExtendedName(raw_ostream &OS) const;
715 /// DILexicalBlock - This is a wrapper for a lexical block.
716 class DILexicalBlock : public DIScope {
718 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
719 DIScope getContext() const { return getFieldAs<DIScope>(1); }
720 unsigned getLineNumber() const { return getUnsignedField(2); }
721 unsigned getColumnNumber() const { return getUnsignedField(3); }
722 StringRef getDirectory() const {
723 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
724 return !dir.empty() ? dir : getContext().getDirectory();
726 StringRef getFilename() const {
727 StringRef filename = getFieldAs<DIFile>(4).getFilename();
728 return !filename.empty() ? filename : getContext().getFilename();
732 /// DILexicalBlockFile - This is a wrapper for a lexical block with
733 /// a filename change.
734 class DILexicalBlockFile : public DIScope {
736 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
737 DIScope getContext() const { if (getScope().isSubprogram()) return getScope(); return getScope().getContext(); }
738 unsigned getLineNumber() const { return getScope().getLineNumber(); }
739 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
740 StringRef getDirectory() const {
741 StringRef dir = getFieldAs<DIFile>(2).getDirectory();
742 return !dir.empty() ? dir : getContext().getDirectory();
744 StringRef getFilename() const {
745 StringRef filename = getFieldAs<DIFile>(2).getFilename();
746 assert(!filename.empty() && "Why'd you create this then?");
749 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
752 /// DINameSpace - A wrapper for a C++ style name space.
753 class DINameSpace : public DIScope {
755 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
756 DIScope getContext() const { return getFieldAs<DIScope>(1); }
757 StringRef getName() const { return getStringField(2); }
758 StringRef getDirectory() const {
759 return getFieldAs<DIFile>(3).getDirectory();
761 StringRef getFilename() const {
762 return getFieldAs<DIFile>(3).getFilename();
764 DICompileUnit getCompileUnit() const{
765 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
766 if (getVersion() == llvm::LLVMDebugVersion7)
767 return getFieldAs<DICompileUnit>(3);
769 return getFieldAs<DIFile>(3).getCompileUnit();
771 unsigned getLineNumber() const { return getUnsignedField(4); }
775 /// DILocation - This object holds location information. This object
776 /// is not associated with any DWARF tag.
777 class DILocation : public DIDescriptor {
779 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
781 unsigned getLineNumber() const { return getUnsignedField(0); }
782 unsigned getColumnNumber() const { return getUnsignedField(1); }
783 DIScope getScope() const { return getFieldAs<DIScope>(2); }
784 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
785 StringRef getFilename() const { return getScope().getFilename(); }
786 StringRef getDirectory() const { return getScope().getDirectory(); }
790 class DIObjCProperty : public DIDescriptor {
791 friend class DIDescriptor;
792 void printInternal(raw_ostream &OS) const;
794 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
796 StringRef getObjCPropertyName() const { return getStringField(1); }
797 DIFile getFile() const { return getFieldAs<DIFile>(2); }
798 unsigned getLineNumber() const { return getUnsignedField(3); }
800 StringRef getObjCPropertyGetterName() const {
801 return getStringField(4);
803 StringRef getObjCPropertySetterName() const {
804 return getStringField(5);
806 bool isReadOnlyObjCProperty() {
807 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
809 bool isReadWriteObjCProperty() {
810 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
812 bool isAssignObjCProperty() {
813 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
815 bool isRetainObjCProperty() {
816 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
818 bool isCopyObjCProperty() {
819 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
821 bool isNonAtomicObjCProperty() {
822 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
825 DIType getType() const { return getFieldAs<DIType>(7); }
827 /// Verify - Verify that a derived type descriptor is well formed.
831 /// getDISubprogram - Find subprogram that is enclosing this scope.
832 DISubprogram getDISubprogram(const MDNode *Scope);
834 /// getDICompositeType - Find underlying composite type.
835 DICompositeType getDICompositeType(DIType T);
837 /// isSubprogramContext - Return true if Context is either a subprogram
838 /// or another context nested inside a subprogram.
839 bool isSubprogramContext(const MDNode *Context);
841 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
842 /// to hold function specific information.
843 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
845 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
846 /// suitable to hold function specific information.
847 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
849 /// createInlinedVariable - Create a new inlined variable based on current
851 /// @param DV Current Variable.
852 /// @param InlinedScope Location at current variable is inlined.
853 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
854 LLVMContext &VMContext);
856 /// cleanseInlinedVariable - Remove inlined scope from the variable.
857 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
859 class DebugInfoFinder {
861 /// processModule - Process entire module and collect debug info
863 void processModule(const Module &M);
866 /// processType - Process DIType.
867 void processType(DIType DT);
869 /// processLexicalBlock - Process DILexicalBlock.
870 void processLexicalBlock(DILexicalBlock LB);
872 /// processSubprogram - Process DISubprogram.
873 void processSubprogram(DISubprogram SP);
875 /// processDeclare - Process DbgDeclareInst.
876 void processDeclare(const DbgDeclareInst *DDI);
878 /// processLocation - Process DILocation.
879 void processLocation(DILocation Loc);
881 /// addCompileUnit - Add compile unit into CUs.
882 bool addCompileUnit(DICompileUnit CU);
884 /// addGlobalVariable - Add global variable into GVs.
885 bool addGlobalVariable(DIGlobalVariable DIG);
887 // addSubprogram - Add subprogram into SPs.
888 bool addSubprogram(DISubprogram SP);
890 /// addType - Add type into Tys.
891 bool addType(DIType DT);
894 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
895 iterator compile_unit_begin() const { return CUs.begin(); }
896 iterator compile_unit_end() const { return CUs.end(); }
897 iterator subprogram_begin() const { return SPs.begin(); }
898 iterator subprogram_end() const { return SPs.end(); }
899 iterator global_variable_begin() const { return GVs.begin(); }
900 iterator global_variable_end() const { return GVs.end(); }
901 iterator type_begin() const { return TYs.begin(); }
902 iterator type_end() const { return TYs.end(); }
904 unsigned compile_unit_count() const { return CUs.size(); }
905 unsigned global_variable_count() const { return GVs.size(); }
906 unsigned subprogram_count() const { return SPs.size(); }
907 unsigned type_count() const { return TYs.size(); }
910 SmallVector<MDNode *, 8> CUs; // Compile Units
911 SmallVector<MDNode *, 8> SPs; // Subprograms
912 SmallVector<MDNode *, 8> GVs; // Global Variables;
913 SmallVector<MDNode *, 8> TYs; // Types
914 SmallPtrSet<MDNode *, 64> NodesSeen;
916 } // end namespace llvm