aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2013-12-12 02:36:13 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-12-13 08:30:22 -0500
commit42d6194d133cbaf12f34cbdc4111bd8f7dc0ed2a (patch)
tree5f7e3db08fa1938a27d52f2b3864f00ac333d12b /tools/lib
parentc8ea690dd0d1385a766d68c51832497181e013b8 (diff)
tools lib traceevent: Refactor process_filter()
So that it can return a proper pevent_errno value. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Steven Rostedt <rostedt@goodmis.org> Link: http://lkml.kernel.org/r/1386833777-3790-11-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/traceevent/event-parse.h6
-rw-r--r--tools/lib/traceevent/parse-filter.c64
2 files changed, 42 insertions, 28 deletions
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index 57b66aed8122..da942d59cc3a 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -368,7 +368,11 @@ enum pevent_flag {
368 _PE(REPARENT_NOT_OP, "cannot reparent other than OP"), \ 368 _PE(REPARENT_NOT_OP, "cannot reparent other than OP"), \
369 _PE(REPARENT_FAILED, "failed to reparent filter OP"), \ 369 _PE(REPARENT_FAILED, "failed to reparent filter OP"), \
370 _PE(BAD_FILTER_ARG, "bad arg in filter tree"), \ 370 _PE(BAD_FILTER_ARG, "bad arg in filter tree"), \
371 _PE(UNEXPECTED_TYPE, "unexpected type (not a value)") 371 _PE(UNEXPECTED_TYPE, "unexpected type (not a value)"), \
372 _PE(ILLEGAL_TOKEN, "illegal token"), \
373 _PE(INVALID_PAREN, "open parenthesis cannot come here"), \
374 _PE(UNBALANCED_PAREN, "unbalanced number of parenthesis"), \
375 _PE(UNKNOWN_TOKEN, "unknown token")
372 376
373#undef _PE 377#undef _PE
374#define _PE(__code, __str) PEVENT_ERRNO__ ## __code 378#define _PE(__code, __str) PEVENT_ERRNO__ ## __code
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index 8d71208f0131..5aa5012a17ee 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -937,9 +937,10 @@ static int test_arg(struct filter_arg *parent, struct filter_arg *arg,
937} 937}
938 938
939/* Remove any unknown event fields */ 939/* Remove any unknown event fields */
940static struct filter_arg *collapse_tree(struct filter_arg *arg, char **error_str) 940static int collapse_tree(struct filter_arg *arg,
941 struct filter_arg **arg_collapsed, char **error_str)
941{ 942{
942 enum filter_vals ret; 943 int ret;
943 944
944 ret = test_arg(arg, arg, error_str); 945 ret = test_arg(arg, arg, error_str);
945 switch (ret) { 946 switch (ret) {
@@ -955,6 +956,7 @@ static struct filter_arg *collapse_tree(struct filter_arg *arg, char **error_str
955 arg->boolean.value = ret == FILTER_VAL_TRUE; 956 arg->boolean.value = ret == FILTER_VAL_TRUE;
956 } else { 957 } else {
957 show_error(error_str, "Failed to allocate filter arg"); 958 show_error(error_str, "Failed to allocate filter arg");
959 ret = PEVENT_ERRNO__MEM_ALLOC_FAILED;
958 } 960 }
959 break; 961 break;
960 962
@@ -965,10 +967,11 @@ static struct filter_arg *collapse_tree(struct filter_arg *arg, char **error_str
965 break; 967 break;
966 } 968 }
967 969
968 return arg; 970 *arg_collapsed = arg;
971 return ret;
969} 972}
970 973
971static int 974static enum pevent_errno
972process_filter(struct event_format *event, struct filter_arg **parg, 975process_filter(struct event_format *event, struct filter_arg **parg,
973 char **error_str, int not) 976 char **error_str, int not)
974{ 977{
@@ -982,7 +985,7 @@ process_filter(struct event_format *event, struct filter_arg **parg,
982 enum filter_op_type btype; 985 enum filter_op_type btype;
983 enum filter_exp_type etype; 986 enum filter_exp_type etype;
984 enum filter_cmp_type ctype; 987 enum filter_cmp_type ctype;
985 int ret; 988 enum pevent_errno ret;
986 989
987 *parg = NULL; 990 *parg = NULL;
988 991
@@ -1007,20 +1010,20 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1007 if (not) { 1010 if (not) {
1008 arg = NULL; 1011 arg = NULL;
1009 if (current_op) 1012 if (current_op)
1010 goto fail_print; 1013 goto fail_syntax;
1011 free(token); 1014 free(token);
1012 *parg = current_exp; 1015 *parg = current_exp;
1013 return 0; 1016 return 0;
1014 } 1017 }
1015 } else 1018 } else
1016 goto fail_print; 1019 goto fail_syntax;
1017 arg = NULL; 1020 arg = NULL;
1018 break; 1021 break;
1019 1022
1020 case EVENT_DELIM: 1023 case EVENT_DELIM:
1021 if (*token == ',') { 1024 if (*token == ',') {
1022 show_error(error_str, 1025 show_error(error_str, "Illegal token ','");
1023 "Illegal token ','"); 1026 ret = PEVENT_ERRNO__ILLEGAL_TOKEN;
1024 goto fail; 1027 goto fail;
1025 } 1028 }
1026 1029
@@ -1028,19 +1031,23 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1028 if (left_item) { 1031 if (left_item) {
1029 show_error(error_str, 1032 show_error(error_str,
1030 "Open paren can not come after item"); 1033 "Open paren can not come after item");
1034 ret = PEVENT_ERRNO__INVALID_PAREN;
1031 goto fail; 1035 goto fail;
1032 } 1036 }
1033 if (current_exp) { 1037 if (current_exp) {
1034 show_error(error_str, 1038 show_error(error_str,
1035 "Open paren can not come after expression"); 1039 "Open paren can not come after expression");
1040 ret = PEVENT_ERRNO__INVALID_PAREN;
1036 goto fail; 1041 goto fail;
1037 } 1042 }
1038 1043
1039 ret = process_filter(event, &arg, error_str, 0); 1044 ret = process_filter(event, &arg, error_str, 0);
1040 if (ret != 1) { 1045 if (ret != PEVENT_ERRNO__UNBALANCED_PAREN) {
1041 if (ret == 0) 1046 if (ret == 0) {
1042 show_error(error_str, 1047 show_error(error_str,
1043 "Unbalanced number of '('"); 1048 "Unbalanced number of '('");
1049 ret = PEVENT_ERRNO__UNBALANCED_PAREN;
1050 }
1044 goto fail; 1051 goto fail;
1045 } 1052 }
1046 ret = 0; 1053 ret = 0;
@@ -1048,7 +1055,7 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1048 /* A not wants just one expression */ 1055 /* A not wants just one expression */
1049 if (not) { 1056 if (not) {
1050 if (current_op) 1057 if (current_op)
1051 goto fail_print; 1058 goto fail_syntax;
1052 *parg = arg; 1059 *parg = arg;
1053 return 0; 1060 return 0;
1054 } 1061 }
@@ -1063,19 +1070,19 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1063 1070
1064 } else { /* ')' */ 1071 } else { /* ')' */
1065 if (!current_op && !current_exp) 1072 if (!current_op && !current_exp)
1066 goto fail_print; 1073 goto fail_syntax;
1067 1074
1068 /* Make sure everything is finished at this level */ 1075 /* Make sure everything is finished at this level */
1069 if (current_exp && !check_op_done(current_exp)) 1076 if (current_exp && !check_op_done(current_exp))
1070 goto fail_print; 1077 goto fail_syntax;
1071 if (current_op && !check_op_done(current_op)) 1078 if (current_op && !check_op_done(current_op))
1072 goto fail_print; 1079 goto fail_syntax;
1073 1080
1074 if (current_op) 1081 if (current_op)
1075 *parg = current_op; 1082 *parg = current_op;
1076 else 1083 else
1077 *parg = current_exp; 1084 *parg = current_exp;
1078 return 1; 1085 return PEVENT_ERRNO__UNBALANCED_PAREN;
1079 } 1086 }
1080 break; 1087 break;
1081 1088
@@ -1087,21 +1094,22 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1087 case OP_BOOL: 1094 case OP_BOOL:
1088 /* Logic ops need a left expression */ 1095 /* Logic ops need a left expression */
1089 if (!current_exp && !current_op) 1096 if (!current_exp && !current_op)
1090 goto fail_print; 1097 goto fail_syntax;
1091 /* fall through */ 1098 /* fall through */
1092 case OP_NOT: 1099 case OP_NOT:
1093 /* logic only processes ops and exp */ 1100 /* logic only processes ops and exp */
1094 if (left_item) 1101 if (left_item)
1095 goto fail_print; 1102 goto fail_syntax;
1096 break; 1103 break;
1097 case OP_EXP: 1104 case OP_EXP:
1098 case OP_CMP: 1105 case OP_CMP:
1099 if (!left_item) 1106 if (!left_item)
1100 goto fail_print; 1107 goto fail_syntax;
1101 break; 1108 break;
1102 case OP_NONE: 1109 case OP_NONE:
1103 show_error(error_str, 1110 show_error(error_str,
1104 "Unknown op token %s", token); 1111 "Unknown op token %s", token);
1112 ret = PEVENT_ERRNO__UNKNOWN_TOKEN;
1105 goto fail; 1113 goto fail;
1106 } 1114 }
1107 1115
@@ -1152,7 +1160,7 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1152 ret = add_left(arg, left_item); 1160 ret = add_left(arg, left_item);
1153 if (ret < 0) { 1161 if (ret < 0) {
1154 arg = NULL; 1162 arg = NULL;
1155 goto fail_print; 1163 goto fail_syntax;
1156 } 1164 }
1157 current_exp = arg; 1165 current_exp = arg;
1158 break; 1166 break;
@@ -1161,25 +1169,25 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1161 } 1169 }
1162 arg = NULL; 1170 arg = NULL;
1163 if (ret < 0) 1171 if (ret < 0)
1164 goto fail_print; 1172 goto fail_syntax;
1165 break; 1173 break;
1166 case EVENT_NONE: 1174 case EVENT_NONE:
1167 break; 1175 break;
1168 case EVENT_ERROR: 1176 case EVENT_ERROR:
1169 goto fail_alloc; 1177 goto fail_alloc;
1170 default: 1178 default:
1171 goto fail_print; 1179 goto fail_syntax;
1172 } 1180 }
1173 } while (type != EVENT_NONE); 1181 } while (type != EVENT_NONE);
1174 1182
1175 if (!current_op && !current_exp) 1183 if (!current_op && !current_exp)
1176 goto fail_print; 1184 goto fail_syntax;
1177 1185
1178 if (!current_op) 1186 if (!current_op)
1179 current_op = current_exp; 1187 current_op = current_exp;
1180 1188
1181 current_op = collapse_tree(current_op, error_str); 1189 ret = collapse_tree(current_op, parg, error_str);
1182 if (current_op == NULL) 1190 if (ret < 0)
1183 goto fail; 1191 goto fail;
1184 1192
1185 *parg = current_op; 1193 *parg = current_op;
@@ -1188,15 +1196,17 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1188 1196
1189 fail_alloc: 1197 fail_alloc:
1190 show_error(error_str, "failed to allocate filter arg"); 1198 show_error(error_str, "failed to allocate filter arg");
1199 ret = PEVENT_ERRNO__MEM_ALLOC_FAILED;
1191 goto fail; 1200 goto fail;
1192 fail_print: 1201 fail_syntax:
1193 show_error(error_str, "Syntax error"); 1202 show_error(error_str, "Syntax error");
1203 ret = PEVENT_ERRNO__SYNTAX_ERROR;
1194 fail: 1204 fail:
1195 free_arg(current_op); 1205 free_arg(current_op);
1196 free_arg(current_exp); 1206 free_arg(current_exp);
1197 free_arg(arg); 1207 free_arg(arg);
1198 free(token); 1208 free(token);
1199 return -1; 1209 return ret;
1200} 1210}
1201 1211
1202static int 1212static int