From owner-svn-src-stable-8@FreeBSD.ORG Fri Sep 16 19:52:49 2011 Return-Path: Delivered-To: svn-src-stable-8@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 881551065674; Fri, 16 Sep 2011 19:52:49 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6DFC98FC1B; Fri, 16 Sep 2011 19:52:49 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p8GJqnj4036326; Fri, 16 Sep 2011 19:52:49 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p8GJqnAr036324; Fri, 16 Sep 2011 19:52:49 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201109161952.p8GJqnAr036324@svn.freebsd.org> From: John Baldwin Date: Fri, 16 Sep 2011 19:52:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225629 - stable/8/gnu/usr.bin/gdb/kgdb X-BeenThere: svn-src-stable-8@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 8-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Sep 2011 19:52:49 -0000 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)