Bug 107154 - [12 Regression] GDB jumping to end of block when stepping over construction of local variable
Summary: [12 Regression] GDB jumping to end of block when stepping over construction o...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 12.2.1
: P2 normal
Target Milestone: 12.3
Assignee: Jason Merrill
URL:
Keywords: wrong-debug
Depends on:
Blocks:
 
Reported: 2022-10-04 20:43 UTC by Jonathan Wakely
Modified: 2024-11-08 18:25 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 11.3.1, 13.0
Known to fail: 12.1.0, 12.2.0
Last reconfirmed: 2022-10-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2022-10-04 20:43:35 UTC
#include <initializer_list>
#include <string>

struct X {
  X(std::initializer_list<std::string>, int) { }
};

int main()
{
  X x( {"", "", "", ""}, 1|4 );
  return 0;
}

tmp$ g++ -g debug.C -o debug
tmp$ gdb -q debug
Reading symbols from debug...
(gdb) start
Temporary breakpoint 1 at 0x40123a: file debug.C, line 12.
Starting program: /tmp/debug 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Temporary breakpoint 1, main () at debug.C:12
12      }
(gdb) n
10        X x( {"", "", "", ""}, 1|4 );
(gdb) 
12      }
(gdb) 
11        return 0;
(gdb) 
__libc_start_call_main (main=main@entry=0x401226 <main()>, argc=argc@entry=1, argv=argv@entry=0x7fffffffd7a8) at ../sysdeps/nptl/libc_start_call_main.h:74
74        exit (result);
(gdb) 
[Inferior 1 (process 577012) exited normally]


Why does "start" break on the closing brace of main(), and then the construction of 'x' also jumps to the closing brace?

In less trivial examples I've seen it jump back and forth multiple times:

243             libmap libs;
(gdb) n
245       redi::ipstream in({"ldd", argv[arg]}, pstdout|pstderr);
(gdb) 
310     }
(gdb) 
245       redi::ipstream in({"ldd", argv[arg]}, pstdout|pstderr);
(gdb) 
310     }
(gdb) 
245       redi::ipstream in({"ldd", argv[arg]}, pstdout|pstderr);
(gdb) 
[Detaching after fork from child process 845854]
310     }
(gdb)
Comment 1 Jonathan Wakely 2022-10-04 20:44:21 UTC
This is with the Fedora packages but I see it with GCC trunk too.

$ rpm -q gcc gdb
gcc-12.2.1-2.fc36.x86_64
gdb-12.1-1.fc36.x86_64
Comment 2 Andrew Pinski 2022-10-04 20:44:48 UTC
I think there is another bug about this one ...
Comment 3 Jonathan Wakely 2022-10-04 21:01:04 UTC
It started with r12-6329

 c++: EH and partially constructed aggr temp [PR66139]
Comment 4 GCC Commits 2022-10-04 22:54:13 UTC
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:ce3a1b5976079b1467473b4628f05797fd2eae08

commit r13-3072-gce3a1b5976079b1467473b4628f05797fd2eae08
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Oct 4 17:06:04 2022 -0400

    c++: fix debug info for array temporary [PR107154]
    
    In the testcase the elaboration of the array init that happens at genericize
    time was getting the location info for the end of the function; fixed by
    doing the expansion at the location of the original expression.
    
            PR c++/107154
    
    gcc/cp/ChangeLog:
    
            * cp-gimplify.cc (cp_genericize_init_expr): Use iloc_sentinel.
            (cp_genericize_target_expr): Likewise.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/debug/dwarf2/lineno-array1.C: New test.
Comment 5 GCC Commits 2023-04-18 20:45:30 UTC
The releases/gcc-12 branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:2088358b658c44f69d37af0d7deec321f557741d

commit r12-9430-g2088358b658c44f69d37af0d7deec321f557741d
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Oct 4 17:06:04 2022 -0400

    c++: fix debug info for array temporary [PR107154]
    
    In the testcase the elaboration of the array init that happens at genericize
    time was getting the location info for the end of the function; fixed by
    doing the expansion at the location of the original expression.
    
            PR c++/107154
    
    gcc/cp/ChangeLog:
    
            * cp-gimplify.cc (cp_genericize_init_expr): Use iloc_sentinel.
            (cp_genericize_target_expr): Likewise.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/debug/dwarf2/lineno-array1.C: New test.
Comment 6 Jason Merrill 2023-04-18 20:47:13 UTC
Fixed for 12.3/13.