Debugging with GDB (February 2008)

Table Of Contents
Chapter 14: HP-UX Configuration-Specific Information 147
Example: set heap-check min-heap-size 100
When the option min-heap-size is set to 100, GDB reports all the cumulative block
allocations that 100 bytes at each call-site.
14.10.8 Scenarios in memory debugging
14.10.8.1 Stop when freeing unallocated or deallocated blocks
WDB enables you to locate improper calls to free() and realloc(), with the com-
mand
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() WDB inspects
the parameters to verify that they are pointing to valid currently allocated heap blocks.
If 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.
14.10.8.2 Stop when freeing a block if bad writes occurred
outside block boundary
WDB enables you to locate problems caused by heap block overflow 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, 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, 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 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 re-
quirements because the extra guard bytes must be allocated at the begin-
ning and end of each block.