]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ddb/db_task_thread.c
59b17159f60c9d12f70d1ef487385c68a8fbbf69
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
61 #include <kern/kern_types.h>
62 #include <kern/processor.h>
63 #include <machine/db_machdep.h>
64 #include <ddb/db_task_thread.h>
65 #include <ddb/db_variables.h>
66 #include <ddb/db_command.h>
67 #include <ddb/db_expr.h>
68 #include <ddb/db_lex.h>
69 #include <ddb/db_output.h> /* For db_printf() */
70 #include <ddb/db_sym.h>
73 * Following constants are used to prevent infinite loop of task
74 * or thread search due to the incorrect list.
76 #define DB_MAX_TASKID 0x10000 /* max # of tasks */
77 #define DB_MAX_THREADID 0x10000 /* max # of threads in a task */
78 #define DB_MAX_PSETS 0x10000 /* max # of processor sets */
80 task_t db_default_task
; /* default target task */
81 thread_t db_default_act
; /* default target thr_act */
85 /* Prototypes for functions local to this file.
87 task_t
db_lookup_task_id(register int task_id
);
89 static thread_t
db_lookup_act_id(
91 register int thread_id
);
96 * search valid task queue, and return the queue position as the task id
99 db_lookup_task(task_t target_task
)
101 register task_t task
;
102 register int task_id
;
103 register processor_set_t pset
= &default_pset
;
104 register int npset
= 0;
107 if (npset
++ >= DB_MAX_PSETS
)
109 if (queue_first(&pset
->tasks
) == 0)
111 queue_iterate(&pset
->tasks
, task
, task_t
, pset_tasks
) {
112 if (target_task
== task
)
114 if (task_id
++ >= DB_MAX_TASKID
)
121 * search thread queue of the task, and return the queue position
128 register thread_t thr_act
;
132 if (queue_first(&task
->threads
) == 0)
134 queue_iterate(&task
->threads
, thr_act
, thread_t
, task_threads
) {
135 if (target_act
== thr_act
)
137 if (act_id
++ >= DB_MAX_THREADID
)
144 * search thr_act queue of every valid task, and return the queue position
148 db_lookup_act(thread_t target_act
)
151 register task_t task
;
152 register processor_set_t pset
= &default_pset
;
153 register int ntask
= 0;
154 register int npset
= 0;
156 if (npset
++ >= DB_MAX_PSETS
)
158 if (queue_first(&pset
->tasks
) == 0)
160 queue_iterate(&pset
->tasks
, task
, task_t
, pset_tasks
) {
161 if (ntask
++ > DB_MAX_TASKID
)
163 if (task
->thread_count
== 0)
165 act_id
= db_lookup_task_act(task
, target_act
);
173 * check the address is a valid thread address
175 int force_act_lookup
= 0;
177 db_check_act_address_valid(thread_t thr_act
)
179 if (!force_act_lookup
&& db_lookup_act(thr_act
) < 0) {
180 db_printf("Bad thr_act address 0x%x\n", thr_act
);
188 * convert task_id(queue postion) to task address
191 db_lookup_task_id(register task_id
)
193 register task_t task
;
194 register processor_set_t pset
= &default_pset
;
195 register int npset
= 0;
197 if (task_id
> DB_MAX_TASKID
)
199 if (npset
++ >= DB_MAX_PSETS
)
201 if (queue_first(&pset
->tasks
) == 0)
203 queue_iterate(&pset
->tasks
, task
, task_t
, pset_tasks
) {
211 * convert (task_id, act_id) pair to thr_act address
218 register thread_t thr_act
;
221 if (act_id
> DB_MAX_THREADID
)
223 if (queue_first(&task
->threads
) == 0)
225 queue_iterate(&task
->threads
, thr_act
, thread_t
, task_threads
) {
233 * get next parameter from a command line, and check it as a valid
245 if (db_expression(&value
)) {
246 thr_act
= (thread_t
) value
;
247 if (!db_check_act_address_valid(thr_act
)) {
251 } else if (position
<= 0) {
252 thr_act
= db_default_act
;
260 * check the default thread is still valid
261 * ( it is called in entering DDB session )
264 db_init_default_act(void)
266 if (db_lookup_act(db_default_act
) < 0) {
267 db_default_act
= THREAD_NULL
;
268 db_default_task
= TASK_NULL
;
270 db_default_task
= db_default_act
->task
;
274 * set or get default thread which is used when /t or :t option is specified
275 * in the command line
279 struct db_variable
*vp
,
282 db_var_aux_param_t ap
) /* unused */
288 if (flag
== DB_VAR_SHOW
) {
289 db_printf("%#n", db_default_act
);
290 task_id
= db_lookup_task(db_default_task
);
292 act_id
= db_lookup_act(db_default_act
);
294 db_printf(" (task%d.%d)", task_id
, act_id
);
300 if (flag
!= DB_VAR_SET
) {
301 *valuep
= (db_expr_t
) db_default_act
;
304 thr_act
= (thread_t
) *valuep
;
305 if (thr_act
!= THREAD_NULL
&& !db_check_act_address_valid(thr_act
))
308 db_default_act
= thr_act
;
310 db_default_task
= thr_act
->task
;
315 * convert $taskXXX[.YYY] type DDB variable to task or thread address
319 struct db_variable
*vp
,
322 db_var_aux_param_t ap
)
328 if (flag
== DB_VAR_SHOW
) {
329 db_printf("%#n", db_default_task
);
330 task_id
= db_lookup_task(db_default_task
);
332 db_printf(" (task%d)", task_id
);
336 if (flag
!= DB_VAR_GET
) {
337 db_error("Cannot set to $task variable\n");
340 if ((task
= db_lookup_task_id(ap
->suffix
[0])) == TASK_NULL
) {
341 db_printf("no such task($task%d)\n", ap
->suffix
[0]);
345 if (ap
->level
<= 1) {
346 *valuep
= (db_expr_t
) task
;
349 if ((thr_act
= db_lookup_act_id(task
, ap
->suffix
[1])) == THREAD_NULL
){
350 db_printf("no such thr_act($task%d.%d)\n",
351 ap
->suffix
[0], ap
->suffix
[1]);
355 *valuep
= (db_expr_t
) thr_act
;