




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2030中国家庭陪护行业市场深度分析及竞争形势与投资前景研究报告
- 《常见气象灾害的成因与应对:高中地理教案》
- 小学2024-2025学年度第二学期教务处课程优化计划
- 小学三年级上册班主任教学计划
- 机动车购买与注册证明书(7篇)
- 我的小西红柿400字9篇
- 教育机构总经理年度总结报告范文
- 写人作文三宝爸爸900字11篇
- 中国书法课件
- 科研人员学术规范心得体会
- 光伏电厂防洪防汛应急预案演练方案
- 乡镇环境保护工作制度
- 现场实名制管理制度
- 浙江大学《分子生物学原理》2023-2024学年第二学期期末试卷
- 2025年“美好生活民法典相伴”主题宣传月活动总结(2篇)
- 移动通信网络流量分析与优化策略制定
- 16949标准培训课件
- T-CMES 04001-2020 机床装备制造成熟度评价规范
- 国开电大《企业信息管理》形考任务参考答案
- 风力发电运维值班员(高级工)理论考试题库(浓缩400题)
- 常见柜面业务操作考核评分表
评论
0/150
提交评论