Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何使用printk在内核模式下进行调试_C_Linux_Linux Kernel_Kernel_Printk - Fatal编程技术网

C 如何使用printk在内核模式下进行调试

C 如何使用printk在内核模式下进行调试,c,linux,linux-kernel,kernel,printk,C,Linux,Linux Kernel,Kernel,Printk,我正在尝试向Linuxtask\u struct添加一些内容 在这个区域中,我从用户复制一个字符串,并尝试将其存储在我的结构中 我试图通过添加打印复制字符串的printk来调试代码 这是代码的调试部分: newTODO->TODO_description=(char*)(kmalloc(in_description_size+1,0)); if( newTODO->TODO_description){ kfree(newTODO); retur

我正在尝试向Linux
task\u struct
添加一些内容

在这个区域中,我从用户复制一个字符串,并尝试将其存储在我的结构中

我试图通过添加打印复制字符串的
printk
来调试代码

这是代码的调试部分:

newTODO->TODO_description=(char*)(kmalloc(in_description_size+1,0));
    if( newTODO->TODO_description){
        kfree(newTODO);
        return -1;
    }

    res=copy_from_user(newTODO->TODO_description, in_TODO_description, in_description_size);
        if (res)                                //  error copying from user space, 1 or more char werent copied.
        {
            printk(KERN_ALERT "function: create element failed to copy from user\n");
            return -EFAULT;
        }
    newTODO->TODO_description[in_description_size]='\o';
    printk(KERN_ALERT "the copied string is: %s \n",newTODO->TODO_description);
对我来说必须的印刷品是

printk(KERN_ALERT "the copied string is: %s \n",newTODO->TODO_description);
行吗

要了解printk:


当我从终端运行测试文件时,无论何时调用printk,它都会将输出直接打印到工作终端?

printk函数将在内核消息缓冲区中追加消息,但除非您发出命令,否则该缓冲区的内容不会显示在终端上

正如Ilya Matveychikov所说,您可以使用“dmesg”命令转储内核消息缓冲区

或者使用以下命令获取实时内核消息观察

echo 8>/proc/sys/kernel/printk
tail-f/var/log/kern.log&




cat/proc/kmsg&(Android环境)

使用
dmesg
查看内核日志。
='\o'看起来可疑。你是说
='\0'(或仅
=0;