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_ANALYSIS_DEBUGINFO_H
18 #define LLVM_ANALYSIS_DEBUGINFO_H
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/SmallPtrSet.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
66 const MDNode *DbgNode;
68 StringRef getStringField(unsigned Elt) const;
69 unsigned getUnsignedField(unsigned Elt) const {
70 return (unsigned)getUInt64Field(Elt);
72 uint64_t getUInt64Field(unsigned Elt) const;
73 DIDescriptor getDescriptorField(unsigned Elt) const;
75 template <typename DescTy>
76 DescTy getFieldAs(unsigned Elt) const {
77 return DescTy(getDescriptorField(Elt));
80 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
81 Constant *getConstantField(unsigned Elt) const;
82 Function *getFunctionField(unsigned Elt) const;
85 explicit DIDescriptor() : DbgNode(0) {}
86 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
87 explicit DIDescriptor(const DIFile F);
88 explicit DIDescriptor(const DISubprogram F);
89 explicit DIDescriptor(const DILexicalBlockFile F);
90 explicit DIDescriptor(const DILexicalBlock F);
91 explicit DIDescriptor(const DIVariable F);
92 explicit DIDescriptor(const DIType F);
94 bool Verify() const { return DbgNode != 0; }
96 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
97 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
99 unsigned getVersion() const {
100 return getUnsignedField(0) & LLVMDebugVersionMask;
103 unsigned getTag() const {
104 return getUnsignedField(0) & ~LLVMDebugVersionMask;
107 bool isDerivedType() const;
108 bool isCompositeType() const;
109 bool isBasicType() const;
110 bool isVariable() const;
111 bool isSubprogram() const;
112 bool isGlobalVariable() const;
113 bool isScope() const;
115 bool isCompileUnit() const;
116 bool isNameSpace() const;
117 bool isLexicalBlockFile() const;
118 bool isLexicalBlock() const;
119 bool isSubrange() const;
120 bool isEnumerator() const;
122 bool isGlobal() const;
123 bool isUnspecifiedParameter() const;
124 bool isTemplateTypeParameter() const;
125 bool isTemplateValueParameter() const;
126 bool isObjCProperty() const;
128 /// print - print descriptor.
129 void print(raw_ostream &OS) const;
131 /// dump - print descriptor to dbgs() with a newline.
135 /// DISubrange - This is used to represent ranges, for array bounds.
136 class DISubrange : public DIDescriptor {
137 friend class DIDescriptor;
138 void printInternal(raw_ostream &OS) const;
140 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
142 uint64_t getLo() const { return getUInt64Field(1); }
143 uint64_t getHi() const { return getUInt64Field(2); }
146 /// DIArray - This descriptor holds an array of descriptors.
147 class DIArray : public DIDescriptor {
149 explicit DIArray(const MDNode *N = 0)
152 unsigned getNumElements() const;
153 DIDescriptor getElement(unsigned Idx) const {
154 return getDescriptorField(Idx);
158 /// DIScope - A base class for various scopes.
159 class DIScope : public DIDescriptor {
160 virtual void anchor();
162 friend class DIDescriptor;
163 void printInternal(raw_ostream &OS) const;
165 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
166 virtual ~DIScope() {}
168 StringRef getFilename() const;
169 StringRef getDirectory() const;
172 /// DICompileUnit - A wrapper for a compile unit.
173 class DICompileUnit : public DIScope {
174 virtual void anchor();
175 friend class DIDescriptor;
176 void printInternal(raw_ostream &OS) const;
178 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
180 unsigned getLanguage() const { return getUnsignedField(2); }
181 StringRef getFilename() const { return getStringField(3); }
182 StringRef getDirectory() const { return getStringField(4); }
183 StringRef getProducer() const { return getStringField(5); }
185 /// isMain - Each input file is encoded as a separate compile unit in LLVM
186 /// debugging information output. However, many target specific tool chains
187 /// prefer to encode only one compile unit in an object file. In this
188 /// situation, the LLVM code generator will include debugging information
189 /// entities in the compile unit that is marked as main compile unit. The
190 /// code generator accepts maximum one main compile unit per module. If a
191 /// module does not contain any main compile unit then the code generator
192 /// will emit multiple compile units in the output object file.
194 bool isMain() const { return getUnsignedField(6) != 0; }
195 bool isOptimized() const { return getUnsignedField(7) != 0; }
196 StringRef getFlags() const { return getStringField(8); }
197 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
199 DIArray getEnumTypes() const;
200 DIArray getRetainedTypes() const;
201 DIArray getSubprograms() const;
202 DIArray getGlobalVariables() const;
204 /// Verify - Verify that a compile unit is well formed.
208 /// DIFile - This is a wrapper for a file.
209 class DIFile : public DIScope {
210 virtual void anchor();
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 {
243 virtual void anchor();
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);
257 DIScope getContext() const { return getFieldAs<DIScope>(1); }
258 StringRef getName() const { return getStringField(2); }
259 DICompileUnit getCompileUnit() const{
260 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
261 if (getVersion() == llvm::LLVMDebugVersion7)
262 return getFieldAs<DICompileUnit>(3);
264 return getFieldAs<DIFile>(3).getCompileUnit();
266 DIFile getFile() const { return getFieldAs<DIFile>(3); }
267 unsigned getLineNumber() const { return getUnsignedField(4); }
268 uint64_t getSizeInBits() const { return getUInt64Field(5); }
269 uint64_t getAlignInBits() const { return getUInt64Field(6); }
270 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
271 // carry this is just plain insane.
272 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
273 unsigned getFlags() const { return getUnsignedField(8); }
274 bool isPrivate() const {
275 return (getFlags() & FlagPrivate) != 0;
277 bool isProtected() const {
278 return (getFlags() & FlagProtected) != 0;
280 bool isForwardDecl() const {
281 return (getFlags() & FlagFwdDecl) != 0;
283 // isAppleBlock - Return true if this is the Apple Blocks extension.
284 bool isAppleBlockExtension() const {
285 return (getFlags() & FlagAppleBlock) != 0;
287 bool isBlockByrefStruct() const {
288 return (getFlags() & FlagBlockByrefStruct) != 0;
290 bool isVirtual() const {
291 return (getFlags() & FlagVirtual) != 0;
293 bool isArtificial() const {
294 return (getFlags() & FlagArtificial) != 0;
296 bool isObjcClassComplete() const {
297 return (getFlags() & FlagObjcClassComplete) != 0;
299 bool isValid() const {
300 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
302 StringRef getDirectory() const {
303 if (getVersion() == llvm::LLVMDebugVersion7)
304 return getCompileUnit().getDirectory();
306 return getFieldAs<DIFile>(3).getDirectory();
308 StringRef getFilename() const {
309 if (getVersion() == llvm::LLVMDebugVersion7)
310 return getCompileUnit().getFilename();
312 return getFieldAs<DIFile>(3).getFilename();
315 /// isUnsignedDIType - Return true if type encoding is unsigned.
316 bool isUnsignedDIType();
318 /// replaceAllUsesWith - Replace all uses of debug info referenced by
320 void replaceAllUsesWith(DIDescriptor &D);
321 void replaceAllUsesWith(MDNode *D);
324 /// DIBasicType - A basic type, like 'int' or 'float'.
325 class DIBasicType : public DIType {
326 virtual void anchor();
328 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
330 unsigned getEncoding() const { return getUnsignedField(9); }
332 /// Verify - Verify that a basic type descriptor is well formed.
336 /// DIDerivedType - A simple derived type, like a const qualified type,
337 /// a typedef, a pointer or reference, etc.
338 class DIDerivedType : public DIType {
339 virtual void anchor();
340 friend class DIDescriptor;
341 void printInternal(raw_ostream &OS) const;
343 explicit DIDerivedType(const MDNode *N, bool, bool)
344 : DIType(N, true, true) {}
346 explicit DIDerivedType(const MDNode *N = 0)
347 : DIType(N, true, true) {}
349 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
351 /// getOriginalTypeSize - If this type is derived from a base type then
352 /// return base type size.
353 uint64_t getOriginalTypeSize() const;
355 /// getObjCProperty - Return property node, if this ivar is
356 /// associated with one.
357 MDNode *getObjCProperty() const;
359 StringRef getObjCPropertyName() const {
360 if (getVersion() > LLVMDebugVersion11)
362 return getStringField(10);
364 StringRef getObjCPropertyGetterName() const {
365 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
366 return getStringField(11);
368 StringRef getObjCPropertySetterName() const {
369 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
370 return getStringField(12);
372 bool isReadOnlyObjCProperty() {
373 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
374 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
376 bool isReadWriteObjCProperty() {
377 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
378 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
380 bool isAssignObjCProperty() {
381 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
382 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
384 bool isRetainObjCProperty() {
385 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
386 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
388 bool isCopyObjCProperty() {
389 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
390 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
392 bool isNonAtomicObjCProperty() {
393 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
394 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
397 /// Verify - Verify that a derived type descriptor is well formed.
401 /// DICompositeType - This descriptor holds a type that can refer to multiple
402 /// other types, like a function or struct.
403 /// FIXME: Why is this a DIDerivedType??
404 class DICompositeType : public DIDerivedType {
405 virtual void anchor();
406 friend class DIDescriptor;
407 void printInternal(raw_ostream &OS) const;
409 explicit DICompositeType(const MDNode *N = 0)
410 : DIDerivedType(N, true, true) {
411 if (N && !isCompositeType())
415 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
416 unsigned getRunTimeLang() const { return getUnsignedField(11); }
417 DICompositeType getContainingType() const {
418 return getFieldAs<DICompositeType>(12);
420 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
422 /// Verify - Verify that a composite type descriptor is well formed.
426 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
427 class DITemplateTypeParameter : public DIDescriptor {
429 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
431 DIScope getContext() const { return getFieldAs<DIScope>(1); }
432 StringRef getName() const { return getStringField(2); }
433 DIType getType() const { return getFieldAs<DIType>(3); }
434 StringRef getFilename() const {
435 return getFieldAs<DIFile>(4).getFilename();
437 StringRef getDirectory() const {
438 return getFieldAs<DIFile>(4).getDirectory();
440 unsigned getLineNumber() const { return getUnsignedField(5); }
441 unsigned getColumnNumber() const { return getUnsignedField(6); }
444 /// DITemplateValueParameter - This is a wrapper for template value parameter.
445 class DITemplateValueParameter : public DIDescriptor {
447 explicit DITemplateValueParameter(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 uint64_t getValue() const { return getUInt64Field(4); }
453 StringRef getFilename() const {
454 return getFieldAs<DIFile>(5).getFilename();
456 StringRef getDirectory() const {
457 return getFieldAs<DIFile>(5).getDirectory();
459 unsigned getLineNumber() const { return getUnsignedField(6); }
460 unsigned getColumnNumber() const { return getUnsignedField(7); }
463 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
464 class DISubprogram : public DIScope {
465 virtual void anchor();
466 friend class DIDescriptor;
467 void printInternal(raw_ostream &OS) const;
469 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
471 DIScope getContext() const { return getFieldAs<DIScope>(2); }
472 StringRef getName() const { return getStringField(3); }
473 StringRef getDisplayName() const { return getStringField(4); }
474 StringRef getLinkageName() const { return getStringField(5); }
475 DICompileUnit getCompileUnit() const{
476 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
477 if (getVersion() == llvm::LLVMDebugVersion7)
478 return getFieldAs<DICompileUnit>(6);
480 return getFieldAs<DIFile>(6).getCompileUnit();
482 unsigned getLineNumber() const { return getUnsignedField(7); }
483 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
485 /// getReturnTypeName - Subprogram return types are encoded either as
486 /// DIType or as DICompositeType.
487 StringRef getReturnTypeName() const {
488 DICompositeType DCT(getFieldAs<DICompositeType>(8));
490 DIArray A = DCT.getTypeArray();
491 DIType T(A.getElement(0));
494 DIType T(getFieldAs<DIType>(8));
498 /// isLocalToUnit - Return true if this subprogram is local to the current
499 /// compile unit, like 'static' in C.
500 unsigned isLocalToUnit() const { return getUnsignedField(9); }
501 unsigned isDefinition() const { return getUnsignedField(10); }
503 unsigned getVirtuality() const { return getUnsignedField(11); }
504 unsigned getVirtualIndex() const { return getUnsignedField(12); }
506 DICompositeType getContainingType() const {
507 return getFieldAs<DICompositeType>(13);
510 unsigned isArtificial() const {
511 if (getVersion() <= llvm::LLVMDebugVersion8)
512 return getUnsignedField(14);
513 return (getUnsignedField(14) & FlagArtificial) != 0;
515 /// isPrivate - Return true if this subprogram has "private"
516 /// access specifier.
517 bool isPrivate() const {
518 if (getVersion() <= llvm::LLVMDebugVersion8)
520 return (getUnsignedField(14) & FlagPrivate) != 0;
522 /// isProtected - Return true if this subprogram has "protected"
523 /// access specifier.
524 bool isProtected() const {
525 if (getVersion() <= llvm::LLVMDebugVersion8)
527 return (getUnsignedField(14) & FlagProtected) != 0;
529 /// isExplicit - Return true if this subprogram is marked as explicit.
530 bool isExplicit() const {
531 if (getVersion() <= llvm::LLVMDebugVersion8)
533 return (getUnsignedField(14) & FlagExplicit) != 0;
535 /// isPrototyped - Return true if this subprogram is prototyped.
536 bool isPrototyped() const {
537 if (getVersion() <= llvm::LLVMDebugVersion8)
539 return (getUnsignedField(14) & FlagPrototyped) != 0;
542 unsigned isOptimized() const;
544 StringRef getFilename() const {
545 if (getVersion() == llvm::LLVMDebugVersion7)
546 return getCompileUnit().getFilename();
548 return getFieldAs<DIFile>(6).getFilename();
551 StringRef getDirectory() const {
552 if (getVersion() == llvm::LLVMDebugVersion7)
553 return getCompileUnit().getFilename();
555 return getFieldAs<DIFile>(6).getDirectory();
558 /// getScopeLineNumber - Get the beginning of the scope of the
559 /// function, not necessarily where the name of the program
561 unsigned getScopeLineNumber() const { return getUnsignedField(20); }
563 /// Verify - Verify that a subprogram descriptor is well formed.
566 /// describes - Return true if this subprogram provides debugging
567 /// information for the function F.
568 bool describes(const Function *F);
570 Function *getFunction() const { return getFunctionField(16); }
571 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
572 DISubprogram getFunctionDeclaration() const {
573 return getFieldAs<DISubprogram>(18);
575 MDNode *getVariablesNodes() const;
576 DIArray getVariables() const;
579 /// DIGlobalVariable - This is a wrapper for a global variable.
580 class DIGlobalVariable : public DIDescriptor {
581 friend class DIDescriptor;
582 void printInternal(raw_ostream &OS) const;
584 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
586 DIScope getContext() const { return getFieldAs<DIScope>(2); }
587 StringRef getName() const { return getStringField(3); }
588 StringRef getDisplayName() const { return getStringField(4); }
589 StringRef getLinkageName() const { return getStringField(5); }
590 DICompileUnit getCompileUnit() const{
591 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
592 if (getVersion() == llvm::LLVMDebugVersion7)
593 return getFieldAs<DICompileUnit>(6);
595 DIFile F = getFieldAs<DIFile>(6);
596 return F.getCompileUnit();
598 StringRef getFilename() const {
599 if (getVersion() <= llvm::LLVMDebugVersion10)
600 return getContext().getFilename();
601 return getFieldAs<DIFile>(6).getFilename();
603 StringRef getDirectory() const {
604 if (getVersion() <= llvm::LLVMDebugVersion10)
605 return getContext().getDirectory();
606 return getFieldAs<DIFile>(6).getDirectory();
610 unsigned getLineNumber() const { return getUnsignedField(7); }
611 DIType getType() const { return getFieldAs<DIType>(8); }
612 unsigned isLocalToUnit() const { return getUnsignedField(9); }
613 unsigned isDefinition() const { return getUnsignedField(10); }
615 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
616 Constant *getConstant() const { return getConstantField(11); }
618 /// Verify - Verify that a global variable descriptor is well formed.
622 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
624 class DIVariable : public DIDescriptor {
625 friend class DIDescriptor;
626 void printInternal(raw_ostream &OS) const;
628 explicit DIVariable(const MDNode *N = 0)
631 DIScope getContext() const { return getFieldAs<DIScope>(1); }
632 StringRef getName() const { return getStringField(2); }
633 DICompileUnit getCompileUnit() const {
634 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
635 if (getVersion() == llvm::LLVMDebugVersion7)
636 return getFieldAs<DICompileUnit>(3);
638 DIFile F = getFieldAs<DIFile>(3);
639 return F.getCompileUnit();
641 unsigned getLineNumber() const {
642 return (getUnsignedField(4) << 8) >> 8;
644 unsigned getArgNumber() const {
645 unsigned L = getUnsignedField(4);
648 DIType getType() const { return getFieldAs<DIType>(5); }
650 /// isArtificial - Return true if this variable is marked as "artificial".
651 bool isArtificial() const {
652 if (getVersion() <= llvm::LLVMDebugVersion8)
654 return (getUnsignedField(6) & FlagArtificial) != 0;
657 /// getInlinedAt - If this variable is inlined then return inline location.
658 MDNode *getInlinedAt() const;
660 /// Verify - Verify that a variable descriptor is well formed.
663 /// HasComplexAddr - Return true if the variable has a complex address.
664 bool hasComplexAddress() const {
665 return getNumAddrElements() > 0;
668 unsigned getNumAddrElements() const;
670 uint64_t getAddrElement(unsigned Idx) const {
671 if (getVersion() <= llvm::LLVMDebugVersion8)
672 return getUInt64Field(Idx+6);
673 if (getVersion() == llvm::LLVMDebugVersion9)
674 return getUInt64Field(Idx+7);
675 return getUInt64Field(Idx+8);
678 /// isBlockByrefVariable - Return true if the variable was declared as
679 /// a "__block" variable (Apple Blocks).
680 bool isBlockByrefVariable() const {
681 return getType().isBlockByrefStruct();
684 /// isInlinedFnArgument - Return trule if this variable provides debugging
685 /// information for an inlined function arguments.
686 bool isInlinedFnArgument(const Function *CurFn);
688 void printExtendedName(raw_ostream &OS) const;
691 /// DILexicalBlock - This is a wrapper for a lexical block.
692 class DILexicalBlock : public DIScope {
693 virtual void anchor();
695 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
696 DIScope getContext() const { return getFieldAs<DIScope>(1); }
697 unsigned getLineNumber() const { return getUnsignedField(2); }
698 unsigned getColumnNumber() const { return getUnsignedField(3); }
699 StringRef getDirectory() const {
700 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
701 return !dir.empty() ? dir : getContext().getDirectory();
703 StringRef getFilename() const {
704 StringRef filename = getFieldAs<DIFile>(4).getFilename();
705 return !filename.empty() ? filename : getContext().getFilename();
709 /// DILexicalBlockFile - This is a wrapper for a lexical block with
710 /// a filename change.
711 class DILexicalBlockFile : public DIScope {
712 virtual void anchor();
714 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
715 DIScope getContext() const { return getScope().getContext(); }
716 unsigned getLineNumber() const { return getScope().getLineNumber(); }
717 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
718 StringRef getDirectory() const {
719 StringRef dir = getFieldAs<DIFile>(2).getDirectory();
720 return !dir.empty() ? dir : getContext().getDirectory();
722 StringRef getFilename() const {
723 StringRef filename = getFieldAs<DIFile>(2).getFilename();
724 assert(!filename.empty() && "Why'd you create this then?");
727 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
730 /// DINameSpace - A wrapper for a C++ style name space.
731 class DINameSpace : public DIScope {
732 virtual void anchor();
734 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
735 DIScope getContext() const { return getFieldAs<DIScope>(1); }
736 StringRef getName() const { return getStringField(2); }
737 StringRef getDirectory() const {
738 return getFieldAs<DIFile>(3).getDirectory();
740 StringRef getFilename() const {
741 return getFieldAs<DIFile>(3).getFilename();
743 DICompileUnit getCompileUnit() const{
744 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
745 if (getVersion() == llvm::LLVMDebugVersion7)
746 return getFieldAs<DICompileUnit>(3);
748 return getFieldAs<DIFile>(3).getCompileUnit();
750 unsigned getLineNumber() const { return getUnsignedField(4); }
754 /// DILocation - This object holds location information. This object
755 /// is not associated with any DWARF tag.
756 class DILocation : public DIDescriptor {
758 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
760 unsigned getLineNumber() const { return getUnsignedField(0); }
761 unsigned getColumnNumber() const { return getUnsignedField(1); }
762 DIScope getScope() const { return getFieldAs<DIScope>(2); }
763 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
764 StringRef getFilename() const { return getScope().getFilename(); }
765 StringRef getDirectory() const { return getScope().getDirectory(); }
769 class DIObjCProperty : public DIDescriptor {
771 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
773 StringRef getObjCPropertyName() const { return getStringField(1); }
774 DIFile getFile() const { return getFieldAs<DIFile>(2); }
775 unsigned getLineNumber() const { return getUnsignedField(3); }
777 StringRef getObjCPropertyGetterName() const {
778 return getStringField(4);
780 StringRef getObjCPropertySetterName() const {
781 return getStringField(5);
783 bool isReadOnlyObjCProperty() {
784 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
786 bool isReadWriteObjCProperty() {
787 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
789 bool isAssignObjCProperty() {
790 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
792 bool isRetainObjCProperty() {
793 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
795 bool isCopyObjCProperty() {
796 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
798 bool isNonAtomicObjCProperty() {
799 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
802 DIType getType() const { return getFieldAs<DIType>(7); }
804 /// Verify - Verify that a derived type descriptor is well formed.
808 /// getDISubprogram - Find subprogram that is enclosing this scope.
809 DISubprogram getDISubprogram(const MDNode *Scope);
811 /// getDICompositeType - Find underlying composite type.
812 DICompositeType getDICompositeType(DIType T);
814 /// isSubprogramContext - Return true if Context is either a subprogram
815 /// or another context nested inside a subprogram.
816 bool isSubprogramContext(const MDNode *Context);
818 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
819 /// to hold function specific information.
820 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
822 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
823 /// suitable to hold function specific information.
824 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
826 /// createInlinedVariable - Create a new inlined variable based on current
828 /// @param DV Current Variable.
829 /// @param InlinedScope Location at current variable is inlined.
830 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
831 LLVMContext &VMContext);
833 /// cleanseInlinedVariable - Remove inlined scope from the variable.
834 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
836 class DebugInfoFinder {
838 /// processModule - Process entire module and collect debug info
840 void processModule(Module &M);
843 /// processType - Process DIType.
844 void processType(DIType DT);
846 /// processLexicalBlock - Process DILexicalBlock.
847 void processLexicalBlock(DILexicalBlock LB);
849 /// processSubprogram - Process DISubprogram.
850 void processSubprogram(DISubprogram SP);
852 /// processDeclare - Process DbgDeclareInst.
853 void processDeclare(DbgDeclareInst *DDI);
855 /// processLocation - Process DILocation.
856 void processLocation(DILocation Loc);
858 /// addCompileUnit - Add compile unit into CUs.
859 bool addCompileUnit(DICompileUnit CU);
861 /// addGlobalVariable - Add global variable into GVs.
862 bool addGlobalVariable(DIGlobalVariable DIG);
864 // addSubprogram - Add subprogram into SPs.
865 bool addSubprogram(DISubprogram SP);
867 /// addType - Add type into Tys.
868 bool addType(DIType DT);
871 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
872 iterator compile_unit_begin() const { return CUs.begin(); }
873 iterator compile_unit_end() const { return CUs.end(); }
874 iterator subprogram_begin() const { return SPs.begin(); }
875 iterator subprogram_end() const { return SPs.end(); }
876 iterator global_variable_begin() const { return GVs.begin(); }
877 iterator global_variable_end() const { return GVs.end(); }
878 iterator type_begin() const { return TYs.begin(); }
879 iterator type_end() const { return TYs.end(); }
881 unsigned compile_unit_count() const { return CUs.size(); }
882 unsigned global_variable_count() const { return GVs.size(); }
883 unsigned subprogram_count() const { return SPs.size(); }
884 unsigned type_count() const { return TYs.size(); }
887 SmallVector<MDNode *, 8> CUs; // Compile Units
888 SmallVector<MDNode *, 8> SPs; // Subprograms
889 SmallVector<MDNode *, 8> GVs; // Global Variables;
890 SmallVector<MDNode *, 8> TYs; // Types
891 SmallPtrSet<MDNode *, 64> NodesSeen;
893 } // end namespace llvm