kernel/debug/kdb/kdb_io.c
Source file repositories/reference/linux-study-clean/kernel/debug/kdb/kdb_io.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/debug/kdb/kdb_io.c- Extension
.c- Size
- 23482 bytes
- Lines
- 919
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/ctype.hlinux/kernel.hlinux/init.hlinux/kdev_t.hlinux/console.hlinux/string.hlinux/sched.hlinux/smp.hlinux/nmi.hlinux/delay.hlinux/kgdb.hlinux/kdb.hlinux/kallsyms.hkdb_private.h
Detected Declarations
function kgdb_transition_checkfunction kdb_handle_escapefunction kdb_getcharfunction receivedfunction kdb_position_cursorfunction kdb_input_flushfunction kdb_search_stringfunction kdb_msg_writefunction vkdb_printffunction kdb_parsefunction kdb_printfexport kdb_printf
Annotated Snippet
if (slen > 3 && buffer[slen - 3] == '#') {
kdb_gdb_state_pass(buffer);
strcpy(buffer, "kgdb");
KDB_STATE_SET(DOING_KGDB);
return 1;
}
}
return 0;
}
/**
* kdb_handle_escape() - validity check on an accumulated escape sequence.
* @buf: Accumulated escape characters to be examined. Note that buf
* is not a string, it is an array of characters and need not be
* nil terminated.
* @sz: Number of accumulated escape characters.
*
* Return: -1 if the escape sequence is unwanted, 0 if it is incomplete,
* otherwise it returns a mapped key value to pass to the upper layers.
*/
static int kdb_handle_escape(char *buf, size_t sz)
{
char *lastkey = buf + sz - 1;
switch (sz) {
case 1:
if (*lastkey == '\e')
return 0;
break;
case 2: /* \e<something> */
if (*lastkey == '[')
return 0;
break;
case 3:
switch (*lastkey) {
case 'A': /* \e[A, up arrow */
return 16;
case 'B': /* \e[B, down arrow */
return 14;
case 'C': /* \e[C, right arrow */
return 6;
case 'D': /* \e[D, left arrow */
return 2;
case '1': /* \e[<1,3,4>], may be home, del, end */
case '3':
case '4':
return 0;
}
break;
case 4:
if (*lastkey == '~') {
switch (buf[2]) {
case '1': /* \e[1~, home */
return 1;
case '3': /* \e[3~, del */
return 4;
case '4': /* \e[4~, end */
return 5;
}
}
break;
}
return -1;
}
/**
* kdb_getchar() - Read a single character from a kdb console (or consoles).
*
* Other than polling the various consoles that are currently enabled,
* most of the work done in this function is dealing with escape sequences.
*
* An escape key could be the start of a vt100 control sequence such as \e[D
* (left arrow) or it could be a character in its own right. The standard
* method for detecting the difference is to wait for 2 seconds to see if there
* are any other characters. kdb is complicated by the lack of a timer service
* (interrupts are off), by multiple input sources. Escape sequence processing
* has to be done as states in the polling loop.
*
* Return: The key pressed or a control code derived from an escape sequence.
*/
char kdb_getchar(void)
{
#define ESCAPE_UDELAY 1000
#define ESCAPE_DELAY (2*1000000/ESCAPE_UDELAY) /* 2 seconds worth of udelays */
char buf[4]; /* longest vt100 escape sequence is 4 bytes */
char *pbuf = buf;
Annotation
- Immediate include surface: `linux/types.h`, `linux/ctype.h`, `linux/kernel.h`, `linux/init.h`, `linux/kdev_t.h`, `linux/console.h`, `linux/string.h`, `linux/sched.h`.
- Detected declarations: `function kgdb_transition_check`, `function kdb_handle_escape`, `function kdb_getchar`, `function received`, `function kdb_position_cursor`, `function kdb_input_flush`, `function kdb_search_string`, `function kdb_msg_write`, `function vkdb_printf`, `function kdb_parse`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.