I have used printk as a debugging technique many times to debug linux kernel and kernel modules. I will cover some basics of printk debugging technique in this post.
Steps to use printk debugging technique
- Step1: Modify the source code to introduce the necessary printks in the part of code that requires debugging.
- Step2: Recompile the kernel or kernel module.
- Step3: Load the recompiled binary to the test system.
- Step4: Look for the newly introduced printk messages. These messages may appear on console/dmesg depending on your configuration. To understand printk configuration controls, please refer my other blog post - Linux log messaging architeture.
Pros & Cons
- Pros:
- Relatively a faster/easier debugging technique because we can skip integration costs necessary for tools such as kdb/kgdb
- Relatively light weight?
- Cons:
- Requires re-compilation of source code
- printk can introduce performance delays & hence making it difficult to debug time sensitive bugs
- Doesn't allow to inspect the system interactively or without additional source code customization the way kdb/kgdb allows
- Can't have advance debugging capabilities such as watchpoints
No comments:
Post a Comment