Skip to content

Commit f30fed1

Browse files
committed
kgdb: Add module event hooks
Allow gdb to auto load kernel modules when it is attached, which makes it trivially easy to debug module init functions or pre-set breakpoints in a kernel module that has not loaded yet. Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
1 parent a0d271c commit f30fed1

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

kernel/debug/debug_core.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,22 @@ kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs)
688688
return kgdb_cpu_enter(ks, regs, DCPU_WANT_MASTER);
689689
}
690690

691+
/*
692+
* GDB places a breakpoint at this function to know dynamically
693+
* loaded objects. It's not defined static so that only one instance with this
694+
* name exists in the kernel.
695+
*/
696+
697+
static int module_event(struct notifier_block *self, unsigned long val,
698+
void *data)
699+
{
700+
return 0;
701+
}
702+
703+
static struct notifier_block dbg_module_load_nb = {
704+
.notifier_call = module_event,
705+
};
706+
691707
int kgdb_nmicallback(int cpu, void *regs)
692708
{
693709
#ifdef CONFIG_SMP
@@ -816,6 +832,7 @@ static void kgdb_register_callbacks(void)
816832
kgdb_arch_init();
817833
if (!dbg_is_early)
818834
kgdb_arch_late();
835+
register_module_notifier(&dbg_module_load_nb);
819836
register_reboot_notifier(&dbg_reboot_notifier);
820837
atomic_notifier_chain_register(&panic_notifier_list,
821838
&kgdb_panic_event_nb);
@@ -839,6 +856,7 @@ static void kgdb_unregister_callbacks(void)
839856
if (kgdb_io_module_registered) {
840857
kgdb_io_module_registered = 0;
841858
unregister_reboot_notifier(&dbg_reboot_notifier);
859+
unregister_module_notifier(&dbg_module_load_nb);
842860
atomic_notifier_chain_unregister(&panic_notifier_list,
843861
&kgdb_panic_event_nb);
844862
kgdb_arch_exit();

0 commit comments

Comments
 (0)