This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
-g -O debug-info problem (on x86)
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: -g -O debug-info problem (on x86)
- From: craig at jcb-sc dot com
- Date: 17 May 1999 04:57:20 -0000
- Cc: craig at jcb-sc dot com
I've been noticing a tendency that, when debugging, the program being
debugged can "slide" through the first executable statement after
hitting a breakpoint supposedly put on the *entry* to a routine, such
as main().
This is apparently due to some internal reorganizing of RTL (?) within
egcs (using the 19990502 snapshot) when optimizing.
Here's a sample test program:
--------
#include <stdio.h>
int
main()
{
{
printf ("hi\n");
printf ("there\n");
}
{
printf ("sailor!\n");
}
return 0;
}
--------
(The use of a compound (block) statement as the first executable statement
might be necessary to trigger the bug.)
Compiled with `-g' only, then debugged, `break main', `run', breaks
*before* the printing of "hi".
However, compiled with `-g -O' instead, the otherwise-same procedure
causes the break to be taken *after* the printing of "hi".
Here's the assembler code generated by `-g -O':
--------
.file "egcs3.c"
.version "01.01"
.stabs "/home3/craig/gnu/play/",100,0,0,.Ltext0
.stabs "egcs3.c",100,0,0,.Ltext0
.text
.Ltext0:
.stabs "gcc2_compiled.", 0x3c, 0, 0, 0
.stabs "int:t(0,1)=r(0,1);0020000000000;0017777777777;",128,0,0,0
.stabs "char:t(0,2)=r(0,2);0;127;",128,0,0,0
.stabs "long int:t(0,3)=r(0,1);0020000000000;0017777777777;",128,0,0,0
.stabs "unsigned int:t(0,4)=r(0,1);0000000000000;0037777777777;",128,0,0,0
.stabs "long unsigned int:t(0,5)=r(0,1);0000000000000;0037777777777;",128,0,0,0
.stabs "long long int:t(0,6)=r(0,1);01000000000000000000000;0777777777777777777777;",128,0,0,0
.stabs "long long unsigned int:t(0,7)=r(0,1);0000000000000;01777777777777777777777;",128,0,0,0
.stabs "short int:t(0,8)=r(0,8);-32768;32767;",128,0,0,0
.stabs "short unsigned int:t(0,9)=r(0,9);0;65535;",128,0,0,0
.stabs "signed char:t(0,10)=r(0,10);-128;127;",128,0,0,0
.stabs "unsigned char:t(0,11)=r(0,11);0;255;",128,0,0,0
.stabs "float:t(0,12)=r(0,1);4;0;",128,0,0,0
.stabs "double:t(0,13)=r(0,1);8;0;",128,0,0,0
.stabs "long double:t(0,14)=r(0,1);12;0;",128,0,0,0
.stabs "complex int:t(0,15)=s8real:(0,1),0,32;imag:(0,1),32,32;;",128,0,0,0
.stabs "complex float:t(0,16)=r(0,16);4;0;",128,0,0,0
.stabs "complex double:t(0,17)=r(0,17);8;0;",128,0,0,0
.stabs "complex long double:t(0,18)=r(0,18);12;0;",128,0,0,0
.stabs "void:t(0,19)=(0,19)",128,0,0,0
.stabs "/usr/include/stdio.h",130,0,0,0
.stabs "/usr/include/libio.h",130,0,0,0
.stabs "/usr/include/features.h",130,0,0,0
.stabs "/usr/include/sys/cdefs.h",130,0,0,0
.stabs "/usr/include/features.h",130,0,0,0
.stabn 162,0,0,0
.stabn 162,0,0,0
.stabs "/usr/include/gnu/stubs.h",130,0,0,0
.stabn 162,0,0,0
.stabn 162,0,0,0
.stabs "/usr/include/_G_config.h",130,0,0,0
.stabs "/develop/egcs/e/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.93.21/include/gnu/types.h",130,0,0,0
.stabs "/usr/include/gnu/types.h",130,0,0,0
.stabs "__u_char:t(9,1)=(0,11)",128,0,25,0
.stabs "__u_short:t(9,2)=(0,9)",128,0,26,0
.stabs "__u_int:t(9,3)=(0,4)",128,0,27,0
.stabs "__u_long:t(9,4)=(0,5)",128,0,28,0
.stabs "__u_quad_t:t(9,5)=(0,7)",128,0,30,0
.stabs "__quad_t:t(9,6)=(0,6)",128,0,31,0
.stabs "__qaddr_t:t(9,7)=(9,8)=*(9,6)",128,0,42,0
.stabs "__dev_t:t(9,9)=(9,5)",128,0,44,0
.stabs "__uid_t:t(9,10)=(9,3)",128,0,45,0
.stabs "__gid_t:t(9,11)=(9,3)",128,0,46,0
.stabs "__ino_t:t(9,12)=(9,4)",128,0,47,0
.stabs "__mode_t:t(9,13)=(9,3)",128,0,48,0
.stabs "__nlink_t:t(9,14)=(9,3)",128,0,49,0
.stabs "__off_t:t(9,15)=(0,3)",128,0,50,0
.stabs "__loff_t:t(9,16)=(9,6)",128,0,51,0
.stabs "__pid_t:t(9,17)=(0,1)",128,0,52,0
.stabs "__ssize_t:t(9,18)=(0,1)",128,0,53,0
.stabs "__fsid_t:t(9,19)=(9,20)=s8__val:(9,21)=ar(0,1);0;1;(0,1),0,64;;",128,0,58,0
.stabs "__daddr_t:t(9,22)=(0,1)",128,0,61,0
.stabs "__caddr_t:t(9,23)=(9,24)=*(0,2)",128,0,62,0
.stabs "__time_t:t(9,25)=(0,3)",128,0,63,0
.stabs "__swblk_t:t(9,26)=(0,3)",128,0,64,0
.stabs "__clock_t:t(9,27)=(0,3)",128,0,66,0
.stabs "__fd_mask:t(9,28)=(0,5)",128,0,69,0
.stabs "__fd_set:t(9,29)=(9,30)=s128fds_bits:(9,31)=ar(0,1);0;31;(9,28),0,1024;;",128,0,84,0
.stabs "__key_t:t(9,32)=(0,1)",128,0,87,0
.stabs "__ipc_pid_t:t(9,33)=(0,9)",128,0,89,0
.stabn 162,0,0,0
.stabn 162,0,0,0
.stabs "/develop/egcs/e/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.93.21/include/stddef.h",130,0,0,0
.stabs "size_t:t(10,1)=(0,4)",128,0,170,0
.stabs "wint_t:t(10,2)=(0,4)",128,0,280,0
.stabn 162,0,0,0
.stabs "_G_int16_t:t(7,1)=(0,8)",128,0,30,0
.stabs "_G_int32_t:t(7,2)=(0,1)",128,0,31,0
.stabs "_G_uint16_t:t(7,3)=(0,9)",128,0,32,0
.stabs "_G_uint32_t:t(7,4)=(0,4)",128,0,33,0
.stabn 162,0,0,0
.stabs "/develop/egcs/e/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.93.21/include/stdarg.h",130,0,0,0
.stabs "__gnuc_va_list:t(11,1)=(11,2)=*(0,19)",128,0,73,0
.stabn 162,0,0,0
.stabs "_IO_lock_t:t(2,1)=(0,19)",128,0,160,0
.stabs "_IO_marker:T(2,2)=s12_next:(2,3)=*(2,2),0,32;_sbuf:(2,4)=*(2,5)=xs_IO_FILE:,32,32;_pos:(0,1),64,32;;",128,0,0,0
.stabs "_IO_FILE:T(2,5)=s76_flags:(0,1),0,32;_IO_read_ptr:(9,24),32,32;_IO_read_end:(9,24),64,32;_IO_read_base:(9,24),96,32;_IO_write_base:(9,24),128,32;_IO_write_ptr:(9,24),160,32;_IO_write_end:(9,24),192,32;_IO_buf_base:(9,24),224,32;_IO_buf_end:(9,24),256,32;_IO_save_base:(9,24),288,32;_IO_backup_base:(9,24),320,32;_IO_save_end:(9,24),352,32;_markers:(2,3),384,32;_chain:(2,4),416,32;_fileno:(0,1),448,32;_blksize:(0,1),480,32;_offset:(9,15),512,32;_cur_column:(0,9),544,16;_unused:(0,2),560,8;_shortbuf:(2,6)=ar(0,1);0;0;(0,2),568,8;_lock:(2,7)=*(2,1),576,32;;",128,0,0,0
.stabs "_IO_FILE:t(2,8)=(2,5)",128,0,224,0
.stabs "_IO_cookie_io_functions_t:t(2,9)=(2,10)=s16read:(2,11)=*(2,12)=f(9,18),0,32;write:(2,13)=*(2,14)=f(9,18),32,32;seek:(2,15)=*(2,16)=f(9,15),64,32;close:(2,17)=*(2,18)=f(0,1),96,32;;",128,0,241,0
.stabs "_IO_cookie_file:T(2,19)=s100file:(2,5),0,608;vtable:(2,20)=*(0,19),608,32;cookie:(11,2),640,32;io_functions:(2,9),672,128;;",128,0,0,0
.stabn 162,0,0,0
.stabs "FILE:t(1,1)=(2,5)",128,0,71,0
.stabs "fpos_t:t(1,2)=(9,15)",128,0,72,0
.stabs "/usr/include/stdio_lim.h",130,0,0,0
.stabn 162,0,0,0
.stabn 162,0,0,0
.section .rodata
.LC0:
.string "hi\n"
.LC1:
.string "there\n"
.LC2:
.string "sailor!\n"
.text
.align 4
.stabs "main:F(0,1)",36,0,5,main
.globl main
.type main,@function
main:
.stabn 68,0,5,.LM1-main
.LM1:
.stabn 68,0,7,.LM2-main
.LM2:
pushl %ebp
movl %esp,%ebp
subl $8,%esp
addl $-12,%esp
pushl $.LC0
call printf
.stabn 68,0,8,.LM3-main
.LM3:
addl $-12,%esp
pushl $.LC1
call printf
.stabn 68,0,11,.LM4-main
.LM4:
addl $32,%esp
addl $-12,%esp
pushl $.LC2
call printf
.stabn 68,0,13,.LM5-main
.LM5:
xorl %eax,%eax
movl %ebp,%esp
popl %ebp
ret
.stabn 68,0,14,.LM6-main
.LM6:
.Lfe1:
.size main,.Lfe1-main
.Lscope0:
.stabs "",36,0,0,.Lscope0-main
.text
.stabs "",100,0,0,Letext
Letext:
.ident "GCC: (GNU) egcs-2.93.21 19990515 (gcc2 ss-980929 experimental)"
--------
I believe the lines reading
.stabn 68,0,7,.LM2-main
.LM2:
should be located three lines (or so) *below* where they are above.
When they're moved accordingly, the breakpoint seems to occur before
the printing of "hi", as appropriate.
This bug does not appear to be in egcs 1.1.2. It also affects g77,
so I'm hoping it's found and fixed in a language-independent fashion
(i.e. not via some quick-fix to the gcc front end). This is the
Fortran case I first started working on, before figuring out the need
for a compound statement to reproduce it in C:
--------
print *, 'hi'
print *, 'there'
end
--------
tq vm, (burley)