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.
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 std::vector<DebugInfoDesc *> Elements;// Information used to compose type.
406 CompositeTypeDesc(unsigned T);
409 std::vector<DebugInfoDesc *> &getElements() { return Elements; }
411 // Implement isa/cast/dyncast.
412 static bool classof(const CompositeTypeDesc *) { return true; }
413 static bool classof(const DebugInfoDesc *D);
415 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
417 virtual void ApplyToFields(DIVisitor *Visitor);
419 /// getDescString - Return a string used to compose global names and labels.
421 virtual const char *getDescString() const;
423 /// getTypeString - Return a string used to label this descriptor's type.
425 virtual const char *getTypeString() const;
432 //===----------------------------------------------------------------------===//
433 /// SubrangeDesc - This class packages debug information associated with integer
435 class SubrangeDesc : public DebugInfoDesc {
437 int64_t Lo; // Low value of range.
438 int64_t Hi; // High value of range.
444 int64_t getLo() const { return Lo; }
445 int64_t getHi() const { return Hi; }
446 void setLo(int64_t L) { Lo = L; }
447 void setHi(int64_t H) { Hi = H; }
449 // Implement isa/cast/dyncast.
450 static bool classof(const SubrangeDesc *) { return true; }
451 static bool classof(const DebugInfoDesc *D);
453 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
455 virtual void ApplyToFields(DIVisitor *Visitor);
457 /// getDescString - Return a string used to compose global names and labels.
459 virtual const char *getDescString() const;
461 /// getTypeString - Return a string used to label this descriptor's type.
463 virtual const char *getTypeString() const;
470 //===----------------------------------------------------------------------===//
471 /// EnumeratorDesc - This class packages debug information associated with
472 /// named integer constants.
473 class EnumeratorDesc : public DebugInfoDesc {
475 std::string Name; // Enumerator name.
476 int64_t Value; // Enumerator value.
482 const std::string &getName() const { return Name; }
483 int64_t getValue() const { return Value; }
484 void setName(const std::string &N) { Name = N; }
485 void setValue(int64_t V) { Value = V; }
487 // Implement isa/cast/dyncast.
488 static bool classof(const EnumeratorDesc *) { return true; }
489 static bool classof(const DebugInfoDesc *D);
491 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
493 virtual void ApplyToFields(DIVisitor *Visitor);
495 /// getDescString - Return a string used to compose global names and labels.
497 virtual const char *getDescString() const;
499 /// getTypeString - Return a string used to label this descriptor's type.
501 virtual const char *getTypeString() const;
508 //===----------------------------------------------------------------------===//
509 /// VariableDesc - This class packages debug information associated with a
510 /// subprogram variable.
512 class VariableDesc : public DebugInfoDesc {
514 DebugInfoDesc *Context; // Context debug descriptor.
515 std::string Name; // Type name (may be empty.)
516 CompileUnitDesc *File; // Defined compile unit (may be NULL.)
517 unsigned Line; // Defined line# (may be zero.)
518 TypeDesc *TyDesc; // Type of variable.
521 VariableDesc(unsigned T);
524 DebugInfoDesc *getContext() const { return Context; }
525 const std::string &getName() const { return Name; }
526 CompileUnitDesc *getFile() const { return File; }
527 unsigned getLine() const { return Line; }
528 TypeDesc *getType() const { return TyDesc; }
529 void setContext(DebugInfoDesc *C) { Context = C; }
530 void setName(const std::string &N) { Name = N; }
531 void setFile(CompileUnitDesc *U) { File = U; }
532 void setLine(unsigned L) { Line = L; }
533 void setType(TypeDesc *T) { TyDesc = T; }
535 // Implement isa/cast/dyncast.
536 static bool classof(const VariableDesc *) { return true; }
537 static bool classof(const DebugInfoDesc *D);
539 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
541 virtual void ApplyToFields(DIVisitor *Visitor);
543 /// getDescString - Return a string used to compose global names and labels.
545 virtual const char *getDescString() const;
547 /// getTypeString - Return a string used to label this descriptor's type.
549 virtual const char *getTypeString() const;
556 //===----------------------------------------------------------------------===//
557 /// GlobalDesc - This class is the base descriptor for global functions and
559 class GlobalDesc : public AnchoredDesc {
561 DebugInfoDesc *Context; // Context debug descriptor.
562 std::string Name; // Global name.
563 CompileUnitDesc *File; // Defined compile unit (may be NULL.)
564 unsigned Line; // Defined line# (may be zero.)
565 TypeDesc *TyDesc; // Type debug descriptor.
566 bool IsStatic; // Is the global a static.
567 bool IsDefinition; // Is the global defined in context.
570 GlobalDesc(unsigned T);
574 DebugInfoDesc *getContext() const { return Context; }
575 const std::string &getName() const { return Name; }
576 CompileUnitDesc *getFile() const { return File; }
577 unsigned getLine() const { return Line; }
578 TypeDesc *getType() const { return TyDesc; }
579 bool isStatic() const { return IsStatic; }
580 bool isDefinition() const { return IsDefinition; }
581 void setContext(DebugInfoDesc *C) { Context = C; }
582 void setName(const std::string &N) { Name = N; }
583 void setFile(CompileUnitDesc *U) { File = U; }
584 void setLine(unsigned L) { Line = L; }
585 void setType(TypeDesc *T) { TyDesc = T; }
586 void setIsStatic(bool IS) { IsStatic = IS; }
587 void setIsDefinition(bool ID) { IsDefinition = ID; }
589 /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
591 virtual void ApplyToFields(DIVisitor *Visitor);
594 //===----------------------------------------------------------------------===//
595 /// GlobalVariableDesc - This class packages debug information associated with a
597 class GlobalVariableDesc : public GlobalDesc {
599 GlobalVariable *Global; // llvm global.
602 GlobalVariableDesc();
605 GlobalVariable *getGlobalVariable() const { return Global; }
606 void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
608 // Implement isa/cast/dyncast.
609 static bool classof(const GlobalVariableDesc *) { return true; }
610 static bool classof(const DebugInfoDesc *D);
612 /// ApplyToFields - Target the visitor to the fields of the
613 /// GlobalVariableDesc.
614 virtual void ApplyToFields(DIVisitor *Visitor);
616 /// getDescString - Return a string used to compose global names and labels.
618 virtual const char *getDescString() const;
620 /// getTypeString - Return a string used to label this descriptor's type.
622 virtual const char *getTypeString() const;
624 /// getAnchorString - Return a string used to label this descriptor's anchor.
626 static const char *AnchorString;
627 virtual const char *getAnchorString() const;
634 //===----------------------------------------------------------------------===//
635 /// SubprogramDesc - This class packages debug information associated with a
636 /// subprogram/function.
637 class SubprogramDesc : public GlobalDesc {
645 // Implement isa/cast/dyncast.
646 static bool classof(const SubprogramDesc *) { return true; }
647 static bool classof(const DebugInfoDesc *D);
649 /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
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 /// BlockDesc - This descriptor groups variables and blocks nested in a block.
674 class BlockDesc : public DebugInfoDesc {
676 DebugInfoDesc *Context; // Context debug descriptor.
682 DebugInfoDesc *getContext() const { return Context; }
683 void setContext(DebugInfoDesc *C) { Context = C; }
685 // Implement isa/cast/dyncast.
686 static bool classof(const BlockDesc *) { return true; }
687 static bool classof(const DebugInfoDesc *D);
689 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
691 virtual void ApplyToFields(DIVisitor *Visitor);
693 /// getDescString - Return a string used to compose global names and labels.
695 virtual const char *getDescString() const;
697 /// getTypeString - Return a string used to label this descriptor's type.
699 virtual const char *getTypeString() const;
706 //===----------------------------------------------------------------------===//
707 /// DIDeserializer - This class is responsible for casting GlobalVariables
708 /// into DebugInfoDesc objects.
709 class DIDeserializer {
711 std::map<GlobalVariable *, DebugInfoDesc *> GlobalDescs;
712 // Previously defined gloabls.
718 /// Deserialize - Reconstitute a GlobalVariable into it's component
719 /// DebugInfoDesc objects.
720 DebugInfoDesc *Deserialize(Value *V);
721 DebugInfoDesc *Deserialize(GlobalVariable *GV);
724 //===----------------------------------------------------------------------===//
725 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
726 /// into GlobalVariables.
729 Module *M; // Definition space module.
730 PointerType *StrPtrTy; // A "sbyte *" type. Created lazily.
731 PointerType *EmptyStructPtrTy; // A "{ }*" type. Created lazily.
732 std::map<unsigned, StructType *> TagTypes;
733 // Types per Tag. Created lazily.
734 std::map<DebugInfoDesc *, GlobalVariable *> DescGlobals;
735 // Previously defined descriptors.
736 std::map<const std::string, Constant *> StringCache;
737 // Previously defined strings.
743 , EmptyStructPtrTy(NULL)
751 Module *getModule() const { return M; };
752 void setModule(Module *module) { M = module; }
754 /// getStrPtrType - Return a "sbyte *" type.
756 const PointerType *getStrPtrType();
758 /// getEmptyStructPtrType - Return a "{ }*" type.
760 const PointerType *getEmptyStructPtrType();
762 /// getTagType - Return the type describing the specified descriptor (via
764 const StructType *getTagType(DebugInfoDesc *DD);
766 /// getString - Construct the string as constant string global.
768 Constant *getString(const std::string &String);
770 /// Serialize - Recursively cast the specified descriptor into a
771 /// GlobalVariable so that it can be serialized to a .bc or .ll file.
772 GlobalVariable *Serialize(DebugInfoDesc *DD);
775 //===----------------------------------------------------------------------===//
776 /// DIVerifier - This class is responsible for verifying the given network of
777 /// GlobalVariables are valid as DebugInfoDesc objects.
785 std::map<GlobalVariable *, unsigned> Validity;// Tracks prior results.
786 std::map<unsigned, unsigned> Counts; // Count of fields per Tag type.
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];
1043 // FIXME - In the short term, changes are too drastic to continue.
1044 if (DebugInfoDesc::TagFromGlobal(GV) == Desc.getTag() &&
1045 DebugInfoDesc::VersionFromGlobal(GV) == LLVMDebugVersion) {
1046 AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
1050 return AnchoredDescs;
1053 /// RecordRegionStart - Indicate the start of a region.
1055 unsigned RecordRegionStart(Value *V);
1057 /// RecordRegionEnd - Indicate the end of a region.
1059 unsigned RecordRegionEnd(Value *V);
1061 /// RecordVariable - Indicate the declaration of a local variable.
1063 void RecordVariable(Value *V, unsigned FrameIndex);
1065 /// getRootScope - Return current functions root scope.
1067 DebugScope *getRootScope() { return RootScope; }
1069 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1071 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1073 /// getFrameMoves - Returns a reference to a list of moves done in the current
1074 /// function's prologue. Used to construct frame maps for debug comsumers.
1075 std::vector<MachineMove *> &getFrameMoves() { return FrameMoves; }
1077 }; // End class MachineDebugInfo
1079 } // End llvm namespace