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 int64_t getLo() const { return getInt64Field(1); }
146 int64_t getCount() const { return getInt64Field(2); }
149 /// DIArray - This descriptor holds an array of descriptors.
150 class DIArray : public DIDescriptor {
152 explicit DIArray(const MDNode *N = 0)
155 unsigned getNumElements() const;
156 DIDescriptor getElement(unsigned Idx) const {
157 return getDescriptorField(Idx);
161 /// DIScope - A base class for various scopes.
162 class DIScope : public DIDescriptor {
164 friend class DIDescriptor;
165 void printInternal(raw_ostream &OS) const;
167 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
169 StringRef getFilename() const;
170 StringRef getDirectory() const;
173 /// DICompileUnit - A wrapper for a compile unit.
174 class DICompileUnit : public DIScope {
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 friend class DIDescriptor;
211 void printInternal(raw_ostream &OS) const {} // FIXME: Output something?
213 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
214 if (DbgNode && !isFile())
217 StringRef getFilename() const { return getStringField(1); }
218 StringRef getDirectory() const { return getStringField(2); }
219 DICompileUnit getCompileUnit() const{
220 assert (getVersion() <= LLVMDebugVersion10 && "Invalid CompileUnit!");
221 return getFieldAs<DICompileUnit>(3);
225 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
226 /// FIXME: it seems strange that this doesn't have either a reference to the
227 /// type/precision or a file/line pair for location info.
228 class DIEnumerator : public DIDescriptor {
229 friend class DIDescriptor;
230 void printInternal(raw_ostream &OS) const;
232 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
234 StringRef getName() const { return getStringField(1); }
235 uint64_t getEnumValue() const { return getUInt64Field(2); }
238 /// DIType - This is a wrapper for a type.
239 /// FIXME: Types should be factored much better so that CV qualifiers and
240 /// others do not require a huge and empty descriptor full of zeros.
241 class DIType : public DIScope {
243 friend class DIDescriptor;
244 void printInternal(raw_ostream &OS) const;
245 // This ctor is used when the Tag has already been validated by a derived
247 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
249 /// Verify - Verify that a type descriptor is well formed.
251 explicit DIType(const MDNode *N);
254 DIScope getContext() const { return getFieldAs<DIScope>(1); }
255 StringRef getName() const { return getStringField(2); }
256 DICompileUnit getCompileUnit() const{
257 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
258 if (getVersion() == llvm::LLVMDebugVersion7)
259 return getFieldAs<DICompileUnit>(3);
261 return getFieldAs<DIFile>(3).getCompileUnit();
263 DIFile getFile() const { return getFieldAs<DIFile>(3); }
264 unsigned getLineNumber() const { return getUnsignedField(4); }
265 uint64_t getSizeInBits() const { return getUInt64Field(5); }
266 uint64_t getAlignInBits() const { return getUInt64Field(6); }
267 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
268 // carry this is just plain insane.
269 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
270 unsigned getFlags() const { return getUnsignedField(8); }
271 bool isPrivate() const {
272 return (getFlags() & FlagPrivate) != 0;
274 bool isProtected() const {
275 return (getFlags() & FlagProtected) != 0;
277 bool isForwardDecl() const {
278 return (getFlags() & FlagFwdDecl) != 0;
280 // isAppleBlock - Return true if this is the Apple Blocks extension.
281 bool isAppleBlockExtension() const {
282 return (getFlags() & FlagAppleBlock) != 0;
284 bool isBlockByrefStruct() const {
285 return (getFlags() & FlagBlockByrefStruct) != 0;
287 bool isVirtual() const {
288 return (getFlags() & FlagVirtual) != 0;
290 bool isArtificial() const {
291 return (getFlags() & FlagArtificial) != 0;
293 bool isObjectPointer() const {
294 return (getFlags() & FlagObjectPointer) != 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 {
327 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
329 unsigned getEncoding() const { return getUnsignedField(9); }
331 /// Verify - Verify that a basic type descriptor is well formed.
335 /// DIDerivedType - A simple derived type, like a const qualified type,
336 /// a typedef, a pointer or reference, etc.
337 class DIDerivedType : public DIType {
338 friend class DIDescriptor;
339 void printInternal(raw_ostream &OS) const;
341 explicit DIDerivedType(const MDNode *N, bool, bool)
342 : DIType(N, true, true) {}
344 explicit DIDerivedType(const MDNode *N = 0)
345 : DIType(N, true, true) {}
347 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
349 /// getOriginalTypeSize - If this type is derived from a base type then
350 /// return base type size.
351 uint64_t getOriginalTypeSize() const;
353 /// getObjCProperty - Return property node, if this ivar is
354 /// associated with one.
355 MDNode *getObjCProperty() const;
357 StringRef getObjCPropertyName() const {
358 if (getVersion() > LLVMDebugVersion11)
360 return getStringField(10);
362 StringRef getObjCPropertyGetterName() const {
363 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
364 return getStringField(11);
366 StringRef getObjCPropertySetterName() const {
367 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
368 return getStringField(12);
370 bool isReadOnlyObjCProperty() {
371 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
372 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
374 bool isReadWriteObjCProperty() {
375 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
376 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
378 bool isAssignObjCProperty() {
379 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
380 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
382 bool isRetainObjCProperty() {
383 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
384 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
386 bool isCopyObjCProperty() {
387 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
388 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
390 bool isNonAtomicObjCProperty() {
391 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
392 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
395 /// Verify - Verify that a derived type descriptor is well formed.
399 /// DICompositeType - This descriptor holds a type that can refer to multiple
400 /// other types, like a function or struct.
401 /// FIXME: Why is this a DIDerivedType??
402 class DICompositeType : public DIDerivedType {
403 friend class DIDescriptor;
404 void printInternal(raw_ostream &OS) const;
406 explicit DICompositeType(const MDNode *N = 0)
407 : DIDerivedType(N, true, true) {
408 if (N && !isCompositeType())
412 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
413 unsigned getRunTimeLang() const { return getUnsignedField(11); }
414 DICompositeType getContainingType() const {
415 return getFieldAs<DICompositeType>(12);
417 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
419 /// Verify - Verify that a composite type descriptor is well formed.
423 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
424 class DITemplateTypeParameter : public DIDescriptor {
426 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
428 DIScope getContext() const { return getFieldAs<DIScope>(1); }
429 StringRef getName() const { return getStringField(2); }
430 DIType getType() const { return getFieldAs<DIType>(3); }
431 StringRef getFilename() const {
432 return getFieldAs<DIFile>(4).getFilename();
434 StringRef getDirectory() const {
435 return getFieldAs<DIFile>(4).getDirectory();
437 unsigned getLineNumber() const { return getUnsignedField(5); }
438 unsigned getColumnNumber() const { return getUnsignedField(6); }
441 /// DITemplateValueParameter - This is a wrapper for template value parameter.
442 class DITemplateValueParameter : public DIDescriptor {
444 explicit DITemplateValueParameter(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 uint64_t getValue() const { return getUInt64Field(4); }
450 StringRef getFilename() const {
451 return getFieldAs<DIFile>(5).getFilename();
453 StringRef getDirectory() const {
454 return getFieldAs<DIFile>(5).getDirectory();
456 unsigned getLineNumber() const { return getUnsignedField(6); }
457 unsigned getColumnNumber() const { return getUnsignedField(7); }
460 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
461 class DISubprogram : public DIScope {
462 friend class DIDescriptor;
463 void printInternal(raw_ostream &OS) const;
465 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
467 DIScope getContext() const { return getFieldAs<DIScope>(2); }
468 StringRef getName() const { return getStringField(3); }
469 StringRef getDisplayName() const { return getStringField(4); }
470 StringRef getLinkageName() const { return getStringField(5); }
471 DICompileUnit getCompileUnit() const{
472 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
473 if (getVersion() == llvm::LLVMDebugVersion7)
474 return getFieldAs<DICompileUnit>(6);
476 return getFieldAs<DIFile>(6).getCompileUnit();
478 unsigned getLineNumber() const { return getUnsignedField(7); }
479 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
481 /// getReturnTypeName - Subprogram return types are encoded either as
482 /// DIType or as DICompositeType.
483 StringRef getReturnTypeName() const {
484 DICompositeType DCT(getFieldAs<DICompositeType>(8));
486 DIArray A = DCT.getTypeArray();
487 DIType T(A.getElement(0));
490 DIType T(getFieldAs<DIType>(8));
494 /// isLocalToUnit - Return true if this subprogram is local to the current
495 /// compile unit, like 'static' in C.
496 unsigned isLocalToUnit() const { return getUnsignedField(9); }
497 unsigned isDefinition() const { return getUnsignedField(10); }
499 unsigned getVirtuality() const { return getUnsignedField(11); }
500 unsigned getVirtualIndex() const { return getUnsignedField(12); }
502 DICompositeType getContainingType() const {
503 return getFieldAs<DICompositeType>(13);
506 unsigned isArtificial() const {
507 if (getVersion() <= llvm::LLVMDebugVersion8)
508 return getUnsignedField(14);
509 return (getUnsignedField(14) & FlagArtificial) != 0;
511 /// isPrivate - Return true if this subprogram has "private"
512 /// access specifier.
513 bool isPrivate() const {
514 if (getVersion() <= llvm::LLVMDebugVersion8)
516 return (getUnsignedField(14) & FlagPrivate) != 0;
518 /// isProtected - Return true if this subprogram has "protected"
519 /// access specifier.
520 bool isProtected() const {
521 if (getVersion() <= llvm::LLVMDebugVersion8)
523 return (getUnsignedField(14) & FlagProtected) != 0;
525 /// isExplicit - Return true if this subprogram is marked as explicit.
526 bool isExplicit() const {
527 if (getVersion() <= llvm::LLVMDebugVersion8)
529 return (getUnsignedField(14) & FlagExplicit) != 0;
531 /// isPrototyped - Return true if this subprogram is prototyped.
532 bool isPrototyped() const {
533 if (getVersion() <= llvm::LLVMDebugVersion8)
535 return (getUnsignedField(14) & FlagPrototyped) != 0;
538 unsigned isOptimized() const;
540 StringRef getFilename() const {
541 if (getVersion() == llvm::LLVMDebugVersion7)
542 return getCompileUnit().getFilename();
544 return getFieldAs<DIFile>(6).getFilename();
547 StringRef getDirectory() const {
548 if (getVersion() == llvm::LLVMDebugVersion7)
549 return getCompileUnit().getFilename();
551 return getFieldAs<DIFile>(6).getDirectory();
554 /// getScopeLineNumber - Get the beginning of the scope of the
555 /// function, not necessarily where the name of the program
557 unsigned getScopeLineNumber() const { return getUnsignedField(20); }
559 /// Verify - Verify that a subprogram descriptor is well formed.
562 /// describes - Return true if this subprogram provides debugging
563 /// information for the function F.
564 bool describes(const Function *F);
566 Function *getFunction() const { return getFunctionField(16); }
567 void replaceFunction(Function *F) { replaceFunctionField(16, F); }
568 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
569 DISubprogram getFunctionDeclaration() const {
570 return getFieldAs<DISubprogram>(18);
572 MDNode *getVariablesNodes() const;
573 DIArray getVariables() const;
576 /// DIGlobalVariable - This is a wrapper for a global variable.
577 class DIGlobalVariable : public DIDescriptor {
578 friend class DIDescriptor;
579 void printInternal(raw_ostream &OS) const;
581 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
583 DIScope getContext() const { return getFieldAs<DIScope>(2); }
584 StringRef getName() const { return getStringField(3); }
585 StringRef getDisplayName() const { return getStringField(4); }
586 StringRef getLinkageName() const { return getStringField(5); }
587 DICompileUnit getCompileUnit() const{
588 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
589 if (getVersion() == llvm::LLVMDebugVersion7)
590 return getFieldAs<DICompileUnit>(6);
592 DIFile F = getFieldAs<DIFile>(6);
593 return F.getCompileUnit();
595 StringRef getFilename() const {
596 if (getVersion() <= llvm::LLVMDebugVersion10)
597 return getContext().getFilename();
598 return getFieldAs<DIFile>(6).getFilename();
600 StringRef getDirectory() const {
601 if (getVersion() <= llvm::LLVMDebugVersion10)
602 return getContext().getDirectory();
603 return getFieldAs<DIFile>(6).getDirectory();
607 unsigned getLineNumber() const { return getUnsignedField(7); }
608 DIType getType() const { return getFieldAs<DIType>(8); }
609 unsigned isLocalToUnit() const { return getUnsignedField(9); }
610 unsigned isDefinition() const { return getUnsignedField(10); }
612 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
613 Constant *getConstant() const { return getConstantField(11); }
615 /// Verify - Verify that a global variable descriptor is well formed.
619 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
621 class DIVariable : public DIDescriptor {
622 friend class DIDescriptor;
623 void printInternal(raw_ostream &OS) const;
625 explicit DIVariable(const MDNode *N = 0)
628 DIScope getContext() const { return getFieldAs<DIScope>(1); }
629 StringRef getName() const { return getStringField(2); }
630 DICompileUnit getCompileUnit() const {
631 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
632 if (getVersion() == llvm::LLVMDebugVersion7)
633 return getFieldAs<DICompileUnit>(3);
635 DIFile F = getFieldAs<DIFile>(3);
636 return F.getCompileUnit();
638 unsigned getLineNumber() const {
639 return (getUnsignedField(4) << 8) >> 8;
641 unsigned getArgNumber() const {
642 unsigned L = getUnsignedField(4);
645 DIType getType() const { return getFieldAs<DIType>(5); }
647 /// isArtificial - Return true if this variable is marked as "artificial".
648 bool isArtificial() const {
649 if (getVersion() <= llvm::LLVMDebugVersion8)
651 return (getUnsignedField(6) & FlagArtificial) != 0;
654 bool isObjectPointer() const {
655 return (getUnsignedField(6) & FlagObjectPointer) != 0;
658 /// getInlinedAt - If this variable is inlined then return inline location.
659 MDNode *getInlinedAt() const;
661 /// Verify - Verify that a variable descriptor is well formed.
664 /// HasComplexAddr - Return true if the variable has a complex address.
665 bool hasComplexAddress() const {
666 return getNumAddrElements() > 0;
669 unsigned getNumAddrElements() const;
671 uint64_t getAddrElement(unsigned Idx) const {
672 if (getVersion() <= llvm::LLVMDebugVersion8)
673 return getUInt64Field(Idx+6);
674 if (getVersion() == llvm::LLVMDebugVersion9)
675 return getUInt64Field(Idx+7);
676 return getUInt64Field(Idx+8);
679 /// isBlockByrefVariable - Return true if the variable was declared as
680 /// a "__block" variable (Apple Blocks).
681 bool isBlockByrefVariable() const {
682 return getType().isBlockByrefStruct();
685 /// isInlinedFnArgument - Return trule if this variable provides debugging
686 /// information for an inlined function arguments.
687 bool isInlinedFnArgument(const Function *CurFn);
689 void printExtendedName(raw_ostream &OS) const;
692 /// DILexicalBlock - This is a wrapper for a lexical block.
693 class DILexicalBlock : public DIScope {
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 {
713 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
714 DIScope getContext() const { return getScope().getContext(); }
715 unsigned getLineNumber() const { return getScope().getLineNumber(); }
716 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
717 StringRef getDirectory() const {
718 StringRef dir = getFieldAs<DIFile>(2).getDirectory();
719 return !dir.empty() ? dir : getContext().getDirectory();
721 StringRef getFilename() const {
722 StringRef filename = getFieldAs<DIFile>(2).getFilename();
723 assert(!filename.empty() && "Why'd you create this then?");
726 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
729 /// DINameSpace - A wrapper for a C++ style name space.
730 class DINameSpace : public DIScope {
732 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
733 DIScope getContext() const { return getFieldAs<DIScope>(1); }
734 StringRef getName() const { return getStringField(2); }
735 StringRef getDirectory() const {
736 return getFieldAs<DIFile>(3).getDirectory();
738 StringRef getFilename() const {
739 return getFieldAs<DIFile>(3).getFilename();
741 DICompileUnit getCompileUnit() const{
742 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
743 if (getVersion() == llvm::LLVMDebugVersion7)
744 return getFieldAs<DICompileUnit>(3);
746 return getFieldAs<DIFile>(3).getCompileUnit();
748 unsigned getLineNumber() const { return getUnsignedField(4); }
752 /// DILocation - This object holds location information. This object
753 /// is not associated with any DWARF tag.
754 class DILocation : public DIDescriptor {
756 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
758 unsigned getLineNumber() const { return getUnsignedField(0); }
759 unsigned getColumnNumber() const { return getUnsignedField(1); }
760 DIScope getScope() const { return getFieldAs<DIScope>(2); }
761 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
762 StringRef getFilename() const { return getScope().getFilename(); }
763 StringRef getDirectory() const { return getScope().getDirectory(); }
767 class DIObjCProperty : public DIDescriptor {
768 friend class DIDescriptor;
769 void printInternal(raw_ostream &OS) const;
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(const 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(const 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