Messages in this thread | | | Date | Sat, 31 Jul 1999 05:11:51 -0400 | From | Jordan Mendelson <> | Subject | Useful KERNEL_ASSERT Macro |
| |
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
-- Jordan Mendelson : http://jordy.wserv.com Web Services, Inc. : http://www.wserv.com
- 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/
| |