Debugging with GDB (September 2007)
Chapter 14: HP-UX Configuration-Specific Information 147
are freed, WDB verifies whether these patterns are intact. If they are corrupted, an
underflow or overflow must have occurred and WDB reports the problem. If you want
to find corruption at any time, use the info corruption command.
The info corruption command can detect memory corruption in an application. That
is, it reports all the memory blocks that have ove r-writes and under-writes.
Syntax:
info corruption [<file name>]
The run time memory checking must be enabled before using the info corruption
command to detect memory corruption. The corruption information is written to a file
specified in the .file name argument if provided. Otherwise, it is printed to the stdout.
Note: Turning on bounds checking increases the program’s memory re-
quirements because the extra guard bytes must be allocated at the begin-
ning and end of each block.
14.10.8.3 Stop when a specified block address is allocated or
deallocated
To stop a program whenever a block at a specified address is allo cate d or deallocated,
use the command:
set heap-check watch address
You can use this to debug situations such as multiple free() calls to the same block.
Limitation : This is not supported in batch mode debugging.
14.10.8.4 Scramble previous memory contents at malloc/free
calls
WDB enables you to p otentially expose latent memory access defects with the com-
mand:
• In Interactive debugging mode: set heap-check scramble [on | off]
• In batch mode debugging: scramble_blocks [on | off].
When this setting is turned on, any time a memory block is allocated or deallocated,
WDB scrambles the space and overwrites it with a spe cific pattern.
This change to the memory contents increases the chance that erroneous behaviors will
cause the program to fail. Examples of such b ehavior include attempting to access
space that is freed or depending on initial values of malloc() blocks.
You can now look at the stack trace to understand where and how the problem occurred.
Note: Turning on scrambling slows down the program slightly, because at
every malloc() and free() call, the space involved must be overwritten.
14.10.9 Comparison of Memory Debugging Commands in
Interactive Mode and Batch Mode
HP WDB 5.6 and later versions provide consistency in format for the batch mode
options and the interactive mode c ommands.