From owner-p4-projects@FreeBSD.ORG Sun Jun 13 19:15:59 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 0134616A4D2; Sun, 13 Jun 2004 19:15:58 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BE28616A4CE for ; Sun, 13 Jun 2004 19:15:58 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id A038543D49 for ; Sun, 13 Jun 2004 19:15:58 +0000 (GMT) (envelope-from marcel@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.11/8.12.11) with ESMTP id i5DJFjbE029962 for ; Sun, 13 Jun 2004 19:15:45 GMT (envelope-from marcel@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id i5DJFiNb029959 for perforce@freebsd.org; Sun, 13 Jun 2004 19:15:44 GMT (envelope-from marcel@freebsd.org) Date: Sun, 13 Jun 2004 19:15:44 GMT Message-Id: <200406131915.i5DJFiNb029959@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to marcel@freebsd.org using -f From: Marcel Moolenaar To: Perforce Change Reviews Subject: PERFORCE change 54840 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Jun 2004 19:15:59 -0000 http://perforce.freebsd.org/chv.cgi?CH=54840 Change 54840 by marcel@marcel_nfs on 2004/06/13 19:15:17 Use the PCB instead of the trapframe for thread context. Add support for using dumppcb and dumptid. This allows us to set the current thread to the one that did the kernel dump and also use the saved context. Note that the kernel currently doesn't save dumptid. Affected files ... .. //depot/projects/gdb/usr.bin/kgdb/kgdb.h#7 edit .. //depot/projects/gdb/usr.bin/kgdb/kthr.c#4 edit .. //depot/projects/gdb/usr.bin/kgdb/md_i386.c#5 edit Differences ... ==== //depot/projects/gdb/usr.bin/kgdb/kgdb.h#7 (text+ko) ==== @@ -107,13 +107,13 @@ extern kvm_t *kvm; extern int verbose; -struct trapframe; +struct pcb; struct kthr { struct kthr *next; uintptr_t kaddr; - struct trapframe *td_frame; uintptr_t td_kstack; + struct pcb *td_pcb; int td_tid; }; ==== //depot/projects/gdb/usr.bin/kgdb/kthr.c#4 (text+ko) ==== @@ -37,10 +37,13 @@ #include #include -#include +#include #include "kgdb.h" +struct pcb *dumppcb; +int dumptid; + static struct kthr *first; struct kthr *curkthr; @@ -53,7 +56,7 @@ struct kthr * kgdb_thr_init(void) { - struct nlist nl[2]; + struct nlist nl[3]; struct proc p; struct thread td; struct kthr *thr; @@ -67,25 +70,38 @@ } kvm_read(kvm, nl[0].n_value, &paddr, sizeof(paddr)); + nl[0].n_name = (char *)(uintptr_t)"_dumppcb"; + nl[1].n_name = (char *)(uintptr_t)"_dumptid"; + nl[2].n_name = NULL; + if (kvm_nlist(kvm, nl) != 0) { + warnx(kvm_geterr(kvm)); + dumppcb = NULL; + dumptid = -1; + } else { + dumppcb = (struct pcb *)(nl[0].n_value); + kvm_read(kvm, nl[1].n_value, &dumptid, sizeof(dumptid)); + } + while (paddr != 0) { kvm_read(kvm, paddr, &p, sizeof(p)); tdaddr = (uintptr_t)TAILQ_FIRST(&p.p_threads); while (tdaddr != 0) { kvm_read(kvm, tdaddr, &td, sizeof(td)); - if (td.td_last_frame != NULL) { - thr = malloc(sizeof(*thr)); - thr->next = first; - thr->kaddr = tdaddr; - thr->td_frame = td.td_last_frame; - thr->td_kstack = td.td_kstack; - thr->td_tid = td.td_tid; - first = thr; - } + thr = malloc(sizeof(*thr)); + thr->next = first; + thr->kaddr = tdaddr; + thr->td_pcb = (td.td_tid == dumptid) ? dumppcb : + td.td_pcb; + thr->td_kstack = td.td_kstack; + thr->td_tid = td.td_tid; + first = thr; tdaddr = (uintptr_t)TAILQ_NEXT(&td, td_plist); } paddr = (uintptr_t)LIST_NEXT(&p, p_list); } - curkthr = first; + curkthr = kgdb_thr_lookup(dumptid); + if (curkthr == NULL) + curkthr = first; return (first); } ==== //depot/projects/gdb/usr.bin/kgdb/md_i386.c#5 (text+ko) ==== @@ -33,60 +33,32 @@ #include #include #include -#include #include +#include #include #include #include "kgdb.h" -static int -getreg(int *addr) -{ - int val; - - kvm_read(kvm, (uintptr_t)addr, &val, sizeof(val)); - return (val); -} - void * gdb_cpu_getreg(int regnum, size_t *regsz) { - struct trapframe *tf = curkthr->td_frame; - int cs; *regsz = gdb_cpu_regsz(regnum); switch (regnum) { - case 0: return (&tf->tf_eax); - case 1: return (&tf->tf_ecx); - case 2: return (&tf->tf_edx); - case 3: return (&tf->tf_ebx); - case 5: return (&tf->tf_ebp); - case 6: return (&tf->tf_esi); - case 7: return (&tf->tf_edi); - case 8: return (&tf->tf_eip); - case 9: return (&tf->tf_eflags); - case 10: return (&tf->tf_cs); - case 12: return (&tf->tf_ds); - case 13: return (&tf->tf_es); - case 4: - cs = getreg(&tf->tf_cs); - return (!ISPL(cs)) ? &tf->tf_ebp : &tf->tf_esp; - case 11: - cs = getreg(&tf->tf_cs); - return (!ISPL(cs)) ? &tf->tf_ds : &tf->tf_ss; + case 3: return (&curkthr->td_pcb->pcb_ebx); + case 4: return (&curkthr->td_pcb->pcb_esp); + case 5: return (&curkthr->td_pcb->pcb_ebp); + case 6: return (&curkthr->td_pcb->pcb_esi); + case 7: return (&curkthr->td_pcb->pcb_edi); + case 8: return (&curkthr->td_pcb->pcb_eip); } return (NULL); } void -gdb_cpu_setreg(int regnum, register_t val) +gdb_cpu_setreg(int regnum __unused, register_t val __unused) { - struct trapframe *tf = curkthr->td_frame; - - switch (regnum) { - case GDB_REG_PC: tf->tf_eip = val; break; - } } int