kernel/debug/gdbstub.c
Source file repositories/reference/linux-study-clean/kernel/debug/gdbstub.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/debug/gdbstub.c- Extension
.c- Size
- 26425 bytes
- Lines
- 1159
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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/kernel.hlinux/sched/signal.hlinux/hex.hlinux/kgdb.hlinux/kdb.hlinux/serial_core.hlinux/string.hlinux/reboot.hlinux/uaccess.hasm/cacheflush.hlinux/unaligned.hdebug_core.h
Detected Declarations
function gdbstub_read_waitfunction gdbstub_read_waitfunction get_packetfunction put_packetfunction gdbstub_msg_writefunction kgdb_hex2memfunction kgdb_hex2longfunction kgdb_ebin2memfunction pt_regs_to_gdb_regsfunction gdb_regs_to_pt_regsfunction write_mem_msgfunction error_packetfunction threadsfunction int_to_threadreffunction shadow_pidfunction gdb_cmd_statusfunction gdb_get_regs_helperfunction for_each_online_cpufunction schedulefunction gdb_cmd_getregsfunction gdb_cmd_setregsfunction gdb_cmd_memreadfunction gdb_cmd_memwritefunction gdb_cmd_reg_getfunction gdb_cmd_reg_setfunction gdb_cmd_binwritefunction gdb_cmd_detachkillfunction gdb_cmd_rebootfunction gdb_cmd_queryfunction for_each_process_threadfunction gdb_cmd_taskfunction gdb_cmd_threadfunction gdb_cmd_breakfunction gdb_cmd_exception_passfunction gdb_serial_stubfunction gdbstub_statefunction gdbstub_exit
Annotated Snippet
while (count < (BUFMAX - 1)) {
ch = gdbstub_read_wait();
if (ch == '#')
break;
checksum = checksum + ch;
buffer[count] = ch;
count = count + 1;
}
if (ch == '#') {
xmitcsum = hex_to_bin(gdbstub_read_wait()) << 4;
xmitcsum += hex_to_bin(gdbstub_read_wait());
if (checksum != xmitcsum)
/* failed checksum */
dbg_io_ops->write_char('-');
else
/* successful transfer */
dbg_io_ops->write_char('+');
if (dbg_io_ops->flush)
dbg_io_ops->flush();
}
buffer[count] = 0;
} while (checksum != xmitcsum);
}
/*
* Send the packet in buffer.
* Check for gdb connection if asked for.
*/
static void put_packet(char *buffer)
{
unsigned char checksum;
int count;
char ch;
/*
* $<packet info>#<checksum>.
*/
while (1) {
dbg_io_ops->write_char('$');
checksum = 0;
count = 0;
while ((ch = buffer[count])) {
dbg_io_ops->write_char(ch);
checksum += ch;
count++;
}
dbg_io_ops->write_char('#');
dbg_io_ops->write_char(hex_asc_hi(checksum));
dbg_io_ops->write_char(hex_asc_lo(checksum));
if (dbg_io_ops->flush)
dbg_io_ops->flush();
/* Now see what we get in reply. */
ch = gdbstub_read_wait();
if (ch == 3)
ch = gdbstub_read_wait();
/* If we get an ACK, we are done. */
if (ch == '+')
return;
/*
* If we get the start of another packet, this means
* that GDB is attempting to reconnect. We will NAK
* the packet being sent, and stop trying to send this
* packet.
*/
if (ch == '$') {
dbg_io_ops->write_char('-');
if (dbg_io_ops->flush)
dbg_io_ops->flush();
return;
}
}
}
static char gdbmsgbuf[BUFMAX + 1];
void gdbstub_msg_write(const char *s, int len)
{
char *bufptr;
int wcount;
int i;
if (len == 0)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/sched/signal.h`, `linux/hex.h`, `linux/kgdb.h`, `linux/kdb.h`, `linux/serial_core.h`, `linux/string.h`, `linux/reboot.h`.
- Detected declarations: `function gdbstub_read_wait`, `function gdbstub_read_wait`, `function get_packet`, `function put_packet`, `function gdbstub_msg_write`, `function kgdb_hex2mem`, `function kgdb_hex2long`, `function kgdb_ebin2mem`, `function pt_regs_to_gdb_regs`, `function gdb_regs_to_pt_regs`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source 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.