6 There are many debug infrastructure and support in Linux. We are going to look
7 at some of them, including:
13 We are also going to point out at some documentation for other debug support.
17 printk adds messages to the kernel log system. It may be read by the syslog
18 syscall (klogctl in glibc). It's also present in /proc/kmsg and is usually read
21 The *dmesg* program may be used to read these log messages. It's usually asked
26 dmesg may configure which levels are output to console. Those log levels are
27 also used by the syslog daemon to filter what messages go where.
29 /proc/sys/kernel/printk shows the current console loglevel, the default level
30 (for messages that miss the level), the minimum level and the boot time console
35 The following macros are used for log levels in printk:
48 You may limit the rate of the messages printed.
51 * You may test for printk\\_ratelimit
52 - limits to *burst* messages in *interval* seconds
53 * Default burst is 10 times in 5 seconds
54 * /proc/sys/kernel/printk\\_ratelimit*
55 * printk\\_ratelimited uses only the default values
66 * pr\\_debug - only if DEBUG macro defined or with dynamic\\_debug
67 * pr\\_devel - only if DEBUG macro defined
69 # Printing from device drivers
71 * include linux/device.h
72 * dev\\_printk(level, device, fmt, ...)
74 * dev\\_warn and not dev\\_warning
75 * dev\\_dbg - only if DEBUG macro defined or with dynamic\\_debug
77 # Defining the DEBUG macro
79 Let's take a look at an example of defining the DEBUG macro for some code and
80 allowing the user to configure it.
82 * drivers/usb/core/Kconfig
83 * drivers/usb/core/Makefile
87 * Allow developers or users to filter debug messages by subsystem, file and line
88 * CONFIG\\_DYNAMIC\\_DEBUG should be defined
89 * Depends on DEBUG\\_FS
90 * Documented in the Kconfig help at lib/Kconfig.debug
91 * Also documented at Documentation/dynamic-debug-howto.txt
95 The proc filesystem has a use of its own, allowing user space to get
96 information about processes and other system configuration as well as to
97 change those configuration items.
99 However, it may be used for debugging too. In fact, developers usually
100 request information from /proc/, when trying to find a solution for a
103 # Creating a proc file
105 * include linux/proc\\_fs.h
106 * struct proc\\_dir\\_entry
109 * create\\_proc\\_entry(name, mode, parent) is racy
110 * Use NULL parent to create a file in the proc root
111 * proc\\_create(name, mode, parent, fops) is not racy
112 * proc\\_create\\_data(name, mode, parent, fops, data)
114 # Removing a proc file and creating directories
116 * remove\\_proc\\_entry(name, parent)
117 * proc\\_mkdir(name, parent)
118 * proc\\_mkdir\\_mode(name, mode, parent)