From c067196984b2f6044668af31e93ce3366226d58e Mon Sep 17 00:00:00 2001 From: Stuart Hastings Date: Tue, 6 Apr 2010 17:19:32 +0000 Subject: Revise debug info machinery to digest nested functions and classes. A certain GDB testsuite case (local.cc) has a function nested inside a class nested inside another function. GCC presents the innermost function to llvm-convert first. Heretofore, the debug info mistakenly placed the inner function at module scope. This patch walks the GCC context links and instantiates the outer class and function so the debug info is properly nested. Radar 7426545. llvm-svn: 100530 --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp') diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index b472d1e5335..0af6b3315ae 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -800,12 +800,26 @@ void DwarfDebug::addToContextOwner(DIE *Die, DIDescriptor Context) { } else if (Context.isNameSpace()) { DIE *ContextDIE = getOrCreateNameSpace(DINameSpace(Context.getNode())); ContextDIE->addChild(Die); + } else if (Context.isSubprogram()) { + DIE *ContextDIE = createSubprogramDIE(DISubprogram(Context.getNode()), + /*MakeDecl=*/false); + ContextDIE->addChild(Die); } else if (DIE *ContextDIE = ModuleCU->getDIE(Context.getNode())) ContextDIE->addChild(Die); else ModuleCU->addDie(Die); } +/// isFunctionContext - True if given Context is nested within a function. +bool DwarfDebug::isFunctionContext(DIE *context) { + if (context == (DIE *)0) + return false; + if (context->getTag() == dwarf::DW_TAG_subprogram) + return true; + else + return isFunctionContext(context->getParent()); +} + /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the /// given DIType. DIE *DwarfDebug::getOrCreateTypeDIE(DIType Ty) { @@ -987,6 +1001,10 @@ void DwarfDebug::constructTypeDIE(DIE &Buffer, DICompositeType CTy) { if (DIDescriptor(ContainingType.getNode()).isCompositeType()) addDIEEntry(&Buffer, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4, getOrCreateTypeDIE(DIType(ContainingType.getNode()))); + else { + DIDescriptor Context = CTy.getContext(); + addToContextOwner(&Buffer, Context); + } break; } default: @@ -1802,19 +1820,15 @@ void DwarfDebug::constructGlobalVariableDIE(MDNode *N) { void DwarfDebug::constructSubprogramDIE(MDNode *N) { DISubprogram SP(N); - // Check for pre-existence. - if (ModuleCU->getDIE(N)) - return; - if (!SP.isDefinition()) // This is a method declaration which will be handled while constructing // class type. return; - DIE *SubprogramDie = createSubprogramDIE(SP); - - // Add to map. - ModuleCU->insertDIE(N, SubprogramDie); + // Check for pre-existence. + DIE *SubprogramDie = ModuleCU->getDIE(N); + if (!SubprogramDie) + SubprogramDie = createSubprogramDIE(SP); // Add to context owner. addToContextOwner(SubprogramDie, SP.getContext()); -- cgit v1.2.3