Debugging Dynamic Memory Usage Errors Using HP WDB
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().
Example 4 (page 31) illustrates the use of this command.
set heap-check null-check <N>
Forces malloc() to return NULL after <N> bytes are
allocated by the program.
Example 5 (page 33) illustrates the use of this command.
set heap-check null-check-size <N>
Forces malloc() to return NULL after random number
of invocations of malloc().
Example 6 (page 35) illustrates the use of this command.
set heap-check null-check random
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
30