Summary: | [4.0 Regression] Another debug info emitting bug | ||
---|---|---|---|
Product: | gcc | Reporter: | Robin Green <greenrd> |
Component: | c++ | Assignee: | Jim Wilson <wilson> |
Status: | RESOLVED FIXED | ||
Severity: | critical | CC: | dberlin, drow, gcc-bugs, jakub, jason, wilson |
Priority: | P2 | Keywords: | wrong-debug |
Version: | 4.0.0 | ||
Target Milestone: | 4.0.1 | ||
Host: | Target: | ||
Build: | Known to work: | 4.1.0 4.0.1 | |
Known to fail: | Last reconfirmed: | 2005-04-21 00:11:24 | |
Attachments: |
gzipped testcase
Only emit specification is this is not a declaration. |
Description
Robin Green
2005-04-07 03:17:59 UTC
Created attachment 8551 [details]
gzipped testcase
Since this is also a gdb bug, it should not be crashing, I would file there too. Simplified testcase: int *v; int *foo () { extern int *v; return static_cast<int *> (v); } compiled with just -g on e.g. x86-64 or i386. int *v; int * foo () { extern int *v; return v; } The section .debug_info contains: Compilation Unit @ 0: Length: 208 Version: 2 Abbrev Offset: 0 Pointer Size: 8 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit) DW_AT_stmt_list : 0 DW_AT_high_pc : 0xd DW_AT_low_pc : 0 DW_AT_producer : GNU C++ 4.1.0 20050405 (experimental) DW_AT_language : 4 (C++) DW_AT_name : /tmp/23.ii <1><52>: Abbrev Number: 2 (DW_TAG_subprogram) DW_AT_sibling : <9a> DW_AT_external : 1 DW_AT_name : foo DW_AT_decl_file : 1 DW_AT_decl_line : 4 DW_AT_MIPS_linkage_name: _Z3foov DW_AT_type : <9a> DW_AT_low_pc : 0 DW_AT_high_pc : 0xd DW_AT_frame_base : 1 byte block: 56 (DW_OP_reg6) <2><7c>: Abbrev Number: 3 (DW_TAG_lexical_block) DW_AT_low_pc : 0x4 DW_AT_high_pc : 0xb <3><8d>: Abbrev Number: 4 (DW_TAG_variable) DW_AT_name : v DW_AT_decl_file : 1 DW_AT_decl_line : 6 DW_AT_type : <9a> DW_AT_external : 1 DW_AT_declaration : 1 <1><9a>: Abbrev Number: 5 (DW_TAG_pointer_type) DW_AT_byte_size : 8 DW_AT_type : <a0> <1><a0>: Abbrev Number: 6 (DW_TAG_base_type) DW_AT_name : int DW_AT_byte_size : 4 DW_AT_encoding : 5 (signed) <1><a7>: Abbrev Number: 7 (DW_TAG_namespace) DW_AT_sibling : <c4> DW_AT_name : :: DW_AT_decl_file : 2 DW_AT_decl_line : 0 <2><b1>: Abbrev Number: 4 (DW_TAG_variable) DW_AT_name : v DW_AT_decl_file : 1 DW_AT_decl_line : 6 DW_AT_type : <9a> DW_AT_external : 1 DW_AT_declaration : 1 <2><bc>: Abbrev Number: 8 (DW_TAG_variable) DW_AT_specification: <8d> DW_AT_decl_line : 1 DW_AT_declaration : 1 <1><c4>: Abbrev Number: 9 (DW_TAG_variable) DW_AT_specification: <bc> DW_AT_location : 9 byte block: 3 0 0 0 0 0 0 0 0 (DW_OP_addr: 0) The gdb ICE happens when trying too lookup the 0x8d specification. I have a GDB patch that will avoid the internal error. I'll dig it up. I suppose there's room to argue that GCC's output is correct. Am I right in thinking that the function-local extern could, in some cases, change the result of name lookup? Jakub, do you know if this is a regression? It is a regression since 3.4.x in the sense that the same testcase was debuggable by gdb. But the main question now is I think whether what g++ 4.0 emits is correct or not. As for whether the debug information is correct: - It would be preferable if the full declaration was the one outside the function rather than inside, but I don't think there's anything in the standard to require this. - What the heck is the DW_TAG_namespace DIE for '::' doing there? We shouldn't be using an explicit namespace qualifier for things not in a namespace. Subject: Re: Another debug info emitting bug On Thu, Apr 07, 2005 at 12:31:35PM -0000, drow at gcc dot gnu dot org wrote: > I have a GDB patch that will avoid the internal error. I'll dig it up. See: http://sources.redhat.com/ml/gdb-patches/2005-04/msg00066.html 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. Created attachment 8560 [details]
Only emit specification is this is not a declaration.
Untested patch. Works for the smallest reduced testcase.
Subject: Bug 20805 CVSROOT: /cvs/gcc Module name: gcc Changes by: wilson@gcc.gnu.org 2005-04-20 23:51:30 Modified files: gcc : ChangeLog Log message: Avoid emitting bogus debug info that confuses gdb. PR c++/20805 * dwarf2out.c (gen_variable_die): Don't emit a specification if this is another declaration. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8380&r2=2.8381 Subject: Bug 20805 CVSROOT: /cvs/gcc Module name: gcc Changes by: wilson@gcc.gnu.org 2005-04-21 00:06:36 Modified files: gcc : dwarf2out.c Log message: Avoid emitting bogus debug info that confuses gdb. PR c++/20805 * dwarf2out.c (gen_variable_die): Don't emit a specification if this is another declaration. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/dwarf2out.c.diff?cvsroot=gcc&r1=1.584&r2=1.585 Fixed on mainline. Do we need this fixed for 4.0.1? If so, this will have to wait for the branch to unfreeze. (In reply to comment #15) > Fixed on mainline. > > Do we need this fixed for 4.0.1? If so, this will have to wait for the branch > to unfreeze. Yes it is also needed for 4.0. I should have marked it as a regression after Jakub's comments in comment #8. Subject: Bug 20805 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: wilson@gcc.gnu.org 2005-04-22 21:49:45 Modified files: gcc : ChangeLog dwarf2out.c Log message: Don't emit debug info that triggers a gdb internal error. PR c++/20805 * dwarf2out.c (gen_variable_die): Don't emit a specification if this is another declaration. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.178&r2=2.7592.2.179 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/dwarf2out.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.570.2.6&r2=1.570.2.7 Fixed on mainline and gcc-4.0 branch. |