Appendix A: Debugging
Practical debugging techniques for kernel driver development.
Debugging Strategy
flowchart TB
BUG["Bug/Issue"]
BUG --> Q1{"Can reproduce?"}
Q1 -->|Yes| LOG["Add printk/dev_*"]
Q1 -->|No| TRACE["Enable tracing"]
LOG --> ANALYZE["Analyze output"]
TRACE --> ANALYZE
ANALYZE --> Q2{"Found cause?"}
Q2 -->|Yes| FIX["Fix"]
Q2 -->|No| DEBUG["debugfs/kgdb"]
DEBUG --> FIX
style LOG fill:#7a8f73,stroke:#2e7d32
style TRACE fill:#738f99,stroke:#0277bd
| Tool |
Use For |
Overhead |
printk/dev_* |
Quick debugging, always available |
Low |
| Dynamic debug |
Enable/disable at runtime |
Very low |
| ftrace |
Function flow, latency |
Medium |
| kprobes |
Inspect without recompile |
Medium |
| KGDB |
Interactive debugging |
High |
| kdump/crash |
Post-mortem analysis |
None (captures on crash) |
Chapters
Quick Reference
# View kernel log
dmesg -w
# Filter by driver
dmesg | grep my_driver
# Enable dynamic debug
echo 'module my_driver +p' > /sys/kernel/debug/dynamic_debug/control
# View function trace
echo function > /sys/kernel/debug/tracing/current_tracer
cat /sys/kernel/debug/tracing/trace
Further Reading
Table of contents