# # Usefull GDB user-command to debug Linux Kernel Modules with gdbstub. # # This don't work for Linux-2.0 or older. # # Author Edouard G. Parmelan # # # Fri Apr 30 20:33:29 CEST 1999 # First public release. # # Major cleanup after experiment Linux-2.0 kernel without success. # Symbols of a module are not in the correct order, I can't explain # why :( # # Fri Mar 19 15:41:40 CET 1999 # Initial version. # # # The basic idea is to find where insmod load the module and inform # GDB to load the symbol table of the module with the GDB command # ``add-symbol-file
''. # # The Linux kernel old the list of all loaded modules in module_list, # this list end with &kernel_module (exactly with module->next == NULL, # but the last module is not a real module). # # Insmod allocates the struct module before the object file. Since # Linux-2.1, this structure contain his size. The real address of # the object file is then (char*)module + module->size_of_struct. # # You can use three user fonctions ``mod-list'', ``mod-print-symbols'' # and ``add-module-symbols''. # # mod-list list all loaded modules with the format: #
# # As soon as you have found the address of your module, you can # print his exported symbols (mod-print-symbols) or inform GDB to add # symbols from your module file (mod-add-symbols). # # The internal function ``mod-validate'' set the GDB variable $mod # as a ``struct module*'' if the kernel known the module otherwise # $mod is set to NULL. This ensure to not add symbols for a wrong # address. # # Have a nice hacking day ! # define mod-list set $mod = (struct module*)module_list # the last module is the kernel, ignore it while $mod != &kernel_module printf "%p\t%s\n", (long)$mod, ($mod)->name set $mod = $mod->next end end document mod-list List all modules and there address (used for mod-print-symbols, mod-load-symbols, ...). end define mod-validate set $mod = (struct module*)module_list while ($mod != $arg0) && ($mod != &kernel_module) set $mod = $mod->next end if $mod == &kernel_module set $mod = 0 printf "%p is not a module\n", $arg0 end end document mod-validate mod-validate : Internal user-command used to validate the module parameter. If is a real loaded module, set $mod to it otherwise set $mod to 0. end define mod-print-symbols mod-validate $arg0 if $mod != 0 set $i = 0 while $i < $mod->nsyms set $sym = $mod->syms[$i] printf "%p\t%s\n", $sym->value, $sym->name set $i = $i + 1 end end end document mod-print-symbols mod-print-symbols : Print all exported symbols of the module. see mod-list end define mod-add-symbols mod-validate $arg0 if $mod != 0 add-symbol-file $arg1 ($mod->size_of_struct + (long)$mod) end end document mod-add-symbols mod-load-symbols : Load the symbols table of the module from the object file. end