1 /* Iterate over a process's threads.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 1999.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include "thread_dbP.h"
22 #include <nptl/descr.h>
26 iterate_thread_list (const td_thragent_t
*ta
, td_thr_iter_f
*callback
,
27 void *cbdata_p
, td_thr_state_e state
, int ti_pri
,
31 td_err_e result
= TD_OK
;
34 XXX This is incomplete. Normally this test should be in the loop. */
35 if (state
!= TD_THR_ANY_STATE
)
38 if (ps_pdread (ta
->ph
, head
, &list
, sizeof (list_t
)) != PS_OK
)
39 return TD_ERR
; /* XXX Other error value? */
41 if (list
.next
== 0 && list
.prev
== 0 && head
== ta
->stack_user
)
43 /* __pthread_initialize_minimal has not run.
44 There is just the main thread to return. */
46 td_err_e err
= td_ta_map_lwp2thr (ta
, ps_getpid (ta
->ph
), &th
);
47 return (err
!= TD_OK
? err
48 : callback (&th
, cbdata_p
) != 0 ? TD_DBERR
: TD_OK
);
51 while (list
.next
!= head
)
53 psaddr_t addr
= ((psaddr_t
) list
.next
- offsetof (struct pthread
, list
));
56 if (ps_pdread (ta
->ph
, &((struct pthread
*) addr
)->schedpolicy
,
57 &schedpolicy
, sizeof (int)) != PS_OK
)
59 result
= TD_ERR
; /* XXX Other error value? */
63 struct sched_param schedparam
;
64 if (ps_pdread (ta
->ph
, &((struct pthread
*) addr
)->schedparam
,
65 &schedparam
, sizeof (struct sched_param
)) != PS_OK
)
67 result
= TD_ERR
; /* XXX Other error value? */
71 /* Now test whether this thread matches the specified
74 /* Only if the priority level is as high or higher. */
75 int descr_pri
= (schedpolicy
== SCHED_OTHER
76 ? 0 : schedparam
.sched_priority
);
77 if (descr_pri
>= ti_pri
)
79 /* XXX For now we ignore threads which are not running anymore.
80 The reason is that gdb tries to get the registers and fails.
81 In future we should have a special mode of the thread library
82 in which we keep the process around until the actual join
83 operation happened. */
85 if (ps_pdread (ta
->ph
, &((struct pthread
*) addr
)->cancelhandling
,
86 &cancelhandling
, sizeof (int)) != PS_OK
)
88 result
= TD_ERR
; /* XXX Other error value? */
92 if ((cancelhandling
& TERMINATED_BITMASK
) == 0)
94 /* Yep, it matches. Call the callback function. */
96 th
.th_ta_p
= (td_thragent_t
*) ta
;
98 if (callback (&th
, cbdata_p
) != 0)
103 /* Get the pointer to the next element. */
104 if (ps_pdread (ta
->ph
, &((struct pthread
*) addr
)->list
,
105 &list
, sizeof (list_t
)) != PS_OK
)
106 return TD_ERR
; /* XXX Other error value? */
114 td_ta_thr_iter (const td_thragent_t
*ta
, td_thr_iter_f
*callback
,
115 void *cbdata_p
, td_thr_state_e state
, int ti_pri
,
116 sigset_t
*ti_sigmask_p
, unsigned int ti_user_flags
)
118 LOG ("td_ta_thr_iter");
120 /* Test whether the TA parameter is ok. */
124 /* The thread library keeps two lists for the running threads. One
125 list contains the thread which are using user-provided stacks
126 (this includes the main thread) and the other includes the
127 threads for which the thread library allocated the stacks. We
128 have to iterate over both lists separately. We start with the
129 list of threads with user-defined stacks. */
130 td_err_e result
= iterate_thread_list (ta
, callback
, cbdata_p
, state
, ti_pri
,
133 /* And the threads with stacks allocated by the implementation. */
135 result
= iterate_thread_list (ta
, callback
, cbdata_p
, state
, ti_pri
,