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]

Re: GDB and threads...


Oop! I just tried this on a Mandrake 8.0 box.  And lo and behold, IT
WORKS!  Soooo I'll figure out what the diff is in version, or upgrade
to 8.0!  Thanks again!

On Mon, Apr 30, 2001 at 06:32:06PM -0700, Kevin Buettner wrote:
> On Apr 26,  5:43pm, Jiva DeVoe wrote:
> 
> > Does anyone have any tips on debugging multithreaded apps using gdb?
> > I have been trying for a couple of months now, and IMO gdb is REALLY
> > not very effective at it (at least in my experience.)  I've used
> > windows debuggers to do this, and when I would have a fault in a
> > subthread, the debugger would actually break *in* that thread.  With
> > gdb, it breaks, but it still breaks in the main thread.  I can't even
> > get the thread info commands to work.
> 
> Jiva,
> 
> I constructed a small program with three threads (counting the main
> thread) to see if I could reproduce the problem that you describe.
> Here's the program:
> 
> #include <stdio.h>
> #include <unistd.h>
> #include <pthread.h>
> 
> void *
> worker (void *args)
> {
>   int i;
>   char **a = args;
> 
>   for (i = 0; i < 5; i++)
>     {
>       printf ("%c\n", a[i][0]);
>       sleep (1);
>     }
>   return NULL;
> }
> 
> int
> main(void)
> {
>   pthread_t tid1, tid2;
>   char *a1[] = { "a", "b", "c", "d", "e" };
>   char *a2[] = { "A", "B", "C", 0, "E" };
> 
>   pthread_create (&tid1, NULL, worker, a1);
>   pthread_create (&tid2, NULL, worker, a2);
> 
> 
>   pthread_join (tid1, NULL);
>   pthread_join (tid2, NULL);
>   return 0;
> }
> 
> I compile it (on my Red Hat 7.0 machine) as follows:
> 
>     gcc -Wall -o threads-segv -g threads-segv.c -lpthread
> 
> When I run it (without GDB), it terminates (as intended) with a
> SIGSEGV.  When I debug it with GDB (using current development
> sources), I see the following:
> 
>     (gdb) r
>     Starting program: /home/kev/ctests/threads-segv 
>     [New Thread 1024 (LWP 5462)]
>     [New Thread 2049 (LWP 5463)]
>     Delayed SIGSTOP caught for LWP 5463.
>     [New Thread 1026 (LWP 5464)]
>     Delayed SIGSTOP caught for LWP 5464.
>     [New Thread 2051 (LWP 5465)]
>     Delayed SIGSTOP caught for LWP 5465.
>     a
>     A
>     b
>     B
>     C
>     c
>     d
> 
>     Program received signal SIGSEGV, Segmentation fault.
>     [Switching to Thread 2051 (LWP 5465)]
>     0x08048577 in worker (args=0xbffff968) at threads-segv.c:13
>     warning: Source file is more recent than executable.
> 
>     13            printf ("%c\n", a[i][0]);
>     (gdb) print i
>     $1 = 3
>     (gdb) print a[i]
>     $2 = 0x0
>     (gdb) info thread
>     * 4 Thread 2051 (LWP 5465)  0x08048577 in worker (args=0xbffff968)
> 	at threads-segv.c:13
>       3 Thread 1026 (LWP 5464)  0x400f3241 in __libc_nanosleep ()
>        from /lib/libc.so.6
>       2 Thread 2049 (LWP 5463)  0x40113b97 in __poll (fds=0x804b684, nfds=1, 
> 	timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63
>       1 Thread 1024 (LWP 5462)  0x40067e75 in __sigsuspend (set=0xbffff7c8)
> 	at ../sysdeps/unix/sysv/linux/sigsuspend.c:45
>     (gdb) bt
>     #0  0x08048577 in worker (args=0xbffff968) at threads-segv.c:13
>     #1  0x4002bc8e in pthread_start_thread_event (arg=0xbf5ffc00) at manager.c:274
>     (gdb) 
> 
> So, with my admittedly simple test case, I've been unable to reproduce
> the problems that you've described.
> 
> Have you tried the current development sources?  If not, see
> 
>     http://sources.redhat.com/gdb/#download
> 
> and read the section about downloading the development version.
> 
> Also, it would be useful if you'd send us your own testcase(s) which
> illustrate the problems that you're seeing.
> 
> Kevin

-- 
Jiva DeVoe
VP Of Software Development
Opnix, Inc. - Simply cool bandwidth.
GPG Fingerprint: 0A17 DF84 516A 1DC4 B837  FE6D 3128 41CD 97CB 4AA7


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