Index: head/sys/kern/tty_info.c =================================================================== --- head/sys/kern/tty_info.c +++ head/sys/kern/tty_info.c @@ -49,11 +49,14 @@ #include #include #include +#include #include #include #include #include #include +#include +#include #include #include @@ -233,6 +236,11 @@ return (-ENXIO); } +static bool tty_info_kstacks = false; +SYSCTL_BOOL(_kern, OID_AUTO, tty_info_kstacks, CTLFLAG_RWTUN, + &tty_info_kstacks, 0, + "Enable printing kernel stack(9) traces on ^T (tty info)"); + /* * Report on state of foreground process group. */ @@ -240,12 +248,13 @@ tty_info(struct tty *tp) { struct timeval rtime, utime, stime; + struct stack stack; struct proc *p, *ppick; struct thread *td, *tdpick; const char *stateprefix, *state; struct sbuf sb; long rss; - int load, pctcpu; + int load, pctcpu, sterr; pid_t pid; char comm[MAXCOMLEN + 1]; struct rusage ru; @@ -320,6 +329,15 @@ else state = "unknown"; pctcpu = (sched_pctcpu(td) * 10000 + FSCALE / 2) >> FSHIFT; + if (tty_info_kstacks) { + stack_zero(&stack); + if (TD_IS_SWAPPED(td) || TD_IS_RUNNING(td)) + sterr = stack_save_td_running(&stack, td); + else { + stack_save_td(&stack, td); + sterr = 0; + } + } thread_unlock(td); if (p->p_state == PRS_NEW || p->p_state == PRS_ZOMBIE) rss = 0; @@ -340,6 +358,9 @@ (long)utime.tv_sec, utime.tv_usec / 10000, (long)stime.tv_sec, stime.tv_usec / 10000, pctcpu / 100, rss); + + if (tty_info_kstacks && sterr == 0) + stack_sbuf_print_flags(&sb, &stack, M_NOWAIT); out: sbuf_finish(&sb);