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 underly MDNode may
50 /// 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 /// print - print descriptor.
108 void print(raw_ostream &OS) const;
110 /// dump - print descriptor to dbgs() with a newline.
113 bool isDerivedType() const;
114 bool isCompositeType() const;
115 bool isBasicType() const;
116 bool isVariable() const;
117 bool isSubprogram() const;
118 bool isGlobalVariable() const;
119 bool isScope() const;
121 bool isCompileUnit() const;
122 bool isNameSpace() const;
123 bool isLexicalBlockFile() const;
124 bool isLexicalBlock() const;
125 bool isSubrange() const;
126 bool isEnumerator() const;
128 bool isGlobal() const;
129 bool isUnspecifiedParameter() const;
130 bool isTemplateTypeParameter() const;
131 bool isTemplateValueParameter() const;
132 bool isObjCProperty() const;
135 /// DISubrange - This is used to represent ranges, for array bounds.
136 class DISubrange : public DIDescriptor {
138 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
140 uint64_t getLo() const { return getUInt64Field(1); }
141 uint64_t getHi() const { return getUInt64Field(2); }
144 /// DIArray - This descriptor holds an array of descriptors.
145 class DIArray : public DIDescriptor {
147 explicit DIArray(const MDNode *N = 0)
150 unsigned getNumElements() const;
151 DIDescriptor getElement(unsigned Idx) const {
152 return getDescriptorField(Idx);
156 /// DIScope - A base class for various scopes.
157 class DIScope : public DIDescriptor {
158 virtual void anchor();
160 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
161 virtual ~DIScope() {}
163 StringRef getFilename() const;
164 StringRef getDirectory() const;
167 /// DICompileUnit - A wrapper for a compile unit.
168 class DICompileUnit : public DIScope {
169 virtual void anchor();
171 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
173 unsigned getLanguage() const { return getUnsignedField(2); }
174 StringRef getFilename() const { return getStringField(3); }
175 StringRef getDirectory() const { return getStringField(4); }
176 StringRef getProducer() const { return getStringField(5); }
178 /// isMain - Each input file is encoded as a separate compile unit in LLVM
179 /// debugging information output. However, many target specific tool chains
180 /// prefer to encode only one compile unit in an object file. In this
181 /// situation, the LLVM code generator will include debugging information
182 /// entities in the compile unit that is marked as main compile unit. The
183 /// code generator accepts maximum one main compile unit per module. If a
184 /// module does not contain any main compile unit then the code generator
185 /// will emit multiple compile units in the output object file.
187 bool isMain() const { return getUnsignedField(6) != 0; }
188 bool isOptimized() const { return getUnsignedField(7) != 0; }
189 StringRef getFlags() const { return getStringField(8); }
190 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
192 DIArray getEnumTypes() const;
193 DIArray getRetainedTypes() const;
194 DIArray getSubprograms() const;
195 DIArray getGlobalVariables() const;
197 /// Verify - Verify that a compile unit is well formed.
200 /// print - print compile unit.
201 void print(raw_ostream &OS) const;
203 /// dump - print compile unit to dbgs() with a newline.
207 /// DIFile - This is a wrapper for a file.
208 class DIFile : public DIScope {
209 virtual void anchor();
211 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
212 if (DbgNode && !isFile())
215 StringRef getFilename() const { return getStringField(1); }
216 StringRef getDirectory() const { return getStringField(2); }
217 DICompileUnit getCompileUnit() const{
218 assert (getVersion() <= LLVMDebugVersion10 && "Invalid CompileUnit!");
219 return getFieldAs<DICompileUnit>(3);
223 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
224 /// FIXME: it seems strange that this doesn't have either a reference to the
225 /// type/precision or a file/line pair for location info.
226 class DIEnumerator : public DIDescriptor {
228 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
230 StringRef getName() const { return getStringField(1); }
231 uint64_t getEnumValue() const { return getUInt64Field(2); }
234 /// DIType - This is a wrapper for a type.
235 /// FIXME: Types should be factored much better so that CV qualifiers and
236 /// others do not require a huge and empty descriptor full of zeros.
237 class DIType : public DIScope {
238 virtual void anchor();
240 // This ctor is used when the Tag has already been validated by a derived
242 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
246 /// Verify - Verify that a type descriptor is well formed.
248 explicit DIType(const MDNode *N);
252 DIScope getContext() const { return getFieldAs<DIScope>(1); }
253 StringRef getName() const { return getStringField(2); }
254 DICompileUnit getCompileUnit() const{
255 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
256 if (getVersion() == llvm::LLVMDebugVersion7)
257 return getFieldAs<DICompileUnit>(3);
259 return getFieldAs<DIFile>(3).getCompileUnit();
261 DIFile getFile() const { return getFieldAs<DIFile>(3); }
262 unsigned getLineNumber() const { return getUnsignedField(4); }
263 uint64_t getSizeInBits() const { return getUInt64Field(5); }
264 uint64_t getAlignInBits() const { return getUInt64Field(6); }
265 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
266 // carry this is just plain insane.
267 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
268 unsigned getFlags() const { return getUnsignedField(8); }
269 bool isPrivate() const {
270 return (getFlags() & FlagPrivate) != 0;
272 bool isProtected() const {
273 return (getFlags() & FlagProtected) != 0;
275 bool isForwardDecl() const {
276 return (getFlags() & FlagFwdDecl) != 0;
278 // isAppleBlock - Return true if this is the Apple Blocks extension.
279 bool isAppleBlockExtension() const {
280 return (getFlags() & FlagAppleBlock) != 0;
282 bool isBlockByrefStruct() const {
283 return (getFlags() & FlagBlockByrefStruct) != 0;
285 bool isVirtual() const {
286 return (getFlags() & FlagVirtual) != 0;
288 bool isArtificial() const {
289 return (getFlags() & FlagArtificial) != 0;
291 bool isObjcClassComplete() const {
292 return (getFlags() & FlagObjcClassComplete) != 0;
294 bool isValid() const {
295 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
297 StringRef getDirectory() const {
298 if (getVersion() == llvm::LLVMDebugVersion7)
299 return getCompileUnit().getDirectory();
301 return getFieldAs<DIFile>(3).getDirectory();
303 StringRef getFilename() const {
304 if (getVersion() == llvm::LLVMDebugVersion7)
305 return getCompileUnit().getFilename();
307 return getFieldAs<DIFile>(3).getFilename();
310 /// isUnsignedDIType - Return true if type encoding is unsigned.
311 bool isUnsignedDIType();
313 /// replaceAllUsesWith - Replace all uses of debug info referenced by
315 void replaceAllUsesWith(DIDescriptor &D);
316 void replaceAllUsesWith(MDNode *D);
318 /// print - print type.
319 void print(raw_ostream &OS) const;
321 /// dump - print type to dbgs() with a newline.
325 /// DIBasicType - A basic type, like 'int' or 'float'.
326 class DIBasicType : public DIType {
327 virtual void anchor();
329 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
331 unsigned getEncoding() const { return getUnsignedField(9); }
333 /// Verify - Verify that a basic type descriptor is well formed.
336 /// print - print basic type.
337 void print(raw_ostream &OS) const;
339 /// dump - print basic type to dbgs() with a newline.
343 /// DIDerivedType - A simple derived type, like a const qualified type,
344 /// a typedef, a pointer or reference, etc.
345 class DIDerivedType : public DIType {
346 virtual void anchor();
348 explicit DIDerivedType(const MDNode *N, bool, bool)
349 : DIType(N, true, true) {}
351 explicit DIDerivedType(const MDNode *N = 0)
352 : DIType(N, true, true) {}
354 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
356 /// getOriginalTypeSize - If this type is derived from a base type then
357 /// return base type size.
358 uint64_t getOriginalTypeSize() const;
360 /// getObjCProperty - Return property node, if this ivar is
361 /// associated with one.
362 MDNode *getObjCProperty() const;
364 StringRef getObjCPropertyName() const {
365 if (getVersion() > LLVMDebugVersion11)
367 return getStringField(10);
369 StringRef getObjCPropertyGetterName() const {
370 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
371 return getStringField(11);
373 StringRef getObjCPropertySetterName() const {
374 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
375 return getStringField(12);
377 bool isReadOnlyObjCProperty() {
378 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
379 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
381 bool isReadWriteObjCProperty() {
382 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
383 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
385 bool isAssignObjCProperty() {
386 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
387 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
389 bool isRetainObjCProperty() {
390 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
391 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
393 bool isCopyObjCProperty() {
394 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
395 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
397 bool isNonAtomicObjCProperty() {
398 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
399 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
402 /// Verify - Verify that a derived type descriptor is well formed.
405 /// print - print derived type.
406 void print(raw_ostream &OS) const;
408 /// dump - print derived type to dbgs() with a newline.
412 /// DICompositeType - This descriptor holds a type that can refer to multiple
413 /// other types, like a function or struct.
414 /// FIXME: Why is this a DIDerivedType??
415 class DICompositeType : public DIDerivedType {
416 virtual void anchor();
418 explicit DICompositeType(const MDNode *N = 0)
419 : DIDerivedType(N, true, true) {
420 if (N && !isCompositeType())
424 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
425 unsigned getRunTimeLang() const { return getUnsignedField(11); }
426 DICompositeType getContainingType() const {
427 return getFieldAs<DICompositeType>(12);
429 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
431 /// Verify - Verify that a composite type descriptor is well formed.
434 /// print - print composite type.
435 void print(raw_ostream &OS) const;
437 /// dump - print composite type to dbgs() with a newline.
441 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
442 class DITemplateTypeParameter : public DIDescriptor {
444 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
446 DIScope getContext() const { return getFieldAs<DIScope>(1); }
447 StringRef getName() const { return getStringField(2); }
448 DIType getType() const { return getFieldAs<DIType>(3); }
449 StringRef getFilename() const {
450 return getFieldAs<DIFile>(4).getFilename();
452 StringRef getDirectory() const {
453 return getFieldAs<DIFile>(4).getDirectory();
455 unsigned getLineNumber() const { return getUnsignedField(5); }
456 unsigned getColumnNumber() const { return getUnsignedField(6); }
459 /// DITemplateValueParameter - This is a wrapper for template value parameter.
460 class DITemplateValueParameter : public DIDescriptor {
462 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
464 DIScope getContext() const { return getFieldAs<DIScope>(1); }
465 StringRef getName() const { return getStringField(2); }
466 DIType getType() const { return getFieldAs<DIType>(3); }
467 uint64_t getValue() const { return getUInt64Field(4); }
468 StringRef getFilename() const {
469 return getFieldAs<DIFile>(5).getFilename();
471 StringRef getDirectory() const {
472 return getFieldAs<DIFile>(5).getDirectory();
474 unsigned getLineNumber() const { return getUnsignedField(6); }
475 unsigned getColumnNumber() const { return getUnsignedField(7); }
478 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
479 class DISubprogram : public DIScope {
480 virtual void anchor();
482 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
484 DIScope getContext() const { return getFieldAs<DIScope>(2); }
485 StringRef getName() const { return getStringField(3); }
486 StringRef getDisplayName() const { return getStringField(4); }
487 StringRef getLinkageName() const { return getStringField(5); }
488 DICompileUnit getCompileUnit() const{
489 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
490 if (getVersion() == llvm::LLVMDebugVersion7)
491 return getFieldAs<DICompileUnit>(6);
493 return getFieldAs<DIFile>(6).getCompileUnit();
495 unsigned getLineNumber() const { return getUnsignedField(7); }
496 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
498 /// getReturnTypeName - Subprogram return types are encoded either as
499 /// DIType or as DICompositeType.
500 StringRef getReturnTypeName() const {
501 DICompositeType DCT(getFieldAs<DICompositeType>(8));
503 DIArray A = DCT.getTypeArray();
504 DIType T(A.getElement(0));
507 DIType T(getFieldAs<DIType>(8));
511 /// isLocalToUnit - Return true if this subprogram is local to the current
512 /// compile unit, like 'static' in C.
513 unsigned isLocalToUnit() const { return getUnsignedField(9); }
514 unsigned isDefinition() const { return getUnsignedField(10); }
516 unsigned getVirtuality() const { return getUnsignedField(11); }
517 unsigned getVirtualIndex() const { return getUnsignedField(12); }
519 DICompositeType getContainingType() const {
520 return getFieldAs<DICompositeType>(13);
522 unsigned isArtificial() const {
523 if (getVersion() <= llvm::LLVMDebugVersion8)
524 return getUnsignedField(14);
525 return (getUnsignedField(14) & FlagArtificial) != 0;
527 /// isPrivate - Return true if this subprogram has "private"
528 /// access specifier.
529 bool isPrivate() const {
530 if (getVersion() <= llvm::LLVMDebugVersion8)
532 return (getUnsignedField(14) & FlagPrivate) != 0;
534 /// isProtected - Return true if this subprogram has "protected"
535 /// access specifier.
536 bool isProtected() const {
537 if (getVersion() <= llvm::LLVMDebugVersion8)
539 return (getUnsignedField(14) & FlagProtected) != 0;
541 /// isExplicit - Return true if this subprogram is marked as explicit.
542 bool isExplicit() const {
543 if (getVersion() <= llvm::LLVMDebugVersion8)
545 return (getUnsignedField(14) & FlagExplicit) != 0;
547 /// isPrototyped - Return true if this subprogram is prototyped.
548 bool isPrototyped() const {
549 if (getVersion() <= llvm::LLVMDebugVersion8)
551 return (getUnsignedField(14) & FlagPrototyped) != 0;
554 unsigned isOptimized() const;
556 StringRef getFilename() const {
557 if (getVersion() == llvm::LLVMDebugVersion7)
558 return getCompileUnit().getFilename();
560 return getFieldAs<DIFile>(6).getFilename();
563 StringRef getDirectory() const {
564 if (getVersion() == llvm::LLVMDebugVersion7)
565 return getCompileUnit().getFilename();
567 return getFieldAs<DIFile>(6).getDirectory();
570 /// Verify - Verify that a subprogram descriptor is well formed.
573 /// print - print subprogram.
574 void print(raw_ostream &OS) const;
576 /// dump - print subprogram to dbgs() with a newline.
579 /// describes - Return true if this subprogram provides debugging
580 /// information for the function F.
581 bool describes(const Function *F);
583 Function *getFunction() const { return getFunctionField(16); }
584 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
585 DISubprogram getFunctionDeclaration() const {
586 return getFieldAs<DISubprogram>(18);
588 MDNode *getVariablesNodes() const;
589 DIArray getVariables() const;
592 /// DIGlobalVariable - This is a wrapper for a global variable.
593 class DIGlobalVariable : public DIDescriptor {
595 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
597 DIScope getContext() const { return getFieldAs<DIScope>(2); }
598 StringRef getName() const { return getStringField(3); }
599 StringRef getDisplayName() const { return getStringField(4); }
600 StringRef getLinkageName() const { return getStringField(5); }
601 DICompileUnit getCompileUnit() const{
602 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
603 if (getVersion() == llvm::LLVMDebugVersion7)
604 return getFieldAs<DICompileUnit>(6);
606 DIFile F = getFieldAs<DIFile>(6);
607 return F.getCompileUnit();
609 StringRef getFilename() const {
610 if (getVersion() <= llvm::LLVMDebugVersion10)
611 return getContext().getFilename();
612 return getFieldAs<DIFile>(6).getFilename();
614 StringRef getDirectory() const {
615 if (getVersion() <= llvm::LLVMDebugVersion10)
616 return getContext().getDirectory();
617 return getFieldAs<DIFile>(6).getDirectory();
621 unsigned getLineNumber() const { return getUnsignedField(7); }
622 DIType getType() const { return getFieldAs<DIType>(8); }
623 unsigned isLocalToUnit() const { return getUnsignedField(9); }
624 unsigned isDefinition() const { return getUnsignedField(10); }
626 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
627 Constant *getConstant() const { return getConstantField(11); }
629 /// Verify - Verify that a global variable descriptor is well formed.
632 /// print - print global variable.
633 void print(raw_ostream &OS) const;
635 /// dump - print global variable to dbgs() with a newline.
639 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
641 class DIVariable : public DIDescriptor {
643 explicit DIVariable(const MDNode *N = 0)
646 DIScope getContext() const { return getFieldAs<DIScope>(1); }
647 StringRef getName() const { return getStringField(2); }
648 DICompileUnit getCompileUnit() const {
649 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
650 if (getVersion() == llvm::LLVMDebugVersion7)
651 return getFieldAs<DICompileUnit>(3);
653 DIFile F = getFieldAs<DIFile>(3);
654 return F.getCompileUnit();
656 unsigned getLineNumber() const {
657 return (getUnsignedField(4) << 8) >> 8;
659 unsigned getArgNumber() const {
660 unsigned L = getUnsignedField(4);
663 DIType getType() const { return getFieldAs<DIType>(5); }
665 /// isArtificial - Return true if this variable is marked as "artificial".
666 bool isArtificial() const {
667 if (getVersion() <= llvm::LLVMDebugVersion8)
669 return (getUnsignedField(6) & FlagArtificial) != 0;
672 /// getInlinedAt - If this variable is inlined then return inline location.
673 MDNode *getInlinedAt() const;
675 /// Verify - Verify that a variable descriptor is well formed.
678 /// HasComplexAddr - Return true if the variable has a complex address.
679 bool hasComplexAddress() const {
680 return getNumAddrElements() > 0;
683 unsigned getNumAddrElements() const;
685 uint64_t getAddrElement(unsigned Idx) const {
686 if (getVersion() <= llvm::LLVMDebugVersion8)
687 return getUInt64Field(Idx+6);
688 if (getVersion() == llvm::LLVMDebugVersion9)
689 return getUInt64Field(Idx+7);
690 return getUInt64Field(Idx+8);
693 /// isBlockByrefVariable - Return true if the variable was declared as
694 /// a "__block" variable (Apple Blocks).
695 bool isBlockByrefVariable() const {
696 return getType().isBlockByrefStruct();
699 /// isInlinedFnArgument - Return trule if this variable provides debugging
700 /// information for an inlined function arguments.
701 bool isInlinedFnArgument(const Function *CurFn);
703 /// print - print variable.
704 void print(raw_ostream &OS) const;
706 void printExtendedName(raw_ostream &OS) const;
708 /// dump - print variable to dbgs() with a newline.
712 /// DILexicalBlock - This is a wrapper for a lexical block.
713 class DILexicalBlock : public DIScope {
714 virtual void anchor();
716 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
717 DIScope getContext() const { return getFieldAs<DIScope>(1); }
718 unsigned getLineNumber() const { return getUnsignedField(2); }
719 unsigned getColumnNumber() const { return getUnsignedField(3); }
720 StringRef getDirectory() const {
721 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
722 return !dir.empty() ? dir : getContext().getDirectory();
724 StringRef getFilename() const {
725 StringRef filename = getFieldAs<DIFile>(4).getFilename();
726 return !filename.empty() ? filename : getContext().getFilename();
730 /// DILexicalBlockFile - This is a wrapper for a lexical block with
731 /// a filename change.
732 class DILexicalBlockFile : public DIScope {
733 virtual void anchor();
735 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
736 DIScope getContext() const { return getScope().getContext(); }
737 unsigned getLineNumber() const { return getScope().getLineNumber(); }
738 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
739 StringRef getDirectory() const {
740 StringRef dir = getFieldAs<DIFile>(2).getDirectory();
741 return !dir.empty() ? dir : getContext().getDirectory();
743 StringRef getFilename() const {
744 StringRef filename = getFieldAs<DIFile>(2).getFilename();
745 assert(!filename.empty() && "Why'd you create this then?");
748 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
751 /// DINameSpace - A wrapper for a C++ style name space.
752 class DINameSpace : public DIScope {
753 virtual void anchor();
755 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
756 DIScope getContext() const { return getFieldAs<DIScope>(1); }
757 StringRef getName() const { return getStringField(2); }
758 StringRef getDirectory() const {
759 return getFieldAs<DIFile>(3).getDirectory();
761 StringRef getFilename() const {
762 return getFieldAs<DIFile>(3).getFilename();
764 DICompileUnit getCompileUnit() const{
765 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
766 if (getVersion() == llvm::LLVMDebugVersion7)
767 return getFieldAs<DICompileUnit>(3);
769 return getFieldAs<DIFile>(3).getCompileUnit();
771 unsigned getLineNumber() const { return getUnsignedField(4); }
775 /// DILocation - This object holds location information. This object
776 /// is not associated with any DWARF tag.
777 class DILocation : public DIDescriptor {
779 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
781 unsigned getLineNumber() const { return getUnsignedField(0); }
782 unsigned getColumnNumber() const { return getUnsignedField(1); }
783 DIScope getScope() const { return getFieldAs<DIScope>(2); }
784 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
785 StringRef getFilename() const { return getScope().getFilename(); }
786 StringRef getDirectory() const { return getScope().getDirectory(); }
790 class DIObjCProperty : public DIDescriptor {
792 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
794 StringRef getObjCPropertyName() const { return getStringField(1); }
795 DIFile getFile() const { return getFieldAs<DIFile>(2); }
796 unsigned getLineNumber() const { return getUnsignedField(3); }
798 StringRef getObjCPropertyGetterName() const {
799 return getStringField(4);
801 StringRef getObjCPropertySetterName() const {
802 return getStringField(5);
804 bool isReadOnlyObjCProperty() {
805 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
807 bool isReadWriteObjCProperty() {
808 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
810 bool isAssignObjCProperty() {
811 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
813 bool isRetainObjCProperty() {
814 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
816 bool isCopyObjCProperty() {
817 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
819 bool isNonAtomicObjCProperty() {
820 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
823 DIType getType() const { return getFieldAs<DIType>(7); }
825 /// Verify - Verify that a derived type descriptor is well formed.
828 /// print - print derived type.
829 void print(raw_ostream &OS) const;
831 /// dump - print derived type to dbgs() with a newline.
835 /// getDISubprogram - Find subprogram that is enclosing this scope.
836 DISubprogram getDISubprogram(const MDNode *Scope);
838 /// getDICompositeType - Find underlying composite type.
839 DICompositeType getDICompositeType(DIType T);
841 /// isSubprogramContext - Return true if Context is either a subprogram
842 /// or another context nested inside a subprogram.
843 bool isSubprogramContext(const MDNode *Context);
845 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
846 /// to hold function specific information.
847 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
849 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
850 /// suitable to hold function specific information.
851 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
853 /// createInlinedVariable - Create a new inlined variable based on current
855 /// @param DV Current Variable.
856 /// @param InlinedScope Location at current variable is inlined.
857 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
858 LLVMContext &VMContext);
860 /// cleanseInlinedVariable - Remove inlined scope from the variable.
861 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
863 class DebugInfoFinder {
865 /// processModule - Process entire module and collect debug info
867 void processModule(Module &M);
870 /// processType - Process DIType.
871 void processType(DIType DT);
873 /// processLexicalBlock - Process DILexicalBlock.
874 void processLexicalBlock(DILexicalBlock LB);
876 /// processSubprogram - Process DISubprogram.
877 void processSubprogram(DISubprogram SP);
879 /// processDeclare - Process DbgDeclareInst.
880 void processDeclare(DbgDeclareInst *DDI);
882 /// processLocation - Process DILocation.
883 void processLocation(DILocation Loc);
885 /// addCompileUnit - Add compile unit into CUs.
886 bool addCompileUnit(DICompileUnit CU);
888 /// addGlobalVariable - Add global variable into GVs.
889 bool addGlobalVariable(DIGlobalVariable DIG);
891 // addSubprogram - Add subprogram into SPs.
892 bool addSubprogram(DISubprogram SP);
894 /// addType - Add type into Tys.
895 bool addType(DIType DT);
898 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
899 iterator compile_unit_begin() const { return CUs.begin(); }
900 iterator compile_unit_end() const { return CUs.end(); }
901 iterator subprogram_begin() const { return SPs.begin(); }
902 iterator subprogram_end() const { return SPs.end(); }
903 iterator global_variable_begin() const { return GVs.begin(); }
904 iterator global_variable_end() const { return GVs.end(); }
905 iterator type_begin() const { return TYs.begin(); }
906 iterator type_end() const { return TYs.end(); }
908 unsigned compile_unit_count() const { return CUs.size(); }
909 unsigned global_variable_count() const { return GVs.size(); }
910 unsigned subprogram_count() const { return SPs.size(); }
911 unsigned type_count() const { return TYs.size(); }
914 SmallVector<MDNode *, 8> CUs; // Compile Units
915 SmallVector<MDNode *, 8> SPs; // Subprograms
916 SmallVector<MDNode *, 8> GVs; // Global Variables;
917 SmallVector<MDNode *, 8> TYs; // Types
918 SmallPtrSet<MDNode *, 64> NodesSeen;
920 } // end namespace llvm