Pages

Sunday, November 1, 2015

How to integrate Cppcheck with Microsoft Visual Studio


  1. Download the latest version of Cppcheck from here.
  2. Open Microsoft Visual Studio IDE.
  3. In Visual Studio, open menu Tools -> External Tools.... The External Tools window will appear.
  4. Click Add button.
  5. Set Title field as Cppcheck (This can be set to any value).
  6. Set Command field to the path to cppcheck.exe (The ... button pops an Open File dialog box to select the required file).
  7. Set Arguments field to the parameters passed to cppcheck.exe (--verbose --enable=all --template=vs *.cpp *.h *.c).
    --verbose: Output more detailed error information.
    --enable=all : Enable all messages including errors, warnings, performance messages, information messages, unused function checks, style messages.
    --template=vs : Show the output in Visual Studio compatible format.
    For extended list of arguments supported by Cppcheck, refer user manual available here.
  8. Set Initial directory to $(ItemDir).
  9. Check Use Output window to redirect the Cppcheck outputs to the Visual Studio Output window.
  10. Click OK. Cppcheck should appear on the Tools menu.

To use Cppcheck, select Cppcheck menu entry on Tools menu.

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. 

Tuesday, March 11, 2014

Preprocessor to control printf debugging

A fundamental way of debugging an application, especially developed using  C / C++ programming languages is "printf debugging". i.e. To dump a message on to console output with some variables.

However, including too many "printf debugging" statements can hinder the performance of an application. Therefore, it is important to include a mechanism to automatically remove all such debugging statements. The easiest way to achieve this is through conditional compilations.

One straight forward way is to wrap the printf statements within a preprocessor directive as follows.


#ifdef _DEBUG
    printf("Debug message\n");
#endif


This approach adds too much clutter into the source code. Therefore, I was looking for a elegant solution to this fundamental problem and came across the following code block.

Saturday, February 22, 2014

Download YouTube videos with VLC Media Player

Saving  YouTube media files on the computer for offline viewing is easier once we have made all the configurations in the VLC media player as given here.
  1. Under Tools menu, select Codec Information (Ctrl + J).
  2. Copy the URL given as Location (As highlighted below), in the Current Media Information popup window.  

Friday, February 14, 2014

Play YouTube videos with VLC Media Player

I was searching the internet for a way to play YouTube videos with special audio and video effects like color correction, hue & contrast adjustment and other special effects. It was quite a surprise to learn that the solution was within my fingertips all the time. 

Countless times, videos have been viewed using VLC media player, simply by double clicking the file on Windows Explorer. Therefore, the Media menu rarely attracted attention and the solution was silently waiting there to be explored.

Here are the simple steps.

Friday, February 7, 2014

FTP made easy with LFTP

I was looking for a decent FTP client program to perform a relatively complex series of file transfers using a Linux shell script and came across LFTP.

LFTP is a freely available file transfer program which allows FTP, HTTP and a number of other connections to a remote host.

A few of the evaluation commands I tried with LFTP are listed here as a future reference to my self as well as anyone looking for quick examples.