[llvm-commits] CVS: llvm/lib/CodeGen/DwarfWriter.cpp MachineDebugInfo.cpp

Jim Laskey jlaskey at apple.com
Wed Mar 15 11:10:11 PST 2006



Changes in directory llvm/lib/CodeGen:

DwarfWriter.cpp updated: 1.47 -> 1.48
MachineDebugInfo.cpp updated: 1.31 -> 1.32
---
Log message:

Expand subprogram and added block descriptor.


---
Diffs of the changes:  (+79 -29)

 DwarfWriter.cpp      |   14 +++----
 MachineDebugInfo.cpp |   94 +++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 79 insertions(+), 29 deletions(-)


Index: llvm/lib/CodeGen/DwarfWriter.cpp
diff -u llvm/lib/CodeGen/DwarfWriter.cpp:1.47 llvm/lib/CodeGen/DwarfWriter.cpp:1.48
--- llvm/lib/CodeGen/DwarfWriter.cpp:1.47	Thu Mar  9 11:48:46 2006
+++ llvm/lib/CodeGen/DwarfWriter.cpp	Wed Mar 15 13:09:58 2006
@@ -1518,19 +1518,19 @@
 
   // Gather the details (simplify add attribute code.)
   const std::string &Name = SPD->getName();
-  unsigned FileID = Unit->getID();
-  // FIXME - faking the line for the time being.
-  unsigned Line = 1;
-  
-  // FIXME - faking the type for the time being.
-  DIE *Type = NewBasicType(Unit->getDie(), Type::IntTy); 
+  CompileUnitDesc *FileDesc = static_cast<CompileUnitDesc *>(SPD->getFile());
+  CompileUnit *File = FindCompileUnit(FileDesc);
+  unsigned FileID = File->getID();
+  DIE *Type = NewBasicType(Unit->getDie(), Type::IntTy);
+  unsigned Line = SPD->getLine();
+  unsigned IsExternal = SPD->isStatic() ? 0 : 1;
                                     
   DIE *SubprogramDie = new DIE(DW_TAG_subprogram);
   SubprogramDie->AddString     (DW_AT_name,      DW_FORM_string, Name);
   SubprogramDie->AddUInt       (DW_AT_decl_file, 0,              FileID);
   SubprogramDie->AddUInt       (DW_AT_decl_line, 0,              Line);
   SubprogramDie->AddDIEntry    (DW_AT_type,      DW_FORM_ref4,   Type);
-  SubprogramDie->AddUInt       (DW_AT_external,  DW_FORM_flag,   1);
+  SubprogramDie->AddUInt       (DW_AT_external,  DW_FORM_flag,   IsExternal);
   
   // Add to map.
   Slot = SubprogramDie;


Index: llvm/lib/CodeGen/MachineDebugInfo.cpp
diff -u llvm/lib/CodeGen/MachineDebugInfo.cpp:1.31 llvm/lib/CodeGen/MachineDebugInfo.cpp:1.32
--- llvm/lib/CodeGen/MachineDebugInfo.cpp:1.31	Tue Mar 14 12:37:57 2006
+++ llvm/lib/CodeGen/MachineDebugInfo.cpp	Wed Mar 15 13:09:58 2006
@@ -270,16 +270,12 @@
     Elements.push_back(ConstantBool::get(Field));
   }
   virtual void Apply(std::string &Field) {
-    if (Field.empty()) {
-      Elements.push_back(NULL);
-    } else {
       Elements.push_back(SR.getString(Field));
-    }
   }
   virtual void Apply(DebugInfoDesc *&Field) {
     GlobalVariable *GV = NULL;
     
-    // If non-NULL the convert to global.
+    // If non-NULL then convert to global.
     if (Field) GV = SR.Serialize(Field);
     
     // FIXME - At some point should use specific type.
@@ -473,19 +469,21 @@
   case DW_TAG_compile_unit:     return new CompileUnitDesc();
   case DW_TAG_variable:         return new GlobalVariableDesc();
   case DW_TAG_subprogram:       return new SubprogramDesc();
+  case DW_TAG_lexical_block:    return new BlockDesc();
   case DW_TAG_base_type:        return new BasicTypeDesc();
   case DW_TAG_typedef:
-  case DW_TAG_pointer_type:         
+  case DW_TAG_pointer_type:        
   case DW_TAG_reference_type:
   case DW_TAG_const_type:
-  case DW_TAG_volatile_type:         
-  case DW_TAG_restrict_type:    return new DerivedTypeDesc(Tag);
+  case DW_TAG_volatile_type:        
+  case DW_TAG_restrict_type:
+  case DW_TAG_formal_parameter:
+  case DW_TAG_member:           return new DerivedTypeDesc(Tag);
   case DW_TAG_array_type:
   case DW_TAG_structure_type:
   case DW_TAG_union_type:
   case DW_TAG_enumeration_type: return new CompositeTypeDesc(Tag);
   case DW_TAG_subrange_type:    return new SubrangeDesc();
-  case DW_TAG_member:           return new DerivedTypeDesc(DW_TAG_member);
   case DW_TAG_enumerator:       return new EnumeratorDesc();
   default: break;
   }
@@ -761,6 +759,7 @@
   case DW_TAG_const_type:
   case DW_TAG_volatile_type:
   case DW_TAG_restrict_type:
+  case DW_TAG_formal_parameter:
   case DW_TAG_member:
     return true;
   default: break;
@@ -948,6 +947,8 @@
 : AnchoredDesc(T)
 , Context(0)
 , Name("")
+, File(NULL)
+, Line(0)
 , TyDesc(NULL)
 , IsStatic(false)
 , IsDefinition(false)
@@ -960,6 +961,8 @@
 
   Visitor->Apply(Context);
   Visitor->Apply(Name);
+  Visitor->Apply((DebugInfoDesc *&)File);
+  Visitor->Apply(Line);
   Visitor->Apply((DebugInfoDesc *&)TyDesc);
   Visitor->Apply(IsStatic);
   Visitor->Apply(IsDefinition);
@@ -983,7 +986,6 @@
   GlobalDesc::ApplyToFields(Visitor);
 
   Visitor->Apply(Global);
-  Visitor->Apply(Line);
 }
 
 /// getDescString - Return a string used to compose global names and labels.
@@ -1011,11 +1013,12 @@
             << "Tag(" << getTag() << "), "
             << "Anchor(" << getAnchor() << "), "
             << "Name(\"" << getName() << "\"), "
+            << "File(" << getFile() << "),"
+            << "Line(" << getLine() << "),"
             << "Type(\"" << getTypeDesc() << "\"), "
             << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
             << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), "
-            << "Global(" << Global << "), "
-            << "Line(" << Line << ")\n";
+            << "Global(" << Global << ")\n";
 }
 #endif
 
@@ -1034,6 +1037,8 @@
 /// SubprogramDesc.
 void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) {
   GlobalDesc::ApplyToFields(Visitor);
+
+  Visitor->Apply(Elements);
 }
 
 /// getDescString - Return a string used to compose global names and labels.
@@ -1061,6 +1066,8 @@
             << "Tag(" << getTag() << "), "
             << "Anchor(" << getAnchor() << "), "
             << "Name(\"" << getName() << "\"), "
+            << "File(" << getFile() << "),"
+            << "Line(" << getLine() << "),"
             << "Type(\"" << getTypeDesc() << "\"), "
             << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
             << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n";
@@ -1069,6 +1076,44 @@
 
 //===----------------------------------------------------------------------===//
 
+BlockDesc::BlockDesc()
+: DebugInfoDesc(DW_TAG_lexical_block)
+{}
+
+// Implement isa/cast/dyncast.
+bool BlockDesc::classof(const DebugInfoDesc *D) {
+  return D->getTag() == DW_TAG_lexical_block;
+}
+
+/// ApplyToFields - Target the visitor to the fields of the BlockDesc.
+///
+void BlockDesc::ApplyToFields(DIVisitor *Visitor) {
+  DebugInfoDesc::ApplyToFields(Visitor);
+
+  Visitor->Apply(Elements);
+}
+
+/// getDescString - Return a string used to compose global names and labels.
+///
+const char *BlockDesc::getDescString() const {
+  return "llvm.dbg.block";
+}
+
+/// getTypeString - Return a string used to label this descriptors type.
+///
+const char *BlockDesc::getTypeString() const {
+  return "llvm.dbg.block.type";
+}
+
+#ifndef NDEBUG
+void BlockDesc::dump() {
+  std::cerr << getDescString() << " "
+            << "Tag(" << getTag() << ")\n";
+}
+#endif
+
+//===----------------------------------------------------------------------===//
+
 DebugInfoDesc *DIDeserializer::Deserialize(Value *V) {
   return Deserialize(getGlobalVariable(V));
 }
@@ -1159,17 +1204,22 @@
 Constant *DISerializer::getString(const std::string &String) {
   // Check string cache for previous edition.
   Constant *&Slot = StringCache[String];
-  // return Constant if previously defined.
+  // Return Constant if previously defined.
   if (Slot) return Slot;
-  // Construct string as an llvm constant.
-  Constant *ConstStr = ConstantArray::get(String);
-  // Otherwise create and return a new string global.
-  GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
-                                             GlobalVariable::InternalLinkage,
-                                             ConstStr, "str", M);
-  StrGV->setSection("llvm.metadata");
-  // Convert to generic string pointer.
-  Slot = ConstantExpr::getCast(StrGV, getStrPtrType());
+  // If empty string then use a sbyte* null instead.
+  if (String.empty()) {
+    Slot = ConstantPointerNull::get(getStrPtrType());
+  } else {
+    // Construct string as an llvm constant.
+    Constant *ConstStr = ConstantArray::get(String);
+    // Otherwise create and return a new string global.
+    GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
+                                               GlobalVariable::InternalLinkage,
+                                               ConstStr, "str", M);
+    StrGV->setSection("llvm.metadata");
+    // Convert to generic string pointer.
+    Slot = ConstantExpr::getCast(StrGV, getStrPtrType());
+  }
   return Slot;
   
 }






More information about the llvm-commits mailing list