1. print

printk(): never

pr_debug(): always good

dev_dbg(): prefered when you have a struct device object

netdev_dbg(): prefered when you have a struct netdevice object

[something]_dbg(): prefered when you have a that something object

see the implementation in source code:

/* If you are writing a driver, please use dev_dbg instead */
#if defined(CONFIG_DYNAMIC_DEBUG)
/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
#define pr_debug(fmt, ...) \
dynamic_pr_debug(fmt, ##__VA_ARGS__)
#elif defined(DEBUG)
#define pr_debug(fmt, ...) \
printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#else
#define pr_debug(fmt, ...) \
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#endif

It shows the CONFIG_DYNAMIC_DEBUG/DEBUG option can be used to enable or disable the print.

dynamic debug:

Benefits:
Almost no overhead when log code is not enabled.
Turn on/off debug log at runtime.
No need to recompile the kernel.

Control interface: uboot boot argus, debugfs

# mount -t debugfs none /sys/kernel/debug/
# cd /sys/kernel/debug/dynamic_debug/
# echo “file xxx.c +p” > control
# echo “file svcsock.c line 1603 +p” > control
# echo “file drivers/usb/core/* +p” > control
# echo “file xxx.c -p” > control

retrive the log information

dmesg

dmesg -C clear

dmesg -c show and then clear.

tail /var/log/syslog-f dynamic to show the log information in case the syslogd is running.

The debug log default size is 64K, you can configure it by menuconfig, note that the size is calculted by 2^n.

dmesg -n 5
Set console logging filter to KERN_WARNING or more severe.
dmesg -l warn
Only print the logs of KERN_WARNING in the kernel ring buffer.

Another option is dynamic debug by configuring the debugfs

enable it in kernel : CONFIG_DYNAMIC_DEBUG=y menuconfig

using pr_debug(), dev_dbg() ... in driver source code

echo “<matches> <ops><flags>” > <debugfs>/dynamic_debug/control

e.g.

echo “file xxx.c+p” > <debugfs>/dynamic_debug/control
 

2. using file system proc/ memory large file or sequence file

3. using ioctrl to get/set specific data

Below shall enable the kernel debug. CONFIG_DEBUG_INFO =y

4. gdb list command to idenfiy the line of oops

e.g.

(gdb ) list *(cppi41_dma_probe+0x2c4)
 

5. addr2line command to identify the line of oops

e.g.  addr2line -fe vmlinux ce000678

6. objdump -dS .o

-d: display assembler conetents of executable sections

-S intermix source code with disassembly

最新文章

  1. Git和Github简单教程
  2. Ubuntu 14.04 安装pdf阅读器
  3. User mode and kernel mode
  4. HTML5 结构性标签 行内语义性标签
  5. Swift-打开其它Storyboard中的自定义模态窗口
  6. Qt label加边框
  7. cpu和内存的关系
  8. python入门 2014-3-21
  9. Lotus防病毒与数据备份案例
  10. OpenGL9-(FreeImage)加载图片-作为纹理
  11. POJ1125 Stockbroker Grapevine(最短路)
  12. mongodb的地理空间索引常见的问题
  13. linux kernel中timer的使用
  14. QT学习 之 事件与事件过滤器(分为五个层次)
  15. ORM-Dapper学习&lt;二&gt;
  16. css-display
  17. oracle 12c 安装指南(各种问题总结)
  18. [Luogu P1119]灾后重建
  19. C语言中使用bool
  20. 后台List里的数据传到前台表格和下拉列表为什么不显示

热门文章

  1. OLAP多维数据库备份
  2. MATLAB绘图功能(1) 二维高层绘图操作
  3. Flutter采坑之路 Run Configuration error:broken configuration due to unavailable
  4. 浅谈awk命令
  5. 『Python CoolBook』数据结构和算法_多变量赋值&amp;“*”的两种用法
  6. 【Git】【1】简单介绍
  7. canvas实现点连线动画
  8. PythonWEB框架之Tornado
  9. maven--插件篇(assembly插件)
  10. Docker(一) 安装Docker