1 /* Routines required for instrumenting a program. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989-2014 Free Software Foundation, Inc.
5 This file is part of GCC.
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
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
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.
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/>. */
28 #if defined(inhibit_libc)
29 /* If libc and its header files are not available, provide dummy functions. */
32 void __gcov_init (struct gcov_info
*p
__attribute__ ((unused
))) {}
35 #else /* inhibit_libc */
47 /* The following functions can be called from outside of this file. */
48 extern void gcov_clear (void) ATTRIBUTE_HIDDEN
;
49 extern void gcov_exit (void) ATTRIBUTE_HIDDEN
;
50 extern void set_gcov_dump_complete (void) ATTRIBUTE_HIDDEN
;
51 extern void reset_gcov_dump_complete (void) ATTRIBUTE_HIDDEN
;
52 extern int get_gcov_dump_complete (void) ATTRIBUTE_HIDDEN
;
53 extern void set_gcov_list (struct gcov_info
*) ATTRIBUTE_HIDDEN
;
57 struct gcov_fn_buffer
*next
;
59 struct gcov_fn_info info
;
60 /* note gcov_fn_info ends in a trailing array. */
63 struct gcov_summary_buffer
65 struct gcov_summary_buffer
*next
;
66 struct gcov_summary summary
;
69 /* Chain of per-object gcov structures. */
70 static struct gcov_info
*gcov_list
;
72 /* Set the head of gcov_list. */
74 set_gcov_list (struct gcov_info
*head
)
79 /* Size of the longest file name. */
80 static size_t gcov_max_filename
= 0;
82 /* Flag when the profile has already been dumped via __gcov_dump(). */
83 static int gcov_dump_complete
;
85 /* A global function that get the vaule of gcov_dump_complete. */
88 get_gcov_dump_complete (void)
90 return gcov_dump_complete
;
93 /* A global functino that set the vaule of gcov_dump_complete. Will
94 be used in __gcov_dump() in libgcov-interface.c. */
97 set_gcov_dump_complete (void)
99 gcov_dump_complete
= 1;
102 /* A global functino that set the vaule of gcov_dump_complete. Will
103 be used in __gcov_reset() in libgcov-interface.c. */
106 reset_gcov_dump_complete (void)
108 gcov_dump_complete
= 0;
111 /* A utility function for outputing errors. */
112 static int gcov_error (const char *, ...);
114 static struct gcov_fn_buffer
*
115 free_fn_data (const struct gcov_info
*gi_ptr
, struct gcov_fn_buffer
*buffer
,
118 struct gcov_fn_buffer
*next
;
119 unsigned ix
, n_ctr
= 0;
125 for (ix
= 0; ix
!= limit
; ix
++)
126 if (gi_ptr
->merge
[ix
])
127 free (buffer
->info
.ctrs
[n_ctr
++].values
);
132 static struct gcov_fn_buffer
**
133 buffer_fn_data (const char *filename
, const struct gcov_info
*gi_ptr
,
134 struct gcov_fn_buffer
**end_ptr
, unsigned fn_ix
)
136 unsigned n_ctrs
= 0, ix
= 0;
137 struct gcov_fn_buffer
*fn_buffer
;
140 for (ix
= GCOV_COUNTERS
; ix
--;)
141 if (gi_ptr
->merge
[ix
])
144 len
= sizeof (*fn_buffer
) + sizeof (fn_buffer
->info
.ctrs
[0]) * n_ctrs
;
145 fn_buffer
= (struct gcov_fn_buffer
*) xmalloc (len
);
151 fn_buffer
->fn_ix
= fn_ix
;
152 fn_buffer
->info
.ident
= gcov_read_unsigned ();
153 fn_buffer
->info
.lineno_checksum
= gcov_read_unsigned ();
154 fn_buffer
->info
.cfg_checksum
= gcov_read_unsigned ();
156 for (n_ctrs
= ix
= 0; ix
!= GCOV_COUNTERS
; ix
++)
158 gcov_unsigned_t length
;
161 if (!gi_ptr
->merge
[ix
])
164 if (gcov_read_unsigned () != GCOV_TAG_FOR_COUNTER (ix
))
170 length
= GCOV_TAG_COUNTER_NUM (gcov_read_unsigned ());
171 len
= length
* sizeof (gcov_type
);
172 values
= (gcov_type
*) xmalloc (len
);
176 fn_buffer
->info
.ctrs
[n_ctrs
].num
= length
;
177 fn_buffer
->info
.ctrs
[n_ctrs
].values
= values
;
180 *values
++ = gcov_read_counter ();
184 *end_ptr
= fn_buffer
;
185 return &fn_buffer
->next
;
188 gcov_error ("profiling:%s:Function %u %s %u \n", filename
, fn_ix
,
189 len
? "cannot allocate" : "counter mismatch", len
? len
: ix
);
191 return (struct gcov_fn_buffer
**)free_fn_data (gi_ptr
, fn_buffer
, ix
);
194 /* Add an unsigned value to the current crc */
196 static gcov_unsigned_t
197 crc32_unsigned (gcov_unsigned_t crc32
, gcov_unsigned_t value
)
201 for (ix
= 32; ix
--; value
<<= 1)
205 feedback
= (value
^ crc32
) & 0x80000000 ? 0x04c11db7 : 0;
213 /* Check if VERSION of the info block PTR matches libgcov one.
214 Return 1 on success, or zero in case of versions mismatch.
215 If FILENAME is not NULL, its value used for reporting purposes
216 instead of value from the info block. */
219 gcov_version (struct gcov_info
*ptr
, gcov_unsigned_t version
,
220 const char *filename
)
222 if (version
!= GCOV_VERSION
)
226 GCOV_UNSIGNED2STRING (v
, version
);
227 GCOV_UNSIGNED2STRING (e
, GCOV_VERSION
);
229 gcov_error ("profiling:%s:Version mismatch - expected %.4s got %.4s\n",
230 filename
? filename
: ptr
->filename
, e
, v
);
236 /* Insert counter VALUE into HISTOGRAM. */
239 gcov_histogram_insert(gcov_bucket_type
*histogram
, gcov_type value
)
243 i
= gcov_histo_index(value
);
244 histogram
[i
].num_counters
++;
245 histogram
[i
].cum_value
+= value
;
246 if (value
< histogram
[i
].min_value
)
247 histogram
[i
].min_value
= value
;
250 /* Computes a histogram of the arc counters to place in the summary SUM. */
253 gcov_compute_histogram (struct gcov_summary
*sum
)
255 struct gcov_info
*gi_ptr
;
256 const struct gcov_fn_info
*gfi_ptr
;
257 const struct gcov_ctr_info
*ci_ptr
;
258 struct gcov_ctr_summary
*cs_ptr
;
259 unsigned t_ix
, f_ix
, ctr_info_ix
, ix
;
262 /* This currently only applies to arc counters. */
263 t_ix
= GCOV_COUNTER_ARCS
;
265 /* First check if there are any counts recorded for this counter. */
266 cs_ptr
= &(sum
->ctrs
[t_ix
]);
270 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
272 cs_ptr
->histogram
[h_ix
].num_counters
= 0;
273 cs_ptr
->histogram
[h_ix
].min_value
= cs_ptr
->run_max
;
274 cs_ptr
->histogram
[h_ix
].cum_value
= 0;
277 /* Walk through all the per-object structures and record each of
278 the count values in histogram. */
279 for (gi_ptr
= gcov_list
; gi_ptr
; gi_ptr
= gi_ptr
->next
)
281 if (!gi_ptr
->merge
[t_ix
])
284 /* Find the appropriate index into the gcov_ctr_info array
285 for the counter we are currently working on based on the
286 existence of the merge function pointer for this object. */
287 for (ix
= 0, ctr_info_ix
= 0; ix
< t_ix
; ix
++)
289 if (gi_ptr
->merge
[ix
])
292 for (f_ix
= 0; f_ix
!= gi_ptr
->n_functions
; f_ix
++)
294 gfi_ptr
= gi_ptr
->functions
[f_ix
];
296 if (!gfi_ptr
|| gfi_ptr
->key
!= gi_ptr
)
299 ci_ptr
= &gfi_ptr
->ctrs
[ctr_info_ix
];
300 for (ix
= 0; ix
< ci_ptr
->num
; ix
++)
301 gcov_histogram_insert (cs_ptr
->histogram
, ci_ptr
->values
[ix
]);
307 static char *gi_filename
;
308 /* buffer for the fn_data from another program. */
309 static struct gcov_fn_buffer
*fn_buffer
;
310 /* buffer for summary from other programs to be written out. */
311 static struct gcov_summary_buffer
*sum_buffer
;
312 /* If application calls fork or exec multiple times, we end up storing
313 profile repeadely. We should not account this as multiple runs or
314 functions executed once may mistakely become cold. */
315 static int run_accounted
= 0;
317 /* This funtions computes the program level summary and the histo-gram.
318 It computes and returns CRC32 and stored summary in THIS_PRG. */
320 static gcov_unsigned_t
321 gcov_exit_compute_summary (struct gcov_summary
*this_prg
)
323 struct gcov_info
*gi_ptr
;
324 const struct gcov_fn_info
*gfi_ptr
;
325 struct gcov_ctr_summary
*cs_ptr
;
326 const struct gcov_ctr_info
*ci_ptr
;
329 gcov_unsigned_t c_num
;
330 gcov_unsigned_t crc32
= 0;
332 /* Find the totals for this execution. */
333 memset (this_prg
, 0, sizeof (*this_prg
));
334 for (gi_ptr
= gcov_list
; gi_ptr
; gi_ptr
= gi_ptr
->next
)
336 crc32
= crc32_unsigned (crc32
, gi_ptr
->stamp
);
337 crc32
= crc32_unsigned (crc32
, gi_ptr
->n_functions
);
339 for (f_ix
= 0; (unsigned)f_ix
!= gi_ptr
->n_functions
; f_ix
++)
341 gfi_ptr
= gi_ptr
->functions
[f_ix
];
343 if (gfi_ptr
&& gfi_ptr
->key
!= gi_ptr
)
346 crc32
= crc32_unsigned (crc32
, gfi_ptr
? gfi_ptr
->cfg_checksum
: 0);
347 crc32
= crc32_unsigned (crc32
,
348 gfi_ptr
? gfi_ptr
->lineno_checksum
: 0);
352 ci_ptr
= gfi_ptr
->ctrs
;
353 for (t_ix
= 0; t_ix
!= GCOV_COUNTERS_SUMMABLE
; t_ix
++)
355 if (!gi_ptr
->merge
[t_ix
])
358 cs_ptr
= &(this_prg
->ctrs
[t_ix
]);
359 cs_ptr
->num
+= ci_ptr
->num
;
360 crc32
= crc32_unsigned (crc32
, ci_ptr
->num
);
362 for (c_num
= 0; c_num
< ci_ptr
->num
; c_num
++)
364 cs_ptr
->sum_all
+= ci_ptr
->values
[c_num
];
365 if (cs_ptr
->run_max
< ci_ptr
->values
[c_num
])
366 cs_ptr
->run_max
= ci_ptr
->values
[c_num
];
372 gcov_compute_histogram (this_prg
);
376 /* A struct that bundles all the related information about the
378 struct gcov_filename_aux
{
379 char *gi_filename_up
;
380 int gcov_prefix_strip
;
381 size_t prefix_length
;
384 /* Including system dependent components. */
385 #include "libgcov-driver-system.c"
387 /* This function merges counters in GI_PTR to an existing gcda file.
389 Return -1 on error. In this case, caller will goto read_fatal. */
392 gcov_exit_merge_gcda (struct gcov_info
*gi_ptr
,
393 struct gcov_summary
*prg_p
,
394 struct gcov_summary
*this_prg
,
395 gcov_position_t
*summary_pos_p
,
396 gcov_position_t
*eof_pos_p
,
397 gcov_unsigned_t crc32
)
399 gcov_unsigned_t tag
, length
;
403 struct gcov_fn_buffer
**fn_tail
= &fn_buffer
;
404 struct gcov_summary_buffer
**sum_tail
= &sum_buffer
;
406 length
= gcov_read_unsigned ();
407 if (!gcov_version (gi_ptr
, length
, gi_filename
))
410 length
= gcov_read_unsigned ();
411 if (length
!= gi_ptr
->stamp
)
412 /* Read from a different compilation. Overwrite the file. */
415 /* Look for program summary. */
418 struct gcov_summary tmp
;
420 *eof_pos_p
= gcov_position ();
421 tag
= gcov_read_unsigned ();
422 if (tag
!= GCOV_TAG_PROGRAM_SUMMARY
)
426 length
= gcov_read_unsigned ();
427 gcov_read_summary (&tmp
);
428 if ((error
= gcov_is_error ()))
432 /* Save all summaries after the one that will be
433 merged into below. These will need to be rewritten
434 as histogram merging may change the number of non-zero
435 histogram entries that will be emitted, and thus the
436 size of the merged summary. */
437 (*sum_tail
) = (struct gcov_summary_buffer
*)
438 xmalloc (sizeof(struct gcov_summary_buffer
));
439 (*sum_tail
)->summary
= tmp
;
440 (*sum_tail
)->next
= 0;
441 sum_tail
= &((*sum_tail
)->next
);
444 if (tmp
.checksum
!= crc32
)
447 for (t_ix
= 0; t_ix
!= GCOV_COUNTERS_SUMMABLE
; t_ix
++)
448 if (tmp
.ctrs
[t_ix
].num
!= this_prg
->ctrs
[t_ix
].num
)
451 *summary_pos_p
= *eof_pos_p
;
456 /* Merge execution counts for each function. */
457 for (f_ix
= 0; (unsigned)f_ix
!= gi_ptr
->n_functions
;
458 f_ix
++, tag
= gcov_read_unsigned ())
460 const struct gcov_ctr_info
*ci_ptr
;
461 const struct gcov_fn_info
*gfi_ptr
= gi_ptr
->functions
[f_ix
];
463 if (tag
!= GCOV_TAG_FUNCTION
)
466 length
= gcov_read_unsigned ();
468 /* This function did not appear in the other program.
469 We have nothing to merge. */
472 if (length
!= GCOV_TAG_FUNCTION_LENGTH
)
475 if (!gfi_ptr
|| gfi_ptr
->key
!= gi_ptr
)
477 /* This function appears in the other program. We
478 need to buffer the information in order to write
479 it back out -- we'll be inserting data before
480 this point, so cannot simply keep the data in the
482 fn_tail
= buffer_fn_data (gi_filename
,
483 gi_ptr
, fn_tail
, f_ix
);
489 length
= gcov_read_unsigned ();
490 if (length
!= gfi_ptr
->ident
)
493 length
= gcov_read_unsigned ();
494 if (length
!= gfi_ptr
->lineno_checksum
)
497 length
= gcov_read_unsigned ();
498 if (length
!= gfi_ptr
->cfg_checksum
)
501 ci_ptr
= gfi_ptr
->ctrs
;
502 for (t_ix
= 0; t_ix
< GCOV_COUNTERS
; t_ix
++)
504 gcov_merge_fn merge
= gi_ptr
->merge
[t_ix
];
509 tag
= gcov_read_unsigned ();
510 length
= gcov_read_unsigned ();
511 if (tag
!= GCOV_TAG_FOR_COUNTER (t_ix
)
512 || length
!= GCOV_TAG_COUNTER_LENGTH (ci_ptr
->num
))
514 (*merge
) (ci_ptr
->values
, ci_ptr
->num
);
517 if ((error
= gcov_is_error ()))
524 gcov_error ("profiling:%s:Merge mismatch for %s %u\n",
525 gi_filename
, f_ix
>= 0 ? "function" : "summary",
526 f_ix
< 0 ? -1 - f_ix
: f_ix
);
532 gcov_error ("profiling:%s:%s merging\n", gi_filename
,
533 error
< 0 ? "Overflow": "Error");
537 /* Write counters in GI_PTR and the summary in PRG to a gcda file. In
538 the case of appending to an existing file, SUMMARY_POS will be non-zero.
539 We will write the file starting from SUMMAY_POS. */
542 gcov_exit_write_gcda (const struct gcov_info
*gi_ptr
,
543 const struct gcov_summary
*prg_p
,
544 const gcov_position_t eof_pos
,
545 const gcov_position_t summary_pos
)
548 struct gcov_summary_buffer
*next_sum_buffer
;
550 /* Write out the data. */
553 gcov_write_tag_length (GCOV_DATA_MAGIC
, GCOV_VERSION
);
554 gcov_write_unsigned (gi_ptr
->stamp
);
558 gcov_seek (summary_pos
);
560 /* Generate whole program statistics. */
561 gcov_write_summary (GCOV_TAG_PROGRAM_SUMMARY
, prg_p
);
563 /* Rewrite all the summaries that were after the summary we merged
564 into. This is necessary as the merged summary may have a different
565 size due to the number of non-zero histogram entries changing after
570 gcov_write_summary (GCOV_TAG_PROGRAM_SUMMARY
, &sum_buffer
->summary
);
571 next_sum_buffer
= sum_buffer
->next
;
573 sum_buffer
= next_sum_buffer
;
576 /* Write execution counts for each function. */
577 for (f_ix
= 0; f_ix
!= gi_ptr
->n_functions
; f_ix
++)
579 unsigned buffered
= 0;
580 const struct gcov_fn_info
*gfi_ptr
;
581 const struct gcov_ctr_info
*ci_ptr
;
582 gcov_unsigned_t length
;
585 if (fn_buffer
&& fn_buffer
->fn_ix
== f_ix
)
587 /* Buffered data from another program. */
589 gfi_ptr
= &fn_buffer
->info
;
590 length
= GCOV_TAG_FUNCTION_LENGTH
;
594 gfi_ptr
= gi_ptr
->functions
[f_ix
];
595 if (gfi_ptr
&& gfi_ptr
->key
== gi_ptr
)
596 length
= GCOV_TAG_FUNCTION_LENGTH
;
601 gcov_write_tag_length (GCOV_TAG_FUNCTION
, length
);
605 gcov_write_unsigned (gfi_ptr
->ident
);
606 gcov_write_unsigned (gfi_ptr
->lineno_checksum
);
607 gcov_write_unsigned (gfi_ptr
->cfg_checksum
);
609 ci_ptr
= gfi_ptr
->ctrs
;
610 for (t_ix
= 0; t_ix
< GCOV_COUNTERS
; t_ix
++)
612 gcov_unsigned_t n_counts
;
615 if (!gi_ptr
->merge
[t_ix
])
618 n_counts
= ci_ptr
->num
;
619 gcov_write_tag_length (GCOV_TAG_FOR_COUNTER (t_ix
),
620 GCOV_TAG_COUNTER_LENGTH (n_counts
));
621 c_ptr
= ci_ptr
->values
;
623 gcov_write_counter (*c_ptr
++);
627 fn_buffer
= free_fn_data (gi_ptr
, fn_buffer
, GCOV_COUNTERS
);
630 gcov_write_unsigned (0);
633 /* Helper function for merging summary.
634 Return -1 on error. Return 0 on success. */
637 gcov_exit_merge_summary (const struct gcov_info
*gi_ptr
, struct gcov_summary
*prg
,
638 struct gcov_summary
*this_prg
, gcov_unsigned_t crc32
,
639 struct gcov_summary
*all_prg
__attribute__ ((unused
)))
641 struct gcov_ctr_summary
*cs_prg
, *cs_tprg
;
644 /* summary for all instances of program. */
645 struct gcov_ctr_summary
*cs_all
;
648 /* Merge the summaries. */
649 for (t_ix
= 0; t_ix
< GCOV_COUNTERS_SUMMABLE
; t_ix
++)
651 cs_prg
= &(prg
->ctrs
[t_ix
]);
652 cs_tprg
= &(this_prg
->ctrs
[t_ix
]);
654 if (gi_ptr
->merge
[t_ix
])
656 int first
= !cs_prg
->runs
;
661 cs_prg
->num
= cs_tprg
->num
;
662 cs_prg
->sum_all
+= cs_tprg
->sum_all
;
663 if (cs_prg
->run_max
< cs_tprg
->run_max
)
664 cs_prg
->run_max
= cs_tprg
->run_max
;
665 cs_prg
->sum_max
+= cs_tprg
->run_max
;
667 memcpy (cs_prg
->histogram
, cs_tprg
->histogram
,
668 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
670 gcov_histogram_merge (cs_prg
->histogram
, cs_tprg
->histogram
);
672 else if (cs_prg
->runs
)
674 gcov_error ("profiling:%s:Merge mismatch for summary.\n",
679 cs_all
= &all_prg
->ctrs
[t_ix
];
680 if (!cs_all
->runs
&& cs_prg
->runs
)
682 cs_all
->num
= cs_prg
->num
;
683 cs_all
->runs
= cs_prg
->runs
;
684 cs_all
->sum_all
= cs_prg
->sum_all
;
685 cs_all
->run_max
= cs_prg
->run_max
;
686 cs_all
->sum_max
= cs_prg
->sum_max
;
688 else if (!all_prg
->checksum
689 /* Don't compare the histograms, which may have slight
690 variations depending on the order they were updated
691 due to the truncating integer divides used in the
693 && (cs_all
->num
!= cs_prg
->num
694 || cs_all
->runs
!= cs_prg
->runs
695 || cs_all
->sum_all
!= cs_prg
->sum_all
696 || cs_all
->run_max
!= cs_prg
->run_max
697 || cs_all
->sum_max
!= cs_prg
->sum_max
))
699 gcov_error ("profiling:%s:Data file mismatch - some "
700 "data files may have been concurrently "
701 "updated without locking support\n", gi_filename
);
702 all_prg
->checksum
= ~0u;
707 prg
->checksum
= crc32
;
712 /* Dump the coverage counts for one gcov_info object. We merge with existing
713 counts when possible, to avoid growing the .da files ad infinitum. We use
714 this program's checksum to make sure we only accumulate whole program
715 statistics to the correct summary. An object file might be embedded
716 in two separate programs, and we must keep the two program
717 summaries separate. */
720 gcov_exit_dump_gcov (struct gcov_info
*gi_ptr
, struct gcov_filename_aux
*gf
,
721 gcov_unsigned_t crc32
, struct gcov_summary
*all_prg
,
722 struct gcov_summary
*this_prg
)
724 struct gcov_summary prg
; /* summary for this object over all program. */
727 gcov_position_t summary_pos
= 0;
728 gcov_position_t eof_pos
= 0;
733 error
= gcov_exit_open_gcda_file (gi_ptr
, gf
);
737 tag
= gcov_read_unsigned ();
740 /* Merge data from file. */
741 if (tag
!= GCOV_DATA_MAGIC
)
743 gcov_error ("profiling:%s:Not a gcov data file\n", gi_filename
);
746 error
= gcov_exit_merge_gcda (gi_ptr
, &prg
, this_prg
, &summary_pos
, &eof_pos
,
756 memset (&prg
, 0, sizeof (prg
));
757 summary_pos
= eof_pos
;
760 error
= gcov_exit_merge_summary (gi_ptr
, &prg
, this_prg
, crc32
, all_prg
);
764 gcov_exit_write_gcda (gi_ptr
, &prg
, eof_pos
, summary_pos
);
769 fn_buffer
= free_fn_data (gi_ptr
, fn_buffer
, GCOV_COUNTERS
);
771 if ((error
= gcov_close ()))
772 gcov_error (error
< 0 ?
773 "profiling:%s:Overflow writing\n" :
774 "profiling:%s:Error writing\n",
779 /* Dump all the coverage counts for the program. It first computes program
780 summary and then traverses gcov_list list and dumps the gcov_info
781 objects one by one. */
786 struct gcov_info
*gi_ptr
;
787 struct gcov_filename_aux gf
;
788 gcov_unsigned_t crc32
;
789 struct gcov_summary all_prg
;
790 struct gcov_summary this_prg
;
792 /* Prevent the counters from being dumped a second time on exit when the
793 application already wrote out the profile using __gcov_dump(). */
794 if (gcov_dump_complete
)
797 crc32
= gcov_exit_compute_summary (&this_prg
);
799 allocate_filename_struct (&gf
);
801 memset (&all_prg
, 0, sizeof (all_prg
));
804 /* Now merge each file. */
805 for (gi_ptr
= gcov_list
; gi_ptr
; gi_ptr
= gi_ptr
->next
)
806 gcov_exit_dump_gcov (gi_ptr
, &gf
, crc32
, &all_prg
, &this_prg
);
813 /* Reset all counters to zero. */
818 const struct gcov_info
*gi_ptr
;
820 for (gi_ptr
= gcov_list
; gi_ptr
; gi_ptr
= gi_ptr
->next
)
824 for (f_ix
= 0; f_ix
< gi_ptr
->n_functions
; f_ix
++)
827 const struct gcov_fn_info
*gfi_ptr
= gi_ptr
->functions
[f_ix
];
829 if (!gfi_ptr
|| gfi_ptr
->key
!= gi_ptr
)
831 const struct gcov_ctr_info
*ci_ptr
= gfi_ptr
->ctrs
;
832 for (t_ix
= 0; t_ix
!= GCOV_COUNTERS
; t_ix
++)
834 if (!gi_ptr
->merge
[t_ix
])
837 memset (ci_ptr
->values
, 0, sizeof (gcov_type
) * ci_ptr
->num
);
844 /* Add a new object file onto the bb chain. Invoked automatically
845 when running an object file's global ctors. */
848 __gcov_init (struct gcov_info
*info
)
850 if (!info
->version
|| !info
->n_functions
)
852 if (gcov_version (info
, info
->version
, 0))
854 size_t filename_length
= strlen(info
->filename
);
856 /* Refresh the longest file name information */
857 if (filename_length
> gcov_max_filename
)
858 gcov_max_filename
= filename_length
;
863 info
->next
= gcov_list
;
870 #endif /* inhibit_libc */