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"
45 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
46 /// This should not be stored in a container, because underly MDNode may
47 /// change in certain situations.
52 FlagProtected = 1 << 1,
54 FlagAppleBlock = 1 << 3,
55 FlagBlockByrefStruct = 1 << 4,
57 FlagArtificial = 1 << 6
60 const MDNode *DbgNode;
62 StringRef getStringField(unsigned Elt) const;
63 unsigned getUnsignedField(unsigned Elt) const {
64 return (unsigned)getUInt64Field(Elt);
66 uint64_t getUInt64Field(unsigned Elt) const;
67 DIDescriptor getDescriptorField(unsigned Elt) const;
69 template <typename DescTy>
70 DescTy getFieldAs(unsigned Elt) const {
71 return DescTy(getDescriptorField(Elt));
74 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
75 Constant *getConstantField(unsigned Elt) const;
76 Function *getFunctionField(unsigned Elt) const;
79 explicit DIDescriptor() : DbgNode(0) {}
80 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
81 explicit DIDescriptor(const DIFile F);
82 explicit DIDescriptor(const DISubprogram F);
83 explicit DIDescriptor(const DILexicalBlock F);
84 explicit DIDescriptor(const DIVariable F);
85 explicit DIDescriptor(const DIType F);
87 bool Verify() const { return DbgNode != 0; }
89 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
90 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
92 unsigned getVersion() const {
93 return getUnsignedField(0) & LLVMDebugVersionMask;
96 unsigned getTag() const {
97 return getUnsignedField(0) & ~LLVMDebugVersionMask;
100 /// print - print descriptor.
101 void print(raw_ostream &OS) const;
103 /// dump - print descriptor to dbgs() with a newline.
106 bool isDerivedType() const;
107 bool isCompositeType() const;
108 bool isBasicType() const;
109 bool isVariable() const;
110 bool isSubprogram() const;
111 bool isGlobalVariable() const;
112 bool isScope() const;
114 bool isCompileUnit() const;
115 bool isNameSpace() const;
116 bool isLexicalBlock() const;
117 bool isSubrange() const;
118 bool isEnumerator() const;
120 bool isGlobal() const;
123 /// DISubrange - This is used to represent ranges, for array bounds.
124 class DISubrange : public DIDescriptor {
126 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
128 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
129 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
132 /// DIArray - This descriptor holds an array of descriptors.
133 class DIArray : public DIDescriptor {
135 explicit DIArray(const MDNode *N = 0)
138 unsigned getNumElements() const;
139 DIDescriptor getElement(unsigned Idx) const {
140 return getDescriptorField(Idx);
144 /// DIScope - A base class for various scopes.
145 class DIScope : public DIDescriptor {
147 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
148 virtual ~DIScope() {}
150 StringRef getFilename() const;
151 StringRef getDirectory() const;
154 /// DICompileUnit - A wrapper for a compile unit.
155 class DICompileUnit : public DIScope {
157 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
159 unsigned getLanguage() const { return getUnsignedField(2); }
160 StringRef getFilename() const { return getStringField(3); }
161 StringRef getDirectory() const { return getStringField(4); }
162 StringRef getProducer() const { return getStringField(5); }
164 /// isMain - Each input file is encoded as a separate compile unit in LLVM
165 /// debugging information output. However, many target specific tool chains
166 /// prefer to encode only one compile unit in an object file. In this
167 /// situation, the LLVM code generator will include debugging information
168 /// entities in the compile unit that is marked as main compile unit. The
169 /// code generator accepts maximum one main compile unit per module. If a
170 /// module does not contain any main compile unit then the code generator
171 /// will emit multiple compile units in the output object file.
173 bool isMain() const { return getUnsignedField(6) != 0; }
174 bool isOptimized() const { return getUnsignedField(7) != 0; }
175 StringRef getFlags() const { return getStringField(8); }
176 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
178 /// Verify - Verify that a compile unit is well formed.
181 /// print - print compile unit.
182 void print(raw_ostream &OS) const;
184 /// dump - print compile unit to dbgs() with a newline.
188 /// DIFile - This is a wrapper for a file.
189 class DIFile : public DIScope {
191 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
192 if (DbgNode && !isFile())
195 StringRef getFilename() const { return getStringField(1); }
196 StringRef getDirectory() const { return getStringField(2); }
197 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
200 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
201 /// FIXME: it seems strange that this doesn't have either a reference to the
202 /// type/precision or a file/line pair for location info.
203 class DIEnumerator : public DIDescriptor {
205 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
207 StringRef getName() const { return getStringField(1); }
208 uint64_t getEnumValue() const { return getUInt64Field(2); }
211 /// DIType - This is a wrapper for a type.
212 /// FIXME: Types should be factored much better so that CV qualifiers and
213 /// others do not require a huge and empty descriptor full of zeros.
214 class DIType : public DIScope {
217 // This ctor is used when the Tag has already been validated by a derived
219 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
223 /// Verify - Verify that a type descriptor is well formed.
226 explicit DIType(const MDNode *N);
230 DIScope getContext() const { return getFieldAs<DIScope>(1); }
231 StringRef getName() const { return getStringField(2); }
232 DICompileUnit getCompileUnit() const{
233 if (getVersion() == llvm::LLVMDebugVersion7)
234 return getFieldAs<DICompileUnit>(3);
236 DIFile F = getFieldAs<DIFile>(3);
237 return F.getCompileUnit();
239 unsigned getLineNumber() const { return getUnsignedField(4); }
240 uint64_t getSizeInBits() const { return getUInt64Field(5); }
241 uint64_t getAlignInBits() const { return getUInt64Field(6); }
242 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
243 // carry this is just plain insane.
244 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
245 unsigned getFlags() const { return getUnsignedField(8); }
246 bool isPrivate() const {
247 return (getFlags() & FlagPrivate) != 0;
249 bool isProtected() const {
250 return (getFlags() & FlagProtected) != 0;
252 bool isForwardDecl() const {
253 return (getFlags() & FlagFwdDecl) != 0;
255 // isAppleBlock - Return true if this is the Apple Blocks extension.
256 bool isAppleBlockExtension() const {
257 return (getFlags() & FlagAppleBlock) != 0;
259 bool isBlockByrefStruct() const {
260 return (getFlags() & FlagBlockByrefStruct) != 0;
262 bool isVirtual() const {
263 return (getFlags() & FlagVirtual) != 0;
265 bool isArtificial() const {
266 return (getFlags() & FlagArtificial) != 0;
268 bool isValid() const {
269 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
271 StringRef getFilename() const { return getCompileUnit().getFilename();}
272 StringRef getDirectory() const { return getCompileUnit().getDirectory();}
274 /// replaceAllUsesWith - Replace all uses of debug info referenced by
276 void replaceAllUsesWith(DIDescriptor &D);
278 /// print - print type.
279 void print(raw_ostream &OS) const;
281 /// dump - print type to dbgs() with a newline.
285 /// DIBasicType - A basic type, like 'int' or 'float'.
286 class DIBasicType : public DIType {
288 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
290 unsigned getEncoding() const { return getUnsignedField(9); }
292 /// Verify - Verify that a basic type descriptor is well formed.
295 /// print - print basic type.
296 void print(raw_ostream &OS) const;
298 /// dump - print basic type to dbgs() with a newline.
302 /// DIDerivedType - A simple derived type, like a const qualified type,
303 /// a typedef, a pointer or reference, etc.
304 class DIDerivedType : public DIType {
306 explicit DIDerivedType(const MDNode *N, bool, bool)
307 : DIType(N, true, true) {}
309 explicit DIDerivedType(const MDNode *N = 0)
310 : DIType(N, true, true) {}
312 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
314 /// getOriginalTypeSize - If this type is derived from a base type then
315 /// return base type size.
316 uint64_t getOriginalTypeSize() const;
318 /// Verify - Verify that a derived type descriptor is well formed.
321 /// print - print derived type.
322 void print(raw_ostream &OS) const;
324 /// dump - print derived type to dbgs() with a newline.
328 /// DICompositeType - This descriptor holds a type that can refer to multiple
329 /// other types, like a function or struct.
330 /// FIXME: Why is this a DIDerivedType??
331 class DICompositeType : public DIDerivedType {
333 explicit DICompositeType(const MDNode *N = 0)
334 : DIDerivedType(N, true, true) {
335 if (N && !isCompositeType())
339 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
340 unsigned getRunTimeLang() const { return getUnsignedField(11); }
341 DICompositeType getContainingType() const {
342 return getFieldAs<DICompositeType>(12);
345 /// Verify - Verify that a composite type descriptor is well formed.
348 /// print - print composite type.
349 void print(raw_ostream &OS) const;
351 /// dump - print composite type to dbgs() with a newline.
355 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
356 class DISubprogram : public DIScope {
358 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
360 DIScope getContext() const { return getFieldAs<DIScope>(2); }
361 StringRef getName() const { return getStringField(3); }
362 StringRef getDisplayName() const { return getStringField(4); }
363 StringRef getLinkageName() const { return getStringField(5); }
364 DICompileUnit getCompileUnit() const{
365 if (getVersion() == llvm::LLVMDebugVersion7)
366 return getFieldAs<DICompileUnit>(6);
368 DIFile F = getFieldAs<DIFile>(6);
369 return F.getCompileUnit();
371 unsigned getLineNumber() const { return getUnsignedField(7); }
372 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
374 /// getReturnTypeName - Subprogram return types are encoded either as
375 /// DIType or as DICompositeType.
376 StringRef getReturnTypeName() const {
377 DICompositeType DCT(getFieldAs<DICompositeType>(8));
379 DIArray A = DCT.getTypeArray();
380 DIType T(A.getElement(0));
383 DIType T(getFieldAs<DIType>(8));
387 /// isLocalToUnit - Return true if this subprogram is local to the current
388 /// compile unit, like 'static' in C.
389 unsigned isLocalToUnit() const { return getUnsignedField(9); }
390 unsigned isDefinition() const { return getUnsignedField(10); }
392 unsigned getVirtuality() const { return getUnsignedField(11); }
393 unsigned getVirtualIndex() const { return getUnsignedField(12); }
395 DICompositeType getContainingType() const {
396 return getFieldAs<DICompositeType>(13);
398 unsigned isArtificial() const {
399 if (getVersion() <= llvm::LLVMDebugVersion8)
400 return getUnsignedField(14);
401 return (getUnsignedField(14) & FlagArtificial) != 0;
403 /// isPrivate - Return true if this subprogram has "private"
404 /// access specifier.
405 bool isPrivate() const {
406 if (getVersion() <= llvm::LLVMDebugVersion8)
408 return (getUnsignedField(14) & FlagPrivate) != 0;
410 /// isProtected - Return true if this subprogram has "protected"
411 /// access specifier.
412 bool isProtected() const {
413 if (getVersion() <= llvm::LLVMDebugVersion8)
415 return (getUnsignedField(14) & FlagProtected) != 0;
417 unsigned isOptimized() const;
419 StringRef getFilename() const {
420 if (getVersion() == llvm::LLVMDebugVersion7)
421 return getCompileUnit().getFilename();
423 DIFile F = getFieldAs<DIFile>(6);
424 return F.getFilename();
427 StringRef getDirectory() const {
428 if (getVersion() == llvm::LLVMDebugVersion7)
429 return getCompileUnit().getFilename();
431 DIFile F = getFieldAs<DIFile>(6);
432 return F.getDirectory();
435 /// Verify - Verify that a subprogram descriptor is well formed.
438 /// print - print subprogram.
439 void print(raw_ostream &OS) const;
441 /// dump - print subprogram to dbgs() with a newline.
444 /// describes - Return true if this subprogram provides debugging
445 /// information for the function F.
446 bool describes(const Function *F);
448 Function *getFunction() const { return getFunctionField(16); }
451 /// DIGlobalVariable - This is a wrapper for a global variable.
452 class DIGlobalVariable : public DIDescriptor {
454 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
456 DIScope getContext() const { return getFieldAs<DIScope>(2); }
457 StringRef getName() const { return getStringField(3); }
458 StringRef getDisplayName() const { return getStringField(4); }
459 StringRef getLinkageName() const { return getStringField(5); }
460 DICompileUnit getCompileUnit() const{
461 if (getVersion() == llvm::LLVMDebugVersion7)
462 return getFieldAs<DICompileUnit>(6);
464 DIFile F = getFieldAs<DIFile>(6);
465 return F.getCompileUnit();
468 unsigned getLineNumber() const { return getUnsignedField(7); }
469 DIType getType() const { return getFieldAs<DIType>(8); }
470 unsigned isLocalToUnit() const { return getUnsignedField(9); }
471 unsigned isDefinition() const { return getUnsignedField(10); }
473 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
474 Constant *getConstant() const { return getConstantField(11); }
476 /// Verify - Verify that a global variable descriptor is well formed.
479 /// print - print global variable.
480 void print(raw_ostream &OS) const;
482 /// dump - print global variable to dbgs() with a newline.
486 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
488 class DIVariable : public DIDescriptor {
490 explicit DIVariable(const MDNode *N = 0)
493 DIScope getContext() const { return getFieldAs<DIScope>(1); }
494 StringRef getName() const { return getStringField(2); }
495 DICompileUnit getCompileUnit() const{
496 if (getVersion() == llvm::LLVMDebugVersion7)
497 return getFieldAs<DICompileUnit>(3);
499 DIFile F = getFieldAs<DIFile>(3);
500 return F.getCompileUnit();
502 unsigned getLineNumber() const { return getUnsignedField(4); }
503 DIType getType() const { return getFieldAs<DIType>(5); }
506 /// Verify - Verify that a variable descriptor is well formed.
509 /// HasComplexAddr - Return true if the variable has a complex address.
510 bool hasComplexAddress() const {
511 return getNumAddrElements() > 0;
514 unsigned getNumAddrElements() const;
516 uint64_t getAddrElement(unsigned Idx) const {
517 return getUInt64Field(Idx+6);
520 /// isBlockByrefVariable - Return true if the variable was declared as
521 /// a "__block" variable (Apple Blocks).
522 bool isBlockByrefVariable() const {
523 return getType().isBlockByrefStruct();
526 /// isInlinedFnArgument - Return trule if this variable provides debugging
527 /// information for an inlined function arguments.
528 bool isInlinedFnArgument(const Function *CurFn);
530 /// print - print variable.
531 void print(raw_ostream &OS) const;
533 /// dump - print variable to dbgs() with a newline.
537 /// DILexicalBlock - This is a wrapper for a lexical block.
538 class DILexicalBlock : public DIScope {
540 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
541 DIScope getContext() const { return getFieldAs<DIScope>(1); }
542 unsigned getLineNumber() const { return getUnsignedField(2); }
543 unsigned getColumnNumber() const { return getUnsignedField(3); }
544 StringRef getDirectory() const {
545 DIFile F = getFieldAs<DIFile>(4);
546 StringRef dir = F.getDirectory();
547 return !dir.empty() ? dir : getContext().getDirectory();
549 StringRef getFilename() const {
550 DIFile F = getFieldAs<DIFile>(4);
551 StringRef filename = F.getFilename();
552 return !filename.empty() ? filename : getContext().getFilename();
556 /// DINameSpace - A wrapper for a C++ style name space.
557 class DINameSpace : public DIScope {
559 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
560 DIScope getContext() const { return getFieldAs<DIScope>(1); }
561 StringRef getName() const { return getStringField(2); }
562 StringRef getDirectory() const { return getContext().getDirectory(); }
563 StringRef getFilename() const { return getContext().getFilename(); }
564 DICompileUnit getCompileUnit() const{
565 if (getVersion() == llvm::LLVMDebugVersion7)
566 return getFieldAs<DICompileUnit>(3);
568 DIFile F = getFieldAs<DIFile>(3);
569 return F.getCompileUnit();
571 unsigned getLineNumber() const { return getUnsignedField(4); }
575 /// DILocation - This object holds location information. This object
576 /// is not associated with any DWARF tag.
577 class DILocation : public DIDescriptor {
579 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
581 unsigned getLineNumber() const { return getUnsignedField(0); }
582 unsigned getColumnNumber() const { return getUnsignedField(1); }
583 DIScope getScope() const { return getFieldAs<DIScope>(2); }
584 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
585 StringRef getFilename() const { return getScope().getFilename(); }
586 StringRef getDirectory() const { return getScope().getDirectory(); }
590 /// DIFactory - This object assists with the construction of the various
594 LLVMContext& VMContext;
596 Function *DeclareFn; // llvm.dbg.declare
597 Function *ValueFn; // llvm.dbg.value
599 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
600 void operator=(const DIFactory&); // DO NOT IMPLEMENT
602 enum ComplexAddrKind { OpPlus=1, OpDeref };
604 explicit DIFactory(Module &m);
606 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
607 /// This implicitly uniques the arrays created.
608 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
610 /// GetOrCreateSubrange - Create a descriptor for a value range. This
611 /// implicitly uniques the values returned.
612 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
614 /// CreateCompileUnit - Create a new descriptor for the specified compile
616 DICompileUnit CreateCompileUnit(unsigned LangID,
621 bool isOptimized = false,
622 StringRef Flags = "",
623 unsigned RunTimeVer = 0);
625 /// CreateFile - Create a new descriptor for the specified file.
626 DIFile CreateFile(StringRef Filename, StringRef Directory,
629 /// CreateEnumerator - Create a single enumerator value.
630 DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val);
632 /// CreateBasicType - Create a basic type like int, float, etc.
633 DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name,
634 DIFile F, unsigned LineNumber,
635 uint64_t SizeInBits, uint64_t AlignInBits,
636 uint64_t OffsetInBits, unsigned Flags,
639 /// CreateBasicType - Create a basic type like int, float, etc.
640 DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name,
641 DIFile F, unsigned LineNumber,
642 Constant *SizeInBits, Constant *AlignInBits,
643 Constant *OffsetInBits, unsigned Flags,
646 /// CreateDerivedType - Create a derived type like const qualified type,
647 /// pointer, typedef, etc.
648 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
652 uint64_t SizeInBits, uint64_t AlignInBits,
653 uint64_t OffsetInBits, unsigned Flags,
656 /// CreateDerivedType - Create a derived type like const qualified type,
657 /// pointer, typedef, etc.
658 DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
662 Constant *SizeInBits,
663 Constant *AlignInBits,
664 Constant *OffsetInBits, unsigned Flags,
667 /// CreateCompositeType - Create a composite type like array, struct, etc.
668 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
673 uint64_t AlignInBits,
674 uint64_t OffsetInBits, unsigned Flags,
677 unsigned RunTimeLang = 0,
678 MDNode *ContainingType = 0);
680 /// CreateTemporaryType - Create a temporary forward-declared type.
681 DIType CreateTemporaryType();
683 /// CreateArtificialType - Create a new DIType with "artificial" flag set.
684 DIType CreateArtificialType(DIType Ty);
686 /// CreateCompositeType - Create a composite type like array, struct, etc.
687 DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
691 Constant *SizeInBits,
692 Constant *AlignInBits,
693 Constant *OffsetInBits,
697 unsigned RunTimeLang = 0,
698 MDNode *ContainingType = 0);
700 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
701 /// See comments in DISubprogram for descriptions of these fields.
702 DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
703 StringRef DisplayName,
704 StringRef LinkageName,
705 DIFile F, unsigned LineNo,
706 DIType Ty, bool isLocalToUnit,
712 bool isOptimized = false,
715 /// CreateSubprogramDefinition - Create new subprogram descriptor for the
716 /// given declaration.
717 DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
719 /// CreateGlobalVariable - Create a new descriptor for the specified global.
721 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
722 StringRef DisplayName,
723 StringRef LinkageName,
725 unsigned LineNo, DIType Ty, bool isLocalToUnit,
726 bool isDefinition, llvm::GlobalVariable *GV);
728 /// CreateGlobalVariable - Create a new descriptor for the specified constant.
730 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
731 StringRef DisplayName,
732 StringRef LinkageName,
734 unsigned LineNo, DIType Ty, bool isLocalToUnit,
735 bool isDefinition, llvm::Constant *C);
737 /// CreateVariable - Create a new descriptor for the specified variable.
738 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
740 DIFile F, unsigned LineNo,
741 DIType Ty, bool AlwaysPreserve = false);
743 /// CreateComplexVariable - Create a new descriptor for the specified
744 /// variable which has a complex address expression for its address.
745 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
746 StringRef Name, DIFile F, unsigned LineNo,
747 DIType Ty, Value *const *Addr,
750 /// CreateLexicalBlock - This creates a descriptor for a lexical block
751 /// with the specified parent context.
752 DILexicalBlock CreateLexicalBlock(DIDescriptor Context, DIFile F,
753 unsigned Line = 0, unsigned Col = 0);
755 /// CreateNameSpace - This creates new descriptor for a namespace
756 /// with the specified parent context.
757 DINameSpace CreateNameSpace(DIDescriptor Context, StringRef Name,
758 DIFile F, unsigned LineNo);
760 /// CreateLocation - Creates a debug info location.
761 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
762 DIScope S, DILocation OrigLoc);
764 /// CreateLocation - Creates a debug info location.
765 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
766 DIScope S, MDNode *OrigLoc = 0);
768 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
769 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
770 BasicBlock *InsertAtEnd);
772 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
773 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
774 Instruction *InsertBefore);
776 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
777 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
778 DIVariable D, BasicBlock *InsertAtEnd);
780 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
781 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
782 DIVariable D, Instruction *InsertBefore);
784 // RecordType - Record DIType in a module such that it is not lost even if
785 // it is not referenced through debug info anchors.
786 void RecordType(DIType T);
789 Constant *GetTagConstant(unsigned TAG);
792 bool getLocationInfo(const Value *V, std::string &DisplayName,
793 std::string &Type, unsigned &LineNo, std::string &File,
796 /// getDISubprogram - Find subprogram that is enclosing this scope.
797 DISubprogram getDISubprogram(const MDNode *Scope);
799 /// getDICompositeType - Find underlying composite type.
800 DICompositeType getDICompositeType(DIType T);
802 class DebugInfoFinder {
804 /// processModule - Process entire module and collect debug info
806 void processModule(Module &M);
809 /// processType - Process DIType.
810 void processType(DIType DT);
812 /// processLexicalBlock - Process DILexicalBlock.
813 void processLexicalBlock(DILexicalBlock LB);
815 /// processSubprogram - Process DISubprogram.
816 void processSubprogram(DISubprogram SP);
818 /// processDeclare - Process DbgDeclareInst.
819 void processDeclare(DbgDeclareInst *DDI);
821 /// processLocation - Process DILocation.
822 void processLocation(DILocation Loc);
824 /// addCompileUnit - Add compile unit into CUs.
825 bool addCompileUnit(DICompileUnit CU);
827 /// addGlobalVariable - Add global variable into GVs.
828 bool addGlobalVariable(DIGlobalVariable DIG);
830 // addSubprogram - Add subprgoram into SPs.
831 bool addSubprogram(DISubprogram SP);
833 /// addType - Add type into Tys.
834 bool addType(DIType DT);
837 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
838 iterator compile_unit_begin() const { return CUs.begin(); }
839 iterator compile_unit_end() const { return CUs.end(); }
840 iterator subprogram_begin() const { return SPs.begin(); }
841 iterator subprogram_end() const { return SPs.end(); }
842 iterator global_variable_begin() const { return GVs.begin(); }
843 iterator global_variable_end() const { return GVs.end(); }
844 iterator type_begin() const { return TYs.begin(); }
845 iterator type_end() const { return TYs.end(); }
847 unsigned compile_unit_count() const { return CUs.size(); }
848 unsigned global_variable_count() const { return GVs.size(); }
849 unsigned subprogram_count() const { return SPs.size(); }
850 unsigned type_count() const { return TYs.size(); }
853 SmallVector<MDNode *, 8> CUs; // Compile Units
854 SmallVector<MDNode *, 8> SPs; // Subprograms
855 SmallVector<MDNode *, 8> GVs; // Global Variables;
856 SmallVector<MDNode *, 8> TYs; // Types
857 SmallPtrSet<MDNode *, 64> NodesSeen;
859 } // end namespace llvm