[llvm-commits] [llvm] r63353 - in /llvm/trunk: include/llvm/Analysis/DebugInfo.h lib/Analysis/DebugInfo.cpp

Devang Patel dpatel at apple.com
Thu Jan 29 17:03:11 PST 2009


Author: dpatel
Date: Thu Jan 29 19:03:10 2009
New Revision: 63353

URL: http://llvm.org/viewvc/llvm-project?rev=63353&view=rev
Log:
Add dump() routines to help debug debug info :)

Modified:
    llvm/trunk/include/llvm/Analysis/DebugInfo.h
    llvm/trunk/lib/Analysis/DebugInfo.cpp

Modified: llvm/trunk/include/llvm/Analysis/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/DebugInfo.h?rev=63353&r1=63352&r2=63353&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/DebugInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/DebugInfo.h Thu Jan 29 19:03:10 2009
@@ -114,6 +114,9 @@
 
     /// Verify - Verify that a compile unit is well formed.
     bool Verify() const;
+
+    /// dump - print compile unit.
+    void dump() const;
   };
 
   /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
@@ -189,6 +192,9 @@
       assert (0 && "Invalid DIDescriptor");
       return "";
     }
+
+    /// dump - print type.
+    void dump() const;
   };
 
   /// DIBasicType - A basic type, like 'int' or 'float'.
@@ -199,6 +205,9 @@
     unsigned getEncoding() const { return getUnsignedField(9); }
     std::string getFilename() const { return getStringField(10); }
     std::string getDirectory() const { return getStringField(11); }
+
+    /// dump - print basic type.
+    void dump() const;
   };
 
   /// DIDerivedType - A simple derived type, like a const qualified type,
@@ -213,6 +222,9 @@
     DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
     std::string getFilename() const { return getStringField(10); }
     std::string getDirectory() const { return getStringField(11); }
+
+    /// dump - print derived type.
+    void dump() const;
   };
 
   /// DICompositeType - This descriptor holds a type that can refer to multiple
@@ -228,6 +240,9 @@
 
     /// Verify - Verify that a composite type descriptor is well formed.
     bool Verify() const;
+
+    /// dump - print composite type.
+    void dump() const;
   };
 
   /// DIGlobal - This is a common class for global variables and subprograms.
@@ -273,6 +288,9 @@
       assert (0 && "Invalid DIDescriptor");
       return "";
     }
+    
+    /// dump - print global.
+    void dump() const;
   };
 
   /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
@@ -285,6 +303,9 @@
 
     /// Verify - Verify that a subprogram descriptor is well formed.
     bool Verify() const;
+
+    /// dump - print subprogram.
+    void dump() const;
   };
 
   /// DIGlobalVariable - This is a wrapper for a global variable.
@@ -298,6 +319,9 @@
 
     /// Verify - Verify that a global variable descriptor is well formed.
     bool Verify() const;
+
+    /// dump - print global variable.
+    void dump() const;
   };
 
   /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
@@ -319,6 +343,9 @@
 
     /// Verify - Verify that a variable descriptor is well formed.
     bool Verify() const;
+
+    /// dump - print variable.
+    void dump() const;
   };
 
   /// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc).

Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=63353&r1=63352&r2=63353&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/DebugInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/DebugInfo.cpp Thu Jan 29 19:03:10 2009
@@ -20,6 +20,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/Analysis/ValueTracking.h"
+#include "llvm/Support/Streams.h"
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//
@@ -870,3 +871,103 @@
   }
 }
 
+/// dump - print compile unit.
+void DICompileUnit::dump() const {
+  cerr << " [" << dwarf::LanguageString(getLanguage()) << "] ";
+  cerr << " [" << getDirectory() << "/" << getFilename() << " ]";
+}
+
+/// dump - print type.
+void DIType::dump() const {
+  if (isNull()) return;
+  if (!getName().empty())
+    cerr << " [" << getName() << "] ";
+  unsigned Tag = getTag();
+  cerr << " [" << dwarf::TagString(Tag) << "] ";
+  // TODO : Print context
+  getCompileUnit().dump();
+  cerr << " [" 
+       << getLineNumber() << ", " 
+       << getSizeInBits() << ", "
+       << getAlignInBits() << ", "
+       << getOffsetInBits() 
+       << "] ";
+  if (isPrivate()) 
+    cerr << " [private] ";
+  else if (isProtected())
+    cerr << " [protected] ";
+  if (isForwardDecl())
+    cerr << " [fwd] ";
+
+  if (isBasicType(Tag))
+    DIBasicType(GV).dump();
+  else if (isDerivedType(Tag))
+    DIDerivedType(GV).dump();
+  else if (isCompositeType(Tag))
+    DICompositeType(GV).dump();
+  else {
+    cerr << "Invalid DIType\n";
+    return;
+  }
+  cerr << "\n";
+}
+
+/// dump - print basic type.
+void DIBasicType::dump() const {
+  cerr << " [" << dwarf::AttributeEncodingString(getEncoding()) << "] ";
+
+}
+
+/// dump - print derived type.
+void DIDerivedType::dump() const {
+  cerr << "\n\t Derived From: "; getTypeDerivedFrom().dump();
+}
+
+/// dump - print composite type.
+void DICompositeType::dump() const {
+  DIArray A = getTypeArray();
+  if (A.isNull())
+    return;
+  cerr << " [" << A.getNumElements() << " elements]";
+}
+
+/// dump - print global.
+void DIGlobal::dump() const {
+
+  if (!getName().empty())
+    cerr << " [" << getName() << "] ";
+  unsigned Tag = getTag();
+  cerr << " [" << dwarf::TagString(Tag) << "] ";
+  // TODO : Print context
+  getCompileUnit().dump();
+  cerr << " [" << getLineNumber() << "] ";
+  if (isLocalToUnit())
+    cerr << " [local] ";
+  if (isDefinition())
+    cerr << " [def] ";
+
+  if (isGlobalVariable(Tag))
+    DIGlobalVariable(GV).dump();
+
+  cerr << "\n";
+}
+
+/// dump - print subprogram.
+void DISubprogram::dump() const {
+  DIGlobal::dump();
+}
+
+/// dump - print global variable.
+void DIGlobalVariable::dump() const {
+  cerr << " ["; getGlobal()->dump(); cerr << "] ";
+}
+
+/// dump - print variable.
+void DIVariable::dump() const {
+  if (!getName().empty())
+    cerr << " [" << getName() << "] ";
+  getCompileUnit().dump();
+  cerr << " [" << getLineNumber() << "] ";
+  getType().dump();
+  cerr << "\n";
+}





More information about the llvm-commits mailing list