Bug 13956 - [3.4/4.0 regression] incorrect stabs for nested local variables
Summary: [3.4/4.0 regression] incorrect stabs for nested local variables
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 3.4.0
: P1 critical
Target Milestone: 3.4.2
Assignee: Zack Weinberg
URL:
Keywords: wrong-debug
Depends on:
Blocks:
 
Reported: 2004-02-01 07:21 UTC by Michael Elizabeth Chastain
Modified: 2005-02-09 02:18 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 3.3.1
Known to fail:
Last reconfirmed: 2004-02-01 13:15:55


Attachments
Source code with nested scopes. (153 bytes, text/plain)
2004-02-01 07:23 UTC, Michael Elizabeth Chastain
Details
Generated assembly code, good, gcc 3.3.2 -S -gstabs+ (1.10 KB, text/plain)
2004-02-01 07:24 UTC, Michael Elizabeth Chastain
Details
Generated assembly code, bad, gcc HEAD 2004-02-01 -gstabs+ -S (1.14 KB, text/plain)
2004-02-01 07:24 UTC, Michael Elizabeth Chastain
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Elizabeth Chastain 2004-02-01 07:21:47 UTC
Here is an excerpt from a test program:

  void f1 ()
  {
    int alpha;
    int beta;

    ...
    {
      int alpha;
      int gamma;
      ...
    }
    ...
   }

My command line is "gcc -gstabs+ -S alpha.c".

With gcc 3.3.2, I get these healthy-looking stabs:

  .LBE2:
        .size   f1, .-f1
        .stabs  "alpha:(0,1)",128,0,15,-4
        .stabs  "beta:(0,1)",128,0,16,-8
        .stabn  192,0,0,.LBB2-f1
        .stabs  "alpha:(0,1)",128,0,21,-12
        .stabs  "gamma:(0,1)",128,0,22,-16
        .stabn  192,0,0,.LBB3-f1
        .stabn  224,0,0,.LBE3-f1
        .stabn  224,0,0,.LBE2-f1

stabn 192 is N_LBRAC, and stabn 224 is N_RBRAC.  Each group of local variables
is followed by its range.  All is well.

With gcc HEAD 2003-04-11 03:00:00 UTC, all is still fine:

  .LBE2:
        .size   f1, .-f1
        .stabs  "alpha:(0,1)",128,0,15,-4
        .stabs  "beta:(0,1)",128,0,16,-8
        .stabn  192,0,0,.LBB2-f1
        .stabs  "alpha:(0,1)",128,0,21,-12
        .stabs  "gamma:(0,1)",128,0,22,-16
        .stabn  192,0,0,.LBB3-f1
        .stabn  224,0,0,.LBE3-f1
        .stabn  224,0,0,.LBE2-f1

With gcc HEAD 2003-04-11 04:30:00 UTC, the stabs are wrong:

        .size   f1, .-f1
        .stabs  "alpha:(0,1)",128,0,15,-4
        .stabs  "beta:(0,1)",128,0,16,-8
        .stabs  "alpha:(0,1)",128,0,21,-12
        .stabs  "gamma:(0,1)",128,0,22,-16
        .stabn  192,0,0,.LBB2-f1
        .stabn  224,0,0,.LBE2-f1

One of the N_LBRAC/N_RBRAC pairs has disappeared.

And with current gcc, gcc HEAD 2004-02-01 01:34:15 UTC:

        .size   f1, .-f1
        .stabs  "alpha:(0,1)",128,0,15,-4
        .stabs  "beta:(0,1)",128,0,16,-8
        .stabs  "alpha:(0,1)",128,0,21,-12
        .stabs  "gamma:(0,1)",128,0,22,-16
        .stabn  192,0,0,.LBB2-f1
        .stabn  224,0,0,.LBE2-f1

This problem came in with this patch:

  2003-04-10  Zack Weinberg  <zack@codesourcery.com>

        * c-decl.c (struct binding_level): Add shadowed_tags and
        function_body; remove this_block, tag_transparent, and
        subblocks_tag_transparent; update comments.
        ...

  2003-04-10  Zack Weinberg  <zack@codesourcery.com>

        * c-tree.h (struct lang_identifier): Replace global_value,
        local_value members with symbol_value, tag_value.  Kill
        implicit_decl and limbo_value.
        ...

There are two ChangeLog entries here, but only one patch.

This is the same patch that caused PR debug/12267.  Per the comments in 12267,
I'm assigning it to Zack (or trying to).

Attachments to follow.
Comment 1 Michael Elizabeth Chastain 2004-02-01 07:23:10 UTC
Created attachment 5633 [details]
Source code with nested scopes.

Compile with gcc -S -gstabs+.
Comment 2 Michael Elizabeth Chastain 2004-02-01 07:24:03 UTC
Created attachment 5634 [details]
Generated assembly code, good, gcc 3.3.2 -S -gstabs+
Comment 3 Michael Elizabeth Chastain 2004-02-01 07:24:47 UTC
Created attachment 5635 [details]
Generated assembly code, bad, gcc HEAD 2004-02-01 -gstabs+ -S
Comment 4 Andrew Pinski 2004-02-01 13:15:55 UTC
Confirmed.
Comment 5 Zack Weinberg 2004-03-15 21:05:52 UTC
fixed the mime types of all the attachments.  sorry for the noise.
Comment 6 Michael Elizabeth Chastain 2004-03-16 02:20:47 UTC
Subject: Re:  [3.4/3.5 regression] incorrect stabs for nested local variables

> fixed the mime types of all the attachments.  sorry for the noise.

Woops, sorry for the un-useful mime types.  I was letting
them be set automatically.  In the future I will set them explicitly
to text/plain.

Michael C
Comment 7 Mark Mitchell 2004-03-21 17:56:00 UTC
Given that stabs are only used on a few platforms by deafult, and that Zack
doesn't think this easy to fix for 3.4.0, I've retargeted this at 3.4.1.

Zack, does the c-decl rewrite fix this one too?
Comment 8 Mark Mitchell 2004-03-21 17:56:18 UTC
Regarted at 3.4.1.
Comment 9 Eric Botcazou 2004-03-21 18:07:08 UTC
One of the primary platforms (sparc-sun-solaris2.8) use stabs by default.
Comment 10 Zack Weinberg 2004-03-21 18:20:57 UTC
Subject: Re:  [3.4/3.5 regression] incorrect stabs for
 nested local variables


This one, unfortunately, is not fixed by the c-decl rewrite; I mean to
look at it as soon as I get the rewrite laid down, but my time is very
limited for the next two weeks.

zw
Comment 11 Mark Mitchell 2004-03-23 21:32:48 UTC
Subject: Re:  [3.4/3.5 regression] incorrect stabs for nested
 local variables

ebotcazou at gcc dot gnu dot org wrote:

>------- Additional Comments From ebotcazou at gcc dot gnu dot org  2004-03-21 18:07 -------
>One of the primary platforms (sparc-sun-solaris2.8) use stabs by default.
>  
>
How unfortunate.

As a SPARC user, do you think this is a showstopper problem?

Comment 12 Eric Botcazou 2004-03-23 23:30:29 UTC
Probably no, since GCC can generate DWARF-2 debug info on Solaris 7 and later,
that both DBX and GDB can grok (DWARF-2 is not available on Solaris 2.6 and
earlier).  But it would be nice to fix it on the 3.4 branch at some point.
Comment 13 Daniel Jacobowitz 2004-03-29 15:28:19 UTC
Subject: Re:  [3.4/3.5 regression] incorrect stabs for nested local variables

Should DWARF-2 be the default for Solaris 7 and later, then?  I'm in
favor of anything that decreases use of stabs!
Comment 14 Eric Botcazou 2004-03-29 16:52:17 UTC
I guess so, since DWARF-2 is already the default for 64-bit code.

Mark, do you think we can switch the default debug format for 32-bit code too?
Comment 15 Mark Mitchell 2004-03-30 17:01:27 UTC
Subject: Re:  [3.4/3.5 regression] incorrect stabs for nested
 local variables

ebotcazou at gcc dot gnu dot org wrote:

>------- Additional Comments From ebotcazou at gcc dot gnu dot org  2004-03-29 16:52 -------
>I guess so, since DWARF-2 is already the default for 64-bit code.
>
>Mark, do you think we can switch the default debug format for 32-bit code too?
>  
>
Yes, I do, actually.  It would be good to do a little testing there to 
make sure that GDB basically works, but it's hard for me to see how 
DWARF-2, which we use on so many systems, including other SPARC 
configurations, could be worse than STABS.

Comment 16 Mark Mitchell 2004-06-18 23:49:01 UTC
Eric -- didn't we end up switching to DWARF for Solaris?  If so, would you
please close this as WONTFIX?

Postponed until GCC 3.4.2 in the meanwhile.
Comment 17 Eric Botcazou 2004-06-19 05:54:08 UTC
> Eric -- didn't we end up switching to DWARF for Solaris?

Yes, we did.  This uncovered a couple of issues, one in each of the 2 supported
assemblers, but nothing that would justify the backwards move I'd say.

> If so, would you please close this as WONTFIX?

Done.
Comment 18 Daniel Jacobowitz 2004-06-21 03:05:28 UTC
Subject: Re:  [3.4/3.5 regression] incorrect stabs for nested local variables

Doesn't this bug still affect HEAD stabs generation?  Surely
SPARC/Solaris was not the only platform left which used stabs.
Comment 19 Andrew Pinski 2004-06-21 03:58:55 UTC
Yes, Mac OS X (darwin) is effect also (even though dwarf-2 support was just added, it is still not the 
default).
Comment 20 GCC Commits 2004-08-04 07:32:26 UTC
Subject: Bug 13956

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	zack@gcc.gnu.org	2004-08-04 07:32:20

Modified files:
	gcc            : ChangeLog dbxout.c 

Log message:
	PR 13956
	* dbxout.c (dbx_output_lbrac, dbx_output_rbrac): New
	functions, broken out of dbxout_block.
	(dbxout_block): The block at depth 0 should get LBRAC/RBRAC
	stabs too, if it contains symbols.  Use the begin_label and
	the Lscope label (emitted by dbxout_function_end) for the
	range of this block.
	(dbxout_function_decl): Always call dbxout_function_end.
	(dbxout_function_end): Return after emitting the "Lscope" symbol
	under the same conditions that this function formerly wasn't called.
	Add explanatory comments.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.573&r2=2.2326.2.574
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/dbxout.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.172.2.1&r2=1.172.2.2

Comment 21 Zack Weinberg 2004-08-04 07:36:05 UTC
there.
Comment 22 Wolfgang Bangerth 2004-08-04 14:53:55 UTC
The cvs commit message for mainline erroneously got attached to 
PR 13596. It is fixed on mainline, though. 
 
W. 
Comment 23 Michael Elizabeth Chastain 2004-08-05 16:29:26 UTC
gcc HEAD works great for me.

I tested it on three examples that I had and it worked on all of them.

Also I ran the gdb test suite on native i686-pc-linux-gnu with this test matrix:

  gdb 6.1.1, gdb HEAD
  gdb test suite HEAD, with local modifications
  gcc 3.4.1, gcc HEAD 20040731, gcc HEAD 20040804
  debug formats dwarf2, stabs+

The bugs got fixed (gdb.base/scope.exp in particular) and no new regressions
appeared.  Cheers for Zack!