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.
54 //===----------------------------------------------------------------------===//
55 // Debug info constants.
58 LLVMDebugVersion = 3 // Current version of debug information.
61 //===----------------------------------------------------------------------===//
62 /// DIVisitor - Subclasses of this class apply steps to each of the fields in
63 /// the supplied DebugInfoDesc.
67 virtual ~DIVisitor() {}
69 /// ApplyToFields - Target the visitor to each field of the debug information
71 void ApplyToFields(DebugInfoDesc *DD);
73 /// Apply - Subclasses override each of these methods to perform the
74 /// appropriate action for the type of field.
75 virtual void Apply(int &Field) = 0;
76 virtual void Apply(unsigned &Field) = 0;
77 virtual void Apply(int64_t &Field) = 0;
78 virtual void Apply(uint64_t &Field) = 0;
79 virtual void Apply(bool &Field) = 0;
80 virtual void Apply(std::string &Field) = 0;
81 virtual void Apply(DebugInfoDesc *&Field) = 0;
82 virtual void Apply(GlobalVariable *&Field) = 0;
83 virtual void Apply(std::vector<DebugInfoDesc *> &Field) = 0;
86 //===----------------------------------------------------------------------===//
87 /// DebugInfoDesc - This class is the base class for debug info descriptors.
91 unsigned Tag; // Content indicator. Dwarf values are
92 // used but that does not limit use to
96 DebugInfoDesc(unsigned T) : Tag(T) {}
99 virtual ~DebugInfoDesc() {}
102 unsigned getTag() const { return Tag; }
104 /// TagFromGlobal - Returns the Tag number from a debug info descriptor
105 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
106 static unsigned TagFromGlobal(GlobalVariable *GV);
108 /// DescFactory - Create an instance of debug info descriptor based on Tag.
109 /// Return NULL if not a recognized Tag.
110 static DebugInfoDesc *DescFactory(unsigned Tag);
112 /// getLinkage - get linkage appropriate for this type of descriptor.
114 virtual GlobalValue::LinkageTypes getLinkage() const;
116 //===--------------------------------------------------------------------===//
117 // Subclasses should supply the following static methods.
119 // Implement isa/cast/dyncast.
120 static bool classof(const DebugInfoDesc *) { return true; }
122 //===--------------------------------------------------------------------===//
123 // Subclasses should supply the following virtual methods.
125 /// ApplyToFields - Target the vistor to the fields of the descriptor.
127 virtual void ApplyToFields(DIVisitor *Visitor);
129 /// getDescString - Return a string used to compose global names and labels.
131 virtual const char *getDescString() const = 0;
133 /// getTypeString - Return a string used to label this descriptor's type.
135 virtual const char *getTypeString() const = 0;
138 virtual void dump() = 0;
142 //===----------------------------------------------------------------------===//
143 /// AnchorDesc - Descriptors of this class act as markers for identifying
144 /// descriptors of certain groups.
146 class AnchorDesc : public DebugInfoDesc {
148 unsigned AnchorTag; // Tag number of descriptors anchored
153 AnchorDesc(AnchoredDesc *D);
156 unsigned getAnchorTag() const { return AnchorTag; }
158 // Implement isa/cast/dyncast.
159 static bool classof(const AnchorDesc *) { return true; }
160 static bool classof(const DebugInfoDesc *D);
162 /// getLinkage - get linkage appropriate for this type of descriptor.
164 virtual GlobalValue::LinkageTypes getLinkage() const;
166 /// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
168 virtual void ApplyToFields(DIVisitor *Visitor);
170 /// getDescString - Return a string used to compose global names and labels.
172 virtual const char *getDescString() const;
174 /// getTypeString - Return a string used to label this descriptor's type.
176 virtual const char *getTypeString() const;
183 //===----------------------------------------------------------------------===//
184 /// AnchoredDesc - This class manages anchors for a variety of top level
186 class AnchoredDesc : public DebugInfoDesc {
188 AnchorDesc *Anchor; // Anchor for all descriptors of the
193 AnchoredDesc(unsigned T);
197 AnchorDesc *getAnchor() const { return Anchor; }
198 void setAnchor(AnchorDesc *A) { Anchor = A; }
200 //===--------------------------------------------------------------------===//
201 // Subclasses should supply the following virtual methods.
203 /// getAnchorString - Return a string used to label descriptor's anchor.
205 virtual const char *getAnchorString() const = 0;
207 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
209 virtual void ApplyToFields(DIVisitor *Visitor);
212 //===----------------------------------------------------------------------===//
213 /// CompileUnitDesc - This class packages debug information associated with a
214 /// source/header file.
215 class CompileUnitDesc : public AnchoredDesc {
217 unsigned DebugVersion; // LLVM debug version when produced.
218 unsigned Language; // Language number (ex. DW_LANG_C89.)
219 std::string FileName; // Source file name.
220 std::string Directory; // Source file directory.
221 std::string Producer; // Compiler string.
228 unsigned getDebugVersion() const { return DebugVersion; }
229 unsigned getLanguage() const { return Language; }
230 const std::string &getFileName() const { return FileName; }
231 const std::string &getDirectory() const { return Directory; }
232 const std::string &getProducer() const { return Producer; }
233 void setLanguage(unsigned L) { Language = L; }
234 void setFileName(const std::string &FN) { FileName = FN; }
235 void setDirectory(const std::string &D) { Directory = D; }
236 void setProducer(const std::string &P) { Producer = P; }
238 // FIXME - Need translation unit getter/setter.
240 // Implement isa/cast/dyncast.
241 static bool classof(const CompileUnitDesc *) { return true; }
242 static bool classof(const DebugInfoDesc *D);
244 /// DebugVersionFromGlobal - Returns the version number from a compile unit
245 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
246 static unsigned DebugVersionFromGlobal(GlobalVariable *GV);
248 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
250 virtual void ApplyToFields(DIVisitor *Visitor);
252 /// getDescString - Return a string used to compose global names and labels.
254 virtual const char *getDescString() const;
256 /// getTypeString - Return a string used to label this descriptor's type.
258 virtual const char *getTypeString() const;
260 /// getAnchorString - Return a string used to label this descriptor's anchor.
262 static const char *AnchorString;
263 virtual const char *getAnchorString() const;
270 //===----------------------------------------------------------------------===//
271 /// TypeDesc - This class packages debug information associated with a type.
273 class TypeDesc : public DebugInfoDesc {
275 DebugInfoDesc *Context; // Context debug descriptor.
276 std::string Name; // Type name (may be empty.)
277 CompileUnitDesc *File; // Defined compile unit (may be NULL.)
278 unsigned Line; // Defined line# (may be zero.)
279 uint64_t Size; // Type bit size (may be zero.)
280 uint64_t Align; // Type bit alignment (may be zero.)
281 uint64_t Offset; // Type bit offset (may be zero.)
284 TypeDesc(unsigned T);
287 DebugInfoDesc *getContext() const { return Context; }
288 const std::string &getName() const { return Name; }
289 CompileUnitDesc *getFile() const { return File; }
290 unsigned getLine() const { return Line; }
291 uint64_t getSize() const { return Size; }
292 uint64_t getAlign() const { return Align; }
293 uint64_t getOffset() const { return Offset; }
294 void setContext(DebugInfoDesc *C) { Context = C; }
295 void setName(const std::string &N) { Name = N; }
296 void setFile(CompileUnitDesc *U) { File = U; }
297 void setLine(unsigned L) { Line = L; }
298 void setSize(uint64_t S) { Size = S; }
299 void setAlign(uint64_t A) { Align = A; }
300 void setOffset(uint64_t O) { Offset = O; }
302 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
304 virtual void ApplyToFields(DIVisitor *Visitor);
306 /// getDescString - Return a string used to compose global names and labels.
308 virtual const char *getDescString() const;
310 /// getTypeString - Return a string used to label this descriptor's type.
312 virtual const char *getTypeString() const;
319 //===----------------------------------------------------------------------===//
320 /// BasicTypeDesc - This class packages debug information associated with a
321 /// basic type (eg. int, bool, double.)
322 class BasicTypeDesc : public TypeDesc {
324 unsigned Encoding; // Type encoding.
330 unsigned getEncoding() const { return Encoding; }
331 void setEncoding(unsigned E) { Encoding = E; }
333 // Implement isa/cast/dyncast.
334 static bool classof(const BasicTypeDesc *) { return true; }
335 static bool classof(const DebugInfoDesc *D);
337 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
339 virtual void ApplyToFields(DIVisitor *Visitor);
341 /// getDescString - Return a string used to compose global names and labels.
343 virtual const char *getDescString() const;
345 /// getTypeString - Return a string used to label this descriptor's type.
347 virtual const char *getTypeString() const;
355 //===----------------------------------------------------------------------===//
356 /// DerivedTypeDesc - This class packages debug information associated with a
357 /// derived types (eg., typedef, pointer, reference.)
358 class DerivedTypeDesc : public TypeDesc {
360 TypeDesc *FromType; // Type derived from.
363 DerivedTypeDesc(unsigned T);
366 TypeDesc *getFromType() const { return FromType; }
367 void setFromType(TypeDesc *F) { FromType = F; }
369 // Implement isa/cast/dyncast.
370 static bool classof(const DerivedTypeDesc *) { return true; }
371 static bool classof(const DebugInfoDesc *D);
373 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
375 virtual void ApplyToFields(DIVisitor *Visitor);
377 /// getDescString - Return a string used to compose global names and labels.
379 virtual const char *getDescString() const;
381 /// getTypeString - Return a string used to label this descriptor's type.
383 virtual const char *getTypeString() const;
390 //===----------------------------------------------------------------------===//
391 /// CompositeTypeDesc - This class packages debug information associated with a
392 /// array/struct types (eg., arrays, struct, union, enums.)
393 class CompositeTypeDesc : public DerivedTypeDesc {
395 std::vector<DebugInfoDesc *> Elements;// Information used to compose type.
398 CompositeTypeDesc(unsigned T);
401 std::vector<DebugInfoDesc *> &getElements() { return Elements; }
403 // Implement isa/cast/dyncast.
404 static bool classof(const CompositeTypeDesc *) { return true; }
405 static bool classof(const DebugInfoDesc *D);
407 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
409 virtual void ApplyToFields(DIVisitor *Visitor);
411 /// getDescString - Return a string used to compose global names and labels.
413 virtual const char *getDescString() const;
415 /// getTypeString - Return a string used to label this descriptor's type.
417 virtual const char *getTypeString() const;
424 //===----------------------------------------------------------------------===//
425 /// SubrangeDesc - This class packages debug information associated with integer
427 class SubrangeDesc : public DebugInfoDesc {
429 int64_t Lo; // Low value of range.
430 int64_t Hi; // High value of range.
436 int64_t getLo() const { return Lo; }
437 int64_t getHi() const { return Hi; }
438 void setLo(int64_t L) { Lo = L; }
439 void setHi(int64_t H) { Hi = H; }
441 // Implement isa/cast/dyncast.
442 static bool classof(const SubrangeDesc *) { return true; }
443 static bool classof(const DebugInfoDesc *D);
445 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
447 virtual void ApplyToFields(DIVisitor *Visitor);
449 /// getDescString - Return a string used to compose global names and labels.
451 virtual const char *getDescString() const;
453 /// getTypeString - Return a string used to label this descriptor's type.
455 virtual const char *getTypeString() const;
462 //===----------------------------------------------------------------------===//
463 /// EnumeratorDesc - This class packages debug information associated with
464 /// named integer constants.
465 class EnumeratorDesc : public DebugInfoDesc {
467 std::string Name; // Enumerator name.
468 int64_t Value; // Enumerator value.
474 const std::string &getName() const { return Name; }
475 int64_t getValue() const { return Value; }
476 void setName(const std::string &N) { Name = N; }
477 void setValue(int64_t V) { Value = V; }
479 // Implement isa/cast/dyncast.
480 static bool classof(const EnumeratorDesc *) { return true; }
481 static bool classof(const DebugInfoDesc *D);
483 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
485 virtual void ApplyToFields(DIVisitor *Visitor);
487 /// getDescString - Return a string used to compose global names and labels.
489 virtual const char *getDescString() const;
491 /// getTypeString - Return a string used to label this descriptor's type.
493 virtual const char *getTypeString() const;
500 //===----------------------------------------------------------------------===//
501 /// VariableDesc - This class packages debug information associated with a
502 /// subprogram variable.
504 class VariableDesc : public DebugInfoDesc {
506 DebugInfoDesc *Context; // Context debug descriptor.
507 std::string Name; // Type name (may be empty.)
508 CompileUnitDesc *File; // Defined compile unit (may be NULL.)
509 unsigned Line; // Defined line# (may be zero.)
510 TypeDesc *TyDesc; // Type of variable.
513 VariableDesc(unsigned T);
516 DebugInfoDesc *getContext() const { return Context; }
517 const std::string &getName() const { return Name; }
518 CompileUnitDesc *getFile() const { return File; }
519 unsigned getLine() const { return Line; }
520 TypeDesc *getType() const { return TyDesc; }
521 void setContext(DebugInfoDesc *C) { Context = C; }
522 void setName(const std::string &N) { Name = N; }
523 void setFile(CompileUnitDesc *U) { File = U; }
524 void setLine(unsigned L) { Line = L; }
525 void setType(TypeDesc *T) { TyDesc = T; }
527 // Implement isa/cast/dyncast.
528 static bool classof(const VariableDesc *) { return true; }
529 static bool classof(const DebugInfoDesc *D);
531 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
533 virtual void ApplyToFields(DIVisitor *Visitor);
535 /// getDescString - Return a string used to compose global names and labels.
537 virtual const char *getDescString() const;
539 /// getTypeString - Return a string used to label this descriptor's type.
541 virtual const char *getTypeString() const;
548 //===----------------------------------------------------------------------===//
549 /// GlobalDesc - This class is the base descriptor for global functions and
551 class GlobalDesc : public AnchoredDesc {
553 DebugInfoDesc *Context; // Context debug descriptor.
554 std::string Name; // Global name.
555 CompileUnitDesc *File; // Defined compile unit (may be NULL.)
556 unsigned Line; // Defined line# (may be zero.)
557 TypeDesc *TyDesc; // Type debug descriptor.
558 bool IsStatic; // Is the global a static.
559 bool IsDefinition; // Is the global defined in context.
562 GlobalDesc(unsigned T);
566 DebugInfoDesc *getContext() const { return Context; }
567 const std::string &getName() const { return Name; }
568 CompileUnitDesc *getFile() const { return File; }
569 unsigned getLine() const { return Line; }
570 TypeDesc *getType() const { return TyDesc; }
571 bool isStatic() const { return IsStatic; }
572 bool isDefinition() const { return IsDefinition; }
573 void setContext(DebugInfoDesc *C) { Context = C; }
574 void setName(const std::string &N) { Name = N; }
575 void setFile(CompileUnitDesc *U) { File = U; }
576 void setLine(unsigned L) { Line = L; }
577 void setTypeDesc(TypeDesc *T) { TyDesc = T; }
578 void setIsStatic(bool IS) { IsStatic = IS; }
579 void setIsDefinition(bool ID) { IsDefinition = ID; }
581 /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
583 virtual void ApplyToFields(DIVisitor *Visitor);
586 //===----------------------------------------------------------------------===//
587 /// GlobalVariableDesc - This class packages debug information associated with a
589 class GlobalVariableDesc : public GlobalDesc {
591 GlobalVariable *Global; // llvm global.
594 GlobalVariableDesc();
597 GlobalVariable *getGlobalVariable() const { return Global; }
598 void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
600 // Implement isa/cast/dyncast.
601 static bool classof(const GlobalVariableDesc *) { return true; }
602 static bool classof(const DebugInfoDesc *D);
604 /// ApplyToFields - Target the visitor to the fields of the
605 /// GlobalVariableDesc.
606 virtual void ApplyToFields(DIVisitor *Visitor);
608 /// getDescString - Return a string used to compose global names and labels.
610 virtual const char *getDescString() const;
612 /// getTypeString - Return a string used to label this descriptor's type.
614 virtual const char *getTypeString() const;
616 /// getAnchorString - Return a string used to label this descriptor's anchor.
618 static const char *AnchorString;
619 virtual const char *getAnchorString() const;
626 //===----------------------------------------------------------------------===//
627 /// SubprogramDesc - This class packages debug information associated with a
628 /// subprogram/function.
629 class SubprogramDesc : public GlobalDesc {
637 // Implement isa/cast/dyncast.
638 static bool classof(const SubprogramDesc *) { return true; }
639 static bool classof(const DebugInfoDesc *D);
641 /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
643 virtual void ApplyToFields(DIVisitor *Visitor);
645 /// getDescString - Return a string used to compose global names and labels.
647 virtual const char *getDescString() const;
649 /// getTypeString - Return a string used to label this descriptor's type.
651 virtual const char *getTypeString() const;
653 /// getAnchorString - Return a string used to label this descriptor's anchor.
655 static const char *AnchorString;
656 virtual const char *getAnchorString() const;
663 //===----------------------------------------------------------------------===//
664 /// BlockDesc - This descriptor groups variables and blocks nested in a block.
666 class BlockDesc : public DebugInfoDesc {
668 DebugInfoDesc *Context; // Context debug descriptor.
674 DebugInfoDesc *getContext() const { return Context; }
675 void setContext(DebugInfoDesc *C) { Context = C; }
677 // Implement isa/cast/dyncast.
678 static bool classof(const BlockDesc *) { return true; }
679 static bool classof(const DebugInfoDesc *D);
681 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
683 virtual void ApplyToFields(DIVisitor *Visitor);
685 /// getDescString - Return a string used to compose global names and labels.
687 virtual const char *getDescString() const;
689 /// getTypeString - Return a string used to label this descriptor's type.
691 virtual const char *getTypeString() const;
698 //===----------------------------------------------------------------------===//
699 /// DIDeserializer - This class is responsible for casting GlobalVariables
700 /// into DebugInfoDesc objects.
701 class DIDeserializer {
703 unsigned DebugVersion; // Version of debug information in use.
704 std::map<GlobalVariable *, DebugInfoDesc *> GlobalDescs;
705 // Previously defined gloabls.
708 DIDeserializer() : DebugVersion(LLVMDebugVersion) {}
712 unsigned getDebugVersion() const { return DebugVersion; }
714 /// Deserialize - Reconstitute a GlobalVariable into it's component
715 /// DebugInfoDesc objects.
716 DebugInfoDesc *Deserialize(Value *V);
717 DebugInfoDesc *Deserialize(GlobalVariable *GV);
720 //===----------------------------------------------------------------------===//
721 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
722 /// into GlobalVariables.
725 Module *M; // Definition space module.
726 PointerType *StrPtrTy; // A "sbyte *" type. Created lazily.
727 PointerType *EmptyStructPtrTy; // A "{ }*" type. Created lazily.
728 std::map<unsigned, StructType *> TagTypes;
729 // Types per Tag. Created lazily.
730 std::map<DebugInfoDesc *, GlobalVariable *> DescGlobals;
731 // Previously defined descriptors.
732 std::map<const std::string, Constant *> StringCache;
733 // Previously defined strings.
739 , EmptyStructPtrTy(NULL)
747 Module *getModule() const { return M; };
748 void setModule(Module *module) { M = module; }
750 /// getStrPtrType - Return a "sbyte *" type.
752 const PointerType *getStrPtrType();
754 /// getEmptyStructPtrType - Return a "{ }*" type.
756 const PointerType *getEmptyStructPtrType();
758 /// getTagType - Return the type describing the specified descriptor (via
760 const StructType *getTagType(DebugInfoDesc *DD);
762 /// getString - Construct the string as constant string global.
764 Constant *getString(const std::string &String);
766 /// Serialize - Recursively cast the specified descriptor into a
767 /// GlobalVariable so that it can be serialized to a .bc or .ll file.
768 GlobalVariable *Serialize(DebugInfoDesc *DD);
771 //===----------------------------------------------------------------------===//
772 /// DIVerifier - This class is responsible for verifying the given network of
773 /// GlobalVariables are valid as DebugInfoDesc objects.
776 unsigned DebugVersion; // Version of debug information in use.
777 std::set<GlobalVariable *> Visited; // Tracks visits during recursion.
778 std::map<unsigned, unsigned> Counts; // Count of fields per Tag type.
780 /// markVisited - Return true if the GlobalVariable hase been "seen" before.
781 /// Mark markVisited otherwise.
782 bool markVisited(GlobalVariable *GV);
785 DIVerifier() : DebugVersion(LLVMDebugVersion) {}
788 /// Verify - Return true if the GlobalVariable appears to be a valid
789 /// serialization of a DebugInfoDesc.
790 bool Verify(Value *V);
791 bool Verify(GlobalVariable *GV);
794 //===----------------------------------------------------------------------===//
795 /// SourceLineInfo - This class is used to record source line correspondence.
797 class SourceLineInfo {
799 unsigned Line; // Source line number.
800 unsigned Column; // Source column.
801 unsigned SourceID; // Source ID number.
802 unsigned LabelID; // Label in code ID number.
805 SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
806 : Line(L), Column(C), SourceID(S), LabelID(I) {}
809 unsigned getLine() const { return Line; }
810 unsigned getColumn() const { return Column; }
811 unsigned getSourceID() const { return SourceID; }
812 unsigned getLabelID() const { return LabelID; }
815 //===----------------------------------------------------------------------===//
816 /// SourceFileInfo - This class is used to track source information.
818 class SourceFileInfo {
820 unsigned DirectoryID; // Directory ID number.
821 std::string Name; // File name (not including directory.)
824 SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
827 unsigned getDirectoryID() const { return DirectoryID; }
828 const std::string &getName() const { return Name; }
830 /// operator== - Used by UniqueVector to locate entry.
832 bool operator==(const SourceFileInfo &SI) const {
833 return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
836 /// operator< - Used by UniqueVector to locate entry.
838 bool operator<(const SourceFileInfo &SI) const {
839 return getDirectoryID() < SI.getDirectoryID() ||
840 (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
844 //===----------------------------------------------------------------------===//
845 /// DebugVariable - This class is used to track local variable information.
847 class DebugVariable {
849 VariableDesc *Desc; // Variable Descriptor.
850 unsigned FrameIndex; // Variable frame index.
853 DebugVariable(VariableDesc *D, unsigned I)
859 VariableDesc *getDesc() const { return Desc; }
860 unsigned getFrameIndex() const { return FrameIndex; }
863 //===----------------------------------------------------------------------===//
864 /// DebugScope - This class is used to track scope information.
868 DebugScope *Parent; // Parent to this scope.
869 DebugInfoDesc *Desc; // Debug info descriptor for scope.
870 // Either subprogram or block.
871 unsigned StartLabelID; // Label ID of the beginning of scope.
872 unsigned EndLabelID; // Label ID of the end of scope.
873 std::vector<DebugScope *> Scopes; // Scopes defined in scope.
874 std::vector<DebugVariable *> Variables;// Variables declared in scope.
877 DebugScope(DebugScope *P, DebugInfoDesc *D)
888 DebugScope *getParent() const { return Parent; }
889 DebugInfoDesc *getDesc() const { return Desc; }
890 unsigned getStartLabelID() const { return StartLabelID; }
891 unsigned getEndLabelID() const { return EndLabelID; }
892 std::vector<DebugScope *> &getScopes() { return Scopes; }
893 std::vector<DebugVariable *> &getVariables() { return Variables; }
894 void setStartLabelID(unsigned S) { StartLabelID = S; }
895 void setEndLabelID(unsigned E) { EndLabelID = E; }
897 /// AddScope - Add a scope to the scope.
899 void AddScope(DebugScope *S) { Scopes.push_back(S); }
901 /// AddVariable - Add a variable to the scope.
903 void AddVariable(DebugVariable *V) { Variables.push_back(V); }
906 //===----------------------------------------------------------------------===//
907 /// MachineDebugInfo - This class contains debug information specific to a
908 /// module. Queries can be made by different debugging schemes and reformated
909 /// for specific use.
911 class MachineDebugInfo : public ImmutablePass {
913 // Use the same deserializer/verifier for the module.
917 // CompileUnits - Uniquing vector for compile units.
918 UniqueVector<CompileUnitDesc *> CompileUnits;
920 // Directories - Uniquing vector for directories.
921 UniqueVector<std::string> Directories;
923 // SourceFiles - Uniquing vector for source files.
924 UniqueVector<SourceFileInfo> SourceFiles;
926 // Lines - List of of source line correspondence.
927 std::vector<SourceLineInfo *> Lines;
929 // LabelID - Current number assigned to unique label numbers.
932 // ScopeMap - Tracks the scopes in the current function.
933 std::map<DebugInfoDesc *, DebugScope *> ScopeMap;
935 // RootScope - Top level scope for the current function.
937 DebugScope *RootScope;
943 /// doInitialization - Initialize the debug state for a new module.
945 bool doInitialization();
947 /// doFinalization - Tear down the debug state after completion of a module.
949 bool doFinalization();
951 /// getDescFor - Convert a Value to a debug information descriptor.
953 // FIXME - use new Value type when available.
954 DebugInfoDesc *getDescFor(Value *V);
956 /// Verify - Verify that a Value is debug information descriptor.
958 bool Verify(Value *V);
960 /// AnalyzeModule - Scan the module for global debug information.
962 void AnalyzeModule(Module &M);
964 /// hasInfo - Returns true if valid debug info is present.
966 bool hasInfo() const { return !CompileUnits.empty(); }
968 /// NextLabelID - Return the next unique label id.
970 unsigned NextLabelID() { return ++LabelID; }
972 /// RecordLabel - Records location information and associates it with a
973 /// debug label. Returns a unique label ID used to generate a label and
974 /// provide correspondence to the source line list.
975 unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source);
977 /// RecordSource - Register a source file with debug info. Returns an source
979 unsigned RecordSource(const std::string &Directory,
980 const std::string &Source);
981 unsigned RecordSource(const CompileUnitDesc *CompileUnit);
983 /// getDirectories - Return the UniqueVector of std::string representing
985 const UniqueVector<std::string> &getDirectories() const {
989 /// getSourceFiles - Return the UniqueVector of source files.
991 const UniqueVector<SourceFileInfo> &getSourceFiles() const {
995 /// getSourceLines - Return a vector of source lines. Vector index + 1
997 const std::vector<SourceLineInfo *> &getSourceLines() const {
1001 /// SetupCompileUnits - Set up the unique vector of compile units.
1003 void SetupCompileUnits(Module &M);
1005 /// getCompileUnits - Return a vector of debug compile units.
1007 const UniqueVector<CompileUnitDesc *> getCompileUnits() const;
1009 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1010 /// named GlobalVariable.
1011 std::vector<GlobalVariable*>
1012 getGlobalVariablesUsing(Module &M, const std::string &RootName);
1014 /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
1016 template <class T>std::vector<T *> getAnchoredDescriptors(Module &M) {
1018 std::vector<GlobalVariable *> Globals =
1019 getGlobalVariablesUsing(M, Desc.getAnchorString());
1020 std::vector<T *> AnchoredDescs;
1021 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
1022 GlobalVariable *GV = Globals[i];
1023 unsigned Tag = DebugInfoDesc::TagFromGlobal(GV);
1025 if (isa<CompileUnitDesc>(&Desc)) {
1026 unsigned DebugVersion = CompileUnitDesc::DebugVersionFromGlobal(GV);
1027 // FIXME - In the short term, changes are too drastic to continue.
1028 if (DebugVersion != LLVMDebugVersion) break;
1031 if (Tag == Desc.getTag()) {
1032 AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
1036 return AnchoredDescs;
1039 /// RecordRegionStart - Indicate the start of a region.
1041 unsigned RecordRegionStart(Value *V);
1043 /// RecordRegionEnd - Indicate the end of a region.
1045 unsigned RecordRegionEnd(Value *V);
1047 /// RecordVariable - Indicate the declaration of a local variable.
1049 void RecordVariable(Value *V, unsigned FrameIndex);
1051 /// getRootScope - Return current functions root scope.
1053 DebugScope *getRootScope() { return RootScope; }
1055 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1057 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1059 /// ClearScopes - Delete the scope and variable info after a function is
1063 }; // End class MachineDebugInfo
1065 } // End llvm namespace