Linux Kernel Debug PRINTK

Source: Internet
Author: User
Tags syslog

Problem Description: The recent two days to debug platform driver, the program is always a little problem, do not get the results they want, suddenly realize the importance of kernel debugging, re-organize the basic usage of PRINTK. the kernel outputs related information through PRINTK (), and the log level must be specified when calling the PRINTK () function.

1. PRINTK Log Level

Several log levels are defined in Include/linux/kernel.h

<span style= "Font-family:microsoft yahei;font-size:12px;" > #defineKERN_EMERG "<0>"/* System crashes */#defineKERN_ALERT "<1>"/* Must be processed urgently */#defineKERN_CRIT "<2>"/* Critical condition, severe hard software error */#defineKERN_ERR        <3> */     * Report Error */#defineKERN_WARNING "<4>"/* warning */#defineKERN_ NOTICE "<5>" * * common but still need to pay attention to */#defineKERN_INFO "<6>"/* information */#defineKERN_DEBUG "<7>"/* Debug Information */</span >
It is also possible to see that the smaller the number, the greater the urgency and severity.


Next, let's look at the Kernel/printk.c file:

/* printk ' s without a loglevel use this: */#define DEFAULT_MESSAGE_LOGLEVEL 4/* Kern_warning *//* Therefore, if you do not specify a log level in PRINTK (), the system will default to level 4 *//* We show everything that is more important than this. */#define MINIMUM_CONSOLE_LOGLEVEL 1/* MINIMUM LOGLEVEL We let people use */#define DEFAULT_CONSOLE_LOGLEVEL 7/* Anythin G more serious than kern_debug */declare_wait_queue_head (log_wait); int console_printk[4] = {default_console_loglevel,/ * Console_loglevel */default_message_loglevel,/* default_message_loglevel */minimum_console_loglevel,/* minimum_ Console_loglevel */default_console_loglevel,/* Default_console_loglevel */};/* These 4 groups of numbers can be changed in/PROC/SYS/KERNEL/PRINTK * /

The/PROC/SYS/KERNEL/PRINTK displays 4 values (which can be modified by echo), respectively, indicating
Current console log level;
The default message log level for the log level is not explicitly specified;
Minimum (maximum) allows the setting of the console log level;
The default log level at boot time;
When the level specified in PRINTK () is less than the current console log level (as previously said, the smaller the value, the higher the severity), the PRINTK information (with a \ n character) is displayed on the console. However, the current console log level is always viewable through DMESG regardless of the value.

There are two main types of logging tools for the system: Syslog and Klog.
Syslog is used to perform system logging activities, and the system process is displayed as SYSLOGD. The configuration file is/etc/syslog.conf. If you remove the # number before the kern.* line in the configuration file, the PRINTK information is also output to the console. Its daemon is syslogd. The SYSLOGD process reads data from a set of log sources, such as/dev/log and/dev/klog, and processes these log messages as described in/etc/syslog.conf.

2. PRINTK output Format character

If the variable type is, use the format specifier of Prink:
int%d or%x (Note:%d is decimal,%x is hexadecimal)
unsigned int%u or%x
long%ld or%LX
unsigned long%lu or%LX
Long Long%lld or%LLX
unsigned long long%llu or%LLX
  size_t%zu or%zx
ssize_t%zd or%zx
The original pointer value must be output with%p.  
u64, i.e. (unsigned long log n), must be output with%llu or%LLX, such as:
PRINTK ("%llu", (unsigned long long) u64_var);
S64, i.e. (long long), must be output with%LLD or%LLX, such as:
PRINTK ("%lld", (Long Long) s64_var);


Linux Kernel Debug PRINTK

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.