@@ -176,7 +176,7 @@ size_t parse_logging_spec(char* spec, log_directive* dirs) {
176
176
}
177
177
178
178
void update_module_map (const mod_entry* map, log_directive* dirs,
179
- size_t n_dirs) {
179
+ size_t n_dirs, size_t *n_matches ) {
180
180
for (const mod_entry* cur = map; cur->name ; cur++) {
181
181
size_t level = default_log_level, longest_match = 0 ;
182
182
for (size_t d = 0 ; d < n_dirs; d++) {
@@ -187,18 +187,28 @@ void update_module_map(const mod_entry* map, log_directive* dirs,
187
187
}
188
188
}
189
189
*cur->state = level;
190
+ (*n_matches)++;
190
191
}
191
192
}
192
193
193
194
void update_crate_map (const cratemap* map, log_directive* dirs,
194
- size_t n_dirs) {
195
+ size_t n_dirs, size_t *n_matches ) {
195
196
// First update log levels for this crate
196
- update_module_map (map->entries , dirs, n_dirs);
197
+ update_module_map (map->entries , dirs, n_dirs, n_matches );
197
198
// Then recurse on linked crates
198
199
// FIXME this does double work in diamond-shaped deps. could keep
199
200
// a set of visited addresses, if it turns out to be actually slow
200
201
for (size_t i = 0 ; map->children [i]; i++) {
201
- update_crate_map (map->children [i], dirs, n_dirs);
202
+ update_crate_map (map->children [i], dirs, n_dirs, n_matches);
203
+ }
204
+ }
205
+
206
+ void print_crate_log_map (const cratemap* map) {
207
+ for (const mod_entry* cur = map->entries ; cur->name ; cur++) {
208
+ printf (" %s\n " , cur->name );
209
+ }
210
+ for (size_t i = 0 ; map->children [i]; i++) {
211
+ print_crate_log_map (map->children [i]);
202
212
}
203
213
}
204
214
@@ -218,33 +228,61 @@ size_t log_rt_kern;
218
228
size_t log_rt_backtrace;
219
229
220
230
static const mod_entry _rt_module_map[] =
221
- {{" rt::mem" , &log_rt_mem},
222
- {" rt::comm" , &log_rt_comm},
223
- {" rt::task" , &log_rt_task},
224
- {" rt::dom" , &log_rt_dom},
225
- {" rt::trace" , &log_rt_trace},
226
- {" rt::cache" , &log_rt_cache},
227
- {" rt::upcall" , &log_rt_upcall},
228
- {" rt::timer" , &log_rt_timer},
229
- {" rt::gc" , &log_rt_gc},
230
- {" rt::stdlib" , &log_rt_stdlib},
231
- {" rt::kern" , &log_rt_kern},
232
- {" rt::backtrace" , &log_rt_backtrace},
231
+ {{" :: rt::mem" , &log_rt_mem},
232
+ {" :: rt::comm" , &log_rt_comm},
233
+ {" :: rt::task" , &log_rt_task},
234
+ {" :: rt::dom" , &log_rt_dom},
235
+ {" :: rt::trace" , &log_rt_trace},
236
+ {" :: rt::cache" , &log_rt_cache},
237
+ {" :: rt::upcall" , &log_rt_upcall},
238
+ {" :: rt::timer" , &log_rt_timer},
239
+ {" :: rt::gc" , &log_rt_gc},
240
+ {" :: rt::stdlib" , &log_rt_stdlib},
241
+ {" :: rt::kern" , &log_rt_kern},
242
+ {" :: rt::backtrace" , &log_rt_backtrace},
233
243
{NULL , NULL }};
234
244
235
245
void update_log_settings (void * crate_map, char * settings) {
236
246
char * buffer = NULL ;
237
247
log_directive dirs[256 ];
238
248
size_t n_dirs = 0 ;
249
+
239
250
if (settings) {
251
+
252
+ if (strcmp (settings, " ::help" ) == 0 ||
253
+ strcmp (settings, " ?" ) == 0 ) {
254
+ printf (" \n Crate log map:\n\n " );
255
+ print_crate_log_map ((const cratemap*)crate_map);
256
+ printf (" \n " );
257
+ exit (1 );
258
+ }
259
+
240
260
size_t buflen = strlen (settings) + 1 ;
241
261
buffer = (char *)malloc (buflen);
242
262
strncpy (buffer, settings, buflen);
243
263
n_dirs = parse_logging_spec (buffer, &dirs[0 ]);
244
264
}
245
265
246
- update_module_map (_rt_module_map, &dirs[0 ], n_dirs);
247
- update_crate_map ((const cratemap*)crate_map, &dirs[0 ], n_dirs);
266
+ size_t n_matches = 0 ;
267
+ update_module_map (_rt_module_map, &dirs[0 ], n_dirs, &n_matches);
268
+ update_crate_map ((const cratemap*)crate_map, &dirs[0 ],
269
+ n_dirs, &n_matches);
270
+
271
+ if (n_matches < n_dirs) {
272
+ printf (" warning: got %d RUST_LOG specs, enabled %d flags." ,
273
+ n_dirs, n_matches);
274
+ }
248
275
249
276
free (buffer);
250
277
}
278
+
279
+ //
280
+ // Local Variables:
281
+ // mode: C++
282
+ // fill-column: 78;
283
+ // indent-tabs-mode: nil
284
+ // c-basic-offset: 4
285
+ // buffer-file-coding-system: utf-8-unix
286
+ // compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
287
+ // End:
288
+ //
0 commit comments