how to debug a module when kernel-2.2.12 running?

Keith Owens kaos at melbourne.sgi.com
Tue Jul 25 20:43:23 PDT 2000


On Wed, 26 Jul 2000 11:00:24 +0800, 
"lhyang" <lhyang at cti.com.cn> wrote:
>    At present, I am programming a module about device driver, and I want to debug the module,
>after using two famous debugger tools, I find that they all can debug kernel code, but no method to debug a module, 
>or maybe what I said makes a mistake, in a word, I expect some help.
>
>below is the two tools
>1.kdb-v0.6 from oss.sgi.com
>no method to set breakpoint to a module, though press Pause key to run kdb, so when running insmod xxx.o, I can't use it.

If you want to debug the loading process for a module, the easiest way
is to put the breakpoint in sys_init_module().  Towards the end of that
function there is this chunk of code

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

You need to set the breakpoint on the call to mod->init().  It is easy
enough to find, objdump -S kernel/module.o and look for "call *%edx" in
sys_init_module(), there should only be one.  When your breakpoint
triggers at that call instruction, your module has been loaded but not
yet executed.  You should be then able to set breakpoints in your
module.

Or you can #include <linux/kdb.h> in your module and stick KDB_ENTER();
statements where you want to get control.

>2. IKD(Intergrated Kernel Debugger), 2.2.12-ikd from e-mind.com
>by running xkgdb in linux/scripts directory, create xkdebug devive file and module and kgdb process,
>but it can't load kernel symbols and module symbols simultaneously, though can set breakpoint to module,
>but can't debug the module at load module by insmod xxx.o.

The problem is in gdb, older versions of gdb stuffed up symbol handling
in modules.  This should have been fixed in current versions of gdb and
recent versions of IKD should support module debugging.  The main
problem with xkgdb is that you have to have a working kernel to use it,
if you lockup with interrupts disabled then xkdb is not much help.

BTW, the latest IKD is not on e-mind, Andrea now ships it in
ftp://ftp.**.kernel.org/pub/linux/kernel/people/andrea/ikd
          ^^ replace '**' with nearest country code.




More information about the kdb mailing list