1 /* Routines required for instrumenting a program. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989-2013 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/>. */
28 #include "coretypes.h"
30 #include "libgcc_tm.h"
33 #if defined(inhibit_libc)
34 #define IN_LIBGCOV (-1)
40 #if defined(inhibit_libc)
43 void __gcov_flush (void) {}
47 void __gcov_reset (void) {}
51 void __gcov_dump (void) {}
56 extern void gcov_clear (void) ATTRIBUTE_HIDDEN
;
57 extern void gcov_exit (void) ATTRIBUTE_HIDDEN
;
58 extern void set_gcov_dump_complete (void) ATTRIBUTE_HIDDEN
;
59 extern void reset_gcov_dump_complete (void) ATTRIBUTE_HIDDEN
;
63 #ifdef __GTHREAD_MUTEX_INIT
64 ATTRIBUTE_HIDDEN __gthread_mutex_t __gcov_flush_mx
= __GTHREAD_MUTEX_INIT
;
65 #define init_mx_once()
67 __gthread_mutex_t __gcov_flush_mx ATTRIBUTE_HIDDEN
;
72 __GTHREAD_MUTEX_INIT_FUNCTION (&__gcov_flush_mx
);
77 static __gthread_once_t once
= __GTHREAD_ONCE_INIT
;
78 __gthread_once (&once
, init_mx
);
82 /* Called before fork or exec - write out profile information gathered so
83 far and reset it to zero. This avoids duplication or loss of the
84 profile information gathered so far. */
90 __gthread_mutex_lock (&__gcov_flush_mx
);
95 __gthread_mutex_unlock (&__gcov_flush_mx
);
98 #endif /* L_gcov_flush */
102 /* Function that can be called from application to reset counters to zero,
103 in order to collect profile in region of interest. */
109 /* Re-enable dumping to support collecting profile in multiple regions
111 reset_gcov_dump_complete ();
114 #endif /* L_gcov_reset */
118 /* Function that can be called from application to write profile collected
119 so far, in order to collect profile in region of interest. */
125 /* Prevent profile from being dumped a second time on application exit. */
126 set_gcov_dump_complete ();
129 #endif /* L_gcov_dump */
133 /* A wrapper for the fork function. Flushes the accumulated profiling data, so
134 that they are not counted twice. */
140 extern __gthread_mutex_t __gcov_flush_mx
;
144 __GTHREAD_MUTEX_INIT_FUNCTION (&__gcov_flush_mx
);
150 /* A wrapper for the execl function. Flushes the accumulated profiling data, so
151 that they are not lost. */
154 __gcov_execl (const char *path
, char *arg
, ...)
166 while (va_arg (ap
, char *))
170 args
= (char **) alloca (length
* sizeof (void *));
172 for (i
= 1; i
< length
; i
++)
173 args
[i
] = va_arg (aq
, char *);
176 return execv (path
, args
);
181 /* A wrapper for the execlp function. Flushes the accumulated profiling data, so
182 that they are not lost. */
185 __gcov_execlp (const char *path
, char *arg
, ...)
197 while (va_arg (ap
, char *))
201 args
= (char **) alloca (length
* sizeof (void *));
203 for (i
= 1; i
< length
; i
++)
204 args
[i
] = va_arg (aq
, char *);
207 return execvp (path
, args
);
212 /* A wrapper for the execle function. Flushes the accumulated profiling data, so
213 that they are not lost. */
216 __gcov_execle (const char *path
, char *arg
, ...)
229 while (va_arg (ap
, char *))
233 args
= (char **) alloca (length
* sizeof (void *));
235 for (i
= 1; i
< length
; i
++)
236 args
[i
] = va_arg (aq
, char *);
237 envp
= va_arg (aq
, char **);
240 return execve (path
, args
, envp
);
245 /* A wrapper for the execv function. Flushes the accumulated profiling data, so
246 that they are not lost. */
249 __gcov_execv (const char *path
, char *const argv
[])
252 return execv (path
, argv
);
257 /* A wrapper for the execvp function. Flushes the accumulated profiling data, so
258 that they are not lost. */
261 __gcov_execvp (const char *path
, char *const argv
[])
264 return execvp (path
, argv
);
269 /* A wrapper for the execve function. Flushes the accumulated profiling data, so
270 that they are not lost. */
273 __gcov_execve (const char *path
, char *const argv
[], char *const envp
[])
276 return execve (path
, argv
, envp
);
279 #endif /* inhibit_libc */