Home | History | Annotate | Line # | Download | only in libgcc
libgcov.h revision 1.1.1.4
      1      1.1  mrg /* Header file for libgcov-*.c.
      2  1.1.1.4  mrg    Copyright (C) 1996-2018 Free Software Foundation, Inc.
      3      1.1  mrg 
      4      1.1  mrg    This file is part of GCC.
      5      1.1  mrg 
      6      1.1  mrg    GCC is free software; you can redistribute it and/or modify it under
      7      1.1  mrg    the terms of the GNU General Public License as published by the Free
      8      1.1  mrg    Software Foundation; either version 3, or (at your option) any later
      9      1.1  mrg    version.
     10      1.1  mrg 
     11      1.1  mrg    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
     12      1.1  mrg    WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13      1.1  mrg    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14      1.1  mrg    for more details.
     15      1.1  mrg 
     16      1.1  mrg    Under Section 7 of GPL version 3, you are granted additional
     17      1.1  mrg    permissions described in the GCC Runtime Library Exception, version
     18      1.1  mrg    3.1, as published by the Free Software Foundation.
     19      1.1  mrg 
     20      1.1  mrg    You should have received a copy of the GNU General Public License and
     21      1.1  mrg    a copy of the GCC Runtime Library Exception along with this program;
     22      1.1  mrg    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     23      1.1  mrg    <http://www.gnu.org/licenses/>.  */
     24      1.1  mrg 
     25      1.1  mrg #ifndef GCC_LIBGCOV_H
     26      1.1  mrg #define GCC_LIBGCOV_H
     27      1.1  mrg 
     28      1.1  mrg /* work around the poisoned malloc/calloc in system.h.  */
     29      1.1  mrg #ifndef xmalloc
     30      1.1  mrg #define xmalloc malloc
     31      1.1  mrg #endif
     32      1.1  mrg #ifndef xcalloc
     33      1.1  mrg #define xcalloc calloc
     34      1.1  mrg #endif
     35      1.1  mrg 
     36      1.1  mrg #ifndef IN_GCOV_TOOL
     37      1.1  mrg /* About the target.  */
     38      1.1  mrg /* This path will be used by libgcov runtime.  */
     39      1.1  mrg 
     40      1.1  mrg #include "tconfig.h"
     41  1.1.1.3  mrg #include "auto-target.h"
     42      1.1  mrg #include "tsystem.h"
     43      1.1  mrg #include "coretypes.h"
     44      1.1  mrg #include "tm.h"
     45      1.1  mrg #include "libgcc_tm.h"
     46  1.1.1.3  mrg #include "gcov.h"
     47      1.1  mrg 
     48  1.1.1.2  mrg #if __CHAR_BIT__ == 8
     49      1.1  mrg typedef unsigned gcov_unsigned_t __attribute__ ((mode (SI)));
     50      1.1  mrg typedef unsigned gcov_position_t __attribute__ ((mode (SI)));
     51      1.1  mrg #if LONG_LONG_TYPE_SIZE > 32
     52      1.1  mrg typedef signed gcov_type __attribute__ ((mode (DI)));
     53      1.1  mrg typedef unsigned gcov_type_unsigned __attribute__ ((mode (DI)));
     54      1.1  mrg #else
     55      1.1  mrg typedef signed gcov_type __attribute__ ((mode (SI)));
     56      1.1  mrg typedef unsigned gcov_type_unsigned __attribute__ ((mode (SI)));
     57      1.1  mrg #endif
     58      1.1  mrg #else
     59  1.1.1.2  mrg #if __CHAR_BIT__ == 16
     60      1.1  mrg typedef unsigned gcov_unsigned_t __attribute__ ((mode (HI)));
     61      1.1  mrg typedef unsigned gcov_position_t __attribute__ ((mode (HI)));
     62      1.1  mrg #if LONG_LONG_TYPE_SIZE > 32
     63      1.1  mrg typedef signed gcov_type __attribute__ ((mode (SI)));
     64      1.1  mrg typedef unsigned gcov_type_unsigned __attribute__ ((mode (SI)));
     65      1.1  mrg #else
     66      1.1  mrg typedef signed gcov_type __attribute__ ((mode (HI)));
     67      1.1  mrg typedef unsigned gcov_type_unsigned __attribute__ ((mode (HI)));
     68      1.1  mrg #endif
     69      1.1  mrg #else
     70      1.1  mrg typedef unsigned gcov_unsigned_t __attribute__ ((mode (QI)));
     71      1.1  mrg typedef unsigned gcov_position_t __attribute__ ((mode (QI)));
     72      1.1  mrg #if LONG_LONG_TYPE_SIZE > 32
     73      1.1  mrg typedef signed gcov_type __attribute__ ((mode (HI)));
     74      1.1  mrg typedef unsigned gcov_type_unsigned __attribute__ ((mode (HI)));
     75      1.1  mrg #else
     76      1.1  mrg typedef signed gcov_type __attribute__ ((mode (QI)));
     77      1.1  mrg typedef unsigned gcov_type_unsigned __attribute__ ((mode (QI)));
     78      1.1  mrg #endif
     79      1.1  mrg #endif
     80      1.1  mrg #endif
     81      1.1  mrg 
     82      1.1  mrg #if defined (TARGET_POSIX_IO)
     83      1.1  mrg #define GCOV_LOCKED 1
     84      1.1  mrg #else
     85      1.1  mrg #define GCOV_LOCKED 0
     86      1.1  mrg #endif
     87      1.1  mrg 
     88      1.1  mrg /* In libgcov we need these functions to be extern, so prefix them with
     89      1.1  mrg    __gcov.  In libgcov they must also be hidden so that the instance in
     90      1.1  mrg    the executable is not also used in a DSO.  */
     91      1.1  mrg #define gcov_var __gcov_var
     92      1.1  mrg #define gcov_open __gcov_open
     93      1.1  mrg #define gcov_close __gcov_close
     94      1.1  mrg #define gcov_write_tag_length __gcov_write_tag_length
     95      1.1  mrg #define gcov_position __gcov_position
     96      1.1  mrg #define gcov_seek __gcov_seek
     97      1.1  mrg #define gcov_rewrite __gcov_rewrite
     98      1.1  mrg #define gcov_is_error __gcov_is_error
     99      1.1  mrg #define gcov_write_unsigned __gcov_write_unsigned
    100      1.1  mrg #define gcov_write_counter __gcov_write_counter
    101      1.1  mrg #define gcov_write_summary __gcov_write_summary
    102      1.1  mrg #define gcov_read_unsigned __gcov_read_unsigned
    103      1.1  mrg #define gcov_read_counter __gcov_read_counter
    104      1.1  mrg #define gcov_read_summary __gcov_read_summary
    105      1.1  mrg #define gcov_sort_n_vals __gcov_sort_n_vals
    106      1.1  mrg 
    107      1.1  mrg #else /* IN_GCOV_TOOL */
    108      1.1  mrg /* About the host.  */
    109      1.1  mrg /* This path will be compiled for the host and linked into
    110      1.1  mrg    gcov-tool binary.  */
    111      1.1  mrg 
    112      1.1  mrg #include "config.h"
    113      1.1  mrg #include "system.h"
    114      1.1  mrg #include "coretypes.h"
    115      1.1  mrg #include "tm.h"
    116      1.1  mrg 
    117      1.1  mrg typedef unsigned gcov_unsigned_t;
    118      1.1  mrg typedef unsigned gcov_position_t;
    119      1.1  mrg /* gcov_type is typedef'd elsewhere for the compiler */
    120      1.1  mrg #if defined (HOST_HAS_F_SETLKW)
    121      1.1  mrg #define GCOV_LOCKED 1
    122      1.1  mrg #else
    123      1.1  mrg #define GCOV_LOCKED 0
    124      1.1  mrg #endif
    125      1.1  mrg 
    126      1.1  mrg /* Some Macros specific to gcov-tool.  */
    127      1.1  mrg 
    128      1.1  mrg #define L_gcov 1
    129      1.1  mrg #define L_gcov_merge_add 1
    130      1.1  mrg #define L_gcov_merge_single 1
    131      1.1  mrg #define L_gcov_merge_ior 1
    132      1.1  mrg #define L_gcov_merge_time_profile 1
    133      1.1  mrg #define L_gcov_merge_icall_topn 1
    134      1.1  mrg 
    135      1.1  mrg extern gcov_type gcov_read_counter_mem ();
    136      1.1  mrg extern unsigned gcov_get_merge_weight ();
    137      1.1  mrg extern struct gcov_info *gcov_list;
    138      1.1  mrg 
    139      1.1  mrg #endif /* !IN_GCOV_TOOL */
    140      1.1  mrg 
    141      1.1  mrg #if defined(inhibit_libc)
    142      1.1  mrg #define IN_LIBGCOV (-1)
    143      1.1  mrg #else
    144      1.1  mrg #define IN_LIBGCOV 1
    145      1.1  mrg #if defined(L_gcov)
    146      1.1  mrg #define GCOV_LINKAGE /* nothing */
    147      1.1  mrg #endif
    148      1.1  mrg #endif
    149      1.1  mrg 
    150      1.1  mrg /* Poison these, so they don't accidentally slip in.  */
    151      1.1  mrg #pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length
    152      1.1  mrg #pragma GCC poison gcov_time gcov_magic
    153      1.1  mrg 
    154      1.1  mrg #ifdef HAVE_GAS_HIDDEN
    155      1.1  mrg #define ATTRIBUTE_HIDDEN  __attribute__ ((__visibility__ ("hidden")))
    156      1.1  mrg #else
    157      1.1  mrg #define ATTRIBUTE_HIDDEN
    158      1.1  mrg #endif
    159      1.1  mrg 
    160      1.1  mrg #include "gcov-io.h"
    161      1.1  mrg 
    162      1.1  mrg /* Structures embedded in coveraged program.  The structures generated
    163      1.1  mrg    by write_profile must match these.  */
    164      1.1  mrg 
    165      1.1  mrg /* Information about counters for a single function.  */
    166      1.1  mrg struct gcov_ctr_info
    167      1.1  mrg {
    168      1.1  mrg   gcov_unsigned_t num;		/* number of counters.  */
    169      1.1  mrg   gcov_type *values;		/* their values.  */
    170      1.1  mrg };
    171      1.1  mrg 
    172      1.1  mrg /* Information about a single function.  This uses the trailing array
    173      1.1  mrg    idiom. The number of counters is determined from the merge pointer
    174      1.1  mrg    array in gcov_info.  The key is used to detect which of a set of
    175      1.1  mrg    comdat functions was selected -- it points to the gcov_info object
    176      1.1  mrg    of the object file containing the selected comdat function.  */
    177      1.1  mrg 
    178      1.1  mrg struct gcov_fn_info
    179      1.1  mrg {
    180      1.1  mrg   const struct gcov_info *key;		/* comdat key */
    181      1.1  mrg   gcov_unsigned_t ident;		/* unique ident of function */
    182      1.1  mrg   gcov_unsigned_t lineno_checksum;	/* function lineo_checksum */
    183      1.1  mrg   gcov_unsigned_t cfg_checksum;		/* function cfg checksum */
    184      1.1  mrg   struct gcov_ctr_info ctrs[1];		/* instrumented counters */
    185      1.1  mrg };
    186      1.1  mrg 
    187      1.1  mrg /* Type of function used to merge counters.  */
    188      1.1  mrg typedef void (*gcov_merge_fn) (gcov_type *, gcov_unsigned_t);
    189      1.1  mrg 
    190      1.1  mrg /* Information about a single object file.  */
    191      1.1  mrg struct gcov_info
    192      1.1  mrg {
    193      1.1  mrg   gcov_unsigned_t version;	/* expected version number */
    194      1.1  mrg   struct gcov_info *next;	/* link to next, used by libgcov */
    195      1.1  mrg 
    196      1.1  mrg   gcov_unsigned_t stamp;	/* uniquifying time stamp */
    197      1.1  mrg   const char *filename;		/* output file name */
    198      1.1  mrg 
    199      1.1  mrg   gcov_merge_fn merge[GCOV_COUNTERS];  /* merge functions (null for
    200      1.1  mrg 					  unused) */
    201      1.1  mrg 
    202      1.1  mrg   unsigned n_functions;		/* number of functions */
    203      1.1  mrg 
    204      1.1  mrg #ifndef IN_GCOV_TOOL
    205      1.1  mrg   const struct gcov_fn_info *const *functions; /* pointer to pointers
    206      1.1  mrg                                                   to function information  */
    207      1.1  mrg #else
    208      1.1  mrg   const struct gcov_fn_info **functions;
    209      1.1  mrg #endif /* !IN_GCOV_TOOL */
    210      1.1  mrg };
    211      1.1  mrg 
    212      1.1  mrg /* Root of a program/shared-object state */
    213      1.1  mrg struct gcov_root
    214      1.1  mrg {
    215      1.1  mrg   struct gcov_info *list;
    216      1.1  mrg   unsigned dumped : 1;	/* counts have been dumped.  */
    217      1.1  mrg   unsigned run_counted : 1;  /* run has been accounted for.  */
    218      1.1  mrg   struct gcov_root *next;
    219      1.1  mrg   struct gcov_root *prev;
    220      1.1  mrg };
    221      1.1  mrg 
    222      1.1  mrg extern struct gcov_root __gcov_root ATTRIBUTE_HIDDEN;
    223      1.1  mrg 
    224      1.1  mrg struct gcov_master
    225      1.1  mrg {
    226      1.1  mrg   gcov_unsigned_t version;
    227      1.1  mrg   struct gcov_root *root;
    228      1.1  mrg };
    229      1.1  mrg 
    230      1.1  mrg /* Exactly one of these will be active in the process.  */
    231      1.1  mrg extern struct gcov_master __gcov_master;
    232      1.1  mrg 
    233      1.1  mrg /* Dump a set of gcov objects.  */
    234      1.1  mrg extern void __gcov_dump_one (struct gcov_root *) ATTRIBUTE_HIDDEN;
    235      1.1  mrg 
    236      1.1  mrg /* Register a new object file module.  */
    237      1.1  mrg extern void __gcov_init (struct gcov_info *) ATTRIBUTE_HIDDEN;
    238      1.1  mrg 
    239  1.1.1.3  mrg /* GCOV exit function registered via a static destructor.  */
    240  1.1.1.3  mrg extern void __gcov_exit (void) ATTRIBUTE_HIDDEN;
    241      1.1  mrg 
    242      1.1  mrg /* Function to reset all counters to 0.  Both externally visible (and
    243      1.1  mrg    overridable) and internal version.  */
    244      1.1  mrg extern void __gcov_reset_int (void) ATTRIBUTE_HIDDEN;
    245      1.1  mrg 
    246      1.1  mrg /* User function to enable early write of profile information so far.  */
    247      1.1  mrg extern void __gcov_dump_int (void) ATTRIBUTE_HIDDEN;
    248      1.1  mrg 
    249      1.1  mrg /* The merge function that just sums the counters.  */
    250      1.1  mrg extern void __gcov_merge_add (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
    251      1.1  mrg 
    252      1.1  mrg /* The merge function to select the minimum valid counter value.  */
    253      1.1  mrg extern void __gcov_merge_time_profile (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
    254      1.1  mrg 
    255      1.1  mrg /* The merge function to choose the most common value.  */
    256      1.1  mrg extern void __gcov_merge_single (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
    257      1.1  mrg 
    258      1.1  mrg /* The merge function that just ors the counters together.  */
    259      1.1  mrg extern void __gcov_merge_ior (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
    260      1.1  mrg 
    261      1.1  mrg /* The merge function is used for topn indirect call counters.  */
    262      1.1  mrg extern void __gcov_merge_icall_topn (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
    263      1.1  mrg 
    264      1.1  mrg /* The profiler functions.  */
    265      1.1  mrg extern void __gcov_interval_profiler (gcov_type *, gcov_type, int, unsigned);
    266  1.1.1.3  mrg extern void __gcov_interval_profiler_atomic (gcov_type *, gcov_type, int,
    267  1.1.1.3  mrg 					     unsigned);
    268      1.1  mrg extern void __gcov_pow2_profiler (gcov_type *, gcov_type);
    269  1.1.1.3  mrg extern void __gcov_pow2_profiler_atomic (gcov_type *, gcov_type);
    270      1.1  mrg extern void __gcov_one_value_profiler (gcov_type *, gcov_type);
    271  1.1.1.3  mrg extern void __gcov_one_value_profiler_atomic (gcov_type *, gcov_type);
    272      1.1  mrg extern void __gcov_indirect_call_profiler_v2 (gcov_type, void *);
    273      1.1  mrg extern void __gcov_time_profiler (gcov_type *);
    274  1.1.1.3  mrg extern void __gcov_time_profiler_atomic (gcov_type *);
    275      1.1  mrg extern void __gcov_average_profiler (gcov_type *, gcov_type);
    276  1.1.1.3  mrg extern void __gcov_average_profiler_atomic (gcov_type *, gcov_type);
    277      1.1  mrg extern void __gcov_ior_profiler (gcov_type *, gcov_type);
    278  1.1.1.3  mrg extern void __gcov_ior_profiler_atomic (gcov_type *, gcov_type);
    279      1.1  mrg extern void __gcov_indirect_call_topn_profiler (gcov_type, void *);
    280      1.1  mrg extern void gcov_sort_n_vals (gcov_type *, int);
    281      1.1  mrg 
    282      1.1  mrg #ifndef inhibit_libc
    283      1.1  mrg /* The wrappers around some library functions..  */
    284      1.1  mrg extern pid_t __gcov_fork (void) ATTRIBUTE_HIDDEN;
    285      1.1  mrg extern int __gcov_execl (const char *, char *, ...) ATTRIBUTE_HIDDEN;
    286      1.1  mrg extern int __gcov_execlp (const char *, char *, ...) ATTRIBUTE_HIDDEN;
    287      1.1  mrg extern int __gcov_execle (const char *, char *, ...) ATTRIBUTE_HIDDEN;
    288      1.1  mrg extern int __gcov_execv (const char *, char *const []) ATTRIBUTE_HIDDEN;
    289      1.1  mrg extern int __gcov_execvp (const char *, char *const []) ATTRIBUTE_HIDDEN;
    290      1.1  mrg extern int __gcov_execve (const char *, char  *const [], char *const [])
    291      1.1  mrg   ATTRIBUTE_HIDDEN;
    292      1.1  mrg 
    293      1.1  mrg /* Functions that only available in libgcov.  */
    294      1.1  mrg GCOV_LINKAGE int gcov_open (const char */*name*/) ATTRIBUTE_HIDDEN;
    295      1.1  mrg GCOV_LINKAGE void gcov_write_counter (gcov_type) ATTRIBUTE_HIDDEN;
    296      1.1  mrg GCOV_LINKAGE void gcov_write_tag_length (gcov_unsigned_t, gcov_unsigned_t)
    297      1.1  mrg     ATTRIBUTE_HIDDEN;
    298      1.1  mrg GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/,
    299      1.1  mrg                                       const struct gcov_summary *)
    300      1.1  mrg     ATTRIBUTE_HIDDEN;
    301      1.1  mrg GCOV_LINKAGE void gcov_seek (gcov_position_t /*position*/) ATTRIBUTE_HIDDEN;
    302      1.1  mrg GCOV_LINKAGE void gcov_rewrite (void) ATTRIBUTE_HIDDEN;
    303      1.1  mrg 
    304      1.1  mrg /* "Counts" stored in gcda files can be a real counter value, or
    305      1.1  mrg    an target address. When differentiate these two types because
    306      1.1  mrg    when manipulating counts, we should only change real counter values,
    307      1.1  mrg    rather target addresses.  */
    308      1.1  mrg 
    309      1.1  mrg static inline gcov_type
    310      1.1  mrg gcov_get_counter (void)
    311      1.1  mrg {
    312      1.1  mrg #ifndef IN_GCOV_TOOL
    313      1.1  mrg   /* This version is for reading count values in libgcov runtime:
    314      1.1  mrg      we read from gcda files.  */
    315      1.1  mrg 
    316      1.1  mrg   return gcov_read_counter ();
    317      1.1  mrg #else
    318      1.1  mrg   /* This version is for gcov-tool. We read the value from memory and
    319      1.1  mrg      multiply it by the merge weight.  */
    320      1.1  mrg 
    321      1.1  mrg   return gcov_read_counter_mem () * gcov_get_merge_weight ();
    322      1.1  mrg #endif
    323      1.1  mrg }
    324      1.1  mrg 
    325      1.1  mrg /* Similar function as gcov_get_counter(), but handles target address
    326      1.1  mrg    counters.  */
    327      1.1  mrg 
    328      1.1  mrg static inline gcov_type
    329      1.1  mrg gcov_get_counter_target (void)
    330      1.1  mrg {
    331      1.1  mrg #ifndef IN_GCOV_TOOL
    332      1.1  mrg   /* This version is for reading count target values in libgcov runtime:
    333      1.1  mrg      we read from gcda files.  */
    334      1.1  mrg 
    335      1.1  mrg   return gcov_read_counter ();
    336      1.1  mrg #else
    337      1.1  mrg   /* This version is for gcov-tool.  We read the value from memory and we do NOT
    338      1.1  mrg      multiply it by the merge weight.  */
    339      1.1  mrg 
    340      1.1  mrg   return gcov_read_counter_mem ();
    341      1.1  mrg #endif
    342      1.1  mrg }
    343      1.1  mrg 
    344      1.1  mrg #endif /* !inhibit_libc */
    345      1.1  mrg 
    346      1.1  mrg #endif /* GCC_LIBGCOV_H */
    347