[llvm-commits] [llvm] r107027 - in /llvm/trunk: lib/CodeGen/AsmPrinter/DwarfDebug.cpp lib/CodeGen/AsmPrinter/DwarfDebug.h test/FrontendC/2010-06-28-DbgLocalVar.c

Benjamin Kramer benny.kra at googlemail.com
Thu Jul 29 09:51:07 PDT 2010


On 28.06.2010, at 20:25, Devang Patel wrote:

> Author: dpatel
> Date: Mon Jun 28 13:25:03 2010
> New Revision: 107027
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=107027&view=rev
> Log:
> Preserve deleted function's local variables' debug info.
> Radar 8122864.
> 
> Added:
>    llvm/trunk/test/FrontendC/2010-06-28-DbgLocalVar.c
> Modified:
>    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
> 
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=107027&r1=107026&r2=107027&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Mon Jun 28 13:25:03 2010
> @@ -1386,6 +1386,7 @@
> /// If there are global variables in this scope then create and insert
> /// DIEs for these variables.
> DIE *DwarfDebug::updateSubprogramScopeDIE(const MDNode *SPNode) {
> +  ProcessedSPNodes.insert(SPNode);
>   CompileUnit *SPCU = getCompileUnit(SPNode);
>   DIE *SPDie = SPCU->getDIE(SPNode);
>   assert(SPDie && "Unable to find subprogram DIE!");
> @@ -2005,6 +2006,40 @@
> ///
> void DwarfDebug::endModule() {
>   if (!FirstCU) return;
> +  const Module *M = MMI->getModule();
> +  if (NamedMDNode *AllSPs = M->getNamedMetadata("llvm.dbg.sp")) {
> +    for (unsigned SI = 0, SE = AllSPs->getNumOperands(); SI != SE; ++SI) {
> +      if (ProcessedSPNodes.count(AllSPs->getOperand(SI)) != 0) continue;
> +      DISubprogram SP(AllSPs->getOperand(SI));
> +      if (!SP.Verify()) continue;
> +
> +      // Collect info for variables that were optimized out.
> +      StringRef FName = SP.getLinkageName();
> +      if (FName.empty())
> +        FName = SP.getName();
> +      NamedMDNode *NMD = 
> +        M->getNamedMetadata(Twine("llvm.dbg.lv.", getRealLinkageName(FName)));
> +      if (!NMD) continue;
> +      unsigned E = NMD->getNumOperands();
> +      if (!E) continue;
> +      DbgScope *Scope = new DbgScope(NULL, DIDescriptor(SP), NULL);

Hi Devang,

valgrind says those DbgScopes are leaked:


******************** TEST 'LLVM :: DebugInfo/2010-07-19-Crash.ll' FAILED ********************Script:
--
llc -o /dev/null < /build/buildbot-llvm/llvm-i686-linux-vg_leak/llvm/test/DebugInfo/2010-07-19-Crash.ll
--
Exit Code: 1
Command Output (stdout):
--
Command has output on stderr!

--
Command Output (stderr):
--
==22197== 196 (184 direct, 12 indirect) bytes in 1 blocks are definitely lost in loss record 138 of 139
==22197==    at 0x7F336CA: operator new(unsigned int) (vg_replace_malloc.c:255)
==22197==    by 0x8A8551D: llvm::DwarfDebug::endModule() (DwarfDebug.cpp:2051)
==22197==    by 0x8A73326: llvm::AsmPrinter::doFinalization(llvm::Module&) (AsmPrinter.cpp:738)
==22197==    by 0x8E1A150: llvm::FPPassManager::doFinalization(llvm::Module&) (PassManager.cpp:1471)
==22197==    by 0x8E1A065: llvm::FPPassManager::runOnModule(llvm::Module&) (PassManager.cpp:1455)
==22197==    by 0x8E1A31D: llvm::MPPassManager::runOnModule(llvm::Module&) (PassManager.cpp:1507)
==22197==    by 0x8E1A7D3: llvm::PassManagerImpl::run(llvm::Module&) (PassManager.cpp:1588)
==22197==    by 0x8E1ACB0: llvm::PassManager::run(llvm::Module&) (PassManager.cpp:1631)
==22197==    by 0x85B738F: main (llc.cpp:343)
==22197== 
--

********************

> +      for (unsigned I = 0; I != E; ++I) {
> +        DIVariable DV(NMD->getOperand(I));
> +        if (!DV.Verify()) continue;
> +        Scope->addVariable(new DbgVariable(DV));
> +      }
> +      
> +      // Construct subprogram DIE and add variables DIEs.
> +      constructSubprogramDIE(SP);
> +      DIE *ScopeDIE = getCompileUnit(SP)->getDIE(SP);
> +      const SmallVector<DbgVariable *, 8> &Variables = Scope->getVariables();
> +      for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
> +        DIE *VariableDIE = constructVariableDIE(Variables[i], Scope);
> +        if (VariableDIE)
> +          ScopeDIE->addChild(VariableDIE);
> +      }
> +    }
> +  }
> 
>   // Attach DW_AT_inline attribute with inlined subprogram DIEs.
>   for (SmallPtrSet<DIE *, 4>::iterator AI = InlinedSubprogramDIEs.begin(),




More information about the llvm-commits mailing list