[英]How to debug in kernel mode using printk
我想在Linux task_struct
添加一些東西。
在這個區域,我從用戶復制一個字符串,並嘗試將其存儲在我的結構中。
我嘗試通過添加printk
來調試我的代碼, 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環境)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.