GCC Middle and Back End API Reference
gcov-io.h File Reference
#include "version.h"
#include "gcov-counter.def"
Include dependency graph for gcov-io.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  gcov_kvp
 
struct  gcov_summary
 

Macros

#define GCOV_LOCKED   0
 
#define GCOV_LOCKED_WITH_LOCKING   0
 
#define ATTRIBUTE_HIDDEN
 
#define GCOV_LINKAGE   extern
 
#define gcov_nonruntime_assert(EXPR)   gcc_assert (EXPR)
 
#define gcov_error(...)   fatal_error (input_location, __VA_ARGS__)
 
#define GCOV_DATA_SUFFIX   ".gcda"
 
#define GCOV_NOTE_SUFFIX   ".gcno"
 
#define GCOV_DATA_MAGIC   ((gcov_unsigned_t)0x67636461) /* "gcda" @endverbatim */
 
#define GCOV_NOTE_MAGIC   ((gcov_unsigned_t)0x67636e6f) /* "gcno" @endverbatim */
 
#define GCOV_FILENAME_MAGIC   ((gcov_unsigned_t)0x6763666e) /* "gcfn" @endverbatim */
 
#define GCOV_UNSIGNED2STRING(ARRAY, VALUE)
 
#define GCOV_WORD_SIZE   4
 
#define GCOV_TAG_FUNCTION   ((gcov_unsigned_t)0x01000000)
 
#define GCOV_TAG_FUNCTION_LENGTH   (3 * GCOV_WORD_SIZE)
 
#define GCOV_TAG_BLOCKS   ((gcov_unsigned_t)0x01410000)
 
#define GCOV_TAG_BLOCKS_LENGTH(NUM)   (NUM)
 
#define GCOV_TAG_ARCS   ((gcov_unsigned_t)0x01430000)
 
#define GCOV_TAG_ARCS_LENGTH(NUM)   (1 + (NUM) * 2 * GCOV_WORD_SIZE)
 
#define GCOV_TAG_ARCS_NUM(LENGTH)   (((LENGTH / GCOV_WORD_SIZE) - 1) / 2)
 
#define GCOV_TAG_CONDS   ((gcov_unsigned_t)0x01470000)
 
#define GCOV_TAG_CONDS_LENGTH(NUM)   ((NUM) * 2 * GCOV_WORD_SIZE)
 
#define GCOV_TAG_CONDS_NUM(LENGTH)   (((LENGTH) / GCOV_WORD_SIZE) / 2)
 
#define GCOV_TAG_LINES   ((gcov_unsigned_t)0x01450000)
 
#define GCOV_TAG_COUNTER_BASE   ((gcov_unsigned_t)0x01a10000)
 
#define GCOV_TAG_COUNTER_LENGTH(NUM)   ((NUM) * 2 * GCOV_WORD_SIZE)
 
#define GCOV_TAG_COUNTER_NUM(LENGTH)   ((LENGTH / GCOV_WORD_SIZE) / 2)
 
#define GCOV_TAG_OBJECT_SUMMARY   ((gcov_unsigned_t)0xa1000000)
 
#define GCOV_TAG_OBJECT_SUMMARY_LENGTH   (2 * GCOV_WORD_SIZE)
 
#define GCOV_TAG_PROGRAM_SUMMARY   ((gcov_unsigned_t)0xa3000000) /* Obsolete @endverbatim */
 
#define GCOV_TAG_AFDO_FILE_NAMES   ((gcov_unsigned_t)0xaa000000)
 
#define GCOV_TAG_AFDO_FUNCTION   ((gcov_unsigned_t)0xac000000)
 
#define GCOV_TAG_AFDO_WORKING_SET   ((gcov_unsigned_t)0xaf000000)
 
#define DEF_GCOV_COUNTER(COUNTER, NAME, MERGE_FN)   COUNTER,
 
#define GCOV_FIRST_VALUE_COUNTER   GCOV_COUNTER_V_INTERVAL
 
#define GCOV_LAST_VALUE_COUNTER   (GCOV_COUNTERS - 1)
 
#define GCOV_N_VALUE_COUNTERS    (GCOV_LAST_VALUE_COUNTER - GCOV_FIRST_VALUE_COUNTER + 1)
 
#define GCOV_TOPN_MEM_COUNTERS   3
 
#define GCOV_TOPN_DISK_COUNTERS   2
 
#define GCOV_TOPN_MAXIMUM_TRACKED_VALUES   32
 
#define GCOV_TAG_FOR_COUNTER(COUNT)    (GCOV_TAG_COUNTER_BASE + ((gcov_unsigned_t)(COUNT) << 17))
 
#define GCOV_COUNTER_FOR_TAG(TAG)    ((unsigned)(((TAG) - GCOV_TAG_COUNTER_BASE) >> 17))
 
#define GCOV_TAG_IS_COUNTER(TAG)    (!((TAG) & 0xFFFF) && GCOV_COUNTER_FOR_TAG (TAG) < GCOV_COUNTERS)
 
#define GCOV_TAG_MASK(TAG)   (((TAG) - 1) ^ (TAG))
 
#define GCOV_TAG_IS_SUBTAG(TAG, SUB)
 
#define GCOV_TAG_IS_SUBLEVEL(TAG, SUB)    (GCOV_TAG_MASK (TAG) > GCOV_TAG_MASK (SUB))
 
#define GCOV_BLOCK_UNEXPECTED   (1 << 1)
 
#define GCOV_ARC_ON_TREE   (1 << 0)
 
#define GCOV_ARC_FAKE   (1 << 1)
 
#define GCOV_ARC_FALLTHROUGH   (1 << 2)
 

Typedefs

typedef unsigned gcov_unsigned_t
 
typedef unsigned gcov_position_t
 

Enumerations

enum  { GCOV_COUNTERS }
 

Functions

GCOV_LINKAGE int gcov_magic (gcov_unsigned_t, gcov_unsigned_t)
 
GCOV_LINKAGE int gcov_open (const char *, int) ATTRIBUTE_HIDDEN
 
GCOV_LINKAGE int gcov_close (void) ATTRIBUTE_HIDDEN
 
GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned (void) ATTRIBUTE_HIDDEN
 
GCOV_LINKAGE gcov_type gcov_read_counter (void) ATTRIBUTE_HIDDEN
 
GCOV_LINKAGE void gcov_read_summary (struct gcov_summary *) ATTRIBUTE_HIDDEN
 
GCOV_LINKAGE const chargcov_read_string (void)
 
GCOV_LINKAGE void gcov_sync (gcov_position_t, gcov_unsigned_t)
 
charmangle_path (char const *base)
 
GCOV_LINKAGE void gcov_write (const void *, unsigned) ATTRIBUTE_HIDDEN
 
GCOV_LINKAGE void gcov_write_unsigned (gcov_unsigned_t) ATTRIBUTE_HIDDEN
 
GCOV_LINKAGE void gcov_write_string (const char *)
 
GCOV_LINKAGE void gcov_write_filename (const char *)
 
GCOV_LINKAGE gcov_position_t gcov_write_tag (gcov_unsigned_t)
 
GCOV_LINKAGE void gcov_write_length (gcov_position_t)
 

Macro Definition Documentation

◆ ATTRIBUTE_HIDDEN

#define ATTRIBUTE_HIDDEN

◆ DEF_GCOV_COUNTER

#define DEF_GCOV_COUNTER ( COUNTER,
NAME,
MERGE_FN )   COUNTER,
Counters that are collected.   

◆ GCOV_ARC_FAKE

#define GCOV_ARC_FAKE   (1 << 1)

◆ GCOV_ARC_FALLTHROUGH

#define GCOV_ARC_FALLTHROUGH   (1 << 2)

◆ GCOV_ARC_ON_TREE

#define GCOV_ARC_ON_TREE   (1 << 0)
Arc flags.   

Referenced by branch_prob(), read_graph_file(), and tag_arcs().

◆ GCOV_BLOCK_UNEXPECTED

#define GCOV_BLOCK_UNEXPECTED   (1 << 1)
Basic block flags.   

◆ GCOV_COUNTER_FOR_TAG

#define GCOV_COUNTER_FOR_TAG ( TAG)     ((unsigned)(((TAG) - GCOV_TAG_COUNTER_BASE) >> 17))
Convert a tag to a counter.   

Referenced by read_counts_file(), and tag_counters().

◆ GCOV_DATA_MAGIC

#define GCOV_DATA_MAGIC   ((gcov_unsigned_t)0x67636461) /* "gcda" @endverbatim */
File magic. Must not be palindromes.   

Referenced by dump_gcov_file(), read_count_file(), read_counts_file(), and autofdo::read_profile().

◆ GCOV_DATA_SUFFIX

#define GCOV_DATA_SUFFIX   ".gcda"
File suffixes.   

Referenced by coverage_init(), and create_file_names().

◆ gcov_error

#define gcov_error ( ...)    fatal_error (input_location, __VA_ARGS__)

◆ GCOV_FILENAME_MAGIC

#define GCOV_FILENAME_MAGIC   ((gcov_unsigned_t)0x6763666e) /* "gcfn" @endverbatim */

◆ GCOV_FIRST_VALUE_COUNTER

#define GCOV_FIRST_VALUE_COUNTER   GCOV_COUNTER_V_INTERVAL
The first of counters used for value profiling.  They must form a
consecutive interval and their order must match the order of
HIST_TYPEs in value-prof.h.   

◆ GCOV_LAST_VALUE_COUNTER

#define GCOV_LAST_VALUE_COUNTER   (GCOV_COUNTERS - 1)
The last of counters used for value profiling.   

◆ GCOV_LINKAGE

#define GCOV_LINKAGE   extern

◆ GCOV_LOCKED

#define GCOV_LOCKED   0
gcov_type is typedef'd elsewhere for the compiler  

◆ GCOV_LOCKED_WITH_LOCKING

#define GCOV_LOCKED_WITH_LOCKING   0

◆ GCOV_N_VALUE_COUNTERS

#define GCOV_N_VALUE_COUNTERS    (GCOV_LAST_VALUE_COUNTER - GCOV_FIRST_VALUE_COUNTER + 1)
Number of counters used for value profiling.   

Referenced by compute_value_histograms().

◆ gcov_nonruntime_assert

#define gcov_nonruntime_assert ( EXPR)    gcc_assert (EXPR)

◆ GCOV_NOTE_MAGIC

#define GCOV_NOTE_MAGIC   ((gcov_unsigned_t)0x67636e6f) /* "gcno" @endverbatim */

◆ GCOV_NOTE_SUFFIX

#define GCOV_NOTE_SUFFIX   ".gcno"

Referenced by coverage_init(), and create_file_names().

◆ GCOV_TAG_AFDO_FILE_NAMES

#define GCOV_TAG_AFDO_FILE_NAMES   ((gcov_unsigned_t)0xaa000000)

◆ GCOV_TAG_AFDO_FUNCTION

#define GCOV_TAG_AFDO_FUNCTION   ((gcov_unsigned_t)0xac000000)

◆ GCOV_TAG_AFDO_WORKING_SET

#define GCOV_TAG_AFDO_WORKING_SET   ((gcov_unsigned_t)0xaf000000)

◆ GCOV_TAG_ARCS

#define GCOV_TAG_ARCS   ((gcov_unsigned_t)0x01430000)

Referenced by branch_prob(), and read_graph_file().

◆ GCOV_TAG_ARCS_LENGTH

#define GCOV_TAG_ARCS_LENGTH ( NUM)    (1 + (NUM) * 2 * GCOV_WORD_SIZE)

◆ GCOV_TAG_ARCS_NUM

#define GCOV_TAG_ARCS_NUM ( LENGTH)    (((LENGTH / GCOV_WORD_SIZE) - 1) / 2)

Referenced by read_graph_file(), and tag_arcs().

◆ GCOV_TAG_BLOCKS

#define GCOV_TAG_BLOCKS   ((gcov_unsigned_t)0x01410000)

Referenced by branch_prob(), and read_graph_file().

◆ GCOV_TAG_BLOCKS_LENGTH

#define GCOV_TAG_BLOCKS_LENGTH ( NUM)    (NUM)

◆ GCOV_TAG_CONDS

#define GCOV_TAG_CONDS   ((gcov_unsigned_t)0x01470000)

Referenced by branch_prob(), and read_graph_file().

◆ GCOV_TAG_CONDS_LENGTH

#define GCOV_TAG_CONDS_LENGTH ( NUM)    ((NUM) * 2 * GCOV_WORD_SIZE)

◆ GCOV_TAG_CONDS_NUM

#define GCOV_TAG_CONDS_NUM ( LENGTH)    (((LENGTH) / GCOV_WORD_SIZE) / 2)

Referenced by read_graph_file(), and tag_conditions().

◆ GCOV_TAG_COUNTER_BASE

#define GCOV_TAG_COUNTER_BASE   ((gcov_unsigned_t)0x01a10000)

◆ GCOV_TAG_COUNTER_LENGTH

#define GCOV_TAG_COUNTER_LENGTH ( NUM)    ((NUM) * 2 * GCOV_WORD_SIZE)

Referenced by read_count_file().

◆ GCOV_TAG_COUNTER_NUM

#define GCOV_TAG_COUNTER_NUM ( LENGTH)    ((LENGTH / GCOV_WORD_SIZE) / 2)

Referenced by read_counts_file(), and tag_counters().

◆ GCOV_TAG_FOR_COUNTER

#define GCOV_TAG_FOR_COUNTER ( COUNT)     (GCOV_TAG_COUNTER_BASE + ((gcov_unsigned_t)(COUNT) << 17))
Convert a counter index to a tag.   

Referenced by read_count_file().

◆ GCOV_TAG_FUNCTION

#define GCOV_TAG_FUNCTION   ((gcov_unsigned_t)0x01000000)

◆ GCOV_TAG_FUNCTION_LENGTH

#define GCOV_TAG_FUNCTION_LENGTH   (3 * GCOV_WORD_SIZE)

Referenced by read_count_file().

◆ GCOV_TAG_IS_COUNTER

#define GCOV_TAG_IS_COUNTER ( TAG)     (!((TAG) & 0xFFFF) && GCOV_COUNTER_FOR_TAG (TAG) < GCOV_COUNTERS)
Check whether a tag is a counter tag.   

Referenced by dump_gcov_file(), and read_counts_file().

◆ GCOV_TAG_IS_SUBLEVEL

#define GCOV_TAG_IS_SUBLEVEL ( TAG,
SUB )    (GCOV_TAG_MASK (TAG) > GCOV_TAG_MASK (SUB))
Return nonzero if SUB is at a sublevel to TAG.   

◆ GCOV_TAG_IS_SUBTAG

#define GCOV_TAG_IS_SUBTAG ( TAG,
SUB )
Value:
&& !(((SUB) ^ (TAG)) & ~GCOV_TAG_MASK (TAG)))
#define GCOV_TAG_MASK(TAG)
Definition gcov-io.h:322
T * ggc_alloc(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:184
Return nonzero if SUB is an immediate subtag of TAG.   

Referenced by dump_gcov_file(), and read_graph_file().

◆ GCOV_TAG_LINES

#define GCOV_TAG_LINES   ((gcov_unsigned_t)0x01450000)

Referenced by output_location(), and read_graph_file().

◆ GCOV_TAG_MASK

#define GCOV_TAG_MASK ( TAG)    (((TAG) - 1) ^ (TAG))
The tag level mask has 1's in the position of the inner levels, &
the lsb of the current level, and zero on the current and outer
levels.   

Referenced by dump_gcov_file().

◆ GCOV_TAG_OBJECT_SUMMARY

#define GCOV_TAG_OBJECT_SUMMARY   ((gcov_unsigned_t)0xa1000000)

◆ GCOV_TAG_OBJECT_SUMMARY_LENGTH

#define GCOV_TAG_OBJECT_SUMMARY_LENGTH   (2 * GCOV_WORD_SIZE)

◆ GCOV_TAG_PROGRAM_SUMMARY

#define GCOV_TAG_PROGRAM_SUMMARY   ((gcov_unsigned_t)0xa3000000) /* Obsolete @endverbatim */

◆ GCOV_TOPN_DISK_COUNTERS

#define GCOV_TOPN_DISK_COUNTERS   2
Number of top N counters in disk representation.   

◆ GCOV_TOPN_MAXIMUM_TRACKED_VALUES

#define GCOV_TOPN_MAXIMUM_TRACKED_VALUES   32
Maximum number of tracked TOP N value profiles.   

Referenced by dump_ic_profile(), ipa_profile_generate_summary(), ipa_profile_read_edge_summary(), and ipa_profile_write_edge_summary().

◆ GCOV_TOPN_MEM_COUNTERS

#define GCOV_TOPN_MEM_COUNTERS   3
Number of top N counters when being in memory.   

Referenced by gimple_find_values_to_profile().

◆ GCOV_UNSIGNED2STRING

#define GCOV_UNSIGNED2STRING ( ARRAY,
VALUE )
Value:
((ARRAY)[0] = (char)((VALUE) >> 24), \
(ARRAY)[1] = (char)((VALUE) >> 16), \
(ARRAY)[2] = (char)((VALUE) >> 8), \
(ARRAY)[3] = (char)((VALUE) >> 0))
@ ARRAY
Definition gengtype.h:486
Convert a magic or version number to a 4 character string.   

Referenced by dump_gcov_file(), read_count_file(), read_counts_file(), and read_graph_file().

◆ GCOV_WORD_SIZE

#define GCOV_WORD_SIZE   4
The record tags.  Values [1..3f] are for tags which may be in either
file.  Values [41..9f] for those in the note file and [a1..ff] for
the data file.  The tag value zero is used as an explicit end of
file marker -- it is not required to be present.
All length values are in bytes.   

Referenced by gcov_read_words(), and gcov_write_length().

Typedef Documentation

◆ gcov_position_t

◆ gcov_unsigned_t

Enumeration Type Documentation

◆ anonymous enum

Enumerator
GCOV_COUNTERS 

Function Documentation

◆ gcov_close()

GCOV_LINKAGE int gcov_close ( void )
Close the current gcov file. Flushes data to disk. Returns nonzero
on failure or error flag set.   

References gcov_var::error, gcov_var::file, GCOV_FILE_WRITE_ERROR, ggc_alloc(), and gcov_var::mode.

Referenced by coverage_finish(), coverage_remove_note_file(), dump_gcov_file(), read_count_file(), read_counts_file(), and read_graph_file().

◆ gcov_magic()

GCOV_LINKAGE int gcov_magic ( gcov_unsigned_t magic,
gcov_unsigned_t expected )
Functions for reading and writing gcov files. In libgcov you can
open the file for reading then writing. Elsewhere you can open the
file either for reading or for writing. When reading a file you may
use the gcov_read_* functions, gcov_sync, gcov_position, and
gcov_error. When writing a file you may use the gcov_write*
functions and gcov_error. When a file is to be rewritten
you use the functions for reading, then gcov_rewrite then the
functions for writing.  Your file may become corrupted if you break
these invariants.   
Check if MAGIC is EXPECTED. Use it to determine endianness of the
file. Returns +1 for same endian, -1 for other endian and zero for
not EXPECTED.   

References gcov_var::endian, and ggc_alloc().

Referenced by dump_gcov_file(), read_count_file(), read_counts_file(), and read_graph_file().

◆ gcov_open()

GCOV_LINKAGE int gcov_open ( const char * name,
int mode )
Available everywhere.   
Open a gcov file. NAME is the name of the file to open and MODE
indicates whether a new file should be created, or an existing file
opened. If MODE is >= 0 an existing file will be opened, if
possible, and if MODE is <= 0, a new file will be created. Use
MODE=0 to attempt to reopen an existing file and then fall back on
creating a new one.  If MODE > 0, the file will be opened in
read-only mode.  Otherwise it will be opened for modification.
Return zero on failure, non-zero on success.   

References gcov_var::endian, errno, gcov_var::error, fdopen, gcov_var::file, fopen, GCOV_FILE_NO_ERROR, GCOV_MODE_STDIN, gcov_nonruntime_assert, ggc_alloc(), LONG_MAX, gcov_var::mode, O_BINARY, O_RDONLY, and SEEK_SET.

Referenced by coverage_init(), dump_gcov_file(), read_count_file(), read_counts_file(), read_graph_file(), and autofdo::read_profile().

◆ gcov_read_counter()

GCOV_LINKAGE gcov_type gcov_read_counter ( void )
Read counter value from a coverage file. Sets error flag on file
error, overflow flag on overflow  

References gcov_var::error, from_file(), GCOV_FILE_COUNTER_OVERFLOW, gcov_read_words(), and ggc_alloc().

Referenced by autofdo::autofdo_source_profile::read(), read_count_file(), read_counts_file(), autofdo::function_instance::read_function_instance(), and tag_counters().

◆ gcov_read_string()

GCOV_LINKAGE const char * gcov_read_string ( void )
We need to expose the below function when compiling for gcov-tool.   
Read string from coverage file.  Allocate the buffer for the string
from the heap or die.  Return a pointer to the string, or NULL on
empty string.   

References gcov_read_bytes(), gcov_read_unsigned(), and ggc_alloc().

Referenced by dump_gcov_file(), autofdo::string_table::read(), read_graph_file(), tag_function(), and tag_lines().

◆ gcov_read_summary()

GCOV_LINKAGE void gcov_read_summary ( struct gcov_summary * summary)

References gcov_read_unsigned(), and ggc_alloc().

Referenced by read_count_file(), and tag_summary().

◆ gcov_read_unsigned()

◆ gcov_sync()

GCOV_LINKAGE void gcov_sync ( gcov_position_t base,
gcov_unsigned_t length )
We need to expose the below function when compiling for gcov-tool.   
Reset to a known position.  BASE should have been obtained from
gcov_position, LENGTH should be a record length.   

References gcov_var::file, GCOV_MODE_STDIN, gcov_nonruntime_assert, ggc_alloc(), gcov_var::mode, and SEEK_SET.

Referenced by dump_gcov_file(), read_count_file(), read_counts_file(), and read_graph_file().

◆ gcov_write()

GCOV_LINKAGE void gcov_write ( const void * data,
unsigned length )
Available outside gcov  
Write DATA of LENGTH characters to coverage file.   

References gcov_var::error, gcov_var::file, GCOV_FILE_WRITE_ERROR, ggc_alloc(), and r.

◆ gcov_write_filename()

GCOV_LINKAGE void gcov_write_filename ( const char * filename)
Write FILENAME to coverage file.  Sets error flag on file
error, overflow flag on overflow  

References free(), gcov_write_string(), ggc_alloc(), and NULL.

Referenced by coverage_begin_function(), and output_location().

◆ gcov_write_length()

GCOV_LINKAGE void gcov_write_length ( gcov_position_t position)
Write a record length using POSITION, which was returned by
gcov_write_tag.  The current file position is the end of the
record, and is restored before returning.  Returns nonzero on
overflow.   

References current_position, gcov_nonruntime_assert, gcov_position(), gcov_seek(), GCOV_WORD_SIZE, gcov_write_unsigned(), and gcov_var::mode.

Referenced by branch_prob(), and coverage_begin_function().

◆ gcov_write_string()

GCOV_LINKAGE void gcov_write_string ( const char * string)
Available only in compiler  
Write STRING to coverage file.  Sets error flag on file
error, overflow flag on overflow  

References gcov_var::error, gcov_var::file, GCOV_FILE_WRITE_ERROR, gcov_write_unsigned(), ggc_alloc(), and r.

Referenced by branch_prob(), coverage_begin_function(), coverage_init(), and gcov_write_filename().

◆ gcov_write_tag()

Write a tag TAG and reserve space for the record length. Return a
value to be used for gcov_write_length.   

References gcov_position(), and gcov_write_unsigned().

Referenced by branch_prob(), coverage_begin_function(), and output_location().

◆ gcov_write_unsigned()

◆ mangle_path()

char * mangle_path ( char const * base)
Mangle filename path of BASE and output new allocated pointer with
mangled path.   

References ggc_alloc().

Referenced by coverage_init(), get_gcov_intermediate_filename(), and mangle_name().