15-410, F’04- 1 -DebuggingSep. 17, 2004Dave EckhardtDave EckhardtL08a_Debug15-410“Experience is what you get......when you don't get what you want.”15-410, F’04- 2 -What is “Debugging”?Debugging is resolving a clash between storiesDebugging is resolving a clash between storiesÿYour hopeful story of achievementÿThe world's sad tale of woeThe stories look alike!The stories look alike!ÿAt the beginning, they both start with main()...ÿKey step: finding the divergenceStories are fractalStories are fractalÿYou can zoom in on them and get more detail each timeÿThe divergence is typically a tiny detailYou will need to zoom in quite a lot15-410, F’04- 3 -Move Beyond “Plot Summaries”“When I install my keyboard handler it crashes”“When I install my keyboard handler it crashes”Insufficient detailThis is a “plot summary”, not a tale of woeDon't ask us to look at your code yet!Deepen your level of detailDeepen your level of detailWhat was your story of hope, in detail?What parts of your story already happened?15-410, F’04- 4 -Telling Your Story“When I install my keyboard handler...”“When I install my keyboard handler...”What do you really hope?Hardware notices keyboard eventHardware posts interruptCPU recognizes interrupt as keyboard interruptCPU responds to (vs. ignores) keyboard interruptCPU stores trap frameCPU vectors through your IDT entryYour wrapper is runWrapper calls C codeC code does ...15-410, F’04- 5 -Pinpointing Depends on the Story“...it crashes”“...it crashes”Ok, that's generally what programs doOr, at least, that's when we start to pay attention to them...The critical questionThe critical questionHow far did your story progress before the crash?Pinpointing the problemPinpointing the problemHow can you measure which steps worked ok?“Keypress ⇒ crash” tells you quite a bit!15-410, F’04- 6 -Matching Phenomena to the Story“Keypress “Keypress ⇒⇒ crash” tells you quite a bit crash” tells you quite a bit√ Hardware notices keyboard event√ Hardware posts interrupt√ CPU recognizes interrupt as keyboard interrupt√ CPU responds to (vs. ignores) keyboard interrupt? CPU stores trap frame? CPU vectors through your IDT entry? Your wrapper is run? Wrapper calls C code? C code does ...What now?What now?15-410, F’04- 7 -MeasuringHow can you How can you measuremeasure the other steps? the other steps?? CPU stores trap frame? CPU vectors through your IDT entry? Your wrapper is run? Wrapper calls C code? C code does ...15-410, F’04- 8 -Measurement Techniques“Obvious”“Obvious”printf()single-step the programMoving beyond the obviousMoving beyond the obviousKnow your debuggerbreakpoints, watchpointsThose pesky registers%esp, %eip – these should always “make sense”»You should always know what would be “sensible”!%CS, %DS, %SS – not all that many legal values, right?%EFLAGS, %CR0 – “when the going gets tough...”15-410, F’04- 9 -Measurement TechniquesWriting codeWriting codeBreakage of a complex data structure is, well complexProbably need code to check invariantsDoing it by hand is fun at most once15-410, F’04- 10 -Asking for Help“Plot summary” is not enough“Plot summary” is not enoughWe probaby have no idea what's wrongReally!Please see “triple fault” web pageYou should always have a measurement planYou should always have a measurement planWhat is the next thing to measure?How would I measure it?You may reach the end of your ropeYou may reach the end of your ropeSome things are genuinely tricky to debugThings in this class may occasionally qualifyThis is a good learning experience15-410, F’04- 11 -Asking for HelpWhen are you ready to ask for help?When are you ready to ask for help?You have a long, detailed story – this is critical!!!Based on lecture, handout, Intel docs“Story” often needs one or two picturesParts of the story are clearly happeningYou have straightforward evidence, you are confidentYou have a measurement problemToo many things to measure?No idea how to measure one complicated thing?Measurement results “make no sense”?15-410, F’04- 12 -SummaryDebugging is about reconciling two storiesDebugging is about reconciling two stories“Plot summaries” aren't stories (you must zoom in)“If you don't know where you are going, you will wind up somewhere else.” — Yogi Berra Measure multiple things, use multiple mechanismsMeasure multiple things, use multiple mechanismsYou should “always” have a next measurement targetYou should “always” have a next measurement targetWhen you see us, bring a long storyWhen you see us, bring a long story...which you will naturally be an expert on the first part ofTry to know why each register has the value it
View Full Document