All of lore.kernel.org
 help / color / mirror / Atom feed
* tools lib traceevent: Report better error message on bad function args
@ 2013-11-19  0:11 Steven Rostedt
  2013-11-19  2:23 ` Namhyung Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2013-11-19  0:11 UTC (permalink / raw)
  To: LKML; +Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar,
	Frederic Weisbecker

When Jiri Olsa was writing a function callback for
scsi_trace_parse_cdb(), he thought that the traceevent library had a
bug in it because he was getting this error:

  Error: expected ')' but read ','
  Error: expected ')' but read ','
  Error: expected ')' but read ','
  Error: expected ')' but read ','

But in truth, he didn't have the write number of arguments for the
function callback, and the error was the library detecting the
discrepancy. A better error message would have prevented the confusion:

  Error: function 'scsi_trace_parse_cdb()' only expects 2 arguments but event scsi_dispatch_cmd_timeout has more
  Error: function 'scsi_trace_parse_cdb()' only expects 2 arguments but event scsi_dispatch_cmd_start has more
  Error: function 'scsi_trace_parse_cdb()' only expects 2 arguments but event scsi_dispatch_cmd_error has more
  Error: function 'scsi_trace_parse_cdb()' only expects 2 arguments but event scsi_dispatch_cmd_done has more

Or

  Error: function 'scsi_trace_parse_cdb()' expects 4 arguments but event scsi_dispatch_cmd_timeout only uses 3
  Error: function 'scsi_trace_parse_cdb()' expects 4 arguments but event scsi_dispatch_cmd_start only uses 3
  Error: function 'scsi_trace_parse_cdb()' expects 4 arguments but event scsi_dispatch_cmd_error only uses 3
  Error: function 'scsi_trace_parse_cdb()' expects 4 arguments but event scsi_dispatch_cmd_done only uses 3

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 0362d57..f7aab3d 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -2691,7 +2691,6 @@ process_func_handler(struct event_format *event, struct pevent_function_handler
 	struct print_arg *farg;
 	enum event_type type;
 	char *token;
-	const char *test;
 	int i;
 
 	arg->type = PRINT_FUNC;
@@ -2708,15 +2707,19 @@ process_func_handler(struct event_format *event, struct pevent_function_handler
 		}
 
 		type = process_arg(event, farg, &token);
-		if (i < (func->nr_args - 1))
-			test = ",";
-		else
-			test = ")";
-
-		if (test_type_token(type, token, EVENT_DELIM, test)) {
-			free_arg(farg);
-			free_token(token);
-			return EVENT_ERROR;
+		if (i < (func->nr_args - 1)) {
+			if (type != EVENT_DELIM || strcmp(token, ",") != 0) {
+				warning("Error: function '%s()' expects %d arguments but event %s only uses %d",
+					func->name, func->nr_args,
+					event->name, i + 1);
+				return EVENT_ERROR;
+			}
+		} else {
+			if (type != EVENT_DELIM || strcmp(token, ")") != 0) {
+				warning("Error: function '%s()' only expects %d arguments but event %s has more",
+					func->name, func->nr_args, event->name);
+				return EVENT_ERROR;
+			}
 		}
 
 		*next_arg = farg;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: tools lib traceevent: Report better error message on bad function args
  2013-11-19  0:11 tools lib traceevent: Report better error message on bad function args Steven Rostedt
@ 2013-11-19  2:23 ` Namhyung Kim
  2013-11-19  2:31   ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Namhyung Kim @ 2013-11-19  2:23 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: LKML, Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar,
	Frederic Weisbecker

Hi Steven,

On Mon, 18 Nov 2013 19:11:31 -0500, Steven Rostedt wrote:
> When Jiri Olsa was writing a function callback for
> scsi_trace_parse_cdb(), he thought that the traceevent library had a
> bug in it because he was getting this error:
>
>   Error: expected ')' but read ','
>   Error: expected ')' but read ','
>   Error: expected ')' but read ','
>   Error: expected ')' but read ','
>
> But in truth, he didn't have the write number of arguments for the
> function callback, and the error was the library detecting the
> discrepancy. A better error message would have prevented the confusion:
>
>   Error: function 'scsi_trace_parse_cdb()' only expects 2 arguments but event scsi_dispatch_cmd_timeout has more
>   Error: function 'scsi_trace_parse_cdb()' only expects 2 arguments but event scsi_dispatch_cmd_start has more
>   Error: function 'scsi_trace_parse_cdb()' only expects 2 arguments but event scsi_dispatch_cmd_error has more
>   Error: function 'scsi_trace_parse_cdb()' only expects 2 arguments but event scsi_dispatch_cmd_done has more
>
> Or
>
>   Error: function 'scsi_trace_parse_cdb()' expects 4 arguments but event scsi_dispatch_cmd_timeout only uses 3
>   Error: function 'scsi_trace_parse_cdb()' expects 4 arguments but event scsi_dispatch_cmd_start only uses 3
>   Error: function 'scsi_trace_parse_cdb()' expects 4 arguments but event scsi_dispatch_cmd_error only uses 3
>   Error: function 'scsi_trace_parse_cdb()' expects 4 arguments but event scsi_dispatch_cmd_done only uses 3
>
> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
>
> diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
> index 0362d57..f7aab3d 100644
> --- a/tools/lib/traceevent/event-parse.c
> +++ b/tools/lib/traceevent/event-parse.c
> @@ -2691,7 +2691,6 @@ process_func_handler(struct event_format *event, struct pevent_function_handler
>  	struct print_arg *farg;
>  	enum event_type type;
>  	char *token;
> -	const char *test;
>  	int i;
>  
>  	arg->type = PRINT_FUNC;
> @@ -2708,15 +2707,19 @@ process_func_handler(struct event_format *event, struct pevent_function_handler
>  		}
>  
>  		type = process_arg(event, farg, &token);
> -		if (i < (func->nr_args - 1))
> -			test = ",";
> -		else
> -			test = ")";
> -
> -		if (test_type_token(type, token, EVENT_DELIM, test)) {
> -			free_arg(farg);
> -			free_token(token);
> -			return EVENT_ERROR;
> +		if (i < (func->nr_args - 1)) {
> +			if (type != EVENT_DELIM || strcmp(token, ",") != 0) {
> +				warning("Error: function '%s()' expects %d arguments but event %s only uses %d",
> +					func->name, func->nr_args,
> +					event->name, i + 1);
> +				return EVENT_ERROR;
> +			}
> +		} else {
> +			if (type != EVENT_DELIM || strcmp(token, ")") != 0) {
> +				warning("Error: function '%s()' only expects %d arguments but event %s has more",
> +					func->name, func->nr_args, event->name);
> +				return EVENT_ERROR;

It seems that you missed to free farg and token in error paths.

Thanks,
Namhyung


> +			}
>  		}
>  
>  		*next_arg = farg;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: tools lib traceevent: Report better error message on bad function args
  2013-11-19  2:23 ` Namhyung Kim
@ 2013-11-19  2:31   ` Steven Rostedt
  0 siblings, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2013-11-19  2:31 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: LKML, Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar,
	Frederic Weisbecker

On Tue, 19 Nov 2013 11:23:56 +0900
Namhyung Kim <namhyung@kernel.org> wrote:
 
> >  	arg->type = PRINT_FUNC;
> > @@ -2708,15 +2707,19 @@ process_func_handler(struct event_format *event, struct pevent_function_handler
> >  		}
> >  
> >  		type = process_arg(event, farg, &token);
> > -		if (i < (func->nr_args - 1))
> > -			test = ",";
> > -		else
> > -			test = ")";
> > -
> > -		if (test_type_token(type, token, EVENT_DELIM, test)) {
> > -			free_arg(farg);
> > -			free_token(token);
> > -			return EVENT_ERROR;
> > +		if (i < (func->nr_args - 1)) {
> > +			if (type != EVENT_DELIM || strcmp(token, ",") != 0) {
> > +				warning("Error: function '%s()' expects %d arguments but event %s only uses %d",
> > +					func->name, func->nr_args,
> > +					event->name, i + 1);
> > +				return EVENT_ERROR;
> > +			}
> > +		} else {
> > +			if (type != EVENT_DELIM || strcmp(token, ")") != 0) {
> > +				warning("Error: function '%s()' only expects %d arguments but event %s has more",
> > +					func->name, func->nr_args, event->name);
> > +				return EVENT_ERROR;
> 
> It seems that you missed to free farg and token in error paths.
> 

Ug, you're right!

Thanks for the review. v2 coming up.

-- Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-11-19  2:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-19  0:11 tools lib traceevent: Report better error message on bad function args Steven Rostedt
2013-11-19  2:23 ` Namhyung Kim
2013-11-19  2:31   ` Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.