Mercurial > hg > CbC > CbC_gcc
comparison gcc/gcov-io.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | a06113de4d67 |
children | 04ced10e8804 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
44 return value; | 44 return value; |
45 } | 45 } |
46 | 46 |
47 /* Open a gcov file. NAME is the name of the file to open and MODE | 47 /* Open a gcov file. NAME is the name of the file to open and MODE |
48 indicates whether a new file should be created, or an existing file | 48 indicates whether a new file should be created, or an existing file |
49 opened for modification. If MODE is >= 0 an existing file will be | 49 opened. If MODE is >= 0 an existing file will be opened, if |
50 opened, if possible, and if MODE is <= 0, a new file will be | 50 possible, and if MODE is <= 0, a new file will be created. Use |
51 created. Use MODE=0 to attempt to reopen an existing file and then | 51 MODE=0 to attempt to reopen an existing file and then fall back on |
52 fall back on creating a new one. Return zero on failure, >0 on | 52 creating a new one. If MODE < 0, the file will be opened in |
53 opening an existing file and <0 on creating a new one. */ | 53 read-only mode. Otherwise it will be opened for modification. |
54 Return zero on failure, >0 on opening an existing file and <0 on | |
55 creating a new one. */ | |
54 | 56 |
55 GCOV_LINKAGE int | 57 GCOV_LINKAGE int |
56 #if IN_LIBGCOV | 58 #if IN_LIBGCOV |
57 gcov_open (const char *name) | 59 gcov_open (const char *name) |
58 #else | 60 #else |
64 #endif | 66 #endif |
65 #if GCOV_LOCKED | 67 #if GCOV_LOCKED |
66 struct flock s_flock; | 68 struct flock s_flock; |
67 int fd; | 69 int fd; |
68 | 70 |
69 s_flock.l_type = F_WRLCK; | |
70 s_flock.l_whence = SEEK_SET; | 71 s_flock.l_whence = SEEK_SET; |
71 s_flock.l_start = 0; | 72 s_flock.l_start = 0; |
72 s_flock.l_len = 0; /* Until EOF. */ | 73 s_flock.l_len = 0; /* Until EOF. */ |
73 s_flock.l_pid = getpid (); | 74 s_flock.l_pid = getpid (); |
74 #endif | 75 #endif |
75 | 76 |
76 gcc_assert (!gcov_var.file); | 77 gcc_assert (!gcov_var.file); |
77 gcov_var.start = 0; | 78 gcov_var.start = 0; |
78 gcov_var.offset = gcov_var.length = 0; | 79 gcov_var.offset = gcov_var.length = 0; |
79 gcov_var.overread = -1u; | 80 gcov_var.overread = -1u; |
80 gcov_var.error = 0; | 81 gcov_var.error = 0; |
81 #if !IN_LIBGCOV | 82 #if !IN_LIBGCOV |
82 gcov_var.endian = 0; | 83 gcov_var.endian = 0; |
83 #endif | 84 #endif |
84 #if GCOV_LOCKED | 85 #if GCOV_LOCKED |
85 if (mode > 0) | 86 if (mode > 0) |
86 fd = open (name, O_RDWR); | 87 { |
88 /* Read-only mode - acquire a read-lock. */ | |
89 s_flock.l_type = F_RDLCK; | |
90 fd = open (name, O_RDONLY); | |
91 } | |
87 else | 92 else |
88 fd = open (name, O_RDWR | O_CREAT, 0666); | 93 { |
94 /* Write mode - acquire a write-lock. */ | |
95 s_flock.l_type = F_WRLCK; | |
96 fd = open (name, O_RDWR | O_CREAT, 0666); | |
97 } | |
89 if (fd < 0) | 98 if (fd < 0) |
90 return 0; | 99 return 0; |
91 | 100 |
92 while (fcntl (fd, F_SETLKW, &s_flock) && errno == EINTR) | 101 while (fcntl (fd, F_SETLKW, &s_flock) && errno == EINTR) |
93 continue; | 102 continue; |
94 | 103 |
95 gcov_var.file = fdopen (fd, "r+b"); | 104 gcov_var.file = fdopen (fd, (mode > 0) ? "rb" : "r+b"); |
105 | |
96 if (!gcov_var.file) | 106 if (!gcov_var.file) |
97 { | 107 { |
98 close (fd); | 108 close (fd); |
99 return 0; | 109 return 0; |
100 } | 110 } |
118 } | 128 } |
119 else | 129 else |
120 gcov_var.mode = mode * 2 + 1; | 130 gcov_var.mode = mode * 2 + 1; |
121 #else | 131 #else |
122 if (mode >= 0) | 132 if (mode >= 0) |
123 gcov_var.file = fopen (name, "r+b"); | 133 gcov_var.file = fopen (name, (mode > 0) ? "rb" : "r+b"); |
134 | |
124 if (gcov_var.file) | 135 if (gcov_var.file) |
125 gcov_var.mode = 1; | 136 gcov_var.mode = 1; |
126 else if (mode <= 0) | 137 else if (mode <= 0) |
127 { | 138 { |
128 gcov_var.file = fopen (name, "w+b"); | 139 gcov_var.file = fopen (name, "w+b"); |
132 if (!gcov_var.file) | 143 if (!gcov_var.file) |
133 return 0; | 144 return 0; |
134 #endif | 145 #endif |
135 | 146 |
136 setbuf (gcov_var.file, (char *)0); | 147 setbuf (gcov_var.file, (char *)0); |
137 | 148 |
138 return 1; | 149 return 1; |
139 } | 150 } |
140 | 151 |
141 /* Close the current gcov file. Flushes data to disk. Returns nonzero | 152 /* Close the current gcov file. Flushes data to disk. Returns nonzero |
142 on failure or error flag set. */ | 153 on failure or error flag set. */ |
187 #if !IN_LIBGCOV | 198 #if !IN_LIBGCOV |
188 static void | 199 static void |
189 gcov_allocate (unsigned length) | 200 gcov_allocate (unsigned length) |
190 { | 201 { |
191 size_t new_size = gcov_var.alloc; | 202 size_t new_size = gcov_var.alloc; |
192 | 203 |
193 if (!new_size) | 204 if (!new_size) |
194 new_size = GCOV_BLOCK_SIZE; | 205 new_size = GCOV_BLOCK_SIZE; |
195 new_size += length; | 206 new_size += length; |
196 new_size *= 2; | 207 new_size *= 2; |
197 | 208 |
198 gcov_var.alloc = new_size; | 209 gcov_var.alloc = new_size; |
199 gcov_var.buffer = XRESIZEVAR (gcov_unsigned_t, gcov_var.buffer, new_size << 2); | 210 gcov_var.buffer = XRESIZEVAR (gcov_unsigned_t, gcov_var.buffer, new_size << 2); |
200 } | 211 } |
201 #endif | 212 #endif |
202 | 213 |
235 if (gcov_var.offset + words > gcov_var.alloc) | 246 if (gcov_var.offset + words > gcov_var.alloc) |
236 gcov_allocate (gcov_var.offset + words); | 247 gcov_allocate (gcov_var.offset + words); |
237 #endif | 248 #endif |
238 result = &gcov_var.buffer[gcov_var.offset]; | 249 result = &gcov_var.buffer[gcov_var.offset]; |
239 gcov_var.offset += words; | 250 gcov_var.offset += words; |
240 | 251 |
241 return result; | 252 return result; |
242 } | 253 } |
243 | 254 |
244 /* Write unsigned VALUE to coverage file. Sets error flag | 255 /* Write unsigned VALUE to coverage file. Sets error flag |
245 appropriately. */ | 256 appropriately. */ |
283 if (string) | 294 if (string) |
284 { | 295 { |
285 length = strlen (string); | 296 length = strlen (string); |
286 alloc = (length + 4) >> 2; | 297 alloc = (length + 4) >> 2; |
287 } | 298 } |
288 | 299 |
289 buffer = gcov_write_words (1 + alloc); | 300 buffer = gcov_write_words (1 + alloc); |
290 | 301 |
291 buffer[0] = alloc; | 302 buffer[0] = alloc; |
292 buffer[alloc] = 0; | 303 buffer[alloc] = 0; |
293 memcpy (&buffer[1], string, length); | 304 memcpy (&buffer[1], string, length); |
304 gcov_position_t result = gcov_var.start + gcov_var.offset; | 315 gcov_position_t result = gcov_var.start + gcov_var.offset; |
305 gcov_unsigned_t *buffer = gcov_write_words (2); | 316 gcov_unsigned_t *buffer = gcov_write_words (2); |
306 | 317 |
307 buffer[0] = tag; | 318 buffer[0] = tag; |
308 buffer[1] = 0; | 319 buffer[1] = 0; |
309 | 320 |
310 return result; | 321 return result; |
311 } | 322 } |
312 | 323 |
313 /* Write a record length using POSITION, which was returned by | 324 /* Write a record length using POSITION, which was returned by |
314 gcov_write_tag. The current file position is the end of the | 325 gcov_write_tag. The current file position is the end of the |
376 static const gcov_unsigned_t * | 387 static const gcov_unsigned_t * |
377 gcov_read_words (unsigned words) | 388 gcov_read_words (unsigned words) |
378 { | 389 { |
379 const gcov_unsigned_t *result; | 390 const gcov_unsigned_t *result; |
380 unsigned excess = gcov_var.length - gcov_var.offset; | 391 unsigned excess = gcov_var.length - gcov_var.offset; |
381 | 392 |
382 gcc_assert (gcov_var.mode > 0); | 393 gcc_assert (gcov_var.mode > 0); |
383 if (excess < words) | 394 if (excess < words) |
384 { | 395 { |
385 gcov_var.start += gcov_var.offset; | 396 gcov_var.start += gcov_var.offset; |
386 #if IN_LIBGCOV | 397 #if IN_LIBGCOV |
459 #if !IN_LIBGCOV | 470 #if !IN_LIBGCOV |
460 GCOV_LINKAGE const char * | 471 GCOV_LINKAGE const char * |
461 gcov_read_string (void) | 472 gcov_read_string (void) |
462 { | 473 { |
463 unsigned length = gcov_read_unsigned (); | 474 unsigned length = gcov_read_unsigned (); |
464 | 475 |
465 if (!length) | 476 if (!length) |
466 return 0; | 477 return 0; |
467 | 478 |
468 return (const char *) gcov_read_words (length); | 479 return (const char *) gcov_read_words (length); |
469 } | 480 } |
472 GCOV_LINKAGE void | 483 GCOV_LINKAGE void |
473 gcov_read_summary (struct gcov_summary *summary) | 484 gcov_read_summary (struct gcov_summary *summary) |
474 { | 485 { |
475 unsigned ix; | 486 unsigned ix; |
476 struct gcov_ctr_summary *csum; | 487 struct gcov_ctr_summary *csum; |
477 | 488 |
478 summary->checksum = gcov_read_unsigned (); | 489 summary->checksum = gcov_read_unsigned (); |
479 for (csum = summary->ctrs, ix = GCOV_COUNTERS_SUMMABLE; ix--; csum++) | 490 for (csum = summary->ctrs, ix = GCOV_COUNTERS_SUMMABLE; ix--; csum++) |
480 { | 491 { |
481 csum->num = gcov_read_unsigned (); | 492 csum->num = gcov_read_unsigned (); |
482 csum->runs = gcov_read_unsigned (); | 493 csum->runs = gcov_read_unsigned (); |
525 | 536 |
526 GCOV_LINKAGE time_t | 537 GCOV_LINKAGE time_t |
527 gcov_time (void) | 538 gcov_time (void) |
528 { | 539 { |
529 struct stat status; | 540 struct stat status; |
530 | 541 |
531 if (fstat (fileno (gcov_var.file), &status)) | 542 if (fstat (fileno (gcov_var.file), &status)) |
532 return 0; | 543 return 0; |
533 else | 544 else |
534 return status.st_mtime; | 545 return status.st_mtime; |
535 } | 546 } |