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

Example 8 Monitoring allocations greater than a specified size
Sample Program
bash-2.05b$ cat block-size.c
1 #include<stdio.h>
2
3 int main()
4 {
5 char * cp;
6 printf("Start of the program\n");
7 cp = (char *)malloc(1024 *1024*10);
8 free (cp);
9 exit(0);
10 }
Sample Debugging Session
bash-2.05b$ /opt/langtools/bin/gdb
HP gdb 5.5.0 for PA-RISC 1.1 or 2.0 (narrow), HP-UX 11.00
and target hppa1.1-hp-hpux11.00.
Copyright 1986 - 2001 Free Software Foundation, Inc.
Hewlett-Packard Wildebeest 5.5.0 (based on GDB) is covered
by the GNU General Public License. Type "show copying" to see
the conditions to change it and/or distribute copies.
Type "show warranty" for warranty/support.
(gdb) file block-size
Reading symbols from block-size...done.
(gdb) set heap-check on
(gdb) set heap-check block-size 900000
(gdb) b main
Breakpoint 1 at 0x2c04: file block-size.c, line 6 from block-size.
(gdb) b 9
Breakpoint 2 at 0x2c3c: file block-size.c, line 9 from block-size.
(gdb) r
Starting program: block-size
Breakpoint 1, main () at block-size.c:6
6 printf("Start of the program\n");
(gdb) c
Continuing.
Start of the program
warning: Attempt to allocate a large object at 0x4042c3e8
0x70e78d7c in __rtc_event+0 () from /opt/langtools/lib/librtc.sl
(gdb) bt
#0 0x70e78d7c in __rtc_event+0 () from /opt/langtools/lib/librtc.sl
#1 0x70e7a918 in rtc_record_malloc+0xf0 () from /opt/langtools/lib/librtc.sl
#2 0x70e7b7e0 in malloc+0x280 () from /opt/langtools/lib/librtc.sl
#3 0x2c28 in main () at block-size.c:7
#4 0x70ee3478 in _start+0xc0 () from /usr/lib/libc.2
(gdb) c
Continuing.
Breakpoint 2, main () at block-size.c:9
9 exit(0);
Monitoring the Program Heap Growth
The set heap-check heap-size command instructs WDB to stop the program and transfer
execution control to the user when the program attempts to increase the heap size of the program
by <num-bytes> or more. Example 9 (page 33) illustrates the use of this command.
Following is the syntax for the set heap-check heap-size command:
set heap-check heap-size <num-bytes>
32