xref: /freebsd/sys/gnu/gcov/gcov.h (revision 3c4ba5f55438f7afd4f4b0b56f88f2bb505fd6a6)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2019, Matthew Macy <mmacy@freebsd.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  *
29  */
30 
31 #ifndef _SYS_GCOV_H_
32 #define _SYS_GCOV_H_
33 
34 MALLOC_DECLARE(M_GCOV);
35 
36 /*
37  * Profiling data types used for gcc 3.4 and above - these are defined by
38  * gcc and need to be kept as close to the original definition as possible to
39  * remain compatible.
40  */
41 #define GCOV_DATA_MAGIC		((unsigned int) 0x67636461)
42 #define GCOV_TAG_FUNCTION	((unsigned int) 0x01000000)
43 #define GCOV_TAG_COUNTER_BASE	((unsigned int) 0x01a10000)
44 #define GCOV_TAG_FOR_COUNTER(count)					\
45 	(GCOV_TAG_COUNTER_BASE + ((unsigned int) (count) << 17))
46 
47 typedef uint64_t gcov_type;
48 
49 /* Opaque gcov_info. The gcov structures can change as for example in gcc 4.7 so
50  * we cannot use full definition here and they need to be placed in gcc specific
51  * implementation of gcov. This also means no direct access to the members in
52  * generic code and usage of the interface below.*/
53 struct gcov_info;
54 
55 /* Interface to access gcov_info data  */
56 const char *gcov_info_filename(struct gcov_info *info);
57 unsigned int gcov_info_version(struct gcov_info *info);
58 struct gcov_info *gcov_info_next(struct gcov_info *info);
59 void gcov_info_link(struct gcov_info *info);
60 void gcov_info_unlink(struct gcov_info *prev, struct gcov_info *info);
61 
62 /* Base interface. */
63 enum gcov_action {
64 	GCOV_ADD,
65 	GCOV_REMOVE,
66 };
67 
68 /* Iterator control. */
69 struct gcov_iterator;
70 
71 struct gcov_iterator *gcov_iter_new(struct gcov_info *info);
72 void gcov_iter_free(struct gcov_iterator *iter);
73 void gcov_iter_start(struct gcov_iterator *iter);
74 int gcov_iter_next(struct gcov_iterator *iter);
75 int gcov_iter_write(struct gcov_iterator *iter, struct sbuf *sbuf);
76 struct gcov_info *gcov_iter_get_info(struct gcov_iterator *iter);
77 
78 /* gcov_info control. */
79 void gcov_info_reset(struct gcov_info *info);
80 int gcov_info_is_compatible(struct gcov_info *info1, struct gcov_info *info2);
81 void gcov_info_add(struct gcov_info *dest, struct gcov_info *source);
82 struct gcov_info *gcov_info_dup(struct gcov_info *info);
83 void gcov_info_free(struct gcov_info *info);
84 void gcov_stats_reset(void);
85 void gcov_enable_events(void);
86 void gcov_module_unload(void *, module_t);
87 void gcov_fs_init(void);
88 
89 int within_module(vm_offset_t addr, module_t mod);
90 
91 struct gcov_link {
92 	enum {
93 		OBJ_TREE,
94 		SRC_TREE,
95 	} dir;
96 	const char *ext;
97 };
98 extern const struct gcov_link gcov_link[];
99 #endif
100