This is the mail archive of the libc-hacker@cygnus.com mailing list for the glibc project.


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

gdb now works with glibc 2.1 linuxthreads


Hi,

Now my gdb works with glibc 2.1 linuxthreads after applying the patch
enclosed here.

BTW, Ulrich, why CLONE_PTRACE was added? It cannot be used in gdb. If
it was intended for gdb, please take it out. Thanks.

I will make a new gdb release after fixing a minor hardware watchpoint
bug.

Thanks.

-- 
H.J. Lu (hjl@gnu.org)
---
Sun Jan 24 13:41:06 1999  H.J. Lu  <hjl@gnu.org>

	* manager.c (__pthread_manager): Delete __pthread_sig_debug
	from mask if __pthread_sig_debug > 0.
	(pthread_handle_create): Increment __pthread_handles_num.

	* manager.c (pthread_handle_create): Don't pass CLONE_PTRACE to
	clone when in gdb.
	* pthread.c (__pthread_initialize_manager): Likewise.

	* pthread.c (pthread_initialize): Use __libc_allocate_rtsig (1)
	instead of __libc_allocate_rtsig (2).
	(__pthread_initialize_manager): Send __pthread_sig_debug to gdb
	instead of __pthread_sig_cancel.
	(pthread_handle_sigdebug): Fix comments.

Index: manager.c
===================================================================
RCS file: /home/work/cvs/gnu/glibc/linuxthreads/manager.c,v
retrieving revision 1.1.1.13
diff -u -p -r1.1.1.13 manager.c
--- manager.c	1999/01/09 18:18:04	1.1.1.13
+++ manager.c	1999/01/24 21:24:58
@@ -104,6 +104,8 @@ int __pthread_manager(void *arg)
   /* Block all signals except __pthread_sig_cancel and SIGTRAP */
   sigfillset(&mask);
   sigdelset(&mask, __pthread_sig_cancel); /* for thread termination */
+  if (__pthread_sig_debug > 0)
+    sigdelset(&mask, __pthread_sig_debug); /* for debugging purposes */
   sigdelset(&mask, SIGTRAP);            /* for debugging purposes */
   sigprocmask(SIG_SETMASK, &mask, NULL);
   /* Raise our priority to match that of main thread */
@@ -162,7 +164,7 @@ int __pthread_manager(void *arg)
       case REQ_DEBUG:
         /* Make gdb aware of new thread */
 	if (__pthread_threads_debug && __pthread_sig_debug > 0)
-          raise(__pthread_sig_debug);
+	  raise(__pthread_sig_debug);
         restart(request.req_thread);
         break;
       }
@@ -292,6 +294,7 @@ static int pthread_handle_create(pthread
   char *guardaddr = NULL;
   size_t guardsize = 0;
   int pagesize = __getpagesize();
+  int flags;
 
   /* First check whether we have to change the policy and if yes, whether
      we can  do this.  Normally this should be done by examining the
@@ -311,6 +314,7 @@ static int pthread_handle_create(pthread
                                  &guardaddr, &guardsize) == 0)
         break;
     }
+  __pthread_handles_num++;
   /* Allocate new thread identifier */
   pthread_threads_counter += PTHREAD_THREADS_MAX;
   new_thread_id = sseg + pthread_threads_counter;
@@ -372,12 +376,14 @@ static int pthread_handle_create(pthread
   /* Raise priority of thread manager if needed */
   __pthread_manager_adjust_prio(new_thread->p_priority);
   /* Do the cloning */
-  pid = __clone(pthread_start_thread, (void **) new_thread,
-                CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
+  flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
+	  __pthread_sig_cancel;
 #ifdef CLONE_PTRACE
-                CLONE_PTRACE |
+  if (!__pthread_threads_debug)
+    flags |= CLONE_PTRACE;
 #endif
-		__pthread_sig_cancel, new_thread);
+  pid = __clone(pthread_start_thread, (void **) new_thread, flags,
+		new_thread);
   /* Check if cloning succeeded */
   if (pid == -1) {
     /* Free the stack if we allocated it */
Index: pthread.c
===================================================================
RCS file: /home/work/cvs/gnu/glibc/linuxthreads/pthread.c,v
retrieving revision 1.1.1.10
diff -u -p -r1.1.1.10 pthread.c
--- pthread.c	1999/01/09 18:18:04	1.1.1.10
+++ pthread.c	1999/01/24 20:06:44
@@ -223,7 +223,7 @@ static void pthread_initialize(void)
   /* Allocate the signals used.  */
   __pthread_sig_restart = __libc_allocate_rtsig (1);
   __pthread_sig_cancel = __libc_allocate_rtsig (1);
-  __pthread_sig_debug = __libc_allocate_rtsig (2);
+  __pthread_sig_debug = __libc_allocate_rtsig (1);
   if (__pthread_sig_restart < 0 ||
       __pthread_sig_cancel < 0 ||
       __pthread_sig_debug < 0)
@@ -280,6 +280,7 @@ int __pthread_initialize_manager(void)
   int manager_pipe[2];
   int pid;
   struct pthread_request request;
+  int flags;
 
   /* If basic initialization not done yet (e.g. we're called from a
      constructor run before our constructor), do it now */
@@ -295,12 +296,13 @@ int __pthread_initialize_manager(void)
     return -1;
   }
   /* Start the thread manager */
-  pid = __clone(__pthread_manager, (void **) __pthread_manager_thread_tos,
-                CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND
+  flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND;
 #ifdef CLONE_PTRACE
-		| CLONE_PTRACE
+  if (!__pthread_threads_debug)
+    flags |= CLONE_PTRACE;
 #endif
-		, (void *)(long)manager_pipe[0]);
+  pid = __clone(__pthread_manager, (void **) __pthread_manager_thread_tos,
+		flags, (void *)(long)manager_pipe[0]);
   if (pid == -1) {
     free(__pthread_manager_thread_bos);
     __libc_close(manager_pipe[0]);
@@ -311,7 +313,8 @@ int __pthread_initialize_manager(void)
   __pthread_manager_reader = manager_pipe[0]; /* reading end */
   __pthread_manager_thread.p_pid = pid;
   /* Make gdb aware of new thread manager */
-  if (__pthread_threads_debug) raise(__pthread_sig_cancel);
+  if (__pthread_threads_debug && __pthread_sig_debug > 0)
+    raise(__pthread_sig_debug);
   /* Synchronize debugging of the thread manager */
   request.req_kind = REQ_DEBUG;
   __libc_write(__pthread_manager_request, (char *) &request, sizeof(request));
@@ -536,7 +539,7 @@ static void pthread_handle_sigcancel(int
    The debugging strategy is as follows:
    On reception of a REQ_DEBUG request (sent by new threads created to
    the thread manager under debugging mode), the thread manager throws
-   __pthread_sig_cancel to itself. The debugger (if active) intercepts
+   __pthread_sig_debug to itself. The debugger (if active) intercepts
    this signal, takes into account new threads and continue execution
    of the thread manager by propagating the signal because it doesn't
    know what it is specifically done for. In the current implementation,


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