annotate gcc/gcov-io.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents 77e2b8dfacca
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* File format for coverage information
16
kono
parents: 9
diff changeset
2 Copyright (C) 1996-2017 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Contributed by Bob Manson <manson@cygnus.com>.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 Completely remangled by Nathan Sidwell <nathan@codesourcery.com>.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
16
kono
parents: 9
diff changeset
18 Under Section 7 of GPL version 3, you are granted additional
kono
parents: 9
diff changeset
19 permissions described in the GCC Runtime Library Exception, version
kono
parents: 9
diff changeset
20 3.1, as published by the Free Software Foundation.
kono
parents: 9
diff changeset
21
kono
parents: 9
diff changeset
22 You should have received a copy of the GNU General Public License and
kono
parents: 9
diff changeset
23 a copy of the GCC Runtime Library Exception along with this program;
kono
parents: 9
diff changeset
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 /* Routines declared in gcov-io.h. This file should be #included by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 another source file, after having #included gcov-io.h. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 #if !IN_GCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 static void gcov_write_block (unsigned);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 static gcov_unsigned_t *gcov_write_words (unsigned);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 static const gcov_unsigned_t *gcov_read_words (unsigned);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 #if !IN_LIBGCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 static void gcov_allocate (unsigned);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
16
kono
parents: 9
diff changeset
39 /* Optimum number of gcov_unsigned_t's read from or written to disk. */
kono
parents: 9
diff changeset
40 #define GCOV_BLOCK_SIZE (1 << 10)
kono
parents: 9
diff changeset
41
kono
parents: 9
diff changeset
42 struct gcov_var
kono
parents: 9
diff changeset
43 {
kono
parents: 9
diff changeset
44 FILE *file;
kono
parents: 9
diff changeset
45 gcov_position_t start; /* Position of first byte of block */
kono
parents: 9
diff changeset
46 unsigned offset; /* Read/write position within the block. */
kono
parents: 9
diff changeset
47 unsigned length; /* Read limit in the block. */
kono
parents: 9
diff changeset
48 unsigned overread; /* Number of words overread. */
kono
parents: 9
diff changeset
49 int error; /* < 0 overflow, > 0 disk error. */
kono
parents: 9
diff changeset
50 int mode; /* < 0 writing, > 0 reading */
kono
parents: 9
diff changeset
51 #if IN_LIBGCOV
kono
parents: 9
diff changeset
52 /* Holds one block plus 4 bytes, thus all coverage reads & writes
kono
parents: 9
diff changeset
53 fit within this buffer and we always can transfer GCOV_BLOCK_SIZE
kono
parents: 9
diff changeset
54 to and from the disk. libgcov never backtracks and only writes 4
kono
parents: 9
diff changeset
55 or 8 byte objects. */
kono
parents: 9
diff changeset
56 gcov_unsigned_t buffer[GCOV_BLOCK_SIZE + 1];
kono
parents: 9
diff changeset
57 #else
kono
parents: 9
diff changeset
58 int endian; /* Swap endianness. */
kono
parents: 9
diff changeset
59 /* Holds a variable length block, as the compiler can write
kono
parents: 9
diff changeset
60 strings and needs to backtrack. */
kono
parents: 9
diff changeset
61 size_t alloc;
kono
parents: 9
diff changeset
62 gcov_unsigned_t *buffer;
kono
parents: 9
diff changeset
63 #endif
kono
parents: 9
diff changeset
64 } gcov_var;
kono
parents: 9
diff changeset
65
kono
parents: 9
diff changeset
66 /* Save the current position in the gcov file. */
kono
parents: 9
diff changeset
67 /* We need to expose this function when compiling for gcov-tool. */
kono
parents: 9
diff changeset
68 #ifndef IN_GCOV_TOOL
kono
parents: 9
diff changeset
69 static inline
kono
parents: 9
diff changeset
70 #endif
kono
parents: 9
diff changeset
71 gcov_position_t
kono
parents: 9
diff changeset
72 gcov_position (void)
kono
parents: 9
diff changeset
73 {
kono
parents: 9
diff changeset
74 gcov_nonruntime_assert (gcov_var.mode > 0);
kono
parents: 9
diff changeset
75 return gcov_var.start + gcov_var.offset;
kono
parents: 9
diff changeset
76 }
kono
parents: 9
diff changeset
77
kono
parents: 9
diff changeset
78 /* Return nonzero if the error flag is set. */
kono
parents: 9
diff changeset
79 /* We need to expose this function when compiling for gcov-tool. */
kono
parents: 9
diff changeset
80 #ifndef IN_GCOV_TOOL
kono
parents: 9
diff changeset
81 static inline
kono
parents: 9
diff changeset
82 #endif
kono
parents: 9
diff changeset
83 int
kono
parents: 9
diff changeset
84 gcov_is_error (void)
kono
parents: 9
diff changeset
85 {
kono
parents: 9
diff changeset
86 return gcov_var.file ? gcov_var.error : 1;
kono
parents: 9
diff changeset
87 }
kono
parents: 9
diff changeset
88
kono
parents: 9
diff changeset
89 #if IN_LIBGCOV
kono
parents: 9
diff changeset
90 /* Move to beginning of file and initialize for writing. */
kono
parents: 9
diff changeset
91 GCOV_LINKAGE inline void
kono
parents: 9
diff changeset
92 gcov_rewrite (void)
kono
parents: 9
diff changeset
93 {
kono
parents: 9
diff changeset
94 gcov_var.mode = -1;
kono
parents: 9
diff changeset
95 gcov_var.start = 0;
kono
parents: 9
diff changeset
96 gcov_var.offset = 0;
kono
parents: 9
diff changeset
97 fseek (gcov_var.file, 0L, SEEK_SET);
kono
parents: 9
diff changeset
98 }
kono
parents: 9
diff changeset
99 #endif
kono
parents: 9
diff changeset
100
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 static inline gcov_unsigned_t from_file (gcov_unsigned_t value)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 #if !IN_LIBGCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 if (gcov_var.endian)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 value = (value >> 16) | (value << 16);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 value = ((value & 0xff00ff) << 8) | ((value >> 8) & 0xff00ff);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 return value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 /* Open a gcov file. NAME is the name of the file to open and MODE
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 indicates whether a new file should be created, or an existing file
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
115 opened. If MODE is >= 0 an existing file will be opened, if
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
116 possible, and if MODE is <= 0, a new file will be created. Use
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
117 MODE=0 to attempt to reopen an existing file and then fall back on
16
kono
parents: 9
diff changeset
118 creating a new one. If MODE > 0, the file will be opened in
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
119 read-only mode. Otherwise it will be opened for modification.
16
kono
parents: 9
diff changeset
120 Return zero on failure, non-zero on success. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 GCOV_LINKAGE int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 #if IN_LIBGCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 gcov_open (const char *name)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 #else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 gcov_open (const char *name, int mode)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 #if IN_LIBGCOV
16
kono
parents: 9
diff changeset
130 int mode = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 #if GCOV_LOCKED
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 struct flock s_flock;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 int fd;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 s_flock.l_whence = SEEK_SET;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 s_flock.l_start = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 s_flock.l_len = 0; /* Until EOF. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 s_flock.l_pid = getpid ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 #endif
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
141
16
kono
parents: 9
diff changeset
142 gcov_nonruntime_assert (!gcov_var.file);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 gcov_var.start = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 gcov_var.offset = gcov_var.length = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 gcov_var.overread = -1u;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 gcov_var.error = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 #if !IN_LIBGCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 gcov_var.endian = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 #if GCOV_LOCKED
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 if (mode > 0)
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
152 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
153 /* Read-only mode - acquire a read-lock. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
154 s_flock.l_type = F_RDLCK;
16
kono
parents: 9
diff changeset
155 /* pass mode (ignored) for compatibility */
kono
parents: 9
diff changeset
156 fd = open (name, O_RDONLY, S_IRUSR | S_IWUSR);
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
157 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 else
16
kono
parents: 9
diff changeset
159 {
kono
parents: 9
diff changeset
160 /* Write mode - acquire a write-lock. */
kono
parents: 9
diff changeset
161 s_flock.l_type = F_WRLCK;
kono
parents: 9
diff changeset
162 /* Truncate if force new mode. */
kono
parents: 9
diff changeset
163 fd = open (name, O_RDWR | O_CREAT | (mode < 0 ? O_TRUNC : 0), 0666);
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
164 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 if (fd < 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 while (fcntl (fd, F_SETLKW, &s_flock) && errno == EINTR)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
171 gcov_var.file = fdopen (fd, (mode > 0) ? "rb" : "r+b");
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
172
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 if (!gcov_var.file)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 close (fd);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 #else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 if (mode >= 0)
16
kono
parents: 9
diff changeset
180 /* Open an existing file. */
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
181 gcov_var.file = fopen (name, (mode > 0) ? "rb" : "r+b");
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
182
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 if (gcov_var.file)
16
kono
parents: 9
diff changeset
184 mode = 1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 else if (mode <= 0)
16
kono
parents: 9
diff changeset
186 /* Create a new file. */
kono
parents: 9
diff changeset
187 gcov_var.file = fopen (name, "w+b");
kono
parents: 9
diff changeset
188
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 if (!gcov_var.file)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192
16
kono
parents: 9
diff changeset
193 gcov_var.mode = mode ? mode : 1;
kono
parents: 9
diff changeset
194
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 setbuf (gcov_var.file, (char *)0);
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
196
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 return 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 /* Close the current gcov file. Flushes data to disk. Returns nonzero
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 on failure or error flag set. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 GCOV_LINKAGE int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 gcov_close (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 if (gcov_var.file)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 #if !IN_GCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 if (gcov_var.offset && gcov_var.mode < 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 gcov_write_block (gcov_var.offset);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 fclose (gcov_var.file);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 gcov_var.file = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 gcov_var.length = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 #if !IN_LIBGCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 free (gcov_var.buffer);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 gcov_var.alloc = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 gcov_var.buffer = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 gcov_var.mode = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 return gcov_var.error;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 #if !IN_LIBGCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 /* Check if MAGIC is EXPECTED. Use it to determine endianness of the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 file. Returns +1 for same endian, -1 for other endian and zero for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 not EXPECTED. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 GCOV_LINKAGE int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 gcov_magic (gcov_unsigned_t magic, gcov_unsigned_t expected)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 if (magic == expected)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 return 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 magic = (magic >> 16) | (magic << 16);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 magic = ((magic & 0xff00ff) << 8) | ((magic >> 8) & 0xff00ff);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 if (magic == expected)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 gcov_var.endian = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 return -1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 #if !IN_LIBGCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 gcov_allocate (unsigned length)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 size_t new_size = gcov_var.alloc;
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
251
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 if (!new_size)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 new_size = GCOV_BLOCK_SIZE;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 new_size += length;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 new_size *= 2;
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
256
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 gcov_var.alloc = new_size;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 gcov_var.buffer = XRESIZEVAR (gcov_unsigned_t, gcov_var.buffer, new_size << 2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 #if !IN_GCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 /* Write out the current block, if needs be. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 gcov_write_block (unsigned size)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 if (fwrite (gcov_var.buffer, size << 2, 1, gcov_var.file) != 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 gcov_var.error = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 gcov_var.start += size;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 gcov_var.offset -= size;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 /* Allocate space to write BYTES bytes to the gcov file. Return a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 pointer to those bytes, or NULL on failure. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 static gcov_unsigned_t *
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 gcov_write_words (unsigned words)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 gcov_unsigned_t *result;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281
16
kono
parents: 9
diff changeset
282 gcov_nonruntime_assert (gcov_var.mode < 0);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 #if IN_LIBGCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 if (gcov_var.offset >= GCOV_BLOCK_SIZE)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 gcov_write_block (GCOV_BLOCK_SIZE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 if (gcov_var.offset)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 memcpy (gcov_var.buffer, gcov_var.buffer + GCOV_BLOCK_SIZE, 4);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 #else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 if (gcov_var.offset + words > gcov_var.alloc)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 gcov_allocate (gcov_var.offset + words);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 result = &gcov_var.buffer[gcov_var.offset];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 gcov_var.offset += words;
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
298
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 return result;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 /* Write unsigned VALUE to coverage file. Sets error flag
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 appropriately. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 GCOV_LINKAGE void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 gcov_write_unsigned (gcov_unsigned_t value)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 gcov_unsigned_t *buffer = gcov_write_words (1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
309
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 buffer[0] = value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
312
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 /* Write counter VALUE to coverage file. Sets error flag
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 appropriately. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 #if IN_LIBGCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 GCOV_LINKAGE void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 gcov_write_counter (gcov_type value)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 gcov_unsigned_t *buffer = gcov_write_words (2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 buffer[0] = (gcov_unsigned_t) value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 if (sizeof (value) > sizeof (gcov_unsigned_t))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 buffer[1] = (gcov_unsigned_t) (value >> 32);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 buffer[1] = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 #endif /* IN_LIBGCOV */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 #if !IN_LIBGCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 /* Write STRING to coverage file. Sets error flag on file
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 error, overflow flag on overflow */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 GCOV_LINKAGE void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 gcov_write_string (const char *string)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 unsigned length = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 unsigned alloc = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 gcov_unsigned_t *buffer;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 if (string)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 length = strlen (string);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 alloc = (length + 4) >> 2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 }
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
346
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 buffer = gcov_write_words (1 + alloc);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 buffer[0] = alloc;
16
kono
parents: 9
diff changeset
350
kono
parents: 9
diff changeset
351 if (alloc > 0)
kono
parents: 9
diff changeset
352 {
kono
parents: 9
diff changeset
353 buffer[alloc] = 0; /* place nul terminators. */
kono
parents: 9
diff changeset
354 memcpy (&buffer[1], string, length);
kono
parents: 9
diff changeset
355 }
kono
parents: 9
diff changeset
356 }
kono
parents: 9
diff changeset
357 #endif
kono
parents: 9
diff changeset
358
kono
parents: 9
diff changeset
359 #if !IN_LIBGCOV
kono
parents: 9
diff changeset
360 /* Write FILENAME to coverage file. Sets error flag on file
kono
parents: 9
diff changeset
361 error, overflow flag on overflow */
kono
parents: 9
diff changeset
362
kono
parents: 9
diff changeset
363 GCOV_LINKAGE void
kono
parents: 9
diff changeset
364 gcov_write_filename (const char *filename)
kono
parents: 9
diff changeset
365 {
kono
parents: 9
diff changeset
366 if (profile_abs_path_flag && filename && filename[0]
kono
parents: 9
diff changeset
367 && !(IS_DIR_SEPARATOR (filename[0])
kono
parents: 9
diff changeset
368 #if HAVE_DOS_BASED_FILE_SYSTEM
kono
parents: 9
diff changeset
369 || filename[1] == ':'
kono
parents: 9
diff changeset
370 #endif
kono
parents: 9
diff changeset
371 ))
kono
parents: 9
diff changeset
372 {
kono
parents: 9
diff changeset
373 char *buf = getcwd (NULL, 0);
kono
parents: 9
diff changeset
374 if (buf != NULL && buf[0])
kono
parents: 9
diff changeset
375 {
kono
parents: 9
diff changeset
376 size_t len = strlen (buf);
kono
parents: 9
diff changeset
377 buf = (char*)xrealloc (buf, len + strlen (filename) + 2);
kono
parents: 9
diff changeset
378 if (!IS_DIR_SEPARATOR (buf[len - 1]))
kono
parents: 9
diff changeset
379 strcat (buf, "/");
kono
parents: 9
diff changeset
380 strcat (buf, filename);
kono
parents: 9
diff changeset
381 gcov_write_string (buf);
kono
parents: 9
diff changeset
382 free (buf);
kono
parents: 9
diff changeset
383 return;
kono
parents: 9
diff changeset
384 }
kono
parents: 9
diff changeset
385 }
kono
parents: 9
diff changeset
386
kono
parents: 9
diff changeset
387 gcov_write_string (filename);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 #if !IN_LIBGCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 /* Write a tag TAG and reserve space for the record length. Return a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 value to be used for gcov_write_length. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 GCOV_LINKAGE gcov_position_t
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 gcov_write_tag (gcov_unsigned_t tag)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 gcov_position_t result = gcov_var.start + gcov_var.offset;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 gcov_unsigned_t *buffer = gcov_write_words (2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 buffer[0] = tag;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 buffer[1] = 0;
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
403
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 return result;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 /* Write a record length using POSITION, which was returned by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 gcov_write_tag. The current file position is the end of the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 record, and is restored before returning. Returns nonzero on
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 overflow. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 GCOV_LINKAGE void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 gcov_write_length (gcov_position_t position)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 unsigned offset;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 gcov_unsigned_t length;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 gcov_unsigned_t *buffer;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418
16
kono
parents: 9
diff changeset
419 gcov_nonruntime_assert (gcov_var.mode < 0);
kono
parents: 9
diff changeset
420 gcov_nonruntime_assert (position + 2 <= gcov_var.start + gcov_var.offset);
kono
parents: 9
diff changeset
421 gcov_nonruntime_assert (position >= gcov_var.start);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 offset = position - gcov_var.start;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 length = gcov_var.offset - offset - 2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 buffer = (gcov_unsigned_t *) &gcov_var.buffer[offset];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 buffer[1] = length;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 if (gcov_var.offset >= GCOV_BLOCK_SIZE)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 gcov_write_block (gcov_var.offset);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 #else /* IN_LIBGCOV */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 /* Write a tag TAG and length LENGTH. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 GCOV_LINKAGE void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 gcov_write_tag_length (gcov_unsigned_t tag, gcov_unsigned_t length)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 gcov_unsigned_t *buffer = gcov_write_words (2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
438
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 buffer[0] = tag;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 buffer[1] = length;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 /* Write a summary structure to the gcov file. Return nonzero on
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 overflow. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 GCOV_LINKAGE void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 gcov_write_summary (gcov_unsigned_t tag, const struct gcov_summary *summary)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 {
16
kono
parents: 9
diff changeset
449 unsigned ix, h_ix, bv_ix, h_cnt = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 const struct gcov_ctr_summary *csum;
16
kono
parents: 9
diff changeset
451 unsigned histo_bitvector[GCOV_HISTOGRAM_BITVECTOR_SIZE];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
452
16
kono
parents: 9
diff changeset
453 /* Count number of non-zero histogram entries, and fill in a bit vector
kono
parents: 9
diff changeset
454 of non-zero indices. The histogram is only currently computed for arc
kono
parents: 9
diff changeset
455 counters. */
kono
parents: 9
diff changeset
456 for (bv_ix = 0; bv_ix < GCOV_HISTOGRAM_BITVECTOR_SIZE; bv_ix++)
kono
parents: 9
diff changeset
457 histo_bitvector[bv_ix] = 0;
kono
parents: 9
diff changeset
458 csum = &summary->ctrs[GCOV_COUNTER_ARCS];
kono
parents: 9
diff changeset
459 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
kono
parents: 9
diff changeset
460 if (csum->histogram[h_ix].num_counters)
kono
parents: 9
diff changeset
461 {
kono
parents: 9
diff changeset
462 histo_bitvector[h_ix / 32] |= 1 << (h_ix % 32);
kono
parents: 9
diff changeset
463 h_cnt++;
kono
parents: 9
diff changeset
464 }
kono
parents: 9
diff changeset
465 gcov_write_tag_length (tag, GCOV_TAG_SUMMARY_LENGTH (h_cnt));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 gcov_write_unsigned (summary->checksum);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 for (csum = summary->ctrs, ix = GCOV_COUNTERS_SUMMABLE; ix--; csum++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 gcov_write_unsigned (csum->num);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 gcov_write_unsigned (csum->runs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 gcov_write_counter (csum->sum_all);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 gcov_write_counter (csum->run_max);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 gcov_write_counter (csum->sum_max);
16
kono
parents: 9
diff changeset
474 if (ix != GCOV_COUNTER_ARCS)
kono
parents: 9
diff changeset
475 {
kono
parents: 9
diff changeset
476 for (bv_ix = 0; bv_ix < GCOV_HISTOGRAM_BITVECTOR_SIZE; bv_ix++)
kono
parents: 9
diff changeset
477 gcov_write_unsigned (0);
kono
parents: 9
diff changeset
478 continue;
kono
parents: 9
diff changeset
479 }
kono
parents: 9
diff changeset
480 for (bv_ix = 0; bv_ix < GCOV_HISTOGRAM_BITVECTOR_SIZE; bv_ix++)
kono
parents: 9
diff changeset
481 gcov_write_unsigned (histo_bitvector[bv_ix]);
kono
parents: 9
diff changeset
482 for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++)
kono
parents: 9
diff changeset
483 {
kono
parents: 9
diff changeset
484 if (!csum->histogram[h_ix].num_counters)
kono
parents: 9
diff changeset
485 continue;
kono
parents: 9
diff changeset
486 gcov_write_unsigned (csum->histogram[h_ix].num_counters);
kono
parents: 9
diff changeset
487 gcov_write_counter (csum->histogram[h_ix].min_value);
kono
parents: 9
diff changeset
488 gcov_write_counter (csum->histogram[h_ix].cum_value);
kono
parents: 9
diff changeset
489 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 #endif /* IN_LIBGCOV */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
493
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 #endif /*!IN_GCOV */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
495
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 /* Return a pointer to read BYTES bytes from the gcov file. Returns
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 NULL on failure (read past EOF). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
498
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 static const gcov_unsigned_t *
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 gcov_read_words (unsigned words)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 const gcov_unsigned_t *result;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 unsigned excess = gcov_var.length - gcov_var.offset;
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
504
16
kono
parents: 9
diff changeset
505 if (gcov_var.mode <= 0)
kono
parents: 9
diff changeset
506 return NULL;
kono
parents: 9
diff changeset
507
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 if (excess < words)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 gcov_var.start += gcov_var.offset;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 if (excess)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
512 {
16
kono
parents: 9
diff changeset
513 #if IN_LIBGCOV
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 memcpy (gcov_var.buffer, gcov_var.buffer + gcov_var.offset, 4);
16
kono
parents: 9
diff changeset
515 #else
kono
parents: 9
diff changeset
516 memmove (gcov_var.buffer, gcov_var.buffer + gcov_var.offset,
kono
parents: 9
diff changeset
517 excess * 4);
kono
parents: 9
diff changeset
518 #endif
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 gcov_var.offset = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 gcov_var.length = excess;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
522 #if IN_LIBGCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 excess = GCOV_BLOCK_SIZE;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 #else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 if (gcov_var.length + words > gcov_var.alloc)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 gcov_allocate (gcov_var.length + words);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 excess = gcov_var.alloc - gcov_var.length;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 excess = fread (gcov_var.buffer + gcov_var.length,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 1, excess << 2, gcov_var.file) >> 2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 gcov_var.length += excess;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 if (gcov_var.length < words)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 gcov_var.overread += words - gcov_var.length;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 gcov_var.length = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 result = &gcov_var.buffer[gcov_var.offset];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 gcov_var.offset += words;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 return result;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 /* Read unsigned value from a coverage file. Sets error flag on file
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 error, overflow flag on overflow */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 GCOV_LINKAGE gcov_unsigned_t
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 gcov_read_unsigned (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 gcov_unsigned_t value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 const gcov_unsigned_t *buffer = gcov_read_words (1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
552
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 if (!buffer)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 value = from_file (buffer[0]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 return value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
558
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 /* Read counter value from a coverage file. Sets error flag on file
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 error, overflow flag on overflow */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
561
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 GCOV_LINKAGE gcov_type
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 gcov_read_counter (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
565 gcov_type value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
566 const gcov_unsigned_t *buffer = gcov_read_words (2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
567
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
568 if (!buffer)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 value = from_file (buffer[0]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 if (sizeof (value) > sizeof (gcov_unsigned_t))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
572 value |= ((gcov_type) from_file (buffer[1])) << 32;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 else if (buffer[1])
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 gcov_var.error = -1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 return value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
577 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
578
16
kono
parents: 9
diff changeset
579 /* We need to expose the below function when compiling for gcov-tool. */
kono
parents: 9
diff changeset
580
kono
parents: 9
diff changeset
581 #if !IN_LIBGCOV || defined (IN_GCOV_TOOL)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
582 /* Read string from coverage file. Returns a pointer to a static
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 buffer, or NULL on empty string. You must copy the string before
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 calling another gcov function. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
585
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 GCOV_LINKAGE const char *
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 gcov_read_string (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 unsigned length = gcov_read_unsigned ();
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
590
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 if (!length)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
593
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 return (const char *) gcov_read_words (length);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 GCOV_LINKAGE void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 gcov_read_summary (struct gcov_summary *summary)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 {
16
kono
parents: 9
diff changeset
601 unsigned ix, h_ix, bv_ix, h_cnt = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 struct gcov_ctr_summary *csum;
16
kono
parents: 9
diff changeset
603 unsigned histo_bitvector[GCOV_HISTOGRAM_BITVECTOR_SIZE];
kono
parents: 9
diff changeset
604 unsigned cur_bitvector;
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
605
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 summary->checksum = gcov_read_unsigned ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 for (csum = summary->ctrs, ix = GCOV_COUNTERS_SUMMABLE; ix--; csum++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 csum->num = gcov_read_unsigned ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 csum->runs = gcov_read_unsigned ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
611 csum->sum_all = gcov_read_counter ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
612 csum->run_max = gcov_read_counter ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
613 csum->sum_max = gcov_read_counter ();
16
kono
parents: 9
diff changeset
614 memset (csum->histogram, 0,
kono
parents: 9
diff changeset
615 sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE);
kono
parents: 9
diff changeset
616 for (bv_ix = 0; bv_ix < GCOV_HISTOGRAM_BITVECTOR_SIZE; bv_ix++)
kono
parents: 9
diff changeset
617 {
kono
parents: 9
diff changeset
618 histo_bitvector[bv_ix] = gcov_read_unsigned ();
kono
parents: 9
diff changeset
619 #if IN_LIBGCOV
kono
parents: 9
diff changeset
620 /* When building libgcov we don't include system.h, which includes
kono
parents: 9
diff changeset
621 hwint.h (where popcount_hwi is declared). However, libgcov.a
kono
parents: 9
diff changeset
622 is built by the bootstrapped compiler and therefore the builtins
kono
parents: 9
diff changeset
623 are always available. */
kono
parents: 9
diff changeset
624 h_cnt += __builtin_popcount (histo_bitvector[bv_ix]);
kono
parents: 9
diff changeset
625 #else
kono
parents: 9
diff changeset
626 h_cnt += popcount_hwi (histo_bitvector[bv_ix]);
kono
parents: 9
diff changeset
627 #endif
kono
parents: 9
diff changeset
628 }
kono
parents: 9
diff changeset
629 bv_ix = 0;
kono
parents: 9
diff changeset
630 h_ix = 0;
kono
parents: 9
diff changeset
631 cur_bitvector = 0;
kono
parents: 9
diff changeset
632 while (h_cnt--)
kono
parents: 9
diff changeset
633 {
kono
parents: 9
diff changeset
634 /* Find the index corresponding to the next entry we will read in.
kono
parents: 9
diff changeset
635 First find the next non-zero bitvector and re-initialize
kono
parents: 9
diff changeset
636 the histogram index accordingly, then right shift and increment
kono
parents: 9
diff changeset
637 the index until we find a set bit. */
kono
parents: 9
diff changeset
638 while (!cur_bitvector)
kono
parents: 9
diff changeset
639 {
kono
parents: 9
diff changeset
640 h_ix = bv_ix * 32;
kono
parents: 9
diff changeset
641 if (bv_ix >= GCOV_HISTOGRAM_BITVECTOR_SIZE)
kono
parents: 9
diff changeset
642 gcov_error ("corrupted profile info: summary histogram "
kono
parents: 9
diff changeset
643 "bitvector is corrupt");
kono
parents: 9
diff changeset
644 cur_bitvector = histo_bitvector[bv_ix++];
kono
parents: 9
diff changeset
645 }
kono
parents: 9
diff changeset
646 while (!(cur_bitvector & 0x1))
kono
parents: 9
diff changeset
647 {
kono
parents: 9
diff changeset
648 h_ix++;
kono
parents: 9
diff changeset
649 cur_bitvector >>= 1;
kono
parents: 9
diff changeset
650 }
kono
parents: 9
diff changeset
651 if (h_ix >= GCOV_HISTOGRAM_SIZE)
kono
parents: 9
diff changeset
652 gcov_error ("corrupted profile info: summary histogram "
kono
parents: 9
diff changeset
653 "index is corrupt");
kono
parents: 9
diff changeset
654
kono
parents: 9
diff changeset
655 csum->histogram[h_ix].num_counters = gcov_read_unsigned ();
kono
parents: 9
diff changeset
656 csum->histogram[h_ix].min_value = gcov_read_counter ();
kono
parents: 9
diff changeset
657 csum->histogram[h_ix].cum_value = gcov_read_counter ();
kono
parents: 9
diff changeset
658 /* Shift off the index we are done with and increment to the
kono
parents: 9
diff changeset
659 corresponding next histogram entry. */
kono
parents: 9
diff changeset
660 cur_bitvector >>= 1;
kono
parents: 9
diff changeset
661 h_ix++;
kono
parents: 9
diff changeset
662 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
663 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
664 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
665
16
kono
parents: 9
diff changeset
666 /* We need to expose the below function when compiling for gcov-tool. */
kono
parents: 9
diff changeset
667
kono
parents: 9
diff changeset
668 #if !IN_LIBGCOV || defined (IN_GCOV_TOOL)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 /* Reset to a known position. BASE should have been obtained from
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
670 gcov_position, LENGTH should be a record length. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
671
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
672 GCOV_LINKAGE void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
673 gcov_sync (gcov_position_t base, gcov_unsigned_t length)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
674 {
16
kono
parents: 9
diff changeset
675 gcov_nonruntime_assert (gcov_var.mode > 0);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 base += length;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
677 if (base - gcov_var.start <= gcov_var.length)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
678 gcov_var.offset = base - gcov_var.start;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
679 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
680 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 gcov_var.offset = gcov_var.length = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 fseek (gcov_var.file, base << 2, SEEK_SET);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 gcov_var.start = ftell (gcov_var.file) >> 2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
685 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
687
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
688 #if IN_LIBGCOV
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
689 /* Move to a given position in a gcov file. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
690
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
691 GCOV_LINKAGE void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
692 gcov_seek (gcov_position_t base)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
693 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
694 if (gcov_var.offset)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
695 gcov_write_block (gcov_var.offset);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
696 fseek (gcov_var.file, base << 2, SEEK_SET);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 gcov_var.start = ftell (gcov_var.file) >> 2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
698 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
701 #if IN_GCOV > 0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
702 /* Return the modification time of the current gcov file. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 GCOV_LINKAGE time_t
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 gcov_time (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 struct stat status;
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
708
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 if (fstat (fileno (gcov_var.file), &status))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
711 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
712 return status.st_mtime;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
713 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
714 #endif /* IN_GCOV */
16
kono
parents: 9
diff changeset
715
kono
parents: 9
diff changeset
716 #if !IN_GCOV
kono
parents: 9
diff changeset
717 /* Determine the index into histogram for VALUE. */
kono
parents: 9
diff changeset
718
kono
parents: 9
diff changeset
719 #if IN_LIBGCOV
kono
parents: 9
diff changeset
720 static unsigned
kono
parents: 9
diff changeset
721 #else
kono
parents: 9
diff changeset
722 GCOV_LINKAGE unsigned
kono
parents: 9
diff changeset
723 #endif
kono
parents: 9
diff changeset
724 gcov_histo_index (gcov_type value)
kono
parents: 9
diff changeset
725 {
kono
parents: 9
diff changeset
726 gcov_type_unsigned v = (gcov_type_unsigned)value;
kono
parents: 9
diff changeset
727 unsigned r = 0;
kono
parents: 9
diff changeset
728 unsigned prev2bits = 0;
kono
parents: 9
diff changeset
729
kono
parents: 9
diff changeset
730 /* Find index into log2 scale histogram, where each of the log2
kono
parents: 9
diff changeset
731 sized buckets is divided into 4 linear sub-buckets for better
kono
parents: 9
diff changeset
732 focus in the higher buckets. */
kono
parents: 9
diff changeset
733
kono
parents: 9
diff changeset
734 /* Find the place of the most-significant bit set. */
kono
parents: 9
diff changeset
735 if (v > 0)
kono
parents: 9
diff changeset
736 {
kono
parents: 9
diff changeset
737 #if IN_LIBGCOV
kono
parents: 9
diff changeset
738 /* When building libgcov we don't include system.h, which includes
kono
parents: 9
diff changeset
739 hwint.h (where floor_log2 is declared). However, libgcov.a
kono
parents: 9
diff changeset
740 is built by the bootstrapped compiler and therefore the builtins
kono
parents: 9
diff changeset
741 are always available. */
kono
parents: 9
diff changeset
742 r = sizeof (long long) * __CHAR_BIT__ - 1 - __builtin_clzll (v);
kono
parents: 9
diff changeset
743 #else
kono
parents: 9
diff changeset
744 /* We use floor_log2 from hwint.c, which takes a HOST_WIDE_INT
kono
parents: 9
diff changeset
745 that is 64 bits and gcov_type_unsigned is 64 bits. */
kono
parents: 9
diff changeset
746 r = floor_log2 (v);
kono
parents: 9
diff changeset
747 #endif
kono
parents: 9
diff changeset
748 }
kono
parents: 9
diff changeset
749
kono
parents: 9
diff changeset
750 /* If at most the 2 least significant bits are set (value is
kono
parents: 9
diff changeset
751 0 - 3) then that value is our index into the lowest set of
kono
parents: 9
diff changeset
752 four buckets. */
kono
parents: 9
diff changeset
753 if (r < 2)
kono
parents: 9
diff changeset
754 return (unsigned)value;
kono
parents: 9
diff changeset
755
kono
parents: 9
diff changeset
756 gcov_nonruntime_assert (r < 64);
kono
parents: 9
diff changeset
757
kono
parents: 9
diff changeset
758 /* Find the two next most significant bits to determine which
kono
parents: 9
diff changeset
759 of the four linear sub-buckets to select. */
kono
parents: 9
diff changeset
760 prev2bits = (v >> (r - 2)) & 0x3;
kono
parents: 9
diff changeset
761 /* Finally, compose the final bucket index from the log2 index and
kono
parents: 9
diff changeset
762 the next 2 bits. The minimum r value at this point is 2 since we
kono
parents: 9
diff changeset
763 returned above if r was 2 or more, so the minimum bucket at this
kono
parents: 9
diff changeset
764 point is 4. */
kono
parents: 9
diff changeset
765 return (r - 1) * 4 + prev2bits;
kono
parents: 9
diff changeset
766 }
kono
parents: 9
diff changeset
767
kono
parents: 9
diff changeset
768 /* Merge SRC_HISTO into TGT_HISTO. The counters are assumed to be in
kono
parents: 9
diff changeset
769 the same relative order in both histograms, and are matched up
kono
parents: 9
diff changeset
770 and merged in reverse order. Each counter is assigned an equal portion of
kono
parents: 9
diff changeset
771 its entry's original cumulative counter value when computing the
kono
parents: 9
diff changeset
772 new merged cum_value. */
kono
parents: 9
diff changeset
773
kono
parents: 9
diff changeset
774 static void gcov_histogram_merge (gcov_bucket_type *tgt_histo,
kono
parents: 9
diff changeset
775 gcov_bucket_type *src_histo)
kono
parents: 9
diff changeset
776 {
kono
parents: 9
diff changeset
777 int src_i, tgt_i, tmp_i = 0;
kono
parents: 9
diff changeset
778 unsigned src_num, tgt_num, merge_num;
kono
parents: 9
diff changeset
779 gcov_type src_cum, tgt_cum, merge_src_cum, merge_tgt_cum, merge_cum;
kono
parents: 9
diff changeset
780 gcov_type merge_min;
kono
parents: 9
diff changeset
781 gcov_bucket_type tmp_histo[GCOV_HISTOGRAM_SIZE];
kono
parents: 9
diff changeset
782 int src_done = 0;
kono
parents: 9
diff changeset
783
kono
parents: 9
diff changeset
784 memset (tmp_histo, 0, sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE);
kono
parents: 9
diff changeset
785
kono
parents: 9
diff changeset
786 /* Assume that the counters are in the same relative order in both
kono
parents: 9
diff changeset
787 histograms. Walk the histograms from largest to smallest entry,
kono
parents: 9
diff changeset
788 matching up and combining counters in order. */
kono
parents: 9
diff changeset
789 src_num = 0;
kono
parents: 9
diff changeset
790 src_cum = 0;
kono
parents: 9
diff changeset
791 src_i = GCOV_HISTOGRAM_SIZE - 1;
kono
parents: 9
diff changeset
792 for (tgt_i = GCOV_HISTOGRAM_SIZE - 1; tgt_i >= 0 && !src_done; tgt_i--)
kono
parents: 9
diff changeset
793 {
kono
parents: 9
diff changeset
794 tgt_num = tgt_histo[tgt_i].num_counters;
kono
parents: 9
diff changeset
795 tgt_cum = tgt_histo[tgt_i].cum_value;
kono
parents: 9
diff changeset
796 /* Keep going until all of the target histogram's counters at this
kono
parents: 9
diff changeset
797 position have been matched and merged with counters from the
kono
parents: 9
diff changeset
798 source histogram. */
kono
parents: 9
diff changeset
799 while (tgt_num > 0 && !src_done)
kono
parents: 9
diff changeset
800 {
kono
parents: 9
diff changeset
801 /* If this is either the first time through this loop or we just
kono
parents: 9
diff changeset
802 exhausted the previous non-zero source histogram entry, look
kono
parents: 9
diff changeset
803 for the next non-zero source histogram entry. */
kono
parents: 9
diff changeset
804 if (!src_num)
kono
parents: 9
diff changeset
805 {
kono
parents: 9
diff changeset
806 /* Locate the next non-zero entry. */
kono
parents: 9
diff changeset
807 while (src_i >= 0 && !src_histo[src_i].num_counters)
kono
parents: 9
diff changeset
808 src_i--;
kono
parents: 9
diff changeset
809 /* If source histogram has fewer counters, then just copy over the
kono
parents: 9
diff changeset
810 remaining target counters and quit. */
kono
parents: 9
diff changeset
811 if (src_i < 0)
kono
parents: 9
diff changeset
812 {
kono
parents: 9
diff changeset
813 tmp_histo[tgt_i].num_counters += tgt_num;
kono
parents: 9
diff changeset
814 tmp_histo[tgt_i].cum_value += tgt_cum;
kono
parents: 9
diff changeset
815 if (!tmp_histo[tgt_i].min_value ||
kono
parents: 9
diff changeset
816 tgt_histo[tgt_i].min_value < tmp_histo[tgt_i].min_value)
kono
parents: 9
diff changeset
817 tmp_histo[tgt_i].min_value = tgt_histo[tgt_i].min_value;
kono
parents: 9
diff changeset
818 while (--tgt_i >= 0)
kono
parents: 9
diff changeset
819 {
kono
parents: 9
diff changeset
820 tmp_histo[tgt_i].num_counters
kono
parents: 9
diff changeset
821 += tgt_histo[tgt_i].num_counters;
kono
parents: 9
diff changeset
822 tmp_histo[tgt_i].cum_value += tgt_histo[tgt_i].cum_value;
kono
parents: 9
diff changeset
823 if (!tmp_histo[tgt_i].min_value ||
kono
parents: 9
diff changeset
824 tgt_histo[tgt_i].min_value
kono
parents: 9
diff changeset
825 < tmp_histo[tgt_i].min_value)
kono
parents: 9
diff changeset
826 tmp_histo[tgt_i].min_value = tgt_histo[tgt_i].min_value;
kono
parents: 9
diff changeset
827 }
kono
parents: 9
diff changeset
828
kono
parents: 9
diff changeset
829 src_done = 1;
kono
parents: 9
diff changeset
830 break;
kono
parents: 9
diff changeset
831 }
kono
parents: 9
diff changeset
832
kono
parents: 9
diff changeset
833 src_num = src_histo[src_i].num_counters;
kono
parents: 9
diff changeset
834 src_cum = src_histo[src_i].cum_value;
kono
parents: 9
diff changeset
835 }
kono
parents: 9
diff changeset
836
kono
parents: 9
diff changeset
837 /* The number of counters to merge on this pass is the minimum
kono
parents: 9
diff changeset
838 of the remaining counters from the current target and source
kono
parents: 9
diff changeset
839 histogram entries. */
kono
parents: 9
diff changeset
840 merge_num = tgt_num;
kono
parents: 9
diff changeset
841 if (src_num < merge_num)
kono
parents: 9
diff changeset
842 merge_num = src_num;
kono
parents: 9
diff changeset
843
kono
parents: 9
diff changeset
844 /* The merged min_value is the sum of the min_values from target
kono
parents: 9
diff changeset
845 and source. */
kono
parents: 9
diff changeset
846 merge_min = tgt_histo[tgt_i].min_value + src_histo[src_i].min_value;
kono
parents: 9
diff changeset
847
kono
parents: 9
diff changeset
848 /* Compute the portion of source and target entries' cum_value
kono
parents: 9
diff changeset
849 that will be apportioned to the counters being merged.
kono
parents: 9
diff changeset
850 The total remaining cum_value from each entry is divided
kono
parents: 9
diff changeset
851 equally among the counters from that histogram entry if we
kono
parents: 9
diff changeset
852 are not merging all of them. */
kono
parents: 9
diff changeset
853 merge_src_cum = src_cum;
kono
parents: 9
diff changeset
854 if (merge_num < src_num)
kono
parents: 9
diff changeset
855 merge_src_cum = merge_num * src_cum / src_num;
kono
parents: 9
diff changeset
856 merge_tgt_cum = tgt_cum;
kono
parents: 9
diff changeset
857 if (merge_num < tgt_num)
kono
parents: 9
diff changeset
858 merge_tgt_cum = merge_num * tgt_cum / tgt_num;
kono
parents: 9
diff changeset
859 /* The merged cum_value is the sum of the source and target
kono
parents: 9
diff changeset
860 components. */
kono
parents: 9
diff changeset
861 merge_cum = merge_src_cum + merge_tgt_cum;
kono
parents: 9
diff changeset
862
kono
parents: 9
diff changeset
863 /* Update the remaining number of counters and cum_value left
kono
parents: 9
diff changeset
864 to be merged from this source and target entry. */
kono
parents: 9
diff changeset
865 src_cum -= merge_src_cum;
kono
parents: 9
diff changeset
866 tgt_cum -= merge_tgt_cum;
kono
parents: 9
diff changeset
867 src_num -= merge_num;
kono
parents: 9
diff changeset
868 tgt_num -= merge_num;
kono
parents: 9
diff changeset
869
kono
parents: 9
diff changeset
870 /* The merged counters get placed in the new merged histogram
kono
parents: 9
diff changeset
871 at the entry for the merged min_value. */
kono
parents: 9
diff changeset
872 tmp_i = gcov_histo_index (merge_min);
kono
parents: 9
diff changeset
873 gcov_nonruntime_assert (tmp_i < GCOV_HISTOGRAM_SIZE);
kono
parents: 9
diff changeset
874 tmp_histo[tmp_i].num_counters += merge_num;
kono
parents: 9
diff changeset
875 tmp_histo[tmp_i].cum_value += merge_cum;
kono
parents: 9
diff changeset
876 if (!tmp_histo[tmp_i].min_value ||
kono
parents: 9
diff changeset
877 merge_min < tmp_histo[tmp_i].min_value)
kono
parents: 9
diff changeset
878 tmp_histo[tmp_i].min_value = merge_min;
kono
parents: 9
diff changeset
879
kono
parents: 9
diff changeset
880 /* Ensure the search for the next non-zero src_histo entry starts
kono
parents: 9
diff changeset
881 at the next smallest histogram bucket. */
kono
parents: 9
diff changeset
882 if (!src_num)
kono
parents: 9
diff changeset
883 src_i--;
kono
parents: 9
diff changeset
884 }
kono
parents: 9
diff changeset
885 }
kono
parents: 9
diff changeset
886
kono
parents: 9
diff changeset
887 gcov_nonruntime_assert (tgt_i < 0);
kono
parents: 9
diff changeset
888
kono
parents: 9
diff changeset
889 /* In the case where there were more counters in the source histogram,
kono
parents: 9
diff changeset
890 accumulate the remaining unmerged cumulative counter values. Add
kono
parents: 9
diff changeset
891 those to the smallest non-zero target histogram entry. Otherwise,
kono
parents: 9
diff changeset
892 the total cumulative counter values in the histogram will be smaller
kono
parents: 9
diff changeset
893 than the sum_all stored in the summary, which will complicate
kono
parents: 9
diff changeset
894 computing the working set information from the histogram later on. */
kono
parents: 9
diff changeset
895 if (src_num)
kono
parents: 9
diff changeset
896 src_i--;
kono
parents: 9
diff changeset
897 while (src_i >= 0)
kono
parents: 9
diff changeset
898 {
kono
parents: 9
diff changeset
899 src_cum += src_histo[src_i].cum_value;
kono
parents: 9
diff changeset
900 src_i--;
kono
parents: 9
diff changeset
901 }
kono
parents: 9
diff changeset
902 /* At this point, tmp_i should be the smallest non-zero entry in the
kono
parents: 9
diff changeset
903 tmp_histo. */
kono
parents: 9
diff changeset
904 gcov_nonruntime_assert (tmp_i >= 0 && tmp_i < GCOV_HISTOGRAM_SIZE
kono
parents: 9
diff changeset
905 && tmp_histo[tmp_i].num_counters > 0);
kono
parents: 9
diff changeset
906 tmp_histo[tmp_i].cum_value += src_cum;
kono
parents: 9
diff changeset
907
kono
parents: 9
diff changeset
908 /* Finally, copy the merged histogram into tgt_histo. */
kono
parents: 9
diff changeset
909 memcpy (tgt_histo, tmp_histo,
kono
parents: 9
diff changeset
910 sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE);
kono
parents: 9
diff changeset
911 }
kono
parents: 9
diff changeset
912 #endif /* !IN_GCOV */
kono
parents: 9
diff changeset
913
kono
parents: 9
diff changeset
914 /* This is used by gcov-dump (IN_GCOV == -1) and in the compiler
kono
parents: 9
diff changeset
915 (!IN_GCOV && !IN_LIBGCOV). */
kono
parents: 9
diff changeset
916 #if IN_GCOV <= 0 && !IN_LIBGCOV
kono
parents: 9
diff changeset
917 /* Compute the working set information from the counter histogram in
kono
parents: 9
diff changeset
918 the profile summary. This is an array of information corresponding to a
kono
parents: 9
diff changeset
919 range of percentages of the total execution count (sum_all), and includes
kono
parents: 9
diff changeset
920 the number of counters required to cover that working set percentage and
kono
parents: 9
diff changeset
921 the minimum counter value in that working set. */
kono
parents: 9
diff changeset
922
kono
parents: 9
diff changeset
923 GCOV_LINKAGE void
kono
parents: 9
diff changeset
924 compute_working_sets (const struct gcov_ctr_summary *summary,
kono
parents: 9
diff changeset
925 gcov_working_set_t *gcov_working_sets)
kono
parents: 9
diff changeset
926 {
kono
parents: 9
diff changeset
927 gcov_type working_set_cum_values[NUM_GCOV_WORKING_SETS];
kono
parents: 9
diff changeset
928 gcov_type ws_cum_hotness_incr;
kono
parents: 9
diff changeset
929 gcov_type cum, tmp_cum;
kono
parents: 9
diff changeset
930 const gcov_bucket_type *histo_bucket;
kono
parents: 9
diff changeset
931 unsigned ws_ix, c_num, count;
kono
parents: 9
diff changeset
932 int h_ix;
kono
parents: 9
diff changeset
933
kono
parents: 9
diff changeset
934 /* Compute the amount of sum_all that the cumulative hotness grows
kono
parents: 9
diff changeset
935 by in each successive working set entry, which depends on the
kono
parents: 9
diff changeset
936 number of working set entries. */
kono
parents: 9
diff changeset
937 ws_cum_hotness_incr = summary->sum_all / NUM_GCOV_WORKING_SETS;
kono
parents: 9
diff changeset
938
kono
parents: 9
diff changeset
939 /* Next fill in an array of the cumulative hotness values corresponding
kono
parents: 9
diff changeset
940 to each working set summary entry we are going to compute below.
kono
parents: 9
diff changeset
941 Skip 0% statistics, which can be extrapolated from the
kono
parents: 9
diff changeset
942 rest of the summary data. */
kono
parents: 9
diff changeset
943 cum = ws_cum_hotness_incr;
kono
parents: 9
diff changeset
944 for (ws_ix = 0; ws_ix < NUM_GCOV_WORKING_SETS;
kono
parents: 9
diff changeset
945 ws_ix++, cum += ws_cum_hotness_incr)
kono
parents: 9
diff changeset
946 working_set_cum_values[ws_ix] = cum;
kono
parents: 9
diff changeset
947 /* The last summary entry is reserved for (roughly) 99.9% of the
kono
parents: 9
diff changeset
948 working set. Divide by 1024 so it becomes a shift, which gives
kono
parents: 9
diff changeset
949 almost exactly 99.9%. */
kono
parents: 9
diff changeset
950 working_set_cum_values[NUM_GCOV_WORKING_SETS-1]
kono
parents: 9
diff changeset
951 = summary->sum_all - summary->sum_all/1024;
kono
parents: 9
diff changeset
952
kono
parents: 9
diff changeset
953 /* Next, walk through the histogram in decending order of hotness
kono
parents: 9
diff changeset
954 and compute the statistics for the working set summary array.
kono
parents: 9
diff changeset
955 As histogram entries are accumulated, we check to see which
kono
parents: 9
diff changeset
956 working set entries have had their expected cum_value reached
kono
parents: 9
diff changeset
957 and fill them in, walking the working set entries in increasing
kono
parents: 9
diff changeset
958 size of cum_value. */
kono
parents: 9
diff changeset
959 ws_ix = 0; /* The current entry into the working set array. */
kono
parents: 9
diff changeset
960 cum = 0; /* The current accumulated counter sum. */
kono
parents: 9
diff changeset
961 count = 0; /* The current accumulated count of block counters. */
kono
parents: 9
diff changeset
962 for (h_ix = GCOV_HISTOGRAM_SIZE - 1;
kono
parents: 9
diff changeset
963 h_ix >= 0 && ws_ix < NUM_GCOV_WORKING_SETS; h_ix--)
kono
parents: 9
diff changeset
964 {
kono
parents: 9
diff changeset
965 histo_bucket = &summary->histogram[h_ix];
kono
parents: 9
diff changeset
966
kono
parents: 9
diff changeset
967 /* If we haven't reached the required cumulative counter value for
kono
parents: 9
diff changeset
968 the current working set percentage, simply accumulate this histogram
kono
parents: 9
diff changeset
969 entry into the running sums and continue to the next histogram
kono
parents: 9
diff changeset
970 entry. */
kono
parents: 9
diff changeset
971 if (cum + histo_bucket->cum_value < working_set_cum_values[ws_ix])
kono
parents: 9
diff changeset
972 {
kono
parents: 9
diff changeset
973 cum += histo_bucket->cum_value;
kono
parents: 9
diff changeset
974 count += histo_bucket->num_counters;
kono
parents: 9
diff changeset
975 continue;
kono
parents: 9
diff changeset
976 }
kono
parents: 9
diff changeset
977
kono
parents: 9
diff changeset
978 /* If adding the current histogram entry's cumulative counter value
kono
parents: 9
diff changeset
979 causes us to exceed the current working set size, then estimate
kono
parents: 9
diff changeset
980 how many of this histogram entry's counter values are required to
kono
parents: 9
diff changeset
981 reach the working set size, and fill in working set entries
kono
parents: 9
diff changeset
982 as we reach their expected cumulative value. */
kono
parents: 9
diff changeset
983 for (c_num = 0, tmp_cum = cum;
kono
parents: 9
diff changeset
984 c_num < histo_bucket->num_counters && ws_ix < NUM_GCOV_WORKING_SETS;
kono
parents: 9
diff changeset
985 c_num++)
kono
parents: 9
diff changeset
986 {
kono
parents: 9
diff changeset
987 count++;
kono
parents: 9
diff changeset
988 /* If we haven't reached the last histogram entry counter, add
kono
parents: 9
diff changeset
989 in the minimum value again. This will underestimate the
kono
parents: 9
diff changeset
990 cumulative sum so far, because many of the counter values in this
kono
parents: 9
diff changeset
991 entry may have been larger than the minimum. We could add in the
kono
parents: 9
diff changeset
992 average value every time, but that would require an expensive
kono
parents: 9
diff changeset
993 divide operation. */
kono
parents: 9
diff changeset
994 if (c_num + 1 < histo_bucket->num_counters)
kono
parents: 9
diff changeset
995 tmp_cum += histo_bucket->min_value;
kono
parents: 9
diff changeset
996 /* If we have reached the last histogram entry counter, then add
kono
parents: 9
diff changeset
997 in the entire cumulative value. */
kono
parents: 9
diff changeset
998 else
kono
parents: 9
diff changeset
999 tmp_cum = cum + histo_bucket->cum_value;
kono
parents: 9
diff changeset
1000
kono
parents: 9
diff changeset
1001 /* Next walk through successive working set entries and fill in
kono
parents: 9
diff changeset
1002 the statistics for any whose size we have reached by accumulating
kono
parents: 9
diff changeset
1003 this histogram counter. */
kono
parents: 9
diff changeset
1004 while (ws_ix < NUM_GCOV_WORKING_SETS
kono
parents: 9
diff changeset
1005 && tmp_cum >= working_set_cum_values[ws_ix])
kono
parents: 9
diff changeset
1006 {
kono
parents: 9
diff changeset
1007 gcov_working_sets[ws_ix].num_counters = count;
kono
parents: 9
diff changeset
1008 gcov_working_sets[ws_ix].min_counter
kono
parents: 9
diff changeset
1009 = histo_bucket->min_value;
kono
parents: 9
diff changeset
1010 ws_ix++;
kono
parents: 9
diff changeset
1011 }
kono
parents: 9
diff changeset
1012 }
kono
parents: 9
diff changeset
1013 /* Finally, update the running cumulative value since we were
kono
parents: 9
diff changeset
1014 using a temporary above. */
kono
parents: 9
diff changeset
1015 cum += histo_bucket->cum_value;
kono
parents: 9
diff changeset
1016 }
kono
parents: 9
diff changeset
1017 gcov_nonruntime_assert (ws_ix == NUM_GCOV_WORKING_SETS);
kono
parents: 9
diff changeset
1018 }
kono
parents: 9
diff changeset
1019 #endif /* IN_GCOV <= 0 && !IN_LIBGCOV */