付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026广东深圳大学艺术学部刘琨教授团队博士后招聘1人备考题库附参考答案详解(综合卷)
- 2026广东中山市沙溪隆都医院第一期招聘合同制人员6人备考题库带答案详解(满分必刷)
- 2026上半年贵州事业单位联考仁怀市招聘77人备考题库附参考答案详解(巩固)
- 2026四川省红十字基金会招聘工作人员1人备考题库带答案详解(模拟题)
- 2026云南昭通仁德中学招聘33人备考题库及答案详解(必刷)
- 2026吉林省科维交通工程有限公司东南地区项目部劳务派遣人员招聘14人备考题库带答案详解(基础题)
- 2026宁夏德渊市政产业投资建设(集团)有限公司招聘专业技术人员15人备考题库含答案详解(达标题)
- 2026上半年贵州事业单位联考铜仁市碧江区招聘40人备考题库附答案详解(达标题)
- 2026广东广州市花都区实验中学临聘教师招聘3人备考题库及答案详解(必刷)
- 2026上半年贵州事业单位联考贵州省住房和城乡建设厅招聘16人备考题库附答案详解(典型题)
- JJG 264-2025 谷物容重器检定规程
- 绘制竣工图合同协议
- 成人脑室外引流护理团体标准解读
- 酒店管理专业实习管理手册
- 2024年劳动保障监察和调解仲裁股年终总结
- 艺术院校合作办学方案
- 安徽省合肥市包河区2023-2024学年七年级下学期期中数学试卷
- 人教版九年级英语上册阅读理解10篇(含答案)
- GB/T 10561-2023钢中非金属夹杂物含量的测定标准评级图显微检验法
- 《思想道德与法治》课件第四章明确价值要求践行价值准则第三节积极践行社会主义核心价值观
- 轨道安装检查检验批施工质量验收表
评论
0/150
提交评论