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 DIFile getFile() const {
574 return getFieldAs<DIFile>(6);
577 /// getScopeLineNumber - Get the beginning of the scope of the
578 /// function, not necessarily where the name of the program
580 unsigned getScopeLineNumber() const { return getUnsignedField(20); }
582 /// Verify - Verify that a subprogram descriptor is well formed.
585 /// describes - Return true if this subprogram provides debugging
586 /// information for the function F.
587 bool describes(const Function *F);
589 Function *getFunction() const { return getFunctionField(16); }
590 void replaceFunction(Function *F) { replaceFunctionField(16, F); }
591 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
592 DISubprogram getFunctionDeclaration() const {
593 return getFieldAs<DISubprogram>(18);
595 MDNode *getVariablesNodes() const;
596 DIArray getVariables() const;
599 /// DIGlobalVariable - This is a wrapper for a global variable.
600 class DIGlobalVariable : public DIDescriptor {
601 friend class DIDescriptor;
602 void printInternal(raw_ostream &OS) const;
604 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
606 DIScope getContext() const { return getFieldAs<DIScope>(2); }
607 StringRef getName() const { return getStringField(3); }
608 StringRef getDisplayName() const { return getStringField(4); }
609 StringRef getLinkageName() const { return getStringField(5); }
610 DICompileUnit getCompileUnit() const{
611 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
612 if (getVersion() == llvm::LLVMDebugVersion7)
613 return getFieldAs<DICompileUnit>(6);
615 DIFile F = getFieldAs<DIFile>(6);
616 return F.getCompileUnit();
618 StringRef getFilename() const {
619 if (getVersion() <= llvm::LLVMDebugVersion10)
620 return getContext().getFilename();
621 return getFieldAs<DIFile>(6).getFilename();
623 StringRef getDirectory() const {
624 if (getVersion() <= llvm::LLVMDebugVersion10)
625 return getContext().getDirectory();
626 return getFieldAs<DIFile>(6).getDirectory();
630 unsigned getLineNumber() const { return getUnsignedField(7); }
631 DIType getType() const { return getFieldAs<DIType>(8); }
632 unsigned isLocalToUnit() const { return getUnsignedField(9); }
633 unsigned isDefinition() const { return getUnsignedField(10); }
635 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
636 Constant *getConstant() const { return getConstantField(11); }
637 DIDerivedType getStaticDataMemberDeclaration() const {
638 return getFieldAs<DIDerivedType>(12);
641 /// Verify - Verify that a global variable descriptor is well formed.
645 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
647 class DIVariable : public DIDescriptor {
648 friend class DIDescriptor;
649 void printInternal(raw_ostream &OS) const;
651 explicit DIVariable(const MDNode *N = 0)
654 DIScope getContext() const { return getFieldAs<DIScope>(1); }
655 StringRef getName() const { return getStringField(2); }
656 DICompileUnit getCompileUnit() const {
657 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
658 if (getVersion() == llvm::LLVMDebugVersion7)
659 return getFieldAs<DICompileUnit>(3);
661 DIFile F = getFieldAs<DIFile>(3);
662 return F.getCompileUnit();
664 DIFile getFile() const { return getFieldAs<DIFile>(3); }
665 unsigned getLineNumber() const {
666 return (getUnsignedField(4) << 8) >> 8;
668 unsigned getArgNumber() const {
669 unsigned L = getUnsignedField(4);
672 DIType getType() const { return getFieldAs<DIType>(5); }
674 /// isArtificial - Return true if this variable is marked as "artificial".
675 bool isArtificial() const {
676 if (getVersion() <= llvm::LLVMDebugVersion8)
678 return (getUnsignedField(6) & FlagArtificial) != 0;
681 bool isObjectPointer() const {
682 return (getUnsignedField(6) & FlagObjectPointer) != 0;
685 /// getInlinedAt - If this variable is inlined then return inline location.
686 MDNode *getInlinedAt() const;
688 /// Verify - Verify that a variable descriptor is well formed.
691 /// HasComplexAddr - Return true if the variable has a complex address.
692 bool hasComplexAddress() const {
693 return getNumAddrElements() > 0;
696 unsigned getNumAddrElements() const;
698 uint64_t getAddrElement(unsigned Idx) const {
699 if (getVersion() <= llvm::LLVMDebugVersion8)
700 return getUInt64Field(Idx+6);
701 if (getVersion() == llvm::LLVMDebugVersion9)
702 return getUInt64Field(Idx+7);
703 return getUInt64Field(Idx+8);
706 /// isBlockByrefVariable - Return true if the variable was declared as
707 /// a "__block" variable (Apple Blocks).
708 bool isBlockByrefVariable() const {
709 return getType().isBlockByrefStruct();
712 /// isInlinedFnArgument - Return true if this variable provides debugging
713 /// information for an inlined function arguments.
714 bool isInlinedFnArgument(const Function *CurFn);
716 void printExtendedName(raw_ostream &OS) const;
719 /// DILexicalBlock - This is a wrapper for a lexical block.
720 class DILexicalBlock : public DIScope {
722 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
723 DIScope getContext() const { return getFieldAs<DIScope>(1); }
724 unsigned getLineNumber() const { return getUnsignedField(2); }
725 unsigned getColumnNumber() const { return getUnsignedField(3); }
726 StringRef getDirectory() const {
727 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
728 return !dir.empty() ? dir : getContext().getDirectory();
730 StringRef getFilename() const {
731 StringRef filename = getFieldAs<DIFile>(4).getFilename();
732 return !filename.empty() ? filename : getContext().getFilename();
736 /// DILexicalBlockFile - This is a wrapper for a lexical block with
737 /// a filename change.
738 class DILexicalBlockFile : public DIScope {
740 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
741 DIScope getContext() const { if (getScope().isSubprogram()) return getScope(); return getScope().getContext(); }
742 unsigned getLineNumber() const { return getScope().getLineNumber(); }
743 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
744 StringRef getDirectory() const {
745 StringRef dir = getFieldAs<DIFile>(2).getDirectory();
746 return !dir.empty() ? dir : getContext().getDirectory();
748 StringRef getFilename() const {
749 StringRef filename = getFieldAs<DIFile>(2).getFilename();
750 assert(!filename.empty() && "Why'd you create this then?");
753 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
756 /// DINameSpace - A wrapper for a C++ style name space.
757 class DINameSpace : public DIScope {
759 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
760 DIScope getContext() const { return getFieldAs<DIScope>(1); }
761 StringRef getName() const { return getStringField(2); }
762 StringRef getDirectory() const {
763 return getFieldAs<DIFile>(3).getDirectory();
765 StringRef getFilename() const {
766 return getFieldAs<DIFile>(3).getFilename();
768 DICompileUnit getCompileUnit() const{
769 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
770 if (getVersion() == llvm::LLVMDebugVersion7)
771 return getFieldAs<DICompileUnit>(3);
773 return getFieldAs<DIFile>(3).getCompileUnit();
775 unsigned getLineNumber() const { return getUnsignedField(4); }
779 /// DILocation - This object holds location information. This object
780 /// is not associated with any DWARF tag.
781 class DILocation : public DIDescriptor {
783 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
785 unsigned getLineNumber() const { return getUnsignedField(0); }
786 unsigned getColumnNumber() const { return getUnsignedField(1); }
787 DIScope getScope() const { return getFieldAs<DIScope>(2); }
788 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
789 StringRef getFilename() const { return getScope().getFilename(); }
790 StringRef getDirectory() const { return getScope().getDirectory(); }
794 class DIObjCProperty : public DIDescriptor {
795 friend class DIDescriptor;
796 void printInternal(raw_ostream &OS) const;
798 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
800 StringRef getObjCPropertyName() const { return getStringField(1); }
801 DIFile getFile() const { return getFieldAs<DIFile>(2); }
802 unsigned getLineNumber() const { return getUnsignedField(3); }
804 StringRef getObjCPropertyGetterName() const {
805 return getStringField(4);
807 StringRef getObjCPropertySetterName() const {
808 return getStringField(5);
810 bool isReadOnlyObjCProperty() {
811 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
813 bool isReadWriteObjCProperty() {
814 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
816 bool isAssignObjCProperty() {
817 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
819 bool isRetainObjCProperty() {
820 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
822 bool isCopyObjCProperty() {
823 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
825 bool isNonAtomicObjCProperty() {
826 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
829 DIType getType() const { return getFieldAs<DIType>(7); }
831 /// Verify - Verify that a derived type descriptor is well formed.
835 /// getDISubprogram - Find subprogram that is enclosing this scope.
836 DISubprogram getDISubprogram(const MDNode *Scope);
838 /// getDICompositeType - Find underlying composite type.
839 DICompositeType getDICompositeType(DIType T);
841 /// isSubprogramContext - Return true if Context is either a subprogram
842 /// or another context nested inside a subprogram.
843 bool isSubprogramContext(const MDNode *Context);
845 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
846 /// to hold function specific information.
847 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
849 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
850 /// suitable to hold function specific information.
851 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
853 /// createInlinedVariable - Create a new inlined variable based on current
855 /// @param DV Current Variable.
856 /// @param InlinedScope Location at current variable is inlined.
857 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
858 LLVMContext &VMContext);
860 /// cleanseInlinedVariable - Remove inlined scope from the variable.
861 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
863 class DebugInfoFinder {
865 /// processModule - Process entire module and collect debug info
867 void processModule(const Module &M);
870 /// processType - Process DIType.
871 void processType(DIType DT);
873 /// processLexicalBlock - Process DILexicalBlock.
874 void processLexicalBlock(DILexicalBlock LB);
876 /// processSubprogram - Process DISubprogram.
877 void processSubprogram(DISubprogram SP);
879 /// processDeclare - Process DbgDeclareInst.
880 void processDeclare(const DbgDeclareInst *DDI);
882 /// processLocation - Process DILocation.
883 void processLocation(DILocation Loc);
885 /// addCompileUnit - Add compile unit into CUs.
886 bool addCompileUnit(DICompileUnit CU);
888 /// addGlobalVariable - Add global variable into GVs.
889 bool addGlobalVariable(DIGlobalVariable DIG);
891 // addSubprogram - Add subprogram into SPs.
892 bool addSubprogram(DISubprogram SP);
894 /// addType - Add type into Tys.
895 bool addType(DIType DT);
898 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
899 iterator compile_unit_begin() const { return CUs.begin(); }
900 iterator compile_unit_end() const { return CUs.end(); }
901 iterator subprogram_begin() const { return SPs.begin(); }
902 iterator subprogram_end() const { return SPs.end(); }
903 iterator global_variable_begin() const { return GVs.begin(); }
904 iterator global_variable_end() const { return GVs.end(); }
905 iterator type_begin() const { return TYs.begin(); }
906 iterator type_end() const { return TYs.end(); }
908 unsigned compile_unit_count() const { return CUs.size(); }
909 unsigned global_variable_count() const { return GVs.size(); }
910 unsigned subprogram_count() const { return SPs.size(); }
911 unsigned type_count() const { return TYs.size(); }
914 SmallVector<MDNode *, 8> CUs; // Compile Units
915 SmallVector<MDNode *, 8> SPs; // Subprograms
916 SmallVector<MDNode *, 8> GVs; // Global Variables;
917 SmallVector<MDNode *, 8> TYs; // Types
918 SmallPtrSet<MDNode *, 64> NodesSeen;
920 } // end namespace llvm