1. Fix symbols needed by libthread_db.
authorDavid Xu <davidxu@dragonflybsd.org>
Sat, 7 May 2005 09:29:46 +0000 (09:29 +0000)
committerDavid Xu <davidxu@dragonflybsd.org>
Sat, 7 May 2005 09:29:46 +0000 (09:29 +0000)
2. Add mechanism to report thread events to debugger.

lib/libthread_xu/Makefile
lib/libthread_xu/pthread.map
lib/libthread_xu/thread/Makefile.inc
lib/libthread_xu/thread/thr_create.c
lib/libthread_xu/thread/thr_event.c [new file with mode: 0644]
lib/libthread_xu/thread/thr_exit.c
lib/libthread_xu/thread/thr_init.c
lib/libthread_xu/thread/thr_private.h
lib/libthread_xu/thread/thr_symbols.c

index f728e9d..08145bd 100644 (file)
@@ -1,5 +1,5 @@
 # $FreeBSD: src/lib/libpthread/Makefile,v 1.53 2004/10/24 15:32:32 ru Exp $
-# $DragonFly: src/lib/libthread_xu/Makefile,v 1.4 2005/05/03 07:29:04 joerg Exp $
+# $DragonFly: src/lib/libthread_xu/Makefile,v 1.5 2005/05/07 09:29:46 davidxu Exp $
 #
 # All library objects contain FreeBSD revision strings by default; they may be
 # excluded as a space-saving measure.  To produce a library that does
@@ -14,6 +14,7 @@ CFLAGS+=-DPTHREAD_KERNEL -D_THREAD_SAFE
 CFLAGS+=-I${.CURDIR}/../libc/include -I${.CURDIR}/thread \
        -I${.CURDIR}/../../include
 CFLAGS+=-I${.CURDIR}/arch/${MACHINE_ARCH}/include
+CFLAGS+=-I${.CURDIR}/../libthread_db
 CFLAGS+=-Winline
 
 CFLAGS+= -g
index 92dc8b3..13568e1 100644 (file)
@@ -1,5 +1,5 @@
 # $FreeBSD: src/lib/libpthread/pthread.map,v 1.13 2004/09/26 06:50:14 deischen Exp $
-# $DragonFly: src/lib/libthread_xu/pthread.map,v 1.3 2005/05/03 07:29:04 joerg Exp $
+# $DragonFly: src/lib/libthread_xu/pthread.map,v 1.4 2005/05/07 09:29:46 davidxu Exp $
 
 LIBTHREAD_1_0 {
 global:
@@ -346,22 +346,24 @@ global:
 
        # Debugger needs these.
        _libthread_xu_debug;
-       _thread_inited;
        _thread_active_threads;
+       _thread_bp_create;
+       _thread_bp_death;
+       _thread_event_mask;
        _thread_keytable;
+       _thread_last_event;
        _thread_list;
        _thread_max_keys;
        _thread_off_attr_flags;
-       _thread_off_linkmap;
-       _thread_off_next;
-       _thread_off_tcb;
-       _thread_off_tid;
+       _thread_off_event_buf;
+       _thread_off_event_mask;
        _thread_off_key_allocated;
        _thread_off_key_destructor;
+       _thread_off_next;
+       _thread_off_report_events;
        _thread_off_state;
-       _thread_off_thr_locklevel;
-       _thread_off_tlsindex;
-       _thread_off_isdead;
+       _thread_off_tcb;
+       _thread_off_tid;
        _thread_size_key;
        _thread_state_running;
        _thread_state_zoombie;
index 853c6fb..14ded29 100644 (file)
@@ -1,4 +1,4 @@
-# $DragonFly: src/lib/libthread_xu/thread/Makefile.inc,v 1.3 2005/05/03 07:29:04 joerg Exp $
+# $DragonFly: src/lib/libthread_xu/thread/Makefile.inc,v 1.4 2005/05/07 09:29:46 davidxu Exp $
 
 # thr sources
 .PATH: ${.CURDIR}/thread
@@ -15,6 +15,7 @@ SRCS+= \
        thr_create.c \
        thr_detach.c \
        thr_equal.c \
+       thr_event.c \
        thr_exit.c \
        thr_fork.c \
        thr_getprio.c \
index 191309a..3144d0e 100644 (file)
@@ -32,7 +32,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/lib/libpthread/thread/thr_create.c,v 1.58 2004/10/23 23:28:36 davidxu Exp $
- * $DragonFly: src/lib/libthread_xu/thread/thr_create.c,v 1.3 2005/03/29 19:26:20 joerg Exp $
+ * $DragonFly: src/lib/libthread_xu/thread/thr_create.c,v 1.4 2005/05/07 09:29:46 davidxu Exp $
  */
 #include <errno.h>
 #include <stdlib.h>
@@ -70,7 +70,7 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
        void *stack;
        sigset_t sigmask, oldsigmask;
        struct pthread *curthread, *new_thread;
-       int ret = 0;
+       int ret = 0, locked;
 
        _thr_check_init();
 
@@ -165,6 +165,11 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
        _thr_link(curthread, new_thread);
        /* Return thread pointer eariler so that new thread can use it. */
        (*thread) = new_thread;
+       if (SHOULD_REPORT_EVENT(curthread, TD_CREATE)) {
+               THR_THREAD_LOCK(curthread, new_thread);
+               locked = 1;
+       } else
+               locked = 0;
        /* Schedule the new thread. */
        stack = (char *)new_thread->attr.stackaddr_attr +
                        new_thread->attr.stacksize_attr;
@@ -185,10 +190,15 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
                ret = EAGAIN;
        }
        if (ret != 0) {
+               if (locked)
+                       THR_THREAD_UNLOCK(curthread, new_thread);
                _thr_unlink(curthread, new_thread);
                free_thread(curthread, new_thread);
                (*thread) = 0;
                ret = EAGAIN;
+       } else if (locked) {
+               _thr_report_creation(curthread, new_thread);
+               THR_THREAD_UNLOCK(curthread, new_thread);
        }
        return (ret);
 }
@@ -240,6 +250,9 @@ thread_start(void *arg)
        start_arg->started = 1;
        _thr_umtx_wake(&start_arg->started, 1);
 
+       THR_LOCK(curthread);
+       THR_UNLOCK(curthread);
+
        /* Thread was created with all signals blocked, unblock them. */
        __sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
 
diff --git a/lib/libthread_xu/thread/thr_event.c b/lib/libthread_xu/thread/thr_event.c
new file mode 100644 (file)
index 0000000..55fcf72
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2005 David Xu
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $DragonFly: src/lib/libthread_xu/thread/thr_event.c,v 1.1 2005/05/07 09:29:46 davidxu Exp $
+ */
+
+#include "thr_private.h"
+
+void
+_thread_bp_create(void)
+{
+}
+
+void
+_thread_bp_death(void)
+{
+}
+
+void
+_thr_report_creation(struct pthread *curthread, struct pthread *newthread)
+{
+       curthread->event_buf.event = TD_CREATE;
+       curthread->event_buf.th_p = (td_thrhandle_t *)newthread;
+       curthread->event_buf.data = 0;
+       THR_UMTX_LOCK(curthread, &_thr_event_lock);
+       _thread_last_event = curthread;
+       _thread_bp_create();
+       _thread_last_event = NULL;
+       THR_UMTX_UNLOCK(curthread, &_thr_event_lock);
+}
+
+void
+_thr_report_death(struct pthread *curthread)
+{
+       curthread->event_buf.event = TD_DEATH;
+       curthread->event_buf.th_p = (td_thrhandle_t *)curthread;
+       curthread->event_buf.data = 0;
+       THR_UMTX_LOCK(curthread, &_thr_event_lock);
+       _thread_last_event = curthread;
+       _thread_bp_death();
+       _thread_last_event = NULL;
+       THR_UMTX_UNLOCK(curthread, &_thr_event_lock);
+}
index f7755e6..c7a5b8d 100644 (file)
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/lib/libpthread/thread/thr_exit.c,v 1.39 2004/10/23 23:37:54 davidxu Exp $
- * $DragonFly: src/lib/libthread_xu/thread/thr_exit.c,v 1.2 2005/03/29 19:26:20 joerg Exp $
+ * $DragonFly: src/lib/libthread_xu/thread/thr_exit.c,v 1.3 2005/05/07 09:29:46 davidxu Exp $
  */
 
 #include <machine/tls.h>
@@ -143,6 +143,8 @@ _pthread_exit(void *status)
         * by userland GC code.
         */
        curthread->terminated = 1;
+       if (SHOULD_REPORT_EVENT(curthread, TD_DEATH))
+               _thr_report_death(curthread);
        _exit(0);
        PANIC("thr_exit() returned");
        /* Never reach! */
index b5859da..8723dd3 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/lib/libpthread/thread/thr_init.c,v 1.66 2004/08/21 11:49:19 davidxu Exp $
- * $DragonFly: src/lib/libthread_xu/thread/thr_init.c,v 1.3 2005/03/29 19:26:20 joerg Exp $
+ * $DragonFly: src/lib/libthread_xu/thread/thr_init.c,v 1.4 2005/05/07 09:29:46 davidxu Exp $
  */
 
 /* Allocate space for global thread variables here: */
@@ -300,6 +300,8 @@ _libpthread_init(struct pthread *curthread)
                _thr_initial = curthread;
                SIGDELSET(oldset, SIGCANCEL);
                __sys_sigprocmask(SIG_SETMASK, &oldset, NULL);
+               if (td_eventismember(&_thread_event_mask, TD_CREATE))
+                       _thr_report_creation(curthread, curthread);
        }
 }
 
@@ -376,6 +378,7 @@ init_private(void)
        _thr_umtx_init(&_rwlock_static_lock);
        _thr_umtx_init(&_keytable_lock);
        _thr_umtx_init(&_thr_atfork_lock);
+       _thr_umtx_init(&_thr_event_lock);
        _thr_spinlock_init();
        _thr_list_init();
 
index 282a1c3..17a5fc4 100644 (file)
@@ -32,7 +32,7 @@
  * Private thread definitions for the uthread kernel.
  *
  * $FreeBSD: src/lib/libpthread/thread/thr_private.h,v 1.120 2004/11/01 10:49:34 davidxu Exp $
- * $DragonFly: src/lib/libthread_xu/thread/thr_private.h,v 1.5 2005/05/07 07:50:51 davidxu Exp $
+ * $DragonFly: src/lib/libthread_xu/thread/thr_private.h,v 1.6 2005/05/07 09:29:46 davidxu Exp $
  */
 
 #ifndef _THR_PRIVATE_H
@@ -57,6 +57,7 @@
 
 #include "pthread_md.h"
 #include "thr_umtx.h"
+#include "thread_db.h"
 
 /*
  * Evaluate the storage class specifier.
@@ -502,6 +503,15 @@ struct pthread {
 
        /* Cleanup handlers Link List */
        struct pthread_cleanup *cleanup;
+
+       /* Enable event reporting */
+       int                     report_events;
+       
+       /* Event mask */
+       td_thr_events_t         event_mask;
+       
+       /* Event */
+       td_event_msg_t          event_buf;
 };
 
 #define THR_UMTX_TRYLOCK(thrd, lck)                    \
@@ -584,6 +594,10 @@ do {                                                               \
 
 #define        THR_IN_SYNCQ(thrd)      (((thrd)->sflags & THR_FLAGS_IN_SYNCQ) != 0)
 
+#define SHOULD_REPORT_EVENT(curthr, e)                 \
+       (curthr->report_events &&                       \
+        (((curthr)->event_mask | _thread_event_mask ) & e) != 0)
+
 extern int __isthreaded;
 
 /*
@@ -592,9 +606,12 @@ extern int __isthreaded;
 
 SCLASS void            *_usrstack      SCLASS_PRESET(NULL);
 SCLASS struct pthread  *_thr_initial   SCLASS_PRESET(NULL);
+SCLASS int             _thread_scope_system    SCLASS_PRESET(0);
+
 /* For debugger */
 SCLASS int             _libthread_xu_debug     SCLASS_PRESET(0);
-SCLASS int             _thread_scope_system    SCLASS_PRESET(0);
+SCLASS int             _thread_event_mask      SCLASS_PRESET(0);
+SCLASS struct pthread  *_thread_last_event;
 
 /* List of all threads: */
 SCLASS TAILQ_HEAD(, pthread)   _thread_list
@@ -654,6 +671,7 @@ SCLASS umtx_t               _cond_static_lock;
 SCLASS umtx_t          _rwlock_static_lock;
 SCLASS umtx_t          _keytable_lock;
 SCLASS umtx_t          _thr_list_lock;
+SCLASS umtx_t          _thr_event_lock;
 
 /* Undefine the storage class and preset specifiers: */
 #undef  SCLASS
@@ -730,6 +748,11 @@ void       _thr_unlink(struct pthread *curthread, struct pthread *thread);
 void   _thr_suspend_check(struct pthread *curthread);
 void   _thr_assert_lock_level() __dead2;
 int    _thr_get_tid(void);
+void   _thr_report_creation(struct pthread *curthread,
+                          struct pthread *newthread);
+void   _thr_report_death(struct pthread *curthread);
+void   _thread_bp_create(void);
+void   _thread_bp_death(void);
 
 /* #include <sys/aio.h> */
 #ifdef _SYS_AIO_H_
index 1e4b3e5..10f1299 100644 (file)
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/lib/libpthread/thread/thr_symbols.c,v 1.1 2004/08/16 03:25:07 davidxu Exp $
- * $DragonFly: src/lib/libthread_xu/thread/thr_symbols.c,v 1.2 2005/03/29 19:26:20 joerg Exp $
+ * $DragonFly: src/lib/libthread_xu/thread/thr_symbols.c,v 1.3 2005/05/07 09:29:46 davidxu Exp $
  */
 
 #include <stddef.h>
 
 /* A collection of symbols needed by debugger */
 
-int _thread_off_tcb = offsetof(struct pthread, tcb);
-int _thread_off_tid = offsetof(struct pthread, tid);
-int _thread_off_next = offsetof(struct pthread, tle.tqe_next);
+int _thread_max_keys = PTHREAD_KEYS_MAX;
 int _thread_off_attr_flags = offsetof(struct pthread, attr.flags);
-int _thread_off_thr_locklevel = offsetof(struct pthread, locklevel);
-int _thread_off_isdead = offsetof(struct pthread, terminated);
-int _thread_size_key = sizeof(struct pthread_key);
+int _thread_off_event_buf = offsetof(struct pthread, event_buf);
+int _thread_off_event_mask = offsetof(struct pthread, event_mask);
 int _thread_off_key_allocated = offsetof(struct pthread_key, allocated);
 int _thread_off_key_destructor = offsetof(struct pthread_key, destructor);
-int _thread_max_keys = PTHREAD_KEYS_MAX;
+int _thread_off_next = offsetof(struct pthread, tle.tqe_next);
+int _thread_off_report_events = offsetof(struct pthread, report_events);
 int _thread_off_state = offsetof(struct pthread, state);
+int _thread_off_tcb = offsetof(struct pthread, tcb);
+int _thread_off_tid = offsetof(struct pthread, tid);
+int _thread_size_key = sizeof(struct pthread_key);
 int _thread_state_running = PS_RUNNING;
 int _thread_state_zoombie = PS_DEAD;
-#ifndef __DragonFly__
-int _thread_off_linkmap = offsetof(Obj_Entry, linkmap);
-int _thread_off_tlsindex = offsetof(Obj_Entry, tlsindex);
-#endif