Bug 27574 - [4.2/4.3 Regression] MIssing debug info at -O0 for a local variable in a C++ constructor
Summary: [4.2/4.3 Regression] MIssing debug info at -O0 for a local variable in a C++ ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.2.0
: P2 normal
Target Milestone: 4.3.3
Assignee: Dodji Seketeli
URL:
Keywords: wrong-debug
: 34767 35212 39961 (view as bug list)
Depends on:
Blocks: 29842
  Show dependency treegraph
 
Reported: 2006-05-12 16:53 UTC by Jorn Wolfgang Rennecke
Modified: 2009-04-29 15:09 UTC (History)
15 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.0.2 4.4.0
Known to fail: 4.1.0 4.2.0
Last reconfirmed: 2008-10-07 20:51:02


Attachments
test case (94 bytes, text/plain)
2006-05-12 16:58 UTC, Jorn Wolfgang Rennecke
Details
With the translation result for this file, the testcase can be linked (89 bytes, text/plain)
2006-05-12 17:02 UTC, Jorn Wolfgang Rennecke
Details
g++.dg/debug test case (185 bytes, text/plain)
2006-07-25 20:43 UTC, Jorn Wolfgang Rennecke
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jorn Wolfgang Rennecke 2006-05-12 16:53:21 UTC
Compilation with -O0 -g no longer creates debug information for all variables.
Comment 1 Jorn Wolfgang Rennecke 2006-05-12 16:58:27 UTC
Created attachment 11447 [details]
test case

Compiled for either sh-elf or i686-pc-linux-gnu, currrent mainline cc1plus does
not generate any debug information for the variable 'problem'.
Comment 2 Jorn Wolfgang Rennecke 2006-05-12 17:02:39 UTC
Created attachment 11448 [details]
With the translation result for this file, the testcase can be linked

This file provides a definition of main and f so that when this file and
the test case are translated to an object file, they can be linked together
so that you can observe gdb showing - or rather not showing - the variable
named "problem".
Comment 3 Andrew Pinski 2006-05-12 17:11:45 UTC
Confirmed.
Comment 4 Mark Mitchell 2006-05-25 02:34:51 UTC
Will not be fixed in 4.1.1; adjust target milestone to 4.1.2.
Comment 5 Daniel Jacobowitz 2006-07-22 20:05:00 UTC
I am not going to track down what did it, but something has fixed this on the 4.2 branch.  I can reproduce it on Debian's 4.1 branch snapshot.  If someone wants to fix it on 4.1, it should probably be easy to use the regression hunter to identify what patch caused the string "problem" to appear in the assembly output.  It is probably something in the last two and a half months, since the bug was reported, but I do not see any obvious candidates.
Comment 6 Jorn Wolfgang Rennecke 2006-07-25 12:14:46 UTC
(In reply to comment #5)
> I am not going to track down what did it, but something has fixed this on the
> 4.2 branch.  I can reproduce it on Debian's 4.1 branch snapshot.  If someone
> wants to fix it on 4.1, it should probably be easy to use the regression hunter
> to identify what patch caused the string "problem" to appear in the assembly
> output.  It is probably something in the last two and a half months, since the
> bug was reported, but I do not see any obvious candidates.
> 
If this is fixed on mainline, the fix must be rather recent; I see this still failing with
r115417: GNU C++ version 4.2.0 20060713 (experimental).
What is the oldest gcc 4.2 version where you saw this work?
Comment 7 Daniel Jacobowitz 2006-07-25 13:27:50 UTC
Subject: Re:  [4.1 Regression] MIssing debug info at -O0 for a local variable in a C++ constructor

On Tue, Jul 25, 2006 at 12:14:46PM -0000, amylaar at gcc dot gnu dot org wrote:
> If this is fixed on mainline, the fix must be rather recent; I see this still
> failing with
> r115417: GNU C++ version 4.2.0 20060713 (experimental).
> What is the oldest gcc 4.2 version where you saw this work?

I tested it on HEAD on the day I posted (2006-07-22).  Could you check
whether that works for you, or it's something environmental?

Comment 8 joern.rennecke@st.com 2006-07-25 17:08:17 UTC
Subject: Re:  [4.1 Regression] MIssing debug info at -O0 for a local variable in a C++ constructor

drow at false dot org wrote:

>------- Comment #7 from drow at gcc dot gnu dot org  2006-07-25 13:27 -------
>Subject: Re:  [4.1 Regression] MIssing debug info at -O0 for a local variable
>in a C++ constructor
>
>On Tue, Jul 25, 2006 at 12:14:46PM -0000, amylaar at gcc dot gnu dot org wrote:
>  
>
>>If this is fixed on mainline, the fix must be rather recent; I see this still
>>failing with
>>r115417: GNU C++ version 4.2.0 20060713 (experimental).
>>What is the oldest gcc 4.2 version where you saw this work?
>>    
>>
>
>I tested it on HEAD on the day I posted (2006-07-22).  Could you check
>whether that works for you, or it's something environmental?
>  
>
When I compile the testcase (using -g -O0) with a cc1plus built from todays
sources (r115734), a test search for "problem" in the .s file comes up 
empty.
OTOH, both a native and a cross build eventually failed.

Can you find out the exact version of gcc that you tested?
Comment 9 Jorn Wolfgang Rennecke 2006-07-25 20:43:19 UTC
Created attachment 11938 [details]
g++.dg/debug test case

As far as I can tell, as a g++.dg/debug test case, this passes for stabs, but
fails for dwarf.
Comment 10 Daniel Jacobowitz 2006-07-26 03:52:08 UTC
Subject: Re:  [4.1 Regression] MIssing debug info at -O0 for a local variable in a C++ constructor

On Tue, Jul 25, 2006 at 05:08:18PM -0000, joern dot rennecke at st dot com wrote:
> When I compile the testcase (using -g -O0) with a cc1plus built from todays
> sources (r115734), a test search for "problem" in the .s file comes up 
> empty.
> OTOH, both a native and a cross build eventually failed.
> 
> Can you find out the exact version of gcc that you tested?

Now it fails.  What the heck?

The problem is that an abstract instance of 'problem' is never emitted. 
For the two concrete instances we try to reference the abstract copy
but there isn't one.  The variable is emitted, but without a name.

The first abstract instance of A::A is a declaration.  Later a
"definition" (still abstract) is seen.  But its DECL_INITIAL is
error_mark_node!

If I had to guess I'd say that this was a C++ front end problem, or
maybe a recent change in cgraph.  I don't have time to debug it further
right now.  The abstract copy of the function has to have a body, or
dwarf2out has no structure with which to describe the local variables.

Comment 11 Jorn Wolfgang Rennecke 2006-07-26 12:30:30 UTC
(In reply to comment #10)
 > If I had to guess I'd say that this was a C++ front end problem, or
> maybe a recent change in cgraph.

It can't have been a particularly recent change, since it already failed
with GNU C++ version 4.1.0 20050323 (experimental) (sh-elf) .
It worked with GNU C++ version 4.1.0 20050314 (experimental) (sh-elf) .
Comment 12 Daniel Jacobowitz 2006-07-26 13:59:33 UTC
It is a cgraph change.  There were several patches affecting cgraph_remove_node during this time period; it was probably one of those.  The problem is that we throw away the body of the abstract copy of the constructor, before we get around to emitting debug information for it.

There's already a debug hook at what looks like the right time.  It's just not used for dwarf2: deferred_inline_function.  It was replaced by outlining_inline_function, which is called only when we know we'll generate a concrete instance.

There's a couple of things we could do:
  - Not throw away the body.
  - Try to generate the debug info earlier, and then prune it if it isn't needed.
  - Try to treat one of the concrete clones (whose bodies we need) as the origin.

I think the first one is going to be safest for now.

I don't really see how to do it.  Jan, do you have a suggestion?
Comment 13 Jorn Wolfgang Rennecke 2006-07-27 17:29:38 UTC
(In reply to comment #12)
> It is a cgraph change.  There were several patches affecting cgraph_remove_node
> during this time period; it was probably one of those.

The problem appeared from r96653 to r96654; AFAICT this is the gcc-patches
posting for the associated patch: http://gcc.gnu.org/ml/gcc-patches/2005-03/msg01709.html
Comment 14 Daniel Jacobowitz 2006-07-27 20:12:45 UTC
Subject: Re:  [4.1/4.2 Regression] MIssing debug info at -O0 for a local variable in a C++ constructor

On Thu, Jul 27, 2006 at 05:29:38PM -0000, amylaar at gcc dot gnu dot org wrote:
> The problem appeared from r96653 to r96654; AFAICT this is the gcc-patches
> posting for the associated patch:
> http://gcc.gnu.org/ml/gcc-patches/2005-03/msg01709.html

Jan and Dan Berlin suggested that the right fix for this bug might be
to not register the uncloned constructor with cgraph, only the clones.

Comment 15 Daniel Jacobowitz 2006-08-25 18:57:16 UTC
I don't think I can sort this one out.  I think the easiest solution will be to check when marking a function as reachable whether it has an abstract origin, and if so set a flag in the abstract origin preventing its body from being killed, but I can't keep track of all the other similar-but-not-quite-the-same flags in cgraph.
Comment 16 Andrew Pinski 2008-01-13 13:02:20 UTC
*** Bug 34767 has been marked as a duplicate of this bug. ***
Comment 17 Richard Biener 2008-01-13 14:04:00 UTC
Honza, can you have a look here?
Comment 18 Andrew Pinski 2008-02-15 21:27:18 UTC
*** Bug 35212 has been marked as a duplicate of this bug. ***
Comment 19 Andrew Pinski 2008-02-15 21:29:29 UTC
I don't know if this is the correct patch but we made this for the PS3 toolchain:
Index: gcc/cgraph.c
===================================================================
--- gcc/cgraph.c	(revision 2280)
+++ gcc/cgraph.c	(working copy)
@@ -476,14 +476,16 @@
       if (!n->next_clone && !n->global.inlined_to
 	  && (cgraph_global_info_ready
 	      && (TREE_ASM_WRITTEN (n->decl) || DECL_EXTERNAL (n->decl))))
-	kill_body = true;
+	{
+	  DECL_INITIAL (node->decl) = error_mark_node;
+	  kill_body = true;
+	}
     }
 
   if (kill_body && !dump_enabled_p (TDI_tree_all) && flag_unit_at_a_time)
     {
       DECL_SAVED_TREE (node->decl) = NULL;
       DECL_STRUCT_FUNCTION (node->decl) = NULL;
-      DECL_INITIAL (node->decl) = error_mark_node;
     }
   cgraph_n_nodes--;
   /* Do not free the structure itself so the walk over chain can continue.  */
Comment 20 Andrew Pinski 2008-04-01 07:11:38 UTC
I am just going to test this patch and relook at it when the test is finished but I can see what the issue is.  at -O0 we have unit-at-a-time on.  Though there is still an issue if we don't have any clones, I think.  I will relook more into it after the bootstrap/test finishes.
Comment 21 Ian Lance Taylor 2008-04-23 22:33:38 UTC
A patch like this seems like a decent workaround to me.

Honza, any opinions on this approach?

Ian

Index: cgraph.c
===================================================================
--- cgraph.c	(revision 134283)
+++ cgraph.c	(working copy)
@@ -615,6 +615,14 @@ cgraph_remove_node (struct cgraph_node *
 	kill_body = true;
     }
 
+  /* We don't release the body of abstract functions, because they may
+     be needed when emitting debugging information.  In particular
+     this will happen for C++ constructors/destructors.  FIXME:
+     Ideally we would check to see whether there are any reachable
+     functions whose DECL_ABSTRACT_ORIGIN points to this decl.  */
+  if (DECL_ABSTRACT (node->decl))
+    kill_body = false;
+
   if (kill_body && flag_unit_at_a_time)
     cgraph_release_function_body (node);
   node->decl = NULL;
Comment 22 Andrew Pinski 2008-04-23 23:08:49 UTC
(In reply to comment #21)
> A patch like this seems like a decent workaround to me.
> 
> Honza, any opinions on this approach?

This looks good to me also.
Comment 23 Joseph S. Myers 2008-07-04 21:22:26 UTC
Closing 4.1 branch.
Comment 24 Dodji Seketeli 2008-11-06 10:24:35 UTC
So the patch http://gcc.gnu.org/ml/gcc-patches/2008-11/msg00133.html that fixes this got accepted. So this might end up in trunk soon.

For 4.3 and 4.2 we might want to apply Ian's patch as it is less disruptive.

See http://gcc.gnu.org/ml/gcc-patches/2008-09/msg01981.html .

Comment 25 Dodji Seketeli 2008-11-12 21:59:09 UTC
Subject: Bug 27574

Author: dodji
Date: Wed Nov 12 21:57:44 2008
New Revision: 141807

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141807
Log:
gcc/ChangeLog:
2008-11-12  Dodji Seketeli  <dodji@redhat.com>

	PR debug/27574
	* cgraph.h: New abstract_and_needed member to struct cgraph_node.
	* cgraphunit.c (cgraph_analyze_functions): Flag abstract functions
	- which clones are reachable - as "abstract and needed".
	* cgraph.c (cgraph_release_function_body):  If a node is "abstract and needed",
	do not release its DECL_INITIAL() content because that will be needed to emit
	debug info.

gcc/testsuite/ChangeLog:
2008-11-12  Dodji Seketeli  <dodji@redhat.com>

	PR debug/27574
	* g++.dg/debug/dwarf2/local-var-in-contructor.C: New test.


Added:
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/local-var-in-contructor.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cgraph.c
    trunk/gcc/cgraph.h
    trunk/gcc/cgraphunit.c
    trunk/gcc/final.c
    trunk/gcc/testsuite/ChangeLog

Comment 26 Dodji Seketeli 2008-11-13 10:56:29 UTC
Subject: Bug 27574

Author: dodji
Date: Thu Nov 13 10:55:01 2008
New Revision: 141819

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141819
Log:
Fix ChangeLog entry:
	PR debug/27574
	* cgraph.h: New abstract_and_needed member to struct cgraph_node.
	* cgraphunit.c (cgraph_analyze_functions): Flag abstract functions
	- which clones are reachable - as "abstract and needed".
	* cgraph.c (cgraph_release_function_body):  If a node is
	"abstract and needed", do not release its DECL_INITIAL() content
	that will be needed to emit debug info.


Modified:
    trunk/gcc/ChangeLog

Comment 27 Dodji Seketeli 2008-11-14 13:28:25 UTC
Subject: Bug 27574

Author: dodji
Date: Fri Nov 14 13:26:59 2008
New Revision: 141858

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141858
Log:
gcc/ChangeLog:
	PR debug/27574
	* cgraph.h: New abstract_and_needed member to struct cgraph_node.
	* cgraphunit.c (cgraph_analyze_functions): Flag abstract functions
	-which clones are reachable - as "abstract and needed".
	* cgraph.c (cgraph_release_function_body):  If a node is
	"abstract and needed", do not release its DECL_INITIAL() content
	will be needed to emit debug info.

gcc/testsuite/ChangeLog:
	PR debug/27574
	* g++.dg/debug/dwarf2/local-var-in-contructor.C: New test.


Added:
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/debug/dwarf2/local-var-in-contructor.C
Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/cgraph.c
    branches/gcc-4_3-branch/gcc/cgraph.h
    branches/gcc-4_3-branch/gcc/cgraphunit.c
    branches/gcc-4_3-branch/gcc/final.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 28 Dodji Seketeli 2008-11-19 00:17:22 UTC
Subject: Bug 27574

Author: dodji
Date: Wed Nov 19 00:15:52 2008
New Revision: 141984

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141984
Log:
gcc/ChangeLog:
2008-11-14  Dodji Seketeli  <dodji@redhat.com>

	PR c++/27574
	* gcc/cgraph.c (cgraph_remove_node): Do not remove the body of
	  abstract functions. It might be useful to emit debugging
	  information. This is a patch from Ian Lance Taylor.
	* cgraphunit.c (cgraph_optimize): Do not cry when bodies of abstract
	  functions are still around. They are useful to output debug info.

gcc/testsuite/ChangeLog
2008-11-14  Dodji Seketeli  <dodji@redhat.com>

	PR c++/27574
	* testsuite/g++.dg/debug/dwarf2/dwarf2.exp: Backport this here from
	gcc-4_3-branch.
	* g++.dg/debug/dwarf2/local-var-in-contructor.C: New testcase.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/g++.dg/debug/dwarf2/
    branches/gcc-4_2-branch/gcc/testsuite/g++.dg/debug/dwarf2/dwarf2.exp
    branches/gcc-4_2-branch/gcc/testsuite/g++.dg/debug/dwarf2/local-var-in-contructor.C
Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/cgraph.c
    branches/gcc-4_2-branch/gcc/cgraphunit.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 29 Dodji Seketeli 2008-11-19 00:21:18 UTC
Fixed in trunk, 4.3 and 4.2 branch.
Comment 30 Jorn Wolfgang Rennecke 2008-12-09 18:22:17 UTC
I think the testcase pr27574.C should be added to the testsuite before
closing this bug.
Comment 31 Jorn Wolfgang Rennecke 2008-12-09 18:48:51 UTC
Sorry, I only checked for the presence of the original testcase name in
the testsuite, and thus missed the fact that there is a new test called
local-var-in-contructor.C [sic] .
Comment 32 Andrew Pinski 2009-04-29 15:09:09 UTC
*** Bug 39961 has been marked as a duplicate of this bug. ***