diff options
Diffstat (limited to 'tools/lib/traceevent')
-rw-r--r-- | tools/lib/traceevent/parse-filter.c | 67 |
1 files changed, 19 insertions, 48 deletions
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c index 9303c55128db..e2842b926759 100644 --- a/tools/lib/traceevent/parse-filter.c +++ b/tools/lib/traceevent/parse-filter.c | |||
@@ -1361,8 +1361,10 @@ enum pevent_errno pevent_filter_add_filter_str(struct event_filter *filter, | |||
1361 | if (ret >= 0 && pevent->test_filters) { | 1361 | if (ret >= 0 && pevent->test_filters) { |
1362 | char *test; | 1362 | char *test; |
1363 | test = pevent_filter_make_string(filter, event->event->id); | 1363 | test = pevent_filter_make_string(filter, event->event->id); |
1364 | printf(" '%s: %s'\n", event->event->name, test); | 1364 | if (test) { |
1365 | free(test); | 1365 | printf(" '%s: %s'\n", event->event->name, test); |
1366 | free(test); | ||
1367 | } | ||
1366 | } | 1368 | } |
1367 | } | 1369 | } |
1368 | 1370 | ||
@@ -2050,7 +2052,6 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2050 | int left_val = -1; | 2052 | int left_val = -1; |
2051 | int right_val = -1; | 2053 | int right_val = -1; |
2052 | int val; | 2054 | int val; |
2053 | int len; | ||
2054 | 2055 | ||
2055 | switch (arg->op.type) { | 2056 | switch (arg->op.type) { |
2056 | case FILTER_OP_AND: | 2057 | case FILTER_OP_AND: |
@@ -2097,11 +2098,7 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2097 | default: | 2098 | default: |
2098 | break; | 2099 | break; |
2099 | } | 2100 | } |
2100 | str = malloc_or_die(6); | 2101 | asprintf(&str, val ? "TRUE" : "FALSE"); |
2101 | if (val) | ||
2102 | strcpy(str, "TRUE"); | ||
2103 | else | ||
2104 | strcpy(str, "FALSE"); | ||
2105 | break; | 2102 | break; |
2106 | } | 2103 | } |
2107 | } | 2104 | } |
@@ -2119,10 +2116,7 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2119 | break; | 2116 | break; |
2120 | } | 2117 | } |
2121 | 2118 | ||
2122 | len = strlen(left) + strlen(right) + strlen(op) + 10; | 2119 | asprintf(&str, "(%s) %s (%s)", left, op, right); |
2123 | str = malloc_or_die(len); | ||
2124 | snprintf(str, len, "(%s) %s (%s)", | ||
2125 | left, op, right); | ||
2126 | break; | 2120 | break; |
2127 | 2121 | ||
2128 | case FILTER_OP_NOT: | 2122 | case FILTER_OP_NOT: |
@@ -2138,16 +2132,10 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2138 | right_val = 0; | 2132 | right_val = 0; |
2139 | if (right_val >= 0) { | 2133 | if (right_val >= 0) { |
2140 | /* just return the opposite */ | 2134 | /* just return the opposite */ |
2141 | str = malloc_or_die(6); | 2135 | asprintf(&str, right_val ? "FALSE" : "TRUE"); |
2142 | if (right_val) | ||
2143 | strcpy(str, "FALSE"); | ||
2144 | else | ||
2145 | strcpy(str, "TRUE"); | ||
2146 | break; | 2136 | break; |
2147 | } | 2137 | } |
2148 | len = strlen(right) + strlen(op) + 3; | 2138 | asprintf(&str, "%s(%s)", op, right); |
2149 | str = malloc_or_die(len); | ||
2150 | snprintf(str, len, "%s(%s)", op, right); | ||
2151 | break; | 2139 | break; |
2152 | 2140 | ||
2153 | default: | 2141 | default: |
@@ -2161,11 +2149,9 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2161 | 2149 | ||
2162 | static char *val_to_str(struct event_filter *filter, struct filter_arg *arg) | 2150 | static char *val_to_str(struct event_filter *filter, struct filter_arg *arg) |
2163 | { | 2151 | { |
2164 | char *str; | 2152 | char *str = NULL; |
2165 | |||
2166 | str = malloc_or_die(30); | ||
2167 | 2153 | ||
2168 | snprintf(str, 30, "%lld", arg->value.val); | 2154 | asprintf(&str, "%lld", arg->value.val); |
2169 | 2155 | ||
2170 | return str; | 2156 | return str; |
2171 | } | 2157 | } |
@@ -2181,7 +2167,6 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2181 | char *rstr; | 2167 | char *rstr; |
2182 | char *op; | 2168 | char *op; |
2183 | char *str = NULL; | 2169 | char *str = NULL; |
2184 | int len; | ||
2185 | 2170 | ||
2186 | lstr = arg_to_str(filter, arg->exp.left); | 2171 | lstr = arg_to_str(filter, arg->exp.left); |
2187 | rstr = arg_to_str(filter, arg->exp.right); | 2172 | rstr = arg_to_str(filter, arg->exp.right); |
@@ -2220,12 +2205,11 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2220 | op = "^"; | 2205 | op = "^"; |
2221 | break; | 2206 | break; |
2222 | default: | 2207 | default: |
2223 | die("oops in exp"); | 2208 | op = "[ERROR IN EXPRESSION TYPE]"; |
2209 | break; | ||
2224 | } | 2210 | } |
2225 | 2211 | ||
2226 | len = strlen(op) + strlen(lstr) + strlen(rstr) + 4; | 2212 | asprintf(&str, "%s %s %s", lstr, op, rstr); |
2227 | str = malloc_or_die(len); | ||
2228 | snprintf(str, len, "%s %s %s", lstr, op, rstr); | ||
2229 | out: | 2213 | out: |
2230 | free(lstr); | 2214 | free(lstr); |
2231 | free(rstr); | 2215 | free(rstr); |
@@ -2239,7 +2223,6 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2239 | char *rstr; | 2223 | char *rstr; |
2240 | char *str = NULL; | 2224 | char *str = NULL; |
2241 | char *op = NULL; | 2225 | char *op = NULL; |
2242 | int len; | ||
2243 | 2226 | ||
2244 | lstr = arg_to_str(filter, arg->num.left); | 2227 | lstr = arg_to_str(filter, arg->num.left); |
2245 | rstr = arg_to_str(filter, arg->num.right); | 2228 | rstr = arg_to_str(filter, arg->num.right); |
@@ -2270,10 +2253,7 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2270 | if (!op) | 2253 | if (!op) |
2271 | op = "<="; | 2254 | op = "<="; |
2272 | 2255 | ||
2273 | len = strlen(lstr) + strlen(op) + strlen(rstr) + 4; | 2256 | asprintf(&str, "%s %s %s", lstr, op, rstr); |
2274 | str = malloc_or_die(len); | ||
2275 | sprintf(str, "%s %s %s", lstr, op, rstr); | ||
2276 | |||
2277 | break; | 2257 | break; |
2278 | 2258 | ||
2279 | default: | 2259 | default: |
@@ -2291,7 +2271,6 @@ static char *str_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2291 | { | 2271 | { |
2292 | char *str = NULL; | 2272 | char *str = NULL; |
2293 | char *op = NULL; | 2273 | char *op = NULL; |
2294 | int len; | ||
2295 | 2274 | ||
2296 | switch (arg->str.type) { | 2275 | switch (arg->str.type) { |
2297 | case FILTER_CMP_MATCH: | 2276 | case FILTER_CMP_MATCH: |
@@ -2309,12 +2288,8 @@ static char *str_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2309 | if (!op) | 2288 | if (!op) |
2310 | op = "!~"; | 2289 | op = "!~"; |
2311 | 2290 | ||
2312 | len = strlen(arg->str.field->name) + strlen(op) + | 2291 | asprintf(&str, "%s %s \"%s\"", |
2313 | strlen(arg->str.val) + 6; | 2292 | arg->str.field->name, op, arg->str.val); |
2314 | str = malloc_or_die(len); | ||
2315 | snprintf(str, len, "%s %s \"%s\"", | ||
2316 | arg->str.field->name, | ||
2317 | op, arg->str.val); | ||
2318 | break; | 2293 | break; |
2319 | 2294 | ||
2320 | default: | 2295 | default: |
@@ -2326,15 +2301,11 @@ static char *str_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2326 | 2301 | ||
2327 | static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg) | 2302 | static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg) |
2328 | { | 2303 | { |
2329 | char *str; | 2304 | char *str = NULL; |
2330 | 2305 | ||
2331 | switch (arg->type) { | 2306 | switch (arg->type) { |
2332 | case FILTER_ARG_BOOLEAN: | 2307 | case FILTER_ARG_BOOLEAN: |
2333 | str = malloc_or_die(6); | 2308 | asprintf(&str, arg->boolean.value ? "TRUE" : "FALSE"); |
2334 | if (arg->boolean.value) | ||
2335 | strcpy(str, "TRUE"); | ||
2336 | else | ||
2337 | strcpy(str, "FALSE"); | ||
2338 | return str; | 2309 | return str; |
2339 | 2310 | ||
2340 | case FILTER_ARG_OP: | 2311 | case FILTER_ARG_OP: |
@@ -2369,7 +2340,7 @@ static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg) | |||
2369 | * | 2340 | * |
2370 | * Returns a string that displays the filter contents. | 2341 | * Returns a string that displays the filter contents. |
2371 | * This string must be freed with free(str). | 2342 | * This string must be freed with free(str). |
2372 | * NULL is returned if no filter is found. | 2343 | * NULL is returned if no filter is found or allocation failed. |
2373 | */ | 2344 | */ |
2374 | char * | 2345 | char * |
2375 | pevent_filter_make_string(struct event_filter *filter, int event_id) | 2346 | pevent_filter_make_string(struct event_filter *filter, int event_id) |