• No results found

Configuration

Whilst manual configuration is often unnecessary, it can be used to adjust the memory checks and pro- tection, or to alter the information which is gathered. A summary of the settings is displayed on the Run dialog in the Memory Debugging section.

To examine or change the options, select the Details button adjacent to the Memory Debugging checkbox in the Run dialog, which then displays the Memory Debugging Options window.

Figure 77: Memory Debugging Options

The two most significant options are:

1. Preload the memory debugging library—when this is checked, DDT will automatically load the memory debugging library. DDT can only preload the memory debugging library when you start a program in DDT and it uses shared libraries.

Preloading is not possible with statically-linked programs or when attaching to a running process. See section12.3.1 Static Linkingfor more information on static linking.

When attaching, you can set the DMALLOC_OPTIONS environment variable before running your program, or see section12.3.3 Changing Settings at Run Timebelow.

2. The box showing C/Fortran, No Threads in the screen shot. You should choose the option that best matches your program—it is often sufficient to leave this set to C++/Threaded rather than continually changing this setting.

The Heap Debugging section allows you to trade speed for thoroughness. The two most important things to remember are:

1. Even the fastest (leftmost) setting will catch trivial memory errors such as deallocating memory twice.

2. The further right you go, the more slowly your program will execute. In practice, the Balanced setting is still fast enough to use and will catch almost all errors. If you come across a memory error that is difficult to pin down, choosing Thorough might expose the problem earlier, but you will need to be very patient for large, memory intensive programs. (Also see12.3.3 Changing Settings at Run Time).

You can see exactly which checks are enabled for each setting in the Enabled Checks box. See section

12.3.2 Available Checksfor a complete list of available checks.

You can turn on Heap Overflow/Underflow Detection to detect out-of-bounds heap access. See section

12.4.3 Writing Beyond An Allocated Areafor more details.

Almost all users can leave the heap check interval at its default setting. It determines how often the mem- ory debugging library will check the entire heap for consistency. This is a slow operation, so it is normally performed every 100 memory allocations. This figure can be changed manually—a higher setting (1000 or above) is recommended if your program allocates and deallocates memory very frequently (e.g. inside a computation loop).

If your program runs particularly slowly with Memory Debugging enabled you may be able to get a modest speed increase by disabling the Store backtraces for memory allocations option. This disables stack backtraces in the View Pointer Details and Current Memory Usage windows, support for custom allocators and cumulative allocation totals.

It is possible to enable Memory Debugging for only selected MPI ranks by checking the Only enable for these processes option and entering the ranks which you want to it for.

Note: The Memory Debugging library will still be loaded into the other processes, but no errors will be reported.

Click on OK to save these settings, or Cancel to undo your changes.

Note: Choosing the wrong library to preload or the wrong number of bits may prevent DDT from starting your job, or may make memory debugging unreliable. You should check these settings if you experience problems when memory debugging is enabled.

12.3.1

Static Linking

If your program is statically linked then you must explicitly link the memory debugging library with your program in order to use the Memory Debugging feature in DDT.

To link with the memory debugging library you must add the appropriate flags from one of the tables below at the end of the link command, but before every occurrence of -lc (if present).

12.3.1.1 Static linking on most systems Multi-thread C++ Bits Library

no no 64 -L/path/to/ddt/lib/64 -ldmalloc -Wl,--

allow-multiple-definition

yes no 64 -L/path/to/ddt/lib/64 -ldmallocth -Wl,--

allow-multiple-definition

no yes 64 -L/path/to/ddt/lib/64 -ldmallocxx -Wl,--

allow-multiple-definition

yes yes 64 -L/path/to/ddt/lib/64 -ldmallocthcxx -Wl,--

allow-multiple-definition

no no 32 -L/path/to/ddt/lib/32 -ldmalloc -Wl,--

allow-multiple-definition

yes no 32 -L/path/to/ddt/lib/32 -ldmallocth -Wl,--

allow-multiple-definition

no yes 32 -L/path/to/ddt/lib/32 -ldmallocxx -Wl,--

allow-multiple-definition

yes yes 32 -L/path/to/ddt/lib/32 -ldmallocthcxx -Wl,--

allow-multiple-definition

Note that -z muldefs is equivalent to -Wl,--allow-multiple-definition in the above. See section E.6 Intel Compilers and section E.8 Portland Group Compilersfor compiler-specific informa- tion.

12.3.1.2 Static linking on Cray

Multi-thread C++ Bits Library

no no 64 -L/path/to/ddt/lib/64 -Wl,-- undefined=malloc -ldmalloc yes no 64 -L/path/to/ddt/lib/64 -Wl,-- undefined=malloc -ldmallocth no yes 64 -L/path/to/ddt/lib/64 -Wl,-- undefined=malloc -ldmallocxx

yes yes 64 -L/path/to/ddt/lib/64 -Wl,--

undefined=malloc -ldmallocthcxx no no 32 -L/path/to/ddt/lib/32 -Wl,-- undefined=malloc -ldmalloc yes no 32 -L/path/to/ddt/lib/32 -Wl,-- undefined=malloc -ldmallocth no yes 32 -L/path/to/ddt/lib/32 -Wl,-- undefined=malloc -ldmallocxx

yes yes 32 -L/path/to/ddt/lib/32 -Wl,--

12.3.2

Available Checks

The following heap checks are available and may be enabled in the Enable Checks box:

Name Description

basic Detect invalid pointers passed to memory functions (malloc, free, ALLOCATE, DEALLOCATE, etc.)

check-funcs Check the arguments of addition functions (mostly string operations) for invalid point- ers.

check-heap Check for heap corruption (e.g. 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 Initialise the bytes of new allocations with a known value.

free-blank Overwrite the bytes of freed memory with a known value.

check-blank Check to see if space that was blanked when a pointer was allocated or when it was freed has been overwritten. Enables alloc-blank and free-blank.

realloc-copy Always copy data to a new pointer when re-allocating a memory allocation (e.g. due to realloc)

free-protect Protect freed memory where possible (using hardware memory protection) so subse- quent read/writes cause a fatal error.

12.3.3

Changing Settings at Run Time

You can change most Memory Debugging settings while your program is running by selecting the Control → Memory Debugging Options menu item. In this way 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 turn on more options when the breakpoint is hit.