debuggingbyprinting.docx

上传人:b****8 文档编号:23966752 上传时间:2023-05-23 格式:DOCX 页数:5 大小:15.59KB
下载 相关 举报
debuggingbyprinting.docx_第1页
第1页 / 共5页
debuggingbyprinting.docx_第2页
第2页 / 共5页
debuggingbyprinting.docx_第3页
第3页 / 共5页
debuggingbyprinting.docx_第4页
第4页 / 共5页
debuggingbyprinting.docx_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

debuggingbyprinting.docx

《debuggingbyprinting.docx》由会员分享,可在线阅读,更多相关《debuggingbyprinting.docx(5页珍藏版)》请在冰豆网上搜索。

debuggingbyprinting.docx

debuggingbyprinting

debuggingbyprinting

Probablythesimplestwaytogetsomedebuginformationfromyourkernelcodeisbyprintingoutvariousinformationwiththekernel'sequivalentofprintf-theprintkfunctionanditsderivatives.

Thekinprintkisusedtospecificallyremindkerneldevelopersthattheenvironmentisdifferent.

Contents[hide]

1Usage

2LogLevels

3Ratelimitingandonetimemessages

4Printkfromuserspace

5Internals/Changingthesizeoftheprintkbuffer

6ProsandCons

7Debuggingearlybootproblems

7.1Accessingtheprintkbufferafterasilenthangonboot

7.1.1RedbootexampleonaFreescaleADSboard

7.1.2U-bootexampleonanOMAPOSKboard

7.1.3Grub

 

7.2UsingCONFIG_DEBUG_LLandprintascii()(ARMonly)

 

8NetConsole

8.1Netconsoleresources

 

9Misc

9.1Dmesg/Clearingthebuffer

9.2PrintkTimestamps

9.3Printingbuffersashex

9.4DynamicDebugging

 

10Disablingprintkmessagesatcompiletime

11Referencesandexternallinks

 

Usage

printkworksmoreorlessthesamewayasprintfinuserspace,soifyoueverdebuggedyouruserspaceprogramusingprintf,youarereadytodothesamewithyourkernelcode,e.g.byadding:

printk("MyDebuggerisPrintk\n");

Thiswasn'tthatdifficult,wasit?

Usuallyyouwouldprintoutsomemoreinterestinginformationlike

printk("Var1%dvar2%d\n",var1,var2);

justlikeinuserspace.

Inordertoseethekernelmessages,justusethe

$dmesg

commandinoneofyourshells-thisonewillprintoutthewholekernellog

buffertoyou.Mostoftheconversionspecifierssupportedbytheuser-spacelibraryroutineprintf()arealsoavailableinthekernel;therearesomenotableadditions,including"%pf",whichwillprintthesymbolnameinplaceofthenumericpointervalue,ifavailable.

Thesupportedformatstringsarequiteextensivelydocumentedin

Documentation/printk-formats.txt

Howeverpleasenote:

alwaysuse%zu,%zdor%zxforprinting

size_tandssize_tvalues.ssize_tandsize_tarequitecommonvaluesinthekernel,so

pleaseusethe%ztoavoidannoyingcompilewarnings.Author'spracticaladvice:

Ifyouwanttodebuganoops(e.gcausedbyreleasingaresourcetwice)inyourdriverandyoudon'thaveacluewheretheoopshappens,simplyaddthisline

printk(KERN_ALERT"DEBUG:

Passed%s%d\n",__FUNCTION__,__LINE__);

aftereachpossiblyoffendingstatement.

Recompileand(re-)loadthemoduleandtriggertheerrorcondition-yourlognowshowsyouthelastlinethatwassuccessfullyexecutedbeforetheoopshappened.

Ofcourseyoushouldremovethese'rude'statementsbeforeshippingyourmodule;)LogLevels

Ifyoulookintorealkernelcodeyouwillalwaysseesomethinglike:

printk(KERN_ERR"somethingwentwrong,returncode:

%d\n",ret);

where"KERN_ERR"isoneoftheeightdifferentloglevelsdefinedin

include/linux/kern_levels.handspecifiestheseverityoftheerrormessage.

NotethatthereisNOcommabetweentheKERN_ERRandtheformatstring(asthepreprocessorconcatenatesbothstrings)

Theloglevelsare:

Name

String

Meaning

aliasfunction

 

KERN_EMERG

"0"

Emergencymessages,systemisabouttocrashorisunstable

pr_emerg

 

KERN_ALERT

"1"

Somethingbadhappenedandactionmustbetakenimmediately

pr_alert

 

KERN_CRIT

"2"

Acriticalconditionoccurredlikeaserioushardware/softwarefailure

pr_crit

 

KERN_ERR

"3"

Anerrorcondition,oftenusedbydriverstoindicatedifficultieswiththehardware

pr_err

 

KERN_WARNING

"4"

Awarning,meaningnothingseriousbyitselfbutmightindicateproblems

pr_warning

 

KERN_NOTICE

"5"

Nothingserious,butnotablynevertheless.Oftenusedtoreportsecurityevents.

pr_notice

 

KERN_INFO

"6"

Informationalmessagee.g.startupinformationatdriverinitialization

pr_info

 

KERN_DEBUG

"7"

Debugmessages

pr_debug,pr_develifDEBUGisdefined

 

KERN_DEFAULT

"d"

ThedefaultkernelloglevelKERN_CONT

""

"continued"lineoflogprintout(onlydoneafteralinethathadnoenclosing\n)[1]

pr_cont

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1