




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、debuggingbyprintingProbably the simplest way to get some debug informationfrom your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.The k in printk is used to specifically remind kernel developers that the enviro
2、nment is different.Contents hide1 Usage2 Log Levels3 Rate limiting and one time messages4 Printk from userspace5 Internals / Changing the size of the printk buffer6 Pros and Cons7 Debugging early boot problems7.1 Accessing the printk buffer after a silent hang on boot7.1.1 Redboot example on a Frees
3、cale ADS board7.1.2 U-boot example on an OMAP OSK board7.1.3 Grub7.2 Using CONFIG_DEBUG_LL and printascii() (ARM only)8 NetConsole8.1 Netconsole resources9 Misc9.1 Dmesg / Clearing the buffer 9.2 Printk Timestamps9.3 Printing buffers as hex9.4 Dynamic Debugging10 Disabling printk messages at compile
4、 time11 References and external linksUsage printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding: printk("My Debugger is Printkn");This wasn't that d
5、ifficult, was it?Usually you would print out some more interesting information like printk("Var1 %d var2 %dn", var1, var2);just like in userspace.In order to see the kernel messages, just use the$ dmesg command in one of your shells - this one will print out thewhole kernel log buffer to y
6、ou.Most of the conversion specifiers supported by the user-space library routine printf() are also available in the kernel;there are some notable additions, including "%pf", which will print the symbol name in place of the numeric pointer value, if available.The supported format strings ar
7、e quite extensively documented inDocumentation/printk-formats.txtHowever please note: always use %zu, %zd or %zx for printing size_t and ssize_t values. ssize_t and size_t are quite common values in the kernel, so please use the %z to avoid annoying compile warnings.Author's practical advice:If
8、you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line printk(KERN_ALERT "DEBUG: Passed %s %d n",_FUNCTION_,_LINE_);after each possibly offending statement.Recompile and (re-)load the mo
9、dule and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.Of course you should remove these 'rude' statements before shipping your module ;)Log LevelsIf you look into real kernel code you will always see something like
10、: printk(KERN_ERR "something went wrong, return code: %dn",ret);where "KERN_ERR" is one of the eight different log levels defined in include/linux/kern_levels.h and specifies the severity of the error message.Note that there is NO comma between the KERN_ERR and the format string
11、(as the preprocessor concatenates both strings)The log levels are:NameStringMeaning alias functionKERN_EMERG"0"Emergency messages, system is about to crash or is unstable pr_emergKERN_ALERT"1"Something bad happened and action must be taken immediately pr_alertKERN_CRIT"2&quo
12、t;A critical condition occurred like a serious hardware/software failure pr_critKERN_ERR"3"An error condition, often used by drivers to indicate difficulties with the hardware pr_errKERN_WARNING"4"A warning, meaning nothing serious by itself but might indicate problems pr_warningKERN_NOTICE"5"Nothing serious, but notably nevertheless. Often used to report security events.pr_noticeKERN_INFOInformational message e.g. startup information at driver initialization pr_infoKERN_DEBUG"7"Debug messages
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 夫妻间忠诚承诺与粉丝影响力合作合同
- 烧伤面积评估与护理要点
- 网络直播导播台租赁及现场灯光音响调试服务合同
- 艺术培训机构教室租赁与课程研发合同
- 婚后家庭财产共有及分割管理细则协议
- 高清体育赛事直播权授权及赛事周边产品开发协议
- 版权侵权赔偿补充协议书
- 票务退改签服务补充协议
- 母婴护理服务质量规范执行与客户权益维护协议
- 网络教育平台兼职教师答疑合同
- 16949标准培训课件
- 术中低体温预防
- 人力资源管理数字化转型解决方案
- 国开电大《企业信息管理》形考任务参考答案
- 《电力系统仿真概述》课件
- 2024年版水利水电工程单元工程单元工程质量验收评定表
- 《酵母表达系统》课件
- 风力发电运维值班员(高级工)理论考试题库(浓缩400题)
- 2020版新疆维吾尔自治区市政工程消耗量定额(四)
- 运动康复案例分析
- GB/T 22082-2024预制混凝土衬砌管片
评论
0/150
提交评论