Debugging Dynamic Memory Usage Errors Using HP WDB v6.3 (5900-2181, August 2012)

Example 15 A sample c program and its openfd report obtained using wdb batch mode
Sample Program
1 #include <stdio.h>
2 #include <fcntl.h>
3 #include <sys/unistd.h>
4
5 int func(void);
6
7 int main()
8 {
9 int fd;
10 fd = func();
11 return 0;
12 }
13
14 int func(void)
15 {
16 char filename[]="/tmp/textfile";
17 int infd, infd1;
18
19 infd = open (filename, O_RDONLY);
20 if (infd == -1)
21 printf("Couldn't open %s",filename);
22
23 infd1 = open (filename, O_RDONLY);
24 if (infd == -1)
25 printf("Couldn't open again %s",filename);
26
27 close (infd);
28
29 return(infd1);
30 }
openfd Report
Total no. of files left open: = 4
No. FD Type Function Name
0 0 Character device ???() <stdin>
1 1 Character device ???() <stdout>
2 2 Character device ???() <stderr>
3 4 Regular type func() /tmp/textfile
-------------------------------------------------------------------------
Detailed Report
-------------------------------------------------------------------------
File Name : <stdin>
File Descriptor : 0
File Type : Character device
-------------------------------------------------------------------------
File Name : <stdout>
File Descriptor : 1
File Type : Character device
-------------------------------------------------------------------------
File Name : <stderr>
File Descriptor : 2
File Type : Character device
-------------------------------------------------------------------------
Memory-Debugging Features of WDB 47