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