From: Devang Patel Date: Fri, 15 Jan 2010 01:12:22 +0000 (+0000) Subject: Do not use AT_specification die for static variables. It confuses gdb. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c9b16cc10887d270aa2a43a5a8c78e0ed3177dea;p=oota-llvm.git Do not use AT_specification die for static variables. It confuses gdb. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93494 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index af8366afabe..15f37aec148 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1653,8 +1653,11 @@ void DwarfDebug::constructGlobalVariableDIE(MDNode *N) { ModuleCU->insertDIE(N, VariableDie); // Add to context owner. - if (DI_GV.isDefinition() - && !DI_GV.getContext().isCompileUnit()) { + DIDescriptor GVContext = DI_GV.getContext(); + // Do not create specification DIE if context is either compile unit + // or a subprogram. + if (DI_GV.isDefinition() && !GVContext.isCompileUnit() + && !GVContext.isSubprogram()) { // Create specification DIE. DIE *VariableSpecDIE = new DIE(dwarf::DW_TAG_variable); addDIEEntry(VariableSpecDIE, dwarf::DW_AT_specification, @@ -1672,7 +1675,7 @@ void DwarfDebug::constructGlobalVariableDIE(MDNode *N) { Asm->Mang->getMangledName(DI_GV.getGlobal())); addBlock(VariableDie, dwarf::DW_AT_location, 0, Block); } - addToContextOwner(VariableDie, DI_GV.getContext()); + addToContextOwner(VariableDie, GVContext); // Expose as global. FIXME - need to check external flag. ModuleCU->addGlobal(DI_GV.getName(), VariableDie); diff --git a/test/FrontendC/2010-01-14-StaticVariable.c b/test/FrontendC/2010-01-14-StaticVariable.c new file mode 100644 index 00000000000..80dd4d45259 --- /dev/null +++ b/test/FrontendC/2010-01-14-StaticVariable.c @@ -0,0 +1,12 @@ +// This is a regression test on debug info to make sure that llvm emitted +// debug info does not crash gdb. +// RUN: %llvmgcc -S -O0 -g %s -o - | \ +// RUN: llc --disable-fp-elim -o %t.s -O0 -relocation-model=pic +// RUN: %compile_c %t.s -o %t.o +// RUN: echo {quit\n} > %t.in +// RUN: gdb -q -batch -n -x %t.in %t.o > /dev/null + +int foo() { + static int i = 42; + return i; +}