From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2089 invoked by alias); 2 Aug 2005 00:34:11 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 2058 invoked by uid 48); 2 Aug 2005 00:34:07 -0000 Date: Tue, 02 Aug 2005 00:34:00 -0000 From: "dpatel at apple dot com" To: gcc-bugs@gcc.gnu.org Message-ID: <20050802003405.23190.dpatel@apple.com> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug debug/23190] New: debug info omitted for uninitialized variables X-Bugzilla-Reason: CC X-SW-Source: 2005-08/txt/msg00126.txt.bz2 List-Id: $ cat t.c static int foo; int bar; int main(void) { foo += 3; bar *= 5; return 0; } $ xgcc -g -O2 -o t t.c $ cat gdbcmds b main ptype foo ptype bar p foo p bar $ gdb --batch -x gdbcmds t Reading symbols for shared libraries ... done Breakpoint 1 at 0x2d14: file t.c, line 6. type = type = $1 = $2 = [ This was discussed in PR 21828 ] >On Jul 22, 2005, at 4:43 PM, mark at codesourcery dot com wrote: > >First, your example was not the one in the original bug report. > >Second, you're using STABS, not DWARF-2. I suspect the stabs debug >generator, or the GDB stabs reader is not as good as DWARF. > >On GNU/Linux, GDB knows that "bar" has type "int". It still doesn't >know the type of "foo"; apparently too much of the debug information is >optimized away. But, that's some other problem -- perhaps in GDB >itself. The information is clearly there for it: > > .uleb128 0x2 # (DIE (0x2d) DW_TAG_variable) > .ascii "foo\0" # DW_AT_name > .byte 0x1 # DW_AT_decl_file > .byte 0x1 # DW_AT_decl_line > .long 0x38 # DW_AT_type > .uleb128 0x3 # (DIE (0x38) DW_TAG_base_type) > .ascii "int\0" # DW_AT_name > .byte 0x4 # DW_AT_byte_size > .byte 0x5 # DW_AT_encoding It seems this is related to order of cgraph_optimize() and writing globals. If globals are wrapped up before emitting code then debug info. is not emitted for uninitialized globals, because DECL_RTL is not set. C++ FE writes globals before doing cgraph_optimize(), but C FE optimizes first. This is why this is C specific only. This patch fixes this but it causes varpool-1.c test failure. With this patch, GDB know about foo as well as bar when DWARF is used. Index: c-decl.c =============================================================== ==== RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v retrieving revision 1.677 diff -Idpatel.pbxuser -c -3 -p -r1.677 c-decl.c *** c-decl.c 19 Jul 2005 20:19:09 -0000 1.677 --- c-decl.c 28 Jul 2005 19:22:47 -0000 *************** tree c_cont_label; *** 131,136 **** --- 131,139 ---- static GTY(()) tree all_translation_units; + /* Outermost block. */ + static GTY(()) tree ext_block; + /* A list of decls to be made automatically visible in each file scope. */ static GTY(()) tree visible_builtins; *************** c_write_global_declarations_1 (tree glob *** 7570,7576 **** void c_write_global_declarations (void) { ! tree ext_block, t; /* We don't want to do this if generating a PCH. */ if (pch_file) --- 7573,7579 ---- void c_write_global_declarations (void) { ! tree t; /* We don't want to do this if generating a PCH. */ if (pch_file) *************** c_write_global_declarations (void) *** 7586,7591 **** --- 7589,7598 ---- external_scope = 0; gcc_assert (!current_scope); + /* We're done parsing; proceed to optimize and emit assembly. + FIXME: shouldn't be the front end's responsibility to call this. */ + cgraph_optimize (); + /* Process all file scopes in this compilation, and the external_scope, through wrapup_global_declarations and check_global_declarations. */ for (t = all_translation_units; t; t = TREE_CHAIN (t)) *************** c_write_global_declarations (void) *** 7608,7617 **** functions have magic names which are detected by collect2. */ build_cdtor ('I', static_ctors); static_ctors = 0; build_cdtor ('D', static_dtors); static_dtors = 0; - - /* We're done parsing; proceed to optimize and emit assembly. - FIXME: shouldn't be the front end's responsibility to call this. */ - cgraph_optimize (); } #include "gt-c-decl.h" --- 7615,7620 ---- -- Summary: debug info omitted for uninitialized variables Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: debug AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dpatel at apple dot com CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23190