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); }
505 /// isArtificial - Return true if this variable is marked as "artificial".
506 bool isArtificial() const {
507 if (getVersion() <= llvm::LLVMDebugVersion8)
509 return (getUnsignedField(6) & FlagArtificial) != 0;
513 /// Verify - Verify that a variable descriptor is well formed.
516 /// HasComplexAddr - Return true if the variable has a complex address.
517 bool hasComplexAddress() const {
518 return getNumAddrElements() > 0;
521 unsigned getNumAddrElements() const;
523 uint64_t getAddrElement(unsigned Idx) const {
524 return getUInt64Field(Idx+6);
527 /// isBlockByrefVariable - Return true if the variable was declared as
528 /// a "__block" variable (Apple Blocks).
529 bool isBlockByrefVariable() const {
530 return getType().isBlockByrefStruct();
533 /// isInlinedFnArgument - Return trule if this variable provides debugging
534 /// information for an inlined function arguments.
535 bool isInlinedFnArgument(const Function *CurFn);
537 /// print - print variable.
538 void print(raw_ostream &OS) const;
540 /// dump - print variable to dbgs() with a newline.
544 /// DILexicalBlock - This is a wrapper for a lexical block.
545 class DILexicalBlock : public DIScope {
547 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
548 DIScope getContext() const { return getFieldAs<DIScope>(1); }
549 unsigned getLineNumber() const { return getUnsignedField(2); }
550 unsigned getColumnNumber() const { return getUnsignedField(3); }
551 StringRef getDirectory() const {
552 DIFile F = getFieldAs<DIFile>(4);
553 StringRef dir = F.getDirectory();
554 return !dir.empty() ? dir : getContext().getDirectory();
556 StringRef getFilename() const {
557 DIFile F = getFieldAs<DIFile>(4);
558 StringRef filename = F.getFilename();
559 return !filename.empty() ? filename : getContext().getFilename();
563 /// DINameSpace - A wrapper for a C++ style name space.
564 class DINameSpace : public DIScope {
566 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
567 DIScope getContext() const { return getFieldAs<DIScope>(1); }
568 StringRef getName() const { return getStringField(2); }
569 StringRef getDirectory() const { return getContext().getDirectory(); }
570 StringRef getFilename() const { return getContext().getFilename(); }
571 DICompileUnit getCompileUnit() const{
572 if (getVersion() == llvm::LLVMDebugVersion7)
573 return getFieldAs<DICompileUnit>(3);
575 DIFile F = getFieldAs<DIFile>(3);
576 return F.getCompileUnit();
578 unsigned getLineNumber() const { return getUnsignedField(4); }
582 /// DILocation - This object holds location information. This object
583 /// is not associated with any DWARF tag.
584 class DILocation : public DIDescriptor {
586 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
588 unsigned getLineNumber() const { return getUnsignedField(0); }
589 unsigned getColumnNumber() const { return getUnsignedField(1); }
590 DIScope getScope() const { return getFieldAs<DIScope>(2); }
591 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
592 StringRef getFilename() const { return getScope().getFilename(); }
593 StringRef getDirectory() const { return getScope().getDirectory(); }
597 /// DIFactory - This object assists with the construction of the various
601 LLVMContext& VMContext;
603 Function *DeclareFn; // llvm.dbg.declare
604 Function *ValueFn; // llvm.dbg.value
606 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
607 void operator=(const DIFactory&); // DO NOT IMPLEMENT
609 enum ComplexAddrKind { OpPlus=1, OpDeref };
611 explicit DIFactory(Module &m);
613 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
614 /// This implicitly uniques the arrays created.
615 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
617 /// GetOrCreateSubrange - Create a descriptor for a value range. This
618 /// implicitly uniques the values returned.
619 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
621 /// CreateCompileUnit - Create a new descriptor for the specified compile
623 DICompileUnit CreateCompileUnit(unsigned LangID,
628 bool isOptimized = false,
629 StringRef Flags = "",
630 unsigned RunTimeVer = 0);
632 /// CreateFile - Create a new descriptor for the specified file.
633 DIFile CreateFile(StringRef Filename, StringRef Directory,
636 /// CreateEnumerator - Create a single enumerator value.
637 DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val);
639 /// CreateBasicType - Create a basic type like int, float, etc.
640 DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name,
641 DIFile F, unsigned LineNumber,
642 uint64_t SizeInBits, uint64_t AlignInBits,
643 uint64_t OffsetInBits, unsigned Flags,
646 /// CreateBasicType - Create a basic type like int, float, etc.
647 DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name,
648 DIFile F, unsigned LineNumber,
649 Constant *SizeInBits, Constant *AlignInBits,
650 Constant *OffsetInBits, unsigned Flags,
653 /// CreateDerivedType - Create a derived type like const qualified type,
654 /// pointer, typedef, etc.
655 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
659 uint64_t SizeInBits, uint64_t AlignInBits,
660 uint64_t OffsetInBits, unsigned Flags,
663 /// CreateDerivedType - Create a derived type like const qualified type,
664 /// pointer, typedef, etc.
665 DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
669 Constant *SizeInBits,
670 Constant *AlignInBits,
671 Constant *OffsetInBits, unsigned Flags,
674 /// CreateCompositeType - Create a composite type like array, struct, etc.
675 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
680 uint64_t AlignInBits,
681 uint64_t OffsetInBits, unsigned Flags,
684 unsigned RunTimeLang = 0,
685 MDNode *ContainingType = 0);
687 /// CreateTemporaryType - Create a temporary forward-declared type.
688 DIType CreateTemporaryType();
690 /// CreateArtificialType - Create a new DIType with "artificial" flag set.
691 DIType CreateArtificialType(DIType Ty);
693 /// CreateCompositeType - Create a composite type like array, struct, etc.
694 DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
698 Constant *SizeInBits,
699 Constant *AlignInBits,
700 Constant *OffsetInBits,
704 unsigned RunTimeLang = 0,
705 MDNode *ContainingType = 0);
707 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
708 /// See comments in DISubprogram for descriptions of these fields.
709 DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
710 StringRef DisplayName,
711 StringRef LinkageName,
712 DIFile F, unsigned LineNo,
713 DIType Ty, bool isLocalToUnit,
719 bool isOptimized = false,
722 /// CreateSubprogramDefinition - Create new subprogram descriptor for the
723 /// given declaration.
724 DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
726 /// CreateGlobalVariable - Create a new descriptor for the specified global.
728 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
729 StringRef DisplayName,
730 StringRef LinkageName,
732 unsigned LineNo, DIType Ty, bool isLocalToUnit,
733 bool isDefinition, llvm::GlobalVariable *GV);
735 /// CreateGlobalVariable - Create a new descriptor for the specified constant.
737 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
738 StringRef DisplayName,
739 StringRef LinkageName,
741 unsigned LineNo, DIType Ty, bool isLocalToUnit,
742 bool isDefinition, llvm::Constant *C);
744 /// CreateVariable - Create a new descriptor for the specified variable.
745 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
747 DIFile F, unsigned LineNo,
748 DIType Ty, bool AlwaysPreserve = false,
751 /// CreateComplexVariable - Create a new descriptor for the specified
752 /// variable which has a complex address expression for its address.
753 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
754 StringRef Name, DIFile F, unsigned LineNo,
755 DIType Ty, Value *const *Addr,
758 /// CreateLexicalBlock - This creates a descriptor for a lexical block
759 /// with the specified parent context.
760 DILexicalBlock CreateLexicalBlock(DIDescriptor Context, DIFile F,
761 unsigned Line = 0, unsigned Col = 0);
763 /// CreateNameSpace - This creates new descriptor for a namespace
764 /// with the specified parent context.
765 DINameSpace CreateNameSpace(DIDescriptor Context, StringRef Name,
766 DIFile F, unsigned LineNo);
768 /// CreateLocation - Creates a debug info location.
769 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
770 DIScope S, DILocation OrigLoc);
772 /// CreateLocation - Creates a debug info location.
773 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
774 DIScope S, MDNode *OrigLoc = 0);
776 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
777 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
778 BasicBlock *InsertAtEnd);
780 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
781 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
782 Instruction *InsertBefore);
784 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
785 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
786 DIVariable D, BasicBlock *InsertAtEnd);
788 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
789 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
790 DIVariable D, Instruction *InsertBefore);
792 // RecordType - Record DIType in a module such that it is not lost even if
793 // it is not referenced through debug info anchors.
794 void RecordType(DIType T);
797 Constant *GetTagConstant(unsigned TAG);
800 bool getLocationInfo(const Value *V, std::string &DisplayName,
801 std::string &Type, unsigned &LineNo, std::string &File,
804 /// getDISubprogram - Find subprogram that is enclosing this scope.
805 DISubprogram getDISubprogram(const MDNode *Scope);
807 /// getDICompositeType - Find underlying composite type.
808 DICompositeType getDICompositeType(DIType T);
810 class DebugInfoFinder {
812 /// processModule - Process entire module and collect debug info
814 void processModule(Module &M);
817 /// processType - Process DIType.
818 void processType(DIType DT);
820 /// processLexicalBlock - Process DILexicalBlock.
821 void processLexicalBlock(DILexicalBlock LB);
823 /// processSubprogram - Process DISubprogram.
824 void processSubprogram(DISubprogram SP);
826 /// processDeclare - Process DbgDeclareInst.
827 void processDeclare(DbgDeclareInst *DDI);
829 /// processLocation - Process DILocation.
830 void processLocation(DILocation Loc);
832 /// addCompileUnit - Add compile unit into CUs.
833 bool addCompileUnit(DICompileUnit CU);
835 /// addGlobalVariable - Add global variable into GVs.
836 bool addGlobalVariable(DIGlobalVariable DIG);
838 // addSubprogram - Add subprgoram into SPs.
839 bool addSubprogram(DISubprogram SP);
841 /// addType - Add type into Tys.
842 bool addType(DIType DT);
845 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
846 iterator compile_unit_begin() const { return CUs.begin(); }
847 iterator compile_unit_end() const { return CUs.end(); }
848 iterator subprogram_begin() const { return SPs.begin(); }
849 iterator subprogram_end() const { return SPs.end(); }
850 iterator global_variable_begin() const { return GVs.begin(); }
851 iterator global_variable_end() const { return GVs.end(); }
852 iterator type_begin() const { return TYs.begin(); }
853 iterator type_end() const { return TYs.end(); }
855 unsigned compile_unit_count() const { return CUs.size(); }
856 unsigned global_variable_count() const { return GVs.size(); }
857 unsigned subprogram_count() const { return SPs.size(); }
858 unsigned type_count() const { return TYs.size(); }
861 SmallVector<MDNode *, 8> CUs; // Compile Units
862 SmallVector<MDNode *, 8> SPs; // Subprograms
863 SmallVector<MDNode *, 8> GVs; // Global Variables;
864 SmallVector<MDNode *, 8> TYs; // Types
865 SmallPtrSet<MDNode *, 64> NodesSeen;
867 } // end namespace llvm