/* Gcov.c: prepend line execution counts and branch probabilities to a
source file.
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
Contributed by James E. Wilson of Cygnus Support.
Mangled by Bob Manson of Cygnus Support.
Mangled further by Nathan Sidwell <nathan@codesourcery.com>
Gcov is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
Gcov is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Gcov; see the file COPYING. If not, write to
the Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
/* ??? Print a list of the ten blocks with the highest execution counts,
and list the line numbers corresponding to those blocks. Also, perhaps
list the line numbers with the highest execution counts, only printing
the first if there are several which are all listed in the same block. */
/* ??? Should have an option to print the number of basic blocks, and the
percent of them that are covered. */
/* ??? Does not correctly handle the case where two .bb files refer to
the same included source file. For example, if one has a short
file containing only inline functions, which is then included in
two other files, then there will be two .bb files which refer to
the include file, but there is no way to get the total execution
counts for the included file, can only get execution counts for one
or the other of the including files. this can be fixed by --ratios
--long-file-names --preserve-paths and perl. */
/* Need an option to show individual block counts, and show
probabilities of fall through arcs. */
#include "config.h"
#include "system.h"
/**
* zubo modified for independent GCOV
* remove the following header files, since it is not necessary for the independent GCOV.
*/
/*
#include "coretypes.h"
#include "tm.h"
*/
#include "intl.h"
#include "version.h"
#include <getopt.h>
#define IN_GCOV 1
#include "gcov-io.h"
#include "gcov-io.c"
/* The bbg file is generated by -ftest-coverage option. The da file is
generated by a program compiled with -fprofile-arcs. Their formats
are documented in gcov-io.h. */
/* The functions in this file for creating and solution program flow graphs
are very similar to functions in the gcc source file profile.c. In
some places we make use of the knowledge of how profile.c works to
select particular algorithms here. */
/* This is the size of the buffer used to read in source file lines. */
#define STRING_SIZE 200
struct function_info;
struct block_info;
struct source_info;
/* Describes an arc between two basic blocks. */
typedef struct arc_info
{
/* source and destination blocks. */
struct block_info *src;
struct block_info *dst;
/* transition counts. */
gcov_type count;
/* used in cycle search, so that we do not clobber original counts. */
gcov_type cs_count;
unsigned int count_valid : 1;
unsigned int on_tree : 1;
unsigned int fake : 1;
unsigned int fall_through : 1;
/* Arc is for a function that abnormally returns. */
unsigned int is_call_non_return : 1;
/* Arc is for catch/setjump. */
unsigned int is_nonlocal_return : 1;
/* Is an unconditional branch. */
unsigned int is_unconditional : 1;
/* Loop making arc. */
unsigned int cycle : 1;
/* Next branch on line. */
struct arc_info *line_next;
/* Links to next arc on src and dst lists. */
struct arc_info *succ_next;
struct arc_info *pred_next;
} arc_t;
/* Describes a basic block. Contains lists of arcs to successor and
predecessor blocks. */
typedef struct block_info
{
/* Chain of exit and entry arcs. */
arc_t *succ;
arc_t *pred;
/* Number of unprocessed exit and entry arcs. */
gcov_type num_succ;
gcov_type num_pred;
/* Block execution count. */
gcov_type count;
unsigned flags : 13;
unsigned count_valid : 1;
unsigned valid_chain : 1;
unsigned invalid_chain : 1;
/* Block is a call instrumenting site. */
unsigned is_call_site : 1; /* Does the call. */
unsigned is_call_return : 1; /* Is the return. */
/* Block is a landing pad for longjmp or throw. */
unsigned is_nonlocal_return : 1;
union
{
struct
{
/* Array of line numbers and source files. source files are
introduced by a linenumber of zero, the next 'line number' is
the number of the source file. Always starts with a source
file. */
unsigned *encoding;
unsigned num;
} line; /* Valid until blocks are linked onto lines */
struct
{
/* Single line graph cycle workspace. Used for all-blocks
mode. */
arc_t *arc;
unsigned ident;
} cycle; /* Used in all-blocks mode, after blocks are linked onto
lines. */
} u;
/* Temporary chain for solving graph, and for chaining blocks on one
line. */
struct block_info *chain;
} block_t;
/* Describes a single function. Contains an array of basic blocks. */
typedef struct function_info
{
/* Name of function. */
char *name;
unsigned ident;
unsigned checksum;
/* Array of basic blocks. */
block_t *blocks;
unsigned num_blocks;
unsigned blocks_executed;
/* Raw arc coverage counts. */
gcov_type *counts;
unsigned num_counts;
/* First line number. */
unsigned line;
struct source_info *src;
/* Next function in same source file. */
struct function_info *line_next;
/* Next function. */
struct function_info *next;
} function_t;
/* Describes coverage of a file or function. */
typedef struct coverage_info
{
int lines;
int lines_executed;
int branches;
int branches_executed;
int branches_taken;
int calls;
int calls_executed;
char *name;
} coverage_t;
/* Describes a single line of source. Contains a chain of basic blocks
with code on it. */
typedef struct line_info
{
gcov_type count; /* execution count */
union
{
arc_t *branches; /* branches from blocks that end on this
line. Used for branch-counts when not
all-blocks mode. */
block_t *blocks; /* blocks which start on this line. Used
in all-blocks mode. */
} u;
unsigned exists : 1;
} line_t;
/* Describes a file mentioned in the block graph. Contains an array
of line info. */
typedef struct source_info
{
/* Name of source file. */
char *name;
unsigned index;
/* Array of line information. */
line_t *lines;
unsigned num_lines;
coverage_t coverage;
/* Functions in this source file. These are in ascending line
number order. */
function_t *functions;
/* Next source file. */
struct source_info *next;
} source_t;
/* Holds a list of function basic block graphs. */
static function_t *functions;
/* This points to the head of the sourcefile structure list. */
static source_t *sources;
/* This holds data summary information. */
static struct gcov_summary object_summary;
static unsigned program_count;
/* Modification time of graph file. */
static time_t bbg_file_time;
/* Name and file pointer of the input file for the basic block graph. */
static char *bbg_file_name;
/* Stamp of the bbg file */
static unsigned bbg_stamp;
/* Name and file pointer of the input file for the arc c
- 1
- 2
- 3
前往页