00001 /* File format for coverage information 00002 Copyright (C) 1996, 1997, 1998, 2000, 2002, 00003 2003, 2004 Free Software Foundation, Inc. 00004 Contributed by Bob Manson <manson@cygnus.com>. 00005 Completely remangled by Nathan Sidwell <nathan@codesourcery.com>. 00006 00007 This file is part of GCC. 00008 00009 GCC is free software; you can redistribute it and/or modify it under 00010 the terms of the GNU General Public License as published by the Free 00011 Software Foundation; either version 2, or (at your option) any later 00012 version. 00013 00014 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 00015 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00016 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00017 for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with GCC; see the file COPYING. If not, write to the Free 00021 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 00022 02111-1307, USA. */ 00023 00024 /* As a special exception, if you link this library with other files, 00025 some of which are compiled with GCC, to produce an executable, 00026 this library does not by itself cause the resulting executable 00027 to be covered by the GNU General Public License. 00028 This exception does not however invalidate any other reasons why 00029 the executable file might be covered by the GNU General Public License. */ 00030 00031 /* Coverage information is held in two files. A notes file, which is 00032 generated by the compiler, and a data file, which is generated by 00033 the program under test. Both files use a similar structure. We do 00034 not attempt to make these files backwards compatible with previous 00035 versions, as you only need coverage information when developing a 00036 program. We do hold version information, so that mismatches can be 00037 detected, and we use a format that allows tools to skip information 00038 they do not understand or are not interested in. 00039 00040 Numbers are recorded in the 32 bit unsigned binary form of the 00041 endianness of the machine generating the file. 64 bit numbers are 00042 stored as two 32 bit numbers, the low part first. Strings are 00043 padded with 1 to 4 NUL bytes, to bring the length up to a multiple 00044 of 4. The number of 4 bytes is stored, followed by the padded 00045 string. Zero length and NULL strings are simply stored as a length 00046 of zero (they have no trailing NUL or padding). 00047 00048 int32: byte3 byte2 byte1 byte0 | byte0 byte1 byte2 byte3 00049 int64: int32:low int32:high 00050 string: int32:0 | int32:length char* char:0 padding 00051 padding: | char:0 | char:0 char:0 | char:0 char:0 char:0 00052 item: int32 | int64 | string 00053 00054 The basic format of the files is 00055 00056 file : int32:magic int32:version int32:stamp record* 00057 00058 The magic ident is different for the notes and the data files. The 00059 magic ident is used to determine the endianness of the file, when 00060 reading. The version is the same for both files and is derived 00061 from gcc's version number. The stamp value is used to synchronize 00062 note and data files and to synchronize merging within a data 00063 file. It need not be an absolute time stamp, merely a ticker that 00064 increments fast enough and cycles slow enough to distinguish 00065 different compile/run/compile cycles. 00066 00067 Although the ident and version are formally 32 bit numbers, they 00068 are derived from 4 character ASCII strings. The version number 00069 consists of the single character major version number, a two 00070 character minor version number (leading zero for versions less than 00071 10), and a single character indicating the status of the release. 00072 That will be 'e' experimental, 'p' prerelease and 'r' for release. 00073 Because, by good fortune, these are in alphabetical order, string 00074 collating can be used to compare version strings. Be aware that 00075 the 'e' designation will (naturally) be unstable and might be 00076 incompatible with itself. For gcc 3.4 experimental, it would be 00077 '304e' (0x33303465). When the major version reaches 10, the 00078 letters A-Z will be used. Assuming minor increments releases every 00079 6 months, we have to make a major increment every 50 years. 00080 Assuming major increments releases every 5 years, we're ok for the 00081 next 155 years -- good enough for me. 00082 00083 A record has a tag, length and variable amount of data. 00084 00085 record: header data 00086 header: int32:tag int32:length 00087 data: item* 00088 00089 Records are not nested, but there is a record hierarchy. Tag 00090 numbers reflect this hierarchy. Tags are unique across note and 00091 data files. Some record types have a varying amount of data. The 00092 LENGTH is the number of 4bytes that follow and is usually used to 00093 determine how much data. The tag value is split into 4 8-bit 00094 fields, one for each of four possible levels. The most significant 00095 is allocated first. Unused levels are zero. Active levels are 00096 odd-valued, so that the LSB of the level is one. A sub-level 00097 incorporates the values of its superlevels. This formatting allows 00098 you to determine the tag hierarchy, without understanding the tags 00099 themselves, and is similar to the standard section numbering used 00100 in technical documents. Level values [1..3f] are used for common 00101 tags, values [41..9f] for the notes file and [a1..ff] for the data 00102 file. 00103 00104 The basic block graph file contains the following records 00105 note: unit function-graph* 00106 unit: header int32:checksum string:source 00107 function-graph: announce_function basic_blocks {arcs | lines}* 00108 announce_function: header int32:ident int32:checksum 00109 string:name string:source int32:lineno 00110 basic_block: header int32:flags* 00111 arcs: header int32:block_no arc* 00112 arc: int32:dest_block int32:flags 00113 lines: header int32:block_no line* 00114 int32:0 string:NULL 00115 line: int32:line_no | int32:0 string:filename 00116 00117 The BASIC_BLOCK record holds per-bb flags. The number of blocks 00118 can be inferred from its data length. There is one ARCS record per 00119 basic block. The number of arcs from a bb is implicit from the 00120 data length. It enumerates the destination bb and per-arc flags. 00121 There is one LINES record per basic block, it enumerates the source 00122 lines which belong to that basic block. Source file names are 00123 introduced by a line number of 0, following lines are from the new 00124 source file. The initial source file for the function is NULL, but 00125 the current source file should be remembered from one LINES record 00126 to the next. The end of a block is indicated by an empty filename 00127 - this does not reset the current source file. Note there is no 00128 ordering of the ARCS and LINES records: they may be in any order, 00129 interleaved in any manner. The current filename follows the order 00130 the LINES records are stored in the file, *not* the ordering of the 00131 blocks they are for. 00132 00133 The data file contains the following records. 00134 data: {unit function-data* summary:object summary:program*}* 00135 unit: header int32:checksum 00136 function-data: announce_function arc_counts 00137 announce_function: header int32:ident int32:checksum 00138 arc_counts: header int64:count* 00139 summary: int32:checksum {count-summary}GCOV_COUNTERS 00140 count-summary: int32:num int32:runs int64:sum 00141 int64:max int64:sum_max 00142 00143 The ANNOUNCE_FUNCTION record is the same as that in the note file, 00144 but without the source location. The ARC_COUNTS gives the counter 00145 values for those arcs that are instrumented. The SUMMARY records 00146 give information about the whole object file and about the whole 00147 program. The checksum is used for whole program summaries, and 00148 disambiguates different programs which include the same 00149 instrumented object file. There may be several program summaries, 00150 each with a unique checksum. The object summary's checksum is zero. 00151 Note that the data file might contain information from several runs 00152 concatenated, or the data might be merged. 00153 00154 This file is included by both the compiler, gcov tools and the 00155 runtime support library libgcov. IN_LIBGCOV and IN_GCOV are used to 00156 distinguish which case is which. If IN_LIBGCOV is nonzero, 00157 libgcov is being built. If IN_GCOV is nonzero, the gcov tools are 00158 being built. Otherwise the compiler is being built. IN_GCOV may be 00159 positive or negative. If positive, we are compiling a tool that 00160 requires additional functions (see the code for knowledge of what 00161 those functions are). */ 00162 00163 #ifndef GCC_GCOV_IO_H 00164 #define GCC_GCOV_IO_H 00165 00166 #if IN_LIBGCOV 00167 /* About the target */ 00168 00169 #if BITS_PER_UNIT == 8 00170 typedef unsigned gcov_unsigned_t __attribute__ ((mode (SI))); 00171 typedef unsigned gcov_position_t __attribute__ ((mode (SI))); 00172 #if LONG_LONG_TYPE_SIZE > 32 00173 typedef signed gcov_type __attribute__ ((mode (DI))); 00174 #else 00175 typedef signed gcov_type __attribute__ ((mode (SI))); 00176 #endif 00177 #else 00178 #if BITS_PER_UNIT == 16 00179 typedef unsigned gcov_unsigned_t __attribute__ ((mode (HI))); 00180 typedef unsigned gcov_position_t __attribute__ ((mode (HI))); 00181 #if LONG_LONG_TYPE_SIZE > 32 00182 typedef signed gcov_type __attribute__ ((mode (SI))); 00183 #else 00184 typedef signed gcov_type __attribute__ ((mode (HI))); 00185 #endif 00186 #else 00187 typedef unsigned gcov_unsigned_t __attribute__ ((mode (QI))); 00188 typedef unsigned gcov_position_t __attribute__ ((mode (QI))); 00189 #if LONG_LONG_TYPE_SIZE > 32 00190 typedef signed gcov_type __attribute__ ((mode (HI))); 00191 #else 00192 typedef signed gcov_type __attribute__ ((mode (QI))); 00193 #endif 00194 #endif 00195 #endif 00196 00197 00198 #if defined (TARGET_HAS_F_SETLKW) 00199 #define GCOV_LOCKED 1 00200 #else 00201 #define GCOV_LOCKED 0 00202 #endif 00203 00204 #else /* !IN_LIBGCOV */ 00205 /* About the host */ 00206 00207 typedef unsigned gcov_unsigned_t; 00208 typedef unsigned gcov_position_t; 00209 /* gcov_type is typedef'd elsewhere for the compiler */ 00210 #if IN_GCOV 00211 #define GCOV_LINKAGE static 00212 typedef HOST_WIDEST_INT gcov_type; 00213 #if IN_GCOV > 0 00214 #include <sys/types.h> 00215 #endif 00216 #else 00217 #if LONG_LONG_TYPE_SIZE > 32 00218 #define GCOV_TYPE_NODE intDI_type_node 00219 #else 00220 #define GCOV_TYPE_NODE intSI_type_node 00221 #endif 00222 #endif 00223 00224 #if defined (HOST_HAS_F_SETLKW) 00225 #define GCOV_LOCKED 1 00226 #else 00227 #define GCOV_LOCKED 0 00228 #endif 00229 00230 #endif /* !IN_LIBGCOV */ 00231 00232 /* In gcov we want function linkage to be static. In the compiler we want 00233 it extern, so that they can be accessed from elsewhere. In libgcov we 00234 need these functions to be extern, so prefix them with __gcov. In 00235 libgcov they must also be hidden so that the instance in the executable 00236 is not also used in a DSO. */ 00237 #if IN_LIBGCOV 00238 00239 #include "auto-host.h" /* for HAVE_GAS_HIDDEN */ 00240 00241 #define gcov_var __gcov_var 00242 #define gcov_open __gcov_open 00243 #define gcov_close __gcov_close 00244 #define gcov_write_tag_length __gcov_write_tag_length 00245 #define gcov_position __gcov_position 00246 #define gcov_seek __gcov_seek 00247 #define gcov_rewrite __gcov_rewrite 00248 #define gcov_is_error __gcov_is_error 00249 #define gcov_write_unsigned __gcov_write_unsigned 00250 #define gcov_write_counter __gcov_write_counter 00251 #define gcov_write_summary __gcov_write_summary 00252 #define gcov_read_unsigned __gcov_read_unsigned 00253 #define gcov_read_counter __gcov_read_counter 00254 #define gcov_read_summary __gcov_read_summary 00255 00256 /* Poison these, so they don't accidentally slip in. */ 00257 #pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length 00258 #pragma GCC poison gcov_read_string gcov_sync gcov_time gcov_magic 00259 00260 #ifdef HAVE_GAS_HIDDEN 00261 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden"))) 00262 #else 00263 #define ATTRIBUTE_HIDDEN 00264 #endif 00265 00266 #else 00267 00268 #define ATTRIBUTE_HIDDEN 00269 00270 #endif 00271 00272 #ifndef GCOV_LINKAGE 00273 #define GCOV_LINKAGE extern 00274 #endif 00275 00276 /* File suffixes. */ 00277 #define GCOV_DATA_SUFFIX ".gcda" 00278 #define GCOV_NOTE_SUFFIX ".gcno" 00279 00280 /* File magic. Must not be palindromes. */ 00281 #define GCOV_DATA_MAGIC ((gcov_unsigned_t)0x67636461) /* "gcda" */ 00282 #define GCOV_NOTE_MAGIC ((gcov_unsigned_t)0x67636e6f) /* "gcno" */ 00283 00284 /* gcov-iov.h is automatically generated by the makefile from 00285 version.c, it looks like 00286 #define GCOV_VERSION ((gcov_unsigned_t)0x89abcdef) 00287 */ 00288 #include "gcov-iov.h" 00289 00290 /* Convert a magic or version number to a 4 character string. */ 00291 #define GCOV_UNSIGNED2STRING(ARRAY,VALUE) \ 00292 ((ARRAY)[0] = (char)((VALUE) >> 24), \ 00293 (ARRAY)[1] = (char)((VALUE) >> 16), \ 00294 (ARRAY)[2] = (char)((VALUE) >> 8), \ 00295 (ARRAY)[3] = (char)((VALUE) >> 0)) 00296 00297 /* The record tags. Values [1..3f] are for tags which may be in either 00298 file. Values [41..9f] for those in the note file and [a1..ff] for 00299 the data file. The tag value zero is used as an explicit end of 00300 file marker -- it is not required to be present. */ 00301 00302 #define GCOV_TAG_FUNCTION ((gcov_unsigned_t)0x01000000) 00303 #define GCOV_TAG_FUNCTION_LENGTH (2) 00304 #define GCOV_TAG_BLOCKS ((gcov_unsigned_t)0x01410000) 00305 #define GCOV_TAG_BLOCKS_LENGTH(NUM) (NUM) 00306 #define GCOV_TAG_BLOCKS_NUM(LENGTH) (LENGTH) 00307 #define GCOV_TAG_ARCS ((gcov_unsigned_t)0x01430000) 00308 #define GCOV_TAG_ARCS_LENGTH(NUM) (1 + (NUM) * 2) 00309 #define GCOV_TAG_ARCS_NUM(LENGTH) (((LENGTH) - 1) / 2) 00310 #define GCOV_TAG_LINES ((gcov_unsigned_t)0x01450000) 00311 #define GCOV_TAG_COUNTER_BASE ((gcov_unsigned_t)0x01a10000) 00312 #define GCOV_TAG_COUNTER_LENGTH(NUM) ((NUM) * 2) 00313 #define GCOV_TAG_COUNTER_NUM(LENGTH) ((LENGTH) / 2) 00314 #define GCOV_TAG_OBJECT_SUMMARY ((gcov_unsigned_t)0xa1000000) 00315 #define GCOV_TAG_PROGRAM_SUMMARY ((gcov_unsigned_t)0xa3000000) 00316 #define GCOV_TAG_SUMMARY_LENGTH \ 00317 (1 + GCOV_COUNTERS_SUMMABLE * (2 + 3 * 2)) 00318 00319 /* Counters that are collected. */ 00320 #define GCOV_COUNTER_ARCS 0 /* Arc transitions. */ 00321 #define GCOV_COUNTERS_SUMMABLE 1 /* Counters which can be 00322 summaried. */ 00323 #define GCOV_FIRST_VALUE_COUNTER 1 /* The first of counters used for value 00324 profiling. They must form a consecutive 00325 interval and their order must match 00326 the order of HIST_TYPEs in 00327 value-prof.h. */ 00328 #define GCOV_COUNTER_V_INTERVAL 1 /* Histogram of value inside an interval. */ 00329 #define GCOV_COUNTER_V_POW2 2 /* Histogram of exact power2 logarithm 00330 of a value. */ 00331 #define GCOV_COUNTER_V_SINGLE 3 /* The most common value of expression. */ 00332 #define GCOV_COUNTER_V_DELTA 4 /* The most common difference between 00333 consecutive values of expression. */ 00334 #define GCOV_LAST_VALUE_COUNTER 4 /* The last of counters used for value 00335 profiling. */ 00336 #define GCOV_COUNTERS 5 00337 00338 /* Number of counters used for value profiling. */ 00339 #define GCOV_N_VALUE_COUNTERS \ 00340 (GCOV_LAST_VALUE_COUNTER - GCOV_FIRST_VALUE_COUNTER + 1) 00341 00342 /* A list of human readable names of the counters */ 00343 #define GCOV_COUNTER_NAMES {"arcs", "interval", "pow2", "single", "delta"} 00344 00345 /* Names of merge functions for counters. */ 00346 #define GCOV_MERGE_FUNCTIONS {"__gcov_merge_add", \ 00347 "__gcov_merge_add", \ 00348 "__gcov_merge_add", \ 00349 "__gcov_merge_single", \ 00350 "__gcov_merge_delta"} 00351 00352 /* Convert a counter index to a tag. */ 00353 #define GCOV_TAG_FOR_COUNTER(COUNT) \ 00354 (GCOV_TAG_COUNTER_BASE + ((gcov_unsigned_t)(COUNT) << 17)) 00355 /* Convert a tag to a counter. */ 00356 #define GCOV_COUNTER_FOR_TAG(TAG) \ 00357 ((unsigned)(((TAG) - GCOV_TAG_COUNTER_BASE) >> 17)) 00358 /* Check whether a tag is a counter tag. */ 00359 #define GCOV_TAG_IS_COUNTER(TAG) \ 00360 (!((TAG) & 0xFFFF) && GCOV_COUNTER_FOR_TAG (TAG) < GCOV_COUNTERS) 00361 00362 /* The tag level mask has 1's in the position of the inner levels, & 00363 the lsb of the current level, and zero on the current and outer 00364 levels. */ 00365 #define GCOV_TAG_MASK(TAG) (((TAG) - 1) ^ (TAG)) 00366 00367 /* Return nonzero if SUB is an immediate subtag of TAG. */ 00368 #define GCOV_TAG_IS_SUBTAG(TAG,SUB) \ 00369 (GCOV_TAG_MASK (TAG) >> 8 == GCOV_TAG_MASK (SUB) \ 00370 && !(((SUB) ^ (TAG)) & ~GCOV_TAG_MASK(TAG))) 00371 00372 /* Return nonzero if SUB is at a sublevel to TAG. */ 00373 #define GCOV_TAG_IS_SUBLEVEL(TAG,SUB) \ 00374 (GCOV_TAG_MASK (TAG) > GCOV_TAG_MASK (SUB)) 00375 00376 /* Basic block flags. */ 00377 #define GCOV_BLOCK_UNEXPECTED (1 << 1) 00378 00379 /* Arc flags. */ 00380 #define GCOV_ARC_ON_TREE (1 << 0) 00381 #define GCOV_ARC_FAKE (1 << 1) 00382 #define GCOV_ARC_FALLTHROUGH (1 << 2) 00383 00384 /* Structured records. */ 00385 00386 /* Cumulative counter data. */ 00387 struct gcov_ctr_summary 00388 { 00389 gcov_unsigned_t num; /* number of counters. */ 00390 gcov_unsigned_t runs; /* number of program runs */ 00391 gcov_type sum_all; /* sum of all counters accumulated. */ 00392 gcov_type run_max; /* maximum value on a single run. */ 00393 gcov_type sum_max; /* sum of individual run max values. */ 00394 }; 00395 00396 /* Object & program summary record. */ 00397 struct gcov_summary 00398 { 00399 gcov_unsigned_t checksum; /* checksum of program */ 00400 struct gcov_ctr_summary ctrs[GCOV_COUNTERS_SUMMABLE]; 00401 }; 00402 00403 /* Structures embedded in coveraged program. The structures generated 00404 by write_profile must match these. */ 00405 00406 #if IN_LIBGCOV 00407 /* Information about a single function. This uses the trailing array 00408 idiom. The number of counters is determined from the counter_mask 00409 in gcov_info. We hold an array of function info, so have to 00410 explicitly calculate the correct array stride. */ 00411 struct gcov_fn_info 00412 { 00413 gcov_unsigned_t ident; /* unique ident of function */ 00414 gcov_unsigned_t checksum; /* function checksum */ 00415 unsigned n_ctrs[0]; /* instrumented counters */ 00416 }; 00417 00418 /* Type of function used to merge counters. */ 00419 typedef void (*gcov_merge_fn) (gcov_type *, gcov_unsigned_t); 00420 00421 /* Information about counters. */ 00422 struct gcov_ctr_info 00423 { 00424 gcov_unsigned_t num; /* number of counters. */ 00425 gcov_type *values; /* their values. */ 00426 gcov_merge_fn merge; /* The function used to merge them. */ 00427 }; 00428 00429 /* Information about a single object file. */ 00430 struct gcov_info 00431 { 00432 gcov_unsigned_t version; /* expected version number */ 00433 struct gcov_info *next; /* link to next, used by libgcov */ 00434 00435 gcov_unsigned_t stamp; /* uniquifying time stamp */ 00436 const char *filename; /* output file name */ 00437 00438 unsigned n_functions; /* number of functions */ 00439 const struct gcov_fn_info *functions; /* table of functions */ 00440 00441 unsigned ctr_mask; /* mask of counters instrumented. */ 00442 struct gcov_ctr_info counts[0]; /* count data. The number of bits 00443 set in the ctr_mask field 00444 determines how big this array 00445 is. */ 00446 }; 00447 00448 /* Register a new object file module. */ 00449 extern void __gcov_init (struct gcov_info *) ATTRIBUTE_HIDDEN; 00450 00451 /* Called before fork, to avoid double counting. */ 00452 extern void __gcov_flush (void) ATTRIBUTE_HIDDEN; 00453 00454 /* The merge function that just sums the counters. */ 00455 extern void __gcov_merge_add (gcov_type *, unsigned) ATTRIBUTE_HIDDEN; 00456 00457 /* The merge function to choose the most common value. */ 00458 extern void __gcov_merge_single (gcov_type *, unsigned) ATTRIBUTE_HIDDEN; 00459 00460 /* The merge function to choose the most common difference between 00461 consecutive values. */ 00462 extern void __gcov_merge_delta (gcov_type *, unsigned) ATTRIBUTE_HIDDEN; 00463 00464 #ifndef inhibit_libc 00465 /* The wrappers around some library functions.. */ 00466 extern pid_t __gcov_fork (void); 00467 extern int __gcov_execl (const char *, const char *, ...) ATTRIBUTE_HIDDEN; 00468 extern int __gcov_execlp (const char *, const char *, ...) ATTRIBUTE_HIDDEN; 00469 extern int __gcov_execle (const char *, const char *, ...) ATTRIBUTE_HIDDEN; 00470 extern int __gcov_execv (const char *, char *const []) ATTRIBUTE_HIDDEN; 00471 extern int __gcov_execvp (const char *, char *const []) ATTRIBUTE_HIDDEN; 00472 extern int __gcov_execve (const char *, char *const [], char *const []) 00473 ATTRIBUTE_HIDDEN; 00474 #endif 00475 00476 #endif /* IN_LIBGCOV */ 00477 00478 #if IN_LIBGCOV >= 0 00479 00480 /* Optimum number of gcov_unsigned_t's read from or written to disk. */ 00481 #define GCOV_BLOCK_SIZE (1 << 10) 00482 00483 GCOV_LINKAGE struct gcov_var 00484 { 00485 FILE *file; 00486 gcov_position_t start; /* Position of first byte of block */ 00487 unsigned offset; /* Read/write position within the block. */ 00488 unsigned length; /* Read limit in the block. */ 00489 unsigned overread; /* Number of words overread. */ 00490 int error; /* < 0 overflow, > 0 disk error. */ 00491 int mode; /* < 0 writing, > 0 reading */ 00492 #if IN_LIBGCOV 00493 /* Holds one block plus 4 bytes, thus all coverage reads & writes 00494 fit within this buffer and we always can transfer GCOV_BLOCK_SIZE 00495 to and from the disk. libgcov never backtracks and only writes 4 00496 or 8 byte objects. */ 00497 gcov_unsigned_t buffer[GCOV_BLOCK_SIZE + 1]; 00498 #else 00499 int endian; /* Swap endianness. */ 00500 /* Holds a variable length block, as the compiler can write 00501 strings and needs to backtrack. */ 00502 size_t alloc; 00503 gcov_unsigned_t *buffer; 00504 #endif 00505 } gcov_var ATTRIBUTE_HIDDEN; 00506 00507 /* Functions for reading and writing gcov files. In libgcov you can 00508 open the file for reading then writing. Elsewhere you can open the 00509 file either for reading or for writing. When reading a file you may 00510 use the gcov_read_* functions, gcov_sync, gcov_position, & 00511 gcov_error. When writing a file you may use the gcov_write 00512 functions, gcov_seek & gcov_error. When a file is to be rewritten 00513 you use the functions for reading, then gcov_rewrite then the 00514 functions for writing. Your file may become corrupted if you break 00515 these invariants. */ 00516 #if IN_LIBGCOV 00517 GCOV_LINKAGE int gcov_open (const char */*name*/) ATTRIBUTE_HIDDEN; 00518 #else 00519 GCOV_LINKAGE int gcov_open (const char */*name*/, int /*direction*/); 00520 GCOV_LINKAGE int gcov_magic (gcov_unsigned_t, gcov_unsigned_t); 00521 #endif 00522 GCOV_LINKAGE int gcov_close (void) ATTRIBUTE_HIDDEN; 00523 00524 /* Available everywhere. */ 00525 static gcov_position_t gcov_position (void); 00526 static int gcov_is_error (void); 00527 00528 GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned (void) ATTRIBUTE_HIDDEN; 00529 GCOV_LINKAGE gcov_type gcov_read_counter (void) ATTRIBUTE_HIDDEN; 00530 GCOV_LINKAGE void gcov_read_summary (struct gcov_summary *) ATTRIBUTE_HIDDEN; 00531 00532 #if IN_LIBGCOV 00533 /* Available only in libgcov */ 00534 GCOV_LINKAGE void gcov_write_counter (gcov_type) ATTRIBUTE_HIDDEN; 00535 GCOV_LINKAGE void gcov_write_tag_length (gcov_unsigned_t, gcov_unsigned_t) 00536 ATTRIBUTE_HIDDEN; 00537 GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/, 00538 const struct gcov_summary *) 00539 ATTRIBUTE_HIDDEN; 00540 static void gcov_rewrite (void); 00541 GCOV_LINKAGE void gcov_seek (gcov_position_t /*position*/) ATTRIBUTE_HIDDEN; 00542 #else 00543 /* Available outside libgcov */ 00544 GCOV_LINKAGE const char *gcov_read_string (void); 00545 GCOV_LINKAGE void gcov_sync (gcov_position_t /*base*/, 00546 gcov_unsigned_t /*length */); 00547 #endif 00548 00549 #if !IN_GCOV 00550 /* Available outside gcov */ 00551 GCOV_LINKAGE void gcov_write_unsigned (gcov_unsigned_t) ATTRIBUTE_HIDDEN; 00552 #endif 00553 00554 #if !IN_GCOV && !IN_LIBGCOV 00555 /* Available only in compiler */ 00556 GCOV_LINKAGE void gcov_write_string (const char *); 00557 GCOV_LINKAGE gcov_position_t gcov_write_tag (gcov_unsigned_t); 00558 GCOV_LINKAGE void gcov_write_length (gcov_position_t /*position*/); 00559 #endif 00560 00561 #if IN_GCOV > 0 00562 /* Available in gcov */ 00563 GCOV_LINKAGE time_t gcov_time (void); 00564 #endif 00565 00566 /* Make sure the library is used correctly. */ 00567 #if IN_LIBGCOV 00568 #if ENABLE_CHECKING 00569 #define GCOV_CHECK(EXPR) (!(EXPR) ? abort (), 0 : 0) 00570 #else 00571 /* Include EXPR, so that unused variable warnings do not occur. */ 00572 #define GCOV_CHECK(EXPR) ((void)(0 && (EXPR))) 00573 #endif 00574 #else 00575 #define GCOV_CHECK(EXPR) gcc_assert (EXPR) 00576 #endif 00577 #define GCOV_CHECK_READING() GCOV_CHECK(gcov_var.mode > 0) 00578 #define GCOV_CHECK_WRITING() GCOV_CHECK(gcov_var.mode < 0) 00579 00580 /* Save the current position in the gcov file. */ 00581 00582 static inline gcov_position_t 00583 gcov_position (void) 00584 { 00585 GCOV_CHECK_READING (); 00586 return gcov_var.start + gcov_var.offset; 00587 } 00588 00589 /* Return nonzero if the error flag is set. */ 00590 00591 static inline int 00592 gcov_is_error (void) 00593 { 00594 return gcov_var.file ? gcov_var.error : 1; 00595 } 00596 00597 #if IN_LIBGCOV 00598 /* Move to beginning of file and initialize for writing. */ 00599 00600 static inline void 00601 gcov_rewrite (void) 00602 { 00603 GCOV_CHECK_READING (); 00604 gcov_var.mode = -1; 00605 gcov_var.start = 0; 00606 gcov_var.offset = 0; 00607 fseek (gcov_var.file, 0L, SEEK_SET); 00608 } 00609 #endif 00610 00611 #endif /* IN_LIBGCOV >= 0 */ 00612 00613 #endif /* GCC_GCOV_IO_H */
1.5.6