comparison gcc/gcov-io.h @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents 77e2b8dfacca
children 84e7813d76e9
comparison
equal deleted inserted replaced
15:561a7518be6b 16:04ced10e8804
1 /* File format for coverage information 1 /* File format for coverage information
2 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2 Copyright (C) 1996-2017 Free Software Foundation, Inc.
3 2003, 2004, 2005, 2008, 2009 Free Software Foundation, Inc.
4 Contributed by Bob Manson <manson@cygnus.com>. 3 Contributed by Bob Manson <manson@cygnus.com>.
5 Completely remangled by Nathan Sidwell <nathan@codesourcery.com>. 4 Completely remangled by Nathan Sidwell <nathan@codesourcery.com>.
6 5
7 This file is part of GCC. 6 This file is part of GCC.
8 7
62 increments fast enough and cycles slow enough to distinguish 61 increments fast enough and cycles slow enough to distinguish
63 different compile/run/compile cycles. 62 different compile/run/compile cycles.
64 63
65 Although the ident and version are formally 32 bit numbers, they 64 Although the ident and version are formally 32 bit numbers, they
66 are derived from 4 character ASCII strings. The version number 65 are derived from 4 character ASCII strings. The version number
67 consists of the single character major version number, a two 66 consists of a two character major version number
68 character minor version number (leading zero for versions less than 67 (first digit starts from 'A' letter to not to clash with the older
69 10), and a single character indicating the status of the release. 68 numbering scheme), the single character minor version number,
69 and a single character indicating the status of the release.
70 That will be 'e' experimental, 'p' prerelease and 'r' for release. 70 That will be 'e' experimental, 'p' prerelease and 'r' for release.
71 Because, by good fortune, these are in alphabetical order, string 71 Because, by good fortune, these are in alphabetical order, string
72 collating can be used to compare version strings. Be aware that 72 collating can be used to compare version strings. Be aware that
73 the 'e' designation will (naturally) be unstable and might be 73 the 'e' designation will (naturally) be unstable and might be
74 incompatible with itself. For gcc 3.4 experimental, it would be 74 incompatible with itself. For gcc 17.0 experimental, it would be
75 '304e' (0x33303465). When the major version reaches 10, the 75 'B70e' (0x42373065). As we currently do not release more than 5 minor
76 letters A-Z will be used. Assuming minor increments releases every 76 releases, the single character should be always fine. Major number
77 6 months, we have to make a major increment every 50 years. 77 is currently changed roughly every year, which gives us space
78 Assuming major increments releases every 5 years, we're ok for the 78 for next 250 years (maximum allowed number would be 259.9).
79 next 155 years -- good enough for me.
80 79
81 A record has a tag, length and variable amount of data. 80 A record has a tag, length and variable amount of data.
82 81
83 record: header data 82 record: header data
84 header: int32:tag int32:length 83 header: int32:tag int32:length
97 themselves, and is similar to the standard section numbering used 96 themselves, and is similar to the standard section numbering used
98 in technical documents. Level values [1..3f] are used for common 97 in technical documents. Level values [1..3f] are used for common
99 tags, values [41..9f] for the notes file and [a1..ff] for the data 98 tags, values [41..9f] for the notes file and [a1..ff] for the data
100 file. 99 file.
101 100
102 The basic block graph file contains the following records 101 The notes file contains the following records
103 note: unit function-graph* 102 note: unit function-graph*
104 unit: header int32:checksum string:source 103 unit: header int32:checksum string:source
105 function-graph: announce_function basic_blocks {arcs | lines}* 104 function-graph: announce_function basic_blocks {arcs | lines}*
106 announce_function: header int32:ident int32:checksum 105 announce_function: header int32:ident
106 int32:lineno_checksum int32:cfg_checksum
107 string:name string:source int32:lineno 107 string:name string:source int32:lineno
108 basic_block: header int32:flags* 108 basic_block: header int32:flags*
109 arcs: header int32:block_no arc* 109 arcs: header int32:block_no arc*
110 arc: int32:dest_block int32:flags 110 arc: int32:dest_block int32:flags
111 lines: header int32:block_no line* 111 lines: header int32:block_no line*
127 interleaved in any manner. The current filename follows the order 127 interleaved in any manner. The current filename follows the order
128 the LINES records are stored in the file, *not* the ordering of the 128 the LINES records are stored in the file, *not* the ordering of the
129 blocks they are for. 129 blocks they are for.
130 130
131 The data file contains the following records. 131 The data file contains the following records.
132 data: {unit function-data* summary:object summary:program*}* 132 data: {unit summary:object summary:program* function-data*}*
133 unit: header int32:checksum 133 unit: header int32:checksum
134 function-data: announce_function arc_counts 134 function-data: announce_function present counts
135 announce_function: header int32:ident int32:checksum 135 announce_function: header int32:ident
136 arc_counts: header int64:count* 136 int32:lineno_checksum int32:cfg_checksum
137 summary: int32:checksum {count-summary}GCOV_COUNTERS 137 present: header int32:present
138 counts: header int64:count*
139 summary: int32:checksum {count-summary}GCOV_COUNTERS_SUMMABLE
138 count-summary: int32:num int32:runs int64:sum 140 count-summary: int32:num int32:runs int64:sum
139 int64:max int64:sum_max 141 int64:max int64:sum_max histogram
142 histogram: {int32:bitvector}8 histogram-buckets*
143 histogram-buckets: int32:num int64:min int64:sum
140 144
141 The ANNOUNCE_FUNCTION record is the same as that in the note file, 145 The ANNOUNCE_FUNCTION record is the same as that in the note file,
142 but without the source location. The ARC_COUNTS gives the counter 146 but without the source location. The COUNTS gives the
143 values for those arcs that are instrumented. The SUMMARY records 147 counter values for instrumented features. The about the whole
144 give information about the whole object file and about the whole
145 program. The checksum is used for whole program summaries, and 148 program. The checksum is used for whole program summaries, and
146 disambiguates different programs which include the same 149 disambiguates different programs which include the same
147 instrumented object file. There may be several program summaries, 150 instrumented object file. There may be several program summaries,
148 each with a unique checksum. The object summary's checksum is zero. 151 each with a unique checksum. The object summary's checksum is
149 Note that the data file might contain information from several runs 152 zero. Note that the data file might contain information from
150 concatenated, or the data might be merged. 153 several runs concatenated, or the data might be merged.
151 154
152 This file is included by both the compiler, gcov tools and the 155 This file is included by both the compiler, gcov tools and the
153 runtime support library libgcov. IN_LIBGCOV and IN_GCOV are used to 156 runtime support library libgcov. IN_LIBGCOV and IN_GCOV are used to
154 distinguish which case is which. If IN_LIBGCOV is nonzero, 157 distinguish which case is which. If IN_LIBGCOV is nonzero,
155 libgcov is being built. If IN_GCOV is nonzero, the gcov tools are 158 libgcov is being built. If IN_GCOV is nonzero, the gcov tools are
159 those functions are). */ 162 those functions are). */
160 163
161 #ifndef GCC_GCOV_IO_H 164 #ifndef GCC_GCOV_IO_H
162 #define GCC_GCOV_IO_H 165 #define GCC_GCOV_IO_H
163 166
164 #if IN_LIBGCOV 167 #ifndef IN_LIBGCOV
165 /* About the target */
166
167 #if BITS_PER_UNIT == 8
168 typedef unsigned gcov_unsigned_t __attribute__ ((mode (SI)));
169 typedef unsigned gcov_position_t __attribute__ ((mode (SI)));
170 #if LONG_LONG_TYPE_SIZE > 32
171 typedef signed gcov_type __attribute__ ((mode (DI)));
172 #else
173 typedef signed gcov_type __attribute__ ((mode (SI)));
174 #endif
175 #else
176 #if BITS_PER_UNIT == 16
177 typedef unsigned gcov_unsigned_t __attribute__ ((mode (HI)));
178 typedef unsigned gcov_position_t __attribute__ ((mode (HI)));
179 #if LONG_LONG_TYPE_SIZE > 32
180 typedef signed gcov_type __attribute__ ((mode (SI)));
181 #else
182 typedef signed gcov_type __attribute__ ((mode (HI)));
183 #endif
184 #else
185 typedef unsigned gcov_unsigned_t __attribute__ ((mode (QI)));
186 typedef unsigned gcov_position_t __attribute__ ((mode (QI)));
187 #if LONG_LONG_TYPE_SIZE > 32
188 typedef signed gcov_type __attribute__ ((mode (HI)));
189 #else
190 typedef signed gcov_type __attribute__ ((mode (QI)));
191 #endif
192 #endif
193 #endif
194
195
196 #if defined (TARGET_POSIX_IO)
197 #define GCOV_LOCKED 1
198 #else
199 #define GCOV_LOCKED 0
200 #endif
201
202 #else /* !IN_LIBGCOV */
203 /* About the host */ 168 /* About the host */
204 169
205 typedef unsigned gcov_unsigned_t; 170 typedef unsigned gcov_unsigned_t;
206 typedef unsigned gcov_position_t; 171 typedef unsigned gcov_position_t;
207 /* gcov_type is typedef'd elsewhere for the compiler */ 172 /* gcov_type is typedef'd elsewhere for the compiler */
208 #if IN_GCOV 173 #if IN_GCOV
209 #define GCOV_LINKAGE static 174 #define GCOV_LINKAGE static
210 typedef HOST_WIDEST_INT gcov_type; 175 typedef int64_t gcov_type;
176 typedef uint64_t gcov_type_unsigned;
211 #if IN_GCOV > 0 177 #if IN_GCOV > 0
212 #include <sys/types.h> 178 #include <sys/types.h>
213 #endif 179 #endif
214 #else /*!IN_GCOV */
215 #define GCOV_TYPE_SIZE (LONG_LONG_TYPE_SIZE > 32 ? 64 : 32)
216 #endif 180 #endif
217 181
218 #if defined (HOST_HAS_F_SETLKW) 182 #if defined (HOST_HAS_F_SETLKW)
219 #define GCOV_LOCKED 1 183 #define GCOV_LOCKED 1
220 #else 184 #else
221 #define GCOV_LOCKED 0 185 #define GCOV_LOCKED 0
222 #endif 186 #endif
223 187
224 #endif /* !IN_LIBGCOV */
225
226 /* In gcov we want function linkage to be static. In the compiler we want
227 it extern, so that they can be accessed from elsewhere. In libgcov we
228 need these functions to be extern, so prefix them with __gcov. In
229 libgcov they must also be hidden so that the instance in the executable
230 is not also used in a DSO. */
231 #if IN_LIBGCOV
232
233 #include "tconfig.h"
234
235 #define gcov_var __gcov_var
236 #define gcov_open __gcov_open
237 #define gcov_close __gcov_close
238 #define gcov_write_tag_length __gcov_write_tag_length
239 #define gcov_position __gcov_position
240 #define gcov_seek __gcov_seek
241 #define gcov_rewrite __gcov_rewrite
242 #define gcov_is_error __gcov_is_error
243 #define gcov_write_unsigned __gcov_write_unsigned
244 #define gcov_write_counter __gcov_write_counter
245 #define gcov_write_summary __gcov_write_summary
246 #define gcov_read_unsigned __gcov_read_unsigned
247 #define gcov_read_counter __gcov_read_counter
248 #define gcov_read_summary __gcov_read_summary
249
250 /* Poison these, so they don't accidentally slip in. */
251 #pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length
252 #pragma GCC poison gcov_read_string gcov_sync gcov_time gcov_magic
253
254 #ifdef HAVE_GAS_HIDDEN
255 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
256 #else
257 #define ATTRIBUTE_HIDDEN 188 #define ATTRIBUTE_HIDDEN
258 #endif 189
259 190 #endif /* !IN_LIBGOCV */
260 #else
261
262 #define ATTRIBUTE_HIDDEN
263
264 #endif
265 191
266 #ifndef GCOV_LINKAGE 192 #ifndef GCOV_LINKAGE
267 #define GCOV_LINKAGE extern 193 #define GCOV_LINKAGE extern
194 #endif
195
196 #if IN_LIBGCOV
197 #define gcov_nonruntime_assert(EXPR) ((void)(0 && (EXPR)))
198 #else
199 #define gcov_nonruntime_assert(EXPR) gcc_assert (EXPR)
200 #define gcov_error(...) fatal_error (input_location, __VA_ARGS__)
268 #endif 201 #endif
269 202
270 /* File suffixes. */ 203 /* File suffixes. */
271 #define GCOV_DATA_SUFFIX ".gcda" 204 #define GCOV_DATA_SUFFIX ".gcda"
272 #define GCOV_NOTE_SUFFIX ".gcno" 205 #define GCOV_NOTE_SUFFIX ".gcno"
292 file. Values [41..9f] for those in the note file and [a1..ff] for 225 file. Values [41..9f] for those in the note file and [a1..ff] for
293 the data file. The tag value zero is used as an explicit end of 226 the data file. The tag value zero is used as an explicit end of
294 file marker -- it is not required to be present. */ 227 file marker -- it is not required to be present. */
295 228
296 #define GCOV_TAG_FUNCTION ((gcov_unsigned_t)0x01000000) 229 #define GCOV_TAG_FUNCTION ((gcov_unsigned_t)0x01000000)
297 #define GCOV_TAG_FUNCTION_LENGTH (2) 230 #define GCOV_TAG_FUNCTION_LENGTH (3)
298 #define GCOV_TAG_BLOCKS ((gcov_unsigned_t)0x01410000) 231 #define GCOV_TAG_BLOCKS ((gcov_unsigned_t)0x01410000)
299 #define GCOV_TAG_BLOCKS_LENGTH(NUM) (NUM) 232 #define GCOV_TAG_BLOCKS_LENGTH(NUM) (NUM)
300 #define GCOV_TAG_BLOCKS_NUM(LENGTH) (LENGTH)
301 #define GCOV_TAG_ARCS ((gcov_unsigned_t)0x01430000) 233 #define GCOV_TAG_ARCS ((gcov_unsigned_t)0x01430000)
302 #define GCOV_TAG_ARCS_LENGTH(NUM) (1 + (NUM) * 2) 234 #define GCOV_TAG_ARCS_LENGTH(NUM) (1 + (NUM) * 2)
303 #define GCOV_TAG_ARCS_NUM(LENGTH) (((LENGTH) - 1) / 2) 235 #define GCOV_TAG_ARCS_NUM(LENGTH) (((LENGTH) - 1) / 2)
304 #define GCOV_TAG_LINES ((gcov_unsigned_t)0x01450000) 236 #define GCOV_TAG_LINES ((gcov_unsigned_t)0x01450000)
305 #define GCOV_TAG_COUNTER_BASE ((gcov_unsigned_t)0x01a10000) 237 #define GCOV_TAG_COUNTER_BASE ((gcov_unsigned_t)0x01a10000)
306 #define GCOV_TAG_COUNTER_LENGTH(NUM) ((NUM) * 2) 238 #define GCOV_TAG_COUNTER_LENGTH(NUM) ((NUM) * 2)
307 #define GCOV_TAG_COUNTER_NUM(LENGTH) ((LENGTH) / 2) 239 #define GCOV_TAG_COUNTER_NUM(LENGTH) ((LENGTH) / 2)
308 #define GCOV_TAG_OBJECT_SUMMARY ((gcov_unsigned_t)0xa1000000) 240 #define GCOV_TAG_OBJECT_SUMMARY ((gcov_unsigned_t)0xa1000000) /* Obsolete */
309 #define GCOV_TAG_PROGRAM_SUMMARY ((gcov_unsigned_t)0xa3000000) 241 #define GCOV_TAG_PROGRAM_SUMMARY ((gcov_unsigned_t)0xa3000000)
310 #define GCOV_TAG_SUMMARY_LENGTH \ 242 #define GCOV_TAG_SUMMARY_LENGTH(NUM) \
311 (1 + GCOV_COUNTERS_SUMMABLE * (2 + 3 * 2)) 243 (1 + GCOV_COUNTERS_SUMMABLE * (10 + 3 * 2) + (NUM) * 5)
244 #define GCOV_TAG_AFDO_FILE_NAMES ((gcov_unsigned_t)0xaa000000)
245 #define GCOV_TAG_AFDO_FUNCTION ((gcov_unsigned_t)0xac000000)
246 #define GCOV_TAG_AFDO_WORKING_SET ((gcov_unsigned_t)0xaf000000)
247
312 248
313 /* Counters that are collected. */ 249 /* Counters that are collected. */
314 #define GCOV_COUNTER_ARCS 0 /* Arc transitions. */ 250
315 #define GCOV_COUNTERS_SUMMABLE 1 /* Counters which can be 251 #define DEF_GCOV_COUNTER(COUNTER, NAME, MERGE_FN) COUNTER,
316 summaried. */ 252 enum {
317 #define GCOV_FIRST_VALUE_COUNTER 1 /* The first of counters used for value 253 #include "gcov-counter.def"
318 profiling. They must form a consecutive 254 GCOV_COUNTERS
319 interval and their order must match 255 };
320 the order of HIST_TYPEs in 256 #undef DEF_GCOV_COUNTER
321 value-prof.h. */ 257
322 #define GCOV_COUNTER_V_INTERVAL 1 /* Histogram of value inside an interval. */ 258 /* Counters which can be summaried. */
323 #define GCOV_COUNTER_V_POW2 2 /* Histogram of exact power2 logarithm 259 #define GCOV_COUNTERS_SUMMABLE (GCOV_COUNTER_ARCS + 1)
324 of a value. */ 260
325 #define GCOV_COUNTER_V_SINGLE 3 /* The most common value of expression. */ 261 /* The first of counters used for value profiling. They must form a
326 #define GCOV_COUNTER_V_DELTA 4 /* The most common difference between 262 consecutive interval and their order must match the order of
327 consecutive values of expression. */ 263 HIST_TYPEs in value-prof.h. */
328 264 #define GCOV_FIRST_VALUE_COUNTER GCOV_COUNTERS_SUMMABLE
329 #define GCOV_COUNTER_V_INDIR 5 /* The most common indirect address */ 265
330 #define GCOV_COUNTER_AVERAGE 6 /* Compute average value passed to the 266 /* The last of counters used for value profiling. */
331 counter. */ 267 #define GCOV_LAST_VALUE_COUNTER (GCOV_COUNTERS - 1)
332 #define GCOV_COUNTER_IOR 7 /* IOR of the all values passed to
333 counter. */
334 #define GCOV_LAST_VALUE_COUNTER 7 /* The last of counters used for value
335 profiling. */
336 #define GCOV_COUNTERS 8
337 268
338 /* Number of counters used for value profiling. */ 269 /* Number of counters used for value profiling. */
339 #define GCOV_N_VALUE_COUNTERS \ 270 #define GCOV_N_VALUE_COUNTERS \
340 (GCOV_LAST_VALUE_COUNTER - GCOV_FIRST_VALUE_COUNTER + 1) 271 (GCOV_LAST_VALUE_COUNTER - GCOV_FIRST_VALUE_COUNTER + 1)
341 272
342 /* A list of human readable names of the counters */ 273 /* The number of hottest callees to be tracked. */
343 #define GCOV_COUNTER_NAMES {"arcs", "interval", "pow2", "single", \ 274 #define GCOV_ICALL_TOPN_VAL 2
344 "delta","indirect_call", "average", "ior"} 275
345 276 /* The number of counter entries per icall callsite. */
346 /* Names of merge functions for counters. */ 277 #define GCOV_ICALL_TOPN_NCOUNTS (1 + GCOV_ICALL_TOPN_VAL * 4)
347 #define GCOV_MERGE_FUNCTIONS {"__gcov_merge_add", \
348 "__gcov_merge_add", \
349 "__gcov_merge_add", \
350 "__gcov_merge_single", \
351 "__gcov_merge_delta", \
352 "__gcov_merge_single", \
353 "__gcov_merge_add", \
354 "__gcov_merge_ior"}
355 278
356 /* Convert a counter index to a tag. */ 279 /* Convert a counter index to a tag. */
357 #define GCOV_TAG_FOR_COUNTER(COUNT) \ 280 #define GCOV_TAG_FOR_COUNTER(COUNT) \
358 (GCOV_TAG_COUNTER_BASE + ((gcov_unsigned_t)(COUNT) << 17)) 281 (GCOV_TAG_COUNTER_BASE + ((gcov_unsigned_t)(COUNT) << 17))
359 /* Convert a tag to a counter. */ 282 /* Convert a tag to a counter. */
369 #define GCOV_TAG_MASK(TAG) (((TAG) - 1) ^ (TAG)) 292 #define GCOV_TAG_MASK(TAG) (((TAG) - 1) ^ (TAG))
370 293
371 /* Return nonzero if SUB is an immediate subtag of TAG. */ 294 /* Return nonzero if SUB is an immediate subtag of TAG. */
372 #define GCOV_TAG_IS_SUBTAG(TAG,SUB) \ 295 #define GCOV_TAG_IS_SUBTAG(TAG,SUB) \
373 (GCOV_TAG_MASK (TAG) >> 8 == GCOV_TAG_MASK (SUB) \ 296 (GCOV_TAG_MASK (TAG) >> 8 == GCOV_TAG_MASK (SUB) \
374 && !(((SUB) ^ (TAG)) & ~GCOV_TAG_MASK(TAG))) 297 && !(((SUB) ^ (TAG)) & ~GCOV_TAG_MASK (TAG)))
375 298
376 /* Return nonzero if SUB is at a sublevel to TAG. */ 299 /* Return nonzero if SUB is at a sublevel to TAG. */
377 #define GCOV_TAG_IS_SUBLEVEL(TAG,SUB) \ 300 #define GCOV_TAG_IS_SUBLEVEL(TAG,SUB) \
378 (GCOV_TAG_MASK (TAG) > GCOV_TAG_MASK (SUB)) 301 (GCOV_TAG_MASK (TAG) > GCOV_TAG_MASK (SUB))
379 302
384 #define GCOV_ARC_ON_TREE (1 << 0) 307 #define GCOV_ARC_ON_TREE (1 << 0)
385 #define GCOV_ARC_FAKE (1 << 1) 308 #define GCOV_ARC_FAKE (1 << 1)
386 #define GCOV_ARC_FALLTHROUGH (1 << 2) 309 #define GCOV_ARC_FALLTHROUGH (1 << 2)
387 310
388 /* Structured records. */ 311 /* Structured records. */
312
313 /* Structure used for each bucket of the log2 histogram of counter values. */
314 typedef struct
315 {
316 /* Number of counters whose profile count falls within the bucket. */
317 gcov_unsigned_t num_counters;
318 /* Smallest profile count included in this bucket. */
319 gcov_type min_value;
320 /* Cumulative value of the profile counts in this bucket. */
321 gcov_type cum_value;
322 } gcov_bucket_type;
323
324 /* For a log2 scale histogram with each range split into 4
325 linear sub-ranges, there will be at most 64 (max gcov_type bit size) - 1 log2
326 ranges since the lowest 2 log2 values share the lowest 4 linear
327 sub-range (values 0 - 3). This is 252 total entries (63*4). */
328
329 #define GCOV_HISTOGRAM_SIZE 252
330
331 /* How many unsigned ints are required to hold a bit vector of non-zero
332 histogram entries when the histogram is written to the gcov file.
333 This is essentially a ceiling divide by 32 bits. */
334 #define GCOV_HISTOGRAM_BITVECTOR_SIZE (GCOV_HISTOGRAM_SIZE + 31) / 32
389 335
390 /* Cumulative counter data. */ 336 /* Cumulative counter data. */
391 struct gcov_ctr_summary 337 struct gcov_ctr_summary
392 { 338 {
393 gcov_unsigned_t num; /* number of counters. */ 339 gcov_unsigned_t num; /* number of counters. */
394 gcov_unsigned_t runs; /* number of program runs */ 340 gcov_unsigned_t runs; /* number of program runs */
395 gcov_type sum_all; /* sum of all counters accumulated. */ 341 gcov_type sum_all; /* sum of all counters accumulated. */
396 gcov_type run_max; /* maximum value on a single run. */ 342 gcov_type run_max; /* maximum value on a single run. */
397 gcov_type sum_max; /* sum of individual run max values. */ 343 gcov_type sum_max; /* sum of individual run max values. */
344 gcov_bucket_type histogram[GCOV_HISTOGRAM_SIZE]; /* histogram of
345 counter values. */
398 }; 346 };
399 347
400 /* Object & program summary record. */ 348 /* Object & program summary record. */
401 struct gcov_summary 349 struct gcov_summary
402 { 350 {
403 gcov_unsigned_t checksum; /* checksum of program */ 351 gcov_unsigned_t checksum; /* checksum of program */
404 struct gcov_ctr_summary ctrs[GCOV_COUNTERS_SUMMABLE]; 352 struct gcov_ctr_summary ctrs[GCOV_COUNTERS_SUMMABLE];
405 }; 353 };
406 354
407 /* Structures embedded in coveraged program. The structures generated 355 #if !defined(inhibit_libc)
408 by write_profile must match these. */
409
410 #if IN_LIBGCOV
411 /* Information about a single function. This uses the trailing array
412 idiom. The number of counters is determined from the counter_mask
413 in gcov_info. We hold an array of function info, so have to
414 explicitly calculate the correct array stride. */
415 struct gcov_fn_info
416 {
417 gcov_unsigned_t ident; /* unique ident of function */
418 gcov_unsigned_t checksum; /* function checksum */
419 unsigned n_ctrs[0]; /* instrumented counters */
420 };
421
422 /* Type of function used to merge counters. */
423 typedef void (*gcov_merge_fn) (gcov_type *, gcov_unsigned_t);
424
425 /* Information about counters. */
426 struct gcov_ctr_info
427 {
428 gcov_unsigned_t num; /* number of counters. */
429 gcov_type *values; /* their values. */
430 gcov_merge_fn merge; /* The function used to merge them. */
431 };
432
433 /* Information about a single object file. */
434 struct gcov_info
435 {
436 gcov_unsigned_t version; /* expected version number */
437 struct gcov_info *next; /* link to next, used by libgcov */
438
439 gcov_unsigned_t stamp; /* uniquifying time stamp */
440 const char *filename; /* output file name */
441
442 unsigned n_functions; /* number of functions */
443 const struct gcov_fn_info *functions; /* table of functions */
444
445 unsigned ctr_mask; /* mask of counters instrumented. */
446 struct gcov_ctr_info counts[0]; /* count data. The number of bits
447 set in the ctr_mask field
448 determines how big this array
449 is. */
450 };
451
452 /* Register a new object file module. */
453 extern void __gcov_init (struct gcov_info *) ATTRIBUTE_HIDDEN;
454
455 /* Called before fork, to avoid double counting. */
456 extern void __gcov_flush (void) ATTRIBUTE_HIDDEN;
457
458 /* The merge function that just sums the counters. */
459 extern void __gcov_merge_add (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
460
461 /* The merge function to choose the most common value. */
462 extern void __gcov_merge_single (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
463
464 /* The merge function to choose the most common difference between
465 consecutive values. */
466 extern void __gcov_merge_delta (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
467
468 /* The merge function that just ors the counters together. */
469 extern void __gcov_merge_ior (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
470
471 /* The profiler functions. */
472 extern void __gcov_interval_profiler (gcov_type *, gcov_type, int, unsigned);
473 extern void __gcov_pow2_profiler (gcov_type *, gcov_type);
474 extern void __gcov_one_value_profiler (gcov_type *, gcov_type);
475 extern void __gcov_indirect_call_profiler (gcov_type *, gcov_type, void *, void *);
476 extern void __gcov_average_profiler (gcov_type *, gcov_type);
477 extern void __gcov_ior_profiler (gcov_type *, gcov_type);
478
479 #ifndef inhibit_libc
480 /* The wrappers around some library functions.. */
481 extern pid_t __gcov_fork (void) ATTRIBUTE_HIDDEN;
482 extern int __gcov_execl (const char *, char *, ...) ATTRIBUTE_HIDDEN;
483 extern int __gcov_execlp (const char *, char *, ...) ATTRIBUTE_HIDDEN;
484 extern int __gcov_execle (const char *, char *, ...) ATTRIBUTE_HIDDEN;
485 extern int __gcov_execv (const char *, char *const []) ATTRIBUTE_HIDDEN;
486 extern int __gcov_execvp (const char *, char *const []) ATTRIBUTE_HIDDEN;
487 extern int __gcov_execve (const char *, char *const [], char *const [])
488 ATTRIBUTE_HIDDEN;
489 #endif
490
491 #endif /* IN_LIBGCOV */
492
493 #if IN_LIBGCOV >= 0
494
495 /* Optimum number of gcov_unsigned_t's read from or written to disk. */
496 #define GCOV_BLOCK_SIZE (1 << 10)
497
498 GCOV_LINKAGE struct gcov_var
499 {
500 FILE *file;
501 gcov_position_t start; /* Position of first byte of block */
502 unsigned offset; /* Read/write position within the block. */
503 unsigned length; /* Read limit in the block. */
504 unsigned overread; /* Number of words overread. */
505 int error; /* < 0 overflow, > 0 disk error. */
506 int mode; /* < 0 writing, > 0 reading */
507 #if IN_LIBGCOV
508 /* Holds one block plus 4 bytes, thus all coverage reads & writes
509 fit within this buffer and we always can transfer GCOV_BLOCK_SIZE
510 to and from the disk. libgcov never backtracks and only writes 4
511 or 8 byte objects. */
512 gcov_unsigned_t buffer[GCOV_BLOCK_SIZE + 1];
513 #else
514 int endian; /* Swap endianness. */
515 /* Holds a variable length block, as the compiler can write
516 strings and needs to backtrack. */
517 size_t alloc;
518 gcov_unsigned_t *buffer;
519 #endif
520 } gcov_var ATTRIBUTE_HIDDEN;
521 356
522 /* Functions for reading and writing gcov files. In libgcov you can 357 /* Functions for reading and writing gcov files. In libgcov you can
523 open the file for reading then writing. Elsewhere you can open the 358 open the file for reading then writing. Elsewhere you can open the
524 file either for reading or for writing. When reading a file you may 359 file either for reading or for writing. When reading a file you may
525 use the gcov_read_* functions, gcov_sync, gcov_position, & 360 use the gcov_read_* functions, gcov_sync, gcov_position, &
526 gcov_error. When writing a file you may use the gcov_write 361 gcov_error. When writing a file you may use the gcov_write
527 functions, gcov_seek & gcov_error. When a file is to be rewritten 362 functions, gcov_seek & gcov_error. When a file is to be rewritten
528 you use the functions for reading, then gcov_rewrite then the 363 you use the functions for reading, then gcov_rewrite then the
529 functions for writing. Your file may become corrupted if you break 364 functions for writing. Your file may become corrupted if you break
530 these invariants. */ 365 these invariants. */
531 #if IN_LIBGCOV 366
532 GCOV_LINKAGE int gcov_open (const char */*name*/) ATTRIBUTE_HIDDEN; 367 #if !IN_LIBGCOV
533 #else
534 GCOV_LINKAGE int gcov_open (const char */*name*/, int /*direction*/); 368 GCOV_LINKAGE int gcov_open (const char */*name*/, int /*direction*/);
535 GCOV_LINKAGE int gcov_magic (gcov_unsigned_t, gcov_unsigned_t); 369 GCOV_LINKAGE int gcov_magic (gcov_unsigned_t, gcov_unsigned_t);
536 #endif 370 #endif
371
372 /* Available everywhere. */
537 GCOV_LINKAGE int gcov_close (void) ATTRIBUTE_HIDDEN; 373 GCOV_LINKAGE int gcov_close (void) ATTRIBUTE_HIDDEN;
538
539 /* Available everywhere. */
540 static gcov_position_t gcov_position (void);
541 static int gcov_is_error (void);
542
543 GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned (void) ATTRIBUTE_HIDDEN; 374 GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned (void) ATTRIBUTE_HIDDEN;
544 GCOV_LINKAGE gcov_type gcov_read_counter (void) ATTRIBUTE_HIDDEN; 375 GCOV_LINKAGE gcov_type gcov_read_counter (void) ATTRIBUTE_HIDDEN;
545 GCOV_LINKAGE void gcov_read_summary (struct gcov_summary *) ATTRIBUTE_HIDDEN; 376 GCOV_LINKAGE void gcov_read_summary (struct gcov_summary *) ATTRIBUTE_HIDDEN;
546
547 #if IN_LIBGCOV
548 /* Available only in libgcov */
549 GCOV_LINKAGE void gcov_write_counter (gcov_type) ATTRIBUTE_HIDDEN;
550 GCOV_LINKAGE void gcov_write_tag_length (gcov_unsigned_t, gcov_unsigned_t)
551 ATTRIBUTE_HIDDEN;
552 GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/,
553 const struct gcov_summary *)
554 ATTRIBUTE_HIDDEN;
555 static void gcov_rewrite (void);
556 GCOV_LINKAGE void gcov_seek (gcov_position_t /*position*/) ATTRIBUTE_HIDDEN;
557 #else
558 /* Available outside libgcov */
559 GCOV_LINKAGE const char *gcov_read_string (void); 377 GCOV_LINKAGE const char *gcov_read_string (void);
560 GCOV_LINKAGE void gcov_sync (gcov_position_t /*base*/, 378 GCOV_LINKAGE void gcov_sync (gcov_position_t /*base*/,
561 gcov_unsigned_t /*length */); 379 gcov_unsigned_t /*length */);
562 #endif
563 380
564 #if !IN_GCOV 381 #if !IN_GCOV
565 /* Available outside gcov */ 382 /* Available outside gcov */
566 GCOV_LINKAGE void gcov_write_unsigned (gcov_unsigned_t) ATTRIBUTE_HIDDEN; 383 GCOV_LINKAGE void gcov_write_unsigned (gcov_unsigned_t) ATTRIBUTE_HIDDEN;
567 #endif 384 #endif
568 385
569 #if !IN_GCOV && !IN_LIBGCOV 386 #if !IN_GCOV && !IN_LIBGCOV
570 /* Available only in compiler */ 387 /* Available only in compiler */
388 GCOV_LINKAGE unsigned gcov_histo_index (gcov_type value);
571 GCOV_LINKAGE void gcov_write_string (const char *); 389 GCOV_LINKAGE void gcov_write_string (const char *);
390 GCOV_LINKAGE void gcov_write_filename (const char *);
572 GCOV_LINKAGE gcov_position_t gcov_write_tag (gcov_unsigned_t); 391 GCOV_LINKAGE gcov_position_t gcov_write_tag (gcov_unsigned_t);
573 GCOV_LINKAGE void gcov_write_length (gcov_position_t /*position*/); 392 GCOV_LINKAGE void gcov_write_length (gcov_position_t /*position*/);
393 #endif
394
395 #if IN_GCOV <= 0 && !IN_LIBGCOV
396 /* Available in gcov-dump and the compiler. */
397
398 /* Number of data points in the working set summary array. Using 128
399 provides information for at least every 1% increment of the total
400 profile size. The last entry is hardwired to 99.9% of the total. */
401 #define NUM_GCOV_WORKING_SETS 128
402
403 /* Working set size statistics for a given percentage of the entire
404 profile (sum_all from the counter summary). */
405 typedef struct gcov_working_set_info
406 {
407 /* Number of hot counters included in this working set. */
408 unsigned num_counters;
409 /* Smallest counter included in this working set. */
410 gcov_type min_counter;
411 } gcov_working_set_t;
412
413 GCOV_LINKAGE void compute_working_sets (const struct gcov_ctr_summary *summary,
414 gcov_working_set_t *gcov_working_sets);
574 #endif 415 #endif
575 416
576 #if IN_GCOV > 0 417 #if IN_GCOV > 0
577 /* Available in gcov */ 418 /* Available in gcov */
578 GCOV_LINKAGE time_t gcov_time (void); 419 GCOV_LINKAGE time_t gcov_time (void);
579 #endif 420 #endif
580 421
581 /* Save the current position in the gcov file. */ 422 #endif /* !inhibit_libc */
582
583 static inline gcov_position_t
584 gcov_position (void)
585 {
586 gcc_assert (gcov_var.mode > 0);
587 return gcov_var.start + gcov_var.offset;
588 }
589
590 /* Return nonzero if the error flag is set. */
591
592 static inline int
593 gcov_is_error (void)
594 {
595 return gcov_var.file ? gcov_var.error : 1;
596 }
597
598 #if IN_LIBGCOV
599 /* Move to beginning of file and initialize for writing. */
600
601 static inline void
602 gcov_rewrite (void)
603 {
604 gcc_assert (gcov_var.mode > 0);
605 gcov_var.mode = -1;
606 gcov_var.start = 0;
607 gcov_var.offset = 0;
608 fseek (gcov_var.file, 0L, SEEK_SET);
609 }
610 #endif
611
612 #endif /* IN_LIBGCOV >= 0 */
613 423
614 #endif /* GCC_GCOV_IO_H */ 424 #endif /* GCC_GCOV_IO_H */