arch/x86/kernel/kgdb.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/kgdb.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/kgdb.c- Extension
.c- Size
- 19925 bytes
- Lines
- 786
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- 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/spinlock.hlinux/kdebug.hlinux/string.hlinux/kernel.hlinux/ptrace.hlinux/sched.hlinux/delay.hlinux/kgdb.hlinux/smp.hlinux/nmi.hlinux/hw_breakpoint.hlinux/uaccess.hlinux/memory.hasm/text-patching.hasm/debugreg.hasm/apicdef.hasm/apic.hasm/nmi.hasm/switch_to.h
Detected Declarations
function dbg_set_regfunction sleeping_thread_to_gdb_regsfunction kgdb_correct_hw_breakfunction hw_break_reserve_slotfunction for_each_online_cpufunction hw_break_release_slotfunction for_each_online_cpufunction kgdb_remove_hw_breakfunction kgdb_remove_all_hw_breakfunction kgdb_set_hw_breakfunction kgdb_disable_hw_debugfunction kgdb_handle_exceptionfunction kgdb_arch_handle_exceptionfunction single_step_contfunction kgdb_nmi_handlerfunction __kgdb_notifyfunction kgdb_ll_trapfunction kgdb_notifyfunction kgdb_arch_initfunction kgdb_hw_overflow_handlerfunction kgdb_arch_latefunction for_each_online_cpufunction kgdb_arch_exitfunction kgdb_skipexceptionfunction kgdb_arch_pcfunction kgdb_arch_set_pcfunction kgdb_arch_set_breakpointfunction kgdb_arch_remove_breakpoint
Annotated Snippet
if (dbg_is_early) {
set_debugreg(breakinfo[breakno].addr, breakno);
early_dr7 |= encode_dr7(breakno,
breakinfo[breakno].len,
breakinfo[breakno].type);
set_debugreg(early_dr7, 7);
continue;
}
bp = *per_cpu_ptr(breakinfo[breakno].pev, cpu);
info = counter_arch_bp(bp);
if (bp->attr.disabled != 1)
continue;
bp->attr.bp_addr = breakinfo[breakno].addr;
bp->attr.bp_len = breakinfo[breakno].len;
bp->attr.bp_type = breakinfo[breakno].type;
info->address = breakinfo[breakno].addr;
info->len = breakinfo[breakno].len;
info->type = breakinfo[breakno].type;
val = arch_install_hw_breakpoint(bp);
if (!val)
bp->attr.disabled = 0;
}
if (!dbg_is_early)
hw_breakpoint_restore();
}
static int hw_break_reserve_slot(int breakno)
{
int cpu;
int cnt = 0;
struct perf_event **pevent;
if (dbg_is_early)
return 0;
for_each_online_cpu(cpu) {
cnt++;
pevent = per_cpu_ptr(breakinfo[breakno].pev, cpu);
if (dbg_reserve_bp_slot(*pevent))
goto fail;
}
return 0;
fail:
for_each_online_cpu(cpu) {
cnt--;
if (!cnt)
break;
pevent = per_cpu_ptr(breakinfo[breakno].pev, cpu);
dbg_release_bp_slot(*pevent);
}
return -1;
}
static int hw_break_release_slot(int breakno)
{
struct perf_event **pevent;
int cpu;
if (dbg_is_early)
return 0;
for_each_online_cpu(cpu) {
pevent = per_cpu_ptr(breakinfo[breakno].pev, cpu);
if (dbg_release_bp_slot(*pevent))
/*
* The debugger is responsible for handing the retry on
* remove failure.
*/
return -1;
}
return 0;
}
static int
kgdb_remove_hw_break(unsigned long addr, int len, enum kgdb_bptype bptype)
{
int i;
for (i = 0; i < HBP_NUM; i++)
if (breakinfo[i].addr == addr && breakinfo[i].enabled)
break;
if (i == HBP_NUM)
return -1;
if (hw_break_release_slot(i)) {
printk(KERN_ERR "Cannot remove hw breakpoint at %lx\n", addr);
return -1;
}
Annotation
- Immediate include surface: `linux/spinlock.h`, `linux/kdebug.h`, `linux/string.h`, `linux/kernel.h`, `linux/ptrace.h`, `linux/sched.h`, `linux/delay.h`, `linux/kgdb.h`.
- Detected declarations: `function dbg_set_reg`, `function sleeping_thread_to_gdb_regs`, `function kgdb_correct_hw_break`, `function hw_break_reserve_slot`, `function for_each_online_cpu`, `function hw_break_release_slot`, `function for_each_online_cpu`, `function kgdb_remove_hw_break`, `function kgdb_remove_all_hw_break`, `function kgdb_set_hw_break`.
- Atlas domain: Architecture Layer / arch/x86.
- 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.