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 coorespondence - 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"
38 #include "llvm/User.h"
45 //===----------------------------------------------------------------------===//
46 // Forward declarations.
50 class MachineFunction;
56 //===----------------------------------------------------------------------===//
57 // Debug info constants.
60 LLVMDebugVersion = 4 // Current version of debug information.
63 //===----------------------------------------------------------------------===//
64 /// DIVisitor - Subclasses of this class apply steps to each of the fields in
65 /// the supplied DebugInfoDesc.
69 virtual ~DIVisitor() {}
71 /// ApplyToFields - Target the visitor to each field of the debug information
73 void ApplyToFields(DebugInfoDesc *DD);
75 /// Apply - Subclasses override each of these methods to perform the
76 /// appropriate action for the type of field.
77 virtual void Apply(int &Field) = 0;
78 virtual void Apply(unsigned &Field) = 0;
79 virtual void Apply(int64_t &Field) = 0;
80 virtual void Apply(uint64_t &Field) = 0;
81 virtual void Apply(bool &Field) = 0;
82 virtual void Apply(std::string &Field) = 0;
83 virtual void Apply(DebugInfoDesc *&Field) = 0;
84 virtual void Apply(GlobalVariable *&Field) = 0;
85 virtual void Apply(std::vector<DebugInfoDesc *> &Field) = 0;
88 //===----------------------------------------------------------------------===//
89 /// DebugInfoDesc - This class is the base class for debug info descriptors.
94 tag_mask = 0x0000ffff,
99 unsigned Tag; // Content indicator. Dwarf values are
100 // used but that does not limit use to
104 DebugInfoDesc(unsigned T) : Tag(T | (LLVMDebugVersion << version_shift)) {}
107 virtual ~DebugInfoDesc() {}
110 unsigned getTag() const { return Tag & tag_mask; }
111 unsigned getVersion() const { return Tag >> version_shift; }
113 /// TagFromGlobal - Returns the tag number from a debug info descriptor
114 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
115 static unsigned TagFromGlobal(GlobalVariable *GV);
117 /// VersionFromGlobal - Returns the version number from a debug info
118 /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned
120 static unsigned VersionFromGlobal(GlobalVariable *GV);
122 /// DescFactory - Create an instance of debug info descriptor based on Tag.
123 /// Return NULL if not a recognized Tag.
124 static DebugInfoDesc *DescFactory(unsigned Tag);
126 /// getLinkage - get linkage appropriate for this type of descriptor.
128 virtual GlobalValue::LinkageTypes getLinkage() const;
130 //===--------------------------------------------------------------------===//
131 // Subclasses should supply the following static methods.
133 // Implement isa/cast/dyncast.
134 static bool classof(const DebugInfoDesc *) { return true; }
136 //===--------------------------------------------------------------------===//
137 // Subclasses should supply the following virtual methods.
139 /// ApplyToFields - Target the vistor to the fields of the descriptor.
141 virtual void ApplyToFields(DIVisitor *Visitor);
143 /// getDescString - Return a string used to compose global names and labels.
145 virtual const char *getDescString() const = 0;
147 /// getTypeString - Return a string used to label this descriptor's type.
149 virtual const char *getTypeString() const = 0;
152 virtual void dump() = 0;
156 //===----------------------------------------------------------------------===//
157 /// AnchorDesc - Descriptors of this class act as markers for identifying
158 /// descriptors of certain groups.
160 class AnchorDesc : public DebugInfoDesc {
162 unsigned AnchorTag; // Tag number of descriptors anchored
167 AnchorDesc(AnchoredDesc *D);
170 unsigned getAnchorTag() const { return AnchorTag; }
172 // Implement isa/cast/dyncast.
173 static bool classof(const AnchorDesc *) { return true; }
174 static bool classof(const DebugInfoDesc *D);
176 /// getLinkage - get linkage appropriate for this type of descriptor.
178 virtual GlobalValue::LinkageTypes getLinkage() const;
180 /// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
182 virtual void ApplyToFields(DIVisitor *Visitor);
184 /// getDescString - Return a string used to compose global names and labels.
186 virtual const char *getDescString() const;
188 /// getTypeString - Return a string used to label this descriptor's type.
190 virtual const char *getTypeString() const;
197 //===----------------------------------------------------------------------===//
198 /// AnchoredDesc - This class manages anchors for a variety of top level
200 class AnchoredDesc : public DebugInfoDesc {
202 AnchorDesc *Anchor; // Anchor for all descriptors of the
207 AnchoredDesc(unsigned T);
211 AnchorDesc *getAnchor() const { return Anchor; }
212 void setAnchor(AnchorDesc *A) { Anchor = A; }
214 //===--------------------------------------------------------------------===//
215 // Subclasses should supply the following virtual methods.
217 /// getAnchorString - Return a string used to label descriptor's anchor.
219 virtual const char *getAnchorString() const = 0;
221 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
223 virtual void ApplyToFields(DIVisitor *Visitor);
226 //===----------------------------------------------------------------------===//
227 /// CompileUnitDesc - This class packages debug information associated with a
228 /// source/header file.
229 class CompileUnitDesc : public AnchoredDesc {
231 unsigned Language; // Language number (ex. DW_LANG_C89.)
232 std::string FileName; // Source file name.
233 std::string Directory; // Source file directory.
234 std::string Producer; // Compiler string.
241 unsigned getLanguage() const { return Language; }
242 const std::string &getFileName() const { return FileName; }
243 const std::string &getDirectory() const { return Directory; }
244 const std::string &getProducer() const { return Producer; }
245 void setLanguage(unsigned L) { Language = L; }
246 void setFileName(const std::string &FN) { FileName = FN; }
247 void setDirectory(const std::string &D) { Directory = D; }
248 void setProducer(const std::string &P) { Producer = P; }
250 // FIXME - Need translation unit getter/setter.
252 // Implement isa/cast/dyncast.
253 static bool classof(const CompileUnitDesc *) { return true; }
254 static bool classof(const DebugInfoDesc *D);
256 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
258 virtual void ApplyToFields(DIVisitor *Visitor);
260 /// getDescString - Return a string used to compose global names and labels.
262 virtual const char *getDescString() const;
264 /// getTypeString - Return a string used to label this descriptor's type.
266 virtual const char *getTypeString() const;
268 /// getAnchorString - Return a string used to label this descriptor's anchor.
270 static const char *AnchorString;
271 virtual const char *getAnchorString() const;
278 //===----------------------------------------------------------------------===//
279 /// TypeDesc - This class packages debug information associated with a type.
281 class TypeDesc : public DebugInfoDesc {
283 DebugInfoDesc *Context; // Context debug descriptor.
284 std::string Name; // Type name (may be empty.)
285 CompileUnitDesc *File; // Defined compile unit (may be NULL.)
286 unsigned Line; // Defined line# (may be zero.)
287 uint64_t Size; // Type bit size (may be zero.)
288 uint64_t Align; // Type bit alignment (may be zero.)
289 uint64_t Offset; // Type bit offset (may be zero.)
292 TypeDesc(unsigned T);
295 DebugInfoDesc *getContext() const { return Context; }
296 const std::string &getName() const { return Name; }
297 CompileUnitDesc *getFile() const { return File; }
298 unsigned getLine() const { return Line; }
299 uint64_t getSize() const { return Size; }
300 uint64_t getAlign() const { return Align; }
301 uint64_t getOffset() const { return Offset; }
302 void setContext(DebugInfoDesc *C) { Context = C; }
303 void setName(const std::string &N) { Name = N; }
304 void setFile(CompileUnitDesc *U) { File = U; }
305 void setLine(unsigned L) { Line = L; }
306 void setSize(uint64_t S) { Size = S; }
307 void setAlign(uint64_t A) { Align = A; }
308 void setOffset(uint64_t O) { Offset = O; }
310 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
312 virtual void ApplyToFields(DIVisitor *Visitor);
314 /// getDescString - Return a string used to compose global names and labels.
316 virtual const char *getDescString() const;
318 /// getTypeString - Return a string used to label this descriptor's type.
320 virtual const char *getTypeString() const;
327 //===----------------------------------------------------------------------===//
328 /// BasicTypeDesc - This class packages debug information associated with a
329 /// basic type (eg. int, bool, double.)
330 class BasicTypeDesc : public TypeDesc {
332 unsigned Encoding; // Type encoding.
338 unsigned getEncoding() const { return Encoding; }
339 void setEncoding(unsigned E) { Encoding = E; }
341 // Implement isa/cast/dyncast.
342 static bool classof(const BasicTypeDesc *) { return true; }
343 static bool classof(const DebugInfoDesc *D);
345 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
347 virtual void ApplyToFields(DIVisitor *Visitor);
349 /// getDescString - Return a string used to compose global names and labels.
351 virtual const char *getDescString() const;
353 /// getTypeString - Return a string used to label this descriptor's type.
355 virtual const char *getTypeString() const;
363 //===----------------------------------------------------------------------===//
364 /// DerivedTypeDesc - This class packages debug information associated with a
365 /// derived types (eg., typedef, pointer, reference.)
366 class DerivedTypeDesc : public TypeDesc {
368 TypeDesc *FromType; // Type derived from.
371 DerivedTypeDesc(unsigned T);
374 TypeDesc *getFromType() const { return FromType; }
375 void setFromType(TypeDesc *F) { FromType = F; }
377 // Implement isa/cast/dyncast.
378 static bool classof(const DerivedTypeDesc *) { return true; }
379 static bool classof(const DebugInfoDesc *D);
381 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
383 virtual void ApplyToFields(DIVisitor *Visitor);
385 /// getDescString - Return a string used to compose global names and labels.
387 virtual const char *getDescString() const;
389 /// getTypeString - Return a string used to label this descriptor's type.
391 virtual const char *getTypeString() const;
398 //===----------------------------------------------------------------------===//
399 /// CompositeTypeDesc - This class packages debug information associated with a
400 /// array/struct types (eg., arrays, struct, union, enums.)
401 class CompositeTypeDesc : public DerivedTypeDesc {
403 bool IsVector; // packed/vector array
404 std::vector<DebugInfoDesc *> Elements;// Information used to compose type.
407 CompositeTypeDesc(unsigned T);
410 bool isVector() const { return IsVector; }
411 std::vector<DebugInfoDesc *> &getElements() { return Elements; }
412 void setIsVector() { IsVector = true; }
414 // Implement isa/cast/dyncast.
415 static bool classof(const CompositeTypeDesc *) { return true; }
416 static bool classof(const DebugInfoDesc *D);
418 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
420 virtual void ApplyToFields(DIVisitor *Visitor);
422 /// getDescString - Return a string used to compose global names and labels.
424 virtual const char *getDescString() const;
426 /// getTypeString - Return a string used to label this descriptor's type.
428 virtual const char *getTypeString() const;
435 //===----------------------------------------------------------------------===//
436 /// SubrangeDesc - This class packages debug information associated with integer
438 class SubrangeDesc : public DebugInfoDesc {
440 int64_t Lo; // Low value of range.
441 int64_t Hi; // High value of range.
447 int64_t getLo() const { return Lo; }
448 int64_t getHi() const { return Hi; }
449 void setLo(int64_t L) { Lo = L; }
450 void setHi(int64_t H) { Hi = H; }
452 // Implement isa/cast/dyncast.
453 static bool classof(const SubrangeDesc *) { return true; }
454 static bool classof(const DebugInfoDesc *D);
456 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
458 virtual void ApplyToFields(DIVisitor *Visitor);
460 /// getDescString - Return a string used to compose global names and labels.
462 virtual const char *getDescString() const;
464 /// getTypeString - Return a string used to label this descriptor's type.
466 virtual const char *getTypeString() const;
473 //===----------------------------------------------------------------------===//
474 /// EnumeratorDesc - This class packages debug information associated with
475 /// named integer constants.
476 class EnumeratorDesc : public DebugInfoDesc {
478 std::string Name; // Enumerator name.
479 int64_t Value; // Enumerator value.
485 const std::string &getName() const { return Name; }
486 int64_t getValue() const { return Value; }
487 void setName(const std::string &N) { Name = N; }
488 void setValue(int64_t V) { Value = V; }
490 // Implement isa/cast/dyncast.
491 static bool classof(const EnumeratorDesc *) { return true; }
492 static bool classof(const DebugInfoDesc *D);
494 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
496 virtual void ApplyToFields(DIVisitor *Visitor);
498 /// getDescString - Return a string used to compose global names and labels.
500 virtual const char *getDescString() const;
502 /// getTypeString - Return a string used to label this descriptor's type.
504 virtual const char *getTypeString() const;
511 //===----------------------------------------------------------------------===//
512 /// VariableDesc - This class packages debug information associated with a
513 /// subprogram variable.
515 class VariableDesc : public DebugInfoDesc {
517 DebugInfoDesc *Context; // Context debug descriptor.
518 std::string Name; // Type name (may be empty.)
519 CompileUnitDesc *File; // Defined compile unit (may be NULL.)
520 unsigned Line; // Defined line# (may be zero.)
521 TypeDesc *TyDesc; // Type of variable.
524 VariableDesc(unsigned T);
527 DebugInfoDesc *getContext() const { return Context; }
528 const std::string &getName() const { return Name; }
529 CompileUnitDesc *getFile() const { return File; }
530 unsigned getLine() const { return Line; }
531 TypeDesc *getType() const { return TyDesc; }
532 void setContext(DebugInfoDesc *C) { Context = C; }
533 void setName(const std::string &N) { Name = N; }
534 void setFile(CompileUnitDesc *U) { File = U; }
535 void setLine(unsigned L) { Line = L; }
536 void setType(TypeDesc *T) { TyDesc = T; }
538 // Implement isa/cast/dyncast.
539 static bool classof(const VariableDesc *) { return true; }
540 static bool classof(const DebugInfoDesc *D);
542 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
544 virtual void ApplyToFields(DIVisitor *Visitor);
546 /// getDescString - Return a string used to compose global names and labels.
548 virtual const char *getDescString() const;
550 /// getTypeString - Return a string used to label this descriptor's type.
552 virtual const char *getTypeString() const;
559 //===----------------------------------------------------------------------===//
560 /// GlobalDesc - This class is the base descriptor for global functions and
562 class GlobalDesc : public AnchoredDesc {
564 DebugInfoDesc *Context; // Context debug descriptor.
565 std::string Name; // Global name.
566 CompileUnitDesc *File; // Defined compile unit (may be NULL.)
567 unsigned Line; // Defined line# (may be zero.)
568 TypeDesc *TyDesc; // Type debug descriptor.
569 bool IsStatic; // Is the global a static.
570 bool IsDefinition; // Is the global defined in context.
573 GlobalDesc(unsigned T);
577 DebugInfoDesc *getContext() const { return Context; }
578 const std::string &getName() const { return Name; }
579 CompileUnitDesc *getFile() const { return File; }
580 unsigned getLine() const { return Line; }
581 TypeDesc *getType() const { return TyDesc; }
582 bool isStatic() const { return IsStatic; }
583 bool isDefinition() const { return IsDefinition; }
584 void setContext(DebugInfoDesc *C) { Context = C; }
585 void setName(const std::string &N) { Name = N; }
586 void setFile(CompileUnitDesc *U) { File = U; }
587 void setLine(unsigned L) { Line = L; }
588 void setType(TypeDesc *T) { TyDesc = T; }
589 void setIsStatic(bool IS) { IsStatic = IS; }
590 void setIsDefinition(bool ID) { IsDefinition = ID; }
592 /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
594 virtual void ApplyToFields(DIVisitor *Visitor);
597 //===----------------------------------------------------------------------===//
598 /// GlobalVariableDesc - This class packages debug information associated with a
600 class GlobalVariableDesc : public GlobalDesc {
602 GlobalVariable *Global; // llvm global.
605 GlobalVariableDesc();
608 GlobalVariable *getGlobalVariable() const { return Global; }
609 void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
611 // Implement isa/cast/dyncast.
612 static bool classof(const GlobalVariableDesc *) { return true; }
613 static bool classof(const DebugInfoDesc *D);
615 /// ApplyToFields - Target the visitor to the fields of the
616 /// GlobalVariableDesc.
617 virtual void ApplyToFields(DIVisitor *Visitor);
619 /// getDescString - Return a string used to compose global names and labels.
621 virtual const char *getDescString() const;
623 /// getTypeString - Return a string used to label this descriptor's type.
625 virtual const char *getTypeString() const;
627 /// getAnchorString - Return a string used to label this descriptor's anchor.
629 static const char *AnchorString;
630 virtual const char *getAnchorString() const;
637 //===----------------------------------------------------------------------===//
638 /// SubprogramDesc - This class packages debug information associated with a
639 /// subprogram/function.
640 class SubprogramDesc : public GlobalDesc {
648 // Implement isa/cast/dyncast.
649 static bool classof(const SubprogramDesc *) { return true; }
650 static bool classof(const DebugInfoDesc *D);
652 /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
654 virtual void ApplyToFields(DIVisitor *Visitor);
656 /// getDescString - Return a string used to compose global names and labels.
658 virtual const char *getDescString() const;
660 /// getTypeString - Return a string used to label this descriptor's type.
662 virtual const char *getTypeString() const;
664 /// getAnchorString - Return a string used to label this descriptor's anchor.
666 static const char *AnchorString;
667 virtual const char *getAnchorString() const;
674 //===----------------------------------------------------------------------===//
675 /// BlockDesc - This descriptor groups variables and blocks nested in a block.
677 class BlockDesc : public DebugInfoDesc {
679 DebugInfoDesc *Context; // Context debug descriptor.
685 DebugInfoDesc *getContext() const { return Context; }
686 void setContext(DebugInfoDesc *C) { Context = C; }
688 // Implement isa/cast/dyncast.
689 static bool classof(const BlockDesc *) { return true; }
690 static bool classof(const DebugInfoDesc *D);
692 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
694 virtual void ApplyToFields(DIVisitor *Visitor);
696 /// getDescString - Return a string used to compose global names and labels.
698 virtual const char *getDescString() const;
700 /// getTypeString - Return a string used to label this descriptor's type.
702 virtual const char *getTypeString() const;
709 //===----------------------------------------------------------------------===//
710 /// DIDeserializer - This class is responsible for casting GlobalVariables
711 /// into DebugInfoDesc objects.
712 class DIDeserializer {
714 std::map<GlobalVariable *, DebugInfoDesc *> GlobalDescs;
715 // Previously defined gloabls.
721 /// Deserialize - Reconstitute a GlobalVariable into it's component
722 /// DebugInfoDesc objects.
723 DebugInfoDesc *Deserialize(Value *V);
724 DebugInfoDesc *Deserialize(GlobalVariable *GV);
727 //===----------------------------------------------------------------------===//
728 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
729 /// into GlobalVariables.
732 Module *M; // Definition space module.
733 PointerType *StrPtrTy; // A "sbyte *" type. Created lazily.
734 PointerType *EmptyStructPtrTy; // A "{ }*" type. Created lazily.
735 std::map<unsigned, StructType *> TagTypes;
736 // Types per Tag. Created lazily.
737 std::map<DebugInfoDesc *, GlobalVariable *> DescGlobals;
738 // Previously defined descriptors.
739 std::map<const std::string, Constant *> StringCache;
740 // Previously defined strings.
746 , EmptyStructPtrTy(NULL)
754 Module *getModule() const { return M; };
755 void setModule(Module *module) { M = module; }
757 /// getStrPtrType - Return a "sbyte *" type.
759 const PointerType *getStrPtrType();
761 /// getEmptyStructPtrType - Return a "{ }*" type.
763 const PointerType *getEmptyStructPtrType();
765 /// getTagType - Return the type describing the specified descriptor (via
767 const StructType *getTagType(DebugInfoDesc *DD);
769 /// getString - Construct the string as constant string global.
771 Constant *getString(const std::string &String);
773 /// Serialize - Recursively cast the specified descriptor into a
774 /// GlobalVariable so that it can be serialized to a .bc or .ll file.
775 GlobalVariable *Serialize(DebugInfoDesc *DD);
778 //===----------------------------------------------------------------------===//
779 /// DIVerifier - This class is responsible for verifying the given network of
780 /// GlobalVariables are valid as DebugInfoDesc objects.
788 std::map<GlobalVariable *, unsigned> Validity;// Tracks prior results.
789 std::map<unsigned, unsigned> Counts; // Count of fields per Tag type.
798 /// Verify - Return true if the GlobalVariable appears to be a valid
799 /// serialization of a DebugInfoDesc.
800 bool Verify(Value *V);
801 bool Verify(GlobalVariable *GV);
804 //===----------------------------------------------------------------------===//
805 /// SourceLineInfo - This class is used to record source line correspondence.
807 class SourceLineInfo {
809 unsigned Line; // Source line number.
810 unsigned Column; // Source column.
811 unsigned SourceID; // Source ID number.
812 unsigned LabelID; // Label in code ID number.
815 SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
816 : Line(L), Column(C), SourceID(S), LabelID(I) {}
819 unsigned getLine() const { return Line; }
820 unsigned getColumn() const { return Column; }
821 unsigned getSourceID() const { return SourceID; }
822 unsigned getLabelID() const { return LabelID; }
825 //===----------------------------------------------------------------------===//
826 /// SourceFileInfo - This class is used to track source information.
828 class SourceFileInfo {
830 unsigned DirectoryID; // Directory ID number.
831 std::string Name; // File name (not including directory.)
834 SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
837 unsigned getDirectoryID() const { return DirectoryID; }
838 const std::string &getName() const { return Name; }
840 /// operator== - Used by UniqueVector to locate entry.
842 bool operator==(const SourceFileInfo &SI) const {
843 return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
846 /// operator< - Used by UniqueVector to locate entry.
848 bool operator<(const SourceFileInfo &SI) const {
849 return getDirectoryID() < SI.getDirectoryID() ||
850 (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
854 //===----------------------------------------------------------------------===//
855 /// DebugVariable - This class is used to track local variable information.
857 class DebugVariable {
859 VariableDesc *Desc; // Variable Descriptor.
860 unsigned FrameIndex; // Variable frame index.
863 DebugVariable(VariableDesc *D, unsigned I)
869 VariableDesc *getDesc() const { return Desc; }
870 unsigned getFrameIndex() const { return FrameIndex; }
873 //===----------------------------------------------------------------------===//
874 /// DebugScope - This class is used to track scope information.
878 DebugScope *Parent; // Parent to this scope.
879 DebugInfoDesc *Desc; // Debug info descriptor for scope.
880 // Either subprogram or block.
881 unsigned StartLabelID; // Label ID of the beginning of scope.
882 unsigned EndLabelID; // Label ID of the end of scope.
883 std::vector<DebugScope *> Scopes; // Scopes defined in scope.
884 std::vector<DebugVariable *> Variables;// Variables declared in scope.
887 DebugScope(DebugScope *P, DebugInfoDesc *D)
898 DebugScope *getParent() const { return Parent; }
899 DebugInfoDesc *getDesc() const { return Desc; }
900 unsigned getStartLabelID() const { return StartLabelID; }
901 unsigned getEndLabelID() const { return EndLabelID; }
902 std::vector<DebugScope *> &getScopes() { return Scopes; }
903 std::vector<DebugVariable *> &getVariables() { return Variables; }
904 void setStartLabelID(unsigned S) { StartLabelID = S; }
905 void setEndLabelID(unsigned E) { EndLabelID = E; }
907 /// AddScope - Add a scope to the scope.
909 void AddScope(DebugScope *S) { Scopes.push_back(S); }
911 /// AddVariable - Add a variable to the scope.
913 void AddVariable(DebugVariable *V) { Variables.push_back(V); }
916 //===----------------------------------------------------------------------===//
917 /// MachineDebugInfo - This class contains debug information specific to a
918 /// module. Queries can be made by different debugging schemes and reformated
919 /// for specific use.
921 class MachineDebugInfo : public ImmutablePass {
923 // Use the same deserializer/verifier for the module.
927 // CompileUnits - Uniquing vector for compile units.
928 UniqueVector<CompileUnitDesc *> CompileUnits;
930 // Directories - Uniquing vector for directories.
931 UniqueVector<std::string> Directories;
933 // SourceFiles - Uniquing vector for source files.
934 UniqueVector<SourceFileInfo> SourceFiles;
936 // Lines - List of of source line correspondence.
937 std::vector<SourceLineInfo *> Lines;
939 // LabelID - Current number assigned to unique label numbers.
942 // ScopeMap - Tracks the scopes in the current function.
943 std::map<DebugInfoDesc *, DebugScope *> ScopeMap;
945 // RootScope - Top level scope for the current function.
947 DebugScope *RootScope;
949 // FrameMoves - List of moves done by a function's prolog. Used to construct
950 // frame maps by debug consumers.
951 std::vector<MachineMove *> FrameMoves;
957 /// doInitialization - Initialize the debug state for a new module.
959 bool doInitialization();
961 /// doFinalization - Tear down the debug state after completion of a module.
963 bool doFinalization();
965 /// BeginFunction - Begin gathering function debug information.
967 void BeginFunction(MachineFunction *MF);
969 /// EndFunction - Discard function debug information.
973 /// getDescFor - Convert a Value to a debug information descriptor.
975 // FIXME - use new Value type when available.
976 DebugInfoDesc *getDescFor(Value *V);
978 /// Verify - Verify that a Value is debug information descriptor.
980 bool Verify(Value *V);
982 /// AnalyzeModule - Scan the module for global debug information.
984 void AnalyzeModule(Module &M);
986 /// hasInfo - Returns true if valid debug info is present.
988 bool hasInfo() const { return !CompileUnits.empty(); }
990 /// NextLabelID - Return the next unique label id.
992 unsigned NextLabelID() { return ++LabelID; }
994 /// RecordLabel - Records location information and associates it with a
995 /// debug label. Returns a unique label ID used to generate a label and
996 /// provide correspondence to the source line list.
997 unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source);
999 /// RecordSource - Register a source file with debug info. Returns an source
1001 unsigned RecordSource(const std::string &Directory,
1002 const std::string &Source);
1003 unsigned RecordSource(const CompileUnitDesc *CompileUnit);
1005 /// getDirectories - Return the UniqueVector of std::string representing
1007 const UniqueVector<std::string> &getDirectories() const {
1011 /// getSourceFiles - Return the UniqueVector of source files.
1013 const UniqueVector<SourceFileInfo> &getSourceFiles() const {
1017 /// getSourceLines - Return a vector of source lines. Vector index + 1
1018 /// equals label ID.
1019 const std::vector<SourceLineInfo *> &getSourceLines() const {
1023 /// SetupCompileUnits - Set up the unique vector of compile units.
1025 void SetupCompileUnits(Module &M);
1027 /// getCompileUnits - Return a vector of debug compile units.
1029 const UniqueVector<CompileUnitDesc *> getCompileUnits() const;
1031 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1032 /// named GlobalVariable.
1033 std::vector<GlobalVariable*>
1034 getGlobalVariablesUsing(Module &M, const std::string &RootName);
1036 /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
1038 template <class T>std::vector<T *> getAnchoredDescriptors(Module &M) {
1040 std::vector<GlobalVariable *> Globals =
1041 getGlobalVariablesUsing(M, Desc.getAnchorString());
1042 std::vector<T *> AnchoredDescs;
1043 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
1044 GlobalVariable *GV = Globals[i];
1046 // FIXME - In the short term, changes are too drastic to continue.
1047 if (DebugInfoDesc::TagFromGlobal(GV) == Desc.getTag() &&
1048 DebugInfoDesc::VersionFromGlobal(GV) == LLVMDebugVersion) {
1049 AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
1053 return AnchoredDescs;
1056 /// RecordRegionStart - Indicate the start of a region.
1058 unsigned RecordRegionStart(Value *V);
1060 /// RecordRegionEnd - Indicate the end of a region.
1062 unsigned RecordRegionEnd(Value *V);
1064 /// RecordVariable - Indicate the declaration of a local variable.
1066 void RecordVariable(Value *V, unsigned FrameIndex);
1068 /// getRootScope - Return current functions root scope.
1070 DebugScope *getRootScope() { return RootScope; }
1072 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1074 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1076 /// getFrameMoves - Returns a reference to a list of moves done in the current
1077 /// function's prologue. Used to construct frame maps for debug comsumers.
1078 std::vector<MachineMove *> &getFrameMoves() { return FrameMoves; }
1080 }; // End class MachineDebugInfo
1082 } // End llvm namespace