Transferred from: http://blog.chinaunix.net/uid-20672559-id-3383042.html
Linux device driver debugging, we see in the kernel that the kernel uses dev_dbg to control the output information, the essence of this function is to call PRINTK (kern_debug) to output printing information. The following two steps are required to open this switch.
1. Open the DEBUG switch: You debug the file must contain, or, the latter contains the former, before the inclusion of this header file, use # define debug to open the debug switch: for example
#include
#include
#include
#include
#define DEBUG 1
#include
In the Linux/device.h file:
#define DEV_PRINTK (level, dev, format, arg ...) \
PRINTK (Level "%s:" format, dev_driver_string (Dev), (dev)->bus_id, # # ARG)
#ifdef DEBUG
#define DEV_DBG (Dev, format, arg ...) \
DEV_PRINTK (kern_debug, Dev, format, # # ARG)
#else
static inline int __attribute__ (format (printf, 2, 3))
dev_dbg (struct device * dev, const char * fmt, ...)
{
return 0;
}
#endif
However, after this is turned on, it is not possible to output information smoothly because PRINTK has a default level of information.
In the Linux/kernel file
#define Kern_emerg "<0>"
#define Kern_alert "<1>"
#define KERN_CRIT "<2>"
#define KERN_ERR "<3>"
#define Kern_warning "<4>"
#define Kern_notice "<5>"
#define KERN_INFO "<6>"
#define KERN_DEBUG "<7>"
You can see that Kern_debug is the lowest level.
2. Modify the file Kernel/printk file
#define DEFAULT_MESSAGE_LOGLEVEL 4
#define MINIMUM_CONSOLE_LOGLEVEL 1
#define Default_console_loglevel 8
Where Default_console_loglevel is the lowest level of output for the terminal CONSOLE, the output will be more severe than this. The value is 7, the debug information can not be output, modified to 8 all have output
Linux Driver Development--open dev_dbg () "Turn"