public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Nikita V . Youshchenko <alexmm@gala.net>
To: Daniel Jacobowitz <drow@mvista.com>
Cc: gdb@sources.redhat.com
Subject: Re[2]: A question about gcc and threads under Linux 2.4
Date: Fri, 21 Mar 2003 18:16:00 -0000	[thread overview]
Message-ID: <183742187.20030321211315@gala.net> (raw)
In-Reply-To: <20030318165749.GA27755@nevyn.them.org>

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

      reply	other threads:[~2003-03-21 18:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-18 10:46 Nikita V. Youshchenko
2003-03-18 16:58 ` Daniel Jacobowitz
2003-03-21 18:16   ` Nikita V . Youshchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=183742187.20030321211315@gala.net \
    --to=alexmm@gala.net \
    --cc=drow@mvista.com \
    --cc=gdb@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).