1 /* Copyright (C) 1996-2018 Free Software Foundation, Inc.
2 
3    This file is part of GCC.
4 
5    GCC is free software; you can redistribute it and/or modify it under
6    the terms of the GNU General Public License as published by the Free
7    Software Foundation; either version 3, or (at your option) any later
8    version.
9 
10    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11    WARRANTY; without even the implied warranty of MERCHANTABILITY or
12    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13    for more details.
14 
15    Under Section 7 of GPL version 3, you are granted additional
16    permissions described in the GCC Runtime Library Exception, version
17    3.1, as published by the Free Software Foundation.
18 
19    You should have received a copy of the GNU General Public License and
20    a copy of the GCC Runtime Library Exception along with this program;
21    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
22    <http://www.gnu.org/licenses/>.  */
23 
24 /**
25  * This file has excerpts from gcc libgcc/libgcov.h and gcc/gcov-io.h.
26  * Which is governed by section 7 of additional permissions.
27  */
28 
29 
30 #ifndef _COVERAGE_H_
31 #define _COVERAGE_H_
32 
33 #if (__GNUC__ >= 10)
34 #define GCOV_COUNTERS 8U
35 #elif (__GNUC__ >= 8)
36 #define GCOV_COUNTERS 9U
37 #else
38 #define GCOV_COUNTERS 10U
39 #endif
40 
41 /* The GCOV 12 gcno/gcda format has slight change,
42  * Please refer to gcov-io.h in the GCC 12 for
43  * more details.
44  *
45  * Following GCC commits introduced these changes:
46  * gcc-mirror/gcc@23eb66d
47  * gcc-mirror/gcc@72e0c74
48  */
49 #if (__GNUC__ >= 12)
50 #define GCOV_12_FORMAT
51 #endif
52 
53 typedef uint64_t gcov_type;
54 
55 #ifdef GCOV_12_FORMAT
56 #define GCOV_TAG_FUNCTION_LENGTH  12
57 #else
58 #define GCOV_TAG_FUNCTION_LENGTH  3
59 #endif
60 
61 #define GCOV_DATA_MAGIC   (0x67636461)
62 #define GCOV_TAG_FUNCTION (0x01000000)
63 #define GCOV_TAG_COUNTER_BASE (0x01a10000)
64 #define GCOV_TAG_FOR_COUNTER(count)         \
65 (GCOV_TAG_COUNTER_BASE + ((uint32_t) (count) << 17))
66 
67 #define FILE_START_INDICATOR	'*'
68 #define GCOV_DUMP_SEPARATOR	'<'
69 
70 /**Information about counters for a single function
71  *
72  * This data is generated by gcc during compilation and doesn't change
73  *  at run-time with the exception of the values array.
74  */
75 struct gcov_ctr_info {
76 	unsigned int num;    /* number of counter values for this type */
77 	gcov_type *values;   /* array of counter values for this type */
78 };
79 
80 /**
81  * Profiling meta data per function
82  *
83  * This data is generated by gcc during compilation and doesn't change
84  * at run-time.
85  *
86  * Information about a single function.  This uses the trailing array
87  * idiom. The number of counters is determined from the merge pointer
88  * array in gcov_info.  The key is used to detect which of a set of
89  * comdat functions was selected -- it points to the gcov_info object
90  * of the object file containing the selected comdat function.
91  */
92 struct gcov_fn_info {
93 	const struct gcov_info *key;     /* comdat key */
94 	unsigned int ident;              /* unique ident of function */
95 	unsigned int lineno_checksum;    /* function lineno_checksum */
96 	unsigned int cfg_checksum;       /* function cfg checksum */
97 	struct gcov_ctr_info ctrs[1];    /* instrumented counters */
98 };
99 
100 /** Profiling data per object file
101  *
102  * This data is generated by gcc during compilation and doesn't change
103  * at run-time with the exception of the next pointer.
104  */
105 struct gcov_info {
106 	unsigned int version;        /* Gcov version (same as GCC version) */
107 	struct gcov_info *next;      /* List head for a singly-linked list */
108 	unsigned int stamp;          /* Uniquifying time stamp */
109 #ifdef GCOV_12_FORMAT
110 	unsigned int checksum;		/* unique object checksum */
111 #endif
112 	const char *filename;        /* Name of the associated gcda data file */
113 	/* merge functions, null for unused*/
114 	void (*merge[GCOV_COUNTERS])(gcov_type *, unsigned int);
115 	unsigned int n_functions;         /* number of instrumented functions */
116 	struct gcov_fn_info **functions;  /* function information */
117 
118 };
119 
120 /*
121  * These functions are in the header for easy access for external interface
122  * reporting since they aren't useful without the structs in this header.
123  */
124 struct gcov_info *gcov_get_list_head(void);
125 size_t gcov_populate_buffer(uint8_t *buffer, struct gcov_info *info);
126 size_t gcov_calculate_buff_size(struct gcov_info *info);
127 
128 #endif /* _COVERAGE_H_ */
129