PowerPoint Presentation

Published on Slideshow
Static slideshow
Download PDF version
Download PDF version
Embed video
Share video
Ask about this video

Scene 1 (0s)

An Introduction to Debugging.

Scene 2 (6s)

Compiling and Debugging r Executable code will not be created until you correct all of the syntax errors in your source code.

Scene 3 (15s)

Syntax & Logic Errors A syntax error is simply the violation of the rules of a language; misuse of structure and form in programming or a violation of the compiler's rules. These errors are detected by the compiler Also know as 'fatal compilation errors' A /ogic error is a mistake that complies with the rules of the compiler that causes the program to generate incorrect output.

Scene 4 (32s)

Linker Errors Not all syntax errors are detectable by the compiler • These errors do not become apparent until files are put together to create an executable • These errors are not linked to a specific line of code Look for the name of the variable and see what lines of code it occurs on using EDIT and FIND • LNIK2001: unresolved external • LNKI 120: unresolved externals.

Scene 5 (49s)

Debugging Debugging is the process of locating and fixing or bypassing bugs (errors) in computer program code or the engineering of a hardware device. To debug a program or hardware device is to start with a problem, isolate the source of the problem, and then fix it..

Scene 6 (1m 2s)

1. Debugging Objective Find the line(s) containing the syntax error(s) using the compiler's chosen line and error messages as a starting point.

Scene 7 (1m 12s)

Debugging is an Art Compilers often miss reporting an actual error and report on subsequent lines which are effected by error but may be completely correct After encountering a real syntax error, compilers often generate many incorrect syntax error messages Different compilers produce different errors and warnings for the same errors in the same program.

Scene 8 (1m 26s)

1. 2. 3. Debugging Steps Proofread before compiling Compile Correct all the obvious errors Start at the beginning of the list of errors and warnings A single syntax error may cause the compiler to believe numerous other syntax errors are occurring Look at the error lines and if you see the error, fix it. Otherwise, leave it for later. It may vanish when you fix something else Don't worry if more errors appear. Some errors mask other errors.

Scene 9 (1m 47s)

4. 5. 6. 7. 8. Debugging Steps Recompile when you have fixed what you recognize Repeat 3 & 4 until no further errors are obvious Attempt to solve the remaining errors in a top- down fashion Solve whatever errors you can without spending long periods of time on any given Recompile whenever you feel you don't see any further solutions.

Scene 10 (2m 3s)

1. 2. 3. Debugging Aids In the Visual C++ (and other GUI-based compilers) double-clicking on an error message move the cursor to the line where the compiler detected the • This may not be the actual line where the error occurred — don't trust the compiler on lines Work from the beginning of the program, because in most compilers, the errors are detected from the beginning to end, sequentially Some errors are so severe, they stop the compiler from continuing so more errors may appear after you successfully fix one or more.

Scene 12 (2m 32s)

Sample Debugging Comment cuot < < "This is a line of code"<< endl; Error is undeclared identifier 1. Checked syntax for endl 2. Check syntax for screen output -- cuot is misspelled.

Scene 13 (2m 42s)

1. 2. 3. 4. Debugging Checklist Visually verify the spelling and case of keywords and identifiers - Remember, in the editor, keywords are blue, literals are black and comments are green - Look for problems with I and 1 and o and O Verify syntax with a reference book, not just visually - Don't trust your eyes; you see what is supposed to be there Try to find an example in the reference book that does something similar and compare the code Verify that the necessary delimiters used for that line a there - Check the lines above and below as well.

Scene 14 (3m 6s)

5. 6. Debugging Checklist Without looking at your source code or notes, rewrite the instruction on a piece of paper and then compare it to your actual code; don't cheat Verify that the line is really the source of the error by commenting the line using // a) b) c) d) Don't worry about other errors that result from this If the error disappears, it probably results from the line you are working on If it moves to the next line it is probably caused earlier in the code Remember that the compiler cannot be trusted to pinpoint lines.

Scene 16 (3m 35s)

Common Causes for Warnings An equal sign used in an expression is actually an assignment operator, not the relational operator testing for equality j- Loops where one condition could never logically be executed Testing a variable that has not received a value yet.

Scene 17 (3m 48s)

Disk Space Issues If the floppy is full or becomes full during the compilation process, the compile will fail with an error message such as: • fatal error C1033: cannot open program database A very cryptic message like this can result If you are not able to view all of the intermediate files created in a compile, suspect a space error.

Scene 19 (4m 10s)

Error Prevention & Testing Use good design and programming style • Don't use global variables Study your code before typing and running it • Have someone else look at it Make your program self-documented Program defensively — put in assertions and self- checking code and comment them out Test your code at boundary values for variables Log your bugs Test code in pieces using "stubs" Consider — correctness, reliability, utility and performance.