2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
34 * Revision 1.1.1.1 1998/09/22 21:05:48 wsanchez
35 * Import of Mac OS X kernel (~semeria)
37 * Revision 1.2 1998/04/29 17:35:25 mburg
40 * Revision 1.2.85.1 1998/02/03 09:24:09 gdt
42 * [1998/02/03 09:10:24 gdt]
44 * Revision 1.2.81.1 1997/03/27 18:46:38 barbou
45 * ri-osc CR1565 - clean up db_print_act, removing old !USER code
46 * which had gotten stale (the option made little sense here anyway).
47 * Added routine db_show_one_thread() to take either act/shuttle and
48 * do something sensible. [dwm] Also rationalize plain, /u and /l
49 * output for "show act", "show task" and "show all acts".
50 * [1995/08/28 15:47:00 bolinger]
53 * Revision 1.2.31.13 1996/01/09 19:16:02 devrcs
54 * Alpha kdebug Changes:
55 * Correct various header spacing to account for 64-bit addresses.
56 * Modify db_show_all_*() functions, so the can be called from kdebug.
57 * ( There's no way to call with "char *modif", so added NULL check. )
58 * Changed db_error() calls to DB_ERROR() macro, so we return on error
59 * on Alpha (we gotta return to kdebug).
60 * Changed declarations of 'register foo' to 'register int foo'.
61 * [1995/12/01 21:42:20 jfraser]
63 * Merged '64-bit safe' changes from DEC alpha port.
64 * [1995/11/21 18:03:24 jfraser]
66 * Revision 1.2.31.12 1995/10/09 17:03:30 devrcs
68 * [1995/08/24 20:56:42 watkins]
70 * Revision 1.2.59.1 1995/08/04 17:03:17 watkins
71 * Change to stack per shuttle model.
72 * [1995/07/19 20:26:13 watkins]
74 * Revision 1.2.31.11 1995/09/18 19:08:49 devrcs
76 * [1995/08/24 20:56:42 watkins]
78 * Revision 1.2.59.1 1995/08/04 17:03:17 watkins
79 * Change to stack per shuttle model.
80 * [1995/07/19 20:26:13 watkins]
82 * Revision 1.2.31.10 1995/05/19 15:43:04 bernadat
83 * Fixed db_print_act for empty activations.
84 * Let thread swapping be configurable.
87 * Revision 1.2.31.9 1995/05/14 18:10:25 dwm
88 * ri-osc CR1304 - merge (nmk19_latest - nmk19b1) diffs into mainline.
89 * mk6 CR938 - restore mach_msg hot path
90 * remove use of now-defunct fields in thread [mmp,dwm]
91 * [1995/05/14 17:25:05 dwm]
93 * Revision 1.2.31.8 1995/04/07 18:53:00 barbou
94 * VM Merge - Task Swapper.
95 * Renamed TH_SWAPPED to TH_STACK_HANDOFF and swap_func to continuation
96 * to resolve name conflict.
97 * From kernel/kdb/kdb_mach.c:
98 * Put in changes for swapping.
99 * [1991/11/21 20:32:15 mmp]
103 * Revision 1.2.31.7 1995/02/28 01:58:38 dwm
104 * mk6 CR1120 - Merge mk6pro_shared into cnmk_shared
105 * * Rev1.2.43.1 1995/01/27 22:01:26 bolinger
106 * * Fix ri-osc CR977: Make "show space" and "show ipc_port" give
107 * * accurate count of ports active in IPC space. Make "show ipc_port"
108 * * output task-visible port name.
109 * [1995/02/28 01:12:46 dwm]
111 * Revision 1.2.31.6 1995/02/23 21:43:34 alanl
112 * Fix db_show_one_task_vm for thread_act_ts.
115 * Merged with DIPC2_SHARED.
118 * Revision 1.2.31.5 1995/01/10 04:49:52 devrcs
119 * mk6 CR801 - merge up from nmk18b4 to nmk18b7
120 * Fix "sh thr/ul"; no cont. to print, fix pri/policy format.
121 * * Rev 1.2.31.4 1994/10/11 16:35:58 emcmanus
122 * Added "show runq" and "show shuttle".
123 * [1994/12/09 20:36:49 dwm]
125 * mk6 CR668 - 1.3b26 merge
126 * * Revision 1.2.8.6 1994/05/06 18:39:37 tmt
127 * Merged osc1.3dec/shared with osc1.3b19
128 * Merge Alpha changes into osc1.312b source code.
131 * [1994/11/04 08:49:52 dwm]
133 * Revision 1.2.31.3 1994/09/23 01:20:51 ezf
134 * change marker to not FREE
135 * [1994/09/22 21:10:41 ezf]
137 * Revision 1.2.31.2 1994/06/14 17:21:05 bolinger
138 * Merge up to NMK17.2.
139 * [1994/06/14 17:20:35 bolinger]
141 * Revision 1.2.23.4 1994/04/15 18:41:31 paire
142 * Changed interface of db_task_from_space routine.
145 * Revision 1.2.23.3 1994/03/07 16:37:48 paire
146 * Merge with Intel R1_1
147 * Change from NMK14.10 [1993/11/15 16:06:21 rwd]
149 * Enhanced pretty print routine and added db_task_from_space.
150 * Change from NMK14.10 [93/09/24 sjs]
153 * Exported ANSI prototype of db_port_kmsg_count routine.
154 * Added header file include for the declaration of db_norma_ipc routine.
157 * Revision 1.2.23.2 1994/02/11 14:21:58 paire
158 * Added new vm_print.h header file for db_vm declaration.
161 * Revision 1.2.23.1 1994/02/08 10:58:19 bernadat
162 * print out msgcount for each port in db_port_iterate
163 * Change from NORMA_MK14.6(August 93) [1993/07/27 12:35:17 mmp]
165 * Removed defintion of db_maxoff (got from <ddb/db_sym.h>).
168 * Show ipc_space_remote msg counts only if NORMA_IPC is on
169 * [93/07/21 bernadat]
171 * Add /s option to "show ipc_port" to pick out port sets.
172 * Change from NORMA_MK14.6 [1993/02/17 16:29:54 dwm]
173 * [93/07/16 bernadat]
174 * [94/02/07 bernadat]
176 * Revision 1.2.20.8 1994/06/08 19:11:15 dswartz
178 * [1994/06/08 19:10:18 dswartz]
180 * Revision 1.2.20.7 1994/04/30 21:28:24 bolinger
181 * Thread control ops synchronization: now that TH_SUSP is back,
182 * enable ddb to show it when printing thread state.
183 * [1994/04/28 21:55:42 bolinger]
185 * Revision 1.2.20.6 1994/03/17 22:35:31 dwm
186 * The infamous name change: thread_activation + thread_shuttle = thread.
187 * [1994/03/17 21:25:46 dwm]
189 * Revision 1.2.20.5 1994/01/26 15:43:37 bolinger
190 * Move kernel_stack from thread to activation.
191 * [1994/01/25 21:53:11 bolinger]
193 * Revision 1.2.20.4 1994/01/12 17:50:44 dwm
194 * Coloc: initial restructuring to follow Utah model.
195 * [1994/01/12 17:13:12 dwm]
197 * Revision 1.2.20.3 1993/11/18 18:11:47 dwm
198 * Coloc: remove continuations entirely; they are incompatible
199 * with migration, and their volume is obfuscatory.
200 * [1993/11/18 18:06:27 dwm]
202 * Revision 1.2.20.2 1993/10/12 16:38:50 dwm
203 * CoLoc: neuter continuations, ifdef USE_CONTINUATIONS.
204 * [1993/10/12 16:14:46 dwm]
206 * Revision 1.2.8.4 1993/08/11 20:38:06 elliston
207 * Add ANSI Prototypes. CR #9523.
208 * [1993/08/11 03:33:51 elliston]
210 * Revision 1.2.8.3 1993/07/27 18:27:55 elliston
211 * Add ANSI prototypes. CR #9523.
212 * [1993/07/27 18:12:39 elliston]
214 * Revision 1.2.8.2 1993/06/09 02:20:35 gm
215 * CR9176 - ANSI C violations: trailing tokens on CPP
216 * directives, extra semicolons after decl_ ..., asm keywords
217 * [1993/06/07 18:57:22 jeffc]
219 * Removed a '#if MACH_FIXPRI' which somehow survived the purge. CR #9131.
220 * [1993/05/11 20:56:00 dswartz]
222 * Revision 1.2 1993/04/19 16:02:50 devrcs
223 * Added printout of thread scheduling policy to long form
228 * Removed unused variable from db_show_regs().
230 * Converted some db_printsyms to db_task_printsyms.
232 * Changed db_print_thread so that both display formats
233 * show the floating-point-used status of the thread.
237 * Revision 1.1 1992/09/30 02:01:18 robert
244 * Revision 2.11.3.2 92/04/08 15:43:10 jeffreyh
245 * Added i option to show thread. This gives wait state information.
248 * Revision 2.11.3.1 92/03/03 16:13:34 jeffreyh
249 * Pick up changes from TRUNK
250 * [92/02/26 11:00:01 jeffreyh]
252 * Revision 2.13 92/02/20 18:34:28 elf
256 * Revision 2.12 92/02/19 15:07:47 elf
257 * Added db_thread_fp_used, to avoid machine-dependent conditionals.
260 * Added 'F' flag to db_thread_stat showing if the thread has a valid
261 * FPU context. Tested on i386 and pmax.
264 * Revision 2.11 91/11/12 11:50:32 rvb
265 * Added OPTION_USER ("/u") to db_show_all_threads, db_show_one_thread,
266 * db_show_one_task. Without it, we display old-style information.
269 * Revision 2.10 91/10/09 16:01:48 af
270 * Supported "show registers" for non current thread.
271 * Changed display format of thread and task information.
272 * Changed "show thread" to print current thread information
273 * if no thread is specified.
274 * Added "show_one_task" for "show task" command.
275 * Added IPC port print routines for "show ipc_port" command.
278 * Revision 2.9 91/08/03 18:17:19 jsb
279 * In db_print_thread, if the thread is swapped and there is a
280 * continuation function, print the function name in parentheses
281 * instead of '(swapped)'.
282 * [91/07/04 09:59:27 jsb]
284 * Revision 2.8 91/07/31 17:30:43 dbg
285 * Revise scheduling state machine.
286 * [91/07/30 16:43:42 dbg]
288 * Revision 2.7 91/07/09 23:15:57 danner
289 * Fixed a few printf that should be db_printfs.
292 * Revision 2.6 91/05/14 15:35:25 mrt
293 * Correcting copyright
295 * Revision 2.5 91/02/05 17:06:53 mrt
296 * Changed to new Mach copyright
297 * [91/01/31 16:18:56 mrt]
299 * Revision 2.4 90/10/25 14:43:54 rwd
300 * Changed db_show_regs to print unsigned.
302 * Generalized the watchpoint support.
305 * Revision 2.3 90/09/09 23:19:52 rpd
306 * Avoid totally incorrect guesses of symbol names for small values.
307 * [90/08/30 17:39:08 af]
309 * Revision 2.2 90/08/27 21:51:49 dbg
310 * Insist that 'show thread' be called with an explicit address.
313 * Fix type for db_maxoff.
316 * Do not dereference the "valuep" field of a variable directly,
317 * call the new db_read/write_variable functions instead.
318 * Reflected changes in symbol lookup functions.
321 * [90/08/10 14:33:44 dbg]
329 * Mach Operating System
330 * Copyright (c) 1991,1990 Carnegie Mellon University
331 * All Rights Reserved.
333 * Permission to use, copy, modify and distribute this software and its
334 * documentation is hereby granted, provided that both the copyright
335 * notice and this permission notice appear in all copies of the
336 * software, derivative works or modified versions, and any portions
337 * thereof, and that both notices appear in supporting documentation.
339 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
340 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
341 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
343 * Carnegie Mellon requests users of this software to return to
345 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
346 * School of Computer Science
347 * Carnegie Mellon University
348 * Pittsburgh PA 15213-3890
350 * any improvements or extensions that they make and grant Carnegie Mellon
351 * the rights to redistribute these changes.
356 * Author: David B. Golub, Carnegie Mellon University
361 * Miscellaneous printing.
364 #include <task_swapper.h>
366 #include <string.h> /* For strlen() */
367 #include <mach/port.h>
368 #include <kern/task.h>
369 #include <kern/thread.h>
370 #include <kern/thread_swap.h>
371 #include <kern/queue.h>
372 #include <ipc/ipc_port.h>
373 #include <ipc/ipc_space.h>
374 #include <ipc/ipc_pset.h>
375 #include <vm/vm_print.h> /* for db_vm() */
377 #include <machine/db_machdep.h>
378 #include <machine/thread.h>
380 #include <ddb/db_lex.h>
381 #include <ddb/db_variables.h>
382 #include <ddb/db_sym.h>
383 #include <ddb/db_task_thread.h>
384 #include <ddb/db_command.h>
385 #include <ddb/db_output.h> /* For db_printf() */
386 #include <ddb/db_print.h>
389 #include <kern/sp_mk.h> /*** ??? fix so this can be removed ***/
392 #include <kern/task_swap.h>
393 #endif /* TASK_SWAPPER */
395 /* Prototypes for functions local to this file. XXX -- should be static!
399 register thread_act_t thr_act
,
402 char *db_act_swap_stat(
403 register thread_act_t thr_act
,
411 void db_reset_print_entry(
414 void db_print_one_entry(
417 mach_port_name_t name
,
421 thread_act_t thr_act
,
423 boolean_t do_output
);
425 ipc_port_t
db_lookup_port(
426 thread_act_t thr_act
,
429 static void db_print_port_id(
436 thread_act_t thr_act
,
445 void db_print_task_vm(
451 void db_system_stats(void);
461 register struct db_variable
*regp
;
466 struct db_var_aux_param aux_param
;
467 task_t task
= TASK_NULL
;
469 aux_param
.modif
= modif
;
470 aux_param
.thr_act
= THR_ACT_NULL
;
471 if (db_option(modif
, 't')) {
473 if (!db_check_act_address_valid((thread_act_t
)addr
))
475 aux_param
.thr_act
= (thread_act_t
)addr
;
477 aux_param
.thr_act
= db_default_act
;
478 if (aux_param
.thr_act
!= THR_ACT_NULL
)
479 task
= aux_param
.thr_act
->task
;
481 for (regp
= db_regs
; regp
< db_eregs
; regp
++) {
482 if (regp
->max_level
> 1) {
483 db_printf("bad multi-suffixed register %s\n", regp
->name
);
486 aux_param
.level
= regp
->max_level
;
487 for (i
= regp
->low
; i
<= regp
->high
; i
++) {
488 aux_param
.suffix
[0] = i
;
489 db_read_write_variable(regp
, &value
, DB_VAR_GET
, &aux_param
);
490 if (regp
->max_level
> 0)
491 db_printf("%s%d%*s", regp
->name
, i
,
492 12-strlen(regp
->name
)-((i
<10)?1:2), "");
494 db_printf("%-12s", regp
->name
);
495 db_printf("%#*N", 2+2*sizeof(vm_offset_t
), value
);
496 db_find_xtrn_task_sym_and_offset((db_addr_t
)value
, &name
,
498 if (name
!= 0 && offset
<= db_maxoff
&& offset
!= value
) {
499 db_printf("\t%s", name
);
501 db_printf("+%#r", offset
);
508 #define OPTION_LONG 0x001 /* long print option */
509 #define OPTION_USER 0x002 /* print ps-like stuff */
510 #define OPTION_INDENT 0x100 /* print with indent */
511 #define OPTION_THREAD_TITLE 0x200 /* print thread title */
512 #define OPTION_TASK_TITLE 0x400 /* print thread title */
515 #define DB_TASK_NAME(task) /* no task name */
516 #define DB_TASK_NAME_TITLE "" /* no task name */
517 #endif /* DB_TASK_NAME */
519 #ifndef db_act_fp_used
520 #define db_act_fp_used(thr_act) FALSE
525 register thread_act_t thr_act
,
528 register char *p
= status
;
530 if (!thr_act
->active
) {
537 } else if (!thr_act
->thread
) {
545 thread_t athread
= thr_act
->thread
;
547 *p
++ = (athread
->state
& TH_RUN
) ? 'R' : '.';
548 *p
++ = (athread
->state
& TH_WAIT
) ? 'W' : '.';
549 *p
++ = (athread
->state
& TH_SUSP
) ? 'S' : '.';
550 *p
++ = (athread
->state
& TH_SWAPPED_OUT
) ? 'O' : '.';
551 *p
++ = (athread
->state
& TH_UNINT
) ? 'N' : '.';
552 /* show if the FPU has been used */
553 *p
++ = db_act_fp_used(thr_act
) ? 'F' : '.';
561 register thread_act_t thr_act
,
564 register char *p
= status
;
567 switch (thr_act
->swap_state
& TH_SW_STATE
) {
568 case TH_SW_UNSWAPPABLE
:
574 case TH_SW_GOING_OUT
:
583 case TH_SW_COMING_IN
:
590 *p
++ = (thr_act
->swap_state
& TH_SW_TASK_SWAPPING
) ? 'T' : '.';
591 #endif /* THREAD_SWAPPER */
597 char *policy_list
[] = { "TS", "RR", "??", "FF",
598 "??", "??", "??", "BE"};
602 thread_act_t thr_act
,
613 db_printf("db_print_act(NULL)!\n");
617 athread
= thr_act
->thread
;
618 if (flag
& OPTION_USER
) {
620 if (flag
& OPTION_LONG
) {
621 if (flag
& OPTION_INDENT
)
623 if (flag
& OPTION_THREAD_TITLE
) {
624 db_printf("%s ID: ACT STAT SW STACK SHUTTLE", indent
);
625 db_printf(" SUS PRI WAIT_FUNC\n");
627 policy
= (athread
? athread
->policy
: 2);
628 db_printf("%s%3d%c %0*X %s %s %0*X %0*X %3d %3d/%s ",
630 (thr_act
== current_act())? '#': ':',
631 2*sizeof(vm_offset_t
), thr_act
,
632 db_act_stat(thr_act
, status
),
633 db_act_swap_stat(thr_act
, swap_status
),
634 2*sizeof(vm_offset_t
), (athread
?athread
->kernel_stack
:0),
635 2*sizeof(vm_offset_t
), athread
,
636 thr_act
->suspend_count
,
637 (athread
? athread
->sched_pri
: 999), /* XXX */
638 policy_list
[policy
-1]);
640 /* no longer TH_SWAP, no continuation to print */
641 if (athread
->state
& TH_WAIT
)
642 db_task_printsym((db_addr_t
)athread
->wait_event
,
643 DB_STGY_ANY
, kernel_task
);
647 if (act_id
% 3 == 0) {
648 if (flag
& OPTION_INDENT
)
652 db_printf("%3d%c(%0*X,%s)", act_id
,
653 (thr_act
== current_act())? '#': ':',
654 2*sizeof(vm_offset_t
), thr_act
,
655 db_act_stat(thr_act
, status
));
658 if (flag
& OPTION_INDENT
)
659 db_printf(" %3d (%0*X) ", act_id
,
660 2*sizeof(vm_offset_t
), thr_act
);
662 db_printf("(%0*X) ", 2*sizeof(vm_offset_t
), thr_act
);
664 db_printf("%c%c%c%c%c",
665 (athread
->state
& TH_RUN
) ? 'R' : ' ',
666 (athread
->state
& TH_WAIT
) ? 'W' : ' ',
667 (athread
->state
& TH_SUSP
) ? 'S' : ' ',
668 (athread
->state
& TH_UNINT
)? 'N' : ' ',
669 db_act_fp_used(thr_act
) ? 'F' : ' ');
670 /* Obsolete TH_STACK_HANDOFF code, left for now; might enhance
671 * to print out safe_points instead */
672 if (athread
->state
& TH_STACK_HANDOFF
) {
673 if (athread
->continuation
) {
675 db_task_printsym((db_addr_t
)athread
->continuation
,
676 DB_STGY_ANY
, kernel_task
);
679 db_printf("(handoff)");
682 if (athread
->state
& TH_WAIT
) {
684 db_task_printsym((db_addr_t
)athread
->wait_event
,
685 DB_STGY_ANY
, kernel_task
);
699 thread_act_t thr_act
;
703 if (flag
& OPTION_USER
) {
704 if (flag
& OPTION_TASK_TITLE
) {
705 db_printf(" ID: TASK MAP THD RES SUS PR SW %s",
707 if ((flag
& OPTION_LONG
) == 0)
712 switch ((int) task
->swap_state
) {
719 case TASK_SW_GOING_OUT
:
722 case TASK_SW_COMING_IN
:
725 case TASK_SW_UNSWAPPABLE
:
732 #else /* TASK_SWAPPER */
734 #endif /* TASK_SWAPPER */
736 db_printf("%3d: %0*X %0*X %3d %3d %3d %2d %c ",
737 task_id
, 2*sizeof(vm_offset_t
), task
,
738 2*sizeof(vm_offset_t
), task
->map
,
739 task
->thr_act_count
, task
->res_act_count
,
741 ((mk_sp_attributes_t
)(task
->sp_attributes
))->priority
,
744 if (flag
& OPTION_LONG
) {
745 if (flag
& OPTION_TASK_TITLE
)
746 flag
|= OPTION_THREAD_TITLE
;
748 } else if (task
->thr_act_count
<= 1)
749 flag
&= ~OPTION_INDENT
;
751 queue_iterate(&task
->thr_acts
, thr_act
, thread_act_t
, thr_acts
) {
752 db_print_act(thr_act
, act_id
, flag
);
753 flag
&= ~OPTION_THREAD_TITLE
;
756 if ((flag
& OPTION_LONG
) == 0)
759 if (flag
& OPTION_LONG
) {
760 if (flag
& OPTION_TASK_TITLE
) {
761 db_printf(" TASK ACT\n");
762 if (task
->thr_act_count
> 1)
763 flag
|= OPTION_THREAD_TITLE
;
766 db_printf("%3d (%0*X): ", task_id
, 2*sizeof(vm_offset_t
), task
);
767 if (task
->thr_act_count
== 0) {
768 db_printf("no threads\n");
770 if (task
->thr_act_count
> 1) {
771 db_printf("%d threads: \n", task
->thr_act_count
);
772 flag
|= OPTION_INDENT
;
774 flag
&= ~OPTION_INDENT
;
776 queue_iterate(&task
->thr_acts
, thr_act
,
777 thread_act_t
, thr_acts
) {
778 db_print_act(thr_act
, act_id
++, flag
);
779 flag
&= ~OPTION_THREAD_TITLE
;
792 thread_act_t act
= (thread_act_t
)queue_first(&task
->thr_acts
);
796 space
= task
->itk_space
;
798 count
= db_port_iterate(act
, FALSE
, FALSE
);
799 db_printf("%3d: %08x %08x %08x %sactive %d\n",
800 task_id
, task
, space
, task
->map
,
801 space
->is_active
? "":"!", count
);
818 db_printf("id task map pmap virtual rss pg rss mem wir pg wir mem\n");
822 pmap
= vm_map_pmap(map
);
824 size
= db_vm_map_total_size(map
);
825 resident
= pmap
->stats
.resident_count
;
826 wired
= pmap
->stats
.wired_count
;
828 db_printf("%2d %08x %08x %08x %7dK %6d %6dK %6d %6dK\n",
834 resident
, (resident
* PAGE_SIZE
) / 1024,
835 wired
, (wired
* PAGE_SIZE
) / 1024);
850 if (have_addr
== FALSE
) {
851 if ((thread
= db_default_act
) == THR_ACT_NULL
) {
852 if ((thread
= current_act()) == THR_ACT_NULL
) {
853 db_printf("no thread.\n");
859 task
= (task_t
) addr
;
862 task_id
= db_lookup_task(task
);
864 db_printf("0x%x is not a task_t\n", addr
);
868 db_print_task_vm(task
, task_id
, TRUE
, modif
);
880 boolean_t title
= TRUE
;
881 processor_set_t pset
;
884 queue_iterate(&all_psets
, pset
, processor_set_t
, all_psets
) {
885 queue_iterate(&pset
->tasks
, task
, task_t
, pset_tasks
) {
886 db_print_task_vm(task
, task_id
, title
, modif
);
903 processor_set_t pset
;
905 flag
= OPTION_TASK_TITLE
|OPTION_INDENT
;
906 if (db_option(modif
, 'u'))
908 if (db_option(modif
, 'l'))
912 queue_iterate(&all_psets
, pset
, processor_set_t
, all_psets
) {
913 queue_iterate(&pset
->tasks
, task
, task_t
, pset_tasks
) {
914 db_print_task(task
, task_id
, flag
);
915 flag
&= ~OPTION_TASK_TITLE
;
917 if ((flag
& (OPTION_LONG
|OPTION_INDENT
)) == OPTION_INDENT
)
934 flag
= OPTION_TASK_TITLE
;
935 if (db_option(modif
, 'u'))
937 if (db_option(modif
, 'l'))
941 task
= db_current_task();
942 if (task
== TASK_NULL
) {
943 db_error("No task\n");
947 task
= (task_t
) addr
;
949 if ((task_id
= db_lookup_task(task
)) < 0) {
950 db_printf("bad task address 0x%x\n", addr
);
955 db_printf(" ID: TASK SPACE MAP COUNT\n");
956 db_print_space(task
, task_id
, flag
);
969 processor_set_t pset
;
971 flag
= OPTION_TASK_TITLE
|OPTION_INDENT
;
972 if (db_option(modif
, 'u'))
974 if (db_option(modif
, 'l'))
977 db_printf(" ID: TASK SPACE MAP COUNT\n");
978 queue_iterate(&all_psets
, pset
, processor_set_t
, all_psets
) {
979 queue_iterate(&pset
->tasks
, task
, task_t
, pset_tasks
) {
980 db_print_space(task
, task_id
, flag
);
993 processor_set_t pset
;
995 queue_iterate(&all_psets
, pset
, processor_set_t
, all_psets
) {
996 queue_iterate(&pset
->tasks
, task
, task_t
, pset_tasks
) {
997 if (task
->itk_space
== space
) {
999 return (db_addr_t
)task
;
1011 boolean_t have_addr
,
1017 thread_act_t thr_act
;
1019 flag
= OPTION_THREAD_TITLE
;
1020 if (db_option(modif
, 'u'))
1021 flag
|= OPTION_USER
;
1022 if (db_option(modif
, 'l'))
1023 flag
|= OPTION_LONG
;
1026 thr_act
= current_act();
1027 if (thr_act
== THR_ACT_NULL
) {
1028 db_error("No thr_act\n");
1032 thr_act
= (thread_act_t
) addr
;
1034 if ((act_id
= db_lookup_act(thr_act
)) < 0) {
1035 db_printf("bad thr_act address %#x\n", addr
);
1040 if (flag
& OPTION_USER
) {
1041 db_printf("TASK%d(%0*X):\n",
1042 db_lookup_task(thr_act
->task
),
1043 2*sizeof(vm_offset_t
), thr_act
->task
);
1044 db_print_act(thr_act
, act_id
, flag
);
1046 db_printf("task %d(%0*Xx): thr_act %d",
1047 db_lookup_task(thr_act
->task
),
1048 2*sizeof(vm_offset_t
), thr_act
->task
, act_id
);
1049 db_print_act(thr_act
, act_id
, flag
);
1051 if (db_option(modif
, 'i') && thr_act
->thread
&&
1052 (thr_act
->thread
->state
& TH_WAIT
) &&
1053 thr_act
->thread
->kernel_stack
== 0) {
1055 db_printf("Wait State: option 0x%x\n",
1056 thr_act
->thread
->ith_option
);
1063 boolean_t have_addr
,
1071 flag
= OPTION_TASK_TITLE
|OPTION_INDENT
;
1072 if (db_option(modif
, 'u'))
1073 flag
|= OPTION_USER
;
1074 if (db_option(modif
, 'l'))
1075 flag
|= OPTION_LONG
;
1078 task
= db_current_task();
1079 if (task
== TASK_NULL
) {
1080 db_error("No task\n");
1084 task
= (task_t
) addr
;
1086 if ((task_id
= db_lookup_task(task
)) < 0) {
1087 db_printf("bad task address 0x%x\n", addr
);
1092 db_print_task(task
, task_id
, flag
);
1098 boolean_t have_addr
,
1102 thread_shuttle_t shuttle
;
1103 thread_act_t thr_act
;
1106 shuttle
= (thread_shuttle_t
) addr
;
1108 thr_act
= current_act();
1109 if (thr_act
== THR_ACT_NULL
) {
1110 db_error("No thr_act\n");
1113 shuttle
= thr_act
->thread
;
1114 if (shuttle
== THREAD_NULL
) {
1115 db_error("No shuttle associated with current thr_act\n");
1119 db_printf("shuttle %x:\n", shuttle
);
1120 if (shuttle
->top_act
== THR_ACT_NULL
)
1121 db_printf(" no activations\n");
1123 db_printf(" activations:");
1124 for (thr_act
= shuttle
->top_act
; thr_act
!= THR_ACT_NULL
;
1125 thr_act
= thr_act
->lower
) {
1126 if (thr_act
!= shuttle
->top_act
)
1128 printf(" $task%d.%d(%x)", db_lookup_task(thr_act
->task
),
1129 db_lookup_act(thr_act
), thr_act
);
1135 #define db_pset_kmsg_count(port) \
1136 (ipc_list_count((port)->ip_pset->ips_messages.imq_messages.ikmq_base))
1142 return (port
->ip_pset
? db_pset_kmsg_count(port
) : port
->ip_msgcount
);
1145 static int db_print_ent_cnt
= 0;
1147 void db_reset_print_entry(
1150 db_print_ent_cnt
= 0;
1160 ipc_port_t aport
= (ipc_port_t
)entry
->ie_object
;
1161 unsigned bits
= entry
->ie_bits
;
1163 if (is_pset
&& !aport
->ip_pset
)
1165 if (db_print_ent_cnt
&& db_print_ent_cnt
% 2 == 0)
1168 db_printf("\t%s%d[%x]",
1169 !is_pset
&& aport
->ip_pset
? "pset" : "port",
1171 MACH_PORT_MAKE(index
, IE_BITS_GEN(bits
)));
1173 db_printf("\t%s[%x]",
1174 !is_pset
&& aport
->ip_pset
? "pset" : "port",
1177 db_printf("(%s,%x,%d)",
1178 (bits
& MACH_PORT_TYPE_RECEIVE
)? "r":
1179 (bits
& MACH_PORT_TYPE_SEND
)? "s": "S",
1181 db_port_kmsg_count(aport
));
1185 db_printf("(%s,%x,set=%x,%d)",
1186 (bits
& MACH_PORT_TYPE_RECEIVE
)? "r":
1187 (bits
& MACH_PORT_TYPE_SEND
)? "s": "S",
1190 db_pset_kmsg_count(aport
));
1197 thread_act_t thr_act
,
1199 boolean_t do_output
)
1202 ipc_tree_entry_t tentry
;
1209 space
= thr_act
->task
->itk_space
;
1210 entry
= space
->is_table
;
1211 size
= space
->is_table_size
;
1212 db_reset_print_entry();
1213 for (index
= 0; index
< size
; ++index
, ++entry
) {
1214 if (entry
->ie_bits
& MACH_PORT_TYPE_PORT_RIGHTS
) {
1216 db_print_one_entry(entry
,
1217 index
, (mach_port_t
)0, is_pset
);
1221 for (tentry
= ipc_splay_traverse_start(&space
->is_tree
);
1223 tentry
= ipc_splay_traverse_next(&space
->is_tree
, FALSE
)) {
1224 entry
= &tentry
->ite_entry
;
1225 if (entry
->ie_bits
& MACH_PORT_TYPE_PORT_RIGHTS
) {
1227 db_print_one_entry(entry
,
1228 0, tentry
->ite_name
, is_pset
);
1237 thread_act_t thr_act
,
1240 register ipc_space_t space
;
1241 register ipc_entry_t entry
;
1243 if (thr_act
== THR_ACT_NULL
)
1245 space
= thr_act
->task
->itk_space
;
1246 if (id
< 0 || id
>= space
->is_table_size
)
1248 entry
= &space
->is_table
[id
];
1249 if (entry
->ie_bits
& MACH_PORT_TYPE_PORT_RIGHTS
)
1250 return((ipc_port_t
)entry
->ie_object
);
1261 if (n
!= 0 && n
% 3 == 0)
1263 db_printf("\tport%d(%s,%x)", id
,
1264 (bits
& MACH_PORT_TYPE_RECEIVE
)? "r":
1265 (bits
& MACH_PORT_TYPE_SEND
)? "s": "S", port
);
1271 boolean_t have_addr
,
1275 thread_act_t thr_act
;
1278 thr_act
= current_act();
1279 if (thr_act
== THR_ACT_NULL
) {
1280 db_error("No thr_act\n");
1284 thr_act
= (thread_act_t
) addr
;
1285 if (db_lookup_act(thr_act
) < 0) {
1286 db_printf("Bad thr_act address 0x%x\n", addr
);
1290 if (db_port_iterate(thr_act
, db_option(modif
,'s'), TRUE
))
1295 * Useful system state when the world has hung.
1300 extern void db_device(void);
1301 extern void db_sched(void);
1303 extern void db_dipc_stats(void);
1304 extern void db_show_kkt(void);
1319 db_printf("current_{thread/task} 0x%x 0x%x\n",
1320 current_thread(),current_task());
1323 void db_show_one_runq(run_queue_t runq
);
1328 boolean_t have_addr
,
1332 processor_set_t pset
;
1335 boolean_t showedany
= FALSE
;
1337 queue_iterate(&all_psets
, pset
, processor_set_t
, all_psets
) {
1338 #if NCPUS > 1 /* This code has not been tested. */
1339 queue_iterate(&pset
->processors
, proc
, processor_t
, processors
) {
1341 if (runq
->count
> 0) {
1342 db_printf("PROCESSOR %x IN SET %x\n", proc
, pset
);
1343 db_show_one_runq(runq
);
1347 #endif /* NCPUS > 1 */
1349 #error NCPUS undefined
1352 if (runq
->count
> 0) {
1353 db_printf("PROCESSOR SET %x\n", pset
);
1354 db_show_one_runq(runq
);
1359 db_printf("No runnable threads\n");
1366 int i
, task_id
, thr_act_id
;
1368 thread_act_t thr_act
;
1372 printf("PRI TASK.ACTIVATION\n");
1373 for (i
= runq
->low
, q
= runq
->runq
+ i
; i
< NRQS
; i
++, q
++) {
1374 if (!queue_empty(q
)) {
1375 db_printf("%3d:", i
);
1376 queue_iterate(q
, thread
, thread_t
, links
) {
1377 thr_act
= thread
->top_act
;
1378 task
= thr_act
->task
;
1379 task_id
= db_lookup_task(task
);
1380 thr_act_id
= db_lookup_task_act(task
, thr_act
);
1381 db_printf(" %d.%d", task_id
, thr_act_id
);