diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | linuxthreads/ChangeLog | 18 | ||||
-rw-r--r-- | linuxthreads/Makefile | 2 | ||||
-rw-r--r-- | linuxthreads/events.c | 35 | ||||
-rw-r--r-- | linuxthreads/internals.h | 17 | ||||
-rw-r--r-- | linuxthreads/join.c | 20 | ||||
-rw-r--r-- | linuxthreads/manager.c | 95 | ||||
-rw-r--r-- | linuxthreads_db/ChangeLog | 28 | ||||
-rw-r--r-- | linuxthreads_db/td_ta_event_addr.c | 45 | ||||
-rw-r--r-- | linuxthreads_db/td_ta_new.c | 11 | ||||
-rw-r--r-- | linuxthreads_db/td_ta_set_event.c | 37 | ||||
-rw-r--r-- | linuxthreads_db/td_thr_event_enable.c | 19 | ||||
-rw-r--r-- | linuxthreads_db/td_thr_event_getmsg.c | 34 | ||||
-rw-r--r-- | linuxthreads_db/td_thr_getfpregs.c | 8 | ||||
-rw-r--r-- | linuxthreads_db/td_thr_getgregs.c | 8 | ||||
-rw-r--r-- | linuxthreads_db/td_thr_set_event.c | 18 | ||||
-rw-r--r-- | linuxthreads_db/td_thr_setfpregs.c | 6 | ||||
-rw-r--r-- | linuxthreads_db/td_thr_setgregs.c | 6 | ||||
-rw-r--r-- | linuxthreads_db/thread_db.h | 24 | ||||
-rw-r--r-- | linuxthreads_db/thread_dbP.h | 3 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/i386/sys/procfs.h | 8 |
21 files changed, 395 insertions, 52 deletions
@@ -1,3 +1,8 @@ +1999-11-02 Ulrich Drepper <drepper@cygnus.com> + + * sysdeps/unix/sysv/linux/i386/sys/procfs.h: Include sys/ucontext.h + instead of duplicating definitions. + 1999-11-01 Ulrich Drepper <drepper@cygnus.com> * sysdeps/unix/sysv/linux/alpha/sys/procfs.h: Add more pr* types used diff --git a/linuxthreads/ChangeLog b/linuxthreads/ChangeLog index 53aea3f..6d00c17 100644 --- a/linuxthreads/ChangeLog +++ b/linuxthreads/ChangeLog @@ -1,3 +1,21 @@ +1999-11-02 Ulrich Drepper <drepper@cygnus.com> + + * Makefile (libpthread-routines): Add events. + * events.c: New file. + * internals.h: Protect against multiple inclusion. + Include thread_dbP.h header. + (struct _pthread_descr_struct): Add new fields p_report_events and + p_eventbuf. + Declare event reporting functions. + * join.c (pthread_exit): Signal event if this is wanted. + * manager.c (__pthread_threads_events): New variable. + (pthread_handle_create): Take new parameters with event information. + Signal TD_CREATE event if wanted. + (__pthread_manager): Adjust pthread_handle_create call. + (pthread_start_thread_event): New function. Block until manager is + finished and then call pthread_start_thread. + (pthread_exited): Signal TD_REAP event if wanted. + 1999-10-26 Ulrich Drepper <drepper@cygnus.com> * restart.h (suspend_with_cancellation): Rewrite as a macro. diff --git a/linuxthreads/Makefile b/linuxthreads/Makefile index 8268666..d2b1542 100644 --- a/linuxthreads/Makefile +++ b/linuxthreads/Makefile @@ -35,7 +35,7 @@ extra-libs-others := $(extra-libs) libpthread-routines := attr cancel condvar join manager mutex ptfork \ ptlongjmp pthread signals specific errno lockfile \ semaphore spinlock wrapsyscall rwlock pt-machine \ - oldsemaphore + oldsemaphore events vpath %.c Examples tests = ex1 ex2 ex3 ex4 ex5 ex6 diff --git a/linuxthreads/events.c b/linuxthreads/events.c new file mode 100644 index 0000000..e5be3d9 --- /dev/null +++ b/linuxthreads/events.c @@ -0,0 +1,35 @@ +/* Event functions used while debugging. + Copyright (C) 1999 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* The functions contained here do nothing, they just return. */ + +void +__linuxthreads_create_event (void) +{ +} + +void +__linuxthreads_death_event (void) +{ +} + +void +__linuxthreads_reap_event (void) +{ +} diff --git a/linuxthreads/internals.h b/linuxthreads/internals.h index 0851223..531b042 100644 --- a/linuxthreads/internals.h +++ b/linuxthreads/internals.h @@ -12,6 +12,9 @@ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU Library General Public License for more details. */ +#ifndef _INTERNALS_H +#define _INTERNALS_H 1 + /* Internal data structures */ /* Includes */ @@ -25,6 +28,7 @@ #include "pt-machine.h" #include "semaphore.h" +#include "../linuxthreads_db/thread_dbP.h" #ifndef THREAD_GETMEM # define THREAD_GETMEM(descr, member) descr->member @@ -115,6 +119,9 @@ struct _pthread_descr_struct { size_t p_guardsize; /* size of guard area */ pthread_descr p_self; /* Pointer to this structure */ int p_nr; /* Index of descriptor in __pthread_handles */ + /* New elements must be added at the end. */ + int p_report_events; /* Nonzero if events must be reported. */ + td_eventbuf_t p_eventbuf; /* Data for event. */ } __attribute__ ((aligned(32))); /* We need to align the structure so that doubles are aligned properly. This is 8 bytes on MIPS and 16 bytes on MIPS64. @@ -219,6 +226,9 @@ extern int __pthread_exit_requested, __pthread_exit_code; extern volatile int __pthread_threads_debug; +/* Globally enabled events. */ +extern volatile td_thr_events_t __pthread_threads_events; + /* Return the handle corresponding to a thread id */ static inline pthread_handle thread_handle(pthread_t id) @@ -364,3 +374,10 @@ extern ssize_t __libc_write (int fd, const void *buf, size_t count); /* Prototypes for some of the new semaphore functions. */ extern int __new_sem_post (sem_t * sem); + +/* The functions called the signal events. */ +extern void __linuxthreads_create_event (void); +extern void __linuxthreads_death_event (void); +extern void __linuxthreads_reap_event (void); + +#endif /* internals.h */ diff --git a/linuxthreads/join.c b/linuxthreads/join.c index 42eb033..a2c8b20 100644 --- a/linuxthreads/join.c +++ b/linuxthreads/join.c @@ -39,6 +39,26 @@ void pthread_exit(void * retval) THREAD_SETMEM(self, p_retval, retval); /* Say that we've terminated */ THREAD_SETMEM(self, p_terminated, 1); + /* See whether we have to signal the death. */ + if (THREAD_GETMEM(self, p_report_events)) + { + /* See whether TD_DEATH is in any of the mask. */ + int idx = __td_eventword (TD_DEATH); + uint32_t mask = __td_eventmask (TD_DEATH); + + if ((mask & (__pthread_threads_events.event_bits[idx] + | THREAD_GETMEM(self, + p_eventbuf.eventmask).event_bits[idx])) + != 0) + { + /* Yep, we have to signal the death. */ + THREAD_SETMEM(self, p_eventbuf.eventnum, TD_DEATH); + THREAD_SETMEM(self, p_eventbuf.eventdata, self); + + /* Now call the function to signal the event. */ + __linuxthreads_death_event(); + } + } /* See if someone is joining on us */ joining = THREAD_GETMEM(self, p_joining); __pthread_unlock(THREAD_GETMEM(self, p_lock)); diff --git a/linuxthreads/manager.c b/linuxthreads/manager.c index daa12bc..3b70097 100644 --- a/linuxthreads/manager.c +++ b/linuxthreads/manager.c @@ -43,14 +43,17 @@ const int __linuxthreads_pthread_threads_max = PTHREAD_THREADS_MAX; /* Indicate whether at least one thread has a user-defined stack (if 1), or if all threads have stacks supplied by LinuxThreads (if 0). */ -int __pthread_nonstandard_stacks = 0; +int __pthread_nonstandard_stacks; /* Number of active entries in __pthread_handles (used by gdb) */ volatile int __pthread_handles_num = 2; /* Whether to use debugger additional actions for thread creation (set to 1 by gdb) */ -volatile int __pthread_threads_debug = 0; +volatile int __pthread_threads_debug; + +/* Globally enabled events. */ +volatile td_thr_events_t __pthread_threads_events; /* Mapping from stack segment to thread descriptor. */ /* Stack segment numbers are also indices into the __pthread_handles array. */ @@ -80,7 +83,9 @@ static pthread_t pthread_threads_counter = 0; static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr, void * (*start_routine)(void *), void *arg, - sigset_t *mask, int father_pid); + sigset_t *mask, int father_pid, + int report_events, + td_thr_events_t *event_maskp); static void pthread_handle_free(pthread_t th_id); static void pthread_handle_exit(pthread_descr issuing_thread, int exitcode); static void pthread_reap_children(void); @@ -141,7 +146,9 @@ int __pthread_manager(void *arg) request.req_args.create.fn, request.req_args.create.arg, &request.req_args.create.mask, - request.req_thread->p_pid); + request.req_thread->p_pid, + request.req_thread->p_report_events, + &request.req_thread->p_eventbuf.eventmask); restart(request.req_thread); break; case REQ_FREE: @@ -220,6 +227,19 @@ static int pthread_start_thread(void *arg) return 0; } +static int pthread_start_thread_event(void *arg) +{ + pthread_descr self = thread_self (); + + /* Get the lock the manager will free once all is correctly set up. */ + __pthread_lock (THREAD_GETMEM(self, p_lock), NULL); + /* Free it immediately. */ + __pthread_unlock (THREAD_GETMEM(self, p_lock)); + + /* Continue with the real function. */ + return pthread_start_thread (arg); +} + static int pthread_allocate_stack(const pthread_attr_t *attr, pthread_descr default_new_thread, int pagesize, @@ -297,7 +317,9 @@ static int pthread_allocate_stack(const pthread_attr_t *attr, static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr, void * (*start_routine)(void *), void *arg, - sigset_t * mask, int father_pid) + sigset_t * mask, int father_pid, + int report_events, + td_thr_events_t *event_maskp) { size_t sseg; int pid; @@ -372,10 +394,47 @@ static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr, new_thread->p_start_args.mask = *mask; /* 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 | - __pthread_sig_cancel, new_thread); + /* Do the cloning. We have to use two different functions depending + on whether we are debugging or not. */ + pid = 0; /* Note that the thread never can have PID zero. */ + if (report_events) + { + /* See whether the TD_CREATE event bit is set in any of the + masks. */ + int idx = __td_eventword (TD_CREATE); + uint32_t mask = __td_eventmask (TD_CREATE); + + if ((mask & (__pthread_threads_events.event_bits[idx] + | event_maskp->event_bits[idx])) != 0) + { + /* Lock the mutex the child will use now so that it will stop. */ + __pthread_lock(new_thread->p_lock, NULL); + + /* We have to report this event. */ + pid = __clone(pthread_start_thread_event, (void **) new_thread, + CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | + __pthread_sig_cancel, new_thread); + if (pid != -1) + { + /* Now fill in the information about the new thread in + the newly created thread's data structure. We cannot let + the new thread do this since we don't know whether it was + already scheduled when we send the event. */ + new_thread->p_eventbuf.eventdata = new_thread; + new_thread->p_eventbuf.eventnum = TD_CREATE; + + /* Now call the function which signals the event. */ + __linuxthreads_create_event (); + + /* Now restart the thread. */ + __pthread_unlock(new_thread->p_lock); + } + } + } + if (pid == 0) + pid = __clone(pthread_start_thread, (void **) new_thread, + CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | + __pthread_sig_cancel, new_thread); /* Check if cloning succeeded */ if (pid == -1) { /* Free the stack if we allocated it */ @@ -451,6 +510,24 @@ static void pthread_exited(pid_t pid) /* Mark thread as exited, and if detached, free its resources */ __pthread_lock(th->p_lock, NULL); th->p_exited = 1; + /* If we have to signal this event do it now. */ + if (th->p_report_events) + { + /* See whether TD_DEATH is in any of the mask. */ + int idx = __td_eventword (TD_REAP); + uint32_t mask = __td_eventmask (TD_REAP); + + if ((mask & (__pthread_threads_events.event_bits[idx] + | th->p_eventbuf.eventmask.event_bits[idx])) != 0) + { + /* Yep, we have to signal the death. */ + th->p_eventbuf.eventnum = TD_DEATH; + th->p_eventbuf.eventdata = th; + + /* Now call the function to signal the event. */ + __linuxthreads_reap_event(); + } + } detached = th->p_detached; __pthread_unlock(th->p_lock); if (detached) diff --git a/linuxthreads_db/ChangeLog b/linuxthreads_db/ChangeLog index e7dd8f6..723f9a4 100644 --- a/linuxthreads_db/ChangeLog +++ b/linuxthreads_db/ChangeLog @@ -1,16 +1,28 @@ +1999-11-02 Ulrich Drepper <drepper@cygnus.com> + + * td_ta_new.c: Don't test for __pthread_threads_debug. Get address + of __pthread_threads_events and fail if this is not possible. + * td_ta_event_addr.c: Implement. + * td_thr_event_enable.c: Implement. + * td_thr_event_getmsg.c: Implement. + * td_thr_set_event.c: Implement. + * td_ta_set_event.c: New file. + * thread_db.h (td_eventbuf_t): Define. + Declare td_ta_set_event. + * thread_dbP.h (struct td_thragent): Add pthread_threads_eventsp. + + * td_thr_getfpregs.c: For terminated threads return empty structure. + * td_thr_getgregs.c: Likewise. + * td_thr_setfpregs.c: Likewise. + * td_thr_setgregs.c: Likewise. + 1999-11-01 Ulrich Drepper <drepper@cygnus.com> - * sysdeps/unix/sysv/linux/alpha/sys/procfs.h: Add more pr* types used - by the debugger. - * sysdeps/unix/sysv/linux/arm/sys/procfs.h: Likewise. - * sysdeps/unix/sysv/linux/i386/sys/procfs.h: Likewise. - * sysdeps/unix/sysv/linux/mips/sys/procfs.h: Likewise. - * sysdeps/unix/sysv/linux/powerpc/sys/procfs.h: Likewise. - * sysdeps/unix/sysv/linux/sys/procfs.h: Likewise. * thread_db.h: Shuffle types around to make things work for gdb. * thread_dbP.h: Include proc_service.h before thread_db.h. - * td_ta_new.c: It's TD_NOLIBTHREAD, not TD_LIBTHREAD. + * thread_db.h: It's TD_NOLIBTHREAD, not TD_LIBTHREAD. + * td_ta_new.c: Likewise. 1999-10-14 Ulrich Drepper <drepper@cygnus.com> diff --git a/linuxthreads_db/td_ta_event_addr.c b/linuxthreads_db/td_ta_event_addr.c index 6d6d4a8..4edd54c 100644 --- a/linuxthreads_db/td_ta_event_addr.c +++ b/linuxthreads_db/td_ta_event_addr.c @@ -18,13 +18,54 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include <gnu/lib-names.h> + #include "thread_dbP.h" td_err_e td_ta_event_addr (const td_thragent_t *ta, td_event_e event, td_notify_t *addr) { - /* XXX We have to figure out what has to be done. */ + td_err_e res = TD_NOEVENT; + const char *symbol = NULL; + LOG (__FUNCTION__); - return TD_NOCAPAB; + + switch (event) + { + case TD_CREATE: + symbol = "__linuxthreads_create_event"; + break; + + case TD_DEATH: + symbol = "__linuxthreads_death_event"; + break; + + case TD_REAP: + symbol = "__linuxthreads_reap_event"; + break; + + default: + /* Event cannot be handled. */ + break; + } + + /* Now get the address. */ + if (symbol != NULL) + { + psaddr_t taddr; + + if (ps_pglobal_lookup (ta->ph, LIBPTHREAD_SO, symbol, &taddr) == PS_OK) + { + /* Success, we got the address. */ + addr->type = NOTIFY_BPT; + addr->u.bptaddr = taddr; + + res = TD_OK; + } + else + res = TD_ERR; + } + + return res; } diff --git a/linuxthreads_db/td_ta_new.c b/linuxthreads_db/td_ta_new.c index 8b22b75..eeaf0cb 100644 --- a/linuxthreads_db/td_ta_new.c +++ b/linuxthreads_db/td_ta_new.c @@ -32,9 +32,11 @@ td_ta_new (struct ps_prochandle *ps, td_thragent_t **ta) LOG (__FUNCTION__); - /* See whether the library contains the necessary symbols. */ - if (ps_pglobal_lookup (ps, LIBPTHREAD_SO, "__pthread_threads_debug", - &addr) != PS_OK) + /* Get the global event mask. This is one of the variables which + are new in the thread library to enable debugging. If it is + not available we cannot debug. */ + if (ps_pglobal_lookup (ps, LIBPTHREAD_SO, + "__pthread_threads_events", &addr) != PS_OK) return TD_NOLIBTHREAD; /* Fill in the appropriate information. */ @@ -46,6 +48,9 @@ td_ta_new (struct ps_prochandle *ps, td_thragent_t **ta) back into the debugger. */ (*ta)->ph = ps; + /* Remember the address. */ + (*ta)->pthread_threads_eventsp = (td_thr_events_t *) addr; + /* See whether the library contains the necessary symbols. */ if (ps_pglobal_lookup (ps, LIBPTHREAD_SO, "__pthread_handles", &addr) != PS_OK) diff --git a/linuxthreads_db/td_ta_set_event.c b/linuxthreads_db/td_ta_set_event.c new file mode 100644 index 0000000..10adbdf --- /dev/null +++ b/linuxthreads_db/td_ta_set_event.c @@ -0,0 +1,37 @@ +/* Globally enable events. + Copyright (C) 1999 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include "thread_dbP.h" + + +td_err_e +td_ta_set_event (ta, event) + const td_thragent_t *ta; + td_thr_events_t *event; +{ + LOG (__FUNCTION__); + + /* Write the new value into the thread data structure. */ + if (ps_pdwrite (ta->ph, ta->pthread_threads_eventsp, + event, sizeof (td_thrhandle_t)) != PS_OK) + return TD_ERR; /* XXX Other error value? */ + + return TD_OK; +} diff --git a/linuxthreads_db/td_thr_event_enable.c b/linuxthreads_db/td_thr_event_enable.c index d6db6a7..79e7d3a 100644 --- a/linuxthreads_db/td_thr_event_enable.c +++ b/linuxthreads_db/td_thr_event_enable.c @@ -1,4 +1,4 @@ -/* Enable event reporting. +/* Enable event process-wide. Copyright (C) 1999 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999. @@ -18,13 +18,24 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include <stddef.h> + #include "thread_dbP.h" td_err_e -td_thr_event_enable (const td_thrhandle_t *th, int event) +td_thr_event_enable (th, onoff) + const td_thrhandle_t *th; + int onoff; { - /* XXX We have to figure out what has to be done. */ LOG (__FUNCTION__); - return TD_NOCAPAB; + + /* Write the new value into the thread data structure. */ + if (ps_pdwrite (th->th_ta_p->ph, + ((char *) th->th_unique + + offsetof (struct _pthread_descr_struct, p_report_events)), + &onoff, sizeof (int)) != PS_OK) + return TD_ERR; /* XXX Other error value? */ + + return TD_OK; } diff --git a/linuxthreads_db/td_thr_event_getmsg.c b/linuxthreads_db/td_thr_event_getmsg.c index 0fa4cd6..4812ece 100644 --- a/linuxthreads_db/td_thr_event_getmsg.c +++ b/linuxthreads_db/td_thr_event_getmsg.c @@ -18,13 +18,43 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include <stddef.h> +#include <string.h> + #include "thread_dbP.h" td_err_e td_thr_event_getmsg (const td_thrhandle_t *th, td_event_msg_t *msg) { - /* XXX We have to figure out what has to be done. */ + td_eventbuf_t event; + LOG (__FUNCTION__); - return TD_NOCAPAB; + + /* Read the even structure from the target. */ + if (ps_pdread (th->th_ta_p->ph, + ((char *) th->th_unique + + offsetof (struct _pthread_descr_struct, p_eventbuf)), + &event, sizeof (td_eventbuf_t)) != PS_OK) + return TD_ERR; /* XXX Other error value? */ + + /* Check whether an event occurred. */ + if (event.eventnum == TD_EVENT_NONE) + /* Nothing. */ + return TD_NOMSG; + + /* Fill the user's data structure. */ + msg->event = event.eventnum; + msg->th_p = th; + msg->msg.data = (uintptr_t) event.eventdata; + + /* And clear the event message in the target. */ + memset (&event, '\0', sizeof (td_eventbuf_t)); + if (ps_pdwrite (th->th_ta_p->ph, + ((char *) th->th_unique + + offsetof (struct _pthread_descr_struct, p_eventbuf)), + &event, sizeof (td_eventbuf_t)) != PS_OK) + return TD_ERR; /* XXX Other error value? */ + + return TD_OK; } diff --git a/linuxthreads_db/td_thr_getfpregs.c b/linuxthreads_db/td_thr_getfpregs.c index 33bd95e..e6635d2 100644 --- a/linuxthreads_db/td_thr_getfpregs.c +++ b/linuxthreads_db/td_thr_getfpregs.c @@ -28,12 +28,16 @@ td_thr_getfpregs (const td_thrhandle_t *th, prfpregset_t *regset) LOG (__FUNCTION__); - /* We have to get the PID for this thread. */ + /* We have to get the state and the PID for this thread. */ if (ps_pdread (th->th_ta_p->ph, th->th_unique, &pds, sizeof (struct _pthread_descr_struct)) != PS_OK) return TD_ERR; - if (ps_lgetfpregs (th->th_ta_p->ph, pds.p_pid, regset) != PS_OK) + /* If the thread already terminated we return all zeroes. */ + if (pds.p_terminated) + memset (regset, '\0', sizeof (*regset)); + /* Otherwise get the register content through the callback. */ + else if (ps_lgetfpregs (th->th_ta_p->ph, pds.p_pid, regset) != PS_OK) return TD_ERR; return TD_OK; diff --git a/linuxthreads_db/td_thr_getgregs.c b/linuxthreads_db/td_thr_getgregs.c index e8a87b1..549c7d8 100644 --- a/linuxthreads_db/td_thr_getgregs.c +++ b/linuxthreads_db/td_thr_getgregs.c @@ -28,12 +28,16 @@ td_thr_getgregs (const td_thrhandle_t *th, prgregset_t gregs) LOG (__FUNCTION__); - /* We have to get the PID for this thread. */ + /* We have to get the state and the PID for this thread. */ if (ps_pdread (th->th_ta_p->ph, th->th_unique, &pds, sizeof (struct _pthread_descr_struct)) != PS_OK) return TD_ERR; - if (ps_lgetregs (th->th_ta_p->ph, pds.p_pid, gregs) != PS_OK) + /* If the thread already terminated we return all zeroes. */ + if (pds.p_terminated) + memset (gregs, '\0', sizeof (gregs)); + /* Otherwise get the register content through the callback. */ + else if (ps_lgetregs (th->th_ta_p->ph, pds.p_pid, gregs) != PS_OK) return TD_ERR; return TD_OK; diff --git a/linuxthreads_db/td_thr_set_event.c b/linuxthreads_db/td_thr_set_event.c index 9454309..e6b6cbc 100644 --- a/linuxthreads_db/td_thr_set_event.c +++ b/linuxthreads_db/td_thr_set_event.c @@ -18,13 +18,25 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include <stddef.h> + #include "thread_dbP.h" td_err_e -td_thr_set_event (const td_thrhandle_t *th, td_thr_events_t *event) +td_thr_set_event (th, event) + const td_thrhandle_t *th; + td_thr_events_t *event; { - /* XXX We have to figure out what has to be done. */ LOG (__FUNCTION__); - return TD_NOCAPAB; + + /* Write the new value into the thread data structure. */ + if (ps_pdwrite (th->th_ta_p->ph, + ((char *) th->th_unique + + offsetof (struct _pthread_descr_struct, + p_eventbuf.eventmask)), + event, sizeof (td_thrhandle_t)) != PS_OK) + return TD_ERR; /* XXX Other error value? */ + + return TD_OK; } diff --git a/linuxthreads_db/td_thr_setfpregs.c b/linuxthreads_db/td_thr_setfpregs.c index a18e1ed..0c426b3 100644 --- a/linuxthreads_db/td_thr_setfpregs.c +++ b/linuxthreads_db/td_thr_setfpregs.c @@ -28,12 +28,14 @@ td_thr_setfpregs (const td_thrhandle_t *th, const prfpregset_t *fpregs) LOG (__FUNCTION__); - /* We have to get the PID for this thread. */ + /* We have to get the state and the PID for this thread. */ if (ps_pdread (th->th_ta_p->ph, th->th_unique, &pds, sizeof (struct _pthread_descr_struct)) != PS_OK) return TD_ERR; - if (ps_lsetfpregs (th->th_ta_p->ph, pds.p_pid, fpregs) != PS_OK) + /* Only set the registers if the thread hasn't yet terminated. */ + if (pds.p_terminated == 0 + && ps_lsetfpregs (th->th_ta_p->ph, pds.p_pid, fpregs) != PS_OK) return TD_ERR; return TD_OK; diff --git a/linuxthreads_db/td_thr_setgregs.c b/linuxthreads_db/td_thr_setgregs.c index 1de2d3c..72f95b1 100644 --- a/linuxthreads_db/td_thr_setgregs.c +++ b/linuxthreads_db/td_thr_setgregs.c @@ -28,12 +28,14 @@ td_thr_setgregs (const td_thrhandle_t *th, prgregset_t gregs) LOG (__FUNCTION__); - /* We have to get the PID for this thread. */ + /* We have to get the state and the PID for this thread. */ if (ps_pdread (th->th_ta_p->ph, th->th_unique, &pds, sizeof (struct _pthread_descr_struct)) != PS_OK) return TD_ERR; - if (ps_lsetregs (th->th_ta_p->ph, pds.p_pid, gregs) != PS_OK) + /* Only set the registers if the thread hasn't yet terminated. */ + if (pds.p_terminated == 0 + && ps_lsetregs (th->th_ta_p->ph, pds.p_pid, gregs) != PS_OK) return TD_ERR; return TD_OK; diff --git a/linuxthreads_db/thread_db.h b/linuxthreads_db/thread_db.h index 312237a..8e33a06 100644 --- a/linuxthreads_db/thread_db.h +++ b/linuxthreads_db/thread_db.h @@ -200,6 +200,14 @@ typedef struct td_event_msg } msg; } td_event_msg_t; +/* Structure containing event data available in each thread structure. */ +typedef struct +{ + td_thr_events_t eventmask; /* Mask of enabled events. */ + td_event_e eventnum; /* Number of last event. */ + void *eventdata; /* Data associated with event. */ +} td_eventbuf_t; + /* Gathered statistics about the process. */ typedef struct td_ta_stats @@ -228,10 +236,10 @@ typedef pthread_key_t thread_key_t; /* Callback for iteration over threads. */ -typedef int td_thr_iter_f __P ((const td_thrhandle_t *, void *)); +typedef int td_thr_iter_f (const td_thrhandle_t *, void *); /* Callback for iteration over thread local data. */ -typedef int td_key_iter_f __P ((thread_key_t, void (*) (void *), void *)); +typedef int td_key_iter_f (thread_key_t, void (*) (void *), void *); @@ -323,6 +331,10 @@ extern td_err_e td_ta_tsd_iter (const td_thragent_t *__ta, td_key_iter_f *__ki, extern td_err_e td_ta_event_addr (const td_thragent_t *__ta, td_event_e __event, td_notify_t *__ptr); +/* Enable EVENT for all threads. */ +extern td_err_e td_ta_set_event (const td_thragent_t *__ta, + td_thr_events_t *__event); + /* Set suggested concurrency level for process associated with TA. */ extern td_err_e td_ta_setconcurrency (const td_thragent_t *__ta, int __level); @@ -348,11 +360,11 @@ extern td_err_e td_thr_get_info (const td_thrhandle_t *__th, /* Retrieve floating-point register contents of process running thread TH. */ extern td_err_e td_thr_getfpregs (const td_thrhandle_t *__th, - fpregset_t *__regset); + prfpregset_t *__regset); /* Retrieve general register contents of process running thread TH. */ extern td_err_e td_thr_getgregs (const td_thrhandle_t *__th, - gregset_t __gregs); + prgregset_t __gregs); /* Retrieve extended register contents of process running thread TH. */ extern td_err_e td_thr_getxregs (const td_thrhandle_t *__th, void *__xregs); @@ -362,11 +374,11 @@ extern td_err_e td_thr_getxregsize (const td_thrhandle_t *__th, int *__sizep); /* Set floating-point register contents of process running thread TH. */ extern td_err_e td_thr_setfpregs (const td_thrhandle_t *__th, - const fpregset_t *__fpregs); + const prfpregset_t *__fpregs); /* Set general register contents of process running thread TH. */ extern td_err_e td_thr_setgregs (const td_thrhandle_t *__th, - gregset_t __gregs); + prgregset_t __gregs); /* Set extended register contents of process running thread TH. */ extern td_err_e td_thr_setxregs (const td_thrhandle_t *__th, diff --git a/linuxthreads_db/thread_dbP.h b/linuxthreads_db/thread_dbP.h index 0fd1c11..5c7fcde 100644 --- a/linuxthreads_db/thread_dbP.h +++ b/linuxthreads_db/thread_dbP.h @@ -38,6 +38,9 @@ struct td_thragent /* Sizeof struct _pthread_descr_struct. */ int sizeof_descr; + + /* Pointer to the `__pthread_threads_events' variable in the target. */ + psaddr_t pthread_threads_eventsp; }; diff --git a/sysdeps/unix/sysv/linux/i386/sys/procfs.h b/sysdeps/unix/sysv/linux/i386/sys/procfs.h index 9c5528e..06300eb 100644 --- a/sysdeps/unix/sysv/linux/i386/sys/procfs.h +++ b/sysdeps/unix/sysv/linux/i386/sys/procfs.h @@ -17,17 +17,17 @@ Boston, MA 02111-1307, USA. */ #ifndef _SYS_PROCFS_H - #define _SYS_PROCFS_H 1 -#include <features.h> /* This is somehow modelled after the file of the same name on SysVr4 systems. It provides a definition of the core file format for ELF used on Linux. */ +#include <features.h> #include <signal.h> #include <sys/time.h> #include <sys/types.h> +#include <sys/ucontext.h> #include <sys/user.h> #include <sys/elf.h> @@ -40,10 +40,6 @@ struct elf_siginfo int si_errno; /* Errno. */ }; -typedef elf_greg_t greg_t; -typedef elf_gregset_t gregset_t; -typedef elf_fpregset_t fpregset_t; -#define NGREG ELF_NGREG /* Definitions to generate Intel SVR4-like core files. These mostly have the same names as the SVR4 types with "elf_" tacked on the |