Module Name: src Committed By: rmind Date: Sat Jun 30 23:33:10 UTC 2012
Modified Files: src/sys/arch/amd64/amd64: trap.c src/sys/arch/i386/i386: trap.c Log Message: trap: move out info printing to trap_print() on amd64, reduce the differences between amd64 and i386, add lowest kernel stack address. To generate a diff of this commit: cvs rdiff -u -r1.71 -r1.72 src/sys/arch/amd64/amd64/trap.c cvs rdiff -u -r1.263 -r1.264 src/sys/arch/i386/i386/trap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/amd64/amd64/trap.c diff -u src/sys/arch/amd64/amd64/trap.c:1.71 src/sys/arch/amd64/amd64/trap.c:1.72 --- src/sys/arch/amd64/amd64/trap.c:1.71 Tue May 22 21:14:37 2012 +++ src/sys/arch/amd64/amd64/trap.c Sat Jun 30 23:33:10 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.71 2012/05/22 21:14:37 dsl Exp $ */ +/* $NetBSD: trap.c,v 1.72 2012/06/30 23:33:10 rmind Exp $ */ /*- * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.71 2012/05/22 21:14:37 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.72 2012/06/30 23:33:10 rmind Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -184,6 +184,27 @@ onfault_handler(const struct pcb *pcb, c return NULL; } +static void +trap_print(const struct trapframe *frame, const lwp_t *l) +{ + const int type = frame->tf_trapno; + + if (frame->tf_trapno < trap_types) { + printf("fatal %s", trap_type[type]); + } else { + printf("unknown trap %d", type); + } + printf(" in %s mode\n", (type & T_USER) ? "user" : "supervisor"); + + printf("trap type %d code %lx rip %lx cs %lx rflags %lx cr2 %lx " + "ilevel %x rsp %lx\n", + type, frame->tf_err, (u_long)frame->tf_rip, frame->tf_cs, + frame->tf_rflags, rcr2(), curcpu()->ci_ilevel, frame->tf_rsp); + + printf("curlwp %p pid %d lid %d lowest kstack %p\n", + l, l->l_proc->p_pid, l->l_lid, KSTACK_LOWEST_ADDR(l)); +} + /* * trap(frame): exception, fault, and trap interface to BSD kernel. * @@ -192,7 +213,6 @@ onfault_handler(const struct pcb *pcb, c * exception has been processed. Note that the effect is as if the arguments * were passed call by reference. */ - void trap(struct trapframe *frame) { @@ -226,13 +246,7 @@ trap(struct trapframe *frame) #ifdef DEBUG if (trapdebug) { - printf("trap %d code %lx eip %lx cs %lx rflags %lx cr2 %lx " - "cpl %x\n", - type, frame->tf_err, frame->tf_rip, frame->tf_cs, - frame->tf_rflags, rcr2(), curcpu()->ci_ilevel); - printf("curlwp %p%s", curlwp, curlwp ? " " : "\n"); - if (curlwp) - printf("pid %d lid %d\n", l->l_proc->p_pid, l->l_lid); + trap_print(frame, l); } #endif if (type != T_NMI && !KERNELMODE(frame->tf_cs, frame->tf_rflags)) { @@ -266,15 +280,8 @@ trap(struct trapframe *frame) default: we_re_toast: - if (frame->tf_trapno < trap_types) - printf("fatal %s", trap_type[frame->tf_trapno]); - else - printf("unknown trap %ld", (u_long)frame->tf_trapno); - printf(" in %s mode\n", (type & T_USER) ? "user" : "supervisor"); - printf("trap type %d code %lx rip %lx cs %lx rflags %lx cr2 " - " %lx cpl %x rsp %lx\n", - type, frame->tf_err, (u_long)frame->tf_rip, frame->tf_cs, - frame->tf_rflags, rcr2(), curcpu()->ci_ilevel, frame->tf_rsp); + trap_print(frame, l); + if (kdb_trap(type, 0, frame)) return; if (kgdb_trap(type, frame)) Index: src/sys/arch/i386/i386/trap.c diff -u src/sys/arch/i386/i386/trap.c:1.263 src/sys/arch/i386/i386/trap.c:1.264 --- src/sys/arch/i386/i386/trap.c:1.263 Sun Feb 19 21:06:11 2012 +++ src/sys/arch/i386/i386/trap.c Sat Jun 30 23:33:10 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.263 2012/02/19 21:06:11 rmind Exp $ */ +/* $NetBSD: trap.c,v 1.264 2012/06/30 23:33:10 rmind Exp $ */ /*- * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.263 2012/02/19 21:06:11 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.264 2012/06/30 23:33:10 rmind Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -262,16 +262,24 @@ onfault_handler(const struct pcb *pcb, c } static void -trap_print(int type, struct trapframe *frame) +trap_print(const struct trapframe *frame, const lwp_t *l) { - if (frame->tf_trapno < trap_types) - printf("fatal %s", trap_type[frame->tf_trapno]); - else - printf("unknown trap %d", frame->tf_trapno); + const int type = frame->tf_trapno; + + if (frame->tf_trapno < trap_types) { + printf("fatal %s", trap_type[type]); + } else { + printf("unknown trap %d", type); + } printf(" in %s mode\n", (type & T_USER) ? "user" : "supervisor"); - printf("trap type %d code %x eip %x cs %x eflags %x cr2 %lx ilevel %x\n", - type, frame->tf_err, frame->tf_eip, frame->tf_cs, - frame->tf_eflags, (long)rcr2(), curcpu()->ci_ilevel); + + printf("trap type %d code %x eip %x cs %x eflags %x cr2 %lx " + "ilevel %x esp %x\n", + type, frame->tf_err, frame->tf_eip, frame->tf_cs, frame->tf_eflags, + (long)rcr2(), curcpu()->ci_ilevel, frame->tf_esp); + + printf("curlwp %p pid %d lid %d lowest kstack %p\n", + l, l->l_proc->p_pid, l->l_lid, KSTACK_LOWEST_ADDR(l)); } static void @@ -329,12 +337,7 @@ trap(struct trapframe *frame) #ifdef DEBUG if (trapdebug) { - printf("trap %d code %x eip %x cs %x eflags %x cr2 %lx cpl %x\n", - type, frame->tf_err, frame->tf_eip, frame->tf_cs, - frame->tf_eflags, rcr2(), curcpu()->ci_ilevel); - printf("curlwp %p%s", curlwp, curlwp ? " " : "\n"); - if (curlwp) - printf("pid %d lid %d\n", l->l_proc->p_pid, l->l_lid); + trap_print(frame, l); } #endif if (type != T_NMI && !KVM86MODE && @@ -379,7 +382,8 @@ trap(struct trapframe *frame) if (type == T_TRCTRAP) check_dr0(); else - trap_print(type, frame); + trap_print(frame, l); + if (kdb_trap(type, 0, frame)) return; if (kgdb_trap(type, frame))