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. */
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to