Re: your mail

Richard B. Johnson (root@chaos.analogic.com)
Wed, 8 Dec 1999 09:10:15 -0500 (EST)


On Wed, 8 Dec 1999, shisheng wrote:

> Hi,
> I have question in a really simple kernel module programming.
> When I try to load it with insmod, the result is "couldn't find the
> kernel version the module is compiled for".
> My kernel version is "2.2.5-15"
> My makefile is
> CC=gcc
> CFLAGS=-Wall -DMODULE -D__KERNEL__ -DLINUX -g
> $(CC) -c $(CFLAGS) hello.c
>
>
> Header of my source file (hello.c)
> #include <linux/module.h>
> #include <linux/kernel.h>
> .....
> init_module(....
>
>
> I want to know how to debug the procedure a kernel module is loading and
> how to debug a kernel module when it is running
>
> Any help will be thankful
>

You can do `insmod -f ` to force the loading of a module with the
wrong version number.

Apparently the kernel you are running was not compiled from the
Linux source headers that you are using for compilation. This
is why you get the version number error.

Since you can insert and remove modules, debugging in the kernel is
easy. If you like to jump off the cliff and see if you can fly, you
just need a few `printk` statements in your code. You use `printk` just
like `printf` except that there is no `%f`. No floating point is
allowed within the kernel.

If you are more cautious or are debugging some complex code, you can
debug from user-mode by inserting a `main()` and stepping through
various called procedures using `gdb`. This is tedious, but often
finds problems that may remain undiscovered when running in the
kernel, i.e., test exception handlers this way. Some debugging
conditionals can be used to substitute malloc() for kmalloc(), etc.

I recently wrote a NVRAM ramdisk driver module with paged NVRAM.
All of the page/switching (hardware page-switches, not Intel pages)
debugging and such was verified (and fixed where necessary --nobody
is perfect) from user-mode. When I inserted the module it worked.

Cheers,
Dick Johnson

Penguin : Linux version 2.3.13 on an i686 machine (400.59 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.
Seconds : 2040585 (until Y2K)

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/