[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-kernel
Subject:    Re: Useful KERNEL_ASSERT Macro
From:       Tim Hockin <thockin () isunix ! it ! ilstu ! edu>
Date:       1999-07-31 20:36:38
[Download RAW message or body]

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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic