Search code examples
linuxlinux-kerneldebugging

Why is pr_debug of the Linux kernel not giving any output?


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\n", temp->name);

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

    /* 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 found\012"
/home/pauldc/Programming/Kernel/id/id.c:65 [id]id_init =_ "id 3 = %s\012"

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?


Solution

  • 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