From c452324f60561bdc1a3f90b8f7d085beb9487f36 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Mon, 5 Jan 2009 23:11:11 +0000 Subject: [PATCH] Construct global variable DIEs using DebugInfo. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61771 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/DwarfWriter.cpp | 49 +++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp index 401252460c4..026671436c0 100644 --- a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp @@ -3116,7 +3116,7 @@ private: 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 Result; @@ -3155,6 +3155,53 @@ private: } } + /// ConstructGlobalVariableDIEs - Create DIEs for each of the externally + /// visible global variables. + void ConstructGlobalVariableDIEs() { + std::string GVName = "llvm.dbg.global_variables"; + std::vector Result; + getGlobalVariablesUsing(*M, GVName, Result); + for (std::vector::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() {