public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/106399] New: Wrong debug info for function with nested function under O0
@ 2022-07-22  5:33 liyd2021 at gmail dot com
  2022-07-22  7:19 ` [Bug debug/106399] [10/11/12/13 Regression] " rguenth at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: liyd2021 at gmail dot com @ 2022-07-22  5:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106399

            Bug ID: 106399
           Summary: Wrong debug info for function with nested function
                    under O0
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: liyd2021 at gmail dot com
  Target Milestone: ---

Affected versions:  gcc 11.1.0 (Ubuntu 20.04.2), since gcc 9

The debugger print `a` with a uninitialized value while `a` should be 3 at the
breakpoint.

(terminal) $ cat a.c && gcc -g -OO a.c
int foo(int a)
{
        int a2()
        {
                return a * a;
        }
        return a2();
}

int main()
{
        return foo(3) - 9;
}

--------------------

(terminal) $ gdb a.out
(gdb) b foo
Breakpoint 1 at 0x401188: file a.c, line 1.
(gdb) r
Breakpoint 1, foo (a=0) at a.c:1   <- **BUG**: a should be 3
1       int foo(int a)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug debug/106399] [10/11/12/13 Regression] Wrong debug info for function with nested function under O0
  2022-07-22  5:33 [Bug debug/106399] New: Wrong debug info for function with nested function under O0 liyd2021 at gmail dot com
@ 2022-07-22  7:19 ` rguenth at gcc dot gnu.org
  2022-07-22 10:10 ` [Bug debug/106399] [10/11/12/13 Regression] Wrong debug info for function with nested function under O0 since r9-1284-gd70ba0c10dec6968 marxin at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-07-22  7:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106399

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |10.4.0, 11.3.0, 12.1.0,
                   |                            |9.5.0
   Last reconfirmed|                            |2022-07-22
            Summary|Wrong debug info for        |[10/11/12/13 Regression]
                   |function with nested        |Wrong debug info for
                   |function under O0           |function with nested
                   |                            |function under O0
   Target Milestone|---                         |10.5
     Ever confirmed|0                           |1
      Known to work|                            |7.5.0, 8.4.0
           Keywords|                            |needs-bisection,
                   |                            |wrong-debug
           Priority|P3                          |P2
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  It works with -O -fno-inline, it also worked at some point.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug debug/106399] [10/11/12/13 Regression] Wrong debug info for function with nested function under O0 since r9-1284-gd70ba0c10dec6968
  2022-07-22  5:33 [Bug debug/106399] New: Wrong debug info for function with nested function under O0 liyd2021 at gmail dot com
  2022-07-22  7:19 ` [Bug debug/106399] [10/11/12/13 Regression] " rguenth at gcc dot gnu.org
@ 2022-07-22 10:10 ` marxin at gcc dot gnu.org
  2022-07-22 12:31 ` ebotcazou at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-07-22 10:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106399

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ebotcazou at gcc dot gnu.org,
                   |                            |marxin at gcc dot gnu.org
            Summary|[10/11/12/13 Regression]    |[10/11/12/13 Regression]
                   |Wrong debug info for        |Wrong debug info for
                   |function with nested        |function with nested
                   |function under O0           |function under O0 since
                   |                            |r9-1284-gd70ba0c10dec6968
           Keywords|needs-bisection             |

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r9-1284-gd70ba0c10dec6968.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug debug/106399] [10/11/12/13 Regression] Wrong debug info for function with nested function under O0 since r9-1284-gd70ba0c10dec6968
  2022-07-22  5:33 [Bug debug/106399] New: Wrong debug info for function with nested function under O0 liyd2021 at gmail dot com
  2022-07-22  7:19 ` [Bug debug/106399] [10/11/12/13 Regression] " rguenth at gcc dot gnu.org
  2022-07-22 10:10 ` [Bug debug/106399] [10/11/12/13 Regression] Wrong debug info for function with nested function under O0 since r9-1284-gd70ba0c10dec6968 marxin at gcc dot gnu.org
@ 2022-07-22 12:31 ` ebotcazou at gcc dot gnu.org
  2022-07-28 17:47 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2022-07-22 12:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106399

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |WAITING

--- Comment #3 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Which version of GDB?  Can you try with a more recent one?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug debug/106399] [10/11/12/13 Regression] Wrong debug info for function with nested function under O0 since r9-1284-gd70ba0c10dec6968
  2022-07-22  5:33 [Bug debug/106399] New: Wrong debug info for function with nested function under O0 liyd2021 at gmail dot com
                   ` (2 preceding siblings ...)
  2022-07-22 12:31 ` ebotcazou at gcc dot gnu.org
@ 2022-07-28 17:47 ` jakub at gcc dot gnu.org
  2022-07-29  8:44 ` ebotcazou at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-07-28 17:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106399

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I can reproduce it, but it was actually wrong-debug before that case.

Consider:
void baz (void) {}
int foo(int a)
{
  int a2 (void)
  {
    a++;
    return a * a;
  }
  baz ();
  int x = a2 ();
  baz ();
  return x;
}

int main ()
{
  return foo (3) - 16;
}

As a is used by nested function, what we actually compile this into (at -O0)
is:
  _3 = __builtin_dwarf_cfa (0);
  FRAME.0.FRAME_BASE.PARENT = _3;
  FRAME.0.a = a_5(D);
  baz ();
  x_9 = a2 (); [static-chain: &FRAME.0]
  baz ();
  _11 = x_9;
  return _11;
Where FRAME.0 is an artificial structure that contains some pointer and the a
parameter.
For -O0, there are 2 copies of a in the foo function's stack.  One is that
holds 
the a_5(D) SSA_NAME, i.e. the value of the argument that was passed to the
function.  And then inside of the FRAME.0 artificial var there is another copy
of it.
Before Eric's change (i.e. GCC 8 and earlier), the former has been declared as
the location holding a in debug info, while after it it is the FRAME.0.a
member.
The former is incorrect, if you put a breakpoint say on the line with second
call to baz () when compiled by GCC 8 and print a, it will print 3, even when a
is actually 4 (a2 has incremented it).
The latter is correct, but it is initialized slightly later.  At -O0 we don't
do (expensive) variable tracking, so we just indicate a single memory location
for the parameter in debug info.  So, unless we there enable the var tracking
too,
we would need to arrange for the breakpoint on foo to be added not just after
the normal prologue, but also after initialization of the FRAME.0 variable.
If you in the debugger stepi a few times or just step, you'll see correct value
of a eventually.
E.g. with current trunk, the foo assembly starts with:
        pushq   %rbp
        movq    %rsp, %rbp
        subq    $48, %rsp
        movl    %edi, -36(%rbp)
        leaq    16(%rbp), %rax
        movq    %rax, -24(%rbp)
        movl    -36(%rbp), %eax
        movl    %eax, -32(%rbp)
        call    baz
and breakpoint on foo is put by the debugger after the movl %edi, -36(%rbp)
instruction, so after the a parameter is stored from %edi register into the
first stack location.  FRAME.0 is at %rbp - 24, so the stores to it are only
completed right before call baz.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug debug/106399] [10/11/12/13 Regression] Wrong debug info for function with nested function under O0 since r9-1284-gd70ba0c10dec6968
  2022-07-22  5:33 [Bug debug/106399] New: Wrong debug info for function with nested function under O0 liyd2021 at gmail dot com
                   ` (3 preceding siblings ...)
  2022-07-28 17:47 ` jakub at gcc dot gnu.org
@ 2022-07-29  8:44 ` ebotcazou at gcc dot gnu.org
  2022-07-29  8:45 ` ebotcazou at gcc dot gnu.org
  2023-07-07 10:43 ` [Bug debug/106399] [11/12/13/14 " rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2022-07-29  8:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106399

--- Comment #5 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
This is an equivalent Ada testcase:

function Foo (A: Integer) return Integer is

  function A2 return Integer is (A * A);

begin
  return A2;
end;

with the same issue.  We have been using the to-be-attached patch for years to
solve the problem, but it does not seem to work for the C compiler because the
prologue_location points to '{' instead of the function declarator.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug debug/106399] [10/11/12/13 Regression] Wrong debug info for function with nested function under O0 since r9-1284-gd70ba0c10dec6968
  2022-07-22  5:33 [Bug debug/106399] New: Wrong debug info for function with nested function under O0 liyd2021 at gmail dot com
                   ` (4 preceding siblings ...)
  2022-07-29  8:44 ` ebotcazou at gcc dot gnu.org
@ 2022-07-29  8:45 ` ebotcazou at gcc dot gnu.org
  2023-07-07 10:43 ` [Bug debug/106399] [11/12/13/14 " rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2022-07-29  8:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106399

--- Comment #6 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Created attachment 53380
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53380&action=edit
Incomplete fix

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug debug/106399] [11/12/13/14 Regression] Wrong debug info for function with nested function under O0 since r9-1284-gd70ba0c10dec6968
  2022-07-22  5:33 [Bug debug/106399] New: Wrong debug info for function with nested function under O0 liyd2021 at gmail dot com
                   ` (5 preceding siblings ...)
  2022-07-29  8:45 ` ebotcazou at gcc dot gnu.org
@ 2023-07-07 10:43 ` rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106399

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-07-07 10:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-22  5:33 [Bug debug/106399] New: Wrong debug info for function with nested function under O0 liyd2021 at gmail dot com
2022-07-22  7:19 ` [Bug debug/106399] [10/11/12/13 Regression] " rguenth at gcc dot gnu.org
2022-07-22 10:10 ` [Bug debug/106399] [10/11/12/13 Regression] Wrong debug info for function with nested function under O0 since r9-1284-gd70ba0c10dec6968 marxin at gcc dot gnu.org
2022-07-22 12:31 ` ebotcazou at gcc dot gnu.org
2022-07-28 17:47 ` jakub at gcc dot gnu.org
2022-07-29  8:44 ` ebotcazou at gcc dot gnu.org
2022-07-29  8:45 ` ebotcazou at gcc dot gnu.org
2023-07-07 10:43 ` [Bug debug/106399] [11/12/13/14 " rguenth at gcc dot gnu.org

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).