Memory debugging options

Manual configuration is often unnecessary, but it can be used to adjust the memory checks and protection, or to alter the information which is gathered.

The current settings are displayed in the Memory Debugging section on the Run dialog.

To examine or change the settings, click Details adjacent to the Memory Debugging checkbox. The Memory Debugging Options window displays.

Memory Debugging Options

The available settings are:

Note

If you choose the wrong library to preload, or the wrong number of bits, your job might not start, or might make memory debugging unreliable. You should check these settings if you experience problems when memory debugging is enabled.

Static linking

If your program is statically linked you must explicitly link the memory debugging library with your program to use the memory debugging feature.

To link with the memory debugging library, you must add the appropriate flags from the table below at the very beginning of the link command. This ensures that all instances of allocators, in both user code and libraries, are wrapped. Any definition of a memory allocator preceding the memory debugging link flags can cause partial wrapping, and unexpected runtime errors.

Note

If in doubt use libdmallocthcxx.a.

Multi-thread C++ Bits Linker Flags
no no 64 -Wl, –allow-multiple-definition, –undefined=malloc /path/to/ddt/lib/64/libdmalloc.a
yes no 64 -Wl, –wrap=dlopen, –wrap=dlclose, –allow-multiple-definition, –undefined=malloc /path/to/ddt/lib/64/libdmallocth.a
no yes 64 -Wl, –allow-multiple-definition, –undefined=malloc, –undefined=_ZdaPv /path/to/ddt/lib/64/libdmallocxx.a
yes yes 64 -Wl, –wrap=dlopen, –wrap=dlclose, –allow-multiple-definition, –undefined=malloc, –undefined=_ZdaPv /path/to/ddt/lib/64/libdmallocthcxx.a

Where

  • –undefined=malloc has the side effect of pulling in all libc-style allocator symbols from the library.
  • –undefined works on a per-object-file level, rather than a per-symbol level, and the c++ and c allocator symbols are in different object files within the library archive. Therefore, you may also need to specify a c++ style allocator such as _ZdaPv below.
  • –undefined=_ZdaPv has the side effect of pulling in all c++ style allocator symbols. It is the c++ mangled name of operator delete[].

To link the correct library, use the full path to the static library. This is more reliable than using the -l argument of a compiler.

See Intel compilers or Portland Group and NVIDIA HPC SDK compilers for compiler-specific information.

Available checks

The following heap checks are available in Enable Checks:

Name Description
basic Detect invalid pointers passed to memory functions (such as malloc, free, ALLOCATE, and DEALLOCATE)
check-funcs Check the arguments of addition functions (mostly string operations) for invalid pointers.
check-heap Check for heap corruption, for example, due to writes to invalid memory addresses.
check-fence Check the end of an allocation has not been overwritten when it is freed.
alloc-blank Initialize the bytes of new allocations with the known value of dmalloc-alloc byte (hex 0xda, decimal 218).
free-blank

Overwrite the bytes of freed memory with the known value of the dmalloc-free byte (hex 0xdf, decimal 223).

If this check is enabled, the library overwrites memory when it is freed, using dmalloc-free. This can be used, for example, to check for corrupted allocations.

This also checks and reports when a free byte has been written to, which can indicate if a freed pointer is being used.

check-blank Check to see if blanked space has been overwritten. Space is blanked when it either has a pointer allocated to it, or the pointer has been freed. This enables alloc-blank and free-blank.
realloc-copy Always copy data to a new pointer when reallocating a memory allocation (for example, due to realloc).
free-protect Protect freed memory where possible (using hardware memory protection) so subsequent read/writes cause a fatal error.

Change settings at run time

You can change most memory debugging settings while your program is running by selecting Control > Memory Debugging Options. This means you can enable memory debugging with a minimal set of options when your program starts, set a breakpoint at a place you want to investigate for memory errors, then switch on more settings when the breakpoint is hit.