dynamic debug动态打印- pr_debug

转载地址:    https://blog.csdn.net/u012719256/article/details/55262058

之前介绍过了 printk_once , 只打印一次。

     有些情况下,需要kernel运行时动态打印与否,dynamic debug就派上用场了。

     具体用法可以参考: kernel/Documentationdynamic-debug-howto.txt

     使用步骤:

       //  打印

       echo  -n  "file nand.c  +p" > /sys/kernel/debug/dynamic_debug/control

       // 不打印
       echo  "file nand.c     -p"' > /sys/kernel/debug/dynamic_debug/control

       // 使用例子

       pr_debug("  dynamic debug \n");

       奇怪的是,加参数-c, 本地验证是不起作用的。

       至于为什么往 dynamic_debug/control 写入设置信息,可参考内核接口文件代码:

      

[cpp] view plain copy

  1. static int __init dynamic_debug_init(void)  
  2. {  
  3.     struct dentry *dir, *file;  
  4.     struct _ddebug *iter, *iter_start;  
  5.     const char *modname = NULL;  
  6.     int ret = 0;  
  7.     int n = 0;  
  8.   
  9.     dir = debugfs_create_dir("dynamic_debug", NULL);  
  10.     if (!dir)  
  11.         return -ENOMEM;  
  12.     file = debugfs_create_file("control", 0644, dir, NULL,  
  13.                     &ddebug_proc_fops);  
 
  1. static int __init dynamic_debug_init(void)

  2. {

  3. struct dentry *dir, *file;

  4. struct _ddebug *iter, *iter_start;

  5. const char *modname = NULL;

  6. int ret = 0;

  7. int n = 0;

  8.  
  9. dir = debugfs_create_dir("dynamic_debug", NULL);

  10. if (!dir)

  11. return -ENOMEM;

  12. file = debugfs_create_file("control", 0644, dir, NULL,

  13. &ddebug_proc_fops);


 

记得要编译kernel的时候使能,让dynamic debug编译进去。(menuconfig)

  │ Symbol: DYNAMIC_DEBUG [=y]                                                                                                         │ 
  │ Prompt: Enable dynamic printk() support                                                                                            │ 
  │   Defined at lib/Kconfig.debug:1039                                                                                                │ 
  │   Depends on: PRINTK [=y] && DEBUG_FS [=y]                                                                                         │ 
  │   Location:                                                                                                                        │ 
  │     -> Kernel hacking   

   或者直接修改

   ./config 文件
   CONFIG_DYNAMIC_DEBUG=y

   注意的是其依赖于: Depends on: PRINTK [=y] && DEBUG_FS [=y]    

猜你喜欢

转载自blog.csdn.net/kunkliu/article/details/83988296