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);
523 unsigned isArtificial() const {
524 if (getVersion() <= llvm::LLVMDebugVersion8)
525 return getUnsignedField(14);
526 return (getUnsignedField(14) & FlagArtificial) != 0;
528 /// isPrivate - Return true if this subprogram has "private"
529 /// access specifier.
530 bool isPrivate() const {
531 if (getVersion() <= llvm::LLVMDebugVersion8)
533 return (getUnsignedField(14) & FlagPrivate) != 0;
535 /// isProtected - Return true if this subprogram has "protected"
536 /// access specifier.
537 bool isProtected() const {
538 if (getVersion() <= llvm::LLVMDebugVersion8)
540 return (getUnsignedField(14) & FlagProtected) != 0;
542 /// isExplicit - Return true if this subprogram is marked as explicit.
543 bool isExplicit() const {
544 if (getVersion() <= llvm::LLVMDebugVersion8)
546 return (getUnsignedField(14) & FlagExplicit) != 0;
548 /// isPrototyped - Return true if this subprogram is prototyped.
549 bool isPrototyped() const {
550 if (getVersion() <= llvm::LLVMDebugVersion8)
552 return (getUnsignedField(14) & FlagPrototyped) != 0;
555 unsigned isOptimized() const;
557 StringRef getFilename() const {
558 if (getVersion() == llvm::LLVMDebugVersion7)
559 return getCompileUnit().getFilename();
561 return getFieldAs<DIFile>(6).getFilename();
564 StringRef getDirectory() const {
565 if (getVersion() == llvm::LLVMDebugVersion7)
566 return getCompileUnit().getFilename();
568 return getFieldAs<DIFile>(6).getDirectory();
571 /// getScopeLineNumber - Get the beginning of the scope of the
572 /// function, not necessarily where the name of the program
574 unsigned getScopeLineNumber() const { return getUnsignedField(20); }
576 /// Verify - Verify that a subprogram descriptor is well formed.
579 /// print - print subprogram.
580 void print(raw_ostream &OS) const;
582 /// dump - print subprogram to dbgs() with a newline.
585 /// describes - Return true if this subprogram provides debugging
586 /// information for the function F.
587 bool describes(const Function *F);
589 Function *getFunction() const { return getFunctionField(16); }
590 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
591 DISubprogram getFunctionDeclaration() const {
592 return getFieldAs<DISubprogram>(18);
594 MDNode *getVariablesNodes() const;
595 DIArray getVariables() const;
598 /// DIGlobalVariable - This is a wrapper for a global variable.
599 class DIGlobalVariable : public DIDescriptor {
601 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
603 DIScope getContext() const { return getFieldAs<DIScope>(2); }
604 StringRef getName() const { return getStringField(3); }
605 StringRef getDisplayName() const { return getStringField(4); }
606 StringRef getLinkageName() const { return getStringField(5); }
607 DICompileUnit getCompileUnit() const{
608 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
609 if (getVersion() == llvm::LLVMDebugVersion7)
610 return getFieldAs<DICompileUnit>(6);
612 DIFile F = getFieldAs<DIFile>(6);
613 return F.getCompileUnit();
615 StringRef getFilename() const {
616 if (getVersion() <= llvm::LLVMDebugVersion10)
617 return getContext().getFilename();
618 return getFieldAs<DIFile>(6).getFilename();
620 StringRef getDirectory() const {
621 if (getVersion() <= llvm::LLVMDebugVersion10)
622 return getContext().getDirectory();
623 return getFieldAs<DIFile>(6).getDirectory();
627 unsigned getLineNumber() const { return getUnsignedField(7); }
628 DIType getType() const { return getFieldAs<DIType>(8); }
629 unsigned isLocalToUnit() const { return getUnsignedField(9); }
630 unsigned isDefinition() const { return getUnsignedField(10); }
632 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
633 Constant *getConstant() const { return getConstantField(11); }
635 /// Verify - Verify that a global variable descriptor is well formed.
638 /// print - print global variable.
639 void print(raw_ostream &OS) const;
641 /// dump - print global variable to dbgs() with a newline.
645 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
647 class DIVariable : public DIDescriptor {
649 explicit DIVariable(const MDNode *N = 0)
652 DIScope getContext() const { return getFieldAs<DIScope>(1); }
653 StringRef getName() const { return getStringField(2); }
654 DICompileUnit getCompileUnit() const {
655 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
656 if (getVersion() == llvm::LLVMDebugVersion7)
657 return getFieldAs<DICompileUnit>(3);
659 DIFile F = getFieldAs<DIFile>(3);
660 return F.getCompileUnit();
662 unsigned getLineNumber() const {
663 return (getUnsignedField(4) << 8) >> 8;
665 unsigned getArgNumber() const {
666 unsigned L = getUnsignedField(4);
669 DIType getType() const { return getFieldAs<DIType>(5); }
671 /// isArtificial - Return true if this variable is marked as "artificial".
672 bool isArtificial() const {
673 if (getVersion() <= llvm::LLVMDebugVersion8)
675 return (getUnsignedField(6) & FlagArtificial) != 0;
678 /// getInlinedAt - If this variable is inlined then return inline location.
679 MDNode *getInlinedAt() const;
681 /// Verify - Verify that a variable descriptor is well formed.
684 /// HasComplexAddr - Return true if the variable has a complex address.
685 bool hasComplexAddress() const {
686 return getNumAddrElements() > 0;
689 unsigned getNumAddrElements() const;
691 uint64_t getAddrElement(unsigned Idx) const {
692 if (getVersion() <= llvm::LLVMDebugVersion8)
693 return getUInt64Field(Idx+6);
694 if (getVersion() == llvm::LLVMDebugVersion9)
695 return getUInt64Field(Idx+7);
696 return getUInt64Field(Idx+8);
699 /// isBlockByrefVariable - Return true if the variable was declared as
700 /// a "__block" variable (Apple Blocks).
701 bool isBlockByrefVariable() const {
702 return getType().isBlockByrefStruct();
705 /// isInlinedFnArgument - Return trule if this variable provides debugging
706 /// information for an inlined function arguments.
707 bool isInlinedFnArgument(const Function *CurFn);
709 /// print - print variable.
710 void print(raw_ostream &OS) const;
712 void printExtendedName(raw_ostream &OS) const;
714 /// dump - print variable to dbgs() with a newline.
718 /// DILexicalBlock - This is a wrapper for a lexical block.
719 class DILexicalBlock : public DIScope {
720 virtual void anchor();
722 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
723 DIScope getContext() const { return getFieldAs<DIScope>(1); }
724 unsigned getLineNumber() const { return getUnsignedField(2); }
725 unsigned getColumnNumber() const { return getUnsignedField(3); }
726 StringRef getDirectory() const {
727 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
728 return !dir.empty() ? dir : getContext().getDirectory();
730 StringRef getFilename() const {
731 StringRef filename = getFieldAs<DIFile>(4).getFilename();
732 return !filename.empty() ? filename : getContext().getFilename();
736 /// DILexicalBlockFile - This is a wrapper for a lexical block with
737 /// a filename change.
738 class DILexicalBlockFile : public DIScope {
739 virtual void anchor();
741 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
742 DIScope getContext() const { return getScope().getContext(); }
743 unsigned getLineNumber() const { return getScope().getLineNumber(); }
744 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
745 StringRef getDirectory() const {
746 StringRef dir = getFieldAs<DIFile>(2).getDirectory();
747 return !dir.empty() ? dir : getContext().getDirectory();
749 StringRef getFilename() const {
750 StringRef filename = getFieldAs<DIFile>(2).getFilename();
751 assert(!filename.empty() && "Why'd you create this then?");
754 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
757 /// DINameSpace - A wrapper for a C++ style name space.
758 class DINameSpace : public DIScope {
759 virtual void anchor();
761 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
762 DIScope getContext() const { return getFieldAs<DIScope>(1); }
763 StringRef getName() const { return getStringField(2); }
764 StringRef getDirectory() const {
765 return getFieldAs<DIFile>(3).getDirectory();
767 StringRef getFilename() const {
768 return getFieldAs<DIFile>(3).getFilename();
770 DICompileUnit getCompileUnit() const{
771 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
772 if (getVersion() == llvm::LLVMDebugVersion7)
773 return getFieldAs<DICompileUnit>(3);
775 return getFieldAs<DIFile>(3).getCompileUnit();
777 unsigned getLineNumber() const { return getUnsignedField(4); }
781 /// DILocation - This object holds location information. This object
782 /// is not associated with any DWARF tag.
783 class DILocation : public DIDescriptor {
785 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
787 unsigned getLineNumber() const { return getUnsignedField(0); }
788 unsigned getColumnNumber() const { return getUnsignedField(1); }
789 DIScope getScope() const { return getFieldAs<DIScope>(2); }
790 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
791 StringRef getFilename() const { return getScope().getFilename(); }
792 StringRef getDirectory() const { return getScope().getDirectory(); }
796 class DIObjCProperty : public DIDescriptor {
798 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
800 StringRef getObjCPropertyName() const { return getStringField(1); }
801 DIFile getFile() const { return getFieldAs<DIFile>(2); }
802 unsigned getLineNumber() const { return getUnsignedField(3); }
804 StringRef getObjCPropertyGetterName() const {
805 return getStringField(4);
807 StringRef getObjCPropertySetterName() const {
808 return getStringField(5);
810 bool isReadOnlyObjCProperty() {
811 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
813 bool isReadWriteObjCProperty() {
814 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
816 bool isAssignObjCProperty() {
817 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
819 bool isRetainObjCProperty() {
820 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
822 bool isCopyObjCProperty() {
823 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
825 bool isNonAtomicObjCProperty() {
826 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
829 DIType getType() const { return getFieldAs<DIType>(7); }
831 /// Verify - Verify that a derived type descriptor is well formed.
834 /// print - print derived type.
835 void print(raw_ostream &OS) const;
837 /// dump - print derived type to dbgs() with a newline.
841 /// getDISubprogram - Find subprogram that is enclosing this scope.
842 DISubprogram getDISubprogram(const MDNode *Scope);
844 /// getDICompositeType - Find underlying composite type.
845 DICompositeType getDICompositeType(DIType T);
847 /// isSubprogramContext - Return true if Context is either a subprogram
848 /// or another context nested inside a subprogram.
849 bool isSubprogramContext(const MDNode *Context);
851 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
852 /// to hold function specific information.
853 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
855 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
856 /// suitable to hold function specific information.
857 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
859 /// createInlinedVariable - Create a new inlined variable based on current
861 /// @param DV Current Variable.
862 /// @param InlinedScope Location at current variable is inlined.
863 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
864 LLVMContext &VMContext);
866 /// cleanseInlinedVariable - Remove inlined scope from the variable.
867 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
869 class DebugInfoFinder {
871 /// processModule - Process entire module and collect debug info
873 void processModule(Module &M);
876 /// processType - Process DIType.
877 void processType(DIType DT);
879 /// processLexicalBlock - Process DILexicalBlock.
880 void processLexicalBlock(DILexicalBlock LB);
882 /// processSubprogram - Process DISubprogram.
883 void processSubprogram(DISubprogram SP);
885 /// processDeclare - Process DbgDeclareInst.
886 void processDeclare(DbgDeclareInst *DDI);
888 /// processLocation - Process DILocation.
889 void processLocation(DILocation Loc);
891 /// addCompileUnit - Add compile unit into CUs.
892 bool addCompileUnit(DICompileUnit CU);
894 /// addGlobalVariable - Add global variable into GVs.
895 bool addGlobalVariable(DIGlobalVariable DIG);
897 // addSubprogram - Add subprogram into SPs.
898 bool addSubprogram(DISubprogram SP);
900 /// addType - Add type into Tys.
901 bool addType(DIType DT);
904 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
905 iterator compile_unit_begin() const { return CUs.begin(); }
906 iterator compile_unit_end() const { return CUs.end(); }
907 iterator subprogram_begin() const { return SPs.begin(); }
908 iterator subprogram_end() const { return SPs.end(); }
909 iterator global_variable_begin() const { return GVs.begin(); }
910 iterator global_variable_end() const { return GVs.end(); }
911 iterator type_begin() const { return TYs.begin(); }
912 iterator type_end() const { return TYs.end(); }
914 unsigned compile_unit_count() const { return CUs.size(); }
915 unsigned global_variable_count() const { return GVs.size(); }
916 unsigned subprogram_count() const { return SPs.size(); }
917 unsigned type_count() const { return TYs.size(); }
920 SmallVector<MDNode *, 8> CUs; // Compile Units
921 SmallVector<MDNode *, 8> SPs; // Subprograms
922 SmallVector<MDNode *, 8> GVs; // Global Variables;
923 SmallVector<MDNode *, 8> TYs; // Types
924 SmallPtrSet<MDNode *, 64> NodesSeen;
926 } // end namespace llvm