Debugging with GDB Manual The GNU Source-Level Debugger (769148-001, March 2014)
This change to the memory contents increases the chance that erroneous behaviors will cause the
program to fail. Examples of such behavior 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.
Detect dangling pointers and dangling blocks
A pointer is a Dangling pointer if the block of memory it points to, has been freed by the application.
The block is called Dangling Block.
The same freed block could be subsequently allocated to the application in response to another
memory allocation request. In this scenario, if the application incorrectly tries to write into the freed
memory block using the dangling pointer, it could result in incorrect or an undefined program
behavior, as the new owner or function owning the same allocated block would find different
values in the heap block.
NOTE: Software literature names this concept as premature free or Reading/writing freed memory
using a pointer.
HP WDB tracks the dangling pointers and dangling blocks using a modified version of Garbage
collection. The enabler for doing this is by retaining all the freed blocks internally within RTC without
actually freeing it as long as possible. It displays all the potential pointers to the freed dangling
blocks, in the application data space.
The pointers are potential because the pointers need not be actual pointers and could be a datum
value and hence there are chances of false positives in the dangling report.
NOTE: HP WDB tries to help as much as possible to detect if these pointers are of type datum
or real pointers. In a -g compiled binary, HP WDB performs a look-up on a symbol table to find
the symbol name and type to find the symbol name of the potential pointer and if its of pointer
type, then the corresponding dangling block is really dangling (not a false positive).
HP WDB turns on these checks, only when you specify set heap-check retain-freed-
blocks on.
Detect in-block corruption of freed blocks
HP WDB detects all the attempts of a program to write to the freed dangling blocks using dangling
pointers. We detect such in-block corruptions and are reported as part of the existing info
corruption command output.
Specify 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. This again is available optionally when the user specifies
set heap-check retain-freed-blocks <on>.
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 commands.
The following table lists the memory debugging commands available in batch and interactive
mode:
Debugging Memory Problems 129