Commit 37f86b46 authored by Jason Wessel's avatar Jason Wessel

kdb,kgdb: Allow arbitrary kgdb magic knock sequences

The first packet that gdb sends when the kernel is in kdb mode seems
to change with every release of gdb.  Instead of continuing to add
many different gdb packets, change kdb to automatically look for any
thing that looks like a gdb packet.

Example 1 cold start test:
echo g > /proc/sysrq-trigger
$D#44+

Example 2 cold start test:
echo g > /proc/sysrq-trigger
$3#33

The second one should re-enter kdb's shell right away and is purely a
test.
Signed-off-by: default avatarJason Wessel <jason.wessel@windriver.com>
parent d613d828
...@@ -31,15 +31,21 @@ char kdb_prompt_str[CMD_BUFLEN]; ...@@ -31,15 +31,21 @@ char kdb_prompt_str[CMD_BUFLEN];
int kdb_trap_printk; int kdb_trap_printk;
static void kgdb_transition_check(char *buffer) static int kgdb_transition_check(char *buffer)
{ {
int slen = strlen(buffer); if (buffer[0] != '+' && buffer[0] != '$') {
if (strncmp(buffer, "$?#3f", slen) != 0 &&
strncmp(buffer, "$qSupported", slen) != 0 &&
strncmp(buffer, "+$qSupported", slen) != 0) {
KDB_STATE_SET(KGDB_TRANS); KDB_STATE_SET(KGDB_TRANS);
kdb_printf("%s", buffer); kdb_printf("%s", buffer);
} else {
int slen = strlen(buffer);
if (slen > 3 && buffer[slen - 3] == '#') {
kdb_gdb_state_pass(buffer);
strcpy(buffer, "kgdb");
KDB_STATE_SET(DOING_KGDB);
return 1;
}
} }
return 0;
} }
static int kdb_read_get_key(char *buffer, size_t bufsize) static int kdb_read_get_key(char *buffer, size_t bufsize)
...@@ -251,6 +257,10 @@ static char *kdb_read(char *buffer, size_t bufsize) ...@@ -251,6 +257,10 @@ static char *kdb_read(char *buffer, size_t bufsize)
case 13: /* enter */ case 13: /* enter */
*lastchar++ = '\n'; *lastchar++ = '\n';
*lastchar++ = '\0'; *lastchar++ = '\0';
if (!KDB_STATE(KGDB_TRANS)) {
KDB_STATE_SET(KGDB_TRANS);
kdb_printf("%s", buffer);
}
kdb_printf("\n"); kdb_printf("\n");
return buffer; return buffer;
case 4: /* Del */ case 4: /* Del */
...@@ -382,10 +392,12 @@ static char *kdb_read(char *buffer, size_t bufsize) ...@@ -382,10 +392,12 @@ static char *kdb_read(char *buffer, size_t bufsize)
* printed characters if we think that * printed characters if we think that
* kgdb is connecting, until the check * kgdb is connecting, until the check
* fails */ * fails */
if (!KDB_STATE(KGDB_TRANS)) if (!KDB_STATE(KGDB_TRANS)) {
kgdb_transition_check(buffer); if (kgdb_transition_check(buffer))
else return buffer;
} else {
kdb_printf("%c", key); kdb_printf("%c", key);
}
} }
/* Special escape to kgdb */ /* Special escape to kgdb */
if (lastchar - buffer >= 5 && if (lastchar - buffer >= 5 &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment