In this tutorial, let’s learn about different debugging approaches adopted by programmers to debug the source code. Identifying errors in a program’s source code and then fixing them is known as debugging.
Some of the debugging approaches are as follows:
- Brute Force Method
- Cause Elimination Method
- Program Slicing
Brute Force Method
In the brute force method, the program is loaded with print statements to print the intermediate values with the hope that some of the printed values will help to identify the statement in error. This approach becomes more systematic with the use of a symbolic debugger (source code debugger) because values of different variables can be easily checked and breakpoints and watchpoints can be easily set to test the values of variables effortlessly. The Brute force method is the least efficient method for debugging.
Backtracking is a common approach for debugging. In the backtracking approach, beginning from the statement at which an error symptom has been observed, the source code is tracked backward until the error is discovered. Unfortunately, as the number of source lines to be traced back increases, the number of potential backward paths increases and may become unmanageably large thus limiting the use of this approach.
Cause Elimination Method
In the cause-elimination method approach, a list of causes that could possibly have contributed to the error symptom is developed and tests are conducted to eliminate each error. A related technique of identification of the error from the error symptom is the software fault tree analysis.
The program-slicing technique is similar to backtracking. Here the search space is reduced by defining slices. A slice of a program for a particular variable and particular statement is the set of source lines preceding this statement that can influence the value of the variable.
Once errors are identified in a program code, it is necessary to first identify the precise program statements responsible for the errors and then fix them.