[llvm-commits] CVS: llvm/include/llvm/CodeGen/DwarfWriter.h MachineDebugInfo.h

Jim Laskey jlaskey at apple.com
Thu Mar 23 10:08:08 PST 2006



Changes in directory llvm/include/llvm/CodeGen:

DwarfWriter.h updated: 1.29 -> 1.30
MachineDebugInfo.h updated: 1.30 -> 1.31
---
Log message:

Generate local variable and scope information and equivalent dwarf forms.


---
Diffs of the changes:  (+215 -34)

 DwarfWriter.h      |   49 +++++++++++-
 MachineDebugInfo.h |  200 +++++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 215 insertions(+), 34 deletions(-)


Index: llvm/include/llvm/CodeGen/DwarfWriter.h
diff -u llvm/include/llvm/CodeGen/DwarfWriter.h:1.29 llvm/include/llvm/CodeGen/DwarfWriter.h:1.30
--- llvm/include/llvm/CodeGen/DwarfWriter.h:1.29	Wed Mar  1 18:21:41 2006
+++ llvm/include/llvm/CodeGen/DwarfWriter.h	Thu Mar 23 12:07:55 2006
@@ -35,6 +35,8 @@
 class CompileUnit;
 class CompileUnitDesc;
 class DebugInfoDesc;
+class DebugVariable;
+class DebugScope;
 class DIE;
 class DIEAbbrev;
 class GlobalVariableDesc;
@@ -78,6 +80,14 @@
   ///
   AsmPrinter *Asm;
   
+  /// M - Current module.
+  ///
+  Module *M;
+  
+  /// MF - Current machine function.
+  ///
+  MachineFunction *MF;
+  
   /// DebugInfo - Collected debug information.
   ///
   MachineDebugInfo *DebugInfo;
@@ -86,6 +96,10 @@
   ///
   bool didInitial;
   
+  /// SubprogramCount - The running count of functions being compiled.
+  ///
+  unsigned SubprogramCount;
+  
   //===--------------------------------------------------------------------===//
   // Attributes used to construct specific Dwarf sections.
   //
@@ -209,6 +223,10 @@
   /// EOL - Print a newline character to asm stream.  If a comment is present
   /// then it will be printed first.  Comments should not contain '\n'.
   void EOL(const std::string &Comment) const;
+  
+  /// EmitAlign - Print a align directive.
+  ///
+  void EmitAlign(unsigned Alignment) const;
                                         
   /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
   /// unsigned leb128 value.
@@ -300,6 +318,10 @@
 
 private:
 
+  /// AddSourceLine - Add location information to specified debug information
+  /// entry. 
+  void AddSourceLine(DIE *Die, CompileUnitDesc *File, unsigned Line);
+
   /// NewType - Create a new type DIE.
   ///
  DIE *NewType(DIE *Context, TypeDesc *TyDesc);
@@ -320,6 +342,19 @@
   ///
   DIE *NewSubprogram(SubprogramDesc *SPD);
 
+  /// NewScopeVariable - Create a new scope variable.
+  ///
+  DIE *NewScopeVariable(DebugVariable *DV, CompileUnit *Unit);
+
+  /// ConstructScope - Construct the components of a scope.
+  ///
+  void ConstructScope(DebugScope *ParentScope, DIE *ParentDie,
+                      CompileUnit *Unit);
+
+  /// ConstructRootScope - Construct the scope for the subprogram.
+  ///
+  void ConstructRootScope(DebugScope *RootScope);
+
   /// EmitInitial - Emit initial Dwarf declarations.
   ///
   void EmitInitial() const;
@@ -330,7 +365,7 @@
   
   /// SizeAndOffsetDie - Compute the size and offset of a DIE.
   ///
-  unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset);
+  unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset, bool Last);
 
   /// SizeAndOffsets - Compute the size and offset of all the DIEs.
   ///
@@ -382,11 +417,11 @@
   
   /// ConstructGlobalDIEs - Create DIEs for each of the externally visible
   /// global variables.
-  void ConstructGlobalDIEs(Module &M);
+  void ConstructGlobalDIEs();
 
   /// ConstructSubprogramDIEs - Create DIEs for each of the externally visible
   /// subprograms.
-  void ConstructSubprogramDIEs(Module &M);
+  void ConstructSubprogramDIEs();
 
   /// ShouldEmitDwarf - Returns true if Dwarf declarations should be made.
   /// When called it also checks to see if debug info is newly available.  if
@@ -408,19 +443,19 @@
   
   /// BeginModule - Emit all Dwarf sections that should come prior to the
   /// content.
-  void BeginModule(Module &M);
+  void BeginModule(Module *M);
   
   /// EndModule - Emit all Dwarf sections that should come after the content.
   ///
-  void EndModule(Module &M);
+  void EndModule();
   
   /// BeginFunction - Gather pre-function debug information.
   ///
-  void BeginFunction(MachineFunction &MF);
+  void BeginFunction(MachineFunction *MF);
   
   /// EndFunction - Gather and emit post-function debug information.
   ///
-  void EndFunction(MachineFunction &MF);
+  void EndFunction();
 };
 
 } // end llvm namespace


Index: llvm/include/llvm/CodeGen/MachineDebugInfo.h
diff -u llvm/include/llvm/CodeGen/MachineDebugInfo.h:1.30 llvm/include/llvm/CodeGen/MachineDebugInfo.h:1.31
--- llvm/include/llvm/CodeGen/MachineDebugInfo.h:1.30	Wed Mar 15 13:09:58 2006
+++ llvm/include/llvm/CodeGen/MachineDebugInfo.h	Thu Mar 23 12:07:55 2006
@@ -55,7 +55,7 @@
 // Debug info constants.
 
 enum {
-  LLVMDebugVersion = 2                  // Current version of debug information.
+  LLVMDebugVersion = 3                  // Current version of debug information.
 };
 
 //===----------------------------------------------------------------------===//
@@ -299,7 +299,7 @@
   void setAlign(uint64_t A)                        { Align = A; }
   void setOffset(uint64_t O)                       { Offset = O; }
   
-  /// ApplyToFields - Target the visitor to the fields of the  TypeDesc.
+  /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
   ///
   virtual void ApplyToFields(DIVisitor *Visitor);
 
@@ -334,7 +334,7 @@
   static bool classof(const BasicTypeDesc *) { return true; }
   static bool classof(const DebugInfoDesc *D);
   
-  /// ApplyToFields - Target the visitor to the fields of the  BasicTypeDesc.
+  /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
   ///
   virtual void ApplyToFields(DIVisitor *Visitor);
 
@@ -370,7 +370,7 @@
   static bool classof(const DerivedTypeDesc *) { return true; }
   static bool classof(const DebugInfoDesc *D);
   
-  /// ApplyToFields - Target the visitor to the fields of the  DerivedTypeDesc.
+  /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
   ///
   virtual void ApplyToFields(DIVisitor *Visitor);
 
@@ -498,6 +498,54 @@
 };
 
 //===----------------------------------------------------------------------===//
+/// VariableDesc - This class packages debug information associated with a
+/// subprogram variable.
+///
+class VariableDesc : public DebugInfoDesc {
+private:
+  DebugInfoDesc *Context;               // Context debug descriptor.
+  std::string Name;                     // Type name (may be empty.)
+  CompileUnitDesc *File;                // Defined compile unit (may be NULL.)
+  unsigned Line;                        // Defined line# (may be zero.)
+  TypeDesc *TyDesc;                     // Type of variable.
+
+public:
+  VariableDesc(unsigned T);
+
+  // Accessors
+  DebugInfoDesc *getContext()                const { return Context; }
+  const std::string &getName()               const { return Name; }
+  CompileUnitDesc *getFile()                 const { return File; }
+  unsigned getLine()                         const { return Line; }
+  TypeDesc *getType()                        const { return TyDesc; }
+  void setContext(DebugInfoDesc *C)                { Context = C; }
+  void setName(const std::string &N)               { Name = N; }
+  void setFile(CompileUnitDesc *U)                 { File = U; }
+  void setLine(unsigned L)                         { Line = L; }
+  void setType(TypeDesc *T)                        { TyDesc = T; }
+  
+  // Implement isa/cast/dyncast.
+  static bool classof(const VariableDesc *) { return true; }
+  static bool classof(const DebugInfoDesc *D);
+  
+  /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
+  ///
+  virtual void ApplyToFields(DIVisitor *Visitor);
+
+  /// getDescString - Return a string used to compose global names and labels.
+  ///
+  virtual const char *getDescString() const;
+
+  /// getTypeString - Return a string used to label this descriptor's type.
+  ///
+  virtual const char *getTypeString() const;
+  
+#ifndef NDEBUG
+  virtual void dump();
+#endif
+};
+
+//===----------------------------------------------------------------------===//
 /// GlobalDesc - This class is the base descriptor for global functions and
 /// variables.
 class GlobalDesc : public AnchoredDesc {
@@ -519,7 +567,7 @@
   const std::string &getName()               const { return Name; }
   CompileUnitDesc *getFile()                 const { return File; }
   unsigned getLine()                         const { return Line; }
-  TypeDesc *getTypeDesc()                    const { return TyDesc; }
+  TypeDesc *getType()                        const { return TyDesc; }
   bool isStatic()                            const { return IsStatic; }
   bool isDefinition()                        const { return IsDefinition; }
   void setContext(DebugInfoDesc *C)                { Context = C; }
@@ -580,14 +628,11 @@
 /// subprogram/function.
 class SubprogramDesc : public GlobalDesc {
 private:
-  std::vector<DebugInfoDesc *> Elements;// Information about args, variables
-                                        // and blocks.
   
 public:
   SubprogramDesc();
   
   // Accessors
-  std::vector<DebugInfoDesc *> &getElements() { return Elements; }
   
   // Implement isa/cast/dyncast.
   static bool classof(const SubprogramDesc *) { return true; }
@@ -620,13 +665,14 @@
 ///
 class BlockDesc : public DebugInfoDesc {
 private:
-  std::vector<DebugInfoDesc *> Elements;// Information about nested variables
-                                        // and blocks.
+  DebugInfoDesc *Context;               // Context debug descriptor.
+
 public:
   BlockDesc();
   
   // Accessors
-  std::vector<DebugInfoDesc *> &getElements() { return Elements; }
+  DebugInfoDesc *getContext()                const { return Context; }
+  void setContext(DebugInfoDesc *C)                { Context = C; }
   
   // Implement isa/cast/dyncast.
   static bool classof(const BlockDesc *) { return true; }
@@ -753,15 +799,17 @@
   unsigned Line;                        // Source line number.
   unsigned Column;                      // Source column.
   unsigned SourceID;                    // Source ID number.
+  unsigned LabelID;                     // Label in code ID number.
 
 public:
-  SourceLineInfo(unsigned L, unsigned C, unsigned S)
-  : Line(L), Column(C), SourceID(S) {}
+  SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
+  : Line(L), Column(C), SourceID(S), LabelID(I) {}
   
   // Accessors
   unsigned getLine()     const { return Line; }
   unsigned getColumn()   const { return Column; }
   unsigned getSourceID() const { return SourceID; }
+  unsigned getLabelID()  const { return LabelID; }
 };
 
 //===----------------------------------------------------------------------===//
@@ -794,14 +842,77 @@
 };
 
 //===----------------------------------------------------------------------===//
+/// DebugVariable - This class is used to track local variable information.
+///
+class DebugVariable {
+private:
+  VariableDesc *Desc;                   // Variable Descriptor.
+  unsigned FrameIndex;                  // Variable frame index.
+
+public:
+  DebugVariable(VariableDesc *D, unsigned I)
+  : Desc(D)
+  , FrameIndex(I)
+  {}
+  
+  // Accessors.
+  VariableDesc *getDesc()  const { return Desc; }
+  unsigned getFrameIndex() const { return FrameIndex; }
+};
+
+//===----------------------------------------------------------------------===//
+/// DebugScope - This class is used to track scope information.
+///
+class DebugScope {
+private:
+  DebugScope *Parent;                   // Parent to this scope.
+  DebugInfoDesc *Desc;                  // Debug info descriptor for scope.
+                                        // Either subprogram or block.
+  unsigned StartLabelID;                // Label ID of the beginning of scope.
+  unsigned EndLabelID;                  // Label ID of the end of scope.
+  std::vector<DebugScope *> Scopes;     // Scopes defined in scope.
+  std::vector<DebugVariable *> Variables;// Variables declared in scope.
+  
+public:
+  DebugScope(DebugScope *P, DebugInfoDesc *D)
+  : Parent(P)
+  , Desc(D)
+  , StartLabelID(0)
+  , EndLabelID(0)
+  , Scopes()
+  , Variables()
+  {}
+  ~DebugScope();
+  
+  // Accessors.
+  DebugScope *getParent()        const { return Parent; }
+  DebugInfoDesc *getDesc()       const { return Desc; }
+  unsigned getStartLabelID()     const { return StartLabelID; }
+  unsigned getEndLabelID()       const { return EndLabelID; }
+  std::vector<DebugScope *> &getScopes() { return Scopes; }
+  std::vector<DebugVariable *> &getVariables() { return Variables; }
+  void setStartLabelID(unsigned S) { StartLabelID = S; }
+  void setEndLabelID(unsigned E)   { EndLabelID = E; }
+  
+  /// AddScope - Add a scope to the scope.
+  ///
+  void AddScope(DebugScope *S) { Scopes.push_back(S); }
+  
+  /// AddVariable - Add a variable to the scope.
+  ///
+  void AddVariable(DebugVariable *V) { Variables.push_back(V); }
+};
+
+//===----------------------------------------------------------------------===//
 /// MachineDebugInfo - This class contains debug information specific to a
 /// module.  Queries can be made by different debugging schemes and reformated
 /// for specific use.
 ///
 class MachineDebugInfo : public ImmutablePass {
 private:
-  // Use the same serializer/deserializer/verifier for the module.
+  // Use the same deserializer/verifier for the module.
   DIDeserializer DR;
+  DIVerifier VR;
 
   // CompileUnits - Uniquing vector for compile units.
   UniqueVector<CompileUnitDesc *> CompileUnits;
@@ -814,6 +925,16 @@
 
   // Lines - List of of source line correspondence.
   std::vector<SourceLineInfo *> Lines;
+  
+  // LabelID - Current number assigned to unique label numbers.
+  unsigned LabelID;
+  
+  // ScopeMap - Tracks the scopes in the current function.
+  std::map<DebugInfoDesc *, DebugScope *> ScopeMap;
+  
+  // RootScope - Top level scope for the current function.
+  //
+  DebugScope *RootScope;
 
 public:
   MachineDebugInfo();
@@ -844,25 +965,20 @@
   ///
   bool hasInfo() const { return !CompileUnits.empty(); }
   
+  /// NextLabelID - Return the next unique label id.
+  ///
+  unsigned NextLabelID() { return ++LabelID; }
+  
   /// RecordLabel - Records location information and associates it with a
   /// debug label.  Returns a unique label ID used to generate a label and 
   /// provide correspondence to the source line list.
-  unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source) {
-    Lines.push_back(new SourceLineInfo(Line, Column, Source));
-    return Lines.size();
-  }
+  unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source);
   
   /// RecordSource - Register a source file with debug info. Returns an source
   /// ID.
   unsigned RecordSource(const std::string &Directory,
-                        const std::string &Source) {
-    unsigned DirectoryID = Directories.insert(Directory);
-    return SourceFiles.insert(SourceFileInfo(DirectoryID, Source));
-  }
-  unsigned RecordSource(const CompileUnitDesc *CompileUnit) {
-    return RecordSource(CompileUnit->getDirectory(),
-                        CompileUnit->getFileName());
-  }
+                        const std::string &Source);
+  unsigned RecordSource(const CompileUnitDesc *CompileUnit);
   
   /// getDirectories - Return the UniqueVector of std::string representing
   /// directories.
@@ -904,8 +1020,14 @@
     std::vector<T *> AnchoredDescs;
     for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
       GlobalVariable *GV = Globals[i];
-      // FIXME - Tag check only necessary for bring up (changed tag values.)
       unsigned Tag = DebugInfoDesc::TagFromGlobal(GV);
+      
+      if (isa<CompileUnitDesc>(&Desc)) {
+        unsigned DebugVersion = CompileUnitDesc::DebugVersionFromGlobal(GV);
+        // FIXME - In the short term, changes are too drastic to continue.
+        if (DebugVersion != LLVMDebugVersion) break;
+      }
+      
       if (Tag == Desc.getTag()) {
         AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
       }
@@ -913,6 +1035,30 @@
 
     return AnchoredDescs;
   }
+  
+  /// RecordRegionStart - Indicate the start of a region.
+  ///
+  unsigned RecordRegionStart(Value *V);
+
+  /// RecordRegionEnd - Indicate the end of a region.
+  ///
+  unsigned RecordRegionEnd(Value *V);
+
+  /// RecordVariable - Indicate the declaration of  a local variable.
+  ///
+  void RecordVariable(Value *V, unsigned FrameIndex);
+  
+  /// getRootScope - Return current functions root scope.
+  ///
+  DebugScope *getRootScope() { return RootScope; }
+  
+  /// getOrCreateScope - Returns the scope associated with the given descriptor.
+  ///
+  DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
+
+  /// ClearScopes - Delete the scope and variable info after a function is
+  /// completed.
+  void ClearScopes();
 
 }; // End class MachineDebugInfo
 






More information about the llvm-commits mailing list