Debugging with GDB Manual (5900-1473; WDB 6.2; January 2011)

Table Of Contents
14.10.11.4 info heap process
The info heap process command enables the user to view a high level memory usage
report of a process. This command is available only for applications running on 11i v3
or later.
14.10.11.5 Example for heap profiling
This example shows how to use this feature on HP-UX 11.x:
1. If the linker version is earlier than B.11.19, link with /opt/langtools/lib/
pa20_ 64/librtc.sl for PA-64 programs. For a 32-bit program, you must link
with /opt/langtools/lib/librtc.sl.
If the dynamic linker version is B.11.19 or later, skip this step because HP WDB
automatically loads the librtc.sl library.
2. Turn on profiling with the set heap-check on command:
(gdb) set heap-check on
3. Set a breakpoint:
(gdb) b myfunction
4. When the program is stopped at a breakpoint, use the info heap command:
(gdb) info heap
Analyzing heap ...done
Actual Heap Usage:
Heap Start = 0x40408000
Heap End = 0x4041a900
Heap Size = 76288 bytes
Outstanding Allocations:
41558 bytes allocated in 28 blocks
No. Total bytes Blocks Address Function
0 34567 1 0x40411000 foo()
1 4096 1 0x7bd63000 bar()
2 1234 1 0x40419710 baz()
3 245 8 0x404108b0 boo()
[...]
The display shows the currently allocated heap blocks. Any blocks that have been
allocated and already freed are not listed.
To look at a specific allocation, specify the allocation number with the info heap
command:
(gdb) info heap 1
4096 bytes at 0x7bd63000 (9.86% of all bytes allocated)
in bar () at test.c:108
in main () at test.c:17
174 HP-UX Configuration-Specific Information