2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
28 * Revision 1.1.1.1 1998/09/22 21:05:48 wsanchez
29 * Import of Mac OS X kernel (~semeria)
31 * Revision 1.2 1998/04/29 17:35:25 mburg
34 * Revision 1.2.85.1 1998/02/03 09:24:09 gdt
36 * [1998/02/03 09:10:24 gdt]
38 * Revision 1.2.81.1 1997/03/27 18:46:38 barbou
39 * ri-osc CR1565 - clean up db_print_act, removing old !USER code
40 * which had gotten stale (the option made little sense here anyway).
41 * Added routine db_show_one_thread() to take either act/shuttle and
42 * do something sensible. [dwm] Also rationalize plain, /u and /l
43 * output for "show act", "show task" and "show all acts".
44 * [1995/08/28 15:47:00 bolinger]
47 * Revision 1.2.31.13 1996/01/09 19:16:02 devrcs
48 * Alpha kdebug Changes:
49 * Correct various header spacing to account for 64-bit addresses.
50 * Modify db_show_all_*() functions, so the can be called from kdebug.
51 * ( There's no way to call with "char *modif", so added NULL check. )
52 * Changed db_error() calls to DB_ERROR() macro, so we return on error
53 * on Alpha (we gotta return to kdebug).
54 * Changed declarations of 'register foo' to 'register int foo'.
55 * [1995/12/01 21:42:20 jfraser]
57 * Merged '64-bit safe' changes from DEC alpha port.
58 * [1995/11/21 18:03:24 jfraser]
60 * Revision 1.2.31.12 1995/10/09 17:03:30 devrcs
62 * [1995/08/24 20:56:42 watkins]
64 * Revision 1.2.59.1 1995/08/04 17:03:17 watkins
65 * Change to stack per shuttle model.
66 * [1995/07/19 20:26:13 watkins]
68 * Revision 1.2.31.11 1995/09/18 19:08:49 devrcs
70 * [1995/08/24 20:56:42 watkins]
72 * Revision 1.2.59.1 1995/08/04 17:03:17 watkins
73 * Change to stack per shuttle model.
74 * [1995/07/19 20:26:13 watkins]
76 * Revision 1.2.31.10 1995/05/19 15:43:04 bernadat
77 * Fixed db_print_act for empty activations.
78 * Let thread swapping be configurable.
81 * Revision 1.2.31.9 1995/05/14 18:10:25 dwm
82 * ri-osc CR1304 - merge (nmk19_latest - nmk19b1) diffs into mainline.
83 * mk6 CR938 - restore mach_msg hot path
84 * remove use of now-defunct fields in thread [mmp,dwm]
85 * [1995/05/14 17:25:05 dwm]
87 * Revision 1.2.31.8 1995/04/07 18:53:00 barbou
88 * VM Merge - Task Swapper.
89 * Renamed TH_SWAPPED to TH_STACK_HANDOFF and swap_func to continuation
90 * to resolve name conflict.
91 * From kernel/kdb/kdb_mach.c:
92 * Put in changes for swapping.
93 * [1991/11/21 20:32:15 mmp]
97 * Revision 1.2.31.7 1995/02/28 01:58:38 dwm
98 * mk6 CR1120 - Merge mk6pro_shared into cnmk_shared
99 * * Rev1.2.43.1 1995/01/27 22:01:26 bolinger
100 * * Fix ri-osc CR977: Make "show space" and "show ipc_port" give
101 * * accurate count of ports active in IPC space. Make "show ipc_port"
102 * * output task-visible port name.
103 * [1995/02/28 01:12:46 dwm]
105 * Revision 1.2.31.6 1995/02/23 21:43:34 alanl
106 * Fix db_show_one_task_vm for thread_act_ts.
109 * Merged with DIPC2_SHARED.
112 * Revision 1.2.31.5 1995/01/10 04:49:52 devrcs
113 * mk6 CR801 - merge up from nmk18b4 to nmk18b7
114 * Fix "sh thr/ul"; no cont. to print, fix pri/policy format.
115 * * Rev 1.2.31.4 1994/10/11 16:35:58 emcmanus
116 * Added "show runq" and "show shuttle".
117 * [1994/12/09 20:36:49 dwm]
119 * mk6 CR668 - 1.3b26 merge
120 * * Revision 1.2.8.6 1994/05/06 18:39:37 tmt
121 * Merged osc1.3dec/shared with osc1.3b19
122 * Merge Alpha changes into osc1.312b source code.
125 * [1994/11/04 08:49:52 dwm]
127 * Revision 1.2.31.3 1994/09/23 01:20:51 ezf
128 * change marker to not FREE
129 * [1994/09/22 21:10:41 ezf]
131 * Revision 1.2.31.2 1994/06/14 17:21:05 bolinger
132 * Merge up to NMK17.2.
133 * [1994/06/14 17:20:35 bolinger]
135 * Revision 1.2.23.4 1994/04/15 18:41:31 paire
136 * Changed interface of db_task_from_space routine.
139 * Revision 1.2.23.3 1994/03/07 16:37:48 paire
140 * Merge with Intel R1_1
141 * Change from NMK14.10 [1993/11/15 16:06:21 rwd]
143 * Enhanced pretty print routine and added db_task_from_space.
144 * Change from NMK14.10 [93/09/24 sjs]
147 * Exported ANSI prototype of db_port_kmsg_count routine.
148 * Added header file include for the declaration of db_norma_ipc routine.
151 * Revision 1.2.23.2 1994/02/11 14:21:58 paire
152 * Added new vm_print.h header file for db_vm declaration.
155 * Revision 1.2.23.1 1994/02/08 10:58:19 bernadat
156 * print out msgcount for each port in db_port_iterate
157 * Change from NORMA_MK14.6(August 93) [1993/07/27 12:35:17 mmp]
159 * Removed defintion of db_maxoff (got from <ddb/db_sym.h>).
162 * Show ipc_space_remote msg counts only if NORMA_IPC is on
163 * [93/07/21 bernadat]
165 * Add /s option to "show ipc_port" to pick out port sets.
166 * Change from NORMA_MK14.6 [1993/02/17 16:29:54 dwm]
167 * [93/07/16 bernadat]
168 * [94/02/07 bernadat]
170 * Revision 1.2.20.8 1994/06/08 19:11:15 dswartz
172 * [1994/06/08 19:10:18 dswartz]
174 * Revision 1.2.20.7 1994/04/30 21:28:24 bolinger
175 * Thread control ops synchronization: now that TH_SUSP is back,
176 * enable ddb to show it when printing thread state.
177 * [1994/04/28 21:55:42 bolinger]
179 * Revision 1.2.20.6 1994/03/17 22:35:31 dwm
180 * The infamous name change: thread_activation + thread_shuttle = thread.
181 * [1994/03/17 21:25:46 dwm]
183 * Revision 1.2.20.5 1994/01/26 15:43:37 bolinger
184 * Move kernel_stack from thread to activation.
185 * [1994/01/25 21:53:11 bolinger]
187 * Revision 1.2.20.4 1994/01/12 17:50:44 dwm
188 * Coloc: initial restructuring to follow Utah model.
189 * [1994/01/12 17:13:12 dwm]
191 * Revision 1.2.20.3 1993/11/18 18:11:47 dwm
192 * Coloc: remove continuations entirely; they are incompatible
193 * with migration, and their volume is obfuscatory.
194 * [1993/11/18 18:06:27 dwm]
196 * Revision 1.2.20.2 1993/10/12 16:38:50 dwm
197 * CoLoc: neuter continuations, ifdef USE_CONTINUATIONS.
198 * [1993/10/12 16:14:46 dwm]
200 * Revision 1.2.8.4 1993/08/11 20:38:06 elliston
201 * Add ANSI Prototypes. CR #9523.
202 * [1993/08/11 03:33:51 elliston]
204 * Revision 1.2.8.3 1993/07/27 18:27:55 elliston
205 * Add ANSI prototypes. CR #9523.
206 * [1993/07/27 18:12:39 elliston]
208 * Revision 1.2.8.2 1993/06/09 02:20:35 gm
209 * CR9176 - ANSI C violations: trailing tokens on CPP
210 * directives, extra semicolons after decl_ ..., asm keywords
211 * [1993/06/07 18:57:22 jeffc]
213 * Removed a '#if MACH_FIXPRI' which somehow survived the purge. CR #9131.
214 * [1993/05/11 20:56:00 dswartz]
216 * Revision 1.2 1993/04/19 16:02:50 devrcs
217 * Added printout of thread scheduling policy to long form
222 * Removed unused variable from db_show_regs().
224 * Converted some db_printsyms to db_task_printsyms.
226 * Changed db_print_thread so that both display formats
227 * show the floating-point-used status of the thread.
231 * Revision 1.1 1992/09/30 02:01:18 robert
238 * Revision 2.11.3.2 92/04/08 15:43:10 jeffreyh
239 * Added i option to show thread. This gives wait state information.
242 * Revision 2.11.3.1 92/03/03 16:13:34 jeffreyh
243 * Pick up changes from TRUNK
244 * [92/02/26 11:00:01 jeffreyh]
246 * Revision 2.13 92/02/20 18:34:28 elf
250 * Revision 2.12 92/02/19 15:07:47 elf
251 * Added db_thread_fp_used, to avoid machine-dependent conditionals.
254 * Added 'F' flag to db_thread_stat showing if the thread has a valid
255 * FPU context. Tested on i386 and pmax.
258 * Revision 2.11 91/11/12 11:50:32 rvb
259 * Added OPTION_USER ("/u") to db_show_all_threads, db_show_one_thread,
260 * db_show_one_task. Without it, we display old-style information.
263 * Revision 2.10 91/10/09 16:01:48 af
264 * Supported "show registers" for non current thread.
265 * Changed display format of thread and task information.
266 * Changed "show thread" to print current thread information
267 * if no thread is specified.
268 * Added "show_one_task" for "show task" command.
269 * Added IPC port print routines for "show ipc_port" command.
272 * Revision 2.9 91/08/03 18:17:19 jsb
273 * In db_print_thread, if the thread is swapped and there is a
274 * continuation function, print the function name in parentheses
275 * instead of '(swapped)'.
276 * [91/07/04 09:59:27 jsb]
278 * Revision 2.8 91/07/31 17:30:43 dbg
279 * Revise scheduling state machine.
280 * [91/07/30 16:43:42 dbg]
282 * Revision 2.7 91/07/09 23:15:57 danner
283 * Fixed a few printf that should be db_printfs.
286 * Revision 2.6 91/05/14 15:35:25 mrt
287 * Correcting copyright
289 * Revision 2.5 91/02/05 17:06:53 mrt
290 * Changed to new Mach copyright
291 * [91/01/31 16:18:56 mrt]
293 * Revision 2.4 90/10/25 14:43:54 rwd
294 * Changed db_show_regs to print unsigned.
296 * Generalized the watchpoint support.
299 * Revision 2.3 90/09/09 23:19:52 rpd
300 * Avoid totally incorrect guesses of symbol names for small values.
301 * [90/08/30 17:39:08 af]
303 * Revision 2.2 90/08/27 21:51:49 dbg
304 * Insist that 'show thread' be called with an explicit address.
307 * Fix type for db_maxoff.
310 * Do not dereference the "valuep" field of a variable directly,
311 * call the new db_read/write_variable functions instead.
312 * Reflected changes in symbol lookup functions.
315 * [90/08/10 14:33:44 dbg]
323 * Mach Operating System
324 * Copyright (c) 1991,1990 Carnegie Mellon University
325 * All Rights Reserved.
327 * Permission to use, copy, modify and distribute this software and its
328 * documentation is hereby granted, provided that both the copyright
329 * notice and this permission notice appear in all copies of the
330 * software, derivative works or modified versions, and any portions
331 * thereof, and that both notices appear in supporting documentation.
333 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
334 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
335 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
337 * Carnegie Mellon requests users of this software to return to
339 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
340 * School of Computer Science
341 * Carnegie Mellon University
342 * Pittsburgh PA 15213-3890
344 * any improvements or extensions that they make and grant Carnegie Mellon
345 * the rights to redistribute these changes.
350 * Author: David B. Golub, Carnegie Mellon University
355 * Miscellaneous printing.
358 #include <task_swapper.h>
360 #include <string.h> /* For strlen() */
361 #include <mach/port.h>
362 #include <kern/task.h>
363 #include <kern/thread.h>
364 #include <kern/thread_swap.h>
365 #include <kern/queue.h>
366 #include <ipc/ipc_port.h>
367 #include <ipc/ipc_space.h>
368 #include <ipc/ipc_pset.h>
369 #include <vm/vm_print.h> /* for db_vm() */
371 #include <machine/db_machdep.h>
372 #include <machine/thread.h>
374 #include <ddb/db_lex.h>
375 #include <ddb/db_variables.h>
376 #include <ddb/db_sym.h>
377 #include <ddb/db_task_thread.h>
378 #include <ddb/db_command.h>
379 #include <ddb/db_output.h> /* For db_printf() */
380 #include <ddb/db_print.h>
383 #include <kern/sp_mk.h> /*** ??? fix so this can be removed ***/
386 #include <kern/task_swap.h>
387 #endif /* TASK_SWAPPER */
389 /* Prototypes for functions local to this file. XXX -- should be static!
393 register thread_act_t thr_act
,
396 char *db_act_swap_stat(
397 register thread_act_t thr_act
,
405 void db_reset_print_entry(
408 void db_print_one_entry(
411 mach_port_name_t name
,
415 thread_act_t thr_act
,
417 boolean_t do_output
);
419 ipc_port_t
db_lookup_port(
420 thread_act_t thr_act
,
423 static void db_print_port_id(
430 thread_act_t thr_act
,
439 void db_print_task_vm(
445 void db_system_stats(void);
455 register struct db_variable
*regp
;
460 struct db_var_aux_param aux_param
;
461 task_t task
= TASK_NULL
;
463 aux_param
.modif
= modif
;
464 aux_param
.thr_act
= THR_ACT_NULL
;
465 if (db_option(modif
, 't')) {
467 if (!db_check_act_address_valid((thread_act_t
)addr
))
469 aux_param
.thr_act
= (thread_act_t
)addr
;
471 aux_param
.thr_act
= db_default_act
;
472 if (aux_param
.thr_act
!= THR_ACT_NULL
)
473 task
= aux_param
.thr_act
->task
;
475 for (regp
= db_regs
; regp
< db_eregs
; regp
++) {
476 if (regp
->max_level
> 1) {
477 db_printf("bad multi-suffixed register %s\n", regp
->name
);
480 aux_param
.level
= regp
->max_level
;
481 for (i
= regp
->low
; i
<= regp
->high
; i
++) {
482 aux_param
.suffix
[0] = i
;
483 db_read_write_variable(regp
, &value
, DB_VAR_GET
, &aux_param
);
484 if (regp
->max_level
> 0)
485 db_printf("%s%d%*s", regp
->name
, i
,
486 12-strlen(regp
->name
)-((i
<10)?1:2), "");
488 db_printf("%-12s", regp
->name
);
489 db_printf("%#*N", 2+2*sizeof(vm_offset_t
), value
);
490 db_find_xtrn_task_sym_and_offset((db_addr_t
)value
, &name
,
492 if (name
!= 0 && offset
<= db_maxoff
&& offset
!= value
) {
493 db_printf("\t%s", name
);
495 db_printf("+%#r", offset
);
502 #define OPTION_LONG 0x001 /* long print option */
503 #define OPTION_USER 0x002 /* print ps-like stuff */
504 #define OPTION_INDENT 0x100 /* print with indent */
505 #define OPTION_THREAD_TITLE 0x200 /* print thread title */
506 #define OPTION_TASK_TITLE 0x400 /* print thread title */
509 #define DB_TASK_NAME(task) /* no task name */
510 #define DB_TASK_NAME_TITLE "" /* no task name */
511 #endif /* DB_TASK_NAME */
513 #ifndef db_act_fp_used
514 #define db_act_fp_used(thr_act) FALSE
519 register thread_act_t thr_act
,
522 register char *p
= status
;
524 if (!thr_act
->active
) {
531 } else if (!thr_act
->thread
) {
539 thread_t athread
= thr_act
->thread
;
541 *p
++ = (athread
->state
& TH_RUN
) ? 'R' : '.';
542 *p
++ = (athread
->state
& TH_WAIT
) ? 'W' : '.';
543 *p
++ = (athread
->state
& TH_SUSP
) ? 'S' : '.';
544 *p
++ = (athread
->state
& TH_SWAPPED_OUT
) ? 'O' : '.';
545 *p
++ = (athread
->state
& TH_UNINT
) ? 'N' : '.';
546 /* show if the FPU has been used */
547 *p
++ = db_act_fp_used(thr_act
) ? 'F' : '.';
555 register thread_act_t thr_act
,
558 register char *p
= status
;
561 switch (thr_act
->swap_state
& TH_SW_STATE
) {
562 case TH_SW_UNSWAPPABLE
:
568 case TH_SW_GOING_OUT
:
577 case TH_SW_COMING_IN
:
584 *p
++ = (thr_act
->swap_state
& TH_SW_TASK_SWAPPING
) ? 'T' : '.';
585 #endif /* THREAD_SWAPPER */
591 char *policy_list
[] = { "TS", "RR", "??", "FF",
592 "??", "??", "??", "BE"};
596 thread_act_t thr_act
,
607 db_printf("db_print_act(NULL)!\n");
611 athread
= thr_act
->thread
;
612 if (flag
& OPTION_USER
) {
614 if (flag
& OPTION_LONG
) {
615 if (flag
& OPTION_INDENT
)
617 if (flag
& OPTION_THREAD_TITLE
) {
618 db_printf("%s ID: ACT STAT SW STACK SHUTTLE", indent
);
619 db_printf(" SUS PRI WAIT_FUNC\n");
621 policy
= (athread
? athread
->policy
: 2);
622 db_printf("%s%3d%c %0*X %s %s %0*X %0*X %3d %3d/%s ",
624 (thr_act
== current_act())? '#': ':',
625 2*sizeof(vm_offset_t
), thr_act
,
626 db_act_stat(thr_act
, status
),
627 db_act_swap_stat(thr_act
, swap_status
),
628 2*sizeof(vm_offset_t
), (athread
?athread
->kernel_stack
:0),
629 2*sizeof(vm_offset_t
), athread
,
630 thr_act
->suspend_count
,
631 (athread
? athread
->sched_pri
: 999), /* XXX */
632 policy_list
[policy
-1]);
634 /* no longer TH_SWAP, no continuation to print */
635 if (athread
->state
& TH_WAIT
)
636 db_task_printsym((db_addr_t
)athread
->wait_event
,
637 DB_STGY_ANY
, kernel_task
);
641 if (act_id
% 3 == 0) {
642 if (flag
& OPTION_INDENT
)
646 db_printf("%3d%c(%0*X,%s)", act_id
,
647 (thr_act
== current_act())? '#': ':',
648 2*sizeof(vm_offset_t
), thr_act
,
649 db_act_stat(thr_act
, status
));
652 if (flag
& OPTION_INDENT
)
653 db_printf(" %3d (%0*X) ", act_id
,
654 2*sizeof(vm_offset_t
), thr_act
);
656 db_printf("(%0*X) ", 2*sizeof(vm_offset_t
), thr_act
);
658 db_printf("%c%c%c%c%c",
659 (athread
->state
& TH_RUN
) ? 'R' : ' ',
660 (athread
->state
& TH_WAIT
) ? 'W' : ' ',
661 (athread
->state
& TH_SUSP
) ? 'S' : ' ',
662 (athread
->state
& TH_UNINT
)? 'N' : ' ',
663 db_act_fp_used(thr_act
) ? 'F' : ' ');
664 /* Obsolete TH_STACK_HANDOFF code, left for now; might enhance
665 * to print out safe_points instead */
666 if (athread
->state
& TH_STACK_HANDOFF
) {
667 if (athread
->continuation
) {
669 db_task_printsym((db_addr_t
)athread
->continuation
,
670 DB_STGY_ANY
, kernel_task
);
673 db_printf("(handoff)");
676 if (athread
->state
& TH_WAIT
) {
678 db_task_printsym((db_addr_t
)athread
->wait_event
,
679 DB_STGY_ANY
, kernel_task
);
693 thread_act_t thr_act
;
697 if (flag
& OPTION_USER
) {
698 if (flag
& OPTION_TASK_TITLE
) {
699 db_printf(" ID: TASK MAP THD RES SUS PR SW %s",
701 if ((flag
& OPTION_LONG
) == 0)
706 switch ((int) task
->swap_state
) {
713 case TASK_SW_GOING_OUT
:
716 case TASK_SW_COMING_IN
:
719 case TASK_SW_UNSWAPPABLE
:
726 #else /* TASK_SWAPPER */
728 #endif /* TASK_SWAPPER */
730 db_printf("%3d: %0*X %0*X %3d %3d %3d %2d %c ",
731 task_id
, 2*sizeof(vm_offset_t
), task
,
732 2*sizeof(vm_offset_t
), task
->map
,
733 task
->thr_act_count
, task
->res_act_count
,
735 ((mk_sp_attributes_t
)(task
->sp_attributes
))->priority
,
738 if (flag
& OPTION_LONG
) {
739 if (flag
& OPTION_TASK_TITLE
)
740 flag
|= OPTION_THREAD_TITLE
;
742 } else if (task
->thr_act_count
<= 1)
743 flag
&= ~OPTION_INDENT
;
745 queue_iterate(&task
->thr_acts
, thr_act
, thread_act_t
, thr_acts
) {
746 db_print_act(thr_act
, act_id
, flag
);
747 flag
&= ~OPTION_THREAD_TITLE
;
750 if ((flag
& OPTION_LONG
) == 0)
753 if (flag
& OPTION_LONG
) {
754 if (flag
& OPTION_TASK_TITLE
) {
755 db_printf(" TASK ACT\n");
756 if (task
->thr_act_count
> 1)
757 flag
|= OPTION_THREAD_TITLE
;
760 db_printf("%3d (%0*X): ", task_id
, 2*sizeof(vm_offset_t
), task
);
761 if (task
->thr_act_count
== 0) {
762 db_printf("no threads\n");
764 if (task
->thr_act_count
> 1) {
765 db_printf("%d threads: \n", task
->thr_act_count
);
766 flag
|= OPTION_INDENT
;
768 flag
&= ~OPTION_INDENT
;
770 queue_iterate(&task
->thr_acts
, thr_act
,
771 thread_act_t
, thr_acts
) {
772 db_print_act(thr_act
, act_id
++, flag
);
773 flag
&= ~OPTION_THREAD_TITLE
;
786 thread_act_t act
= (thread_act_t
)queue_first(&task
->thr_acts
);
790 space
= task
->itk_space
;
792 count
= db_port_iterate(act
, FALSE
, FALSE
);
793 db_printf("%3d: %08x %08x %08x %sactive %d\n",
794 task_id
, task
, space
, task
->map
,
795 space
->is_active
? "":"!", count
);
812 db_printf("id task map pmap virtual rss pg rss mem wir pg wir mem\n");
816 pmap
= vm_map_pmap(map
);
818 size
= db_vm_map_total_size(map
);
819 resident
= pmap
->stats
.resident_count
;
820 wired
= pmap
->stats
.wired_count
;
822 db_printf("%2d %08x %08x %08x %7dK %6d %6dK %6d %6dK\n",
828 resident
, (resident
* PAGE_SIZE
) / 1024,
829 wired
, (wired
* PAGE_SIZE
) / 1024);
844 if (have_addr
== FALSE
) {
845 if ((thread
= db_default_act
) == THR_ACT_NULL
) {
846 if ((thread
= current_act()) == THR_ACT_NULL
) {
847 db_printf("no thread.\n");
853 task
= (task_t
) addr
;
856 task_id
= db_lookup_task(task
);
858 db_printf("0x%x is not a task_t\n", addr
);
862 db_print_task_vm(task
, task_id
, TRUE
, modif
);
874 boolean_t title
= TRUE
;
875 processor_set_t pset
;
878 queue_iterate(&all_psets
, pset
, processor_set_t
, all_psets
) {
879 queue_iterate(&pset
->tasks
, task
, task_t
, pset_tasks
) {
880 db_print_task_vm(task
, task_id
, title
, modif
);
897 processor_set_t pset
;
899 flag
= OPTION_TASK_TITLE
|OPTION_INDENT
;
900 if (db_option(modif
, 'u'))
902 if (db_option(modif
, 'l'))
906 queue_iterate(&all_psets
, pset
, processor_set_t
, all_psets
) {
907 queue_iterate(&pset
->tasks
, task
, task_t
, pset_tasks
) {
908 db_print_task(task
, task_id
, flag
);
909 flag
&= ~OPTION_TASK_TITLE
;
911 if ((flag
& (OPTION_LONG
|OPTION_INDENT
)) == OPTION_INDENT
)
928 flag
= OPTION_TASK_TITLE
;
929 if (db_option(modif
, 'u'))
931 if (db_option(modif
, 'l'))
935 task
= db_current_task();
936 if (task
== TASK_NULL
) {
937 db_error("No task\n");
941 task
= (task_t
) addr
;
943 if ((task_id
= db_lookup_task(task
)) < 0) {
944 db_printf("bad task address 0x%x\n", addr
);
949 db_printf(" ID: TASK SPACE MAP COUNT\n");
950 db_print_space(task
, task_id
, flag
);
963 processor_set_t pset
;
965 flag
= OPTION_TASK_TITLE
|OPTION_INDENT
;
966 if (db_option(modif
, 'u'))
968 if (db_option(modif
, 'l'))
971 db_printf(" ID: TASK SPACE MAP COUNT\n");
972 queue_iterate(&all_psets
, pset
, processor_set_t
, all_psets
) {
973 queue_iterate(&pset
->tasks
, task
, task_t
, pset_tasks
) {
974 db_print_space(task
, task_id
, flag
);
987 processor_set_t pset
;
989 queue_iterate(&all_psets
, pset
, processor_set_t
, all_psets
) {
990 queue_iterate(&pset
->tasks
, task
, task_t
, pset_tasks
) {
991 if (task
->itk_space
== space
) {
993 return (db_addr_t
)task
;
1005 boolean_t have_addr
,
1011 thread_act_t thr_act
;
1013 flag
= OPTION_THREAD_TITLE
;
1014 if (db_option(modif
, 'u'))
1015 flag
|= OPTION_USER
;
1016 if (db_option(modif
, 'l'))
1017 flag
|= OPTION_LONG
;
1020 thr_act
= current_act();
1021 if (thr_act
== THR_ACT_NULL
) {
1022 db_error("No thr_act\n");
1026 thr_act
= (thread_act_t
) addr
;
1028 if ((act_id
= db_lookup_act(thr_act
)) < 0) {
1029 db_printf("bad thr_act address %#x\n", addr
);
1034 if (flag
& OPTION_USER
) {
1035 db_printf("TASK%d(%0*X):\n",
1036 db_lookup_task(thr_act
->task
),
1037 2*sizeof(vm_offset_t
), thr_act
->task
);
1038 db_print_act(thr_act
, act_id
, flag
);
1040 db_printf("task %d(%0*Xx): thr_act %d",
1041 db_lookup_task(thr_act
->task
),
1042 2*sizeof(vm_offset_t
), thr_act
->task
, act_id
);
1043 db_print_act(thr_act
, act_id
, flag
);
1045 if (db_option(modif
, 'i') && thr_act
->thread
&&
1046 (thr_act
->thread
->state
& TH_WAIT
) &&
1047 thr_act
->thread
->kernel_stack
== 0) {
1049 db_printf("Wait State: option 0x%x\n",
1050 thr_act
->thread
->ith_option
);
1057 boolean_t have_addr
,
1065 flag
= OPTION_TASK_TITLE
|OPTION_INDENT
;
1066 if (db_option(modif
, 'u'))
1067 flag
|= OPTION_USER
;
1068 if (db_option(modif
, 'l'))
1069 flag
|= OPTION_LONG
;
1072 task
= db_current_task();
1073 if (task
== TASK_NULL
) {
1074 db_error("No task\n");
1078 task
= (task_t
) addr
;
1080 if ((task_id
= db_lookup_task(task
)) < 0) {
1081 db_printf("bad task address 0x%x\n", addr
);
1086 db_print_task(task
, task_id
, flag
);
1092 boolean_t have_addr
,
1096 thread_shuttle_t shuttle
;
1097 thread_act_t thr_act
;
1100 shuttle
= (thread_shuttle_t
) addr
;
1102 thr_act
= current_act();
1103 if (thr_act
== THR_ACT_NULL
) {
1104 db_error("No thr_act\n");
1107 shuttle
= thr_act
->thread
;
1108 if (shuttle
== THREAD_NULL
) {
1109 db_error("No shuttle associated with current thr_act\n");
1113 db_printf("shuttle %x:\n", shuttle
);
1114 if (shuttle
->top_act
== THR_ACT_NULL
)
1115 db_printf(" no activations\n");
1117 db_printf(" activations:");
1118 for (thr_act
= shuttle
->top_act
; thr_act
!= THR_ACT_NULL
;
1119 thr_act
= thr_act
->lower
) {
1120 if (thr_act
!= shuttle
->top_act
)
1122 printf(" $task%d.%d(%x)", db_lookup_task(thr_act
->task
),
1123 db_lookup_act(thr_act
), thr_act
);
1129 #define db_pset_kmsg_count(port) \
1130 (ipc_list_count((port)->ip_pset->ips_messages.imq_messages.ikmq_base))
1136 return (port
->ip_pset
? db_pset_kmsg_count(port
) : port
->ip_msgcount
);
1139 static int db_print_ent_cnt
= 0;
1141 void db_reset_print_entry(
1144 db_print_ent_cnt
= 0;
1154 ipc_port_t aport
= (ipc_port_t
)entry
->ie_object
;
1155 unsigned bits
= entry
->ie_bits
;
1157 if (is_pset
&& !aport
->ip_pset
)
1159 if (db_print_ent_cnt
&& db_print_ent_cnt
% 2 == 0)
1162 db_printf("\t%s%d[%x]",
1163 !is_pset
&& aport
->ip_pset
? "pset" : "port",
1165 MACH_PORT_MAKE(index
, IE_BITS_GEN(bits
)));
1167 db_printf("\t%s[%x]",
1168 !is_pset
&& aport
->ip_pset
? "pset" : "port",
1171 db_printf("(%s,%x,%d)",
1172 (bits
& MACH_PORT_TYPE_RECEIVE
)? "r":
1173 (bits
& MACH_PORT_TYPE_SEND
)? "s": "S",
1175 db_port_kmsg_count(aport
));
1179 db_printf("(%s,%x,set=%x,%d)",
1180 (bits
& MACH_PORT_TYPE_RECEIVE
)? "r":
1181 (bits
& MACH_PORT_TYPE_SEND
)? "s": "S",
1184 db_pset_kmsg_count(aport
));
1191 thread_act_t thr_act
,
1193 boolean_t do_output
)
1196 ipc_tree_entry_t tentry
;
1203 space
= thr_act
->task
->itk_space
;
1204 entry
= space
->is_table
;
1205 size
= space
->is_table_size
;
1206 db_reset_print_entry();
1207 for (index
= 0; index
< size
; ++index
, ++entry
) {
1208 if (entry
->ie_bits
& MACH_PORT_TYPE_PORT_RIGHTS
) {
1210 db_print_one_entry(entry
,
1211 index
, (mach_port_t
)0, is_pset
);
1215 for (tentry
= ipc_splay_traverse_start(&space
->is_tree
);
1217 tentry
= ipc_splay_traverse_next(&space
->is_tree
, FALSE
)) {
1218 entry
= &tentry
->ite_entry
;
1219 if (entry
->ie_bits
& MACH_PORT_TYPE_PORT_RIGHTS
) {
1221 db_print_one_entry(entry
,
1222 0, tentry
->ite_name
, is_pset
);
1231 thread_act_t thr_act
,
1234 register ipc_space_t space
;
1235 register ipc_entry_t entry
;
1237 if (thr_act
== THR_ACT_NULL
)
1239 space
= thr_act
->task
->itk_space
;
1240 if (id
< 0 || id
>= space
->is_table_size
)
1242 entry
= &space
->is_table
[id
];
1243 if (entry
->ie_bits
& MACH_PORT_TYPE_PORT_RIGHTS
)
1244 return((ipc_port_t
)entry
->ie_object
);
1255 if (n
!= 0 && n
% 3 == 0)
1257 db_printf("\tport%d(%s,%x)", id
,
1258 (bits
& MACH_PORT_TYPE_RECEIVE
)? "r":
1259 (bits
& MACH_PORT_TYPE_SEND
)? "s": "S", port
);
1265 boolean_t have_addr
,
1269 thread_act_t thr_act
;
1272 thr_act
= current_act();
1273 if (thr_act
== THR_ACT_NULL
) {
1274 db_error("No thr_act\n");
1278 thr_act
= (thread_act_t
) addr
;
1279 if (db_lookup_act(thr_act
) < 0) {
1280 db_printf("Bad thr_act address 0x%x\n", addr
);
1284 if (db_port_iterate(thr_act
, db_option(modif
,'s'), TRUE
))
1289 * Useful system state when the world has hung.
1294 extern void db_device(void);
1295 extern void db_sched(void);
1297 extern void db_dipc_stats(void);
1298 extern void db_show_kkt(void);
1313 db_printf("current_{thread/task} 0x%x 0x%x\n",
1314 current_thread(),current_task());
1317 void db_show_one_runq(run_queue_t runq
);
1322 boolean_t have_addr
,
1326 processor_set_t pset
;
1329 boolean_t showedany
= FALSE
;
1331 queue_iterate(&all_psets
, pset
, processor_set_t
, all_psets
) {
1332 #if NCPUS > 1 /* This code has not been tested. */
1333 queue_iterate(&pset
->processors
, proc
, processor_t
, processors
) {
1335 if (runq
->count
> 0) {
1336 db_printf("PROCESSOR %x IN SET %x\n", proc
, pset
);
1337 db_show_one_runq(runq
);
1341 #endif /* NCPUS > 1 */
1343 #error NCPUS undefined
1346 if (runq
->count
> 0) {
1347 db_printf("PROCESSOR SET %x\n", pset
);
1348 db_show_one_runq(runq
);
1353 db_printf("No runnable threads\n");
1360 int i
, task_id
, thr_act_id
;
1362 thread_act_t thr_act
;
1366 printf("PRI TASK.ACTIVATION\n");
1367 for (i
= runq
->low
, q
= runq
->runq
+ i
; i
< NRQS
; i
++, q
++) {
1368 if (!queue_empty(q
)) {
1369 db_printf("%3d:", i
);
1370 queue_iterate(q
, thread
, thread_t
, links
) {
1371 thr_act
= thread
->top_act
;
1372 task
= thr_act
->task
;
1373 task_id
= db_lookup_task(task
);
1374 thr_act_id
= db_lookup_task_act(task
, thr_act
);
1375 db_printf(" %d.%d", task_id
, thr_act_id
);