Use kdb_thr_* to iterate over threads consistently in DDB.

The "findstack", "show all trace", and "show active trace" commands
were iterating over allproc to enumerate threads.  This missed threads
executing in exit1() after being removed from allproc.

Reviewed by:	kib
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D27829
This commit is contained in:
John Baldwin 2020-12-31 16:01:35 -08:00
parent ae450907c6
commit 3e06c7da02
2 changed files with 22 additions and 26 deletions

View File

@ -847,32 +847,31 @@ db_stack_trace(db_expr_t tid, bool hastid, db_expr_t count, char *modif)
static void static void
_db_stack_trace_all(bool active_only) _db_stack_trace_all(bool active_only)
{ {
struct proc *p;
struct thread *td; struct thread *td;
jmp_buf jb; jmp_buf jb;
void *prev_jb; void *prev_jb;
FOREACH_PROC_IN_SYSTEM(p) { for (td = kdb_thr_first(); td != NULL; td = kdb_thr_next(td)) {
prev_jb = kdb_jmpbuf(jb); prev_jb = kdb_jmpbuf(jb);
if (setjmp(jb) == 0) { if (setjmp(jb) == 0) {
FOREACH_THREAD_IN_PROC(p, td) { if (td->td_state == TDS_RUNNING)
if (td->td_state == TDS_RUNNING) db_printf("\nTracing command %s pid %d"
db_printf("\nTracing command %s pid %d" " tid %ld td %p (CPU %d)\n",
" tid %ld td %p (CPU %d)\n", td->td_proc->p_comm, td->td_proc->p_pid,
p->p_comm, p->p_pid, (long)td->td_tid, td, td->td_oncpu);
(long)td->td_tid, td, else if (active_only)
td->td_oncpu); continue;
else if (active_only) else
continue; db_printf("\nTracing command %s pid %d"
else " tid %ld td %p\n", td->td_proc->p_comm,
db_printf("\nTracing command %s pid %d" td->td_proc->p_pid, (long)td->td_tid, td);
" tid %ld td %p\n", p->p_comm, if (td->td_proc->p_flag & P_INMEM)
p->p_pid, (long)td->td_tid, td);
db_trace_thread(td, -1); db_trace_thread(td, -1);
if (db_pager_quit) { else
kdb_jmpbuf(prev_jb); db_printf("--- swapped out\n");
return; if (db_pager_quit) {
} kdb_jmpbuf(prev_jb);
return;
} }
} }
kdb_jmpbuf(prev_jb); kdb_jmpbuf(prev_jb);

View File

@ -512,7 +512,6 @@ void
db_findstack_cmd(db_expr_t addr, bool have_addr, db_expr_t dummy3 __unused, db_findstack_cmd(db_expr_t addr, bool have_addr, db_expr_t dummy3 __unused,
char *dummy4 __unused) char *dummy4 __unused)
{ {
struct proc *p;
struct thread *td; struct thread *td;
vm_offset_t saddr; vm_offset_t saddr;
@ -523,12 +522,10 @@ db_findstack_cmd(db_expr_t addr, bool have_addr, db_expr_t dummy3 __unused,
return; return;
} }
FOREACH_PROC_IN_SYSTEM(p) { for (td = kdb_thr_first(); td != NULL; td = kdb_thr_next(td)) {
FOREACH_THREAD_IN_PROC(p, td) { if (kstack_contains(td, saddr, 1)) {
if (kstack_contains(td, saddr, 1)) { db_printf("Thread %p\n", td);
db_printf("Thread %p\n", td); return;
return;
}
} }
} }
} }