##// END OF EJS Templates
Increased libgcov gcda buffer to avoid file splitting
jeandet -
r388:01d5c5b53213 No PWD scrub with... draft
parent child
Show More
@@ -1,2 +1,2
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
2 042275d1388a0f360073a0d85bf50d128f4b8cfc header/lfr_common_headers
2 7053a75ef0a55a40e950a8302065856f3bd06a26 header/lfr_common_headers
@@ -1,38 +1,41
1 #!/usr/bin/env python3
1 #!/usr/bin/env python3
2
2
3 __author__ = "Alexis Jeandet"
3 __author__ = "Alexis Jeandet"
4 __copyright__ = "Copyright 2018, Laboratory of Plasma Physics"
4 __copyright__ = "Copyright 2018, Laboratory of Plasma Physics"
5 __credits__ = []
5 __credits__ = []
6 __license__ = "GPLv2"
6 __license__ = "GPLv2"
7 __version__ = "1.0.0"
7 __version__ = "1.0.0"
8 __maintainer__ = "Alexis Jeandet"
8 __maintainer__ = "Alexis Jeandet"
9 __email__ = "alexis.jeandet@member.fsf.org"
9 __email__ = "alexis.jeandet@member.fsf.org"
10 __status__ = "Development"
10 __status__ = "Development"
11
11
12 import time
12 import time
13 import sys
13 import sys
14 import os
14 import os
15 import serial
15 import serial
16 import argparse
16 import argparse
17 from datetime import datetime
17 from datetime import datetime
18
18
19 parser = argparse.ArgumentParser()
19 parser = argparse.ArgumentParser()
20 parser.add_argument("-f", "--gcov-file", help="Gcov output file generated by record_lfr_console.py")
20 parser.add_argument("-f", "--gcov-file", help="Gcov output file generated by record_lfr_console.py")
21 args = parser.parse_args()
21 args = parser.parse_args()
22
22
23
23
24
24
25 def main():
25 def main():
26 with open(args.gcov_file,'r') as gcov:
26 with open(args.gcov_file,'r') as gcov:
27 files = []
27 for line in gcov.readlines():
28 for line in gcov.readlines():
28 head,dest_file,data = line.split(',')
29 head,dest_file,data = line.split(',')
29 if head == '_GCOV_':
30 if dest_file not in files:
30 print(f"Writing {dest_file}\n")
31 files.append(dest_file)
31 with open(dest_file,'wb') as gcda_file:
32 if head == '_GCOV_':
32 gcda_file.write(bytes([int(''.join(value),16) for value in zip(data[::2],data[1::2]) ]))
33 print(f"Writing {dest_file}\n")
33 else:
34 with open(dest_file,'wb') as gcda_file:
34 raise
35 gcda_file.write(bytes([int(''.join(value),16) for value in zip(data[::2],data[1::2]) ]))
36 else:
37 raise
35
38
36
39
37 if __name__ == "__main__":
40 if __name__ == "__main__":
38 main()
41 main()
@@ -1,820 +1,488
1 /* Test for GCC >= 3.4.4 && <= 4.4.6 */
1 /* Test for GCC >= 3.4.4 && <= 4.4.6 */
2 //#if ( ( __GNUC__ > 3 ) || \
2 //#if ( ( __GNUC__ > 3 ) || \
3 // ( __GNUC__ == 3 && __GNUC_MINOR__ > 4 )|| \
3 // ( __GNUC__ == 3 && __GNUC_MINOR__ > 4 )|| \
4 // ( __GNUC__ == 3 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ >= 4 ) ) && \
4 // ( __GNUC__ == 3 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ >= 4 ) ) && \
5 // ( ( __GNUC__ < 4 ) || \
5 // ( ( __GNUC__ < 4 ) || \
6 // ( __GNUC__ == 4 && __GNUC_MINOR__ < 4 )|| \
6 // ( __GNUC__ == 4 && __GNUC_MINOR__ < 4 )|| \
7 // ( __GNUC__ == 4 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ <= 6 ) )
7 // ( __GNUC__ == 4 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ <= 6 ) )
8 /*
8 /*
9 * =====================================================================================
9 * =====================================================================================
10 *
10 *
11 * Filename: gcov-io.c
11 * Filename: gcov-io.c
12 *
12 *
13 * Description: This is the I/O file for embedded systems
13 * Description: This is the I/O file for embedded systems
14 *
14 *
15 * Version: 1.0
15 * Version: 1.0
16 * Created: 03/04/08 09:51:59
16 * Created: 03/04/08 09:51:59
17 * Revision: none
17 * Revision: none
18 * Compiler: gcc
18 * Compiler: gcc
19 *
19 *
20 * Author: Aitor Viana Sanchez (avs), aitor.viana.sanchez@esa.int
20 * Author: Aitor Viana Sanchez (avs), aitor.viana.sanchez@esa.int
21 * Company: European Space Agency (ESA-ESTEC)
21 * Company: European Space Agency (ESA-ESTEC)
22 *
22 *
23 * =====================================================================================
23 * =====================================================================================
24 */
24 */
25
25
26 /* File format for coverage information
26 /* File format for coverage information
27 Copyright (C) 1996, 1997, 1998, 2000, 2002,
27 Copyright (C) 1996, 1997, 1998, 2000, 2002,
28 2003 Free Software Foundation, Inc.
28 2003 Free Software Foundation, Inc.
29 Contributed by Bob Manson <manson@cygnus.com>.
29 Contributed by Bob Manson <manson@cygnus.com>.
30 Completely remangled by Nathan Sidwell <nathan@codesourcery.com>.
30 Completely remangled by Nathan Sidwell <nathan@codesourcery.com>.
31
31
32 This file is part of GCC.
32 This file is part of GCC.
33
33
34 GCC is free software; you can redistribute it and/or modify it under
34 GCC is free software; you can redistribute it and/or modify it under
35 the terms of the GNU General Public License as published by the Free
35 the terms of the GNU General Public License as published by the Free
36 Software Foundation; either version 2, or (at your option) any later
36 Software Foundation; either version 2, or (at your option) any later
37 version.
37 version.
38
38
39 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
39 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
40 WARRANTY; without even the implied warranty of MERCHANTABILITY or
40 WARRANTY; without even the implied warranty of MERCHANTABILITY or
41 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
41 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
42 for more details.
42 for more details.
43
43
44 You should have received a copy of the GNU General Public License
44 You should have received a copy of the GNU General Public License
45 along with GCC; see the file COPYING. If not, write to the Free
45 along with GCC; see the file COPYING. If not, write to the Free
46 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
46 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
47 02111-1307, USA. */
47 02111-1307, USA. */
48
48
49 #include <stdio.h>
49 #include <stdio.h>
50 #include <stdlib.h> /* for atexit() */
50 #include <stdlib.h> /* for atexit() */
51 #include <string.h>
51 #include <string.h>
52 #include "gcov-io.h"
52 #include "gcov-io.h"
53
53
54 /* Routines declared in gcov-io.h. This file should be #included by
54 /* Routines declared in gcov-io.h. This file should be #included by
55 another source file, after having #included gcov-io.h. */
55 another source file, after having #included gcov-io.h. */
56
56
57
57
58 /* This function shall be defined somewhere else */
58 /* This function shall be defined somewhere else */
59 //int send_data(unsigned char * buffer, unsigned int size);
59 //int send_data(unsigned char * buffer, unsigned int size);
60
60
61 /*-----------------------------------------------------------------------------
61 /*-----------------------------------------------------------------------------
62 * PRIVATE INTERFACE
62 * PRIVATE INTERFACE
63 *-----------------------------------------------------------------------------*/
63 *-----------------------------------------------------------------------------*/
64
64
65 static void gcov_write_block (unsigned);
65 static void gcov_write_block (unsigned);
66 static gcov_unsigned_t *gcov_write_words (unsigned);
66 static gcov_unsigned_t *gcov_write_words (unsigned);
67 GCOV_LINKAGE int gcov_send (void);
67 GCOV_LINKAGE int gcov_send (void);
68 GCOV_LINKAGE int gcov_close(void);
68 GCOV_LINKAGE int gcov_close(void);
69 //static const gcov_unsigned_t *gcov_read_words (unsigned);
70
69
71 extern struct gcov_info * gcov_list;
70 extern struct gcov_info * gcov_list;
72 extern gcov_unsigned_t gcov_crc32;
71 extern gcov_unsigned_t gcov_crc32;
73
72
74 int dev_id = 0;
73 int dev_id = 0;
75
74
76 /*
75 /*
77 * === FUNCTION ======================================================================
76 * === FUNCTION ======================================================================
78 * Name: from_file
77 * Name: from_file
79 * Description: This function just return the given parameter
78 * Description: This function just return the given parameter
80 * =====================================================================================
79 * =====================================================================================
81 */
80 */
82 static inline gcov_unsigned_t from_file (gcov_unsigned_t value)
81 static inline gcov_unsigned_t from_file (gcov_unsigned_t value)
83 {
82 {
84 return value;
83 return value;
85 }
84 }
86
85
87 /*
86 /*
88 * === FUNCTION ======================================================================
87 * === FUNCTION ======================================================================
89 * Name: gcov_version
88 * Name: gcov_version
90 * Description: This function returns TRUE (1) if the gcov version is the
89 * Description: This function returns TRUE (1) if the gcov version is the
91 * version expected. The function returns FALSE (0) in any other case.
90 * version expected. The function returns FALSE (0) in any other case.
92 * =====================================================================================
91 * =====================================================================================
93 */
92 */
94 static int gcov_version (struct gcov_info *ptr, gcov_unsigned_t version)
93 static int gcov_version (struct gcov_info *ptr, gcov_unsigned_t version)
95 {
94 {
96 if (version != GCOV_VERSION)
95 if (version != GCOV_VERSION)
97 {
96 {
98 char v[4], e[4];
97 char v[4], e[4];
99
98
100 GCOV_UNSIGNED2STRING (v, version);
99 GCOV_UNSIGNED2STRING (v, version);
101 GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
100 GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
102
101
103 printf ("profiling:%s:Version mismatch - expected %.4s got %.4s\n",
102 printf ("profiling:%s:Version mismatch - expected %.4s got %.4s\n",
104 ptr->filename, e, v);
103 ptr->filename, e, v);
105
104
106 return 0;
105 return 0;
107 }
106 }
108 return 1;
107 return 1;
109 }
108 }
110
109
111
110
112 /*-----------------------------------------------------------------------------
111 /*-----------------------------------------------------------------------------
113 * PUBLIC INTERFACE
112 * PUBLIC INTERFACE
114 *-----------------------------------------------------------------------------*/
113 *-----------------------------------------------------------------------------*/
115
114
116 /* Dump the coverage counts. We merge with existing counts when
115 /* Dump the coverage counts. We merge with existing counts when
117 possible, to avoid growing the .da files ad infinitum. We use this
116 possible, to avoid growing the .da files ad infinitum. We use this
118 program's checksum to make sure we only accumulate whole program
117 program's checksum to make sure we only accumulate whole program
119 statistics to the correct summary. An object file might be embedded
118 statistics to the correct summary. An object file might be embedded
120 in two separate programs, and we must keep the two program
119 in two separate programs, and we must keep the two program
121 summaries separate. */
120 summaries separate. */
122
121
123 /*
122 /*
124 * === FUNCTION ======================================================================
123 * === FUNCTION ======================================================================
125 * Name: gcov_exit
124 * Name: gcov_exit
126 * Description: This function dumps the coverage couns. The merging with
125 * Description: This function dumps the coverage couns. The merging with
127 * existing counts is not done in embedded systems.
126 * existing counts is not done in embedded systems.
128 * =====================================================================================
127 * =====================================================================================
129 */
128 */
130 void gcov_exit (void)
129 void gcov_exit (void)
131 {
130 {
132 struct gcov_info *gi_ptr;
131 struct gcov_info *gi_ptr;
133 struct gcov_summary this_program;
132 struct gcov_summary this_program;
134 struct gcov_summary all;
133 struct gcov_summary all;
135 struct gcov_ctr_summary *cs_ptr;
134 struct gcov_ctr_summary *cs_ptr;
136 const struct gcov_ctr_info *ci_ptr;
135 const struct gcov_ctr_info *ci_ptr;
137 unsigned t_ix;
136 unsigned t_ix;
138 gcov_unsigned_t c_num;
137 gcov_unsigned_t c_num;
139 unsigned long coreId = 0;
138 unsigned long coreId = 0;
140
139
141 /* retrieve the id of the CPU the program is running on */
140 /* retrieve the id of the CPU the program is running on */
142 #ifdef LEON3
141 #ifdef LEON3
143 __asm__ __volatile__("rd %%asr17,%0\n\t"
142 __asm__ __volatile__("rd %%asr17,%0\n\t"
144 "srl %0,28,%0" :
143 "srl %0,28,%0" :
145 "=&r" (coreId) : );
144 "=&r" (coreId) : );
146 #endif
145 #endif
147
146
148 printf("_GCOVEXIT_BEGIN_,core%d\n", coreId); /* see also _GCOVEXIT_END_ */
147 printf("_GCOVEXIT_BEGIN_,core%d\n", coreId); /* see also _GCOVEXIT_END_ */
149
148
150 if(gcov_list == (void*)0x0)
149 if(gcov_list == (void*)0x0)
151 printf("%s: gcov_list == NULL\n", __func__);
150 printf("%s: gcov_list == NULL\n", __func__);
152
151
153 memset (&all, 0, sizeof (all));
152 memset (&all, 0, sizeof (all));
154 /* Find the totals for this execution. */
153 /* Find the totals for this execution. */
155 memset (&this_program, 0, sizeof (this_program));
154 memset (&this_program, 0, sizeof (this_program));
156 for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr->next)
155 for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr->next)
157 {
156 {
158
157
159 ci_ptr = gi_ptr->counts;
158 ci_ptr = gi_ptr->counts;
160 for (t_ix = 0; t_ix < GCOV_COUNTERS_SUMMABLE; t_ix++)
159 for (t_ix = 0; t_ix < GCOV_COUNTERS_SUMMABLE; t_ix++)
161 {
160 {
162 if (!((1 << t_ix) & gi_ptr->ctr_mask))
161 if (!((1 << t_ix) & gi_ptr->ctr_mask))
163 continue;
162 continue;
164
163
165 cs_ptr = &this_program.ctrs[t_ix];
164 cs_ptr = &this_program.ctrs[t_ix];
166 cs_ptr->num += ci_ptr->num;
165 cs_ptr->num += ci_ptr->num;
167 for (c_num = 0; c_num < ci_ptr->num; c_num++)
166 for (c_num = 0; c_num < ci_ptr->num; c_num++)
168 {
167 {
169 cs_ptr->sum_all += ci_ptr->values[c_num];
168 cs_ptr->sum_all += ci_ptr->values[c_num];
170 if (cs_ptr->run_max < ci_ptr->values[c_num])
169 if (cs_ptr->run_max < ci_ptr->values[c_num])
171 cs_ptr->run_max = ci_ptr->values[c_num];
170 cs_ptr->run_max = ci_ptr->values[c_num];
172 }
171 }
173 ci_ptr++;
172 ci_ptr++;
174 }
173 }
175 }
174 }
176 /* Now merge each file. */
175 /* Now merge each file. */
177 for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr->next)
176 for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr->next)
178 {
177 {
179 // struct gcov_summary this_object, object;
178
180 // struct gcov_ctr_summary *cs_obj, *cs_tobj, *cs_prg, *cs_tprg, *cs_all;
181 // int error = 0;
182 // gcov_unsigned_t tag, length;
183 // gcov_position_t summary_pos = 0;
184 struct gcov_summary program;
179 struct gcov_summary program;
185 gcov_type *values[GCOV_COUNTERS];
180 gcov_type *values[GCOV_COUNTERS];
186 const struct gcov_fn_info *fi_ptr;
181 const struct gcov_fn_info *fi_ptr;
187 unsigned fi_stride;
182 unsigned fi_stride;
188 unsigned c_ix, f_ix, n_counts;
183 unsigned c_ix, f_ix, n_counts;
189
184
190 #if 0
191 memset (&this_object, 0, sizeof (this_object));
192 memset (&object, 0, sizeof (object));
193
194
195 /* Totals for this object file. */
196 ci_ptr = gi_ptr->counts;
197 for (t_ix = 0; t_ix < GCOV_COUNTERS_SUMMABLE; t_ix++)
198 {
199 if (!((1 << t_ix) & gi_ptr->ctr_mask))
200 continue;
201
202 cs_ptr = &this_object.ctrs[t_ix];
203 cs_ptr->num += ci_ptr->num;
204 for (c_num = 0; c_num < ci_ptr->num; c_num++)
205 {
206 cs_ptr->sum_all += ci_ptr->values[c_num];
207 if (cs_ptr->run_max < ci_ptr->values[c_num])
208 cs_ptr->run_max = ci_ptr->values[c_num];
209 }
210
211 ci_ptr++;
212 }
213 #endif
214
215 c_ix = 0;
185 c_ix = 0;
216 for (t_ix = 0; t_ix < GCOV_COUNTERS; t_ix++)
186 for (t_ix = 0; t_ix < GCOV_COUNTERS; t_ix++)
217 if ((1 << t_ix) & gi_ptr->ctr_mask)
187 if ((1 << t_ix) & gi_ptr->ctr_mask)
218 {
188 {
219 values[c_ix] = gi_ptr->counts[c_ix].values;
189 values[c_ix] = gi_ptr->counts[c_ix].values;
220 c_ix++;
190 c_ix++;
221 }
191 }
222
192
223 /* Calculate the function_info stride. This depends on the
193 /* Calculate the function_info stride. This depends on the
224 number of counter types being measured. */
194 number of counter types being measured. */
225 fi_stride = sizeof (struct gcov_fn_info) + c_ix * sizeof (unsigned);
195 fi_stride = sizeof (struct gcov_fn_info) + c_ix * sizeof (unsigned);
226 if (__alignof__ (struct gcov_fn_info) > sizeof (unsigned))
196 if (__alignof__ (struct gcov_fn_info) > sizeof (unsigned))
227 {
197 {
228 fi_stride += __alignof__ (struct gcov_fn_info) - 1;
198 fi_stride += __alignof__ (struct gcov_fn_info) - 1;
229 fi_stride &= ~(__alignof__ (struct gcov_fn_info) - 1);
199 fi_stride &= ~(__alignof__ (struct gcov_fn_info) - 1);
230 }
200 }
231
201
232 if (!gcov_open (gi_ptr->filename))
202 if (!gcov_open (gi_ptr->filename))
233 {
203 {
234 printf ("profiling:%s:Cannot open\n", gi_ptr->filename);
204 printf ("profiling:%s:Cannot open\n", gi_ptr->filename);
235 continue;
205 continue;
236 }
206 }
237
207
238 #if 0
239 tag = gcov_read_unsigned ();
240 if (tag)
241 {
242 /* Merge data from file. */
243 if (tag != GCOV_DATA_MAGIC)
244 {
245 fprintf (stderr, "profiling:%s:Not a gcov data file\n",
246 gi_ptr->filename);
247 read_fatal:;
248 gcov_close ();
249 continue;
250 }
251 length = gcov_read_unsigned ();
252 if (!gcov_version (gi_ptr, length))
253 goto read_fatal;
254
255 length = gcov_read_unsigned ();
256 if (length != gi_ptr->stamp)
257 {
258 /* Read from a different compilation. Overwrite the
259 file. */
260 gcov_truncate ();
261 goto rewrite;
262 }
263
264 /* Merge execution counts for each function. */
265 for (f_ix = 0; f_ix < gi_ptr->n_functions; f_ix++)
266 {
267 fi_ptr = (const struct gcov_fn_info *)
268 ((const char *) gi_ptr->functions + f_ix * fi_stride);
269 tag = gcov_read_unsigned ();
270 length = gcov_read_unsigned ();
271
272 /* Check function. */
273 if (tag != GCOV_TAG_FUNCTION
274 || length != GCOV_TAG_FUNCTION_LENGTH
275 || gcov_read_unsigned () != fi_ptr->ident
276 || gcov_read_unsigned () != fi_ptr->checksum)
277 {
278 read_mismatch:;
279 fprintf (stderr, "profiling:%s:Merge mismatch for %s\n",
280 gi_ptr->filename,
281 f_ix + 1 ? "function" : "summaries");
282 goto read_fatal;
283 }
284
285 c_ix = 0;
286 for (t_ix = 0; t_ix < GCOV_COUNTERS; t_ix++)
287 {
288 gcov_merge_fn merge;
289
290 if (!((1 << t_ix) & gi_ptr->ctr_mask))
291 continue;
292
293 n_counts = fi_ptr->n_ctrs[c_ix];
294 merge = gi_ptr->counts[c_ix].merge;
295
296 tag = gcov_read_unsigned ();
297 length = gcov_read_unsigned ();
298 if (tag != GCOV_TAG_FOR_COUNTER (t_ix)
299 || length != GCOV_TAG_COUNTER_LENGTH (n_counts))
300 goto read_mismatch;
301 (*merge) (values[c_ix], n_counts);
302 values[c_ix] += n_counts;
303 c_ix++;
304 }
305 if ((error = gcov_is_error ()))
306 goto read_error;
307 }
308
309 f_ix = ~0u;
310 /* Check program & object summary */
311 while (1)
312 {
313 gcov_position_t base = gcov_position ();
314 int is_program;
315
316 tag = gcov_read_unsigned ();
317 if (!tag)
318 break;
319 length = gcov_read_unsigned ();
320 is_program = tag == GCOV_TAG_PROGRAM_SUMMARY;
321 if (length != GCOV_TAG_SUMMARY_LENGTH
322 || (!is_program && tag != GCOV_TAG_OBJECT_SUMMARY))
323 goto read_mismatch;
324 gcov_read_summary (is_program ? &program : &object);
325 if ((error = gcov_is_error ()))
326 goto read_error;
327 if (is_program && program.checksum == gcov_crc32)
328 {
329 summary_pos = base;
330 goto rewrite;
331 }
332 }
333 }
334
335 if (!gcov_is_eof ())
336 {
337 read_error:;
338 fprintf (stderr, error < 0 ? "profiling:%s:Overflow merging\n"
339 : "profiling:%s:Error merging\n", gi_ptr->filename);
340 goto read_fatal;
341 }
342 rewrite:;
343 gcov_rewrite ();
344 if (!summary_pos)
345 memset (&program, 0, sizeof (program));
346 /* Merge the summaries. */
347 f_ix = ~0u;
348 for (t_ix = 0; t_ix < GCOV_COUNTERS_SUMMABLE; t_ix++)
349 {
350 cs_obj = &object.ctrs[t_ix];
351 cs_tobj = &this_object.ctrs[t_ix];
352 cs_prg = &program.ctrs[t_ix];
353 cs_tprg = &this_program.ctrs[t_ix];
354 cs_all = &all.ctrs[t_ix];
355
356 if ((1 << t_ix) & gi_ptr->ctr_mask)
357 {
358 if (!cs_obj->runs++)
359 cs_obj->num = cs_tobj->num;
360 else if (cs_obj->num != cs_tobj->num)
361 goto read_mismatch;
362 cs_obj->sum_all += cs_tobj->sum_all;
363 if (cs_obj->run_max < cs_tobj->run_max)
364 cs_obj->run_max = cs_tobj->run_max;
365 cs_obj->sum_max += cs_tobj->run_max;
366
367 if (!cs_prg->runs++)
368 cs_prg->num = cs_tprg->num;
369 else if (cs_prg->num != cs_tprg->num)
370 goto read_mismatch;
371 cs_prg->sum_all += cs_tprg->sum_all;
372 if (cs_prg->run_max < cs_tprg->run_max)
373 cs_prg->run_max = cs_tprg->run_max;
374 cs_prg->sum_max += cs_tprg->run_max;
375 }
376 else if (cs_obj->num || cs_prg->num)
377 goto read_mismatch;
378
379 if (!cs_all->runs && cs_prg->runs)
380 memcpy (cs_all, cs_prg, sizeof (*cs_all));
381 else if (!all.checksum
382 && (!GCOV_LOCKED || cs_all->runs == cs_prg->runs)
383 && memcmp (cs_all, cs_prg, sizeof (*cs_all)))
384 {
385 fprintf (stderr, "profiling:%s:Invocation mismatch - some data files may have been removed%s",
386 gi_ptr->filename, GCOV_LOCKED
387 ? "" : " or concurrent update without locking support");
388 all.checksum = ~0u;
389 }
390 }
391
392 c_ix = 0;
393 for (t_ix = 0; t_ix < GCOV_COUNTERS; t_ix++)
394 if ((1 << t_ix) & gi_ptr->ctr_mask)
395 {
396 values[c_ix] = gi_ptr->counts[c_ix].values;
397 c_ix++;
398 }
399
400 #endif
401 program.checksum = gcov_crc32;
208 program.checksum = gcov_crc32;
402
209
403 /* Write out the data. */
210 /* Write out the data. */
404 gcov_write_tag_length (GCOV_DATA_MAGIC, GCOV_VERSION);
211 gcov_write_tag_length (GCOV_DATA_MAGIC, GCOV_VERSION);
405 gcov_write_unsigned (gi_ptr->stamp);
212 gcov_write_unsigned (gi_ptr->stamp);
406
213
407 /* Write execution counts for each function. */
214 /* Write execution counts for each function. */
408 for (f_ix = 0; f_ix < gi_ptr->n_functions; f_ix++)
215 for (f_ix = 0; f_ix < gi_ptr->n_functions; f_ix++)
409 {
216 {
410 fi_ptr = (const struct gcov_fn_info *)
217 fi_ptr = (const struct gcov_fn_info *)
411 ((const char *) gi_ptr->functions + f_ix * fi_stride);
218 ((const char *) gi_ptr->functions + f_ix * fi_stride);
412
219
413 /* Announce function. */
220 /* Announce function. */
414 gcov_write_tag_length (GCOV_TAG_FUNCTION, GCOV_TAG_FUNCTION_LENGTH);
221 gcov_write_tag_length (GCOV_TAG_FUNCTION, GCOV_TAG_FUNCTION_LENGTH);
415 gcov_write_unsigned (fi_ptr->ident);
222 gcov_write_unsigned (fi_ptr->ident);
416 gcov_write_unsigned (fi_ptr->checksum);
223 gcov_write_unsigned (fi_ptr->checksum);
417
224
418 c_ix = 0;
225 c_ix = 0;
419 for (t_ix = 0; t_ix < GCOV_COUNTERS; t_ix++)
226 for (t_ix = 0; t_ix < GCOV_COUNTERS; t_ix++)
420 {
227 {
421 gcov_type *c_ptr;
228 gcov_type *c_ptr;
422
229
423 if (!((1 << t_ix) & gi_ptr->ctr_mask))
230 if (!((1 << t_ix) & gi_ptr->ctr_mask))
424 continue;
231 continue;
425
232
426 n_counts = fi_ptr->n_ctrs[c_ix];
233 n_counts = fi_ptr->n_ctrs[c_ix];
427
234
428 gcov_write_tag_length (GCOV_TAG_FOR_COUNTER (t_ix),
235 gcov_write_tag_length (GCOV_TAG_FOR_COUNTER (t_ix),
429 GCOV_TAG_COUNTER_LENGTH (n_counts));
236 GCOV_TAG_COUNTER_LENGTH (n_counts));
430 c_ptr = values[c_ix];
237 c_ptr = values[c_ix];
431 while (n_counts--)
238 while (n_counts--)
432 gcov_write_counter (*c_ptr++);
239 gcov_write_counter (*c_ptr++);
433
240
434 values[c_ix] = c_ptr;
241 values[c_ix] = c_ptr;
435 c_ix++;
242 c_ix++;
436 }
243 }
437 }
244 }
438
245
439 /* Object file summary. */
440 // gcov_write_summary (GCOV_TAG_OBJECT_SUMMARY, &object);
441
442 /* Generate whole program statistics. */
443 // gcov_seek (summary_pos);
444 // gcov_write_summary (GCOV_TAG_PROGRAM_SUMMARY, &program);
445 gcov_send();
246 gcov_send();
446 gcov_close();
247 gcov_close();
447 /* if ((error = gcov_send ()))
248
448 fprintf (stderr, error < 0 ?
449 "profiling:%s:Overflow writing\n" :
450 "profiling:%s:Error writing\n",
451 gi_ptr->filename);*/
452 }
249 }
453
250
454 printf("_GCOVEXIT_END_,core%d\n", coreId);
251 printf("_GCOVEXIT_END_,core%d\n", coreId);
455 }
252 }
456
253
457
254
458 /* Called before fork or exec - write out profile information gathered so
255 /* Called before fork or exec - write out profile information gathered so
459 far and reset it to zero. This avoids duplication or loss of the
256 far and reset it to zero. This avoids duplication or loss of the
460 profile information gathered so far. */
257 profile information gathered so far. */
461
258
462 void
259 void
463 __gcov_flush (void)
260 __gcov_flush (void)
464 {
261 {
465 const struct gcov_info *gi_ptr;
262 const struct gcov_info *gi_ptr;
466
263
467 gcov_exit ();
264 gcov_exit ();
468 for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr->next)
265 for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr->next)
469 {
266 {
470 unsigned t_ix;
267 unsigned t_ix;
471 const struct gcov_ctr_info *ci_ptr;
268 const struct gcov_ctr_info *ci_ptr;
472
269
473 for (t_ix = 0, ci_ptr = gi_ptr->counts; t_ix != GCOV_COUNTERS; t_ix++)
270 for (t_ix = 0, ci_ptr = gi_ptr->counts; t_ix != GCOV_COUNTERS; t_ix++)
474 if ((1 << t_ix) & gi_ptr->ctr_mask)
271 if ((1 << t_ix) & gi_ptr->ctr_mask)
475 {
272 {
476 memset (ci_ptr->values, 0, sizeof (gcov_type) * ci_ptr->num);
273 memset (ci_ptr->values, 0, sizeof (gcov_type) * ci_ptr->num);
477 ci_ptr++;
274 ci_ptr++;
478 }
275 }
479 }
276 }
480 }
277 }
481
278
482
279
483
280
484 /* Open a gcov file. NAME is the name of the file to open and MODE
281 /* Open a gcov file. NAME is the name of the file to open and MODE
485 indicates whether a new file should be created, or an existing file
282 indicates whether a new file should be created, or an existing file
486 opened for modification. If MODE is >= 0 an existing file will be
283 opened for modification. If MODE is >= 0 an existing file will be
487 opened, if possible, and if MODE is <= 0, a new file will be
284 opened, if possible, and if MODE is <= 0, a new file will be
488 created. Use MODE=0 to attempt to reopen an existing file and then
285 created. Use MODE=0 to attempt to reopen an existing file and then
489 fall back on creating a new one. Return zero on failure, >0 on
286 fall back on creating a new one. Return zero on failure, >0 on
490 opening an existing file and <0 on creating a new one. */
287 opening an existing file and <0 on creating a new one. */
491 GCOV_LINKAGE int gcov_open(const char *name)
288 GCOV_LINKAGE int gcov_open(const char *name)
492 {
289 {
493 // gcov_var.start is cleared in the gcov_close function.
290 // gcov_var.start is cleared in the gcov_close function.
494 // If this variable is not cleared...ERROR
291 // If this variable is not cleared...ERROR
495 if( gcov_var.start != 0 )
292 if( gcov_var.start != 0 )
496 return 0;
293 return 0;
497
294
498 // Clear everything
295 // Clear everything
499 gcov_var.start = 0;
296 gcov_var.start = 0;
500 gcov_var.offset = gcov_var.length = 0;
297 gcov_var.offset = gcov_var.length = 0;
501 gcov_var.overread = -1u;
298 gcov_var.overread = -1u;
502 gcov_var.error = 0;
299 gcov_var.error = 0;
503
300
504
301
505 // copy the filename in the gcov_var structure
302 // copy the filename in the gcov_var structure
506 strcpy(gcov_var.filename, name);
303 strcpy(gcov_var.filename, name);
507
304
508
305
509 // return 1 means everything is OK
306 // return 1 means everything is OK
510 return 1;
307 return 1;
511 }
308 }
512
309
513 /* Close the current gcov file. Flushes data to disk. Returns nonzero
310 /* Close the current gcov file. Flushes data to disk. Returns nonzero
514 on failure or error flag set. */
311 on failure or error flag set. */
515
312
516 GCOV_LINKAGE int gcov_send (void)
313 GCOV_LINKAGE int gcov_send (void)
517 {
314 {
518 /*printf("%s: file %s\n", __func__, gcov_var.filename);*/
315 /*printf("%s: file %s\n", __func__, gcov_var.filename);*/
519 if (gcov_var.offset)
316 if (gcov_var.offset)
520 gcov_write_block (gcov_var.offset);
317 gcov_write_block (gcov_var.offset);
521
318
522 gcov_var.length = 0;
319 gcov_var.length = 0;
523 return gcov_var.error;
320 return gcov_var.error;
524 }
321 }
525
322
526 GCOV_LINKAGE int gcov_close(void)
323 GCOV_LINKAGE int gcov_close(void)
527 {
324 {
528 /*printf("%s: %s\n", __func__, gcov_var.filename);*/
529 memset(gcov_var.filename, 0, strlen(gcov_var.filename));
325 memset(gcov_var.filename, 0, strlen(gcov_var.filename));
530
326
531 // Clear the start variable because will be tested in the gcov_open
327 // Clear the start variable because will be tested in the gcov_open
532 // function
328 // function
533 gcov_var.start = 0;
329 gcov_var.start = 0;
534
330
535 // Return the error, not sure whether the error is modifed.
331 // Return the error, not sure whether the error is modifed.
536 return gcov_var.error;
332 return gcov_var.error;
537 }
333 }
538
334
539 /* Write out the
540 current block, if needs be. */
541 /*static void gcov_write_block (unsigned size) {
542 unsigned int bw = 0;
543 unsigned int i;
544
545 printf("_GCOV_,%s,", gcov_var.filename);
546 for(i = 0; i < size << 2; i++) {
547 char str[5] = {0};
548
549 printf("%02X", ((unsigned char*)(gcov_var.buffer))[i]);
550 }
551 printf("\n");
552
553 gcov_var.start += size;
554 gcov_var.offset -= size;
555 }*/
556
335
557 static void gcov_write_block (unsigned size) {
336 static void gcov_write_block (unsigned size) {
558 unsigned char *buffer = (unsigned char*) gcov_var.buffer;
337 unsigned char *buffer = (unsigned char*) gcov_var.buffer;
559 unsigned int i;
338 unsigned int i;
560
339
561 printf("_GCOV_,%s,", gcov_var.filename);
340 printf("_GCOV_,%s,", gcov_var.filename);
562 /* to speed up the printing process, we display bytes 4 by 4 */
341 /* to speed up the printing process, we display bytes 4 by 4 */
563 for(i = 0; i < size; i++) {
342 for(i = 0; i < size; i++) {
564 printf("%02X%02X%02X%02X", (unsigned int)(buffer[0]),
343 printf("%02X%02X%02X%02X", (unsigned int)(buffer[0]),
565 (unsigned int)(buffer[1]),
344 (unsigned int)(buffer[1]),
566 (unsigned int)(buffer[2]),
345 (unsigned int)(buffer[2]),
567 (unsigned int)(buffer[3]));
346 (unsigned int)(buffer[3]));
568
347
569 buffer += sizeof(gcov_unsigned_t);
348 buffer += sizeof(gcov_unsigned_t);
570 }
349 }
571 printf("\n");
350 printf("\n");
572
351
573 gcov_var.start += size;
352 gcov_var.start += size;
574 gcov_var.offset -= size;
353 gcov_var.offset -= size;
575 }
354 }
576
355
577 /* Allocate space to write BYTES bytes to the gcov file. Return a
356 /* Allocate space to write BYTES bytes to the gcov file. Return a
578 pointer to those bytes, or NULL on failure. */
357 pointer to those bytes, or NULL on failure. */
579
358
580 static gcov_unsigned_t *gcov_write_words (unsigned words) {
359 static gcov_unsigned_t *gcov_write_words (unsigned words) {
581 gcov_unsigned_t *result;
360 gcov_unsigned_t *result;
582
361
583 GCOV_CHECK_WRITING ();
362 GCOV_CHECK_WRITING ();
584 if (gcov_var.offset >= GCOV_BLOCK_SIZE)
363 if (gcov_var.offset >= GCOV_BLOCK_SIZE)
585 {
364 {
586 gcov_write_block (GCOV_BLOCK_SIZE);
365 gcov_write_block (GCOV_BLOCK_SIZE);
587 if (gcov_var.offset)
366 if (gcov_var.offset)
588 {
367 {
589 GCOV_CHECK (gcov_var.offset == 1);
368 GCOV_CHECK (gcov_var.offset == 1);
590 memcpy (gcov_var.buffer, gcov_var.buffer + GCOV_BLOCK_SIZE, 4);
369 memcpy (gcov_var.buffer, gcov_var.buffer + GCOV_BLOCK_SIZE, 4);
591 }
370 }
592 }
371 }
593 result = &gcov_var.buffer[gcov_var.offset];
372 result = &gcov_var.buffer[gcov_var.offset];
594 gcov_var.offset += words;
373 gcov_var.offset += words;
595
374
596 return result;
375 return result;
597 }
376 }
598
377
599 /* Write unsigned VALUE to coverage file. Sets error flag
378 /* Write unsigned VALUE to coverage file. Sets error flag
600 appropriately. */
379 appropriately. */
601
380
602 GCOV_LINKAGE void
381 GCOV_LINKAGE void
603 gcov_write_unsigned (gcov_unsigned_t value)
382 gcov_write_unsigned (gcov_unsigned_t value)
604 {
383 {
605 gcov_unsigned_t *buffer = gcov_write_words (1);
384 gcov_unsigned_t *buffer = gcov_write_words (1);
606
385
607 buffer[0] = value;
386 buffer[0] = value;
608 }
387 }
609
388
610 /* Write counter VALUE to coverage file. Sets error flag
389 /* Write counter VALUE to coverage file. Sets error flag
611 appropriately. */
390 appropriately. */
612
391
613 GCOV_LINKAGE void
392 GCOV_LINKAGE void
614 gcov_write_counter (gcov_type value)
393 gcov_write_counter (gcov_type value)
615 {
394 {
616 gcov_unsigned_t *buffer = gcov_write_words (2);
395 gcov_unsigned_t *buffer = gcov_write_words (2);
617
396
618 buffer[0] = (gcov_unsigned_t) value;
397 buffer[0] = (gcov_unsigned_t) value;
619 if (sizeof (value) > sizeof (gcov_unsigned_t))
398 if (sizeof (value) > sizeof (gcov_unsigned_t))
620 buffer[1] = (gcov_unsigned_t) (value >> 32);
399 buffer[1] = (gcov_unsigned_t) (value >> 32);
621 else
400 else
622 buffer[1] = 0;
401 buffer[1] = 0;
623
402
624 // if (value < 0)
625 // gcov_var.error = -1;
626 }
403 }
627
404
628 /* Write a tag TAG and length LENGTH. */
405 /* Write a tag TAG and length LENGTH. */
629
406
630 GCOV_LINKAGE void
407 GCOV_LINKAGE void
631 gcov_write_tag_length (gcov_unsigned_t tag, gcov_unsigned_t length)
408 gcov_write_tag_length (gcov_unsigned_t tag, gcov_unsigned_t length)
632 {
409 {
633 gcov_unsigned_t *buffer = gcov_write_words (2);
410 gcov_unsigned_t *buffer = gcov_write_words (2);
634
411
635 buffer[0] = tag;
412 buffer[0] = tag;
636 buffer[1] = length;
413 buffer[1] = length;
637 }
414 }
638
415
639 /* Write a summary structure to the gcov file. Return nonzero on
416 /* Write a summary structure to the gcov file. Return nonzero on
640 overflow. */
417 overflow. */
641
418
642 GCOV_LINKAGE void
419 GCOV_LINKAGE void
643 gcov_write_summary (gcov_unsigned_t tag, const struct gcov_summary *summary)
420 gcov_write_summary (gcov_unsigned_t tag, const struct gcov_summary *summary)
644 {
421 {
645 unsigned ix;
422 unsigned ix;
646 const struct gcov_ctr_summary *csum;
423 const struct gcov_ctr_summary *csum;
647
424
648 gcov_write_tag_length (tag, GCOV_TAG_SUMMARY_LENGTH);
425 gcov_write_tag_length (tag, GCOV_TAG_SUMMARY_LENGTH);
649 gcov_write_unsigned (summary->checksum);
426 gcov_write_unsigned (summary->checksum);
650 for (csum = summary->ctrs, ix = GCOV_COUNTERS_SUMMABLE; ix--; csum++)
427 for (csum = summary->ctrs, ix = GCOV_COUNTERS_SUMMABLE; ix--; csum++)
651 {
428 {
652 gcov_write_unsigned (csum->num);
429 gcov_write_unsigned (csum->num);
653 gcov_write_unsigned (csum->runs);
430 gcov_write_unsigned (csum->runs);
654 gcov_write_counter (csum->sum_all);
431 gcov_write_counter (csum->sum_all);
655 gcov_write_counter (csum->run_max);
432 gcov_write_counter (csum->run_max);
656 gcov_write_counter (csum->sum_max);
433 gcov_write_counter (csum->sum_max);
657 }
434 }
658 }
435 }
659
436
660 /* Return a pointer to read BYTES bytes from the gcov file. Returns
661 NULL on failure (read past EOF). */
662 #if 0
663 GCOV_LINKAGE const gcov_unsigned_t *
664 gcov_read_words (unsigned words)
665 {
666 const gcov_unsigned_t *result;
667 unsigned excess = gcov_var.length - gcov_var.offset;
668
669 GCOV_CHECK_READING ();
670 if (excess < words)
671 {
672 gcov_var.start += gcov_var.offset;
673 if (excess)
674 {
675 GCOV_CHECK (excess == 1);
676 memcpy (gcov_var.buffer, gcov_var.buffer + gcov_var.offset, 4);
677 }
678 gcov_var.offset = 0;
679 gcov_var.length = excess;
680 GCOV_CHECK (!gcov_var.length || gcov_var.length == 1);
681 excess = GCOV_BLOCK_SIZE;
682 excess = fread (gcov_var.buffer + gcov_var.length,
683 1, excess << 2, gcov_var.file) >> 2;
684 gcov_var.length += excess;
685 if (gcov_var.length < words)
686 {
687 gcov_var.overread += words - gcov_var.length;
688 gcov_var.length = 0;
689 return 0;
690 }
691 }
692 result = &gcov_var.buffer[gcov_var.offset];
693 gcov_var.offset += words;
694 return result;
695 }
696
697
698 /* Read unsigned value from a coverage file. Sets error flag on file
699 error, overflow flag on overflow */
700
701 GCOV_LINKAGE gcov_unsigned_t
702 gcov_read_unsigned (void)
703 {
704 gcov_unsigned_t value;
705 const gcov_unsigned_t *buffer = gcov_read_words (1);
706
707 if (!buffer)
708 return 0;
709 value = from_file (buffer[0]);
710 return value;
711 }
712
713 /* Read counter value from a coverage file. Sets error flag on file
714 error, overflow flag on overflow */
715 #endif
716 GCOV_LINKAGE gcov_type
437 GCOV_LINKAGE gcov_type
717 gcov_read_counter (void)
438 gcov_read_counter (void)
718 {
439 {
719 #if 0
720 gcov_type value;
721 const gcov_unsigned_t *buffer = gcov_read_words (2);
722
723 if (!buffer)
724 return 0;
725 value = from_file (buffer[0]);
726 if (sizeof (value) > sizeof (gcov_unsigned_t))
727 value |= ((gcov_type) from_file (buffer[1])) << 32;
728 else if (buffer[1])
729 gcov_var.error = -1;
730
731 if (value < 0)
732 gcov_var.error = -1;
733 return value;
734 #endif
735 return 0;
440 return 0;
736 }
441 }
737 #if 0
738
739 /* Read string from coverage file. Returns a pointer to a static
740 buffer, or NULL on empty string. You must copy the string before
741 calling another gcov function. */
742
743 GCOV_LINKAGE void
744 gcov_read_summary (struct gcov_summary *summary)
745 {
746 unsigned ix;
747 struct gcov_ctr_summary *csum;
748
749 summary->checksum = gcov_read_unsigned ();
750 for (csum = summary->ctrs, ix = GCOV_COUNTERS_SUMMABLE; ix--; csum++)
751 {
752 csum->num = gcov_read_unsigned ();
753 csum->runs = gcov_read_unsigned ();
754 csum->sum_all = gcov_read_counter ();
755 csum->run_max = gcov_read_counter ();
756 csum->sum_max = gcov_read_counter ();
757 }
758 }
759
760 /* Move to the a set position in a gcov file. BASE is zero to move to
761 the end, and nonzero to move to that position. */
762
763 GCOV_LINKAGE void
764 gcov_seek (gcov_position_t base)
765 {
766 GCOV_CHECK_WRITING ();
767 if (gcov_var.offset)
768 gcov_write_block (gcov_var.offset);
769 fseek (gcov_var.file, base << 2, base ? SEEK_SET : SEEK_END);
770 gcov_var.start = ftell (gcov_var.file) >> 2;
771 }
772
773 #endif
774
442
775 /* Add a new object file onto the bb chain. Invoked automatically
443 /* Add a new object file onto the bb chain. Invoked automatically
776 when running an object file's global ctors. */
444 when running an object file's global ctors. */
777
445
778 void
446 void
779 __gcov_init (struct gcov_info *info)
447 __gcov_init (struct gcov_info *info)
780 {
448 {
781 if (!info->version)
449 if (!info->version)
782 return;
450 return;
783 if (gcov_version (info, info->version))
451 if (gcov_version (info, info->version))
784 {
452 {
785 const char *ptr = info->filename;
453 const char *ptr = info->filename;
786 gcov_unsigned_t crc32 = gcov_crc32;
454 gcov_unsigned_t crc32 = gcov_crc32;
787
455
788 /* Added by LESIA*/
456 /* Added by LESIA*/
789 /*printf("Covered file: %s\n", info->filename);*/
457 printf("Covered file: %s\n", info->filename);
790 /* End of Added by LESIA*/
458 /* End of Added by LESIA*/
791
459
792 do
460 do
793 {
461 {
794 unsigned ix;
462 unsigned ix;
795 gcov_unsigned_t value = *ptr << 24;
463 gcov_unsigned_t value = *ptr << 24;
796
464
797 for (ix = 8; ix--; value <<= 1)
465 for (ix = 8; ix--; value <<= 1)
798 {
466 {
799 gcov_unsigned_t feedback;
467 gcov_unsigned_t feedback;
800
468
801 feedback = (value ^ crc32) & 0x80000000 ? 0x04c11db7 : 0;
469 feedback = (value ^ crc32) & 0x80000000 ? 0x04c11db7 : 0;
802 crc32 <<= 1;
470 crc32 <<= 1;
803 crc32 ^= feedback;
471 crc32 ^= feedback;
804 }
472 }
805 }
473 }
806 while (*ptr++);
474 while (*ptr++);
807
475
808 gcov_crc32 = crc32;
476 gcov_crc32 = crc32;
809
477
810 if (!gcov_list)
478 if (!gcov_list)
811 atexit (gcov_exit);
479 atexit (gcov_exit);
812
480
813 info->next = gcov_list;
481 info->next = gcov_list;
814 gcov_list = info;
482 gcov_list = info;
815 }
483 }
816 else
484 else
817 printf("%s: Version mismatch\n", "WARNING");
485 printf("%s: Version mismatch\n", "WARNING");
818 info->version = 0;
486 info->version = 0;
819 }
487 }
820 //#endif /* __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ */
488 //#endif /* __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ */
@@ -1,531 +1,485
1 /* Test for GCC >= 3.4.4 && <= 4.4.6 */
1 /* Test for GCC >= 3.4.4 && <= 4.4.6 */
2 //#if ( ( __GNUC__ > 3 ) || \
2 //#if ( ( __GNUC__ > 3 ) || \
3 // ( __GNUC__ == 3 && __GNUC_MINOR__ > 4 )|| \
3 // ( __GNUC__ == 3 && __GNUC_MINOR__ > 4 )|| \
4 // ( __GNUC__ == 3 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ >= 4 ) ) && \
4 // ( __GNUC__ == 3 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ >= 4 ) ) && \
5 // ( ( __GNUC__ < 4 ) || \
5 // ( ( __GNUC__ < 4 ) || \
6 // ( __GNUC__ == 4 && __GNUC_MINOR__ < 4 )|| \
6 // ( __GNUC__ == 4 && __GNUC_MINOR__ < 4 )|| \
7 // ( __GNUC__ == 4 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ <= 6 ) )
7 // ( __GNUC__ == 4 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ <= 6 ) )
8 //#include <stdlib.h>
8 //#include <stdlib.h>
9 //#include <stdio.h>
9 //#include <stdio.h>
10 /* File format for coverage information
10 /* File format for coverage information
11 Copyright (C) 1996, 1997, 1998, 2000, 2002,
11 Copyright (C) 1996, 1997, 1998, 2000, 2002,
12 2003, 2004 Free Software Foundation, Inc.
12 2003, 2004 Free Software Foundation, Inc.
13 Contributed by Bob Manson <manson@cygnus.com>.
13 Contributed by Bob Manson <manson@cygnus.com>.
14 Completely remangled by Nathan Sidwell <nathan@codesourcery.com>.
14 Completely remangled by Nathan Sidwell <nathan@codesourcery.com>.
15
15
16 This file is part of GCC.
16 This file is part of GCC.
17
17
18 GCC is free software; you can redistribute it and/or modify it under
18 GCC is free software; you can redistribute it and/or modify it under
19 the terms of the GNU General Public License as published by the Free
19 the terms of the GNU General Public License as published by the Free
20 Software Foundation; either version 2, or (at your option) any later
20 Software Foundation; either version 2, or (at your option) any later
21 version.
21 version.
22
22
23 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
23 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
24 WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 for more details.
26 for more details.
27
27
28 You should have received a copy of the GNU General Public License
28 You should have received a copy of the GNU General Public License
29 along with GCC; see the file COPYING. If not, write to the Free
29 along with GCC; see the file COPYING. If not, write to the Free
30 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
30 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
31 02111-1307, USA. */
31 02111-1307, USA. */
32
32
33 /* As a special exception, if you link this library with other files,
33 /* As a special exception, if you link this library with other files,
34 some of which are compiled with GCC, to produce an executable,
34 some of which are compiled with GCC, to produce an executable,
35 this library does not by itself cause the resulting executable
35 this library does not by itself cause the resulting executable
36 to be covered by the GNU General Public License.
36 to be covered by the GNU General Public License.
37 This exception does not however invalidate any other reasons why
37 This exception does not however invalidate any other reasons why
38 the executable file might be covered by the GNU General Public License. */
38 the executable file might be covered by the GNU General Public License. */
39
39
40 /* Coverage information is held in two files. A notes file, which is
40 /* Coverage information is held in two files. A notes file, which is
41 generated by the compiler, and a data file, which is generated
41 generated by the compiler, and a data file, which is generated
42 by the program under test. Both files use a similar structure. We
42 by the program under test. Both files use a similar structure. We
43 do not attempt to make these files backwards compatible with
43 do not attempt to make these files backwards compatible with
44 previous versions, as you only need coverage information when
44 previous versions, as you only need coverage information when
45 developing a program. We do hold version information, so that
45 developing a program. We do hold version information, so that
46 mismatches can be detected, and we use a format that allows tools
46 mismatches can be detected, and we use a format that allows tools
47 to skip information they do not understand or are not interested
47 to skip information they do not understand or are not interested
48 in.
48 in.
49
49
50 Numbers are recorded in the 32 bit unsigned binary form of the
50 Numbers are recorded in the 32 bit unsigned binary form of the
51 endianness of the machine generating the file. 64 bit numbers are
51 endianness of the machine generating the file. 64 bit numbers are
52 stored as two 32 bit numbers, the low part first. Strings are
52 stored as two 32 bit numbers, the low part first. Strings are
53 padded with 1 to 4 NUL bytes, to bring the length up to a multiple
53 padded with 1 to 4 NUL bytes, to bring the length up to a multiple
54 of 4. The number of 4 bytes is stored, followed by the padded
54 of 4. The number of 4 bytes is stored, followed by the padded
55 string. Zero length and NULL strings are simply stored as
55 string. Zero length and NULL strings are simply stored as
56 a length of zero (they have no trailing NUL or padding).
56 a length of zero (they have no trailing NUL or padding).
57
57
58 int32: byte3 byte2 byte1 byte0 | byte0 byte1 byte2 byte3
58 int32: byte3 byte2 byte1 byte0 | byte0 byte1 byte2 byte3
59 int64: int32:low int32:high
59 int64: int32:low int32:high
60 string: int32:0 | int32:length char* char:0 padding
60 string: int32:0 | int32:length char* char:0 padding
61 padding: | char:0 | char:0 char:0 | char:0 char:0 char:0
61 padding: | char:0 | char:0 char:0 | char:0 char:0 char:0
62 item: int32 | int64 | string
62 item: int32 | int64 | string
63
63
64 The basic format of the files is
64 The basic format of the files is
65
65
66 file : int32:magic int32:version int32:stamp record*
66 file : int32:magic int32:version int32:stamp record*
67
67
68 The magic ident is different for the notes and the data files. The
68 The magic ident is different for the notes and the data files. The
69 magic ident is used to determine the endianness of the file, when
69 magic ident is used to determine the endianness of the file, when
70 reading. The version is the same for both files and is derived
70 reading. The version is the same for both files and is derived
71 from gcc's version number. The stamp value is used to synchronize
71 from gcc's version number. The stamp value is used to synchronize
72 note and data files and to synchronize merging within a data
72 note and data files and to synchronize merging within a data
73 file. It need not be an absolute time stamp, merely a ticker that
73 file. It need not be an absolute time stamp, merely a ticker that
74 increments fast enough and cycles slow enough to distinguish
74 increments fast enough and cycles slow enough to distinguish
75 different compile/run/compile cycles.
75 different compile/run/compile cycles.
76
76
77 Although the ident and version are formally 32 bit numbers, they
77 Although the ident and version are formally 32 bit numbers, they
78 are derived from 4 character ASCII strings. The version number
78 are derived from 4 character ASCII strings. The version number
79 consists of the single character major version number, a two
79 consists of the single character major version number, a two
80 character minor version number (leading zero for versions less than
80 character minor version number (leading zero for versions less than
81 10), and a single character indicating the status of the release.
81 10), and a single character indicating the status of the release.
82 That will be 'e' experimental, 'p' prerelease and 'r' for release.
82 That will be 'e' experimental, 'p' prerelease and 'r' for release.
83 Because, by good fortune, these are in alphabetical order, string
83 Because, by good fortune, these are in alphabetical order, string
84 collating can be used to compare version strings. Be aware that
84 collating can be used to compare version strings. Be aware that
85 the 'e' designation will (naturally) be unstable and might be
85 the 'e' designation will (naturally) be unstable and might be
86 incompatible with itself. For gcc 3.4 experimental, it would be
86 incompatible with itself. For gcc 3.4 experimental, it would be
87 '304e' (0x33303465). When the major version reaches 10, the
87 '304e' (0x33303465). When the major version reaches 10, the
88 letters A-Z will be used. Assuming minor increments releases every
88 letters A-Z will be used. Assuming minor increments releases every
89 6 months, we have to make a major increment every 50 years.
89 6 months, we have to make a major increment every 50 years.
90 Assuming major increments releases every 5 years, we're ok for the
90 Assuming major increments releases every 5 years, we're ok for the
91 next 155 years -- good enough for me.
91 next 155 years -- good enough for me.
92
92
93 A record has a tag, length and variable amount of data.
93 A record has a tag, length and variable amount of data.
94
94
95 record: header data
95 record: header data
96 header: int32:tag int32:length
96 header: int32:tag int32:length
97 data: item*
97 data: item*
98
98
99 Records are not nested, but there is a record hierarchy. Tag
99 Records are not nested, but there is a record hierarchy. Tag
100 numbers reflect this hierarchy. Tags are unique across note and
100 numbers reflect this hierarchy. Tags are unique across note and
101 data files. Some record types have a varying amount of data. The
101 data files. Some record types have a varying amount of data. The
102 LENGTH is the number of 4bytes that follow and is usually used to
102 LENGTH is the number of 4bytes that follow and is usually used to
103 determine how much data. The tag value is split into 4 8-bit
103 determine how much data. The tag value is split into 4 8-bit
104 fields, one for each of four possible levels. The most significant
104 fields, one for each of four possible levels. The most significant
105 is allocated first. Unused levels are zero. Active levels are
105 is allocated first. Unused levels are zero. Active levels are
106 odd-valued, so that the LSB of the level is one. A sub-level
106 odd-valued, so that the LSB of the level is one. A sub-level
107 incorporates the values of its superlevels. This formatting allows
107 incorporates the values of its superlevels. This formatting allows
108 you to determine the tag hierarchy, without understanding the tags
108 you to determine the tag hierarchy, without understanding the tags
109 themselves, and is similar to the standard section numbering used
109 themselves, and is similar to the standard section numbering used
110 in technical documents. Level values [1..3f] are used for common
110 in technical documents. Level values [1..3f] are used for common
111 tags, values [41..9f] for the notes file and [a1..ff] for the data
111 tags, values [41..9f] for the notes file and [a1..ff] for the data
112 file.
112 file.
113
113
114 The basic block graph file contains the following records
114 The basic block graph file contains the following records
115 note: unit function-graph*
115 note: unit function-graph*
116 unit: header int32:checksum string:source
116 unit: header int32:checksum string:source
117 function-graph: announce_function basic_blocks {arcs | lines}*
117 function-graph: announce_function basic_blocks {arcs | lines}*
118 announce_function: header int32:ident int32:checksum
118 announce_function: header int32:ident int32:checksum
119 string:name string:source int32:lineno
119 string:name string:source int32:lineno
120 basic_block: header int32:flags*
120 basic_block: header int32:flags*
121 arcs: header int32:block_no arc*
121 arcs: header int32:block_no arc*
122 arc: int32:dest_block int32:flags
122 arc: int32:dest_block int32:flags
123 lines: header int32:block_no line*
123 lines: header int32:block_no line*
124 int32:0 string:NULL
124 int32:0 string:NULL
125 line: int32:line_no | int32:0 string:filename
125 line: int32:line_no | int32:0 string:filename
126
126
127 The BASIC_BLOCK record holds per-bb flags. The number of blocks
127 The BASIC_BLOCK record holds per-bb flags. The number of blocks
128 can be inferred from its data length. There is one ARCS record per
128 can be inferred from its data length. There is one ARCS record per
129 basic block. The number of arcs from a bb is implicit from the
129 basic block. The number of arcs from a bb is implicit from the
130 data length. It enumerates the destination bb and per-arc flags.
130 data length. It enumerates the destination bb and per-arc flags.
131 There is one LINES record per basic block, it enumerates the source
131 There is one LINES record per basic block, it enumerates the source
132 lines which belong to that basic block. Source file names are
132 lines which belong to that basic block. Source file names are
133 introduced by a line number of 0, following lines are from the new
133 introduced by a line number of 0, following lines are from the new
134 source file. The initial source file for the function is NULL, but
134 source file. The initial source file for the function is NULL, but
135 the current source file should be remembered from one LINES record
135 the current source file should be remembered from one LINES record
136 to the next. The end of a block is indicated by an empty filename
136 to the next. The end of a block is indicated by an empty filename
137 - this does not reset the current source file. Note there is no
137 - this does not reset the current source file. Note there is no
138 ordering of the ARCS and LINES records: they may be in any order,
138 ordering of the ARCS and LINES records: they may be in any order,
139 interleaved in any manner. The current filename follows the order
139 interleaved in any manner. The current filename follows the order
140 the LINES records are stored in the file, *not* the ordering of the
140 the LINES records are stored in the file, *not* the ordering of the
141 blocks they are for.
141 blocks they are for.
142
142
143 The data file contains the following records.
143 The data file contains the following records.
144 data: {unit function-data* summary:object summary:program*}*
144 data: {unit function-data* summary:object summary:program*}*
145 unit: header int32:checksum
145 unit: header int32:checksum
146 function-data: announce_function arc_counts
146 function-data: announce_function arc_counts
147 announce_function: header int32:ident int32:checksum
147 announce_function: header int32:ident int32:checksum
148 arc_counts: header int64:count*
148 arc_counts: header int64:count*
149 summary: int32:checksum {count-summary}GCOV_COUNTERS
149 summary: int32:checksum {count-summary}GCOV_COUNTERS
150 count-summary: int32:num int32:runs int64:sum
150 count-summary: int32:num int32:runs int64:sum
151 int64:max int64:sum_max
151 int64:max int64:sum_max
152
152
153 The ANNOUNCE_FUNCTION record is the same as that in the note file,
153 The ANNOUNCE_FUNCTION record is the same as that in the note file,
154 but without the source location. The ARC_COUNTS gives the counter
154 but without the source location. The ARC_COUNTS gives the counter
155 values for those arcs that are instrumented. The SUMMARY records
155 values for those arcs that are instrumented. The SUMMARY records
156 give information about the whole object file and about the whole
156 give information about the whole object file and about the whole
157 program. The checksum is used for whole program summaries, and
157 program. The checksum is used for whole program summaries, and
158 disambiguates different programs which include the same
158 disambiguates different programs which include the same
159 instrumented object file. There may be several program summaries,
159 instrumented object file. There may be several program summaries,
160 each with a unique checksum. The object summary's checksum is zero.
160 each with a unique checksum. The object summary's checksum is zero.
161 Note that the data file might contain information from several runs
161 Note that the data file might contain information from several runs
162 concatenated, or the data might be merged.
162 concatenated, or the data might be merged.
163
163
164 This file is included by both the compiler, gcov tools and the
164 This file is included by both the compiler, gcov tools and the
165 runtime support library libgcov. IN_LIBGCOV and IN_GCOV are used to
165 runtime support library libgcov. IN_LIBGCOV and IN_GCOV are used to
166 distinguish which case is which. If IN_LIBGCOV is nonzero,
166 distinguish which case is which. If IN_LIBGCOV is nonzero,
167 libgcov is being built. If IN_GCOV is nonzero, the gcov tools are
167 libgcov is being built. If IN_GCOV is nonzero, the gcov tools are
168 being built. Otherwise the compiler is being built. IN_GCOV may be
168 being built. Otherwise the compiler is being built. IN_GCOV may be
169 positive or negative. If positive, we are compiling a tool that
169 positive or negative. If positive, we are compiling a tool that
170 requires additional functions (see the code for knowledge of what
170 requires additional functions (see the code for knowledge of what
171 those functions are). */
171 those functions are). */
172
172
173 #ifndef GCC_GCOV_IO_H
173 #ifndef GCC_GCOV_IO_H
174 #define GCC_GCOV_IO_H
174 #define GCC_GCOV_IO_H
175
175
176 typedef unsigned int gcov_unsigned_t;
176 typedef unsigned int gcov_unsigned_t;
177 typedef unsigned int gcov_position_t;
177 typedef unsigned int gcov_position_t;
178
178
179 typedef unsigned long long gcov_type;
179 typedef unsigned long long gcov_type;
180
180
181 /* No tengo ni idea de que es el SETLKW, asi que de momento el target
181 /* No tengo ni idea de que es el SETLKW, asi que de momento el target
182 * no tiene de eso */
182 * no tiene de eso */
183
183
184 //#if defined (TARGET_HAS_F_SETLKW)
184 //#if defined (TARGET_HAS_F_SETLKW)
185 //#define GCOV_LOCKED 1
185 //#define GCOV_LOCKED 1
186 //#else
186 //#else
187 #define GCOV_LOCKED 0
187 #define GCOV_LOCKED 0
188 //#endif
188 //#endif
189 //#endif
189 //#endif
190
190
191
191
192
192
193 /* In gcov we want function linkage to be static. In the compiler we want
193 /* In gcov we want function linkage to be static. In the compiler we want
194 it extern, so that they can be accessed from elsewhere. In libgcov we
194 it extern, so that they can be accessed from elsewhere. In libgcov we
195 need these functions to be extern, so prefix them with __gcov. In
195 need these functions to be extern, so prefix them with __gcov. In
196 libgcov they must also be hidden so that the instance in the executable
196 libgcov they must also be hidden so that the instance in the executable
197 is not also used in a DSO. */
197 is not also used in a DSO. */
198
198
199 #define gcov_var __gcov_var
199 #define gcov_var __gcov_var
200 #define gcov_open __gcov_open
200 #define gcov_open __gcov_open
201 #define gcov_close __gcov_close
201 #define gcov_close __gcov_close
202 #define gcov_write_tag_length __gcov_write_tag_length
202 #define gcov_write_tag_length __gcov_write_tag_length
203 #define gcov_position __gcov_position
203 #define gcov_position __gcov_position
204 #define gcov_seek __gcov_seek
204 #define gcov_seek __gcov_seek
205 #define gcov_rewrite __gcov_rewrite
205 #define gcov_rewrite __gcov_rewrite
206 #define gcov_is_error __gcov_is_error
206 #define gcov_is_error __gcov_is_error
207 #define gcov_is_eof __gcov_is_eof
207 #define gcov_is_eof __gcov_is_eof
208 #define gcov_write_unsigned __gcov_write_unsigned
208 #define gcov_write_unsigned __gcov_write_unsigned
209 #define gcov_write_counter __gcov_write_counter
209 #define gcov_write_counter __gcov_write_counter
210 #define gcov_write_summary __gcov_write_summary
210 #define gcov_write_summary __gcov_write_summary
211 #define gcov_read_unsigned __gcov_read_unsigned
211 #define gcov_read_unsigned __gcov_read_unsigned
212 #define gcov_read_counter __gcov_read_counter
212 #define gcov_read_counter __gcov_read_counter
213 #define gcov_read_summary __gcov_read_summary
213 #define gcov_read_summary __gcov_read_summary
214
214
215 /* Esto no tengo ni repajolera idea de para que vale */
215 /* Esto no tengo ni repajolera idea de para que vale */
216
216
217 /* Poison these, so they don't accidentally slip in. */
217 /* Poison these, so they don't accidentally slip in. */
218 //#pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length
218 //#pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length
219 //#pragma GCC poison gcov_read_string gcov_sync gcov_time gcov_magic
219 //#pragma GCC poison gcov_read_string gcov_sync gcov_time gcov_magic
220
220
221 #ifdef HAVE_GAS_HIDDEN
221 #ifdef HAVE_GAS_HIDDEN
222 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
222 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
223 #else
223 #else
224 #define ATTRIBUTE_HIDDEN
224 #define ATTRIBUTE_HIDDEN
225 #endif
225 #endif
226
226
227 #ifndef GCOV_LINKAGE
227 #ifndef GCOV_LINKAGE
228 #define GCOV_LINKAGE extern
228 #define GCOV_LINKAGE extern
229 //#define GCOV_LINKAGE
229 //#define GCOV_LINKAGE
230 #endif
230 #endif
231
231
232 /* File suffixes. */
232 /* File suffixes. */
233 #define GCOV_DATA_SUFFIX ".gcda"
233 #define GCOV_DATA_SUFFIX ".gcda"
234 #define GCOV_NOTE_SUFFIX ".gcno"
234 #define GCOV_NOTE_SUFFIX ".gcno"
235
235
236 /* File magic. Must not be palindromes. */
236 /* File magic. Must not be palindromes. */
237 #define GCOV_DATA_MAGIC ((gcov_unsigned_t)0x67636461) /* "gcda" */
237 #define GCOV_DATA_MAGIC ((gcov_unsigned_t)0x67636461) /* "gcda" */
238 #define GCOV_NOTE_MAGIC ((gcov_unsigned_t)0x67636e6f) /* "gcno" */
238 #define GCOV_NOTE_MAGIC ((gcov_unsigned_t)0x67636e6f) /* "gcno" */
239
239
240 /* gcov-iov.h is automatically generated by the makefile from
240 /* gcov-iov.h is automatically generated by the makefile from
241 version.c, it looks like
241 version.c, it looks like
242 #define GCOV_VERSION ((gcov_unsigned_t)0x89abcdef)
242 #define GCOV_VERSION ((gcov_unsigned_t)0x89abcdef)
243 */
243 */
244 #include "gcov-iov.h"
244 #include "gcov-iov.h"
245
245
246 /* Convert a magic or version number to a 4 character string. */
246 /* Convert a magic or version number to a 4 character string. */
247 #define GCOV_UNSIGNED2STRING(ARRAY,VALUE) \
247 #define GCOV_UNSIGNED2STRING(ARRAY,VALUE) \
248 ((ARRAY)[0] = (char)((VALUE) >> 24), \
248 ((ARRAY)[0] = (char)((VALUE) >> 24), \
249 (ARRAY)[1] = (char)((VALUE) >> 16), \
249 (ARRAY)[1] = (char)((VALUE) >> 16), \
250 (ARRAY)[2] = (char)((VALUE) >> 8), \
250 (ARRAY)[2] = (char)((VALUE) >> 8), \
251 (ARRAY)[3] = (char)((VALUE) >> 0))
251 (ARRAY)[3] = (char)((VALUE) >> 0))
252
252
253 /* The record tags. Values [1..3f] are for tags which may be in either
253 /* The record tags. Values [1..3f] are for tags which may be in either
254 file. Values [41..9f] for those in the note file and [a1..ff] for
254 file. Values [41..9f] for those in the note file and [a1..ff] for
255 the data file. */
255 the data file. */
256
256
257 #define GCOV_TAG_FUNCTION ((gcov_unsigned_t)0x01000000)
257 #define GCOV_TAG_FUNCTION ((gcov_unsigned_t)0x01000000)
258 #define GCOV_TAG_FUNCTION_LENGTH (2)
258 #define GCOV_TAG_FUNCTION_LENGTH (2)
259 #define GCOV_TAG_BLOCKS ((gcov_unsigned_t)0x01410000)
259 #define GCOV_TAG_BLOCKS ((gcov_unsigned_t)0x01410000)
260 #define GCOV_TAG_BLOCKS_LENGTH(NUM) (NUM)
260 #define GCOV_TAG_BLOCKS_LENGTH(NUM) (NUM)
261 #define GCOV_TAG_BLOCKS_NUM(LENGTH) (LENGTH)
261 #define GCOV_TAG_BLOCKS_NUM(LENGTH) (LENGTH)
262 #define GCOV_TAG_ARCS ((gcov_unsigned_t)0x01430000)
262 #define GCOV_TAG_ARCS ((gcov_unsigned_t)0x01430000)
263 #define GCOV_TAG_ARCS_LENGTH(NUM) (1 + (NUM) * 2)
263 #define GCOV_TAG_ARCS_LENGTH(NUM) (1 + (NUM) * 2)
264 #define GCOV_TAG_ARCS_NUM(LENGTH) (((LENGTH) - 1) / 2)
264 #define GCOV_TAG_ARCS_NUM(LENGTH) (((LENGTH) - 1) / 2)
265 #define GCOV_TAG_LINES ((gcov_unsigned_t)0x01450000)
265 #define GCOV_TAG_LINES ((gcov_unsigned_t)0x01450000)
266 #define GCOV_TAG_COUNTER_BASE ((gcov_unsigned_t)0x01a10000)
266 #define GCOV_TAG_COUNTER_BASE ((gcov_unsigned_t)0x01a10000)
267 #define GCOV_TAG_COUNTER_LENGTH(NUM) ((NUM) * 2)
267 #define GCOV_TAG_COUNTER_LENGTH(NUM) ((NUM) * 2)
268 #define GCOV_TAG_COUNTER_NUM(LENGTH) ((LENGTH) / 2)
268 #define GCOV_TAG_COUNTER_NUM(LENGTH) ((LENGTH) / 2)
269 #define GCOV_TAG_OBJECT_SUMMARY ((gcov_unsigned_t)0xa1000000)
269 #define GCOV_TAG_OBJECT_SUMMARY ((gcov_unsigned_t)0xa1000000)
270 #define GCOV_TAG_PROGRAM_SUMMARY ((gcov_unsigned_t)0xa3000000)
270 #define GCOV_TAG_PROGRAM_SUMMARY ((gcov_unsigned_t)0xa3000000)
271 #define GCOV_TAG_SUMMARY_LENGTH \
271 #define GCOV_TAG_SUMMARY_LENGTH \
272 (1 + GCOV_COUNTERS_SUMMABLE * (2 + 3 * 2))
272 (1 + GCOV_COUNTERS_SUMMABLE * (2 + 3 * 2))
273
273
274 /* Counters that are collected. */
274 /* Counters that are collected. */
275 #define GCOV_COUNTER_ARCS 0 /* Arc transitions. */
275 #define GCOV_COUNTER_ARCS 0 /* Arc transitions. */
276 #define GCOV_COUNTERS_SUMMABLE 1 /* Counters which can be
276 #define GCOV_COUNTERS_SUMMABLE 1 /* Counters which can be
277 summaried. */
277 summaried. */
278 #define GCOV_FIRST_VALUE_COUNTER 1 /* The first of counters used for value
278 #define GCOV_FIRST_VALUE_COUNTER 1 /* The first of counters used for value
279 profiling. They must form a consecutive
279 profiling. They must form a consecutive
280 interval and their order must match
280 interval and their order must match
281 the order of HIST_TYPEs in
281 the order of HIST_TYPEs in
282 value-prof.h. */
282 value-prof.h. */
283 #define GCOV_COUNTER_V_INTERVAL 1 /* Histogram of value inside an interval. */
283 #define GCOV_COUNTER_V_INTERVAL 1 /* Histogram of value inside an interval. */
284 #define GCOV_COUNTER_V_POW2 2 /* Histogram of exact power2 logarithm
284 #define GCOV_COUNTER_V_POW2 2 /* Histogram of exact power2 logarithm
285 of a value. */
285 of a value. */
286 #define GCOV_COUNTER_V_SINGLE 3 /* The most common value of expression. */
286 #define GCOV_COUNTER_V_SINGLE 3 /* The most common value of expression. */
287 #define GCOV_COUNTER_V_DELTA 4 /* The most common difference between
287 #define GCOV_COUNTER_V_DELTA 4 /* The most common difference between
288 consecutive values of expression. */
288 consecutive values of expression. */
289 #define GCOV_LAST_VALUE_COUNTER 4 /* The last of counters used for value
289 #define GCOV_LAST_VALUE_COUNTER 4 /* The last of counters used for value
290 profiling. */
290 profiling. */
291 #define GCOV_COUNTERS 5
291 #define GCOV_COUNTERS 5
292
292
293 /* Number of counters used for value profiling. */
293 /* Number of counters used for value profiling. */
294 #define GCOV_N_VALUE_COUNTERS \
294 #define GCOV_N_VALUE_COUNTERS \
295 (GCOV_LAST_VALUE_COUNTER - GCOV_FIRST_VALUE_COUNTER + 1)
295 (GCOV_LAST_VALUE_COUNTER - GCOV_FIRST_VALUE_COUNTER + 1)
296
296
297 /* A list of human readable names of the counters */
297 /* A list of human readable names of the counters */
298 #define GCOV_COUNTER_NAMES {"arcs", "interval", "pow2", "single", "delta"}
298 #define GCOV_COUNTER_NAMES {"arcs", "interval", "pow2", "single", "delta"}
299
299
300 /* Names of merge functions for counters. */
300 /* Names of merge functions for counters. */
301 #define GCOV_MERGE_FUNCTIONS {"__gcov_merge_add", \
301 #define GCOV_MERGE_FUNCTIONS {"__gcov_merge_add", \
302 "__gcov_merge_add", \
302 "__gcov_merge_add", \
303 "__gcov_merge_add", \
303 "__gcov_merge_add", \
304 "__gcov_merge_single", \
304 "__gcov_merge_single", \
305 "__gcov_merge_delta"}
305 "__gcov_merge_delta"}
306
306
307 /* Convert a counter index to a tag. */
307 /* Convert a counter index to a tag. */
308 #define GCOV_TAG_FOR_COUNTER(COUNT) \
308 #define GCOV_TAG_FOR_COUNTER(COUNT) \
309 (GCOV_TAG_COUNTER_BASE + ((gcov_unsigned_t)(COUNT) << 17))
309 (GCOV_TAG_COUNTER_BASE + ((gcov_unsigned_t)(COUNT) << 17))
310 /* Convert a tag to a counter. */
310 /* Convert a tag to a counter. */
311 #define GCOV_COUNTER_FOR_TAG(TAG) \
311 #define GCOV_COUNTER_FOR_TAG(TAG) \
312 ((unsigned)(((TAG) - GCOV_TAG_COUNTER_BASE) >> 17))
312 ((unsigned)(((TAG) - GCOV_TAG_COUNTER_BASE) >> 17))
313 /* Check whether a tag is a counter tag. */
313 /* Check whether a tag is a counter tag. */
314 #define GCOV_TAG_IS_COUNTER(TAG) \
314 #define GCOV_TAG_IS_COUNTER(TAG) \
315 (!((TAG) & 0xFFFF) && GCOV_COUNTER_FOR_TAG (TAG) < GCOV_COUNTERS)
315 (!((TAG) & 0xFFFF) && GCOV_COUNTER_FOR_TAG (TAG) < GCOV_COUNTERS)
316
316
317 /* The tag level mask has 1's in the position of the inner levels, &
317 /* The tag level mask has 1's in the position of the inner levels, &
318 the lsb of the current level, and zero on the current and outer
318 the lsb of the current level, and zero on the current and outer
319 levels. */
319 levels. */
320 #define GCOV_TAG_MASK(TAG) (((TAG) - 1) ^ (TAG))
320 #define GCOV_TAG_MASK(TAG) (((TAG) - 1) ^ (TAG))
321
321
322 /* Return nonzero if SUB is an immediate subtag of TAG. */
322 /* Return nonzero if SUB is an immediate subtag of TAG. */
323 #define GCOV_TAG_IS_SUBTAG(TAG,SUB) \
323 #define GCOV_TAG_IS_SUBTAG(TAG,SUB) \
324 (GCOV_TAG_MASK (TAG) >> 8 == GCOV_TAG_MASK (SUB) \
324 (GCOV_TAG_MASK (TAG) >> 8 == GCOV_TAG_MASK (SUB) \
325 && !(((SUB) ^ (TAG)) & ~GCOV_TAG_MASK(TAG)))
325 && !(((SUB) ^ (TAG)) & ~GCOV_TAG_MASK(TAG)))
326
326
327 /* Return nonzero if SUB is at a sublevel to TAG. */
327 /* Return nonzero if SUB is at a sublevel to TAG. */
328 #define GCOV_TAG_IS_SUBLEVEL(TAG,SUB) \
328 #define GCOV_TAG_IS_SUBLEVEL(TAG,SUB) \
329 (GCOV_TAG_MASK (TAG) > GCOV_TAG_MASK (SUB))
329 (GCOV_TAG_MASK (TAG) > GCOV_TAG_MASK (SUB))
330
330
331 /* Basic block flags. */
331 /* Basic block flags. */
332 #define GCOV_BLOCK_UNEXPECTED (1 << 1)
332 #define GCOV_BLOCK_UNEXPECTED (1 << 1)
333
333
334 /* Arc flags. */
334 /* Arc flags. */
335 #define GCOV_ARC_ON_TREE (1 << 0)
335 #define GCOV_ARC_ON_TREE (1 << 0)
336 #define GCOV_ARC_FAKE (1 << 1)
336 #define GCOV_ARC_FAKE (1 << 1)
337 #define GCOV_ARC_FALLTHROUGH (1 << 2)
337 #define GCOV_ARC_FALLTHROUGH (1 << 2)
338
338
339 /* Structured records. */
339 /* Structured records. */
340
340
341 /* Cumulative counter data. */
341 /* Cumulative counter data. */
342 struct gcov_ctr_summary
342 struct gcov_ctr_summary
343 {
343 {
344 gcov_unsigned_t num; /* number of counters. */
344 gcov_unsigned_t num; /* number of counters. */
345 gcov_unsigned_t runs; /* number of program runs */
345 gcov_unsigned_t runs; /* number of program runs */
346 gcov_type sum_all; /* sum of all counters accumulated. */
346 gcov_type sum_all; /* sum of all counters accumulated. */
347 gcov_type run_max; /* maximum value on a single run. */
347 gcov_type run_max; /* maximum value on a single run. */
348 gcov_type sum_max; /* sum of individual run max values. */
348 gcov_type sum_max; /* sum of individual run max values. */
349 };
349 };
350
350
351
351
352 /* Object & program summary record. */
352 /* Object & program summary record. */
353 struct gcov_summary
353 struct gcov_summary
354 {
354 {
355 gcov_unsigned_t checksum; /* checksum of program */
355 gcov_unsigned_t checksum; /* checksum of program */
356 struct gcov_ctr_summary ctrs[GCOV_COUNTERS_SUMMABLE];
356 struct gcov_ctr_summary ctrs[GCOV_COUNTERS_SUMMABLE];
357 };
357 };
358
358
359 /* Structures embedded in coveraged program. The structures generated
359 /* Structures embedded in coveraged program. The structures generated
360 by write_profile must match these. */
360 by write_profile must match these. */
361
361
362 /* Information about a single function. This uses the trailing array
362 /* Information about a single function. This uses the trailing array
363 idiom. The number of counters is determined from the counter_mask
363 idiom. The number of counters is determined from the counter_mask
364 in gcov_info. We hold an array of function info, so have to
364 in gcov_info. We hold an array of function info, so have to
365 explicitly calculate the correct array stride. */
365 explicitly calculate the correct array stride. */
366 struct gcov_fn_info
366 struct gcov_fn_info
367 {
367 {
368 gcov_unsigned_t ident; /* unique ident of function */
368 gcov_unsigned_t ident; /* unique ident of function */
369 gcov_unsigned_t checksum; /* function checksum */
369 gcov_unsigned_t checksum; /* function checksum */
370 unsigned n_ctrs[0]; /* instrumented counters */
370 unsigned n_ctrs[0]; /* instrumented counters */
371 };
371 };
372
372
373 /* Type of function used to merge counters. */
373 /* Type of function used to merge counters. */
374 typedef void (*gcov_merge_fn) (gcov_type *, gcov_unsigned_t);
374 typedef void (*gcov_merge_fn) (gcov_type *, gcov_unsigned_t);
375
375
376 /* Information about counters. */
376 /* Information about counters. */
377 struct gcov_ctr_info
377 struct gcov_ctr_info
378 {
378 {
379 gcov_unsigned_t num; /* number of counters. */
379 gcov_unsigned_t num; /* number of counters. */
380 gcov_type *values; /* their values. */
380 gcov_type *values; /* their values. */
381 gcov_merge_fn merge; /* The function used to merge them. */
381 gcov_merge_fn merge; /* The function used to merge them. */
382 };
382 };
383
383
384 /* Information about a single object file. */
384 /* Information about a single object file. */
385 struct gcov_info
385 struct gcov_info
386 {
386 {
387 gcov_unsigned_t version; /* expected version number */
387 gcov_unsigned_t version; /* expected version number */
388 struct gcov_info *next; /* link to next, used by libgcov */
388 struct gcov_info *next; /* link to next, used by libgcov */
389
389
390 gcov_unsigned_t stamp; /* uniquifying time stamp */
390 gcov_unsigned_t stamp; /* uniquifying time stamp */
391 const char *filename; /* output file name */
391 const char *filename; /* output file name */
392
392
393 unsigned n_functions; /* number of functions */
393 unsigned n_functions; /* number of functions */
394 const struct gcov_fn_info *functions; /* table of functions */
394 const struct gcov_fn_info *functions; /* table of functions */
395
395
396 unsigned ctr_mask; /* mask of counters instrumented. */
396 unsigned ctr_mask; /* mask of counters instrumented. */
397 struct gcov_ctr_info counts[0]; /* count data. The number of bits
397 struct gcov_ctr_info counts[0]; /* count data. The number of bits
398 set in the ctr_mask field
398 set in the ctr_mask field
399 determines how big this array
399 determines how big this array
400 is. */
400 is. */
401 };
401 };
402
402
403 /* Register a new object file module. */
403 /* Register a new object file module. */
404 extern void __gcov_init (struct gcov_info *) ATTRIBUTE_HIDDEN;
404 extern void __gcov_init (struct gcov_info *) ATTRIBUTE_HIDDEN;
405
405
406 /* Called before fork, to avoid double counting. */
406 /* Called before fork, to avoid double counting. */
407 extern void __gcov_flush (void) ATTRIBUTE_HIDDEN;
407 extern void __gcov_flush (void) ATTRIBUTE_HIDDEN;
408
408
409 /* The merge function that just sums the counters. */
409 /* The merge function that just sums the counters. */
410 extern void __gcov_merge_add (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
410 extern void __gcov_merge_add (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
411
411
412 /* The merge function to choose the most common value. */
412 /* The merge function to choose the most common value. */
413 extern void __gcov_merge_single (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
413 extern void __gcov_merge_single (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
414
414
415 /* The merge function to choose the most common difference between
415 /* The merge function to choose the most common difference between
416 consecutive values. */
416 consecutive values. */
417 extern void __gcov_merge_delta (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
417 extern void __gcov_merge_delta (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
418
418
419 /* Optimum number of gcov_unsigned_t's read from or written to disk. */
419 /* Optimum number of gcov_unsigned_t's read from or written to disk. */
420 // We limit GCOV_BLOCK_SIZE to 512 unsigned long because post processing with
420 // We limit GCOV_BLOCK_SIZE to 512 unsigned long because post processing with
421 // DOS batch cannot handle command lines bigger than 8191 characters, knowing
421 // DOS batch cannot handle command lines bigger than 8191 characters, knowing
422 // that for each char, we print 4 characters (e.g "\x00")
422 // that for each char, we print 4 characters (e.g "\x00")
423 #define GCOV_BLOCK_SIZE (1 << 8)
423 #define GCOV_BLOCK_SIZE (1 << 11)
424 #define MAXFILENAME (1024)
424 #define MAXFILENAME (1024)
425
425
426 GCOV_LINKAGE struct gcov_var
426 GCOV_LINKAGE struct gcov_var
427 {
427 {
428 // FILE *file;
428 // FILE *file;
429 char filename[MAXFILENAME];
429 char filename[MAXFILENAME];
430 gcov_position_t start; /* Position of first byte of block */
430 gcov_position_t start; /* Position of first byte of block */
431 unsigned offset; /* Read/write position within the block. */
431 unsigned offset; /* Read/write position within the block. */
432 unsigned length; /* Read limit in the block. */
432 unsigned length; /* Read limit in the block. */
433 unsigned overread; /* Number of words overread. */
433 unsigned overread; /* Number of words overread. */
434 int error; /* < 0 overflow, > 0 disk error. */
434 int error; /* < 0 overflow, > 0 disk error. */
435 /* Holds one block plus 4 bytes, thus all coverage reads & writes
435 /* Holds one block plus 4 bytes, thus all coverage reads & writes
436 fit within this buffer and we always can transfer GCOV_BLOCK_SIZE
436 fit within this buffer and we always can transfer GCOV_BLOCK_SIZE
437 to and from the disk. libgcov never backtracks and only writes 4
437 to and from the disk. libgcov never backtracks and only writes 4
438 or 8 byte objects. */
438 or 8 byte objects. */
439 gcov_unsigned_t buffer[GCOV_BLOCK_SIZE + 1];
439 gcov_unsigned_t buffer[GCOV_BLOCK_SIZE + 1];
440 } gcov_var ATTRIBUTE_HIDDEN;
440 } gcov_var ATTRIBUTE_HIDDEN;
441
441
442 #if 1
442 #if 1
443 /* Functions for reading and writing gcov files. In libgcov you can
443 /* Functions for reading and writing gcov files. In libgcov you can
444 open the file for reading then writing. Elsewhere you can open the
444 open the file for reading then writing. Elsewhere you can open the
445 file either for reading or for writing. When reading a file you may
445 file either for reading or for writing. When reading a file you may
446 use the gcov_read_* functions, gcov_sync, gcov_position, &
446 use the gcov_read_* functions, gcov_sync, gcov_position, &
447 gcov_error. When writing a file you may use the gcov_write
447 gcov_error. When writing a file you may use the gcov_write
448 functions, gcov_seek & gcov_error. When a file is to be rewritten
448 functions, gcov_seek & gcov_error. When a file is to be rewritten
449 you use the functions for reading, then gcov_rewrite then the
449 you use the functions for reading, then gcov_rewrite then the
450 functions for writing. Your file may become corrupted if you break
450 functions for writing. Your file may become corrupted if you break
451 these invariants. */
451 these invariants. */
452 GCOV_LINKAGE int gcov_open (const char */*name*/) ATTRIBUTE_HIDDEN;
452 GCOV_LINKAGE int gcov_open (const char */*name*/) ATTRIBUTE_HIDDEN;
453 GCOV_LINKAGE int gcov_close (void) ATTRIBUTE_HIDDEN;
453 GCOV_LINKAGE int gcov_close (void) ATTRIBUTE_HIDDEN;
454
454
455 /* Available everywhere. */
455 /* Available everywhere. */
456 /* static gcov_position_t gcov_position (void);
456 /* static gcov_position_t gcov_position (void);
457 * static int gcov_is_error (void);
457 * static int gcov_is_error (void);
458 * static int gcov_is_eof (void);
458 * static int gcov_is_eof (void);
459 */
459 */
460
460
461 GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned (void) ATTRIBUTE_HIDDEN;
461 GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned (void) ATTRIBUTE_HIDDEN;
462 GCOV_LINKAGE gcov_type gcov_read_counter (void) ATTRIBUTE_HIDDEN;
462 GCOV_LINKAGE gcov_type gcov_read_counter (void) ATTRIBUTE_HIDDEN;
463 GCOV_LINKAGE void gcov_read_summary (struct gcov_summary *) ATTRIBUTE_HIDDEN;
463 GCOV_LINKAGE void gcov_read_summary (struct gcov_summary *) ATTRIBUTE_HIDDEN;
464 #endif
464 #endif
465 /* Available only in libgcov */
465 /* Available only in libgcov */
466 GCOV_LINKAGE void gcov_write_counter (gcov_type) ATTRIBUTE_HIDDEN;
466 GCOV_LINKAGE void gcov_write_counter (gcov_type) ATTRIBUTE_HIDDEN;
467 GCOV_LINKAGE void gcov_write_tag_length (gcov_unsigned_t,
467 GCOV_LINKAGE void gcov_write_tag_length (gcov_unsigned_t,
468 gcov_unsigned_t) ATTRIBUTE_HIDDEN;
468 gcov_unsigned_t) ATTRIBUTE_HIDDEN;
469 GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/,
469 GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/,
470 const struct gcov_summary *) ATTRIBUTE_HIDDEN;
470 const struct gcov_summary *) ATTRIBUTE_HIDDEN;
471
471
472 /* Available outside gcov */
472 /* Available outside gcov */
473 GCOV_LINKAGE void gcov_write_unsigned (gcov_unsigned_t) ATTRIBUTE_HIDDEN;
473 GCOV_LINKAGE void gcov_write_unsigned (gcov_unsigned_t) ATTRIBUTE_HIDDEN;
474
474
475 /* Make sure the library is used correctly. */
475 /* Make sure the library is used correctly. */
476 #if ENABLE_CHECKING
476 #if ENABLE_CHECKING
477 #define GCOV_CHECK(expr) ((expr) ? (void)0 : (void)abort ())
477 #define GCOV_CHECK(expr) ((expr) ? (void)0 : (void)abort ())
478 #else
478 #else
479 #define GCOV_CHECK(expr)
479 #define GCOV_CHECK(expr)
480 #endif
480 #endif
481 #define GCOV_CHECK_READING() GCOV_CHECK(gcov_var.mode > 0)
481 #define GCOV_CHECK_READING() GCOV_CHECK(gcov_var.mode > 0)
482 #define GCOV_CHECK_WRITING() GCOV_CHECK(gcov_var.mode < 0)
482 #define GCOV_CHECK_WRITING() GCOV_CHECK(gcov_var.mode < 0)
483 #if 0
484 /* Save the current position in the gcov file. */
485
483
486 static inline gcov_position_t
487 gcov_position (void)
488 {
489 GCOV_CHECK_READING ();
490 return gcov_var.start + gcov_var.offset;
491 }
492
493 /* Return nonzero if we read to end of file. */
494
495 static inline int
496 gcov_is_eof (void)
497 {
498 return !gcov_var.overread;
499 }
500
501 /* Return nonzero if the error flag is set. */
502
503 static inline int
504 gcov_is_error (void)
505 {
506 return gcov_var.file ? gcov_var.error : 1;
507 }
508
509 /* Move to beginning of file and initialize for writing. */
510
511 static inline void
512 gcov_rewrite (void)
513 {
514 GCOV_CHECK_READING ();
515 gcov_var.mode = -1;
516 gcov_var.start = 0;
517 gcov_var.offset = 0;
518 fseek (gcov_var.file, 0L, SEEK_SET);
519 }
520
521 #ifdef __MINGW32__
522 #define ftruncate _chsize
523 #endif
524 static inline void
525 gcov_truncate (void)
526 {
527 ftruncate (fileno (gcov_var.file), 0L);
528 }
529 #endif
530 #endif /* GCC_GCOV_IO_H */
484 #endif /* GCC_GCOV_IO_H */
531 //#endif /* __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ */
485 //#endif /* __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ */
@@ -1,133 +1,134
1 /* Test for GCC >= 3.4.4 && <= 4.4.6 */
1 /* Test for GCC >= 3.4.4 && <= 4.4.6 */
2 #if ( ( __GNUC__ > 3 ) || \
2 /*#if ( ( __GNUC__ > 3 ) || \
3 ( __GNUC__ == 3 && __GNUC_MINOR__ > 4 )|| \
3 ( __GNUC__ == 3 && __GNUC_MINOR__ > 4 )|| \
4 ( __GNUC__ == 3 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ >= 4 ) ) && \
4 ( __GNUC__ == 3 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ >= 4 ) ) && \
5 ( ( __GNUC__ < 4 ) || \
5 ( ( __GNUC__ < 4 ) || \
6 ( __GNUC__ == 4 && __GNUC_MINOR__ < 4 )|| \
6 ( __GNUC__ == 4 && __GNUC_MINOR__ < 4 )|| \
7 ( __GNUC__ == 4 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ <= 6 ) )
7 ( __GNUC__ == 4 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ <= 6 ) )
8 */
8 /* Routines required for instrumenting a program. */
9 /* Routines required for instrumenting a program. */
9 /* Compile this one with gcc. */
10 /* Compile this one with gcc. */
10 /* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
11 /* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
11 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
12 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
12
13
13 This file is part of GCC.
14 This file is part of GCC.
14
15
15 GCC is free software; you can redistribute it and/or modify it under
16 GCC is free software; you can redistribute it and/or modify it under
16 the terms of the GNU General Public License as published by the Free
17 the terms of the GNU General Public License as published by the Free
17 Software Foundation; either version 2, or (at your option) any later
18 Software Foundation; either version 2, or (at your option) any later
18 version.
19 version.
19
20
20 In addition to the permissions in the GNU General Public License, the
21 In addition to the permissions in the GNU General Public License, the
21 Free Software Foundation gives you unlimited permission to link the
22 Free Software Foundation gives you unlimited permission to link the
22 compiled version of this file into combinations with other programs,
23 compiled version of this file into combinations with other programs,
23 and to distribute those combinations without any restriction coming
24 and to distribute those combinations without any restriction coming
24 from the use of this file. (The General Public License restrictions
25 from the use of this file. (The General Public License restrictions
25 do apply in other respects; for example, they cover modification of
26 do apply in other respects; for example, they cover modification of
26 the file, and distribution when not linked into a combine
27 the file, and distribution when not linked into a combine
27 executable.)
28 executable.)
28
29
29 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
30 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
30 WARRANTY; without even the implied warranty of MERCHANTABILITY or
31 WARRANTY; without even the implied warranty of MERCHANTABILITY or
31 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
32 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
32 for more details.
33 for more details.
33
34
34 You should have received a copy of the GNU General Public License
35 You should have received a copy of the GNU General Public License
35 along with GCC; see the file COPYING. If not, write to the Free
36 along with GCC; see the file COPYING. If not, write to the Free
36 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
37 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
37 02111-1307, USA. */
38 02111-1307, USA. */
38
39
39 #define GCOV_LINKAGE /* nothing */
40 #define GCOV_LINKAGE /* nothing */
40
41
41 #include "gcov-io.h"
42 #include "gcov-io.h"
42
43
43 /* Chain of per-object gcov structures. */
44 /* Chain of per-object gcov structures. */
44 struct gcov_info *gcov_list;
45 struct gcov_info *gcov_list;
45
46
46 /* A program checksum allows us to distinguish program data for an
47 /* A program checksum allows us to distinguish program data for an
47 object file included in multiple programs. */
48 object file included in multiple programs. */
48 gcov_unsigned_t gcov_crc32;
49 gcov_unsigned_t gcov_crc32;
49
50
50 /* The profile merging function that just adds the counters. It is given
51 /* The profile merging function that just adds the counters. It is given
51 an array COUNTERS of N_COUNTERS old counters and it reads the same number
52 an array COUNTERS of N_COUNTERS old counters and it reads the same number
52 of counters from the gcov file. */
53 of counters from the gcov file. */
53 void
54 void
54 __gcov_merge_add (gcov_type *counters, unsigned n_counters)
55 __gcov_merge_add (gcov_type *counters, unsigned n_counters)
55 {
56 {
56 for (; n_counters; counters++, n_counters--)
57 for (; n_counters; counters++, n_counters--)
57 *counters += gcov_read_counter ();
58 *counters += gcov_read_counter ();
58 }
59 }
59 /* The profile merging function for choosing the most common value.
60 /* The profile merging function for choosing the most common value.
60 It is given an array COUNTERS of N_COUNTERS old counters and it
61 It is given an array COUNTERS of N_COUNTERS old counters and it
61 reads the same number of counters from the gcov file. The counters
62 reads the same number of counters from the gcov file. The counters
62 are split into 3-tuples where the members of the tuple have
63 are split into 3-tuples where the members of the tuple have
63 meanings:
64 meanings:
64
65
65 -- the stored candidate on the most common value of the measured entity
66 -- the stored candidate on the most common value of the measured entity
66 -- counter
67 -- counter
67 -- total number of evaluations of the value */
68 -- total number of evaluations of the value */
68 void
69 void
69 __gcov_merge_single (gcov_type *counters, unsigned n_counters)
70 __gcov_merge_single (gcov_type *counters, unsigned n_counters)
70 {
71 {
71 unsigned i, n_measures;
72 unsigned i, n_measures;
72 gcov_type value, counter, all;
73 gcov_type value, counter, all;
73
74
74 GCOV_CHECK (!(n_counters % 3));
75 GCOV_CHECK (!(n_counters % 3));
75 n_measures = n_counters / 3;
76 n_measures = n_counters / 3;
76 for (i = 0; i < n_measures; i++, counters += 3)
77 for (i = 0; i < n_measures; i++, counters += 3)
77 {
78 {
78 value = gcov_read_counter ();
79 value = gcov_read_counter ();
79 counter = gcov_read_counter ();
80 counter = gcov_read_counter ();
80 all = gcov_read_counter ();
81 all = gcov_read_counter ();
81
82
82 if (counters[0] == value)
83 if (counters[0] == value)
83 counters[1] += counter;
84 counters[1] += counter;
84 else if (counter > counters[1])
85 else if (counter > counters[1])
85 {
86 {
86 counters[0] = value;
87 counters[0] = value;
87 counters[1] = counter - counters[1];
88 counters[1] = counter - counters[1];
88 }
89 }
89 else
90 else
90 counters[1] -= counter;
91 counters[1] -= counter;
91 counters[2] += all;
92 counters[2] += all;
92 }
93 }
93 }
94 }
94
95
95 /* The profile merging function for choosing the most common
96 /* The profile merging function for choosing the most common
96 difference between two consecutive evaluations of the value. It is
97 difference between two consecutive evaluations of the value. It is
97 given an array COUNTERS of N_COUNTERS old counters and it reads the
98 given an array COUNTERS of N_COUNTERS old counters and it reads the
98 same number of counters from the gcov file. The counters are split
99 same number of counters from the gcov file. The counters are split
99 into 4-tuples where the members of the tuple have meanings:
100 into 4-tuples where the members of the tuple have meanings:
100
101
101 -- the last value of the measured entity
102 -- the last value of the measured entity
102 -- the stored candidate on the most common difference
103 -- the stored candidate on the most common difference
103 -- counter
104 -- counter
104 -- total number of evaluations of the value */
105 -- total number of evaluations of the value */
105
106
106 void
107 void
107 __gcov_merge_delta (gcov_type *counters, unsigned n_counters)
108 __gcov_merge_delta (gcov_type *counters, unsigned n_counters)
108 {
109 {
109 unsigned i, n_measures;
110 unsigned i, n_measures;
110 gcov_type last, value, counter, all;
111 gcov_type last, value, counter, all;
111
112
112 GCOV_CHECK (!(n_counters % 4));
113 GCOV_CHECK (!(n_counters % 4));
113 n_measures = n_counters / 4;
114 n_measures = n_counters / 4;
114 for (i = 0; i < n_measures; i++, counters += 4)
115 for (i = 0; i < n_measures; i++, counters += 4)
115 {
116 {
116 last = gcov_read_counter ();
117 last = gcov_read_counter ();
117 value = gcov_read_counter ();
118 value = gcov_read_counter ();
118 counter = gcov_read_counter ();
119 counter = gcov_read_counter ();
119 all = gcov_read_counter ();
120 all = gcov_read_counter ();
120
121
121 if (counters[1] == value)
122 if (counters[1] == value)
122 counters[2] += counter;
123 counters[2] += counter;
123 else if (counter > counters[2])
124 else if (counter > counters[2])
124 {
125 {
125 counters[1] = value;
126 counters[1] = value;
126 counters[2] = counter - counters[2];
127 counters[2] = counter - counters[2];
127 }
128 }
128 else
129 else
129 counters[2] -= counter;
130 counters[2] -= counter;
130 counters[3] += all;
131 counters[3] += all;
131 }
132 }
132 }
133 }
133 #endif /* __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ */
134 //#endif /* __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ */
@@ -1,44 +1,44
1 set(rtems_dir /opt/rtems-4.10/)
1 set(rtems_dir /opt/rtems-4.10/)
2
2
3 set(CMAKE_SYSTEM_NAME rtems)
3 set(CMAKE_SYSTEM_NAME rtems)
4 set(CMAKE_C_COMPILER ${rtems_dir}/bin/sparc-rtems-gcc)
4 set(CMAKE_C_COMPILER ${rtems_dir}/bin/sparc-rtems-gcc)
5 set(CMAKE_CXX_COMPILER ${rtems_dir}/bin/sparc-rtems-g++)
5 set(CMAKE_CXX_COMPILER ${rtems_dir}/bin/sparc-rtems-g++)
6 set(CMAKE_LINKER ${rtems_dir}/bin/sparc-rtems-g++)
6 set(CMAKE_LINKER ${rtems_dir}/bin/sparc-rtems-g++)
7 SET(CMAKE_EXE_LINKER_FLAGS "-static")
7 SET(CMAKE_EXE_LINKER_FLAGS "-static")
8 option(fix-b2bst "Activate -mfix-b2bst switch to mitigate \"LEON3FT Stale Cache Entry After Store with Data Tag Parity Error\" errata, GRLIB-TN-0009" ON)
8 option(fix-b2bst "Activate -mfix-b2bst switch to mitigate \"LEON3FT Stale Cache Entry After Store with Data Tag Parity Error\" errata, GRLIB-TN-0009" ON)
9
9
10 option(Coverage "Enables code coverage" OFF)
10 option(Coverage "Enables code coverage" OFF)
11
11
12
12
13 set(CMAKE_C_FLAGS_RELEASE "-O3")
13 set(CMAKE_C_FLAGS_RELEASE "-O3")
14 set(CMAKE_C_FLAGS_DEBUG "-O0")
14 set(CMAKE_C_FLAGS_DEBUG "-O0")
15
15
16
16
17 if(fix-b2bst)
17 if(fix-b2bst)
18 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mfix-b2bst")
18 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mfix-b2bst")
19 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mfix-b2bst")
19 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mfix-b2bst")
20 endif()
20 endif()
21
21
22 if(Coverage)
22 #if(Coverage)
23 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage")
23 # set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage")
24 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
24 # set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
25 endif()
25 #endif()
26
26
27
27
28 set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <FLAGS> -Xlinker -Map=<TARGET>.map <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
28 set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <FLAGS> -Xlinker -Map=<TARGET>.map <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
29
29
30 include_directories("${rtems_dir}/sparc-rtems/leon3/lib/include")
30 include_directories("${rtems_dir}/sparc-rtems/leon3/lib/include")
31
31
32 function (check_b2bst target bin)
32 function (check_b2bst target bin)
33 add_custom_command(TARGET ${target}
33 add_custom_command(TARGET ${target}
34 POST_BUILD
34 POST_BUILD
35 COMMAND ${rtems_dir}/bin/sparc-rtems-objdump -d ${bin}/${target} | ${CMAKE_SOURCE_DIR}/sparc/leon3ft-b2bst-scan.tcl
35 COMMAND ${rtems_dir}/bin/sparc-rtems-objdump -d ${bin}/${target} | ${CMAKE_SOURCE_DIR}/sparc/leon3ft-b2bst-scan.tcl
36 )
36 )
37 endfunction()
37 endfunction()
38
38
39 function (build_srec target bin rev)
39 function (build_srec target bin rev)
40 add_custom_command(TARGET ${target}
40 add_custom_command(TARGET ${target}
41 POST_BUILD
41 POST_BUILD
42 COMMAND ${rtems_dir}/bin/sparc-rtems-objcopy -j .data -F srec ${bin}/${target} RpwLfrApp_XXXX_data_rev-${rev}.srec && ${rtems_dir}/bin/sparc-rtems-objcopy -j .text -F srec ${bin}/${target} RpwLfrApp_XXXX_text_rev-${rev}.srec
42 COMMAND ${rtems_dir}/bin/sparc-rtems-objcopy -j .data -F srec ${bin}/${target} RpwLfrApp_XXXX_data_rev-${rev}.srec && ${rtems_dir}/bin/sparc-rtems-objcopy -j .text -F srec ${bin}/${target} RpwLfrApp_XXXX_text_rev-${rev}.srec
43 )
43 )
44 endfunction()
44 endfunction()
@@ -1,124 +1,125
1 cmake_minimum_required (VERSION 2.6)
1 cmake_minimum_required (VERSION 2.6)
2 project (fsw)
2 project (fsw)
3
3
4 include(sparc-rtems)
4 include(sparc-rtems)
5 include(cppcheck)
5 include(cppcheck)
6
6
7 include_directories("../header"
7 include_directories("../header"
8 "../header/lfr_common_headers"
8 "../header/lfr_common_headers"
9 "../header/processing"
9 "../header/processing"
10 "../LFR_basic-parameters"
10 "../LFR_basic-parameters"
11 "../src")
11 "../src")
12
12
13 set(SOURCES wf_handler.c
13 set(SOURCES wf_handler.c
14 tc_handler.c
14 tc_handler.c
15 fsw_misc.c
15 fsw_misc.c
16 fsw_init.c
16 fsw_init.c
17 fsw_globals.c
17 fsw_globals.c
18 fsw_spacewire.c
18 fsw_spacewire.c
19 tc_load_dump_parameters.c
19 tc_load_dump_parameters.c
20 tm_lfr_tc_exe.c
20 tm_lfr_tc_exe.c
21 tc_acceptance.c
21 tc_acceptance.c
22 processing/fsw_processing.c
22 processing/fsw_processing.c
23 processing/avf0_prc0.c
23 processing/avf0_prc0.c
24 processing/avf1_prc1.c
24 processing/avf1_prc1.c
25 processing/avf2_prc2.c
25 processing/avf2_prc2.c
26 lfr_cpu_usage_report.c
26 lfr_cpu_usage_report.c
27 ${LFR_BP_SRC}
27 ${LFR_BP_SRC}
28 ../header/wf_handler.h
28 ../header/wf_handler.h
29 ../header/tc_handler.h
29 ../header/tc_handler.h
30 ../header/grlib_regs.h
30 ../header/grlib_regs.h
31 ../header/fsw_misc.h
31 ../header/fsw_misc.h
32 ../header/fsw_init.h
32 ../header/fsw_init.h
33 ../header/fsw_spacewire.h
33 ../header/fsw_spacewire.h
34 ../header/tc_load_dump_parameters.h
34 ../header/tc_load_dump_parameters.h
35 ../header/tm_lfr_tc_exe.h
35 ../header/tm_lfr_tc_exe.h
36 ../header/tc_acceptance.h
36 ../header/tc_acceptance.h
37 ../header/processing/fsw_processing.h
37 ../header/processing/fsw_processing.h
38 ../header/processing/avf0_prc0.h
38 ../header/processing/avf0_prc0.h
39 ../header/processing/avf1_prc1.h
39 ../header/processing/avf1_prc1.h
40 ../header/processing/avf2_prc2.h
40 ../header/processing/avf2_prc2.h
41 ../header/fsw_params_wf_handler.h
41 ../header/fsw_params_wf_handler.h
42 ../header/lfr_cpu_usage_report.h
42 ../header/lfr_cpu_usage_report.h
43 ../header/lfr_common_headers/ccsds_types.h
43 ../header/lfr_common_headers/ccsds_types.h
44 ../header/lfr_common_headers/fsw_params.h
44 ../header/lfr_common_headers/fsw_params.h
45 ../header/lfr_common_headers/fsw_params_nb_bytes.h
45 ../header/lfr_common_headers/fsw_params_nb_bytes.h
46 ../header/lfr_common_headers/fsw_params_processing.h
46 ../header/lfr_common_headers/fsw_params_processing.h
47 ../header/lfr_common_headers/tm_byte_positions.h
47 ../header/lfr_common_headers/tm_byte_positions.h
48 ../LFR_basic-parameters/basic_parameters.h
48 ../LFR_basic-parameters/basic_parameters.h
49 ../LFR_basic-parameters/basic_parameters_params.h
49 ../LFR_basic-parameters/basic_parameters_params.h
50 ../header/GscMemoryLPP.hpp
50 ../header/GscMemoryLPP.hpp
51 )
51 )
52
52
53
53
54 option(FSW_verbose "Enable verbose LFR" OFF)
54 option(FSW_verbose "Enable verbose LFR" OFF)
55 option(FSW_boot_messages "Enable LFR boot messages" OFF)
55 option(FSW_boot_messages "Enable LFR boot messages" OFF)
56 option(FSW_debug_messages "Enable LFR debug messages" OFF)
56 option(FSW_debug_messages "Enable LFR debug messages" OFF)
57 option(FSW_cpu_usage_report "Enable LFR cpu usage report" OFF)
57 option(FSW_cpu_usage_report "Enable LFR cpu usage report" OFF)
58 option(FSW_stack_report "Enable LFR stack report" OFF)
58 option(FSW_stack_report "Enable LFR stack report" OFF)
59 option(FSW_vhdl_dev "?" OFF)
59 option(FSW_vhdl_dev "?" OFF)
60 option(FSW_lpp_dpu_destid "Set to debug at LPP" OFF)
60 option(FSW_lpp_dpu_destid "Set to debug at LPP" OFF)
61 option(FSW_debug_watchdog "Enable debug watchdog" OFF)
61 option(FSW_debug_watchdog "Enable debug watchdog" OFF)
62 option(FSW_debug_tch "?" OFF)
62 option(FSW_debug_tch "?" OFF)
63
63
64 set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE)
64 set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE)
65 set(SW_VERSION_N2 "2" CACHE STRING "Choose N2 FSW Version." FORCE)
65 set(SW_VERSION_N2 "2" CACHE STRING "Choose N2 FSW Version." FORCE)
66 set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE)
66 set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE)
67 set(SW_VERSION_N4 "20" CACHE STRING "Choose N4 FSW Version." FORCE)
67 set(SW_VERSION_N4 "20" CACHE STRING "Choose N4 FSW Version." FORCE)
68
68
69 if(FSW_verbose)
69 if(FSW_verbose)
70 add_definitions(-DPRINT_MESSAGES_ON_CONSOLE)
70 add_definitions(-DPRINT_MESSAGES_ON_CONSOLE)
71 endif()
71 endif()
72 if(FSW_boot_messages)
72 if(FSW_boot_messages)
73 add_definitions(-DBOOT_MESSAGES)
73 add_definitions(-DBOOT_MESSAGES)
74 endif()
74 endif()
75 if(FSW_debug_messages)
75 if(FSW_debug_messages)
76 add_definitions(-DDEBUG_MESSAGES)
76 add_definitions(-DDEBUG_MESSAGES)
77 endif()
77 endif()
78 if(FSW_cpu_usage_report)
78 if(FSW_cpu_usage_report)
79 add_definitions(-DPRINT_TASK_STATISTICS)
79 add_definitions(-DPRINT_TASK_STATISTICS)
80 endif()
80 endif()
81 if(FSW_stack_report)
81 if(FSW_stack_report)
82 add_definitions(-DPRINT_STACK_REPORT)
82 add_definitions(-DPRINT_STACK_REPORT)
83 endif()
83 endif()
84 if(FSW_vhdl_dev)
84 if(FSW_vhdl_dev)
85 add_definitions(-DVHDL_DEV)
85 add_definitions(-DVHDL_DEV)
86 endif()
86 endif()
87 if(FSW_lpp_dpu_destid)
87 if(FSW_lpp_dpu_destid)
88 add_definitions(-DLPP_DPU_DESTID)
88 add_definitions(-DLPP_DPU_DESTID)
89 endif()
89 endif()
90 if(FSW_debug_watchdog)
90 if(FSW_debug_watchdog)
91 add_definitions(-DDEBUG_WATCHDOG)
91 add_definitions(-DDEBUG_WATCHDOG)
92 endif()
92 endif()
93 if(FSW_debug_tch)
93 if(FSW_debug_tch)
94 add_definitions(-DDEBUG_TCH)
94 add_definitions(-DDEBUG_TCH)
95 endif()
95 endif()
96
96
97
97
98
98
99 add_definitions(-DMSB_FIRST_TCH)
99 add_definitions(-DMSB_FIRST_TCH)
100
100
101 add_definitions(-DSWVERSION=-1-0)
101 add_definitions(-DSWVERSION=-1-0)
102 add_definitions(-DSW_VERSION_N1=${SW_VERSION_N1})
102 add_definitions(-DSW_VERSION_N1=${SW_VERSION_N1})
103 add_definitions(-DSW_VERSION_N2=${SW_VERSION_N2})
103 add_definitions(-DSW_VERSION_N2=${SW_VERSION_N2})
104 add_definitions(-DSW_VERSION_N3=${SW_VERSION_N3})
104 add_definitions(-DSW_VERSION_N3=${SW_VERSION_N3})
105 add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4})
105 add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4})
106
106
107 add_executable(fsw ${SOURCES})
107 add_executable(fsw ${SOURCES})
108
108
109 if(Coverage)
109 if(Coverage)
110 target_link_libraries(fsw gcov)
110 target_link_libraries(fsw gcov)
111 SET_TARGET_PROPERTIES(fsw PROPERTIES COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
111 endif()
112 endif()
112
113
113
114
114 if(fix-b2bst)
115 if(fix-b2bst)
115 check_b2bst(fsw ${CMAKE_CURRENT_BINARY_DIR})
116 check_b2bst(fsw ${CMAKE_CURRENT_BINARY_DIR})
116 endif()
117 endif()
117
118
118 if(NOT FSW_lpp_dpu_destid)
119 if(NOT FSW_lpp_dpu_destid)
119 build_srec(fsw ${CMAKE_CURRENT_BINARY_DIR} "${SW_VERSION_N1}-${SW_VERSION_N2}-${SW_VERSION_N3}-${SW_VERSION_N4}")
120 build_srec(fsw ${CMAKE_CURRENT_BINARY_DIR} "${SW_VERSION_N1}-${SW_VERSION_N2}-${SW_VERSION_N3}-${SW_VERSION_N4}")
120 endif()
121 endif()
121
122
122
123
123 add_test_cppcheck(fsw STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE)
124 add_test_cppcheck(fsw STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE)
124
125
General Comments 0
You need to be logged in to leave comments. Login now