2 * gcov-pull - Request gcov data from server and write it to gcda files
3 * Author: Anton Kuijsten
10 #include <sys/types.h>
17 #include <minix/gcov.h>
19 #define BUFF_SZ (4 * 1024 * 1024) /* 4MB */
25 /* helper function to read int from the buffer */
29 memcpy(&res
, buff_p
, sizeof(int));
30 buff_p
+= sizeof(int);
34 int main(int argc
, char *argv
[])
37 int server_nr
, command
, size
, result
;
38 char buff
[BUFF_SZ
]; /* Buffer for all the metadata and file data sent */
40 if(argc
!=2 || sscanf(argv
[1], "%d", &server_nr
)!=1) {
41 fprintf(stderr
, "Usage: %s <pid>\n", argv
[0]);
46 When making a GCOV call to a server, the gcov library linked into
47 the server will try to write gcov data to disk. This writing is
48 normally done with calls to the vfs, using stdio library calls.
49 This is not correct behaviour for servers, especially vfs itself.
50 Therefore, the server catches those attempts. The messages used for
51 this communication are stored in a buffer. When the gcov operation
52 is done, the buffer is copied from the server to this user space,
53 from where the calls are finally made to the vfs. GCOV calls to the
54 various servers are all routed trough vfs. For more information, see
55 the <minix/gcov.h> header file.
58 /* visit complete buffer, so vm won't has to
59 manage the pages while flushing
61 memset(buff
, 'a', sizeof(buff
));
65 result
= gcov_flush_svr(buff_p
, BUFF_SZ
, server_nr
);
67 if(result
>= BUFF_SZ
) {
68 fprintf(stderr
, "Too much data to hold in buffer: %d\n", result
);
69 fprintf(stderr
, "Maximum: %d\n", BUFF_SZ
);
74 fprintf(stderr
, "Call failed\n");
78 /* At least GCOVOP_END opcode expected. */
79 if(result
< sizeof(int)) {
80 fprintf(stderr
, "Invalid gcov data from pid %d\n", server_nr
);
84 /* Only GCOVOP_END is valid but empty. */
85 if(result
== sizeof(int)) {
86 fprintf(stderr
, "no gcov data.\n");
90 /* Iterate through the system calls contained in the buffer,
93 while((command
=read_int()) != GCOVOP_END
) {
100 fn
= strrchr(fn
, '/');
105 if(!(fd
= fopen(fn
, "w+"))) {
113 fprintf(stderr
, "bogus close\n");
121 fwrite(buff_p
, size
, 1, fd
);
125 fprintf(stderr
, "bogus command %d in buffer.\n",