内核无动态调试信息输出问题:模块dynamic debug配置疑问
Let's break down why your command isn't working and fix it step by step:
1. The Critical Flaw in Your Command
Your current command uses > (overwrite) inside the xargs loop, which means only the last module's debug rule gets applied. Each iteration of echo 'module {} +p' > /sys/kernel/debug/dynamic_debug/control overwrites the previous rule, so all earlier modules' debug settings are discarded entirely.
Fixed Command to Enable All Modules' Dynamic Debug
Instead, generate all rules first and write them to the control interface in one go. Here's a more reliable version:
# Extract unique module names, generate rules, and apply all at once awk -F'[][]' '{print "module " $2 " +p"}' /sys/kernel/debug/dynamic_debug/control | sort -u > /sys/kernel/debug/dynamic_debug/control
awk -F'[][]'splits each line by[and]to grab the module name directly (cleaner than nested cuts)sort -uremoves duplicate module entries (since one module can have multiple debug lines)- Writing all rules in a single operation ensures every module's debug flag is set properly
2. Verify Debug Configuration is Applied
Check if the +p flag is present for your target module in the control file:
grep "your_module_name" /sys/kernel/debug/dynamic_debug/control
You should see lines ending with +p (the p indicates print is enabled for those debug statements).
3. Ensure Your Module Uses Dynamic Debug Macros
Dynamic debug only works with specific macros, not regular printk(). Make sure your module uses:
pr_debug()for general debug messagesdev_dbg()for device-specific debug messagesnetdev_dbg()for network device debug messages
If you're using printk(KERN_DEBUG ...), those messages will log regardless of dynamic debug settings (they just depend on the kernel log level).
4. Adjust Kernel Log Level
Dynamic debug messages are logged at the DEBUG level (kernel log level 7). If your system is filtering out low-priority logs, you won't see them.
- Temporarily set the log level to show all messages:
dmesg -n 8 - Monitor logs in real-time to catch the debug output as it happens:
dmesg -w # Or use journalctl on systemd-based systems journalctl -k -f
5. Confirm Module and Kernel Configuration
- Ensure your kernel was compiled with
CONFIG_DYNAMIC_DEBUG=y(verify withzcat /proc/config.gz | grep CONFIG_DYNAMIC_DEBUG) - Check that your module was built with debug support: it should have been compiled with
-DDEBUG(review your module's Makefile or build flags) - Confirm the module is actually loaded:
lsmod | grep <your_module_name>
6. Test with a Single Module First
To isolate the issue, try enabling debug for just one module manually:
echo 'module my_target_module +p' > /sys/kernel/debug/dynamic_debug/control
Then trigger the module's code path and check logs. If this works, the problem was with your batch command; if not, focus on verifying the module's debug macro usage or kernel configuration.
内容的提问来源于stack exchange,提问作者Masoud

