public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dpatel at apple dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug debug/23190] New: debug info omitted for uninitialized variables
Date: Tue, 02 Aug 2005 00:34:00 -0000	[thread overview]
Message-ID: <20050802003405.23190.dpatel@apple.com> (raw)

$ 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 = <unknown type>
type = <unknown type>
$1 = <unknown type>
$2 = <unknown type>

[ 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


             reply	other threads:[~2005-08-02  0:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-02  0:34 dpatel at apple dot com [this message]
2005-08-02  0:37 ` [Bug debug/23190] [4.0/4.1 Regression] debug info omitted for uninitialized variables (stabs) pinskia at gcc dot gnu dot org
2005-08-02  0:41 ` pinskia at gcc dot gnu dot org
2005-08-02  0:42 ` pinskia at gcc dot gnu dot org
2005-08-02  3:25 ` mark at codesourcery dot com
2005-08-02 16:52 ` dpatel at apple dot com
2005-08-02 17:01 ` mmitchel at gcc dot gnu dot org
2005-08-02 17:12 ` dpatel at apple dot com
2005-08-02 17:16 ` mark at codesourcery dot com
2005-08-02 17:21 ` dpatel at apple dot com
2005-09-08  2:39 ` rth at gcc dot gnu dot org
2005-09-08  2:42 ` rth at gcc dot gnu dot org
2005-09-09  0:47 ` cvs-commit at gcc dot gnu dot org
2005-09-09  0:52 ` cvs-commit at gcc dot gnu dot org
2005-09-09  1:08 ` rth at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050802003405.23190.dpatel@apple.com \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).