This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB 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[2]: A question about gcc and threads under Linux 2.4


Tuesday, March 18, 2003, 7:57:49 PM, you wrote:

DJ> On Tue, Mar 18, 2003 at 01:45:10PM +0300, Nikita V. Youshchenko wrote:
>> Hello.
>> 
>> When debugging threaded programs with gdb, unexpected thread switches often 
>> happen. E.g. if another gdb step-by-step executes one thread, and another 
>> thread executes a system call, ofted gdb switches to than thread.
>> 
>> Gdb documentation says that on some targets gdb supports "set 
>> scheduler-locking" command that can help to avoid this behaviuor. But 
>> seems that this is not supported under Linux.

DJ> Actually, it is supported and works - at least in recent GDBs.

DJ> I don't know why GDB would be switching threads as you describe; do you
DJ> have a transcript you can show us?  A test case?

The scheduler-locking mode can be set only after program being run.
With 'on' parameter it`S work correct, but with 'step' parameter it`S
work in not the same way, as it described in documentation.
E.g. unexpected thread switches often happen.

Example:

a.c:

#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void *th1(void *){
        int q;
        for(;;)  {
                        q++;
                        sleep(1);
                }
        }

main(){
pthread_t tid1;
int r;
pthread_create(&tid1,NULL,th1,NULL);
for(;;){
        sleep(1);
        r++;
        }
pthread_join(tid1,NULL);
}


>gdb a.out
GNU gdb 5.3-debian
Copyright 2002 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-linux"...
(gdb) b main
Breakpoint 1 at 0x80485de: file a.c, line 18.
(gdb) r
Starting program: /home/a/Old/1/a.out
[New Thread 16384 (LWP 415)]
[Switching to Thread 16384 (LWP 415)]

Breakpoint 1, main () at a.c:18
18      pthread_create(&tid1,NULL,th1,NULL);
(gdb) set scheduler-locking step
(gdb) n
[New Thread 32769 (LWP 416)]
[New Thread 16386 (LWP 417)]
20              sleep(1);
(gdb)
22              r++;
(gdb)
23              }
(gdb) thread 3
[Switching to thread 3 (Thread 16386 (LWP 417))]#0  0x4016ef11 in nanosleep () from /lib/libc.so.6
(gdb) n
Single stepping until exit from function nanosleep,
which has no line number information.
0x401c231c in __frame_state_for () from /lib/libc.so.6
(gdb) n
Single stepping until exit from function __frame_state_for,
which has no line number information.
0x4016ef21 in nanosleep () from /lib/libc.so.6
(gdb) n
Single stepping until exit from function nanosleep,
which has no line number information.
0x40025d0d in nanosleep () from /lib/libpthread.so.0
(gdb) n
Single stepping until exit from function nanosleep,
which has no line number information.
0x4016eea0 in sleep () from /lib/libc.so.6
(gdb) n
Single stepping until exit from function sleep,
which has no line number information.
th1__FPv () at a.c:12
12                      }
(gdb)
9                               q++;
(gdb)
10                              sleep(1);
(gdb)
12                      }
(gdb)
9                               q++;
(gdb)
10                              sleep(1);
(gdb)
12                      }
(gdb)
9                               q++;
(gdb)
10                              sleep(1);
(gdb)
12                      }
(gdb)
9                               q++;
(gdb)
10                              sleep(1);
(gdb)
12                      }
(gdb)
9                               q++;
(gdb) thread 3
[Switching to thread 3 (Thread 16386 (LWP 417))]#0  th1__FPv () at a.c:9
9                               q++;
(gdb) n
10                              sleep(1);
(gdb)

12                      }
(gdb)
9                               q++;
(gdb)
10                              sleep(1);
(gdb)

12                      }
(gdb)
9                               q++;
(gdb)
10                              sleep(1);
(gdb)
12                      }
(gdb)
9                               q++;
(gdb)
10                              sleep(1);
(gdb)
12                      }
(gdb)
9                               q++;
(gdb) thread 1
[Switching to thread 1 (Thread 16384 (LWP 415))]#0  0x4016ef11 in nanosleep () from /lib/libc.so.6
(gdb) n
Single stepping until exit from function nanosleep,
which has no line number information.
0x401c231c in __frame_state_for () from /lib/libc.so.6
(gdb)
Single stepping until exit from function __frame_state_for,
which has no line number information.
0x4016ef21 in nanosleep () from /lib/libc.so.6
(gdb)
Single stepping until exit from function nanosleep,
which has no line number information.
0x40025d0d in nanosleep () from /lib/libpthread.so.0
(gdb)
Single stepping until exit from function nanosleep,
which has no line number information.
0x4016eea0 in sleep () from /lib/libc.so.6
(gdb)
Single stepping until exit from function sleep,
which has no line number information.
main () at a.c:22
22              r++;
(gdb)
23              }
(gdb)
20              sleep(1);
(gdb)
22              r++;
(gdb)
23              }
(gdb)
20              sleep(1);
(gdb)

22              r++;
(gdb)
23              }
(gdb)
20              sleep(1);
(gdb)
22              r++;
(gdb)
23              }
(gdb)
20              sleep(1);
(gdb)
22              r++;
(gdb)
23              }
(gdb)
20              sleep(1);
(gdb)
22              r++;
(gdb) htread 3
Undefined command: "htread".  Try "help".
(gdb) thread 3
[Switching to thread 3 (Thread 16386 (LWP 417))]#0  0x4016ef11 in nanosleep () from /lib/libc.so.6
(gdb) n
Single stepping until exit from function nanosleep,
which has no line number information.
0x401c231c in __frame_state_for () from /lib/libc.so.6
(gdb)
Single stepping until exit from function __frame_state_for,
which has no line number information.
0x4016ef21 in nanosleep () from /lib/libc.so.6
(gdb)
Single stepping until exit from function nanosleep,
which has no line number information.
0x40025d0d in nanosleep () from /lib/libpthread.so.0
(gdb)
Single stepping until exit from function nanosleep,
which has no line number information.
0x4016eea0 in sleep () from /lib/libc.so.6
(gdb)
Single stepping until exit from function sleep,
which has no line number information.
th1__FPv () at a.c:12
12                      }
(gdb)
9                               q++;
(gdb)
10                              sleep(1);
(gdb)
12                      }
(gdb)
9                               q++;
(gdb)
10                              sleep(1);
(gdb)
12                      }
(gdb)
9                               q++;
(gdb)
10                              sleep(1);
(gdb)
12                      }
(gdb)
9                               q++;
(gdb) thread 1
[Switching to thread 1 (Thread 16384 (LWP 415))]#0  0x4016ef11 in nanosleep () from /lib/libc.so.6
(gdb) n
Single stepping until exit from function nanosleep,
which has no line number information.
0x401c231c in __frame_state_for () from /lib/libc.so.6
(gdb)
Single stepping until exit from function __frame_state_for,
which has no line number information.
0x4016ef21 in nanosleep () from /lib/libc.so.6
(gdb)
Single stepping until exit from function nanosleep,
which has no line number information.
0x40025d0d in nanosleep () from /lib/libpthread.so.0
(gdb)
Single stepping until exit from function nanosleep,
which has no line number information.
0x4016eea0 in sleep () from /lib/libc.so.6
(gdb)
Single stepping until exit from function sleep,
which has no line number information.
main () at a.c:22
22              r++;
(gdb)
23              }
(gdb)
20              sleep(1);
(gdb)
22              r++;
(gdb)
23              }
(gdb)
20              sleep(1);
(gdb)
22              r++;
(gdb)
23              }
(gdb)
20              sleep(1);
(gdb)
22              r++;
(gdb) n
23              }
(gdb) n
20              sleep(1);
(gdb) n
n22             r++;
(gdb) n
23              }
(gdb) n
20              sleep(1);
(gdb) n
22              r++;
(gdb) n
23              }
(gdb) n
20              sleep(1);
(gdb) n
n22             r++;
(gdb) n
23              }
(gdb) thread 3
[Switching to thread 3 (Thread 16386 (LWP 417))]#0  0x4016ef11 in nanosleep () from /lib/libc.so.6
(gdb) n
Single stepping until exit from function nanosleep,
which has no line number information.
0x401c231c in __frame_state_for () from /lib/libc.so.6
(gdb) n
Single stepping until exit from function __frame_state_for,
which has no line number information.
0x4016ef21 in nanosleep () from /lib/libc.so.6
(gdb) n
Single stepping until exit from function nanosleep,
which has no line number information.
0x40025d0d in nanosleep () from /lib/libpthread.so.0
(gdb) n
Single stepping until exit from function nanosleep,
which has no line number information.
[Switching to Thread 16384 (LWP 415)]     // !!!!!!!
0x4016eea0 in sleep () from /lib/libc.so.6
(gdb) n
Single stepping until exit from function sleep,
which has no line number information.
main () at a.c:22
22              r++;
(gdb) n
23              }
(gdb) n
20              sleep(1);
(gdb) n
[Switching to Thread 16386 (LWP 417)]      // !!!!!!!
0x4016eea0 in sleep () from /lib/libc.so.6




-- 
Best regards
                             mailto:alexmm at gala dot net


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