Dynamic code analysis for C++ - c++

Is there an open source and (relatively) simple-to-use dynamic code analysis tool for C++ code?
Something like IBM Purify (memory corruption detection, memory leak detection, application performance profiling, etc.)

The software that is widely used (on Linux at least) is Valgrind. It has a lot of sub tools used to do what you are looking for.
There is also KCacheGrind which is a GUI frontend to the profiling tool of Valgrind, AKA Cachegrind.

Try Duma (Detect Unintended Memory Access).

Try Valgrind. It is not as powerful as IBM Purify, but it works quite fine...

CodeCompass is quite good as well.
Although it has quite the dependencies compared to Valgrind and Duma, it's a quality analysis tool.

Related

How to Detect Memory leaks for Qt windows desktop application, using QtCreator [duplicate]

Lately I have been developing in C++ with QT Creator. All is well and I'm nearly at the point of packaging and distributing my application. But obviously before any release you better make sure you have everything right. So I'm at the testing stage, and something tells me that I have some slight memory issues. Nothing serious, but I like to obsess over these ;-).
So I decided to try some memory leak detection libraries. For starters I looked at this question. I disregarded Purify and Insure++ because of the costs. Someone else suggested to use the MSVC compiler so I could use the CRT memory validation routines. Which I considered but decided against for now because of the implications it would have on using the debugger from within QT Creator.
Then I stumbled across DUMA which I got to compile using the MinGW32 compiler that comes with QT. However, I found that it doesn't really play well with QT because of the incredible amount of segmentation faults. I know they are how DUMA works, but I'm pretty sure I did not screw things up as much as DUMA tried to make me believe.
Another something I tried was the google-performance-tools which I sadly cannot get to compile with the MinGW32 version supplied with QT, even if I add in the required dependencies.
All of this brings me to my question: Is there any working solution out there for QT Creator developers that want to check their programs for memory leaks?
Thanks,
Personally, I find the valgrind / memcheck / callgrind / kcachegrind combo to be too powerful to pass up for memory leaks and performance analysis. Being free (gratis) is especially nice since I cannot personally afford the cost of some of these other professional tools.
I've been working on a cross platform Qt application for a couple years now. As I develop, I bounce back and forth between windows and linux when I want to test features and functionality. However, I always do my performance analysis in linux. The memory leaks and performance concerns that I find are always ones that are injected by my team of developers on top of Qt. So when these problems are fixed, regardless of being identified in Linux, the benefits will carry over into windows.
I suggest you investigate setting up a pure linux build environment that you can test in. Perhaps the easiest solution for you would be to create a virtual machine to do your performance analysis on. My preferred combination is VirtualBox and Ubuntu.
May be you can use these libs for windows
Hooks for Malloc [gnu.org]
Backtrace [gnu.org]
valgrind [valgrind.org]

Memory leak checking on Windows with QT and MinGW32

Lately I have been developing in C++ with QT Creator. All is well and I'm nearly at the point of packaging and distributing my application. But obviously before any release you better make sure you have everything right. So I'm at the testing stage, and something tells me that I have some slight memory issues. Nothing serious, but I like to obsess over these ;-).
So I decided to try some memory leak detection libraries. For starters I looked at this question. I disregarded Purify and Insure++ because of the costs. Someone else suggested to use the MSVC compiler so I could use the CRT memory validation routines. Which I considered but decided against for now because of the implications it would have on using the debugger from within QT Creator.
Then I stumbled across DUMA which I got to compile using the MinGW32 compiler that comes with QT. However, I found that it doesn't really play well with QT because of the incredible amount of segmentation faults. I know they are how DUMA works, but I'm pretty sure I did not screw things up as much as DUMA tried to make me believe.
Another something I tried was the google-performance-tools which I sadly cannot get to compile with the MinGW32 version supplied with QT, even if I add in the required dependencies.
All of this brings me to my question: Is there any working solution out there for QT Creator developers that want to check their programs for memory leaks?
Thanks,
Personally, I find the valgrind / memcheck / callgrind / kcachegrind combo to be too powerful to pass up for memory leaks and performance analysis. Being free (gratis) is especially nice since I cannot personally afford the cost of some of these other professional tools.
I've been working on a cross platform Qt application for a couple years now. As I develop, I bounce back and forth between windows and linux when I want to test features and functionality. However, I always do my performance analysis in linux. The memory leaks and performance concerns that I find are always ones that are injected by my team of developers on top of Qt. So when these problems are fixed, regardless of being identified in Linux, the benefits will carry over into windows.
I suggest you investigate setting up a pure linux build environment that you can test in. Perhaps the easiest solution for you would be to create a virtual machine to do your performance analysis on. My preferred combination is VirtualBox and Ubuntu.
May be you can use these libs for windows
Hooks for Malloc [gnu.org]
Backtrace [gnu.org]
valgrind [valgrind.org]

C++ dynamic review tools

What's the best tool (commercial/open source) you've used for dynamic review/memory analysis of a C++ application?
EDIT: removed 'static' as there is already a great question on this topic (thanks Iulian!)
For dynamic memory analysis definitely Valgrind.
CPPCheck has served me well for a while now. This is for statical analysis.
Ryan, if you are on Windows and using MSVC++, then I can recommend BoundsChecker within DevPartner VC++ edition from Micro Focus. It has a feature within its memory tracking analysis called the Memory Resource Viewer. You use this to mark a point in time then look for allocations from that point forward. This plus the traditional heap corruption and other memory checks should help you dynamically track your C++ heap and stack issues. Shameless plug: I work on the DevPartner team. Look for DPS 10.5 with 64-bit support in BoundsChecker to launch February 4, 2011 at http://www.DevPartner.com.
Valgrind on Linux
Duma on Windows
For static code review KLOCWORKS is good.
For memory profiling, memory leaks identification, devpartner is a very good one.
Microsoft FxCop for static analysis (free). Parasoft Insure ($$$$) or IBM Purify ($$) for dynamic memory analysis.

G++ Multi-platform memory leak detection tool

Does anyone know where I can find a memory memory leak detection tool for C++ which can be either run in a command line or as an Eclipse plug-in in Windows and Linux. I would like it to be easy to use. Preferably one that doesn't overwrite new(), delete(), malloc() or free(). Something like GDB if its gonna be in the command line, but I don't remember that being used for detecting memory leaks. If there is a unit testing framework which does this automatically, that would be great.
This question is similar to other questions (such as Memory leak detection under Windows for GNU C/C++ ) however I feel it is different because those ask for windows specific solutions or have solutions which I would rather avoid. I feel I am looking for something a bit more specific here. Suggestions don't have to fulfill all requirements, but as many as possible would be nice.
Thanks.
EDIT: Since this has come up, by "overwrite" I mean anything which requires me to #include a library or which otherwise changes how C++ compiles my code, if it does this at run time so that running the code in a different environment won't affect anything that would be great. Also, unfortunately, I don't have a Mac, so any suggestions for that are unhelpful, but thank you for trying. My desktop runs Windows (I have Linux installed but my dual monitors don't work with it) and I'd rather not run Linux in a VM, although that is certainly an option. My laptop runs Linux, so I can use that tool on there, although I would definitely prefer sticking to my desktop as the screen space is excellent for keeping all of the design documentation and requirements in view without having to move too much around on the desktop.
NOTE: While I may try answers, I won't mark one as accepted until I have tried the suggestion and it is satisfactory.
EDIT2: I'm not worried about the cross-platform compatibility of my code, it's a command line application using just the C++ libraries.
Valgrind is your best friend. Valgrind has a plugin for eclipse.
"Sadly" Valgrind does not run on Windows, but it runs on Mac OSX, *BSD and Linux, so I'd consider that "multi-platform". :)
Valgrind does "overwrite" new/delete/malloc/free but not during compilation (so you don't have to recompile if that's what you mean). It interprets the binary so the performance suffer a bit during testing.
In newer versions of gcc there is something called leak sanitizer. You just have to add -fsanitize=leak to compile command. Then you run your program normally and at the end, if there was any leak, you'll get summary (in terminal of course).
for 32 bits applications, valgrind + wine can be a working solution as well for windows apps. If your app can be run under wine without any change, then running it under valgrind + wine works well in my (quite limited) experience. Since your app works under Linux, I would guess that your app is likely to run under wine (avoids very windows specific code which is not yet supported in wine).
DUMA is a cross-platform leak detection library which I use for many of my projects. It's nice because you don't have to #include any DUMA-specific header, but just link in the library before you link in your system's libc, which contains the memory allocation routines, and after linking in libstdc++.
It can be kind of tricky to set up, especially when used with C++ projects, but I think that it is well worth the time invested. It has helped me to find a few memory leaks before that I might not have discovered otherwise, and one case where I deleted an allocation twice.
One note: it's much easier if you build a static archive (built by default on Windows) because it helps to reduce "false positives" that are actually caused by leaky runtimes.
There's the leaks tool on MacOS X (i don't know if it exists elsewhere) and i used to use a tool called memprof on linux. There's also valgrind which works on linux and is incredibly awesome but has a substantial performance hit, and ostensibly on macos but i haven't tried it.
I am unaware of any such tools on windows however.
While you mentioned that this isn't preferred the Boehm Garbage Collector can be used to detect memory leaks. Simply put, if the garbage collector is ever actually running then generally you have a memory leak. It's used this way by Mozilla to detect memory leaks in Firefox.

C++ Code Profiler

Can anybody recommend a good code profiler for C++?
I came across Shiny - any good? http://sourceforge.net/projects/shinyprofiler/
Callgrind for Unix/Linux
DevPartner for Windows
Not C++ specific, but AMD's CodeAnalyst software is free and is feature-packed.
http://developer.amd.com/cpu/codeanalyst/codeanalystwindows/Pages/default.aspx
Gprof if you use gcc. It may not be user friendly but still useful.
Probably you will be interested in Intel VTune. Rather useful and allows to collect low-level events like cache misses which helps a lot in tuning.
Quantify (part of the IBM/Rational PurifyPlus package) is a very good profiler, but not exactly cheap. It is available on several platforms, too - I've used it on Solaris, Windows and Linux.
Depends on what you need to do:
Measure, so you can do regressions testing to see if changes in performance happened.
Find reasons for suboptimal performance and optimize them.
These are not the same.
For 1, use one of the recommended profilers.
For 2, the profiler I much prefer is one you already have:
http://www.wikihow.com/Optimize-Your-Program%27s-Performance
To see how this goes, check this out.
For C++, as for C# and any language that encourages layers of abstraction, those layers may or may not be good from a software engineering standpoint, but they can kill performance. Every method call is a detour in the execution of your program, and the style encourages you to nest those things, sometimes needlessly. Also the style discourages you from knowing or caring what goes on inside them. You may find them creating and deleting objects underneath at a rate and level of generality far beyond what your application really needs.
AQtime (for Windows)
If you are running a Premium version of VS 2010 then you get a profiler with it.
I've also used a couple of other free ones, but they don't compare to the on MS ships. Useful as a second opinion though.
If you have access to a Mac, then I recommend using Shark from the CHUD tools.
You can use the analyzer that´s in Sun Studio 12 on Linux or Solaris. Itś free. http://developers.sun.com/sunstudio/index.jsp
If you cannot locate DevPartner it is because we've moved under new ownership. Check us out on the Micro Focus website: http://www.microfocus.com/products/micro-focus-developer/devpartner/index.aspx. Shameless plug: I work on the DevPartner team. Our long awaited 64-bit versions of BoundsChecker and C++/.NET profilers ship on February 4, 2011. We've changed our pricing model so you can choose either the whole suite or just the performance profiler if that's what you need. Please check out the new DPS 10.5 release when it goes live!