付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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-2026学年贴画蛋糕制作教案
- 市场策划市场效果绩效衡量表
- 8.2 东南亚(教学设计)七年级地理下册同步高效课堂(人教版2024)
- 品牌保护措施备案函(3篇)范文
- 大型活动人群失控紧急响应项目管理团队预案
- 通知各部门关于项目验收的安排8篇
- 产品功能升级的用户通知函件5篇
- 社区健康数据分析与应用
- 2026年医疗机构院感管理条例法规培训试题(附答案)
- 2026年广东省高三一模英语试题及答案
- 2025-2026年护士执业资格考试试题及答案解析(完整版)
- 2026年珲春市事业单位公开招聘工作人员和基层治理专干(含专项招聘高校毕业生)(180人)笔试参考试题及答案详解
- 重庆师范大学《英语读写2》2026-2027学年第一学期期末试卷含解析
- 六升七 英语综合能力提升课|备战初中入学考试
- 2026中国质子治疗系统引进成本与本土化生产可行性报告
- (完整)2026年全国高校辅导员素质能力大赛基础知识试题+参考答案
- 2026-2030中国间苯二甲酰氯(ICL)(CAS-99-63-8)行业市场发展趋势与前景展望战略分析研究报告
- 应急处置安全指导手册
- 妇幼院质控办工作制度
- 智能光谱检测技术-洞察与解读
评论
0/150
提交评论