i think everytime you load it and unload it you may get different addresses

so you want a few more things in the [Host](gdb) section before loading
a module these stepd should allow you to debug a module_init routine

1) from http://kgdb.linsyssoft.com/downloads/miscmacros
    we get an idea how to address modules from within gdb

#Miscellaneous macros
define lsmod
    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

2) you need a break point in module.c (sys_init_module) where we have
    the mod pointer in hand and are about to call init. like here in 2.4.26

    /* Initialize the module.  */
    atomic_set(&mod->uc.usecount,1);
    mod->flags |= MOD_INITIALIZING;
    if (mod->init && (error = mod->init()) != 0) {

3) so when you set this break point you want to do something like this:

    (gdb)break module.c:553
    # note the breakpoint number xx
    (gdb)commands xx
         printf "add-symbol-file %s\t%p\n", ($mod)->name, (long)$mod +
$mod->size_of_struct
         end

Note the extra size_of_struct to point to the correct area.

Cut-and-Paste the resulting line into your gdb window.
Assuming the path to your module is in the gdb session 'dir' path
(if not you can point it to using a path to the .o)

your symbols should load and you should be able to step into
mod->init() with code you can read.

db

Mikado wrote:
>
> - How can I debug loadable modules at run time?
>
> Here is my way:
>
>   ( /tmp/mymodule.ko exists on both [Host] and [UML] )
>   + [Host] # gdb linux
>   + [Host] (gdb) ...
>   + [Host] (gdb) r <params>
>   + [UML] # insmod /tmp/mymodule.ko
>   + [UML] # cat /sys/module/mymodule/sections/{.text,.bss,.data}
>   + [Host] (gdb) add-symbol-file /tmp/mymodule.ko <.text_addr> -s .bss
> <.bss_addr> -s .data <.data_addr>
>   + ...
>
> Tell me if I was wrong, thanks!
>
> - How can I set breakpoint at module's init function?
>
> After add module's symbol, I set breakpoint at init function then
> 'rmmod' then re-'insmod' but gdb didn't break at init function. What was
> wrong?
>
> - Sometimes gdb can't follow source codes in '.h' header files. Did I
> miss something?
>
> Thanks in advance,
> Mikado.


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to