Linux Driver Development--open dev_dbg () "Turn"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.