Debugging Dynamic Memory Usage Errors Using HP WDB (766161-001, March 2014)

Example 1 Filtered Heap Reporting for Allocations Exceeding <num> at a Particular Call-Site
Sample Program
1 #include <stdio.h>
2 #include <stdlib.h>
3 main()
4 {
5 int i, *arr[1000];
6 for (i=0; i < 1000; i++)
7 arr[i] = malloc (49);
8 malloc (30);
9 set_brkpt_here(0)
10 exit(0);
11
12 }
Sample Debugging Session
$ gdb minheap
(gdb) b set_brkpt_here
(gdb) set heap-check min-heap-size 31
(gdb) run
(gdb) info heap
Analyzing heap ...
49000 bytes allocated in 1000 blocks
No. Total bytes Blocks Address Function
0 49000 1000 0x4044eff0 main()
Incremental Heap Profile
The incremental profile displays the outstanding allocations at multiple probe points in an application
at runtime. This profile is analogous to processing multiple snapshot profiles. Example 2 (page 14)
illustrates this feature.
Table 5 lists the commands for incremental heap-profiling.
Table 5 Commands for Incremental Heap-Profiling
DescriptionCommand
Starts the incremental heap growth profile. All allocations
prior to the execution of this command are ignored. If
set heap-check interval <nn>
incremental heap growth profile is already on, executing
this command resets the counters and starts a fresh
collection. The interval is specified in seconds.
Enables you to specify the number of intervals for which
WDB must collect the incremental heap growth. The default
set heap-check repeat <nn>
value is 100. Every repeat of the interval tracks heap
allocation during that interval.
Creates a detailed report of the heap growth. The data for
each interval has the start and end time of the interval. If
info heap-interval <filename>
a filename is specified, the detailed report is written in the
specified file.
When incremental heap profile is used the heap growth
data is internally stored by WDB in a temporary file. The
set heap-check reset
heap growth data gathered during each interval is
appended to this file . If the session is very long, this file
may become very large. This command discards the data
existing in the file and creates a new data file. If the
command is executed, the user cannot see the old data in
the file.
Memory-Debugging Features of WDB 13