lkml.org 
[lkml]   [1999]   [Jul]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: Useful KERNEL_ASSERT Macro
Date
> 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/

\
 
 \ /
  Last update: 2005-03-22 13:53    [W:0.048 / U:0.068 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site