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.

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 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.

14.10.8.4 Scramble previous memory contents at malloc/free calls

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, WDB scrambles the space and overwrites it with a specific pattern.

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.

14.10.8.5 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 nd different values in the heap block.

14.10 Debugging Memory Problems 175

Page 175
Image 175
HP gnu source-level debugger 5992-4701 manual Syntax, Scramble previous memory contents at malloc/free calls