0bd8f0393d110838702312162020428a0864c354
[cascardo/kernel/slides/.git] / 05debug / debug
1 %Debugging
2 %Thadeu Cascardo
3
4 # Introduction
5
6 There are many debug infrastructure and support in Linux. We are going to look
7 at some of them, including:
8
9 * printk
10 * procfs
11 * debugfs
12
13 We are also going to point out at some documentation for other debug support.
14
15 # printk
16
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
19 by klogd.
20
21 The *dmesg* program may be used to read these log messages. It's usually asked
22 for in bug reports.
23
24 # printk log levels
25
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.
28
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
31 loglevel.
32
33 # Log levels
34
35 The following macros are used for log levels in printk:
36
37 * KERN\\_EMERG
38 * KERN\\_ALERT
39 * KERN\\_CRIT
40 * KERN\\_ERR
41 * KERN\\_WARNING
42 * KERN\\_NOTICE
43 * KERN\\_INFO
44 * KERN\\_DEBUG
45
46 # Rate limiting
47
48 You may limit the rate of the messages printed.
49
50 * printk\\_once
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
56
57 # printk macros
58
59 * pr\\_emerg
60 * pr\\_alert
61 * pr\\_crit
62 * pr\\_err
63 * pr\\_warning
64 * pr\\_notice
65 * pr\\_info
66 * pr\\_debug - only if DEBUG macro defined or with dynamic\\_debug
67 * pr\\_devel - only if DEBUG macro defined
68
69 # Printing from device drivers
70
71 * include linux/device.h
72 * dev\\_printk(level, device, fmt, ...)
73 * dev\\_*
74 * dev\\_warn and not dev\\_warning
75 * dev\\_dbg - only if DEBUG macro defined or with dynamic\\_debug
76
77 # Defining the DEBUG macro
78
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.
81
82 * drivers/usb/core/Kconfig
83 * drivers/usb/core/Makefile
84
85 # Dynamic debug
86
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