1994-08-27 16:28:45 +00:00
|
|
|
/*-
|
2017-11-20 19:43:44 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
1994-08-27 16:28:45 +00:00
|
|
|
* Copyright (c) 1993 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-08-27 16:28:45 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
2003-06-10 22:09:23 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2015-07-16 10:46:52 +00:00
|
|
|
#include "opt_kstack_pages.h"
|
|
|
|
|
1994-08-27 16:28:45 +00:00
|
|
|
#include <sys/param.h>
|
2006-04-27 22:09:18 +00:00
|
|
|
#include <sys/cons.h>
|
2006-04-25 20:34:04 +00:00
|
|
|
#include <sys/jail.h>
|
|
|
|
#include <sys/kdb.h>
|
2016-03-25 19:35:29 +00:00
|
|
|
#include <sys/kernel.h>
|
1994-08-27 16:28:45 +00:00
|
|
|
#include <sys/proc.h>
|
2006-04-25 20:34:04 +00:00
|
|
|
#include <sys/sysent.h>
|
2006-04-27 22:09:18 +00:00
|
|
|
#include <sys/systm.h>
|
2011-12-16 11:44:20 +00:00
|
|
|
#include <sys/_kstack_cache.h>
|
2002-12-28 01:23:07 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/pmap.h>
|
2018-05-25 13:59:48 +00:00
|
|
|
#include <vm/vm_map.h>
|
1994-08-27 16:28:45 +00:00
|
|
|
|
1995-12-10 19:08:32 +00:00
|
|
|
#include <ddb/ddb.h>
|
2003-06-06 17:19:27 +00:00
|
|
|
|
2018-08-09 11:21:31 +00:00
|
|
|
#define PRINT_NONE 0
|
|
|
|
#define PRINT_ARGS 1
|
|
|
|
|
2006-04-25 20:34:04 +00:00
|
|
|
static void dumpthread(volatile struct proc *p, volatile struct thread *td,
|
|
|
|
int all);
|
2018-08-09 11:21:31 +00:00
|
|
|
static int ps_mode;
|
|
|
|
|
2008-03-25 20:36:32 +00:00
|
|
|
/*
|
|
|
|
* At least one non-optional show-command must be implemented using
|
|
|
|
* DB_SHOW_ALL_COMMAND() so that db_show_all_cmd_set gets created.
|
|
|
|
* Here is one.
|
|
|
|
*/
|
|
|
|
DB_SHOW_ALL_COMMAND(procs, db_procs_cmd)
|
|
|
|
{
|
|
|
|
db_ps(addr, have_addr, count, modif);
|
|
|
|
}
|
1995-12-10 19:08:32 +00:00
|
|
|
|
2018-08-09 11:21:31 +00:00
|
|
|
static void
|
|
|
|
dump_args(volatile struct proc *p)
|
|
|
|
{
|
|
|
|
char *args;
|
|
|
|
int i, len;
|
|
|
|
|
|
|
|
if (p->p_args == NULL)
|
|
|
|
return;
|
|
|
|
args = p->p_args->ar_args;
|
|
|
|
len = (int)p->p_args->ar_length;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (args[i] == '\0')
|
|
|
|
db_printf(" ");
|
|
|
|
else
|
|
|
|
db_printf("%c", args[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-25 20:34:04 +00:00
|
|
|
/*
|
|
|
|
* Layout:
|
|
|
|
* - column counts
|
|
|
|
* - header
|
|
|
|
* - single-threaded process
|
|
|
|
* - multi-threaded process
|
|
|
|
* - thread in a MT process
|
|
|
|
*
|
|
|
|
* 1 2 3 4 5 6 7
|
|
|
|
* 1234567890123456789012345678901234567890123456789012345678901234567890
|
2016-08-14 15:26:40 +00:00
|
|
|
* pid ppid pgrp uid state wmesg wchan cmd
|
|
|
|
* <pid> <ppi> <pgi> <uid> <stat> <wmesg> <wchan > <name>
|
2006-08-01 22:30:55 +00:00
|
|
|
* <pid> <ppi> <pgi> <uid> <stat> (threaded) <command>
|
2016-08-14 15:26:40 +00:00
|
|
|
* <tid > <stat> <wmesg> <wchan > <name>
|
2006-04-25 20:34:04 +00:00
|
|
|
*
|
|
|
|
* For machines with 64-bit pointers, we expand the wchan field 8 more
|
|
|
|
* characters.
|
|
|
|
*/
|
1994-08-27 16:28:45 +00:00
|
|
|
void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_ps(db_expr_t addr, bool hasaddr, db_expr_t count, char *modif)
|
1995-08-27 02:40:39 +00:00
|
|
|
{
|
1995-08-20 05:25:11 +00:00
|
|
|
volatile struct proc *p, *pp;
|
2001-10-20 03:22:23 +00:00
|
|
|
volatile struct thread *td;
|
2006-04-25 20:34:04 +00:00
|
|
|
struct ucred *cred;
|
|
|
|
struct pgrp *pgrp;
|
|
|
|
char state[9];
|
2006-07-12 21:22:44 +00:00
|
|
|
int np, rflag, sflag, dflag, lflag, wflag;
|
1995-08-20 05:25:11 +00:00
|
|
|
|
2018-08-09 11:21:31 +00:00
|
|
|
ps_mode = modif[0] == 'a' ? PRINT_ARGS : PRINT_NONE;
|
1994-08-27 16:28:45 +00:00
|
|
|
np = nprocs;
|
1995-08-20 05:25:11 +00:00
|
|
|
|
2000-12-30 22:06:19 +00:00
|
|
|
if (!LIST_EMPTY(&allproc))
|
|
|
|
p = LIST_FIRST(&allproc);
|
1995-08-20 05:25:11 +00:00
|
|
|
else
|
|
|
|
p = &proc0;
|
1994-08-27 16:28:45 +00:00
|
|
|
|
2006-05-11 21:59:55 +00:00
|
|
|
#ifdef __LP64__
|
2016-08-14 15:26:40 +00:00
|
|
|
db_printf(" pid ppid pgrp uid state wmesg wchan cmd\n");
|
2006-04-25 20:34:04 +00:00
|
|
|
#else
|
2016-08-14 15:26:40 +00:00
|
|
|
db_printf(" pid ppid pgrp uid state wmesg wchan cmd\n");
|
2006-04-25 20:34:04 +00:00
|
|
|
#endif
|
2006-07-12 21:22:44 +00:00
|
|
|
while (--np >= 0 && !db_pager_quit) {
|
1996-06-15 07:08:02 +00:00
|
|
|
if (p == NULL) {
|
2006-04-25 20:34:04 +00:00
|
|
|
db_printf("oops, ran out of processes early!\n");
|
1996-06-15 07:08:02 +00:00
|
|
|
break;
|
|
|
|
}
|
1994-08-27 16:28:45 +00:00
|
|
|
pp = p->p_pptr;
|
1995-08-20 05:25:11 +00:00
|
|
|
if (pp == NULL)
|
1994-08-27 16:28:45 +00:00
|
|
|
pp = p;
|
1995-08-20 05:25:11 +00:00
|
|
|
|
2006-04-25 20:34:04 +00:00
|
|
|
cred = p->p_ucred;
|
|
|
|
pgrp = p->p_pgrp;
|
2006-08-01 15:29:46 +00:00
|
|
|
db_printf("%5d %5d %5d %5d ", p->p_pid, pp->p_pid,
|
|
|
|
pgrp != NULL ? pgrp->pg_id : 0,
|
|
|
|
cred != NULL ? cred->cr_ruid : 0);
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
|
2006-04-25 20:34:04 +00:00
|
|
|
/* Determine our primary process state. */
|
2006-04-27 22:02:27 +00:00
|
|
|
switch (p->p_state) {
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
case PRS_NORMAL:
|
|
|
|
if (P_SHOULDSTOP(p))
|
2006-04-25 20:34:04 +00:00
|
|
|
state[0] = 'T';
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* One of D, L, R, S, W. For a
|
|
|
|
* multithreaded process we will use
|
|
|
|
* the state of the thread with the
|
|
|
|
* highest precedence. The
|
|
|
|
* precendence order from high to low
|
|
|
|
* is R, L, D, S, W. If no thread is
|
|
|
|
* in a sane state we use '?' for our
|
|
|
|
* primary state.
|
|
|
|
*/
|
|
|
|
rflag = sflag = dflag = lflag = wflag = 0;
|
|
|
|
FOREACH_THREAD_IN_PROC(p, td) {
|
|
|
|
if (td->td_state == TDS_RUNNING ||
|
|
|
|
td->td_state == TDS_RUNQ ||
|
|
|
|
td->td_state == TDS_CAN_RUN)
|
|
|
|
rflag++;
|
|
|
|
if (TD_ON_LOCK(td))
|
|
|
|
lflag++;
|
|
|
|
if (TD_IS_SLEEPING(td)) {
|
2010-01-08 15:44:49 +00:00
|
|
|
if (!(td->td_flags & TDF_SINTR))
|
2006-04-25 20:34:04 +00:00
|
|
|
dflag++;
|
|
|
|
else
|
|
|
|
sflag++;
|
|
|
|
}
|
|
|
|
if (TD_AWAITING_INTR(td))
|
|
|
|
wflag++;
|
|
|
|
}
|
|
|
|
if (rflag)
|
|
|
|
state[0] = 'R';
|
|
|
|
else if (lflag)
|
|
|
|
state[0] = 'L';
|
|
|
|
else if (dflag)
|
|
|
|
state[0] = 'D';
|
|
|
|
else if (sflag)
|
|
|
|
state[0] = 'S';
|
|
|
|
else if (wflag)
|
|
|
|
state[0] = 'W';
|
|
|
|
else
|
2014-10-11 20:25:19 +00:00
|
|
|
state[0] = '?';
|
2006-04-25 20:34:04 +00:00
|
|
|
}
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
break;
|
|
|
|
case PRS_NEW:
|
2006-04-25 20:34:04 +00:00
|
|
|
state[0] = 'N';
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
break;
|
|
|
|
case PRS_ZOMBIE:
|
2006-04-25 20:34:04 +00:00
|
|
|
state[0] = 'Z';
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
break;
|
|
|
|
default:
|
2006-04-25 20:34:04 +00:00
|
|
|
state[0] = 'U';
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-04-25 20:34:04 +00:00
|
|
|
state[1] = '\0';
|
|
|
|
|
|
|
|
/* Additional process state flags. */
|
2010-01-08 15:44:49 +00:00
|
|
|
if (!(p->p_flag & P_INMEM))
|
2006-04-25 20:34:04 +00:00
|
|
|
strlcat(state, "W", sizeof(state));
|
|
|
|
if (p->p_flag & P_TRACED)
|
|
|
|
strlcat(state, "X", sizeof(state));
|
|
|
|
if (p->p_flag & P_WEXIT && p->p_state != PRS_ZOMBIE)
|
|
|
|
strlcat(state, "E", sizeof(state));
|
|
|
|
if (p->p_flag & P_PPWAIT)
|
|
|
|
strlcat(state, "V", sizeof(state));
|
|
|
|
if (p->p_flag & P_SYSTEM || p->p_lock > 0)
|
|
|
|
strlcat(state, "L", sizeof(state));
|
2016-04-15 09:13:01 +00:00
|
|
|
if (p->p_pgrp != NULL && p->p_session != NULL &&
|
|
|
|
SESS_LEADER(p))
|
2006-04-25 20:34:04 +00:00
|
|
|
strlcat(state, "s", sizeof(state));
|
|
|
|
/* Cheated here and didn't compare pgid's. */
|
|
|
|
if (p->p_flag & P_CONTROLT)
|
|
|
|
strlcat(state, "+", sizeof(state));
|
|
|
|
if (cred != NULL && jailed(cred))
|
|
|
|
strlcat(state, "J", sizeof(state));
|
|
|
|
db_printf(" %-6.6s ", state);
|
2009-10-01 19:12:14 +00:00
|
|
|
if (p->p_flag & P_HADTHREADS) {
|
2006-05-11 21:59:55 +00:00
|
|
|
#ifdef __LP64__
|
2009-10-01 19:12:14 +00:00
|
|
|
db_printf(" (threaded) ");
|
2006-04-25 20:34:04 +00:00
|
|
|
#else
|
2009-10-01 19:12:14 +00:00
|
|
|
db_printf(" (threaded) ");
|
2006-04-25 20:34:04 +00:00
|
|
|
#endif
|
2009-10-01 19:12:14 +00:00
|
|
|
if (p->p_flag & P_SYSTEM)
|
|
|
|
db_printf("[");
|
|
|
|
db_printf("%s", p->p_comm);
|
|
|
|
if (p->p_flag & P_SYSTEM)
|
|
|
|
db_printf("]");
|
2018-08-09 11:21:31 +00:00
|
|
|
if (ps_mode == PRINT_ARGS) {
|
|
|
|
db_printf(" ");
|
|
|
|
dump_args(p);
|
|
|
|
}
|
2009-10-01 19:12:14 +00:00
|
|
|
db_printf("\n");
|
|
|
|
}
|
2002-09-11 08:13:56 +00:00
|
|
|
FOREACH_THREAD_IN_PROC(p, td) {
|
2006-04-25 20:34:04 +00:00
|
|
|
dumpthread(p, td, p->p_flag & P_HADTHREADS);
|
2006-07-12 21:22:44 +00:00
|
|
|
if (db_pager_quit)
|
2003-07-31 17:29:42 +00:00
|
|
|
break;
|
1994-08-27 16:28:45 +00:00
|
|
|
}
|
2002-04-11 21:01:34 +00:00
|
|
|
|
2000-12-30 22:06:19 +00:00
|
|
|
p = LIST_NEXT(p, p_list);
|
1995-08-20 05:25:11 +00:00
|
|
|
if (p == NULL && np > 0)
|
2000-12-30 22:06:19 +00:00
|
|
|
p = LIST_FIRST(&zombproc);
|
2014-10-11 20:25:19 +00:00
|
|
|
}
|
1994-08-27 16:28:45 +00:00
|
|
|
}
|
2003-06-06 17:19:27 +00:00
|
|
|
|
2002-12-28 01:23:07 +00:00
|
|
|
static void
|
2006-04-25 20:34:04 +00:00
|
|
|
dumpthread(volatile struct proc *p, volatile struct thread *td, int all)
|
2002-12-28 01:23:07 +00:00
|
|
|
{
|
2006-04-25 20:34:04 +00:00
|
|
|
char state[9], wprefix;
|
|
|
|
const char *wmesg;
|
|
|
|
void *wchan;
|
|
|
|
|
|
|
|
if (all) {
|
2006-08-01 15:29:46 +00:00
|
|
|
db_printf("%6d ", td->td_tid);
|
2006-04-25 20:34:04 +00:00
|
|
|
switch (td->td_state) {
|
|
|
|
case TDS_RUNNING:
|
|
|
|
snprintf(state, sizeof(state), "Run");
|
|
|
|
break;
|
|
|
|
case TDS_RUNQ:
|
|
|
|
snprintf(state, sizeof(state), "RunQ");
|
|
|
|
break;
|
|
|
|
case TDS_CAN_RUN:
|
|
|
|
snprintf(state, sizeof(state), "CanRun");
|
|
|
|
break;
|
|
|
|
case TDS_INACTIVE:
|
|
|
|
snprintf(state, sizeof(state), "Inactv");
|
|
|
|
break;
|
|
|
|
case TDS_INHIBITED:
|
|
|
|
state[0] = '\0';
|
|
|
|
if (TD_ON_LOCK(td))
|
|
|
|
strlcat(state, "L", sizeof(state));
|
|
|
|
if (TD_IS_SLEEPING(td)) {
|
|
|
|
if (td->td_flags & TDF_SINTR)
|
|
|
|
strlcat(state, "S", sizeof(state));
|
|
|
|
else
|
|
|
|
strlcat(state, "D", sizeof(state));
|
|
|
|
}
|
|
|
|
if (TD_IS_SWAPPED(td))
|
|
|
|
strlcat(state, "W", sizeof(state));
|
|
|
|
if (TD_AWAITING_INTR(td))
|
|
|
|
strlcat(state, "I", sizeof(state));
|
|
|
|
if (TD_IS_SUSPENDED(td))
|
|
|
|
strlcat(state, "s", sizeof(state));
|
|
|
|
if (state[0] != '\0')
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
snprintf(state, sizeof(state), "???");
|
|
|
|
}
|
|
|
|
db_printf(" %-6.6s ", state);
|
|
|
|
}
|
|
|
|
wprefix = ' ';
|
|
|
|
if (TD_ON_LOCK(td)) {
|
|
|
|
wprefix = '*';
|
|
|
|
wmesg = td->td_lockname;
|
|
|
|
wchan = td->td_blocked;
|
|
|
|
} else if (TD_ON_SLEEPQ(td)) {
|
|
|
|
wmesg = td->td_wmesg;
|
|
|
|
wchan = td->td_wchan;
|
|
|
|
} else if (TD_IS_RUNNING(td)) {
|
|
|
|
snprintf(state, sizeof(state), "CPU %d", td->td_oncpu);
|
|
|
|
wmesg = state;
|
|
|
|
wchan = NULL;
|
|
|
|
} else {
|
|
|
|
wmesg = "";
|
|
|
|
wchan = NULL;
|
|
|
|
}
|
2016-08-14 15:26:40 +00:00
|
|
|
db_printf("%c%-7.7s ", wprefix, wmesg);
|
2006-04-25 20:34:04 +00:00
|
|
|
if (wchan == NULL)
|
2006-05-11 21:59:55 +00:00
|
|
|
#ifdef __LP64__
|
2016-08-14 15:26:40 +00:00
|
|
|
db_printf("%18s ", "");
|
2006-04-25 20:34:04 +00:00
|
|
|
#else
|
2016-08-14 15:26:40 +00:00
|
|
|
db_printf("%10s ", "");
|
2006-04-25 20:34:04 +00:00
|
|
|
#endif
|
|
|
|
else
|
2016-08-14 15:26:40 +00:00
|
|
|
db_printf("%p ", wchan);
|
2006-04-25 20:34:04 +00:00
|
|
|
if (p->p_flag & P_SYSTEM)
|
|
|
|
db_printf("[");
|
|
|
|
if (td->td_name[0] != '\0')
|
|
|
|
db_printf("%s", td->td_name);
|
|
|
|
else
|
|
|
|
db_printf("%s", td->td_proc->p_comm);
|
|
|
|
if (p->p_flag & P_SYSTEM)
|
|
|
|
db_printf("]");
|
2018-08-09 11:21:31 +00:00
|
|
|
if (ps_mode == PRINT_ARGS && all == 0) {
|
|
|
|
db_printf(" ");
|
|
|
|
dump_args(p);
|
|
|
|
}
|
2006-04-25 20:34:04 +00:00
|
|
|
db_printf("\n");
|
|
|
|
}
|
2003-07-30 20:59:36 +00:00
|
|
|
|
2006-04-25 20:34:04 +00:00
|
|
|
DB_SHOW_COMMAND(thread, db_show_thread)
|
|
|
|
{
|
|
|
|
struct thread *td;
|
2008-06-18 20:42:01 +00:00
|
|
|
struct lock_object *lock;
|
2015-05-21 15:16:18 +00:00
|
|
|
bool comma;
|
2016-03-25 19:35:29 +00:00
|
|
|
int delta;
|
2006-04-25 20:34:04 +00:00
|
|
|
|
|
|
|
/* Determine which thread to examine. */
|
|
|
|
if (have_addr)
|
2015-05-18 22:27:46 +00:00
|
|
|
td = db_lookup_thread(addr, false);
|
2006-04-25 20:34:04 +00:00
|
|
|
else
|
|
|
|
td = kdb_thread;
|
2008-06-18 20:42:01 +00:00
|
|
|
lock = (struct lock_object *)td->td_lock;
|
2006-04-25 20:34:04 +00:00
|
|
|
|
|
|
|
db_printf("Thread %d at %p:\n", td->td_tid, td);
|
2006-10-26 21:42:22 +00:00
|
|
|
db_printf(" proc (pid %d): %p\n", td->td_proc->p_pid, td->td_proc);
|
2006-04-25 20:34:04 +00:00
|
|
|
if (td->td_name[0] != '\0')
|
|
|
|
db_printf(" name: %s\n", td->td_name);
|
2019-02-09 21:08:19 +00:00
|
|
|
db_printf(" pcb: %p\n", td->td_pcb);
|
2007-10-16 17:52:59 +00:00
|
|
|
db_printf(" stack: %p-%p\n", (void *)td->td_kstack,
|
|
|
|
(void *)(td->td_kstack + td->td_kstack_pages * PAGE_SIZE - 1));
|
2006-04-25 20:34:04 +00:00
|
|
|
db_printf(" flags: %#x ", td->td_flags);
|
|
|
|
db_printf(" pflags: %#x\n", td->td_pflags);
|
|
|
|
db_printf(" state: ");
|
2002-12-28 01:23:07 +00:00
|
|
|
switch (td->td_state) {
|
2006-04-25 20:34:04 +00:00
|
|
|
case TDS_INACTIVE:
|
|
|
|
db_printf("INACTIVE\n");
|
|
|
|
break;
|
|
|
|
case TDS_CAN_RUN:
|
|
|
|
db_printf("CAN RUN\n");
|
|
|
|
break;
|
|
|
|
case TDS_RUNQ:
|
|
|
|
db_printf("RUNQ\n");
|
|
|
|
break;
|
|
|
|
case TDS_RUNNING:
|
|
|
|
db_printf("RUNNING (CPU %d)\n", td->td_oncpu);
|
|
|
|
break;
|
2002-12-28 01:23:07 +00:00
|
|
|
case TDS_INHIBITED:
|
2006-04-25 20:34:04 +00:00
|
|
|
db_printf("INHIBITED: {");
|
2015-05-18 22:27:46 +00:00
|
|
|
comma = false;
|
2002-12-28 01:23:07 +00:00
|
|
|
if (TD_IS_SLEEPING(td)) {
|
2006-04-25 20:34:04 +00:00
|
|
|
db_printf("SLEEPING");
|
2015-05-18 22:27:46 +00:00
|
|
|
comma = true;
|
2002-12-28 01:23:07 +00:00
|
|
|
}
|
|
|
|
if (TD_IS_SUSPENDED(td)) {
|
2006-04-25 20:34:04 +00:00
|
|
|
if (comma)
|
|
|
|
db_printf(", ");
|
|
|
|
db_printf("SUSPENDED");
|
2015-05-18 22:27:46 +00:00
|
|
|
comma = true;
|
2006-04-25 20:34:04 +00:00
|
|
|
}
|
|
|
|
if (TD_IS_SWAPPED(td)) {
|
|
|
|
if (comma)
|
|
|
|
db_printf(", ");
|
|
|
|
db_printf("SWAPPED");
|
2015-05-18 22:27:46 +00:00
|
|
|
comma = true;
|
2006-04-25 20:34:04 +00:00
|
|
|
}
|
|
|
|
if (TD_ON_LOCK(td)) {
|
|
|
|
if (comma)
|
|
|
|
db_printf(", ");
|
|
|
|
db_printf("LOCK");
|
2015-05-18 22:27:46 +00:00
|
|
|
comma = true;
|
2002-12-28 01:23:07 +00:00
|
|
|
}
|
|
|
|
if (TD_AWAITING_INTR(td)) {
|
2006-04-25 20:34:04 +00:00
|
|
|
if (comma)
|
|
|
|
db_printf(", ");
|
|
|
|
db_printf("IWAIT");
|
2002-12-28 01:23:07 +00:00
|
|
|
}
|
2006-04-25 20:34:04 +00:00
|
|
|
db_printf("}\n");
|
2002-12-28 01:23:07 +00:00
|
|
|
break;
|
2006-04-25 20:34:04 +00:00
|
|
|
default:
|
|
|
|
db_printf("??? (%#x)\n", td->td_state);
|
2002-12-28 01:23:07 +00:00
|
|
|
break;
|
2006-04-25 20:34:04 +00:00
|
|
|
}
|
|
|
|
if (TD_ON_LOCK(td))
|
|
|
|
db_printf(" lock: %s turnstile: %p\n", td->td_lockname,
|
|
|
|
td->td_blocked);
|
|
|
|
if (TD_ON_SLEEPQ(td))
|
2016-07-28 09:09:55 +00:00
|
|
|
db_printf(
|
|
|
|
" wmesg: %s wchan: %p sleeptimo %lx. %jx (curr %lx. %jx)\n",
|
|
|
|
td->td_wmesg, td->td_wchan,
|
|
|
|
(long)sbttobt(td->td_sleeptimo).sec,
|
|
|
|
(uintmax_t)sbttobt(td->td_sleeptimo).frac,
|
|
|
|
(long)sbttobt(sbinuptime()).sec,
|
|
|
|
(uintmax_t)sbttobt(sbinuptime()).frac);
|
2006-04-25 20:34:04 +00:00
|
|
|
db_printf(" priority: %d\n", td->td_priority);
|
2008-06-18 20:42:01 +00:00
|
|
|
db_printf(" container lock: %s (%p)\n", lock->lo_name, lock);
|
2016-03-25 19:35:29 +00:00
|
|
|
if (td->td_swvoltick != 0) {
|
|
|
|
delta = (u_int)ticks - (u_int)td->td_swvoltick;
|
|
|
|
db_printf(" last voluntary switch: %d ms ago\n",
|
|
|
|
1000 * delta / hz);
|
|
|
|
}
|
|
|
|
if (td->td_swinvoltick != 0) {
|
|
|
|
delta = (u_int)ticks - (u_int)td->td_swinvoltick;
|
|
|
|
db_printf(" last involuntary switch: %d ms ago\n",
|
|
|
|
1000 * delta / hz);
|
|
|
|
}
|
2006-04-25 20:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DB_SHOW_COMMAND(proc, db_show_proc)
|
|
|
|
{
|
|
|
|
struct thread *td;
|
|
|
|
struct proc *p;
|
2006-07-12 21:22:44 +00:00
|
|
|
int i;
|
2006-04-25 20:34:04 +00:00
|
|
|
|
|
|
|
/* Determine which process to examine. */
|
|
|
|
if (have_addr)
|
|
|
|
p = db_lookup_proc(addr);
|
|
|
|
else
|
|
|
|
p = kdb_thread->td_proc;
|
|
|
|
|
|
|
|
db_printf("Process %d (%s) at %p:\n", p->p_pid, p->p_comm, p);
|
|
|
|
db_printf(" state: ");
|
|
|
|
switch (p->p_state) {
|
|
|
|
case PRS_NEW:
|
|
|
|
db_printf("NEW\n");
|
2002-12-28 01:23:07 +00:00
|
|
|
break;
|
2006-04-25 20:34:04 +00:00
|
|
|
case PRS_NORMAL:
|
|
|
|
db_printf("NORMAL\n");
|
2002-12-28 01:23:07 +00:00
|
|
|
break;
|
2006-04-25 20:34:04 +00:00
|
|
|
case PRS_ZOMBIE:
|
|
|
|
db_printf("ZOMBIE\n");
|
2003-06-06 17:20:47 +00:00
|
|
|
break;
|
2002-12-28 01:23:07 +00:00
|
|
|
default:
|
2006-04-25 20:34:04 +00:00
|
|
|
db_printf("??? (%#x)\n", p->p_state);
|
2002-12-28 01:23:07 +00:00
|
|
|
}
|
2006-04-25 20:34:04 +00:00
|
|
|
if (p->p_ucred != NULL) {
|
|
|
|
db_printf(" uid: %d gids: ", p->p_ucred->cr_uid);
|
|
|
|
for (i = 0; i < p->p_ucred->cr_ngroups; i++) {
|
|
|
|
db_printf("%d", p->p_ucred->cr_groups[i]);
|
|
|
|
if (i < (p->p_ucred->cr_ngroups - 1))
|
|
|
|
db_printf(", ");
|
|
|
|
}
|
2002-12-28 01:23:07 +00:00
|
|
|
db_printf("\n");
|
2006-04-25 20:34:04 +00:00
|
|
|
}
|
|
|
|
if (p->p_pptr != NULL)
|
|
|
|
db_printf(" parent: pid %d at %p\n", p->p_pptr->p_pid,
|
|
|
|
p->p_pptr);
|
|
|
|
if (p->p_leader != NULL && p->p_leader != p)
|
|
|
|
db_printf(" leader: pid %d at %p\n", p->p_leader->p_pid,
|
|
|
|
p->p_leader);
|
|
|
|
if (p->p_sysent != NULL)
|
|
|
|
db_printf(" ABI: %s\n", p->p_sysent->sv_name);
|
2016-08-01 22:41:50 +00:00
|
|
|
if (p->p_args != NULL) {
|
|
|
|
db_printf(" arguments: ");
|
2018-08-09 11:21:31 +00:00
|
|
|
dump_args(p);
|
2016-08-01 22:41:50 +00:00
|
|
|
db_printf("\n");
|
|
|
|
}
|
2018-05-25 13:59:48 +00:00
|
|
|
db_printf(" repear: %p reapsubtree: %d\n",
|
|
|
|
p->p_reaper, p->p_reapsubtree);
|
|
|
|
db_printf(" sigparent: %d\n", p->p_sigparent);
|
|
|
|
db_printf(" vmspace: %p\n", p->p_vmspace);
|
|
|
|
db_printf(" (map %p)\n",
|
|
|
|
(p->p_vmspace != NULL) ? &p->p_vmspace->vm_map : 0);
|
|
|
|
db_printf(" (map.pmap %p)\n",
|
|
|
|
(p->p_vmspace != NULL) ? &p->p_vmspace->vm_map.pmap : 0);
|
|
|
|
db_printf(" (pmap %p)\n",
|
|
|
|
(p->p_vmspace != NULL) ? &p->p_vmspace->vm_pmap : 0);
|
2006-04-25 20:34:04 +00:00
|
|
|
db_printf(" threads: %d\n", p->p_numthreads);
|
|
|
|
FOREACH_THREAD_IN_PROC(p, td) {
|
|
|
|
dumpthread(p, td, 1);
|
2006-07-12 21:22:44 +00:00
|
|
|
if (db_pager_quit)
|
2006-04-25 20:34:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-12-28 01:23:07 +00:00
|
|
|
}
|
2011-12-16 11:44:20 +00:00
|
|
|
|
|
|
|
void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_findstack_cmd(db_expr_t addr, bool have_addr, db_expr_t dummy3 __unused,
|
|
|
|
char *dummy4 __unused)
|
2011-12-16 11:44:20 +00:00
|
|
|
{
|
|
|
|
struct proc *p;
|
|
|
|
struct thread *td;
|
|
|
|
struct kstack_cache_entry *ks_ce;
|
|
|
|
vm_offset_t saddr;
|
|
|
|
|
|
|
|
if (have_addr)
|
|
|
|
saddr = addr;
|
|
|
|
else {
|
|
|
|
db_printf("Usage: findstack <address>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-18 15:36:21 +00:00
|
|
|
FOREACH_PROC_IN_SYSTEM(p) {
|
2011-12-16 11:44:20 +00:00
|
|
|
FOREACH_THREAD_IN_PROC(p, td) {
|
|
|
|
if (td->td_kstack <= saddr && saddr < td->td_kstack +
|
|
|
|
PAGE_SIZE * td->td_kstack_pages) {
|
|
|
|
db_printf("Thread %p\n", td);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ks_ce = kstack_cache; ks_ce != NULL;
|
|
|
|
ks_ce = ks_ce->next_ks_entry) {
|
|
|
|
if ((vm_offset_t)ks_ce <= saddr && saddr < (vm_offset_t)ks_ce +
|
2015-08-10 17:18:21 +00:00
|
|
|
PAGE_SIZE * kstack_pages) {
|
2011-12-16 11:44:20 +00:00
|
|
|
db_printf("Cached stack %p\n", ks_ce);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|