转载地址: https://blog.youkuaiyun.com/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
- 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);
-
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]
本文详细介绍了Linux内核中Dynamic Debug特性的使用方法,包括如何动态控制内核打印信息,以及在编译时如何使能该特性。适用于需要在运行时调整内核调试输出的场景。
2900

被折叠的 条评论
为什么被折叠?



