This is the mail archive of the gdb@sourceware.org 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]
Other format: [Raw text]

Re: gdbserver and "terminated with signal SIGTRAP"


On Thu, 29 Nov 2007 23:55:02 +0900 (JST), Atsushi Nemoto <anemo@mba.ocn.ne.jp> wrote:
> I confirmed that maybe_attach_thread() in thread-db.c did not call
> linux_attach_lwp() on the second time.  That was because
> find_inferior_id() returned non NULL value.  It seems
> find_inferior_id() returned the first thread (which should be dead
> before the second thread creation).

Now I understand why find_inferior_id() misbehaves.  The "id" is
actually pthread_t and it might be recycled.

For example, This program shows same id values!

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void *func(void *data)
{
	return data;
}

int main(int argc, char **argv) 
{
        pthread_t id;
	int i;

	for (i = 0; i < 4; i++) {
		pthread_create(&id, NULL, func, NULL);
		printf("%x\n", id);
		pthread_join(id, NULL);
	}
	return 0;
}

$ ./foo
b7fdbb90
b7fdbb90
b7fdbb90
b7fdbb90


But... how can this be avoided?

---
Atsushi Nemoto


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