Start dev_dbg in Linux

Source: Internet
Author: User

[Transferred from: http://hi.baidu.com/dreammerge/item/1fe7e04db5cd8fea1e19bca0]

For Linux Device Driver debugging, we can see in the kernel that the kernel uses dev_dbg to control output information. The essence of this function is to call printk (kern_debug) to output print information. To enable this switch, follow these two steps:

1. Turn on the debug switch.

The file you debug must include <Linux/device. h> or <Linux/paltforam_device.h>. The latter includes the former. Before including this header file, use # define debug 1 to turn on the debugging switch.

For example:

#include <linux/kernel.h>#include <linux/init.h>#include <linux/clk.h>#include <linux/module.h>#define DEBUG    1#include <linux/platform_device.h> 

In the Linux/device. h file:

#define dev_printk(level, dev, format, arg...)    \    printk(level "%s %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)#elsestatic inline int __attribute__ ((format (printf, 2, 3)))dev_dbg(struct device * dev, const char * fmt, ...){    return 0;}#endif 

However, after this function is enabled, the output information cannot be smoothly obtained because printk has a default information level.

Linux/kernel. h file

#define    KERN_EMERG    "<0>"    /* system is unusable            */#define    KERN_ALERT    "<1>"    /* action must be taken immediately    */#define    KERN_CRIT    "<2>"    /* critical conditions            */#define    KERN_ERR    "<3>"    /* error conditions            */#define    KERN_WARNING    "<4>"    /* warning conditions            */#define    KERN_NOTICE    "<5>"    /* normal but significant condition    */#define    KERN_INFO    "<6>"    /* informational            */#define    KERN_DEBUG    "<7>"    /* debug-level messages            */ 

We can see that kern_debug is the lowest level.

2. Modify the file kernel/printk. h.

/* printk's without a loglevel use this.. */#define DEFAULT_MESSAGE_LOGLEVEL 4 /* KERN_WARNING *//* We show everything that is MORE important than this.. */#define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */#define DEFAULT_CONSOLE_LOGLEVEL 8 /* anything MORE serious than KERN_DEBUG */

Among them, default_console_loglevel is the lowest level of the terminal console output, which is more serious than this. If the original value is 7, debugging information cannot be output. If it is changed to 8, all debugging information is output.

The key issue may be that debug needs to be defined before the header file !!!

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.