From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kevin Buettner To: Jiva DeVoe , gdb@sources.redhat.com Subject: Re: GDB and threads... Date: Mon, 30 Apr 2001 18:32:00 -0000 Message-id: <1010501013206.ZM31835@ocotillo.lan> References: <20010426174305.B19540@opnix.com> X-SW-Source: 2001-04/msg00244.html 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: --- threads-segv.c --- #include #include #include 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; } --- end threads-segv.c --- 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