Date: Fri, 16 Sep 2011 19:52:49 +0000 (UTC) From: John Baldwin <jhb@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r225629 - stable/8/gnu/usr.bin/gdb/kgdb Message-ID: <201109161952.p8GJqnAr036324@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jhb Date: Fri Sep 16 19:52:49 2011 New Revision: 225629 URL: http://svn.freebsd.org/changeset/base/225629 Log: MFC 225017: Walk the zombproc list as well as the allproc list when enumerating threads and processes in a kernel image. This allows examination of threads that have exited or are in the late stages of exiting. Modified: stable/8/gnu/usr.bin/gdb/kgdb/kthr.c Directory Properties: stable/8/gnu/usr.bin/gdb/kgdb/ (props changed) Modified: stable/8/gnu/usr.bin/gdb/kgdb/kthr.c ============================================================================== --- stable/8/gnu/usr.bin/gdb/kgdb/kthr.c Fri Sep 16 19:29:11 2011 (r225628) +++ stable/8/gnu/usr.bin/gdb/kgdb/kthr.c Fri Sep 16 19:52:49 2011 (r225629) @@ -72,12 +72,53 @@ kgdb_thr_first(void) return (first); } -struct kthr * -kgdb_thr_init(void) +static void +kgdb_thr_add_procs(uintptr_t paddr) { struct proc p; struct thread td; struct kthr *kt; + CORE_ADDR addr; + + while (paddr != 0) { + if (kvm_read(kvm, paddr, &p, sizeof(p)) != sizeof(p)) { + warnx("kvm_read: %s", kvm_geterr(kvm)); + break; + } + addr = (uintptr_t)TAILQ_FIRST(&p.p_threads); + while (addr != 0) { + if (kvm_read(kvm, addr, &td, sizeof(td)) != + sizeof(td)) { + warnx("kvm_read: %s", kvm_geterr(kvm)); + break; + } + kt = malloc(sizeof(*kt)); + kt->next = first; + kt->kaddr = addr; + if (td.td_tid == dumptid) + kt->pcb = dumppcb; + else if (td.td_state == TDS_RUNNING && ((1 << td.td_oncpu) & stopped_cpus) + && stoppcbs != 0) + kt->pcb = (uintptr_t)stoppcbs + + sizeof(struct pcb) * td.td_oncpu; + else + kt->pcb = (uintptr_t)td.td_pcb; + kt->kstack = td.td_kstack; + kt->tid = td.td_tid; + kt->pid = p.p_pid; + kt->paddr = paddr; + kt->cpu = td.td_oncpu; + first = kt; + addr = (uintptr_t)TAILQ_NEXT(&td, td_plist); + } + paddr = (uintptr_t)LIST_NEXT(&p, p_list); + } +} + +struct kthr * +kgdb_thr_init(void) +{ + struct kthr *kt; uintptr_t addr, paddr; while (first != NULL) { @@ -113,37 +154,11 @@ kgdb_thr_init(void) stoppcbs = kgdb_lookup("_stoppcbs"); - while (paddr != 0) { - if (kvm_read(kvm, paddr, &p, sizeof(p)) != sizeof(p)) { - warnx("kvm_read: %s", kvm_geterr(kvm)); - break; - } - addr = (uintptr_t)TAILQ_FIRST(&p.p_threads); - while (addr != 0) { - if (kvm_read(kvm, addr, &td, sizeof(td)) != - sizeof(td)) { - warnx("kvm_read: %s", kvm_geterr(kvm)); - break; - } - kt = malloc(sizeof(*kt)); - kt->next = first; - kt->kaddr = addr; - if (td.td_tid == dumptid) - kt->pcb = dumppcb; - else if (td.td_state == TDS_RUNNING && ((1 << td.td_oncpu) & stopped_cpus) - && stoppcbs != 0) - kt->pcb = (uintptr_t) stoppcbs + sizeof(struct pcb) * td.td_oncpu; - else - kt->pcb = (uintptr_t)td.td_pcb; - kt->kstack = td.td_kstack; - kt->tid = td.td_tid; - kt->pid = p.p_pid; - kt->paddr = paddr; - kt->cpu = td.td_oncpu; - first = kt; - addr = (uintptr_t)TAILQ_NEXT(&td, td_plist); - } - paddr = (uintptr_t)LIST_NEXT(&p, p_list); + kgdb_thr_add_procs(paddr); + addr = kgdb_lookup("zombproc"); + if (addr != 0) { + kvm_read(kvm, addr, &paddr, sizeof(paddr)); + kgdb_thr_add_procs(paddr); } curkthr = kgdb_thr_lookup_tid(dumptid); if (curkthr == NULL)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201109161952.p8GJqnAr036324>