Debugging with printk explained.
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 16 May 2010 19:49:53 +0000 (16:49 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 16 May 2010 19:49:53 +0000 (16:49 -0300)
05debug/debug [new file with mode: 0644]

diff --git a/05debug/debug b/05debug/debug
new file mode 100644 (file)
index 0000000..0bd8f03
--- /dev/null
@@ -0,0 +1,91 @@
+%Debugging
+%Thadeu Cascardo
+
+# Introduction
+
+There are many debug infrastructure and support in Linux. We are going to look
+at some of them, including:
+
+* printk
+* procfs
+* debugfs
+
+We are also going to point out at some documentation for other debug support.
+
+# printk
+
+printk adds messages to the kernel log system. It may be read by the syslog
+syscall (klogctl in glibc). It's also present in /proc/kmsg and is usually read
+by klogd.
+
+The *dmesg* program may be used to read these log messages. It's usually asked
+for in bug reports.
+
+# printk log levels
+
+dmesg may configure which levels are output to console. Those log levels are
+also used by the syslog daemon to filter what messages go where.
+
+/proc/sys/kernel/printk shows the current console loglevel, the default level
+(for messages that miss the level), the minimum level and the boot time console
+loglevel.
+
+# Log levels
+
+The following macros are used for log levels in printk:
+
+* KERN\\_EMERG
+* KERN\\_ALERT
+* KERN\\_CRIT
+* KERN\\_ERR
+* KERN\\_WARNING
+* KERN\\_NOTICE
+* KERN\\_INFO
+* KERN\\_DEBUG
+
+# Rate limiting
+
+You may limit the rate of the messages printed.
+
+* printk\\_once
+* You may test for printk\\_ratelimit
+       - limits to *burst* messages in *interval* seconds
+* Default burst is 10 times in 5 seconds
+* /proc/sys/kernel/printk\\_ratelimit*
+* printk\\_ratelimited uses only the default values
+
+# printk macros
+
+* pr\\_emerg
+* pr\\_alert
+* pr\\_crit
+* pr\\_err
+* pr\\_warning
+* pr\\_notice
+* pr\\_info
+* pr\\_debug - only if DEBUG macro defined or with dynamic\\_debug
+* pr\\_devel - only if DEBUG macro defined
+
+# Printing from device drivers
+
+* include linux/device.h
+* dev\\_printk(level, device, fmt, ...)
+* dev\\_*
+* dev\\_warn and not dev\\_warning
+* dev\\_dbg - only if DEBUG macro defined or with dynamic\\_debug
+
+# Defining the DEBUG macro
+
+Let's take a look at an example of defining the DEBUG macro for some code and
+allowing the user to configure it.
+
+* drivers/usb/core/Kconfig
+* drivers/usb/core/Makefile
+
+# Dynamic debug
+
+* Allow developers or users to filter debug messages by subsystem, file and line
+* CONFIG\\_DYNAMIC\\_DEBUG should be defined
+* Depends on DEBUG\\_FS
+* Documented in the Kconfig help at lib/Kconfig.debug
+* Also documented at Documentation/dynamic-debug-howto.txt