ANDROID: kdb: support new lines without carriage returns
authorColin Cross <ccross@android.com>
Thu, 15 Mar 2012 02:26:53 +0000 (19:26 -0700)
committerAmit Pundir <amit.pundir@linaro.org>
Mon, 18 Dec 2017 15:41:22 +0000 (21:11 +0530)
kdb expects carriage returns through the serial port to terminate
commands.  Modify it to accept the first seen carriage return or
new line as a terminator, but not treat \r\n as two terminators.

Change-Id: I06166017e7703d24310eefcb71c3a7d427088db7
Signed-off-by: Colin Cross <ccross@android.com>
kernel/debug/kdb/kdb_io.c

index e74be38245adf732f34c55c0a676004f59870ba4..c4929be5fe6554ccd5573135006765b0a45549bf 100644 (file)
@@ -217,7 +217,7 @@ static char *kdb_read(char *buffer, size_t bufsize)
        int i;
        int diag, dtab_count;
        int key;
-
+       static int last_crlf;
 
        diag = kdbgetintenv("DTABCOUNT", &dtab_count);
        if (diag)
@@ -238,6 +238,9 @@ poll_again:
                return buffer;
        if (key != 9)
                tab = 0;
+       if (key != 10 && key != 13)
+               last_crlf = 0;
+
        switch (key) {
        case 8: /* backspace */
                if (cp > buffer) {
@@ -255,7 +258,12 @@ poll_again:
                        *cp = tmp;
                }
                break;
-       case 13: /* enter */
+       case 10: /* new line */
+       case 13: /* carriage return */
+               /* handle \n after \r */
+               if (last_crlf && last_crlf != key)
+                       break;
+               last_crlf = key;
                *lastchar++ = '\n';
                *lastchar++ = '\0';
                if (!KDB_STATE(KGDB_TRANS)) {