problems using gdb on threaded programs

Jurjen Middendorp jurjenm at stack.nl
Sat Nov 10 08:55:10 PST 2007


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

/home/jurjen/C
    $cat threadthingy.c
#include <stdio.h>
#include <pthread.h>

void *
start(void* blah) 
{
	printf("hello from a thread!\n");
	return NULL;
}

int 
main(void) 
{
	pthread_t tid;
	pthread_create(&tid, NULL, start, NULL);
	pthread_join(tid, NULL);
	printf("done!\n");
	return 0;
}

/home/jurjen/C
    $gdb -v
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 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-marcel-freebsd".

/home/jurjen/C
    $gdb threadthingy
(gdb) break main
Breakpoint 1 at 0x804860c: file threadthingy.c, line 11.
(gdb) r
Starting program: /stuff/backup/C/threadthingy 
warning: Unable to get location for thread creation breakpoint: generic error
[New LWP 100143]
^C^C^Chelp, gdb hang and now i have to kill it!!^C^C^C^CKilled

/home/jurjen/C
    $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"...
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.


(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
Continuing.

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
Continuing.

Breakpoint 2, start (blah=0x0) at threadthingy.c:5
5		printf("hello from a thread!\n");
(gdb) c
Continuing.

Breakpoint 2, start (blah=0x0) at threadthingy.c:5
5		printf("hello from a thread!\n");
(gdb) c
Continuing.

Breakpoint 2, start (blah=0x0) at threadthingy.c:5
5		printf("hello from a thread!\n");
(gdb) n
0x2809373e in ?? () from /lib/libpthread.so.2
(gdb) d b
Delete all breakpoints? (y or n) y
(gdb) c
Continuing.
hello from a thread!
done!

Program exited normally.
(gdb) quit

Script done on Sat Nov 10 16:53:31 2007
--------------------------------------------------------------------------------


More information about the freebsd-questions mailing list