Debugging is an art rather than a science, and it is a very big topic in itself. Strong debugging skills are the strengths of a good developer. All expert developers have some common traits, of which strong problem-solving and debugging skills top all. The first step in fixing a bug is to reproduce the issue. It is crucial to capture the steps involved in reproducing the bug very efficiently. Experienced QA engineers will know the importance of capturing detailed steps to reproduce, as developers will find it difficult to fix an issue if they can't reproduce it.
From my point of view, a bug that can't be reproduced can't be fixed. One could make guesses and beat around the bush but can't be sure whether the issue has really been fixed without being able to reproduce the bug in the first place.
The following details will help developers reproduce and debug the issue more quickly:
- Detailed steps to reproduce the issue
- Screenshot images of the bug
- Priority and severity
- Inputs and scenarios that reproduce the issue
- Expected and actual output
- Error logs
- Application logs and traces
- Dump files in case the application crashes
- Environment details
- OS details
- Software versions
Some commonly used debugging techniques are as follows:
- Use of the cout/cerr print statements comes in really handy
- Core dumps, mini dumps, and full dumps help analyze the bug remotely
- Using debugging tools to execute the code step by step by inspecting variables, arguments, intermediate values, and so on
- Test frameworks help prevent the issue in the first place
- Performance analysis tools can be of great help in finding performance issues
- Tools that deduct memory leaks, resource leaks, deadlocks, and so on
The log4cpp open source C++ library is an elegant and useful log utility which helps add debug messages that support debugging, which can be disabled in the release mode or in the production environment.