]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ddb/db_task_thread.c
866d1fdb00e94b25b001638c71fbd8e15838ed42
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * Mach Operating System
28 * Copyright (c) 1991,1990 Carnegie Mellon University
29 * All Rights Reserved.
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
41 * Carnegie Mellon requests users of this software to return to
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
54 #include <kern/kern_types.h>
55 #include <kern/processor.h>
56 #include <machine/db_machdep.h>
57 #include <ddb/db_task_thread.h>
58 #include <ddb/db_variables.h>
59 #include <ddb/db_command.h>
60 #include <ddb/db_expr.h>
61 #include <ddb/db_lex.h>
62 #include <ddb/db_output.h> /* For db_printf() */
63 #include <ddb/db_sym.h>
66 * Following constants are used to prevent infinite loop of task
67 * or thread search due to the incorrect list.
69 #define DB_MAX_TASKID 0x10000 /* max # of tasks */
70 #define DB_MAX_THREADID 0x10000 /* max # of threads in a task */
71 #define DB_MAX_PSETS 0x10000 /* max # of processor sets */
73 task_t db_default_task
; /* default target task */
74 thread_t db_default_act
; /* default target thr_act */
78 /* Prototypes for functions local to this file.
80 task_t
db_lookup_task_id(register int task_id
);
82 static thread_t
db_lookup_act_id(
84 register int thread_id
);
89 * search valid task queue, and return the queue position as the task id
92 db_lookup_task(task_t target_task
)
96 register processor_set_t pset
= &default_pset
;
97 register int npset
= 0;
100 if (npset
++ >= DB_MAX_PSETS
)
102 if (queue_first(&pset
->tasks
) == 0)
104 queue_iterate(&pset
->tasks
, task
, task_t
, pset_tasks
) {
105 if (target_task
== task
)
107 if (task_id
++ >= DB_MAX_TASKID
)
114 * search thread queue of the task, and return the queue position
121 register thread_t thr_act
;
125 if (queue_first(&task
->threads
) == 0)
127 queue_iterate(&task
->threads
, thr_act
, thread_t
, task_threads
) {
128 if (target_act
== thr_act
)
130 if (act_id
++ >= DB_MAX_THREADID
)
137 * search thr_act queue of every valid task, and return the queue position
141 db_lookup_act(thread_t target_act
)
144 register task_t task
;
145 register processor_set_t pset
= &default_pset
;
146 register int ntask
= 0;
147 register int npset
= 0;
149 if (npset
++ >= DB_MAX_PSETS
)
151 if (queue_first(&pset
->tasks
) == 0)
153 queue_iterate(&pset
->tasks
, task
, task_t
, pset_tasks
) {
154 if (ntask
++ > DB_MAX_TASKID
)
156 if (task
->thread_count
== 0)
158 act_id
= db_lookup_task_act(task
, target_act
);
166 * check the address is a valid thread address
168 int force_act_lookup
= 0;
170 db_check_act_address_valid(thread_t thr_act
)
172 if (!force_act_lookup
&& db_lookup_act(thr_act
) < 0) {
173 db_printf("Bad thr_act address 0x%x\n", thr_act
);
181 * convert task_id(queue postion) to task address
184 db_lookup_task_id(register task_id
)
186 register task_t task
;
187 register processor_set_t pset
= &default_pset
;
188 register int npset
= 0;
190 if (task_id
> DB_MAX_TASKID
)
192 if (npset
++ >= DB_MAX_PSETS
)
194 if (queue_first(&pset
->tasks
) == 0)
196 queue_iterate(&pset
->tasks
, task
, task_t
, pset_tasks
) {
204 * convert (task_id, act_id) pair to thr_act address
211 register thread_t thr_act
;
214 if (act_id
> DB_MAX_THREADID
)
216 if (queue_first(&task
->threads
) == 0)
218 queue_iterate(&task
->threads
, thr_act
, thread_t
, task_threads
) {
226 * get next parameter from a command line, and check it as a valid
238 if (db_expression(&value
)) {
239 thr_act
= (thread_t
) value
;
240 if (!db_check_act_address_valid(thr_act
)) {
244 } else if (position
<= 0) {
245 thr_act
= db_default_act
;
253 * check the default thread is still valid
254 * ( it is called in entering DDB session )
257 db_init_default_act(void)
259 if (db_lookup_act(db_default_act
) < 0) {
260 db_default_act
= THREAD_NULL
;
261 db_default_task
= TASK_NULL
;
263 db_default_task
= db_default_act
->task
;
267 * set or get default thread which is used when /t or :t option is specified
268 * in the command line
272 struct db_variable
*vp
,
275 db_var_aux_param_t ap
) /* unused */
281 if (flag
== DB_VAR_SHOW
) {
282 db_printf("%#n", db_default_act
);
283 task_id
= db_lookup_task(db_default_task
);
285 act_id
= db_lookup_act(db_default_act
);
287 db_printf(" (task%d.%d)", task_id
, act_id
);
293 if (flag
!= DB_VAR_SET
) {
294 *valuep
= (db_expr_t
) db_default_act
;
297 thr_act
= (thread_t
) *valuep
;
298 if (thr_act
!= THREAD_NULL
&& !db_check_act_address_valid(thr_act
))
301 db_default_act
= thr_act
;
303 db_default_task
= thr_act
->task
;
308 * convert $taskXXX[.YYY] type DDB variable to task or thread address
312 struct db_variable
*vp
,
315 db_var_aux_param_t ap
)
321 if (flag
== DB_VAR_SHOW
) {
322 db_printf("%#n", db_default_task
);
323 task_id
= db_lookup_task(db_default_task
);
325 db_printf(" (task%d)", task_id
);
329 if (flag
!= DB_VAR_GET
) {
330 db_error("Cannot set to $task variable\n");
333 if ((task
= db_lookup_task_id(ap
->suffix
[0])) == TASK_NULL
) {
334 db_printf("no such task($task%d)\n", ap
->suffix
[0]);
338 if (ap
->level
<= 1) {
339 *valuep
= (db_expr_t
) task
;
342 if ((thr_act
= db_lookup_act_id(task
, ap
->suffix
[1])) == THREAD_NULL
){
343 db_printf("no such thr_act($task%d.%d)\n",
344 ap
->suffix
[0], ap
->suffix
[1]);
348 *valuep
= (db_expr_t
) thr_act
;