howie@cunixc.cc.columbia.edu (Howie Kaye) (09/18/89)
I have a piece of code which works exactly correctly when compiled
under gcc, however, when run under gdb (or dbx), the value of a static
variable "x" is always shown wrong (see source below). Checking
further, I find that the address gdb is looking at for "x" is wrong
(nm shows its address to be 0x1030, while gdb show it to be 0xfe4).
The assembly code produced by gcc appears to be correct. Gdb does
debug this correctly when using the standard ultrix (bsd) C compiler.
I am using gcc version 1.35.
Debuggers which i have tried out with this are:
gdb version 3.2
gdb version 2.7
dbx version 4.0
This is all running on a Vax 8700, running Ultrix version 2.0
attached are:
1) C source,
2) gcc -S output,
3) cc -S output (for comparison purposes)
4) nm output
5) script of compilation and gdb run.
------------------------------------------------------------
Howie Kaye howie@columbia.edu
Columbia University hlkcu@cuvma.bitnet
Systems Group ...!rutgers!columbia!howie
------------------------------------------------------------
xxx.c:
---------
main() {
int z=5;
foo(&z);
}
foo(y)
int *y;
{
static int x=10;
*y = x = 2;
x = 9;
printf("%d %d\n", x, *y);
}
-----------------
xxx.s: (from gcc)
-----------------
#NO_APP
gcc_compiled.:
.text
.align 1
.globl _main
_main:
.word 0x0
subl2 $4,sp
movl $5,-4(fp)
subl3 $4,fp,r0
pushl r0
calls $1,_foo
ret
.data
.align 2
_x.0:
.long 10
.text
.align 0
LC0:
.ascii "%d %d\12\0"
.align 1
.globl _foo
_foo:
.word 0x0
movl $2,_x.0
movl $2,*4(ap)
movl $9,_x.0
pushl *4(ap)
pushl _x.0
pushab LC0
calls $3,_printf
ret
---------------
xxx.s (from cc)
---------------
LL0:
.data
.text
.align 2
.globl _main
_main:
.word L12
jbr L14
L15:
movl $5,-4(fp)
subl3 $4,fp,r0
pushl r0
calls $1,_foo
ret
.set L12,0x0
L14:
subl2 $4,sp
jbr L15
.data
.text
.align 2
.globl _foo
_foo:
.word L17
jbr L19
L20:
.data
.align 2
L21:
.long 10
.text
movl $2,L21
movl L21,r0
movl r0,*4(ap)
.data 1
L23:
.ascii "%d %d\12\0"
.text
pushl *4(ap)
pushl L21
pushl $L23
calls $3,_printf
ret
.set L17,0x0
L19:
jbr L20
.data
------------
nm output
------------
% nm xxx
00000098 t -lg
00000ac0 T __cleanup
00001170 B __dbargs
00000098 T __dbsubc
000000a3 T __dbsubn
000001cc T __doprnt
00000f5c T __exit
0000095c T __flsbuf
00000a5c T __fwalk
00000bbc T __getstdiobuf
00001088 D __iob
00001370 B __iob_end
000010c4 D __iob_start
00000ea4 T _bcopy
00000bb4 T _close
000013e8 B _end
00001004 D _environ
00001374 B _errno
00000f48 T _exit
00000f5c t _exit.o
00000b44 T _fclose
00000ad0 T _fflush
0000006a T _foo
00000d5c T _free
00000c1c T _fstat
00000c44 T _gtty
00000c64 T _ioctl
00000c24 T _isatty
0000004c T _main
00000c6c T _malloc
00000044 T _moncontrol
000000a4 T _printf
00000d90 T _realloc
00001140 D _realloc_srchlen
00000f08 T _sbrk
00000f40 T _write
00001030 d _x.0 ******************
00000ea4 t bcopy.o
00000f60 T cerror
00000f60 t cerror.o
00000bac t close.o
00000000 t crt0.o
0000116c D curbrk
00000a5c t data.o
000000cc t doprnt.o
00000f48 t exit.o
00000ad0 t fclose.o
0000095c t flsbuf.o
00000c14 t fstat.o
0000004c t gcc_compiled.
00000bbc t getstdiobuf.o
00000c44 t gtty.o
00000c5c t ioctl.o
00000c24 t isatty.o
00000c6c t malloc.o
00001008 D mcount
00001168 D minbrk
000000a4 t printf.o
00000f08 t sbrk.o
00000000 T start
00000f38 t write.o
0000004c t xxx.o
------------
Script started on Sun Sep 17 22:28:11 1989
% gcc -v -g -o xxx xxx.c
gcc version 1.35
/usr/local/lib/gcc-cpp -v -undef -D__GNUC__ -Dvax -Dunix -D__vax__ -D__unix__ xxx.c /tmp/cc005675.cpp
GNU CPP version 1.35
/usr/local/lib/gcc-cc1 /tmp/cc005675.cpp -quiet -dumpbase xxx.c -g -version -o /tmp/cc005675.s
GNU C version 1.35 (vax) compiled by GNU C version 1.35.
as -o xxx.o /tmp/cc005675.s
ld -o xxx /lib/crt0.o xxx.o /usr/local/lib/gcc-gnulib -lg -lc
% gdb xxx
GDB 3.2, Copyright (C) 1988 Free Software Foundation, Inc.
There is ABSOLUTELY NO WARRANTY for GDB; type "info warranty" for details.
GDB is free software and you are welcome to distribute copies of it
under certain conditions; type "info copying" to see the conditions.
Reading symbol data from /sy/howie/tmp/xxx...done.
Type "help" for a list of commands.
(gdb) b main
Reading in symbols for xxx.c...done.
Breakpoint 1 at 0x51: file xxx.c, line 2.
(gdb) r
Starting program: /sy/howie/tmp/xxx
Bpt 1, main (1, 2147474988, 2147474996) (xxx.c line 2)
2 int z=5;
(gdb) step
4 foo(&z);
(gdb) print z
$1 = 5
(gdb) step
foo (y=(int *) 0x7fffde00) (xxx.c line 12)
12 *y = x = 2;
(gdb) print x
$2 = 0
(gdb) print &x
$1 = (int *) 0xfe4
(gdb) print *y
$3 = 5
(gdb) step
13 x = 9;
(gdb) print *y
$4 = 2
(gdb) print x
$5 = 0
(gdb) step
14 printf("%d %d\n", x, *y);
(gdb) print x
$6 = 0
(gdb) step
9 2
15 }
(gdb) c
Continuing.
Program exited normally.
(gdb) quit
% exit
%
script done on Sun Sep 17 22:29:26 1989
----------