Debugging with GDB Manual The GNU Source-Level Debugger (769148-001, March 2014)
Scenarios in memory debugging
Stop when freeing unallocated or deallocated blocks
HP WDB enables you to locate improper calls to free() and realloc(), with the command:
– In interactive debugging mode: set heap-check free [on | off].
– In batch mode debugging: check_free [on | off].
With this setting on, whenever the program calls free() or realloc() HP WDB inspects the
parameters to verify that they are pointing to valid currently allocated heap blocks.
If HP WDB detects an erroneous call to free(), it stops the program and reports this condition.
You can then look at the stack trace to understand where and how the problem occurred.
Stop when freeing a block if bad writes occurred outside block boundary
HP WDB enables you to locate problems caused by heap block over flow or underflow with the
command
– In Interactive debugging mode: set heap-check bounds [on | off]
– In batch mode debugging: check_bounds [on | off]
When bounds checking is turned on, HP WDB allocates extra space at the beginning and end of
a block during allocation and fills it up with a specific pattern. When blocks are freed, HP WDB
verifies whether these patterns are intact. If they are corrupted, an under flow or over flow must
have occurred and HP 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 over-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 requirements because the
extra guard bytes must be allocated at the beginning and end of each block.
Stop when a specified block address is allocated or deallocated
To stop a program whenever a block at a specified address is allocated 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.
Scramble previous memory contents at malloc/free calls
HP WDB enables you to potentially expose latent memory access defects with the command:
– 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, HP WDB
scrambles the space and overwrites it with a specific pattern.
128 HP-UX Configuration-Specific Information