Debugging Dynamic Memory Usage Errors Using HP WDB (766161-001, March 2014)

0x70e78d7c in __rtc_event+0 () from /opt/langtools/lib/librtc.sl
(gdb) f 4
#4 0x4000960:0 in main () at bounds.c:9
9 free(cp);
(gdb)
Setting the amount of guard bytes for every block of allocated memory
HP WDB enables you to programmatically control the size of guard bytes for every block of the
allocated memory. You can use these guard bytes to spot very rare and non-trivial boundary (buffer
over-run and buffer under-run) corruptions.
The commands which enable you to change the guard byte size are effective only when
bounds-check is turned on.
The following are the command that enable you to set the guard bytes for every block of allocated
memory:
1. set heap-check header-size <no of bytes>
This is used for setting the header guard for each block of memory that is allocated. The default
no of bytes for the footer is 16 bytes if this option is not used. If the user specifies any number
than 16, WDB ignores it and considers the default of 16 bytes. If the user specifies more than
16 bytes, then the largest closest 16 byte integral of the user given value is chosen. For
example, if the user enters 60 bytes, WDB takes it as 48; if the user specifies 65, WDB
considers it as 64.
2. set heap-check footer-size <no of bytes>
This is used for setting the footer guard for each block of memory that is allocated. The default
no of bytes for the footer is 1 byte, if this option is not used.
Detecting Heap Corruption
The info corruption <filename> command enables you to view the corruption profile of
all the allocations that are corrupted at a specified probe-point in the program. Ensure that the
bounds checking is enabled before using the info corruption command. The corruption
information is written to a specified file if the <file name> is provided. Otherwise, it is written
to stdout.
In addition, it lists the in-block corruptions in the freed blocks if the set heap-check
retain-freed-blocks is set to on.
NOTE: The info corruption command is not supported in batch mode debugging
Example 13 (page 42) illustrates the use of the info corruption command.
Memory-Debugging Features of WDB 41