]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/ddb/db_ps.c
This commit was generated by cvs2svn to compensate for changes in r147353,
[FreeBSD/FreeBSD.git] / sys / ddb / db_ps.c
1 /*-
2  * Copyright (c) 1993 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 4. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/lock.h>
36 #include <sys/mutex.h>
37 #include <sys/proc.h>
38 #include <sys/cons.h>
39 #include <vm/vm.h>
40 #include <vm/vm_param.h>
41 #include <vm/pmap.h>
42
43 #include <ddb/ddb.h>
44
45 static void     dumpthread(volatile struct proc *p, volatile struct thread *td);
46
47 void
48 db_ps(dummy1, dummy2, dummy3, dummy4)
49         db_expr_t       dummy1;
50         boolean_t       dummy2;
51         db_expr_t       dummy3;
52         char *          dummy4;
53 {
54         volatile struct proc *p, *pp;
55         volatile struct thread *td;
56         char *state;
57         int np, quit;
58
59         np = nprocs;
60         quit = 0;
61
62         /* sx_slock(&allproc_lock); */
63         if (!LIST_EMPTY(&allproc))
64                 p = LIST_FIRST(&allproc);
65         else
66                 p = &proc0;
67
68         db_setup_paging(db_simple_pager, &quit, db_lines_per_page);
69         db_printf("  pid   proc     uid  ppid  pgrp  flag   stat  wmesg    wchan  cmd\n");
70         while (--np >= 0 && !quit) {
71                 if (p == NULL) {
72                         printf("oops, ran out of processes early!\n");
73                         break;
74                 }
75                 /* PROC_LOCK(p); */
76                 pp = p->p_pptr;
77                 if (pp == NULL)
78                         pp = p;
79
80
81                 switch(p->p_state) {
82                 case PRS_NORMAL:
83                         if (P_SHOULDSTOP(p))
84                                 state = "stop";
85                         else
86                                 state = "";
87                         break;
88                 case PRS_NEW:
89                         state = "new ";
90                         break;
91                 case PRS_ZOMBIE:
92                         state = "zomb";
93                         break;
94                 default:
95                         state = "Unkn";
96                         break;
97                 }
98                 db_printf("%5d %8p %4d %5d %5d %07x %s",
99                     p->p_pid, (volatile void *)p,
100                     p->p_ucred != NULL ? p->p_ucred->cr_ruid : 0, pp->p_pid,
101                     p->p_pgrp != NULL ? p->p_pgrp->pg_id : 0, p->p_flag,
102                     state);
103                 if (p->p_flag & P_HADTHREADS)
104                         db_printf("(threaded)  %s\n", p->p_comm);
105                 FOREACH_THREAD_IN_PROC(p, td) {
106                         dumpthread(p, td);
107                         if (quit)
108                                 break;
109                 }
110                 /* PROC_UNLOCK(p); */
111
112                 p = LIST_NEXT(p, p_list);
113                 if (p == NULL && np > 0)
114                         p = LIST_FIRST(&zombproc);
115         }
116         /* sx_sunlock(&allproc_lock); */
117 }
118
119 static void
120 dumpthread(volatile struct proc *p, volatile struct thread *td)
121 {
122
123         if (p->p_flag & P_HADTHREADS)
124                 db_printf( "   thread %p ksegrp %p ", td, td->td_ksegrp);
125         if (TD_ON_SLEEPQ(td))
126                 db_printf("[SLPQ %s %p]", td->td_wmesg, (void *)td->td_wchan);
127         switch (td->td_state) {
128         case TDS_INHIBITED:
129                 if (TD_ON_LOCK(td)) {
130                         db_printf("[LOCK %6s %8p]",
131                             td->td_lockname,
132                             (void *)td->td_blocked);
133                 }
134                 if (TD_IS_SLEEPING(td)) {
135                         db_printf("[SLP]");
136                 }  
137                 if (TD_IS_SWAPPED(td)) {
138                         db_printf("[SWAP]");
139                 }
140                 if (TD_IS_SUSPENDED(td)) {
141                         db_printf("[SUSP]");
142                 }
143                 if (TD_AWAITING_INTR(td)) {
144                         db_printf("[IWAIT]");
145                 }
146                 break;
147         case TDS_CAN_RUN:
148                 db_printf("[Can run]");
149                 break;
150         case TDS_RUNQ:
151                 db_printf("[RUNQ]");
152                 break;
153         case TDS_RUNNING:
154                 db_printf("[CPU %d]", td->td_oncpu);
155                 break;
156         case TDS_INACTIVE:
157                 db_printf("[INACTIVE]");
158                 break;
159         default:
160                 db_printf("[UNK: %#x]", td->td_state);
161         }
162         if (p->p_flag & P_HADTHREADS) {
163 #ifdef KEF_DIDRUN
164                 if (td->td_kse)
165                         db_printf("[kse %p]", td->td_kse);
166 #endif
167                 db_printf("\n");
168         } else
169                 db_printf(" %s\n", p->p_comm);
170 }