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,
68 const MDNode *DbgNode;
70 StringRef getStringField(unsigned Elt) const;
71 unsigned getUnsignedField(unsigned Elt) const {
72 return (unsigned)getUInt64Field(Elt);
74 uint64_t getUInt64Field(unsigned Elt) const;
75 int64_t getInt64Field(unsigned Elt) const;
76 DIDescriptor getDescriptorField(unsigned Elt) const;
78 template <typename DescTy>
79 DescTy getFieldAs(unsigned Elt) const {
80 return DescTy(getDescriptorField(Elt));
83 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
84 Constant *getConstantField(unsigned Elt) const;
85 Function *getFunctionField(unsigned Elt) const;
86 void replaceFunctionField(unsigned Elt, Function *F);
89 explicit DIDescriptor() : DbgNode(0) {}
90 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
91 explicit DIDescriptor(const DIFile F);
92 explicit DIDescriptor(const DISubprogram F);
93 explicit DIDescriptor(const DILexicalBlockFile F);
94 explicit DIDescriptor(const DILexicalBlock F);
95 explicit DIDescriptor(const DIVariable F);
96 explicit DIDescriptor(const DIType F);
98 bool Verify() const { return DbgNode != 0; }
100 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
101 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
103 unsigned getVersion() const {
104 return getUnsignedField(0) & LLVMDebugVersionMask;
107 unsigned getTag() const {
108 return getUnsignedField(0) & ~LLVMDebugVersionMask;
111 bool isDerivedType() const;
112 bool isCompositeType() const;
113 bool isBasicType() const;
114 bool isVariable() const;
115 bool isSubprogram() const;
116 bool isGlobalVariable() const;
117 bool isScope() const;
119 bool isCompileUnit() const;
120 bool isNameSpace() const;
121 bool isLexicalBlockFile() const;
122 bool isLexicalBlock() const;
123 bool isSubrange() const;
124 bool isEnumerator() const;
126 bool isGlobal() const;
127 bool isUnspecifiedParameter() const;
128 bool isTemplateTypeParameter() const;
129 bool isTemplateValueParameter() const;
130 bool isObjCProperty() const;
132 /// print - print descriptor.
133 void print(raw_ostream &OS) const;
135 /// dump - print descriptor to dbgs() with a newline.
139 /// DISubrange - This is used to represent ranges, for array bounds.
140 class DISubrange : public DIDescriptor {
141 friend class DIDescriptor;
142 void printInternal(raw_ostream &OS) const;
144 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
146 int64_t getLo() const { return getInt64Field(1); }
147 int64_t getCount() const { return getInt64Field(2); }
150 /// DIArray - This descriptor holds an array of descriptors.
151 class DIArray : public DIDescriptor {
153 explicit DIArray(const MDNode *N = 0)
156 unsigned getNumElements() const;
157 DIDescriptor getElement(unsigned Idx) const {
158 return getDescriptorField(Idx);
162 /// DIScope - A base class for various scopes.
163 class DIScope : public DIDescriptor {
165 friend class DIDescriptor;
166 void printInternal(raw_ostream &OS) const;
168 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
170 StringRef getFilename() const;
171 StringRef getDirectory() const;
174 /// DICompileUnit - A wrapper for a compile unit.
175 class DICompileUnit : public DIScope {
176 friend class DIDescriptor;
177 void printInternal(raw_ostream &OS) const;
179 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
181 unsigned getLanguage() const { return getUnsignedField(2); }
182 StringRef getFilename() const { return getStringField(3); }
183 StringRef getDirectory() const { return getStringField(4); }
184 StringRef getProducer() const { return getStringField(5); }
186 /// isMain - Each input file is encoded as a separate compile unit in LLVM
187 /// debugging information output. However, many target specific tool chains
188 /// prefer to encode only one compile unit in an object file. In this
189 /// situation, the LLVM code generator will include debugging information
190 /// entities in the compile unit that is marked as main compile unit. The
191 /// code generator accepts maximum one main compile unit per module. If a
192 /// module does not contain any main compile unit then the code generator
193 /// will emit multiple compile units in the output object file.
195 bool isMain() const { return getUnsignedField(6) != 0; }
196 bool isOptimized() const { return getUnsignedField(7) != 0; }
197 StringRef getFlags() const { return getStringField(8); }
198 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
200 DIArray getEnumTypes() const;
201 DIArray getRetainedTypes() const;
202 DIArray getSubprograms() const;
203 DIArray getGlobalVariables() const;
205 /// Verify - Verify that a compile unit is well formed.
209 /// DIFile - This is a wrapper for a file.
210 class DIFile : public DIScope {
211 friend class DIDescriptor;
212 void printInternal(raw_ostream &OS) const {} // FIXME: Output something?
214 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
215 if (DbgNode && !isFile())
218 StringRef getFilename() const { return getStringField(1); }
219 StringRef getDirectory() const { return getStringField(2); }
220 DICompileUnit getCompileUnit() const{
221 assert (getVersion() <= LLVMDebugVersion10 && "Invalid CompileUnit!");
222 return getFieldAs<DICompileUnit>(3);
226 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
227 /// FIXME: it seems strange that this doesn't have either a reference to the
228 /// type/precision or a file/line pair for location info.
229 class DIEnumerator : public DIDescriptor {
230 friend class DIDescriptor;
231 void printInternal(raw_ostream &OS) const;
233 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
235 StringRef getName() const { return getStringField(1); }
236 uint64_t getEnumValue() const { return getUInt64Field(2); }
239 /// DIType - This is a wrapper for a type.
240 /// FIXME: Types should be factored much better so that CV qualifiers and
241 /// others do not require a huge and empty descriptor full of zeros.
242 class DIType : public DIScope {
244 friend class DIDescriptor;
245 void printInternal(raw_ostream &OS) const;
246 // This ctor is used when the Tag has already been validated by a derived
248 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
250 /// Verify - Verify that a type descriptor is well formed.
252 explicit DIType(const MDNode *N);
255 DIScope getContext() const { return getFieldAs<DIScope>(1); }
256 StringRef getName() const { return getStringField(2); }
257 DICompileUnit getCompileUnit() const{
258 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
259 if (getVersion() == llvm::LLVMDebugVersion7)
260 return getFieldAs<DICompileUnit>(3);
262 return getFieldAs<DIFile>(3).getCompileUnit();
264 DIFile getFile() const { return getFieldAs<DIFile>(3); }
265 unsigned getLineNumber() const { return getUnsignedField(4); }
266 uint64_t getSizeInBits() const { return getUInt64Field(5); }
267 uint64_t getAlignInBits() const { return getUInt64Field(6); }
268 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
269 // carry this is just plain insane.
270 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
271 unsigned getFlags() const { return getUnsignedField(8); }
272 bool isPrivate() const {
273 return (getFlags() & FlagPrivate) != 0;
275 bool isProtected() const {
276 return (getFlags() & FlagProtected) != 0;
278 bool isForwardDecl() const {
279 return (getFlags() & FlagFwdDecl) != 0;
281 // isAppleBlock - Return true if this is the Apple Blocks extension.
282 bool isAppleBlockExtension() const {
283 return (getFlags() & FlagAppleBlock) != 0;
285 bool isBlockByrefStruct() const {
286 return (getFlags() & FlagBlockByrefStruct) != 0;
288 bool isVirtual() const {
289 return (getFlags() & FlagVirtual) != 0;
291 bool isArtificial() const {
292 return (getFlags() & FlagArtificial) != 0;
294 bool isObjectPointer() const {
295 return (getFlags() & FlagObjectPointer) != 0;
297 bool isObjcClassComplete() const {
298 return (getFlags() & FlagObjcClassComplete) != 0;
300 bool isVector() const {
301 return (getFlags() & FlagVector) != 0;
303 bool isValid() const {
304 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
306 StringRef getDirectory() const {
307 if (getVersion() == llvm::LLVMDebugVersion7)
308 return getCompileUnit().getDirectory();
310 return getFieldAs<DIFile>(3).getDirectory();
312 StringRef getFilename() const {
313 if (getVersion() == llvm::LLVMDebugVersion7)
314 return getCompileUnit().getFilename();
316 return getFieldAs<DIFile>(3).getFilename();
319 /// isUnsignedDIType - Return true if type encoding is unsigned.
320 bool isUnsignedDIType();
322 /// replaceAllUsesWith - Replace all uses of debug info referenced by
324 void replaceAllUsesWith(DIDescriptor &D);
325 void replaceAllUsesWith(MDNode *D);
328 /// DIBasicType - A basic type, like 'int' or 'float'.
329 class DIBasicType : public DIType {
331 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
333 unsigned getEncoding() const { return getUnsignedField(9); }
335 /// Verify - Verify that a basic type descriptor is well formed.
339 /// DIDerivedType - A simple derived type, like a const qualified type,
340 /// a typedef, a pointer or reference, etc.
341 class DIDerivedType : public DIType {
342 friend class DIDescriptor;
343 void printInternal(raw_ostream &OS) const;
345 explicit DIDerivedType(const MDNode *N, bool, bool)
346 : DIType(N, true, true) {}
348 explicit DIDerivedType(const MDNode *N = 0)
349 : DIType(N, true, true) {}
351 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
353 /// getOriginalTypeSize - If this type is derived from a base type then
354 /// return base type size.
355 uint64_t getOriginalTypeSize() const;
357 /// getObjCProperty - Return property node, if this ivar is
358 /// associated with one.
359 MDNode *getObjCProperty() const;
361 DIType getClassType() const {
362 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
363 return getFieldAs<DIType>(10);
366 StringRef getObjCPropertyName() const {
367 if (getVersion() > LLVMDebugVersion11)
369 return getStringField(10);
371 StringRef getObjCPropertyGetterName() const {
372 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
373 return getStringField(11);
375 StringRef getObjCPropertySetterName() const {
376 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
377 return getStringField(12);
379 bool isReadOnlyObjCProperty() {
380 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
381 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
383 bool isReadWriteObjCProperty() {
384 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
385 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
387 bool isAssignObjCProperty() {
388 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
389 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
391 bool isRetainObjCProperty() {
392 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
393 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
395 bool isCopyObjCProperty() {
396 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
397 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
399 bool isNonAtomicObjCProperty() {
400 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
401 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
404 /// Verify - Verify that a derived type descriptor is well formed.
408 /// DICompositeType - This descriptor holds a type that can refer to multiple
409 /// other types, like a function or struct.
410 /// FIXME: Why is this a DIDerivedType??
411 class DICompositeType : public DIDerivedType {
412 friend class DIDescriptor;
413 void printInternal(raw_ostream &OS) const;
415 explicit DICompositeType(const MDNode *N = 0)
416 : DIDerivedType(N, true, true) {
417 if (N && !isCompositeType())
421 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
422 unsigned getRunTimeLang() const { return getUnsignedField(11); }
423 DICompositeType getContainingType() const {
424 return getFieldAs<DICompositeType>(12);
426 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
428 /// Verify - Verify that a composite type descriptor is well formed.
432 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
433 class DITemplateTypeParameter : public DIDescriptor {
435 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
437 DIScope getContext() const { return getFieldAs<DIScope>(1); }
438 StringRef getName() const { return getStringField(2); }
439 DIType getType() const { return getFieldAs<DIType>(3); }
440 StringRef getFilename() const {
441 return getFieldAs<DIFile>(4).getFilename();
443 StringRef getDirectory() const {
444 return getFieldAs<DIFile>(4).getDirectory();
446 unsigned getLineNumber() const { return getUnsignedField(5); }
447 unsigned getColumnNumber() const { return getUnsignedField(6); }
450 /// DITemplateValueParameter - This is a wrapper for template value parameter.
451 class DITemplateValueParameter : public DIDescriptor {
453 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
455 DIScope getContext() const { return getFieldAs<DIScope>(1); }
456 StringRef getName() const { return getStringField(2); }
457 DIType getType() const { return getFieldAs<DIType>(3); }
458 uint64_t getValue() const { return getUInt64Field(4); }
459 StringRef getFilename() const {
460 return getFieldAs<DIFile>(5).getFilename();
462 StringRef getDirectory() const {
463 return getFieldAs<DIFile>(5).getDirectory();
465 unsigned getLineNumber() const { return getUnsignedField(6); }
466 unsigned getColumnNumber() const { return getUnsignedField(7); }
469 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
470 class DISubprogram : public DIScope {
471 friend class DIDescriptor;
472 void printInternal(raw_ostream &OS) const;
474 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
476 DIScope getContext() const { return getFieldAs<DIScope>(2); }
477 StringRef getName() const { return getStringField(3); }
478 StringRef getDisplayName() const { return getStringField(4); }
479 StringRef getLinkageName() const { return getStringField(5); }
480 DICompileUnit getCompileUnit() const{
481 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
482 if (getVersion() == llvm::LLVMDebugVersion7)
483 return getFieldAs<DICompileUnit>(6);
485 return getFieldAs<DIFile>(6).getCompileUnit();
487 unsigned getLineNumber() const { return getUnsignedField(7); }
488 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
490 /// getReturnTypeName - Subprogram return types are encoded either as
491 /// DIType or as DICompositeType.
492 StringRef getReturnTypeName() const {
493 DICompositeType DCT(getFieldAs<DICompositeType>(8));
495 DIArray A = DCT.getTypeArray();
496 DIType T(A.getElement(0));
499 DIType T(getFieldAs<DIType>(8));
503 /// isLocalToUnit - Return true if this subprogram is local to the current
504 /// compile unit, like 'static' in C.
505 unsigned isLocalToUnit() const { return getUnsignedField(9); }
506 unsigned isDefinition() const { return getUnsignedField(10); }
508 unsigned getVirtuality() const { return getUnsignedField(11); }
509 unsigned getVirtualIndex() const { return getUnsignedField(12); }
511 DICompositeType getContainingType() const {
512 return getFieldAs<DICompositeType>(13);
515 unsigned isArtificial() const {
516 if (getVersion() <= llvm::LLVMDebugVersion8)
517 return getUnsignedField(14);
518 return (getUnsignedField(14) & FlagArtificial) != 0;
520 /// isPrivate - Return true if this subprogram has "private"
521 /// access specifier.
522 bool isPrivate() const {
523 if (getVersion() <= llvm::LLVMDebugVersion8)
525 return (getUnsignedField(14) & FlagPrivate) != 0;
527 /// isProtected - Return true if this subprogram has "protected"
528 /// access specifier.
529 bool isProtected() const {
530 if (getVersion() <= llvm::LLVMDebugVersion8)
532 return (getUnsignedField(14) & FlagProtected) != 0;
534 /// isExplicit - Return true if this subprogram is marked as explicit.
535 bool isExplicit() const {
536 if (getVersion() <= llvm::LLVMDebugVersion8)
538 return (getUnsignedField(14) & FlagExplicit) != 0;
540 /// isPrototyped - Return true if this subprogram is prototyped.
541 bool isPrototyped() const {
542 if (getVersion() <= llvm::LLVMDebugVersion8)
544 return (getUnsignedField(14) & FlagPrototyped) != 0;
547 unsigned isOptimized() const;
549 StringRef getFilename() const {
550 if (getVersion() == llvm::LLVMDebugVersion7)
551 return getCompileUnit().getFilename();
553 return getFieldAs<DIFile>(6).getFilename();
556 StringRef getDirectory() const {
557 if (getVersion() == llvm::LLVMDebugVersion7)
558 return getCompileUnit().getFilename();
560 return getFieldAs<DIFile>(6).getDirectory();
563 /// getScopeLineNumber - Get the beginning of the scope of the
564 /// function, not necessarily where the name of the program
566 unsigned getScopeLineNumber() const { return getUnsignedField(20); }
568 /// Verify - Verify that a subprogram descriptor is well formed.
571 /// describes - Return true if this subprogram provides debugging
572 /// information for the function F.
573 bool describes(const Function *F);
575 Function *getFunction() const { return getFunctionField(16); }
576 void replaceFunction(Function *F) { replaceFunctionField(16, F); }
577 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
578 DISubprogram getFunctionDeclaration() const {
579 return getFieldAs<DISubprogram>(18);
581 MDNode *getVariablesNodes() const;
582 DIArray getVariables() const;
585 /// DIGlobalVariable - This is a wrapper for a global variable.
586 class DIGlobalVariable : public DIDescriptor {
587 friend class DIDescriptor;
588 void printInternal(raw_ostream &OS) const;
590 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
592 DIScope getContext() const { return getFieldAs<DIScope>(2); }
593 StringRef getName() const { return getStringField(3); }
594 StringRef getDisplayName() const { return getStringField(4); }
595 StringRef getLinkageName() const { return getStringField(5); }
596 DICompileUnit getCompileUnit() const{
597 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
598 if (getVersion() == llvm::LLVMDebugVersion7)
599 return getFieldAs<DICompileUnit>(6);
601 DIFile F = getFieldAs<DIFile>(6);
602 return F.getCompileUnit();
604 StringRef getFilename() const {
605 if (getVersion() <= llvm::LLVMDebugVersion10)
606 return getContext().getFilename();
607 return getFieldAs<DIFile>(6).getFilename();
609 StringRef getDirectory() const {
610 if (getVersion() <= llvm::LLVMDebugVersion10)
611 return getContext().getDirectory();
612 return getFieldAs<DIFile>(6).getDirectory();
616 unsigned getLineNumber() const { return getUnsignedField(7); }
617 DIType getType() const { return getFieldAs<DIType>(8); }
618 unsigned isLocalToUnit() const { return getUnsignedField(9); }
619 unsigned isDefinition() const { return getUnsignedField(10); }
621 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
622 Constant *getConstant() const { return getConstantField(11); }
624 /// Verify - Verify that a global variable descriptor is well formed.
628 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
630 class DIVariable : public DIDescriptor {
631 friend class DIDescriptor;
632 void printInternal(raw_ostream &OS) const;
634 explicit DIVariable(const MDNode *N = 0)
637 DIScope getContext() const { return getFieldAs<DIScope>(1); }
638 StringRef getName() const { return getStringField(2); }
639 DICompileUnit getCompileUnit() const {
640 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
641 if (getVersion() == llvm::LLVMDebugVersion7)
642 return getFieldAs<DICompileUnit>(3);
644 DIFile F = getFieldAs<DIFile>(3);
645 return F.getCompileUnit();
647 DIFile getFile() const { return getFieldAs<DIFile>(3); }
648 unsigned getLineNumber() const {
649 return (getUnsignedField(4) << 8) >> 8;
651 unsigned getArgNumber() const {
652 unsigned L = getUnsignedField(4);
655 DIType getType() const { return getFieldAs<DIType>(5); }
657 /// isArtificial - Return true if this variable is marked as "artificial".
658 bool isArtificial() const {
659 if (getVersion() <= llvm::LLVMDebugVersion8)
661 return (getUnsignedField(6) & FlagArtificial) != 0;
664 bool isObjectPointer() const {
665 return (getUnsignedField(6) & FlagObjectPointer) != 0;
668 /// getInlinedAt - If this variable is inlined then return inline location.
669 MDNode *getInlinedAt() const;
671 /// Verify - Verify that a variable descriptor is well formed.
674 /// HasComplexAddr - Return true if the variable has a complex address.
675 bool hasComplexAddress() const {
676 return getNumAddrElements() > 0;
679 unsigned getNumAddrElements() const;
681 uint64_t getAddrElement(unsigned Idx) const {
682 if (getVersion() <= llvm::LLVMDebugVersion8)
683 return getUInt64Field(Idx+6);
684 if (getVersion() == llvm::LLVMDebugVersion9)
685 return getUInt64Field(Idx+7);
686 return getUInt64Field(Idx+8);
689 /// isBlockByrefVariable - Return true if the variable was declared as
690 /// a "__block" variable (Apple Blocks).
691 bool isBlockByrefVariable() const {
692 return getType().isBlockByrefStruct();
695 /// isInlinedFnArgument - Return trule if this variable provides debugging
696 /// information for an inlined function arguments.
697 bool isInlinedFnArgument(const Function *CurFn);
699 void printExtendedName(raw_ostream &OS) const;
702 /// DILexicalBlock - This is a wrapper for a lexical block.
703 class DILexicalBlock : public DIScope {
705 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
706 DIScope getContext() const { return getFieldAs<DIScope>(1); }
707 unsigned getLineNumber() const { return getUnsignedField(2); }
708 unsigned getColumnNumber() const { return getUnsignedField(3); }
709 StringRef getDirectory() const {
710 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
711 return !dir.empty() ? dir : getContext().getDirectory();
713 StringRef getFilename() const {
714 StringRef filename = getFieldAs<DIFile>(4).getFilename();
715 return !filename.empty() ? filename : getContext().getFilename();
719 /// DILexicalBlockFile - This is a wrapper for a lexical block with
720 /// a filename change.
721 class DILexicalBlockFile : public DIScope {
723 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
724 DIScope getContext() const { return getScope().getContext(); }
725 unsigned getLineNumber() const { return getScope().getLineNumber(); }
726 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
727 StringRef getDirectory() const {
728 StringRef dir = getFieldAs<DIFile>(2).getDirectory();
729 return !dir.empty() ? dir : getContext().getDirectory();
731 StringRef getFilename() const {
732 StringRef filename = getFieldAs<DIFile>(2).getFilename();
733 assert(!filename.empty() && "Why'd you create this then?");
736 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
739 /// DINameSpace - A wrapper for a C++ style name space.
740 class DINameSpace : public DIScope {
742 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
743 DIScope getContext() const { return getFieldAs<DIScope>(1); }
744 StringRef getName() const { return getStringField(2); }
745 StringRef getDirectory() const {
746 return getFieldAs<DIFile>(3).getDirectory();
748 StringRef getFilename() const {
749 return getFieldAs<DIFile>(3).getFilename();
751 DICompileUnit getCompileUnit() const{
752 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
753 if (getVersion() == llvm::LLVMDebugVersion7)
754 return getFieldAs<DICompileUnit>(3);
756 return getFieldAs<DIFile>(3).getCompileUnit();
758 unsigned getLineNumber() const { return getUnsignedField(4); }
762 /// DILocation - This object holds location information. This object
763 /// is not associated with any DWARF tag.
764 class DILocation : public DIDescriptor {
766 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
768 unsigned getLineNumber() const { return getUnsignedField(0); }
769 unsigned getColumnNumber() const { return getUnsignedField(1); }
770 DIScope getScope() const { return getFieldAs<DIScope>(2); }
771 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
772 StringRef getFilename() const { return getScope().getFilename(); }
773 StringRef getDirectory() const { return getScope().getDirectory(); }
777 class DIObjCProperty : public DIDescriptor {
778 friend class DIDescriptor;
779 void printInternal(raw_ostream &OS) const;
781 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
783 StringRef getObjCPropertyName() const { return getStringField(1); }
784 DIFile getFile() const { return getFieldAs<DIFile>(2); }
785 unsigned getLineNumber() const { return getUnsignedField(3); }
787 StringRef getObjCPropertyGetterName() const {
788 return getStringField(4);
790 StringRef getObjCPropertySetterName() const {
791 return getStringField(5);
793 bool isReadOnlyObjCProperty() {
794 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
796 bool isReadWriteObjCProperty() {
797 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
799 bool isAssignObjCProperty() {
800 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
802 bool isRetainObjCProperty() {
803 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
805 bool isCopyObjCProperty() {
806 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
808 bool isNonAtomicObjCProperty() {
809 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
812 DIType getType() const { return getFieldAs<DIType>(7); }
814 /// Verify - Verify that a derived type descriptor is well formed.
818 /// getDISubprogram - Find subprogram that is enclosing this scope.
819 DISubprogram getDISubprogram(const MDNode *Scope);
821 /// getDICompositeType - Find underlying composite type.
822 DICompositeType getDICompositeType(DIType T);
824 /// isSubprogramContext - Return true if Context is either a subprogram
825 /// or another context nested inside a subprogram.
826 bool isSubprogramContext(const MDNode *Context);
828 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
829 /// to hold function specific information.
830 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
832 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
833 /// suitable to hold function specific information.
834 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
836 /// createInlinedVariable - Create a new inlined variable based on current
838 /// @param DV Current Variable.
839 /// @param InlinedScope Location at current variable is inlined.
840 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
841 LLVMContext &VMContext);
843 /// cleanseInlinedVariable - Remove inlined scope from the variable.
844 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
846 class DebugInfoFinder {
848 /// processModule - Process entire module and collect debug info
850 void processModule(const Module &M);
853 /// processType - Process DIType.
854 void processType(DIType DT);
856 /// processLexicalBlock - Process DILexicalBlock.
857 void processLexicalBlock(DILexicalBlock LB);
859 /// processSubprogram - Process DISubprogram.
860 void processSubprogram(DISubprogram SP);
862 /// processDeclare - Process DbgDeclareInst.
863 void processDeclare(const DbgDeclareInst *DDI);
865 /// processLocation - Process DILocation.
866 void processLocation(DILocation Loc);
868 /// addCompileUnit - Add compile unit into CUs.
869 bool addCompileUnit(DICompileUnit CU);
871 /// addGlobalVariable - Add global variable into GVs.
872 bool addGlobalVariable(DIGlobalVariable DIG);
874 // addSubprogram - Add subprogram into SPs.
875 bool addSubprogram(DISubprogram SP);
877 /// addType - Add type into Tys.
878 bool addType(DIType DT);
881 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
882 iterator compile_unit_begin() const { return CUs.begin(); }
883 iterator compile_unit_end() const { return CUs.end(); }
884 iterator subprogram_begin() const { return SPs.begin(); }
885 iterator subprogram_end() const { return SPs.end(); }
886 iterator global_variable_begin() const { return GVs.begin(); }
887 iterator global_variable_end() const { return GVs.end(); }
888 iterator type_begin() const { return TYs.begin(); }
889 iterator type_end() const { return TYs.end(); }
891 unsigned compile_unit_count() const { return CUs.size(); }
892 unsigned global_variable_count() const { return GVs.size(); }
893 unsigned subprogram_count() const { return SPs.size(); }
894 unsigned type_count() const { return TYs.size(); }
897 SmallVector<MDNode *, 8> CUs; // Compile Units
898 SmallVector<MDNode *, 8> SPs; // Subprograms
899 SmallVector<MDNode *, 8> GVs; // Global Variables;
900 SmallVector<MDNode *, 8> TYs; // Types
901 SmallPtrSet<MDNode *, 64> NodesSeen;
903 } // end namespace llvm