Re: Useful KERNEL_ASSERT Macro

Kent Overstreet (kento@pobox.alaska.net)
Sat, 31 Jul 1999 01:59:40 -0800


Jordan Mendelson wrote:
>
> I was curious if there was any plans to implement a sort of global ASSERT()
> macro for the kernel that all functions could use when the kernel is compiled
> with extra debugging on.
>
> It would seem to me that if you had a lot of problems with your machine
> crashing, ASSERT() macros placed in every function to verify variables would be
> extremely helpful. Of course this code would significantly slow down the kernel,
> it would be easier than using one of the kernel based debuggers out there (which
> are great btw).
>
> The following ASSERT macro seems adequate:
>
> #ifdef KERNEL_ASSERT
> #define KERNEL_ASSERT(expr) (expr || printk(KERN_DEBUG "%s/%d: Assertion failed!
> %s\n", __FILE__, __LINE__, #expr));
> #else
> #define KERNEL_ASSERT(expr) 0
> #endif
>
> This sort of thing might be useful if you are having hardware problems which are
> are generally difficult to diagnose. Just recompile your kernel with
> KERNEL_ASSERT and wait for errors, if you get errors, you know you have
> problems.
>
> Of course, this would require putting KERNEL_ASSERT()'s everywhere, any time you
> pass a variable where you know that a normal kernel will not set a NULL or odd
> range... KERNEL_ASSERT().
>
> KERNEL_ASSERT() could also replace a lot of the checking code already in the
> kernel which would not be called under any circumstance unless something was
> really wrong...
>
> Just a thought.
>
> Jordan

What about implementing this specific to the function? i.e. you usually
wouldn't turn on all the asserts, just the ones for the function you
thought had the bug. This wouldn't slow down the kernel nearly as much,
and with all of them on it could take awhile to sift through all the
information. And, you wouldn't need to put it in the whole kernel right
away, you could insert the code as it was needed.

-
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/