⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linux设备驱动程序学习(2)-调试技术 - linux设备驱动程序 - tekkaman ninja.htm

📁 Linux设备驱动程序学习(2)-调试技术 - Linux设备驱动程序.rar
💻 HTM
📖 第 1 页 / 共 5 页
字号:
                              <DIV style="TEXT-ALIGN: left"><FONT size=4><SPAN 
                              style="COLOR: rgb(0,1,255)">一、内核中的调试支持</SPAN></FONT><BR></DIV>在前面已经建议过:学习编写驱动程序要构建安装自己的内核(标准主线内核)。最重要的原因之一是:内核开发者已经建立了多项用于调试的功能。但是由于这些功能会造成额外的输出,并导致能下降,因此发行版厂商通常会禁止发行版内核中的调试功能。<BR>为了实现内核调试,我在内核配置上增加了几项:<BR>&nbsp; 
                              Kernel hacking&nbsp; 
                              ---&gt;&nbsp;&nbsp;&nbsp;&nbsp; 
                              <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [*] 
                              Magic SysRq key<BR>&nbsp;&nbsp;&nbsp; 
                              &nbsp;&nbsp;&nbsp; [*] Kernel 
                              debugging<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
                              [*]&nbsp;&nbsp; Debug slab memory 
                              allocations&nbsp; <BR>&nbsp;&nbsp;&nbsp; 
                              &nbsp;&nbsp;&nbsp; [*]&nbsp;&nbsp; Spinlock and 
                              rw-lock debugging: basic checks 
                              <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
                              [*]&nbsp;&nbsp; Spinlock debugging: 
                              sleep-inside-spinlock 
                              checking<BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 
                              [*]&nbsp;&nbsp; Compile the kernel with debug 
                              info&nbsp; <BR>&nbsp;&nbsp;&nbsp; 
                              &nbsp;&nbsp;&nbsp; [*] Magic SysRq key <BR>Device 
                              Drivers&nbsp; ---&gt;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 
                              &nbsp;&nbsp;&nbsp; Generic Driver Options&nbsp; 
                              ---&gt;<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 
                              &nbsp;&nbsp; [*] Driver Core verbose debug 
                              messages <BR>General setup&nbsp; 
                              ---&gt;<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; [*] 
                              Configure standard kernel features (for small 
                              systems)&nbsp; ---&gt;<BR>&nbsp;&nbsp;&nbsp; 
                              &nbsp;&nbsp; &nbsp;&nbsp; [*]&nbsp;&nbsp; Load all 
                              symbols for 
                              debugging/ksymoops<BR>书上介绍的还有其他配置,有的我不需要,或是s3c2440不支持,菜单里看不见。<BR>
                              <HR style="WIDTH: 100%; HEIGHT: 2px">
                              </DIV></DIV><FONT size=4><SPAN 
                              style="COLOR: rgb(0,1,255)">二、通过打印调试<BR>(1)printk<BR><FONT 
                              size=3>&nbsp;</FONT><FONT size=3><SPAN 
                              style="COLOR: rgb(0,1,2)">首先,printk有8个loglevel,定义在<FONT 
                              color=#0000ff>&lt;linux/kernel.h&gt;</FONT>中:</SPAN></FONT><BR></SPAN></FONT>
                              <TABLE style="BORDER-COLLAPSE: collapse" 
                              borderColor=#999999 cellSpacing=0 cellPadding=0 
                              width="95%" bgColor=#f1f1f1 border=1>
                                <TBODY>
                                <TR>
                                <TD>
                                <P 
                                style="MARGIN: 5px; LINE-HEIGHT: 150%"><CODE><SPAN 
                                style="COLOR: rgb(0,0,0)"><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">define</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;KERN_EMERG&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,0,255)">"&lt;0&gt;"</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,153,0)">/* system is 
                                unusable&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                                */</SPAN><BR><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">define</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;KERN_ALERT&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,0,255)">"&lt;1&gt;"</SPAN>&nbsp;&nbsp; 
                                <SPAN style="COLOR: rgb(255,153,0)">/* action 
                                must be taken immediately*/</SPAN><BR><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">define</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;KERN_CRIT&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,0,255)">"&lt;2&gt;"</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,153,0)">/* critical 
                                conditions&nbsp;&nbsp;&nbsp; */</SPAN><BR><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">define</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;KERN_ERR&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,0,255)">"&lt;3&gt;"</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,153,0)">/* error 
                                conditions&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</SPAN><BR><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">define</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;KERN_WARNING&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,0,255)">"&lt;4&gt;"</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,153,0)">/* warning 
                                conditions&nbsp;&nbsp; */</SPAN><BR><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">define</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;KERN_NOTICE&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,0,255)">"&lt;5&gt;"</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,153,0)">/* normal but 
                                significant condition */</SPAN><BR><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">define</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;KERN_INFO&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,0,255)">"&lt;6&gt;"</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,153,0)">/* 
                                informational&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</SPAN><BR><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">define</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;KERN_DEBUG&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,0,255)">"&lt;7&gt;"</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
                                style="COLOR: rgb(255,153,0)">/* debug-level 
                                messages&nbsp;&nbsp; 
                                */</SPAN></SPAN></CODE></P></TD></TR></TBODY></TABLE><BR><FONT 
                              size=3>未指定优先级的默认级别定义在/kernel/printk.c中:</FONT><BR>
                              <TABLE style="BORDER-COLLAPSE: collapse" 
                              borderColor=#999999 cellSpacing=0 cellPadding=0 
                              width="95%" bgColor=#f1f1f1 border=1>
                                <TBODY>
                                <TR>
                                <TD>
                                <P 
                                style="MARGIN: 5px; LINE-HEIGHT: 150%"><CODE><SPAN 
                                style="COLOR: rgb(0,0,0)"><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">define</SPAN> 
                                DEFAULT_MESSAGE_LOGLEVEL 4 <SPAN 
                                style="COLOR: rgb(255,153,0)">/* KERN_WARNING 
                                */</SPAN></SPAN></CODE></P></TD></TR></TBODY></TABLE><FONT 
                              size=3><BR>当优先级的值小于console_loglevel这个整数变量的值,信息才能显示出来。而console_loglevel的初始值DEFAULT_CONSOLE_LOGLEVEL也定义在/kernel/printk.c中:</FONT> 

                              <TABLE style="BORDER-COLLAPSE: collapse" 
                              borderColor=#999999 cellSpacing=0 cellPadding=0 
                              width="95%" bgColor=#f1f1f1 border=1>
                                <TBODY>
                                <TR>
                                <TD>
                                <P 
                                style="MARGIN: 5px; LINE-HEIGHT: 150%"><CODE><SPAN 
                                style="COLOR: rgb(0,0,0)"><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">define</SPAN> 
                                DEFAULT_CONSOLE_LOGLEVEL 7 <SPAN 
                                style="COLOR: rgb(255,153,0)">/* anything MORE 
                                serious than KERN_DEBUG 
                                */</SPAN><BR></SPAN></CODE></P></TD></TR></TBODY></TABLE>
                              <HR id=null>
                              <FONT size=3><BR>而在运行是改变console_loglevel的程序(<SPAN 
                              style="FONT-WEIGHT: normal; COLOR: rgb(0,1,2)"></SPAN><SPAN 
                              style="COLOR: rgb(0,1,255)">《Linux设备驱动程序(第3版)》提供</SPAN><SPAN 
                              style="FONT-WEIGHT: normal; COLOR: rgb(0,1,2)"></SPAN>)如下:</FONT> 

                              <TABLE style="BORDER-COLLAPSE: collapse" 
                              borderColor=#999999 cellSpacing=0 cellPadding=0 
                              width="95%" bgColor=#f1f1f1 border=1>
                                <TBODY>
                                <TR>
                                <TD>
                                <P 
                                style="MARGIN: 5px; LINE-HEIGHT: 150%"><CODE><SPAN 
                                style="COLOR: rgb(0,0,0)"><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">include</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN>stdio<SPAN 
                                style="COLOR: rgb(0,0,204)">.</SPAN>h<SPAN 
                                style="COLOR: rgb(0,0,204)">&gt;</SPAN><BR><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">include</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN>stdlib<SPAN 
                                style="COLOR: rgb(0,0,204)">.</SPAN>h<SPAN 
                                style="COLOR: rgb(0,0,204)">&gt;</SPAN><BR><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">include</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">string</SPAN><SPAN 
                                style="COLOR: rgb(0,0,204)">.</SPAN>h<SPAN 
                                style="COLOR: rgb(0,0,204)">&gt;</SPAN><BR><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">include</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">errno</SPAN><SPAN 
                                style="COLOR: rgb(0,0,204)">.</SPAN>h<SPAN 
                                style="COLOR: rgb(0,0,204)">&gt;</SPAN><BR><SPAN 
                                style="COLOR: rgb(255,153,0)"></SPAN><SPAN 
                                style="COLOR: rgb(255,153,0)"></SPAN><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">define</SPAN> 
                                __LIBRARY__ <SPAN 
                                style="COLOR: rgb(255,153,0)">/* _syscall3 and 
                                friends are only available through this 
                                */</SPAN><BR><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">include</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN>linux<SPAN 
                                style="COLOR: rgb(0,0,204)">/</SPAN>unistd<SPAN 
                                style="COLOR: rgb(0,0,204)">.</SPAN>h<SPAN 
                                style="COLOR: rgb(0,0,204)">&gt;</SPAN><BR><SPAN 
                                style="COLOR: rgb(255,153,0)">/* define the 
                                system call, to override the library function 
                                */</SPAN><BR>_syscall3<SPAN 
                                style="COLOR: rgb(0,0,204)">(</SPAN><SPAN 
                                style="COLOR: rgb(0,0,255)">int</SPAN><SPAN 
                                style="COLOR: rgb(0,0,204)">,</SPAN> syslog<SPAN 
                                style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,255)">int</SPAN><SPAN 
                                style="COLOR: rgb(0,0,204)">,</SPAN> type<SPAN 
                                style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,255)">char</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">*</SPAN><SPAN 
                                style="COLOR: rgb(0,0,204)">,</SPAN> bufp<SPAN 
                                style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,255)">int</SPAN><SPAN 
                                style="COLOR: rgb(0,0,204)">,</SPAN> len<SPAN 
                                style="COLOR: rgb(0,0,204)">)</SPAN><SPAN 
                                style="COLOR: rgb(0,0,204)">;</SPAN><BR><BR><SPAN 
                                style="COLOR: rgb(0,0,255)">int</SPAN> main<SPAN 
                                style="COLOR: rgb(0,0,204)">(</SPAN><SPAN 
                                style="COLOR: rgb(0,0,255)">int</SPAN> argc<SPAN 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -