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

Example 16 Batch Mode Debugging for a 32-bit Application running on Itanium
Sample Program
$ cat memtest.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 #include <signal.h>
6 void myhandler(void ) {
7 exit(0);
8 }
9
10 main(int argc)
11 {
12
13 // signal(11, myhandler);
14
15 char *p[20], buffer[]="0123456789012345", *temp;
16 int i;
17
18 for (i=0; i<20; i++) {
19 p[i]=(char *)malloc(4);
20 };
21 memcpy(p[15], buffer, 12);
22 for (i=0; i<10; i++) {
23 free(p[i]);
24 };
25 free(p[9]);
26 }
27
Sample Configuration File
$ cat rtcconfig
"rtcconfig" 7 lines, 86 characters
set heap-check on
set heap-check leaks on
set heap-check free on
set heap-check string on
files=memtest
output_dir=./
Sample Debugging Session
$ cc -g -o memtest memtest.c
$ export BATCH_RTC=on
$ chatr +rtc enable memtest
warning: Memory corruption info is written to "memtest.8494.mem".
warning: Memory leak info is written to "memtest.8494.leaks".
Memory heap info is written to "memtest.8494.heap
$ cat memtest.8494.mem
-----------------------------------------
Attempt to free unallocated or already freed object at 0x4006e7b0
(0) 0x60000000cac1bdc0 print_stack_trace_to_log_file + 0x1d0 at
../../../Src/gnu/gdb/infrtc.c:996
[/opt/langtools/lib/hpux32/librtc.sl]
(1) 0x60000000cac1d3e0 __rtc_event + 0x160 at
../../../Src/gnu/gdb/infrtc.c:1296
[/opt/langtools/lib/hpux32/librtc.sl]
(2) 0x60000000cac22da0 rtc_record_free + 0x380 at
../../../Src/gnu/gdb/infrtc.c:2651
56