Pages

Friday, October 23, 2015

Identify Memory Leaks in Visual CPP Applications

A friend of mine told me about this useful tool to identify hard to find memory leaks in Visual C++ applications. Visual Leak Detector (VLD) is an easy to use memory leak detection system. The installation package can be downloaded from here.

After installation, it can be used with any C/C++ project simply by adding the following line to the code:


#include <vld.h>



When the program is executed under the Visual Studio debugger, Visual Leak Detector will output a memory leak report of the executed segment of the code, at the end of the debugging session. If memory leaks are detected, this report will point to the exact locations in the code segment, which allocated the leaked memory block.

The header file can be easily isolated from rest of the source codes by guarding it with the pre-processor directive block. It can be made further user friendly by defining a separate Visual Studio build configuration for VLD. The steps are as follows.

Monday, October 19, 2015

Debugging with GDB


As discussed here, "printf debugging" is the most straight forward way of figuring out what is happening under the hood, during run time of an C / C++ program. But this approach is a bit time consuming as the code has to be modified and recompiled according to the debugging scenario. A more flexible way is to use a separate debugger program. GDB: The GNU project debugger stands at the top of this list. 

The general practice is to use GDB with an Integrated Development Environment as eclipse, which greatly simplifies the debugging process. However, to debug a program executing within a device which does not have a graphical user interface (for instance an embedded Linux system with a serial console), GDB on a console is a pretty useful option.