Open Source Support Tools
 
Search Item
 
Summary
  Reported Issue
Title: [gcc-37616] Lines with 'break', 'goto', and 'continue' are not available for debugging.
Project: gcc
Item Last Modified: Tue, 07 Oct 2008 19:01:10
Tags:  
 
 
4.1.2 Bug add adjust avoid basic blocks branch_prob breakpoint breakpoints cat cfg cfg_layout_merge_blocks com compilers configured cont convert edge edge_def emit explicitly fails fixed force_nonfallthru_and_redirect gcc gdb general glibc glibc-2.5 gnu goto host href insn int jakub jump library lines linux main make_goto_expr_edges move_block_to_fn namespace nop opcode optimization point print printf rel root rtl source special try_forward_edges txt type uname wrong x86_64
Details
[gcc-37616] Lines with 'break', 'goto', and 'continue' are not available for debugging.
Reporter:   seppo
Created:   Mon, 22 Sep 2008 17:15:00
Updated:   Tue, 07 Oct 2008 19:01:10
Key:   37616
Versions:   Not provided
Environment:  
Priority:   3
Status:   Resolved
Resolution:   Not provided
Original Link:   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37616
Summary:   Lines with 'break', 'goto', and 'continue' are not available for debugging.
Description:
Lines with 'break', 'goto', and 'continue' are not available for
debugging.

On GCC compilers, one can not set a breakpoint on lines with 'goto', 'break',
or
'continue' statements. This is incorrect, since these lines contain
user statements. Also, for example IBM XLC compilers on AIX 6.1 have
these lines available for setting breakpoints when debugging.

This fails both when using gdb and TotalView debugger.

The root problem seems to be that the GCC DWARF explicitly tells the
debugger to skip the lines in question.


> uname -a
Linux rhel52-x8664.totalviewtech.com 2.6.18-92.el5 #1 SMP Tue Apr 29 13:16:15
EDT 2008 x86_64 x86_64 x86_64 GNU/Linux
> cat /etc/*-rel*
cat: /etc/lsb-release.d: Is a directory
Red Hat Enterprise Linux Server release 5.2 (Tikanga)
> rpm -q glibc
glibc-2.5-24
glibc-2.5-24

g++ -g -O0 -v -o a_g_gcc.out e24018.cxx

gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)


totalview ./a_g_gcc.out

=> looking at the source code pane, we see that lines #12 (continue),
#14 (goto), and #16 (break) are not available for setting breakpoints.


How to reproduce using gdb:

> gdb a_g_gcc.out
GNU gdb Red Hat Linux (6.5-37.el5rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu"...Using host libthread_db
library "/lib64/libthread_db.so.1".

(gdb) break 12
Breakpoint 1 at 0x40071b: file e24018.cxx, line 12.
(gdb) run
Starting program: /nfs/netapp0/user/home/seppo/Bugs/Bug_11496/a_g_gcc.out

Breakpoint 1, main () at e24018.cxx:13
13 if (jj == 7)
(gdb) list
8
9 for (jj = 0; jj < 10; jj++)
10 {
11 if (jj == 5)
12 continue;
13 if (jj == 7)
14 goto exit;
15 if (jj == 9)
16 break;
17 mm = jj;
(gdb) print jj
$1 = 0
(gdb) cont
Continuing.

Breakpoint 1, main () at e24018.cxx:13
13 if (jj == 7)
(gdb) print jj
$2 = 1
(gdb)

=> notice how the debugger stopped at line #13, although the breakpoint
was set at line #12. Also the stopping happened at the wrong point in
execution, since jj=0 (and not jj=5, as the user wanted).

XXXXXXXXXXX Analysis:


readelf -wl ./a_g_gcc.out > ! readelf_gcc.txt

...
Set File Name to entry 1 in the File Name Table
Advance Line by -71 to 5
Special opcode 173: advance Address by 12 to 0x400704 and Line by 0 to 5
Special opcode 121: advance Address by 8 to 0x40070c and Line by 4 to 9
Special opcode 133: advance Address by 9 to 0x400715 and Line by 2 to 11
Special opcode 91: advance Address by 6 to 0x40071b and Line by 2 to 13
Special opcode 91: advance Address by 6 to 0x400721 and Line by 2 to 15
Special opcode 91: advance Address by 6 to 0x400727 and Line by 2 to 17
Advance Line by -8 to 9

=> notice how lines #12, 14, and #16 are skipped in DWARF


XXXXXXXXXXXXX reproducer
#include <iostream>

using namespace std;

int main()
{
int jj, mm;

for (jj = 0; jj < 10; jj++)
{
if (jj == 5)
continue;
if (jj == 7)
goto exit;
if (jj == 9)
break;
mm = jj;
}

exit:
printf("About to exit\n");

return(0);
}
XXXXXXXXXXXXXX
Comments:
Andrew Pinski Mon, 22 Sep 2008 19:39:00
Related to PR 29609.
Andrew Pinski Mon, 22 Sep 2008 19:44:00
Also related to PR 36690.
Jakub Jelinek Tue, 07 Oct 2008 18:50:00
Subject: Bug 37616

Author: jakub
Date: Tue Oct 7 18:48:40 2008
New Revision: 140948

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=140948
Log:
PR debug/29609
PR debug/36690
PR debug/37616
* basic-block.h (struct edge_def): Add goto_block field.
* cfglayout.c (fixup_reorder_chain): Ensure that there is at least
one insn with locus corresponding to edge's goto_locus if !optimize.
* profile.c (branch_prob): Copy edge's goto_block.
* cfgrtl.c (force_nonfallthru_and_redirect): Use goto_locus for
emitted jumps.
(cfg_layout_merge_blocks): Emit a nop with edge's goto_locus
locator in between the merged basic blocks if !optimize and needed.
* cfgexpand.c (expand_gimple_cond): Convert goto_block and
goto_locus into RTL locator. For unconditional jump use that
locator for the jump insn.
(expand_gimple_cond): Convert goto_block and goto_locus into
RTL locator for all remaining edges. For unconditional jump
use that locator for the jump insn.
* cfgcleanup.c (try_forward_edges): Avoid the optimization if
there is more than one edge or insn locator along the forwarding
edges and !optimize. If there is just one, set e->goto_locus.
* tree-cfg.c (make_cond_expr_edges, make_goto_expr_edges): Set also
edge's goto_block.
(move_block_to_fn): Adjust edge's goto_block.

* gcc.dg/debug/pr29609-1.c: New test.
* gcc.dg/debug/pr29609-2.c: New test.
* gcc.dg/debug/pr36690-1.c: New test.
* gcc.dg/debug/pr36690-2.c: New test.
* gcc.dg/debug/pr36690-3.c: New test.
* gcc.dg/debug/pr37616.c: New test.
* gcc.dg/debug/dwarf2/pr29609-1.c: New test.
* gcc.dg/debug/dwarf2/pr29609-2.c: New test.
* gcc.dg/debug/dwarf2/pr36690-1.c: New test.
* gcc.dg/debug/dwarf2/pr36690-2.c: New test.
* gcc.dg/debug/dwarf2/pr36690-3.c: New test.
* gcc.dg/debug/dwarf2/pr37616.c: New test.

Added:
trunk/gcc/testsuite/gcc.dg/debug/dwarf2/pr29609-1.c
trunk/gcc/testsuite/gcc.dg/debug/dwarf2/pr29609-2.c
trunk/gcc/testsuite/gcc.dg/debug/dwarf2/pr36690-1.c
trunk/gcc/testsuite/gcc.dg/debug/dwarf2/pr36690-2.c
trunk/gcc/testsuite/gcc.dg/debug/dwarf2/pr36690-3.c
trunk/gcc/testsuite/gcc.dg/debug/dwarf2/pr37616.c
trunk/gcc/testsuite/gcc.dg/debug/pr29609-1.c
trunk/gcc/testsuite/gcc.dg/debug/pr29609-2.c
trunk/gcc/testsuite/gcc.dg/debug/pr36690-1.c
trunk/gcc/testsuite/gcc.dg/debug/pr36690-2.c
trunk/gcc/testsuite/gcc.dg/debug/pr36690-3.c
trunk/gcc/testsuite/gcc.dg/debug/pr37616.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/basic-block.h
trunk/gcc/cfgcleanup.c
trunk/gcc/cfgexpand.c
trunk/gcc/cfglayout.c
trunk/gcc/cfgrtl.c
trunk/gcc/profile.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-cfg.c
Jakub Jelinek Tue, 07 Oct 2008 19:01:00
Fixed.