1 /* Header file for libgcov-*.c.
2 Copyright (C) 1996-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
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
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
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.
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/>. */
28 /* work around the poisoned malloc/calloc in system.h. */
30 #define xmalloc malloc
33 #define xcalloc calloc
37 /* About the target. */
38 /* This path will be used by libgcov runtime. */
42 #include "coretypes.h"
44 #include "libgcc_tm.h"
46 #if BITS_PER_UNIT == 8
47 typedef unsigned gcov_unsigned_t
__attribute__ ((mode (SI
)));
48 typedef unsigned gcov_position_t
__attribute__ ((mode (SI
)));
49 #if LONG_LONG_TYPE_SIZE > 32
50 typedef signed gcov_type
__attribute__ ((mode (DI
)));
51 typedef unsigned gcov_type_unsigned
__attribute__ ((mode (DI
)));
53 typedef signed gcov_type
__attribute__ ((mode (SI
)));
54 typedef unsigned gcov_type_unsigned
__attribute__ ((mode (SI
)));
57 #if BITS_PER_UNIT == 16
58 typedef unsigned gcov_unsigned_t
__attribute__ ((mode (HI
)));
59 typedef unsigned gcov_position_t
__attribute__ ((mode (HI
)));
60 #if LONG_LONG_TYPE_SIZE > 32
61 typedef signed gcov_type
__attribute__ ((mode (SI
)));
62 typedef unsigned gcov_type_unsigned
__attribute__ ((mode (SI
)));
64 typedef signed gcov_type
__attribute__ ((mode (HI
)));
65 typedef unsigned gcov_type_unsigned
__attribute__ ((mode (HI
)));
68 typedef unsigned gcov_unsigned_t
__attribute__ ((mode (QI
)));
69 typedef unsigned gcov_position_t
__attribute__ ((mode (QI
)));
70 #if LONG_LONG_TYPE_SIZE > 32
71 typedef signed gcov_type
__attribute__ ((mode (HI
)));
72 typedef unsigned gcov_type_unsigned
__attribute__ ((mode (HI
)));
74 typedef signed gcov_type
__attribute__ ((mode (QI
)));
75 typedef unsigned gcov_type_unsigned
__attribute__ ((mode (QI
)));
80 #if defined (TARGET_POSIX_IO)
86 #else /* IN_GCOV_TOOL */
88 /* This path will be compiled for the host and linked into
93 #include "coretypes.h"
96 typedef unsigned gcov_unsigned_t
;
97 typedef 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
102 #define GCOV_LOCKED 0
105 /* Some Macros specific to gcov-tool. */
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
114 extern gcov_type
gcov_read_counter_mem ();
115 extern unsigned gcov_get_merge_weight ();
116 extern struct gcov_info
*gcov_list
;
118 #endif /* !IN_GCOV_TOOL */
120 #if defined(inhibit_libc)
121 #define IN_LIBGCOV (-1)
125 #define GCOV_LINKAGE /* nothing */
129 /* In libgcov we need these functions to be extern, so prefix them with
130 __gcov. In libgcov they must also be hidden so that the instance in
131 the executable is not also used in a DSO. */
132 #define gcov_var __gcov_var
133 #define gcov_open __gcov_open
134 #define gcov_close __gcov_close
135 #define gcov_write_tag_length __gcov_write_tag_length
136 #define gcov_position __gcov_position
137 #define gcov_seek __gcov_seek
138 #define gcov_rewrite __gcov_rewrite
139 #define gcov_is_error __gcov_is_error
140 #define gcov_write_unsigned __gcov_write_unsigned
141 #define gcov_write_counter __gcov_write_counter
142 #define gcov_write_summary __gcov_write_summary
143 #define gcov_read_unsigned __gcov_read_unsigned
144 #define gcov_read_counter __gcov_read_counter
145 #define gcov_read_summary __gcov_read_summary
147 /* Poison these, so they don't accidentally slip in. */
148 #pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length
149 #pragma GCC poison gcov_time gcov_magic
151 #ifdef HAVE_GAS_HIDDEN
152 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
154 #define ATTRIBUTE_HIDDEN
159 /* Structures embedded in coveraged program. The structures generated
160 by write_profile must match these. */
162 /* Information about counters for a single function. */
165 gcov_unsigned_t num
; /* number of counters. */
166 gcov_type
*values
; /* their values. */
169 /* Information about a single function. This uses the trailing array
170 idiom. The number of counters is determined from the merge pointer
171 array in gcov_info. The key is used to detect which of a set of
172 comdat functions was selected -- it points to the gcov_info object
173 of the object file containing the selected comdat function. */
177 const struct gcov_info
*key
; /* comdat key */
178 gcov_unsigned_t ident
; /* unique ident of function */
179 gcov_unsigned_t lineno_checksum
; /* function lineo_checksum */
180 gcov_unsigned_t cfg_checksum
; /* function cfg checksum */
181 struct gcov_ctr_info ctrs
[1]; /* instrumented counters */
184 /* Type of function used to merge counters. */
185 typedef void (*gcov_merge_fn
) (gcov_type
*, gcov_unsigned_t
);
187 /* Information about a single object file. */
190 gcov_unsigned_t version
; /* expected version number */
191 struct gcov_info
*next
; /* link to next, used by libgcov */
193 gcov_unsigned_t stamp
; /* uniquifying time stamp */
194 const char *filename
; /* output file name */
196 gcov_merge_fn merge
[GCOV_COUNTERS
]; /* merge functions (null for
199 unsigned n_functions
; /* number of functions */
202 const struct gcov_fn_info
*const *functions
; /* pointer to pointers
203 to function information */
205 const struct gcov_fn_info
**functions
;
206 #endif /* !IN_GCOV_TOOL */
209 /* Register a new object file module. */
210 extern void __gcov_init (struct gcov_info
*) ATTRIBUTE_HIDDEN
;
212 /* Called before fork, to avoid double counting. */
213 extern void __gcov_flush (void) ATTRIBUTE_HIDDEN
;
215 /* Function to reset all counters to 0. */
216 extern void __gcov_reset (void);
218 /* Function to enable early write of profile information so far. */
219 extern void __gcov_dump (void);
221 /* The merge function that just sums the counters. */
222 extern void __gcov_merge_add (gcov_type
*, unsigned) ATTRIBUTE_HIDDEN
;
224 /* The merge function to select the minimum valid counter value. */
225 extern void __gcov_merge_time_profile (gcov_type
*, unsigned) ATTRIBUTE_HIDDEN
;
227 /* The merge function to choose the most common value. */
228 extern void __gcov_merge_single (gcov_type
*, unsigned) ATTRIBUTE_HIDDEN
;
230 /* The merge function to choose the most common difference between
231 consecutive values. */
232 extern void __gcov_merge_delta (gcov_type
*, unsigned) ATTRIBUTE_HIDDEN
;
234 /* The merge function that just ors the counters together. */
235 extern void __gcov_merge_ior (gcov_type
*, unsigned) ATTRIBUTE_HIDDEN
;
237 /* The profiler functions. */
238 extern void __gcov_interval_profiler (gcov_type
*, gcov_type
, int, unsigned);
239 extern void __gcov_pow2_profiler (gcov_type
*, gcov_type
);
240 extern void __gcov_one_value_profiler (gcov_type
*, gcov_type
);
241 extern void __gcov_indirect_call_profiler (gcov_type
*, gcov_type
,
243 extern void __gcov_indirect_call_profiler_v2 (gcov_type
, void *);
244 extern void __gcov_time_profiler (gcov_type
*);
245 extern void __gcov_average_profiler (gcov_type
*, gcov_type
);
246 extern void __gcov_ior_profiler (gcov_type
*, gcov_type
);
249 /* The wrappers around some library functions.. */
250 extern pid_t
__gcov_fork (void) ATTRIBUTE_HIDDEN
;
251 extern int __gcov_execl (const char *, char *, ...) ATTRIBUTE_HIDDEN
;
252 extern int __gcov_execlp (const char *, char *, ...) ATTRIBUTE_HIDDEN
;
253 extern int __gcov_execle (const char *, char *, ...) ATTRIBUTE_HIDDEN
;
254 extern int __gcov_execv (const char *, char *const []) ATTRIBUTE_HIDDEN
;
255 extern int __gcov_execvp (const char *, char *const []) ATTRIBUTE_HIDDEN
;
256 extern int __gcov_execve (const char *, char *const [], char *const [])
259 /* Functions that only available in libgcov. */
260 GCOV_LINKAGE
int gcov_open (const char */
*name*/
) ATTRIBUTE_HIDDEN
;
261 GCOV_LINKAGE
void gcov_write_counter (gcov_type
) ATTRIBUTE_HIDDEN
;
262 GCOV_LINKAGE
void gcov_write_tag_length (gcov_unsigned_t
, gcov_unsigned_t
)
264 GCOV_LINKAGE
void gcov_write_summary (gcov_unsigned_t
/*tag*/,
265 const struct gcov_summary
*)
267 GCOV_LINKAGE
void gcov_seek (gcov_position_t
/*position*/) ATTRIBUTE_HIDDEN
;
268 GCOV_LINKAGE
inline void gcov_rewrite (void);
270 /* "Counts" stored in gcda files can be a real counter value, or
271 an target address. When differentiate these two types because
272 when manipulating counts, we should only change real counter values,
273 rather target addresses. */
275 static inline gcov_type
276 gcov_get_counter (void)
279 /* This version is for reading count values in libgcov runtime:
280 we read from gcda files. */
282 return gcov_read_counter ();
284 /* This version is for gcov-tool. We read the value from memory and
285 multiply it by the merge weight. */
287 return gcov_read_counter_mem () * gcov_get_merge_weight ();
291 /* Similar function as gcov_get_counter(), but handles target address
294 static inline gcov_type
295 gcov_get_counter_target (void)
298 /* This version is for reading count target values in libgcov runtime:
299 we read from gcda files. */
301 return gcov_read_counter ();
303 /* This version is for gcov-tool. We read the value from memory and we do NOT
304 multiply it by the merge weight. */
306 return gcov_read_counter_mem ();
310 #endif /* !inhibit_libc */
312 #endif /* GCC_LIBGCOV_H */