Alexey Kardashevskiy writes: > On 05/28/2014 10:34 PM, Lluís Vilanova wrote: >> Stefan Hajnoczi writes: >> >>> On Wed, May 21, 2014 at 06:16:01PM +1000, Alexey Kardashevskiy wrote: >>>> At the moment QEMU exits if trace point is not defined which makes >>>> a developer life harder if he has to switch between branches with >>>> different traces implemented. >>>> >>>> This replaces error+exit wit WARNING if the tracepoint does not exist or >>>> not traceable. >>>> >>>> Signed-off-by: Alexey Kardashevskiy <a...@ozlabs.ru> >>>> --- >>>> >>>> >>>> That would make my life easier indeed. Thanks :) >>>> >>>> >>>> --- >>>> trace/control.c | 14 +++++++------- >>>> 1 file changed, 7 insertions(+), 7 deletions(-) >> >>> Thanks, applied to my tracing tree: >>> https://github.com/stefanha/qemu/commits/tracing >> >> I was doing some silly tests with "error_report". Would it be worth to port >> all >> these printfs to it? >> >> It also makes it prettier to see, for example, what line in the event list >> file >> failed when executing 'trace_init_events'.
> Yep, I'll cook another patch, with error_report + line#. Here's some initial patch, if you want. It is not rebased on top of your non-exiting patch, though. Thanks, Lluis diff --git a/trace/control.c b/trace/control.c index cbbaadf..7876366 100644 --- a/trace/control.c +++ b/trace/control.c @@ -16,6 +16,7 @@ #ifdef CONFIG_TRACE_FTRACE #include "trace/ftrace.h" #endif +#include "qemu/error-report.h" #include "qemu-common.h" @@ -108,14 +109,18 @@ static void trace_init_events(const char *fname) return; } + Location loc; + loc_push_none(&loc); + loc_set_file(fname, 0); FILE *fp = fopen(fname, "r"); if (!fp) { - fprintf(stderr, "error: could not open trace events file '%s': %s\n", - fname, strerror(errno)); + error_report("%s", strerror(errno)); exit(1); } char line_buf[1024]; + size_t line_idx = 0; 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'; @@ -134,13 +139,11 @@ static void trace_init_events(const char *fname) } else { TraceEvent *ev = trace_event_name(line_ptr); if (ev == NULL) { - fprintf(stderr, - "error: trace event '%s' does not exist\n", line_ptr); + error_report("trace event '%s' does not exist", line_ptr); exit(1); } if (!trace_event_get_state_static(ev)) { - fprintf(stderr, - "error: trace event '%s' is not traceable\n", line_ptr); + error_report("trace event '%s' is not traceable\n", line_ptr); exit(1); } trace_event_set_state_dynamic(ev, enable); @@ -148,10 +151,11 @@ static void trace_init_events(const char *fname) } } if (fclose(fp) != 0) { - fprintf(stderr, "error: closing file '%s': %s\n", - fname, strerror(errno)); + loc_set_file(fname, 0); + error_report("%s", strerror(errno)); exit(1); } + loc_pop(&loc); } bool trace_init_backends(const char *events, const char *file)