Debugging Dynamic Memory Usage Errors Using HP WDB (766161-001, March 2014)
Error Injection
WDB supports error injection features to debug out-of-memory events in an application. It enables
you to simulate out-of-memory conditions in an application and analyze the behavior of the
applications under such conditions. In addition, it enables you to gain control over program
execution when an out-of-memory event occurs.
To simulate an out-of-memory condition, you must use the set heap-check null-check
command to force malloc() to return NULL after <N> or a random number of allocations. After
simulating the out-of-memory error, you can use the catch nomem command to gain control over
the execution when an out-of-memory error occurs.
Table 8 lists the commands available for error injection.
Table 8 Commands for Error Injection
DescriptionCommand
Forces malloc() to return NULL after <N> invocations of
malloc().
set heap-check null-check <N>
Example 4 (page 24) illustrates the use of this command.
Forces malloc() to return NULL after <N> bytes are
allocated by the program.
set heap-check null-check-size <N>
Example 5 (page 26) illustrates the use of this command.
Forces malloc() to return NULL after random number of
invocations of malloc().
set heap-check null-check random
Example 6 (page 28) illustrates the use of this command.
Defines the range for random number calculation for the
set heap-check null-check random command
set heap-check random-range <N>
Defines the seed-value for random number calculation for
the set heap-check null-check random command
set heap-check seed-value <N>
Enables the user to gain control over an out-of-memory
event. The user can step through program execution after
the nomem event is detected.
catch nomem
Memory-Debugging Features of WDB 23