GCC Middle and Back End API Reference
gcov.c File Reference

Data Structures

struct  arc_info
struct  block_info
struct  function_info
struct  coverage_info
struct  line_info
struct  source_info
struct  name_map

Typedefs

typedef struct arc_info arc_t
typedef struct block_info block_t
typedef struct function_info function_t
typedef struct coverage_info coverage_t
typedef struct line_info line_t
typedef struct source_info source_t
typedef struct name_map name_map_t

Functions

static int process_args (int, char **)
static void print_usage (static int output_branch_count(FILE int)
static void print_usage ()
static void print_version ()
static int process_args ()
static char * get_gcov_intermediate_filename ()
static void output_intermediate_file ()
static void process_file ()
static void output_gcov_file ()
static void generate_results ()
static void release_function ()
static void release_structures ()
static void create_file_names ()
static int name_search ()
static int name_sort ()
static unsigned find_source ()
static function_tread_graph_file ()
static int read_count_file ()
static void solve_flow_graph ()
static void find_exception_blocks ()
static void add_branch_counts ()
static char const * format_gcov ()
static void executed_summary ()
static void function_summary ()
static char * canonicalize_name ()
static char * make_gcov_file_name ()
static char * mangle_name ()
static void add_line_counts ()
static void accumulate_line_counts ()
static int output_branch_count ()
static const char * read_line ()
static void output_lines ()

Variables

static function_tfunctions
static function_t ** fn_end = &functions
static source_tsources
static unsigned n_sources
static unsigned a_sources
static name_map_tnames
static unsigned n_names
static unsigned a_names
static unsigned object_runs
static unsigned program_count
static unsigned total_lines
static unsigned total_executed
static time_t bbg_file_time
static char * bbg_file_name
static unsigned bbg_stamp
static char * da_file_name
static int no_data_file
static int multiple_files = 0
static int flag_branches = 0
static int flag_unconditional = 0
static int flag_gcov_file = 1
static int flag_display_progress = 0
static int flag_intermediate_format = 0
static int flag_demangled_names = 0
static int flag_long_names = 0
static int flag_all_blocks = 0
static int flag_function_summary = 0
static char * object_directory = 0
static char * source_prefix = 0
static size_t source_length = 0
static int flag_relative_only = 0
static int flag_preserve_paths = 0
static int flag_counts = 0
static struct option options []

Typedef Documentation

typedef struct arc_info arc_t
Describes an arc between two basic blocks.   
typedef struct block_info block_t
Describes a basic block. Contains lists of arcs to successor and
   predecessor blocks.   
typedef struct coverage_info coverage_t
Describes coverage of a file or function.   
typedef struct function_info function_t
Describes a single function. Contains an array of basic blocks.   
typedef struct line_info line_t
Describes a single line of source. Contains a chain of basic blocks
   with code on it.   
typedef struct name_map name_map_t
typedef struct source_info source_t
Describes a file mentioned in the block graph.  Contains an array
   of line info.   

Function Documentation

static char* canonicalize_name ( )
static
Canonicalize the filename NAME by canonicalizing directory
   separators, eliding . components and resolving .. components
   appropriately.  Always returns a unique string.   

References len, memcpy(), function_info::name, and strlen().

Referenced by find_source(), and generate_results().

static void create_file_names ( )
static
Generate the names of the graph and data files.  If OBJECT_DIRECTORY
   is not specified, these are named from FILE_NAME sans extension.  If
   OBJECT_DIRECTORY is specified and is a directory, the files are in that
   directory, but named from the basename of the FILE_NAME, sans extension.
   Otherwise OBJECT_DIRECTORY is taken to be the name of the object *file*
   and the data files are named from that.   

References bbg_file_name, bbg_file_time, bbg_stamp, da_file_name, free(), object_directory, and strlen().

Referenced by process_file().

static void executed_summary ( )
static
Summary of execution  

References fnotice(), and format_gcov().

Referenced by function_summary(), and generate_results().

static void find_exception_blocks ( )
static
static unsigned find_source ( )
static
static char const* format_gcov ( )
static
Format a GCOV_TYPE integer as either a percent ratio, or absolute
   count.  If dp >= 0, format TOP/BOTTOM * 100 to DP decimal places.
   If DP is zero, no decimal point is printed. Only print 100% when
   TOP==BOTTOM and only print 0% when TOP=0.  If dp < 0, then simply
   format TOP.  Return pointer to a static string.   

References buffer, HOST_WIDEST_INT, HOST_WIDEST_INT_PRINT_DEC, and limit.

Referenced by executed_summary(), function_summary(), output_branch_count(), output_intermediate_file(), and output_lines().

static char* get_gcov_intermediate_filename ( )
static
Get the name of the gcov file.  The return value must be free'd.

   It appends the '.gcov' extension to the *basename* of the file.
   The resulting file name will be in PWD.

   e.g.,
   input: foo.da,       output: foo.da.gcov
   input: a/b/foo.cc,   output: foo.cc.gcov   

References strlen().

Referenced by generate_results().

static char* make_gcov_file_name ( )
static
Generate an output file name. INPUT_NAME is the canonicalized main
   input file and SRC_NAME is the canonicalized file name.
   LONG_OUTPUT_NAMES and PRESERVE_PATHS affect name generation.  With
   long_output_names we prepend the processed name of the input file
   to each output name (except when the current source file is the
   input file, so you don't get a double concatenation). The two
   components are separated by '##'.  With preserve_paths we create a
   filename from all path components of the source file, replacing '/'
   with '#', and .. with '^', without it we simply take the basename
   component.  (Remember, the canonicalized name will already have
   elided '.' components and converted \\ separators.)   

References flag_long_names, mangle_name(), and strlen().

Referenced by output_gcov_file().

static char* mangle_name ( )
static

References flag_preserve_paths, len, memcpy(), and strlen().

Referenced by make_gcov_file_name().

static int name_search ( )
static
A is a string and B is a pointer to name_map_t.  Compare for file
   name orderability.   

References name_map::name.

Referenced by find_source(), generate_results(), and name_sort().

static int name_sort ( )
static
A and B are a pointer to name_map_t.  Compare for file name
   orderability.   

References name_map::name, and name_search().

Referenced by find_source().

static int output_branch_count ( )
static
static void output_gcov_file ( )
static
static void output_intermediate_file ( )
static
@verbatim Output the result in intermediate format used by 'lcov'.

The intermediate format contains a single file named 'foo.cc.gcov', with no source code included. A sample output is

file:foo.cc function:5,1,Z3foov function:13,1,main function:19,1,_GLOBAL__sub_I__Z3foov function:19,1,_Z41__static_initialization_and_destruction_0ii lcount:5,1 lcount:7,9 lcount:9,8 lcount:11,1 file:/.../iostream lcount:74,1 file:/.../basic_ios.h file:/.../ostream file:/.../ios_base.h function:157,0,_ZStorSt12_Ios_IostateS lcount:157,0 file:/.../char_traits.h function:258,0,_ZNSt11char_traitsIcE6lengthEPKc lcount:258,0 ...

The default gcov outputs multiple files: 'foo.cc.gcov', 'iostream.gcov', 'ios_base.h.gcov', etc. with source code included. Instead the intermediate format here outputs only a single file 'foo.cc.gcov' similar to the above example.

References function_info::blocks, line_info::branches, arc_info::count, block_info::count, line_info::count, function_info::demangled_name, line_info::exists, flag_branches, flag_demangled_names, format_gcov(), source_info::functions, arc_info::is_call_non_return, arc_info::is_unconditional, function_info::line, arc_info::line_next, function_info::line_next, source_info::lines, function_info::name, source_info::name, arc_info::src, and line_info::u.

Referenced by generate_results().

static void print_usage ( void  )
static
Print a usage message and exit.  If ERROR_P is nonzero, this is an error,
   otherwise the output of --help.   

References bug_report_url, and fnotice().

static void print_version ( void  )
static
Print version information and exit.   

References fnotice(), pkgversion_string, and version_string.

static int process_args ( int  ,
char **   
)
static
Forward declarations.   
static const char* read_line ( )
static

References len, and strlen().

Referenced by output_lines().

static void release_structures ( )
static
Release all memory used.   

References free(), n_names, n_sources, function_info::next, and release_function().

Referenced by print_usage().


Variable Documentation

unsigned a_names
static

Referenced by find_source(), and print_usage().

unsigned a_sources
static

Referenced by find_source(), and print_usage().

char* bbg_file_name
static
Name of the notes (gcno) output file.  The "bbg" prefix is for
   historical reasons, when the notes file contained only the
   basic block graph notes.   

Referenced by add_line_counts(), create_file_names(), find_source(), output_lines(), read_graph_file(), and solve_flow_graph().

time_t bbg_file_time
static
Modification time of graph file.   

Referenced by create_file_names(), find_source(), and read_graph_file().

unsigned bbg_stamp
static
Stamp of the bbg file  

Referenced by create_file_names(), read_count_file(), and read_graph_file().

char* da_file_name
static
Name and file pointer of the input file for the count data (gcda).   

Referenced by create_file_names(), output_lines(), and read_count_file().

int flag_all_blocks = 0
static
Output count information for every basic block, not merely those
   that contain line number information.   

Referenced by accumulate_line_counts(), add_line_counts(), output_lines(), and process_args().

int flag_branches = 0
static
int flag_counts = 0
static
Output the number of times a branch was taken as opposed to the percentage
   of times it was taken.   

Referenced by output_branch_count(), and process_args().

int flag_demangled_names = 0
static
int flag_display_progress = 0
static
Output progress indication if this is true.  This is off by default
   and can be turned on by the -d option.   

Referenced by print_usage(), and process_args().

int flag_function_summary = 0
static
Output summary info for each function.   

Referenced by generate_results(), and process_args().

int flag_gcov_file = 1
static
Output a gcov file if this is true.  This is on by default, and can
   be turned off by the -n option.   

Referenced by generate_results(), and process_args().

int flag_intermediate_format = 0
static
Output *.gcov file in intermediate format used by 'lcov'.   

Referenced by generate_results(), and process_args().

int flag_long_names = 0
static
For included files, make the gcov output file name include the name
   of the input source file.  For example, if x.h is included in a.c,
   then the output file name is a.c##x.h.gcov instead of x.h.gcov.   

Referenced by make_gcov_file_name(), and process_args().

int flag_preserve_paths = 0
static
Preserve all pathname components. Needed when object files and
   source files are in subdirectories. '/' is mangled as '#', '.' is
   elided and '..' mangled to '^'.   

Referenced by mangle_name(), and process_args().

int flag_relative_only = 0
static
Only show data for sources with relative pathnames.  Absolute ones
   usually indicate a system header file, which although it may
   contain inline functions, is usually uninteresting.   

Referenced by generate_results(), and process_args().

int flag_unconditional = 0
static
Show unconditional branches too.   

Referenced by output_branch_count(), and process_args().

function_t** fn_end = &functions
static
function_t* functions
static
Holds a list of function basic block graphs.   
int multiple_files = 0
static
If there is several input files, compute and display results after
   reading all data files.  This way if two or more gcda file refer to
   the same source file (eg inline subprograms in a .h file), the
   counts are added.   

Referenced by output_lines(), and print_usage().

unsigned n_names
static
unsigned n_sources
static
int no_data_file
static
Data file is missing.   

Referenced by output_lines(), and read_count_file().

char* object_directory = 0
static
Object directory file prefix.  This is the directory/file where the
   graph and data files are looked for, if nonzero.   

Referenced by create_file_names(), and process_args().

unsigned object_runs
static
This holds data summary information.   

Referenced by output_lines(), and read_count_file().

struct option options[]
static
Initial value:
{
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'v' },
{ "all-blocks", no_argument, NULL, 'a' },
{ "branch-probabilities", no_argument, NULL, 'b' },
{ "branch-counts", no_argument, NULL, 'c' },
{ "intermediate-format", no_argument, NULL, 'i' },
{ "no-output", no_argument, NULL, 'n' },
{ "long-file-names", no_argument, NULL, 'l' },
{ "function-summaries", no_argument, NULL, 'f' },
{ "demangled-names", no_argument, NULL, 'm' },
{ "preserve-paths", no_argument, NULL, 'p' },
{ "relative-only", no_argument, NULL, 'r' },
{ "object-directory", required_argument, NULL, 'o' },
{ "object-file", required_argument, NULL, 'o' },
{ "source-prefix", required_argument, NULL, 's' },
{ "unconditional-branches", no_argument, NULL, 'u' },
{ "display-progress", no_argument, NULL, 'd' },
{ 0, 0, 0, 0 }
}
unsigned program_count
static

Referenced by output_lines(), and read_count_file().

size_t source_length = 0
static

Referenced by find_source(), and process_args().

char* source_prefix = 0
static
Source directory prefix.  This is removed from source pathnames
   that match, when generating the output file name.   

Referenced by find_source(), and process_args().

source_t* sources
static
unsigned total_executed
static

Referenced by generate_results().

unsigned total_lines
static

Referenced by generate_results().