char *trace_opt_parse(const char *optarg) { char *trace_file; QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("trace"), optarg, true); if (!opts) { exit(1); } if (qemu_opt_get(opts, "enable")) { trace_enable_events(qemu_opt_get(opts, "enable")); } trace_init_events(qemu_opt_get(opts, "events")); trace_file = g_strdup(qemu_opt_get(opts, "file")); qemu_opts_del(opts); return trace_file; }
/* takes a comma separated list of log masks. Return 0 if error. */ int qemu_str_to_log_mask(const char *str) { const QEMULogItem *item; int mask; const char *p, *p1; p = str; mask = 0; for (;;) { p1 = strchr(p, ','); if (!p1) { p1 = p + strlen(p); } if (cmp1(p,p1-p,"all")) { for (item = qemu_log_items; item->mask != 0; item++) { mask |= item->mask; } #ifdef CONFIG_TRACE_LOG } else if (strncmp(p, "trace:", 6) == 0 && p + 6 != p1) { trace_enable_events(p + 6); mask |= LOG_TRACE; #endif } else { for (item = qemu_log_items; item->mask != 0; item++) { if (cmp1(p, p1 - p, item->name)) { goto found; } } return 0; found: mask |= item->mask; } if (*p1 != ',') { break; } p = p1 + 1; } return mask; }
static void trace_init_events(const char *fname) { Location loc; FILE *fp; char line_buf[1024]; size_t line_idx = 0; if (fname == NULL) { return; } loc_push_none(&loc); loc_set_file(fname, 0); fp = fopen(fname, "r"); if (!fp) { error_report("%s", strerror(errno)); exit(1); } while (fgets(line_buf, sizeof(line_buf), fp)) { loc_set_file(fname, ++line_idx); size_t len = strlen(line_buf); if (len > 1) { /* skip empty lines */ line_buf[len - 1] = '\0'; if ('#' == line_buf[0]) { /* skip commented lines */ continue; } trace_enable_events(line_buf); } } if (fclose(fp) != 0) { loc_set_file(fname, 0); error_report("%s", strerror(errno)); exit(1); } loc_pop(&loc); }