[Bug debug/65821] New: [4.8.2 regression] incorrect debug line # info for main

classic Classic list List threaded Threaded
22 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] New: [4.8.2 regression] incorrect debug line # info for main

thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

            Bug ID: 65821
           Summary: [4.8.2 regression] incorrect debug line # info for
                    main
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chihin.ko at oracle dot com

this happen since 4.8.2, 4.9.0 also have same problem.

cat t.cc
==========================================================
  1 #include <stdio.h>
  2
  3 int b = 12;
  4
  5 inline void foo(const int &x = (b+3))
  6 {
  7     printf("%d\n", x);
  8 }   9
 10 inline void baz(const int &x = 200)
 11 {
 12     printf("%d\n", x);
 13 }
 14
 15 inline void bar(int &x = b)
 16 {  17     printf("%d\n", x);
 18     x = 100;
 19     printf("%d\n", x);
 20 }
 21
 22
 23 void
 24 bob(char *s = "hello")  25 {
 26     printf("%s\n", s);
 27 }  28
 29 int main()
 30 {
 31   foo();  32   baz();
 33   bar();
 34   bob();
 35   return 0;
 36 }
====================================================
The line table for main is incorrect:

< 1><0x0000067e>    DW_TAG_subprogram
                      DW_AT_external              yes(1)
                      DW_AT_name                  "main"
                      DW_AT_decl_file             0x00000001 t.cc
                      DW_AT_decl_line             0x0000001d
                      DW_AT_type                  <0x00000491>
                      DW_AT_low_pc                0x0040129f
                      DW_AT_high_pc               0x004012ff
.debug_line
---
....
0x0040129f  [  30, 0] NS
0x004012a7  [   5, 0] NS   <==== extra line info
0x004012b0  [  31, 0] NS
0x004012bf  [  32, 0] NS DI=0x1
0x004012d2  [  33, 0] NS
0x004012dc  [  34, 0] NS

This cause follwing problem:
(gdb) b main
Breakpoint 1 at 0x4006ea: file c++defargs3.cc, line 5.  <== should be line 31
(gdb) run
Starting program:
/workspace/chko/ws/dinstall/dbx_test/intel_S11_gcc482/c++defargs3.dbx,gcc/g47/a.out

Breakpoint 1, main () at c++defargs3.cc:5
5       inline void foo(const int &x = (b+3))
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [4.8.2 regression] incorrect debug line # info for main

thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It is doing (b+3) first which is from :5 which seems correct to me.  Default
arguments should have a line information right?
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [4.8.2 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

--- Comment #2 from chihin ko <chihin.ko at oracle dot com> ---
(In reply to Andrew Pinski from comment #1)
> It is doing (b+3) first which is from :5 which seems correct to me.  Default
> arguments should have a line information right?

Then gdb should stop at line 30 first and when I step into foo(),
it stop at line 5. line 5 should belongs to foo().

Current behavior is confusing to user.
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [4.8/4.9/5/6 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2015-04-21
   Target Milestone|---                         |4.8.5
            Summary|[4.8.2 regression]          |[4.8/4.9/5/6 regression]
                   |incorrect debug line # info |incorrect debug line # info
                   |for main                    |for main
     Ever confirmed|0                           |1

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
What version works correctly?  (please provide the testcase as attachment as
well)
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [4.8/4.9/5/6 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

--- Comment #4 from chihin ko <chihin.ko at oracle dot com> ---
(In reply to Richard Biener from comment #3)
> What version works correctly?  (please provide the testcase as attachment as
> well)

< 0><0x0000000b>  DW_TAG_compile_unit
                    DW_AT_producer              "GNU C++ 4.7.2"
                    DW_AT_language              DW_LANG_C_plus_plus
...
...
< 1><0x00000547>    DW_TAG_subprogram
                      DW_AT_external              yes(1)
                      DW_AT_name                  "main"
                      DW_AT_decl_file             0x00000001
/workspace/chko/ws/dinstall/dbx_test/intel_S11_gcc482/c++defargs3.dbx,gcc/g47/c++defargs3.cc
                      DW_AT_decl_line             0x0000001d
                      DW_AT_type                  <0x00000371>
                      DW_AT_low_pc                0x00400b02
                      DW_AT_high_pc               0x00400b62
...
...

0x00400b02  [  30, 0] NS
0x00400b0a  [  31, 0] NS
0x00400b22  [  32, 0] NS DI=0x1
0x00400b35  [  33, 0] NS
0x00400b3f  [  34, 0] NS
0x00400b49  [  35, 0] NS
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [4.8/4.9/5/6 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

--- Comment #5 from chihin ko <chihin.ko at oracle dot com> ---
Created attachment 35381
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35381&action=edit
test case 1/1
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [4.8/4.9/5/6 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.8.5                       |4.9.3

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
The gcc-4_8-branch is being closed, re-targeting regressions to 4.9.3.
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [4.9/5/6 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 4.9.3 has been released.
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [4.9/5/6 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.9.3                       |4.9.4
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [4.9/5/6 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
             Status|WAITING                     |NEW
      Known to work|                            |4.7.2
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [4.9/5/6 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jan.kratochvil at redhat dot com,
                   |                            |jason at gcc dot gnu.org,
                   |                            |mark at gcc dot gnu.org,
                   |                            |paolo at gcc dot gnu.org

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think this changed with r192246.  And the question is what we want for the
debugging experience.  Not emitting location info for the expressions expanded
from the default arguments is strange, and it is something that is evaluated on
the caller side, not on the callee side.
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [4.9/5/6 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

--- Comment #9 from Jan Kratochvil <jan.kratochvil at redhat dot com> ---
-O2 -g does not show this problem so I am testing it with -O0 -g below:

g++ (GCC) 4.7.3 20130221 (prerelease)
   0x0000000000400748 <+4>:     sub    $0x10,%rsp
=> 0x000000000040074c <+8>:     mov    0x200906(%rip),%eax        # 0x601058
<b>
   0x0000000000400752 <+14>:    add    $0x3,%eax
.debug_line:
  [0x00000078]  Special opcode 36: advance Address by 2 to 0x400744 and Line by
3 to 30
  [0x00000079]  Special opcode 118: advance Address by 8 to 0x40074c and Line
by 1 to 31
  [0x0000007a]  Extended opcode 4: set Discriminator to 1
  [0x0000007e]  Advance PC by constant 17 to 0x40075d
  [0x0000007f]  Special opcode 104: advance Address by 7 to 0x400764 and Line
by 1 to 32
Not OK, the line 5 of inlined function foo() is not present there at all.

g++ (GCC) 6.0.0 20160205 (Red Hat 6.0.0-0.10)
   0x0000000000400645 <+4>:     sub    $0x10,%rsp
=> 0x0000000000400649 <+8>:     mov    0x2009e5(%rip),%eax        # 0x601034
<b>
   0x000000000040064f <+14>:    add    $0x3,%eax
.debug_line:
  [0x00000104]  Special opcode 50: advance Address by 3 to 0x400641 and Line by
3 to 30
  [0x00000105]  Advance Line by -25 to 5
  [0x00000107]  Special opcode 117: advance Address by 8 to 0x400649 and Line
by 0 to 5
  [0x00000108]  Advance Line by 26 to 31
  [0x0000010a]  Special opcode 173: advance Address by 12 to 0x400655 and Line
by 0 to 31
This is basically OK, inlined function foo() is shown for its lines of code.

The bug is that in both cases .debug_info does not contain DW_AT_inline-d
DW_TAG_subprogram foo() as a child of DW_TAG_subprogram main() with its proper
PC range 0x400649..0x400655 excl.  This is why GDB shows:
  5     /*  5 */ inline void foo(const int &x = (b+3))
  (gdb) bt
  #0  main () at t.cc:5
while GDB should show:
  5     /*  5 */ inline void foo(const int &x = (b+3))
  (gdb) bt
  #0  foo (...) at t.cc:5
  #1  main () at t.cc:31

But that would be still look wrong as it would show the latter case even after
  $ gdb -ex start ./t
(therefore stopping at line 5 instead of expected line 31) because GDB
currently shows the innermost inlined frame after stopping at a breakpoint.
That is IMO a GDB bug and Fedora GDB was showing the outermost frame (so that
then one "step"ped into the inlined functions without changing $pc) for some
time.  But current Fedora GDB is back again aligned with upstream GDB to the
"buggy" behavior.
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [4.9/5/6/7 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.9.4                       |5.5

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 4.9 branch is being closed
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [5/6/7 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The default arguments are evaluated in the caller even for non-inline
functions, for those we can hardly have any DW_AT_inline or
DW_TAG_inlined_subroutine just because of the arguments.
So, the question is, do we want for the debug experience have the location info
of the default parameters come from the location where the expression of the
default parameters appear in the source (that is what current gcc emits), or do
we want it to be overridden to the call location (that is pretty much what we
used to emit before)?
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [5/6/7/8 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|5.5                         |6.5

--- Comment #12 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 5 branch is being closed
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [6/7/8 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [6/7/8 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

--- Comment #13 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Tue Apr 10 14:24:00 2018
New Revision: 259278

URL: https://gcc.gnu.org/viewcvs?rev=259278&root=gcc&view=rev
Log:
        PR debug/65821 - wrong location for main().

        * call.c (clear_location_r): New.
        (convert_default_arg): Use it.
        * tree.c (bot_manip): Remove builtin_LINE/FILE handling.

Added:
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/default-arg1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/tree.c
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [6/7 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[6/7/8 regression]          |[6/7 regression] incorrect
                   |incorrect debug line # info |debug line # info for main
                   |for main                    |

--- Comment #14 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 8.  I'm reluctant to backport this sort of change in behavior.
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [6/7 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

--- Comment #15 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Tue Apr 10 17:19:09 2018
New Revision: 259291

URL: https://gcc.gnu.org/viewcvs?rev=259291&root=gcc&view=rev
Log:
        PR debug/65821 - wrong location for main().

        * call.c (clear_location_r, convert_default_arg): Revert.
        * tree.c (break_out_target_exprs): Add clear_location parm.
        (struct bot_data): New.
        (bot_manip): Clear location if requested.
        * init.c (get_nsdmi): Pass clear_location.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/init.c
    trunk/gcc/cp/tree.c
Reply | Threaded
Open this post in threaded view
|

[Bug debug/65821] [6/7 regression] incorrect debug line # info for main

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65821

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|6.5                         |7.4

--- Comment #16 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 6 branch is being closed
12