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.
195 // TODO: This can be removed when we remove the legacy debug information.
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 StringRef getSplitDebugFilename() const { return getStringField(14); }
208 /// Verify - Verify that a compile unit is well formed.
212 /// DIFile - This is a wrapper for a file.
213 class DIFile : public DIScope {
214 friend class DIDescriptor;
215 void printInternal(raw_ostream &OS) const {} // FIXME: Output something?
217 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
218 if (DbgNode && !isFile())
221 StringRef getFilename() const { return getStringField(1); }
222 StringRef getDirectory() const { return getStringField(2); }
223 DICompileUnit getCompileUnit() const{
224 assert (getVersion() <= LLVMDebugVersion10 && "Invalid CompileUnit!");
225 return getFieldAs<DICompileUnit>(3);
229 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
230 /// FIXME: it seems strange that this doesn't have either a reference to the
231 /// type/precision or a file/line pair for location info.
232 class DIEnumerator : public DIDescriptor {
233 friend class DIDescriptor;
234 void printInternal(raw_ostream &OS) const;
236 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
238 StringRef getName() const { return getStringField(1); }
239 uint64_t getEnumValue() const { return getUInt64Field(2); }
242 /// DIType - This is a wrapper for a type.
243 /// FIXME: Types should be factored much better so that CV qualifiers and
244 /// others do not require a huge and empty descriptor full of zeros.
245 class DIType : public DIScope {
247 friend class DIDescriptor;
248 void printInternal(raw_ostream &OS) const;
249 // This ctor is used when the Tag has already been validated by a derived
251 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
253 /// Verify - Verify that a type descriptor is well formed.
255 explicit DIType(const MDNode *N);
258 DIScope getContext() const { return getFieldAs<DIScope>(1); }
259 StringRef getName() const { return getStringField(2); }
260 DICompileUnit getCompileUnit() const{
261 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
262 if (getVersion() == llvm::LLVMDebugVersion7)
263 return getFieldAs<DICompileUnit>(3);
265 return getFieldAs<DIFile>(3).getCompileUnit();
267 DIFile getFile() const { return getFieldAs<DIFile>(3); }
268 unsigned getLineNumber() const { return getUnsignedField(4); }
269 uint64_t getSizeInBits() const { return getUInt64Field(5); }
270 uint64_t getAlignInBits() const { return getUInt64Field(6); }
271 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
272 // carry this is just plain insane.
273 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
274 unsigned getFlags() const { return getUnsignedField(8); }
275 bool isPrivate() const {
276 return (getFlags() & FlagPrivate) != 0;
278 bool isProtected() const {
279 return (getFlags() & FlagProtected) != 0;
281 bool isForwardDecl() const {
282 return (getFlags() & FlagFwdDecl) != 0;
284 // isAppleBlock - Return true if this is the Apple Blocks extension.
285 bool isAppleBlockExtension() const {
286 return (getFlags() & FlagAppleBlock) != 0;
288 bool isBlockByrefStruct() const {
289 return (getFlags() & FlagBlockByrefStruct) != 0;
291 bool isVirtual() const {
292 return (getFlags() & FlagVirtual) != 0;
294 bool isArtificial() const {
295 return (getFlags() & FlagArtificial) != 0;
297 bool isObjectPointer() const {
298 return (getFlags() & FlagObjectPointer) != 0;
300 bool isObjcClassComplete() const {
301 return (getFlags() & FlagObjcClassComplete) != 0;
303 bool isVector() const {
304 return (getFlags() & FlagVector) != 0;
306 bool isStaticMember() const {
307 return (getFlags() & FlagStaticMember) != 0;
309 bool isValid() const {
310 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
312 StringRef getDirectory() const {
313 if (getVersion() == llvm::LLVMDebugVersion7)
314 return getCompileUnit().getDirectory();
316 return getFieldAs<DIFile>(3).getDirectory();
318 StringRef getFilename() const {
319 if (getVersion() == llvm::LLVMDebugVersion7)
320 return getCompileUnit().getFilename();
322 return getFieldAs<DIFile>(3).getFilename();
325 /// isUnsignedDIType - Return true if type encoding is unsigned.
326 bool isUnsignedDIType();
328 /// replaceAllUsesWith - Replace all uses of debug info referenced by
330 void replaceAllUsesWith(DIDescriptor &D);
331 void replaceAllUsesWith(MDNode *D);
334 /// DIBasicType - A basic type, like 'int' or 'float'.
335 class DIBasicType : public DIType {
337 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
339 unsigned getEncoding() const { return getUnsignedField(9); }
341 /// Verify - Verify that a basic type descriptor is well formed.
345 /// DIDerivedType - A simple derived type, like a const qualified type,
346 /// a typedef, a pointer or reference, et cetera. Or, a data member of
347 /// a class/struct/union.
348 class DIDerivedType : public DIType {
349 friend class DIDescriptor;
350 void printInternal(raw_ostream &OS) const;
352 explicit DIDerivedType(const MDNode *N, bool, bool)
353 : DIType(N, true, true) {}
355 explicit DIDerivedType(const MDNode *N = 0)
356 : DIType(N, true, true) {}
358 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
360 /// getOriginalTypeSize - If this type is derived from a base type then
361 /// return base type size.
362 uint64_t getOriginalTypeSize() const;
364 /// getObjCProperty - Return property node, if this ivar is
365 /// associated with one.
366 MDNode *getObjCProperty() const;
368 DIType getClassType() const {
369 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
370 return getFieldAs<DIType>(10);
373 Constant *getConstant() const {
374 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
375 return getConstantField(10);
378 StringRef getObjCPropertyName() const {
379 if (getVersion() > LLVMDebugVersion11)
381 return getStringField(10);
383 StringRef getObjCPropertyGetterName() const {
384 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
385 return getStringField(11);
387 StringRef getObjCPropertySetterName() const {
388 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
389 return getStringField(12);
391 bool isReadOnlyObjCProperty() {
392 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
393 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
395 bool isReadWriteObjCProperty() {
396 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
397 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
399 bool isAssignObjCProperty() {
400 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
401 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
403 bool isRetainObjCProperty() {
404 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
405 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
407 bool isCopyObjCProperty() {
408 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
409 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
411 bool isNonAtomicObjCProperty() {
412 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
413 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
416 /// Verify - Verify that a derived type descriptor is well formed.
420 /// DICompositeType - This descriptor holds a type that can refer to multiple
421 /// other types, like a function or struct.
422 /// FIXME: Why is this a DIDerivedType??
423 class DICompositeType : public DIDerivedType {
424 friend class DIDescriptor;
425 void printInternal(raw_ostream &OS) const;
427 explicit DICompositeType(const MDNode *N = 0)
428 : DIDerivedType(N, true, true) {
429 if (N && !isCompositeType())
433 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
434 unsigned getRunTimeLang() const { return getUnsignedField(11); }
435 DICompositeType getContainingType() const {
436 return getFieldAs<DICompositeType>(12);
438 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
440 /// Verify - Verify that a composite type descriptor is well formed.
444 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
445 class DITemplateTypeParameter : public DIDescriptor {
447 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
449 DIScope getContext() const { return getFieldAs<DIScope>(1); }
450 StringRef getName() const { return getStringField(2); }
451 DIType getType() const { return getFieldAs<DIType>(3); }
452 StringRef getFilename() const {
453 return getFieldAs<DIFile>(4).getFilename();
455 StringRef getDirectory() const {
456 return getFieldAs<DIFile>(4).getDirectory();
458 unsigned getLineNumber() const { return getUnsignedField(5); }
459 unsigned getColumnNumber() const { return getUnsignedField(6); }
462 /// DITemplateValueParameter - This is a wrapper for template value parameter.
463 class DITemplateValueParameter : public DIDescriptor {
465 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
467 DIScope getContext() const { return getFieldAs<DIScope>(1); }
468 StringRef getName() const { return getStringField(2); }
469 DIType getType() const { return getFieldAs<DIType>(3); }
470 uint64_t getValue() const { return getUInt64Field(4); }
471 StringRef getFilename() const {
472 return getFieldAs<DIFile>(5).getFilename();
474 StringRef getDirectory() const {
475 return getFieldAs<DIFile>(5).getDirectory();
477 unsigned getLineNumber() const { return getUnsignedField(6); }
478 unsigned getColumnNumber() const { return getUnsignedField(7); }
481 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
482 class DISubprogram : public DIScope {
483 friend class DIDescriptor;
484 void printInternal(raw_ostream &OS) const;
486 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
488 DIScope getContext() const { return getFieldAs<DIScope>(2); }
489 StringRef getName() const { return getStringField(3); }
490 StringRef getDisplayName() const { return getStringField(4); }
491 StringRef getLinkageName() const { return getStringField(5); }
492 DICompileUnit getCompileUnit() const{
493 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
494 if (getVersion() == llvm::LLVMDebugVersion7)
495 return getFieldAs<DICompileUnit>(6);
497 return getFieldAs<DIFile>(6).getCompileUnit();
499 unsigned getLineNumber() const { return getUnsignedField(7); }
500 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
502 /// getReturnTypeName - Subprogram return types are encoded either as
503 /// DIType or as DICompositeType.
504 StringRef getReturnTypeName() const {
505 DICompositeType DCT(getFieldAs<DICompositeType>(8));
507 DIArray A = DCT.getTypeArray();
508 DIType T(A.getElement(0));
511 DIType T(getFieldAs<DIType>(8));
515 /// isLocalToUnit - Return true if this subprogram is local to the current
516 /// compile unit, like 'static' in C.
517 unsigned isLocalToUnit() const { return getUnsignedField(9); }
518 unsigned isDefinition() const { return getUnsignedField(10); }
520 unsigned getVirtuality() const { return getUnsignedField(11); }
521 unsigned getVirtualIndex() const { return getUnsignedField(12); }
523 DICompositeType getContainingType() const {
524 return getFieldAs<DICompositeType>(13);
527 unsigned getFlags() const {
528 return getUnsignedField(14);
531 unsigned isArtificial() const {
532 if (getVersion() <= llvm::LLVMDebugVersion8)
533 return getUnsignedField(14);
534 return (getUnsignedField(14) & FlagArtificial) != 0;
536 /// isPrivate - Return true if this subprogram has "private"
537 /// access specifier.
538 bool isPrivate() const {
539 if (getVersion() <= llvm::LLVMDebugVersion8)
541 return (getUnsignedField(14) & FlagPrivate) != 0;
543 /// isProtected - Return true if this subprogram has "protected"
544 /// access specifier.
545 bool isProtected() const {
546 if (getVersion() <= llvm::LLVMDebugVersion8)
548 return (getUnsignedField(14) & FlagProtected) != 0;
550 /// isExplicit - Return true if this subprogram is marked as explicit.
551 bool isExplicit() const {
552 if (getVersion() <= llvm::LLVMDebugVersion8)
554 return (getUnsignedField(14) & FlagExplicit) != 0;
556 /// isPrototyped - Return true if this subprogram is prototyped.
557 bool isPrototyped() const {
558 if (getVersion() <= llvm::LLVMDebugVersion8)
560 return (getUnsignedField(14) & FlagPrototyped) != 0;
563 unsigned isOptimized() const;
565 StringRef getFilename() const {
566 if (getVersion() == llvm::LLVMDebugVersion7)
567 return getCompileUnit().getFilename();
569 return getFieldAs<DIFile>(6).getFilename();
572 StringRef getDirectory() const {
573 if (getVersion() == llvm::LLVMDebugVersion7)
574 return getCompileUnit().getFilename();
576 return getFieldAs<DIFile>(6).getDirectory();
579 DIFile getFile() const {
580 return getFieldAs<DIFile>(6);
583 /// getScopeLineNumber - Get the beginning of the scope of the
584 /// function, not necessarily where the name of the program
586 unsigned getScopeLineNumber() const { return getUnsignedField(20); }
588 /// Verify - Verify that a subprogram descriptor is well formed.
591 /// describes - Return true if this subprogram provides debugging
592 /// information for the function F.
593 bool describes(const Function *F);
595 Function *getFunction() const { return getFunctionField(16); }
596 void replaceFunction(Function *F) { replaceFunctionField(16, F); }
597 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
598 DISubprogram getFunctionDeclaration() const {
599 return getFieldAs<DISubprogram>(18);
601 MDNode *getVariablesNodes() const;
602 DIArray getVariables() const;
605 /// DIGlobalVariable - This is a wrapper for a global variable.
606 class DIGlobalVariable : public DIDescriptor {
607 friend class DIDescriptor;
608 void printInternal(raw_ostream &OS) const;
610 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
612 DIScope getContext() const { return getFieldAs<DIScope>(2); }
613 StringRef getName() const { return getStringField(3); }
614 StringRef getDisplayName() const { return getStringField(4); }
615 StringRef getLinkageName() const { return getStringField(5); }
616 DICompileUnit getCompileUnit() const{
617 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
618 if (getVersion() == llvm::LLVMDebugVersion7)
619 return getFieldAs<DICompileUnit>(6);
621 DIFile F = getFieldAs<DIFile>(6);
622 return F.getCompileUnit();
624 StringRef getFilename() const {
625 if (getVersion() <= llvm::LLVMDebugVersion10)
626 return getContext().getFilename();
627 return getFieldAs<DIFile>(6).getFilename();
629 StringRef getDirectory() const {
630 if (getVersion() <= llvm::LLVMDebugVersion10)
631 return getContext().getDirectory();
632 return getFieldAs<DIFile>(6).getDirectory();
636 unsigned getLineNumber() const { return getUnsignedField(7); }
637 DIType getType() const { return getFieldAs<DIType>(8); }
638 unsigned isLocalToUnit() const { return getUnsignedField(9); }
639 unsigned isDefinition() const { return getUnsignedField(10); }
641 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
642 Constant *getConstant() const { return getConstantField(11); }
643 DIDerivedType getStaticDataMemberDeclaration() const {
644 return getFieldAs<DIDerivedType>(12);
647 /// Verify - Verify that a global variable descriptor is well formed.
651 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
653 class DIVariable : public DIDescriptor {
654 friend class DIDescriptor;
655 void printInternal(raw_ostream &OS) const;
657 explicit DIVariable(const MDNode *N = 0)
660 DIScope getContext() const { return getFieldAs<DIScope>(1); }
661 StringRef getName() const { return getStringField(2); }
662 DICompileUnit getCompileUnit() const {
663 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
664 if (getVersion() == llvm::LLVMDebugVersion7)
665 return getFieldAs<DICompileUnit>(3);
667 DIFile F = getFieldAs<DIFile>(3);
668 return F.getCompileUnit();
670 DIFile getFile() const { return getFieldAs<DIFile>(3); }
671 unsigned getLineNumber() const {
672 return (getUnsignedField(4) << 8) >> 8;
674 unsigned getArgNumber() const {
675 unsigned L = getUnsignedField(4);
678 DIType getType() const { return getFieldAs<DIType>(5); }
680 /// isArtificial - Return true if this variable is marked as "artificial".
681 bool isArtificial() const {
682 if (getVersion() <= llvm::LLVMDebugVersion8)
684 return (getUnsignedField(6) & FlagArtificial) != 0;
687 bool isObjectPointer() const {
688 return (getUnsignedField(6) & FlagObjectPointer) != 0;
691 /// getInlinedAt - If this variable is inlined then return inline location.
692 MDNode *getInlinedAt() const;
694 /// Verify - Verify that a variable descriptor is well formed.
697 /// HasComplexAddr - Return true if the variable has a complex address.
698 bool hasComplexAddress() const {
699 return getNumAddrElements() > 0;
702 unsigned getNumAddrElements() const;
704 uint64_t getAddrElement(unsigned Idx) const {
705 if (getVersion() <= llvm::LLVMDebugVersion8)
706 return getUInt64Field(Idx+6);
707 if (getVersion() == llvm::LLVMDebugVersion9)
708 return getUInt64Field(Idx+7);
709 return getUInt64Field(Idx+8);
712 /// isBlockByrefVariable - Return true if the variable was declared as
713 /// a "__block" variable (Apple Blocks).
714 bool isBlockByrefVariable() const {
715 return getType().isBlockByrefStruct();
718 /// isInlinedFnArgument - Return true if this variable provides debugging
719 /// information for an inlined function arguments.
720 bool isInlinedFnArgument(const Function *CurFn);
722 void printExtendedName(raw_ostream &OS) const;
725 /// DILexicalBlock - This is a wrapper for a lexical block.
726 class DILexicalBlock : public DIScope {
728 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
729 DIScope getContext() const { return getFieldAs<DIScope>(1); }
730 unsigned getLineNumber() const { return getUnsignedField(2); }
731 unsigned getColumnNumber() const { return getUnsignedField(3); }
732 StringRef getDirectory() const {
733 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
734 return !dir.empty() ? dir : getContext().getDirectory();
736 StringRef getFilename() const {
737 StringRef filename = getFieldAs<DIFile>(4).getFilename();
738 return !filename.empty() ? filename : getContext().getFilename();
742 /// DILexicalBlockFile - This is a wrapper for a lexical block with
743 /// a filename change.
744 class DILexicalBlockFile : public DIScope {
746 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
747 DIScope getContext() const { if (getScope().isSubprogram()) return getScope(); return getScope().getContext(); }
748 unsigned getLineNumber() const { return getScope().getLineNumber(); }
749 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
750 StringRef getDirectory() const {
751 StringRef dir = getFieldAs<DIFile>(2).getDirectory();
752 return !dir.empty() ? dir : getContext().getDirectory();
754 StringRef getFilename() const {
755 StringRef filename = getFieldAs<DIFile>(2).getFilename();
756 assert(!filename.empty() && "Why'd you create this then?");
759 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
762 /// DINameSpace - A wrapper for a C++ style name space.
763 class DINameSpace : public DIScope {
765 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
766 DIScope getContext() const { return getFieldAs<DIScope>(1); }
767 StringRef getName() const { return getStringField(2); }
768 StringRef getDirectory() const {
769 return getFieldAs<DIFile>(3).getDirectory();
771 StringRef getFilename() const {
772 return getFieldAs<DIFile>(3).getFilename();
774 DICompileUnit getCompileUnit() const{
775 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
776 if (getVersion() == llvm::LLVMDebugVersion7)
777 return getFieldAs<DICompileUnit>(3);
779 return getFieldAs<DIFile>(3).getCompileUnit();
781 unsigned getLineNumber() const { return getUnsignedField(4); }
785 /// DILocation - This object holds location information. This object
786 /// is not associated with any DWARF tag.
787 class DILocation : public DIDescriptor {
789 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
791 unsigned getLineNumber() const { return getUnsignedField(0); }
792 unsigned getColumnNumber() const { return getUnsignedField(1); }
793 DIScope getScope() const { return getFieldAs<DIScope>(2); }
794 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
795 StringRef getFilename() const { return getScope().getFilename(); }
796 StringRef getDirectory() const { return getScope().getDirectory(); }
800 class DIObjCProperty : public DIDescriptor {
801 friend class DIDescriptor;
802 void printInternal(raw_ostream &OS) const;
804 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
806 StringRef getObjCPropertyName() const { return getStringField(1); }
807 DIFile getFile() const { return getFieldAs<DIFile>(2); }
808 unsigned getLineNumber() const { return getUnsignedField(3); }
810 StringRef getObjCPropertyGetterName() const {
811 return getStringField(4);
813 StringRef getObjCPropertySetterName() const {
814 return getStringField(5);
816 bool isReadOnlyObjCProperty() {
817 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
819 bool isReadWriteObjCProperty() {
820 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
822 bool isAssignObjCProperty() {
823 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
825 bool isRetainObjCProperty() {
826 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
828 bool isCopyObjCProperty() {
829 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
831 bool isNonAtomicObjCProperty() {
832 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
835 DIType getType() const { return getFieldAs<DIType>(7); }
837 /// Verify - Verify that a derived type descriptor is well formed.
841 /// getDISubprogram - Find subprogram that is enclosing this scope.
842 DISubprogram getDISubprogram(const MDNode *Scope);
844 /// getDICompositeType - Find underlying composite type.
845 DICompositeType getDICompositeType(DIType T);
847 /// isSubprogramContext - Return true if Context is either a subprogram
848 /// or another context nested inside a subprogram.
849 bool isSubprogramContext(const MDNode *Context);
851 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
852 /// to hold function specific information.
853 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
855 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
856 /// suitable to hold function specific information.
857 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
859 /// createInlinedVariable - Create a new inlined variable based on current
861 /// @param DV Current Variable.
862 /// @param InlinedScope Location at current variable is inlined.
863 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
864 LLVMContext &VMContext);
866 /// cleanseInlinedVariable - Remove inlined scope from the variable.
867 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
869 class DebugInfoFinder {
871 /// processModule - Process entire module and collect debug info
873 void processModule(const Module &M);
876 /// processType - Process DIType.
877 void processType(DIType DT);
879 /// processLexicalBlock - Process DILexicalBlock.
880 void processLexicalBlock(DILexicalBlock LB);
882 /// processSubprogram - Process DISubprogram.
883 void processSubprogram(DISubprogram SP);
885 /// processDeclare - Process DbgDeclareInst.
886 void processDeclare(const DbgDeclareInst *DDI);
888 /// processLocation - Process DILocation.
889 void processLocation(DILocation Loc);
891 /// addCompileUnit - Add compile unit into CUs.
892 bool addCompileUnit(DICompileUnit CU);
894 /// addGlobalVariable - Add global variable into GVs.
895 bool addGlobalVariable(DIGlobalVariable DIG);
897 // addSubprogram - Add subprogram into SPs.
898 bool addSubprogram(DISubprogram SP);
900 /// addType - Add type into Tys.
901 bool addType(DIType DT);
904 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
905 iterator compile_unit_begin() const { return CUs.begin(); }
906 iterator compile_unit_end() const { return CUs.end(); }
907 iterator subprogram_begin() const { return SPs.begin(); }
908 iterator subprogram_end() const { return SPs.end(); }
909 iterator global_variable_begin() const { return GVs.begin(); }
910 iterator global_variable_end() const { return GVs.end(); }
911 iterator type_begin() const { return TYs.begin(); }
912 iterator type_end() const { return TYs.end(); }
914 unsigned compile_unit_count() const { return CUs.size(); }
915 unsigned global_variable_count() const { return GVs.size(); }
916 unsigned subprogram_count() const { return SPs.size(); }
917 unsigned type_count() const { return TYs.size(); }
920 SmallVector<MDNode *, 8> CUs; // Compile Units
921 SmallVector<MDNode *, 8> SPs; // Subprograms
922 SmallVector<MDNode *, 8> GVs; // Global Variables;
923 SmallVector<MDNode *, 8> TYs; // Types
924 SmallPtrSet<MDNode *, 64> NodesSeen;
926 } // end namespace llvm