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 -- Summary: Lines with 'break', 'goto', and 'continue' are not available for debugging. Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: seppo at totalviewtech dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37616