From owner-svn-src-stable-11@freebsd.org Thu May 3 07:47:04 2018 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7E578FC80D2; Thu, 3 May 2018 07:47:04 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3051C6F63E; Thu, 3 May 2018 07:47:04 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2B4DE1CE26; Thu, 3 May 2018 07:47:04 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w437l4xs007752; Thu, 3 May 2018 07:47:04 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w437l3LQ007748; Thu, 3 May 2018 07:47:03 GMT (envelope-from avg@FreeBSD.org) Message-Id: <201805030747.w437l3LQ007748@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Thu, 3 May 2018 07:47:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r333204 - in stable/11/sys: amd64/amd64 i386/i386 powerpc/powerpc sys X-SVN-Group: stable-11 X-SVN-Commit-Author: avg X-SVN-Commit-Paths: in stable/11/sys: amd64/amd64 i386/i386 powerpc/powerpc sys X-SVN-Commit-Revision: 333204 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 May 2018 07:47:04 -0000 Author: avg Date: Thu May 3 07:47:03 2018 New Revision: 333204 URL: https://svnweb.freebsd.org/changeset/base/333204 Log: MFC r332752: set kdb_why to "trap" when calling kdb_trap from trap_fatal This will allow to hook a ddb script to "kdb.enter.trap" event. Previously there was no specific name for this event, so it could only be handled by either "kdb.enter.unknown" or "kdb.enter.default" hooks. Both are very unspecific. Having a specific event is useful because the fatal trap condition is very similar to panic but it has an additional property that the current stack frame is the frame where the trap occurred. So, both a register dump and a stack bottom dump have additional information that can help analyze the problem. I have added the event only on architectures that have trap_fatal() function defined. I haven't looked at other architectures. Their maintainers can add support for the event later. Sample script: kdb.enter.trap=bt; show reg; x/aS $rsp,20; x/agx $rsp,20 Sponsored by: Panzura Modified: stable/11/sys/amd64/amd64/trap.c stable/11/sys/i386/i386/trap.c stable/11/sys/powerpc/powerpc/trap.c stable/11/sys/sys/kdb.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/amd64/amd64/trap.c ============================================================================== --- stable/11/sys/amd64/amd64/trap.c Thu May 3 07:38:45 2018 (r333203) +++ stable/11/sys/amd64/amd64/trap.c Thu May 3 07:47:03 2018 (r333204) @@ -758,6 +758,9 @@ trap_fatal(frame, eva) u_int type; struct soft_segment_descriptor softseg; char *msg; +#ifdef KDB + bool handled; +#endif code = frame->tf_err; type = frame->tf_trapno; @@ -808,9 +811,13 @@ trap_fatal(frame, eva) curproc->p_pid, curthread->td_name); #ifdef KDB - if (debugger_on_panic) - if (kdb_trap(type, 0, frame)) + if (debugger_on_panic) { + kdb_why = KDB_WHY_TRAP; + handled = kdb_trap(type, 0, frame); + kdb_why = KDB_WHY_UNSET; + if (handled) return; + } #endif printf("trap number = %d\n", type); if (type <= MAX_TRAP_MSG) Modified: stable/11/sys/i386/i386/trap.c ============================================================================== --- stable/11/sys/i386/i386/trap.c Thu May 3 07:38:45 2018 (r333203) +++ stable/11/sys/i386/i386/trap.c Thu May 3 07:47:03 2018 (r333204) @@ -880,6 +880,9 @@ trap_fatal(frame, eva) u_int type; struct soft_segment_descriptor softseg; char *msg; +#ifdef KDB + bool handled; +#endif code = frame->tf_err; type = frame->tf_trapno; @@ -945,12 +948,13 @@ trap_fatal(frame, eva) #ifdef KDB if (debugger_on_panic) { + kdb_why = KDB_WHY_TRAP; frame->tf_err = eva; /* smuggle fault address to ddb */ - if (kdb_trap(type, 0, frame)) { - frame->tf_err = code; /* restore error code */ + handled = kdb_trap(type, 0, frame); + frame->tf_err = code; /* restore error code */ + kdb_why = KDB_WHY_UNSET; + if (handled) return; - } - frame->tf_err = code; /* restore error code */ } #endif printf("trap number = %d\n", type); Modified: stable/11/sys/powerpc/powerpc/trap.c ============================================================================== --- stable/11/sys/powerpc/powerpc/trap.c Thu May 3 07:38:45 2018 (r333203) +++ stable/11/sys/powerpc/powerpc/trap.c Thu May 3 07:47:03 2018 (r333204) @@ -389,11 +389,19 @@ trap(struct trapframe *frame) static void trap_fatal(struct trapframe *frame) { +#ifdef KDB + bool handled; +#endif printtrap(frame->exc, frame, 1, (frame->srr1 & PSL_PR)); #ifdef KDB - if (debugger_on_panic && kdb_trap(frame->exc, 0, frame)) - return; + if (debugger_on_panic) { + kdb_why = KDB_WHY_TRAP; + handled = kdb_trap(frame->exc, 0, frame); + kdb_why = KDB_WHY_UNSET; + if (handled) + return; + } #endif panic("%s trap", trapname(frame->exc)); } Modified: stable/11/sys/sys/kdb.h ============================================================================== --- stable/11/sys/sys/kdb.h Thu May 3 07:38:45 2018 (r333203) +++ stable/11/sys/sys/kdb.h Thu May 3 07:47:03 2018 (r333204) @@ -98,6 +98,7 @@ extern const char * volatile kdb_why; #define KDB_WHY_UNSET NULL /* No reason set. */ #define KDB_WHY_PANIC "panic" /* panic() was called. */ #define KDB_WHY_KASSERT "kassert" /* kassert failed. */ +#define KDB_WHY_TRAP "trap" /* Fatal trap. */ #define KDB_WHY_SYSCTL "sysctl" /* Sysctl entered debugger. */ #define KDB_WHY_BOOTFLAGS "bootflags" /* Boot flags were set. */ #define KDB_WHY_WITNESS "witness" /* Witness entered debugger. */