2 * gcov-pull - Request gcov data from server and write it to gcda files
3 * Author: Anton Kuijsten
10 #include <sys/types.h>
14 #include <minix/gcov.h>
16 #define BUFF_SZ (4 * 1024 * 1024) /* 4MB */
22 /* helper function to read int from the buffer */
26 memcpy(&res
, buff_p
, sizeof(int));
27 buff_p
+= sizeof(int);
31 int main(int argc
, char *argv
[])
34 int server_nr
, command
, size
, result
;
35 static char buff
[BUFF_SZ
]; /* Buffer for all the metadata and file data */
38 fprintf(stderr
, "Usage: %s <label>\n", argv
[0]);
43 When making a GCOV call to a server, the gcov library linked into
44 the server will try to write gcov data to disk. This writing is
45 normally done with calls to the vfs, using stdio library calls.
46 This is not correct behaviour for servers, especially vfs itself.
47 Therefore, the server catches those attempts. The messages used for
48 this communication are stored in a buffer. When the gcov operation
49 is done, the buffer is copied from the server to this user space,
50 from where the calls are finally made to the vfs. GCOV calls to the
51 various servers are all routed trough vfs. For more information, see
52 the <minix/gcov.h> header file.
55 /* Fault in the complete buffer, so vm won't have to
56 manage the pages while flushing
58 memset(buff
, '\0', sizeof(buff
));
62 result
= gcov_flush_svr(argv
[1], buff_p
, BUFF_SZ
);
64 if(result
>= BUFF_SZ
) {
65 fprintf(stderr
, "Too much data to hold in buffer: %d\n", result
);
66 fprintf(stderr
, "Maximum: %d\n", BUFF_SZ
);
71 fprintf(stderr
, "Call failed\n");
75 /* At least GCOVOP_END opcode expected. */
76 if(result
< sizeof(int)) {
77 fprintf(stderr
, "Invalid gcov data from pid %d\n", server_nr
);
81 /* Only GCOVOP_END is valid but empty. */
82 if(result
== sizeof(int)) {
83 fprintf(stderr
, "no gcov data.\n");
87 /* Iterate through the system calls contained in the buffer,
90 while((command
=read_int()) != GCOVOP_END
) {
97 fn
= strrchr(fn
, '/');
102 if(!(fd
= fopen(fn
, "w+"))) {
110 fprintf(stderr
, "bogus close\n");
118 fwrite(buff_p
, size
, 1, fd
);
122 fprintf(stderr
, "bogus command %d in buffer.\n",