Bug 86675 - C++ lambdas are not debugable with -std=c++17 (or above) and -Og
Summary: C++ lambdas are not debugable with -std=c++17 (or above) and -Og
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 8.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, wrong-debug
Depends on:
Blocks: ohgee lambdas
  Show dependency treegraph
 
Reported: 2018-07-25 14:59 UTC by Bernd Amend
Modified: 2022-03-11 00:32 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-08-07 00:00:00


Attachments
Example program (52 bytes, text/plain)
2018-07-25 14:59 UTC, Bernd Amend
Details
Script to test the compiler with different command line args (227 bytes, application/x-shellscript)
2018-07-25 15:01 UTC, Bernd Amend
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bernd Amend 2018-07-25 14:59:14 UTC
Created attachment 44440 [details]
Example program

If I compile the attached (main.cpp) test program
  int main() {
	return [] {
		return 000031415;
	}();
  }

with the following options I'm unable to debug it
  g++ main.cpp -std=c++17 -g -Og
  g++ main.cpp -std=c++2a -g -Og

using the following compile options debugging works as expected
  g++ main.cpp -std=c++17 -g -O0
  g++ main.cpp -std=c++2a -g -O0
  g++ main.cpp -std=c++11 -g -Og
  g++ main.cpp -std=c++14 -g -Og
  g++ main.cpp -std=c++14 -g -Og

The attached script test.sh reports the following
Success: Standard c++11 Optimization 0
Success: Standard c++14 Optimization 0
Success: Standard c++17 Optimization 0
Success: Standard c++2a Optimization 0
Success: Standard c++11 Optimization g
Success: Standard c++14 Optimization g
Failed: Standard c++17 Optimization g
Failed: Standard c++2a Optimization g

Systems used: Archlinux (last updated 2018-07-25)
g++ -v
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/8.1.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp
Thread model: posix
gcc version 8.1.1 20180531 (GCC)
Comment 1 Bernd Amend 2018-07-25 15:01:03 UTC
Created attachment 44441 [details]
Script to test the compiler with different command line args
Comment 2 Jonathan Wakely 2019-08-07 10:57:28 UTC
Confirmed. With -std=gnu++17 the breakpoint on line 3 (the return statement inside the lambda expression) actually breaks on line 2:

Breakpoint 1, main () at 86675.cc:2
2               return [] {
Comment 3 Jonathan Wakely 2019-08-07 11:09:38 UTC
cat >86675.cc <<EOT
  int main() {
	return [] {
		return 000031415;
	}();
  }
EOT

cat >cmds <<EOT
br main:3
run
step
cont
quit
EOT

g++ 86675.cc -g -Og -std=c++14
gdb -q -x cmds ./a.out 2>/dev/null | grep return

g++ 86675.cc -g -Og -std=c++17
gdb -q -x cmds ./a.out 2>/dev/null | grep return



The first GDB session breaks at:

3       return 000031415;

The second at:

2       return [] {