Merge tag 'kgdb-6.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt...
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 3 Jul 2023 22:19:56 +0000 (15:19 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 3 Jul 2023 22:19:56 +0000 (15:19 -0700)
Pull kgdb updates from Daniel Thompson:
 "Fairly small changes this cycle:

   - An additional static inline function when kgdb is not enabled to
     reduce boilerplate in arch files

   - kdb will now handle input with linefeeds more like carriage return.
     This will make little difference for interactive use but can make
     it script to use expect-like interaction with kdb

   - A couple of warning fixes"

* tag 'kgdb-6.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt/linux:
  kdb: move kdb_send_sig() declaration to a better header file
  kdb: Handle LF in the command parser
  kdb: include kdb_private.h for function prototypes
  kgdb: Provide a stub kgdb_nmicallback() if !CONFIG_KGDB

include/linux/kdb.h
include/linux/kgdb.h
kernel/debug/kdb/kdb_io.c
kernel/debug/kdb/kdb_keyboard.c
kernel/debug/kdb/kdb_private.h

index 07dfb6a..f6c2ddb 100644 (file)
@@ -196,6 +196,8 @@ int kdb_process_cpu(const struct task_struct *p)
        return cpu;
 }
 
+extern void kdb_send_sig(struct task_struct *p, int sig);
+
 #ifdef CONFIG_KALLSYMS
 extern const char *kdb_walk_kallsyms(loff_t *pos);
 #else /* ! CONFIG_KALLSYMS */
index 258cdde..76e891e 100644 (file)
@@ -365,5 +365,6 @@ extern void kgdb_free_init_mem(void);
 #define dbg_late_init()
 static inline void kgdb_panic(const char *msg) {}
 static inline void kgdb_free_init_mem(void) { }
+static inline int kgdb_nmicallback(int cpu, void *regs) { return 1; }
 #endif /* ! CONFIG_KGDB */
 #endif /* _KGDB_H_ */
index 5c7e9ba..813cb6c 100644 (file)
@@ -131,6 +131,7 @@ char kdb_getchar(void)
        int escape_delay = 0;
        get_char_func *f, *f_prev = NULL;
        int key;
+       static bool last_char_was_cr;
 
        for (f = &kdb_poll_funcs[0]; ; ++f) {
                if (*f == NULL) {
@@ -150,6 +151,18 @@ char kdb_getchar(void)
                }
 
                /*
+                * The caller expects that newlines are either CR or LF. However
+                * some terminals send _both_ CR and LF. Avoid having to handle
+                * this in the caller by stripping the LF if we saw a CR right
+                * before.
+                */
+               if (last_char_was_cr && key == '\n') {
+                       last_char_was_cr = false;
+                       continue;
+               }
+               last_char_was_cr = (key == '\r');
+
+               /*
                 * When the first character is received (or we get a change
                 * input source) we set ourselves up to handle an escape
                 * sequences (just in case).
@@ -244,7 +257,8 @@ poll_again:
                        *cp = tmp;
                }
                break;
-       case 13: /* enter */
+       case 10: /* linefeed */
+       case 13: /* carriage return */
                *lastchar++ = '\n';
                *lastchar++ = '\0';
                if (!KDB_STATE(KGDB_TRANS)) {
index f87c750..3c2987f 100644 (file)
@@ -13,6 +13,8 @@
 #include <linux/ctype.h>
 #include <linux/io.h>
 
+#include "kdb_private.h"
+
 /* Keyboard Controller Registers on normal PCs. */
 
 #define KBD_STATUS_REG         0x64    /* Status register (R) */
index 1f8c519..548fd40 100644 (file)
@@ -194,7 +194,6 @@ extern char kdb_task_state_char (const struct task_struct *);
 extern bool kdb_task_state(const struct task_struct *p, const char *mask);
 extern void kdb_ps_suppressed(void);
 extern void kdb_ps1(const struct task_struct *p);
-extern void kdb_send_sig(struct task_struct *p, int sig);
 extern char kdb_getchar(void);
 extern char *kdb_getstr(char *, size_t, const char *);
 extern void kdb_gdb_state_pass(char *buf);