Bug 20805 - [4.0 Regression] Another debug info emitting bug
Summary: [4.0 Regression] Another debug info emitting bug
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: 4.0.1
Assignee: Jim Wilson
URL:
Keywords: wrong-debug
Depends on:
Blocks:
 
Reported: 2005-04-07 03:17 UTC by Robin Green
Modified: 2005-09-06 14:07 UTC (History)
6 users (show)

See Also:
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 (112.94 KB, application/x-gzip)
2005-04-07 03:20 UTC, Robin Green
Details
Only emit specification is this is not a declaration. (619 bytes, patch)
2005-04-08 03:02 UTC, Jim Wilson
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Robin Green 2005-04-07 03:17:59 UTC
Like bug 19769, this debug info emitting bug also breaks gdb.

I will attach a .ii which triggers it.

Here is the gcc output, followed by the gdb output; this is tracked as fedora
bug https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=153681

# rm -f xpcjsid.o;make CXX="/usr/bin/g++ -v -save-temps "
/usr/bin/gmake export
gmake[1]: Entering directory `/usr/local/src/mozilla/js/src/xpconnect/src'
gmake[1]: Nothing to be done for `export'.
gmake[1]: Leaving directory `/usr/local/src/mozilla/js/src/xpconnect/src'
/usr/bin/gmake libs
gmake[1]: Entering directory `/usr/local/src/mozilla/js/src/xpconnect/src'
xpcjsid.cpp
/usr/bin/g++ -v -save-temps  -o xpcjsid.o -c
-I../../../../dist/include/system_wrappers -include
../../../../config/gcc_hidden.h -DOSTYPE=\"Linux2.6.11-1\" -DOSARCH=\"Linux\"
-DBUILD_ID=2005040517 -DHAVE_DEPENDENT_LIBS -DJSFILE -DJS_THREADSAFE
-DEXPORT_XPC_API -I./../loader  -I../../../../dist/include/xpcom
-I../../../../dist/include/string -I../../../../dist/include/js
-I../../../../dist/include/caps -I../../../../dist/include/dom
-I../../../../dist/include/xpconnect -I../../../../dist/include
-I../../../../dist/include/nspr    -I. -I/usr/X11R6/include   -fPIC 
-I/usr/X11R6/include -fno-rtti -fno-exceptions -Wall -Wconversion
-Wpointer-arith -Wcast-align -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy
-Wno-non-virtual-dtor -Wno-long-long -pedantic -fshort-wchar -pthread -pipe 
-DDEBUG -D_DEBUG -DDEBUG_root -DTRACING -g -fno-inline  -I/usr/X11R6/include
-DMOZILLA_CLIENT -include ../../../../mozilla-config.h -Wp,-MD,.deps/xpcjsid.pp
xpcjsid.cpp
g++: warning: -pipe ignored because -save-temps specified
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-languages=c,c++,objc,java,f95,ada
--enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 4.0.0 20050402 (Red Hat 4.0.0-0.39)
 /usr/libexec/gcc/i386-redhat-linux/4.0.0/cc1plus -E -quiet -v
-I../../../../dist/include/system_wrappers -I./../loader
-I../../../../dist/include/xpcom -I../../../../dist/include/string
-I../../../../dist/include/js -I../../../../dist/include/caps
-I../../../../dist/include/dom -I../../../../dist/include/xpconnect
-I../../../../dist/include -I../../../../dist/include/nspr -I.
-I/usr/X11R6/include -I/usr/X11R6/include -I/usr/X11R6/include -D_GNU_SOURCE
-D_REENTRANT -DOSTYPE="Linux2.6.11-1" -DOSARCH="Linux" -DBUILD_ID=2005040517
-DHAVE_DEPENDENT_LIBS -DJSFILE -DJS_THREADSAFE -DEXPORT_XPC_API -DDEBUG -D_DEBUG
-DDEBUG_root -DTRACING -DMOZILLA_CLIENT -include ../../../../config/gcc_hidden.h
-include ../../../../mozilla-config.h -MD .deps/xpcjsid.pp xpcjsid.cpp -Wall
-Wconversion -Wpointer-arith -Wcast-align -Woverloaded-virtual -Wsynth
-Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wno-long-long -pedantic -fPIC
-fno-rtti -fno-exceptions -fshort-wchar -fno-inline -fworking-directory
-fpch-preprocess -o xpcjsid.ii
ignoring nonexistent directory
"/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../../i386-redhat-linux/include"
ignoring duplicate directory "/usr/X11R6/include"
ignoring duplicate directory "/usr/X11R6/include"
#include "..." search starts here:
#include <...> search starts here:
 ../../../../dist/include/system_wrappers
 ./../loader
 ../../../../dist/include/xpcom
 ../../../../dist/include/string
 ../../../../dist/include/js
 ../../../../dist/include/caps
 ../../../../dist/include/dom
 ../../../../dist/include/xpconnect
 ../../../../dist/include
 ../../../../dist/include/nspr
 .
 /usr/X11R6/include
 /usr/lib/gcc/i386-redhat-linux/4.0.0/../../../../include/c++/4.0.0
 /usr/lib/gcc/i386-redhat-linux/4.0.0/../../../../include/c++/4.0.0/i386-redhat-linux
 /usr/lib/gcc/i386-redhat-linux/4.0.0/../../../../include/c++/4.0.0/backward
 /usr/local/include
 /usr/lib/gcc/i386-redhat-linux/4.0.0/include
 /usr/include
End of search list.
 /usr/libexec/gcc/i386-redhat-linux/4.0.0/cc1plus -fpreprocessed xpcjsid.ii
-quiet -dumpbase xpcjsid.cpp -auxbase-strip xpcjsid.o -g -Wall -Wconversion
-Wpointer-arith -Wcast-align -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy
-Wno-non-virtual-dtor -Wno-long-long -pedantic -version -fPIC -fno-rtti
-fno-exceptions -fshort-wchar -fno-inline -o xpcjsid.s
GNU C++ version 4.0.0 20050402 (Red Hat 4.0.0-0.39) (i386-redhat-linux)
        compiled by GNU C version 4.0.0 20050402 (Red Hat 4.0.0-0.39).
GGC heuristics: --param ggc-min-expand=96 --param ggc-min-heapsize=125365
 as -V -Qy -o xpcjsid.o xpcjsid.s
GNU assembler version 2.15.94.0.2.2 (i386-redhat-linux) using BFD version
2.15.94.0.2.2 20041220


# gdb xpcjsid.o
GNU gdb Red Hat Linux (6.3.0.0-1.10rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
../../gdb-6.3/gdb/dwarf2read.c:5446: internal-error: could not find partial DIE
in cache

A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)
Comment 1 Robin Green 2005-04-07 03:20:57 UTC
Created attachment 8551 [details]
gzipped testcase
Comment 2 Andrew Pinski 2005-04-07 05:38:53 UTC
Since this is also a gdb bug, it should not be crashing, I would file there too.
Comment 3 Robin Green 2005-04-07 11:06:00 UTC
gdb PR 1903 has already been filed for that.
Comment 4 Jakub Jelinek 2005-04-07 11:58:11 UTC
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.
Comment 5 Jakub Jelinek 2005-04-07 12:13:55 UTC
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.
Comment 6 Daniel Jacobowitz 2005-04-07 12:31:32 UTC
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?
Comment 7 Andrew Pinski 2005-04-07 14:03:43 UTC
Jakub, do you know if this is a regression?
Comment 8 Jakub Jelinek 2005-04-07 14:11:55 UTC
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.
Comment 9 Daniel Jacobowitz 2005-04-07 14:28:03 UTC
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.
Comment 10 Daniel Jacobowitz 2005-04-07 14:39:22 UTC
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

Comment 11 Jim Wilson 2005-04-08 03:01:10 UTC
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.
Comment 12 Jim Wilson 2005-04-08 03:02:52 UTC
Created attachment 8560 [details]
Only emit specification is this is not a declaration.

Untested patch.  Works for the smallest reduced testcase.
Comment 13 GCC Commits 2005-04-20 23:51:42 UTC
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

Comment 14 GCC Commits 2005-04-21 00:06:50 UTC
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

Comment 15 Jim Wilson 2005-04-21 00:11:23 UTC
Fixed on mainline.

Do we need this fixed for 4.0.1?  If so, this will have to wait for the branch
to unfreeze.
Comment 16 Andrew Pinski 2005-04-21 00:46:15 UTC
(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.
Comment 17 GCC Commits 2005-04-22 21:49:54 UTC
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

Comment 18 Jim Wilson 2005-04-22 21:53:20 UTC
Fixed on mainline and gcc-4.0 branch.