xref: /freebsd/sys/gnu/gcov/gcov.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
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  */
28 
29 #ifndef _SYS_GCOV_H_
30 #define _SYS_GCOV_H_
31 
32 MALLOC_DECLARE(M_GCOV);
33 
34 /*
35  * Profiling data types used for gcc 3.4 and above - these are defined by
36  * gcc and need to be kept as close to the original definition as possible to
37  * remain compatible.
38  */
39 #define GCOV_DATA_MAGIC		((unsigned int) 0x67636461)
40 #define GCOV_TAG_FUNCTION	((unsigned int) 0x01000000)
41 #define GCOV_TAG_COUNTER_BASE	((unsigned int) 0x01a10000)
42 #define GCOV_TAG_FOR_COUNTER(count)					\
43 	(GCOV_TAG_COUNTER_BASE + ((unsigned int) (count) << 17))
44 
45 typedef uint64_t gcov_type;
46 
47 /* Opaque gcov_info. The gcov structures can change as for example in gcc 4.7 so
48  * we cannot use full definition here and they need to be placed in gcc specific
49  * implementation of gcov. This also means no direct access to the members in
50  * generic code and usage of the interface below.*/
51 struct gcov_info;
52 
53 /* Interface to access gcov_info data  */
54 const char *gcov_info_filename(struct gcov_info *info);
55 unsigned int gcov_info_version(struct gcov_info *info);
56 struct gcov_info *gcov_info_next(struct gcov_info *info);
57 void gcov_info_link(struct gcov_info *info);
58 void gcov_info_unlink(struct gcov_info *prev, struct gcov_info *info);
59 
60 /* Base interface. */
61 enum gcov_action {
62 	GCOV_ADD,
63 	GCOV_REMOVE,
64 };
65 
66 /* Iterator control. */
67 struct gcov_iterator;
68 
69 struct gcov_iterator *gcov_iter_new(struct gcov_info *info);
70 void gcov_iter_free(struct gcov_iterator *iter);
71 void gcov_iter_start(struct gcov_iterator *iter);
72 int gcov_iter_next(struct gcov_iterator *iter);
73 int gcov_iter_write(struct gcov_iterator *iter, struct sbuf *sbuf);
74 struct gcov_info *gcov_iter_get_info(struct gcov_iterator *iter);
75 
76 /* gcov_info control. */
77 void gcov_info_reset(struct gcov_info *info);
78 int gcov_info_is_compatible(struct gcov_info *info1, struct gcov_info *info2);
79 void gcov_info_add(struct gcov_info *dest, struct gcov_info *source);
80 struct gcov_info *gcov_info_dup(struct gcov_info *info);
81 void gcov_info_free(struct gcov_info *info);
82 void gcov_stats_reset(void);
83 void gcov_enable_events(void);
84 void gcov_module_unload(void *, module_t);
85 void gcov_fs_init(void);
86 
87 int within_module(vm_offset_t addr, module_t mod);
88 
89 struct gcov_link {
90 	enum {
91 		OBJ_TREE,
92 		SRC_TREE,
93 	} dir;
94 	const char *ext;
95 };
96 extern const struct gcov_link gcov_link[];
97 #endif
98