Docsity

Tracing and Debugging: Identifying and Fixing Bugs in MATLAB - Prof. Susha Rewaskar, Study notes of Computer Science

Toggle sidebar
bg1
1
๎˜๎˜‚๎˜ƒ๎˜„๎˜…๎˜†๎˜‡๎˜ˆ๎˜ƒ๎˜‰๎˜…๎˜‚๎˜Š๎˜ƒ๎˜…๎˜Š๎˜‹๎˜ˆ๎˜‰๎˜Œ๎˜‚๎˜ƒ๎˜‰๎˜๎˜‰๎˜ˆ๎˜Š
๎˜Ž๎˜„๎˜…๎˜๎˜„๎˜๎˜‘ ๎˜‘ ๎˜‰๎˜‚๎˜
Comp 116
Tracing and Debugging
June 3
rd
, 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
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

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