public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* A question about gcc and threads under Linux 2.4
@ 2003-03-18 10:46 Nikita V. Youshchenko
  2003-03-18 16:58 ` Daniel Jacobowitz
  0 siblings, 1 reply; 3+ messages in thread
From: Nikita V. Youshchenko @ 2003-03-18 10:46 UTC (permalink / raw)
  To: gdb

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.

Is there any method to make debugging threads smarter under Linux? E.g. a 
kernel patch, another threading library, some patch to gdb, etc? If there 
are none, could someone assist me it implementing one?

Thank you for your help.
Please CC: me, I am not on the list.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: A question about gcc and threads under Linux 2.4
  2003-03-18 10:46 A question about gcc and threads under Linux 2.4 Nikita V. Youshchenko
@ 2003-03-18 16:58 ` Daniel Jacobowitz
  2003-03-21 18:16   ` Re[2]: " Nikita V . Youshchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Jacobowitz @ 2003-03-18 16:58 UTC (permalink / raw)
  To: Nikita V. Youshchenko; +Cc: gdb

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.

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

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

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re[2]: A question about gcc and threads under Linux 2.4
  2003-03-18 16:58 ` Daniel Jacobowitz
@ 2003-03-21 18:16   ` Nikita V . Youshchenko
  0 siblings, 0 replies; 3+ messages in thread
From: Nikita V . Youshchenko @ 2003-03-21 18:16 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb

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@gala.net

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-03-21 18:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-18 10:46 A question about gcc and threads under Linux 2.4 Nikita V. Youshchenko
2003-03-18 16:58 ` Daniel Jacobowitz
2003-03-21 18:16   ` Re[2]: " Nikita V . Youshchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).