stabs line number incorrect

Richard Sharman richard_sharman@Mitel.COM
Sun Feb 20 17:27:00 GMT 2000


This example shows incorrect stabs line number information.
There are 2 statements with a call to the CHECK macro.
The stabs line number does not point at the beginning of the
statement,  thus we cannot put a breakpoint at the start of 
the statement.

This can be seen by trying to put breakpoints on both statements
that contain calls to the CHECK macro (Lines 16 and 210).
Neither breakpoint is in the right place,  it gets put on the call to
nil_ptr() which does not occur on the first but does on the second.

% cat -n x.c
     1	#include <stdio.h>
     2	void nil_ptr() {
     3	  fprintf(stderr, "nil pointer!\n");
     4	  exit(1);
     5	}
     6	
     7	#define CHECK(p) (*( p ? : ({ nil_ptr();p; }) ))
     8	
     9	int main()
    10	{
    11	  int i;
    12	  int j;
    13	  int  *p = &i;
    14	
    15	  i= 99;
    16	  j = CHECK(p);
    17	  printf("%d\n", j);
    18	
    19	  p = NULL;
    20	
    21	  j = CHECK(p);
    22	  printf("%d\n", j);
    23	
    24	  exit(0);
    25	}
% gcc -g -o x x.c
% ./x
99
nil pointer!
% gdb x
GNU gdb 4.18 - Local  Jun 24 1999 17:14:45
Copyright 1998 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 "sparc-sun-solaris2.6"...
(gdb) set listsize 7
(gdb) l 18
15	  i= 99;
16	  j = CHECK(p);
17	  printf("%d\n", j);
18	
19	  p = NULL;
20	
21	  j = CHECK(p);
(gdb) b 16
Breakpoint 1 at 0x1097c: file x.c, line 16.
(gdb) b 21
Breakpoint 2 at 0x109c4: file x.c, line 21.
(gdb) c
The program is not being run.
(gdb) r
Starting program: /home/tools/sharman/mpascal/frontend/x 
99

Breakpoint 2, main () at x.c:21
21	  j = CHECK(p);
(gdb) c
Continuing.
nil pointer!

Program exited with code 01.
(gdb) info b
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x0001097c in main at x.c:16
2   breakpoint     keep y   0x000109c4 in main at x.c:21
	breakpoint already hit 1 time
(gdb) disas 0x0001097c-0x20 0x0001097c+0x20
Dump of assembler code from 0x1095c to 0x1099c:
0x1095c <main+4>:	add  %fp, -20, %o0
0x10960 <main+8>:	st  %o0, [ %fp + -28 ]
0x10964 <main+12>:	mov  0x63, %o0
0x10968 <main+16>:	st  %o0, [ %fp + -20 ]
0x1096c <main+20>:	ld  [ %fp + -28 ], %l0   <-- should be here
0x10970 <main+24>:	cmp  %l0, 0
0x10974 <main+28>:	bne  0x10990 <main+56>
0x10978 <main+32>:	nop 
0x1097c <main+36>:	call  0x10928 <nil_ptr>    <--- not here
0x10980 <main+40>:	nop 
0x10984 <main+44>:	ld  [ %fp + -28 ], %o0
0x10988 <main+48>:	b  0x10994 <main+60>
0x1098c <main+52>:	nop 
0x10990 <main+56>:	mov  %l0, %o0
0x10994 <main+60>:	ld  [ %o0 ], %o0
0x10998 <main+64>:	st  %o0, [ %fp + -24 ]
End of assembler dump.
(gdb) % 
% gcc -S -g x.c
% cat x.s
	.file	"x.c"
.stabs "/home/tools/sharman/mpascal/frontend/",100,0,0,.LLtext0
.stabs "x.c",100,0,0,.LLtext0
.section	".text"
.LLtext0:
	.stabs	"gcc2_compiled.", 0x3c, 0, 0, 0
.stabs "int:t(0,1)=r(0,1);-2147483648;2147483647;",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,3);-2147483648;2147483647;",128,0,0,0
.stabs "unsigned int:t(0,4)=r(0,4);0;-1;",128,0,0,0
.stabs "long unsigned int:t(0,5)=r(0,5);0;-1;",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);16;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);16;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/sys/feature_tests.h",130,0,0,0
.stabn 162,0,0,0
.stabs "/usr/include/sys/va_list.h",130,0,0,0
.stabs "__va_list:t(3,1)=(3,2)=*(0,19)",128,0,44,0
.stabn 162,0,0,0
.stabs "size_t:t(1,1)=(0,4)",128,0,34,0
.stabs "__longlong_t:t(1,2)=(0,6)",128,0,44,0
.stabs "off_t:t(1,3)=(0,3)",128,0,58,0
.stabs "off64_t:t(1,4)=(1,2)",128,0,63,0
.stabs "fpos_t:t(1,5)=(0,3)",128,0,69,0
.stabs "fpos64_t:t(1,6)=(1,2)",128,0,74,0
.stabs "FILE:t(1,7)=(1,8)=s16_cnt:(0,1),0,32;_ptr:(1,9)=*(0,11),32,32;_base:(1,9),64,32;_flag:(0,11),96,8;_file:(0,11),104,8;;",128,0,186,0
.stabn 162,0,0,0
.section	".rodata"
	.align 8
.LLC0:
	.asciz	"nil pointer!\n"
.section	".text"
	.align 4
.stabs "nil_ptr:F(0,19)",36,0,2,nil_ptr
	.global nil_ptr
	.type	 nil_ptr,#function
	.proc	020
nil_ptr:
.stabn 68,0,2,.LM1-nil_ptr
.LM1:
	!#PROLOGUE# 0
	save %sp,-112,%sp
	!#PROLOGUE# 1
.stabn 68,0,3,.LM2-nil_ptr
.LM2:
	sethi %hi(__iob+32),%o1
	or %o1,%lo(__iob+32),%o0
	sethi %hi(.LLC0),%o2
	or %o2,%lo(.LLC0),%o1
	call fprintf,0
	nop
.stabn 68,0,4,.LM3-nil_ptr
.LM3:
	mov 1,%o0
	call exit,0
	nop
.stabn 68,0,5,.LM4-nil_ptr
.LM4:
.LL1:
	ret
	restore
.LLfe1:
	.size	 nil_ptr,.LLfe1-nil_ptr
.LLscope0:
.stabs "",36,0,0,.LLscope0-nil_ptr
.section	".rodata"
	.align 8
.LLC1:
	.asciz	"%d\n"
.section	".text"
	.align 4
.stabs "main:F(0,1)",36,0,10,main
	.global main
	.type	 main,#function
	.proc	04
main:
.stabn 68,0,10,.LM5-main
.LM5:
	!#PROLOGUE# 0
	save %sp,-128,%sp
	!#PROLOGUE# 1
.stabn 68,0,11,.LM6-main
.LM6:
.LLBB2:
.stabn 68,0,13,.LM7-main
.LM7:
	add %fp,-20,%o0
	st %o0,[%fp-28]
.stabn 68,0,15,.LM8-main
.LM8:
	mov 99,%o0
	st %o0,[%fp-20]
	ld [%fp-28],%l0		<-- the real start of line 16
	cmp %l0,0
	bne .LL3
	nop
.stabn 68,0,16,.LM9-main
.LM9:
.LLBB3:
	call nil_ptr,0
	nop
.LLBE3:
	ld [%fp-28],%o0
	b .LL4
	nop
.LL3:
	mov %l0,%o0
.LL4:
	ld [%o0],%o0
	st %o0,[%fp-24]
.stabn 68,0,17,.LM10-main
.LM10:
	sethi %hi(.LLC1),%o1
	or %o1,%lo(.LLC1),%o0
	ld [%fp-24],%o1
	call printf,0
	nop
.stabn 68,0,19,.LM11-main
.LM11:
	st %g0,[%fp-28]
	ld [%fp-28],%l1		<--- the real start of line 21
	cmp %l1,0
	bne .LL5
	nop
.stabn 68,0,21,.LM12-main
.LM12:
.LLBB4:
	call nil_ptr,0
	nop
.LLBE4:
	ld [%fp-28],%o0
	b .LL6
	nop
.LL5:
	mov %l1,%o0
.LL6:
	ld [%o0],%o0
	st %o0,[%fp-24]
.stabn 68,0,22,.LM13-main
.LM13:
	sethi %hi(.LLC1),%o1
	or %o1,%lo(.LLC1),%o0
	ld [%fp-24],%o1
	call printf,0
	nop
.stabn 68,0,24,.LM14-main
.LM14:
	mov 0,%o0
	call exit,0
	nop
.stabn 68,0,25,.LM15-main
.LM15:
.LLBE2:
.stabn 68,0,25,.LM16-main
.LM16:
.LL2:
	ret
	restore
.LLfe2:
	.size	 main,.LLfe2-main
.stabs "i:(0,1)",128,0,11,-20
.stabs "j:(0,1)",128,0,12,-24
.stabs "p:(0,20)=*(0,1)",128,0,13,-28
.stabn 192,0,0,.LLBB2-main
.stabn 192,0,0,.LLBB3-main
.stabn 224,0,0,.LLBE3-main
.stabn 192,0,0,.LLBB4-main
.stabn 224,0,0,.LLBE4-main
.stabn 224,0,0,.LLBE2-main
.LLscope1:
.stabs "",36,0,0,.LLscope1-main
	.stabs "",100,0,0,.Letext
.Letext:
	.ident	"GCC: (GNU) 2.8.1"
% 

This was 2.8.1 under sunos 5.6.

egcs-gcc showed the same behaviour

% egcs-gcc -v
Reading specs from /usr/tools/egcs/sparc-solaris/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
% egcs-gcc -s -g x.c
% 

.stabn 68,0,15,.LM8-main
.LM8:
	mov 99,%o0
	st %o0,[%fp-20]
	ld [%fp-28],%l0		<-- stabn should be here
	cmp %l0,0
	bne .LL3
	nop
.stabn 68,0,16,.LM9-main
.LM9:
.LLBB3:
	call nil_ptr,0
	nop
.LLBE3:


Also, gcc 2.7.2.3 for i386 under Linux showed the same problem.

.stabn 68,0,15,.LM8-main
.LM8:
	movl $99,-4(%ebp)
	movl -12(%ebp),%ebx
	testl %ebx,%ebx
	jne .L3
.stabn 68,0,16,.LM9-main
.LM9:
.LBB3:
	call nil_ptr
.LBE3:


More information about the Gcc-bugs mailing list