Received: from eggs.gnu.org ([2001:4830:134:3::10]:58175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrBGe-0005E5-O8 for qemu-devel@nongnu.org; Sun, 01 Jun 2014 15:18:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrBGY-0005w1-F6 for qemu-devel@nongnu.org; Sun, 01 Jun 2014 15:18:04 -0400 Received: from roura.ac.upc.edu ([147.83.33.10]:58023 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrBGY-0005vj-3N for qemu-devel@nongnu.org; Sun, 01 Jun 2014 15:17:58 -0400 From: =?utf-8?Q?Llu=C3=ADs_Vilanova?= References: <1401332129-15677-1-git-send-email-aik@ozlabs.ru> <874n08iwmq.fsf@fimbulvetr.bsc.es> <5387C824.3020201@ozlabs.ru> <87bnufs6j6.fsf@fimbulvetr.bsc.es> <538B4328.8000704@ozlabs.ru> Date: Sun, 01 Jun 2014 21:17:50 +0200 In-Reply-To: <538B4328.8000704@ozlabs.ru> (Alexey Kardashevskiy's message of "Mon, 02 Jun 2014 01:13:44 +1000") Message-ID: <87k390fnhd.fsf@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] trace: Replace fprintf with error_report and print location List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexey Kardashevskiy Cc: qemu-devel@nongnu.org, Stefan Hajnoczi Alexey Kardashevskiy writes: > On 05/31/2014 12:08 AM, Llu=C3=ADs Vilanova wrote: >> Alexey Kardashevskiy writes: >>=20 >>> On 05/29/2014 10:42 PM, Llu=C3=ADs Vilanova wrote: >>>> Alexey Kardashevskiy writes: >>>>=20 >>>>> This replaces fprintf(stderr) with error_report. >>>>> This prints line number of the trace which does not exist or is not >>>>> traceable. >>>>=20 >>>> A little nit pick; it shows an error when some of the events in the li= st of >>>> events to enable (not the trace) does not exist or is not traceable. >>=20 >>=20 >>> Sorry, I am not following you. It shows me this: >>=20 >>> qemu-system-ppc64:/home/aik/qemu_trace_events:75: WARNING: trace event >>> 'mememe' does not exist >>=20 >>> and continues. This exactly what I wanted. >>=20 >> Yes, that's right. All I'm saying is that the commit message is a little= bit >> misleading. These are not the line numbers of a trace, but the line numb= ers of a >> list of events to enable when QEMU starts. > Like this? Thanks. > =3D=3D=3D > This replaces fprintf(stderr) with error_report. > This prints the line number of a list of events which does not exist or is > not traceable. > This moves local variables to the beginning of the function because of > the QEMU coding style. > =3D=3D=3D I think there is no need to describe what that function is doing. Instead I would say something like: Replaces fprintf(stdeer) with error_report. Also moves some local variables to the beginning of the function to comply with QEMU's coding style. Thanks, Lluis >>=20 >>=20 >> Thanks, >> Lluis >>=20 >>=20 >>>>=20 >>>>=20 >>>> Thanks, >>>> Lluis >>>>=20 >>>>=20 >>>>> This moves local variables to the beginning of the function because of >>>>> the QEMU coding style. >>>>=20 >>>>> Suggested-by: Llu=C3=ADs Vilanova >>>>> Signed-off-by: Alexey Kardashevskiy >>>>> --- >>>>=20 >>>>> Llu=C3=ADs, or it is s/Suggested-by/From/ ? >>>>=20 >>>>> Stefan, this is made on top of "trace: Replace error with warning if = event is not defined" >>>>=20 >>>>> --- >>>>> trace/control.c | 31 ++++++++++++++++++------------- >>>>> 1 file changed, 18 insertions(+), 13 deletions(-) >>>>=20 >>>>> diff --git a/trace/control.c b/trace/control.c >>>>> index 4aa02cf..4ee2bd2 100644 >>>>> --- a/trace/control.c >>>>> +++ b/trace/control.c >>>>> @@ -8,7 +8,7 @@ >>>>> */ >>>>=20 >>>>> #include "trace/control.h" >>>>> - >>>>> +#include "qemu/error-report.h" >>>>=20 >>>>> TraceEvent *trace_event_name(const char *name) >>>>> { >>>>> @@ -81,18 +81,24 @@ TraceEvent *trace_event_pattern(const char *pat, = TraceEvent *ev) >>>>=20 >>>>> void trace_backend_init_events(const char *fname) >>>>> { >>>>> + Location loc; >>>>> + FILE *fp; >>>>> + char line_buf[1024]; >>>>> + size_t line_idx =3D 0; >>>>> + >>>>> if (fname =3D=3D NULL) { >>>>> return; >>>>> } >>>>=20 >>>>> - FILE *fp =3D fopen(fname, "r"); >>>>> + loc_push_none(&loc); >>>>> + loc_set_file(fname, 0); >>>>> + fp =3D 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]; >>>>> while (fgets(line_buf, sizeof(line_buf), fp)) { >>>>> + loc_set_file(fname, ++line_idx); >>>>> size_t len =3D strlen(line_buf); >>>>> if (len > 1) { /* skip empty lines */ >>>>> line_buf[len - 1] =3D '\0'; >>>>> @@ -111,13 +117,11 @@ void trace_backend_init_events(const char *fnam= e) >>>>> } else { >>>>> TraceEvent *ev =3D trace_event_name(line_ptr); >>>>> if (ev =3D=3D NULL) { >>>>> - fprintf(stderr, >>>>> - "WARNING: trace event '%s' does not exis= t\n", >>>>> - line_ptr); >>>>> + error_report("WARNING: trace event '%s' does not= exist", >>>>> + line_ptr); >>>>> } else if (!trace_event_get_state_static(ev)) { >>>>> - fprintf(stderr, >>>>> - "WARNING: trace event '%s' is not tracea= ble\n", >>>>> - line_ptr); >>>>> + error_report("WARNING: trace event '%s' is not t= raceable\n", >>>>> + line_ptr); >>>>> } else { >>>>> trace_event_set_state_dynamic(ev, enable); >>>>> } >>>>> @@ -125,8 +129,9 @@ void trace_backend_init_events(const char *fname) >>>>> } >>>>> } >>>>> if (fclose(fp) !=3D 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); >>>>> } > --=20 > Alexey --=20 "And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth