tools lib traceevent: Report better error message on bad function args
PATCH v2 1/1 tools lib traceevent: Report better error message on bad function args
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
---
V2:
Added '[PATCH.*]' in subject. Don't know how I missed that the first time.
Free token and farg. Thanks to Namhyung Kim for pointing that out.
tools/lib/traceevent/event-parse.c +18 -10
@@ -2691,7 +2691,6 @@ process_func_handler(struct event_format *event, struct pevent_function_handlerstruct 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 ); + goto err; + } + }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); + goto err; + } } *next_arg = farg;
@@ -2728,6 +2731,11 @@ process_func_handler(struct event_format *event, struct pevent_function_handler *tok = token;return type; + +err: +free_arg (farg); +free_token (token); +return EVENT_ERROR ; } static enum event_type
Quoted 18 lines · Steven Rostedt
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 eventscsi_dispatch_cmd_timeouthas more
Error: function 'scsi_trace_parse_cdb()' only expects 2 arguments but eventscsi_dispatch_cmd_starthas more
Error: function 'scsi_trace_parse_cdb()' only expects 2 arguments but eventscsi_dispatch_cmd_errorhas more
Error: function 'scsi_trace_parse_cdb()' only expects 2 arguments but eventscsi_dispatch_cmd_donehas more
Quoted 6 lines
Or
Error: function '
scsi_trace_parse_cdb()' expects 4 arguments but eventscsi_dispatch_cmd_timeoutonly uses 3
Error: function 'scsi_trace_parse_cdb()' expects 4 arguments but eventscsi_dispatch_cmd_startonly uses 3
Error: function 'scsi_trace_parse_cdb()' expects 4 arguments but eventscsi_dispatch_cmd_erroronly uses 3
Error: function 'scsi_trace_parse_cdb()' expects 4 arguments but eventscsi_dispatch_cmd_doneonly uses 3
Thanks,
Namhyung