]>
Commit | Line | Data |
---|---|---|
67745126 | 1 | /* Header file for libgcov-*.c. |
aad93da1 | 2 | Copyright (C) 1996-2017 Free Software Foundation, Inc. |
67745126 | 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 | ||
d2dc729f | 46 | #if __CHAR_BIT__ == 8 |
67745126 | 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))); | |
52 | #else | |
53 | typedef signed gcov_type __attribute__ ((mode (SI))); | |
54 | typedef unsigned gcov_type_unsigned __attribute__ ((mode (SI))); | |
55 | #endif | |
56 | #else | |
d2dc729f | 57 | #if __CHAR_BIT__ == 16 |
67745126 | 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))); | |
63 | #else | |
64 | typedef signed gcov_type __attribute__ ((mode (HI))); | |
65 | typedef unsigned gcov_type_unsigned __attribute__ ((mode (HI))); | |
66 | #endif | |
67 | #else | |
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))); | |
73 | #else | |
74 | typedef signed gcov_type __attribute__ ((mode (QI))); | |
75 | typedef 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 | ||
1186f97a | 86 | /* In libgcov we need these functions to be extern, so prefix them with |
87 | __gcov. In libgcov they must also be hidden so that the instance in | |
88 | the executable is not also used in a DSO. */ | |
89 | #define gcov_var __gcov_var | |
90 | #define gcov_open __gcov_open | |
91 | #define gcov_close __gcov_close | |
92 | #define gcov_write_tag_length __gcov_write_tag_length | |
93 | #define gcov_position __gcov_position | |
94 | #define gcov_seek __gcov_seek | |
95 | #define gcov_rewrite __gcov_rewrite | |
96 | #define gcov_is_error __gcov_is_error | |
97 | #define gcov_write_unsigned __gcov_write_unsigned | |
98 | #define gcov_write_counter __gcov_write_counter | |
99 | #define gcov_write_summary __gcov_write_summary | |
100 | #define gcov_read_unsigned __gcov_read_unsigned | |
101 | #define gcov_read_counter __gcov_read_counter | |
102 | #define gcov_read_summary __gcov_read_summary | |
8ceaa1ef | 103 | #define gcov_sort_n_vals __gcov_sort_n_vals |
1186f97a | 104 | |
e76f6040 | 105 | #else /* IN_GCOV_TOOL */ |
106 | /* About the host. */ | |
107 | /* This path will be compiled for the host and linked into | |
108 | gcov-tool binary. */ | |
109 | ||
110 | #include "config.h" | |
111 | #include "system.h" | |
112 | #include "coretypes.h" | |
113 | #include "tm.h" | |
114 | ||
115 | typedef unsigned gcov_unsigned_t; | |
116 | typedef unsigned gcov_position_t; | |
117 | /* gcov_type is typedef'd elsewhere for the compiler */ | |
118 | #if defined (HOST_HAS_F_SETLKW) | |
119 | #define GCOV_LOCKED 1 | |
120 | #else | |
121 | #define GCOV_LOCKED 0 | |
122 | #endif | |
123 | ||
124 | /* Some Macros specific to gcov-tool. */ | |
125 | ||
126 | #define L_gcov 1 | |
127 | #define L_gcov_merge_add 1 | |
128 | #define L_gcov_merge_single 1 | |
e76f6040 | 129 | #define L_gcov_merge_ior 1 |
130 | #define L_gcov_merge_time_profile 1 | |
8ceaa1ef | 131 | #define L_gcov_merge_icall_topn 1 |
e76f6040 | 132 | |
e76f6040 | 133 | extern gcov_type gcov_read_counter_mem (); |
134 | extern unsigned gcov_get_merge_weight (); | |
145d88ea | 135 | extern struct gcov_info *gcov_list; |
e76f6040 | 136 | |
137 | #endif /* !IN_GCOV_TOOL */ | |
138 | ||
67745126 | 139 | #if defined(inhibit_libc) |
140 | #define IN_LIBGCOV (-1) | |
141 | #else | |
142 | #define IN_LIBGCOV 1 | |
143 | #if defined(L_gcov) | |
144 | #define GCOV_LINKAGE /* nothing */ | |
145 | #endif | |
146 | #endif | |
147 | ||
67745126 | 148 | /* Poison these, so they don't accidentally slip in. */ |
149 | #pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length | |
150 | #pragma GCC poison gcov_time gcov_magic | |
151 | ||
152 | #ifdef HAVE_GAS_HIDDEN | |
153 | #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden"))) | |
154 | #else | |
155 | #define ATTRIBUTE_HIDDEN | |
156 | #endif | |
157 | ||
158 | #include "gcov-io.h" | |
159 | ||
160 | /* Structures embedded in coveraged program. The structures generated | |
161 | by write_profile must match these. */ | |
162 | ||
163 | /* Information about counters for a single function. */ | |
164 | struct gcov_ctr_info | |
165 | { | |
166 | gcov_unsigned_t num; /* number of counters. */ | |
167 | gcov_type *values; /* their values. */ | |
168 | }; | |
169 | ||
170 | /* Information about a single function. This uses the trailing array | |
171 | idiom. The number of counters is determined from the merge pointer | |
172 | array in gcov_info. The key is used to detect which of a set of | |
173 | comdat functions was selected -- it points to the gcov_info object | |
174 | of the object file containing the selected comdat function. */ | |
175 | ||
176 | struct gcov_fn_info | |
177 | { | |
178 | const struct gcov_info *key; /* comdat key */ | |
179 | gcov_unsigned_t ident; /* unique ident of function */ | |
180 | gcov_unsigned_t lineno_checksum; /* function lineo_checksum */ | |
181 | gcov_unsigned_t cfg_checksum; /* function cfg checksum */ | |
3dc22a01 | 182 | struct gcov_ctr_info ctrs[1]; /* instrumented counters */ |
67745126 | 183 | }; |
184 | ||
185 | /* Type of function used to merge counters. */ | |
186 | typedef void (*gcov_merge_fn) (gcov_type *, gcov_unsigned_t); | |
187 | ||
188 | /* Information about a single object file. */ | |
189 | struct gcov_info | |
190 | { | |
191 | gcov_unsigned_t version; /* expected version number */ | |
192 | struct gcov_info *next; /* link to next, used by libgcov */ | |
193 | ||
194 | gcov_unsigned_t stamp; /* uniquifying time stamp */ | |
195 | const char *filename; /* output file name */ | |
196 | ||
197 | gcov_merge_fn merge[GCOV_COUNTERS]; /* merge functions (null for | |
198 | unused) */ | |
199 | ||
200 | unsigned n_functions; /* number of functions */ | |
e76f6040 | 201 | |
202 | #ifndef IN_GCOV_TOOL | |
67745126 | 203 | const struct gcov_fn_info *const *functions; /* pointer to pointers |
e76f6040 | 204 | to function information */ |
205 | #else | |
206 | const struct gcov_fn_info **functions; | |
207 | #endif /* !IN_GCOV_TOOL */ | |
67745126 | 208 | }; |
209 | ||
859fa1a9 | 210 | /* Root of a program/shared-object state */ |
211 | struct gcov_root | |
212 | { | |
213 | struct gcov_info *list; | |
214 | unsigned dumped : 1; /* counts have been dumped. */ | |
215 | unsigned run_counted : 1; /* run has been accounted for. */ | |
bc587267 | 216 | struct gcov_root *next; |
217 | struct gcov_root *prev; | |
859fa1a9 | 218 | }; |
219 | ||
220 | extern struct gcov_root __gcov_root ATTRIBUTE_HIDDEN; | |
221 | ||
bc587267 | 222 | struct gcov_master |
223 | { | |
224 | gcov_unsigned_t version; | |
225 | struct gcov_root *root; | |
226 | }; | |
227 | ||
228 | /* Exactly one of these will be active in the process. */ | |
229 | extern struct gcov_master __gcov_master; | |
230 | ||
859fa1a9 | 231 | /* Dump a set of gcov objects. */ |
232 | extern void __gcov_dump_one (struct gcov_root *) ATTRIBUTE_HIDDEN; | |
233 | ||
67745126 | 234 | /* Register a new object file module. */ |
235 | extern void __gcov_init (struct gcov_info *) ATTRIBUTE_HIDDEN; | |
236 | ||
db46bcd3 | 237 | /* GCOV exit function registered via a static destructor. */ |
238 | extern void __gcov_exit (void) ATTRIBUTE_HIDDEN; | |
239 | ||
67745126 | 240 | /* Called before fork, to avoid double counting. */ |
241 | extern void __gcov_flush (void) ATTRIBUTE_HIDDEN; | |
242 | ||
b12d2330 | 243 | /* Function to reset all counters to 0. Both externally visible (and |
244 | overridable) and internal version. */ | |
67745126 | 245 | extern void __gcov_reset (void); |
b12d2330 | 246 | extern void __gcov_reset_int (void) ATTRIBUTE_HIDDEN; |
67745126 | 247 | |
bc587267 | 248 | /* User function to enable early write of profile information so far. */ |
67745126 | 249 | extern void __gcov_dump (void); |
bc587267 | 250 | extern void __gcov_dump_int (void) ATTRIBUTE_HIDDEN; |
67745126 | 251 | |
252 | /* The merge function that just sums the counters. */ | |
253 | extern void __gcov_merge_add (gcov_type *, unsigned) ATTRIBUTE_HIDDEN; | |
254 | ||
255 | /* The merge function to select the minimum valid counter value. */ | |
256 | extern void __gcov_merge_time_profile (gcov_type *, unsigned) ATTRIBUTE_HIDDEN; | |
257 | ||
258 | /* The merge function to choose the most common value. */ | |
259 | extern void __gcov_merge_single (gcov_type *, unsigned) ATTRIBUTE_HIDDEN; | |
260 | ||
67745126 | 261 | /* The merge function that just ors the counters together. */ |
262 | extern void __gcov_merge_ior (gcov_type *, unsigned) ATTRIBUTE_HIDDEN; | |
263 | ||
8ceaa1ef | 264 | /* The merge function is used for topn indirect call counters. */ |
265 | extern void __gcov_merge_icall_topn (gcov_type *, unsigned) ATTRIBUTE_HIDDEN; | |
266 | ||
67745126 | 267 | /* The profiler functions. */ |
268 | extern void __gcov_interval_profiler (gcov_type *, gcov_type, int, unsigned); | |
2d2b4107 | 269 | extern void __gcov_interval_profiler_atomic (gcov_type *, gcov_type, int, |
270 | unsigned); | |
67745126 | 271 | extern void __gcov_pow2_profiler (gcov_type *, gcov_type); |
2d2b4107 | 272 | extern void __gcov_pow2_profiler_atomic (gcov_type *, gcov_type); |
67745126 | 273 | extern void __gcov_one_value_profiler (gcov_type *, gcov_type); |
2d2b4107 | 274 | extern void __gcov_one_value_profiler_atomic (gcov_type *, gcov_type); |
67745126 | 275 | extern void __gcov_indirect_call_profiler_v2 (gcov_type, void *); |
276 | extern void __gcov_time_profiler (gcov_type *); | |
2d2b4107 | 277 | extern void __gcov_time_profiler_atomic (gcov_type *); |
67745126 | 278 | extern void __gcov_average_profiler (gcov_type *, gcov_type); |
2d2b4107 | 279 | extern void __gcov_average_profiler_atomic (gcov_type *, gcov_type); |
67745126 | 280 | extern void __gcov_ior_profiler (gcov_type *, gcov_type); |
2d2b4107 | 281 | extern void __gcov_ior_profiler_atomic (gcov_type *, gcov_type); |
8ceaa1ef | 282 | extern void __gcov_indirect_call_topn_profiler (gcov_type, void *); |
283 | extern void gcov_sort_n_vals (gcov_type *, int); | |
67745126 | 284 | |
285 | #ifndef inhibit_libc | |
286 | /* The wrappers around some library functions.. */ | |
287 | extern pid_t __gcov_fork (void) ATTRIBUTE_HIDDEN; | |
288 | extern int __gcov_execl (const char *, char *, ...) ATTRIBUTE_HIDDEN; | |
289 | extern int __gcov_execlp (const char *, char *, ...) ATTRIBUTE_HIDDEN; | |
290 | extern int __gcov_execle (const char *, char *, ...) ATTRIBUTE_HIDDEN; | |
291 | extern int __gcov_execv (const char *, char *const []) ATTRIBUTE_HIDDEN; | |
292 | extern int __gcov_execvp (const char *, char *const []) ATTRIBUTE_HIDDEN; | |
293 | extern int __gcov_execve (const char *, char *const [], char *const []) | |
294 | ATTRIBUTE_HIDDEN; | |
295 | ||
296 | /* Functions that only available in libgcov. */ | |
297 | GCOV_LINKAGE int gcov_open (const char */*name*/) ATTRIBUTE_HIDDEN; | |
298 | GCOV_LINKAGE void gcov_write_counter (gcov_type) ATTRIBUTE_HIDDEN; | |
299 | GCOV_LINKAGE void gcov_write_tag_length (gcov_unsigned_t, gcov_unsigned_t) | |
300 | ATTRIBUTE_HIDDEN; | |
301 | GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/, | |
302 | const struct gcov_summary *) | |
303 | ATTRIBUTE_HIDDEN; | |
304 | GCOV_LINKAGE void gcov_seek (gcov_position_t /*position*/) ATTRIBUTE_HIDDEN; | |
1186f97a | 305 | GCOV_LINKAGE void gcov_rewrite (void) ATTRIBUTE_HIDDEN; |
67745126 | 306 | |
e76f6040 | 307 | /* "Counts" stored in gcda files can be a real counter value, or |
308 | an target address. When differentiate these two types because | |
309 | when manipulating counts, we should only change real counter values, | |
310 | rather target addresses. */ | |
311 | ||
312 | static inline gcov_type | |
313 | gcov_get_counter (void) | |
314 | { | |
315 | #ifndef IN_GCOV_TOOL | |
316 | /* This version is for reading count values in libgcov runtime: | |
317 | we read from gcda files. */ | |
318 | ||
319 | return gcov_read_counter (); | |
320 | #else | |
321 | /* This version is for gcov-tool. We read the value from memory and | |
322 | multiply it by the merge weight. */ | |
323 | ||
324 | return gcov_read_counter_mem () * gcov_get_merge_weight (); | |
325 | #endif | |
326 | } | |
327 | ||
328 | /* Similar function as gcov_get_counter(), but handles target address | |
329 | counters. */ | |
330 | ||
331 | static inline gcov_type | |
332 | gcov_get_counter_target (void) | |
333 | { | |
334 | #ifndef IN_GCOV_TOOL | |
335 | /* This version is for reading count target values in libgcov runtime: | |
336 | we read from gcda files. */ | |
337 | ||
338 | return gcov_read_counter (); | |
339 | #else | |
340 | /* This version is for gcov-tool. We read the value from memory and we do NOT | |
341 | multiply it by the merge weight. */ | |
342 | ||
343 | return gcov_read_counter_mem (); | |
344 | #endif | |
345 | } | |
346 | ||
67745126 | 347 | #endif /* !inhibit_libc */ |
348 | ||
349 | #endif /* GCC_LIBGCOV_H */ |