550 likes | 672 Views
Lecture 9. Introduction to Debugging. Precision: The High Standards of Computing. Humans are imprecise and error-prone Computers demand precision. Be Accurate. Developing an awareness for mistakes l for 1, O for 0, for /, and so forth Corbel zero (o) and oh (o)
E N D
Lecture 9 Introduction to Debugging
Precision: The High Standards of Computing • Humans are imprecise and error-prone • Computers demand precision
Be Accurate • Developing an awareness for mistakes • l for 1, O for 0, \ for /, and so forth • Corbel zero (o) and oh (o) • Special characters: “, ”, ‘, ’ • Case sensitivity
Be Observant • Pay attention to computer feedback • Browser’s formatting of web page • Warning dialogs
What’s the Problem? • Debugging • Process to figure out why something isn’t working properly • “Troubleshooting” • Debugging relies on • Logical reasoning • Experience
Whose Problem Is It? • Weare almost always part of the problem • Two of the three possible problems involve us • wrong data • wrong command • broken system – less likely
Steps to Debugging • Check that error is reproducible • Computers are deterministic • Start by trying to reproduce the problem
Steps to Debugging • Know exactly what the problem is • Pinpoint • Sequence of operations may occur after an error
Steps to Debugging • Check all of the “obvious” error sources • Checking inputs, connections, links, etc.
Steps to Debugging • Isolate the problem by dividing the operation into working and non-working parts • Theorize about where the problem is located • Collect information • Limit untested assumptions** • Eliminate possibilities
Debugging Recap Guidelines • Key points to debug • Reproduce • Determine the problem exactly • Eliminate the “obvious” • Isolate problem • If stuck, check assumptions and conclusions** • Make predictions about what should happen and verify
A Debugging Case Study • HTML page • Want page to look like this
Look Closely At the Page Working Page Not Working Page..Firefox
Look Closely At the Page Working Page Not Working Page..Safari
Look Closely At the Page Working Page Not Working Page..Chrome
Look Closely At the Page Working Page Not Working Page..IE
Look Closely At the Page • Study output closely • What’s right and wrong? • Browsers display buggy page differently • Correct pages should render same way
Reproduce the Error • Begin debugging the HTML • Can we reproduce the error? • Close the browser and reopen the file • Definitely a problem with our HTML!
Determine the Exact Problem • Pinpoint • Look at the displayed page • Pick one error to focus on
Eliminate the Obvious • Once problem is known • Look for the “obvious” causes • Most obvious problem with missing image? • File isn’t where it should be • Is image in the pic folder? Yes
Eliminate the Obvious • Next most obvious error is … • Spelling the file name • Oops, path doesn’t mention ‘pic’ folder • Fix tag and image appears! • One down!
Focusing the Search • Identify next problem • Pinpoint • Eliminate the obvious • Divide up the process
The “Divide Up the Process” Process • Go through style section • For each element • Delete the entire element • Save the file; refresh the display • What changed? • If only removed element, then undo deletion and continue
The “Divide Up the Process” Process • Stop when removing element restores other formatting • We’ve separated broken from unbroken
The “Divide Up the Process” Process • Drill down on CSS element • Repeat division process for parts of line • Sometimes easier to reenter text
(Tools > Web Developer > Error Console) • In Firefox, go to Error Console • Clear whatever errors have accumulated • Refresh the page
Find the Error(s) img{padding:6; border-width:1px;border-style:solid; border-color:burlywood;} table{outline:solidburlywood thin; font-size:14px} th (text-align:center;border-width:1px; border-style:solid; border-color:burlywood:padding:3px}
Find the Error(s) (2) img{ padding: 6; border-width: 1px; border-style: solid; border-color: burlywood; } table { outline: solid burlywood thin; font-size: 14px } Easier now?
Find the Error(s) (3) th ( text-align: center; border-width: 1px; border-style: solid; border-color: burlywood: padding: 3px }
Errors in HTML <span class=“au”>golds </span> in long jump, and a long jump <span class=“au”>gold </spam> in the Pan American Games. She also played starting forward all four years of college at UCLA in basketball.
Errors in HTML (2) <p> ... <span style=“font-size;small”> Jackie Joyner Kersee Competing in High Jump</span><br/></p>
Debugging the Page:A Postmortem • We applied these debugging guidelines • Checked if image file was in the pic folder—it was. • Checked spelling of filename. Fixed. • Checked that the end tags were all present—they were. • Looked at Error Console.
Debugging the Page:A Postmortem • Applied debugging guidelines • Checked that the closing braces were all present—they were. • Separated working from failing code by a process of delete, check, undo—found th had stopped styling. • Checked the th element, and eventually spotted the opening parenthesis. Fixed.
Debugging the Page:A Postmortem • Applied debugging guidelines • Looked at the Error Console again • Checked padding, and noticed that the unit had not been set. Fixed. • Looked up “caption-align” property to find it is “caption-side.” Fixed.
Debugging the Page:A Postmortem • Applied debugging guidelines • Checked the wrongly colored text, and spotted a typo in the end tag. Fixed. • Checked the caption’s small font specification, and spotted a colon typo. Fixed.
Debugging the Page:A Postmortem • Sometimes we “correct” working code • May change correct to correct • May change correct to incorrect • “back out”
Debugging the Page:A Postmortem • Errors may hide other errors
Debugging the Page:A Postmortem • Asking the System to Help • Browser’s Error Console feature • May get hard to understand messages • View page source in browser shows color- and font-coded HTML source
No Printer Output… • You try to print a document and nothing happens… • Debugging process • Reproduce the error, • Pinpoint the problem • Check the obvious causes • Isolate
No Printer Output… • Try to pinpoint • check printer’s control panel, paper, etc. • canothers print if it’sa shared printer, and • can you print a different document
No Printer Output… • Isolate the problem • You’ve printed before your computer is configured correctly • Try to print a plain text file– fails • Unplug and try again • Look at print queue
The Print Queue • Print queue • Consists of jobs waiting to print • Clear jobs, and restart • Ensure computer is reconnectedto printer
Ensuring Software Reliability • Software • Will have bugs • Will often crash • Consequences of errors • Annoyance • More serious if occur in life-support systems, medical apparatus, airplanes, nuclear power plants, weapons systems, etc.
Hardware Failures • Dealing with hardware failures • Redundancy • Burn in • Most errors show up after few hours • Record of successful operation indicates likeliness of continued operation
Software Failures • Software is amazingly complex • Possible configurations are typically very large • All states cannot be examined for correctness • How can s/w engineers be sure program works correctly?
Software Failures • Programmers begin with a specification of • the input • how system should behave • how output should be produced • Specification states correct behavior • Not how it should be achieved