problems using gdb on threaded programs

Jurjen Middendorp jurjenm at
Tue Nov 13 03:43:34 PST 2007

Ok let me try again (more explanation/question below).

Also sorry that i screwed up the script output by having a copy of the text
in it... not sure how that happened!

On Sat, Nov 10, 2007 at 05:53:09PM +0000, Jurjen Middendorp wrote:
>Hello, when i try to debug a program with threads (with gdb) gdb complains
>about not being able to find thread start point and kind of hangs (see
>below). It is quite likely i misconfigured something, but i have no idea
>what that something would be (maybe forgot to put stuff in kernel?). 
>I tried installing a newer version of gdb (6.6) but that fails in a
>different way, it can't get the thread info (breakpoints seem to work
>better though :) I also tried to recompile libpthread in /usr/src/lib with
>debug flag, but no potato.
>What else can i try now? i'm kind of stumped.
>- jurjen
>PS. Below is an output of the errors of gdb and a small program that fails.
>Script started on Sat Nov 10 16:51:32 2007
>    $cat threadthingy.c
>#include <stdio.h>
>#include <pthread.h>
>void *
>start(void* blah) 
>	printf("hello from a thread!\n");
>	return NULL;
>	pthread_t tid;
>	pthread_create(&tid, NULL, start, NULL);
>	pthread_join(tid, NULL);
>	printf("done!\n");
>	return 0;
>    $gdb66 threadthingy
>GNU gdb 6.6 [GDB v6.6 for FreeBSD]
>Copyright (C) 2006 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-portbld-freebsd6.2"...
>(gdb) b main
>Breakpoint 1 at 0x804860c: file threadthingy.c, line 11.
>(gdb) b start
>Breakpoint 2 at 0x80485d6: file threadthingy.c, line 5.
>(gdb) r
>Starting program: /stuff/backup/C/threadthingy 
>Breakpoint 1, main () at threadthingy.c:11
>11		pthread_create(&tid, NULL, start, NULL);
>(gdb) c
>Breakpoint 2, start (blah=0x0) at threadthingy.c:5
>5		printf("hello from a thread!\n");
>(gdb) info threads
>(gdb) info thread
>(gdb) help info threads
>IDs of currently known threads.
>(gdb) thread 1
>Thread ID 1 not known.
>(gdb) thread 0
>Thread ID 0 not known.
>(gdb) thread
>[Current thread is 0 (process 53031)]
>(gdb) thread next
>No symbol "next" in current context.
>(gdb) thread 0
>Thread ID 0 not known.
>(gdb) info thread
>(gdb) c

The problem is here i think, why can't gdb display the thread-info? (Or
find thread creation points (?) using an older version of gdb).
Do i need to use another library/compiler flags if i want to debug threaded

- jurjen

More information about the freebsd-questions mailing list