Popular Posts

Tuesday, December 23, 2008

Debugging, Profiling, Memory Leaks and more!

I have been searching for open source tools to assist in detecting memory leaks and application profiling. Also, static code analysis was another goal.

For static code analysis I found:
CppCheck (http://en.wikipedia.org/wiki/Cppcheck)

I used it to its full power by invoking (at the top level of the project):

cppcheck --recursive --all --errorsonly --style

Also, SPlint (http://en.wikipedia.org/wiki/SPlint) seems promising, though it is for C code only (no C++).

A comprehensive list of static code analysis could be found in Wikipedia:
http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis

About application profiling, the GNU Profiler (gprof) does a good job. It is light-weight and has support in GCC. This is an excellent article about using gprof:
Of course, you can best visualize the output of gprof using the (kprof) KDE front-end.

Memory leak detection has many options. Of the best is using Valgrind(http://valgrind.org/). However, I found an interesting and promising feature that has been added to the gcc. This feature is called Mudflap. It is easy to use as a compiler flag and adds memory debugging support directly into your application using libmudflap. More interesting information could be found here:
http://gcc.gnu.org/wiki/Mudflap_Pointer_Debugging
http://gcc.fyxm.net/summit/2003/mudflap.pdf
It is so promising that it will be integrated into the QNX IDE:
http://qnxdevtools.blogspot.com/2008/02/mudflap.html
It can print the memory leaks on program exit via the (-print-leaks) option

Memory debugging tools are so many. There is a list on Wikipedia article:
http://en.wikipedia.org/wiki/Memory_debugger

The task of memory leak detection is achievable using lightwieght tools. These tools basically replaces the default C library malloc() and free() with special debugging implementations. Notable is mtrace(), the memory debugger built in the GNU C library:
http://en.wikipedia.org/wiki/Mtrace

A good article about memory leak detection in C++:
http://www.linuxjournal.com/article/6556

And finally, all what you can dream of are collected in one article, in the GRASS wiki here:
http://josef.fsv.cvut.cz/WIKI/grass-osgeo/index.php/GRASS_Debugging


Hope you find this useful!

No comments: