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 = 3 // 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.
93 unsigned Tag; // Content indicator. Dwarf values are
94 // used but that does not limit use to
98 DebugInfoDesc(unsigned T) : Tag(T) {}
101 virtual ~DebugInfoDesc() {}
104 unsigned getTag() const { return Tag; }
106 /// TagFromGlobal - Returns the Tag number from a debug info descriptor
107 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
108 static unsigned TagFromGlobal(GlobalVariable *GV);
110 /// DescFactory - Create an instance of debug info descriptor based on Tag.
111 /// Return NULL if not a recognized Tag.
112 static DebugInfoDesc *DescFactory(unsigned Tag);
114 /// getLinkage - get linkage appropriate for this type of descriptor.
116 virtual GlobalValue::LinkageTypes getLinkage() const;
118 //===--------------------------------------------------------------------===//
119 // Subclasses should supply the following static methods.
121 // Implement isa/cast/dyncast.
122 static bool classof(const DebugInfoDesc *) { return true; }
124 //===--------------------------------------------------------------------===//
125 // Subclasses should supply the following virtual methods.
127 /// ApplyToFields - Target the vistor to the fields of the descriptor.
129 virtual void ApplyToFields(DIVisitor *Visitor);
131 /// getDescString - Return a string used to compose global names and labels.
133 virtual const char *getDescString() const = 0;
135 /// getTypeString - Return a string used to label this descriptor's type.
137 virtual const char *getTypeString() const = 0;
140 virtual void dump() = 0;
144 //===----------------------------------------------------------------------===//
145 /// AnchorDesc - Descriptors of this class act as markers for identifying
146 /// descriptors of certain groups.
148 class AnchorDesc : public DebugInfoDesc {
150 unsigned AnchorTag; // Tag number of descriptors anchored
155 AnchorDesc(AnchoredDesc *D);
158 unsigned getAnchorTag() const { return AnchorTag; }
160 // Implement isa/cast/dyncast.
161 static bool classof(const AnchorDesc *) { return true; }
162 static bool classof(const DebugInfoDesc *D);
164 /// getLinkage - get linkage appropriate for this type of descriptor.
166 virtual GlobalValue::LinkageTypes getLinkage() const;
168 /// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
170 virtual void ApplyToFields(DIVisitor *Visitor);
172 /// getDescString - Return a string used to compose global names and labels.
174 virtual const char *getDescString() const;
176 /// getTypeString - Return a string used to label this descriptor's type.
178 virtual const char *getTypeString() const;
185 //===----------------------------------------------------------------------===//
186 /// AnchoredDesc - This class manages anchors for a variety of top level
188 class AnchoredDesc : public DebugInfoDesc {
190 AnchorDesc *Anchor; // Anchor for all descriptors of the
195 AnchoredDesc(unsigned T);
199 AnchorDesc *getAnchor() const { return Anchor; }
200 void setAnchor(AnchorDesc *A) { Anchor = A; }
202 //===--------------------------------------------------------------------===//
203 // Subclasses should supply the following virtual methods.
205 /// getAnchorString - Return a string used to label descriptor's anchor.
207 virtual const char *getAnchorString() const = 0;
209 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
211 virtual void ApplyToFields(DIVisitor *Visitor);
214 //===----------------------------------------------------------------------===//
215 /// CompileUnitDesc - This class packages debug information associated with a
216 /// source/header file.
217 class CompileUnitDesc : public AnchoredDesc {
219 unsigned DebugVersion; // LLVM debug version when produced.
220 unsigned Language; // Language number (ex. DW_LANG_C89.)
221 std::string FileName; // Source file name.
222 std::string Directory; // Source file directory.
223 std::string Producer; // Compiler string.
230 unsigned getDebugVersion() const { return DebugVersion; }
231 unsigned getLanguage() const { return Language; }
232 const std::string &getFileName() const { return FileName; }
233 const std::string &getDirectory() const { return Directory; }
234 const std::string &getProducer() const { return Producer; }
235 void setLanguage(unsigned L) { Language = L; }
236 void setFileName(const std::string &FN) { FileName = FN; }
237 void setDirectory(const std::string &D) { Directory = D; }
238 void setProducer(const std::string &P) { Producer = P; }
240 // FIXME - Need translation unit getter/setter.
242 // Implement isa/cast/dyncast.
243 static bool classof(const CompileUnitDesc *) { return true; }
244 static bool classof(const DebugInfoDesc *D);
246 /// DebugVersionFromGlobal - Returns the version number from a compile unit
247 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
248 static unsigned DebugVersionFromGlobal(GlobalVariable *GV);
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 {
277 DebugInfoDesc *Context; // Context debug descriptor.
278 std::string Name; // Type name (may be empty.)
279 CompileUnitDesc *File; // Defined compile unit (may be NULL.)
280 unsigned Line; // Defined line# (may be zero.)
281 uint64_t Size; // Type bit size (may be zero.)
282 uint64_t Align; // Type bit alignment (may be zero.)
283 uint64_t Offset; // Type bit offset (may be zero.)
286 TypeDesc(unsigned T);
289 DebugInfoDesc *getContext() const { return Context; }
290 const std::string &getName() const { return Name; }
291 CompileUnitDesc *getFile() const { return File; }
292 unsigned getLine() const { return Line; }
293 uint64_t getSize() const { return Size; }
294 uint64_t getAlign() const { return Align; }
295 uint64_t getOffset() const { return Offset; }
296 void setContext(DebugInfoDesc *C) { Context = C; }
297 void setName(const std::string &N) { Name = N; }
298 void setFile(CompileUnitDesc *U) { File = U; }
299 void setLine(unsigned L) { Line = L; }
300 void setSize(uint64_t S) { Size = S; }
301 void setAlign(uint64_t A) { Align = A; }
302 void setOffset(uint64_t O) { Offset = O; }
304 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
306 virtual void ApplyToFields(DIVisitor *Visitor);
308 /// getDescString - Return a string used to compose global names and labels.
310 virtual const char *getDescString() const;
312 /// getTypeString - Return a string used to label this descriptor's type.
314 virtual const char *getTypeString() const;
321 //===----------------------------------------------------------------------===//
322 /// BasicTypeDesc - This class packages debug information associated with a
323 /// basic type (eg. int, bool, double.)
324 class BasicTypeDesc : public TypeDesc {
326 unsigned Encoding; // Type encoding.
332 unsigned getEncoding() const { return Encoding; }
333 void setEncoding(unsigned E) { Encoding = E; }
335 // Implement isa/cast/dyncast.
336 static bool classof(const BasicTypeDesc *) { return true; }
337 static bool classof(const DebugInfoDesc *D);
339 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
341 virtual void ApplyToFields(DIVisitor *Visitor);
343 /// getDescString - Return a string used to compose global names and labels.
345 virtual const char *getDescString() const;
347 /// getTypeString - Return a string used to label this descriptor's type.
349 virtual const char *getTypeString() const;
357 //===----------------------------------------------------------------------===//
358 /// DerivedTypeDesc - This class packages debug information associated with a
359 /// derived types (eg., typedef, pointer, reference.)
360 class DerivedTypeDesc : public TypeDesc {
362 TypeDesc *FromType; // Type derived from.
365 DerivedTypeDesc(unsigned T);
368 TypeDesc *getFromType() const { return FromType; }
369 void setFromType(TypeDesc *F) { FromType = F; }
371 // Implement isa/cast/dyncast.
372 static bool classof(const DerivedTypeDesc *) { return true; }
373 static bool classof(const DebugInfoDesc *D);
375 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
377 virtual void ApplyToFields(DIVisitor *Visitor);
379 /// getDescString - Return a string used to compose global names and labels.
381 virtual const char *getDescString() const;
383 /// getTypeString - Return a string used to label this descriptor's type.
385 virtual const char *getTypeString() const;
392 //===----------------------------------------------------------------------===//
393 /// CompositeTypeDesc - This class packages debug information associated with a
394 /// array/struct types (eg., arrays, struct, union, enums.)
395 class CompositeTypeDesc : public DerivedTypeDesc {
397 std::vector<DebugInfoDesc *> Elements;// Information used to compose type.
400 CompositeTypeDesc(unsigned T);
403 std::vector<DebugInfoDesc *> &getElements() { return Elements; }
405 // Implement isa/cast/dyncast.
406 static bool classof(const CompositeTypeDesc *) { return true; }
407 static bool classof(const DebugInfoDesc *D);
409 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
411 virtual void ApplyToFields(DIVisitor *Visitor);
413 /// getDescString - Return a string used to compose global names and labels.
415 virtual const char *getDescString() const;
417 /// getTypeString - Return a string used to label this descriptor's type.
419 virtual const char *getTypeString() const;
426 //===----------------------------------------------------------------------===//
427 /// SubrangeDesc - This class packages debug information associated with integer
429 class SubrangeDesc : public DebugInfoDesc {
431 int64_t Lo; // Low value of range.
432 int64_t Hi; // High value of range.
438 int64_t getLo() const { return Lo; }
439 int64_t getHi() const { return Hi; }
440 void setLo(int64_t L) { Lo = L; }
441 void setHi(int64_t H) { Hi = H; }
443 // Implement isa/cast/dyncast.
444 static bool classof(const SubrangeDesc *) { return true; }
445 static bool classof(const DebugInfoDesc *D);
447 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
449 virtual void ApplyToFields(DIVisitor *Visitor);
451 /// getDescString - Return a string used to compose global names and labels.
453 virtual const char *getDescString() const;
455 /// getTypeString - Return a string used to label this descriptor's type.
457 virtual const char *getTypeString() const;
464 //===----------------------------------------------------------------------===//
465 /// EnumeratorDesc - This class packages debug information associated with
466 /// named integer constants.
467 class EnumeratorDesc : public DebugInfoDesc {
469 std::string Name; // Enumerator name.
470 int64_t Value; // Enumerator value.
476 const std::string &getName() const { return Name; }
477 int64_t getValue() const { return Value; }
478 void setName(const std::string &N) { Name = N; }
479 void setValue(int64_t V) { Value = V; }
481 // Implement isa/cast/dyncast.
482 static bool classof(const EnumeratorDesc *) { return true; }
483 static bool classof(const DebugInfoDesc *D);
485 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
487 virtual void ApplyToFields(DIVisitor *Visitor);
489 /// getDescString - Return a string used to compose global names and labels.
491 virtual const char *getDescString() const;
493 /// getTypeString - Return a string used to label this descriptor's type.
495 virtual const char *getTypeString() const;
502 //===----------------------------------------------------------------------===//
503 /// VariableDesc - This class packages debug information associated with a
504 /// subprogram variable.
506 class VariableDesc : public DebugInfoDesc {
508 DebugInfoDesc *Context; // Context debug descriptor.
509 std::string Name; // Type name (may be empty.)
510 CompileUnitDesc *File; // Defined compile unit (may be NULL.)
511 unsigned Line; // Defined line# (may be zero.)
512 TypeDesc *TyDesc; // Type of variable.
515 VariableDesc(unsigned T);
518 DebugInfoDesc *getContext() const { return Context; }
519 const std::string &getName() const { return Name; }
520 CompileUnitDesc *getFile() const { return File; }
521 unsigned getLine() const { return Line; }
522 TypeDesc *getType() const { return TyDesc; }
523 void setContext(DebugInfoDesc *C) { Context = C; }
524 void setName(const std::string &N) { Name = N; }
525 void setFile(CompileUnitDesc *U) { File = U; }
526 void setLine(unsigned L) { Line = L; }
527 void setType(TypeDesc *T) { TyDesc = T; }
529 // Implement isa/cast/dyncast.
530 static bool classof(const VariableDesc *) { return true; }
531 static bool classof(const DebugInfoDesc *D);
533 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
535 virtual void ApplyToFields(DIVisitor *Visitor);
537 /// getDescString - Return a string used to compose global names and labels.
539 virtual const char *getDescString() const;
541 /// getTypeString - Return a string used to label this descriptor's type.
543 virtual const char *getTypeString() const;
550 //===----------------------------------------------------------------------===//
551 /// GlobalDesc - This class is the base descriptor for global functions and
553 class GlobalDesc : public AnchoredDesc {
555 DebugInfoDesc *Context; // Context debug descriptor.
556 std::string Name; // Global name.
557 CompileUnitDesc *File; // Defined compile unit (may be NULL.)
558 unsigned Line; // Defined line# (may be zero.)
559 TypeDesc *TyDesc; // Type debug descriptor.
560 bool IsStatic; // Is the global a static.
561 bool IsDefinition; // Is the global defined in context.
564 GlobalDesc(unsigned T);
568 DebugInfoDesc *getContext() const { return Context; }
569 const std::string &getName() const { return Name; }
570 CompileUnitDesc *getFile() const { return File; }
571 unsigned getLine() const { return Line; }
572 TypeDesc *getType() const { return TyDesc; }
573 bool isStatic() const { return IsStatic; }
574 bool isDefinition() const { return IsDefinition; }
575 void setContext(DebugInfoDesc *C) { Context = C; }
576 void setName(const std::string &N) { Name = N; }
577 void setFile(CompileUnitDesc *U) { File = U; }
578 void setLine(unsigned L) { Line = L; }
579 void setType(TypeDesc *T) { TyDesc = T; }
580 void setIsStatic(bool IS) { IsStatic = IS; }
581 void setIsDefinition(bool ID) { IsDefinition = ID; }
583 /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
585 virtual void ApplyToFields(DIVisitor *Visitor);
588 //===----------------------------------------------------------------------===//
589 /// GlobalVariableDesc - This class packages debug information associated with a
591 class GlobalVariableDesc : public GlobalDesc {
593 GlobalVariable *Global; // llvm global.
596 GlobalVariableDesc();
599 GlobalVariable *getGlobalVariable() const { return Global; }
600 void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
602 // Implement isa/cast/dyncast.
603 static bool classof(const GlobalVariableDesc *) { return true; }
604 static bool classof(const DebugInfoDesc *D);
606 /// ApplyToFields - Target the visitor to the fields of the
607 /// GlobalVariableDesc.
608 virtual void ApplyToFields(DIVisitor *Visitor);
610 /// getDescString - Return a string used to compose global names and labels.
612 virtual const char *getDescString() const;
614 /// getTypeString - Return a string used to label this descriptor's type.
616 virtual const char *getTypeString() const;
618 /// getAnchorString - Return a string used to label this descriptor's anchor.
620 static const char *AnchorString;
621 virtual const char *getAnchorString() const;
628 //===----------------------------------------------------------------------===//
629 /// SubprogramDesc - This class packages debug information associated with a
630 /// subprogram/function.
631 class SubprogramDesc : public GlobalDesc {
639 // Implement isa/cast/dyncast.
640 static bool classof(const SubprogramDesc *) { return true; }
641 static bool classof(const DebugInfoDesc *D);
643 /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
645 virtual void ApplyToFields(DIVisitor *Visitor);
647 /// getDescString - Return a string used to compose global names and labels.
649 virtual const char *getDescString() const;
651 /// getTypeString - Return a string used to label this descriptor's type.
653 virtual const char *getTypeString() const;
655 /// getAnchorString - Return a string used to label this descriptor's anchor.
657 static const char *AnchorString;
658 virtual const char *getAnchorString() const;
665 //===----------------------------------------------------------------------===//
666 /// BlockDesc - This descriptor groups variables and blocks nested in a block.
668 class BlockDesc : public DebugInfoDesc {
670 DebugInfoDesc *Context; // Context debug descriptor.
676 DebugInfoDesc *getContext() const { return Context; }
677 void setContext(DebugInfoDesc *C) { Context = C; }
679 // Implement isa/cast/dyncast.
680 static bool classof(const BlockDesc *) { return true; }
681 static bool classof(const DebugInfoDesc *D);
683 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
685 virtual void ApplyToFields(DIVisitor *Visitor);
687 /// getDescString - Return a string used to compose global names and labels.
689 virtual const char *getDescString() const;
691 /// getTypeString - Return a string used to label this descriptor's type.
693 virtual const char *getTypeString() const;
700 //===----------------------------------------------------------------------===//
701 /// DIDeserializer - This class is responsible for casting GlobalVariables
702 /// into DebugInfoDesc objects.
703 class DIDeserializer {
705 unsigned DebugVersion; // Version of debug information in use.
706 std::map<GlobalVariable *, DebugInfoDesc *> GlobalDescs;
707 // Previously defined gloabls.
710 DIDeserializer() : DebugVersion(LLVMDebugVersion) {}
714 unsigned getDebugVersion() const { return DebugVersion; }
716 /// Deserialize - Reconstitute a GlobalVariable into it's component
717 /// DebugInfoDesc objects.
718 DebugInfoDesc *Deserialize(Value *V);
719 DebugInfoDesc *Deserialize(GlobalVariable *GV);
722 //===----------------------------------------------------------------------===//
723 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
724 /// into GlobalVariables.
727 Module *M; // Definition space module.
728 PointerType *StrPtrTy; // A "sbyte *" type. Created lazily.
729 PointerType *EmptyStructPtrTy; // A "{ }*" type. Created lazily.
730 std::map<unsigned, StructType *> TagTypes;
731 // Types per Tag. Created lazily.
732 std::map<DebugInfoDesc *, GlobalVariable *> DescGlobals;
733 // Previously defined descriptors.
734 std::map<const std::string, Constant *> StringCache;
735 // Previously defined strings.
741 , EmptyStructPtrTy(NULL)
749 Module *getModule() const { return M; };
750 void setModule(Module *module) { M = module; }
752 /// getStrPtrType - Return a "sbyte *" type.
754 const PointerType *getStrPtrType();
756 /// getEmptyStructPtrType - Return a "{ }*" type.
758 const PointerType *getEmptyStructPtrType();
760 /// getTagType - Return the type describing the specified descriptor (via
762 const StructType *getTagType(DebugInfoDesc *DD);
764 /// getString - Construct the string as constant string global.
766 Constant *getString(const std::string &String);
768 /// Serialize - Recursively cast the specified descriptor into a
769 /// GlobalVariable so that it can be serialized to a .bc or .ll file.
770 GlobalVariable *Serialize(DebugInfoDesc *DD);
773 //===----------------------------------------------------------------------===//
774 /// DIVerifier - This class is responsible for verifying the given network of
775 /// GlobalVariables are valid as DebugInfoDesc objects.
783 unsigned DebugVersion; // Version of debug information in use.
784 std::map<GlobalVariable *, unsigned> Validity;// Tracks prior results.
785 std::map<unsigned, unsigned> Counts; // Count of fields per Tag type.
789 : DebugVersion(LLVMDebugVersion)
795 /// Verify - Return true if the GlobalVariable appears to be a valid
796 /// serialization of a DebugInfoDesc.
797 bool Verify(Value *V);
798 bool Verify(GlobalVariable *GV);
801 //===----------------------------------------------------------------------===//
802 /// SourceLineInfo - This class is used to record source line correspondence.
804 class SourceLineInfo {
806 unsigned Line; // Source line number.
807 unsigned Column; // Source column.
808 unsigned SourceID; // Source ID number.
809 unsigned LabelID; // Label in code ID number.
812 SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
813 : Line(L), Column(C), SourceID(S), LabelID(I) {}
816 unsigned getLine() const { return Line; }
817 unsigned getColumn() const { return Column; }
818 unsigned getSourceID() const { return SourceID; }
819 unsigned getLabelID() const { return LabelID; }
822 //===----------------------------------------------------------------------===//
823 /// SourceFileInfo - This class is used to track source information.
825 class SourceFileInfo {
827 unsigned DirectoryID; // Directory ID number.
828 std::string Name; // File name (not including directory.)
831 SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
834 unsigned getDirectoryID() const { return DirectoryID; }
835 const std::string &getName() const { return Name; }
837 /// operator== - Used by UniqueVector to locate entry.
839 bool operator==(const SourceFileInfo &SI) const {
840 return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
843 /// operator< - Used by UniqueVector to locate entry.
845 bool operator<(const SourceFileInfo &SI) const {
846 return getDirectoryID() < SI.getDirectoryID() ||
847 (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
851 //===----------------------------------------------------------------------===//
852 /// DebugVariable - This class is used to track local variable information.
854 class DebugVariable {
856 VariableDesc *Desc; // Variable Descriptor.
857 unsigned FrameIndex; // Variable frame index.
860 DebugVariable(VariableDesc *D, unsigned I)
866 VariableDesc *getDesc() const { return Desc; }
867 unsigned getFrameIndex() const { return FrameIndex; }
870 //===----------------------------------------------------------------------===//
871 /// DebugScope - This class is used to track scope information.
875 DebugScope *Parent; // Parent to this scope.
876 DebugInfoDesc *Desc; // Debug info descriptor for scope.
877 // Either subprogram or block.
878 unsigned StartLabelID; // Label ID of the beginning of scope.
879 unsigned EndLabelID; // Label ID of the end of scope.
880 std::vector<DebugScope *> Scopes; // Scopes defined in scope.
881 std::vector<DebugVariable *> Variables;// Variables declared in scope.
884 DebugScope(DebugScope *P, DebugInfoDesc *D)
895 DebugScope *getParent() const { return Parent; }
896 DebugInfoDesc *getDesc() const { return Desc; }
897 unsigned getStartLabelID() const { return StartLabelID; }
898 unsigned getEndLabelID() const { return EndLabelID; }
899 std::vector<DebugScope *> &getScopes() { return Scopes; }
900 std::vector<DebugVariable *> &getVariables() { return Variables; }
901 void setStartLabelID(unsigned S) { StartLabelID = S; }
902 void setEndLabelID(unsigned E) { EndLabelID = E; }
904 /// AddScope - Add a scope to the scope.
906 void AddScope(DebugScope *S) { Scopes.push_back(S); }
908 /// AddVariable - Add a variable to the scope.
910 void AddVariable(DebugVariable *V) { Variables.push_back(V); }
913 //===----------------------------------------------------------------------===//
914 /// MachineDebugInfo - This class contains debug information specific to a
915 /// module. Queries can be made by different debugging schemes and reformated
916 /// for specific use.
918 class MachineDebugInfo : public ImmutablePass {
920 // Use the same deserializer/verifier for the module.
924 // CompileUnits - Uniquing vector for compile units.
925 UniqueVector<CompileUnitDesc *> CompileUnits;
927 // Directories - Uniquing vector for directories.
928 UniqueVector<std::string> Directories;
930 // SourceFiles - Uniquing vector for source files.
931 UniqueVector<SourceFileInfo> SourceFiles;
933 // Lines - List of of source line correspondence.
934 std::vector<SourceLineInfo *> Lines;
936 // LabelID - Current number assigned to unique label numbers.
939 // ScopeMap - Tracks the scopes in the current function.
940 std::map<DebugInfoDesc *, DebugScope *> ScopeMap;
942 // RootScope - Top level scope for the current function.
944 DebugScope *RootScope;
946 // FrameMoves - List of moves done by a function's prolog. Used to construct
947 // frame maps by debug consumers.
948 std::vector<MachineMove *> FrameMoves;
954 /// doInitialization - Initialize the debug state for a new module.
956 bool doInitialization();
958 /// doFinalization - Tear down the debug state after completion of a module.
960 bool doFinalization();
962 /// BeginFunction - Begin gathering function debug information.
964 void BeginFunction(MachineFunction *MF);
966 /// EndFunction - Discard function debug information.
970 /// getDescFor - Convert a Value to a debug information descriptor.
972 // FIXME - use new Value type when available.
973 DebugInfoDesc *getDescFor(Value *V);
975 /// Verify - Verify that a Value is debug information descriptor.
977 bool Verify(Value *V);
979 /// AnalyzeModule - Scan the module for global debug information.
981 void AnalyzeModule(Module &M);
983 /// hasInfo - Returns true if valid debug info is present.
985 bool hasInfo() const { return !CompileUnits.empty(); }
987 /// NextLabelID - Return the next unique label id.
989 unsigned NextLabelID() { return ++LabelID; }
991 /// RecordLabel - Records location information and associates it with a
992 /// debug label. Returns a unique label ID used to generate a label and
993 /// provide correspondence to the source line list.
994 unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source);
996 /// RecordSource - Register a source file with debug info. Returns an source
998 unsigned RecordSource(const std::string &Directory,
999 const std::string &Source);
1000 unsigned RecordSource(const CompileUnitDesc *CompileUnit);
1002 /// getDirectories - Return the UniqueVector of std::string representing
1004 const UniqueVector<std::string> &getDirectories() const {
1008 /// getSourceFiles - Return the UniqueVector of source files.
1010 const UniqueVector<SourceFileInfo> &getSourceFiles() const {
1014 /// getSourceLines - Return a vector of source lines. Vector index + 1
1015 /// equals label ID.
1016 const std::vector<SourceLineInfo *> &getSourceLines() const {
1020 /// SetupCompileUnits - Set up the unique vector of compile units.
1022 void SetupCompileUnits(Module &M);
1024 /// getCompileUnits - Return a vector of debug compile units.
1026 const UniqueVector<CompileUnitDesc *> getCompileUnits() const;
1028 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1029 /// named GlobalVariable.
1030 std::vector<GlobalVariable*>
1031 getGlobalVariablesUsing(Module &M, const std::string &RootName);
1033 /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
1035 template <class T>std::vector<T *> getAnchoredDescriptors(Module &M) {
1037 std::vector<GlobalVariable *> Globals =
1038 getGlobalVariablesUsing(M, Desc.getAnchorString());
1039 std::vector<T *> AnchoredDescs;
1040 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
1041 GlobalVariable *GV = Globals[i];
1042 unsigned Tag = DebugInfoDesc::TagFromGlobal(GV);
1044 if (isa<CompileUnitDesc>(&Desc)) {
1045 unsigned DebugVersion = CompileUnitDesc::DebugVersionFromGlobal(GV);
1046 // FIXME - In the short term, changes are too drastic to continue.
1047 if (DebugVersion != LLVMDebugVersion) break;
1050 if (Tag == Desc.getTag()) {
1051 AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
1055 return AnchoredDescs;
1058 /// RecordRegionStart - Indicate the start of a region.
1060 unsigned RecordRegionStart(Value *V);
1062 /// RecordRegionEnd - Indicate the end of a region.
1064 unsigned RecordRegionEnd(Value *V);
1066 /// RecordVariable - Indicate the declaration of a local variable.
1068 void RecordVariable(Value *V, unsigned FrameIndex);
1070 /// getRootScope - Return current functions root scope.
1072 DebugScope *getRootScope() { return RootScope; }
1074 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1076 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1078 /// getFrameMoves - Returns a reference to a list of moves done in the current
1079 /// function's prologue. Used to construct frame maps for debug comsumers.
1080 std::vector<MachineMove *> &getFrameMoves() { return FrameMoves; }
1082 }; // End class MachineDebugInfo
1084 } // End llvm namespace