1 /* Routines required for instrumenting a program. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989-2014 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
29 #if defined(inhibit_libc)
32 void __gcov_flush (void) {}
36 void __gcov_reset (void) {}
40 void __gcov_dump (void) {}
45 extern void gcov_clear (void) ATTRIBUTE_HIDDEN
;
46 extern void gcov_exit (void) ATTRIBUTE_HIDDEN
;
47 extern __gthread_mutex_t __gcov_flush_mx ATTRIBUTE_HIDDEN
;
50 #ifdef __GTHREAD_MUTEX_INIT
51 __gthread_mutex_t __gcov_flush_mx
= __GTHREAD_MUTEX_INIT
;
52 #define init_mx_once()
54 __gthread_mutex_t __gcov_flush_mx
;
59 __GTHREAD_MUTEX_INIT_FUNCTION (&__gcov_flush_mx
);
65 static __gthread_once_t once
= __GTHREAD_ONCE_INIT
;
66 __gthread_once (&once
, init_mx
);
70 /* Called before fork or exec - write out profile information gathered so
71 far and reset it to zero. This avoids duplication or loss of the
72 profile information gathered so far. */
78 __gthread_mutex_lock (&__gcov_flush_mx
);
83 __gthread_mutex_unlock (&__gcov_flush_mx
);
86 #endif /* L_gcov_flush */
90 /* Function that can be called from application to reset counters to zero,
91 in order to collect profile in region of interest. */
99 #endif /* L_gcov_reset */
103 /* Function that can be called from application to write profile collected
104 so far, in order to collect profile in region of interest. */
112 #endif /* L_gcov_dump */
114 #ifdef L_gcov_sampling
116 /* Emitted in coverage.c. */
118 /* Sampling period. */
119 extern gcov_unsigned_t __gcov_sampling_period
;
120 extern gcov_unsigned_t __gcov_has_sampling
;
121 void __gcov_set_sampling_period (unsigned int period
);
122 unsigned int __gcov_sampling_enabled ();
123 /* Per thread sample counter. */
124 __thread gcov_unsigned_t __gcov_sample_counter
= 0;
126 /* Set sampling period to PERIOD. */
128 void __gcov_set_sampling_period (unsigned int period
)
130 gcc_assert (__gcov_has_sampling
);
131 __gcov_sampling_period
= period
;
134 unsigned int __gcov_sampling_enabled ()
136 return __gcov_has_sampling
;
143 /* Profile directory prefix specified to -fprofile-generate=. */
144 extern char * __gcov_profile_prefix
;
146 char *__gcov_get_profile_prefix ()
148 return __gcov_profile_prefix
;
155 /* A wrapper for the fork function. Flushes the accumulated profiling data, so
156 that they are not counted twice. */
162 extern __gthread_mutex_t __gcov_flush_mx
;
166 __GTHREAD_MUTEX_INIT_FUNCTION (&__gcov_flush_mx
);
172 /* A wrapper for the execl function. Flushes the accumulated profiling data, so
173 that they are not lost. */
176 __gcov_execl (const char *path
, char *arg
, ...)
188 while (va_arg (ap
, char *))
192 args
= (char **) alloca (length
* sizeof (void *));
194 for (i
= 1; i
< length
; i
++)
195 args
[i
] = va_arg (aq
, char *);
198 return execv (path
, args
);
203 /* A wrapper for the execlp function. Flushes the accumulated
204 profiling data, so that they are not lost. */
207 __gcov_execlp (const char *path
, char *arg
, ...)
219 while (va_arg (ap
, char *))
223 args
= (char **) alloca (length
* sizeof (void *));
225 for (i
= 1; i
< length
; i
++)
226 args
[i
] = va_arg (aq
, char *);
229 return execvp (path
, args
);
234 /* A wrapper for the execle function. Flushes the accumulated
235 profiling data, so that they are not lost. */
238 __gcov_execle (const char *path
, char *arg
, ...)
251 while (va_arg (ap
, char *))
255 args
= (char **) alloca (length
* sizeof (void *));
257 for (i
= 1; i
< length
; i
++)
258 args
[i
] = va_arg (aq
, char *);
259 envp
= va_arg (aq
, char **);
262 return execve (path
, args
, envp
);
267 /* A wrapper for the execv function. Flushes the accumulated
268 profiling data, so that they are not lost. */
271 __gcov_execv (const char *path
, char *const argv
[])
274 return execv (path
, argv
);
279 /* A wrapper for the execvp function. Flushes the accumulated
280 profiling data, so that they are not lost. */
283 __gcov_execvp (const char *path
, char *const argv
[])
286 return execvp (path
, argv
);
291 /* A wrapper for the execve function. Flushes the accumulated
292 profiling data, so that they are not lost. */
295 __gcov_execve (const char *path
, char *const argv
[], char *const envp
[])
298 return execve (path
, argv
, envp
);
301 #endif /* inhibit_libc */