Debugging Dynamic Memory Usage Errors Using HP WDB (766161-001, March 2014)

When a stray pointer overflows the bounds of a heap block, or tries to access a heap block
that is already freed to cause buffer overruns and under-runs
When reading or writing to memory locations that are already freed in the program
NOTE: WDB provides minimal support for debugging some of the memory access errors. The
scrambling feature and detection for out-of-bounds writes are supported by WDB.
Using WDB to Debug Memory Problems
WDB supports the memory-debugging of applications involving dynamic allocations and
de-allocations of virtual memory blocks, or during the calls to libc string routines like strcpy(),
and memcpy(). It debugs memory-related problems at the time of allocation or de-allocation of
memory blocks. It supports the detection of outstanding memory-related problems at specific
user-defined probe-points (breakpoints) during the use of the memory blocks. Memory-related
problems that appear after the specified probe points are not detected. It does not support the
debugging of access errors that are caused when reading from or writing to unallocated,
uninitialized, or de-allocated memory.
WDB does not support the memory-debugging of the stack, static memory, and register memory.
WDB provides interactive, batch, attach and rtc-api modes for debugging memory-related problems.
See “Supported Modes of Memory-debugging in WDB” (page 48) for more information on the
supported modes for debugging.
HP aC++/ HP C Compiler Runtime Checking Options
The HP aC++/HP C compiler also provides options for enabling memory debugging using WDB
in Integrity Systems. This feature is supported only on Integrity Systems.
Table 2 list the runtime checking options are available in HP aC++/HP C compilers for memory
debugging.
Table 2 Compiler Options for Memory Debugging
DescriptionCompiler Option
The +check compiler options provide runtime checks to
detect out-of-bounds array references (+check=bounds),
+check=
[all|none|bounds|malloc|stack|uninit]
memory leaks and heap corruption (+check=malloc),
writing outside the stack frame(+check=stack), and
uninitialized variables (+check=uninit). The
+check=all option enables all the available runtime
checks for the +check compiler option.
A failed check results in the program abort at runtime. The
error message and the stack trace is printed to stderr
before the program terminates. The environment variable
RTC_NO_ABORT must be set to 1 to continue the program
execution after a failed runtime check. This enables you to
collect the diagnostics for all the failed checks in a single
execution run.
NOTE: The +check options must be specified at compile time and link time. If different +check
options are specified while compiling different source files, all the specified +check options are
needed at link time. Multiple +check options are interpreted from left to right with the options on
the right overriding earlier +check options.
For more information on the HP aC++ compiler options for memory debugging, see the HP aC++
World Wide Webpage at:
http://www.hp.com/go/cpp
Using WDB to Debug Memory Problems 9