Alternatives To Valgrind

Unfortunately, Valgrind does not support OS X 10.8 yet. After some Googling, I came across some forum posts where people were able to get it to compile and 'almost' link. Does anyone know of any good alternatives to Valgrind for memory leak detection? The Valgrind tool suite provides a number of debugging and profiling tools that help you make your programs faster and more correct. The most popular of these tools is called Memcheck. It can detect many memory-related errors that are common in C and C programs and that can lead to crashes and unpredictable behaviour. I don't think it is that bad either, given the alternatives. If one is going to fill this with boost::tostring or boost::lexicalcast or std::tostring, these functions would be doing the same thing internally (and several times). – alfC Dec 2 '20 at 21:09.

Valgrind

The Valgrind distribution includes the following debugging andprofiling tools:

Alternatives To Valgrind

Memcheck

Memcheck detects memory-management problems, and is aimedprimarily at C and C++ programs. When a program is run underMemcheck's supervision, all reads and writes of memory arechecked, and calls to malloc/new/free/delete are intercepted. Asa result, Memcheck can detect if your program:

  • Accesses memory it shouldn't (areas not yet allocated, areas that have been freed, areas past the end of heap blocks, inaccessible areas of the stack).
  • Uses uninitialised values in dangerous ways.
  • Leaks memory.
  • Does bad frees of heap blocks (double frees, mismatched frees).
  • Passes overlapping source and destination memory blocks to memcpy() and related functions.

Memcheck reports these errors as soon as they occur, givingthe source line number at which it occurred, and also a stacktrace of the functions called to reach that line. Memcheck tracksaddressability at the byte-level, and initialisation of values atthe bit-level. As a result, it can detect the use of singleuninitialised bits, and does not report spurious errors onbitfield operations. Memcheck runs programs about 10--30x slowerthan normal.

Cachegrind

Cachegrind is a cache profiler. It performs detailedsimulation of the I1, D1 and L2 caches in your CPU and so canaccurately pinpoint the sources of cache misses in your code. Itidentifies the number of cache misses, memory references andinstructions executed for each line of source code, withper-function, per-module and whole-program summaries. It isuseful with programs written in any language. Cachegrind runsprograms about 20--100x slower than normal.

Callgrind

Callgrind, by Josef Weidendorfer, is an extension to Cachegrind. It provides all theinformation that Cachegrind does, plus extra information aboutcallgraphs. It was folded into the main Valgrind distribution in version 3.2.0. Available separately is an amazing visualisation tool, KCachegrind, which gives a much better overview of the data that Callgrind collects;it can also be used to visualise Cachegrind's output.

Massif

Massif is a heap profiler. It performs detailed heap profilingby taking regular snapshots of a program's heap. It produces agraph showing heap usage over time, including information aboutwhich parts of the program are responsible for the most memoryallocations. The graph is supplemented by a text or HTML filethat includes more information for determining where the mostmemory is being allocated. Massif runs programs about 20x slowerthan normal.

Helgrind

Helgrind is a thread debugger which finds data races inmultithreaded programs. It looks for memory locations which areaccessed by more than one (POSIX p-)thread, but for which noconsistently used (pthread_mutex_) lock can be found. Suchlocations are indicative of missing synchronisation betweenthreads, and could cause hard-to-find timing-dependentproblems. It is useful for any program that uses pthreads. It isa somewhat experimental tool, so your feedback is especiallywelcome here.

DRD

DRD is a tool for detecting errors in multithreaded C and C++ programs. Thetool works for any program that uses the POSIXthreading primitives or that uses threading concepts built on top of thePOSIX threading primitives. While Helgrind can detect locking orderviolations, for most programs DRD needs less memory to perform its analysis.

Lackey, Nulgrind

Lackey and Nulgrind are also included in theValgrind distribution. They don't do very much, and are therefor testing and demonstrative purposes.

DHAT

Valgrind

DHAT is a tool for examining how programs use their heap allocations. Ittracks the allocated blocks, and inspects every memory access to find whichblock, if any, it is to. It comes with a GUI to facilitate exploring theprofile results.

Experimental Tools

BBV

A basic block is a linear section of code with one entry point and one exitpoint. A basic block vector (BBV) is a list of all basic blocks entered duringprogram execution, and a count of how many times each basic block was run.

BBV is a tool that generates basic block vectors for use with the SimPointanalysis tool.

SGCheck

Alternatives To Valgrind

SGCheck is a tool for finding overruns of stack and global arrays. It worksby using a heuristic approach derived from an observation about the likely formsof stack and global array accesses.

Other Tools

Several other Valgrind tools have been created: you can find alist of them on the Variants / Patchespage.

Valgrind Memcheck is a tool for detecting memory-usage problems such as leaks, invalid memory access, incorrect freeing, and referencing undefined values.

Valgrind integration in CLion works on Linux, macOS, and Windows via WSL (see Valgrind on WSL ).

Configure Valgrind

  1. Install Valgrind on your system.

    For WSL, install Valgrind on your WSL instance (sudo apt-get install valgrind) and provide CLion with the path to the executable (see next steps).

  2. In CLion, go to Settings / Preferences | Build, Execution, Deployment | Dynamic Analysis Tools | Valgrind.

  3. CLion will attempt to detect the Valgrind binary by searching in standard locations defined in the system PATH variable.

    In case of a non-standard Valgrind location, set the path manually in the Valgrind executable field.

  4. Specify analysis options or use the default ones.

  5. Optionally, configure the list of the suppression files. For example, you may want to add a suppression file to turn off the Valgrind checks for some particular libraries.

To use Valgrind on Windows via WSL, provide the 'subsystem' path to Valgrind, which is /usr/bin/valgrind by default, instead of the actual Windows location of the Valgrind binary. However, this path will not be valid until you select the CMake profile connected to the WSL toolchain. For this, do one of the following:

  • Set the WSL toolchain as default. This way, it will automatically connect to the default CMake profile:

  • Create a separate CMake profile, connect it to the WSL toolchain, and select this profile in the configurations switcher:

Run targets

To run a target (application or test) with Valgrind Memcheck, do one of the following:

  • Click the gutter icon and select Run 'your_target_name' with Valgrind Memcheck option from the menu:

  • Select the desired Run/Debug configuration and call Run | Run 'your_target_name' with Valgrind Memcheck from the main menu or click the dedicated toolbar icon:

If Valgrind was not configured previously, CLion will open the configuration dialog.

Explore results

  • When the launch is finished, open the Valgrind tab in the Run tool window.

  • The left-hand pane shows the list of all problems found by Valgrind Memcheck. Each entry includes the instruction pointer, problematic function name, and (if possible) the source file where the problem is located.

  • In the right-hand pane, you can find full stack frame description and the corresponding code preview (when possible).

    Press F4 to jump back to the source code.

Export and import results

Alternatives To Valgrind On Windows

  • To export the results, click the Export icon in the left pane of the Valgrind tab and specify the destination XML file: Note that the Export button is unavailable during execution.

  • To import the results, select Run | Import Valgrind XML Results from the main menu and choose the XML file to import from.