[llvm-commits] [llvm] r61771 - /llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp

Devang Patel dpatel at apple.com
Mon Jan 5 15:11:13 PST 2009


Author: dpatel
Date: Mon Jan  5 17:11:11 2009
New Revision: 61771

URL: http://llvm.org/viewvc/llvm-project?rev=61771&view=rev
Log:

Construct global variable DIEs using DebugInfo.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp?rev=61771&r1=61770&r2=61771&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Mon Jan  5 17:11:11 2009
@@ -3116,7 +3116,7 @@
     Asm->EOL();
   }
 
-  /// ConstructCompileUnitDIEs - Create a compile unit DIEs.
+  /// ConstructCompileUnits - Create a compile unit DIEs.
   void ConstructCompileUnits() {
     std::string CUName = "llvm.dbg.compile_units";
     std::vector<GlobalVariable*> Result;
@@ -3155,6 +3155,53 @@
     }
   }
 
+  /// ConstructGlobalVariableDIEs - Create DIEs for each of the externally 
+  /// visible global variables.
+  void ConstructGlobalVariableDIEs() {
+    std::string GVName = "llvm.dbg.global_variables";
+    std::vector<GlobalVariable*> Result;
+    getGlobalVariablesUsing(*M, GVName, Result);
+    for (std::vector<GlobalVariable *>::iterator GVI = Result.begin(),
+           GVE = Result.end(); GVI != GVE; ++GVI) {
+      DIGlobalVariable *DI_GV = new DIGlobalVariable(*GVI);
+      CompileUnit *DW_Unit = FindCompileUnit(DI_GV->getCompileUnit());
+
+      // Check for pre-existence.
+      DIE *&Slot = DW_Unit->getDieMapSlotFor(DI_GV->getGV());
+      if (Slot) continue;
+
+      DIE *VariableDie = new DIE(DW_TAG_variable);
+      AddString(VariableDie, DW_AT_name, DW_FORM_string, DI_GV->getName());
+      const std::string &LinkageName  = DI_GV->getLinkageName();
+      if (!LinkageName.empty())
+        AddString(VariableDie, DW_AT_MIPS_linkage_name, DW_FORM_string,
+                  LinkageName);
+      AddType(DW_Unit, VariableDie, DI_GV->getType());
+
+      if (!DI_GV->isLocalToUnit())
+        AddUInt(VariableDie, DW_AT_external, DW_FORM_flag, 1);              
+
+      // Add source line info, if available.
+      AddSourceLine(VariableDie, DI_GV);
+
+      // Add address.
+      DIEBlock *Block = new DIEBlock();
+      AddUInt(Block, 0, DW_FORM_data1, DW_OP_addr);
+      AddObjectLabel(Block, 0, DW_FORM_udata,
+                     Asm->getGlobalLinkName(DI_GV->getGV()));
+      AddBlock(VariableDie, DW_AT_location, 0, Block);
+
+      //Add to map.
+      Slot = VariableDie;
+
+      //Add to context owner.
+      DW_Unit->getDie()->AddChild(VariableDie);
+
+      //Expose as global. FIXME - need to check external flag.
+      DW_Unit->AddGlobal(DI_GV->getName(), VariableDie);
+    }
+  }
+
   /// ConstructGlobalDIEs - Create DIEs for each of the externally visible
   /// global variables.
   void ConstructGlobalDIEs() {





More information about the llvm-commits mailing list