diff options
author | Steven Rostedt <srostedt@redhat.com> | 2011-01-20 22:48:56 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-01-20 22:49:39 -0500 |
commit | b8b14ccd92219d98b6336069de79d5605b4e3f45 (patch) | |
tree | 09715025a55c0ce272d3e44b2c97adc86466f1b8 | |
parent | e2fd3f44d10c5ac28727215d65445e7cd9342e49 (diff) |
parse-events: Show where error occurred in filtering
Show a nice pointer where an error occurred in filtering:
# trace-cmd report -F 'sched_switch:(next_pid==x)||)prev_pid == 1'
version = 6
cpus=4
trace-cmd: No such file or directory
Error filtering: sched_switch:(next_pid==x)||)prev_pid == 1
(next_pid==x)||)prev_pid == 1
^
Expected end where ) was found
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | parse-events.c | 10 | ||||
-rw-r--r-- | parse-events.h | 2 | ||||
-rw-r--r-- | parse-filter.c | 28 | ||||
-rw-r--r-- | trace-read.c | 2 |
4 files changed, 39 insertions, 3 deletions
diff --git a/parse-events.c b/parse-events.c index beab8f3..99c9593 100644 --- a/parse-events.c +++ b/parse-events.c | |||
@@ -53,6 +53,16 @@ static void init_input_buf(const char *buf, unsigned long long size) | |||
53 | input_buf_ptr = 0; | 53 | input_buf_ptr = 0; |
54 | } | 54 | } |
55 | 55 | ||
56 | const char *pevent_get_input_buf(void) | ||
57 | { | ||
58 | return input_buf; | ||
59 | } | ||
60 | |||
61 | unsigned long long pevent_get_input_buf_ptr(void) | ||
62 | { | ||
63 | return input_buf_ptr; | ||
64 | } | ||
65 | |||
56 | struct event_handler { | 66 | struct event_handler { |
57 | struct event_handler *next; | 67 | struct event_handler *next; |
58 | int id; | 68 | int id; |
diff --git a/parse-events.h b/parse-events.h index 4732acf..3ffe56f 100644 --- a/parse-events.h +++ b/parse-events.h | |||
@@ -558,6 +558,8 @@ void pevent_buffer_init(const char *buf, unsigned long long size); | |||
558 | enum event_type pevent_read_token(char **tok); | 558 | enum event_type pevent_read_token(char **tok); |
559 | void pevent_free_token(char *token); | 559 | void pevent_free_token(char *token); |
560 | int pevent_peek_char(void); | 560 | int pevent_peek_char(void); |
561 | const char *pevent_get_input_buf(void); | ||
562 | unsigned long long pevent_get_input_buf_ptr(void); | ||
561 | 563 | ||
562 | /* for debugging */ | 564 | /* for debugging */ |
563 | void pevent_print_funcs(struct pevent *pevent); | 565 | void pevent_print_funcs(struct pevent *pevent); |
diff --git a/parse-filter.c b/parse-filter.c index 0eeab5e..e5ff909 100644 --- a/parse-filter.c +++ b/parse-filter.c | |||
@@ -43,16 +43,37 @@ struct event_list { | |||
43 | 43 | ||
44 | static void show_error(char **error_str, const char *fmt, ...) | 44 | static void show_error(char **error_str, const char *fmt, ...) |
45 | { | 45 | { |
46 | unsigned long long index; | ||
47 | const char *input; | ||
48 | char *error; | ||
46 | va_list ap; | 49 | va_list ap; |
50 | int len; | ||
51 | int i; | ||
47 | 52 | ||
48 | if (!error_str) | 53 | if (!error_str) |
49 | return; | 54 | return; |
50 | 55 | ||
51 | *error_str = malloc_or_die(MAX_ERR_STR_SIZE); | 56 | input = pevent_get_input_buf(); |
57 | index = pevent_get_input_buf_ptr(); | ||
58 | len = input ? strlen(input) : 0; | ||
59 | |||
60 | error = malloc_or_die(MAX_ERR_STR_SIZE + (len*2) + 3); | ||
61 | |||
62 | if (len) { | ||
63 | strcpy(error, input); | ||
64 | error[len] = '\n'; | ||
65 | for (i = 1; i < len && i < index; i++) | ||
66 | error[len+i] = ' '; | ||
67 | error[len + i] = '^'; | ||
68 | error[len + i + 1] = '\n'; | ||
69 | len += i+2; | ||
70 | } | ||
52 | 71 | ||
53 | va_start(ap, fmt); | 72 | va_start(ap, fmt); |
54 | vsnprintf(*error_str, MAX_ERR_STR_SIZE, fmt, ap); | 73 | vsnprintf(error + len, MAX_ERR_STR_SIZE, fmt, ap); |
55 | va_end(ap); | 74 | va_end(ap); |
75 | |||
76 | *error_str = error; | ||
56 | } | 77 | } |
57 | 78 | ||
58 | static void free_token(char *token) | 79 | static void free_token(char *token) |
@@ -1055,6 +1076,9 @@ int pevent_filter_add_filter_str(struct event_filter *filter, | |||
1055 | int len; | 1076 | int len; |
1056 | int ret; | 1077 | int ret; |
1057 | 1078 | ||
1079 | /* clear buffer to reset show error */ | ||
1080 | pevent_buffer_init("", 0); | ||
1081 | |||
1058 | if (error_str) | 1082 | if (error_str) |
1059 | *error_str = NULL; | 1083 | *error_str = NULL; |
1060 | 1084 | ||
diff --git a/trace-read.c b/trace-read.c index dc79cf1..a4c3538 100644 --- a/trace-read.c +++ b/trace-read.c | |||
@@ -269,7 +269,7 @@ static void process_filters(struct tracecmd_input *handle) | |||
269 | filter->filter, | 269 | filter->filter, |
270 | &errstr); | 270 | &errstr); |
271 | if (ret < 0) | 271 | if (ret < 0) |
272 | die("Error filtering: %s\n %s", | 272 | die("Error filtering: %s\n%s", |
273 | filter->filter, errstr); | 273 | filter->filter, errstr); |
274 | free(errstr); | 274 | free(errstr); |
275 | free(filter); | 275 | free(filter); |