111
|
1 /* Routines required for instrumenting a program. */
|
|
2 /* Compile this one with gcc. */
|
131
|
3 /* Copyright (C) 1989-2018 Free Software Foundation, Inc.
|
111
|
4
|
|
5 This file is part of GCC.
|
|
6
|
|
7 GCC is free software; you can redistribute it and/or modify it under
|
|
8 the terms of the GNU General Public License as published by the Free
|
|
9 Software Foundation; either version 3, or (at your option) any later
|
|
10 version.
|
|
11
|
|
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 Under Section 7 of GPL version 3, you are granted additional
|
|
18 permissions described in the GCC Runtime Library Exception, version
|
|
19 3.1, as published by the Free Software Foundation.
|
|
20
|
|
21 You should have received a copy of the GNU General Public License and
|
|
22 a copy of the GCC Runtime Library Exception along with this program;
|
|
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
24 <http://www.gnu.org/licenses/>. */
|
|
25
|
|
26 #include "libgcov.h"
|
131
|
27 #include "gcov-io.h"
|
111
|
28
|
|
29 #if defined(inhibit_libc)
|
|
30 /* If libc and its header files are not available, provide dummy functions. */
|
|
31
|
|
32 #if defined(L_gcov)
|
|
33 void __gcov_init (struct gcov_info *p __attribute__ ((unused))) {}
|
|
34 #endif
|
|
35
|
|
36 #else /* inhibit_libc */
|
|
37
|
|
38 #include <string.h>
|
|
39 #if GCOV_LOCKED
|
|
40 #include <fcntl.h>
|
|
41 #include <errno.h>
|
|
42 #include <sys/stat.h>
|
|
43 #endif
|
|
44
|
|
45 #ifdef L_gcov
|
|
46
|
|
47 /* A utility function for outputting errors. */
|
|
48 static int gcov_error (const char *, ...);
|
|
49
|
|
50 #if !IN_GCOV_TOOL
|
|
51 static void gcov_error_exit (void);
|
|
52 #endif
|
|
53
|
|
54 #include "gcov-io.c"
|
|
55
|
|
56 struct gcov_fn_buffer
|
|
57 {
|
|
58 struct gcov_fn_buffer *next;
|
|
59 unsigned fn_ix;
|
|
60 struct gcov_fn_info info;
|
|
61 /* note gcov_fn_info ends in a trailing array. */
|
|
62 };
|
|
63
|
|
64 struct gcov_summary_buffer
|
|
65 {
|
|
66 struct gcov_summary_buffer *next;
|
|
67 struct gcov_summary summary;
|
|
68 };
|
|
69
|
|
70 /* A struct that bundles all the related information about the
|
|
71 gcda filename. */
|
|
72
|
|
73 struct gcov_filename
|
|
74 {
|
|
75 char *filename; /* filename buffer */
|
|
76 int strip; /* leading chars to strip from filename */
|
131
|
77 char *prefix; /* prefix string */
|
111
|
78 };
|
|
79
|
|
80 static struct gcov_fn_buffer *
|
|
81 free_fn_data (const struct gcov_info *gi_ptr, struct gcov_fn_buffer *buffer,
|
|
82 unsigned limit)
|
|
83 {
|
|
84 struct gcov_fn_buffer *next;
|
|
85 unsigned ix, n_ctr = 0;
|
|
86
|
|
87 if (!buffer)
|
|
88 return 0;
|
|
89 next = buffer->next;
|
|
90
|
|
91 for (ix = 0; ix != limit; ix++)
|
|
92 if (gi_ptr->merge[ix])
|
|
93 free (buffer->info.ctrs[n_ctr++].values);
|
|
94 free (buffer);
|
|
95 return next;
|
|
96 }
|
|
97
|
|
98 static struct gcov_fn_buffer **
|
|
99 buffer_fn_data (const char *filename, const struct gcov_info *gi_ptr,
|
|
100 struct gcov_fn_buffer **end_ptr, unsigned fn_ix)
|
|
101 {
|
|
102 unsigned n_ctrs = 0, ix = 0;
|
|
103 struct gcov_fn_buffer *fn_buffer;
|
|
104 unsigned len;
|
|
105
|
|
106 for (ix = GCOV_COUNTERS; ix--;)
|
|
107 if (gi_ptr->merge[ix])
|
|
108 n_ctrs++;
|
|
109
|
|
110 len = sizeof (*fn_buffer) + sizeof (fn_buffer->info.ctrs[0]) * n_ctrs;
|
|
111 fn_buffer = (struct gcov_fn_buffer *) xmalloc (len);
|
|
112
|
|
113 if (!fn_buffer)
|
|
114 goto fail;
|
|
115
|
|
116 fn_buffer->next = 0;
|
|
117 fn_buffer->fn_ix = fn_ix;
|
|
118 fn_buffer->info.ident = gcov_read_unsigned ();
|
|
119 fn_buffer->info.lineno_checksum = gcov_read_unsigned ();
|
|
120 fn_buffer->info.cfg_checksum = gcov_read_unsigned ();
|
|
121
|
|
122 for (n_ctrs = ix = 0; ix != GCOV_COUNTERS; ix++)
|
|
123 {
|
|
124 gcov_unsigned_t length;
|
|
125 gcov_type *values;
|
|
126
|
|
127 if (!gi_ptr->merge[ix])
|
|
128 continue;
|
|
129
|
|
130 if (gcov_read_unsigned () != GCOV_TAG_FOR_COUNTER (ix))
|
|
131 {
|
|
132 len = 0;
|
|
133 goto fail;
|
|
134 }
|
|
135
|
|
136 length = GCOV_TAG_COUNTER_NUM (gcov_read_unsigned ());
|
|
137 len = length * sizeof (gcov_type);
|
|
138 values = (gcov_type *) xmalloc (len);
|
|
139 if (!values)
|
|
140 goto fail;
|
|
141
|
|
142 fn_buffer->info.ctrs[n_ctrs].num = length;
|
|
143 fn_buffer->info.ctrs[n_ctrs].values = values;
|
|
144
|
|
145 while (length--)
|
|
146 *values++ = gcov_read_counter ();
|
|
147 n_ctrs++;
|
|
148 }
|
|
149
|
|
150 *end_ptr = fn_buffer;
|
|
151 return &fn_buffer->next;
|
|
152
|
|
153 fail:
|
|
154 gcov_error ("profiling:%s:Function %u %s %u \n", filename, fn_ix,
|
|
155 len ? "cannot allocate" : "counter mismatch", len ? len : ix);
|
|
156
|
|
157 return (struct gcov_fn_buffer **)free_fn_data (gi_ptr, fn_buffer, ix);
|
|
158 }
|
|
159
|
|
160 /* Check if VERSION of the info block PTR matches libgcov one.
|
|
161 Return 1 on success, or zero in case of versions mismatch.
|
|
162 If FILENAME is not NULL, its value used for reporting purposes
|
|
163 instead of value from the info block. */
|
|
164
|
|
165 static int
|
|
166 gcov_version (struct gcov_info *ptr, gcov_unsigned_t version,
|
|
167 const char *filename)
|
|
168 {
|
|
169 if (version != GCOV_VERSION)
|
|
170 {
|
|
171 char v[4], e[4];
|
|
172
|
|
173 GCOV_UNSIGNED2STRING (v, version);
|
|
174 GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
|
|
175
|
|
176 gcov_error ("profiling:%s:Version mismatch - expected %.4s got %.4s\n",
|
|
177 filename? filename : ptr->filename, e, v);
|
|
178 return 0;
|
|
179 }
|
|
180 return 1;
|
|
181 }
|
|
182
|
|
183 /* buffer for the fn_data from another program. */
|
|
184 static struct gcov_fn_buffer *fn_buffer;
|
|
185
|
|
186 /* Including system dependent components. */
|
|
187 #include "libgcov-driver-system.c"
|
|
188
|
|
189 /* This function merges counters in GI_PTR to an existing gcda file.
|
|
190 Return 0 on success.
|
|
191 Return -1 on error. In this case, caller will goto read_fatal. */
|
|
192
|
|
193 static int
|
|
194 merge_one_data (const char *filename,
|
|
195 struct gcov_info *gi_ptr,
|
131
|
196 struct gcov_summary *summary)
|
111
|
197 {
|
|
198 gcov_unsigned_t tag, length;
|
|
199 unsigned t_ix;
|
131
|
200 int f_ix = -1;
|
111
|
201 int error = 0;
|
|
202 struct gcov_fn_buffer **fn_tail = &fn_buffer;
|
|
203
|
|
204 length = gcov_read_unsigned ();
|
|
205 if (!gcov_version (gi_ptr, length, filename))
|
|
206 return -1;
|
|
207
|
|
208 length = gcov_read_unsigned ();
|
|
209 if (length != gi_ptr->stamp)
|
|
210 {
|
131
|
211 /* Read from a different compilation. Overwrite the file. */
|
|
212 gcov_error ("profiling:%s:overwriting an existing profile data "
|
|
213 "with a different timestamp\n", filename);
|
|
214 return 0;
|
111
|
215 }
|
|
216
|
131
|
217 tag = gcov_read_unsigned ();
|
|
218 if (tag != GCOV_TAG_OBJECT_SUMMARY)
|
|
219 goto read_mismatch;
|
|
220 length = gcov_read_unsigned ();
|
|
221 gcc_assert (length > 0);
|
|
222 gcov_read_summary (summary);
|
|
223
|
|
224 tag = gcov_read_unsigned ();
|
111
|
225 /* Merge execution counts for each function. */
|
|
226 for (f_ix = 0; (unsigned)f_ix != gi_ptr->n_functions;
|
|
227 f_ix++, tag = gcov_read_unsigned ())
|
|
228 {
|
|
229 const struct gcov_ctr_info *ci_ptr;
|
|
230 const struct gcov_fn_info *gfi_ptr = gi_ptr->functions[f_ix];
|
|
231
|
|
232 if (tag != GCOV_TAG_FUNCTION)
|
|
233 goto read_mismatch;
|
|
234
|
|
235 length = gcov_read_unsigned ();
|
|
236 if (!length)
|
|
237 /* This function did not appear in the other program.
|
|
238 We have nothing to merge. */
|
|
239 continue;
|
|
240
|
|
241 if (length != GCOV_TAG_FUNCTION_LENGTH)
|
|
242 goto read_mismatch;
|
|
243
|
|
244 if (!gfi_ptr || gfi_ptr->key != gi_ptr)
|
|
245 {
|
|
246 /* This function appears in the other program. We
|
|
247 need to buffer the information in order to write
|
|
248 it back out -- we'll be inserting data before
|
|
249 this point, so cannot simply keep the data in the
|
|
250 file. */
|
|
251 fn_tail = buffer_fn_data (filename, gi_ptr, fn_tail, f_ix);
|
|
252 if (!fn_tail)
|
|
253 goto read_mismatch;
|
|
254 continue;
|
|
255 }
|
|
256
|
|
257 length = gcov_read_unsigned ();
|
|
258 if (length != gfi_ptr->ident)
|
|
259 goto read_mismatch;
|
|
260
|
|
261 length = gcov_read_unsigned ();
|
|
262 if (length != gfi_ptr->lineno_checksum)
|
|
263 goto read_mismatch;
|
|
264
|
|
265 length = gcov_read_unsigned ();
|
|
266 if (length != gfi_ptr->cfg_checksum)
|
|
267 goto read_mismatch;
|
|
268
|
|
269 ci_ptr = gfi_ptr->ctrs;
|
|
270 for (t_ix = 0; t_ix < GCOV_COUNTERS; t_ix++)
|
|
271 {
|
|
272 gcov_merge_fn merge = gi_ptr->merge[t_ix];
|
|
273
|
|
274 if (!merge)
|
|
275 continue;
|
|
276
|
|
277 tag = gcov_read_unsigned ();
|
|
278 length = gcov_read_unsigned ();
|
|
279 if (tag != GCOV_TAG_FOR_COUNTER (t_ix)
|
|
280 || length != GCOV_TAG_COUNTER_LENGTH (ci_ptr->num))
|
|
281 goto read_mismatch;
|
|
282 (*merge) (ci_ptr->values, ci_ptr->num);
|
|
283 ci_ptr++;
|
|
284 }
|
|
285 if ((error = gcov_is_error ()))
|
|
286 goto read_error;
|
|
287 }
|
|
288
|
|
289 if (tag)
|
|
290 {
|
|
291 read_mismatch:;
|
|
292 gcov_error ("profiling:%s:Merge mismatch for %s %u\n",
|
|
293 filename, f_ix >= 0 ? "function" : "summary",
|
|
294 f_ix < 0 ? -1 - f_ix : f_ix);
|
|
295 return -1;
|
|
296 }
|
|
297 return 0;
|
|
298
|
|
299 read_error:
|
|
300 gcov_error ("profiling:%s:%s merging\n", filename,
|
|
301 error < 0 ? "Overflow": "Error");
|
|
302 return -1;
|
|
303 }
|
|
304
|
|
305 /* Write counters in GI_PTR and the summary in PRG to a gcda file. In
|
|
306 the case of appending to an existing file, SUMMARY_POS will be non-zero.
|
|
307 We will write the file starting from SUMMAY_POS. */
|
|
308
|
|
309 static void
|
|
310 write_one_data (const struct gcov_info *gi_ptr,
|
131
|
311 const struct gcov_summary *prg_p)
|
111
|
312 {
|
|
313 unsigned f_ix;
|
|
314
|
131
|
315 gcov_write_tag_length (GCOV_DATA_MAGIC, GCOV_VERSION);
|
|
316 gcov_write_unsigned (gi_ptr->stamp);
|
111
|
317
|
|
318 /* Generate whole program statistics. */
|
131
|
319 gcov_write_summary (GCOV_TAG_OBJECT_SUMMARY, prg_p);
|
111
|
320
|
|
321 /* Write execution counts for each function. */
|
|
322 for (f_ix = 0; f_ix != gi_ptr->n_functions; f_ix++)
|
|
323 {
|
|
324 unsigned buffered = 0;
|
|
325 const struct gcov_fn_info *gfi_ptr;
|
|
326 const struct gcov_ctr_info *ci_ptr;
|
|
327 gcov_unsigned_t length;
|
|
328 unsigned t_ix;
|
|
329
|
|
330 if (fn_buffer && fn_buffer->fn_ix == f_ix)
|
|
331 {
|
|
332 /* Buffered data from another program. */
|
|
333 buffered = 1;
|
|
334 gfi_ptr = &fn_buffer->info;
|
|
335 length = GCOV_TAG_FUNCTION_LENGTH;
|
|
336 }
|
|
337 else
|
|
338 {
|
|
339 gfi_ptr = gi_ptr->functions[f_ix];
|
|
340 if (gfi_ptr && gfi_ptr->key == gi_ptr)
|
|
341 length = GCOV_TAG_FUNCTION_LENGTH;
|
|
342 else
|
|
343 length = 0;
|
|
344 }
|
|
345
|
|
346 gcov_write_tag_length (GCOV_TAG_FUNCTION, length);
|
|
347 if (!length)
|
|
348 continue;
|
|
349
|
|
350 gcov_write_unsigned (gfi_ptr->ident);
|
|
351 gcov_write_unsigned (gfi_ptr->lineno_checksum);
|
|
352 gcov_write_unsigned (gfi_ptr->cfg_checksum);
|
|
353
|
|
354 ci_ptr = gfi_ptr->ctrs;
|
|
355 for (t_ix = 0; t_ix < GCOV_COUNTERS; t_ix++)
|
|
356 {
|
|
357 gcov_unsigned_t n_counts;
|
|
358 gcov_type *c_ptr;
|
|
359
|
|
360 if (!gi_ptr->merge[t_ix])
|
|
361 continue;
|
|
362
|
|
363 n_counts = ci_ptr->num;
|
|
364 gcov_write_tag_length (GCOV_TAG_FOR_COUNTER (t_ix),
|
|
365 GCOV_TAG_COUNTER_LENGTH (n_counts));
|
|
366 c_ptr = ci_ptr->values;
|
|
367 while (n_counts--)
|
|
368 gcov_write_counter (*c_ptr++);
|
|
369 ci_ptr++;
|
|
370 }
|
|
371 if (buffered)
|
|
372 fn_buffer = free_fn_data (gi_ptr, fn_buffer, GCOV_COUNTERS);
|
|
373 }
|
|
374
|
|
375 gcov_write_unsigned (0);
|
|
376 }
|
|
377
|
131
|
378 /* Helper function for merging summary. */
|
111
|
379
|
131
|
380 static void
|
|
381 merge_summary (int run_counted, struct gcov_summary *summary,
|
|
382 gcov_type run_max)
|
|
383 {
|
|
384 if (!run_counted)
|
|
385 {
|
|
386 summary->runs++;
|
|
387 summary->sum_max += run_max;
|
111
|
388 }
|
|
389 }
|
|
390
|
|
391 /* Sort N entries in VALUE_ARRAY in descending order.
|
|
392 Each entry in VALUE_ARRAY has two values. The sorting
|
|
393 is based on the second value. */
|
|
394
|
|
395 GCOV_LINKAGE void
|
|
396 gcov_sort_n_vals (gcov_type *value_array, int n)
|
|
397 {
|
|
398 int j, k;
|
|
399
|
|
400 for (j = 2; j < n; j += 2)
|
|
401 {
|
|
402 gcov_type cur_ent[2];
|
|
403
|
|
404 cur_ent[0] = value_array[j];
|
|
405 cur_ent[1] = value_array[j + 1];
|
|
406 k = j - 2;
|
|
407 while (k >= 0 && value_array[k + 1] < cur_ent[1])
|
|
408 {
|
|
409 value_array[k + 2] = value_array[k];
|
|
410 value_array[k + 3] = value_array[k+1];
|
|
411 k -= 2;
|
|
412 }
|
|
413 value_array[k + 2] = cur_ent[0];
|
|
414 value_array[k + 3] = cur_ent[1];
|
|
415 }
|
|
416 }
|
|
417
|
|
418 /* Sort the profile counters for all indirect call sites. Counters
|
|
419 for each call site are allocated in array COUNTERS. */
|
|
420
|
|
421 static void
|
|
422 gcov_sort_icall_topn_counter (const struct gcov_ctr_info *counters)
|
|
423 {
|
|
424 int i;
|
|
425 gcov_type *values;
|
|
426 int n = counters->num;
|
|
427
|
|
428 gcc_assert (!(n % GCOV_ICALL_TOPN_NCOUNTS));
|
|
429 values = counters->values;
|
|
430
|
|
431 for (i = 0; i < n; i += GCOV_ICALL_TOPN_NCOUNTS)
|
|
432 {
|
|
433 gcov_type *value_array = &values[i + 1];
|
|
434 gcov_sort_n_vals (value_array, GCOV_ICALL_TOPN_NCOUNTS - 1);
|
|
435 }
|
|
436 }
|
|
437
|
|
438 /* Sort topn indirect_call profile counters in GI_PTR. */
|
|
439
|
|
440 static void
|
|
441 gcov_sort_topn_counter_arrays (const struct gcov_info *gi_ptr)
|
|
442 {
|
|
443 unsigned int i;
|
|
444 int f_ix;
|
|
445 const struct gcov_fn_info *gfi_ptr;
|
|
446 const struct gcov_ctr_info *ci_ptr;
|
|
447
|
|
448 if (!gi_ptr->merge[GCOV_COUNTER_ICALL_TOPNV])
|
|
449 return;
|
|
450
|
|
451 for (f_ix = 0; (unsigned)f_ix != gi_ptr->n_functions; f_ix++)
|
|
452 {
|
|
453 gfi_ptr = gi_ptr->functions[f_ix];
|
|
454 ci_ptr = gfi_ptr->ctrs;
|
|
455 for (i = 0; i < GCOV_COUNTERS; i++)
|
|
456 {
|
|
457 if (!gi_ptr->merge[i])
|
|
458 continue;
|
|
459 if (i == GCOV_COUNTER_ICALL_TOPNV)
|
|
460 {
|
|
461 gcov_sort_icall_topn_counter (ci_ptr);
|
|
462 break;
|
|
463 }
|
|
464 ci_ptr++;
|
|
465 }
|
|
466 }
|
|
467 }
|
|
468
|
|
469 /* Dump the coverage counts for one gcov_info object. We merge with existing
|
|
470 counts when possible, to avoid growing the .da files ad infinitum. We use
|
|
471 this program's checksum to make sure we only accumulate whole program
|
|
472 statistics to the correct summary. An object file might be embedded
|
|
473 in two separate programs, and we must keep the two program
|
|
474 summaries separate. */
|
|
475
|
|
476 static void
|
|
477 dump_one_gcov (struct gcov_info *gi_ptr, struct gcov_filename *gf,
|
131
|
478 unsigned run_counted, gcov_type run_max)
|
111
|
479 {
|
131
|
480 struct gcov_summary summary = {};
|
111
|
481 int error;
|
|
482 gcov_unsigned_t tag;
|
|
483
|
|
484 fn_buffer = 0;
|
|
485
|
|
486 gcov_sort_topn_counter_arrays (gi_ptr);
|
|
487
|
|
488 error = gcov_exit_open_gcda_file (gi_ptr, gf);
|
|
489 if (error == -1)
|
|
490 return;
|
|
491
|
|
492 tag = gcov_read_unsigned ();
|
|
493 if (tag)
|
|
494 {
|
|
495 /* Merge data from file. */
|
|
496 if (tag != GCOV_DATA_MAGIC)
|
|
497 {
|
|
498 gcov_error ("profiling:%s:Not a gcov data file\n", gf->filename);
|
|
499 goto read_fatal;
|
|
500 }
|
131
|
501 error = merge_one_data (gf->filename, gi_ptr, &summary);
|
111
|
502 if (error == -1)
|
|
503 goto read_fatal;
|
|
504 }
|
|
505
|
|
506 gcov_rewrite ();
|
|
507
|
131
|
508 merge_summary (run_counted, &summary, run_max);
|
111
|
509
|
131
|
510 write_one_data (gi_ptr, &summary);
|
111
|
511 /* fall through */
|
|
512
|
|
513 read_fatal:;
|
|
514 while (fn_buffer)
|
|
515 fn_buffer = free_fn_data (gi_ptr, fn_buffer, GCOV_COUNTERS);
|
|
516
|
|
517 if ((error = gcov_close ()))
|
|
518 gcov_error (error < 0 ?
|
|
519 "profiling:%s:Overflow writing\n" :
|
|
520 "profiling:%s:Error writing\n",
|
|
521 gf->filename);
|
|
522 }
|
|
523
|
|
524
|
|
525 /* Dump all the coverage counts for the program. It first computes program
|
|
526 summary and then traverses gcov_list list and dumps the gcov_info
|
|
527 objects one by one. */
|
|
528
|
|
529 #if !IN_GCOV_TOOL
|
|
530 static
|
|
531 #endif
|
|
532 void
|
|
533 gcov_do_dump (struct gcov_info *list, int run_counted)
|
|
534 {
|
|
535 struct gcov_info *gi_ptr;
|
|
536 struct gcov_filename gf;
|
|
537
|
131
|
538 /* Compute run_max of this program run. */
|
|
539 gcov_type run_max = 0;
|
|
540 for (gi_ptr = list; gi_ptr; gi_ptr = gi_ptr->next)
|
|
541 for (unsigned f_ix = 0; (unsigned)f_ix != gi_ptr->n_functions; f_ix++)
|
|
542 {
|
|
543 const struct gcov_ctr_info *cinfo
|
|
544 = &gi_ptr->functions[f_ix]->ctrs[GCOV_COUNTER_ARCS];
|
|
545
|
|
546 for (unsigned i = 0; i < cinfo->num; i++)
|
|
547 if (run_max < cinfo->values[i])
|
|
548 run_max = cinfo->values[i];
|
|
549 }
|
111
|
550
|
|
551 allocate_filename_struct (&gf);
|
|
552
|
|
553 /* Now merge each file. */
|
|
554 for (gi_ptr = list; gi_ptr; gi_ptr = gi_ptr->next)
|
131
|
555 {
|
|
556 dump_one_gcov (gi_ptr, &gf, run_counted, run_max);
|
|
557 free (gf.filename);
|
|
558 }
|
111
|
559
|
131
|
560 free (gf.prefix);
|
111
|
561 }
|
|
562
|
|
563 #if IN_GCOV_TOOL
|
|
564 const char *
|
|
565 __attribute__ ((unused))
|
|
566 gcov_get_filename (struct gcov_info *list)
|
|
567 {
|
|
568 return list->filename;
|
|
569 }
|
|
570 #endif
|
|
571
|
|
572 #if !IN_GCOV_TOOL
|
|
573 void
|
|
574 __gcov_dump_one (struct gcov_root *root)
|
|
575 {
|
|
576 if (root->dumped)
|
|
577 return;
|
|
578
|
|
579 gcov_do_dump (root->list, root->run_counted);
|
|
580
|
|
581 root->dumped = 1;
|
|
582 root->run_counted = 1;
|
|
583 }
|
|
584
|
|
585 /* Per-dynamic-object gcov state. */
|
|
586 struct gcov_root __gcov_root;
|
|
587
|
|
588 /* Exactly one of these will be live in the process image. */
|
|
589 struct gcov_master __gcov_master =
|
|
590 {GCOV_VERSION, 0};
|
|
591
|
|
592 void
|
|
593 __gcov_exit (void)
|
|
594 {
|
|
595 __gcov_dump_one (&__gcov_root);
|
|
596 if (__gcov_root.next)
|
|
597 __gcov_root.next->prev = __gcov_root.prev;
|
|
598 if (__gcov_root.prev)
|
|
599 __gcov_root.prev->next = __gcov_root.next;
|
|
600 else
|
|
601 __gcov_master.root = __gcov_root.next;
|
|
602
|
|
603 gcov_error_exit ();
|
|
604 }
|
|
605
|
|
606 /* Add a new object file onto the bb chain. Invoked automatically
|
|
607 when running an object file's global ctors. */
|
|
608
|
|
609 void
|
|
610 __gcov_init (struct gcov_info *info)
|
|
611 {
|
|
612 if (!info->version || !info->n_functions)
|
|
613 return;
|
|
614 if (gcov_version (info, info->version, 0))
|
|
615 {
|
|
616 if (!__gcov_root.list)
|
|
617 {
|
|
618 /* Add to master list and at exit function. */
|
|
619 if (gcov_version (NULL, __gcov_master.version, "<master>"))
|
|
620 {
|
|
621 __gcov_root.next = __gcov_master.root;
|
|
622 if (__gcov_master.root)
|
|
623 __gcov_master.root->prev = &__gcov_root;
|
|
624 __gcov_master.root = &__gcov_root;
|
|
625 }
|
|
626 }
|
|
627
|
|
628 info->next = __gcov_root.list;
|
|
629 __gcov_root.list = info;
|
|
630 }
|
|
631 }
|
|
632 #endif /* !IN_GCOV_TOOL */
|
|
633 #endif /* L_gcov */
|
|
634 #endif /* inhibit_libc */
|