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 /// 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 getFlags() const {
526 return getUnsignedField(14);
529 unsigned isArtificial() const {
530 if (getVersion() <= llvm::LLVMDebugVersion8)
531 return getUnsignedField(14);
532 return (getUnsignedField(14) & FlagArtificial) != 0;
534 /// isPrivate - Return true if this subprogram has "private"
535 /// access specifier.
536 bool isPrivate() const {
537 if (getVersion() <= llvm::LLVMDebugVersion8)
539 return (getUnsignedField(14) & FlagPrivate) != 0;
541 /// isProtected - Return true if this subprogram has "protected"
542 /// access specifier.
543 bool isProtected() const {
544 if (getVersion() <= llvm::LLVMDebugVersion8)
546 return (getUnsignedField(14) & FlagProtected) != 0;
548 /// isExplicit - Return true if this subprogram is marked as explicit.
549 bool isExplicit() const {
550 if (getVersion() <= llvm::LLVMDebugVersion8)
552 return (getUnsignedField(14) & FlagExplicit) != 0;
554 /// isPrototyped - Return true if this subprogram is prototyped.
555 bool isPrototyped() const {
556 if (getVersion() <= llvm::LLVMDebugVersion8)
558 return (getUnsignedField(14) & FlagPrototyped) != 0;
561 unsigned isOptimized() const;
563 StringRef getFilename() const {
564 if (getVersion() == llvm::LLVMDebugVersion7)
565 return getCompileUnit().getFilename();
567 return getFieldAs<DIFile>(6).getFilename();
570 StringRef getDirectory() const {
571 if (getVersion() == llvm::LLVMDebugVersion7)
572 return getCompileUnit().getFilename();
574 return getFieldAs<DIFile>(6).getDirectory();
577 DIFile getFile() const {
578 return getFieldAs<DIFile>(6);
581 /// getScopeLineNumber - Get the beginning of the scope of the
582 /// function, not necessarily where the name of the program
584 unsigned getScopeLineNumber() const { return getUnsignedField(20); }
586 /// Verify - Verify that a subprogram descriptor is well formed.
589 /// describes - Return true if this subprogram provides debugging
590 /// information for the function F.
591 bool describes(const Function *F);
593 Function *getFunction() const { return getFunctionField(16); }
594 void replaceFunction(Function *F) { replaceFunctionField(16, F); }
595 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
596 DISubprogram getFunctionDeclaration() const {
597 return getFieldAs<DISubprogram>(18);
599 MDNode *getVariablesNodes() const;
600 DIArray getVariables() const;
603 /// DIGlobalVariable - This is a wrapper for a global variable.
604 class DIGlobalVariable : public DIDescriptor {
605 friend class DIDescriptor;
606 void printInternal(raw_ostream &OS) const;
608 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
610 DIScope getContext() const { return getFieldAs<DIScope>(2); }
611 StringRef getName() const { return getStringField(3); }
612 StringRef getDisplayName() const { return getStringField(4); }
613 StringRef getLinkageName() const { return getStringField(5); }
614 DICompileUnit getCompileUnit() const{
615 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
616 if (getVersion() == llvm::LLVMDebugVersion7)
617 return getFieldAs<DICompileUnit>(6);
619 DIFile F = getFieldAs<DIFile>(6);
620 return F.getCompileUnit();
622 StringRef getFilename() const {
623 if (getVersion() <= llvm::LLVMDebugVersion10)
624 return getContext().getFilename();
625 return getFieldAs<DIFile>(6).getFilename();
627 StringRef getDirectory() const {
628 if (getVersion() <= llvm::LLVMDebugVersion10)
629 return getContext().getDirectory();
630 return getFieldAs<DIFile>(6).getDirectory();
634 unsigned getLineNumber() const { return getUnsignedField(7); }
635 DIType getType() const { return getFieldAs<DIType>(8); }
636 unsigned isLocalToUnit() const { return getUnsignedField(9); }
637 unsigned isDefinition() const { return getUnsignedField(10); }
639 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
640 Constant *getConstant() const { return getConstantField(11); }
641 DIDerivedType getStaticDataMemberDeclaration() const {
642 return getFieldAs<DIDerivedType>(12);
645 /// Verify - Verify that a global variable descriptor is well formed.
649 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
651 class DIVariable : public DIDescriptor {
652 friend class DIDescriptor;
653 void printInternal(raw_ostream &OS) const;
655 explicit DIVariable(const MDNode *N = 0)
658 DIScope getContext() const { return getFieldAs<DIScope>(1); }
659 StringRef getName() const { return getStringField(2); }
660 DICompileUnit getCompileUnit() const {
661 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
662 if (getVersion() == llvm::LLVMDebugVersion7)
663 return getFieldAs<DICompileUnit>(3);
665 DIFile F = getFieldAs<DIFile>(3);
666 return F.getCompileUnit();
668 DIFile getFile() const { return getFieldAs<DIFile>(3); }
669 unsigned getLineNumber() const {
670 return (getUnsignedField(4) << 8) >> 8;
672 unsigned getArgNumber() const {
673 unsigned L = getUnsignedField(4);
676 DIType getType() const { return getFieldAs<DIType>(5); }
678 /// isArtificial - Return true if this variable is marked as "artificial".
679 bool isArtificial() const {
680 if (getVersion() <= llvm::LLVMDebugVersion8)
682 return (getUnsignedField(6) & FlagArtificial) != 0;
685 bool isObjectPointer() const {
686 return (getUnsignedField(6) & FlagObjectPointer) != 0;
689 /// getInlinedAt - If this variable is inlined then return inline location.
690 MDNode *getInlinedAt() const;
692 /// Verify - Verify that a variable descriptor is well formed.
695 /// HasComplexAddr - Return true if the variable has a complex address.
696 bool hasComplexAddress() const {
697 return getNumAddrElements() > 0;
700 unsigned getNumAddrElements() const;
702 uint64_t getAddrElement(unsigned Idx) const {
703 if (getVersion() <= llvm::LLVMDebugVersion8)
704 return getUInt64Field(Idx+6);
705 if (getVersion() == llvm::LLVMDebugVersion9)
706 return getUInt64Field(Idx+7);
707 return getUInt64Field(Idx+8);
710 /// isBlockByrefVariable - Return true if the variable was declared as
711 /// a "__block" variable (Apple Blocks).
712 bool isBlockByrefVariable() const {
713 return getType().isBlockByrefStruct();
716 /// isInlinedFnArgument - Return true if this variable provides debugging
717 /// information for an inlined function arguments.
718 bool isInlinedFnArgument(const Function *CurFn);
720 void printExtendedName(raw_ostream &OS) const;
723 /// DILexicalBlock - This is a wrapper for a lexical block.
724 class DILexicalBlock : public DIScope {
726 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
727 DIScope getContext() const { return getFieldAs<DIScope>(1); }
728 unsigned getLineNumber() const { return getUnsignedField(2); }
729 unsigned getColumnNumber() const { return getUnsignedField(3); }
730 StringRef getDirectory() const {
731 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
732 return !dir.empty() ? dir : getContext().getDirectory();
734 StringRef getFilename() const {
735 StringRef filename = getFieldAs<DIFile>(4).getFilename();
736 return !filename.empty() ? filename : getContext().getFilename();
740 /// DILexicalBlockFile - This is a wrapper for a lexical block with
741 /// a filename change.
742 class DILexicalBlockFile : public DIScope {
744 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
745 DIScope getContext() const { if (getScope().isSubprogram()) return getScope(); return getScope().getContext(); }
746 unsigned getLineNumber() const { return getScope().getLineNumber(); }
747 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
748 StringRef getDirectory() const {
749 StringRef dir = getFieldAs<DIFile>(2).getDirectory();
750 return !dir.empty() ? dir : getContext().getDirectory();
752 StringRef getFilename() const {
753 StringRef filename = getFieldAs<DIFile>(2).getFilename();
754 assert(!filename.empty() && "Why'd you create this then?");
757 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
760 /// DINameSpace - A wrapper for a C++ style name space.
761 class DINameSpace : public DIScope {
763 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
764 DIScope getContext() const { return getFieldAs<DIScope>(1); }
765 StringRef getName() const { return getStringField(2); }
766 StringRef getDirectory() const {
767 return getFieldAs<DIFile>(3).getDirectory();
769 StringRef getFilename() const {
770 return getFieldAs<DIFile>(3).getFilename();
772 DICompileUnit getCompileUnit() const{
773 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
774 if (getVersion() == llvm::LLVMDebugVersion7)
775 return getFieldAs<DICompileUnit>(3);
777 return getFieldAs<DIFile>(3).getCompileUnit();
779 unsigned getLineNumber() const { return getUnsignedField(4); }
783 /// DILocation - This object holds location information. This object
784 /// is not associated with any DWARF tag.
785 class DILocation : public DIDescriptor {
787 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
789 unsigned getLineNumber() const { return getUnsignedField(0); }
790 unsigned getColumnNumber() const { return getUnsignedField(1); }
791 DIScope getScope() const { return getFieldAs<DIScope>(2); }
792 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
793 StringRef getFilename() const { return getScope().getFilename(); }
794 StringRef getDirectory() const { return getScope().getDirectory(); }
798 class DIObjCProperty : public DIDescriptor {
799 friend class DIDescriptor;
800 void printInternal(raw_ostream &OS) const;
802 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
804 StringRef getObjCPropertyName() const { return getStringField(1); }
805 DIFile getFile() const { return getFieldAs<DIFile>(2); }
806 unsigned getLineNumber() const { return getUnsignedField(3); }
808 StringRef getObjCPropertyGetterName() const {
809 return getStringField(4);
811 StringRef getObjCPropertySetterName() const {
812 return getStringField(5);
814 bool isReadOnlyObjCProperty() {
815 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
817 bool isReadWriteObjCProperty() {
818 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
820 bool isAssignObjCProperty() {
821 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
823 bool isRetainObjCProperty() {
824 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
826 bool isCopyObjCProperty() {
827 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
829 bool isNonAtomicObjCProperty() {
830 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
833 DIType getType() const { return getFieldAs<DIType>(7); }
835 /// Verify - Verify that a derived type descriptor is well formed.
839 /// getDISubprogram - Find subprogram that is enclosing this scope.
840 DISubprogram getDISubprogram(const MDNode *Scope);
842 /// getDICompositeType - Find underlying composite type.
843 DICompositeType getDICompositeType(DIType T);
845 /// isSubprogramContext - Return true if Context is either a subprogram
846 /// or another context nested inside a subprogram.
847 bool isSubprogramContext(const MDNode *Context);
849 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
850 /// to hold function specific information.
851 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
853 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
854 /// suitable to hold function specific information.
855 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
857 /// createInlinedVariable - Create a new inlined variable based on current
859 /// @param DV Current Variable.
860 /// @param InlinedScope Location at current variable is inlined.
861 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
862 LLVMContext &VMContext);
864 /// cleanseInlinedVariable - Remove inlined scope from the variable.
865 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
867 class DebugInfoFinder {
869 /// processModule - Process entire module and collect debug info
871 void processModule(const Module &M);
874 /// processType - Process DIType.
875 void processType(DIType DT);
877 /// processLexicalBlock - Process DILexicalBlock.
878 void processLexicalBlock(DILexicalBlock LB);
880 /// processSubprogram - Process DISubprogram.
881 void processSubprogram(DISubprogram SP);
883 /// processDeclare - Process DbgDeclareInst.
884 void processDeclare(const DbgDeclareInst *DDI);
886 /// processLocation - Process DILocation.
887 void processLocation(DILocation Loc);
889 /// addCompileUnit - Add compile unit into CUs.
890 bool addCompileUnit(DICompileUnit CU);
892 /// addGlobalVariable - Add global variable into GVs.
893 bool addGlobalVariable(DIGlobalVariable DIG);
895 // addSubprogram - Add subprogram into SPs.
896 bool addSubprogram(DISubprogram SP);
898 /// addType - Add type into Tys.
899 bool addType(DIType DT);
902 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
903 iterator compile_unit_begin() const { return CUs.begin(); }
904 iterator compile_unit_end() const { return CUs.end(); }
905 iterator subprogram_begin() const { return SPs.begin(); }
906 iterator subprogram_end() const { return SPs.end(); }
907 iterator global_variable_begin() const { return GVs.begin(); }
908 iterator global_variable_end() const { return GVs.end(); }
909 iterator type_begin() const { return TYs.begin(); }
910 iterator type_end() const { return TYs.end(); }
912 unsigned compile_unit_count() const { return CUs.size(); }
913 unsigned global_variable_count() const { return GVs.size(); }
914 unsigned subprogram_count() const { return SPs.size(); }
915 unsigned type_count() const { return TYs.size(); }
918 SmallVector<MDNode *, 8> CUs; // Compile Units
919 SmallVector<MDNode *, 8> SPs; // Subprograms
920 SmallVector<MDNode *, 8> GVs; // Global Variables;
921 SmallVector<MDNode *, 8> TYs; // Types
922 SmallPtrSet<MDNode *, 64> NodesSeen;
924 } // end namespace llvm