Bug 1325396

Summary: gdb cannot debug local variables inside c++ lambdas
Product: Red Hat Enterprise Linux 7 Reporter: Jacob Hunt <jhunt>
Component: gdbAssignee: Jan Kratochvil <jan.kratochvil>
Status: CLOSED ERRATA QA Contact: Martin Cermak <mcermak>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.2CC: gdb-bugs, jan.kratochvil, mcermak, ohudlick, sergiodj
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: gdb-7.6.1-92.el7 Doc Type: Bug Fix
Doc Text:
Cause: With a code produced by RHEL-7.3 GCC being debugged by GDB the debugger does not see local variables in C++ lambda functions. This happens even for code compiled without optimizations (gcc -O0 -g). Consequence: User cannot display content of such variables. Fix: GDB now properly recognizes debug information (DWARF (debugging data format) DIE (Debug Information Entry) DW_TAG_lexical_block with no attributes) as produced by RHEL-7.3 GCC. Result: User can now display (or even modify) local variables in C++ lambda functions.
Story Points: ---
Clone Of:
: 1357079 (view as bug list) Environment:
Last Closed: 2016-11-04 03:50:54 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On:    
Bug Blocks: 1357079    

Description Jacob Hunt 2016-04-08 17:12:25 UTC
Description of problem:

Stock g++ and gdb from RHEL 7. The example program from the upstream bug report linked below demonstrates the issue succinctly. The local "x" variable is not visible in any of the stack frames from within gdb.

Version-Release number of selected component (if applicable):

gcc-c++-4.8.5-4.el7.x86_64
gdb-7.6.1-80.el7.x86_64

How reproducible:

100 %

Steps to Reproduce:
1. See https://sourceware.org/bugzilla/show_bug.cgi?id=15231 for reproducer

Additional info:

upstream bug https://sourceware.org/bugzilla/show_bug.cgi?id=15231

Comment 1 Jan Kratochvil 2016-04-21 21:27:23 UTC
PASS: gcc-6.0.0-0.20.fc24.x86_64
FAIL: gcc-5.3.1-6.fc23.x86_64
Tested with gdb-7.10.1-31.fc23.x86_64 and even more recent GDBs.

gcc-5.3.1 did generate dummy DW_TAG_lexical_block:

 <2><92>: Abbrev Number: 11 (DW_TAG_lexical_block)
 <3><93>: Abbrev Number: 12 (DW_TAG_variable)

GDB stops at that die <92> and it does not inherit DIE <93>.
read_lexical_block_scope()
  /* Ignore blocks with missing or invalid low and high pc attributes.  */
[...]
  if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
    return;

GDB probably could just ignore empty DW_TAG_lexical_block and just recursively process its DIEs.

Asking GCC whether it should be fixed on GCC or GDB side.

More info in the upstream GDB PR.

Comment 2 Jakub Jelinek 2016-05-10 14:07:52 UTC
This changed with http://gcc.gnu.org/r224161, which is not backportable.

Comment 3 Jan Kratochvil 2016-05-14 17:51:56 UTC
OK, thanks for the evaluation.  Therefore going to make GDB interpreting bare DW_TAG_lexical_block's children as if there was no DW_TAG_lexical_block there.

Comment 4 Jan Kratochvil 2016-05-14 19:31:24 UTC
[patch] PR 15231: import bare DW_TAG_lexical_block
https://sourceware.org/ml/gdb-patches/2016-05/msg00236.html

Comment 5 Jan Kratochvil 2016-05-14 19:32:06 UTC
QA: New testfile: gdb.dwarf2/dw2-lexical-block-bare.exp

Comment 6 Jan Kratochvil 2016-05-14 19:33:07 UTC
QA: additionally it does: XFAIL->PASS: gdb.ada/out_of_line_in_inlined.exp
(as it would XFAIL->XPASS without removing that setup_xfail by this patch)

Comment 12 Jan Kratochvil 2016-09-20 16:27:47 UTC
I do not see why this Bug should be private for RH employees only.

Comment 14 errata-xmlrpc 2016-11-04 03:50:54 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2016-2328.html