Skip to contentSkip to conversation

kdb: fix ctrl+e/a/f/b/d/p/n broken in keyboard mode

PATCH Superseded Nir Lichtman 2 participants 3 messages Nov 8, 2024 – Nov 9, 2024 KGDB / KDB /debug_core

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kdb: fix ctrl+e/a/f/b/d/p/n broken in keyboard mode

Problem: When using KDB via keyboard it does not react to control characters which are supported in serial mode.

Example: Chords such as CTRL+A/E/D/P do not work in keyboard mode

Solution: Before disregarding a non-printable key character, check if it is one of the supported control characters, I have took the control characters from the switch case upwards in this function that translates scan codes of arrow keys/backspace/home/.. to the control characters. I have took them all besides the TAB control character translation (I am not sure what that maps to on the keyboard)

---
 kernel/debug/kdb/kdb_keyboard.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/debug/kdb/kdb_keyboard.c +3 -0
index 3c2987f46f6e..2c004abd5375 100644
@@ -172,6 +172,9 @@ int kdb_get_kbd_char(void)
 	switch (KTYP(keychar)) {
 	case KT_LETTER:
 	case KT_LATIN:
+		if (keychar == 4 || keychar == 1 || keychar == 5 || keychar == 2 ||
+		    keychar == 16 || keychar == 14 || keychar == 6)
+			return keychar;		/* non-printable supported control characters (e.g. CTRL+A) */
 		if (isprint(keychar))
 			break;		/* printable characters */
 		fallthrough;
Signature · 1 line
2.39.2
reviewer
#1 lore raw

Hi,

Quoted 4 lines · Nir Lichtman

Problem: When using KDB via keyboard it does not react to control characters which are supported in serial mode.

Quoted 8 lines

Example: Chords such as CTRL+A/E/D/P do not work in keyboard mode

Solution: Before disregarding a non-printable key character, check if it is one of the supported control characters, I have took the control characters from the switch case upwards in this function that translates scan codes of arrow keys/backspace/home/.. to the control characters. I have took them all besides the TAB control character translation (I am not sure what that maps to on the keyboard)

Tab translates to 9, so the 9th character. Ctrl-I.

Quoted 8 lines
 kernel/debug/kdb/kdb_keyboard.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/debug/kdb/kdb_keyboard.c +0 -0
index 3c2987f46f6e..2c004abd5375 100644

kernel/debug/kdb/kdb_keyboard.c int kdb_get_kbd_char(void) · line 177

Quoted 6 lines
kernel/debug/kdb/kdb_keyboard.c +3 -0
@@ -172,6 +172,9 @@ int kdb_get_kbd_char(void)
        switch (KTYP(keychar)) {
        case KT_LETTER:
        case KT_LATIN:
+               if (keychar == 4 || keychar == 1 || keychar == 5 || keychar == 2 ||
+                   keychar == 16 || keychar == 14 || keychar == 6)
+                       return keychar;         /* non-printable supported control characters (e.g. CTRL+A) */

This is probably OK, but IMO readability here (and above) could be improved. Untested, but I think:

#define CTRL(c) (c - 64)

Then:

/* Allowlist supported control characters */
switch(keychar) {
case CTRL('A'): /* Home */
case CTRL('B'): /* Left */
case CTRL('D'): /* Del */
case CTRL('E'): /* End */
case CTRL('F'): /* Right */
case CTRL('I'): /* Tab */
case CTRL('N'): /* Down */
case CTRL('P'): /* Up */

    return keychar;
}

The code above could also use them, AKA (untested):

/* Translate special keys to equivalent Ctrl characters */ switch (scancode) {
case 0xF: /* Tab */
return CTRL('I');
case 0x53: /* Del */
return CTRL('D');
case 0x47: /* Home */
return CTRL('A');
case 0x4F: /* End */
return CTRL('E');
case 0x4B: /* Left */
return CTRL('B');
case 0x48: /* Up */
return CTRL('P');
case 0x50: /* Down */
return CTRL('N');
case 0x4D: /* Right */
return CTRL('F');
}

#2 lore raw
Quoted 11 lines · Doug Anderson

Hi,

Quoted 6 lines · Nir Lichtman

Problem: When using KDB via keyboard it does not react to control characters which are supported in serial mode.

I have took them all besides the TAB control character translation (I am not sure what that maps to on the keyboard)

Tab translates to 9, so the 9th character. Ctrl-I.

Noted, thanks

Quoted 20 lines
Quoted 10 lines

 kernel/debug/kdb/kdb_keyboard.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/debug/kdb/kdb_keyboard.c +0 -0
index 3c2987f46f6e..2c004abd5375 100644

kernel/debug/kdb/kdb_keyboard.c int kdb_get_kbd_char(void) · line 177

Quoted 6 lines
kernel/debug/kdb/kdb_keyboard.c +3 -0
@@ -172,6 +172,9 @@ int kdb_get_kbd_char(void)
        switch (KTYP(keychar)) {
        case KT_LETTER:
        case KT_LATIN:
+               if (keychar == 4 || keychar == 1 || keychar == 5 || keychar == 2 ||
+                   keychar == 16 || keychar == 14 || keychar == 6)
+                       return keychar;         /* non-printable supported control characters (e.g. CTRL+A) */

This is probably OK, but IMO readability here (and above) could be improved. Untested, but I think:

Quoted 1 line

#define CTRL(c) (c - 64)

That's a good point, I will work on a v2 with this fix.

Quoted 6 lines

Then:

/* Allowlist supported control characters */
switch(keychar) {
case CTRL('A'): /* Home */

[...]

Thanks,
Nir