------- Additional Comments From wilson at gcc dot gnu dot org 2005-04-08 03:01 ------- The testcase works if the variable declaration is moved after the function. This is the case I fixed a few weeks ago, which was breaking java debugging.
The declare_in_namespace design causes us to get two DIEs for one declaration. The first DIE is in the variable namespace, and the second one is in the current context. When we emit the second one, lookup_decl_die in gen_variable_die will find the first one. It is important not to confuse this with a declaration followed by a definition, which requires DW_AT_specification. The difference between putting the definition before or after the function is whether DECL_STATIC is set. If it is declared before, DECL_STATIC is set. If it is declared after, DECL_STATIC is not set. So in first case we get DW_AT_specification which is wrong and confuses gdb, and in the second case we don't get DW_AT_specification, and gdb is happy. A possible way to resolve this is to add an addition check !declaration before emitting DW_AT_specification. The patch I am attaching to the PR does this, and works for Jakub's last reduced testcase. I haven't tried this with a bootstrap or make check or gdb make check yet. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20805