Messages in this thread | | | From | Tim Hockin <> | Subject | Re: Useful KERNEL_ASSERT Macro | Date | Sat, 31 Jul 1999 15:36:38 -0500 (CDT) |
| |
> 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
I have noodled a lot on this concept.
Firstly - I think this is a Good Idea. This and a global KPRINTD() macro for debug info. This will eliminate the various debug macros that float around in all the different subsystems and drivers etc. These should be in a commonly included header <kdebug.h>. Then each file/subsystem can opt to turn on each feature or not. This way we can debug all the different bits independantly, without getting flooded out.
But there are a few problems with the above.. I think you wanted something more like:
/* a general purpose kernel debug print macro */ #ifdef KERNEL_KPRINTD_ON #define KPRINTD(fmt, args...) printk(KERN_DEBUG "KDEBUG: "##fmt, ##args) #else #define KPRINTD(fmt, args...) #endif
/* a general purpose kernel assert macro */ #ifdef KERNEL_ASSERT_ON #define KERNEL_ASSERT(expr) if (!(expr)) \ printk(KERN_DEBUG "KASSERT: %s:%d" \ " - Assertion failed! (%s)\n", \ __FILE__, __LINE__, #expr) #else #define KERNEL_ASSERT(expr) #endif
We could expand this debugging "macro library" quite a lot. I think it would be worthwhile, if we can convince everyone to USE it. It would cut a lot of redundant definitions of ASSERT and DEBUG_PRINT sorts of macros.
Comments?
Tim
- 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/
| |