为什么 Linux 内核的 pr_debug 没有任何输出? [英] Why is pr_debug of the Linux kernel not giving any output?

查看:22
本文介绍了为什么 Linux 内核的 pr_debug 没有任何输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可加载的内核模块,它的初始化如下

static int __init id_init(void){结构标识 *temp;/* 一些与问题无关的代码 */temp = identity_find(3);pr_debug("id 3 = %s
", temp->name);temp = identity_find(42);如果(温度 == NULL)pr_debug("id 42 未找到
");/* 一些与问题无关的代码 */返回0;}

此外,我在我使用的内核版本上启用了动态调试 - 即 CONFIG_DYNAMIC_DEBUG=y.

在模块的 Makefile 中,我添加了一行 CFLAGS_[id].o := -DDEBUG 其中 id.c 是文件名.>

现在我在执行这个模块的 insmod 后检查了 /sys/kernel/debug/dynamic_debug/control,在其中我发现了以下几行

/home/pauldc/Programming/Kernel/id/id.c:69 [id]id_init =_ "id 42 not found12"/home/pauldc/Programming/Kernel/id/id.c:65 [id]id_init =_ "id 3 = %s12"

即使做了这一切,令我失望的是我在 dmesg 的输出中找不到上述两个 pr_debug 语句.那么我错过了什么或做错了什么?

解决方案

在 Makefile 中添加以下内容,假设 filename.c 是模块源文件.

CFLAGS_filename.o := -DDEBUG

不是

CFLAGS_[文件名].o := -DDEBUG

参考 https://www.kernel.org/doc/local/pr_debug.txt

I have a loadable kernel module and its init is as given below

static int __init id_init(void)
{
    struct identity *temp;

    /* some code which is not relevant to the question */

    temp = identity_find(3);
    pr_debug("id 3 = %s
", temp->name);

    temp = identity_find(42);
    if (temp == NULL)
        pr_debug("id 42 not found
");

    /* some code which is not relevant to the question */

    return 0;
}

Also I have enabled dynamic debugging enabled on the kernel version I am using - i.e CONFIG_DYNAMIC_DEBUG=y.

And in the Makefile of the module I have added a line CFLAGS_[id].o := -DDEBUG where id.c is the file name.

Now I checked in the /sys/kernel/debug/dynamic_debug/control after doing insmod of this module, in which I found the below lines

/home/pauldc/Programming/Kernel/id/id.c:69 [id]id_init =_ "id 42 not found12"
/home/pauldc/Programming/Kernel/id/id.c:65 [id]id_init =_ "id 3 = %s12"

Even after doing all this, to my disappointment I could not find the above two pr_debug statements in the output of dmesg. So what am I missing or doing wrong?

解决方案

Add following to Makefile, assuming filename.c is the module source file.

CFLAGS_filename.o := -DDEBUG

not

CFLAGS_[filename].o := -DDEBUG

Refer https://www.kernel.org/doc/local/pr_debug.txt

这篇关于为什么 Linux 内核的 pr_debug 没有任何输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆