An introduction to the concept of bugs in programming, their types, and methods for debugging and preventing them in matlab. It covers common mistakes such as syntax errors, run-time errors, and logical errors, and offers advice from grace hopper and chapman on preventing bugs and identifying their causes. The document also introduces the use of a debugger as a tool for understanding program behavior.
Download Tracing and Debugging: Identifying and Fixing Bugs in MATLAB - Prof. Susha Rewaskar and more Study notes Computer Science in PDF only on Docsity!
Comp 116
Tracing and Debugging
June 3rd, 2007
Bugs
Glitches that cause unexpected behavior
Range of severity
Program does not work at all
Program does something but not what you want
Program does what I want most of the times but sometimes โฆโฆ
Debugging โ removing bugs
First Computer Bug
First Computer Bug
Grace Hopper
1945 or 1947
Syntax Errors
MATLAB doesnโt understand itโs input
Doesnโt even try to run the program
Common Cause
Parenthesis mistakes
Undefined functions or variables
Spelling
Capitalization?
Lower vs upper case
Run-time Errors
MATLAB understands your program, but not your data
Program continues but gives undesired results - Inf - NaN
Program stops running
Size mismatch
Array and matrix operations
Logical Errors
Program runs but answer is incorrect
โThinkingโ vs. โtypingโ
Algorithm has flaws
Typing error (either syntax or logical error)
Common causes
Accessing the wrong variables
Wrong units
Order of operations
Two important Questions
How can I prevent bugs?
I know I have a bug, how do I explain it?
Testing for bugs
Write a test input to test part of the code which may have a bug
Once bug is fixed, use same test to confirm the fix
The Debugger
A tool that helps you understand what a program is doing
Step through one line at a time
Break on interesting lines
Conditioned on a values
Interact with program state
View/change variables during calculations
Debugger
Insert or remove a breakpoint on this line
When you run a program it runs till the breakpoint and stops
Button Bar in Editor Window
Debugger
Clears all breakpoints in this file
Debugger
Steps out to the function calling this one
Debugger
Run/Continue
Continues running the program after a breakpoint
If program is not running it starts running
Debugger
Exit Debug Mode
stops running current program and exits the debugger