Debugging with GDB (September 2007)
Chapter 14: HP-UX Configuration-Specific Information 133
The program is running. Exit anyway? (y or n) y.
14.10 De bugging Memory Problems
You can use WDB to find leaks, profile heap usage and detect other heap-related errors
in HP C, HP aC++, and HP Fortran programs written for HP-UX 11.x systems. (Both
32-bit and 64-bit programs are supported.)
On HP-UX 11.x, the memory debugging features of WDB work with both single-threaded
and multi-threaded programs that use POSIX threads.
For more information on memory debugging with WDB, see the Debugging Dynamic
Memory Usage Errors Using HP WDB whitepaper at the HP WDB Documentation web-
page at:
http://www.hp.com/go/wdb.
14.10.1 When to suspect a memory leak
You should suspect a memory leak in the code when you notice that the system is
running out of swap space or running slower, or both.
Applications or non-kernel code (including daemons) that have memory leaks can even-
tually use up all swap space . You can run top(1) to verify whether the process data space
(SIZE, RES) is growing more than you expect.
If the system is running out of swap space, programs will fail with out-of-memory
(ENOMEM) errors or SIGBUS signals. In addition, the system might run slower and slower
until it comes to a stop; all processes requiring swap to continue running will wait for it
indefinitely.GDB allows you to catch out-of-memory c onditions through runtime memory
checking. Use the command catch nomem to detect out-of-memory conditions. GDB will
stop whenever malloc returns NULL and allows you to look at the current context.
14.10.2 Memory debugging restrictions
Programs with these attributes are not supported:
• CMA or DCE threaded programs on 11.x (32-bit and 64-bit)
• Memory checking features. These features work only in programs that directly or
indirectly call malloc, realloc, free, mmap, or munmap from the standard C library
‘libc.sl’.
• Programs that link the archive version of the standard C library, libc.a, or the core
library, libcl.a, on HP-UX 11.x
Note: Linker with version number B.11.19 or higher is required for debugging memory
problems.
• From HP WDB 5.7 onwards, the archive version of the run time check library,
librtc.a, is not available. You must use the shared version of the library,
librtc.[sl|so], instead.