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/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
67 const MDNode *DbgNode;
69 StringRef getStringField(unsigned Elt) const;
70 unsigned getUnsignedField(unsigned Elt) const {
71 return (unsigned)getUInt64Field(Elt);
73 uint64_t getUInt64Field(unsigned Elt) const;
74 int64_t getInt64Field(unsigned Elt) const;
75 DIDescriptor getDescriptorField(unsigned Elt) const;
77 template <typename DescTy>
78 DescTy getFieldAs(unsigned Elt) const {
79 return DescTy(getDescriptorField(Elt));
82 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
83 Constant *getConstantField(unsigned Elt) const;
84 Function *getFunctionField(unsigned Elt) const;
85 void replaceFunctionField(unsigned Elt, Function *F);
88 explicit DIDescriptor() : DbgNode(0) {}
89 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
90 explicit DIDescriptor(const DIFile F);
91 explicit DIDescriptor(const DISubprogram F);
92 explicit DIDescriptor(const DILexicalBlockFile F);
93 explicit DIDescriptor(const DILexicalBlock F);
94 explicit DIDescriptor(const DIVariable F);
95 explicit DIDescriptor(const DIType F);
97 bool Verify() const { return DbgNode != 0; }
99 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
100 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
102 unsigned getVersion() const {
103 return getUnsignedField(0) & LLVMDebugVersionMask;
106 unsigned getTag() const {
107 return getUnsignedField(0) & ~LLVMDebugVersionMask;
110 bool isDerivedType() const;
111 bool isCompositeType() const;
112 bool isBasicType() const;
113 bool isVariable() const;
114 bool isSubprogram() const;
115 bool isGlobalVariable() const;
116 bool isScope() const;
118 bool isCompileUnit() const;
119 bool isNameSpace() const;
120 bool isLexicalBlockFile() const;
121 bool isLexicalBlock() const;
122 bool isSubrange() const;
123 bool isEnumerator() const;
125 bool isGlobal() const;
126 bool isUnspecifiedParameter() const;
127 bool isTemplateTypeParameter() const;
128 bool isTemplateValueParameter() const;
129 bool isObjCProperty() const;
131 /// print - print descriptor.
132 void print(raw_ostream &OS) const;
134 /// dump - print descriptor to dbgs() with a newline.
138 /// DISubrange - This is used to represent ranges, for array bounds.
139 class DISubrange : public DIDescriptor {
140 friend class DIDescriptor;
141 void printInternal(raw_ostream &OS) const;
143 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
145 uint64_t getLo() const { return getUInt64Field(1); }
146 uint64_t getHi() const { return getUInt64Field(2); }
147 int64_t getCount() const { return getInt64Field(3); }
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 isValid() const {
301 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
303 StringRef getDirectory() const {
304 if (getVersion() == llvm::LLVMDebugVersion7)
305 return getCompileUnit().getDirectory();
307 return getFieldAs<DIFile>(3).getDirectory();
309 StringRef getFilename() const {
310 if (getVersion() == llvm::LLVMDebugVersion7)
311 return getCompileUnit().getFilename();
313 return getFieldAs<DIFile>(3).getFilename();
316 /// isUnsignedDIType - Return true if type encoding is unsigned.
317 bool isUnsignedDIType();
319 /// replaceAllUsesWith - Replace all uses of debug info referenced by
321 void replaceAllUsesWith(DIDescriptor &D);
322 void replaceAllUsesWith(MDNode *D);
325 /// DIBasicType - A basic type, like 'int' or 'float'.
326 class DIBasicType : public DIType {
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 friend class DIDescriptor;
340 void printInternal(raw_ostream &OS) const;
342 explicit DIDerivedType(const MDNode *N, bool, bool)
343 : DIType(N, true, true) {}
345 explicit DIDerivedType(const MDNode *N = 0)
346 : DIType(N, true, true) {}
348 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
350 /// getOriginalTypeSize - If this type is derived from a base type then
351 /// return base type size.
352 uint64_t getOriginalTypeSize() const;
354 /// getObjCProperty - Return property node, if this ivar is
355 /// associated with one.
356 MDNode *getObjCProperty() const;
358 StringRef getObjCPropertyName() const {
359 if (getVersion() > LLVMDebugVersion11)
361 return getStringField(10);
363 StringRef getObjCPropertyGetterName() const {
364 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
365 return getStringField(11);
367 StringRef getObjCPropertySetterName() const {
368 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
369 return getStringField(12);
371 bool isReadOnlyObjCProperty() {
372 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
373 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
375 bool isReadWriteObjCProperty() {
376 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
377 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
379 bool isAssignObjCProperty() {
380 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
381 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
383 bool isRetainObjCProperty() {
384 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
385 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
387 bool isCopyObjCProperty() {
388 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
389 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
391 bool isNonAtomicObjCProperty() {
392 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
393 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
396 /// Verify - Verify that a derived type descriptor is well formed.
400 /// DICompositeType - This descriptor holds a type that can refer to multiple
401 /// other types, like a function or struct.
402 /// FIXME: Why is this a DIDerivedType??
403 class DICompositeType : public DIDerivedType {
404 friend class DIDescriptor;
405 void printInternal(raw_ostream &OS) const;
407 explicit DICompositeType(const MDNode *N = 0)
408 : DIDerivedType(N, true, true) {
409 if (N && !isCompositeType())
413 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
414 unsigned getRunTimeLang() const { return getUnsignedField(11); }
415 DICompositeType getContainingType() const {
416 return getFieldAs<DICompositeType>(12);
418 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
420 /// Verify - Verify that a composite type descriptor is well formed.
424 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
425 class DITemplateTypeParameter : public DIDescriptor {
427 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
429 DIScope getContext() const { return getFieldAs<DIScope>(1); }
430 StringRef getName() const { return getStringField(2); }
431 DIType getType() const { return getFieldAs<DIType>(3); }
432 StringRef getFilename() const {
433 return getFieldAs<DIFile>(4).getFilename();
435 StringRef getDirectory() const {
436 return getFieldAs<DIFile>(4).getDirectory();
438 unsigned getLineNumber() const { return getUnsignedField(5); }
439 unsigned getColumnNumber() const { return getUnsignedField(6); }
442 /// DITemplateValueParameter - This is a wrapper for template value parameter.
443 class DITemplateValueParameter : public DIDescriptor {
445 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
447 DIScope getContext() const { return getFieldAs<DIScope>(1); }
448 StringRef getName() const { return getStringField(2); }
449 DIType getType() const { return getFieldAs<DIType>(3); }
450 uint64_t getValue() const { return getUInt64Field(4); }
451 StringRef getFilename() const {
452 return getFieldAs<DIFile>(5).getFilename();
454 StringRef getDirectory() const {
455 return getFieldAs<DIFile>(5).getDirectory();
457 unsigned getLineNumber() const { return getUnsignedField(6); }
458 unsigned getColumnNumber() const { return getUnsignedField(7); }
461 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
462 class DISubprogram : public DIScope {
463 friend class DIDescriptor;
464 void printInternal(raw_ostream &OS) const;
466 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
468 DIScope getContext() const { return getFieldAs<DIScope>(2); }
469 StringRef getName() const { return getStringField(3); }
470 StringRef getDisplayName() const { return getStringField(4); }
471 StringRef getLinkageName() const { return getStringField(5); }
472 DICompileUnit getCompileUnit() const{
473 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
474 if (getVersion() == llvm::LLVMDebugVersion7)
475 return getFieldAs<DICompileUnit>(6);
477 return getFieldAs<DIFile>(6).getCompileUnit();
479 unsigned getLineNumber() const { return getUnsignedField(7); }
480 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
482 /// getReturnTypeName - Subprogram return types are encoded either as
483 /// DIType or as DICompositeType.
484 StringRef getReturnTypeName() const {
485 DICompositeType DCT(getFieldAs<DICompositeType>(8));
487 DIArray A = DCT.getTypeArray();
488 DIType T(A.getElement(0));
491 DIType T(getFieldAs<DIType>(8));
495 /// isLocalToUnit - Return true if this subprogram is local to the current
496 /// compile unit, like 'static' in C.
497 unsigned isLocalToUnit() const { return getUnsignedField(9); }
498 unsigned isDefinition() const { return getUnsignedField(10); }
500 unsigned getVirtuality() const { return getUnsignedField(11); }
501 unsigned getVirtualIndex() const { return getUnsignedField(12); }
503 DICompositeType getContainingType() const {
504 return getFieldAs<DICompositeType>(13);
507 unsigned isArtificial() const {
508 if (getVersion() <= llvm::LLVMDebugVersion8)
509 return getUnsignedField(14);
510 return (getUnsignedField(14) & FlagArtificial) != 0;
512 /// isPrivate - Return true if this subprogram has "private"
513 /// access specifier.
514 bool isPrivate() const {
515 if (getVersion() <= llvm::LLVMDebugVersion8)
517 return (getUnsignedField(14) & FlagPrivate) != 0;
519 /// isProtected - Return true if this subprogram has "protected"
520 /// access specifier.
521 bool isProtected() const {
522 if (getVersion() <= llvm::LLVMDebugVersion8)
524 return (getUnsignedField(14) & FlagProtected) != 0;
526 /// isExplicit - Return true if this subprogram is marked as explicit.
527 bool isExplicit() const {
528 if (getVersion() <= llvm::LLVMDebugVersion8)
530 return (getUnsignedField(14) & FlagExplicit) != 0;
532 /// isPrototyped - Return true if this subprogram is prototyped.
533 bool isPrototyped() const {
534 if (getVersion() <= llvm::LLVMDebugVersion8)
536 return (getUnsignedField(14) & FlagPrototyped) != 0;
539 unsigned isOptimized() const;
541 StringRef getFilename() const {
542 if (getVersion() == llvm::LLVMDebugVersion7)
543 return getCompileUnit().getFilename();
545 return getFieldAs<DIFile>(6).getFilename();
548 StringRef getDirectory() const {
549 if (getVersion() == llvm::LLVMDebugVersion7)
550 return getCompileUnit().getFilename();
552 return getFieldAs<DIFile>(6).getDirectory();
555 /// getScopeLineNumber - Get the beginning of the scope of the
556 /// function, not necessarily where the name of the program
558 unsigned getScopeLineNumber() const { return getUnsignedField(20); }
560 /// Verify - Verify that a subprogram descriptor is well formed.
563 /// describes - Return true if this subprogram provides debugging
564 /// information for the function F.
565 bool describes(const Function *F);
567 Function *getFunction() const { return getFunctionField(16); }
568 void replaceFunction(Function *F) { replaceFunctionField(16, F); }
569 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
570 DISubprogram getFunctionDeclaration() const {
571 return getFieldAs<DISubprogram>(18);
573 MDNode *getVariablesNodes() const;
574 DIArray getVariables() const;
577 /// DIGlobalVariable - This is a wrapper for a global variable.
578 class DIGlobalVariable : public DIDescriptor {
579 friend class DIDescriptor;
580 void printInternal(raw_ostream &OS) const;
582 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
584 DIScope getContext() const { return getFieldAs<DIScope>(2); }
585 StringRef getName() const { return getStringField(3); }
586 StringRef getDisplayName() const { return getStringField(4); }
587 StringRef getLinkageName() const { return getStringField(5); }
588 DICompileUnit getCompileUnit() const{
589 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
590 if (getVersion() == llvm::LLVMDebugVersion7)
591 return getFieldAs<DICompileUnit>(6);
593 DIFile F = getFieldAs<DIFile>(6);
594 return F.getCompileUnit();
596 StringRef getFilename() const {
597 if (getVersion() <= llvm::LLVMDebugVersion10)
598 return getContext().getFilename();
599 return getFieldAs<DIFile>(6).getFilename();
601 StringRef getDirectory() const {
602 if (getVersion() <= llvm::LLVMDebugVersion10)
603 return getContext().getDirectory();
604 return getFieldAs<DIFile>(6).getDirectory();
608 unsigned getLineNumber() const { return getUnsignedField(7); }
609 DIType getType() const { return getFieldAs<DIType>(8); }
610 unsigned isLocalToUnit() const { return getUnsignedField(9); }
611 unsigned isDefinition() const { return getUnsignedField(10); }
613 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
614 Constant *getConstant() const { return getConstantField(11); }
616 /// Verify - Verify that a global variable descriptor is well formed.
620 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
622 class DIVariable : public DIDescriptor {
623 friend class DIDescriptor;
624 void printInternal(raw_ostream &OS) const;
626 explicit DIVariable(const MDNode *N = 0)
629 DIScope getContext() const { return getFieldAs<DIScope>(1); }
630 StringRef getName() const { return getStringField(2); }
631 DICompileUnit getCompileUnit() const {
632 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
633 if (getVersion() == llvm::LLVMDebugVersion7)
634 return getFieldAs<DICompileUnit>(3);
636 DIFile F = getFieldAs<DIFile>(3);
637 return F.getCompileUnit();
639 unsigned getLineNumber() const {
640 return (getUnsignedField(4) << 8) >> 8;
642 unsigned getArgNumber() const {
643 unsigned L = getUnsignedField(4);
646 DIType getType() const { return getFieldAs<DIType>(5); }
648 /// isArtificial - Return true if this variable is marked as "artificial".
649 bool isArtificial() const {
650 if (getVersion() <= llvm::LLVMDebugVersion8)
652 return (getUnsignedField(6) & FlagArtificial) != 0;
655 bool isObjectPointer() const {
656 return (getUnsignedField(6) & FlagObjectPointer) != 0;
659 /// getInlinedAt - If this variable is inlined then return inline location.
660 MDNode *getInlinedAt() const;
662 /// Verify - Verify that a variable descriptor is well formed.
665 /// HasComplexAddr - Return true if the variable has a complex address.
666 bool hasComplexAddress() const {
667 return getNumAddrElements() > 0;
670 unsigned getNumAddrElements() const;
672 uint64_t getAddrElement(unsigned Idx) const {
673 if (getVersion() <= llvm::LLVMDebugVersion8)
674 return getUInt64Field(Idx+6);
675 if (getVersion() == llvm::LLVMDebugVersion9)
676 return getUInt64Field(Idx+7);
677 return getUInt64Field(Idx+8);
680 /// isBlockByrefVariable - Return true if the variable was declared as
681 /// a "__block" variable (Apple Blocks).
682 bool isBlockByrefVariable() const {
683 return getType().isBlockByrefStruct();
686 /// isInlinedFnArgument - Return trule if this variable provides debugging
687 /// information for an inlined function arguments.
688 bool isInlinedFnArgument(const Function *CurFn);
690 void printExtendedName(raw_ostream &OS) const;
693 /// DILexicalBlock - This is a wrapper for a lexical block.
694 class DILexicalBlock : public DIScope {
696 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
697 DIScope getContext() const { return getFieldAs<DIScope>(1); }
698 unsigned getLineNumber() const { return getUnsignedField(2); }
699 unsigned getColumnNumber() const { return getUnsignedField(3); }
700 StringRef getDirectory() const {
701 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
702 return !dir.empty() ? dir : getContext().getDirectory();
704 StringRef getFilename() const {
705 StringRef filename = getFieldAs<DIFile>(4).getFilename();
706 return !filename.empty() ? filename : getContext().getFilename();
710 /// DILexicalBlockFile - This is a wrapper for a lexical block with
711 /// a filename change.
712 class DILexicalBlockFile : public DIScope {
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 {
733 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
734 DIScope getContext() const { return getFieldAs<DIScope>(1); }
735 StringRef getName() const { return getStringField(2); }
736 StringRef getDirectory() const {
737 return getFieldAs<DIFile>(3).getDirectory();
739 StringRef getFilename() const {
740 return getFieldAs<DIFile>(3).getFilename();
742 DICompileUnit getCompileUnit() const{
743 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
744 if (getVersion() == llvm::LLVMDebugVersion7)
745 return getFieldAs<DICompileUnit>(3);
747 return getFieldAs<DIFile>(3).getCompileUnit();
749 unsigned getLineNumber() const { return getUnsignedField(4); }
753 /// DILocation - This object holds location information. This object
754 /// is not associated with any DWARF tag.
755 class DILocation : public DIDescriptor {
757 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
759 unsigned getLineNumber() const { return getUnsignedField(0); }
760 unsigned getColumnNumber() const { return getUnsignedField(1); }
761 DIScope getScope() const { return getFieldAs<DIScope>(2); }
762 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
763 StringRef getFilename() const { return getScope().getFilename(); }
764 StringRef getDirectory() const { return getScope().getDirectory(); }
768 class DIObjCProperty : public DIDescriptor {
769 friend class DIDescriptor;
770 void printInternal(raw_ostream &OS) const;
772 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
774 StringRef getObjCPropertyName() const { return getStringField(1); }
775 DIFile getFile() const { return getFieldAs<DIFile>(2); }
776 unsigned getLineNumber() const { return getUnsignedField(3); }
778 StringRef getObjCPropertyGetterName() const {
779 return getStringField(4);
781 StringRef getObjCPropertySetterName() const {
782 return getStringField(5);
784 bool isReadOnlyObjCProperty() {
785 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
787 bool isReadWriteObjCProperty() {
788 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
790 bool isAssignObjCProperty() {
791 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
793 bool isRetainObjCProperty() {
794 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
796 bool isCopyObjCProperty() {
797 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
799 bool isNonAtomicObjCProperty() {
800 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
803 DIType getType() const { return getFieldAs<DIType>(7); }
805 /// Verify - Verify that a derived type descriptor is well formed.
809 /// getDISubprogram - Find subprogram that is enclosing this scope.
810 DISubprogram getDISubprogram(const MDNode *Scope);
812 /// getDICompositeType - Find underlying composite type.
813 DICompositeType getDICompositeType(DIType T);
815 /// isSubprogramContext - Return true if Context is either a subprogram
816 /// or another context nested inside a subprogram.
817 bool isSubprogramContext(const MDNode *Context);
819 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
820 /// to hold function specific information.
821 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
823 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
824 /// suitable to hold function specific information.
825 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
827 /// createInlinedVariable - Create a new inlined variable based on current
829 /// @param DV Current Variable.
830 /// @param InlinedScope Location at current variable is inlined.
831 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
832 LLVMContext &VMContext);
834 /// cleanseInlinedVariable - Remove inlined scope from the variable.
835 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
837 class DebugInfoFinder {
839 /// processModule - Process entire module and collect debug info
841 void processModule(const Module &M);
844 /// processType - Process DIType.
845 void processType(DIType DT);
847 /// processLexicalBlock - Process DILexicalBlock.
848 void processLexicalBlock(DILexicalBlock LB);
850 /// processSubprogram - Process DISubprogram.
851 void processSubprogram(DISubprogram SP);
853 /// processDeclare - Process DbgDeclareInst.
854 void processDeclare(const DbgDeclareInst *DDI);
856 /// processLocation - Process DILocation.
857 void processLocation(DILocation Loc);
859 /// addCompileUnit - Add compile unit into CUs.
860 bool addCompileUnit(DICompileUnit CU);
862 /// addGlobalVariable - Add global variable into GVs.
863 bool addGlobalVariable(DIGlobalVariable DIG);
865 // addSubprogram - Add subprogram into SPs.
866 bool addSubprogram(DISubprogram SP);
868 /// addType - Add type into Tys.
869 bool addType(DIType DT);
872 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
873 iterator compile_unit_begin() const { return CUs.begin(); }
874 iterator compile_unit_end() const { return CUs.end(); }
875 iterator subprogram_begin() const { return SPs.begin(); }
876 iterator subprogram_end() const { return SPs.end(); }
877 iterator global_variable_begin() const { return GVs.begin(); }
878 iterator global_variable_end() const { return GVs.end(); }
879 iterator type_begin() const { return TYs.begin(); }
880 iterator type_end() const { return TYs.end(); }
882 unsigned compile_unit_count() const { return CUs.size(); }
883 unsigned global_variable_count() const { return GVs.size(); }
884 unsigned subprogram_count() const { return SPs.size(); }
885 unsigned type_count() const { return TYs.size(); }
888 SmallVector<MDNode *, 8> CUs; // Compile Units
889 SmallVector<MDNode *, 8> SPs; // Subprograms
890 SmallVector<MDNode *, 8> GVs; // Global Variables;
891 SmallVector<MDNode *, 8> TYs; // Types
892 SmallPtrSet<MDNode *, 64> NodesSeen;
894 } // end namespace llvm