Mercurial > ~dholland > hg > tradcpp > index.cgi
annotate place.c @ 199:1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
Intended to be used when debugging imake templates and other complex
input, not for debugging tradcpp itself.
author | David A. Holland |
---|---|
date | Sun, 04 Sep 2016 17:14:42 -0400 |
parents | 16b4451e34b8 |
children | 3a25180d3a5c |
rev | line source |
---|---|
30 | 1 /*- |
2 * Copyright (c) 2010 The NetBSD Foundation, Inc. | |
3 * All rights reserved. | |
4 * | |
5 * This code is derived from software contributed to The NetBSD Foundation | |
6 * by David A. Holland. | |
7 * | |
8 * Redistribution and use in source and binary forms, with or without | |
9 * modification, are permitted provided that the following conditions | |
10 * are met: | |
11 * 1. Redistributions of source code must retain the above copyright | |
12 * notice, this list of conditions and the following disclaimer. | |
13 * 2. Redistributions in binary form must reproduce the above copyright | |
14 * notice, this list of conditions and the following disclaimer in the | |
15 * documentation and/or other materials provided with the distribution. | |
16 * | |
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | |
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
27 * POSSIBILITY OF SUCH DAMAGE. | |
28 */ | |
29 | |
8 | 30 #include <assert.h> |
31 #include <stdarg.h> | |
32 #include <stdio.h> | |
33 #include <stdlib.h> | |
112 | 34 #include <string.h> |
199
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
35 #include <errno.h> |
8 | 36 |
37 #include "utils.h" | |
10 | 38 #include "array.h" |
8 | 39 #include "place.h" |
40 | |
13 | 41 struct placefile { |
10 | 42 struct place includedfrom; |
112 | 43 char *dir; |
10 | 44 char *name; |
28 | 45 int depth; |
10 | 46 bool fromsystemdir; |
47 }; | |
107 | 48 DECLARRAY(placefile, static UNUSED); |
47
2e25e55dba6b
Fix inline usage as per the version in dholland-make2.
David A. Holland
parents:
39
diff
changeset
|
49 DEFARRAY(placefile, static); |
10 | 50 |
13 | 51 static struct placefilearray placefiles; |
10 | 52 static bool overall_failure; |
53 | |
142 | 54 static const char *myprogname; |
55 | |
199
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
56 static FILE *debuglogfile; |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
57 |
10 | 58 //////////////////////////////////////////////////////////// |
176
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
59 // placefiles |
10 | 60 |
61 static | |
13 | 62 struct placefile * |
63 placefile_create(const struct place *from, const char *name, | |
64 bool fromsystemdir) | |
10 | 65 { |
13 | 66 struct placefile *pf; |
112 | 67 const char *s; |
68 size_t len; | |
10 | 69 |
13 | 70 pf = domalloc(sizeof(*pf)); |
71 pf->includedfrom = *from; | |
112 | 72 |
73 s = strrchr(name, '/'); | |
74 len = (s == NULL) ? 0 : s - name; | |
75 pf->dir = dostrndup(name, len); | |
76 | |
13 | 77 pf->name = dostrdup(name); |
78 pf->fromsystemdir = fromsystemdir; | |
112 | 79 |
28 | 80 if (from->file != NULL) { |
81 pf->depth = from->file->depth + 1; | |
82 } else { | |
83 pf->depth = 1; | |
84 } | |
13 | 85 return pf; |
10 | 86 } |
87 | |
88 static | |
89 void | |
13 | 90 placefile_destroy(struct placefile *pf) |
10 | 91 { |
39
337110e7240a
Pass the size to free; it makes debug checking easier.
David A. Holland
parents:
38
diff
changeset
|
92 dostrfree(pf->name); |
337110e7240a
Pass the size to free; it makes debug checking easier.
David A. Holland
parents:
38
diff
changeset
|
93 dofree(pf, sizeof(*pf)); |
10 | 94 } |
95 | |
13 | 96 DESTROYALL_ARRAY(placefile, ); |
10 | 97 |
112 | 98 const char * |
99 place_getparsedir(const struct place *place) | |
100 { | |
101 if (place->file == NULL) { | |
102 return "."; | |
103 } | |
104 return place->file->dir; | |
105 } | |
106 | |
176
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
107 static |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
108 struct placefile * |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
109 placefile_find(const struct place *incfrom, const char *name) |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
110 { |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
111 unsigned i, num; |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
112 struct placefile *pf; |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
113 |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
114 num = placefilearray_num(&placefiles); |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
115 for (i=0; i<num; i++) { |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
116 pf = placefilearray_get(&placefiles, i); |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
117 if (place_eq(incfrom, &pf->includedfrom) && |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
118 !strcmp(name, pf->name)) { |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
119 return pf; |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
120 } |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
121 } |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
122 return NULL; |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
123 } |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
124 |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
125 void |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
126 place_changefile(struct place *p, const char *name) |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
127 { |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
128 struct placefile *pf; |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
129 |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
130 assert(p->type == P_FILE); |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
131 if (!strcmp(name, p->file->name)) { |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
132 return; |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
133 } |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
134 pf = placefile_find(&p->file->includedfrom, name); |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
135 if (pf == NULL) { |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
136 pf = placefile_create(&p->file->includedfrom, name, |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
137 p->file->fromsystemdir); |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
138 placefilearray_add(&placefiles, pf, NULL); |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
139 } |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
140 p->file = pf; |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
141 } |
a2f047301c15
Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents:
160
diff
changeset
|
142 |
13 | 143 const struct placefile * |
144 place_addfile(const struct place *place, const char *file, bool issystem) | |
10 | 145 { |
13 | 146 struct placefile *pf; |
10 | 147 |
13 | 148 pf = placefile_create(place, file, issystem); |
149 placefilearray_add(&placefiles, pf, NULL); | |
114
05d67dd74e1f
Reduce the maximum include depth from 128 to 120.
David A. Holland
parents:
112
diff
changeset
|
150 if (pf->depth > 120) { |
28 | 151 complain(place, "Maximum include nesting depth exceeded"); |
152 die(); | |
153 } | |
13 | 154 return pf; |
10 | 155 } |
156 | |
157 //////////////////////////////////////////////////////////// | |
158 // places | |
159 | |
8 | 160 void |
161 place_setnowhere(struct place *p) | |
162 { | |
12 | 163 p->type = P_NOWHERE; |
8 | 164 p->file = NULL; |
12 | 165 p->line = 0; |
8 | 166 p->column = 0; |
167 } | |
168 | |
169 void | |
170 place_setbuiltin(struct place *p, unsigned num) | |
171 { | |
12 | 172 p->type = P_BUILTIN; |
8 | 173 p->file = NULL; |
12 | 174 p->line = num; |
175 p->column = 1; | |
8 | 176 } |
177 | |
178 void | |
14 | 179 place_setcommandline(struct place *p, unsigned line, unsigned column) |
8 | 180 { |
14 | 181 p->type = P_COMMANDLINE; |
8 | 182 p->file = NULL; |
14 | 183 p->line = line; |
8 | 184 p->column = column; |
185 } | |
186 | |
14 | 187 void |
188 place_setfilestart(struct place *p, const struct placefile *pf) | |
189 { | |
28 | 190 p->type = P_FILE; |
14 | 191 p->file = pf; |
192 p->line = 1; | |
193 p->column = 1; | |
194 } | |
195 | |
12 | 196 const char * |
197 place_getname(const struct place *p) | |
8 | 198 { |
12 | 199 switch (p->type) { |
200 case P_NOWHERE: return "<nowhere>"; | |
201 case P_BUILTIN: return "<built-in>"; | |
202 case P_COMMANDLINE: return "<command-line>"; | |
203 case P_FILE: return p->file->name; | |
8 | 204 } |
12 | 205 assert(0); |
206 return NULL; | |
8 | 207 } |
208 | |
185
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
209 bool |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
210 place_samefile(const struct place *a, const struct place *b) |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
211 { |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
212 if (a->type != b->type) { |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
213 return false; |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
214 } |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
215 if (a->file != b->file) { |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
216 return false; |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
217 } |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
218 return true; |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
219 } |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
220 |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
221 bool |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
222 place_eq(const struct place *a, const struct place *b) |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
223 { |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
224 if (!place_samefile(a, b)) { |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
225 return false; |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
226 } |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
227 if (a->line != b->line || a->column != b->column) { |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
228 return false; |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
229 } |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
230 return true; |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
231 } |
16b4451e34b8
Add the ability to output line numbers, sort of.
David A. Holland
parents:
176
diff
changeset
|
232 |
8 | 233 static |
234 void | |
235 place_printfrom(const struct place *p) | |
236 { | |
237 const struct place *from; | |
238 | |
95
1c0575f7dd46
Don't crash printing the commandline place.
David A. Holland
parents:
47
diff
changeset
|
239 if (p->file == NULL) { |
1c0575f7dd46
Don't crash printing the commandline place.
David A. Holland
parents:
47
diff
changeset
|
240 return; |
1c0575f7dd46
Don't crash printing the commandline place.
David A. Holland
parents:
47
diff
changeset
|
241 } |
10 | 242 from = &p->file->includedfrom; |
12 | 243 if (from->type != P_NOWHERE) { |
8 | 244 place_printfrom(from); |
12 | 245 fprintf(stderr, "In file included from %s:%u:%u:\n", |
246 place_getname(from), from->line, from->column); | |
8 | 247 } |
248 } | |
249 | |
10 | 250 //////////////////////////////////////////////////////////// |
251 // complaints | |
252 | |
8 | 253 void |
142 | 254 complain_init(const char *pn) |
255 { | |
256 myprogname = pn; | |
257 } | |
258 | |
259 void | |
8 | 260 complain(const struct place *p, const char *fmt, ...) |
261 { | |
262 va_list ap; | |
263 | |
142 | 264 if (p != NULL) { |
265 place_printfrom(p); | |
266 fprintf(stderr, "%s:%u:%u: ", place_getname(p), | |
267 p->line, p->column); | |
268 } else { | |
269 fprintf(stderr, "%s: ", myprogname); | |
270 } | |
8 | 271 va_start(ap, fmt); |
272 vfprintf(stderr, fmt, ap); | |
273 va_end(ap); | |
274 fprintf(stderr, "\n"); | |
275 } | |
276 | |
277 void | |
278 complain_fail(void) | |
279 { | |
280 overall_failure = true; | |
281 } | |
282 | |
283 bool | |
284 complain_failed(void) | |
285 { | |
286 return overall_failure; | |
287 } | |
288 | |
10 | 289 //////////////////////////////////////////////////////////// |
199
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
290 // debug logging |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
291 |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
292 void |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
293 debuglog_open(const struct place *p, /*const*/ char *file) |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
294 { |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
295 assert(debuglogfile == NULL); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
296 debuglogfile = fopen(file, "w"); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
297 if (debuglogfile == NULL) { |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
298 complain(p, "%s: %s", file, strerror(errno)); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
299 die(); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
300 } |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
301 } |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
302 |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
303 void |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
304 debuglog_close(void) |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
305 { |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
306 if (debuglogfile != NULL) { |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
307 fclose(debuglogfile); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
308 debuglogfile = NULL; |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
309 } |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
310 } |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
311 |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
312 PF(2, 3) void |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
313 debuglog(const struct place *p, const char *fmt, ...) |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
314 { |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
315 va_list ap; |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
316 |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
317 if (debuglogfile == NULL) { |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
318 return; |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
319 } |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
320 |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
321 fprintf(debuglogfile, "%s:%u: ", place_getname(p), p->line); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
322 va_start(ap, fmt); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
323 vfprintf(debuglogfile, fmt, ap); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
324 va_end(ap); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
325 fprintf(debuglogfile, "\n"); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
326 fflush(debuglogfile); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
327 } |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
328 |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
329 PF(3, 4) void |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
330 debuglog2(const struct place *p, const struct place *p2, const char *fmt, ...) |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
331 { |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
332 va_list ap; |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
333 |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
334 if (debuglogfile == NULL) { |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
335 return; |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
336 } |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
337 |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
338 fprintf(debuglogfile, "%s:%u: ", place_getname(p), p->line); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
339 if (place_samefile(p, p2)) { |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
340 fprintf(debuglogfile, "(block began at line %u) ", |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
341 p2->line); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
342 } else { |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
343 fprintf(debuglogfile, "(block began at %s:%u)", |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
344 place_getname(p2), p2->line); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
345 } |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
346 va_start(ap, fmt); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
347 vfprintf(debuglogfile, fmt, ap); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
348 va_end(ap); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
349 fprintf(debuglogfile, "\n"); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
350 fflush(debuglogfile); |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
351 } |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
352 |
1d2bad7151f9
Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents:
185
diff
changeset
|
353 //////////////////////////////////////////////////////////// |
10 | 354 // module init and cleanup |
355 | |
356 void | |
357 place_init(void) | |
358 { | |
13 | 359 placefilearray_init(&placefiles); |
10 | 360 } |
361 | |
362 void | |
363 place_cleanup(void) | |
364 { | |
13 | 365 placefilearray_destroyall(&placefiles); |
366 placefilearray_cleanup(&placefiles); | |
10 | 367 } |