Debugging Tactics Flashcards
Basic debugging tactics
- commenting out the code
- validating the code flow
- printing values
Validating code flow
Used when the program is calling to a function too many or few times.
Using validating code flow
By placing statements at the top of the function to print the functions name
Use std::cerr and do not indent the debug statements
Printing values
Used when the program is calculating or passing wrong value
Using printing values
By outputting the value of variables and expressions by using std::cerr
Why not to use debug statements
- clutter the code
- clutter the output of the program
- must be removed, it is not reusable
- requires modification which can introduce new bugs
Conditionalizing the debugging code
To make the debugging statements conditional using preprocessor directives
Using conditionalizing the debugging code
With #define ENABLE_DEBUG by commenting/uncommenting it
Conditionalizing the debugging code in multi-file program
Use #define ENABLE_DEBUG in a header file in all code files
Log file
File stored in disk, that records events that occur in the software
Logging
Process of writing information to a log file
Advantages of log file
- aviding clutter, because it is stored on a separate file
* can be sent to others for diagnosis
Program state
Tracked value of variables , called function and current point of execution within the program
Debugger
Computer program that allows the programer to control how a program executes and examin the program state while the program is running
Advantige of debugger
Ability to precisily control execution of the program and ability to view/modify program’s state
Stepping
Set of related debugger features that let us execute (step through) our code statement by statement
Step into
That executes the next statement in the normal execution path of the program, and pauses so you can inspect the code
Stepping into without running
- the program will recompile
- will begin to run
- will open diagnostic windows
Step over
Executes an entire function without stepping, use it when you know a function works