7.1. Debugging by Brute Force
The most common scheme for debugging a program is the "brute force" method. It is popular because it requires little thought and is the least mentally taxing of the methods, but it is inefficient and generally unsuccessful.
Brute force methods can be partitioned into at least three categories:
Debugging with a storage dump.
Debugging according to the common suggestion to "scatter print statements throughout your program."
Debugging with automated debugging tools.
The first, debugging with a storage dump (usually a crude display of all storage locations in hexadecimal or octal format) is the most inefficient of the brute force methods. Here's why:
It is difficult to establish a correspondence between memory locations and the variables in a source program.
With any program of reasonable complexity, such a memory dump will produce a massive amount of data, most of which is irrelevant.
A memory dump is a static picture of the program, showing the state of the program at only one instant in time; to find errors, you have to study the dynamics of a program (state changes over time).
A memory dump is rarely produced at the exact point of the error, so it doesn't show the program's state at the point of the error. Program actions between the time of the dump and the time of the error can mask the clues you need to find the error.
There aren't adequate methodologies for finding errors by analyzing a memory dump (so many programmers stare, with glazed eyes, wistfully ...
Get The Art of Software Testing, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.