12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/ctype.h>
15 #include <linux/kernel.h>
17 #include <linux/kdev_t.h>
19 #include <linux/string.h>
20 #include <linux/sched.h>
29 #define CMD_BUFLEN 256
34 static int kgdb_transition_check(
char *
buffer)
36 if (buffer[0] !=
'+' && buffer[0] !=
'$') {
41 if (slen > 3 && buffer[slen - 3] ==
'#') {
53 #define ESCAPE_UDELAY 1000
54 #define ESCAPE_DELAY (2*1000000/ESCAPE_UDELAY)
56 char *ped = escape_data;
58 get_char_func *
f, *f_escape =
NULL;
67 if (escape_delay == 2) {
72 if (escape_delay == 1) {
93 if (escape_delay == 0 && key ==
'\e') {
104 if (ped - escape_data == 1) {
107 }
else if (ped - escape_data == 2) {
112 }
else if (ped - escape_data == 3) {
137 escape_data[0] = mapkey;
138 escape_data[1] =
'\0';
143 }
else if (ped - escape_data == 4) {
147 switch (escape_data[2]) {
160 escape_data[0] = mapkey;
161 escape_data[1] =
'\0';
203 static char *kdb_read(
char *buffer,
size_t bufsize)
206 char *bufend = buffer+bufsize-2;
217 int diag, dtab_count;
227 if (*(buffer+len-1) ==
'\n')
235 key = kdb_read_get_key(buffer, bufsize);
244 memcpy(tmpbuffer, cp, lastchar - cp);
245 memcpy(cp-1, tmpbuffer, lastchar - cp);
247 *(--lastchar) =
'\0';
268 memcpy(tmpbuffer, cp+1, lastchar - cp - 1);
269 memcpy(cp, tmpbuffer, lastchar - cp - 1);
270 *(--lastchar) =
'\0';
302 (lastchar-
buffer)) =
'\0';
304 *lastchar = (
char)key;
305 *(lastchar+1) =
'\0';
317 (lastchar-
buffer)) =
'\0';
319 *lastchar = (
char)key;
320 *(lastchar+1) =
'\0';
326 while (*p_tmp ==
' ')
330 memcpy(tmpbuffer, p_tmp, cp-p_tmp);
331 *(tmpbuffer + (cp-p_tmp)) =
'\0';
332 p_tmp =
strrchr(tmpbuffer,
' ');
340 (p_tmp - tmpbuffer));
341 if (tab == 2 && count > 0) {
343 if (count > dtab_count) {
346 " be printed.\nYou can change the"
347 " environment variable DTABCOUNT.",
351 for (i = 0; i <
count; i++) {
355 *(p_tmp + len) =
'\0';
362 }
else if (tab != 2 && count > 0) {
364 strncpy(p_tmp+len_tmp, cp, lastchar-cp+1);
366 strncpy(cp, p_tmp+len, len_tmp-len + 1);
375 if (key >= 32 && lastchar < bufend) {
377 memcpy(tmpbuffer, cp, lastchar - cp);
378 memcpy(cp+1, tmpbuffer, lastchar - cp);
396 if (kgdb_transition_check(buffer))
403 if (lastchar - buffer >= 5 &&
404 strcmp(lastchar - 5,
"$?#3f") == 0) {
410 if (lastchar - buffer >= 11 &&
411 strcmp(lastchar - 11,
"$qSupported") == 0) {
448 return kdb_read(buffer, bufsize);
468 static void kdb_input_flush(
void)
473 while (flush_delay) {
510 static char kdb_buffer[256];
511 static char *next_avail = kdb_buffer;
512 static int size_avail;
513 static int suspend_grep;
521 static int kdb_search_string(
char *searched,
char *searchfor)
527 len1 =
strlen(searched)-1;
534 if (!
strncmp(searched, searchfor, len2))
537 if (!
strncmp(searched+len1-len2, searchfor, len2))
540 firstchar = *searchfor;
542 while ((cp =
strchr(cp, firstchar))) {
543 if (!
strncmp(cp, searchfor, len2))
556 int logging, saved_loglevel = 0;
557 int saved_trap_printk;
558 int got_printf_lock = 0;
561 char *
cp, *cp2, *cphold =
NULL, replaced_byte =
' ';
562 char *moreprompt =
"more> ";
585 if (diag || linecount <= 1)
589 if (diag || colcount <= 1)
598 next_avail = kdb_buffer;
599 size_avail =
sizeof(kdb_buffer);
601 vsnprintf(next_avail, size_avail, fmt, ap);
613 cp =
strchr(kdb_buffer,
'\n');
628 if (next_avail == kdb_buffer) {
649 next_avail = kdb_buffer + len;
650 size_avail =
sizeof(kdb_buffer) - len;
676 *cphold = replaced_byte;
677 strcpy(kdb_buffer, cphold);
679 next_avail = kdb_buffer + len;
680 size_avail =
sizeof(kdb_buffer) - len;
693 retlen =
strlen(kdb_buffer);
706 c->
write(c, kdb_buffer, retlen);
726 if (kdb_buffer[len] ==
'\n') {
729 }
else if (kdb_buffer[len] ==
'\r') {
752 if (moreprompt ==
NULL)
753 moreprompt =
"more> ";
780 kdb_buffer[0] =
'\0';
781 next_avail = kdb_buffer;
782 size_avail =
sizeof(kdb_buffer);
783 if ((buf1[0] ==
'q') || (buf1[0] ==
'Q')) {
790 }
else if (buf1[0] ==
' ') {
793 }
else if (buf1[0] ==
'\n') {
797 }
else if (buf1[0] && buf1[0] !=
'\n') {
800 kdb_printf(
"\nOnly 'q' or 'Q' are processed at more "
801 "prompt, input ignored\n");
817 *cphold = replaced_byte;
818 strcpy(kdb_buffer, cphold);
820 next_avail = kdb_buffer + len;
821 size_avail =
sizeof(kdb_buffer) - len;
828 if (
KDB_STATE(PRINTF_LOCK) && got_printf_lock) {
830 spin_unlock_irqrestore(&kdb_printf_lock,
flags);