All of lore.kernel.org
 help / color / mirror / Atom feed
From: "David Härdeman" <david@2gen.com>
To: linux-kernel@vger.kernel.org
Subject: Consolidate dprintk and friends?
Date: Thu, 1 Sep 2005 20:17:23 +0200	[thread overview]
Message-ID: <20050901181722.GA4604@hansolo> (raw)

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

                 reply	other threads:[~2005-09-01 18:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050901181722.GA4604@hansolo \
    --to=david@2gen.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.