kernel/debug/kdb/kdb_main.c
Source file repositories/reference/linux-study-clean/kernel/debug/kdb/kdb_main.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/debug/kdb/kdb_main.c- Extension
.c- Size
- 67688 bytes
- Lines
- 2812
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/ctype.hlinux/types.hlinux/string.hlinux/kernel.hlinux/kmsg_dump.hlinux/reboot.hlinux/sched.hlinux/sched/loadavg.hlinux/sched/stat.hlinux/sched/debug.hlinux/sysrq.hlinux/smp.hlinux/utsname.hlinux/vmalloc.hlinux/moduleparam.hlinux/mm.hlinux/init.hlinux/kallsyms.hlinux/kgdb.hlinux/kdb.hlinux/notifier.hlinux/interrupt.hlinux/delay.hlinux/nmi.hlinux/time.hlinux/ptrace.hlinux/sysctl.hlinux/cpu.hlinux/kdebug.hlinux/proc_fs.hlinux/uaccess.hlinux/slab.h
Detected Declarations
struct kdb_macrostruct kdb_macro_statementfunction flagsfunction kdb_check_flagsfunction kdbgetulenvfunction kdbgetintenvfunction kdb_setenvfunction kdb_printenvfunction kdbgetulargfunction kdbgetu64argfunction kdb_setfunction kdb_check_regsfunction valuefunction kdb_cmderrorfunction kdb_defcmd2function kdb_defcmdfunction list_for_each_entryfunction kdb_exec_defcmdfunction list_for_each_entryfunction parse_grepfunction kdb_parsefunction list_for_each_entryfunction list_for_each_entryfunction handle_ctrl_cmdfunction kdb_rebootfunction kdb_dumpregsfunction kdb_set_current_taskfunction drop_newlinefunction kdb_localfunction kdb_print_statefunction kdb_main_loopfunction kdb_mdrfunction kdb_md_linefunction kdb_mdfunction kdb_mmfunction kdb_gofunction kdb_rdfunction kdb_rmfunction kdb_srfunction kdb_effunction kdb_envfunction kdb_dmesgfunction kdb_cpu_statusfunction kdb_cpufunction kdb_ps_suppressedfunction kdb_ps1function kdb_psfunction kdb_pid
Annotated Snippet
struct kdb_macro {
kdbtab_t cmd; /* Macro command */
struct list_head statements; /* Associated statement list */
};
struct kdb_macro_statement {
char *statement; /* Statement text */
struct list_head list_node; /* Statement list node */
};
static struct kdb_macro *kdb_macro;
static bool defcmd_in_progress;
/* Forward references */
static int kdb_exec_defcmd(int argc, const char **argv);
static int kdb_defcmd2(const char *cmdstr, const char *argv0)
{
struct kdb_macro_statement *kms;
if (!kdb_macro)
return KDB_NOTIMP;
if (strcmp(argv0, "endefcmd") == 0) {
defcmd_in_progress = false;
if (!list_empty(&kdb_macro->statements))
kdb_register(&kdb_macro->cmd);
return 0;
}
kms = kmalloc_obj(*kms, GFP_KDB);
if (!kms) {
kdb_printf("Could not allocate new kdb macro command: %s\n",
cmdstr);
return KDB_NOTIMP;
}
kms->statement = kdb_strdup(cmdstr, GFP_KDB);
list_add_tail(&kms->list_node, &kdb_macro->statements);
return 0;
}
static int kdb_defcmd(int argc, const char **argv)
{
kdbtab_t *mp;
if (defcmd_in_progress) {
kdb_printf("kdb: nested defcmd detected, assuming missing "
"endefcmd\n");
kdb_defcmd2("endefcmd", "endefcmd");
}
if (argc == 0) {
kdbtab_t *kp;
struct kdb_macro *kmp;
struct kdb_macro_statement *kms;
list_for_each_entry(kp, &kdb_cmds_head, list_node) {
if (kp->func == kdb_exec_defcmd) {
kdb_printf("defcmd %s \"%s\" \"%s\"\n",
kp->name, kp->usage, kp->help);
kmp = container_of(kp, struct kdb_macro, cmd);
list_for_each_entry(kms, &kmp->statements,
list_node)
kdb_printf("%s", kms->statement);
kdb_printf("endefcmd\n");
}
}
return 0;
}
if (argc != 3)
return KDB_ARGCOUNT;
if (in_dbg_master()) {
kdb_printf("Command only available during kdb_init()\n");
return KDB_NOTIMP;
}
kdb_macro = kzalloc_obj(*kdb_macro, GFP_KDB);
if (!kdb_macro)
goto fail_defcmd;
mp = &kdb_macro->cmd;
mp->func = kdb_exec_defcmd;
mp->minlen = 0;
mp->flags = KDB_ENABLE_ALWAYS_SAFE;
mp->name = kdb_strdup(argv[1], GFP_KDB);
if (!mp->name)
goto fail_name;
mp->usage = kdb_strdup_dequote(argv[2], GFP_KDB);
if (!mp->usage)
goto fail_usage;
Annotation
- Immediate include surface: `linux/ctype.h`, `linux/types.h`, `linux/string.h`, `linux/kernel.h`, `linux/kmsg_dump.h`, `linux/reboot.h`, `linux/sched.h`, `linux/sched/loadavg.h`.
- Detected declarations: `struct kdb_macro`, `struct kdb_macro_statement`, `function flags`, `function kdb_check_flags`, `function kdbgetulenv`, `function kdbgetintenv`, `function kdb_setenv`, `function kdb_printenv`, `function kdbgetularg`, `function kdbgetu64arg`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
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.