dynamic debug动态打印

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

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

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

     使用步骤:

       //  打印

       echo  'file nand.c line 4210 +p' > /sys/kernel/debug/dynamic_debug/control

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

       // 使用例子

       pr_debug("  dynamic debug \n");

 

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

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

      

static int __init dynamic_debug_init(void)
{
	struct dentry *dir, *file;
	struct _ddebug *iter, *iter_start;
	const char *modname = NULL;
	int ret = 0;
	int n = 0;

	dir = debugfs_create_dir("dynamic_debug", NULL);
	if (!dir)
		return -ENOMEM;
	file = debugfs_create_file("control", 0644, dir, NULL,
					&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]      

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值