Debugging Runtime Errors - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Debugging Runtime Errors

Description:

Support to run the statements line by line. Debugger. Steps to use debugger ... Line by line. Jump into the function. Leave the function. Debugger ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 12
Provided by: cpeg
Category:

less

Transcript and Presenter's Notes

Title: Debugging Runtime Errors


1
Debugging Runtime Errors
  • COMP103 Lab 4

2
Errors
  • Compilation
  • Syntax errors
  • Compilers usually catch them at compilation time
  • Runtime
  • Array index out of bound
  • Memory referencing errors
  • File accessing errors
  • Compilers usually generate NO errors but error
    messages appear at runtime

3
Runtime Errors
include ltiostreamgt using namespace std void
main() int k k 4
Wheres the problem?
k is not pointing to a valid address
4
Compiler Warnings
  • Sometimes the compiler will generate warnings to
    you!
  • Dont ignore them!

include ltiostreamgt using namespace std void
main() int k k 4
--------------------Configuration debug - Win32
Debug-------------------- Compiling... main.cpp d
\temp\103\tutorial\debug\main.cpp(6) warning
C4700 local variable 'k' used without having
been initialized Linking... debug.exe - 0
error(s), 1 warning(s)
Warning Message
5
Debugger
  • However, compiler is not always helpful
  • MS Visual C has a built-in debugger
  • Support to run the program until reaching a
    breakpoint
  • Support to run the statements line by line

6
Debugger
  • Steps to use debugger
  • Identify the possible locations for the bug
  • Add a breakpoint to those locations (more
    breakpoints could also be added while you are
    debugging)
  • Run the debugger

7
Debugger
  • Right click on the suspicious lines
  • Choose Insert/Remove Breakpoint

8
Debugger
  • Choose Build-gtStart Debug-gtGo

stop at breakpoint
Note This statement is not executed yet!
9
Debugger
  • Run the codes
  • To the next breakpoint (pressing F5)
  • Line by line
  • Jump into the function
  • Leave the function

10
Debugger
  • Point to the variable to see its current value
  • Look at some variables in the variables window

11
Final Note
  • Compiler and debugger are helpful
  • BUT dont rely on them to catch all your program
    bugs
  • The most effective way is to design and write
    your code with care
Write a Comment
User Comments (0)
About PowerShow.com