2005-09-01 18:17:38

by David Härdeman

[permalink] [raw]
Subject: Consolidate dprintk and friends?

A case-insensitive grep through the 2.6.13 tree for "define printk"
yields 378 hits ("define dbg": 736, "define warn": 50, "define info":
65).

Maybe it would be a good idea to create include/linux/debug.h as
included inline below (or to add the content in include/linux/kernel.h
where pr_debug is already located)?

Then a module could simply do:

#include <linux/debug.h>
MODULE_DEBUG;

and then sprinkle debug() statements where appropriate.

It would also make the name and description of the debug variable in
sysfs more consistent.

I tried searching the lkml archives, but couldn't find any discussion on
the topic...so is it a good idea?

Re,
David


--- /dev/null 2005-09-01 20:05:20.395616648 +0200
+++ linux-2.6.13/include/linux/debug.h 2005-09-01 20:01:56.000000000 +0200
@@ -0,0 +1,52 @@
+#ifndef _LINUX_DEBUG_H
+#define _LINUX_DEBUG_H
+
+/*
+ * unconditional messages
+ */
+
+/* unc(onditional)_debug should not be used, but rather debug or pr_debug */
+#define unc_debug(fmt,arg...) printk(KERN_DEBUG fmt, ##arg)
+
+/* convenience macros */
+#define info(fmt,arg...) printk(KERN_INFO fmt, ##arg)
+#define warn(fmt,arg...) printk(KERN_WARN fmt, ##arg)
+#define err(fmt,arg...) printk(KERN_EMERG fmt, ##arg)
+
+
+
+/*
+ * debug messages (de)activated at runtime
+ */
+
+/* the variable which (de)activates debugging messages */
+#ifndef DEBUG_VARIABLE
+#define DEBUG_VARIABLE debug
+#endif
+
+/* quick macro to add a debug parameter to a module */
+#define MODULE_DEBUG \
+do { \
+ static unsigned int DEBUG_VARIABLE = 0; \
+ module_param(DEBUG_VARIABLE, uint, 0644); \
+ MODULE_PARM_DESC(DEBUG_VARIABLE, "Enable debug messages"); \
+} while(0)
+
+/* regular debug messages */
+#define debug(fmt,arg...) do { if (DEBUG_VARIABLE) unc_debug(fmt, ##arg); } while (0)
+
+/* different levels of debug messages (only output if DEBUG_VARIABLE is large enough) */
+#define ldebug(level,fmt,arg...) do { if (DEBUG_VARIABLE >= level) unc_debug(fmt, ##arg); } while (0)
+
+
+
+/*
+ * debug messages (de)activated by the preprocessor
+ */
+#ifdef DEBUG
+#define pr_debug(fmt,arg...) unc_debug(fmt, ##arg)
+#else
+#define pr_debug(fmt,arg...) do { } while (0)
+#endif
+
+#endif /* _LINUX_DEBUG_H */