The DWARF emitted for a "char" variable is incorrect from gcc, but correct from g++. Consider this code ---- const_strings.c --------- typedef struct { const char * name; int value; } named_value; int main (int argc, char ** argv) { named_value v; const char * zero = "zero"; v.name = "one"; v.value = 1; v.value++; } ------------------------------- jcownie@pc4: gcc31 -v -g -c const_strings.c Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/specs Configured with: /home1/GNU/gcc-3.1/configure Thread model: single gcc version 3.1 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/cc1 -lang-c -v -iprefix /home1/jim/bin/Linux-i686/../lib/gcc-lib/i686-pc-linux-gnu/3.1/ -D__GNUC__=3 -D__GNUC_MINOR__=1 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ const_strings.c -quiet -dumpbase const_strings.c -g -version -o /tmp/ccStmXSo.s GNU CPP version 3.1 (cpplib) (i386 Linux/ELF) GNU C version 3.1 (i686-pc-linux-gnu) compiled by GNU C version 3.1. ignoring nonexistent directory "/home1/jim/bin/Linux-i686/../lib/gcc-lib/i686-pc-linux-gnu/3.1/include" ignoring nonexistent directory "/home1/jim/bin/Linux-i686/../lib/gcc-lib/i686-pc-linux-gnu/3.1/../../../../i686-pc-linux-gnu/include" ignoring nonexistent directory "NONE/include" ignoring nonexistent directory "/usr/local/i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/include /usr/include End of search list. as --traditional-format -V -Qy -o const_strings.o /tmp/ccStmXSo.s GNU assembler version 2.12 (i686-pc-linux-gnu) using BFD version 2.12 If we dump out the DWARF info with readelf -wi we see that the definition of the base type "char" is <1><a0>: Abbrev Number: 6 (DW_TAG_base_type) DW_AT_name : char DW_AT_byte_size : 1 DW_AT_encoding : 5 (signed) Which (see page 62 of the DWARF 3 document) defines it as a signed binary integer of size one byte, _NOT_ a signed character (which would be encoding 6). If we do the same thing with g++, we get <1><d7>: Abbrev Number: 5 (DW_TAG_base_type) DW_AT_name : char DW_AT_byte_size : 1 DW_AT_encoding : 6 (signed char) which is correct. Release: 3.1 Environment: System: Linux pc4 2.4.18 #1 Tue Apr 2 10:17:01 BST 2002 i686 unknown Architecture: i686 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: i686-pc-linux-gnu configured with: /home1/GNU/gcc-3.1/configure How-To-Repeat: As above.
From: James Cownie <jcownie@etnus.com> To: Franz Sirl <Franz.Sirl-kernel@lauterbach.com> Cc: gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org Subject: Re: debug/7241: DWARF encoding for "char" incorrect in gcc Date: Tue, 09 Jul 2002 12:12:20 +0100 > Hmm, I would rather think g++ is the wrong one here. IIRC in C++ (C > too?) "char"/"signed char"/"unsigned char" are actually 3 distinct > types and thus encoding 6 should have only be used if you would have > explicitly written "signed char" in your example, or? My point is not the issue of signedness, but that of "character"-ness. Gcc is emitting this as if it were int8_t (a single byte integer), and is not telling the debugger that the type should be displayed as holding a character. DWARF only has encodings for explicitly signed or explicitly unsigned objects. The fact that C has three different char types ("char", "signed char" and "unsigned char") is not expressible in DWARF, where the debugger needs to know what the underlying representation really is. Therefore in DWARF I would always expect that the C "char" type should be represented as either DW_ATE_signed_char or DW_ATE_unsigned_char, as appropriate. "char" should _not_ be represented as DW_ATE_signed or DW_ATE_unsigned, since those are _integer_ types, and the debugger will not attempt to display them as characters. -- Jim James Cownie <jcownie@etnus.com> Etnus, LLC. +44 117 9071438 http://www.etnus.com
From: Franz Sirl <Franz.Sirl-kernel@lauterbach.com> To: jcownie@etnus.com Cc: gcc-gnats@gcc.gnu.org,gcc-bugs@gcc.gnu.org Subject: Re: debug/7241: DWARF encoding for "char" incorrect in gcc Date: Tue, 09 Jul 2002 13:04:25 +0200 At 12:01 09.07.2002, jcownie@etnus.com wrote: > >Number: 7241 > >Category: debug > >Synopsis: DWARF encoding for "char" incorrect in gcc > >Confidential: no > >Severity: serious > >Priority: medium > >Responsible: unassigned > >State: open > >Class: sw-bug > >Submitter-Id: net > >Arrival-Date: Tue Jul 09 03:06:00 PDT 2002 > >Closed-Date: > >Last-Modified: > >Originator: James Cownie > >Release: 3.1 > >Organization: >Etnus LLC > >Environment: >System: Linux pc4 2.4.18 #1 Tue Apr 2 10:17:01 BST 2002 i686 unknown >Architecture: i686 >host: i686-pc-linux-gnu >build: i686-pc-linux-gnu >target: i686-pc-linux-gnu >configured with: /home1/GNU/gcc-3.1/configure > > >Description: >The DWARF emitted for a "char" variable is incorrect from gcc, but >correct from g++. > >Consider this code >---- const_strings.c --------- >typedef struct >{ > const char * name; > int value; >} named_value; > >int main (int argc, char ** argv) >{ > named_value v; > const char * zero = "zero"; > > v.name = "one"; > v.value = 1; > > v.value++; >} >------------------------------- >jcownie@pc4: gcc31 -v -g -c const_strings.c >Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/specs >Configured with: /home1/GNU/gcc-3.1/configure >Thread model: single >gcc version 3.1 > /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/cc1 -lang-c -v -iprefix > /home1/jim/bin/Linux-i686/../lib/gcc-lib/i686-pc-linux-gnu/3.1/ > -D__GNUC__=3 -D__GNUC_MINOR__=1 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix > -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ > -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 > -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ > -D__tune_pentiumpro__ const_strings.c -quiet -dumpbase const_strings.c -g > -version -o /tmp/ccStmXSo.s >GNU CPP version 3.1 (cpplib) (i386 Linux/ELF) >GNU C version 3.1 (i686-pc-linux-gnu) > compiled by GNU C version 3.1. >ignoring nonexistent directory >"/home1/jim/bin/Linux-i686/../lib/gcc-lib/i686-pc-linux-gnu/3.1/include" >ignoring nonexistent directory >"/home1/jim/bin/Linux-i686/../lib/gcc-lib/i686-pc-linux-gnu/3.1/../../../../i686-pc-linux-gnu/include" >ignoring nonexistent directory "NONE/include" >ignoring nonexistent directory "/usr/local/i686-pc-linux-gnu/include" >#include "..." search starts here: >#include <...> search starts here: > /usr/local/include > /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/include > /usr/include >End of search list. > as --traditional-format -V -Qy -o const_strings.o /tmp/ccStmXSo.s >GNU assembler version 2.12 (i686-pc-linux-gnu) using BFD version 2.12 > >If we dump out the DWARF info with readelf -wi we see that the >definition of the base type "char" is > > <1><a0>: Abbrev Number: 6 (DW_TAG_base_type) > DW_AT_name : char > DW_AT_byte_size : 1 > DW_AT_encoding : 5 (signed) > >Which (see page 62 of the DWARF 3 document) defines it as a signed >binary integer of size one byte, _NOT_ a signed character (which would >be encoding 6). > >If we do the same thing with g++, we get > <1><d7>: Abbrev Number: 5 (DW_TAG_base_type) > DW_AT_name : char > DW_AT_byte_size : 1 > DW_AT_encoding : 6 (signed char) > >which is correct. Hmm, I would rather think g++ is the wrong one here. IIRC in C++ (C too?) "char"/"signed char"/"unsigned char" are actually 3 distinct types and thus encoding 6 should have only be used if you would have explicitly written "signed char" in your example, or? Franz.
From: jakub@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: debug/7241 Date: 20 May 2003 12:33:08 -0000 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-rhl-branch Changes by: jakub@gcc.gnu.org 2003-05-20 12:33:08 Modified files: gcc : ChangeLog dwarf2out.c Log message: PR debug/7241 * dwarf2out.c (base_type_die): Use DW_ATE_*_char even if main variant is char_type_node and type name is char. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-rhl-branch&r1=1.16114.2.523.2.2&r2=1.16114.2.523.2.3 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/dwarf2out.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-rhl-branch&r1=1.390.2.6.2.1&r2=1.390.2.6.2.2
I see that there was fix on redhat's 3.3 branch, would someone comment on it if it is the right way of fixing it?
Sigh. Wrong bug, meant 7081, typed 7241 instead. Sorry about that.
Subject: Bug 7241 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-rhl-branch Changes by: jakub@gcc.gnu.org 2004-04-22 17:20:18 Modified files: gcc : ChangeLog dwarf2out.c Log message: PR debug/7241 * dwarf2out.c (base_type_die): Use DW_ATE_*_char even if main variant is char_type_node and type name is char. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-rhl-branch&r1=2.2326.2.399.2.3&r2=2.2326.2.399.2.4 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/dwarf2out.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-rhl-branch&r1=1.478.2.8&r2=1.478.2.8.2.1
Would someone comment if the fix in comment #6 is correct? And could it be applied to mainline to close out this bug?
It looks right to me. Jakub, could you submit this patch to gcc-patches, please?
Subject: Bug 7241 CVSROOT: /cvs/gcc Module name: gcc Changes by: jakub@gcc.gnu.org 2005-09-01 13:53:45 Modified files: gcc : ChangeLog dwarf2out.c gcc/testsuite : ChangeLog gcc/testsuite/gcc.dg/debug/dwarf2: dwarf-die1.c dwarf-die2.c dwarf-die3.c dwarf-die5.c dwarf-die6.c dwarf-die7.c dwarf-uninit.c dwarf2-macro.c Added files: gcc/testsuite/gcc.dg/debug/dwarf2: dwarf-char1.c dwarf-char2.c dwarf-char3.c Log message: PR debug/7241 * dwarf2out.c (base_type_die): Compare char_type_node with TYPE_MAIN_VARIANT (type), not type. * gcc.dg/debug/dwarf2/dwarf-char1.c: New test. * gcc.dg/debug/dwarf2/dwarf-char2.c: New test. * gcc.dg/debug/dwarf2/dwarf-char3.c: New test. * gcc.dg/debug/dwarf2/dwarf-die1.c: Fix a typo. * gcc.dg/debug/dwarf2/dwarf-die2.c: Likewise. * gcc.dg/debug/dwarf2/dwarf-die3.c: Likewise. * gcc.dg/debug/dwarf2/dwarf-die5.c: Likewise. * gcc.dg/debug/dwarf2/dwarf-die6.c: Likewise. * gcc.dg/debug/dwarf2/dwarf-die7.c: Likewise. * gcc.dg/debug/dwarf2/dwarf-uninit.c: Likewise. * gcc.dg/debug/dwarf2/dwarf2-macro.c: Likewise. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9873&r2=2.9874 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/dwarf2out.c.diff?cvsroot=gcc&r1=1.612&r2=1.613 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5991&r2=1.5992 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-char1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-char2.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-char3.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-die1.c.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-die2.c.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-die3.c.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-die5.c.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-die6.c.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-die7.c.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-uninit.c.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf2-macro.c.diff?cvsroot=gcc&r1=1.1&r2=1.2
Subject: Bug 7241 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: jakub@gcc.gnu.org 2005-09-01 14:04:55 Modified files: gcc : ChangeLog dwarf2out.c gcc/testsuite : ChangeLog gcc/testsuite/gcc.dg/debug/dwarf2: dwarf-die1.c dwarf2-macro.c dwarf-die2.c dwarf-uninit.c dwarf-die7.c dwarf-die6.c dwarf-die5.c dwarf-die3.c Added files: gcc/testsuite/gcc.dg/debug/dwarf2: dwarf-char1.c dwarf-char2.c dwarf-char3.c Log message: PR debug/7241 * dwarf2out.c (base_type_die): Compare char_type_node with TYPE_MAIN_VARIANT (type), not type. * gcc.dg/debug/dwarf2/dwarf-char1.c: New test. * gcc.dg/debug/dwarf2/dwarf-char2.c: New test. * gcc.dg/debug/dwarf2/dwarf-char3.c: New test. * gcc.dg/debug/dwarf2/dwarf-die1.c: Fix a typo. * gcc.dg/debug/dwarf2/dwarf-die2.c: Likewise. * gcc.dg/debug/dwarf2/dwarf-die3.c: Likewise. * gcc.dg/debug/dwarf2/dwarf-die5.c: Likewise. * gcc.dg/debug/dwarf2/dwarf-die6.c: Likewise. * gcc.dg/debug/dwarf2/dwarf-die7.c: Likewise. * gcc.dg/debug/dwarf2/dwarf-uninit.c: Likewise. * gcc.dg/debug/dwarf2/dwarf2-macro.c: Likewise. 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.404&r2=2.7592.2.405 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.10&r2=1.570.2.11 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.365&r2=1.5084.2.366 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-char1.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-char2.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-char3.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-die1.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1&r2=1.1.78.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf2-macro.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1.2.1&r2=1.1.2.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-die2.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1&r2=1.1.78.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-uninit.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1.2.1&r2=1.1.2.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-die7.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1&r2=1.1.78.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-die6.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1&r2=1.1.78.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-die5.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1&r2=1.1.78.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-die3.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1&r2=1.1.78.1
Fixed in 4.0.2.