Author: gibbs
Date: Tue Jun 14 21:37:25 2011
New Revision: 223099
URL: http://svn.freebsd.org/changeset/base/223099

Log:
  sys/kern/subr_kdb.c:
        Modify the "alternate break sequence" detecting state
        machine so that only a contiguous invocation of the
        break sequence is accepted.  The old implementation
        did not reset the state machine when detecting an
        unexpected character.
  
        While here, use an enum for the states of the machine
        instead of magic numbers.bmitted by:
  
  Sponsored by: Spectra Logic Corporation

Modified:
  head/sys/kern/subr_kdb.c

Modified: head/sys/kern/subr_kdb.c
==============================================================================
--- head/sys/kern/subr_kdb.c    Tue Jun 14 20:30:49 2011        (r223098)
+++ head/sys/kern/subr_kdb.c    Tue Jun 14 21:37:25 2011        (r223099)
@@ -244,29 +244,44 @@ kdb_reboot(void)
 #define        KEY_CRTLP       16      /* ^P */
 #define        KEY_CRTLR       18      /* ^R */
 
+/* States of th KDB "alternate break sequence" detecting state machine. */
+enum {
+       KDB_ALT_BREAK_SEEN_NONE,
+       KDB_ALT_BREAK_SEEN_CR,
+       KDB_ALT_BREAK_SEEN_CR_TILDE,
+};
+
 int
 kdb_alt_break(int key, int *state)
 {
        int brk;
 
+       /* All states transition to KDB_ALT_BREAK_SEEN_CR on a CR. */
+       if (key == KEY_CR) {
+               *state = KDB_ALT_BREAK_SEEN_CR;
+               return (0);
+       }
+
        brk = 0;
        switch (*state) {
-       case 0:
-               if (key == KEY_CR)
-                       *state = 1;
-               break;
-       case 1:
+       case KDB_ALT_BREAK_SEEN_CR:
+               *state = KDB_ALT_BREAK_SEEN_NONE;
                if (key == KEY_TILDE)
-                       *state = 2;
+                       *state = KDB_ALT_BREAK_SEEN_CR_TILDE;
                break;
-       case 2:
+       case KDB_ALT_BREAK_SEEN_CR_TILDE:
+               *state = KDB_ALT_BREAK_SEEN_NONE;
                if (key == KEY_CRTLB)
                        brk = KDB_REQ_DEBUGGER;
                else if (key == KEY_CRTLP)
                        brk = KDB_REQ_PANIC;
                else if (key == KEY_CRTLR)
                        brk = KDB_REQ_REBOOT;
-               *state = 0;
+               break;
+       case KDB_ALT_BREAK_SEEN_NONE:
+       default:
+               *state = KDB_ALT_BREAK_SEEN_NONE;
+               break;
        }
        return (brk);
 }
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to