Home | History | Annotate | Line # | Download | only in libgcc
libgcov.h revision 1.1.1.8
      1      1.1  mrg /* Header file for libgcov-*.c.
      2  1.1.1.8  mrg    Copyright (C) 1996-2020 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 
    106      1.1  mrg #else /* IN_GCOV_TOOL */
    107      1.1  mrg /* About the host.  */
    108      1.1  mrg /* This path will be compiled for the host and linked into
    109      1.1  mrg    gcov-tool binary.  */
    110      1.1  mrg 
    111      1.1  mrg #include "config.h"
    112      1.1  mrg #include "system.h"
    113      1.1  mrg #include "coretypes.h"
    114      1.1  mrg #include "tm.h"
    115      1.1  mrg 
    116      1.1  mrg typedef unsigned gcov_unsigned_t;
    117      1.1  mrg typedef unsigned gcov_position_t;
    118      1.1  mrg /* gcov_type is typedef'd elsewhere for the compiler */
    119      1.1  mrg #if defined (HOST_HAS_F_SETLKW)
    120      1.1  mrg #define GCOV_LOCKED 1
    121      1.1  mrg #else
    122      1.1  mrg #define GCOV_LOCKED 0
    123      1.1  mrg #endif
    124      1.1  mrg 
    125      1.1  mrg /* Some Macros specific to gcov-tool.  */
    126      1.1  mrg 
    127      1.1  mrg #define L_gcov 1
    128      1.1  mrg #define L_gcov_merge_add 1
    129  1.1.1.8  mrg #define L_gcov_merge_topn 1
    130      1.1  mrg #define L_gcov_merge_ior 1
    131      1.1  mrg #define L_gcov_merge_time_profile 1
    132      1.1  mrg 
    133      1.1  mrg extern gcov_type gcov_read_counter_mem ();
    134      1.1  mrg extern unsigned gcov_get_merge_weight ();
    135      1.1  mrg extern struct gcov_info *gcov_list;
    136      1.1  mrg 
    137      1.1  mrg #endif /* !IN_GCOV_TOOL */
    138      1.1  mrg 
    139      1.1  mrg #if defined(inhibit_libc)
    140      1.1  mrg #define IN_LIBGCOV (-1)
    141      1.1  mrg #else
    142      1.1  mrg #define IN_LIBGCOV 1
    143      1.1  mrg #if defined(L_gcov)
    144      1.1  mrg #define GCOV_LINKAGE /* nothing */
    145      1.1  mrg #endif
    146      1.1  mrg #endif
    147      1.1  mrg 
    148      1.1  mrg /* Poison these, so they don't accidentally slip in.  */
    149      1.1  mrg #pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length
    150  1.1.1.8  mrg #pragma GCC poison gcov_time
    151      1.1  mrg 
    152      1.1  mrg #ifdef HAVE_GAS_HIDDEN
    153      1.1  mrg #define ATTRIBUTE_HIDDEN  __attribute__ ((__visibility__ ("hidden")))
    154      1.1  mrg #else
    155      1.1  mrg #define ATTRIBUTE_HIDDEN
    156      1.1  mrg #endif
    157      1.1  mrg 
    158      1.1  mrg #include "gcov-io.h"
    159      1.1  mrg 
    160      1.1  mrg /* Structures embedded in coveraged program.  The structures generated
    161      1.1  mrg    by write_profile must match these.  */
    162      1.1  mrg 
    163      1.1  mrg /* Information about counters for a single function.  */
    164      1.1  mrg struct gcov_ctr_info
    165      1.1  mrg {
    166      1.1  mrg   gcov_unsigned_t num;		/* number of counters.  */
    167      1.1  mrg   gcov_type *values;		/* their values.  */
    168      1.1  mrg };
    169      1.1  mrg 
    170      1.1  mrg /* Information about a single function.  This uses the trailing array
    171      1.1  mrg    idiom. The number of counters is determined from the merge pointer
    172      1.1  mrg    array in gcov_info.  The key is used to detect which of a set of
    173      1.1  mrg    comdat functions was selected -- it points to the gcov_info object
    174      1.1  mrg    of the object file containing the selected comdat function.  */
    175      1.1  mrg 
    176      1.1  mrg struct gcov_fn_info
    177      1.1  mrg {
    178      1.1  mrg   const struct gcov_info *key;		/* comdat key */
    179      1.1  mrg   gcov_unsigned_t ident;		/* unique ident of function */
    180      1.1  mrg   gcov_unsigned_t lineno_checksum;	/* function lineo_checksum */
    181      1.1  mrg   gcov_unsigned_t cfg_checksum;		/* function cfg checksum */
    182      1.1  mrg   struct gcov_ctr_info ctrs[1];		/* instrumented counters */
    183      1.1  mrg };
    184      1.1  mrg 
    185      1.1  mrg /* Type of function used to merge counters.  */
    186      1.1  mrg typedef void (*gcov_merge_fn) (gcov_type *, gcov_unsigned_t);
    187      1.1  mrg 
    188      1.1  mrg /* Information about a single object file.  */
    189      1.1  mrg struct gcov_info
    190      1.1  mrg {
    191      1.1  mrg   gcov_unsigned_t version;	/* expected version number */
    192      1.1  mrg   struct gcov_info *next;	/* link to next, used by libgcov */
    193      1.1  mrg 
    194      1.1  mrg   gcov_unsigned_t stamp;	/* uniquifying time stamp */
    195      1.1  mrg   const char *filename;		/* output file name */
    196      1.1  mrg 
    197      1.1  mrg   gcov_merge_fn merge[GCOV_COUNTERS];  /* merge functions (null for
    198      1.1  mrg 					  unused) */
    199      1.1  mrg 
    200      1.1  mrg   unsigned n_functions;		/* number of functions */
    201      1.1  mrg 
    202      1.1  mrg #ifndef IN_GCOV_TOOL
    203      1.1  mrg   const struct gcov_fn_info *const *functions; /* pointer to pointers
    204      1.1  mrg                                                   to function information  */
    205      1.1  mrg #else
    206      1.1  mrg   const struct gcov_fn_info **functions;
    207      1.1  mrg #endif /* !IN_GCOV_TOOL */
    208      1.1  mrg };
    209      1.1  mrg 
    210      1.1  mrg /* Root of a program/shared-object state */
    211      1.1  mrg struct gcov_root
    212      1.1  mrg {
    213      1.1  mrg   struct gcov_info *list;
    214      1.1  mrg   unsigned dumped : 1;	/* counts have been dumped.  */
    215      1.1  mrg   unsigned run_counted : 1;  /* run has been accounted for.  */
    216      1.1  mrg   struct gcov_root *next;
    217      1.1  mrg   struct gcov_root *prev;
    218      1.1  mrg };
    219      1.1  mrg 
    220      1.1  mrg extern struct gcov_root __gcov_root ATTRIBUTE_HIDDEN;
    221      1.1  mrg 
    222      1.1  mrg struct gcov_master
    223      1.1  mrg {
    224      1.1  mrg   gcov_unsigned_t version;
    225      1.1  mrg   struct gcov_root *root;
    226      1.1  mrg };
    227  1.1.1.7  mrg 
    228  1.1.1.7  mrg struct indirect_call_tuple
    229  1.1.1.7  mrg {
    230  1.1.1.7  mrg   /* Callee function.  */
    231  1.1.1.7  mrg   void *callee;
    232  1.1.1.7  mrg 
    233  1.1.1.7  mrg   /* Pointer to counters.  */
    234  1.1.1.7  mrg   gcov_type *counters;
    235  1.1.1.7  mrg };
    236      1.1  mrg 
    237      1.1  mrg /* Exactly one of these will be active in the process.  */
    238      1.1  mrg extern struct gcov_master __gcov_master;
    239      1.1  mrg 
    240      1.1  mrg /* Dump a set of gcov objects.  */
    241      1.1  mrg extern void __gcov_dump_one (struct gcov_root *) ATTRIBUTE_HIDDEN;
    242      1.1  mrg 
    243      1.1  mrg /* Register a new object file module.  */
    244      1.1  mrg extern void __gcov_init (struct gcov_info *) ATTRIBUTE_HIDDEN;
    245      1.1  mrg 
    246  1.1.1.3  mrg /* GCOV exit function registered via a static destructor.  */
    247  1.1.1.3  mrg extern void __gcov_exit (void) ATTRIBUTE_HIDDEN;
    248      1.1  mrg 
    249      1.1  mrg /* Function to reset all counters to 0.  Both externally visible (and
    250      1.1  mrg    overridable) and internal version.  */
    251      1.1  mrg extern void __gcov_reset_int (void) ATTRIBUTE_HIDDEN;
    252      1.1  mrg 
    253      1.1  mrg /* User function to enable early write of profile information so far.  */
    254      1.1  mrg extern void __gcov_dump_int (void) ATTRIBUTE_HIDDEN;
    255      1.1  mrg 
    256      1.1  mrg /* The merge function that just sums the counters.  */
    257      1.1  mrg extern void __gcov_merge_add (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
    258      1.1  mrg 
    259      1.1  mrg /* The merge function to select the minimum valid counter value.  */
    260      1.1  mrg extern void __gcov_merge_time_profile (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
    261      1.1  mrg 
    262  1.1.1.8  mrg /* The merge function to choose the most common N values.  */
    263  1.1.1.8  mrg extern void __gcov_merge_topn (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
    264      1.1  mrg 
    265      1.1  mrg /* The merge function that just ors the counters together.  */
    266      1.1  mrg extern void __gcov_merge_ior (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
    267      1.1  mrg 
    268      1.1  mrg /* The profiler functions.  */
    269      1.1  mrg extern void __gcov_interval_profiler (gcov_type *, gcov_type, int, unsigned);
    270  1.1.1.3  mrg extern void __gcov_interval_profiler_atomic (gcov_type *, gcov_type, int,
    271  1.1.1.3  mrg 					     unsigned);
    272      1.1  mrg extern void __gcov_pow2_profiler (gcov_type *, gcov_type);
    273  1.1.1.3  mrg extern void __gcov_pow2_profiler_atomic (gcov_type *, gcov_type);
    274  1.1.1.8  mrg extern void __gcov_topn_values_profiler (gcov_type *, gcov_type);
    275  1.1.1.8  mrg extern void __gcov_topn_values_profiler_atomic (gcov_type *, gcov_type);
    276  1.1.1.8  mrg extern void __gcov_indirect_call_profiler_v4 (gcov_type, void *);
    277  1.1.1.8  mrg extern void __gcov_indirect_call_profiler_v4_atomic (gcov_type, void *);
    278      1.1  mrg extern void __gcov_time_profiler (gcov_type *);
    279  1.1.1.3  mrg extern void __gcov_time_profiler_atomic (gcov_type *);
    280      1.1  mrg extern void __gcov_average_profiler (gcov_type *, gcov_type);
    281  1.1.1.3  mrg extern void __gcov_average_profiler_atomic (gcov_type *, gcov_type);
    282      1.1  mrg extern void __gcov_ior_profiler (gcov_type *, gcov_type);
    283  1.1.1.3  mrg extern void __gcov_ior_profiler_atomic (gcov_type *, gcov_type);
    284      1.1  mrg 
    285      1.1  mrg #ifndef inhibit_libc
    286      1.1  mrg /* The wrappers around some library functions..  */
    287      1.1  mrg extern pid_t __gcov_fork (void) ATTRIBUTE_HIDDEN;
    288      1.1  mrg extern int __gcov_execl (const char *, char *, ...) ATTRIBUTE_HIDDEN;
    289      1.1  mrg extern int __gcov_execlp (const char *, char *, ...) ATTRIBUTE_HIDDEN;
    290      1.1  mrg extern int __gcov_execle (const char *, char *, ...) ATTRIBUTE_HIDDEN;
    291      1.1  mrg extern int __gcov_execv (const char *, char *const []) ATTRIBUTE_HIDDEN;
    292      1.1  mrg extern int __gcov_execvp (const char *, char *const []) ATTRIBUTE_HIDDEN;
    293      1.1  mrg extern int __gcov_execve (const char *, char  *const [], char *const [])
    294      1.1  mrg   ATTRIBUTE_HIDDEN;
    295      1.1  mrg 
    296      1.1  mrg /* Functions that only available in libgcov.  */
    297      1.1  mrg GCOV_LINKAGE int gcov_open (const char */*name*/) ATTRIBUTE_HIDDEN;
    298      1.1  mrg GCOV_LINKAGE void gcov_write_counter (gcov_type) ATTRIBUTE_HIDDEN;
    299      1.1  mrg GCOV_LINKAGE void gcov_write_tag_length (gcov_unsigned_t, gcov_unsigned_t)
    300      1.1  mrg     ATTRIBUTE_HIDDEN;
    301      1.1  mrg GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/,
    302      1.1  mrg                                       const struct gcov_summary *)
    303      1.1  mrg     ATTRIBUTE_HIDDEN;
    304      1.1  mrg GCOV_LINKAGE void gcov_seek (gcov_position_t /*position*/) ATTRIBUTE_HIDDEN;
    305      1.1  mrg GCOV_LINKAGE void gcov_rewrite (void) ATTRIBUTE_HIDDEN;
    306      1.1  mrg 
    307      1.1  mrg /* "Counts" stored in gcda files can be a real counter value, or
    308      1.1  mrg    an target address. When differentiate these two types because
    309      1.1  mrg    when manipulating counts, we should only change real counter values,
    310      1.1  mrg    rather target addresses.  */
    311      1.1  mrg 
    312      1.1  mrg static inline gcov_type
    313      1.1  mrg gcov_get_counter (void)
    314      1.1  mrg {
    315      1.1  mrg #ifndef IN_GCOV_TOOL
    316      1.1  mrg   /* This version is for reading count values in libgcov runtime:
    317      1.1  mrg      we read from gcda files.  */
    318      1.1  mrg 
    319      1.1  mrg   return gcov_read_counter ();
    320      1.1  mrg #else
    321      1.1  mrg   /* This version is for gcov-tool. We read the value from memory and
    322      1.1  mrg      multiply it by the merge weight.  */
    323      1.1  mrg 
    324      1.1  mrg   return gcov_read_counter_mem () * gcov_get_merge_weight ();
    325      1.1  mrg #endif
    326      1.1  mrg }
    327      1.1  mrg 
    328  1.1.1.8  mrg /* Similar function as gcov_get_counter(), but do not scale
    329  1.1.1.8  mrg    when read value is equal to IGNORE_SCALING.  */
    330  1.1.1.8  mrg 
    331  1.1.1.8  mrg static inline gcov_type
    332  1.1.1.8  mrg gcov_get_counter_ignore_scaling (gcov_type ignore_scaling ATTRIBUTE_UNUSED)
    333  1.1.1.8  mrg {
    334  1.1.1.8  mrg #ifndef IN_GCOV_TOOL
    335  1.1.1.8  mrg   /* This version is for reading count values in libgcov runtime:
    336  1.1.1.8  mrg      we read from gcda files.  */
    337  1.1.1.8  mrg 
    338  1.1.1.8  mrg   return gcov_read_counter ();
    339  1.1.1.8  mrg #else
    340  1.1.1.8  mrg   /* This version is for gcov-tool. We read the value from memory and
    341  1.1.1.8  mrg      multiply it by the merge weight.  */
    342  1.1.1.8  mrg 
    343  1.1.1.8  mrg   gcov_type v = gcov_read_counter_mem ();
    344  1.1.1.8  mrg   if (v != ignore_scaling)
    345  1.1.1.8  mrg     v *= gcov_get_merge_weight ();
    346  1.1.1.8  mrg 
    347  1.1.1.8  mrg   return v;
    348  1.1.1.8  mrg #endif
    349  1.1.1.8  mrg }
    350  1.1.1.8  mrg 
    351      1.1  mrg /* Similar function as gcov_get_counter(), but handles target address
    352      1.1  mrg    counters.  */
    353      1.1  mrg 
    354      1.1  mrg static inline gcov_type
    355      1.1  mrg gcov_get_counter_target (void)
    356      1.1  mrg {
    357      1.1  mrg #ifndef IN_GCOV_TOOL
    358      1.1  mrg   /* This version is for reading count target values in libgcov runtime:
    359      1.1  mrg      we read from gcda files.  */
    360      1.1  mrg 
    361      1.1  mrg   return gcov_read_counter ();
    362      1.1  mrg #else
    363      1.1  mrg   /* This version is for gcov-tool.  We read the value from memory and we do NOT
    364      1.1  mrg      multiply it by the merge weight.  */
    365      1.1  mrg 
    366      1.1  mrg   return gcov_read_counter_mem ();
    367      1.1  mrg #endif
    368      1.1  mrg }
    369      1.1  mrg 
    370      1.1  mrg #endif /* !inhibit_libc */
    371      1.1  mrg 
    372      1.1  mrg #endif /* GCC_LIBGCOV_H */
    373