Debugging with GDB (September 2007)
134 Debugging with GDB
14.10.3 Memory Debugging Methodologie s
WDB enables you to debug memory problems in applications written for HP-UX 11.x
or later using C, aC++, FORTRAN 77, and Fortran 90.
WDB provides several commands that help expos e memory-related problems.
HP WDB offers the following memory-debugging capabilities:
• Reports memory leaks
• Reports heap allocation profile
• Stops program exec ution if bad writes oc cur with string operations such as strcpy and
memcpy
• Stops program execution when freeing un-allocated or de-allocated blocks
• Stops program execution when freeing a block if bad writes occur outside block bound-
ary
• Stops program execution conditionally based on whether a specified block address is
allocated or de-allocated
• Scrambles previous memory contents at malloc() and free() calls
• Simulates and detects out-of-memory event errors.
You can use any of the following methods to identify memory problems:
• See Section 14.10.4 [Debugging Memory in Interactive Mode], page 134
• See Section 14.10.5 [Debugging Memory in Batch Mode], page 137
• See Section 14.10.6 [Debugging Memory Interactively After Attaching to a Running
Process], page 144
14.10.4 Debugging Memory in Interactive Mode
This section describe s the various commands which help in debugging memory problems
when the debugger is used in the interactive mode.
14.10.4.1 Commands for interactive memory debugging
To debug memory problems, use these commands:
set heap-check [on|off]
This toggles the capability for detection of leaks, heap profiles, bounds checking,
and checking for double free.
info heap Displays a heap report, listing information such as the start of heap, end of
heap, heap size, heap allocations, size of blocks, and number of instances. The
report shows heap usage at the point you use the info heap command. The
report does not show allocations that have already been freed. For example, if
you make several alloc ations, free them all, and then you use info heap, the
result does not show any allocations.
info heap filename
Writes heap report output to the specified file.