2026-06-02
The asker has a vmlinux with debug symbols and a .ko module they need to debug during init. The usual recipe — load the module, read its section addresses from /sys/module/<name>/sections/, then add-symbol-file in GDB — doesn't work here because by the time you've gathered that information, module_init() has already run. They need symbols resolved before the module's init code executes.
This is a classic chicken-and-egg: you can't know where the module will be loaded until the kernel allocates memory for it, but you need a breakpoint before that memory is used.
The kernel itself loads modules through do_init_module() in kernel/module/main.c (or kernel/module.c on older trees). The trick is to set a breakpoint in the kernel that fires after the module's sections have been allocated and relocated but before do_one_initcall(mod->init) runs.
-s -S (or use kgdb on real hardware).vmlinux symbols, then break do_init_module.insmod the module. When the breakpoint fires, the struct module *mod argument has all the section addresses you need: mod->mem[MOD_TEXT].base, plus the .data, .bss, .rodata sections (older kernels use mod->core_layout.base).add-symbol-file mymod.ko <text_addr> -s .data <data_addr> -s .bss <bss_addr> ... command.init function and continue.The kernel's own scripts/gdb/linux/symbols.py (the lx-symbols command) does almost exactly this — it walks the module list and loads symbols automatically. The catch is that it normally runs after modules are loaded. You can either hack it to break at do_init_module entry, or call lx-symbols from inside that breakpoint handler before stepping into do_one_initcall.
mod->core_layout/init_layout got replaced by the mod->mem[] array. Your script must match the kernel version.vmlinux symbols are loaded against the actual runtime base (use the kernel's nokaslr boot param for sanity while debugging).-O1 or -Og and EXTRA_CFLAGS += -g; -O2 will inline most of module_init away.core_initcall in a built-in module won't go through do_init_module at all — different path entirely.