bug-gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Program linked with lpthred is going to be mad in gdb


From: 吉見隆
Subject: Program linked with lpthred is going to be mad in gdb
Date: Mon, 25 Nov 2002 13:10:28 +0900

Hi
My name is Takashi Yoshimi.

I found a serious behavior of gdb when it runs a program linked with 
"pthread" library.

My environment is :
        Linux 2.4.18-0v13
        gcc: 2.95.3
        gdb: 5.0

The following is the sample program.

>/* gdbdebug.c */
>/* gdb debug program */
>
>#include <stdio.h>
>
>int
>main()
>{
>  char ca, cb, cc, cd;
>  int  ia, ib, ic, id;
>  double       da, db, dc, dd;
>
>  ca = 1;
>  cb = 2;
>  cc = 3;
>  cd = 4;
>  ia = 5;
>  ib = 6;
>  ic = 7;
>  id = 8;
>  da = 9.0;
>  db = 10.1;
>  dc = 11.2;
>  dd = 13.3;
>
>  printf("c %d %d %d %d\n", ca, cb, cc,cd);
>  printf("i %d %d %d %d\n", ia, ib, ic, id);
>  printf("d %g %g %g %g\n", da, db, dc, dd);
>
>  exit(0);
>  return 0;
>}

When it is compiled as
> gcc -g gdbdebug.c

It works OK.(of course!) both in shell and in gdb.

But when you compile just adding unnecessary library -lpthread,

> gcc -g gdbdebug.c -lpthread

the result is strange.

In shell, the behavior is as same as the one without the library.
But in gdb, it comes as

>address@hidden /tmp]$ gcc -g gdbdebug.c -lpthread
>address@hidden /tmp]$ ./a.out 
>c 1 2 3 4
>i 5 6 7 8
>d 9 10.1 11.2 13.3
>address@hidden /tmp]$ gdb a.out
>GNU gdb 5.0
>Copyright 2000 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 "i386-redhat-linux"...
>(gdb) run
>Starting program: /tmp/a.out 
>[New Thread 1024 (LWP 2500)]
>c 1 2 3 4
>i 5 6 7 8
>d nan 10.1 11.2 13.3
>
>Program exited normally.
>(gdb) quit
>address@hidden /tmp]$ 

The first assignment of real number variable comes to be Nan.

The next example "gdbdebug2.c" is much more strange. It is just 
different from "gdbdebug.c" by duplicated assignment of da.
It terminates with no Nan when no breakpoint is set, but when some 
brekpoints are set, the result includes Nan and the position of Nan 
appearance changes with location of breakpoints.

>/* gdedebug2.c */
>/* gdb debug program */
>
>#include <stdio.h>
>
>int
>main()
>{
>  char ca, cb, cc, cd;
>  int  ia, ib, ic, id;
>  double       da, db, dc, dd;
>
>  ca = 1;
>  cb = 2;
>  cc = 3;
>  cd = 4;
>  ia = 5;
>  ib = 6;
>  ic = 7;
>  id = 8;
>  da = 9.0;
>  da = 9.0; /* added line */
>  db = 10.1;
>  dc = 11.2;
>  dd = 13.3;
>
>  printf("c %d %d %d %d\n", ca, cb, cc,cd);
>  printf("i %d %d %d %d\n", ia, ib, ic, id);
>  printf("d %g %g %g %g\n", da, db, dc, dd);
>
>  exit(0);
>  return 0;
>}
>


>address@hidden /tmp]$ gcc -g gdbdebug2.c -lpthread
>address@hidden /tmp]$ gdb a.out
>GNU gdb 5.0
>Copyright 2000 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 "i386-redhat-linux"...
>(gdb) run
>Starting program: /tmp/a.out 
>[New Thread 1024 (LWP 2609)]
>c 1 2 3 4
>i 5 6 7 8
>d 9 10.1 11.2 13.3
>
>Program exited normally.
>(gdb) b 20
>Breakpoint 1 at 0x8048472: file gdbdebug2.c, line 20.
>(gdb) b 21
>Breakpoint 2 at 0x804847b: file gdbdebug2.c, line 21.
>(gdb) b 22
>Breakpoint 3 at 0x8048484: file gdbdebug2.c, line 22.
>(gdb) b 23
>Breakpoint 4 at 0x804848d: file gdbdebug2.c, line 23.
>(gdb) disa 2 3 4
>(gdb) run
>Starting program: /tmp/a.out 
>[New Thread 1024 (LWP 2657)]
>[Switching to Thread 1024 (LWP 2657)]
>
>Breakpoint 1, main () at gdbdebug2.c:20
>20       da = 9.0;
>(gdb) c
>Continuing.
>c 1 2 3 4
>i 5 6 7 8
>d 9 10.1 11.2 13.3
>
>Program exited normally.
>(gdb) ena 2
>(gdb) run
>Starting program: /tmp/a.out 
>[New Thread 1024 (LWP 2705)]
>[Switching to Thread 1024 (LWP 2705)]
>
>Breakpoint 1, main () at gdbdebug2.c:20
>20       da = 9.0;
>(gdb) c
>Continuing.
>
>Breakpoint 2, main () at gdbdebug2.c:21
>21       da = 9.0;
>(gdb) c
>Continuing.
>c 1 2 3 4
>i 5 6 7 8
>d nan 10.1 11.2 13.3
>
>Program exited normally.
>(gdb) ena 3
>(gdb) run
>Starting program: /tmp/a.out 
>[New Thread 1024 (LWP 2753)]
>[Switching to Thread 1024 (LWP 2753)]
>
>Breakpoint 1, main () at gdbdebug2.c:20
>20       da = 9.0;
>(gdb) c
>Continuing.
>
>Breakpoint 2, main () at gdbdebug2.c:21
>21       da = 9.0;
>(gdb) c
>Continuing.
>
>Breakpoint 3, main () at gdbdebug2.c:22
>22       db = 10.1;
>(gdb) c
>Continuing.
>c 1 2 3 4
>i 5 6 7 8
>d nan nan 11.2 13.3
>
>Program exited normally.
>(gdb) disa 1 2
>(gdb) run
>Starting program: /tmp/a.out 
>[New Thread 1024 (LWP 2801)]
>[Switching to Thread 1024 (LWP 2801)]
>
>Breakpoint 3, main () at gdbdebug2.c:22
>22       db = 10.1;
>(gdb) c
>Continuing.
>c 1 2 3 4
>i 5 6 7 8
>d 9 nan 11.2 13.3
>
>Program exited normally.
>(gdb) 

-----
Takashi Yoshimi
address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]