Linux内核驱动模块的调试技术总结

论坛 期权论坛     
选择匿名的用户   2021-6-2 18:29   249   0
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">这些天来弄了一个简单的驱动模块,后发现系统只要一卸载模块系统就会死掉。到底是那里出了错?</span>
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">如果你只是通过printk来调试, 而没有其他的方法去检测错误的。</span>
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">也是这个原因促使我写驱动模块调试技术相关技术。要学好一个编程语言工具首先调试技术也一定同步。</span>
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">(如果linux 也能做出一个类似windows 下的 Windbg 或 </span>
<span size="-1" style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">Soft-ICE</span>
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px"> 那就不必那么麻烦了)</span>
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">这篇文章不是一气呵成的,只是我在学习内核调试的一个笔记。</span>
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">调试技术有以下几种:</span>
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">  1.用打印调试 </span>
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">  2.文件保存调试信息</span>
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">  3.truss、strace和ltrace命令输出信息来调试</span>
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">  4.调试器来调试</span>
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">对于第一种 “用打印调试 ”</span>
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">利用函数或命令把相应的信息输出到console或文件内</span>
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">这些函数有 printk , STOCLINUX 等等</span>
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">prink 的一般用法是定义成一个公用的宏</span>
<br style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px">
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px; color:rgb(0,0,255)"></span>
<span style="font-family:Tahoma,Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px"></span>
<div style="border:1px solid rgb(204,204,204); padding:4px 5px 4px 4px; background-color:rgb(238,238,238); width:1007.433349609375px">
<span style="color:rgb(0,128,0)"></span>
<br>
<span style="color:rgb(0,0,255)">#undef</span> PDEBUG           
<span style="color:#008000">  /* undef it, just in case */</span>
<br>
<span style="color:#0000ff">#ifdef</span> SCULL_DEBUG
<br>
<span style="color:#0000ff">   #ifdef</span> __KERNEL__
<br>      
<span style="color:rgb(0,128,0)">/*</span>
<span style="color:rgb(0,128,0)"> This one if debugging is on, and kernel space </span>
<span style="color:rgb(0,128,0)">*/</span>
<br>   
<span style="color:#0000ff">     #define</span> PDEBUG(fmt, args
<img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-e2a6613082b46951a97093f596d56b92.gif">) printk( KERN_DEBUG &#34;scull: &#34; fmt, ## args)
<br>
<span style="color:#0000ff">   #</span>
<span style="color:#0000ff">else</span>
<br>      
<span style="color:rgb(0,128,0)">/*</span>
<span style="color:rgb(0,128,0)"> This one for user space </span>
<span style="color:rgb(0,128,0)">*/</span
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP