1 //===-- llvm/CodeGen/MachineDebugInfo.h -------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by James M. Laskey and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Collect debug information for a module. This information should be in a
11 // neutral form that can be used by different debugging schemes.
13 // The organization of information is primarily clustered around the source
14 // compile units. The main exception is source line correspondence where
15 // inlining may interleave code from various compile units.
17 // The following information can be retrieved from the MachineDebugInfo.
19 // -- Source directories - Directories are uniqued based on their canonical
20 // string and assigned a sequential numeric ID (base 1.)
21 // -- Source files - Files are also uniqued based on their name and directory
22 // ID. A file ID is sequential number (base 1.)
23 // -- Source line correspondence - A vector of file ID, line#, column# triples.
24 // A DEBUG_LOCATION instruction is generated by the DAG Legalizer
25 // corresponding to each entry in the source line list. This allows a debug
26 // emitter to generate labels referenced by debug information tables.
28 //===----------------------------------------------------------------------===//
30 #ifndef LLVM_CODEGEN_MACHINEDEBUGINFO_H
31 #define LLVM_CODEGEN_MACHINEDEBUGINFO_H
33 #include "llvm/Support/Dwarf.h"
34 #include "llvm/Support/DataTypes.h"
35 #include "llvm/ADT/UniqueVector.h"
36 #include "llvm/GlobalValue.h"
37 #include "llvm/Pass.h"
41 //===----------------------------------------------------------------------===//
42 // Forward declarations.
46 class MachineFunction;
52 //===----------------------------------------------------------------------===//
53 // Debug info constants.
56 LLVMDebugVersion = (6 << 16), // Current version of debug information.
57 LLVMDebugVersion5 = (5 << 16), // Constant for version 5.
58 LLVMDebugVersion4 = (4 << 16), // Constant for version 4.
59 LLVMDebugVersionMask = 0xffff0000 // Mask for version number.
62 //===----------------------------------------------------------------------===//
63 /// DIVisitor - Subclasses of this class apply steps to each of the fields in
64 /// the supplied DebugInfoDesc.
68 virtual ~DIVisitor() {}
70 /// ApplyToFields - Target the visitor to each field of the debug information
72 void ApplyToFields(DebugInfoDesc *DD);
74 /// Apply - Subclasses override each of these methods to perform the
75 /// appropriate action for the type of field.
76 virtual void Apply(int &Field) = 0;
77 virtual void Apply(unsigned &Field) = 0;
78 virtual void Apply(int64_t &Field) = 0;
79 virtual void Apply(uint64_t &Field) = 0;
80 virtual void Apply(bool &Field) = 0;
81 virtual void Apply(std::string &Field) = 0;
82 virtual void Apply(DebugInfoDesc *&Field) = 0;
83 virtual void Apply(GlobalVariable *&Field) = 0;
84 virtual void Apply(std::vector<DebugInfoDesc *> &Field) = 0;
87 //===----------------------------------------------------------------------===//
88 /// DebugInfoDesc - This class is the base class for debug info descriptors.
92 unsigned Tag; // Content indicator. Dwarf values are
93 // used but that does not limit use to
97 DebugInfoDesc(unsigned T) : Tag(T | LLVMDebugVersion) {}
100 virtual ~DebugInfoDesc() {}
103 unsigned getTag() const { return Tag & ~LLVMDebugVersionMask; }
104 unsigned getVersion() const { return Tag & LLVMDebugVersionMask; }
105 void setTag(unsigned T) { Tag = T | LLVMDebugVersion; }
107 /// TagFromGlobal - Returns the tag number from a debug info descriptor
108 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
109 static unsigned TagFromGlobal(GlobalVariable *GV);
111 /// VersionFromGlobal - Returns the version number from a debug info
112 /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned
114 static unsigned VersionFromGlobal(GlobalVariable *GV);
116 /// DescFactory - Create an instance of debug info descriptor based on Tag.
117 /// Return NULL if not a recognized Tag.
118 static DebugInfoDesc *DescFactory(unsigned Tag);
120 /// getLinkage - get linkage appropriate for this type of descriptor.
122 virtual GlobalValue::LinkageTypes getLinkage() const;
124 //===--------------------------------------------------------------------===//
125 // Subclasses should supply the following static methods.
127 // Implement isa/cast/dyncast.
128 static bool classof(const DebugInfoDesc *) { return true; }
130 //===--------------------------------------------------------------------===//
131 // Subclasses should supply the following virtual methods.
133 /// ApplyToFields - Target the vistor to the fields of the descriptor.
135 virtual void ApplyToFields(DIVisitor *Visitor);
137 /// getDescString - Return a string used to compose global names and labels.
139 virtual const char *getDescString() const = 0;
141 /// getTypeString - Return a string used to label this descriptor's type.
143 virtual const char *getTypeString() const = 0;
146 virtual void dump() = 0;
150 //===----------------------------------------------------------------------===//
151 /// AnchorDesc - Descriptors of this class act as markers for identifying
152 /// descriptors of certain groups.
154 class AnchorDesc : public DebugInfoDesc {
156 unsigned AnchorTag; // Tag number of descriptors anchored
161 AnchorDesc(AnchoredDesc *D);
164 unsigned getAnchorTag() const { return AnchorTag; }
166 // Implement isa/cast/dyncast.
167 static bool classof(const AnchorDesc *) { return true; }
168 static bool classof(const DebugInfoDesc *D);
170 /// getLinkage - get linkage appropriate for this type of descriptor.
172 virtual GlobalValue::LinkageTypes getLinkage() const;
174 /// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
176 virtual void ApplyToFields(DIVisitor *Visitor);
178 /// getDescString - Return a string used to compose global names and labels.
180 virtual const char *getDescString() const;
182 /// getTypeString - Return a string used to label this descriptor's type.
184 virtual const char *getTypeString() const;
191 //===----------------------------------------------------------------------===//
192 /// AnchoredDesc - This class manages anchors for a variety of top level
194 class AnchoredDesc : public DebugInfoDesc {
196 DebugInfoDesc *Anchor; // Anchor for all descriptors of the
201 AnchoredDesc(unsigned T);
205 AnchorDesc *getAnchor() const { return static_cast<AnchorDesc *>(Anchor); }
206 void setAnchor(AnchorDesc *A) { Anchor = static_cast<DebugInfoDesc *>(A); }
208 //===--------------------------------------------------------------------===//
209 // Subclasses should supply the following virtual methods.
211 /// getAnchorString - Return a string used to label descriptor's anchor.
213 virtual const char *getAnchorString() const = 0;
215 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
217 virtual void ApplyToFields(DIVisitor *Visitor);
220 //===----------------------------------------------------------------------===//
221 /// CompileUnitDesc - This class packages debug information associated with a
222 /// source/header file.
223 class CompileUnitDesc : public AnchoredDesc {
225 unsigned Language; // Language number (ex. DW_LANG_C89.)
226 std::string FileName; // Source file name.
227 std::string Directory; // Source file directory.
228 std::string Producer; // Compiler string.
235 unsigned getLanguage() const { return Language; }
236 const std::string &getFileName() const { return FileName; }
237 const std::string &getDirectory() const { return Directory; }
238 const std::string &getProducer() const { return Producer; }
239 void setLanguage(unsigned L) { Language = L; }
240 void setFileName(const std::string &FN) { FileName = FN; }
241 void setDirectory(const std::string &D) { Directory = D; }
242 void setProducer(const std::string &P) { Producer = P; }
244 // FIXME - Need translation unit getter/setter.
246 // Implement isa/cast/dyncast.
247 static bool classof(const CompileUnitDesc *) { return true; }
248 static bool classof(const DebugInfoDesc *D);
250 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
252 virtual void ApplyToFields(DIVisitor *Visitor);
254 /// getDescString - Return a string used to compose global names and labels.
256 virtual const char *getDescString() const;
258 /// getTypeString - Return a string used to label this descriptor's type.
260 virtual const char *getTypeString() const;
262 /// getAnchorString - Return a string used to label this descriptor's anchor.
264 static const char *AnchorString;
265 virtual const char *getAnchorString() const;
272 //===----------------------------------------------------------------------===//
273 /// TypeDesc - This class packages debug information associated with a type.
275 class TypeDesc : public DebugInfoDesc {
278 FlagPrivate = 1 << 0,
279 FlagProtected = 1 << 1
281 DebugInfoDesc *Context; // Context debug descriptor.
282 std::string Name; // Type name (may be empty.)
283 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
284 unsigned Line; // Defined line# (may be zero.)
285 uint64_t Size; // Type bit size (may be zero.)
286 uint64_t Align; // Type bit alignment (may be zero.)
287 uint64_t Offset; // Type bit offset (may be zero.)
288 unsigned Flags; // Miscellaneous flags.
291 TypeDesc(unsigned T);
294 DebugInfoDesc *getContext() const { return Context; }
295 const std::string &getName() const { return Name; }
296 CompileUnitDesc *getFile() const {
297 return static_cast<CompileUnitDesc *>(File);
299 unsigned getLine() const { return Line; }
300 uint64_t getSize() const { return Size; }
301 uint64_t getAlign() const { return Align; }
302 uint64_t getOffset() const { return Offset; }
303 bool isPrivate() const {
304 return (Flags & FlagPrivate) != 0;
306 bool isProtected() const {
307 return (Flags & FlagProtected) != 0;
309 void setContext(DebugInfoDesc *C) { Context = C; }
310 void setName(const std::string &N) { Name = N; }
311 void setFile(CompileUnitDesc *U) {
312 File = static_cast<DebugInfoDesc *>(U);
314 void setLine(unsigned L) { Line = L; }
315 void setSize(uint64_t S) { Size = S; }
316 void setAlign(uint64_t A) { Align = A; }
317 void setOffset(uint64_t O) { Offset = O; }
318 void setIsPrivate() { Flags |= FlagPrivate; }
319 void setIsProtected() { Flags |= FlagProtected; }
321 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
323 virtual void ApplyToFields(DIVisitor *Visitor);
325 /// getDescString - Return a string used to compose global names and labels.
327 virtual const char *getDescString() const;
329 /// getTypeString - Return a string used to label this descriptor's type.
331 virtual const char *getTypeString() const;
338 //===----------------------------------------------------------------------===//
339 /// BasicTypeDesc - This class packages debug information associated with a
340 /// basic type (eg. int, bool, double.)
341 class BasicTypeDesc : public TypeDesc {
343 unsigned Encoding; // Type encoding.
349 unsigned getEncoding() const { return Encoding; }
350 void setEncoding(unsigned E) { Encoding = E; }
352 // Implement isa/cast/dyncast.
353 static bool classof(const BasicTypeDesc *) { return true; }
354 static bool classof(const DebugInfoDesc *D);
356 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
358 virtual void ApplyToFields(DIVisitor *Visitor);
360 /// getDescString - Return a string used to compose global names and labels.
362 virtual const char *getDescString() const;
364 /// getTypeString - Return a string used to label this descriptor's type.
366 virtual const char *getTypeString() const;
374 //===----------------------------------------------------------------------===//
375 /// DerivedTypeDesc - This class packages debug information associated with a
376 /// derived types (eg., typedef, pointer, reference.)
377 class DerivedTypeDesc : public TypeDesc {
379 DebugInfoDesc *FromType; // Type derived from.
382 DerivedTypeDesc(unsigned T);
385 TypeDesc *getFromType() const {
386 return static_cast<TypeDesc *>(FromType);
388 void setFromType(TypeDesc *F) {
389 FromType = static_cast<DebugInfoDesc *>(F);
392 // Implement isa/cast/dyncast.
393 static bool classof(const DerivedTypeDesc *) { return true; }
394 static bool classof(const DebugInfoDesc *D);
396 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
398 virtual void ApplyToFields(DIVisitor *Visitor);
400 /// getDescString - Return a string used to compose global names and labels.
402 virtual const char *getDescString() const;
404 /// getTypeString - Return a string used to label this descriptor's type.
406 virtual const char *getTypeString() const;
413 //===----------------------------------------------------------------------===//
414 /// CompositeTypeDesc - This class packages debug information associated with a
415 /// array/struct types (eg., arrays, struct, union, enums.)
416 class CompositeTypeDesc : public DerivedTypeDesc {
418 std::vector<DebugInfoDesc *> Elements;// Information used to compose type.
421 CompositeTypeDesc(unsigned T);
424 std::vector<DebugInfoDesc *> &getElements() { return Elements; }
426 // Implement isa/cast/dyncast.
427 static bool classof(const CompositeTypeDesc *) { return true; }
428 static bool classof(const DebugInfoDesc *D);
430 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
432 virtual void ApplyToFields(DIVisitor *Visitor);
434 /// getDescString - Return a string used to compose global names and labels.
436 virtual const char *getDescString() const;
438 /// getTypeString - Return a string used to label this descriptor's type.
440 virtual const char *getTypeString() const;
447 //===----------------------------------------------------------------------===//
448 /// SubrangeDesc - This class packages debug information associated with integer
450 class SubrangeDesc : public DebugInfoDesc {
452 int64_t Lo; // Low value of range.
453 int64_t Hi; // High value of range.
459 int64_t getLo() const { return Lo; }
460 int64_t getHi() const { return Hi; }
461 void setLo(int64_t L) { Lo = L; }
462 void setHi(int64_t H) { Hi = H; }
464 // Implement isa/cast/dyncast.
465 static bool classof(const SubrangeDesc *) { return true; }
466 static bool classof(const DebugInfoDesc *D);
468 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
470 virtual void ApplyToFields(DIVisitor *Visitor);
472 /// getDescString - Return a string used to compose global names and labels.
474 virtual const char *getDescString() const;
476 /// getTypeString - Return a string used to label this descriptor's type.
478 virtual const char *getTypeString() const;
485 //===----------------------------------------------------------------------===//
486 /// EnumeratorDesc - This class packages debug information associated with
487 /// named integer constants.
488 class EnumeratorDesc : public DebugInfoDesc {
490 std::string Name; // Enumerator name.
491 int64_t Value; // Enumerator value.
497 const std::string &getName() const { return Name; }
498 int64_t getValue() const { return Value; }
499 void setName(const std::string &N) { Name = N; }
500 void setValue(int64_t V) { Value = V; }
502 // Implement isa/cast/dyncast.
503 static bool classof(const EnumeratorDesc *) { return true; }
504 static bool classof(const DebugInfoDesc *D);
506 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
508 virtual void ApplyToFields(DIVisitor *Visitor);
510 /// getDescString - Return a string used to compose global names and labels.
512 virtual const char *getDescString() const;
514 /// getTypeString - Return a string used to label this descriptor's type.
516 virtual const char *getTypeString() const;
523 //===----------------------------------------------------------------------===//
524 /// VariableDesc - This class packages debug information associated with a
525 /// subprogram variable.
527 class VariableDesc : public DebugInfoDesc {
529 DebugInfoDesc *Context; // Context debug descriptor.
530 std::string Name; // Type name (may be empty.)
531 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
532 unsigned Line; // Defined line# (may be zero.)
533 DebugInfoDesc *TyDesc; // Type of variable.
536 VariableDesc(unsigned T);
539 DebugInfoDesc *getContext() const { return Context; }
540 const std::string &getName() const { return Name; }
541 CompileUnitDesc *getFile() const {
542 return static_cast<CompileUnitDesc *>(File);
544 unsigned getLine() const { return Line; }
545 TypeDesc *getType() const {
546 return static_cast<TypeDesc *>(TyDesc);
548 void setContext(DebugInfoDesc *C) { Context = C; }
549 void setName(const std::string &N) { Name = N; }
550 void setFile(CompileUnitDesc *U) {
551 File = static_cast<DebugInfoDesc *>(U);
553 void setLine(unsigned L) { Line = L; }
554 void setType(TypeDesc *T) {
555 TyDesc = static_cast<DebugInfoDesc *>(T);
558 // Implement isa/cast/dyncast.
559 static bool classof(const VariableDesc *) { return true; }
560 static bool classof(const DebugInfoDesc *D);
562 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
564 virtual void ApplyToFields(DIVisitor *Visitor);
566 /// getDescString - Return a string used to compose global names and labels.
568 virtual const char *getDescString() const;
570 /// getTypeString - Return a string used to label this descriptor's type.
572 virtual const char *getTypeString() const;
579 //===----------------------------------------------------------------------===//
580 /// GlobalDesc - This class is the base descriptor for global functions and
582 class GlobalDesc : public AnchoredDesc {
584 DebugInfoDesc *Context; // Context debug descriptor.
585 std::string Name; // Global name.
586 std::string FullName; // Fully qualified name.
587 std::string LinkageName; // Name for binding to MIPS linkage.
588 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
589 unsigned Line; // Defined line# (may be zero.)
590 DebugInfoDesc *TyDesc; // Type debug descriptor.
591 bool IsStatic; // Is the global a static.
592 bool IsDefinition; // Is the global defined in context.
595 GlobalDesc(unsigned T);
599 DebugInfoDesc *getContext() const { return Context; }
600 const std::string &getName() const { return Name; }
601 const std::string &getFullName() const { return FullName; }
602 const std::string &getLinkageName() const { return LinkageName; }
603 CompileUnitDesc *getFile() const {
604 return static_cast<CompileUnitDesc *>(File);
606 unsigned getLine() const { return Line; }
607 TypeDesc *getType() const {
608 return static_cast<TypeDesc *>(TyDesc);
610 bool isStatic() const { return IsStatic; }
611 bool isDefinition() const { return IsDefinition; }
612 void setContext(DebugInfoDesc *C) { Context = C; }
613 void setName(const std::string &N) { Name = N; }
614 void setFullName(const std::string &N) { FullName = N; }
615 void setLinkageName(const std::string &N) { LinkageName = N; }
616 void setFile(CompileUnitDesc *U) {
617 File = static_cast<DebugInfoDesc *>(U);
619 void setLine(unsigned L) { Line = L; }
620 void setType(TypeDesc *T) {
621 TyDesc = static_cast<DebugInfoDesc *>(T);
623 void setIsStatic(bool IS) { IsStatic = IS; }
624 void setIsDefinition(bool ID) { IsDefinition = ID; }
626 /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
628 virtual void ApplyToFields(DIVisitor *Visitor);
631 //===----------------------------------------------------------------------===//
632 /// GlobalVariableDesc - This class packages debug information associated with a
634 class GlobalVariableDesc : public GlobalDesc {
636 GlobalVariable *Global; // llvm global.
639 GlobalVariableDesc();
642 GlobalVariable *getGlobalVariable() const { return Global; }
643 void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
645 // Implement isa/cast/dyncast.
646 static bool classof(const GlobalVariableDesc *) { return true; }
647 static bool classof(const DebugInfoDesc *D);
649 /// ApplyToFields - Target the visitor to the fields of the
650 /// GlobalVariableDesc.
651 virtual void ApplyToFields(DIVisitor *Visitor);
653 /// getDescString - Return a string used to compose global names and labels.
655 virtual const char *getDescString() const;
657 /// getTypeString - Return a string used to label this descriptor's type.
659 virtual const char *getTypeString() const;
661 /// getAnchorString - Return a string used to label this descriptor's anchor.
663 static const char *AnchorString;
664 virtual const char *getAnchorString() const;
671 //===----------------------------------------------------------------------===//
672 /// SubprogramDesc - This class packages debug information associated with a
673 /// subprogram/function.
674 class SubprogramDesc : public GlobalDesc {
682 // Implement isa/cast/dyncast.
683 static bool classof(const SubprogramDesc *) { return true; }
684 static bool classof(const DebugInfoDesc *D);
686 /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
688 virtual void ApplyToFields(DIVisitor *Visitor);
690 /// getDescString - Return a string used to compose global names and labels.
692 virtual const char *getDescString() const;
694 /// getTypeString - Return a string used to label this descriptor's type.
696 virtual const char *getTypeString() const;
698 /// getAnchorString - Return a string used to label this descriptor's anchor.
700 static const char *AnchorString;
701 virtual const char *getAnchorString() const;
708 //===----------------------------------------------------------------------===//
709 /// BlockDesc - This descriptor groups variables and blocks nested in a block.
711 class BlockDesc : public DebugInfoDesc {
713 DebugInfoDesc *Context; // Context debug descriptor.
719 DebugInfoDesc *getContext() const { return Context; }
720 void setContext(DebugInfoDesc *C) { Context = C; }
722 // Implement isa/cast/dyncast.
723 static bool classof(const BlockDesc *) { return true; }
724 static bool classof(const DebugInfoDesc *D);
726 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
728 virtual void ApplyToFields(DIVisitor *Visitor);
730 /// getDescString - Return a string used to compose global names and labels.
732 virtual const char *getDescString() const;
734 /// getTypeString - Return a string used to label this descriptor's type.
736 virtual const char *getTypeString() const;
743 //===----------------------------------------------------------------------===//
744 /// DIDeserializer - This class is responsible for casting GlobalVariables
745 /// into DebugInfoDesc objects.
746 class DIDeserializer {
748 std::map<GlobalVariable *, DebugInfoDesc *> GlobalDescs;
749 // Previously defined gloabls.
755 /// Deserialize - Reconstitute a GlobalVariable into it's component
756 /// DebugInfoDesc objects.
757 DebugInfoDesc *Deserialize(Value *V);
758 DebugInfoDesc *Deserialize(GlobalVariable *GV);
761 //===----------------------------------------------------------------------===//
762 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
763 /// into GlobalVariables.
766 Module *M; // Definition space module.
767 PointerType *StrPtrTy; // A "sbyte *" type. Created lazily.
768 PointerType *EmptyStructPtrTy; // A "{ }*" type. Created lazily.
769 std::map<unsigned, StructType *> TagTypes;
770 // Types per Tag. Created lazily.
771 std::map<DebugInfoDesc *, GlobalVariable *> DescGlobals;
772 // Previously defined descriptors.
773 std::map<const std::string, Constant *> StringCache;
774 // Previously defined strings.
780 , EmptyStructPtrTy(NULL)
788 Module *getModule() const { return M; };
789 void setModule(Module *module) { M = module; }
791 /// getStrPtrType - Return a "sbyte *" type.
793 const PointerType *getStrPtrType();
795 /// getEmptyStructPtrType - Return a "{ }*" type.
797 const PointerType *getEmptyStructPtrType();
799 /// getTagType - Return the type describing the specified descriptor (via
801 const StructType *getTagType(DebugInfoDesc *DD);
803 /// getString - Construct the string as constant string global.
805 Constant *getString(const std::string &String);
807 /// Serialize - Recursively cast the specified descriptor into a
808 /// GlobalVariable so that it can be serialized to a .bc or .ll file.
809 GlobalVariable *Serialize(DebugInfoDesc *DD);
812 //===----------------------------------------------------------------------===//
813 /// DIVerifier - This class is responsible for verifying the given network of
814 /// GlobalVariables are valid as DebugInfoDesc objects.
822 std::map<GlobalVariable *, unsigned> Validity;// Tracks prior results.
823 std::map<unsigned, unsigned> Counts; // Count of fields per Tag type.
832 /// Verify - Return true if the GlobalVariable appears to be a valid
833 /// serialization of a DebugInfoDesc.
834 bool Verify(Value *V);
835 bool Verify(GlobalVariable *GV);
838 //===----------------------------------------------------------------------===//
839 /// SourceLineInfo - This class is used to record source line correspondence.
841 class SourceLineInfo {
843 unsigned Line; // Source line number.
844 unsigned Column; // Source column.
845 unsigned SourceID; // Source ID number.
846 unsigned LabelID; // Label in code ID number.
849 SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
850 : Line(L), Column(C), SourceID(S), LabelID(I) {}
853 unsigned getLine() const { return Line; }
854 unsigned getColumn() const { return Column; }
855 unsigned getSourceID() const { return SourceID; }
856 unsigned getLabelID() const { return LabelID; }
859 //===----------------------------------------------------------------------===//
860 /// SourceFileInfo - This class is used to track source information.
862 class SourceFileInfo {
864 unsigned DirectoryID; // Directory ID number.
865 std::string Name; // File name (not including directory.)
868 SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
871 unsigned getDirectoryID() const { return DirectoryID; }
872 const std::string &getName() const { return Name; }
874 /// operator== - Used by UniqueVector to locate entry.
876 bool operator==(const SourceFileInfo &SI) const {
877 return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
880 /// operator< - Used by UniqueVector to locate entry.
882 bool operator<(const SourceFileInfo &SI) const {
883 return getDirectoryID() < SI.getDirectoryID() ||
884 (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
888 //===----------------------------------------------------------------------===//
889 /// DebugVariable - This class is used to track local variable information.
891 class DebugVariable {
893 VariableDesc *Desc; // Variable Descriptor.
894 unsigned FrameIndex; // Variable frame index.
897 DebugVariable(VariableDesc *D, unsigned I)
903 VariableDesc *getDesc() const { return Desc; }
904 unsigned getFrameIndex() const { return FrameIndex; }
907 //===----------------------------------------------------------------------===//
908 /// DebugScope - This class is used to track scope information.
912 DebugScope *Parent; // Parent to this scope.
913 DebugInfoDesc *Desc; // Debug info descriptor for scope.
914 // Either subprogram or block.
915 unsigned StartLabelID; // Label ID of the beginning of scope.
916 unsigned EndLabelID; // Label ID of the end of scope.
917 std::vector<DebugScope *> Scopes; // Scopes defined in scope.
918 std::vector<DebugVariable *> Variables;// Variables declared in scope.
921 DebugScope(DebugScope *P, DebugInfoDesc *D)
932 DebugScope *getParent() const { return Parent; }
933 DebugInfoDesc *getDesc() const { return Desc; }
934 unsigned getStartLabelID() const { return StartLabelID; }
935 unsigned getEndLabelID() const { return EndLabelID; }
936 std::vector<DebugScope *> &getScopes() { return Scopes; }
937 std::vector<DebugVariable *> &getVariables() { return Variables; }
938 void setStartLabelID(unsigned S) { StartLabelID = S; }
939 void setEndLabelID(unsigned E) { EndLabelID = E; }
941 /// AddScope - Add a scope to the scope.
943 void AddScope(DebugScope *S) { Scopes.push_back(S); }
945 /// AddVariable - Add a variable to the scope.
947 void AddVariable(DebugVariable *V) { Variables.push_back(V); }
950 //===----------------------------------------------------------------------===//
951 /// MachineDebugInfo - This class contains debug information specific to a
952 /// module. Queries can be made by different debugging schemes and reformated
953 /// for specific use.
955 class MachineDebugInfo : public ImmutablePass {
957 // Use the same deserializer/verifier for the module.
961 // CompileUnits - Uniquing vector for compile units.
962 UniqueVector<CompileUnitDesc *> CompileUnits;
964 // Directories - Uniquing vector for directories.
965 UniqueVector<std::string> Directories;
967 // SourceFiles - Uniquing vector for source files.
968 UniqueVector<SourceFileInfo> SourceFiles;
970 // Lines - List of of source line correspondence.
971 std::vector<SourceLineInfo> Lines;
973 // LabelIDList - One entry per assigned label. Normally the entry is equal to
974 // the list index(+1). If the entry is zero then the label has been deleted.
975 // Any other value indicates the label has been deleted by is mapped to
977 std::vector<unsigned> LabelIDList;
979 // ScopeMap - Tracks the scopes in the current function.
980 std::map<DebugInfoDesc *, DebugScope *> ScopeMap;
982 // RootScope - Top level scope for the current function.
984 DebugScope *RootScope;
986 // FrameMoves - List of moves done by a function's prolog. Used to construct
987 // frame maps by debug consumers.
988 std::vector<MachineMove *> FrameMoves;
994 /// doInitialization - Initialize the debug state for a new module.
996 bool doInitialization();
998 /// doFinalization - Tear down the debug state after completion of a module.
1000 bool doFinalization();
1002 /// BeginFunction - Begin gathering function debug information.
1004 void BeginFunction(MachineFunction *MF);
1006 /// EndFunction - Discard function debug information.
1010 /// getDescFor - Convert a Value to a debug information descriptor.
1012 // FIXME - use new Value type when available.
1013 DebugInfoDesc *getDescFor(Value *V);
1015 /// Verify - Verify that a Value is debug information descriptor.
1017 bool Verify(Value *V);
1019 /// AnalyzeModule - Scan the module for global debug information.
1021 void AnalyzeModule(Module &M);
1023 /// hasInfo - Returns true if valid debug info is present.
1025 bool hasInfo() const { return !CompileUnits.empty(); }
1027 /// NextLabelID - Return the next unique label id.
1029 unsigned NextLabelID() {
1030 unsigned ID = LabelIDList.size() + 1;
1031 LabelIDList.push_back(ID);
1035 /// RecordLabel - Records location information and associates it with a
1036 /// debug label. Returns a unique label ID used to generate a label and
1037 /// provide correspondence to the source line list.
1038 unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source);
1040 /// InvalidateLabel - Inhibit use of the specified label # from
1041 /// MachineDebugInfo, for example because the code was deleted.
1042 void InvalidateLabel(unsigned LabelID) {
1043 // Remap to zero to indicate deletion.
1044 RemapLabel(LabelID, 0);
1047 /// RemapLabel - Indicate that a label has been merged into another.
1049 void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
1050 assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() &&
1051 "Old debug label ID out of range.");
1052 assert(NewLabelID <= LabelIDList.size() &&
1053 "New debug label ID out of range.");
1054 LabelIDList[OldLabelID - 1] = NewLabelID;
1057 /// MappedLabel - Find out the label's final ID. Zero indicates deletion.
1058 /// ID != Mapped ID indicates that the label was folded into another label.
1059 unsigned MappedLabel(unsigned LabelID) const {
1060 assert(LabelID <= LabelIDList.size() && "Debug label ID out of range.");
1061 return LabelID ? LabelIDList[LabelID - 1] : 0;
1064 /// RecordSource - Register a source file with debug info. Returns an source
1066 unsigned RecordSource(const std::string &Directory,
1067 const std::string &Source);
1068 unsigned RecordSource(const CompileUnitDesc *CompileUnit);
1070 /// getDirectories - Return the UniqueVector of std::string representing
1072 const UniqueVector<std::string> &getDirectories() const {
1076 /// getSourceFiles - Return the UniqueVector of source files.
1078 const UniqueVector<SourceFileInfo> &getSourceFiles() const {
1082 /// getSourceLines - Return a vector of source lines.
1084 const std::vector<SourceLineInfo> &getSourceLines() const {
1088 // FIXME: nuke this.
1089 void ClearLineInfo() {
1093 /// SetupCompileUnits - Set up the unique vector of compile units.
1095 void SetupCompileUnits(Module &M);
1097 /// getCompileUnits - Return a vector of debug compile units.
1099 const UniqueVector<CompileUnitDesc *> getCompileUnits() const;
1101 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1102 /// named GlobalVariable.
1103 std::vector<GlobalVariable*>
1104 getGlobalVariablesUsing(Module &M, const std::string &RootName);
1106 /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
1108 template <class T>std::vector<T *> getAnchoredDescriptors(Module &M) {
1110 std::vector<GlobalVariable *> Globals =
1111 getGlobalVariablesUsing(M, Desc.getAnchorString());
1112 std::vector<T *> AnchoredDescs;
1113 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
1114 GlobalVariable *GV = Globals[i];
1116 // FIXME - In the short term, changes are too drastic to continue.
1117 if (DebugInfoDesc::TagFromGlobal(GV) == Desc.getTag() &&
1118 DebugInfoDesc::VersionFromGlobal(GV) == LLVMDebugVersion) {
1119 AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
1123 return AnchoredDescs;
1126 /// RecordRegionStart - Indicate the start of a region.
1128 unsigned RecordRegionStart(Value *V);
1130 /// RecordRegionEnd - Indicate the end of a region.
1132 unsigned RecordRegionEnd(Value *V);
1134 /// RecordVariable - Indicate the declaration of a local variable.
1136 void RecordVariable(Value *V, unsigned FrameIndex);
1138 /// getRootScope - Return current functions root scope.
1140 DebugScope *getRootScope() { return RootScope; }
1142 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1144 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1146 /// getFrameMoves - Returns a reference to a list of moves done in the current
1147 /// function's prologue. Used to construct frame maps for debug comsumers.
1148 std::vector<MachineMove *> &getFrameMoves() { return FrameMoves; }
1150 }; // End class MachineDebugInfo
1152 } // End llvm namespace