Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley An Introduction to Debugging To Err is Human lawrence snyder c h a p t e.

Similar presentations


Presentation on theme: "Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley An Introduction to Debugging To Err is Human lawrence snyder c h a p t e."— Presentation transcript:

1 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley An Introduction to Debugging To Err is Human lawrence snyder c h a p t e r 7

2 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-2 Precision: High Standard in Computing Precision in Everyday Life –Many people say "oh" rather than zero when giving a phone number –The listener makes the mental conversion because he knows phone numbers are numeric –Computer does not know that unless it has been programmed to know it

3 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-3 Exactly How Accurate Is "Precise?" Modem or database software can be programmed to make "oh" to zero corrections automatically because all digits will always be numbers In programs, both letters and numbers are allowed, so the computer can't be programmed to auto-correct. Users have to be careful Being exact can save time and frustration

4 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-4 Lexical Structures Field Inputs: Information entered into boxes/forms on screen –Governed by lexical structures (rules about the legal form for input fields) May limit symbols that can appear in specific positions, length of entry, etc. May also be loose, allowing any sequence of symbols of any length

5 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-5 Debugging: What's the Problem? Debugging: The method of figuring out why a process or system doesn't work properly –Usually learned from experience Debugging in Everyday Life: People troubleshoot problems such as why their cars don't start –Usually involve well-designed system with broken, worn-out part Debugging in Information Technology: –Working system might have wrong data or wrong configuration information, or –There might be a logical design error –We will always begin by assuming a correct, working system

6 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-6

7 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-7 Whose Problem Is It? When we debug an information system, we are always part of the problem –We give the commands and the input Operator or pilot error –Only other possible cause is broken system People don't knowingly make errors –We may think we did everything right because we misunderstand the system

8 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-8 Using the Computer to Debug A computer can't debug itself We can't debug it directly, either Error is internal to the computer –To get information about the error, we have to ask the computer what data it stored, etc. With faulty software we cannot fix, try to bypass error with alternative approach (workaround)

9 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-9 A Dialog About Debugging Debugging is solving a mystery –Whatdunit vs. whodunit Ask purposeful questions like: –Do I need more clues? –Are my clues reliable? –What is a theory to explain the problem? Better than aimlessly "trying stuff"

10 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-10 Basic Debugging Strategy 1.Check that the error is reproducible 2.Make sure you know what the problem is If no mailing labels come out of printer, problem may be with printer or with program sending labels to printer or file containing addresses

11 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-11 Basic Debugging Strategy (cont.) 3.Check all the "obvious" sources of error 4.Isolate the problem Divide operation into those parts that are working and those that are not working Think objectively—ask yourself if you've made a wrong assumption, etc. When you reach a dead end, reassess your information; then step through the process again As you work through, make predictions about what should happen and verify that they are fulfilled (or not) Take nothing for granted… you may assume away the error

12 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-12 Butterflies And Bugs: A Case Study Imagine we are developing a simple XHTML page, information on endangered butterflies Our intention is the screen shown following However, something is not right… we get different erroneous views when the page is rendered in some popular browsers

13 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-13 Our Goal Page

14 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-14 Safari Browser Display

15 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-15 Firefox Browser Display

16 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-16 Chrome Browser Display

17 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-17 Butterflies and Bugs (cont'd) The XHTML source for the page is shown following We can study the XHTML very closely and "brain out" where the error is Or… we can apply our basic debugging strategy

18 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-18 The HTML for Our Page

19 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-19 The HTML for Our Page (cont'd)

20 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-20 Butterflies and Bugs (cont'd) First, be sure we can re-create the error –Reload the page (here, the results stay the same) Next, determine the problem exactly –View the page and determine where the errors occur table without pictures skewed table entries Links not highlighted, colors not showing –Since there are multiple errors on different parts of the page, we suspect they are caused by different mistakes in the XHTML

21 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-21 Butterflies and Bugs (cont'd) Next, eliminate the obvious –In XHTML, common error is forgetting to close a tag For example: with no closing tag In this case, all tags match Make sure all string quotes match too (open and close) –Check for missing spaces (create unknown tags) Why is the "More here" link not highlighted? Space missing between

22 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-22 Butterflies and Bugs (cont'd) Can try a checking tool like the Validator Not a bad idea, but often is not helpful –Won’t find design flaws –Easily confused when more than a 1 or 2 syntax errors (this page does not have errors)

23 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-23 Butterflies and Bugs (cont'd) OK, two bugs down, one to go (we think) First colored row of the table looks strange but not sure why Maybe related to the images not displaying in the table Check the tag for correct image file names They are correct… so backup and reassess

24 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-24

25 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-25 Butterflies and Bugs (cont'd) Divide up the process –Separate the working from the not working (as best we can) –Here, most of the page looks fine, the table is not –Concentrate on top row of table… we compare intent to what we see, and notice an entire row is missing (the headers) –Zero in on headings specifications in XHTML

26 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-26 Butterflies and Bugs (cont'd) –We pore over the XHTML source in detail but don’t see an error –Browsers and debugging systems for XHTML can give us some help/clues with these details For example, try Source View in Firefox (shown following) See a color-coded version of the XHTML syntax, showing how it's being interpreted –We see the entire heading line is colored blue as if it is an attribute –Then we notice a fancy quote character that the browser cannot interpret, so a string is not closed

27 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-27

28 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-28

29 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-29 Butterflies and Bugs (cont'd) Reassess and keep going –The pictures are still not displaying –We find that the image tags are well structured and the browser is interpreting them correctly –What is the problem? To check that images are ok, display in another document To check that the JPEG specification is ok, put another image file in the document Check the exact file name for the image, including capitalization Bingo… we find the filename extension is.jpeg, not.jpg as we have been using

30 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-30

31 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-31 Butterflies and Bugs (postmortem) Unnecessary changes (are ok) –We fixed the page by making conjectures, try changes, run experiments, draw conclusions –During the process, we made some unnecessary changes due to wrong conjectures about the error –Making unnecessary changes is typical in debugging –Sometimes we even make the situation worse by introducing new errors, but we backup and reassess

32 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-32 Butterflies and Bugs (postmortem) Hiding other errors: –At first we thought we had three errors—bad caption, missing link, busted table –Because there were two things wrong with the table (messed up heading line and wrong file names specified) there were actually four errors –Because it is common for one error to hide another, always suspect there is more than one error

33 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-33 Butterflies and Bugs (postmortem) Viewing the source: –Best tool in our debugging was the View Source feature –In general, we find ways for the computer to tell us the meaning of the information it stores or the commands it executes Little errors, big problems: –The errors in the XHTML code were tiny, but had serious effects –We must be extremely precise

34 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-34 No Printer Output: A Classic Scenario Most systems we use, we don't create Software is very complicated. How do we troubleshoot a system we don't understand? Generally, software has been extensively tested before we come in contact with it –Standard operations are likely to be bug-free To illustrate debugging a system without understanding it, consider a common problem: You try to print a document and nothing comes out of the printer

35 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-35 Applying the Debugging Strategy –Reproduce the error, understand the problem, check the obvious causes –Check the printer's control panel, the paper, the cartridges, cable connection, file to be printed, installation of printer driver, whether others can print (if it's a shared printer) and whether you can print a different document Simple, quick checks –If this does not solve the problem, press on

36 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-36 Try to Isolate the Problem –Configuration is correct because you've printed before –Try printing a simple document Same problem –Think through the probable process If the computer couldn't send the data to the printer, wouldn't it give a message to plug in the printer? Look around for the stranded files –In the printing monitor's files, you find a list of files you've tried to print recently –Start > Printers and Faxes

37 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-37 The Print Queue You've found the print queue Computer's settings may tell it to "queue" converted files rather than printing them immediately –Pause Printing You may never know how this occurred, but you can still fix it by re-configuring the driver –Unclick Pause Printing or click Resume Printing

38 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-38 Software Reliability Our digital society has computers controlling significant critical resources –banks, planes, nuclear reactors, weapons, medical Errors in software can have serious consequences –injury, death, economic havoc NO software is perfect (even in safety-critical systems) What are the ways a system can fail?

39 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-39 Safety-Critical Systems Hardware failures –Redundancy can mitigate these 3 computers all perform the same computations, vote on correct values and look to see if they all agree 1 failure will be detected by the voting and ignored (What if voting mechanism contains the failure?) –Burn-in can mitigate these Infant mortality: if hardware fails, it is usually very early in its lifetime Use hardware that has run successfully for a test time –We can gain confidence that hardware will work correctly

40 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-40 Safety-Critical Systems Software failures –Software is hugely complex compared to mechanical and electronic physical systems Number of possible reachable configurations grows exponentially with increasing program size Impossible to examine all possible states –How do we gain confidence in correct execution then? –Start with precise specification of what outputs are expected for particular inputs (program design) –Test program behavior to see if it matches specs

41 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-41 Software Testing: The Reality Not possible to determine if specs are correct –same problem we have with programs, just pushed “up a level” in abstraction Testing can only reveal the presence of bugs, never the absence of bugs –We can test a long time and may not find the last bug –Testing brings increased confidence, not certainty

42 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-42 The Software User’s Challenge We must accept that software will contain errors and watch during use for unusual behavior that could reveal unfound bugs –Be prepared to limit the harm unfound bugs might cause Poorly tested software is unprofessional practice on the part of developers –Users should demand high quality and be prepared to switch to better programs

43 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-43 Fail-Soft vs. Fail-Safe Software Since correctness is near-impossible, we can concentrate our concerns on safety –Will a failure cause reactor meltdown? –Will a failure cause patient harm? Fail-soft means a program keeps running when errors occur, but at some reduced level of functionality Fail-safe means a program stops functioning on failure to avoid potential harms Perfectly safe software is as elusive as perfectly correct –All software-controlled systems bring some risk

44 Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7-44 Summary Standards of precision are higher in computing than in most other situations Learned what debugging is, why we need it, and how to do it Learned the basic debugging strategy Web page debugging involves comparing the source view of the HTML to how the browser interprets it Learned how to analyze our debugging performance Debugging involves both correct and incorrect conjectures The basic strategy allows debugging something we know little about It is impossible to have bug-free software


Download ppt "Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley An Introduction to Debugging To Err is Human lawrence snyder c h a p t e."

Similar presentations


Ads by Google