This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: isatty bug


> * Brian Ford <sbeq@iff.sfv.pbz> [2003-09-16 14:22:33 -0500]:
>
> Was that stock Cygwin gdb that crashed?

yes, gdb 20030901-1

> $ cat stest.c
> #include <sys/types.h>
> #include <sys/stat.h>
> 
> int same_tty_p (int fd1, int fd2)
> {
>   struct stat stat1, stat2;
> 
>   return (fstat(fd1, &stat1) >= 0 && fstat(fd2, &stat2) >= 0 &&
>           stat1.st_dev == stat2.st_dev && stat2.st_ino == stat2.st_ino);
> }
> 
> int main(void)
> {
>   printf("0/1: %d\n1/2: %d\n2/0: %d\n",same_tty_p(0,1),
>          same_tty_p(1,2),same_tty_p(2,0));
>   printf("stat %d bytes\n", sizeof(struct stat));
> }
> 
> ford@fordpc ~
> $ gcc -o stest stest.c
> 
> ford@fordpc ~
> $ ./stest
> 0/1: 1
> 1/2: 1
> 2/0: 1
> stat 96 bytes
> 
> $ nm stest.exe | grep fstat
> 00402970 T __fstat64
> 004060a4 I __imp___fstat64
> 004060e0 I __imp__fstat
> 004027a0 T _fstat

i get the exact same output (but read on!):

15:57:15 /cygdrive/d/sds/c [74]$ gcc -o stest stest.c
15:57:21 /cygdrive/d/sds/c [75]$ ./stest
0/1: 1
1/2: 1
2/0: 1
stat 96 bytes
15:57:27 /cygdrive/d/sds/c [76]$ nm stest.exe | grep fstat
00402970 T __fstat64
004060a4 I __imp___fstat64
004060e0 I __imp__fstat
004027a0 T _fstat
15:57:40 /cygdrive/d/sds/c [77]$ gcc -g -o stest stest.c
15:58:05 /cygdrive/d/sds/c [78]$ ./stest
0/1: 1
1/2: 1
2/0: 1
stat 96 bytes
15:58:07 /cygdrive/d/sds/c [79]$ nm stest.exe | grep fstat
00402970 T __fstat64
004060a4 I __imp___fstat64
004060e0 I __imp__fstat
004027a0 T _fstat
15:58:10 /cygdrive/d/sds/c [80]$ gdb stest
GNU gdb 2003-09-02-cvs (cygwin-special)
Copyright 2003 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 "i686-pc-cygwin"...
(gdb) run
Starting program: /cygdrive/d/sds/c/stest.exe
0/1: 1
1/2: 1
2/0: 1
stat 96 bytes

Program exited with code 016.
(gdb) break main
Breakpoint 1 at 0x401138: file stest.c, line 17.
(gdb) run
Starting program: /cygdrive/d/sds/c/stest.exe

Breakpoint 1, main () at stest.c:17
17        printf("0/1: %d\n1/2: %d\n2/0: %d\n",same_tty_p(0,1),
(gdb) s
same_tty_p (fd1=0, fd2=1) at stest.c:11
11        return (fstat(fd1, &stat1) >= 0 && fstat(fd2, &stat2) >= 0 &&
(gdb) s
13      }
(gdb) p stat1
$1 = {st_dev = 65536, st_ino = 768719909725019470, st_mode = 8630,
  st_nlink = 1, st_uid = 13044, st_gid = 10513, st_rdev = 65536, st_size = 0,
  st_atim = {tv_sec = 1063742318, tv_nsec = 659000000}, st_mtim = {
    tv_sec = 1063742318, tv_nsec = 659000000}, st_ctim = {
    tv_sec = 1063742318, tv_nsec = 659000000}, st_blksize = 1024,
  st_blocks = 0, st_spare4 = {0, 0}}
(gdb) p stat2
$2 = {st_dev = 65536, st_ino = 5383573127766058053, st_mode = 8630,
  st_nlink = 1, st_uid = 13044, st_gid = 10513, st_rdev = 65536, st_size = 0,
  st_atim = {tv_sec = 1063742318, tv_nsec = 699000000}, st_mtim = {
    tv_sec = 1063742318, tv_nsec = 699000000}, st_ctim = {
    tv_sec = 1063742318, tv_nsec = 699000000}, st_blksize = 1024,
  st_blocks = 0, st_spare4 = {0, 0}}
(gdb) p fstat(fd1, &stat1)
Segmentation fault (core dumped)

it turned out that I needed to recompile the obj file that defined my
same_tty_p() - of course.  how silly of me!  [now, I think I was told
that everything was binary backwards compatible; I guess I was confused]
now that I did it -- my scratch.c works just like your stest.c.
good.

now, why does GDB crash?

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
All extremists should be taken out and shot.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]