[PATCH] Fix debugging of threaded processes using trunk -lpthread
Jakub Jelinek
jakub@redhat.com
Mon Apr 8 06:24:00 GMT 2002
Hi!
gdb was dying when debugging threaded apps:
[New Thread 1024 (LWP 10933)]
Searching for the number = 10933...
[New Thread 2049 (LWP 10940)]
Can't attach LWP 10940: Operation not permitted
The problem is that thread manager segfaulted, thus task->mm
in pthread_attach was NULL and kernel returned -EPERM.
The reason for the segfault was that __pthread_manager_event passed
a void * variable to INIT_THREAD_SELF and i386/useldt.h relied on it
being pthread_descr type.
Below is a fix, actually only one of the 2 patched files is enough
to fix this (doesn't matter which one), but I think it won't hurt to
change both places for robustness.
2002-04-08 Jakub Jelinek <jakub@redhat.com>
* manager.c (__pthread_manager_event): Use self instead of arg
for INIT_THREAD_SELF.
* sysdeps/i386/useldt.h (INIT_THREAD_SELF): Use sizeof (struct
_pthread_descr_struct) instead of sizeof (*descr).
--- libc/linuxthreads/manager.c.jj Thu Feb 28 12:31:50 2002
+++ libc/linuxthreads/manager.c Mon Apr 8 15:12:02 2002
@@ -244,15 +244,16 @@ __pthread_manager(void *arg)
int __pthread_manager_event(void *arg)
{
+ pthread_descr self = arg;
/* If we have special thread_self processing, initialize it. */
#ifdef INIT_THREAD_SELF
- INIT_THREAD_SELF(arg, 1);
+ INIT_THREAD_SELF(self, 1);
#endif
/* Get the lock the manager will free once all is correctly set up. */
- __pthread_lock (THREAD_GETMEM(((pthread_descr) arg), p_lock), NULL);
+ __pthread_lock (THREAD_GETMEM(self, p_lock), NULL);
/* Free it immediately. */
- __pthread_unlock (THREAD_GETMEM(((pthread_descr) arg), p_lock));
+ __pthread_unlock (THREAD_GETMEM(self, p_lock));
return __pthread_manager(arg);
}
--- libc/linuxthreads/sysdeps/i386/useldt.h.jj Mon Jul 23 10:35:31 2001
+++ libc/linuxthreads/sysdeps/i386/useldt.h Mon Apr 8 15:20:13 2002
@@ -64,7 +64,8 @@ extern int __modify_ldt (int, struct mod
#define INIT_THREAD_SELF(descr, nr) \
{ \
struct modify_ldt_ldt_s ldt_entry = \
- { nr, (unsigned long int) descr, sizeof (*descr), 1, 0, 0, 0, 0, 1, 0 }; \
+ { nr, (unsigned long int) descr, sizeof (struct _pthread_descr_struct), \
+ 1, 0, 0, 0, 0, 1, 0 }; \
if (__modify_ldt (1, &ldt_entry, sizeof (ldt_entry)) != 0) \
abort (); \
__asm__ __volatile__ ("movw %w0, %%gs" : : "q" (nr * 8 + 7)); \
Jakub
More information about the Libc-hacker
mailing list