我正在尝试向Linux的task_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,它都将直接输出到当前的终端,是这样吗?
dmesg
命令查看内核日志。 - Ilya Matveychikov='\o';
看起来很可疑。你是不是想说='\0';
(或者只是= 0;
)? - nos