Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Documentation: expand/clarify debug documentation

The pr_debug() and related debug print macros all differ from the normal
pr_XXX() macros, in that the normal ones print unconditionally, while
the debug macros are compiled out unless DEBUG is defined or
CONFIG_DYNAMIC_DEBUG is set. This isn't obvious, and the only way to
find this out is either to review the actual printk.h code or to read
CodingStyle, and the message there doesn't highlight the fact.

Change Documentation/CodingStyle to clearly indicate that pr_debug() and
related debug printing macros behave differently than all other pr_XXX()
macros, and attempt to clarify when and where the different debug
printing methods might be used.

Add short comment to printk.h above the pr_XXX() macros indicating that
while these macros print unconditionally, pr_debug() does not.

Signed-off-by: Dan Streetman <ddstreet@ieee.org>
Cc: Joe Perches <joe@perches.com>
Cc: Fabian Frederick <fabf@skynet.be>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Dan Streetman and committed by
Linus Torvalds
6e099f55 6d9bcb62

+21 -7
+15 -7
Documentation/CodingStyle
··· 660 660 which you should use to make sure messages are matched to the right device 661 661 and driver, and are tagged with the right level: dev_err(), dev_warn(), 662 662 dev_info(), and so forth. For messages that aren't associated with a 663 - particular device, <linux/printk.h> defines pr_debug() and pr_info(). 663 + particular device, <linux/printk.h> defines pr_notice(), pr_info(), 664 + pr_warn(), pr_err(), etc. 664 665 665 666 Coming up with good debugging messages can be quite a challenge; and once 666 - you have them, they can be a huge help for remote troubleshooting. Such 667 - messages should be compiled out when the DEBUG symbol is not defined (that 668 - is, by default they are not included). When you use dev_dbg() or pr_debug(), 669 - that's automatic. Many subsystems have Kconfig options to turn on -DDEBUG. 670 - A related convention uses VERBOSE_DEBUG to add dev_vdbg() messages to the 671 - ones already enabled by DEBUG. 667 + you have them, they can be a huge help for remote troubleshooting. However 668 + debug message printing is handled differently than printing other non-debug 669 + messages. While the other pr_XXX() functions print unconditionally, 670 + pr_debug() does not; it is compiled out by default, unless either DEBUG is 671 + defined or CONFIG_DYNAMIC_DEBUG is set. That is true for dev_dbg() also, 672 + and a related convention uses VERBOSE_DEBUG to add dev_vdbg() messages to 673 + the ones already enabled by DEBUG. 674 + 675 + Many subsystems have Kconfig debug options to turn on -DDEBUG in the 676 + corresponding Makefile; in other cases specific files #define DEBUG. And 677 + when a debug message should be unconditionally printed, such as if it is 678 + already inside a debug-related #ifdef secton, printk(KERN_DEBUG ...) can be 679 + used. 672 680 673 681 674 682 Chapter 14: Allocating memory
+6
include/linux/printk.h
··· 210 210 #define pr_fmt(fmt) fmt 211 211 #endif 212 212 213 + /* 214 + * These can be used to print at the various log levels. 215 + * All of these will print unconditionally, although note that pr_debug() 216 + * and other debug macros are compiled out unless either DEBUG is defined 217 + * or CONFIG_DYNAMIC_DEBUG is set. 218 + */ 213 219 #define pr_emerg(fmt, ...) \ 214 220 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) 215 221 #define pr_alert(fmt, ...) \