GCC Wikia
Advertisement

このページを編集する際は,編集に関する方針に従ってください.[]

概要[]

引数[]

  • void

実装[]

 166 /* Read in the counts file, if available.  */
167 
168 static void
169 read_counts_file (void)
170 {
171   gcov_unsigned_t fn_ident = 0;
172   gcov_unsigned_t checksum = -1;
173   counts_entry_t *summaried = NULL;
174   unsigned seen_summary = 0;
175   gcov_unsigned_t tag;
176   int is_error = 0;
177 
178   if (!gcov_open (da_file_name, 1))
179     return;
180 
181   if (!gcov_magic (gcov_read_unsigned (), GCOV_DATA_MAGIC))
182     {
183       warning (0, "%qs is not a gcov data file", da_file_name);
184       gcov_close ();
185       return;
186     }
187   else if ((tag = gcov_read_unsigned ()) != GCOV_VERSION)
188     {
189       char v[4], e[4];
190 
191       GCOV_UNSIGNED2STRING (v, tag);
192       GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
193 
194       warning (0, "%qs is version %q.*s, expected version %q.*s",
195                da_file_name, 4, v, 4, e);
196       gcov_close ();
197       return;
198     }
199 
 200   /* Read and discard the stamp.  */
201   gcov_read_unsigned ();
202   
203   counts_hash = htab_create (10,
204                              htab_counts_entry_hash, htab_counts_entry_eq,
205                              htab_counts_entry_del);
206   while ((tag = gcov_read_unsigned ()))
207     {
208       gcov_unsigned_t length;
209       gcov_position_t offset;
210 
211       length = gcov_read_unsigned ();
212       offset = gcov_position ();
213       if (tag == GCOV_TAG_FUNCTION)
214         {
215           fn_ident = gcov_read_unsigned ();
216           checksum = gcov_read_unsigned ();
217           if (seen_summary)
218             {
 219               /* We have already seen a summary, this means that this
 220                  new function begins a new set of program runs. We
 221                  must unlink the summaried chain.  */
222               counts_entry_t *entry, *chain;
223 
224               for (entry = summaried; entry; entry = chain)
225                 {
226                   chain = entry->chain;
227                   entry->chain = NULL;
228                 }
229               summaried = NULL;
230               seen_summary = 0;
231             }
232         }
233       else if (tag == GCOV_TAG_PROGRAM_SUMMARY)
234         {
235           counts_entry_t *entry;
236           struct gcov_summary summary;
237 
238           gcov_read_summary (&summary);
239           seen_summary = 1;
240           for (entry = summaried; entry; entry = entry->chain)
241             {
242               struct gcov_ctr_summary *csum = &summary.ctrs[entry->ctr];
243 
244               entry->summary.runs += csum->runs;
245               entry->summary.sum_all += csum->sum_all;
246               if (entry->summary.run_max < csum->run_max)
247                 entry->summary.run_max = csum->run_max;
248               entry->summary.sum_max += csum->sum_max;
249             }
250         }
251       else if (GCOV_TAG_IS_COUNTER (tag) && fn_ident)
252         {
253           counts_entry_t **slot, *entry, elt;
254           unsigned n_counts = GCOV_TAG_COUNTER_NUM (length);
255           unsigned ix;
256 
257           elt.ident = fn_ident;
258           elt.ctr = GCOV_COUNTER_FOR_TAG (tag);
259 
260           slot = (counts_entry_t **) htab_find_slot
261             (counts_hash, &elt, INSERT);
262           entry = *slot;
263           if (!entry)
264             {
265               *slot = entry = xcalloc (1, sizeof (counts_entry_t));
266               entry->ident = elt.ident;
267               entry->ctr = elt.ctr;
268               entry->checksum = checksum;
269               entry->summary.num = n_counts;
270               entry->counts = xcalloc (n_counts, sizeof (gcov_type));
271             }
272           else if (entry->checksum != checksum)
273             {
274               error ("coverage mismatch for function %u while reading execution counters",
275                      fn_ident);
276               error ("checksum is %x instead of %x", entry->checksum, checksum);
277               htab_delete (counts_hash);
278               break;
279             }
280           else if (entry->summary.num != n_counts)
281             {
282               error ("coverage mismatch for function %u while reading execution counters",
283                      fn_ident);
284               error ("number of counters is %d instead of %d", entry->summary.num, n_counts);
285               htab_delete (counts_hash);
286               break;
287             }
288           else if (elt.ctr >= GCOV_COUNTERS_SUMMABLE)
289             {
290               error ("cannot merge separate %s counters for function %u",
291                      ctr_names[elt.ctr], fn_ident);
292               goto skip_merge;
293             }
294 
295           if (elt.ctr < GCOV_COUNTERS_SUMMABLE
 296               /* This should always be true for a just allocated entry,
 297                  and always false for an existing one. Check this way, in
 298                  case the gcov file is corrupt.  */
299               && (!entry->chain || summaried != entry))
300             {
301               entry->chain = summaried;
302               summaried = entry;
303             }
304           for (ix = 0; ix != n_counts; ix++)
305             entry->counts[ix] += gcov_read_counter ();
306         skip_merge:;
307         }
308       gcov_sync (offset, length);
309       if ((is_error = gcov_is_error ()))
310         {
311           error (is_error < 0 ? "%qs has overflowed" : "%qs is corrupted",
312                  da_file_name);
313           htab_delete (counts_hash);
314           break;
315         }
316     }
317 
318   gcov_close ();
319 }


リンク元

Advertisement