Steven Rostedt (VMware) | 6ab025e | 2018-08-16 11:10:15 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: LGPL-2.1 |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> |
| 4 | * |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5 | * |
| 6 | * The parts for function graph printing was taken and modified from the |
| 7 | * Linux Kernel that were written by |
| 8 | * - Copyright (C) 2009 Frederic Weisbecker, |
| 9 | * Frederic Weisbecker gave his permission to relicense the code to |
| 10 | * the Lesser General Public License. |
| 11 | */ |
Arnaldo Carvalho de Melo | ca575ad | 2016-07-14 11:23:25 -0300 | [diff] [blame] | 12 | #include <inttypes.h> |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
| 15 | #include <string.h> |
| 16 | #include <stdarg.h> |
| 17 | #include <ctype.h> |
| 18 | #include <errno.h> |
Robert Richter | 0cf2601 | 2012-08-07 19:43:14 +0200 | [diff] [blame] | 19 | #include <stdint.h> |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 20 | #include <limits.h> |
Steven Rostedt | bb5a731 | 2016-11-22 15:00:31 -0300 | [diff] [blame] | 21 | #include <linux/time64.h> |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 22 | |
Arnaldo Carvalho de Melo | ca575ad | 2016-07-14 11:23:25 -0300 | [diff] [blame] | 23 | #include <netinet/in.h> |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 24 | #include "event-parse.h" |
Tzvetomir Stoyanov | bb3dd7e | 2018-10-05 12:22:25 -0400 | [diff] [blame] | 25 | |
| 26 | #include "event-parse-local.h" |
Steven Rostedt | 668fe01 | 2012-04-06 00:47:55 +0200 | [diff] [blame] | 27 | #include "event-utils.h" |
Tzvetomir Stoyanov (VMware) | 266b851 | 2018-08-28 18:50:38 -0400 | [diff] [blame] | 28 | #include "trace-seq.h" |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 29 | |
| 30 | static const char *input_buf; |
| 31 | static unsigned long long input_buf_ptr; |
| 32 | static unsigned long long input_buf_siz; |
| 33 | |
Tom Zanussi | 5205aec | 2012-04-06 00:47:58 +0200 | [diff] [blame] | 34 | static int is_flag_field; |
| 35 | static int is_symbolic_field; |
| 36 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 37 | static int show_warning = 1; |
| 38 | |
| 39 | #define do_warning(fmt, ...) \ |
| 40 | do { \ |
| 41 | if (show_warning) \ |
| 42 | warning(fmt, ##__VA_ARGS__); \ |
| 43 | } while (0) |
| 44 | |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 45 | #define do_warning_event(event, fmt, ...) \ |
| 46 | do { \ |
| 47 | if (!show_warning) \ |
| 48 | continue; \ |
| 49 | \ |
| 50 | if (event) \ |
| 51 | warning("[%s:%s] " fmt, event->system, \ |
| 52 | event->name, ##__VA_ARGS__); \ |
| 53 | else \ |
| 54 | warning(fmt, ##__VA_ARGS__); \ |
| 55 | } while (0) |
| 56 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 57 | static void init_input_buf(const char *buf, unsigned long long size) |
| 58 | { |
| 59 | input_buf = buf; |
| 60 | input_buf_siz = size; |
| 61 | input_buf_ptr = 0; |
| 62 | } |
| 63 | |
Tzvetomir Stoyanov (VMware) | 1634e46 | 2018-08-08 14:03:07 -0400 | [diff] [blame] | 64 | const char *tep_get_input_buf(void) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 65 | { |
| 66 | return input_buf; |
| 67 | } |
| 68 | |
Tzvetomir Stoyanov (VMware) | 1634e46 | 2018-08-08 14:03:07 -0400 | [diff] [blame] | 69 | unsigned long long tep_get_input_buf_ptr(void) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 70 | { |
| 71 | return input_buf_ptr; |
| 72 | } |
| 73 | |
| 74 | struct event_handler { |
| 75 | struct event_handler *next; |
| 76 | int id; |
| 77 | const char *sys_name; |
| 78 | const char *event_name; |
Tzvetomir Stoyanov (VMware) | c32d52b | 2018-08-08 14:02:48 -0400 | [diff] [blame] | 79 | tep_event_handler_func func; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 80 | void *context; |
| 81 | }; |
| 82 | |
Tzvetomir Stoyanov (VMware) | 0ae9863 | 2018-08-08 14:03:09 -0400 | [diff] [blame] | 83 | struct func_params { |
| 84 | struct func_params *next; |
| 85 | enum tep_func_arg_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 86 | }; |
| 87 | |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 88 | struct tep_function_handler { |
| 89 | struct tep_function_handler *next; |
| 90 | enum tep_func_arg_type ret_type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 91 | char *name; |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 92 | tep_func_handler func; |
Tzvetomir Stoyanov (VMware) | 0ae9863 | 2018-08-08 14:03:09 -0400 | [diff] [blame] | 93 | struct func_params *params; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 94 | int nr_args; |
| 95 | }; |
| 96 | |
| 97 | static unsigned long long |
| 98 | process_defined_func(struct trace_seq *s, void *data, int size, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 99 | struct tep_event *event, struct tep_print_arg *arg); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 100 | |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 101 | static void free_func_handle(struct tep_function_handler *func); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 102 | |
| 103 | /** |
Tzvetomir Stoyanov (VMware) | 1634e46 | 2018-08-08 14:03:07 -0400 | [diff] [blame] | 104 | * tep_buffer_init - init buffer for parsing |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 105 | * @buf: buffer to parse |
| 106 | * @size: the size of the buffer |
| 107 | * |
Tzvetomir Stoyanov (VMware) | 1634e46 | 2018-08-08 14:03:07 -0400 | [diff] [blame] | 108 | * For use with tep_read_token(), this initializes the internal |
| 109 | * buffer that tep_read_token() will parse. |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 110 | */ |
Tzvetomir Stoyanov (VMware) | 1634e46 | 2018-08-08 14:03:07 -0400 | [diff] [blame] | 111 | void tep_buffer_init(const char *buf, unsigned long long size) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 112 | { |
| 113 | init_input_buf(buf, size); |
| 114 | } |
| 115 | |
| 116 | void breakpoint(void) |
| 117 | { |
| 118 | static int x; |
| 119 | x++; |
| 120 | } |
| 121 | |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 122 | struct tep_print_arg *alloc_arg(void) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 123 | { |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 124 | return calloc(1, sizeof(struct tep_print_arg)); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 125 | } |
| 126 | |
Tzvetomir Stoyanov | 2e4318a | 2018-11-30 23:08:09 -0500 | [diff] [blame] | 127 | struct tep_cmdline { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 128 | char *comm; |
| 129 | int pid; |
| 130 | }; |
| 131 | |
| 132 | static int cmdline_cmp(const void *a, const void *b) |
| 133 | { |
Tzvetomir Stoyanov | 2e4318a | 2018-11-30 23:08:09 -0500 | [diff] [blame] | 134 | const struct tep_cmdline *ca = a; |
| 135 | const struct tep_cmdline *cb = b; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 136 | |
| 137 | if (ca->pid < cb->pid) |
| 138 | return -1; |
| 139 | if (ca->pid > cb->pid) |
| 140 | return 1; |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | struct cmdline_list { |
| 146 | struct cmdline_list *next; |
| 147 | char *comm; |
| 148 | int pid; |
| 149 | }; |
| 150 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 151 | static int cmdline_init(struct tep_handle *pevent) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 152 | { |
| 153 | struct cmdline_list *cmdlist = pevent->cmdlist; |
| 154 | struct cmdline_list *item; |
Tzvetomir Stoyanov | 2e4318a | 2018-11-30 23:08:09 -0500 | [diff] [blame] | 155 | struct tep_cmdline *cmdlines; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 156 | int i; |
| 157 | |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 158 | cmdlines = malloc(sizeof(*cmdlines) * pevent->cmdline_count); |
| 159 | if (!cmdlines) |
| 160 | return -1; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 161 | |
| 162 | i = 0; |
| 163 | while (cmdlist) { |
| 164 | cmdlines[i].pid = cmdlist->pid; |
| 165 | cmdlines[i].comm = cmdlist->comm; |
| 166 | i++; |
| 167 | item = cmdlist; |
| 168 | cmdlist = cmdlist->next; |
| 169 | free(item); |
| 170 | } |
| 171 | |
| 172 | qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp); |
| 173 | |
| 174 | pevent->cmdlines = cmdlines; |
| 175 | pevent->cmdlist = NULL; |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 180 | static const char *find_cmdline(struct tep_handle *pevent, int pid) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 181 | { |
Tzvetomir Stoyanov | 2e4318a | 2018-11-30 23:08:09 -0500 | [diff] [blame] | 182 | const struct tep_cmdline *comm; |
| 183 | struct tep_cmdline key; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 184 | |
| 185 | if (!pid) |
| 186 | return "<idle>"; |
| 187 | |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 188 | if (!pevent->cmdlines && cmdline_init(pevent)) |
| 189 | return "<not enough memory for cmdlines!>"; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 190 | |
| 191 | key.pid = pid; |
| 192 | |
| 193 | comm = bsearch(&key, pevent->cmdlines, pevent->cmdline_count, |
| 194 | sizeof(*pevent->cmdlines), cmdline_cmp); |
| 195 | |
| 196 | if (comm) |
| 197 | return comm->comm; |
| 198 | return "<...>"; |
| 199 | } |
| 200 | |
| 201 | /** |
Tzvetomir Stoyanov | 55c34ae | 2019-04-01 12:43:16 -0400 | [diff] [blame] | 202 | * tep_is_pid_registered - return if a pid has a cmdline registered |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 203 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 204 | * @pid: The pid to check if it has a cmdline registered with. |
| 205 | * |
Tzvetomir Stoyanov | 55c34ae | 2019-04-01 12:43:16 -0400 | [diff] [blame] | 206 | * Returns true if the pid has a cmdline mapped to it |
| 207 | * false otherwise. |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 208 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 209 | bool tep_is_pid_registered(struct tep_handle *tep, int pid) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 210 | { |
Tzvetomir Stoyanov | 2e4318a | 2018-11-30 23:08:09 -0500 | [diff] [blame] | 211 | const struct tep_cmdline *comm; |
| 212 | struct tep_cmdline key; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 213 | |
| 214 | if (!pid) |
Tzvetomir Stoyanov | 55c34ae | 2019-04-01 12:43:16 -0400 | [diff] [blame] | 215 | return true; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 216 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 217 | if (!tep->cmdlines && cmdline_init(tep)) |
Tzvetomir Stoyanov | 55c34ae | 2019-04-01 12:43:16 -0400 | [diff] [blame] | 218 | return false; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 219 | |
| 220 | key.pid = pid; |
| 221 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 222 | comm = bsearch(&key, tep->cmdlines, tep->cmdline_count, |
| 223 | sizeof(*tep->cmdlines), cmdline_cmp); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 224 | |
| 225 | if (comm) |
Tzvetomir Stoyanov | 55c34ae | 2019-04-01 12:43:16 -0400 | [diff] [blame] | 226 | return true; |
| 227 | return false; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /* |
| 231 | * If the command lines have been converted to an array, then |
| 232 | * we must add this pid. This is much slower than when cmdlines |
| 233 | * are added before the array is initialized. |
| 234 | */ |
Tzvetomir Stoyanov | ca3958b | 2018-11-30 10:44:11 -0500 | [diff] [blame] | 235 | static int add_new_comm(struct tep_handle *pevent, |
| 236 | const char *comm, int pid, bool override) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 237 | { |
Tzvetomir Stoyanov | 2e4318a | 2018-11-30 23:08:09 -0500 | [diff] [blame] | 238 | struct tep_cmdline *cmdlines = pevent->cmdlines; |
| 239 | struct tep_cmdline *cmdline; |
| 240 | struct tep_cmdline key; |
Tzvetomir Stoyanov | ca3958b | 2018-11-30 10:44:11 -0500 | [diff] [blame] | 241 | char *new_comm; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 242 | |
| 243 | if (!pid) |
| 244 | return 0; |
| 245 | |
| 246 | /* avoid duplicates */ |
| 247 | key.pid = pid; |
| 248 | |
| 249 | cmdline = bsearch(&key, pevent->cmdlines, pevent->cmdline_count, |
| 250 | sizeof(*pevent->cmdlines), cmdline_cmp); |
| 251 | if (cmdline) { |
Tzvetomir Stoyanov | ca3958b | 2018-11-30 10:44:11 -0500 | [diff] [blame] | 252 | if (!override) { |
| 253 | errno = EEXIST; |
| 254 | return -1; |
| 255 | } |
| 256 | new_comm = strdup(comm); |
| 257 | if (!new_comm) { |
| 258 | errno = ENOMEM; |
| 259 | return -1; |
| 260 | } |
| 261 | free(cmdline->comm); |
| 262 | cmdline->comm = new_comm; |
| 263 | |
| 264 | return 0; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | cmdlines = realloc(cmdlines, sizeof(*cmdlines) * (pevent->cmdline_count + 1)); |
| 268 | if (!cmdlines) { |
| 269 | errno = ENOMEM; |
| 270 | return -1; |
| 271 | } |
| 272 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 273 | cmdlines[pevent->cmdline_count].comm = strdup(comm); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 274 | if (!cmdlines[pevent->cmdline_count].comm) { |
| 275 | free(cmdlines); |
| 276 | errno = ENOMEM; |
| 277 | return -1; |
| 278 | } |
| 279 | |
| 280 | cmdlines[pevent->cmdline_count].pid = pid; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 281 | |
| 282 | if (cmdlines[pevent->cmdline_count].comm) |
| 283 | pevent->cmdline_count++; |
| 284 | |
| 285 | qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp); |
| 286 | pevent->cmdlines = cmdlines; |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 291 | static int _tep_register_comm(struct tep_handle *tep, |
Tzvetomir Stoyanov | ca3958b | 2018-11-30 10:44:11 -0500 | [diff] [blame] | 292 | const char *comm, int pid, bool override) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 293 | { |
| 294 | struct cmdline_list *item; |
| 295 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 296 | if (tep->cmdlines) |
| 297 | return add_new_comm(tep, comm, pid, override); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 298 | |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 299 | item = malloc(sizeof(*item)); |
| 300 | if (!item) |
| 301 | return -1; |
| 302 | |
Josef Bacik | deab6f5 | 2015-03-24 09:57:49 -0400 | [diff] [blame] | 303 | if (comm) |
| 304 | item->comm = strdup(comm); |
| 305 | else |
| 306 | item->comm = strdup("<...>"); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 307 | if (!item->comm) { |
| 308 | free(item); |
| 309 | return -1; |
| 310 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 311 | item->pid = pid; |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 312 | item->next = tep->cmdlist; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 313 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 314 | tep->cmdlist = item; |
| 315 | tep->cmdline_count++; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
Tzvetomir Stoyanov | ca3958b | 2018-11-30 10:44:11 -0500 | [diff] [blame] | 320 | /** |
| 321 | * tep_register_comm - register a pid / comm mapping |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 322 | * @tep: a handle to the trace event parser context |
Tzvetomir Stoyanov | ca3958b | 2018-11-30 10:44:11 -0500 | [diff] [blame] | 323 | * @comm: the command line to register |
| 324 | * @pid: the pid to map the command line to |
| 325 | * |
| 326 | * This adds a mapping to search for command line names with |
| 327 | * a given pid. The comm is duplicated. If a command with the same pid |
| 328 | * already exist, -1 is returned and errno is set to EEXIST |
| 329 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 330 | int tep_register_comm(struct tep_handle *tep, const char *comm, int pid) |
Tzvetomir Stoyanov | ca3958b | 2018-11-30 10:44:11 -0500 | [diff] [blame] | 331 | { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 332 | return _tep_register_comm(tep, comm, pid, false); |
Tzvetomir Stoyanov | ca3958b | 2018-11-30 10:44:11 -0500 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /** |
| 336 | * tep_override_comm - register a pid / comm mapping |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 337 | * @tep: a handle to the trace event parser context |
Tzvetomir Stoyanov | ca3958b | 2018-11-30 10:44:11 -0500 | [diff] [blame] | 338 | * @comm: the command line to register |
| 339 | * @pid: the pid to map the command line to |
| 340 | * |
| 341 | * This adds a mapping to search for command line names with |
| 342 | * a given pid. The comm is duplicated. If a command with the same pid |
| 343 | * already exist, the command string is udapted with the new one |
| 344 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 345 | int tep_override_comm(struct tep_handle *tep, const char *comm, int pid) |
Tzvetomir Stoyanov | ca3958b | 2018-11-30 10:44:11 -0500 | [diff] [blame] | 346 | { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 347 | if (!tep->cmdlines && cmdline_init(tep)) { |
Tzvetomir Stoyanov | ca3958b | 2018-11-30 10:44:11 -0500 | [diff] [blame] | 348 | errno = ENOMEM; |
| 349 | return -1; |
| 350 | } |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 351 | return _tep_register_comm(tep, comm, pid, true); |
Tzvetomir Stoyanov | ca3958b | 2018-11-30 10:44:11 -0500 | [diff] [blame] | 352 | } |
| 353 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 354 | int tep_register_trace_clock(struct tep_handle *tep, const char *trace_clock) |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 355 | { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 356 | tep->trace_clock = strdup(trace_clock); |
| 357 | if (!tep->trace_clock) { |
Steven Rostedt (Red Hat) | 99ad141 | 2015-03-24 09:57:50 -0400 | [diff] [blame] | 358 | errno = ENOMEM; |
| 359 | return -1; |
| 360 | } |
| 361 | return 0; |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 362 | } |
| 363 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 364 | struct func_map { |
| 365 | unsigned long long addr; |
| 366 | char *func; |
| 367 | char *mod; |
| 368 | }; |
| 369 | |
| 370 | struct func_list { |
| 371 | struct func_list *next; |
| 372 | unsigned long long addr; |
| 373 | char *func; |
| 374 | char *mod; |
| 375 | }; |
| 376 | |
| 377 | static int func_cmp(const void *a, const void *b) |
| 378 | { |
| 379 | const struct func_map *fa = a; |
| 380 | const struct func_map *fb = b; |
| 381 | |
| 382 | if (fa->addr < fb->addr) |
| 383 | return -1; |
| 384 | if (fa->addr > fb->addr) |
| 385 | return 1; |
| 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | * We are searching for a record in between, not an exact |
| 392 | * match. |
| 393 | */ |
| 394 | static int func_bcmp(const void *a, const void *b) |
| 395 | { |
| 396 | const struct func_map *fa = a; |
| 397 | const struct func_map *fb = b; |
| 398 | |
| 399 | if ((fa->addr == fb->addr) || |
| 400 | |
| 401 | (fa->addr > fb->addr && |
| 402 | fa->addr < (fb+1)->addr)) |
| 403 | return 0; |
| 404 | |
| 405 | if (fa->addr < fb->addr) |
| 406 | return -1; |
| 407 | |
| 408 | return 1; |
| 409 | } |
| 410 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 411 | static int func_map_init(struct tep_handle *pevent) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 412 | { |
| 413 | struct func_list *funclist; |
| 414 | struct func_list *item; |
| 415 | struct func_map *func_map; |
| 416 | int i; |
| 417 | |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 418 | func_map = malloc(sizeof(*func_map) * (pevent->func_count + 1)); |
| 419 | if (!func_map) |
| 420 | return -1; |
| 421 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 422 | funclist = pevent->funclist; |
| 423 | |
| 424 | i = 0; |
| 425 | while (funclist) { |
| 426 | func_map[i].func = funclist->func; |
| 427 | func_map[i].addr = funclist->addr; |
| 428 | func_map[i].mod = funclist->mod; |
| 429 | i++; |
| 430 | item = funclist; |
| 431 | funclist = funclist->next; |
| 432 | free(item); |
| 433 | } |
| 434 | |
| 435 | qsort(func_map, pevent->func_count, sizeof(*func_map), func_cmp); |
| 436 | |
| 437 | /* |
| 438 | * Add a special record at the end. |
| 439 | */ |
| 440 | func_map[pevent->func_count].func = NULL; |
| 441 | func_map[pevent->func_count].addr = 0; |
| 442 | func_map[pevent->func_count].mod = NULL; |
| 443 | |
| 444 | pevent->func_map = func_map; |
| 445 | pevent->funclist = NULL; |
| 446 | |
| 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | static struct func_map * |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 451 | __find_func(struct tep_handle *pevent, unsigned long long addr) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 452 | { |
| 453 | struct func_map *func; |
| 454 | struct func_map key; |
| 455 | |
| 456 | if (!pevent->func_map) |
| 457 | func_map_init(pevent); |
| 458 | |
| 459 | key.addr = addr; |
| 460 | |
| 461 | func = bsearch(&key, pevent->func_map, pevent->func_count, |
| 462 | sizeof(*pevent->func_map), func_bcmp); |
| 463 | |
| 464 | return func; |
| 465 | } |
| 466 | |
Arnaldo Carvalho de Melo | 33a2471 | 2015-07-22 12:36:55 -0300 | [diff] [blame] | 467 | struct func_resolver { |
Tzvetomir Stoyanov (VMware) | 4d5c58b | 2018-08-08 14:02:49 -0400 | [diff] [blame] | 468 | tep_func_resolver_t *func; |
| 469 | void *priv; |
| 470 | struct func_map map; |
Arnaldo Carvalho de Melo | 33a2471 | 2015-07-22 12:36:55 -0300 | [diff] [blame] | 471 | }; |
| 472 | |
| 473 | /** |
Tzvetomir Stoyanov (VMware) | ece2a4f | 2018-08-08 14:02:55 -0400 | [diff] [blame] | 474 | * tep_set_function_resolver - set an alternative function resolver |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 475 | * @tep: a handle to the trace event parser context |
Arnaldo Carvalho de Melo | 33a2471 | 2015-07-22 12:36:55 -0300 | [diff] [blame] | 476 | * @resolver: function to be used |
| 477 | * @priv: resolver function private state. |
| 478 | * |
| 479 | * Some tools may have already a way to resolve kernel functions, allow them to |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 480 | * keep using it instead of duplicating all the entries inside tep->funclist. |
Arnaldo Carvalho de Melo | 33a2471 | 2015-07-22 12:36:55 -0300 | [diff] [blame] | 481 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 482 | int tep_set_function_resolver(struct tep_handle *tep, |
Tzvetomir Stoyanov (VMware) | ece2a4f | 2018-08-08 14:02:55 -0400 | [diff] [blame] | 483 | tep_func_resolver_t *func, void *priv) |
Arnaldo Carvalho de Melo | 33a2471 | 2015-07-22 12:36:55 -0300 | [diff] [blame] | 484 | { |
| 485 | struct func_resolver *resolver = malloc(sizeof(*resolver)); |
| 486 | |
| 487 | if (resolver == NULL) |
| 488 | return -1; |
| 489 | |
| 490 | resolver->func = func; |
| 491 | resolver->priv = priv; |
| 492 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 493 | free(tep->func_resolver); |
| 494 | tep->func_resolver = resolver; |
Arnaldo Carvalho de Melo | 33a2471 | 2015-07-22 12:36:55 -0300 | [diff] [blame] | 495 | |
| 496 | return 0; |
| 497 | } |
| 498 | |
| 499 | /** |
Tzvetomir Stoyanov (VMware) | c99eeaf | 2018-08-08 14:03:08 -0400 | [diff] [blame] | 500 | * tep_reset_function_resolver - reset alternative function resolver |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 501 | * @tep: a handle to the trace event parser context |
Arnaldo Carvalho de Melo | 33a2471 | 2015-07-22 12:36:55 -0300 | [diff] [blame] | 502 | * |
| 503 | * Stop using whatever alternative resolver was set, use the default |
| 504 | * one instead. |
| 505 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 506 | void tep_reset_function_resolver(struct tep_handle *tep) |
Arnaldo Carvalho de Melo | 33a2471 | 2015-07-22 12:36:55 -0300 | [diff] [blame] | 507 | { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 508 | free(tep->func_resolver); |
| 509 | tep->func_resolver = NULL; |
Arnaldo Carvalho de Melo | 33a2471 | 2015-07-22 12:36:55 -0300 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | static struct func_map * |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 513 | find_func(struct tep_handle *pevent, unsigned long long addr) |
Arnaldo Carvalho de Melo | 33a2471 | 2015-07-22 12:36:55 -0300 | [diff] [blame] | 514 | { |
| 515 | struct func_map *map; |
| 516 | |
| 517 | if (!pevent->func_resolver) |
| 518 | return __find_func(pevent, addr); |
| 519 | |
| 520 | map = &pevent->func_resolver->map; |
| 521 | map->mod = NULL; |
| 522 | map->addr = addr; |
| 523 | map->func = pevent->func_resolver->func(pevent->func_resolver->priv, |
| 524 | &map->addr, &map->mod); |
| 525 | if (map->func == NULL) |
| 526 | return NULL; |
| 527 | |
| 528 | return map; |
| 529 | } |
| 530 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 531 | /** |
Tzvetomir Stoyanov (VMware) | 610e1e4 | 2018-08-08 14:03:05 -0400 | [diff] [blame] | 532 | * tep_find_function - find a function by a given address |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 533 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 534 | * @addr: the address to find the function with |
| 535 | * |
| 536 | * Returns a pointer to the function stored that has the given |
| 537 | * address. Note, the address does not have to be exact, it |
| 538 | * will select the function that would contain the address. |
| 539 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 540 | const char *tep_find_function(struct tep_handle *tep, unsigned long long addr) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 541 | { |
| 542 | struct func_map *map; |
| 543 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 544 | map = find_func(tep, addr); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 545 | if (!map) |
| 546 | return NULL; |
| 547 | |
| 548 | return map->func; |
| 549 | } |
| 550 | |
| 551 | /** |
Tzvetomir Stoyanov (VMware) | 610e1e4 | 2018-08-08 14:03:05 -0400 | [diff] [blame] | 552 | * tep_find_function_address - find a function address by a given address |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 553 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 554 | * @addr: the address to find the function with |
| 555 | * |
| 556 | * Returns the address the function starts at. This can be used in |
Tzvetomir Stoyanov (VMware) | 610e1e4 | 2018-08-08 14:03:05 -0400 | [diff] [blame] | 557 | * conjunction with tep_find_function to print both the function |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 558 | * name and the function offset. |
| 559 | */ |
| 560 | unsigned long long |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 561 | tep_find_function_address(struct tep_handle *tep, unsigned long long addr) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 562 | { |
| 563 | struct func_map *map; |
| 564 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 565 | map = find_func(tep, addr); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 566 | if (!map) |
| 567 | return 0; |
| 568 | |
| 569 | return map->addr; |
| 570 | } |
| 571 | |
| 572 | /** |
Tzvetomir Stoyanov (VMware) | b843e9c | 2018-08-08 14:03:02 -0400 | [diff] [blame] | 573 | * tep_register_function - register a function with a given address |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 574 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 575 | * @function: the function name to register |
| 576 | * @addr: the address the function starts at |
| 577 | * @mod: the kernel module the function may be in (NULL for none) |
| 578 | * |
| 579 | * This registers a function name with an address and module. |
| 580 | * The @func passed in is duplicated. |
| 581 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 582 | int tep_register_function(struct tep_handle *tep, char *func, |
Tzvetomir Stoyanov (VMware) | b843e9c | 2018-08-08 14:03:02 -0400 | [diff] [blame] | 583 | unsigned long long addr, char *mod) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 584 | { |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 585 | struct func_list *item = malloc(sizeof(*item)); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 586 | |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 587 | if (!item) |
| 588 | return -1; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 589 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 590 | item->next = tep->funclist; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 591 | item->func = strdup(func); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 592 | if (!item->func) |
| 593 | goto out_free; |
| 594 | |
| 595 | if (mod) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 596 | item->mod = strdup(mod); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 597 | if (!item->mod) |
| 598 | goto out_free_func; |
| 599 | } else |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 600 | item->mod = NULL; |
| 601 | item->addr = addr; |
| 602 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 603 | tep->funclist = item; |
| 604 | tep->func_count++; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 605 | |
| 606 | return 0; |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 607 | |
| 608 | out_free_func: |
| 609 | free(item->func); |
| 610 | item->func = NULL; |
| 611 | out_free: |
| 612 | free(item); |
| 613 | errno = ENOMEM; |
| 614 | return -1; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | /** |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 618 | * tep_print_funcs - print out the stored functions |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 619 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 620 | * |
| 621 | * This prints out the stored functions. |
| 622 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 623 | void tep_print_funcs(struct tep_handle *tep) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 624 | { |
| 625 | int i; |
| 626 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 627 | if (!tep->func_map) |
| 628 | func_map_init(tep); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 629 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 630 | for (i = 0; i < (int)tep->func_count; i++) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 631 | printf("%016llx %s", |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 632 | tep->func_map[i].addr, |
| 633 | tep->func_map[i].func); |
| 634 | if (tep->func_map[i].mod) |
| 635 | printf(" [%s]\n", tep->func_map[i].mod); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 636 | else |
| 637 | printf("\n"); |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | struct printk_map { |
| 642 | unsigned long long addr; |
| 643 | char *printk; |
| 644 | }; |
| 645 | |
| 646 | struct printk_list { |
| 647 | struct printk_list *next; |
| 648 | unsigned long long addr; |
| 649 | char *printk; |
| 650 | }; |
| 651 | |
| 652 | static int printk_cmp(const void *a, const void *b) |
| 653 | { |
Namhyung Kim | 0fc45ef | 2012-04-09 11:54:29 +0900 | [diff] [blame] | 654 | const struct printk_map *pa = a; |
| 655 | const struct printk_map *pb = b; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 656 | |
Namhyung Kim | 0fc45ef | 2012-04-09 11:54:29 +0900 | [diff] [blame] | 657 | if (pa->addr < pb->addr) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 658 | return -1; |
Namhyung Kim | 0fc45ef | 2012-04-09 11:54:29 +0900 | [diff] [blame] | 659 | if (pa->addr > pb->addr) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 660 | return 1; |
| 661 | |
| 662 | return 0; |
| 663 | } |
| 664 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 665 | static int printk_map_init(struct tep_handle *pevent) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 666 | { |
| 667 | struct printk_list *printklist; |
| 668 | struct printk_list *item; |
| 669 | struct printk_map *printk_map; |
| 670 | int i; |
| 671 | |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 672 | printk_map = malloc(sizeof(*printk_map) * (pevent->printk_count + 1)); |
| 673 | if (!printk_map) |
| 674 | return -1; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 675 | |
| 676 | printklist = pevent->printklist; |
| 677 | |
| 678 | i = 0; |
| 679 | while (printklist) { |
| 680 | printk_map[i].printk = printklist->printk; |
| 681 | printk_map[i].addr = printklist->addr; |
| 682 | i++; |
| 683 | item = printklist; |
| 684 | printklist = printklist->next; |
| 685 | free(item); |
| 686 | } |
| 687 | |
| 688 | qsort(printk_map, pevent->printk_count, sizeof(*printk_map), printk_cmp); |
| 689 | |
| 690 | pevent->printk_map = printk_map; |
| 691 | pevent->printklist = NULL; |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 692 | |
| 693 | return 0; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | static struct printk_map * |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 697 | find_printk(struct tep_handle *pevent, unsigned long long addr) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 698 | { |
| 699 | struct printk_map *printk; |
| 700 | struct printk_map key; |
| 701 | |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 702 | if (!pevent->printk_map && printk_map_init(pevent)) |
| 703 | return NULL; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 704 | |
| 705 | key.addr = addr; |
| 706 | |
| 707 | printk = bsearch(&key, pevent->printk_map, pevent->printk_count, |
| 708 | sizeof(*pevent->printk_map), printk_cmp); |
| 709 | |
| 710 | return printk; |
| 711 | } |
| 712 | |
| 713 | /** |
Tzvetomir Stoyanov (VMware) | 13a4189 | 2018-08-08 14:02:54 -0400 | [diff] [blame] | 714 | * tep_register_print_string - register a string by its address |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 715 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 716 | * @fmt: the string format to register |
| 717 | * @addr: the address the string was located at |
| 718 | * |
| 719 | * This registers a string by the address it was stored in the kernel. |
| 720 | * The @fmt passed in is duplicated. |
| 721 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 722 | int tep_register_print_string(struct tep_handle *tep, const char *fmt, |
Tzvetomir Stoyanov (VMware) | 13a4189 | 2018-08-08 14:02:54 -0400 | [diff] [blame] | 723 | unsigned long long addr) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 724 | { |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 725 | struct printk_list *item = malloc(sizeof(*item)); |
Steven Rostedt (Red Hat) | 18900af | 2013-11-01 17:53:54 -0400 | [diff] [blame] | 726 | char *p; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 727 | |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 728 | if (!item) |
| 729 | return -1; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 730 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 731 | item->next = tep->printklist; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 732 | item->addr = addr; |
| 733 | |
Steven Rostedt (Red Hat) | 18900af | 2013-11-01 17:53:54 -0400 | [diff] [blame] | 734 | /* Strip off quotes and '\n' from the end */ |
| 735 | if (fmt[0] == '"') |
| 736 | fmt++; |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 737 | item->printk = strdup(fmt); |
Namhyung Kim | ca63858 | 2012-04-09 11:54:31 +0900 | [diff] [blame] | 738 | if (!item->printk) |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 739 | goto out_free; |
Namhyung Kim | ca63858 | 2012-04-09 11:54:31 +0900 | [diff] [blame] | 740 | |
Steven Rostedt (Red Hat) | 18900af | 2013-11-01 17:53:54 -0400 | [diff] [blame] | 741 | p = item->printk + strlen(item->printk) - 1; |
| 742 | if (*p == '"') |
| 743 | *p = 0; |
| 744 | |
| 745 | p -= 2; |
| 746 | if (strcmp(p, "\\n") == 0) |
| 747 | *p = 0; |
| 748 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 749 | tep->printklist = item; |
| 750 | tep->printk_count++; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 751 | |
| 752 | return 0; |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 753 | |
| 754 | out_free: |
| 755 | free(item); |
| 756 | errno = ENOMEM; |
| 757 | return -1; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | /** |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 761 | * tep_print_printk - print out the stored strings |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 762 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 763 | * |
| 764 | * This prints the string formats that were stored. |
| 765 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 766 | void tep_print_printk(struct tep_handle *tep) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 767 | { |
| 768 | int i; |
| 769 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 770 | if (!tep->printk_map) |
| 771 | printk_map_init(tep); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 772 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 773 | for (i = 0; i < (int)tep->printk_count; i++) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 774 | printf("%016llx %s\n", |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 775 | tep->printk_map[i].addr, |
| 776 | tep->printk_map[i].printk); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 780 | static struct tep_event *alloc_event(void) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 781 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 782 | return calloc(1, sizeof(struct tep_event)); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 783 | } |
| 784 | |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 785 | static int add_event(struct tep_handle *pevent, struct tep_event *event) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 786 | { |
| 787 | int i; |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 788 | struct tep_event **events = realloc(pevent->events, sizeof(event) * |
| 789 | (pevent->nr_events + 1)); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 790 | if (!events) |
| 791 | return -1; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 792 | |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 793 | pevent->events = events; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 794 | |
| 795 | for (i = 0; i < pevent->nr_events; i++) { |
| 796 | if (pevent->events[i]->id > event->id) |
| 797 | break; |
| 798 | } |
| 799 | if (i < pevent->nr_events) |
| 800 | memmove(&pevent->events[i + 1], |
| 801 | &pevent->events[i], |
| 802 | sizeof(event) * (pevent->nr_events - i)); |
| 803 | |
| 804 | pevent->events[i] = event; |
| 805 | pevent->nr_events++; |
| 806 | |
| 807 | event->pevent = pevent; |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 808 | |
| 809 | return 0; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 810 | } |
| 811 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 812 | static int event_item_type(enum tep_event_type type) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 813 | { |
| 814 | switch (type) { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 815 | case TEP_EVENT_ITEM ... TEP_EVENT_SQUOTE: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 816 | return 1; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 817 | case TEP_EVENT_ERROR ... TEP_EVENT_DELIM: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 818 | default: |
| 819 | return 0; |
| 820 | } |
| 821 | } |
| 822 | |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 823 | static void free_flag_sym(struct tep_print_flag_sym *fsym) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 824 | { |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 825 | struct tep_print_flag_sym *next; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 826 | |
| 827 | while (fsym) { |
| 828 | next = fsym->next; |
| 829 | free(fsym->value); |
| 830 | free(fsym->str); |
| 831 | free(fsym); |
| 832 | fsym = next; |
| 833 | } |
| 834 | } |
| 835 | |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 836 | static void free_arg(struct tep_print_arg *arg) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 837 | { |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 838 | struct tep_print_arg *farg; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 839 | |
| 840 | if (!arg) |
| 841 | return; |
| 842 | |
| 843 | switch (arg->type) { |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 844 | case TEP_PRINT_ATOM: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 845 | free(arg->atom.atom); |
| 846 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 847 | case TEP_PRINT_FIELD: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 848 | free(arg->field.name); |
| 849 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 850 | case TEP_PRINT_FLAGS: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 851 | free_arg(arg->flags.field); |
| 852 | free(arg->flags.delim); |
| 853 | free_flag_sym(arg->flags.flags); |
| 854 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 855 | case TEP_PRINT_SYMBOL: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 856 | free_arg(arg->symbol.field); |
| 857 | free_flag_sym(arg->symbol.symbols); |
| 858 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 859 | case TEP_PRINT_HEX: |
| 860 | case TEP_PRINT_HEX_STR: |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 861 | free_arg(arg->hex.field); |
| 862 | free_arg(arg->hex.size); |
| 863 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 864 | case TEP_PRINT_INT_ARRAY: |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 865 | free_arg(arg->int_array.field); |
| 866 | free_arg(arg->int_array.count); |
| 867 | free_arg(arg->int_array.el_size); |
| 868 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 869 | case TEP_PRINT_TYPE: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 870 | free(arg->typecast.type); |
| 871 | free_arg(arg->typecast.item); |
| 872 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 873 | case TEP_PRINT_STRING: |
| 874 | case TEP_PRINT_BSTRING: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 875 | free(arg->string.string); |
| 876 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 877 | case TEP_PRINT_BITMASK: |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 878 | free(arg->bitmask.bitmask); |
| 879 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 880 | case TEP_PRINT_DYNAMIC_ARRAY: |
| 881 | case TEP_PRINT_DYNAMIC_ARRAY_LEN: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 882 | free(arg->dynarray.index); |
| 883 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 884 | case TEP_PRINT_OP: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 885 | free(arg->op.op); |
| 886 | free_arg(arg->op.left); |
| 887 | free_arg(arg->op.right); |
| 888 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 889 | case TEP_PRINT_FUNC: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 890 | while (arg->func.args) { |
| 891 | farg = arg->func.args; |
| 892 | arg->func.args = farg->next; |
| 893 | free_arg(farg); |
| 894 | } |
| 895 | break; |
| 896 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 897 | case TEP_PRINT_NULL: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 898 | default: |
| 899 | break; |
| 900 | } |
| 901 | |
| 902 | free(arg); |
| 903 | } |
| 904 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 905 | static enum tep_event_type get_type(int ch) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 906 | { |
| 907 | if (ch == '\n') |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 908 | return TEP_EVENT_NEWLINE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 909 | if (isspace(ch)) |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 910 | return TEP_EVENT_SPACE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 911 | if (isalnum(ch) || ch == '_') |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 912 | return TEP_EVENT_ITEM; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 913 | if (ch == '\'') |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 914 | return TEP_EVENT_SQUOTE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 915 | if (ch == '"') |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 916 | return TEP_EVENT_DQUOTE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 917 | if (!isprint(ch)) |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 918 | return TEP_EVENT_NONE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 919 | if (ch == '(' || ch == ')' || ch == ',') |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 920 | return TEP_EVENT_DELIM; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 921 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 922 | return TEP_EVENT_OP; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | static int __read_char(void) |
| 926 | { |
| 927 | if (input_buf_ptr >= input_buf_siz) |
| 928 | return -1; |
| 929 | |
| 930 | return input_buf[input_buf_ptr++]; |
| 931 | } |
| 932 | |
| 933 | static int __peek_char(void) |
| 934 | { |
| 935 | if (input_buf_ptr >= input_buf_siz) |
| 936 | return -1; |
| 937 | |
| 938 | return input_buf[input_buf_ptr]; |
| 939 | } |
| 940 | |
| 941 | /** |
Tzvetomir Stoyanov (VMware) | 1634e46 | 2018-08-08 14:03:07 -0400 | [diff] [blame] | 942 | * tep_peek_char - peek at the next character that will be read |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 943 | * |
| 944 | * Returns the next character read, or -1 if end of buffer. |
| 945 | */ |
Tzvetomir Stoyanov (VMware) | 1634e46 | 2018-08-08 14:03:07 -0400 | [diff] [blame] | 946 | int tep_peek_char(void) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 947 | { |
| 948 | return __peek_char(); |
| 949 | } |
| 950 | |
Namhyung Kim | deba3fb | 2012-04-09 11:54:30 +0900 | [diff] [blame] | 951 | static int extend_token(char **tok, char *buf, int size) |
| 952 | { |
| 953 | char *newtok = realloc(*tok, size); |
| 954 | |
| 955 | if (!newtok) { |
| 956 | free(*tok); |
| 957 | *tok = NULL; |
| 958 | return -1; |
| 959 | } |
| 960 | |
| 961 | if (!*tok) |
| 962 | strcpy(newtok, buf); |
| 963 | else |
| 964 | strcat(newtok, buf); |
| 965 | *tok = newtok; |
| 966 | |
| 967 | return 0; |
| 968 | } |
| 969 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 970 | static enum tep_event_type force_token(const char *str, char **tok); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 971 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 972 | static enum tep_event_type __read_token(char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 973 | { |
| 974 | char buf[BUFSIZ]; |
| 975 | int ch, last_ch, quote_ch, next_ch; |
| 976 | int i = 0; |
| 977 | int tok_size = 0; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 978 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 979 | |
| 980 | *tok = NULL; |
| 981 | |
| 982 | |
| 983 | ch = __read_char(); |
| 984 | if (ch < 0) |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 985 | return TEP_EVENT_NONE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 986 | |
| 987 | type = get_type(ch); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 988 | if (type == TEP_EVENT_NONE) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 989 | return type; |
| 990 | |
| 991 | buf[i++] = ch; |
| 992 | |
| 993 | switch (type) { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 994 | case TEP_EVENT_NEWLINE: |
| 995 | case TEP_EVENT_DELIM: |
Arnaldo Carvalho de Melo | 0dbca1e | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 996 | if (asprintf(tok, "%c", ch) < 0) |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 997 | return TEP_EVENT_ERROR; |
Arnaldo Carvalho de Melo | 0dbca1e | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 998 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 999 | return type; |
| 1000 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1001 | case TEP_EVENT_OP: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1002 | switch (ch) { |
| 1003 | case '-': |
| 1004 | next_ch = __peek_char(); |
| 1005 | if (next_ch == '>') { |
| 1006 | buf[i++] = __read_char(); |
| 1007 | break; |
| 1008 | } |
| 1009 | /* fall through */ |
| 1010 | case '+': |
| 1011 | case '|': |
| 1012 | case '&': |
| 1013 | case '>': |
| 1014 | case '<': |
| 1015 | last_ch = ch; |
| 1016 | ch = __peek_char(); |
| 1017 | if (ch != last_ch) |
| 1018 | goto test_equal; |
| 1019 | buf[i++] = __read_char(); |
| 1020 | switch (last_ch) { |
| 1021 | case '>': |
| 1022 | case '<': |
| 1023 | goto test_equal; |
| 1024 | default: |
| 1025 | break; |
| 1026 | } |
| 1027 | break; |
| 1028 | case '!': |
| 1029 | case '=': |
| 1030 | goto test_equal; |
| 1031 | default: /* what should we do instead? */ |
| 1032 | break; |
| 1033 | } |
| 1034 | buf[i] = 0; |
| 1035 | *tok = strdup(buf); |
| 1036 | return type; |
| 1037 | |
| 1038 | test_equal: |
| 1039 | ch = __peek_char(); |
| 1040 | if (ch == '=') |
| 1041 | buf[i++] = __read_char(); |
| 1042 | goto out; |
| 1043 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1044 | case TEP_EVENT_DQUOTE: |
| 1045 | case TEP_EVENT_SQUOTE: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1046 | /* don't keep quotes */ |
| 1047 | i--; |
| 1048 | quote_ch = ch; |
| 1049 | last_ch = 0; |
| 1050 | concat: |
| 1051 | do { |
| 1052 | if (i == (BUFSIZ - 1)) { |
| 1053 | buf[i] = 0; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1054 | tok_size += BUFSIZ; |
Namhyung Kim | deba3fb | 2012-04-09 11:54:30 +0900 | [diff] [blame] | 1055 | |
| 1056 | if (extend_token(tok, buf, tok_size) < 0) |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1057 | return TEP_EVENT_NONE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1058 | i = 0; |
| 1059 | } |
| 1060 | last_ch = ch; |
| 1061 | ch = __read_char(); |
| 1062 | buf[i++] = ch; |
| 1063 | /* the '\' '\' will cancel itself */ |
| 1064 | if (ch == '\\' && last_ch == '\\') |
| 1065 | last_ch = 0; |
| 1066 | } while (ch != quote_ch || last_ch == '\\'); |
| 1067 | /* remove the last quote */ |
| 1068 | i--; |
| 1069 | |
| 1070 | /* |
| 1071 | * For strings (double quotes) check the next token. |
| 1072 | * If it is another string, concatinate the two. |
| 1073 | */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1074 | if (type == TEP_EVENT_DQUOTE) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1075 | unsigned long long save_input_buf_ptr = input_buf_ptr; |
| 1076 | |
| 1077 | do { |
| 1078 | ch = __read_char(); |
| 1079 | } while (isspace(ch)); |
| 1080 | if (ch == '"') |
| 1081 | goto concat; |
| 1082 | input_buf_ptr = save_input_buf_ptr; |
| 1083 | } |
| 1084 | |
| 1085 | goto out; |
| 1086 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1087 | case TEP_EVENT_ERROR ... TEP_EVENT_SPACE: |
| 1088 | case TEP_EVENT_ITEM: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1089 | default: |
| 1090 | break; |
| 1091 | } |
| 1092 | |
| 1093 | while (get_type(__peek_char()) == type) { |
| 1094 | if (i == (BUFSIZ - 1)) { |
| 1095 | buf[i] = 0; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1096 | tok_size += BUFSIZ; |
Namhyung Kim | deba3fb | 2012-04-09 11:54:30 +0900 | [diff] [blame] | 1097 | |
| 1098 | if (extend_token(tok, buf, tok_size) < 0) |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1099 | return TEP_EVENT_NONE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1100 | i = 0; |
| 1101 | } |
| 1102 | ch = __read_char(); |
| 1103 | buf[i++] = ch; |
| 1104 | } |
| 1105 | |
| 1106 | out: |
| 1107 | buf[i] = 0; |
Namhyung Kim | deba3fb | 2012-04-09 11:54:30 +0900 | [diff] [blame] | 1108 | if (extend_token(tok, buf, tok_size + i + 1) < 0) |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1109 | return TEP_EVENT_NONE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1110 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1111 | if (type == TEP_EVENT_ITEM) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1112 | /* |
| 1113 | * Older versions of the kernel has a bug that |
| 1114 | * creates invalid symbols and will break the mac80211 |
| 1115 | * parsing. This is a work around to that bug. |
| 1116 | * |
| 1117 | * See Linux kernel commit: |
| 1118 | * 811cb50baf63461ce0bdb234927046131fc7fa8b |
| 1119 | */ |
| 1120 | if (strcmp(*tok, "LOCAL_PR_FMT") == 0) { |
| 1121 | free(*tok); |
| 1122 | *tok = NULL; |
Michael Sartain | 952a99c | 2018-01-11 19:47:42 -0500 | [diff] [blame] | 1123 | return force_token("\"%s\" ", tok); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1124 | } else if (strcmp(*tok, "STA_PR_FMT") == 0) { |
| 1125 | free(*tok); |
| 1126 | *tok = NULL; |
| 1127 | return force_token("\" sta:%pM\" ", tok); |
| 1128 | } else if (strcmp(*tok, "VIF_PR_FMT") == 0) { |
| 1129 | free(*tok); |
| 1130 | *tok = NULL; |
| 1131 | return force_token("\" vif:%p(%d)\" ", tok); |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | return type; |
| 1136 | } |
| 1137 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1138 | static enum tep_event_type force_token(const char *str, char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1139 | { |
| 1140 | const char *save_input_buf; |
| 1141 | unsigned long long save_input_buf_ptr; |
| 1142 | unsigned long long save_input_buf_siz; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1143 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1144 | |
| 1145 | /* save off the current input pointers */ |
| 1146 | save_input_buf = input_buf; |
| 1147 | save_input_buf_ptr = input_buf_ptr; |
| 1148 | save_input_buf_siz = input_buf_siz; |
| 1149 | |
| 1150 | init_input_buf(str, strlen(str)); |
| 1151 | |
| 1152 | type = __read_token(tok); |
| 1153 | |
| 1154 | /* reset back to original token */ |
| 1155 | input_buf = save_input_buf; |
| 1156 | input_buf_ptr = save_input_buf_ptr; |
| 1157 | input_buf_siz = save_input_buf_siz; |
| 1158 | |
| 1159 | return type; |
| 1160 | } |
| 1161 | |
| 1162 | static void free_token(char *tok) |
| 1163 | { |
| 1164 | if (tok) |
| 1165 | free(tok); |
| 1166 | } |
| 1167 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1168 | static enum tep_event_type read_token(char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1169 | { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1170 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1171 | |
| 1172 | for (;;) { |
| 1173 | type = __read_token(tok); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1174 | if (type != TEP_EVENT_SPACE) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1175 | return type; |
| 1176 | |
| 1177 | free_token(*tok); |
| 1178 | } |
| 1179 | |
| 1180 | /* not reached */ |
| 1181 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1182 | return TEP_EVENT_NONE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | /** |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 1186 | * tep_read_token - access to utilities to use the tep parser |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1187 | * @tok: The token to return |
| 1188 | * |
| 1189 | * This will parse tokens from the string given by |
Tzvetomir Stoyanov (VMware) | 0ae9863 | 2018-08-08 14:03:09 -0400 | [diff] [blame] | 1190 | * tep_init_data(). |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1191 | * |
| 1192 | * Returns the token type. |
| 1193 | */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1194 | enum tep_event_type tep_read_token(char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1195 | { |
| 1196 | return read_token(tok); |
| 1197 | } |
| 1198 | |
| 1199 | /** |
Tzvetomir Stoyanov (VMware) | 1634e46 | 2018-08-08 14:03:07 -0400 | [diff] [blame] | 1200 | * tep_free_token - free a token returned by tep_read_token |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1201 | * @token: the token to free |
| 1202 | */ |
Tzvetomir Stoyanov (VMware) | 1634e46 | 2018-08-08 14:03:07 -0400 | [diff] [blame] | 1203 | void tep_free_token(char *token) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1204 | { |
| 1205 | free_token(token); |
| 1206 | } |
| 1207 | |
| 1208 | /* no newline */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1209 | static enum tep_event_type read_token_item(char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1210 | { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1211 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1212 | |
| 1213 | for (;;) { |
| 1214 | type = __read_token(tok); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1215 | if (type != TEP_EVENT_SPACE && type != TEP_EVENT_NEWLINE) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1216 | return type; |
| 1217 | free_token(*tok); |
| 1218 | *tok = NULL; |
| 1219 | } |
| 1220 | |
| 1221 | /* not reached */ |
| 1222 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1223 | return TEP_EVENT_NONE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1224 | } |
| 1225 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1226 | static int test_type(enum tep_event_type type, enum tep_event_type expect) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1227 | { |
| 1228 | if (type != expect) { |
| 1229 | do_warning("Error: expected type %d but read %d", |
| 1230 | expect, type); |
| 1231 | return -1; |
| 1232 | } |
| 1233 | return 0; |
| 1234 | } |
| 1235 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1236 | static int test_type_token(enum tep_event_type type, const char *token, |
| 1237 | enum tep_event_type expect, const char *expect_tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1238 | { |
| 1239 | if (type != expect) { |
| 1240 | do_warning("Error: expected type %d but read %d", |
| 1241 | expect, type); |
| 1242 | return -1; |
| 1243 | } |
| 1244 | |
| 1245 | if (strcmp(token, expect_tok) != 0) { |
| 1246 | do_warning("Error: expected '%s' but read '%s'", |
| 1247 | expect_tok, token); |
| 1248 | return -1; |
| 1249 | } |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1253 | static int __read_expect_type(enum tep_event_type expect, char **tok, int newline_ok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1254 | { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1255 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1256 | |
| 1257 | if (newline_ok) |
| 1258 | type = read_token(tok); |
| 1259 | else |
| 1260 | type = read_token_item(tok); |
| 1261 | return test_type(type, expect); |
| 1262 | } |
| 1263 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1264 | static int read_expect_type(enum tep_event_type expect, char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1265 | { |
| 1266 | return __read_expect_type(expect, tok, 1); |
| 1267 | } |
| 1268 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1269 | static int __read_expected(enum tep_event_type expect, const char *str, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1270 | int newline_ok) |
| 1271 | { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1272 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1273 | char *token; |
| 1274 | int ret; |
| 1275 | |
| 1276 | if (newline_ok) |
| 1277 | type = read_token(&token); |
| 1278 | else |
| 1279 | type = read_token_item(&token); |
| 1280 | |
| 1281 | ret = test_type_token(type, token, expect, str); |
| 1282 | |
| 1283 | free_token(token); |
| 1284 | |
| 1285 | return ret; |
| 1286 | } |
| 1287 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1288 | static int read_expected(enum tep_event_type expect, const char *str) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1289 | { |
| 1290 | return __read_expected(expect, str, 1); |
| 1291 | } |
| 1292 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1293 | static int read_expected_item(enum tep_event_type expect, const char *str) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1294 | { |
| 1295 | return __read_expected(expect, str, 0); |
| 1296 | } |
| 1297 | |
| 1298 | static char *event_read_name(void) |
| 1299 | { |
| 1300 | char *token; |
| 1301 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1302 | if (read_expected(TEP_EVENT_ITEM, "name") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1303 | return NULL; |
| 1304 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1305 | if (read_expected(TEP_EVENT_OP, ":") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1306 | return NULL; |
| 1307 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1308 | if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1309 | goto fail; |
| 1310 | |
| 1311 | return token; |
| 1312 | |
| 1313 | fail: |
| 1314 | free_token(token); |
| 1315 | return NULL; |
| 1316 | } |
| 1317 | |
| 1318 | static int event_read_id(void) |
| 1319 | { |
| 1320 | char *token; |
| 1321 | int id; |
| 1322 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1323 | if (read_expected_item(TEP_EVENT_ITEM, "ID") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1324 | return -1; |
| 1325 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1326 | if (read_expected(TEP_EVENT_OP, ":") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1327 | return -1; |
| 1328 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1329 | if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1330 | goto fail; |
| 1331 | |
| 1332 | id = strtoul(token, NULL, 0); |
| 1333 | free_token(token); |
| 1334 | return id; |
| 1335 | |
| 1336 | fail: |
| 1337 | free_token(token); |
| 1338 | return -1; |
| 1339 | } |
| 1340 | |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 1341 | static int field_is_string(struct tep_format_field *field) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1342 | { |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 1343 | if ((field->flags & TEP_FIELD_IS_ARRAY) && |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1344 | (strstr(field->type, "char") || strstr(field->type, "u8") || |
| 1345 | strstr(field->type, "s8"))) |
| 1346 | return 1; |
| 1347 | |
| 1348 | return 0; |
| 1349 | } |
| 1350 | |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 1351 | static int field_is_dynamic(struct tep_format_field *field) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1352 | { |
| 1353 | if (strncmp(field->type, "__data_loc", 10) == 0) |
| 1354 | return 1; |
| 1355 | |
| 1356 | return 0; |
| 1357 | } |
| 1358 | |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 1359 | static int field_is_long(struct tep_format_field *field) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1360 | { |
| 1361 | /* includes long long */ |
| 1362 | if (strstr(field->type, "long")) |
| 1363 | return 1; |
| 1364 | |
| 1365 | return 0; |
| 1366 | } |
| 1367 | |
Jiri Olsa | e23c1a5 | 2013-01-24 21:46:43 +0100 | [diff] [blame] | 1368 | static unsigned int type_size(const char *name) |
| 1369 | { |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 1370 | /* This covers all TEP_FIELD_IS_STRING types. */ |
Jiri Olsa | e23c1a5 | 2013-01-24 21:46:43 +0100 | [diff] [blame] | 1371 | static struct { |
| 1372 | const char *type; |
| 1373 | unsigned int size; |
| 1374 | } table[] = { |
| 1375 | { "u8", 1 }, |
| 1376 | { "u16", 2 }, |
| 1377 | { "u32", 4 }, |
| 1378 | { "u64", 8 }, |
| 1379 | { "s8", 1 }, |
| 1380 | { "s16", 2 }, |
| 1381 | { "s32", 4 }, |
| 1382 | { "s64", 8 }, |
| 1383 | { "char", 1 }, |
| 1384 | { }, |
| 1385 | }; |
| 1386 | int i; |
| 1387 | |
| 1388 | for (i = 0; table[i].type; i++) { |
| 1389 | if (!strcmp(table[i].type, name)) |
| 1390 | return table[i].size; |
| 1391 | } |
| 1392 | |
| 1393 | return 0; |
| 1394 | } |
| 1395 | |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 1396 | static int event_read_fields(struct tep_event *event, struct tep_format_field **fields) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1397 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 1398 | struct tep_format_field *field = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1399 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1400 | char *token; |
| 1401 | char *last_token; |
| 1402 | int count = 0; |
| 1403 | |
| 1404 | do { |
Jiri Olsa | e23c1a5 | 2013-01-24 21:46:43 +0100 | [diff] [blame] | 1405 | unsigned int size_dynamic = 0; |
| 1406 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1407 | type = read_token(&token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1408 | if (type == TEP_EVENT_NEWLINE) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1409 | free_token(token); |
| 1410 | return count; |
| 1411 | } |
| 1412 | |
| 1413 | count++; |
| 1414 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1415 | if (test_type_token(type, token, TEP_EVENT_ITEM, "field")) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1416 | goto fail; |
| 1417 | free_token(token); |
| 1418 | |
| 1419 | type = read_token(&token); |
| 1420 | /* |
| 1421 | * The ftrace fields may still use the "special" name. |
| 1422 | * Just ignore it. |
| 1423 | */ |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 1424 | if (event->flags & TEP_EVENT_FL_ISFTRACE && |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1425 | type == TEP_EVENT_ITEM && strcmp(token, "special") == 0) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1426 | free_token(token); |
| 1427 | type = read_token(&token); |
| 1428 | } |
| 1429 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1430 | if (test_type_token(type, token, TEP_EVENT_OP, ":") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1431 | goto fail; |
| 1432 | |
| 1433 | free_token(token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1434 | if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1435 | goto fail; |
| 1436 | |
| 1437 | last_token = token; |
| 1438 | |
Arnaldo Carvalho de Melo | 87162d8 | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 1439 | field = calloc(1, sizeof(*field)); |
| 1440 | if (!field) |
| 1441 | goto fail; |
| 1442 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1443 | field->event = event; |
| 1444 | |
| 1445 | /* read the rest of the type */ |
| 1446 | for (;;) { |
| 1447 | type = read_token(&token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1448 | if (type == TEP_EVENT_ITEM || |
| 1449 | (type == TEP_EVENT_OP && strcmp(token, "*") == 0) || |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1450 | /* |
| 1451 | * Some of the ftrace fields are broken and have |
| 1452 | * an illegal "." in them. |
| 1453 | */ |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 1454 | (event->flags & TEP_EVENT_FL_ISFTRACE && |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1455 | type == TEP_EVENT_OP && strcmp(token, ".") == 0)) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1456 | |
| 1457 | if (strcmp(token, "*") == 0) |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 1458 | field->flags |= TEP_FIELD_IS_POINTER; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1459 | |
| 1460 | if (field->type) { |
Namhyung Kim | d286447 | 2012-04-09 11:54:33 +0900 | [diff] [blame] | 1461 | char *new_type; |
| 1462 | new_type = realloc(field->type, |
| 1463 | strlen(field->type) + |
| 1464 | strlen(last_token) + 2); |
| 1465 | if (!new_type) { |
| 1466 | free(last_token); |
| 1467 | goto fail; |
| 1468 | } |
| 1469 | field->type = new_type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1470 | strcat(field->type, " "); |
| 1471 | strcat(field->type, last_token); |
| 1472 | free(last_token); |
| 1473 | } else |
| 1474 | field->type = last_token; |
| 1475 | last_token = token; |
| 1476 | continue; |
| 1477 | } |
| 1478 | |
| 1479 | break; |
| 1480 | } |
| 1481 | |
| 1482 | if (!field->type) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 1483 | do_warning_event(event, "%s: no type found", __func__); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1484 | goto fail; |
| 1485 | } |
Jiri Olsa | d354243 | 2015-04-18 17:50:18 +0200 | [diff] [blame] | 1486 | field->name = field->alias = last_token; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1487 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1488 | if (test_type(type, TEP_EVENT_OP)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1489 | goto fail; |
| 1490 | |
| 1491 | if (strcmp(token, "[") == 0) { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1492 | enum tep_event_type last_type = type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1493 | char *brackets = token; |
Namhyung Kim | d286447 | 2012-04-09 11:54:33 +0900 | [diff] [blame] | 1494 | char *new_brackets; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1495 | int len; |
| 1496 | |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 1497 | field->flags |= TEP_FIELD_IS_ARRAY; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1498 | |
| 1499 | type = read_token(&token); |
| 1500 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1501 | if (type == TEP_EVENT_ITEM) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1502 | field->arraylen = strtoul(token, NULL, 0); |
| 1503 | else |
| 1504 | field->arraylen = 0; |
| 1505 | |
| 1506 | while (strcmp(token, "]") != 0) { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1507 | if (last_type == TEP_EVENT_ITEM && |
| 1508 | type == TEP_EVENT_ITEM) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1509 | len = 2; |
| 1510 | else |
| 1511 | len = 1; |
| 1512 | last_type = type; |
| 1513 | |
Namhyung Kim | d286447 | 2012-04-09 11:54:33 +0900 | [diff] [blame] | 1514 | new_brackets = realloc(brackets, |
| 1515 | strlen(brackets) + |
| 1516 | strlen(token) + len); |
| 1517 | if (!new_brackets) { |
| 1518 | free(brackets); |
| 1519 | goto fail; |
| 1520 | } |
| 1521 | brackets = new_brackets; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1522 | if (len == 2) |
| 1523 | strcat(brackets, " "); |
| 1524 | strcat(brackets, token); |
| 1525 | /* We only care about the last token */ |
| 1526 | field->arraylen = strtoul(token, NULL, 0); |
| 1527 | free_token(token); |
| 1528 | type = read_token(&token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1529 | if (type == TEP_EVENT_NONE) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 1530 | do_warning_event(event, "failed to find token"); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1531 | goto fail; |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | free_token(token); |
| 1536 | |
Namhyung Kim | d286447 | 2012-04-09 11:54:33 +0900 | [diff] [blame] | 1537 | new_brackets = realloc(brackets, strlen(brackets) + 2); |
| 1538 | if (!new_brackets) { |
| 1539 | free(brackets); |
| 1540 | goto fail; |
| 1541 | } |
| 1542 | brackets = new_brackets; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1543 | strcat(brackets, "]"); |
| 1544 | |
| 1545 | /* add brackets to type */ |
| 1546 | |
| 1547 | type = read_token(&token); |
| 1548 | /* |
| 1549 | * If the next token is not an OP, then it is of |
| 1550 | * the format: type [] item; |
| 1551 | */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1552 | if (type == TEP_EVENT_ITEM) { |
Namhyung Kim | d286447 | 2012-04-09 11:54:33 +0900 | [diff] [blame] | 1553 | char *new_type; |
| 1554 | new_type = realloc(field->type, |
| 1555 | strlen(field->type) + |
| 1556 | strlen(field->name) + |
| 1557 | strlen(brackets) + 2); |
| 1558 | if (!new_type) { |
| 1559 | free(brackets); |
| 1560 | goto fail; |
| 1561 | } |
| 1562 | field->type = new_type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1563 | strcat(field->type, " "); |
| 1564 | strcat(field->type, field->name); |
Jiri Olsa | e23c1a5 | 2013-01-24 21:46:43 +0100 | [diff] [blame] | 1565 | size_dynamic = type_size(field->name); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1566 | free_token(field->name); |
| 1567 | strcat(field->type, brackets); |
Jiri Olsa | d354243 | 2015-04-18 17:50:18 +0200 | [diff] [blame] | 1568 | field->name = field->alias = token; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1569 | type = read_token(&token); |
| 1570 | } else { |
Namhyung Kim | d286447 | 2012-04-09 11:54:33 +0900 | [diff] [blame] | 1571 | char *new_type; |
| 1572 | new_type = realloc(field->type, |
| 1573 | strlen(field->type) + |
| 1574 | strlen(brackets) + 1); |
| 1575 | if (!new_type) { |
| 1576 | free(brackets); |
| 1577 | goto fail; |
| 1578 | } |
| 1579 | field->type = new_type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1580 | strcat(field->type, brackets); |
| 1581 | } |
| 1582 | free(brackets); |
| 1583 | } |
| 1584 | |
| 1585 | if (field_is_string(field)) |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 1586 | field->flags |= TEP_FIELD_IS_STRING; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1587 | if (field_is_dynamic(field)) |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 1588 | field->flags |= TEP_FIELD_IS_DYNAMIC; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1589 | if (field_is_long(field)) |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 1590 | field->flags |= TEP_FIELD_IS_LONG; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1591 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1592 | if (test_type_token(type, token, TEP_EVENT_OP, ";")) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1593 | goto fail; |
| 1594 | free_token(token); |
| 1595 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1596 | if (read_expected(TEP_EVENT_ITEM, "offset") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1597 | goto fail_expect; |
| 1598 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1599 | if (read_expected(TEP_EVENT_OP, ":") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1600 | goto fail_expect; |
| 1601 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1602 | if (read_expect_type(TEP_EVENT_ITEM, &token)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1603 | goto fail; |
| 1604 | field->offset = strtoul(token, NULL, 0); |
| 1605 | free_token(token); |
| 1606 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1607 | if (read_expected(TEP_EVENT_OP, ";") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1608 | goto fail_expect; |
| 1609 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1610 | if (read_expected(TEP_EVENT_ITEM, "size") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1611 | goto fail_expect; |
| 1612 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1613 | if (read_expected(TEP_EVENT_OP, ":") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1614 | goto fail_expect; |
| 1615 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1616 | if (read_expect_type(TEP_EVENT_ITEM, &token)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1617 | goto fail; |
| 1618 | field->size = strtoul(token, NULL, 0); |
| 1619 | free_token(token); |
| 1620 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1621 | if (read_expected(TEP_EVENT_OP, ";") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1622 | goto fail_expect; |
| 1623 | |
| 1624 | type = read_token(&token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1625 | if (type != TEP_EVENT_NEWLINE) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1626 | /* newer versions of the kernel have a "signed" type */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1627 | if (test_type_token(type, token, TEP_EVENT_ITEM, "signed")) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1628 | goto fail; |
| 1629 | |
| 1630 | free_token(token); |
| 1631 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1632 | if (read_expected(TEP_EVENT_OP, ":") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1633 | goto fail_expect; |
| 1634 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1635 | if (read_expect_type(TEP_EVENT_ITEM, &token)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1636 | goto fail; |
| 1637 | |
Tom Zanussi | 10ee9fa | 2013-01-18 13:51:25 -0600 | [diff] [blame] | 1638 | if (strtoul(token, NULL, 0)) |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 1639 | field->flags |= TEP_FIELD_IS_SIGNED; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1640 | |
| 1641 | free_token(token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1642 | if (read_expected(TEP_EVENT_OP, ";") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1643 | goto fail_expect; |
| 1644 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1645 | if (read_expect_type(TEP_EVENT_NEWLINE, &token)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1646 | goto fail; |
| 1647 | } |
| 1648 | |
| 1649 | free_token(token); |
| 1650 | |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 1651 | if (field->flags & TEP_FIELD_IS_ARRAY) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1652 | if (field->arraylen) |
| 1653 | field->elementsize = field->size / field->arraylen; |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 1654 | else if (field->flags & TEP_FIELD_IS_DYNAMIC) |
Jiri Olsa | e23c1a5 | 2013-01-24 21:46:43 +0100 | [diff] [blame] | 1655 | field->elementsize = size_dynamic; |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 1656 | else if (field->flags & TEP_FIELD_IS_STRING) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1657 | field->elementsize = 1; |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 1658 | else if (field->flags & TEP_FIELD_IS_LONG) |
Jiri Olsa | e23c1a5 | 2013-01-24 21:46:43 +0100 | [diff] [blame] | 1659 | field->elementsize = event->pevent ? |
| 1660 | event->pevent->long_size : |
| 1661 | sizeof(long); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1662 | } else |
| 1663 | field->elementsize = field->size; |
| 1664 | |
| 1665 | *fields = field; |
| 1666 | fields = &field->next; |
| 1667 | |
| 1668 | } while (1); |
| 1669 | |
| 1670 | return 0; |
| 1671 | |
| 1672 | fail: |
| 1673 | free_token(token); |
| 1674 | fail_expect: |
Namhyung Kim | 57d34dc | 2012-05-23 11:36:47 +0900 | [diff] [blame] | 1675 | if (field) { |
| 1676 | free(field->type); |
| 1677 | free(field->name); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1678 | free(field); |
Namhyung Kim | 57d34dc | 2012-05-23 11:36:47 +0900 | [diff] [blame] | 1679 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1680 | return -1; |
| 1681 | } |
| 1682 | |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 1683 | static int event_read_format(struct tep_event *event) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1684 | { |
| 1685 | char *token; |
| 1686 | int ret; |
| 1687 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1688 | if (read_expected_item(TEP_EVENT_ITEM, "format") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1689 | return -1; |
| 1690 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1691 | if (read_expected(TEP_EVENT_OP, ":") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1692 | return -1; |
| 1693 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1694 | if (read_expect_type(TEP_EVENT_NEWLINE, &token)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1695 | goto fail; |
| 1696 | free_token(token); |
| 1697 | |
| 1698 | ret = event_read_fields(event, &event->format.common_fields); |
| 1699 | if (ret < 0) |
| 1700 | return ret; |
| 1701 | event->format.nr_common = ret; |
| 1702 | |
| 1703 | ret = event_read_fields(event, &event->format.fields); |
| 1704 | if (ret < 0) |
| 1705 | return ret; |
| 1706 | event->format.nr_fields = ret; |
| 1707 | |
| 1708 | return 0; |
| 1709 | |
| 1710 | fail: |
| 1711 | free_token(token); |
| 1712 | return -1; |
| 1713 | } |
| 1714 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1715 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 1716 | process_arg_token(struct tep_event *event, struct tep_print_arg *arg, |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1717 | char **tok, enum tep_event_type type); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1718 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1719 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 1720 | process_arg(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1721 | { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1722 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1723 | char *token; |
| 1724 | |
| 1725 | type = read_token(&token); |
| 1726 | *tok = token; |
| 1727 | |
| 1728 | return process_arg_token(event, arg, tok, type); |
| 1729 | } |
| 1730 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1731 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 1732 | process_op(struct tep_event *event, struct tep_print_arg *arg, char **tok); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1733 | |
Steven Rostedt | eff2c92 | 2013-11-18 14:23:14 -0500 | [diff] [blame] | 1734 | /* |
| 1735 | * For __print_symbolic() and __print_flags, we need to completely |
| 1736 | * evaluate the first argument, which defines what to print next. |
| 1737 | */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1738 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 1739 | process_field_arg(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
Steven Rostedt | eff2c92 | 2013-11-18 14:23:14 -0500 | [diff] [blame] | 1740 | { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1741 | enum tep_event_type type; |
Steven Rostedt | eff2c92 | 2013-11-18 14:23:14 -0500 | [diff] [blame] | 1742 | |
| 1743 | type = process_arg(event, arg, tok); |
| 1744 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1745 | while (type == TEP_EVENT_OP) { |
Steven Rostedt | eff2c92 | 2013-11-18 14:23:14 -0500 | [diff] [blame] | 1746 | type = process_op(event, arg, tok); |
| 1747 | } |
| 1748 | |
| 1749 | return type; |
| 1750 | } |
| 1751 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1752 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 1753 | process_cond(struct tep_event *event, struct tep_print_arg *top, char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1754 | { |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 1755 | struct tep_print_arg *arg, *left, *right; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1756 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1757 | char *token = NULL; |
| 1758 | |
| 1759 | arg = alloc_arg(); |
| 1760 | left = alloc_arg(); |
| 1761 | right = alloc_arg(); |
| 1762 | |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 1763 | if (!arg || !left || !right) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 1764 | do_warning_event(event, "%s: not enough memory!", __func__); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 1765 | /* arg will be freed at out_free */ |
| 1766 | free_arg(left); |
| 1767 | free_arg(right); |
| 1768 | goto out_free; |
| 1769 | } |
| 1770 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 1771 | arg->type = TEP_PRINT_OP; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1772 | arg->op.left = left; |
| 1773 | arg->op.right = right; |
| 1774 | |
| 1775 | *tok = NULL; |
| 1776 | type = process_arg(event, left, &token); |
| 1777 | |
| 1778 | again: |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1779 | if (type == TEP_EVENT_ERROR) |
Dean Nelson | 6f56e9c | 2015-08-20 11:16:32 -0400 | [diff] [blame] | 1780 | goto out_free; |
| 1781 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1782 | /* Handle other operations in the arguments */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1783 | if (type == TEP_EVENT_OP && strcmp(token, ":") != 0) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1784 | type = process_op(event, left, &token); |
| 1785 | goto again; |
| 1786 | } |
| 1787 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1788 | if (test_type_token(type, token, TEP_EVENT_OP, ":")) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1789 | goto out_free; |
| 1790 | |
| 1791 | arg->op.op = token; |
| 1792 | |
| 1793 | type = process_arg(event, right, &token); |
| 1794 | |
| 1795 | top->op.right = arg; |
| 1796 | |
| 1797 | *tok = token; |
| 1798 | return type; |
| 1799 | |
| 1800 | out_free: |
| 1801 | /* Top may point to itself */ |
| 1802 | top->op.right = NULL; |
| 1803 | free_token(token); |
| 1804 | free_arg(arg); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1805 | return TEP_EVENT_ERROR; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1806 | } |
| 1807 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1808 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 1809 | process_array(struct tep_event *event, struct tep_print_arg *top, char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1810 | { |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 1811 | struct tep_print_arg *arg; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1812 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1813 | char *token = NULL; |
| 1814 | |
| 1815 | arg = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 1816 | if (!arg) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 1817 | do_warning_event(event, "%s: not enough memory!", __func__); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 1818 | /* '*tok' is set to top->op.op. No need to free. */ |
| 1819 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1820 | return TEP_EVENT_ERROR; |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 1821 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1822 | |
| 1823 | *tok = NULL; |
| 1824 | type = process_arg(event, arg, &token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1825 | if (test_type_token(type, token, TEP_EVENT_OP, "]")) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1826 | goto out_free; |
| 1827 | |
| 1828 | top->op.right = arg; |
| 1829 | |
| 1830 | free_token(token); |
| 1831 | type = read_token_item(&token); |
| 1832 | *tok = token; |
| 1833 | |
| 1834 | return type; |
| 1835 | |
| 1836 | out_free: |
Namhyung Kim | 1bce6e0 | 2012-09-19 15:58:41 +0900 | [diff] [blame] | 1837 | free_token(token); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1838 | free_arg(arg); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1839 | return TEP_EVENT_ERROR; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | static int get_op_prio(char *op) |
| 1843 | { |
| 1844 | if (!op[1]) { |
| 1845 | switch (op[0]) { |
| 1846 | case '~': |
| 1847 | case '!': |
| 1848 | return 4; |
| 1849 | case '*': |
| 1850 | case '/': |
| 1851 | case '%': |
| 1852 | return 6; |
| 1853 | case '+': |
| 1854 | case '-': |
| 1855 | return 7; |
| 1856 | /* '>>' and '<<' are 8 */ |
| 1857 | case '<': |
| 1858 | case '>': |
| 1859 | return 9; |
| 1860 | /* '==' and '!=' are 10 */ |
| 1861 | case '&': |
| 1862 | return 11; |
| 1863 | case '^': |
| 1864 | return 12; |
| 1865 | case '|': |
| 1866 | return 13; |
| 1867 | case '?': |
| 1868 | return 16; |
| 1869 | default: |
Vaibhav Nagarnaik | 14ffde0 | 2012-04-06 00:48:01 +0200 | [diff] [blame] | 1870 | do_warning("unknown op '%c'", op[0]); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1871 | return -1; |
| 1872 | } |
| 1873 | } else { |
| 1874 | if (strcmp(op, "++") == 0 || |
| 1875 | strcmp(op, "--") == 0) { |
| 1876 | return 3; |
| 1877 | } else if (strcmp(op, ">>") == 0 || |
| 1878 | strcmp(op, "<<") == 0) { |
| 1879 | return 8; |
| 1880 | } else if (strcmp(op, ">=") == 0 || |
| 1881 | strcmp(op, "<=") == 0) { |
| 1882 | return 9; |
| 1883 | } else if (strcmp(op, "==") == 0 || |
| 1884 | strcmp(op, "!=") == 0) { |
| 1885 | return 10; |
| 1886 | } else if (strcmp(op, "&&") == 0) { |
| 1887 | return 14; |
| 1888 | } else if (strcmp(op, "||") == 0) { |
| 1889 | return 15; |
| 1890 | } else { |
Vaibhav Nagarnaik | 14ffde0 | 2012-04-06 00:48:01 +0200 | [diff] [blame] | 1891 | do_warning("unknown op '%s'", op); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1892 | return -1; |
| 1893 | } |
| 1894 | } |
| 1895 | } |
| 1896 | |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 1897 | static int set_op_prio(struct tep_print_arg *arg) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1898 | { |
| 1899 | |
| 1900 | /* single ops are the greatest */ |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 1901 | if (!arg->op.left || arg->op.left->type == TEP_PRINT_NULL) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1902 | arg->op.prio = 0; |
Vaibhav Nagarnaik | 14ffde0 | 2012-04-06 00:48:01 +0200 | [diff] [blame] | 1903 | else |
| 1904 | arg->op.prio = get_op_prio(arg->op.op); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1905 | |
Vaibhav Nagarnaik | 14ffde0 | 2012-04-06 00:48:01 +0200 | [diff] [blame] | 1906 | return arg->op.prio; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | /* Note, *tok does not get freed, but will most likely be saved */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1910 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 1911 | process_op(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1912 | { |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 1913 | struct tep_print_arg *left, *right = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 1914 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1915 | char *token; |
| 1916 | |
| 1917 | /* the op is passed in via tok */ |
| 1918 | token = *tok; |
| 1919 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 1920 | if (arg->type == TEP_PRINT_OP && !arg->op.left) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1921 | /* handle single op */ |
| 1922 | if (token[1]) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 1923 | do_warning_event(event, "bad op token %s", token); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1924 | goto out_free; |
| 1925 | } |
| 1926 | switch (token[0]) { |
| 1927 | case '~': |
| 1928 | case '!': |
| 1929 | case '+': |
| 1930 | case '-': |
| 1931 | break; |
| 1932 | default: |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 1933 | do_warning_event(event, "bad op token %s", token); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1934 | goto out_free; |
| 1935 | |
| 1936 | } |
| 1937 | |
| 1938 | /* make an empty left */ |
| 1939 | left = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 1940 | if (!left) |
| 1941 | goto out_warn_free; |
| 1942 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 1943 | left->type = TEP_PRINT_NULL; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1944 | arg->op.left = left; |
| 1945 | |
| 1946 | right = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 1947 | if (!right) |
| 1948 | goto out_warn_free; |
| 1949 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1950 | arg->op.right = right; |
| 1951 | |
| 1952 | /* do not free the token, it belongs to an op */ |
| 1953 | *tok = NULL; |
| 1954 | type = process_arg(event, right, tok); |
| 1955 | |
| 1956 | } else if (strcmp(token, "?") == 0) { |
| 1957 | |
| 1958 | left = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 1959 | if (!left) |
| 1960 | goto out_warn_free; |
| 1961 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1962 | /* copy the top arg to the left */ |
| 1963 | *left = *arg; |
| 1964 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 1965 | arg->type = TEP_PRINT_OP; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1966 | arg->op.op = token; |
| 1967 | arg->op.left = left; |
| 1968 | arg->op.prio = 0; |
| 1969 | |
Namhyung Kim | 41e51a2 | 2012-09-19 15:58:42 +0900 | [diff] [blame] | 1970 | /* it will set arg->op.right */ |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1971 | type = process_cond(event, arg, tok); |
| 1972 | |
| 1973 | } else if (strcmp(token, ">>") == 0 || |
| 1974 | strcmp(token, "<<") == 0 || |
| 1975 | strcmp(token, "&") == 0 || |
| 1976 | strcmp(token, "|") == 0 || |
| 1977 | strcmp(token, "&&") == 0 || |
| 1978 | strcmp(token, "||") == 0 || |
| 1979 | strcmp(token, "-") == 0 || |
| 1980 | strcmp(token, "+") == 0 || |
| 1981 | strcmp(token, "*") == 0 || |
| 1982 | strcmp(token, "^") == 0 || |
| 1983 | strcmp(token, "/") == 0 || |
Daniel Bristot de Oliveira | 0e47b38 | 2016-02-22 14:08:22 -0300 | [diff] [blame] | 1984 | strcmp(token, "%") == 0 || |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1985 | strcmp(token, "<") == 0 || |
| 1986 | strcmp(token, ">") == 0 || |
Namhyung Kim | ff58268 | 2013-01-15 17:02:19 +0900 | [diff] [blame] | 1987 | strcmp(token, "<=") == 0 || |
| 1988 | strcmp(token, ">=") == 0 || |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1989 | strcmp(token, "==") == 0 || |
| 1990 | strcmp(token, "!=") == 0) { |
| 1991 | |
| 1992 | left = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 1993 | if (!left) |
| 1994 | goto out_warn_free; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1995 | |
| 1996 | /* copy the top arg to the left */ |
| 1997 | *left = *arg; |
| 1998 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 1999 | arg->type = TEP_PRINT_OP; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2000 | arg->op.op = token; |
| 2001 | arg->op.left = left; |
Namhyung Kim | 41e51a2 | 2012-09-19 15:58:42 +0900 | [diff] [blame] | 2002 | arg->op.right = NULL; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2003 | |
Vaibhav Nagarnaik | 14ffde0 | 2012-04-06 00:48:01 +0200 | [diff] [blame] | 2004 | if (set_op_prio(arg) == -1) { |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 2005 | event->flags |= TEP_EVENT_FL_FAILED; |
Namhyung Kim | d1de108 | 2012-05-23 11:36:49 +0900 | [diff] [blame] | 2006 | /* arg->op.op (= token) will be freed at out_free */ |
| 2007 | arg->op.op = NULL; |
Vaibhav Nagarnaik | 14ffde0 | 2012-04-06 00:48:01 +0200 | [diff] [blame] | 2008 | goto out_free; |
| 2009 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2010 | |
| 2011 | type = read_token_item(&token); |
| 2012 | *tok = token; |
| 2013 | |
| 2014 | /* could just be a type pointer */ |
| 2015 | if ((strcmp(arg->op.op, "*") == 0) && |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2016 | type == TEP_EVENT_DELIM && (strcmp(token, ")") == 0)) { |
Namhyung Kim | d286447 | 2012-04-09 11:54:33 +0900 | [diff] [blame] | 2017 | char *new_atom; |
| 2018 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2019 | if (left->type != TEP_PRINT_ATOM) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 2020 | do_warning_event(event, "bad pointer type"); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 2021 | goto out_free; |
| 2022 | } |
Namhyung Kim | d286447 | 2012-04-09 11:54:33 +0900 | [diff] [blame] | 2023 | new_atom = realloc(left->atom.atom, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2024 | strlen(left->atom.atom) + 3); |
Namhyung Kim | d286447 | 2012-04-09 11:54:33 +0900 | [diff] [blame] | 2025 | if (!new_atom) |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2026 | goto out_warn_free; |
Namhyung Kim | d286447 | 2012-04-09 11:54:33 +0900 | [diff] [blame] | 2027 | |
| 2028 | left->atom.atom = new_atom; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2029 | strcat(left->atom.atom, " *"); |
| 2030 | free(arg->op.op); |
| 2031 | *arg = *left; |
| 2032 | free(left); |
| 2033 | |
| 2034 | return type; |
| 2035 | } |
| 2036 | |
| 2037 | right = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2038 | if (!right) |
| 2039 | goto out_warn_free; |
| 2040 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2041 | type = process_arg_token(event, right, tok, type); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2042 | if (type == TEP_EVENT_ERROR) { |
Dean Nelson | 6f56e9c | 2015-08-20 11:16:32 -0400 | [diff] [blame] | 2043 | free_arg(right); |
| 2044 | /* token was freed in process_arg_token() via *tok */ |
| 2045 | token = NULL; |
| 2046 | goto out_free; |
| 2047 | } |
Namhyung Kim | 3201f0d | 2015-04-06 14:36:16 +0900 | [diff] [blame] | 2048 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2049 | if (right->type == TEP_PRINT_OP && |
Namhyung Kim | 3201f0d | 2015-04-06 14:36:16 +0900 | [diff] [blame] | 2050 | get_op_prio(arg->op.op) < get_op_prio(right->op.op)) { |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 2051 | struct tep_print_arg tmp; |
Namhyung Kim | 3201f0d | 2015-04-06 14:36:16 +0900 | [diff] [blame] | 2052 | |
| 2053 | /* rotate ops according to the priority */ |
| 2054 | arg->op.right = right->op.left; |
| 2055 | |
| 2056 | tmp = *arg; |
| 2057 | *arg = *right; |
| 2058 | *right = tmp; |
| 2059 | |
| 2060 | arg->op.left = right; |
| 2061 | } else { |
| 2062 | arg->op.right = right; |
| 2063 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2064 | |
| 2065 | } else if (strcmp(token, "[") == 0) { |
| 2066 | |
| 2067 | left = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2068 | if (!left) |
| 2069 | goto out_warn_free; |
| 2070 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2071 | *left = *arg; |
| 2072 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2073 | arg->type = TEP_PRINT_OP; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2074 | arg->op.op = token; |
| 2075 | arg->op.left = left; |
| 2076 | |
| 2077 | arg->op.prio = 0; |
| 2078 | |
Namhyung Kim | 41e51a2 | 2012-09-19 15:58:42 +0900 | [diff] [blame] | 2079 | /* it will set arg->op.right */ |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2080 | type = process_array(event, arg, tok); |
| 2081 | |
| 2082 | } else { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 2083 | do_warning_event(event, "unknown op '%s'", token); |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 2084 | event->flags |= TEP_EVENT_FL_FAILED; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2085 | /* the arg is now the left side */ |
| 2086 | goto out_free; |
| 2087 | } |
| 2088 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2089 | if (type == TEP_EVENT_OP && strcmp(*tok, ":") != 0) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2090 | int prio; |
| 2091 | |
| 2092 | /* higher prios need to be closer to the root */ |
| 2093 | prio = get_op_prio(*tok); |
| 2094 | |
| 2095 | if (prio > arg->op.prio) |
| 2096 | return process_op(event, arg, tok); |
| 2097 | |
| 2098 | return process_op(event, right, tok); |
| 2099 | } |
| 2100 | |
| 2101 | return type; |
| 2102 | |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2103 | out_warn_free: |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 2104 | do_warning_event(event, "%s: not enough memory!", __func__); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2105 | out_free: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2106 | free_token(token); |
| 2107 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2108 | return TEP_EVENT_ERROR; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2109 | } |
| 2110 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2111 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2112 | process_entry(struct tep_event *event __maybe_unused, struct tep_print_arg *arg, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2113 | char **tok) |
| 2114 | { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2115 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2116 | char *field; |
| 2117 | char *token; |
| 2118 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2119 | if (read_expected(TEP_EVENT_OP, "->") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2120 | goto out_err; |
| 2121 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2122 | if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2123 | goto out_free; |
| 2124 | field = token; |
| 2125 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2126 | arg->type = TEP_PRINT_FIELD; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2127 | arg->field.name = field; |
| 2128 | |
Tom Zanussi | 5205aec | 2012-04-06 00:47:58 +0200 | [diff] [blame] | 2129 | if (is_flag_field) { |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 2130 | arg->field.field = tep_find_any_field(event, arg->field.name); |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 2131 | arg->field.field->flags |= TEP_FIELD_IS_FLAG; |
Tom Zanussi | 5205aec | 2012-04-06 00:47:58 +0200 | [diff] [blame] | 2132 | is_flag_field = 0; |
| 2133 | } else if (is_symbolic_field) { |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 2134 | arg->field.field = tep_find_any_field(event, arg->field.name); |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 2135 | arg->field.field->flags |= TEP_FIELD_IS_SYMBOLIC; |
Tom Zanussi | 5205aec | 2012-04-06 00:47:58 +0200 | [diff] [blame] | 2136 | is_symbolic_field = 0; |
| 2137 | } |
| 2138 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2139 | type = read_token(&token); |
| 2140 | *tok = token; |
| 2141 | |
| 2142 | return type; |
| 2143 | |
| 2144 | out_free: |
| 2145 | free_token(token); |
| 2146 | out_err: |
| 2147 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2148 | return TEP_EVENT_ERROR; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2149 | } |
| 2150 | |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2151 | static int alloc_and_process_delim(struct tep_event *event, char *next_token, |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 2152 | struct tep_print_arg **print_arg) |
Javi Merino | 929a6bb | 2015-03-20 18:12:55 +0000 | [diff] [blame] | 2153 | { |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 2154 | struct tep_print_arg *field; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2155 | enum tep_event_type type; |
Javi Merino | 929a6bb | 2015-03-20 18:12:55 +0000 | [diff] [blame] | 2156 | char *token; |
| 2157 | int ret = 0; |
| 2158 | |
| 2159 | field = alloc_arg(); |
| 2160 | if (!field) { |
| 2161 | do_warning_event(event, "%s: not enough memory!", __func__); |
| 2162 | errno = ENOMEM; |
| 2163 | return -1; |
| 2164 | } |
| 2165 | |
| 2166 | type = process_arg(event, field, &token); |
| 2167 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2168 | if (test_type_token(type, token, TEP_EVENT_DELIM, next_token)) { |
Javi Merino | 929a6bb | 2015-03-20 18:12:55 +0000 | [diff] [blame] | 2169 | errno = EINVAL; |
| 2170 | ret = -1; |
| 2171 | free_arg(field); |
| 2172 | goto out_free_token; |
| 2173 | } |
| 2174 | |
| 2175 | *print_arg = field; |
| 2176 | |
| 2177 | out_free_token: |
| 2178 | free_token(token); |
| 2179 | |
| 2180 | return ret; |
| 2181 | } |
| 2182 | |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 2183 | static char *arg_eval (struct tep_print_arg *arg); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2184 | |
| 2185 | static unsigned long long |
| 2186 | eval_type_str(unsigned long long val, const char *type, int pointer) |
| 2187 | { |
| 2188 | int sign = 0; |
| 2189 | char *ref; |
| 2190 | int len; |
| 2191 | |
| 2192 | len = strlen(type); |
| 2193 | |
| 2194 | if (pointer) { |
| 2195 | |
| 2196 | if (type[len-1] != '*') { |
| 2197 | do_warning("pointer expected with non pointer type"); |
| 2198 | return val; |
| 2199 | } |
| 2200 | |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 2201 | ref = malloc(len); |
| 2202 | if (!ref) { |
| 2203 | do_warning("%s: not enough memory!", __func__); |
| 2204 | return val; |
| 2205 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2206 | memcpy(ref, type, len); |
| 2207 | |
| 2208 | /* chop off the " *" */ |
| 2209 | ref[len - 2] = 0; |
| 2210 | |
| 2211 | val = eval_type_str(val, ref, 0); |
| 2212 | free(ref); |
| 2213 | return val; |
| 2214 | } |
| 2215 | |
| 2216 | /* check if this is a pointer */ |
| 2217 | if (type[len - 1] == '*') |
| 2218 | return val; |
| 2219 | |
| 2220 | /* Try to figure out the arg size*/ |
| 2221 | if (strncmp(type, "struct", 6) == 0) |
| 2222 | /* all bets off */ |
| 2223 | return val; |
| 2224 | |
| 2225 | if (strcmp(type, "u8") == 0) |
| 2226 | return val & 0xff; |
| 2227 | |
| 2228 | if (strcmp(type, "u16") == 0) |
| 2229 | return val & 0xffff; |
| 2230 | |
| 2231 | if (strcmp(type, "u32") == 0) |
| 2232 | return val & 0xffffffff; |
| 2233 | |
| 2234 | if (strcmp(type, "u64") == 0 || |
| 2235 | strcmp(type, "s64")) |
| 2236 | return val; |
| 2237 | |
| 2238 | if (strcmp(type, "s8") == 0) |
| 2239 | return (unsigned long long)(char)val & 0xff; |
| 2240 | |
| 2241 | if (strcmp(type, "s16") == 0) |
| 2242 | return (unsigned long long)(short)val & 0xffff; |
| 2243 | |
| 2244 | if (strcmp(type, "s32") == 0) |
| 2245 | return (unsigned long long)(int)val & 0xffffffff; |
| 2246 | |
| 2247 | if (strncmp(type, "unsigned ", 9) == 0) { |
| 2248 | sign = 0; |
| 2249 | type += 9; |
| 2250 | } |
| 2251 | |
| 2252 | if (strcmp(type, "char") == 0) { |
| 2253 | if (sign) |
| 2254 | return (unsigned long long)(char)val & 0xff; |
| 2255 | else |
| 2256 | return val & 0xff; |
| 2257 | } |
| 2258 | |
| 2259 | if (strcmp(type, "short") == 0) { |
| 2260 | if (sign) |
| 2261 | return (unsigned long long)(short)val & 0xffff; |
| 2262 | else |
| 2263 | return val & 0xffff; |
| 2264 | } |
| 2265 | |
| 2266 | if (strcmp(type, "int") == 0) { |
| 2267 | if (sign) |
| 2268 | return (unsigned long long)(int)val & 0xffffffff; |
| 2269 | else |
| 2270 | return val & 0xffffffff; |
| 2271 | } |
| 2272 | |
| 2273 | return val; |
| 2274 | } |
| 2275 | |
| 2276 | /* |
| 2277 | * Try to figure out the type. |
| 2278 | */ |
| 2279 | static unsigned long long |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 2280 | eval_type(unsigned long long val, struct tep_print_arg *arg, int pointer) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2281 | { |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2282 | if (arg->type != TEP_PRINT_TYPE) { |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 2283 | do_warning("expected type argument"); |
| 2284 | return 0; |
| 2285 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2286 | |
| 2287 | return eval_type_str(val, arg->typecast.type, pointer); |
| 2288 | } |
| 2289 | |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 2290 | static int arg_num_eval(struct tep_print_arg *arg, long long *val) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2291 | { |
| 2292 | long long left, right; |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2293 | int ret = 1; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2294 | |
| 2295 | switch (arg->type) { |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2296 | case TEP_PRINT_ATOM: |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2297 | *val = strtoll(arg->atom.atom, NULL, 0); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2298 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2299 | case TEP_PRINT_TYPE: |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2300 | ret = arg_num_eval(arg->typecast.item, val); |
| 2301 | if (!ret) |
| 2302 | break; |
| 2303 | *val = eval_type(*val, arg, 0); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2304 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2305 | case TEP_PRINT_OP: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2306 | switch (arg->op.op[0]) { |
| 2307 | case '|': |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2308 | ret = arg_num_eval(arg->op.left, &left); |
| 2309 | if (!ret) |
| 2310 | break; |
| 2311 | ret = arg_num_eval(arg->op.right, &right); |
| 2312 | if (!ret) |
| 2313 | break; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2314 | if (arg->op.op[1]) |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2315 | *val = left || right; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2316 | else |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2317 | *val = left | right; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2318 | break; |
| 2319 | case '&': |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2320 | ret = arg_num_eval(arg->op.left, &left); |
| 2321 | if (!ret) |
| 2322 | break; |
| 2323 | ret = arg_num_eval(arg->op.right, &right); |
| 2324 | if (!ret) |
| 2325 | break; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2326 | if (arg->op.op[1]) |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2327 | *val = left && right; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2328 | else |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2329 | *val = left & right; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2330 | break; |
| 2331 | case '<': |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2332 | ret = arg_num_eval(arg->op.left, &left); |
| 2333 | if (!ret) |
| 2334 | break; |
| 2335 | ret = arg_num_eval(arg->op.right, &right); |
| 2336 | if (!ret) |
| 2337 | break; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2338 | switch (arg->op.op[1]) { |
| 2339 | case 0: |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2340 | *val = left < right; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2341 | break; |
| 2342 | case '<': |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2343 | *val = left << right; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2344 | break; |
| 2345 | case '=': |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2346 | *val = left <= right; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2347 | break; |
| 2348 | default: |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2349 | do_warning("unknown op '%s'", arg->op.op); |
| 2350 | ret = 0; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2351 | } |
| 2352 | break; |
| 2353 | case '>': |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2354 | ret = arg_num_eval(arg->op.left, &left); |
| 2355 | if (!ret) |
| 2356 | break; |
| 2357 | ret = arg_num_eval(arg->op.right, &right); |
| 2358 | if (!ret) |
| 2359 | break; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2360 | switch (arg->op.op[1]) { |
| 2361 | case 0: |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2362 | *val = left > right; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2363 | break; |
| 2364 | case '>': |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2365 | *val = left >> right; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2366 | break; |
| 2367 | case '=': |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2368 | *val = left >= right; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2369 | break; |
| 2370 | default: |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2371 | do_warning("unknown op '%s'", arg->op.op); |
| 2372 | ret = 0; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2373 | } |
| 2374 | break; |
| 2375 | case '=': |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2376 | ret = arg_num_eval(arg->op.left, &left); |
| 2377 | if (!ret) |
| 2378 | break; |
| 2379 | ret = arg_num_eval(arg->op.right, &right); |
| 2380 | if (!ret) |
| 2381 | break; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2382 | |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2383 | if (arg->op.op[1] != '=') { |
| 2384 | do_warning("unknown op '%s'", arg->op.op); |
| 2385 | ret = 0; |
| 2386 | } else |
| 2387 | *val = left == right; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2388 | break; |
| 2389 | case '!': |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2390 | ret = arg_num_eval(arg->op.left, &left); |
| 2391 | if (!ret) |
| 2392 | break; |
| 2393 | ret = arg_num_eval(arg->op.right, &right); |
| 2394 | if (!ret) |
| 2395 | break; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2396 | |
| 2397 | switch (arg->op.op[1]) { |
| 2398 | case '=': |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2399 | *val = left != right; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2400 | break; |
| 2401 | default: |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2402 | do_warning("unknown op '%s'", arg->op.op); |
| 2403 | ret = 0; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2404 | } |
| 2405 | break; |
| 2406 | case '-': |
| 2407 | /* check for negative */ |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2408 | if (arg->op.left->type == TEP_PRINT_NULL) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2409 | left = 0; |
| 2410 | else |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2411 | ret = arg_num_eval(arg->op.left, &left); |
| 2412 | if (!ret) |
| 2413 | break; |
| 2414 | ret = arg_num_eval(arg->op.right, &right); |
| 2415 | if (!ret) |
| 2416 | break; |
| 2417 | *val = left - right; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2418 | break; |
Vaibhav Nagarnaik | b482859 | 2012-04-06 00:48:03 +0200 | [diff] [blame] | 2419 | case '+': |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2420 | if (arg->op.left->type == TEP_PRINT_NULL) |
Vaibhav Nagarnaik | b482859 | 2012-04-06 00:48:03 +0200 | [diff] [blame] | 2421 | left = 0; |
| 2422 | else |
| 2423 | ret = arg_num_eval(arg->op.left, &left); |
| 2424 | if (!ret) |
| 2425 | break; |
| 2426 | ret = arg_num_eval(arg->op.right, &right); |
| 2427 | if (!ret) |
| 2428 | break; |
| 2429 | *val = left + right; |
| 2430 | break; |
Steven Rostedt | 9eb42de | 2016-02-26 18:13:28 -0500 | [diff] [blame] | 2431 | case '~': |
| 2432 | ret = arg_num_eval(arg->op.right, &right); |
| 2433 | if (!ret) |
| 2434 | break; |
| 2435 | *val = ~right; |
| 2436 | break; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2437 | default: |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2438 | do_warning("unknown op '%s'", arg->op.op); |
| 2439 | ret = 0; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2440 | } |
| 2441 | break; |
| 2442 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2443 | case TEP_PRINT_NULL: |
| 2444 | case TEP_PRINT_FIELD ... TEP_PRINT_SYMBOL: |
| 2445 | case TEP_PRINT_STRING: |
| 2446 | case TEP_PRINT_BSTRING: |
| 2447 | case TEP_PRINT_BITMASK: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2448 | default: |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2449 | do_warning("invalid eval type %d", arg->type); |
| 2450 | ret = 0; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2451 | |
| 2452 | } |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2453 | return ret; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2454 | } |
| 2455 | |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 2456 | static char *arg_eval (struct tep_print_arg *arg) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2457 | { |
| 2458 | long long val; |
Tony Jones | 7c5b019 | 2019-02-27 17:55:32 -0800 | [diff] [blame] | 2459 | static char buf[24]; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2460 | |
| 2461 | switch (arg->type) { |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2462 | case TEP_PRINT_ATOM: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2463 | return arg->atom.atom; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2464 | case TEP_PRINT_TYPE: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2465 | return arg_eval(arg->typecast.item); |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2466 | case TEP_PRINT_OP: |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2467 | if (!arg_num_eval(arg, &val)) |
| 2468 | break; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2469 | sprintf(buf, "%lld", val); |
| 2470 | return buf; |
| 2471 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2472 | case TEP_PRINT_NULL: |
| 2473 | case TEP_PRINT_FIELD ... TEP_PRINT_SYMBOL: |
| 2474 | case TEP_PRINT_STRING: |
| 2475 | case TEP_PRINT_BSTRING: |
| 2476 | case TEP_PRINT_BITMASK: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2477 | default: |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 2478 | do_warning("invalid eval type %d", arg->type); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2479 | break; |
| 2480 | } |
| 2481 | |
| 2482 | return NULL; |
| 2483 | } |
| 2484 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2485 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2486 | process_fields(struct tep_event *event, struct tep_print_flag_sym **list, char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2487 | { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2488 | enum tep_event_type type; |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 2489 | struct tep_print_arg *arg = NULL; |
| 2490 | struct tep_print_flag_sym *field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2491 | char *token = *tok; |
| 2492 | char *value; |
| 2493 | |
| 2494 | do { |
| 2495 | free_token(token); |
| 2496 | type = read_token_item(&token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2497 | if (test_type_token(type, token, TEP_EVENT_OP, "{")) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2498 | break; |
| 2499 | |
| 2500 | arg = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2501 | if (!arg) |
| 2502 | goto out_free; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2503 | |
| 2504 | free_token(token); |
| 2505 | type = process_arg(event, arg, &token); |
Stefan Hajnoczi | 00b9da7 | 2012-05-23 11:36:42 +0900 | [diff] [blame] | 2506 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2507 | if (type == TEP_EVENT_OP) |
Stefan Hajnoczi | 00b9da7 | 2012-05-23 11:36:42 +0900 | [diff] [blame] | 2508 | type = process_op(event, arg, &token); |
| 2509 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2510 | if (type == TEP_EVENT_ERROR) |
Stefan Hajnoczi | 00b9da7 | 2012-05-23 11:36:42 +0900 | [diff] [blame] | 2511 | goto out_free; |
| 2512 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2513 | if (test_type_token(type, token, TEP_EVENT_DELIM, ",")) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2514 | goto out_free; |
| 2515 | |
Arnaldo Carvalho de Melo | 87162d8 | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 2516 | field = calloc(1, sizeof(*field)); |
| 2517 | if (!field) |
| 2518 | goto out_free; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2519 | |
| 2520 | value = arg_eval(arg); |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2521 | if (value == NULL) |
Namhyung Kim | f8c49d2 | 2012-09-19 15:58:43 +0900 | [diff] [blame] | 2522 | goto out_free_field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2523 | field->value = strdup(value); |
Namhyung Kim | ca63858 | 2012-04-09 11:54:31 +0900 | [diff] [blame] | 2524 | if (field->value == NULL) |
Namhyung Kim | f8c49d2 | 2012-09-19 15:58:43 +0900 | [diff] [blame] | 2525 | goto out_free_field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2526 | |
| 2527 | free_arg(arg); |
| 2528 | arg = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2529 | if (!arg) |
| 2530 | goto out_free; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2531 | |
| 2532 | free_token(token); |
| 2533 | type = process_arg(event, arg, &token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2534 | if (test_type_token(type, token, TEP_EVENT_OP, "}")) |
Namhyung Kim | f8c49d2 | 2012-09-19 15:58:43 +0900 | [diff] [blame] | 2535 | goto out_free_field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2536 | |
| 2537 | value = arg_eval(arg); |
Vaibhav Nagarnaik | d69afed5 | 2012-04-06 00:48:00 +0200 | [diff] [blame] | 2538 | if (value == NULL) |
Namhyung Kim | f8c49d2 | 2012-09-19 15:58:43 +0900 | [diff] [blame] | 2539 | goto out_free_field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2540 | field->str = strdup(value); |
Namhyung Kim | ca63858 | 2012-04-09 11:54:31 +0900 | [diff] [blame] | 2541 | if (field->str == NULL) |
Namhyung Kim | f8c49d2 | 2012-09-19 15:58:43 +0900 | [diff] [blame] | 2542 | goto out_free_field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2543 | free_arg(arg); |
| 2544 | arg = NULL; |
| 2545 | |
| 2546 | *list = field; |
| 2547 | list = &field->next; |
| 2548 | |
| 2549 | free_token(token); |
| 2550 | type = read_token_item(&token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2551 | } while (type == TEP_EVENT_DELIM && strcmp(token, ",") == 0); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2552 | |
| 2553 | *tok = token; |
| 2554 | return type; |
| 2555 | |
Namhyung Kim | f8c49d2 | 2012-09-19 15:58:43 +0900 | [diff] [blame] | 2556 | out_free_field: |
| 2557 | free_flag_sym(field); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2558 | out_free: |
| 2559 | free_arg(arg); |
| 2560 | free_token(token); |
| 2561 | *tok = NULL; |
| 2562 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2563 | return TEP_EVENT_ERROR; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2564 | } |
| 2565 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2566 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2567 | process_flags(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2568 | { |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 2569 | struct tep_print_arg *field; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2570 | enum tep_event_type type; |
Rickard Strandqvist | 21da83f | 2014-06-24 13:09:10 +0200 | [diff] [blame] | 2571 | char *token = NULL; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2572 | |
| 2573 | memset(arg, 0, sizeof(*arg)); |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2574 | arg->type = TEP_PRINT_FLAGS; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2575 | |
| 2576 | field = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2577 | if (!field) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 2578 | do_warning_event(event, "%s: not enough memory!", __func__); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2579 | goto out_free; |
| 2580 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2581 | |
Steven Rostedt | eff2c92 | 2013-11-18 14:23:14 -0500 | [diff] [blame] | 2582 | type = process_field_arg(event, field, &token); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2583 | |
| 2584 | /* Handle operations in the first argument */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2585 | while (type == TEP_EVENT_OP) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2586 | type = process_op(event, field, &token); |
| 2587 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2588 | if (test_type_token(type, token, TEP_EVENT_DELIM, ",")) |
Namhyung Kim | 70d9304 | 2012-09-19 15:58:44 +0900 | [diff] [blame] | 2589 | goto out_free_field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2590 | free_token(token); |
| 2591 | |
| 2592 | arg->flags.field = field; |
| 2593 | |
| 2594 | type = read_token_item(&token); |
| 2595 | if (event_item_type(type)) { |
| 2596 | arg->flags.delim = token; |
| 2597 | type = read_token_item(&token); |
| 2598 | } |
| 2599 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2600 | if (test_type_token(type, token, TEP_EVENT_DELIM, ",")) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2601 | goto out_free; |
| 2602 | |
| 2603 | type = process_fields(event, &arg->flags.flags, &token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2604 | if (test_type_token(type, token, TEP_EVENT_DELIM, ")")) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2605 | goto out_free; |
| 2606 | |
| 2607 | free_token(token); |
| 2608 | type = read_token_item(tok); |
| 2609 | return type; |
| 2610 | |
Namhyung Kim | 70d9304 | 2012-09-19 15:58:44 +0900 | [diff] [blame] | 2611 | out_free_field: |
| 2612 | free_arg(field); |
| 2613 | out_free: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2614 | free_token(token); |
| 2615 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2616 | return TEP_EVENT_ERROR; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2617 | } |
| 2618 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2619 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2620 | process_symbols(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2621 | { |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 2622 | struct tep_print_arg *field; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2623 | enum tep_event_type type; |
Rickard Strandqvist | 21da83f | 2014-06-24 13:09:10 +0200 | [diff] [blame] | 2624 | char *token = NULL; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2625 | |
| 2626 | memset(arg, 0, sizeof(*arg)); |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2627 | arg->type = TEP_PRINT_SYMBOL; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2628 | |
| 2629 | field = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2630 | if (!field) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 2631 | do_warning_event(event, "%s: not enough memory!", __func__); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2632 | goto out_free; |
| 2633 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2634 | |
Steven Rostedt | eff2c92 | 2013-11-18 14:23:14 -0500 | [diff] [blame] | 2635 | type = process_field_arg(event, field, &token); |
| 2636 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2637 | if (test_type_token(type, token, TEP_EVENT_DELIM, ",")) |
Namhyung Kim | 70d9304 | 2012-09-19 15:58:44 +0900 | [diff] [blame] | 2638 | goto out_free_field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2639 | |
| 2640 | arg->symbol.field = field; |
| 2641 | |
| 2642 | type = process_fields(event, &arg->symbol.symbols, &token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2643 | if (test_type_token(type, token, TEP_EVENT_DELIM, ")")) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2644 | goto out_free; |
| 2645 | |
| 2646 | free_token(token); |
| 2647 | type = read_token_item(tok); |
| 2648 | return type; |
| 2649 | |
Namhyung Kim | 70d9304 | 2012-09-19 15:58:44 +0900 | [diff] [blame] | 2650 | out_free_field: |
| 2651 | free_arg(field); |
| 2652 | out_free: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2653 | free_token(token); |
| 2654 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2655 | return TEP_EVENT_ERROR; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2656 | } |
| 2657 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2658 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2659 | process_hex_common(struct tep_event *event, struct tep_print_arg *arg, |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2660 | char **tok, enum tep_print_arg_type type) |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2661 | { |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2662 | memset(arg, 0, sizeof(*arg)); |
Daniel Borkmann | 0fe0559 | 2017-01-25 02:28:17 +0100 | [diff] [blame] | 2663 | arg->type = type; |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2664 | |
Javi Merino | 929a6bb | 2015-03-20 18:12:55 +0000 | [diff] [blame] | 2665 | if (alloc_and_process_delim(event, ",", &arg->hex.field)) |
| 2666 | goto out; |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2667 | |
Javi Merino | 929a6bb | 2015-03-20 18:12:55 +0000 | [diff] [blame] | 2668 | if (alloc_and_process_delim(event, ")", &arg->hex.size)) |
| 2669 | goto free_field; |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2670 | |
Javi Merino | 929a6bb | 2015-03-20 18:12:55 +0000 | [diff] [blame] | 2671 | return read_token_item(tok); |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2672 | |
Javi Merino | 929a6bb | 2015-03-20 18:12:55 +0000 | [diff] [blame] | 2673 | free_field: |
| 2674 | free_arg(arg->hex.field); |
Steven Rostedt (Red Hat) | 9ec72ea | 2016-02-09 15:40:16 -0500 | [diff] [blame] | 2675 | arg->hex.field = NULL; |
Javi Merino | 929a6bb | 2015-03-20 18:12:55 +0000 | [diff] [blame] | 2676 | out: |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2677 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2678 | return TEP_EVENT_ERROR; |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2679 | } |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2680 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2681 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2682 | process_hex(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
Daniel Borkmann | 0fe0559 | 2017-01-25 02:28:17 +0100 | [diff] [blame] | 2683 | { |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2684 | return process_hex_common(event, arg, tok, TEP_PRINT_HEX); |
Daniel Borkmann | 0fe0559 | 2017-01-25 02:28:17 +0100 | [diff] [blame] | 2685 | } |
| 2686 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2687 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2688 | process_hex_str(struct tep_event *event, struct tep_print_arg *arg, |
Daniel Borkmann | 0fe0559 | 2017-01-25 02:28:17 +0100 | [diff] [blame] | 2689 | char **tok) |
| 2690 | { |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2691 | return process_hex_common(event, arg, tok, TEP_PRINT_HEX_STR); |
Daniel Borkmann | 0fe0559 | 2017-01-25 02:28:17 +0100 | [diff] [blame] | 2692 | } |
| 2693 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2694 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2695 | process_int_array(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 2696 | { |
| 2697 | memset(arg, 0, sizeof(*arg)); |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2698 | arg->type = TEP_PRINT_INT_ARRAY; |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2699 | |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 2700 | if (alloc_and_process_delim(event, ",", &arg->int_array.field)) |
| 2701 | goto out; |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2702 | |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 2703 | if (alloc_and_process_delim(event, ",", &arg->int_array.count)) |
| 2704 | goto free_field; |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2705 | |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 2706 | if (alloc_and_process_delim(event, ")", &arg->int_array.el_size)) |
| 2707 | goto free_size; |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2708 | |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 2709 | return read_token_item(tok); |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2710 | |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 2711 | free_size: |
| 2712 | free_arg(arg->int_array.count); |
Steven Rostedt (Red Hat) | 9ec72ea | 2016-02-09 15:40:16 -0500 | [diff] [blame] | 2713 | arg->int_array.count = NULL; |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 2714 | free_field: |
| 2715 | free_arg(arg->int_array.field); |
Steven Rostedt (Red Hat) | 9ec72ea | 2016-02-09 15:40:16 -0500 | [diff] [blame] | 2716 | arg->int_array.field = NULL; |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 2717 | out: |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2718 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2719 | return TEP_EVENT_ERROR; |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 2720 | } |
| 2721 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2722 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2723 | process_dynamic_array(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2724 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 2725 | struct tep_format_field *field; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2726 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2727 | char *token; |
| 2728 | |
| 2729 | memset(arg, 0, sizeof(*arg)); |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2730 | arg->type = TEP_PRINT_DYNAMIC_ARRAY; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2731 | |
| 2732 | /* |
| 2733 | * The item within the parenthesis is another field that holds |
| 2734 | * the index into where the array starts. |
| 2735 | */ |
| 2736 | type = read_token(&token); |
| 2737 | *tok = token; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2738 | if (type != TEP_EVENT_ITEM) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2739 | goto out_free; |
| 2740 | |
| 2741 | /* Find the field */ |
| 2742 | |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 2743 | field = tep_find_field(event, token); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2744 | if (!field) |
| 2745 | goto out_free; |
| 2746 | |
| 2747 | arg->dynarray.field = field; |
| 2748 | arg->dynarray.index = 0; |
| 2749 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2750 | if (read_expected(TEP_EVENT_DELIM, ")") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2751 | goto out_free; |
| 2752 | |
| 2753 | free_token(token); |
| 2754 | type = read_token_item(&token); |
| 2755 | *tok = token; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2756 | if (type != TEP_EVENT_OP || strcmp(token, "[") != 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2757 | return type; |
| 2758 | |
| 2759 | free_token(token); |
| 2760 | arg = alloc_arg(); |
Sasha Levin | fba7a78 | 2012-12-21 15:00:58 -0500 | [diff] [blame] | 2761 | if (!arg) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 2762 | do_warning_event(event, "%s: not enough memory!", __func__); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2763 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2764 | return TEP_EVENT_ERROR; |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2765 | } |
| 2766 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2767 | type = process_arg(event, arg, &token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2768 | if (type == TEP_EVENT_ERROR) |
Namhyung Kim | b3511d0 | 2012-05-23 11:36:50 +0900 | [diff] [blame] | 2769 | goto out_free_arg; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2770 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2771 | if (!test_type_token(type, token, TEP_EVENT_OP, "]")) |
Namhyung Kim | b3511d0 | 2012-05-23 11:36:50 +0900 | [diff] [blame] | 2772 | goto out_free_arg; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2773 | |
| 2774 | free_token(token); |
| 2775 | type = read_token_item(tok); |
| 2776 | return type; |
| 2777 | |
Namhyung Kim | b3511d0 | 2012-05-23 11:36:50 +0900 | [diff] [blame] | 2778 | out_free_arg: |
| 2779 | free_arg(arg); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2780 | out_free: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2781 | free_token(token); |
| 2782 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2783 | return TEP_EVENT_ERROR; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2784 | } |
| 2785 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2786 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2787 | process_dynamic_array_len(struct tep_event *event, struct tep_print_arg *arg, |
He Kuang | 7605594 | 2015-08-29 04:22:05 +0000 | [diff] [blame] | 2788 | char **tok) |
| 2789 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 2790 | struct tep_format_field *field; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2791 | enum tep_event_type type; |
He Kuang | 7605594 | 2015-08-29 04:22:05 +0000 | [diff] [blame] | 2792 | char *token; |
| 2793 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2794 | if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
He Kuang | 7605594 | 2015-08-29 04:22:05 +0000 | [diff] [blame] | 2795 | goto out_free; |
| 2796 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2797 | arg->type = TEP_PRINT_DYNAMIC_ARRAY_LEN; |
He Kuang | 7605594 | 2015-08-29 04:22:05 +0000 | [diff] [blame] | 2798 | |
| 2799 | /* Find the field */ |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 2800 | field = tep_find_field(event, token); |
He Kuang | 7605594 | 2015-08-29 04:22:05 +0000 | [diff] [blame] | 2801 | if (!field) |
| 2802 | goto out_free; |
| 2803 | |
| 2804 | arg->dynarray.field = field; |
| 2805 | arg->dynarray.index = 0; |
| 2806 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2807 | if (read_expected(TEP_EVENT_DELIM, ")") < 0) |
He Kuang | 7605594 | 2015-08-29 04:22:05 +0000 | [diff] [blame] | 2808 | goto out_err; |
| 2809 | |
| 2810 | type = read_token(&token); |
| 2811 | *tok = token; |
| 2812 | |
| 2813 | return type; |
| 2814 | |
| 2815 | out_free: |
| 2816 | free_token(token); |
| 2817 | out_err: |
| 2818 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2819 | return TEP_EVENT_ERROR; |
He Kuang | 7605594 | 2015-08-29 04:22:05 +0000 | [diff] [blame] | 2820 | } |
| 2821 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2822 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2823 | process_paren(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2824 | { |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 2825 | struct tep_print_arg *item_arg; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2826 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2827 | char *token; |
| 2828 | |
| 2829 | type = process_arg(event, arg, &token); |
| 2830 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2831 | if (type == TEP_EVENT_ERROR) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2832 | goto out_free; |
| 2833 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2834 | if (type == TEP_EVENT_OP) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2835 | type = process_op(event, arg, &token); |
| 2836 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2837 | if (type == TEP_EVENT_ERROR) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2838 | goto out_free; |
| 2839 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2840 | if (test_type_token(type, token, TEP_EVENT_DELIM, ")")) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2841 | goto out_free; |
| 2842 | |
| 2843 | free_token(token); |
| 2844 | type = read_token_item(&token); |
| 2845 | |
| 2846 | /* |
| 2847 | * If the next token is an item or another open paren, then |
| 2848 | * this was a typecast. |
| 2849 | */ |
| 2850 | if (event_item_type(type) || |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2851 | (type == TEP_EVENT_DELIM && strcmp(token, "(") == 0)) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2852 | |
| 2853 | /* make this a typecast and contine */ |
| 2854 | |
| 2855 | /* prevous must be an atom */ |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2856 | if (arg->type != TEP_PRINT_ATOM) { |
| 2857 | do_warning_event(event, "previous needed to be TEP_PRINT_ATOM"); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 2858 | goto out_free; |
| 2859 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2860 | |
| 2861 | item_arg = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2862 | if (!item_arg) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 2863 | do_warning_event(event, "%s: not enough memory!", |
| 2864 | __func__); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2865 | goto out_free; |
| 2866 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2867 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2868 | arg->type = TEP_PRINT_TYPE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2869 | arg->typecast.type = arg->atom.atom; |
| 2870 | arg->typecast.item = item_arg; |
| 2871 | type = process_arg_token(event, item_arg, &token, type); |
| 2872 | |
| 2873 | } |
| 2874 | |
| 2875 | *tok = token; |
| 2876 | return type; |
| 2877 | |
| 2878 | out_free: |
| 2879 | free_token(token); |
| 2880 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2881 | return TEP_EVENT_ERROR; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2882 | } |
| 2883 | |
| 2884 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2885 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2886 | process_str(struct tep_event *event __maybe_unused, struct tep_print_arg *arg, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 2887 | char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2888 | { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2889 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2890 | char *token; |
| 2891 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2892 | if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2893 | goto out_free; |
| 2894 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2895 | arg->type = TEP_PRINT_STRING; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2896 | arg->string.string = token; |
| 2897 | arg->string.offset = -1; |
| 2898 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2899 | if (read_expected(TEP_EVENT_DELIM, ")") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2900 | goto out_err; |
| 2901 | |
| 2902 | type = read_token(&token); |
| 2903 | *tok = token; |
| 2904 | |
| 2905 | return type; |
| 2906 | |
| 2907 | out_free: |
| 2908 | free_token(token); |
| 2909 | out_err: |
| 2910 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2911 | return TEP_EVENT_ERROR; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2912 | } |
| 2913 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2914 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2915 | process_bitmask(struct tep_event *event __maybe_unused, struct tep_print_arg *arg, |
Tzvetomir Stoyanov (VMware) | 4963b0f | 2018-09-19 14:56:44 -0400 | [diff] [blame] | 2916 | char **tok) |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 2917 | { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2918 | enum tep_event_type type; |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 2919 | char *token; |
| 2920 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2921 | if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 2922 | goto out_free; |
| 2923 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2924 | arg->type = TEP_PRINT_BITMASK; |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 2925 | arg->bitmask.bitmask = token; |
| 2926 | arg->bitmask.offset = -1; |
| 2927 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2928 | if (read_expected(TEP_EVENT_DELIM, ")") < 0) |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 2929 | goto out_err; |
| 2930 | |
| 2931 | type = read_token(&token); |
| 2932 | *tok = token; |
| 2933 | |
| 2934 | return type; |
| 2935 | |
| 2936 | out_free: |
| 2937 | free_token(token); |
| 2938 | out_err: |
| 2939 | *tok = NULL; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2940 | return TEP_EVENT_ERROR; |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 2941 | } |
| 2942 | |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 2943 | static struct tep_function_handler * |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 2944 | find_func_handler(struct tep_handle *pevent, char *func_name) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2945 | { |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 2946 | struct tep_function_handler *func; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2947 | |
Steven Rostedt | 101782e | 2012-10-01 20:13:51 -0400 | [diff] [blame] | 2948 | if (!pevent) |
| 2949 | return NULL; |
| 2950 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2951 | for (func = pevent->func_handlers; func; func = func->next) { |
| 2952 | if (strcmp(func->name, func_name) == 0) |
| 2953 | break; |
| 2954 | } |
| 2955 | |
| 2956 | return func; |
| 2957 | } |
| 2958 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 2959 | static void remove_func_handler(struct tep_handle *pevent, char *func_name) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2960 | { |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 2961 | struct tep_function_handler *func; |
| 2962 | struct tep_function_handler **next; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2963 | |
| 2964 | next = &pevent->func_handlers; |
| 2965 | while ((func = *next)) { |
| 2966 | if (strcmp(func->name, func_name) == 0) { |
| 2967 | *next = func->next; |
| 2968 | free_func_handle(func); |
| 2969 | break; |
| 2970 | } |
| 2971 | next = &func->next; |
| 2972 | } |
| 2973 | } |
| 2974 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2975 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 2976 | process_func_handler(struct tep_event *event, struct tep_function_handler *func, |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 2977 | struct tep_print_arg *arg, char **tok) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2978 | { |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 2979 | struct tep_print_arg **next_arg; |
| 2980 | struct tep_print_arg *farg; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2981 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2982 | char *token; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2983 | int i; |
| 2984 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 2985 | arg->type = TEP_PRINT_FUNC; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2986 | arg->func.func = func; |
| 2987 | |
| 2988 | *tok = NULL; |
| 2989 | |
| 2990 | next_arg = &(arg->func.args); |
| 2991 | for (i = 0; i < func->nr_args; i++) { |
| 2992 | farg = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2993 | if (!farg) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 2994 | do_warning_event(event, "%s: not enough memory!", |
| 2995 | __func__); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 2996 | return TEP_EVENT_ERROR; |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 2997 | } |
| 2998 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2999 | type = process_arg(event, farg, &token); |
Steven Rostedt | 3a3ffa2 | 2013-11-18 21:38:20 -0500 | [diff] [blame] | 3000 | if (i < (func->nr_args - 1)) { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3001 | if (type != TEP_EVENT_DELIM || strcmp(token, ",") != 0) { |
Namhyung Kim | 9e9e5df | 2014-03-19 10:22:54 +0900 | [diff] [blame] | 3002 | do_warning_event(event, |
| 3003 | "Error: function '%s()' expects %d arguments but event %s only uses %d", |
Steven Rostedt | 3a3ffa2 | 2013-11-18 21:38:20 -0500 | [diff] [blame] | 3004 | func->name, func->nr_args, |
| 3005 | event->name, i + 1); |
| 3006 | goto err; |
| 3007 | } |
| 3008 | } else { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3009 | if (type != TEP_EVENT_DELIM || strcmp(token, ")") != 0) { |
Namhyung Kim | 9e9e5df | 2014-03-19 10:22:54 +0900 | [diff] [blame] | 3010 | do_warning_event(event, |
| 3011 | "Error: function '%s()' only expects %d arguments but event %s has more", |
Steven Rostedt | 3a3ffa2 | 2013-11-18 21:38:20 -0500 | [diff] [blame] | 3012 | func->name, func->nr_args, event->name); |
| 3013 | goto err; |
| 3014 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3015 | } |
| 3016 | |
| 3017 | *next_arg = farg; |
| 3018 | next_arg = &(farg->next); |
| 3019 | free_token(token); |
| 3020 | } |
| 3021 | |
| 3022 | type = read_token(&token); |
| 3023 | *tok = token; |
| 3024 | |
| 3025 | return type; |
Steven Rostedt | 3a3ffa2 | 2013-11-18 21:38:20 -0500 | [diff] [blame] | 3026 | |
| 3027 | err: |
| 3028 | free_arg(farg); |
| 3029 | free_token(token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3030 | return TEP_EVENT_ERROR; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3031 | } |
| 3032 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3033 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 3034 | process_function(struct tep_event *event, struct tep_print_arg *arg, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3035 | char *token, char **tok) |
| 3036 | { |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 3037 | struct tep_function_handler *func; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3038 | |
| 3039 | if (strcmp(token, "__print_flags") == 0) { |
| 3040 | free_token(token); |
Tom Zanussi | 5205aec | 2012-04-06 00:47:58 +0200 | [diff] [blame] | 3041 | is_flag_field = 1; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3042 | return process_flags(event, arg, tok); |
| 3043 | } |
| 3044 | if (strcmp(token, "__print_symbolic") == 0) { |
| 3045 | free_token(token); |
Tom Zanussi | 5205aec | 2012-04-06 00:47:58 +0200 | [diff] [blame] | 3046 | is_symbolic_field = 1; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3047 | return process_symbols(event, arg, tok); |
| 3048 | } |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 3049 | if (strcmp(token, "__print_hex") == 0) { |
| 3050 | free_token(token); |
| 3051 | return process_hex(event, arg, tok); |
| 3052 | } |
Daniel Borkmann | 0fe0559 | 2017-01-25 02:28:17 +0100 | [diff] [blame] | 3053 | if (strcmp(token, "__print_hex_str") == 0) { |
| 3054 | free_token(token); |
| 3055 | return process_hex_str(event, arg, tok); |
| 3056 | } |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 3057 | if (strcmp(token, "__print_array") == 0) { |
| 3058 | free_token(token); |
| 3059 | return process_int_array(event, arg, tok); |
| 3060 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3061 | if (strcmp(token, "__get_str") == 0) { |
| 3062 | free_token(token); |
| 3063 | return process_str(event, arg, tok); |
| 3064 | } |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 3065 | if (strcmp(token, "__get_bitmask") == 0) { |
| 3066 | free_token(token); |
| 3067 | return process_bitmask(event, arg, tok); |
| 3068 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3069 | if (strcmp(token, "__get_dynamic_array") == 0) { |
| 3070 | free_token(token); |
| 3071 | return process_dynamic_array(event, arg, tok); |
| 3072 | } |
He Kuang | 7605594 | 2015-08-29 04:22:05 +0000 | [diff] [blame] | 3073 | if (strcmp(token, "__get_dynamic_array_len") == 0) { |
| 3074 | free_token(token); |
| 3075 | return process_dynamic_array_len(event, arg, tok); |
| 3076 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3077 | |
| 3078 | func = find_func_handler(event->pevent, token); |
| 3079 | if (func) { |
| 3080 | free_token(token); |
| 3081 | return process_func_handler(event, func, arg, tok); |
| 3082 | } |
| 3083 | |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 3084 | do_warning_event(event, "function %s not defined", token); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3085 | free_token(token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3086 | return TEP_EVENT_ERROR; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3087 | } |
| 3088 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3089 | static enum tep_event_type |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 3090 | process_arg_token(struct tep_event *event, struct tep_print_arg *arg, |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3091 | char **tok, enum tep_event_type type) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3092 | { |
| 3093 | char *token; |
| 3094 | char *atom; |
| 3095 | |
| 3096 | token = *tok; |
| 3097 | |
| 3098 | switch (type) { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3099 | case TEP_EVENT_ITEM: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3100 | if (strcmp(token, "REC") == 0) { |
| 3101 | free_token(token); |
| 3102 | type = process_entry(event, arg, &token); |
| 3103 | break; |
| 3104 | } |
| 3105 | atom = token; |
| 3106 | /* test the next token */ |
| 3107 | type = read_token_item(&token); |
| 3108 | |
| 3109 | /* |
| 3110 | * If the next token is a parenthesis, then this |
| 3111 | * is a function. |
| 3112 | */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3113 | if (type == TEP_EVENT_DELIM && strcmp(token, "(") == 0) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3114 | free_token(token); |
| 3115 | token = NULL; |
| 3116 | /* this will free atom. */ |
| 3117 | type = process_function(event, arg, atom, &token); |
| 3118 | break; |
| 3119 | } |
| 3120 | /* atoms can be more than one token long */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3121 | while (type == TEP_EVENT_ITEM) { |
Namhyung Kim | d286447 | 2012-04-09 11:54:33 +0900 | [diff] [blame] | 3122 | char *new_atom; |
| 3123 | new_atom = realloc(atom, |
| 3124 | strlen(atom) + strlen(token) + 2); |
| 3125 | if (!new_atom) { |
| 3126 | free(atom); |
| 3127 | *tok = NULL; |
| 3128 | free_token(token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3129 | return TEP_EVENT_ERROR; |
Namhyung Kim | d286447 | 2012-04-09 11:54:33 +0900 | [diff] [blame] | 3130 | } |
| 3131 | atom = new_atom; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3132 | strcat(atom, " "); |
| 3133 | strcat(atom, token); |
| 3134 | free_token(token); |
| 3135 | type = read_token_item(&token); |
| 3136 | } |
| 3137 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3138 | arg->type = TEP_PRINT_ATOM; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3139 | arg->atom.atom = atom; |
| 3140 | break; |
| 3141 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3142 | case TEP_EVENT_DQUOTE: |
| 3143 | case TEP_EVENT_SQUOTE: |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3144 | arg->type = TEP_PRINT_ATOM; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3145 | arg->atom.atom = token; |
| 3146 | type = read_token_item(&token); |
| 3147 | break; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3148 | case TEP_EVENT_DELIM: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3149 | if (strcmp(token, "(") == 0) { |
| 3150 | free_token(token); |
| 3151 | type = process_paren(event, arg, &token); |
| 3152 | break; |
| 3153 | } |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3154 | case TEP_EVENT_OP: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3155 | /* handle single ops */ |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3156 | arg->type = TEP_PRINT_OP; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3157 | arg->op.op = token; |
| 3158 | arg->op.left = NULL; |
| 3159 | type = process_op(event, arg, &token); |
| 3160 | |
| 3161 | /* On error, the op is freed */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3162 | if (type == TEP_EVENT_ERROR) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3163 | arg->op.op = NULL; |
| 3164 | |
| 3165 | /* return error type if errored */ |
| 3166 | break; |
| 3167 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3168 | case TEP_EVENT_ERROR ... TEP_EVENT_NEWLINE: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3169 | default: |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 3170 | do_warning_event(event, "unexpected type %d", type); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3171 | return TEP_EVENT_ERROR; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3172 | } |
| 3173 | *tok = token; |
| 3174 | |
| 3175 | return type; |
| 3176 | } |
| 3177 | |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 3178 | static int event_read_print_args(struct tep_event *event, struct tep_print_arg **list) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3179 | { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3180 | enum tep_event_type type = TEP_EVENT_ERROR; |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 3181 | struct tep_print_arg *arg; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3182 | char *token; |
| 3183 | int args = 0; |
| 3184 | |
| 3185 | do { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3186 | if (type == TEP_EVENT_NEWLINE) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3187 | type = read_token_item(&token); |
| 3188 | continue; |
| 3189 | } |
| 3190 | |
| 3191 | arg = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 3192 | if (!arg) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 3193 | do_warning_event(event, "%s: not enough memory!", |
| 3194 | __func__); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 3195 | return -1; |
| 3196 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3197 | |
| 3198 | type = process_arg(event, arg, &token); |
| 3199 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3200 | if (type == TEP_EVENT_ERROR) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3201 | free_token(token); |
| 3202 | free_arg(arg); |
| 3203 | return -1; |
| 3204 | } |
| 3205 | |
| 3206 | *list = arg; |
| 3207 | args++; |
| 3208 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3209 | if (type == TEP_EVENT_OP) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3210 | type = process_op(event, arg, &token); |
| 3211 | free_token(token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3212 | if (type == TEP_EVENT_ERROR) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3213 | *list = NULL; |
| 3214 | free_arg(arg); |
| 3215 | return -1; |
| 3216 | } |
| 3217 | list = &arg->next; |
| 3218 | continue; |
| 3219 | } |
| 3220 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3221 | if (type == TEP_EVENT_DELIM && strcmp(token, ",") == 0) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3222 | free_token(token); |
| 3223 | *list = arg; |
| 3224 | list = &arg->next; |
| 3225 | continue; |
| 3226 | } |
| 3227 | break; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3228 | } while (type != TEP_EVENT_NONE); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3229 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3230 | if (type != TEP_EVENT_NONE && type != TEP_EVENT_ERROR) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3231 | free_token(token); |
| 3232 | |
| 3233 | return args; |
| 3234 | } |
| 3235 | |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 3236 | static int event_read_print(struct tep_event *event) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3237 | { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3238 | enum tep_event_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3239 | char *token; |
| 3240 | int ret; |
| 3241 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3242 | if (read_expected_item(TEP_EVENT_ITEM, "print") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3243 | return -1; |
| 3244 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3245 | if (read_expected(TEP_EVENT_ITEM, "fmt") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3246 | return -1; |
| 3247 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3248 | if (read_expected(TEP_EVENT_OP, ":") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3249 | return -1; |
| 3250 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3251 | if (read_expect_type(TEP_EVENT_DQUOTE, &token) < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3252 | goto fail; |
| 3253 | |
| 3254 | concat: |
| 3255 | event->print_fmt.format = token; |
| 3256 | event->print_fmt.args = NULL; |
| 3257 | |
| 3258 | /* ok to have no arg */ |
| 3259 | type = read_token_item(&token); |
| 3260 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3261 | if (type == TEP_EVENT_NONE) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3262 | return 0; |
| 3263 | |
| 3264 | /* Handle concatenation of print lines */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3265 | if (type == TEP_EVENT_DQUOTE) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3266 | char *cat; |
| 3267 | |
Arnaldo Carvalho de Melo | 0dbca1e | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 3268 | if (asprintf(&cat, "%s%s", event->print_fmt.format, token) < 0) |
| 3269 | goto fail; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3270 | free_token(token); |
| 3271 | free_token(event->print_fmt.format); |
| 3272 | event->print_fmt.format = NULL; |
| 3273 | token = cat; |
| 3274 | goto concat; |
| 3275 | } |
| 3276 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 3277 | if (test_type_token(type, token, TEP_EVENT_DELIM, ",")) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3278 | goto fail; |
| 3279 | |
| 3280 | free_token(token); |
| 3281 | |
| 3282 | ret = event_read_print_args(event, &event->print_fmt.args); |
| 3283 | if (ret < 0) |
| 3284 | return -1; |
| 3285 | |
| 3286 | return ret; |
| 3287 | |
| 3288 | fail: |
| 3289 | free_token(token); |
| 3290 | return -1; |
| 3291 | } |
| 3292 | |
| 3293 | /** |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 3294 | * tep_find_common_field - return a common field by event |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3295 | * @event: handle for the event |
| 3296 | * @name: the name of the common field to return |
| 3297 | * |
| 3298 | * Returns a common field from the event by the given @name. |
Ingo Molnar | 3e449f7 | 2018-12-03 11:22:00 +0100 | [diff] [blame] | 3299 | * This only searches the common fields and not all field. |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3300 | */ |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 3301 | struct tep_format_field * |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 3302 | tep_find_common_field(struct tep_event *event, const char *name) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3303 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 3304 | struct tep_format_field *format; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3305 | |
| 3306 | for (format = event->format.common_fields; |
| 3307 | format; format = format->next) { |
| 3308 | if (strcmp(format->name, name) == 0) |
| 3309 | break; |
| 3310 | } |
| 3311 | |
| 3312 | return format; |
| 3313 | } |
| 3314 | |
| 3315 | /** |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 3316 | * tep_find_field - find a non-common field |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3317 | * @event: handle for the event |
| 3318 | * @name: the name of the non-common field |
| 3319 | * |
| 3320 | * Returns a non-common field by the given @name. |
| 3321 | * This does not search common fields. |
| 3322 | */ |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 3323 | struct tep_format_field * |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 3324 | tep_find_field(struct tep_event *event, const char *name) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3325 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 3326 | struct tep_format_field *format; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3327 | |
| 3328 | for (format = event->format.fields; |
| 3329 | format; format = format->next) { |
| 3330 | if (strcmp(format->name, name) == 0) |
| 3331 | break; |
| 3332 | } |
| 3333 | |
| 3334 | return format; |
| 3335 | } |
| 3336 | |
| 3337 | /** |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 3338 | * tep_find_any_field - find any field by name |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3339 | * @event: handle for the event |
| 3340 | * @name: the name of the field |
| 3341 | * |
| 3342 | * Returns a field by the given @name. |
Ingo Molnar | 3e449f7 | 2018-12-03 11:22:00 +0100 | [diff] [blame] | 3343 | * This searches the common field names first, then |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3344 | * the non-common ones if a common one was not found. |
| 3345 | */ |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 3346 | struct tep_format_field * |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 3347 | tep_find_any_field(struct tep_event *event, const char *name) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3348 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 3349 | struct tep_format_field *format; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3350 | |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 3351 | format = tep_find_common_field(event, name); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3352 | if (format) |
| 3353 | return format; |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 3354 | return tep_find_field(event, name); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | /** |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 3358 | * tep_read_number - read a number from data |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3359 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3360 | * @ptr: the raw data |
| 3361 | * @size: the size of the data that holds the number |
| 3362 | * |
| 3363 | * Returns the number (converted to host) from the |
| 3364 | * raw data. |
| 3365 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3366 | unsigned long long tep_read_number(struct tep_handle *tep, |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 3367 | const void *ptr, int size) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3368 | { |
Tzvetomir Stoyanov | 6cd99d2 | 2018-11-30 10:44:10 -0500 | [diff] [blame] | 3369 | unsigned long long val; |
| 3370 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3371 | switch (size) { |
| 3372 | case 1: |
| 3373 | return *(unsigned char *)ptr; |
| 3374 | case 2: |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3375 | return tep_data2host2(tep, *(unsigned short *)ptr); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3376 | case 4: |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3377 | return tep_data2host4(tep, *(unsigned int *)ptr); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3378 | case 8: |
Tzvetomir Stoyanov | 6cd99d2 | 2018-11-30 10:44:10 -0500 | [diff] [blame] | 3379 | memcpy(&val, (ptr), sizeof(unsigned long long)); |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3380 | return tep_data2host8(tep, val); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3381 | default: |
| 3382 | /* BUG! */ |
| 3383 | return 0; |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | /** |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 3388 | * tep_read_number_field - read a number from data |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3389 | * @field: a handle to the field |
| 3390 | * @data: the raw data to read |
| 3391 | * @value: the value to place the number in |
| 3392 | * |
| 3393 | * Reads raw data according to a field offset and size, |
| 3394 | * and translates it into @value. |
| 3395 | * |
| 3396 | * Returns 0 on success, -1 otherwise. |
| 3397 | */ |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 3398 | int tep_read_number_field(struct tep_format_field *field, const void *data, |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 3399 | unsigned long long *value) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3400 | { |
| 3401 | if (!field) |
| 3402 | return -1; |
| 3403 | switch (field->size) { |
| 3404 | case 1: |
| 3405 | case 2: |
| 3406 | case 4: |
| 3407 | case 8: |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 3408 | *value = tep_read_number(field->event->pevent, |
| 3409 | data + field->offset, field->size); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3410 | return 0; |
| 3411 | default: |
| 3412 | return -1; |
| 3413 | } |
| 3414 | } |
| 3415 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 3416 | static int get_common_info(struct tep_handle *pevent, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3417 | const char *type, int *offset, int *size) |
| 3418 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 3419 | struct tep_event *event; |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 3420 | struct tep_format_field *field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3421 | |
| 3422 | /* |
| 3423 | * All events should have the same common elements. |
| 3424 | * Pick any event to find where the type is; |
| 3425 | */ |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 3426 | if (!pevent->events) { |
| 3427 | do_warning("no event_list!"); |
| 3428 | return -1; |
| 3429 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3430 | |
| 3431 | event = pevent->events[0]; |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 3432 | field = tep_find_common_field(event, type); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3433 | if (!field) |
Steven Rostedt | 0866a97 | 2012-05-22 14:52:40 +0900 | [diff] [blame] | 3434 | return -1; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3435 | |
| 3436 | *offset = field->offset; |
| 3437 | *size = field->size; |
| 3438 | |
| 3439 | return 0; |
| 3440 | } |
| 3441 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 3442 | static int __parse_common(struct tep_handle *pevent, void *data, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3443 | int *size, int *offset, const char *name) |
| 3444 | { |
| 3445 | int ret; |
| 3446 | |
| 3447 | if (!*size) { |
| 3448 | ret = get_common_info(pevent, name, offset, size); |
| 3449 | if (ret < 0) |
| 3450 | return ret; |
| 3451 | } |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 3452 | return tep_read_number(pevent, data + *offset, *size); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3453 | } |
| 3454 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 3455 | static int trace_parse_common_type(struct tep_handle *pevent, void *data) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3456 | { |
| 3457 | return __parse_common(pevent, data, |
| 3458 | &pevent->type_size, &pevent->type_offset, |
| 3459 | "common_type"); |
| 3460 | } |
| 3461 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 3462 | static int parse_common_pid(struct tep_handle *pevent, void *data) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3463 | { |
| 3464 | return __parse_common(pevent, data, |
| 3465 | &pevent->pid_size, &pevent->pid_offset, |
| 3466 | "common_pid"); |
| 3467 | } |
| 3468 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 3469 | static int parse_common_pc(struct tep_handle *pevent, void *data) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3470 | { |
| 3471 | return __parse_common(pevent, data, |
| 3472 | &pevent->pc_size, &pevent->pc_offset, |
| 3473 | "common_preempt_count"); |
| 3474 | } |
| 3475 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 3476 | static int parse_common_flags(struct tep_handle *pevent, void *data) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3477 | { |
| 3478 | return __parse_common(pevent, data, |
| 3479 | &pevent->flags_size, &pevent->flags_offset, |
| 3480 | "common_flags"); |
| 3481 | } |
| 3482 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 3483 | static int parse_common_lock_depth(struct tep_handle *pevent, void *data) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3484 | { |
Steven Rostedt | 0866a97 | 2012-05-22 14:52:40 +0900 | [diff] [blame] | 3485 | return __parse_common(pevent, data, |
| 3486 | &pevent->ld_size, &pevent->ld_offset, |
| 3487 | "common_lock_depth"); |
| 3488 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3489 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 3490 | static int parse_common_migrate_disable(struct tep_handle *pevent, void *data) |
Steven Rostedt | 0866a97 | 2012-05-22 14:52:40 +0900 | [diff] [blame] | 3491 | { |
| 3492 | return __parse_common(pevent, data, |
| 3493 | &pevent->ld_size, &pevent->ld_offset, |
| 3494 | "common_migrate_disable"); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | static int events_id_cmp(const void *a, const void *b); |
| 3498 | |
| 3499 | /** |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 3500 | * tep_find_event - find an event by given id |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3501 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3502 | * @id: the id of the event |
| 3503 | * |
| 3504 | * Returns an event that has a given @id. |
| 3505 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3506 | struct tep_event *tep_find_event(struct tep_handle *tep, int id) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3507 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 3508 | struct tep_event **eventptr; |
| 3509 | struct tep_event key; |
| 3510 | struct tep_event *pkey = &key; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3511 | |
| 3512 | /* Check cache first */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3513 | if (tep->last_event && tep->last_event->id == id) |
| 3514 | return tep->last_event; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3515 | |
| 3516 | key.id = id; |
| 3517 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3518 | eventptr = bsearch(&pkey, tep->events, tep->nr_events, |
| 3519 | sizeof(*tep->events), events_id_cmp); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3520 | |
| 3521 | if (eventptr) { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3522 | tep->last_event = *eventptr; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3523 | return *eventptr; |
| 3524 | } |
| 3525 | |
| 3526 | return NULL; |
| 3527 | } |
| 3528 | |
| 3529 | /** |
Tzvetomir Stoyanov (VMware) | 610e1e4 | 2018-08-08 14:03:05 -0400 | [diff] [blame] | 3530 | * tep_find_event_by_name - find an event by given name |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3531 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3532 | * @sys: the system name to search for |
| 3533 | * @name: the name of the event to search for |
| 3534 | * |
| 3535 | * This returns an event with a given @name and under the system |
| 3536 | * @sys. If @sys is NULL the first event with @name is returned. |
| 3537 | */ |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 3538 | struct tep_event * |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3539 | tep_find_event_by_name(struct tep_handle *tep, |
Tzvetomir Stoyanov (VMware) | 610e1e4 | 2018-08-08 14:03:05 -0400 | [diff] [blame] | 3540 | const char *sys, const char *name) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3541 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 3542 | struct tep_event *event = NULL; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3543 | int i; |
| 3544 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3545 | if (tep->last_event && |
| 3546 | strcmp(tep->last_event->name, name) == 0 && |
| 3547 | (!sys || strcmp(tep->last_event->system, sys) == 0)) |
| 3548 | return tep->last_event; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3549 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3550 | for (i = 0; i < tep->nr_events; i++) { |
| 3551 | event = tep->events[i]; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3552 | if (strcmp(event->name, name) == 0) { |
| 3553 | if (!sys) |
| 3554 | break; |
| 3555 | if (strcmp(event->system, sys) == 0) |
| 3556 | break; |
| 3557 | } |
| 3558 | } |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3559 | if (i == tep->nr_events) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3560 | event = NULL; |
| 3561 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 3562 | tep->last_event = event; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3563 | return event; |
| 3564 | } |
| 3565 | |
| 3566 | static unsigned long long |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 3567 | eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg *arg) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3568 | { |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 3569 | struct tep_handle *pevent = event->pevent; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3570 | unsigned long long val = 0; |
| 3571 | unsigned long long left, right; |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 3572 | struct tep_print_arg *typearg = NULL; |
| 3573 | struct tep_print_arg *larg; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3574 | unsigned long offset; |
| 3575 | unsigned int field_size; |
| 3576 | |
| 3577 | switch (arg->type) { |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3578 | case TEP_PRINT_NULL: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3579 | /* ?? */ |
| 3580 | return 0; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3581 | case TEP_PRINT_ATOM: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3582 | return strtoull(arg->atom.atom, NULL, 0); |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3583 | case TEP_PRINT_FIELD: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3584 | if (!arg->field.field) { |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 3585 | arg->field.field = tep_find_any_field(event, arg->field.name); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3586 | if (!arg->field.field) |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 3587 | goto out_warning_field; |
| 3588 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3589 | } |
| 3590 | /* must be a number */ |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 3591 | val = tep_read_number(pevent, data + arg->field.field->offset, |
| 3592 | arg->field.field->size); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3593 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3594 | case TEP_PRINT_FLAGS: |
| 3595 | case TEP_PRINT_SYMBOL: |
| 3596 | case TEP_PRINT_INT_ARRAY: |
| 3597 | case TEP_PRINT_HEX: |
| 3598 | case TEP_PRINT_HEX_STR: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3599 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3600 | case TEP_PRINT_TYPE: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3601 | val = eval_num_arg(data, size, event, arg->typecast.item); |
| 3602 | return eval_type(val, arg, 0); |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3603 | case TEP_PRINT_STRING: |
| 3604 | case TEP_PRINT_BSTRING: |
| 3605 | case TEP_PRINT_BITMASK: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3606 | return 0; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3607 | case TEP_PRINT_FUNC: { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3608 | struct trace_seq s; |
| 3609 | trace_seq_init(&s); |
| 3610 | val = process_defined_func(&s, data, size, event, arg); |
| 3611 | trace_seq_destroy(&s); |
| 3612 | return val; |
| 3613 | } |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3614 | case TEP_PRINT_OP: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3615 | if (strcmp(arg->op.op, "[") == 0) { |
| 3616 | /* |
| 3617 | * Arrays are special, since we don't want |
| 3618 | * to read the arg as is. |
| 3619 | */ |
| 3620 | right = eval_num_arg(data, size, event, arg->op.right); |
| 3621 | |
| 3622 | /* handle typecasts */ |
| 3623 | larg = arg->op.left; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3624 | while (larg->type == TEP_PRINT_TYPE) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3625 | if (!typearg) |
| 3626 | typearg = larg; |
| 3627 | larg = larg->typecast.item; |
| 3628 | } |
| 3629 | |
| 3630 | /* Default to long size */ |
| 3631 | field_size = pevent->long_size; |
| 3632 | |
| 3633 | switch (larg->type) { |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3634 | case TEP_PRINT_DYNAMIC_ARRAY: |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 3635 | offset = tep_read_number(pevent, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3636 | data + larg->dynarray.field->offset, |
| 3637 | larg->dynarray.field->size); |
| 3638 | if (larg->dynarray.field->elementsize) |
| 3639 | field_size = larg->dynarray.field->elementsize; |
| 3640 | /* |
| 3641 | * The actual length of the dynamic array is stored |
| 3642 | * in the top half of the field, and the offset |
| 3643 | * is in the bottom half of the 32 bit field. |
| 3644 | */ |
| 3645 | offset &= 0xffff; |
| 3646 | offset += right; |
| 3647 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3648 | case TEP_PRINT_FIELD: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3649 | if (!larg->field.field) { |
| 3650 | larg->field.field = |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 3651 | tep_find_any_field(event, larg->field.name); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 3652 | if (!larg->field.field) { |
| 3653 | arg = larg; |
| 3654 | goto out_warning_field; |
| 3655 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3656 | } |
| 3657 | field_size = larg->field.field->elementsize; |
| 3658 | offset = larg->field.field->offset + |
| 3659 | right * larg->field.field->elementsize; |
| 3660 | break; |
| 3661 | default: |
| 3662 | goto default_op; /* oops, all bets off */ |
| 3663 | } |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 3664 | val = tep_read_number(pevent, |
| 3665 | data + offset, field_size); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3666 | if (typearg) |
| 3667 | val = eval_type(val, typearg, 1); |
| 3668 | break; |
| 3669 | } else if (strcmp(arg->op.op, "?") == 0) { |
| 3670 | left = eval_num_arg(data, size, event, arg->op.left); |
| 3671 | arg = arg->op.right; |
| 3672 | if (left) |
| 3673 | val = eval_num_arg(data, size, event, arg->op.left); |
| 3674 | else |
| 3675 | val = eval_num_arg(data, size, event, arg->op.right); |
| 3676 | break; |
| 3677 | } |
| 3678 | default_op: |
| 3679 | left = eval_num_arg(data, size, event, arg->op.left); |
| 3680 | right = eval_num_arg(data, size, event, arg->op.right); |
| 3681 | switch (arg->op.op[0]) { |
| 3682 | case '!': |
| 3683 | switch (arg->op.op[1]) { |
| 3684 | case 0: |
| 3685 | val = !right; |
| 3686 | break; |
| 3687 | case '=': |
| 3688 | val = left != right; |
| 3689 | break; |
| 3690 | default: |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 3691 | goto out_warning_op; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3692 | } |
| 3693 | break; |
| 3694 | case '~': |
| 3695 | val = ~right; |
| 3696 | break; |
| 3697 | case '|': |
| 3698 | if (arg->op.op[1]) |
| 3699 | val = left || right; |
| 3700 | else |
| 3701 | val = left | right; |
| 3702 | break; |
| 3703 | case '&': |
| 3704 | if (arg->op.op[1]) |
| 3705 | val = left && right; |
| 3706 | else |
| 3707 | val = left & right; |
| 3708 | break; |
| 3709 | case '<': |
| 3710 | switch (arg->op.op[1]) { |
| 3711 | case 0: |
| 3712 | val = left < right; |
| 3713 | break; |
| 3714 | case '<': |
| 3715 | val = left << right; |
| 3716 | break; |
| 3717 | case '=': |
| 3718 | val = left <= right; |
| 3719 | break; |
| 3720 | default: |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 3721 | goto out_warning_op; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3722 | } |
| 3723 | break; |
| 3724 | case '>': |
| 3725 | switch (arg->op.op[1]) { |
| 3726 | case 0: |
| 3727 | val = left > right; |
| 3728 | break; |
| 3729 | case '>': |
| 3730 | val = left >> right; |
| 3731 | break; |
| 3732 | case '=': |
| 3733 | val = left >= right; |
| 3734 | break; |
| 3735 | default: |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 3736 | goto out_warning_op; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3737 | } |
| 3738 | break; |
| 3739 | case '=': |
| 3740 | if (arg->op.op[1] != '=') |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 3741 | goto out_warning_op; |
| 3742 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3743 | val = left == right; |
| 3744 | break; |
| 3745 | case '-': |
| 3746 | val = left - right; |
| 3747 | break; |
| 3748 | case '+': |
| 3749 | val = left + right; |
| 3750 | break; |
Steven Rostedt | 2e7a5fc | 2012-04-06 00:48:04 +0200 | [diff] [blame] | 3751 | case '/': |
| 3752 | val = left / right; |
| 3753 | break; |
Daniel Bristot de Oliveira | 0e47b38 | 2016-02-22 14:08:22 -0300 | [diff] [blame] | 3754 | case '%': |
| 3755 | val = left % right; |
| 3756 | break; |
Steven Rostedt | 2e7a5fc | 2012-04-06 00:48:04 +0200 | [diff] [blame] | 3757 | case '*': |
| 3758 | val = left * right; |
| 3759 | break; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3760 | default: |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 3761 | goto out_warning_op; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3762 | } |
| 3763 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3764 | case TEP_PRINT_DYNAMIC_ARRAY_LEN: |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 3765 | offset = tep_read_number(pevent, |
| 3766 | data + arg->dynarray.field->offset, |
| 3767 | arg->dynarray.field->size); |
He Kuang | 7605594 | 2015-08-29 04:22:05 +0000 | [diff] [blame] | 3768 | /* |
| 3769 | * The total allocated length of the dynamic array is |
| 3770 | * stored in the top half of the field, and the offset |
| 3771 | * is in the bottom half of the 32 bit field. |
| 3772 | */ |
| 3773 | val = (unsigned long long)(offset >> 16); |
| 3774 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3775 | case TEP_PRINT_DYNAMIC_ARRAY: |
Steven Rostedt | 0497a9e | 2013-11-11 16:08:10 -0500 | [diff] [blame] | 3776 | /* Without [], we pass the address to the dynamic data */ |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 3777 | offset = tep_read_number(pevent, |
| 3778 | data + arg->dynarray.field->offset, |
| 3779 | arg->dynarray.field->size); |
Steven Rostedt | 0497a9e | 2013-11-11 16:08:10 -0500 | [diff] [blame] | 3780 | /* |
He Kuang | 7605594 | 2015-08-29 04:22:05 +0000 | [diff] [blame] | 3781 | * The total allocated length of the dynamic array is |
| 3782 | * stored in the top half of the field, and the offset |
Steven Rostedt | 0497a9e | 2013-11-11 16:08:10 -0500 | [diff] [blame] | 3783 | * is in the bottom half of the 32 bit field. |
| 3784 | */ |
| 3785 | offset &= 0xffff; |
Arnaldo Carvalho de Melo | 6b5fa0b | 2013-11-19 16:14:51 -0300 | [diff] [blame] | 3786 | val = (unsigned long long)((unsigned long)data + offset); |
Steven Rostedt | 0497a9e | 2013-11-11 16:08:10 -0500 | [diff] [blame] | 3787 | break; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3788 | default: /* not sure what to do there */ |
| 3789 | return 0; |
| 3790 | } |
| 3791 | return val; |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 3792 | |
| 3793 | out_warning_op: |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 3794 | do_warning_event(event, "%s: unknown op '%s'", __func__, arg->op.op); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 3795 | return 0; |
| 3796 | |
| 3797 | out_warning_field: |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 3798 | do_warning_event(event, "%s: field %s not found", |
| 3799 | __func__, arg->field.name); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 3800 | return 0; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | struct flag { |
| 3804 | const char *name; |
| 3805 | unsigned long long value; |
| 3806 | }; |
| 3807 | |
| 3808 | static const struct flag flags[] = { |
| 3809 | { "HI_SOFTIRQ", 0 }, |
| 3810 | { "TIMER_SOFTIRQ", 1 }, |
| 3811 | { "NET_TX_SOFTIRQ", 2 }, |
| 3812 | { "NET_RX_SOFTIRQ", 3 }, |
| 3813 | { "BLOCK_SOFTIRQ", 4 }, |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 3814 | { "IRQ_POLL_SOFTIRQ", 5 }, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3815 | { "TASKLET_SOFTIRQ", 6 }, |
| 3816 | { "SCHED_SOFTIRQ", 7 }, |
| 3817 | { "HRTIMER_SOFTIRQ", 8 }, |
| 3818 | { "RCU_SOFTIRQ", 9 }, |
| 3819 | |
| 3820 | { "HRTIMER_NORESTART", 0 }, |
| 3821 | { "HRTIMER_RESTART", 1 }, |
| 3822 | }; |
| 3823 | |
Steven Rostedt | 7c27f78 | 2015-03-24 14:58:13 -0400 | [diff] [blame] | 3824 | static long long eval_flag(const char *flag) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3825 | { |
| 3826 | int i; |
| 3827 | |
| 3828 | /* |
| 3829 | * Some flags in the format files do not get converted. |
| 3830 | * If the flag is not numeric, see if it is something that |
| 3831 | * we already know about. |
| 3832 | */ |
| 3833 | if (isdigit(flag[0])) |
| 3834 | return strtoull(flag, NULL, 0); |
| 3835 | |
| 3836 | for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++) |
| 3837 | if (strcmp(flags[i].name, flag) == 0) |
| 3838 | return flags[i].value; |
| 3839 | |
Steven Rostedt | 7c27f78 | 2015-03-24 14:58:13 -0400 | [diff] [blame] | 3840 | return -1LL; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | static void print_str_to_seq(struct trace_seq *s, const char *format, |
| 3844 | int len_arg, const char *str) |
| 3845 | { |
| 3846 | if (len_arg >= 0) |
| 3847 | trace_seq_printf(s, format, len_arg, str); |
| 3848 | else |
| 3849 | trace_seq_printf(s, format, str); |
| 3850 | } |
| 3851 | |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 3852 | static void print_bitmask_to_seq(struct tep_handle *pevent, |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 3853 | struct trace_seq *s, const char *format, |
| 3854 | int len_arg, const void *data, int size) |
| 3855 | { |
| 3856 | int nr_bits = size * 8; |
| 3857 | int str_size = (nr_bits + 3) / 4; |
| 3858 | int len = 0; |
| 3859 | char buf[3]; |
| 3860 | char *str; |
| 3861 | int index; |
| 3862 | int i; |
| 3863 | |
| 3864 | /* |
| 3865 | * The kernel likes to put in commas every 32 bits, we |
| 3866 | * can do the same. |
| 3867 | */ |
| 3868 | str_size += (nr_bits - 1) / 32; |
| 3869 | |
| 3870 | str = malloc(str_size + 1); |
| 3871 | if (!str) { |
| 3872 | do_warning("%s: not enough memory!", __func__); |
| 3873 | return; |
| 3874 | } |
| 3875 | str[str_size] = 0; |
| 3876 | |
| 3877 | /* Start out with -2 for the two chars per byte */ |
| 3878 | for (i = str_size - 2; i >= 0; i -= 2) { |
| 3879 | /* |
| 3880 | * data points to a bit mask of size bytes. |
| 3881 | * In the kernel, this is an array of long words, thus |
Ingo Molnar | 3e449f7 | 2018-12-03 11:22:00 +0100 | [diff] [blame] | 3882 | * endianness is very important. |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 3883 | */ |
| 3884 | if (pevent->file_bigendian) |
| 3885 | index = size - (len + 1); |
| 3886 | else |
| 3887 | index = len; |
| 3888 | |
| 3889 | snprintf(buf, 3, "%02x", *((unsigned char *)data + index)); |
| 3890 | memcpy(str + i, buf, 2); |
| 3891 | len++; |
| 3892 | if (!(len & 3) && i > 0) { |
| 3893 | i--; |
| 3894 | str[i] = ','; |
| 3895 | } |
| 3896 | } |
| 3897 | |
| 3898 | if (len_arg >= 0) |
| 3899 | trace_seq_printf(s, format, len_arg, str); |
| 3900 | else |
| 3901 | trace_seq_printf(s, format, str); |
| 3902 | |
| 3903 | free(str); |
| 3904 | } |
| 3905 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3906 | static void print_str_arg(struct trace_seq *s, void *data, int size, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 3907 | struct tep_event *event, const char *format, |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 3908 | int len_arg, struct tep_print_arg *arg) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3909 | { |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 3910 | struct tep_handle *pevent = event->pevent; |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 3911 | struct tep_print_flag_sym *flag; |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 3912 | struct tep_format_field *field; |
Steven Rostedt (Red Hat) | 0970b5f | 2013-11-01 17:53:55 -0400 | [diff] [blame] | 3913 | struct printk_map *printk; |
Steven Rostedt | 7c27f78 | 2015-03-24 14:58:13 -0400 | [diff] [blame] | 3914 | long long val, fval; |
Kapileshwar Singh | c2e4b24 | 2015-09-22 14:22:03 +0100 | [diff] [blame] | 3915 | unsigned long long addr; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3916 | char *str; |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 3917 | unsigned char *hex; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3918 | int print; |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 3919 | int i, len; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3920 | |
| 3921 | switch (arg->type) { |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3922 | case TEP_PRINT_NULL: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3923 | /* ?? */ |
| 3924 | return; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3925 | case TEP_PRINT_ATOM: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3926 | print_str_to_seq(s, format, len_arg, arg->atom.atom); |
| 3927 | return; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3928 | case TEP_PRINT_FIELD: |
Namhyung Kim | b700807 | 2012-06-27 09:41:40 +0900 | [diff] [blame] | 3929 | field = arg->field.field; |
| 3930 | if (!field) { |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 3931 | field = tep_find_any_field(event, arg->field.name); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 3932 | if (!field) { |
| 3933 | str = arg->field.name; |
| 3934 | goto out_warning_field; |
| 3935 | } |
Namhyung Kim | b700807 | 2012-06-27 09:41:40 +0900 | [diff] [blame] | 3936 | arg->field.field = field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3937 | } |
| 3938 | /* Zero sized fields, mean the rest of the data */ |
Namhyung Kim | b700807 | 2012-06-27 09:41:40 +0900 | [diff] [blame] | 3939 | len = field->size ? : size - field->offset; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3940 | |
| 3941 | /* |
| 3942 | * Some events pass in pointers. If this is not an array |
| 3943 | * and the size is the same as long_size, assume that it |
| 3944 | * is a pointer. |
| 3945 | */ |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 3946 | if (!(field->flags & TEP_FIELD_IS_ARRAY) && |
Namhyung Kim | b700807 | 2012-06-27 09:41:40 +0900 | [diff] [blame] | 3947 | field->size == pevent->long_size) { |
Kapileshwar Singh | c2e4b24 | 2015-09-22 14:22:03 +0100 | [diff] [blame] | 3948 | |
| 3949 | /* Handle heterogeneous recording and processing |
| 3950 | * architectures |
| 3951 | * |
| 3952 | * CASE I: |
| 3953 | * Traces recorded on 32-bit devices (32-bit |
| 3954 | * addressing) and processed on 64-bit devices: |
| 3955 | * In this case, only 32 bits should be read. |
| 3956 | * |
| 3957 | * CASE II: |
| 3958 | * Traces recorded on 64 bit devices and processed |
| 3959 | * on 32-bit devices: |
| 3960 | * In this case, 64 bits must be read. |
| 3961 | */ |
| 3962 | addr = (pevent->long_size == 8) ? |
| 3963 | *(unsigned long long *)(data + field->offset) : |
| 3964 | (unsigned long long)*(unsigned int *)(data + field->offset); |
| 3965 | |
Steven Rostedt (Red Hat) | 0970b5f | 2013-11-01 17:53:55 -0400 | [diff] [blame] | 3966 | /* Check if it matches a print format */ |
| 3967 | printk = find_printk(pevent, addr); |
| 3968 | if (printk) |
| 3969 | trace_seq_puts(s, printk->printk); |
| 3970 | else |
Kapileshwar Singh | c2e4b24 | 2015-09-22 14:22:03 +0100 | [diff] [blame] | 3971 | trace_seq_printf(s, "%llx", addr); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3972 | break; |
| 3973 | } |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 3974 | str = malloc(len + 1); |
| 3975 | if (!str) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 3976 | do_warning_event(event, "%s: not enough memory!", |
| 3977 | __func__); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 3978 | return; |
| 3979 | } |
Namhyung Kim | b700807 | 2012-06-27 09:41:40 +0900 | [diff] [blame] | 3980 | memcpy(str, data + field->offset, len); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3981 | str[len] = 0; |
| 3982 | print_str_to_seq(s, format, len_arg, str); |
| 3983 | free(str); |
| 3984 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 3985 | case TEP_PRINT_FLAGS: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3986 | val = eval_num_arg(data, size, event, arg->flags.field); |
| 3987 | print = 0; |
| 3988 | for (flag = arg->flags.flags; flag; flag = flag->next) { |
| 3989 | fval = eval_flag(flag->value); |
Steven Rostedt | 7c27f78 | 2015-03-24 14:58:13 -0400 | [diff] [blame] | 3990 | if (!val && fval < 0) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3991 | print_str_to_seq(s, format, len_arg, flag->str); |
| 3992 | break; |
| 3993 | } |
Steven Rostedt | 7c27f78 | 2015-03-24 14:58:13 -0400 | [diff] [blame] | 3994 | if (fval > 0 && (val & fval) == fval) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 3995 | if (print && arg->flags.delim) |
| 3996 | trace_seq_puts(s, arg->flags.delim); |
| 3997 | print_str_to_seq(s, format, len_arg, flag->str); |
| 3998 | print = 1; |
| 3999 | val &= ~fval; |
| 4000 | } |
| 4001 | } |
Steven Rostedt (VMware) | 3df76c9 | 2018-01-11 19:47:43 -0500 | [diff] [blame] | 4002 | if (val) { |
| 4003 | if (print && arg->flags.delim) |
| 4004 | trace_seq_puts(s, arg->flags.delim); |
| 4005 | trace_seq_printf(s, "0x%llx", val); |
| 4006 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4007 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4008 | case TEP_PRINT_SYMBOL: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4009 | val = eval_num_arg(data, size, event, arg->symbol.field); |
| 4010 | for (flag = arg->symbol.symbols; flag; flag = flag->next) { |
| 4011 | fval = eval_flag(flag->value); |
| 4012 | if (val == fval) { |
| 4013 | print_str_to_seq(s, format, len_arg, flag->str); |
| 4014 | break; |
| 4015 | } |
| 4016 | } |
Jan Kiszka | d634447 | 2018-01-11 19:47:44 -0500 | [diff] [blame] | 4017 | if (!flag) |
| 4018 | trace_seq_printf(s, "0x%llx", val); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4019 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4020 | case TEP_PRINT_HEX: |
| 4021 | case TEP_PRINT_HEX_STR: |
| 4022 | if (arg->hex.field->type == TEP_PRINT_DYNAMIC_ARRAY) { |
Howard Cochran | b30f75e | 2013-11-01 17:53:56 -0400 | [diff] [blame] | 4023 | unsigned long offset; |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 4024 | offset = tep_read_number(pevent, |
Howard Cochran | b30f75e | 2013-11-01 17:53:56 -0400 | [diff] [blame] | 4025 | data + arg->hex.field->dynarray.field->offset, |
| 4026 | arg->hex.field->dynarray.field->size); |
| 4027 | hex = data + (offset & 0xffff); |
| 4028 | } else { |
| 4029 | field = arg->hex.field->field.field; |
| 4030 | if (!field) { |
| 4031 | str = arg->hex.field->field.name; |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 4032 | field = tep_find_any_field(event, str); |
Howard Cochran | b30f75e | 2013-11-01 17:53:56 -0400 | [diff] [blame] | 4033 | if (!field) |
| 4034 | goto out_warning_field; |
| 4035 | arg->hex.field->field.field = field; |
| 4036 | } |
| 4037 | hex = data + field->offset; |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 4038 | } |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 4039 | len = eval_num_arg(data, size, event, arg->hex.size); |
| 4040 | for (i = 0; i < len; i++) { |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4041 | if (i && arg->type == TEP_PRINT_HEX) |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 4042 | trace_seq_putc(s, ' '); |
| 4043 | trace_seq_printf(s, "%02x", hex[i]); |
| 4044 | } |
| 4045 | break; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4046 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4047 | case TEP_PRINT_INT_ARRAY: { |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 4048 | void *num; |
| 4049 | int el_size; |
| 4050 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4051 | if (arg->int_array.field->type == TEP_PRINT_DYNAMIC_ARRAY) { |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 4052 | unsigned long offset; |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 4053 | struct tep_format_field *field = |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 4054 | arg->int_array.field->dynarray.field; |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 4055 | offset = tep_read_number(pevent, |
| 4056 | data + field->offset, |
| 4057 | field->size); |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 4058 | num = data + (offset & 0xffff); |
| 4059 | } else { |
| 4060 | field = arg->int_array.field->field.field; |
| 4061 | if (!field) { |
| 4062 | str = arg->int_array.field->field.name; |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 4063 | field = tep_find_any_field(event, str); |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 4064 | if (!field) |
| 4065 | goto out_warning_field; |
| 4066 | arg->int_array.field->field.field = field; |
| 4067 | } |
| 4068 | num = data + field->offset; |
| 4069 | } |
| 4070 | len = eval_num_arg(data, size, event, arg->int_array.count); |
| 4071 | el_size = eval_num_arg(data, size, event, |
| 4072 | arg->int_array.el_size); |
| 4073 | for (i = 0; i < len; i++) { |
| 4074 | if (i) |
| 4075 | trace_seq_putc(s, ' '); |
| 4076 | |
| 4077 | if (el_size == 1) { |
| 4078 | trace_seq_printf(s, "%u", *(uint8_t *)num); |
| 4079 | } else if (el_size == 2) { |
| 4080 | trace_seq_printf(s, "%u", *(uint16_t *)num); |
| 4081 | } else if (el_size == 4) { |
| 4082 | trace_seq_printf(s, "%u", *(uint32_t *)num); |
| 4083 | } else if (el_size == 8) { |
Namhyung Kim | 410ceb8 | 2015-04-24 10:45:16 +0900 | [diff] [blame] | 4084 | trace_seq_printf(s, "%"PRIu64, *(uint64_t *)num); |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 4085 | } else { |
| 4086 | trace_seq_printf(s, "BAD SIZE:%d 0x%x", |
| 4087 | el_size, *(uint8_t *)num); |
| 4088 | el_size = 1; |
| 4089 | } |
| 4090 | |
| 4091 | num += el_size; |
| 4092 | } |
| 4093 | break; |
| 4094 | } |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4095 | case TEP_PRINT_TYPE: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4096 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4097 | case TEP_PRINT_STRING: { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4098 | int str_offset; |
| 4099 | |
| 4100 | if (arg->string.offset == -1) { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 4101 | struct tep_format_field *f; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4102 | |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 4103 | f = tep_find_any_field(event, arg->string.string); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4104 | arg->string.offset = f->offset; |
| 4105 | } |
Tzvetomir Stoyanov | 6cd99d2 | 2018-11-30 10:44:10 -0500 | [diff] [blame] | 4106 | str_offset = tep_data2host4(pevent, *(unsigned int *)(data + arg->string.offset)); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4107 | str_offset &= 0xffff; |
| 4108 | print_str_to_seq(s, format, len_arg, ((char *)data) + str_offset); |
| 4109 | break; |
| 4110 | } |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4111 | case TEP_PRINT_BSTRING: |
Steven Rostedt | c2e6dc2 | 2011-11-15 18:47:48 -0500 | [diff] [blame] | 4112 | print_str_to_seq(s, format, len_arg, arg->string.string); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4113 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4114 | case TEP_PRINT_BITMASK: { |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 4115 | int bitmask_offset; |
| 4116 | int bitmask_size; |
| 4117 | |
| 4118 | if (arg->bitmask.offset == -1) { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 4119 | struct tep_format_field *f; |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 4120 | |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 4121 | f = tep_find_any_field(event, arg->bitmask.bitmask); |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 4122 | arg->bitmask.offset = f->offset; |
| 4123 | } |
Tzvetomir Stoyanov | 6cd99d2 | 2018-11-30 10:44:10 -0500 | [diff] [blame] | 4124 | bitmask_offset = tep_data2host4(pevent, *(unsigned int *)(data + arg->bitmask.offset)); |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 4125 | bitmask_size = bitmask_offset >> 16; |
| 4126 | bitmask_offset &= 0xffff; |
| 4127 | print_bitmask_to_seq(pevent, s, format, len_arg, |
| 4128 | data + bitmask_offset, bitmask_size); |
| 4129 | break; |
| 4130 | } |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4131 | case TEP_PRINT_OP: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4132 | /* |
| 4133 | * The only op for string should be ? : |
| 4134 | */ |
| 4135 | if (arg->op.op[0] != '?') |
| 4136 | return; |
| 4137 | val = eval_num_arg(data, size, event, arg->op.left); |
| 4138 | if (val) |
| 4139 | print_str_arg(s, data, size, event, |
| 4140 | format, len_arg, arg->op.right->op.left); |
| 4141 | else |
| 4142 | print_str_arg(s, data, size, event, |
| 4143 | format, len_arg, arg->op.right->op.right); |
| 4144 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4145 | case TEP_PRINT_FUNC: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4146 | process_defined_func(s, data, size, event, arg); |
| 4147 | break; |
| 4148 | default: |
| 4149 | /* well... */ |
| 4150 | break; |
| 4151 | } |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4152 | |
| 4153 | return; |
| 4154 | |
| 4155 | out_warning_field: |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 4156 | do_warning_event(event, "%s: field %s not found", |
| 4157 | __func__, arg->field.name); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4158 | } |
| 4159 | |
| 4160 | static unsigned long long |
| 4161 | process_defined_func(struct trace_seq *s, void *data, int size, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 4162 | struct tep_event *event, struct tep_print_arg *arg) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4163 | { |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 4164 | struct tep_function_handler *func_handle = arg->func.func; |
Tzvetomir Stoyanov (VMware) | 0ae9863 | 2018-08-08 14:03:09 -0400 | [diff] [blame] | 4165 | struct func_params *param; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4166 | unsigned long long *args; |
| 4167 | unsigned long long ret; |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 4168 | struct tep_print_arg *farg; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4169 | struct trace_seq str; |
| 4170 | struct save_str { |
| 4171 | struct save_str *next; |
| 4172 | char *str; |
| 4173 | } *strings = NULL, *string; |
| 4174 | int i; |
| 4175 | |
| 4176 | if (!func_handle->nr_args) { |
| 4177 | ret = (*func_handle->func)(s, NULL); |
| 4178 | goto out; |
| 4179 | } |
| 4180 | |
| 4181 | farg = arg->func.args; |
| 4182 | param = func_handle->params; |
| 4183 | |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4184 | ret = ULLONG_MAX; |
| 4185 | args = malloc(sizeof(*args) * func_handle->nr_args); |
| 4186 | if (!args) |
| 4187 | goto out; |
| 4188 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4189 | for (i = 0; i < func_handle->nr_args; i++) { |
| 4190 | switch (param->type) { |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 4191 | case TEP_FUNC_ARG_INT: |
| 4192 | case TEP_FUNC_ARG_LONG: |
| 4193 | case TEP_FUNC_ARG_PTR: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4194 | args[i] = eval_num_arg(data, size, event, farg); |
| 4195 | break; |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 4196 | case TEP_FUNC_ARG_STRING: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4197 | trace_seq_init(&str); |
| 4198 | print_str_arg(&str, data, size, event, "%s", -1, farg); |
| 4199 | trace_seq_terminate(&str); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4200 | string = malloc(sizeof(*string)); |
| 4201 | if (!string) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 4202 | do_warning_event(event, "%s(%d): malloc str", |
| 4203 | __func__, __LINE__); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4204 | goto out_free; |
| 4205 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4206 | string->next = strings; |
| 4207 | string->str = strdup(str.buffer); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4208 | if (!string->str) { |
| 4209 | free(string); |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 4210 | do_warning_event(event, "%s(%d): malloc str", |
| 4211 | __func__, __LINE__); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4212 | goto out_free; |
| 4213 | } |
Robert Richter | 0cf2601 | 2012-08-07 19:43:14 +0200 | [diff] [blame] | 4214 | args[i] = (uintptr_t)string->str; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4215 | strings = string; |
| 4216 | trace_seq_destroy(&str); |
| 4217 | break; |
| 4218 | default: |
| 4219 | /* |
| 4220 | * Something went totally wrong, this is not |
| 4221 | * an input error, something in this code broke. |
| 4222 | */ |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 4223 | do_warning_event(event, "Unexpected end of arguments\n"); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4224 | goto out_free; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4225 | } |
| 4226 | farg = farg->next; |
Namhyung Kim | 21c69e72 | 2012-05-23 11:36:51 +0900 | [diff] [blame] | 4227 | param = param->next; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4228 | } |
| 4229 | |
| 4230 | ret = (*func_handle->func)(s, args); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4231 | out_free: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4232 | free(args); |
| 4233 | while (strings) { |
| 4234 | string = strings; |
| 4235 | strings = string->next; |
| 4236 | free(string->str); |
| 4237 | free(string); |
| 4238 | } |
| 4239 | |
| 4240 | out: |
| 4241 | /* TBD : handle return type here */ |
| 4242 | return ret; |
| 4243 | } |
| 4244 | |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 4245 | static void free_args(struct tep_print_arg *args) |
Arnaldo Carvalho de Melo | 0dbca1e | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 4246 | { |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 4247 | struct tep_print_arg *next; |
Arnaldo Carvalho de Melo | 0dbca1e | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 4248 | |
| 4249 | while (args) { |
| 4250 | next = args->next; |
| 4251 | |
| 4252 | free_arg(args); |
| 4253 | args = next; |
| 4254 | } |
| 4255 | } |
| 4256 | |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 4257 | static struct tep_print_arg *make_bprint_args(char *fmt, void *data, int size, struct tep_event *event) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4258 | { |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 4259 | struct tep_handle *pevent = event->pevent; |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 4260 | struct tep_format_field *field, *ip_field; |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 4261 | struct tep_print_arg *args, *arg, **next; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4262 | unsigned long long ip, val; |
| 4263 | char *ptr; |
| 4264 | void *bptr; |
Adrian Hunter | 0631ca3 | 2018-11-22 13:29:37 +0200 | [diff] [blame] | 4265 | int vsize = 0; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4266 | |
| 4267 | field = pevent->bprint_buf_field; |
| 4268 | ip_field = pevent->bprint_ip_field; |
| 4269 | |
| 4270 | if (!field) { |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 4271 | field = tep_find_field(event, "buf"); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4272 | if (!field) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 4273 | do_warning_event(event, "can't find buffer field for binary printk"); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4274 | return NULL; |
| 4275 | } |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 4276 | ip_field = tep_find_field(event, "ip"); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4277 | if (!ip_field) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 4278 | do_warning_event(event, "can't find ip field for binary printk"); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4279 | return NULL; |
| 4280 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4281 | pevent->bprint_buf_field = field; |
| 4282 | pevent->bprint_ip_field = ip_field; |
| 4283 | } |
| 4284 | |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 4285 | ip = tep_read_number(pevent, data + ip_field->offset, ip_field->size); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4286 | |
| 4287 | /* |
| 4288 | * The first arg is the IP pointer. |
| 4289 | */ |
| 4290 | args = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 4291 | if (!args) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 4292 | do_warning_event(event, "%s(%d): not enough memory!", |
| 4293 | __func__, __LINE__); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 4294 | return NULL; |
| 4295 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4296 | arg = args; |
| 4297 | arg->next = NULL; |
| 4298 | next = &arg->next; |
| 4299 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4300 | arg->type = TEP_PRINT_ATOM; |
Arnaldo Carvalho de Melo | 0dbca1e | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 4301 | |
| 4302 | if (asprintf(&arg->atom.atom, "%lld", ip) < 0) |
| 4303 | goto out_free; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4304 | |
Scott Wood | bbedb17 | 2015-03-11 22:13:57 -0500 | [diff] [blame] | 4305 | /* skip the first "%ps: " */ |
Steven Rostedt (Red Hat) | 0883d9d | 2013-11-01 17:53:57 -0400 | [diff] [blame] | 4306 | for (ptr = fmt + 5, bptr = data + field->offset; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4307 | bptr < data + size && *ptr; ptr++) { |
| 4308 | int ls = 0; |
| 4309 | |
| 4310 | if (*ptr == '%') { |
| 4311 | process_again: |
| 4312 | ptr++; |
| 4313 | switch (*ptr) { |
| 4314 | case '%': |
| 4315 | break; |
| 4316 | case 'l': |
| 4317 | ls++; |
| 4318 | goto process_again; |
| 4319 | case 'L': |
| 4320 | ls = 2; |
| 4321 | goto process_again; |
| 4322 | case '0' ... '9': |
| 4323 | goto process_again; |
Steven Rostedt | c2e6dc2 | 2011-11-15 18:47:48 -0500 | [diff] [blame] | 4324 | case '.': |
| 4325 | goto process_again; |
Steven Rostedt (Red Hat) | 5542629 | 2015-03-24 09:57:51 -0400 | [diff] [blame] | 4326 | case 'z': |
| 4327 | case 'Z': |
| 4328 | ls = 1; |
| 4329 | goto process_again; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4330 | case 'p': |
| 4331 | ls = 1; |
Steven Rostedt (VMware) | 37db96b | 2018-01-11 19:47:46 -0500 | [diff] [blame] | 4332 | if (isalnum(ptr[1])) { |
| 4333 | ptr++; |
| 4334 | /* Check for special pointers */ |
| 4335 | switch (*ptr) { |
| 4336 | case 's': |
| 4337 | case 'S': |
| 4338 | case 'f': |
| 4339 | case 'F': |
Steven Rostedt (VMware) | 328b82b | 2019-04-01 12:43:06 -0400 | [diff] [blame] | 4340 | case 'x': |
Steven Rostedt (VMware) | 37db96b | 2018-01-11 19:47:46 -0500 | [diff] [blame] | 4341 | break; |
| 4342 | default: |
| 4343 | /* |
| 4344 | * Older kernels do not process |
| 4345 | * dereferenced pointers. |
| 4346 | * Only process if the pointer |
| 4347 | * value is a printable. |
| 4348 | */ |
| 4349 | if (isprint(*(char *)bptr)) |
| 4350 | goto process_string; |
| 4351 | } |
| 4352 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4353 | /* fall through */ |
| 4354 | case 'd': |
| 4355 | case 'u': |
| 4356 | case 'x': |
| 4357 | case 'i': |
Steven Rostedt | c2e6dc2 | 2011-11-15 18:47:48 -0500 | [diff] [blame] | 4358 | switch (ls) { |
| 4359 | case 0: |
| 4360 | vsize = 4; |
| 4361 | break; |
| 4362 | case 1: |
| 4363 | vsize = pevent->long_size; |
| 4364 | break; |
| 4365 | case 2: |
| 4366 | vsize = 8; |
Peter Huewe | c9bbabe | 2012-04-24 23:19:40 +0200 | [diff] [blame] | 4367 | break; |
Steven Rostedt | c2e6dc2 | 2011-11-15 18:47:48 -0500 | [diff] [blame] | 4368 | default: |
| 4369 | vsize = ls; /* ? */ |
| 4370 | break; |
| 4371 | } |
| 4372 | /* fall through */ |
| 4373 | case '*': |
| 4374 | if (*ptr == '*') |
| 4375 | vsize = 4; |
| 4376 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4377 | /* the pointers are always 4 bytes aligned */ |
| 4378 | bptr = (void *)(((unsigned long)bptr + 3) & |
| 4379 | ~3); |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 4380 | val = tep_read_number(pevent, bptr, vsize); |
Steven Rostedt | c2e6dc2 | 2011-11-15 18:47:48 -0500 | [diff] [blame] | 4381 | bptr += vsize; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4382 | arg = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 4383 | if (!arg) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 4384 | do_warning_event(event, "%s(%d): not enough memory!", |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 4385 | __func__, __LINE__); |
| 4386 | goto out_free; |
| 4387 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4388 | arg->next = NULL; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4389 | arg->type = TEP_PRINT_ATOM; |
Arnaldo Carvalho de Melo | 0dbca1e | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 4390 | if (asprintf(&arg->atom.atom, "%lld", val) < 0) { |
| 4391 | free(arg); |
| 4392 | goto out_free; |
| 4393 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4394 | *next = arg; |
| 4395 | next = &arg->next; |
Steven Rostedt | c2e6dc2 | 2011-11-15 18:47:48 -0500 | [diff] [blame] | 4396 | /* |
| 4397 | * The '*' case means that an arg is used as the length. |
| 4398 | * We need to continue to figure out for what. |
| 4399 | */ |
| 4400 | if (*ptr == '*') |
| 4401 | goto process_again; |
| 4402 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4403 | break; |
| 4404 | case 's': |
Steven Rostedt (VMware) | 37db96b | 2018-01-11 19:47:46 -0500 | [diff] [blame] | 4405 | process_string: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4406 | arg = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 4407 | if (!arg) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 4408 | do_warning_event(event, "%s(%d): not enough memory!", |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 4409 | __func__, __LINE__); |
| 4410 | goto out_free; |
| 4411 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4412 | arg->next = NULL; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4413 | arg->type = TEP_PRINT_BSTRING; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4414 | arg->string.string = strdup(bptr); |
Namhyung Kim | ca63858 | 2012-04-09 11:54:31 +0900 | [diff] [blame] | 4415 | if (!arg->string.string) |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4416 | goto out_free; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4417 | bptr += strlen(bptr) + 1; |
| 4418 | *next = arg; |
| 4419 | next = &arg->next; |
| 4420 | default: |
| 4421 | break; |
| 4422 | } |
| 4423 | } |
| 4424 | } |
| 4425 | |
| 4426 | return args; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4427 | |
Arnaldo Carvalho de Melo | 0dbca1e | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 4428 | out_free: |
| 4429 | free_args(args); |
| 4430 | return NULL; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4431 | } |
| 4432 | |
| 4433 | static char * |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 4434 | get_bprint_format(void *data, int size __maybe_unused, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 4435 | struct tep_event *event) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4436 | { |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 4437 | struct tep_handle *pevent = event->pevent; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4438 | unsigned long long addr; |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 4439 | struct tep_format_field *field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4440 | struct printk_map *printk; |
| 4441 | char *format; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4442 | |
| 4443 | field = pevent->bprint_fmt_field; |
| 4444 | |
| 4445 | if (!field) { |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 4446 | field = tep_find_field(event, "fmt"); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4447 | if (!field) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 4448 | do_warning_event(event, "can't find format field for binary printk"); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4449 | return NULL; |
| 4450 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4451 | pevent->bprint_fmt_field = field; |
| 4452 | } |
| 4453 | |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 4454 | addr = tep_read_number(pevent, data + field->offset, field->size); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4455 | |
| 4456 | printk = find_printk(pevent, addr); |
| 4457 | if (!printk) { |
Steven Rostedt (Red Hat) | 0883d9d | 2013-11-01 17:53:57 -0400 | [diff] [blame] | 4458 | if (asprintf(&format, "%%pf: (NO FORMAT FOUND at %llx)\n", addr) < 0) |
Arnaldo Carvalho de Melo | 0dbca1e | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 4459 | return NULL; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4460 | return format; |
| 4461 | } |
| 4462 | |
Steven Rostedt (Red Hat) | 0883d9d | 2013-11-01 17:53:57 -0400 | [diff] [blame] | 4463 | if (asprintf(&format, "%s: %s", "%pf", printk->printk) < 0) |
Arnaldo Carvalho de Melo | 0dbca1e | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 4464 | return NULL; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4465 | |
| 4466 | return format; |
| 4467 | } |
| 4468 | |
| 4469 | static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 4470 | struct tep_event *event, struct tep_print_arg *arg) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4471 | { |
| 4472 | unsigned char *buf; |
Arnaldo Carvalho de Melo | 27f94d5 | 2012-11-09 17:40:47 -0300 | [diff] [blame] | 4473 | const char *fmt = "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x"; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4474 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4475 | if (arg->type == TEP_PRINT_FUNC) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4476 | process_defined_func(s, data, size, event, arg); |
| 4477 | return; |
| 4478 | } |
| 4479 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4480 | if (arg->type != TEP_PRINT_FIELD) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4481 | trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", |
| 4482 | arg->type); |
| 4483 | return; |
| 4484 | } |
| 4485 | |
| 4486 | if (mac == 'm') |
| 4487 | fmt = "%.2x%.2x%.2x%.2x%.2x%.2x"; |
| 4488 | if (!arg->field.field) { |
| 4489 | arg->field.field = |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 4490 | tep_find_any_field(event, arg->field.name); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4491 | if (!arg->field.field) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 4492 | do_warning_event(event, "%s: field %s not found", |
| 4493 | __func__, arg->field.name); |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 4494 | return; |
| 4495 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4496 | } |
| 4497 | if (arg->field.field->size != 6) { |
| 4498 | trace_seq_printf(s, "INVALIDMAC"); |
| 4499 | return; |
| 4500 | } |
| 4501 | buf = data + arg->field.field->offset; |
| 4502 | trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); |
| 4503 | } |
| 4504 | |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 4505 | static void print_ip4_addr(struct trace_seq *s, char i, unsigned char *buf) |
| 4506 | { |
| 4507 | const char *fmt; |
| 4508 | |
| 4509 | if (i == 'i') |
| 4510 | fmt = "%03d.%03d.%03d.%03d"; |
| 4511 | else |
| 4512 | fmt = "%d.%d.%d.%d"; |
| 4513 | |
| 4514 | trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3]); |
| 4515 | } |
| 4516 | |
| 4517 | static inline bool ipv6_addr_v4mapped(const struct in6_addr *a) |
| 4518 | { |
| 4519 | return ((unsigned long)(a->s6_addr32[0] | a->s6_addr32[1]) | |
| 4520 | (unsigned long)(a->s6_addr32[2] ^ htonl(0x0000ffff))) == 0UL; |
| 4521 | } |
| 4522 | |
| 4523 | static inline bool ipv6_addr_is_isatap(const struct in6_addr *addr) |
| 4524 | { |
| 4525 | return (addr->s6_addr32[2] | htonl(0x02000000)) == htonl(0x02005EFE); |
| 4526 | } |
| 4527 | |
| 4528 | static void print_ip6c_addr(struct trace_seq *s, unsigned char *addr) |
| 4529 | { |
| 4530 | int i, j, range; |
| 4531 | unsigned char zerolength[8]; |
| 4532 | int longest = 1; |
| 4533 | int colonpos = -1; |
| 4534 | uint16_t word; |
| 4535 | uint8_t hi, lo; |
| 4536 | bool needcolon = false; |
| 4537 | bool useIPv4; |
| 4538 | struct in6_addr in6; |
| 4539 | |
| 4540 | memcpy(&in6, addr, sizeof(struct in6_addr)); |
| 4541 | |
| 4542 | useIPv4 = ipv6_addr_v4mapped(&in6) || ipv6_addr_is_isatap(&in6); |
| 4543 | |
| 4544 | memset(zerolength, 0, sizeof(zerolength)); |
| 4545 | |
| 4546 | if (useIPv4) |
| 4547 | range = 6; |
| 4548 | else |
| 4549 | range = 8; |
| 4550 | |
| 4551 | /* find position of longest 0 run */ |
| 4552 | for (i = 0; i < range; i++) { |
| 4553 | for (j = i; j < range; j++) { |
| 4554 | if (in6.s6_addr16[j] != 0) |
| 4555 | break; |
| 4556 | zerolength[i]++; |
| 4557 | } |
| 4558 | } |
| 4559 | for (i = 0; i < range; i++) { |
| 4560 | if (zerolength[i] > longest) { |
| 4561 | longest = zerolength[i]; |
| 4562 | colonpos = i; |
| 4563 | } |
| 4564 | } |
| 4565 | if (longest == 1) /* don't compress a single 0 */ |
| 4566 | colonpos = -1; |
| 4567 | |
| 4568 | /* emit address */ |
| 4569 | for (i = 0; i < range; i++) { |
| 4570 | if (i == colonpos) { |
| 4571 | if (needcolon || i == 0) |
| 4572 | trace_seq_printf(s, ":"); |
| 4573 | trace_seq_printf(s, ":"); |
| 4574 | needcolon = false; |
| 4575 | i += longest - 1; |
| 4576 | continue; |
| 4577 | } |
| 4578 | if (needcolon) { |
| 4579 | trace_seq_printf(s, ":"); |
| 4580 | needcolon = false; |
| 4581 | } |
| 4582 | /* hex u16 without leading 0s */ |
| 4583 | word = ntohs(in6.s6_addr16[i]); |
| 4584 | hi = word >> 8; |
| 4585 | lo = word & 0xff; |
| 4586 | if (hi) |
| 4587 | trace_seq_printf(s, "%x%02x", hi, lo); |
| 4588 | else |
| 4589 | trace_seq_printf(s, "%x", lo); |
| 4590 | |
| 4591 | needcolon = true; |
| 4592 | } |
| 4593 | |
| 4594 | if (useIPv4) { |
| 4595 | if (needcolon) |
| 4596 | trace_seq_printf(s, ":"); |
| 4597 | print_ip4_addr(s, 'I', &in6.s6_addr[12]); |
| 4598 | } |
| 4599 | |
| 4600 | return; |
| 4601 | } |
| 4602 | |
| 4603 | static void print_ip6_addr(struct trace_seq *s, char i, unsigned char *buf) |
| 4604 | { |
| 4605 | int j; |
| 4606 | |
| 4607 | for (j = 0; j < 16; j += 2) { |
| 4608 | trace_seq_printf(s, "%02x%02x", buf[j], buf[j+1]); |
| 4609 | if (i == 'I' && j < 14) |
| 4610 | trace_seq_printf(s, ":"); |
| 4611 | } |
| 4612 | } |
| 4613 | |
| 4614 | /* |
| 4615 | * %pi4 print an IPv4 address with leading zeros |
| 4616 | * %pI4 print an IPv4 address without leading zeros |
| 4617 | * %pi6 print an IPv6 address without colons |
| 4618 | * %pI6 print an IPv6 address with colons |
| 4619 | * %pI6c print an IPv6 address in compressed form with colons |
| 4620 | * %pISpc print an IP address based on sockaddr; p adds port. |
| 4621 | */ |
| 4622 | static int print_ipv4_arg(struct trace_seq *s, const char *ptr, char i, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 4623 | void *data, int size, struct tep_event *event, |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 4624 | struct tep_print_arg *arg) |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 4625 | { |
| 4626 | unsigned char *buf; |
| 4627 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4628 | if (arg->type == TEP_PRINT_FUNC) { |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 4629 | process_defined_func(s, data, size, event, arg); |
| 4630 | return 0; |
| 4631 | } |
| 4632 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4633 | if (arg->type != TEP_PRINT_FIELD) { |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 4634 | trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); |
| 4635 | return 0; |
| 4636 | } |
| 4637 | |
| 4638 | if (!arg->field.field) { |
| 4639 | arg->field.field = |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 4640 | tep_find_any_field(event, arg->field.name); |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 4641 | if (!arg->field.field) { |
| 4642 | do_warning("%s: field %s not found", |
| 4643 | __func__, arg->field.name); |
| 4644 | return 0; |
| 4645 | } |
| 4646 | } |
| 4647 | |
| 4648 | buf = data + arg->field.field->offset; |
| 4649 | |
| 4650 | if (arg->field.field->size != 4) { |
| 4651 | trace_seq_printf(s, "INVALIDIPv4"); |
| 4652 | return 0; |
| 4653 | } |
| 4654 | print_ip4_addr(s, i, buf); |
| 4655 | |
| 4656 | return 0; |
| 4657 | } |
| 4658 | |
| 4659 | static int print_ipv6_arg(struct trace_seq *s, const char *ptr, char i, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 4660 | void *data, int size, struct tep_event *event, |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 4661 | struct tep_print_arg *arg) |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 4662 | { |
| 4663 | char have_c = 0; |
| 4664 | unsigned char *buf; |
| 4665 | int rc = 0; |
| 4666 | |
| 4667 | /* pI6c */ |
| 4668 | if (i == 'I' && *ptr == 'c') { |
| 4669 | have_c = 1; |
| 4670 | ptr++; |
| 4671 | rc++; |
| 4672 | } |
| 4673 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4674 | if (arg->type == TEP_PRINT_FUNC) { |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 4675 | process_defined_func(s, data, size, event, arg); |
| 4676 | return rc; |
| 4677 | } |
| 4678 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4679 | if (arg->type != TEP_PRINT_FIELD) { |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 4680 | trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); |
| 4681 | return rc; |
| 4682 | } |
| 4683 | |
| 4684 | if (!arg->field.field) { |
| 4685 | arg->field.field = |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 4686 | tep_find_any_field(event, arg->field.name); |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 4687 | if (!arg->field.field) { |
| 4688 | do_warning("%s: field %s not found", |
| 4689 | __func__, arg->field.name); |
| 4690 | return rc; |
| 4691 | } |
| 4692 | } |
| 4693 | |
| 4694 | buf = data + arg->field.field->offset; |
| 4695 | |
| 4696 | if (arg->field.field->size != 16) { |
| 4697 | trace_seq_printf(s, "INVALIDIPv6"); |
| 4698 | return rc; |
| 4699 | } |
| 4700 | |
| 4701 | if (have_c) |
| 4702 | print_ip6c_addr(s, buf); |
| 4703 | else |
| 4704 | print_ip6_addr(s, i, buf); |
| 4705 | |
| 4706 | return rc; |
| 4707 | } |
| 4708 | |
| 4709 | static int print_ipsa_arg(struct trace_seq *s, const char *ptr, char i, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 4710 | void *data, int size, struct tep_event *event, |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 4711 | struct tep_print_arg *arg) |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 4712 | { |
| 4713 | char have_c = 0, have_p = 0; |
| 4714 | unsigned char *buf; |
| 4715 | struct sockaddr_storage *sa; |
| 4716 | int rc = 0; |
| 4717 | |
| 4718 | /* pISpc */ |
| 4719 | if (i == 'I') { |
| 4720 | if (*ptr == 'p') { |
| 4721 | have_p = 1; |
| 4722 | ptr++; |
| 4723 | rc++; |
| 4724 | } |
| 4725 | if (*ptr == 'c') { |
| 4726 | have_c = 1; |
| 4727 | ptr++; |
| 4728 | rc++; |
| 4729 | } |
| 4730 | } |
| 4731 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4732 | if (arg->type == TEP_PRINT_FUNC) { |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 4733 | process_defined_func(s, data, size, event, arg); |
| 4734 | return rc; |
| 4735 | } |
| 4736 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 4737 | if (arg->type != TEP_PRINT_FIELD) { |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 4738 | trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); |
| 4739 | return rc; |
| 4740 | } |
| 4741 | |
| 4742 | if (!arg->field.field) { |
| 4743 | arg->field.field = |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 4744 | tep_find_any_field(event, arg->field.name); |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 4745 | if (!arg->field.field) { |
| 4746 | do_warning("%s: field %s not found", |
| 4747 | __func__, arg->field.name); |
| 4748 | return rc; |
| 4749 | } |
| 4750 | } |
| 4751 | |
| 4752 | sa = (struct sockaddr_storage *) (data + arg->field.field->offset); |
| 4753 | |
| 4754 | if (sa->ss_family == AF_INET) { |
| 4755 | struct sockaddr_in *sa4 = (struct sockaddr_in *) sa; |
| 4756 | |
| 4757 | if (arg->field.field->size < sizeof(struct sockaddr_in)) { |
| 4758 | trace_seq_printf(s, "INVALIDIPv4"); |
| 4759 | return rc; |
| 4760 | } |
| 4761 | |
| 4762 | print_ip4_addr(s, i, (unsigned char *) &sa4->sin_addr); |
| 4763 | if (have_p) |
| 4764 | trace_seq_printf(s, ":%d", ntohs(sa4->sin_port)); |
| 4765 | |
| 4766 | |
| 4767 | } else if (sa->ss_family == AF_INET6) { |
| 4768 | struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) sa; |
| 4769 | |
| 4770 | if (arg->field.field->size < sizeof(struct sockaddr_in6)) { |
| 4771 | trace_seq_printf(s, "INVALIDIPv6"); |
| 4772 | return rc; |
| 4773 | } |
| 4774 | |
| 4775 | if (have_p) |
| 4776 | trace_seq_printf(s, "["); |
| 4777 | |
| 4778 | buf = (unsigned char *) &sa6->sin6_addr; |
| 4779 | if (have_c) |
| 4780 | print_ip6c_addr(s, buf); |
| 4781 | else |
| 4782 | print_ip6_addr(s, i, buf); |
| 4783 | |
| 4784 | if (have_p) |
| 4785 | trace_seq_printf(s, "]:%d", ntohs(sa6->sin6_port)); |
| 4786 | } |
| 4787 | |
| 4788 | return rc; |
| 4789 | } |
| 4790 | |
| 4791 | static int print_ip_arg(struct trace_seq *s, const char *ptr, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 4792 | void *data, int size, struct tep_event *event, |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 4793 | struct tep_print_arg *arg) |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 4794 | { |
| 4795 | char i = *ptr; /* 'i' or 'I' */ |
| 4796 | char ver; |
| 4797 | int rc = 0; |
| 4798 | |
| 4799 | ptr++; |
| 4800 | rc++; |
| 4801 | |
| 4802 | ver = *ptr; |
| 4803 | ptr++; |
| 4804 | rc++; |
| 4805 | |
| 4806 | switch (ver) { |
| 4807 | case '4': |
| 4808 | rc += print_ipv4_arg(s, ptr, i, data, size, event, arg); |
| 4809 | break; |
| 4810 | case '6': |
| 4811 | rc += print_ipv6_arg(s, ptr, i, data, size, event, arg); |
| 4812 | break; |
| 4813 | case 'S': |
| 4814 | rc += print_ipsa_arg(s, ptr, i, data, size, event, arg); |
| 4815 | break; |
| 4816 | default: |
| 4817 | return 0; |
| 4818 | } |
| 4819 | |
| 4820 | return rc; |
| 4821 | } |
| 4822 | |
Namhyung Kim | 600da3c | 2012-06-22 17:10:15 +0900 | [diff] [blame] | 4823 | static int is_printable_array(char *p, unsigned int len) |
| 4824 | { |
| 4825 | unsigned int i; |
| 4826 | |
| 4827 | for (i = 0; i < len && p[i]; i++) |
Steven Rostedt (Red Hat) | 5efb9fb | 2013-11-01 17:53:58 -0400 | [diff] [blame] | 4828 | if (!isprint(p[i]) && !isspace(p[i])) |
Namhyung Kim | 600da3c | 2012-06-22 17:10:15 +0900 | [diff] [blame] | 4829 | return 0; |
| 4830 | return 1; |
| 4831 | } |
| 4832 | |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 4833 | void tep_print_field(struct trace_seq *s, void *data, |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 4834 | struct tep_format_field *field) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4835 | { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4836 | unsigned long long val; |
| 4837 | unsigned int offset, len, i; |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 4838 | struct tep_handle *pevent = field->event->pevent; |
Namhyung Kim | be45d40 | 2015-12-23 22:08:41 +0900 | [diff] [blame] | 4839 | |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 4840 | if (field->flags & TEP_FIELD_IS_ARRAY) { |
Namhyung Kim | be45d40 | 2015-12-23 22:08:41 +0900 | [diff] [blame] | 4841 | offset = field->offset; |
| 4842 | len = field->size; |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 4843 | if (field->flags & TEP_FIELD_IS_DYNAMIC) { |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 4844 | val = tep_read_number(pevent, data + offset, len); |
Namhyung Kim | be45d40 | 2015-12-23 22:08:41 +0900 | [diff] [blame] | 4845 | offset = val; |
| 4846 | len = offset >> 16; |
| 4847 | offset &= 0xffff; |
| 4848 | } |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 4849 | if (field->flags & TEP_FIELD_IS_STRING && |
Namhyung Kim | be45d40 | 2015-12-23 22:08:41 +0900 | [diff] [blame] | 4850 | is_printable_array(data + offset, len)) { |
| 4851 | trace_seq_printf(s, "%s", (char *)data + offset); |
| 4852 | } else { |
| 4853 | trace_seq_puts(s, "ARRAY["); |
| 4854 | for (i = 0; i < len; i++) { |
| 4855 | if (i) |
| 4856 | trace_seq_puts(s, ", "); |
| 4857 | trace_seq_printf(s, "%02x", |
| 4858 | *((unsigned char *)data + offset + i)); |
| 4859 | } |
| 4860 | trace_seq_putc(s, ']'); |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 4861 | field->flags &= ~TEP_FIELD_IS_STRING; |
Namhyung Kim | be45d40 | 2015-12-23 22:08:41 +0900 | [diff] [blame] | 4862 | } |
| 4863 | } else { |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 4864 | val = tep_read_number(pevent, data + field->offset, |
| 4865 | field->size); |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 4866 | if (field->flags & TEP_FIELD_IS_POINTER) { |
Namhyung Kim | be45d40 | 2015-12-23 22:08:41 +0900 | [diff] [blame] | 4867 | trace_seq_printf(s, "0x%llx", val); |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 4868 | } else if (field->flags & TEP_FIELD_IS_SIGNED) { |
Namhyung Kim | be45d40 | 2015-12-23 22:08:41 +0900 | [diff] [blame] | 4869 | switch (field->size) { |
| 4870 | case 4: |
| 4871 | /* |
| 4872 | * If field is long then print it in hex. |
| 4873 | * A long usually stores pointers. |
| 4874 | */ |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 4875 | if (field->flags & TEP_FIELD_IS_LONG) |
Namhyung Kim | be45d40 | 2015-12-23 22:08:41 +0900 | [diff] [blame] | 4876 | trace_seq_printf(s, "0x%x", (int)val); |
| 4877 | else |
| 4878 | trace_seq_printf(s, "%d", (int)val); |
| 4879 | break; |
| 4880 | case 2: |
| 4881 | trace_seq_printf(s, "%2d", (short)val); |
| 4882 | break; |
| 4883 | case 1: |
| 4884 | trace_seq_printf(s, "%1d", (char)val); |
| 4885 | break; |
| 4886 | default: |
| 4887 | trace_seq_printf(s, "%lld", val); |
| 4888 | } |
| 4889 | } else { |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 4890 | if (field->flags & TEP_FIELD_IS_LONG) |
Namhyung Kim | be45d40 | 2015-12-23 22:08:41 +0900 | [diff] [blame] | 4891 | trace_seq_printf(s, "0x%llx", val); |
| 4892 | else |
| 4893 | trace_seq_printf(s, "%llu", val); |
| 4894 | } |
| 4895 | } |
| 4896 | } |
| 4897 | |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 4898 | void tep_print_fields(struct trace_seq *s, void *data, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 4899 | int size __maybe_unused, struct tep_event *event) |
Namhyung Kim | be45d40 | 2015-12-23 22:08:41 +0900 | [diff] [blame] | 4900 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 4901 | struct tep_format_field *field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4902 | |
| 4903 | field = event->format.fields; |
| 4904 | while (field) { |
| 4905 | trace_seq_printf(s, " %s=", field->name); |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 4906 | tep_print_field(s, data, field); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4907 | field = field->next; |
| 4908 | } |
| 4909 | } |
| 4910 | |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 4911 | static void pretty_print(struct trace_seq *s, void *data, int size, struct tep_event *event) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4912 | { |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 4913 | struct tep_handle *pevent = event->pevent; |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 4914 | struct tep_print_fmt *print_fmt = &event->print_fmt; |
| 4915 | struct tep_print_arg *arg = print_fmt->args; |
| 4916 | struct tep_print_arg *args = NULL; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4917 | const char *ptr = print_fmt->format; |
| 4918 | unsigned long long val; |
| 4919 | struct func_map *func; |
| 4920 | const char *saveptr; |
Steven Rostedt | 12e5556 | 2013-11-19 18:29:37 -0500 | [diff] [blame] | 4921 | struct trace_seq p; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4922 | char *bprint_fmt = NULL; |
| 4923 | char format[32]; |
| 4924 | int show_func; |
| 4925 | int len_as_arg; |
Adrian Hunter | 0631ca3 | 2018-11-22 13:29:37 +0200 | [diff] [blame] | 4926 | int len_arg = 0; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4927 | int len; |
| 4928 | int ls; |
| 4929 | |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 4930 | if (event->flags & TEP_EVENT_FL_FAILED) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4931 | trace_seq_printf(s, "[FAILED TO PARSE]"); |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 4932 | tep_print_fields(s, data, size, event); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4933 | return; |
| 4934 | } |
| 4935 | |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 4936 | if (event->flags & TEP_EVENT_FL_ISBPRINT) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4937 | bprint_fmt = get_bprint_format(data, size, event); |
| 4938 | args = make_bprint_args(bprint_fmt, data, size, event); |
| 4939 | arg = args; |
| 4940 | ptr = bprint_fmt; |
| 4941 | } |
| 4942 | |
| 4943 | for (; *ptr; ptr++) { |
| 4944 | ls = 0; |
| 4945 | if (*ptr == '\\') { |
| 4946 | ptr++; |
| 4947 | switch (*ptr) { |
| 4948 | case 'n': |
| 4949 | trace_seq_putc(s, '\n'); |
| 4950 | break; |
| 4951 | case 't': |
| 4952 | trace_seq_putc(s, '\t'); |
| 4953 | break; |
| 4954 | case 'r': |
| 4955 | trace_seq_putc(s, '\r'); |
| 4956 | break; |
| 4957 | case '\\': |
| 4958 | trace_seq_putc(s, '\\'); |
| 4959 | break; |
| 4960 | default: |
| 4961 | trace_seq_putc(s, *ptr); |
| 4962 | break; |
| 4963 | } |
| 4964 | |
| 4965 | } else if (*ptr == '%') { |
| 4966 | saveptr = ptr; |
| 4967 | show_func = 0; |
| 4968 | len_as_arg = 0; |
| 4969 | cont_process: |
| 4970 | ptr++; |
| 4971 | switch (*ptr) { |
| 4972 | case '%': |
| 4973 | trace_seq_putc(s, '%'); |
| 4974 | break; |
| 4975 | case '#': |
| 4976 | /* FIXME: need to handle properly */ |
| 4977 | goto cont_process; |
| 4978 | case 'h': |
| 4979 | ls--; |
| 4980 | goto cont_process; |
| 4981 | case 'l': |
| 4982 | ls++; |
| 4983 | goto cont_process; |
| 4984 | case 'L': |
| 4985 | ls = 2; |
| 4986 | goto cont_process; |
| 4987 | case '*': |
| 4988 | /* The argument is the length. */ |
Namhyung Kim | 245c5a1 | 2012-09-07 11:49:45 +0900 | [diff] [blame] | 4989 | if (!arg) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 4990 | do_warning_event(event, "no argument match"); |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 4991 | event->flags |= TEP_EVENT_FL_FAILED; |
Namhyung Kim | 245c5a1 | 2012-09-07 11:49:45 +0900 | [diff] [blame] | 4992 | goto out_failed; |
| 4993 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 4994 | len_arg = eval_num_arg(data, size, event, arg); |
| 4995 | len_as_arg = 1; |
| 4996 | arg = arg->next; |
| 4997 | goto cont_process; |
| 4998 | case '.': |
| 4999 | case 'z': |
| 5000 | case 'Z': |
| 5001 | case '0' ... '9': |
Steven Rostedt | 1d94501 | 2015-08-27 09:46:01 -0400 | [diff] [blame] | 5002 | case '-': |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5003 | goto cont_process; |
| 5004 | case 'p': |
| 5005 | if (pevent->long_size == 4) |
| 5006 | ls = 1; |
| 5007 | else |
| 5008 | ls = 2; |
| 5009 | |
Steven Rostedt (VMware) | 38d70b7 | 2018-01-11 19:47:45 -0500 | [diff] [blame] | 5010 | if (isalnum(ptr[1])) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5011 | ptr++; |
Steven Rostedt (VMware) | 38d70b7 | 2018-01-11 19:47:45 -0500 | [diff] [blame] | 5012 | |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 5013 | if (arg->type == TEP_PRINT_BSTRING) { |
Steven Rostedt (VMware) | 37db96b | 2018-01-11 19:47:46 -0500 | [diff] [blame] | 5014 | trace_seq_puts(s, arg->string.string); |
Steven Rostedt (VMware) | f024cf0 | 2018-12-10 13:45:22 -0500 | [diff] [blame] | 5015 | arg = arg->next; |
Steven Rostedt (VMware) | 37db96b | 2018-01-11 19:47:46 -0500 | [diff] [blame] | 5016 | break; |
| 5017 | } |
| 5018 | |
Steven Rostedt (VMware) | 38d70b7 | 2018-01-11 19:47:45 -0500 | [diff] [blame] | 5019 | if (*ptr == 'F' || *ptr == 'f' || |
| 5020 | *ptr == 'S' || *ptr == 's') { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5021 | show_func = *ptr; |
Steven Rostedt (VMware) | 38d70b7 | 2018-01-11 19:47:45 -0500 | [diff] [blame] | 5022 | } else if (*ptr == 'M' || *ptr == 'm') { |
| 5023 | print_mac_arg(s, *ptr, data, size, event, arg); |
Steven Rostedt | aaf05c7 | 2012-01-09 15:58:09 -0500 | [diff] [blame] | 5024 | arg = arg->next; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5025 | break; |
Steven Rostedt (VMware) | 38d70b7 | 2018-01-11 19:47:45 -0500 | [diff] [blame] | 5026 | } else if (*ptr == 'I' || *ptr == 'i') { |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 5027 | int n; |
| 5028 | |
Steven Rostedt (VMware) | 38d70b7 | 2018-01-11 19:47:45 -0500 | [diff] [blame] | 5029 | n = print_ip_arg(s, ptr, data, size, event, arg); |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 5030 | if (n > 0) { |
Steven Rostedt (VMware) | 38d70b7 | 2018-01-11 19:47:45 -0500 | [diff] [blame] | 5031 | ptr += n - 1; |
David Ahern | 3d199b5 | 2014-12-18 19:11:11 -0700 | [diff] [blame] | 5032 | arg = arg->next; |
| 5033 | break; |
| 5034 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5035 | } |
| 5036 | |
| 5037 | /* fall through */ |
| 5038 | case 'd': |
| 5039 | case 'i': |
| 5040 | case 'x': |
| 5041 | case 'X': |
| 5042 | case 'u': |
Namhyung Kim | 245c5a1 | 2012-09-07 11:49:45 +0900 | [diff] [blame] | 5043 | if (!arg) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 5044 | do_warning_event(event, "no argument match"); |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 5045 | event->flags |= TEP_EVENT_FL_FAILED; |
Namhyung Kim | 245c5a1 | 2012-09-07 11:49:45 +0900 | [diff] [blame] | 5046 | goto out_failed; |
| 5047 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5048 | |
| 5049 | len = ((unsigned long)ptr + 1) - |
| 5050 | (unsigned long)saveptr; |
| 5051 | |
| 5052 | /* should never happen */ |
Namhyung Kim | 245c5a1 | 2012-09-07 11:49:45 +0900 | [diff] [blame] | 5053 | if (len > 31) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 5054 | do_warning_event(event, "bad format!"); |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 5055 | event->flags |= TEP_EVENT_FL_FAILED; |
Namhyung Kim | 245c5a1 | 2012-09-07 11:49:45 +0900 | [diff] [blame] | 5056 | len = 31; |
| 5057 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5058 | |
| 5059 | memcpy(format, saveptr, len); |
| 5060 | format[len] = 0; |
| 5061 | |
| 5062 | val = eval_num_arg(data, size, event, arg); |
| 5063 | arg = arg->next; |
| 5064 | |
| 5065 | if (show_func) { |
| 5066 | func = find_func(pevent, val); |
| 5067 | if (func) { |
| 5068 | trace_seq_puts(s, func->func); |
| 5069 | if (show_func == 'F') |
| 5070 | trace_seq_printf(s, |
| 5071 | "+0x%llx", |
| 5072 | val - func->addr); |
| 5073 | break; |
| 5074 | } |
| 5075 | } |
Steven Rostedt (Red Hat) | a66673a | 2016-02-09 15:40:17 -0500 | [diff] [blame] | 5076 | if (pevent->long_size == 8 && ls == 1 && |
Wolfgang Mauerer | c5b35b7 | 2012-03-22 11:18:21 +0100 | [diff] [blame] | 5077 | sizeof(long) != 8) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5078 | char *p; |
| 5079 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5080 | /* make %l into %ll */ |
Steven Rostedt | 32abc2e | 2015-11-16 17:25:16 -0500 | [diff] [blame] | 5081 | if (ls == 1 && (p = strchr(format, 'l'))) |
Wolfgang Mauerer | c5b35b7 | 2012-03-22 11:18:21 +0100 | [diff] [blame] | 5082 | memmove(p+1, p, strlen(p)+1); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5083 | else if (strcmp(format, "%p") == 0) |
| 5084 | strcpy(format, "0x%llx"); |
Steven Rostedt | 32abc2e | 2015-11-16 17:25:16 -0500 | [diff] [blame] | 5085 | ls = 2; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5086 | } |
| 5087 | switch (ls) { |
| 5088 | case -2: |
| 5089 | if (len_as_arg) |
| 5090 | trace_seq_printf(s, format, len_arg, (char)val); |
| 5091 | else |
| 5092 | trace_seq_printf(s, format, (char)val); |
| 5093 | break; |
| 5094 | case -1: |
| 5095 | if (len_as_arg) |
| 5096 | trace_seq_printf(s, format, len_arg, (short)val); |
| 5097 | else |
| 5098 | trace_seq_printf(s, format, (short)val); |
| 5099 | break; |
| 5100 | case 0: |
| 5101 | if (len_as_arg) |
| 5102 | trace_seq_printf(s, format, len_arg, (int)val); |
| 5103 | else |
| 5104 | trace_seq_printf(s, format, (int)val); |
| 5105 | break; |
| 5106 | case 1: |
| 5107 | if (len_as_arg) |
| 5108 | trace_seq_printf(s, format, len_arg, (long)val); |
| 5109 | else |
| 5110 | trace_seq_printf(s, format, (long)val); |
| 5111 | break; |
| 5112 | case 2: |
| 5113 | if (len_as_arg) |
| 5114 | trace_seq_printf(s, format, len_arg, |
| 5115 | (long long)val); |
| 5116 | else |
| 5117 | trace_seq_printf(s, format, (long long)val); |
| 5118 | break; |
| 5119 | default: |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 5120 | do_warning_event(event, "bad count (%d)", ls); |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 5121 | event->flags |= TEP_EVENT_FL_FAILED; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5122 | } |
| 5123 | break; |
| 5124 | case 's': |
Namhyung Kim | 245c5a1 | 2012-09-07 11:49:45 +0900 | [diff] [blame] | 5125 | if (!arg) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 5126 | do_warning_event(event, "no matching argument"); |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 5127 | event->flags |= TEP_EVENT_FL_FAILED; |
Namhyung Kim | 245c5a1 | 2012-09-07 11:49:45 +0900 | [diff] [blame] | 5128 | goto out_failed; |
| 5129 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5130 | |
| 5131 | len = ((unsigned long)ptr + 1) - |
| 5132 | (unsigned long)saveptr; |
| 5133 | |
| 5134 | /* should never happen */ |
Namhyung Kim | 245c5a1 | 2012-09-07 11:49:45 +0900 | [diff] [blame] | 5135 | if (len > 31) { |
Namhyung Kim | 3388cc3 | 2014-03-19 10:22:53 +0900 | [diff] [blame] | 5136 | do_warning_event(event, "bad format!"); |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 5137 | event->flags |= TEP_EVENT_FL_FAILED; |
Namhyung Kim | 245c5a1 | 2012-09-07 11:49:45 +0900 | [diff] [blame] | 5138 | len = 31; |
| 5139 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5140 | |
| 5141 | memcpy(format, saveptr, len); |
| 5142 | format[len] = 0; |
| 5143 | if (!len_as_arg) |
| 5144 | len_arg = -1; |
Steven Rostedt | 12e5556 | 2013-11-19 18:29:37 -0500 | [diff] [blame] | 5145 | /* Use helper trace_seq */ |
| 5146 | trace_seq_init(&p); |
| 5147 | print_str_arg(&p, data, size, event, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5148 | format, len_arg, arg); |
Steven Rostedt | 12e5556 | 2013-11-19 18:29:37 -0500 | [diff] [blame] | 5149 | trace_seq_terminate(&p); |
| 5150 | trace_seq_puts(s, p.buffer); |
Steven Rostedt | de04f86 | 2014-04-22 19:23:30 -0400 | [diff] [blame] | 5151 | trace_seq_destroy(&p); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5152 | arg = arg->next; |
| 5153 | break; |
| 5154 | default: |
| 5155 | trace_seq_printf(s, ">%c<", *ptr); |
| 5156 | |
| 5157 | } |
| 5158 | } else |
| 5159 | trace_seq_putc(s, *ptr); |
| 5160 | } |
| 5161 | |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 5162 | if (event->flags & TEP_EVENT_FL_FAILED) { |
Namhyung Kim | 245c5a1 | 2012-09-07 11:49:45 +0900 | [diff] [blame] | 5163 | out_failed: |
| 5164 | trace_seq_printf(s, "[FAILED TO PARSE]"); |
| 5165 | } |
| 5166 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5167 | if (args) { |
| 5168 | free_args(args); |
| 5169 | free(bprint_fmt); |
| 5170 | } |
| 5171 | } |
| 5172 | |
| 5173 | /** |
Tzvetomir Stoyanov | 55c34ae | 2019-04-01 12:43:16 -0400 | [diff] [blame] | 5174 | * tep_data_latency_format - parse the data for the latency format |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5175 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5176 | * @s: the trace_seq to write to |
Namhyung Kim | 16e6b8f | 2012-04-23 13:58:35 +0900 | [diff] [blame] | 5177 | * @record: the record to read from |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5178 | * |
| 5179 | * This parses out the Latency format (interrupts disabled, |
| 5180 | * need rescheduling, in hard/soft interrupt, preempt count |
| 5181 | * and lock depth) and places it into the trace_seq. |
| 5182 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5183 | void tep_data_latency_format(struct tep_handle *tep, |
Tzvetomir Stoyanov | 55c34ae | 2019-04-01 12:43:16 -0400 | [diff] [blame] | 5184 | struct trace_seq *s, struct tep_record *record) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5185 | { |
| 5186 | static int check_lock_depth = 1; |
Steven Rostedt | 0866a97 | 2012-05-22 14:52:40 +0900 | [diff] [blame] | 5187 | static int check_migrate_disable = 1; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5188 | static int lock_depth_exists; |
Steven Rostedt | 0866a97 | 2012-05-22 14:52:40 +0900 | [diff] [blame] | 5189 | static int migrate_disable_exists; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5190 | unsigned int lat_flags; |
| 5191 | unsigned int pc; |
Adrian Hunter | 0631ca3 | 2018-11-22 13:29:37 +0200 | [diff] [blame] | 5192 | int lock_depth = 0; |
| 5193 | int migrate_disable = 0; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5194 | int hardirq; |
| 5195 | int softirq; |
| 5196 | void *data = record->data; |
| 5197 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5198 | lat_flags = parse_common_flags(tep, data); |
| 5199 | pc = parse_common_pc(tep, data); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5200 | /* lock_depth may not always exist */ |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5201 | if (lock_depth_exists) |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5202 | lock_depth = parse_common_lock_depth(tep, data); |
Steven Rostedt | 0866a97 | 2012-05-22 14:52:40 +0900 | [diff] [blame] | 5203 | else if (check_lock_depth) { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5204 | lock_depth = parse_common_lock_depth(tep, data); |
Steven Rostedt | 0866a97 | 2012-05-22 14:52:40 +0900 | [diff] [blame] | 5205 | if (lock_depth < 0) |
| 5206 | check_lock_depth = 0; |
| 5207 | else |
| 5208 | lock_depth_exists = 1; |
| 5209 | } |
| 5210 | |
| 5211 | /* migrate_disable may not always exist */ |
| 5212 | if (migrate_disable_exists) |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5213 | migrate_disable = parse_common_migrate_disable(tep, data); |
Steven Rostedt | 0866a97 | 2012-05-22 14:52:40 +0900 | [diff] [blame] | 5214 | else if (check_migrate_disable) { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5215 | migrate_disable = parse_common_migrate_disable(tep, data); |
Steven Rostedt | 0866a97 | 2012-05-22 14:52:40 +0900 | [diff] [blame] | 5216 | if (migrate_disable < 0) |
| 5217 | check_migrate_disable = 0; |
| 5218 | else |
| 5219 | migrate_disable_exists = 1; |
| 5220 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5221 | |
| 5222 | hardirq = lat_flags & TRACE_FLAG_HARDIRQ; |
| 5223 | softirq = lat_flags & TRACE_FLAG_SOFTIRQ; |
| 5224 | |
| 5225 | trace_seq_printf(s, "%c%c%c", |
| 5226 | (lat_flags & TRACE_FLAG_IRQS_OFF) ? 'd' : |
| 5227 | (lat_flags & TRACE_FLAG_IRQS_NOSUPPORT) ? |
| 5228 | 'X' : '.', |
| 5229 | (lat_flags & TRACE_FLAG_NEED_RESCHED) ? |
| 5230 | 'N' : '.', |
| 5231 | (hardirq && softirq) ? 'H' : |
| 5232 | hardirq ? 'h' : softirq ? 's' : '.'); |
| 5233 | |
| 5234 | if (pc) |
| 5235 | trace_seq_printf(s, "%x", pc); |
| 5236 | else |
| 5237 | trace_seq_putc(s, '.'); |
| 5238 | |
Steven Rostedt | 0866a97 | 2012-05-22 14:52:40 +0900 | [diff] [blame] | 5239 | if (migrate_disable_exists) { |
| 5240 | if (migrate_disable < 0) |
| 5241 | trace_seq_putc(s, '.'); |
| 5242 | else |
| 5243 | trace_seq_printf(s, "%d", migrate_disable); |
| 5244 | } |
| 5245 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5246 | if (lock_depth_exists) { |
| 5247 | if (lock_depth < 0) |
| 5248 | trace_seq_putc(s, '.'); |
| 5249 | else |
| 5250 | trace_seq_printf(s, "%d", lock_depth); |
| 5251 | } |
| 5252 | |
| 5253 | trace_seq_terminate(s); |
| 5254 | } |
| 5255 | |
| 5256 | /** |
Tzvetomir Stoyanov (VMware) | dc05ebf | 2018-08-08 14:03:03 -0400 | [diff] [blame] | 5257 | * tep_data_type - parse out the given event type |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5258 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5259 | * @rec: the record to read from |
| 5260 | * |
| 5261 | * This returns the event id from the @rec. |
| 5262 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5263 | int tep_data_type(struct tep_handle *tep, struct tep_record *rec) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5264 | { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5265 | return trace_parse_common_type(tep, rec->data); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | /** |
Tzvetomir Stoyanov (VMware) | dc05ebf | 2018-08-08 14:03:03 -0400 | [diff] [blame] | 5269 | * tep_data_pid - parse the PID from record |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5270 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5271 | * @rec: the record to parse |
| 5272 | * |
Steven Rostedt | c52d9e4 | 2016-11-22 11:31:58 -0500 | [diff] [blame] | 5273 | * This returns the PID from a record. |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5274 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5275 | int tep_data_pid(struct tep_handle *tep, struct tep_record *rec) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5276 | { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5277 | return parse_common_pid(tep, rec->data); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5278 | } |
| 5279 | |
| 5280 | /** |
Tzvetomir Stoyanov (VMware) | dc05ebf | 2018-08-08 14:03:03 -0400 | [diff] [blame] | 5281 | * tep_data_preempt_count - parse the preempt count from the record |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5282 | * @tep: a handle to the trace event parser context |
Steven Rostedt | c52d9e4 | 2016-11-22 11:31:58 -0500 | [diff] [blame] | 5283 | * @rec: the record to parse |
| 5284 | * |
| 5285 | * This returns the preempt count from a record. |
| 5286 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5287 | int tep_data_preempt_count(struct tep_handle *tep, struct tep_record *rec) |
Steven Rostedt | c52d9e4 | 2016-11-22 11:31:58 -0500 | [diff] [blame] | 5288 | { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5289 | return parse_common_pc(tep, rec->data); |
Steven Rostedt | c52d9e4 | 2016-11-22 11:31:58 -0500 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | /** |
Tzvetomir Stoyanov (VMware) | dc05ebf | 2018-08-08 14:03:03 -0400 | [diff] [blame] | 5293 | * tep_data_flags - parse the latency flags from the record |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5294 | * @tep: a handle to the trace event parser context |
Steven Rostedt | c52d9e4 | 2016-11-22 11:31:58 -0500 | [diff] [blame] | 5295 | * @rec: the record to parse |
| 5296 | * |
| 5297 | * This returns the latency flags from a record. |
| 5298 | * |
| 5299 | * Use trace_flag_type enum for the flags (see event-parse.h). |
| 5300 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5301 | int tep_data_flags(struct tep_handle *tep, struct tep_record *rec) |
Steven Rostedt | c52d9e4 | 2016-11-22 11:31:58 -0500 | [diff] [blame] | 5302 | { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5303 | return parse_common_flags(tep, rec->data); |
Steven Rostedt | c52d9e4 | 2016-11-22 11:31:58 -0500 | [diff] [blame] | 5304 | } |
| 5305 | |
| 5306 | /** |
Tzvetomir Stoyanov (VMware) | dc05ebf | 2018-08-08 14:03:03 -0400 | [diff] [blame] | 5307 | * tep_data_comm_from_pid - return the command line from PID |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5308 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5309 | * @pid: the PID of the task to search for |
| 5310 | * |
| 5311 | * This returns a pointer to the command line that has the given |
| 5312 | * @pid. |
| 5313 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5314 | const char *tep_data_comm_from_pid(struct tep_handle *tep, int pid) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5315 | { |
| 5316 | const char *comm; |
| 5317 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5318 | comm = find_cmdline(tep, pid); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5319 | return comm; |
| 5320 | } |
| 5321 | |
Tzvetomir Stoyanov | 2e4318a | 2018-11-30 23:08:09 -0500 | [diff] [blame] | 5322 | static struct tep_cmdline * |
| 5323 | pid_from_cmdlist(struct tep_handle *pevent, const char *comm, struct tep_cmdline *next) |
Steven Rostedt (Red Hat) | 2771984 | 2015-03-24 09:57:52 -0400 | [diff] [blame] | 5324 | { |
| 5325 | struct cmdline_list *cmdlist = (struct cmdline_list *)next; |
| 5326 | |
| 5327 | if (cmdlist) |
| 5328 | cmdlist = cmdlist->next; |
| 5329 | else |
| 5330 | cmdlist = pevent->cmdlist; |
| 5331 | |
| 5332 | while (cmdlist && strcmp(cmdlist->comm, comm) != 0) |
| 5333 | cmdlist = cmdlist->next; |
| 5334 | |
Tzvetomir Stoyanov | 2e4318a | 2018-11-30 23:08:09 -0500 | [diff] [blame] | 5335 | return (struct tep_cmdline *)cmdlist; |
Steven Rostedt (Red Hat) | 2771984 | 2015-03-24 09:57:52 -0400 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | /** |
Tzvetomir Stoyanov (VMware) | dc05ebf | 2018-08-08 14:03:03 -0400 | [diff] [blame] | 5339 | * tep_data_pid_from_comm - return the pid from a given comm |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5340 | * @tep: a handle to the trace event parser context |
Steven Rostedt (Red Hat) | 2771984 | 2015-03-24 09:57:52 -0400 | [diff] [blame] | 5341 | * @comm: the cmdline to find the pid from |
| 5342 | * @next: the cmdline structure to find the next comm |
| 5343 | * |
| 5344 | * This returns the cmdline structure that holds a pid for a given |
| 5345 | * comm, or NULL if none found. As there may be more than one pid for |
| 5346 | * a given comm, the result of this call can be passed back into |
Ingo Molnar | 3e449f7 | 2018-12-03 11:22:00 +0100 | [diff] [blame] | 5347 | * a recurring call in the @next parameter, and then it will find the |
Steven Rostedt (Red Hat) | 2771984 | 2015-03-24 09:57:52 -0400 | [diff] [blame] | 5348 | * next pid. |
Ingo Molnar | 3e449f7 | 2018-12-03 11:22:00 +0100 | [diff] [blame] | 5349 | * Also, it does a linear search, so it may be slow. |
Steven Rostedt (Red Hat) | 2771984 | 2015-03-24 09:57:52 -0400 | [diff] [blame] | 5350 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5351 | struct tep_cmdline *tep_data_pid_from_comm(struct tep_handle *tep, const char *comm, |
Tzvetomir Stoyanov | 2e4318a | 2018-11-30 23:08:09 -0500 | [diff] [blame] | 5352 | struct tep_cmdline *next) |
Steven Rostedt (Red Hat) | 2771984 | 2015-03-24 09:57:52 -0400 | [diff] [blame] | 5353 | { |
Tzvetomir Stoyanov | 2e4318a | 2018-11-30 23:08:09 -0500 | [diff] [blame] | 5354 | struct tep_cmdline *cmdline; |
Steven Rostedt (Red Hat) | 2771984 | 2015-03-24 09:57:52 -0400 | [diff] [blame] | 5355 | |
| 5356 | /* |
| 5357 | * If the cmdlines have not been converted yet, then use |
| 5358 | * the list. |
| 5359 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5360 | if (!tep->cmdlines) |
| 5361 | return pid_from_cmdlist(tep, comm, next); |
Steven Rostedt (Red Hat) | 2771984 | 2015-03-24 09:57:52 -0400 | [diff] [blame] | 5362 | |
| 5363 | if (next) { |
| 5364 | /* |
| 5365 | * The next pointer could have been still from |
| 5366 | * a previous call before cmdlines were created |
| 5367 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5368 | if (next < tep->cmdlines || |
| 5369 | next >= tep->cmdlines + tep->cmdline_count) |
Steven Rostedt (Red Hat) | 2771984 | 2015-03-24 09:57:52 -0400 | [diff] [blame] | 5370 | next = NULL; |
| 5371 | else |
| 5372 | cmdline = next++; |
| 5373 | } |
| 5374 | |
| 5375 | if (!next) |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5376 | cmdline = tep->cmdlines; |
Steven Rostedt (Red Hat) | 2771984 | 2015-03-24 09:57:52 -0400 | [diff] [blame] | 5377 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5378 | while (cmdline < tep->cmdlines + tep->cmdline_count) { |
Steven Rostedt (Red Hat) | 2771984 | 2015-03-24 09:57:52 -0400 | [diff] [blame] | 5379 | if (strcmp(cmdline->comm, comm) == 0) |
| 5380 | return cmdline; |
| 5381 | cmdline++; |
| 5382 | } |
| 5383 | return NULL; |
| 5384 | } |
| 5385 | |
| 5386 | /** |
Tzvetomir Stoyanov (VMware) | dc05ebf | 2018-08-08 14:03:03 -0400 | [diff] [blame] | 5387 | * tep_cmdline_pid - return the pid associated to a given cmdline |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5388 | * @tep: a handle to the trace event parser context |
Steven Rostedt (Red Hat) | 2771984 | 2015-03-24 09:57:52 -0400 | [diff] [blame] | 5389 | * @cmdline: The cmdline structure to get the pid from |
| 5390 | * |
| 5391 | * Returns the pid for a give cmdline. If @cmdline is NULL, then |
| 5392 | * -1 is returned. |
| 5393 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5394 | int tep_cmdline_pid(struct tep_handle *tep, struct tep_cmdline *cmdline) |
Steven Rostedt (Red Hat) | 2771984 | 2015-03-24 09:57:52 -0400 | [diff] [blame] | 5395 | { |
| 5396 | struct cmdline_list *cmdlist = (struct cmdline_list *)cmdline; |
| 5397 | |
| 5398 | if (!cmdline) |
| 5399 | return -1; |
| 5400 | |
| 5401 | /* |
| 5402 | * If cmdlines have not been created yet, or cmdline is |
| 5403 | * not part of the array, then treat it as a cmdlist instead. |
| 5404 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5405 | if (!tep->cmdlines || |
| 5406 | cmdline < tep->cmdlines || |
| 5407 | cmdline >= tep->cmdlines + tep->cmdline_count) |
Steven Rostedt (Red Hat) | 2771984 | 2015-03-24 09:57:52 -0400 | [diff] [blame] | 5408 | return cmdlist->pid; |
| 5409 | |
| 5410 | return cmdline->pid; |
| 5411 | } |
| 5412 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5413 | /** |
Tzvetomir Stoyanov (VMware) | dc05ebf | 2018-08-08 14:03:03 -0400 | [diff] [blame] | 5414 | * tep_event_info - parse the data into the print format |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5415 | * @s: the trace_seq to write to |
| 5416 | * @event: the handle to the event |
Namhyung Kim | 16e6b8f | 2012-04-23 13:58:35 +0900 | [diff] [blame] | 5417 | * @record: the record to read from |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5418 | * |
| 5419 | * This parses the raw @data using the given @event information and |
| 5420 | * writes the print format into the trace_seq. |
| 5421 | */ |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 5422 | void tep_event_info(struct trace_seq *s, struct tep_event *event, |
Tzvetomir Stoyanov (VMware) | 4d5c58b | 2018-08-08 14:02:49 -0400 | [diff] [blame] | 5423 | struct tep_record *record) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5424 | { |
| 5425 | int print_pretty = 1; |
| 5426 | |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 5427 | if (event->pevent->print_raw || (event->flags & TEP_EVENT_FL_PRINTRAW)) |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 5428 | tep_print_fields(s, record->data, record->size, event); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5429 | else { |
| 5430 | |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 5431 | if (event->handler && !(event->flags & TEP_EVENT_FL_NOHANDLE)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5432 | print_pretty = event->handler(s, record, event, |
| 5433 | event->context); |
| 5434 | |
| 5435 | if (print_pretty) |
| 5436 | pretty_print(s, record->data, record->size, event); |
| 5437 | } |
| 5438 | |
| 5439 | trace_seq_terminate(s); |
| 5440 | } |
| 5441 | |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 5442 | static bool is_timestamp_in_us(char *trace_clock, bool use_trace_clock) |
| 5443 | { |
Tzvetomir Stoyanov | 44e92f8 | 2018-11-28 14:55:52 -0500 | [diff] [blame] | 5444 | if (!trace_clock || !use_trace_clock) |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 5445 | return true; |
| 5446 | |
| 5447 | if (!strcmp(trace_clock, "local") || !strcmp(trace_clock, "global") |
Steven Rostedt (VMware) | fed33e9 | 2019-04-01 12:43:07 -0400 | [diff] [blame] | 5448 | || !strcmp(trace_clock, "uptime") || !strcmp(trace_clock, "perf") |
| 5449 | || !strncmp(trace_clock, "mono", 4)) |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 5450 | return true; |
| 5451 | |
| 5452 | /* trace_clock is setting in tsc or counter mode */ |
| 5453 | return false; |
| 5454 | } |
| 5455 | |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5456 | /** |
Tzvetomir Stoyanov (VMware) | 610e1e4 | 2018-08-08 14:03:05 -0400 | [diff] [blame] | 5457 | * tep_find_event_by_record - return the event from a given record |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5458 | * @tep: a handle to the trace event parser context |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5459 | * @record: The record to get the event from |
| 5460 | * |
| 5461 | * Returns the associated event for a given record, or NULL if non is |
| 5462 | * is found. |
| 5463 | */ |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 5464 | struct tep_event * |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5465 | tep_find_event_by_record(struct tep_handle *tep, struct tep_record *record) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5466 | { |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5467 | int type; |
| 5468 | |
| 5469 | if (record->size < 0) { |
| 5470 | do_warning("ug! negative record size %d", record->size); |
| 5471 | return NULL; |
| 5472 | } |
| 5473 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5474 | type = trace_parse_common_type(tep, record->data); |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5475 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5476 | return tep_find_event(tep, type); |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5477 | } |
| 5478 | |
| 5479 | /** |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 5480 | * tep_print_event_task - Write the event task comm, pid and CPU |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5481 | * @tep: a handle to the trace event parser context |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5482 | * @s: the trace_seq to write to |
| 5483 | * @event: the handle to the record's event |
| 5484 | * @record: The record to get the event from |
| 5485 | * |
| 5486 | * Writes the tasks comm, pid and CPU to @s. |
| 5487 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5488 | void tep_print_event_task(struct tep_handle *tep, struct trace_seq *s, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 5489 | struct tep_event *event, |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 5490 | struct tep_record *record) |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5491 | { |
| 5492 | void *data = record->data; |
| 5493 | const char *comm; |
| 5494 | int pid; |
| 5495 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5496 | pid = parse_common_pid(tep, data); |
| 5497 | comm = find_cmdline(tep, pid); |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5498 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5499 | if (tep->latency_format) |
| 5500 | trace_seq_printf(s, "%8.8s-%-5d %3d", comm, pid, record->cpu); |
| 5501 | else |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5502 | trace_seq_printf(s, "%16s-%-5d [%03d]", comm, pid, record->cpu); |
| 5503 | } |
| 5504 | |
| 5505 | /** |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 5506 | * tep_print_event_time - Write the event timestamp |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5507 | * @tep: a handle to the trace event parser context |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5508 | * @s: the trace_seq to write to |
| 5509 | * @event: the handle to the record's event |
| 5510 | * @record: The record to get the event from |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5511 | * @use_trace_clock: Set to parse according to the @tep->trace_clock |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5512 | * |
| 5513 | * Writes the timestamp of the record into @s. |
| 5514 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5515 | void tep_print_event_time(struct tep_handle *tep, struct trace_seq *s, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 5516 | struct tep_event *event, |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 5517 | struct tep_record *record, |
| 5518 | bool use_trace_clock) |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5519 | { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5520 | unsigned long secs; |
| 5521 | unsigned long usecs; |
Steven Rostedt | 4dc1024 | 2012-04-06 00:47:57 +0200 | [diff] [blame] | 5522 | unsigned long nsecs; |
Steven Rostedt | 4dc1024 | 2012-04-06 00:47:57 +0200 | [diff] [blame] | 5523 | int p; |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 5524 | bool use_usec_format; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5525 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5526 | use_usec_format = is_timestamp_in_us(tep->trace_clock, use_trace_clock); |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 5527 | if (use_usec_format) { |
Steven Rostedt | bb5a731 | 2016-11-22 15:00:31 -0300 | [diff] [blame] | 5528 | secs = record->ts / NSEC_PER_SEC; |
| 5529 | nsecs = record->ts - secs * NSEC_PER_SEC; |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 5530 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5531 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5532 | if (tep->latency_format) { |
| 5533 | tep_data_latency_format(tep, s, record); |
Steven Rostedt | 4f3c8876 | 2016-03-23 10:16:28 -0400 | [diff] [blame] | 5534 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5535 | |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 5536 | if (use_usec_format) { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5537 | if (tep->flags & TEP_NSEC_OUTPUT) { |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 5538 | usecs = nsecs; |
| 5539 | p = 9; |
| 5540 | } else { |
Steven Rostedt | bb5a731 | 2016-11-22 15:00:31 -0300 | [diff] [blame] | 5541 | usecs = (nsecs + 500) / NSEC_PER_USEC; |
Chaos.Chen | 21a3010 | 2016-02-09 15:40:14 -0500 | [diff] [blame] | 5542 | /* To avoid usecs larger than 1 sec */ |
Steven Rostedt | bb5a731 | 2016-11-22 15:00:31 -0300 | [diff] [blame] | 5543 | if (usecs >= USEC_PER_SEC) { |
| 5544 | usecs -= USEC_PER_SEC; |
Chaos.Chen | 21a3010 | 2016-02-09 15:40:14 -0500 | [diff] [blame] | 5545 | secs++; |
| 5546 | } |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 5547 | p = 6; |
| 5548 | } |
Steven Rostedt | 4dc1024 | 2012-04-06 00:47:57 +0200 | [diff] [blame] | 5549 | |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5550 | trace_seq_printf(s, " %5lu.%0*lu:", secs, p, usecs); |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 5551 | } else |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5552 | trace_seq_printf(s, " %12llu:", record->ts); |
| 5553 | } |
| 5554 | |
| 5555 | /** |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 5556 | * tep_print_event_data - Write the event data section |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5557 | * @tep: a handle to the trace event parser context |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5558 | * @s: the trace_seq to write to |
| 5559 | * @event: the handle to the record's event |
| 5560 | * @record: The record to get the event from |
| 5561 | * |
| 5562 | * Writes the parsing of the record's data to @s. |
| 5563 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5564 | void tep_print_event_data(struct tep_handle *tep, struct trace_seq *s, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 5565 | struct tep_event *event, |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 5566 | struct tep_record *record) |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5567 | { |
| 5568 | static const char *spaces = " "; /* 20 spaces */ |
| 5569 | int len; |
| 5570 | |
| 5571 | trace_seq_printf(s, " %s: ", event->name); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5572 | |
| 5573 | /* Space out the event names evenly. */ |
| 5574 | len = strlen(event->name); |
| 5575 | if (len < 20) |
| 5576 | trace_seq_printf(s, "%.*s", 20 - len, spaces); |
| 5577 | |
Tzvetomir Stoyanov (VMware) | 4d5c58b | 2018-08-08 14:02:49 -0400 | [diff] [blame] | 5578 | tep_event_info(s, event, record); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5579 | } |
| 5580 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5581 | void tep_print_event(struct tep_handle *tep, struct trace_seq *s, |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 5582 | struct tep_record *record, bool use_trace_clock) |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5583 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 5584 | struct tep_event *event; |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5585 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5586 | event = tep_find_event_by_record(tep, record); |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5587 | if (!event) { |
Steven Rostedt (VMware) | e877372 | 2018-01-11 19:47:47 -0500 | [diff] [blame] | 5588 | int i; |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5589 | int type = trace_parse_common_type(tep, record->data); |
Steven Rostedt (VMware) | e877372 | 2018-01-11 19:47:47 -0500 | [diff] [blame] | 5590 | |
| 5591 | do_warning("ug! no event found for type %d", type); |
| 5592 | trace_seq_printf(s, "[UNKNOWN TYPE %d]", type); |
| 5593 | for (i = 0; i < record->size; i++) |
| 5594 | trace_seq_printf(s, " %02x", |
| 5595 | ((unsigned char *)record->data)[i]); |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5596 | return; |
| 5597 | } |
| 5598 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 5599 | tep_print_event_task(tep, s, event, record); |
| 5600 | tep_print_event_time(tep, s, event, record, use_trace_clock); |
| 5601 | tep_print_event_data(tep, s, event, record); |
Steven Rostedt | a674533 | 2016-02-29 09:01:28 -0500 | [diff] [blame] | 5602 | } |
| 5603 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5604 | static int events_id_cmp(const void *a, const void *b) |
| 5605 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 5606 | struct tep_event * const * ea = a; |
| 5607 | struct tep_event * const * eb = b; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5608 | |
| 5609 | if ((*ea)->id < (*eb)->id) |
| 5610 | return -1; |
| 5611 | |
| 5612 | if ((*ea)->id > (*eb)->id) |
| 5613 | return 1; |
| 5614 | |
| 5615 | return 0; |
| 5616 | } |
| 5617 | |
| 5618 | static int events_name_cmp(const void *a, const void *b) |
| 5619 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 5620 | struct tep_event * const * ea = a; |
| 5621 | struct tep_event * const * eb = b; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5622 | int res; |
| 5623 | |
| 5624 | res = strcmp((*ea)->name, (*eb)->name); |
| 5625 | if (res) |
| 5626 | return res; |
| 5627 | |
| 5628 | res = strcmp((*ea)->system, (*eb)->system); |
| 5629 | if (res) |
| 5630 | return res; |
| 5631 | |
| 5632 | return events_id_cmp(a, b); |
| 5633 | } |
| 5634 | |
| 5635 | static int events_system_cmp(const void *a, const void *b) |
| 5636 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 5637 | struct tep_event * const * ea = a; |
| 5638 | struct tep_event * const * eb = b; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5639 | int res; |
| 5640 | |
| 5641 | res = strcmp((*ea)->system, (*eb)->system); |
| 5642 | if (res) |
| 5643 | return res; |
| 5644 | |
| 5645 | res = strcmp((*ea)->name, (*eb)->name); |
| 5646 | if (res) |
| 5647 | return res; |
| 5648 | |
| 5649 | return events_id_cmp(a, b); |
| 5650 | } |
| 5651 | |
Tzvetomir Stoyanov | 6699ed7 | 2019-04-01 12:43:08 -0400 | [diff] [blame] | 5652 | static struct tep_event **list_events_copy(struct tep_handle *tep) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5653 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 5654 | struct tep_event **events; |
Tzvetomir Stoyanov | 6699ed7 | 2019-04-01 12:43:08 -0400 | [diff] [blame] | 5655 | |
| 5656 | if (!tep) |
| 5657 | return NULL; |
| 5658 | |
| 5659 | events = malloc(sizeof(*events) * (tep->nr_events + 1)); |
| 5660 | if (!events) |
| 5661 | return NULL; |
| 5662 | |
| 5663 | memcpy(events, tep->events, sizeof(*events) * tep->nr_events); |
| 5664 | events[tep->nr_events] = NULL; |
| 5665 | return events; |
| 5666 | } |
| 5667 | |
| 5668 | static void list_events_sort(struct tep_event **events, int nr_events, |
| 5669 | enum tep_event_sort_type sort_type) |
| 5670 | { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5671 | int (*sort)(const void *a, const void *b); |
| 5672 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5673 | switch (sort_type) { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5674 | case TEP_EVENT_SORT_ID: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5675 | sort = events_id_cmp; |
| 5676 | break; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5677 | case TEP_EVENT_SORT_NAME: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5678 | sort = events_name_cmp; |
| 5679 | break; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5680 | case TEP_EVENT_SORT_SYSTEM: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5681 | sort = events_system_cmp; |
| 5682 | break; |
| 5683 | default: |
Tzvetomir Stoyanov | 6699ed7 | 2019-04-01 12:43:08 -0400 | [diff] [blame] | 5684 | sort = NULL; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5685 | } |
| 5686 | |
Tzvetomir Stoyanov | 6699ed7 | 2019-04-01 12:43:08 -0400 | [diff] [blame] | 5687 | if (sort) |
| 5688 | qsort(events, nr_events, sizeof(*events), sort); |
| 5689 | } |
| 5690 | |
| 5691 | /** |
| 5692 | * tep_list_events - Get events, sorted by given criteria. |
| 5693 | * @tep: a handle to the tep context |
| 5694 | * @sort_type: desired sort order of the events in the array |
| 5695 | * |
| 5696 | * Returns an array of pointers to all events, sorted by the given |
| 5697 | * @sort_type criteria. The last element of the array is NULL. The returned |
| 5698 | * memory must not be freed, it is managed by the library. |
| 5699 | * The function is not thread safe. |
| 5700 | */ |
| 5701 | struct tep_event **tep_list_events(struct tep_handle *tep, |
| 5702 | enum tep_event_sort_type sort_type) |
| 5703 | { |
| 5704 | struct tep_event **events; |
| 5705 | |
| 5706 | if (!tep) |
| 5707 | return NULL; |
| 5708 | |
| 5709 | events = tep->sort_events; |
| 5710 | if (events && tep->last_type == sort_type) |
| 5711 | return events; |
| 5712 | |
| 5713 | if (!events) { |
| 5714 | events = list_events_copy(tep); |
| 5715 | if (!events) |
| 5716 | return NULL; |
| 5717 | |
| 5718 | tep->sort_events = events; |
| 5719 | |
| 5720 | /* the internal events are sorted by id */ |
| 5721 | if (sort_type == TEP_EVENT_SORT_ID) { |
| 5722 | tep->last_type = sort_type; |
| 5723 | return events; |
| 5724 | } |
| 5725 | } |
| 5726 | |
| 5727 | list_events_sort(events, tep->nr_events, sort_type); |
| 5728 | tep->last_type = sort_type; |
| 5729 | |
| 5730 | return events; |
| 5731 | } |
| 5732 | |
| 5733 | |
| 5734 | /** |
| 5735 | * tep_list_events_copy - Thread safe version of tep_list_events() |
| 5736 | * @tep: a handle to the tep context |
| 5737 | * @sort_type: desired sort order of the events in the array |
| 5738 | * |
| 5739 | * Returns an array of pointers to all events, sorted by the given |
| 5740 | * @sort_type criteria. The last element of the array is NULL. The returned |
| 5741 | * array is newly allocated inside the function and must be freed by the caller |
| 5742 | */ |
| 5743 | struct tep_event **tep_list_events_copy(struct tep_handle *tep, |
| 5744 | enum tep_event_sort_type sort_type) |
| 5745 | { |
| 5746 | struct tep_event **events; |
| 5747 | |
| 5748 | if (!tep) |
| 5749 | return NULL; |
| 5750 | |
| 5751 | events = list_events_copy(tep); |
| 5752 | if (!events) |
| 5753 | return NULL; |
| 5754 | |
| 5755 | /* the internal events are sorted by id */ |
| 5756 | if (sort_type == TEP_EVENT_SORT_ID) |
| 5757 | return events; |
| 5758 | |
| 5759 | list_events_sort(events, tep->nr_events, sort_type); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5760 | |
| 5761 | return events; |
| 5762 | } |
| 5763 | |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 5764 | static struct tep_format_field ** |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5765 | get_event_fields(const char *type, const char *name, |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 5766 | int count, struct tep_format_field *list) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5767 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 5768 | struct tep_format_field **fields; |
| 5769 | struct tep_format_field *field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5770 | int i = 0; |
| 5771 | |
Arnaldo Carvalho de Melo | a6d2a61 | 2012-09-12 17:30:50 -0300 | [diff] [blame] | 5772 | fields = malloc(sizeof(*fields) * (count + 1)); |
| 5773 | if (!fields) |
| 5774 | return NULL; |
| 5775 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5776 | for (field = list; field; field = field->next) { |
| 5777 | fields[i++] = field; |
| 5778 | if (i == count + 1) { |
| 5779 | do_warning("event %s has more %s fields than specified", |
| 5780 | name, type); |
| 5781 | i--; |
| 5782 | break; |
| 5783 | } |
| 5784 | } |
| 5785 | |
| 5786 | if (i != count) |
| 5787 | do_warning("event %s has less %s fields than specified", |
| 5788 | name, type); |
| 5789 | |
| 5790 | fields[i] = NULL; |
| 5791 | |
| 5792 | return fields; |
| 5793 | } |
| 5794 | |
| 5795 | /** |
Tzvetomir Stoyanov (VMware) | c99eeaf | 2018-08-08 14:03:08 -0400 | [diff] [blame] | 5796 | * tep_event_common_fields - return a list of common fields for an event |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5797 | * @event: the event to return the common fields of. |
| 5798 | * |
| 5799 | * Returns an allocated array of fields. The last item in the array is NULL. |
| 5800 | * The array must be freed with free(). |
| 5801 | */ |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 5802 | struct tep_format_field **tep_event_common_fields(struct tep_event *event) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5803 | { |
| 5804 | return get_event_fields("common", event->name, |
| 5805 | event->format.nr_common, |
| 5806 | event->format.common_fields); |
| 5807 | } |
| 5808 | |
| 5809 | /** |
Tzvetomir Stoyanov (VMware) | c99eeaf | 2018-08-08 14:03:08 -0400 | [diff] [blame] | 5810 | * tep_event_fields - return a list of event specific fields for an event |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5811 | * @event: the event to return the fields of. |
| 5812 | * |
| 5813 | * Returns an allocated array of fields. The last item in the array is NULL. |
| 5814 | * The array must be freed with free(). |
| 5815 | */ |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 5816 | struct tep_format_field **tep_event_fields(struct tep_event *event) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5817 | { |
| 5818 | return get_event_fields("event", event->name, |
| 5819 | event->format.nr_fields, |
| 5820 | event->format.fields); |
| 5821 | } |
| 5822 | |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 5823 | static void print_fields(struct trace_seq *s, struct tep_print_flag_sym *field) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5824 | { |
| 5825 | trace_seq_printf(s, "{ %s, %s }", field->value, field->str); |
| 5826 | if (field->next) { |
| 5827 | trace_seq_puts(s, ", "); |
| 5828 | print_fields(s, field->next); |
| 5829 | } |
| 5830 | } |
| 5831 | |
| 5832 | /* for debugging */ |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 5833 | static void print_args(struct tep_print_arg *args) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5834 | { |
| 5835 | int print_paren = 1; |
| 5836 | struct trace_seq s; |
| 5837 | |
| 5838 | switch (args->type) { |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 5839 | case TEP_PRINT_NULL: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5840 | printf("null"); |
| 5841 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 5842 | case TEP_PRINT_ATOM: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5843 | printf("%s", args->atom.atom); |
| 5844 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 5845 | case TEP_PRINT_FIELD: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5846 | printf("REC->%s", args->field.name); |
| 5847 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 5848 | case TEP_PRINT_FLAGS: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5849 | printf("__print_flags("); |
| 5850 | print_args(args->flags.field); |
| 5851 | printf(", %s, ", args->flags.delim); |
| 5852 | trace_seq_init(&s); |
| 5853 | print_fields(&s, args->flags.flags); |
| 5854 | trace_seq_do_printf(&s); |
| 5855 | trace_seq_destroy(&s); |
| 5856 | printf(")"); |
| 5857 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 5858 | case TEP_PRINT_SYMBOL: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5859 | printf("__print_symbolic("); |
| 5860 | print_args(args->symbol.field); |
| 5861 | printf(", "); |
| 5862 | trace_seq_init(&s); |
| 5863 | print_fields(&s, args->symbol.symbols); |
| 5864 | trace_seq_do_printf(&s); |
| 5865 | trace_seq_destroy(&s); |
| 5866 | printf(")"); |
| 5867 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 5868 | case TEP_PRINT_HEX: |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 5869 | printf("__print_hex("); |
| 5870 | print_args(args->hex.field); |
| 5871 | printf(", "); |
| 5872 | print_args(args->hex.size); |
| 5873 | printf(")"); |
| 5874 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 5875 | case TEP_PRINT_HEX_STR: |
Daniel Borkmann | 0fe0559 | 2017-01-25 02:28:17 +0100 | [diff] [blame] | 5876 | printf("__print_hex_str("); |
| 5877 | print_args(args->hex.field); |
| 5878 | printf(", "); |
| 5879 | print_args(args->hex.size); |
| 5880 | printf(")"); |
| 5881 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 5882 | case TEP_PRINT_INT_ARRAY: |
Javi Merino | b839e1e8 | 2015-03-24 11:07:19 +0000 | [diff] [blame] | 5883 | printf("__print_array("); |
| 5884 | print_args(args->int_array.field); |
| 5885 | printf(", "); |
| 5886 | print_args(args->int_array.count); |
| 5887 | printf(", "); |
| 5888 | print_args(args->int_array.el_size); |
| 5889 | printf(")"); |
| 5890 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 5891 | case TEP_PRINT_STRING: |
| 5892 | case TEP_PRINT_BSTRING: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5893 | printf("__get_str(%s)", args->string.string); |
| 5894 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 5895 | case TEP_PRINT_BITMASK: |
Steven Rostedt (Red Hat) | 473a778 | 2014-06-02 23:20:16 -0400 | [diff] [blame] | 5896 | printf("__get_bitmask(%s)", args->bitmask.bitmask); |
| 5897 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 5898 | case TEP_PRINT_TYPE: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5899 | printf("(%s)", args->typecast.type); |
| 5900 | print_args(args->typecast.item); |
| 5901 | break; |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 5902 | case TEP_PRINT_OP: |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5903 | if (strcmp(args->op.op, ":") == 0) |
| 5904 | print_paren = 0; |
| 5905 | if (print_paren) |
| 5906 | printf("("); |
| 5907 | print_args(args->op.left); |
| 5908 | printf(" %s ", args->op.op); |
| 5909 | print_args(args->op.right); |
| 5910 | if (print_paren) |
| 5911 | printf(")"); |
| 5912 | break; |
| 5913 | default: |
| 5914 | /* we should warn... */ |
| 5915 | return; |
| 5916 | } |
| 5917 | if (args->next) { |
| 5918 | printf("\n"); |
| 5919 | print_args(args->next); |
| 5920 | } |
| 5921 | } |
| 5922 | |
| 5923 | static void parse_header_field(const char *field, |
| 5924 | int *offset, int *size, int mandatory) |
| 5925 | { |
| 5926 | unsigned long long save_input_buf_ptr; |
| 5927 | unsigned long long save_input_buf_siz; |
| 5928 | char *token; |
| 5929 | int type; |
| 5930 | |
| 5931 | save_input_buf_ptr = input_buf_ptr; |
| 5932 | save_input_buf_siz = input_buf_siz; |
| 5933 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5934 | if (read_expected(TEP_EVENT_ITEM, "field") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5935 | return; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5936 | if (read_expected(TEP_EVENT_OP, ":") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5937 | return; |
| 5938 | |
| 5939 | /* type */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5940 | if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5941 | goto fail; |
| 5942 | free_token(token); |
| 5943 | |
| 5944 | /* |
| 5945 | * If this is not a mandatory field, then test it first. |
| 5946 | */ |
| 5947 | if (mandatory) { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5948 | if (read_expected(TEP_EVENT_ITEM, field) < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5949 | return; |
| 5950 | } else { |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5951 | if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5952 | goto fail; |
| 5953 | if (strcmp(token, field) != 0) |
| 5954 | goto discard; |
| 5955 | free_token(token); |
| 5956 | } |
| 5957 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5958 | if (read_expected(TEP_EVENT_OP, ";") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5959 | return; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5960 | if (read_expected(TEP_EVENT_ITEM, "offset") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5961 | return; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5962 | if (read_expected(TEP_EVENT_OP, ":") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5963 | return; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5964 | if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5965 | goto fail; |
| 5966 | *offset = atoi(token); |
| 5967 | free_token(token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5968 | if (read_expected(TEP_EVENT_OP, ";") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5969 | return; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5970 | if (read_expected(TEP_EVENT_ITEM, "size") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5971 | return; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5972 | if (read_expected(TEP_EVENT_OP, ":") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5973 | return; |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5974 | if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5975 | goto fail; |
| 5976 | *size = atoi(token); |
| 5977 | free_token(token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5978 | if (read_expected(TEP_EVENT_OP, ";") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5979 | return; |
| 5980 | type = read_token(&token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5981 | if (type != TEP_EVENT_NEWLINE) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5982 | /* newer versions of the kernel have a "signed" type */ |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5983 | if (type != TEP_EVENT_ITEM) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5984 | goto fail; |
| 5985 | |
| 5986 | if (strcmp(token, "signed") != 0) |
| 5987 | goto fail; |
| 5988 | |
| 5989 | free_token(token); |
| 5990 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5991 | if (read_expected(TEP_EVENT_OP, ":") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5992 | return; |
| 5993 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5994 | if (read_expect_type(TEP_EVENT_ITEM, &token)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5995 | goto fail; |
| 5996 | |
| 5997 | free_token(token); |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 5998 | if (read_expected(TEP_EVENT_OP, ";") < 0) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5999 | return; |
| 6000 | |
Tzvetomir Stoyanov (VMware) | f25d9e0 | 2018-09-19 14:56:47 -0400 | [diff] [blame] | 6001 | if (read_expect_type(TEP_EVENT_NEWLINE, &token)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6002 | goto fail; |
| 6003 | } |
| 6004 | fail: |
| 6005 | free_token(token); |
| 6006 | return; |
| 6007 | |
| 6008 | discard: |
| 6009 | input_buf_ptr = save_input_buf_ptr; |
| 6010 | input_buf_siz = save_input_buf_siz; |
| 6011 | *offset = 0; |
| 6012 | *size = 0; |
| 6013 | free_token(token); |
| 6014 | } |
| 6015 | |
| 6016 | /** |
Tzvetomir Stoyanov (VMware) | c60167c | 2018-08-08 14:02:51 -0400 | [diff] [blame] | 6017 | * tep_parse_header_page - parse the data stored in the header page |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6018 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6019 | * @buf: the buffer storing the header page format string |
| 6020 | * @size: the size of @buf |
| 6021 | * @long_size: the long size to use if there is no header |
| 6022 | * |
| 6023 | * This parses the header page format for information on the |
| 6024 | * ring buffer used. The @buf should be copied from |
| 6025 | * |
| 6026 | * /sys/kernel/debug/tracing/events/header_page |
| 6027 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6028 | int tep_parse_header_page(struct tep_handle *tep, char *buf, unsigned long size, |
Tzvetomir Stoyanov (VMware) | c60167c | 2018-08-08 14:02:51 -0400 | [diff] [blame] | 6029 | int long_size) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6030 | { |
| 6031 | int ignore; |
| 6032 | |
| 6033 | if (!size) { |
| 6034 | /* |
| 6035 | * Old kernels did not have header page info. |
| 6036 | * Sorry but we just use what we find here in user space. |
| 6037 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6038 | tep->header_page_ts_size = sizeof(long long); |
| 6039 | tep->header_page_size_size = long_size; |
| 6040 | tep->header_page_data_offset = sizeof(long long) + long_size; |
| 6041 | tep->old_format = 1; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6042 | return -1; |
| 6043 | } |
| 6044 | init_input_buf(buf, size); |
| 6045 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6046 | parse_header_field("timestamp", &tep->header_page_ts_offset, |
| 6047 | &tep->header_page_ts_size, 1); |
| 6048 | parse_header_field("commit", &tep->header_page_size_offset, |
| 6049 | &tep->header_page_size_size, 1); |
| 6050 | parse_header_field("overwrite", &tep->header_page_overwrite, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6051 | &ignore, 0); |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6052 | parse_header_field("data", &tep->header_page_data_offset, |
| 6053 | &tep->header_page_data_size, 1); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6054 | |
| 6055 | return 0; |
| 6056 | } |
| 6057 | |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6058 | static int event_matches(struct tep_event *event, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6059 | int id, const char *sys_name, |
| 6060 | const char *event_name) |
| 6061 | { |
| 6062 | if (id >= 0 && id != event->id) |
| 6063 | return 0; |
| 6064 | |
| 6065 | if (event_name && (strcmp(event_name, event->name) != 0)) |
| 6066 | return 0; |
| 6067 | |
| 6068 | if (sys_name && (strcmp(sys_name, event->system) != 0)) |
| 6069 | return 0; |
| 6070 | |
| 6071 | return 1; |
| 6072 | } |
| 6073 | |
| 6074 | static void free_handler(struct event_handler *handle) |
| 6075 | { |
| 6076 | free((void *)handle->sys_name); |
| 6077 | free((void *)handle->event_name); |
| 6078 | free(handle); |
| 6079 | } |
| 6080 | |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6081 | static int find_event_handle(struct tep_handle *pevent, struct tep_event *event) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6082 | { |
| 6083 | struct event_handler *handle, **next; |
| 6084 | |
| 6085 | for (next = &pevent->handlers; *next; |
| 6086 | next = &(*next)->next) { |
| 6087 | handle = *next; |
| 6088 | if (event_matches(event, handle->id, |
| 6089 | handle->sys_name, |
| 6090 | handle->event_name)) |
| 6091 | break; |
| 6092 | } |
| 6093 | |
| 6094 | if (!(*next)) |
| 6095 | return 0; |
| 6096 | |
| 6097 | pr_stat("overriding event (%d) %s:%s with new print handler", |
| 6098 | event->id, event->system, event->name); |
| 6099 | |
| 6100 | event->handler = handle->func; |
| 6101 | event->context = handle->context; |
| 6102 | |
| 6103 | *next = handle->next; |
| 6104 | free_handler(handle); |
| 6105 | |
| 6106 | return 1; |
| 6107 | } |
| 6108 | |
| 6109 | /** |
Tzvetomir Stoyanov (VMware) | 0ae9863 | 2018-08-08 14:03:09 -0400 | [diff] [blame] | 6110 | * __tep_parse_format - parse the event format |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6111 | * @buf: the buffer storing the event format string |
| 6112 | * @size: the size of @buf |
| 6113 | * @sys: the system the event belongs to |
| 6114 | * |
| 6115 | * This parses the event format and creates an event structure |
| 6116 | * to quickly parse raw data for a given event. |
| 6117 | * |
| 6118 | * These files currently come from: |
| 6119 | * |
| 6120 | * /sys/kernel/debug/tracing/events/.../.../format |
| 6121 | */ |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6122 | enum tep_errno __tep_parse_format(struct tep_event **eventp, |
Tzvetomir Stoyanov (VMware) | 0ae9863 | 2018-08-08 14:03:09 -0400 | [diff] [blame] | 6123 | struct tep_handle *pevent, const char *buf, |
| 6124 | unsigned long size, const char *sys) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6125 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6126 | struct tep_event *event; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6127 | int ret; |
| 6128 | |
| 6129 | init_input_buf(buf, size); |
| 6130 | |
Arnaldo Carvalho de Melo | 2b29175 | 2012-09-18 11:13:15 -0300 | [diff] [blame] | 6131 | *eventp = event = alloc_event(); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6132 | if (!event) |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6133 | return TEP_ERRNO__MEM_ALLOC_FAILED; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6134 | |
| 6135 | event->name = event_read_name(); |
| 6136 | if (!event->name) { |
| 6137 | /* Bad event? */ |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6138 | ret = TEP_ERRNO__MEM_ALLOC_FAILED; |
Namhyung Kim | bffddff | 2012-08-22 16:00:29 +0900 | [diff] [blame] | 6139 | goto event_alloc_failed; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6140 | } |
| 6141 | |
| 6142 | if (strcmp(sys, "ftrace") == 0) { |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 6143 | event->flags |= TEP_EVENT_FL_ISFTRACE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6144 | |
| 6145 | if (strcmp(event->name, "bprint") == 0) |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 6146 | event->flags |= TEP_EVENT_FL_ISBPRINT; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6147 | } |
| 6148 | |
| 6149 | event->id = event_read_id(); |
Namhyung Kim | bffddff | 2012-08-22 16:00:29 +0900 | [diff] [blame] | 6150 | if (event->id < 0) { |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6151 | ret = TEP_ERRNO__READ_ID_FAILED; |
Namhyung Kim | bffddff | 2012-08-22 16:00:29 +0900 | [diff] [blame] | 6152 | /* |
| 6153 | * This isn't an allocation error actually. |
| 6154 | * But as the ID is critical, just bail out. |
| 6155 | */ |
| 6156 | goto event_alloc_failed; |
| 6157 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6158 | |
| 6159 | event->system = strdup(sys); |
Namhyung Kim | bffddff | 2012-08-22 16:00:29 +0900 | [diff] [blame] | 6160 | if (!event->system) { |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6161 | ret = TEP_ERRNO__MEM_ALLOC_FAILED; |
Namhyung Kim | bffddff | 2012-08-22 16:00:29 +0900 | [diff] [blame] | 6162 | goto event_alloc_failed; |
| 6163 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6164 | |
Steven Rostedt | 101782e | 2012-10-01 20:13:51 -0400 | [diff] [blame] | 6165 | /* Add pevent to event so that it can be referenced */ |
| 6166 | event->pevent = pevent; |
| 6167 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6168 | ret = event_read_format(event); |
| 6169 | if (ret < 0) { |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6170 | ret = TEP_ERRNO__READ_FORMAT_FAILED; |
Namhyung Kim | bffddff | 2012-08-22 16:00:29 +0900 | [diff] [blame] | 6171 | goto event_parse_failed; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6172 | } |
| 6173 | |
| 6174 | /* |
| 6175 | * If the event has an override, don't print warnings if the event |
| 6176 | * print format fails to parse. |
| 6177 | */ |
Arnaldo Carvalho de Melo | 2b29175 | 2012-09-18 11:13:15 -0300 | [diff] [blame] | 6178 | if (pevent && find_event_handle(pevent, event)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6179 | show_warning = 0; |
| 6180 | |
| 6181 | ret = event_read_print(event); |
Arnaldo Carvalho de Melo | 2b29175 | 2012-09-18 11:13:15 -0300 | [diff] [blame] | 6182 | show_warning = 1; |
| 6183 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6184 | if (ret < 0) { |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6185 | ret = TEP_ERRNO__READ_PRINT_FAILED; |
Namhyung Kim | bffddff | 2012-08-22 16:00:29 +0900 | [diff] [blame] | 6186 | goto event_parse_failed; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6187 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6188 | |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 6189 | if (!ret && (event->flags & TEP_EVENT_FL_ISFTRACE)) { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 6190 | struct tep_format_field *field; |
Tzvetomir Stoyanov (VMware) | 5647f94 | 2018-09-19 14:56:49 -0400 | [diff] [blame] | 6191 | struct tep_print_arg *arg, **list; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6192 | |
| 6193 | /* old ftrace had no args */ |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6194 | list = &event->print_fmt.args; |
| 6195 | for (field = event->format.fields; field; field = field->next) { |
| 6196 | arg = alloc_arg(); |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 6197 | if (!arg) { |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 6198 | event->flags |= TEP_EVENT_FL_FAILED; |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6199 | return TEP_ERRNO__OLD_FTRACE_ARG_FAILED; |
Namhyung Kim | b1ac754 | 2012-09-20 11:09:19 +0900 | [diff] [blame] | 6200 | } |
Tzvetomir Stoyanov (VMware) | 1e97216f | 2018-09-19 14:56:50 -0400 | [diff] [blame] | 6201 | arg->type = TEP_PRINT_FIELD; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6202 | arg->field.name = strdup(field->name); |
Namhyung Kim | ca63858 | 2012-04-09 11:54:31 +0900 | [diff] [blame] | 6203 | if (!arg->field.name) { |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 6204 | event->flags |= TEP_EVENT_FL_FAILED; |
Namhyung Kim | fd34f0b | 2012-08-22 16:00:28 +0900 | [diff] [blame] | 6205 | free_arg(arg); |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6206 | return TEP_ERRNO__OLD_FTRACE_ARG_FAILED; |
Namhyung Kim | ca63858 | 2012-04-09 11:54:31 +0900 | [diff] [blame] | 6207 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6208 | arg->field.field = field; |
Namhyung Kim | fd34f0b | 2012-08-22 16:00:28 +0900 | [diff] [blame] | 6209 | *list = arg; |
| 6210 | list = &arg->next; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6211 | } |
| 6212 | return 0; |
| 6213 | } |
| 6214 | |
Arnaldo Carvalho de Melo | 2b29175 | 2012-09-18 11:13:15 -0300 | [diff] [blame] | 6215 | return 0; |
| 6216 | |
| 6217 | event_parse_failed: |
Tzvetomir Stoyanov (VMware) | c1953bc | 2018-09-19 14:56:48 -0400 | [diff] [blame] | 6218 | event->flags |= TEP_EVENT_FL_FAILED; |
Arnaldo Carvalho de Melo | 2b29175 | 2012-09-18 11:13:15 -0300 | [diff] [blame] | 6219 | return ret; |
| 6220 | |
| 6221 | event_alloc_failed: |
| 6222 | free(event->system); |
| 6223 | free(event->name); |
| 6224 | free(event); |
| 6225 | *eventp = NULL; |
| 6226 | return ret; |
| 6227 | } |
| 6228 | |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6229 | static enum tep_errno |
Tzvetomir Stoyanov (VMware) | 0ae9863 | 2018-08-08 14:03:09 -0400 | [diff] [blame] | 6230 | __parse_event(struct tep_handle *pevent, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6231 | struct tep_event **eventp, |
Tzvetomir Stoyanov (VMware) | 0ae9863 | 2018-08-08 14:03:09 -0400 | [diff] [blame] | 6232 | const char *buf, unsigned long size, |
| 6233 | const char *sys) |
Jiri Olsa | 71ad958 | 2013-12-03 14:09:19 +0100 | [diff] [blame] | 6234 | { |
Tzvetomir Stoyanov (VMware) | 0ae9863 | 2018-08-08 14:03:09 -0400 | [diff] [blame] | 6235 | int ret = __tep_parse_format(eventp, pevent, buf, size, sys); |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6236 | struct tep_event *event = *eventp; |
Jiri Olsa | 71ad958 | 2013-12-03 14:09:19 +0100 | [diff] [blame] | 6237 | |
| 6238 | if (event == NULL) |
| 6239 | return ret; |
| 6240 | |
| 6241 | if (pevent && add_event(pevent, event)) { |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6242 | ret = TEP_ERRNO__MEM_ALLOC_FAILED; |
Jiri Olsa | 71ad958 | 2013-12-03 14:09:19 +0100 | [diff] [blame] | 6243 | goto event_add_failed; |
| 6244 | } |
| 6245 | |
| 6246 | #define PRINT_ARGS 0 |
| 6247 | if (PRINT_ARGS && event->print_fmt.args) |
| 6248 | print_args(event->print_fmt.args); |
| 6249 | |
| 6250 | return 0; |
| 6251 | |
| 6252 | event_add_failed: |
Tzvetomir Stoyanov | fc39851 | 2018-11-30 10:44:08 -0500 | [diff] [blame] | 6253 | tep_free_event(event); |
Jiri Olsa | 71ad958 | 2013-12-03 14:09:19 +0100 | [diff] [blame] | 6254 | return ret; |
| 6255 | } |
| 6256 | |
Arnaldo Carvalho de Melo | 2b29175 | 2012-09-18 11:13:15 -0300 | [diff] [blame] | 6257 | /** |
Tzvetomir Stoyanov (VMware) | c60167c | 2018-08-08 14:02:51 -0400 | [diff] [blame] | 6258 | * tep_parse_format - parse the event format |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6259 | * @tep: a handle to the trace event parser context |
Jiri Olsa | 71ad958 | 2013-12-03 14:09:19 +0100 | [diff] [blame] | 6260 | * @eventp: returned format |
Arnaldo Carvalho de Melo | 2b29175 | 2012-09-18 11:13:15 -0300 | [diff] [blame] | 6261 | * @buf: the buffer storing the event format string |
| 6262 | * @size: the size of @buf |
| 6263 | * @sys: the system the event belongs to |
| 6264 | * |
| 6265 | * This parses the event format and creates an event structure |
| 6266 | * to quickly parse raw data for a given event. |
| 6267 | * |
| 6268 | * These files currently come from: |
| 6269 | * |
| 6270 | * /sys/kernel/debug/tracing/events/.../.../format |
| 6271 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6272 | enum tep_errno tep_parse_format(struct tep_handle *tep, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6273 | struct tep_event **eventp, |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6274 | const char *buf, |
| 6275 | unsigned long size, const char *sys) |
Arnaldo Carvalho de Melo | 2b29175 | 2012-09-18 11:13:15 -0300 | [diff] [blame] | 6276 | { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6277 | return __parse_event(tep, eventp, buf, size, sys); |
Arnaldo Carvalho de Melo | 2b29175 | 2012-09-18 11:13:15 -0300 | [diff] [blame] | 6278 | } |
| 6279 | |
| 6280 | /** |
Tzvetomir Stoyanov (VMware) | c60167c | 2018-08-08 14:02:51 -0400 | [diff] [blame] | 6281 | * tep_parse_event - parse the event format |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6282 | * @tep: a handle to the trace event parser context |
Arnaldo Carvalho de Melo | 2b29175 | 2012-09-18 11:13:15 -0300 | [diff] [blame] | 6283 | * @buf: the buffer storing the event format string |
| 6284 | * @size: the size of @buf |
| 6285 | * @sys: the system the event belongs to |
| 6286 | * |
| 6287 | * This parses the event format and creates an event structure |
| 6288 | * to quickly parse raw data for a given event. |
| 6289 | * |
| 6290 | * These files currently come from: |
| 6291 | * |
| 6292 | * /sys/kernel/debug/tracing/events/.../.../format |
| 6293 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6294 | enum tep_errno tep_parse_event(struct tep_handle *tep, const char *buf, |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6295 | unsigned long size, const char *sys) |
Arnaldo Carvalho de Melo | 2b29175 | 2012-09-18 11:13:15 -0300 | [diff] [blame] | 6296 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6297 | struct tep_event *event = NULL; |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6298 | return __parse_event(tep, &event, buf, size, sys); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6299 | } |
| 6300 | |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 6301 | int get_field_val(struct trace_seq *s, struct tep_format_field *field, |
Tzvetomir Stoyanov (VMware) | cbc49b2 | 2018-08-08 14:02:47 -0400 | [diff] [blame] | 6302 | const char *name, struct tep_record *record, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6303 | unsigned long long *val, int err) |
| 6304 | { |
| 6305 | if (!field) { |
| 6306 | if (err) |
| 6307 | trace_seq_printf(s, "<CANT FIND FIELD %s>", name); |
| 6308 | return -1; |
| 6309 | } |
| 6310 | |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 6311 | if (tep_read_number_field(field, record->data, val)) { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6312 | if (err) |
| 6313 | trace_seq_printf(s, " %s=INVALID", name); |
| 6314 | return -1; |
| 6315 | } |
| 6316 | |
| 6317 | return 0; |
| 6318 | } |
| 6319 | |
| 6320 | /** |
Tzvetomir Stoyanov (VMware) | 8b3e087 | 2018-08-08 14:03:04 -0400 | [diff] [blame] | 6321 | * tep_get_field_raw - return the raw pointer into the data field |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6322 | * @s: The seq to print to on error |
| 6323 | * @event: the event that the field is for |
| 6324 | * @name: The name of the field |
| 6325 | * @record: The record with the field name. |
| 6326 | * @len: place to store the field length. |
| 6327 | * @err: print default error if failed. |
| 6328 | * |
| 6329 | * Returns a pointer into record->data of the field and places |
| 6330 | * the length of the field in @len. |
| 6331 | * |
| 6332 | * On failure, it returns NULL. |
| 6333 | */ |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6334 | void *tep_get_field_raw(struct trace_seq *s, struct tep_event *event, |
Tzvetomir Stoyanov (VMware) | 8b3e087 | 2018-08-08 14:03:04 -0400 | [diff] [blame] | 6335 | const char *name, struct tep_record *record, |
| 6336 | int *len, int err) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6337 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 6338 | struct tep_format_field *field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6339 | void *data = record->data; |
| 6340 | unsigned offset; |
| 6341 | int dummy; |
| 6342 | |
| 6343 | if (!event) |
| 6344 | return NULL; |
| 6345 | |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 6346 | field = tep_find_field(event, name); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6347 | |
| 6348 | if (!field) { |
| 6349 | if (err) |
| 6350 | trace_seq_printf(s, "<CANT FIND FIELD %s>", name); |
| 6351 | return NULL; |
| 6352 | } |
| 6353 | |
| 6354 | /* Allow @len to be NULL */ |
| 6355 | if (!len) |
| 6356 | len = &dummy; |
| 6357 | |
| 6358 | offset = field->offset; |
Tzvetomir Stoyanov (VMware) | bb39ccb | 2018-09-19 14:56:46 -0400 | [diff] [blame] | 6359 | if (field->flags & TEP_FIELD_IS_DYNAMIC) { |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 6360 | offset = tep_read_number(event->pevent, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6361 | data + offset, field->size); |
| 6362 | *len = offset >> 16; |
| 6363 | offset &= 0xffff; |
| 6364 | } else |
| 6365 | *len = field->size; |
| 6366 | |
| 6367 | return data + offset; |
| 6368 | } |
| 6369 | |
| 6370 | /** |
Tzvetomir Stoyanov (VMware) | 8b3e087 | 2018-08-08 14:03:04 -0400 | [diff] [blame] | 6371 | * tep_get_field_val - find a field and return its value |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6372 | * @s: The seq to print to on error |
| 6373 | * @event: the event that the field is for |
| 6374 | * @name: The name of the field |
| 6375 | * @record: The record with the field name. |
| 6376 | * @val: place to store the value of the field. |
| 6377 | * @err: print default error if failed. |
| 6378 | * |
| 6379 | * Returns 0 on success -1 on field not found. |
| 6380 | */ |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6381 | int tep_get_field_val(struct trace_seq *s, struct tep_event *event, |
Tzvetomir Stoyanov (VMware) | 8b3e087 | 2018-08-08 14:03:04 -0400 | [diff] [blame] | 6382 | const char *name, struct tep_record *record, |
| 6383 | unsigned long long *val, int err) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6384 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 6385 | struct tep_format_field *field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6386 | |
| 6387 | if (!event) |
| 6388 | return -1; |
| 6389 | |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 6390 | field = tep_find_field(event, name); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6391 | |
| 6392 | return get_field_val(s, field, name, record, val, err); |
| 6393 | } |
| 6394 | |
| 6395 | /** |
Tzvetomir Stoyanov (VMware) | 8b3e087 | 2018-08-08 14:03:04 -0400 | [diff] [blame] | 6396 | * tep_get_common_field_val - find a common field and return its value |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6397 | * @s: The seq to print to on error |
| 6398 | * @event: the event that the field is for |
| 6399 | * @name: The name of the field |
| 6400 | * @record: The record with the field name. |
| 6401 | * @val: place to store the value of the field. |
| 6402 | * @err: print default error if failed. |
| 6403 | * |
| 6404 | * Returns 0 on success -1 on field not found. |
| 6405 | */ |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6406 | int tep_get_common_field_val(struct trace_seq *s, struct tep_event *event, |
Tzvetomir Stoyanov (VMware) | 8b3e087 | 2018-08-08 14:03:04 -0400 | [diff] [blame] | 6407 | const char *name, struct tep_record *record, |
| 6408 | unsigned long long *val, int err) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6409 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 6410 | struct tep_format_field *field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6411 | |
| 6412 | if (!event) |
| 6413 | return -1; |
| 6414 | |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 6415 | field = tep_find_common_field(event, name); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6416 | |
| 6417 | return get_field_val(s, field, name, record, val, err); |
| 6418 | } |
| 6419 | |
| 6420 | /** |
Tzvetomir Stoyanov (VMware) | 8b3e087 | 2018-08-08 14:03:04 -0400 | [diff] [blame] | 6421 | * tep_get_any_field_val - find a any field and return its value |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6422 | * @s: The seq to print to on error |
| 6423 | * @event: the event that the field is for |
| 6424 | * @name: The name of the field |
| 6425 | * @record: The record with the field name. |
| 6426 | * @val: place to store the value of the field. |
| 6427 | * @err: print default error if failed. |
| 6428 | * |
| 6429 | * Returns 0 on success -1 on field not found. |
| 6430 | */ |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6431 | int tep_get_any_field_val(struct trace_seq *s, struct tep_event *event, |
Tzvetomir Stoyanov (VMware) | 8b3e087 | 2018-08-08 14:03:04 -0400 | [diff] [blame] | 6432 | const char *name, struct tep_record *record, |
| 6433 | unsigned long long *val, int err) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6434 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 6435 | struct tep_format_field *field; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6436 | |
| 6437 | if (!event) |
| 6438 | return -1; |
| 6439 | |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 6440 | field = tep_find_any_field(event, name); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6441 | |
| 6442 | return get_field_val(s, field, name, record, val, err); |
| 6443 | } |
| 6444 | |
| 6445 | /** |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 6446 | * tep_print_num_field - print a field and a format |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6447 | * @s: The seq to print to |
| 6448 | * @fmt: The printf format to print the field with. |
| 6449 | * @event: the event that the field is for |
| 6450 | * @name: The name of the field |
| 6451 | * @record: The record with the field name. |
| 6452 | * @err: print default error if failed. |
| 6453 | * |
Tzvetomir Stoyanov | 489b349 | 2019-04-01 12:43:10 -0400 | [diff] [blame] | 6454 | * Returns positive value on success, negative in case of an error, |
| 6455 | * or 0 if buffer is full. |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6456 | */ |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 6457 | int tep_print_num_field(struct trace_seq *s, const char *fmt, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6458 | struct tep_event *event, const char *name, |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 6459 | struct tep_record *record, int err) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6460 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 6461 | struct tep_format_field *field = tep_find_field(event, name); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6462 | unsigned long long val; |
| 6463 | |
| 6464 | if (!field) |
| 6465 | goto failed; |
| 6466 | |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 6467 | if (tep_read_number_field(field, record->data, &val)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6468 | goto failed; |
| 6469 | |
| 6470 | return trace_seq_printf(s, fmt, val); |
| 6471 | |
| 6472 | failed: |
| 6473 | if (err) |
| 6474 | trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name); |
| 6475 | return -1; |
| 6476 | } |
| 6477 | |
Steven Rostedt | 6d862b8 | 2013-11-01 17:54:00 -0400 | [diff] [blame] | 6478 | /** |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 6479 | * tep_print_func_field - print a field and a format for function pointers |
Steven Rostedt | 6d862b8 | 2013-11-01 17:54:00 -0400 | [diff] [blame] | 6480 | * @s: The seq to print to |
| 6481 | * @fmt: The printf format to print the field with. |
| 6482 | * @event: the event that the field is for |
| 6483 | * @name: The name of the field |
| 6484 | * @record: The record with the field name. |
| 6485 | * @err: print default error if failed. |
| 6486 | * |
Tzvetomir Stoyanov | 489b349 | 2019-04-01 12:43:10 -0400 | [diff] [blame] | 6487 | * Returns positive value on success, negative in case of an error, |
| 6488 | * or 0 if buffer is full. |
Steven Rostedt | 6d862b8 | 2013-11-01 17:54:00 -0400 | [diff] [blame] | 6489 | */ |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 6490 | int tep_print_func_field(struct trace_seq *s, const char *fmt, |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6491 | struct tep_event *event, const char *name, |
Tzvetomir Stoyanov (VMware) | 6a48dc2 | 2018-08-08 14:02:52 -0400 | [diff] [blame] | 6492 | struct tep_record *record, int err) |
Steven Rostedt | 6d862b8 | 2013-11-01 17:54:00 -0400 | [diff] [blame] | 6493 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 6494 | struct tep_format_field *field = tep_find_field(event, name); |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 6495 | struct tep_handle *pevent = event->pevent; |
Steven Rostedt | 6d862b8 | 2013-11-01 17:54:00 -0400 | [diff] [blame] | 6496 | unsigned long long val; |
| 6497 | struct func_map *func; |
| 6498 | char tmp[128]; |
| 6499 | |
| 6500 | if (!field) |
| 6501 | goto failed; |
| 6502 | |
Tzvetomir Stoyanov (VMware) | 59c1bae | 2018-08-08 14:02:53 -0400 | [diff] [blame] | 6503 | if (tep_read_number_field(field, record->data, &val)) |
Steven Rostedt | 6d862b8 | 2013-11-01 17:54:00 -0400 | [diff] [blame] | 6504 | goto failed; |
| 6505 | |
| 6506 | func = find_func(pevent, val); |
| 6507 | |
| 6508 | if (func) |
| 6509 | snprintf(tmp, 128, "%s/0x%llx", func->func, func->addr - val); |
| 6510 | else |
| 6511 | sprintf(tmp, "0x%08llx", val); |
| 6512 | |
| 6513 | return trace_seq_printf(s, fmt, tmp); |
| 6514 | |
| 6515 | failed: |
| 6516 | if (err) |
| 6517 | trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name); |
| 6518 | return -1; |
| 6519 | } |
| 6520 | |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 6521 | static void free_func_handle(struct tep_function_handler *func) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6522 | { |
Tzvetomir Stoyanov (VMware) | 0ae9863 | 2018-08-08 14:03:09 -0400 | [diff] [blame] | 6523 | struct func_params *params; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6524 | |
| 6525 | free(func->name); |
| 6526 | |
| 6527 | while (func->params) { |
| 6528 | params = func->params; |
| 6529 | func->params = params->next; |
| 6530 | free(params); |
| 6531 | } |
| 6532 | |
| 6533 | free(func); |
| 6534 | } |
| 6535 | |
| 6536 | /** |
Tzvetomir Stoyanov (VMware) | b843e9c | 2018-08-08 14:03:02 -0400 | [diff] [blame] | 6537 | * tep_register_print_function - register a helper function |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6538 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6539 | * @func: the function to process the helper function |
Namhyung Kim | 16e6b8f | 2012-04-23 13:58:35 +0900 | [diff] [blame] | 6540 | * @ret_type: the return type of the helper function |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6541 | * @name: the name of the helper function |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 6542 | * @parameters: A list of enum tep_func_arg_type |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6543 | * |
| 6544 | * Some events may have helper functions in the print format arguments. |
Namhyung Kim | 16e6b8f | 2012-04-23 13:58:35 +0900 | [diff] [blame] | 6545 | * This allows a plugin to dynamically create a way to process one |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6546 | * of these functions. |
| 6547 | * |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 6548 | * The @parameters is a variable list of tep_func_arg_type enums that |
| 6549 | * must end with TEP_FUNC_ARG_VOID. |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6550 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6551 | int tep_register_print_function(struct tep_handle *tep, |
Tzvetomir Stoyanov (VMware) | b843e9c | 2018-08-08 14:03:02 -0400 | [diff] [blame] | 6552 | tep_func_handler func, |
| 6553 | enum tep_func_arg_type ret_type, |
| 6554 | char *name, ...) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6555 | { |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 6556 | struct tep_function_handler *func_handle; |
Tzvetomir Stoyanov (VMware) | 0ae9863 | 2018-08-08 14:03:09 -0400 | [diff] [blame] | 6557 | struct func_params **next_param; |
| 6558 | struct func_params *param; |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 6559 | enum tep_func_arg_type type; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6560 | va_list ap; |
Namhyung Kim | 67ed939 | 2012-09-07 11:49:47 +0900 | [diff] [blame] | 6561 | int ret; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6562 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6563 | func_handle = find_func_handler(tep, name); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6564 | if (func_handle) { |
| 6565 | /* |
| 6566 | * This is most like caused by the users own |
| 6567 | * plugins updating the function. This overrides the |
| 6568 | * system defaults. |
| 6569 | */ |
| 6570 | pr_stat("override of function helper '%s'", name); |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6571 | remove_func_handler(tep, name); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6572 | } |
| 6573 | |
Arnaldo Carvalho de Melo | 87162d8 | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 6574 | func_handle = calloc(1, sizeof(*func_handle)); |
Namhyung Kim | 67ed939 | 2012-09-07 11:49:47 +0900 | [diff] [blame] | 6575 | if (!func_handle) { |
| 6576 | do_warning("Failed to allocate function handler"); |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6577 | return TEP_ERRNO__MEM_ALLOC_FAILED; |
Namhyung Kim | 67ed939 | 2012-09-07 11:49:47 +0900 | [diff] [blame] | 6578 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6579 | |
| 6580 | func_handle->ret_type = ret_type; |
| 6581 | func_handle->name = strdup(name); |
| 6582 | func_handle->func = func; |
Namhyung Kim | 67ed939 | 2012-09-07 11:49:47 +0900 | [diff] [blame] | 6583 | if (!func_handle->name) { |
| 6584 | do_warning("Failed to allocate function name"); |
| 6585 | free(func_handle); |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6586 | return TEP_ERRNO__MEM_ALLOC_FAILED; |
Namhyung Kim | 67ed939 | 2012-09-07 11:49:47 +0900 | [diff] [blame] | 6587 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6588 | |
| 6589 | next_param = &(func_handle->params); |
| 6590 | va_start(ap, name); |
| 6591 | for (;;) { |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 6592 | type = va_arg(ap, enum tep_func_arg_type); |
| 6593 | if (type == TEP_FUNC_ARG_VOID) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6594 | break; |
| 6595 | |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 6596 | if (type >= TEP_FUNC_ARG_MAX_TYPES) { |
Namhyung Kim | 67ed939 | 2012-09-07 11:49:47 +0900 | [diff] [blame] | 6597 | do_warning("Invalid argument type %d", type); |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6598 | ret = TEP_ERRNO__INVALID_ARG_TYPE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6599 | goto out_free; |
| 6600 | } |
| 6601 | |
Namhyung Kim | 67ed939 | 2012-09-07 11:49:47 +0900 | [diff] [blame] | 6602 | param = malloc(sizeof(*param)); |
| 6603 | if (!param) { |
| 6604 | do_warning("Failed to allocate function param"); |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6605 | ret = TEP_ERRNO__MEM_ALLOC_FAILED; |
Namhyung Kim | 67ed939 | 2012-09-07 11:49:47 +0900 | [diff] [blame] | 6606 | goto out_free; |
| 6607 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6608 | param->type = type; |
| 6609 | param->next = NULL; |
| 6610 | |
| 6611 | *next_param = param; |
| 6612 | next_param = &(param->next); |
| 6613 | |
| 6614 | func_handle->nr_args++; |
| 6615 | } |
| 6616 | va_end(ap); |
| 6617 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6618 | func_handle->next = tep->func_handlers; |
| 6619 | tep->func_handlers = func_handle; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6620 | |
| 6621 | return 0; |
| 6622 | out_free: |
| 6623 | va_end(ap); |
| 6624 | free_func_handle(func_handle); |
Namhyung Kim | 67ed939 | 2012-09-07 11:49:47 +0900 | [diff] [blame] | 6625 | return ret; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6626 | } |
| 6627 | |
Namhyung Kim | 20c7e5a | 2014-01-16 11:31:08 +0900 | [diff] [blame] | 6628 | /** |
Tzvetomir Stoyanov (VMware) | b843e9c | 2018-08-08 14:03:02 -0400 | [diff] [blame] | 6629 | * tep_unregister_print_function - unregister a helper function |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6630 | * @tep: a handle to the trace event parser context |
Namhyung Kim | 20c7e5a | 2014-01-16 11:31:08 +0900 | [diff] [blame] | 6631 | * @func: the function to process the helper function |
| 6632 | * @name: the name of the helper function |
| 6633 | * |
| 6634 | * This function removes existing print handler for function @name. |
| 6635 | * |
| 6636 | * Returns 0 if the handler was removed successully, -1 otherwise. |
| 6637 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6638 | int tep_unregister_print_function(struct tep_handle *tep, |
Tzvetomir Stoyanov (VMware) | b843e9c | 2018-08-08 14:03:02 -0400 | [diff] [blame] | 6639 | tep_func_handler func, char *name) |
Namhyung Kim | 20c7e5a | 2014-01-16 11:31:08 +0900 | [diff] [blame] | 6640 | { |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 6641 | struct tep_function_handler *func_handle; |
Namhyung Kim | 20c7e5a | 2014-01-16 11:31:08 +0900 | [diff] [blame] | 6642 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6643 | func_handle = find_func_handler(tep, name); |
Namhyung Kim | 20c7e5a | 2014-01-16 11:31:08 +0900 | [diff] [blame] | 6644 | if (func_handle && func_handle->func == func) { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6645 | remove_func_handler(tep, name); |
Namhyung Kim | 20c7e5a | 2014-01-16 11:31:08 +0900 | [diff] [blame] | 6646 | return 0; |
| 6647 | } |
| 6648 | return -1; |
| 6649 | } |
| 6650 | |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6651 | static struct tep_event *search_event(struct tep_handle *pevent, int id, |
| 6652 | const char *sys_name, |
| 6653 | const char *event_name) |
Namhyung Kim | ad13701 | 2014-01-16 11:31:07 +0900 | [diff] [blame] | 6654 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6655 | struct tep_event *event; |
Namhyung Kim | ad13701 | 2014-01-16 11:31:07 +0900 | [diff] [blame] | 6656 | |
| 6657 | if (id >= 0) { |
| 6658 | /* search by id */ |
Tzvetomir Stoyanov (VMware) | af85cd1 | 2018-08-08 14:02:50 -0400 | [diff] [blame] | 6659 | event = tep_find_event(pevent, id); |
Namhyung Kim | ad13701 | 2014-01-16 11:31:07 +0900 | [diff] [blame] | 6660 | if (!event) |
| 6661 | return NULL; |
| 6662 | if (event_name && (strcmp(event_name, event->name) != 0)) |
| 6663 | return NULL; |
| 6664 | if (sys_name && (strcmp(sys_name, event->system) != 0)) |
| 6665 | return NULL; |
| 6666 | } else { |
Tzvetomir Stoyanov (VMware) | 610e1e4 | 2018-08-08 14:03:05 -0400 | [diff] [blame] | 6667 | event = tep_find_event_by_name(pevent, sys_name, event_name); |
Namhyung Kim | ad13701 | 2014-01-16 11:31:07 +0900 | [diff] [blame] | 6668 | if (!event) |
| 6669 | return NULL; |
| 6670 | } |
| 6671 | return event; |
| 6672 | } |
| 6673 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6674 | /** |
Tzvetomir Stoyanov (VMware) | b843e9c | 2018-08-08 14:03:02 -0400 | [diff] [blame] | 6675 | * tep_register_event_handler - register a way to parse an event |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6676 | * @tep: a handle to the trace event parser context |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6677 | * @id: the id of the event to register |
| 6678 | * @sys_name: the system name the event belongs to |
| 6679 | * @event_name: the name of the event |
| 6680 | * @func: the function to call to parse the event information |
Namhyung Kim | 16e6b8f | 2012-04-23 13:58:35 +0900 | [diff] [blame] | 6681 | * @context: the data to be passed to @func |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6682 | * |
| 6683 | * This function allows a developer to override the parsing of |
| 6684 | * a given event. If for some reason the default print format |
| 6685 | * is not sufficient, this function will register a function |
| 6686 | * for an event to be used to parse the data instead. |
| 6687 | * |
| 6688 | * If @id is >= 0, then it is used to find the event. |
| 6689 | * else @sys_name and @event_name are used. |
Tzvetomir Stoyanov | f87ce7c | 2018-11-30 23:08:11 -0500 | [diff] [blame] | 6690 | * |
| 6691 | * Returns: |
| 6692 | * TEP_REGISTER_SUCCESS_OVERWRITE if an existing handler is overwritten |
| 6693 | * TEP_REGISTER_SUCCESS if a new handler is registered successfully |
| 6694 | * negative TEP_ERRNO_... in case of an error |
| 6695 | * |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6696 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6697 | int tep_register_event_handler(struct tep_handle *tep, int id, |
Tzvetomir Stoyanov (VMware) | b843e9c | 2018-08-08 14:03:02 -0400 | [diff] [blame] | 6698 | const char *sys_name, const char *event_name, |
| 6699 | tep_event_handler_func func, void *context) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6700 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6701 | struct tep_event *event; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6702 | struct event_handler *handle; |
| 6703 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6704 | event = search_event(tep, id, sys_name, event_name); |
Namhyung Kim | ad13701 | 2014-01-16 11:31:07 +0900 | [diff] [blame] | 6705 | if (event == NULL) |
| 6706 | goto not_found; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6707 | |
| 6708 | pr_stat("overriding event (%d) %s:%s with new print handler", |
| 6709 | event->id, event->system, event->name); |
| 6710 | |
| 6711 | event->handler = func; |
| 6712 | event->context = context; |
Tzvetomir Stoyanov | f87ce7c | 2018-11-30 23:08:11 -0500 | [diff] [blame] | 6713 | return TEP_REGISTER_SUCCESS_OVERWRITE; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6714 | |
| 6715 | not_found: |
| 6716 | /* Save for later use. */ |
Arnaldo Carvalho de Melo | 87162d8 | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 6717 | handle = calloc(1, sizeof(*handle)); |
Namhyung Kim | 0ca8da0 | 2012-09-07 11:49:46 +0900 | [diff] [blame] | 6718 | if (!handle) { |
| 6719 | do_warning("Failed to allocate event handler"); |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6720 | return TEP_ERRNO__MEM_ALLOC_FAILED; |
Namhyung Kim | 0ca8da0 | 2012-09-07 11:49:46 +0900 | [diff] [blame] | 6721 | } |
| 6722 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6723 | handle->id = id; |
| 6724 | if (event_name) |
| 6725 | handle->event_name = strdup(event_name); |
| 6726 | if (sys_name) |
| 6727 | handle->sys_name = strdup(sys_name); |
| 6728 | |
Namhyung Kim | ca63858 | 2012-04-09 11:54:31 +0900 | [diff] [blame] | 6729 | if ((event_name && !handle->event_name) || |
| 6730 | (sys_name && !handle->sys_name)) { |
Namhyung Kim | 0ca8da0 | 2012-09-07 11:49:46 +0900 | [diff] [blame] | 6731 | do_warning("Failed to allocate event/sys name"); |
| 6732 | free((void *)handle->event_name); |
| 6733 | free((void *)handle->sys_name); |
| 6734 | free(handle); |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 6735 | return TEP_ERRNO__MEM_ALLOC_FAILED; |
Namhyung Kim | ca63858 | 2012-04-09 11:54:31 +0900 | [diff] [blame] | 6736 | } |
| 6737 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6738 | handle->func = func; |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6739 | handle->next = tep->handlers; |
| 6740 | tep->handlers = handle; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6741 | handle->context = context; |
| 6742 | |
Tzvetomir Stoyanov | f87ce7c | 2018-11-30 23:08:11 -0500 | [diff] [blame] | 6743 | return TEP_REGISTER_SUCCESS; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6744 | } |
| 6745 | |
Namhyung Kim | ad13701 | 2014-01-16 11:31:07 +0900 | [diff] [blame] | 6746 | static int handle_matches(struct event_handler *handler, int id, |
| 6747 | const char *sys_name, const char *event_name, |
Tzvetomir Stoyanov (VMware) | c32d52b | 2018-08-08 14:02:48 -0400 | [diff] [blame] | 6748 | tep_event_handler_func func, void *context) |
Namhyung Kim | ad13701 | 2014-01-16 11:31:07 +0900 | [diff] [blame] | 6749 | { |
| 6750 | if (id >= 0 && id != handler->id) |
| 6751 | return 0; |
| 6752 | |
| 6753 | if (event_name && (strcmp(event_name, handler->event_name) != 0)) |
| 6754 | return 0; |
| 6755 | |
| 6756 | if (sys_name && (strcmp(sys_name, handler->sys_name) != 0)) |
| 6757 | return 0; |
| 6758 | |
| 6759 | if (func != handler->func || context != handler->context) |
| 6760 | return 0; |
| 6761 | |
| 6762 | return 1; |
| 6763 | } |
| 6764 | |
| 6765 | /** |
Tzvetomir Stoyanov (VMware) | b843e9c | 2018-08-08 14:03:02 -0400 | [diff] [blame] | 6766 | * tep_unregister_event_handler - unregister an existing event handler |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6767 | * @tep: a handle to the trace event parser context |
Namhyung Kim | ad13701 | 2014-01-16 11:31:07 +0900 | [diff] [blame] | 6768 | * @id: the id of the event to unregister |
| 6769 | * @sys_name: the system name the handler belongs to |
| 6770 | * @event_name: the name of the event handler |
| 6771 | * @func: the function to call to parse the event information |
| 6772 | * @context: the data to be passed to @func |
| 6773 | * |
| 6774 | * This function removes existing event handler (parser). |
| 6775 | * |
| 6776 | * If @id is >= 0, then it is used to find the event. |
| 6777 | * else @sys_name and @event_name are used. |
| 6778 | * |
| 6779 | * Returns 0 if handler was removed successfully, -1 if event was not found. |
| 6780 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6781 | int tep_unregister_event_handler(struct tep_handle *tep, int id, |
Tzvetomir Stoyanov (VMware) | b843e9c | 2018-08-08 14:03:02 -0400 | [diff] [blame] | 6782 | const char *sys_name, const char *event_name, |
| 6783 | tep_event_handler_func func, void *context) |
Namhyung Kim | ad13701 | 2014-01-16 11:31:07 +0900 | [diff] [blame] | 6784 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 6785 | struct tep_event *event; |
Namhyung Kim | ad13701 | 2014-01-16 11:31:07 +0900 | [diff] [blame] | 6786 | struct event_handler *handle; |
| 6787 | struct event_handler **next; |
| 6788 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6789 | event = search_event(tep, id, sys_name, event_name); |
Namhyung Kim | ad13701 | 2014-01-16 11:31:07 +0900 | [diff] [blame] | 6790 | if (event == NULL) |
| 6791 | goto not_found; |
| 6792 | |
| 6793 | if (event->handler == func && event->context == context) { |
| 6794 | pr_stat("removing override handler for event (%d) %s:%s. Going back to default handler.", |
| 6795 | event->id, event->system, event->name); |
| 6796 | |
| 6797 | event->handler = NULL; |
| 6798 | event->context = NULL; |
| 6799 | return 0; |
| 6800 | } |
| 6801 | |
| 6802 | not_found: |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6803 | for (next = &tep->handlers; *next; next = &(*next)->next) { |
Namhyung Kim | ad13701 | 2014-01-16 11:31:07 +0900 | [diff] [blame] | 6804 | handle = *next; |
| 6805 | if (handle_matches(handle, id, sys_name, event_name, |
| 6806 | func, context)) |
| 6807 | break; |
| 6808 | } |
| 6809 | |
| 6810 | if (!(*next)) |
| 6811 | return -1; |
| 6812 | |
| 6813 | *next = handle->next; |
| 6814 | free_handler(handle); |
| 6815 | |
| 6816 | return 0; |
| 6817 | } |
| 6818 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6819 | /** |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6820 | * tep_alloc - create a tep handle |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6821 | */ |
Tzvetomir Stoyanov (VMware) | 4d5c58b | 2018-08-08 14:02:49 -0400 | [diff] [blame] | 6822 | struct tep_handle *tep_alloc(void) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6823 | { |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 6824 | struct tep_handle *pevent = calloc(1, sizeof(*pevent)); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6825 | |
Tzvetomir Stoyanov | eed14f4 | 2018-11-30 23:08:08 -0500 | [diff] [blame] | 6826 | if (pevent) { |
Arnaldo Carvalho de Melo | 87162d8 | 2012-09-12 15:39:59 -0300 | [diff] [blame] | 6827 | pevent->ref_count = 1; |
Tzvetomir Stoyanov | 55c34ae | 2019-04-01 12:43:16 -0400 | [diff] [blame] | 6828 | pevent->host_bigendian = tep_is_bigendian(); |
Tzvetomir Stoyanov | eed14f4 | 2018-11-30 23:08:08 -0500 | [diff] [blame] | 6829 | } |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6830 | |
| 6831 | return pevent; |
| 6832 | } |
| 6833 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6834 | void tep_ref(struct tep_handle *tep) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6835 | { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6836 | tep->ref_count++; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6837 | } |
| 6838 | |
Tzvetomir Stoyanov | 477be10 | 2018-11-30 10:44:04 -0500 | [diff] [blame] | 6839 | int tep_get_ref(struct tep_handle *tep) |
| 6840 | { |
| 6841 | if (tep) |
| 6842 | return tep->ref_count; |
| 6843 | return 0; |
| 6844 | } |
| 6845 | |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 6846 | void tep_free_format_field(struct tep_format_field *field) |
David Ahern | 00ae112 | 2015-03-19 12:36:21 -0600 | [diff] [blame] | 6847 | { |
| 6848 | free(field->type); |
Jiri Olsa | d354243 | 2015-04-18 17:50:18 +0200 | [diff] [blame] | 6849 | if (field->alias != field->name) |
| 6850 | free(field->alias); |
David Ahern | 00ae112 | 2015-03-19 12:36:21 -0600 | [diff] [blame] | 6851 | free(field->name); |
| 6852 | free(field); |
| 6853 | } |
| 6854 | |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 6855 | static void free_format_fields(struct tep_format_field *field) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6856 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 6857 | struct tep_format_field *next; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6858 | |
| 6859 | while (field) { |
| 6860 | next = field->next; |
Tzvetomir Stoyanov (VMware) | 8b3e087 | 2018-08-08 14:03:04 -0400 | [diff] [blame] | 6861 | tep_free_format_field(field); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6862 | field = next; |
| 6863 | } |
| 6864 | } |
| 6865 | |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 6866 | static void free_formats(struct tep_format *format) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6867 | { |
| 6868 | free_format_fields(format->common_fields); |
| 6869 | free_format_fields(format->fields); |
| 6870 | } |
| 6871 | |
Tzvetomir Stoyanov | fc39851 | 2018-11-30 10:44:08 -0500 | [diff] [blame] | 6872 | void tep_free_event(struct tep_event *event) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6873 | { |
| 6874 | free(event->name); |
| 6875 | free(event->system); |
| 6876 | |
| 6877 | free_formats(&event->format); |
| 6878 | |
| 6879 | free(event->print_fmt.format); |
| 6880 | free_args(event->print_fmt.args); |
| 6881 | |
| 6882 | free(event); |
| 6883 | } |
| 6884 | |
| 6885 | /** |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6886 | * tep_free - free a tep handle |
| 6887 | * @tep: the tep handle to free |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6888 | */ |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6889 | void tep_free(struct tep_handle *tep) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6890 | { |
Steven Rostedt | a2525a0 | 2012-04-06 00:48:02 +0200 | [diff] [blame] | 6891 | struct cmdline_list *cmdlist, *cmdnext; |
| 6892 | struct func_list *funclist, *funcnext; |
| 6893 | struct printk_list *printklist, *printknext; |
Tzvetomir Stoyanov (VMware) | 3cf4778 | 2018-08-08 14:02:59 -0400 | [diff] [blame] | 6894 | struct tep_function_handler *func_handler; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6895 | struct event_handler *handle; |
| 6896 | int i; |
| 6897 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6898 | if (!tep) |
Steven Rostedt | a2525a0 | 2012-04-06 00:48:02 +0200 | [diff] [blame] | 6899 | return; |
| 6900 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6901 | cmdlist = tep->cmdlist; |
| 6902 | funclist = tep->funclist; |
| 6903 | printklist = tep->printklist; |
Steven Rostedt | a2525a0 | 2012-04-06 00:48:02 +0200 | [diff] [blame] | 6904 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6905 | tep->ref_count--; |
| 6906 | if (tep->ref_count) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6907 | return; |
| 6908 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6909 | if (tep->cmdlines) { |
| 6910 | for (i = 0; i < tep->cmdline_count; i++) |
| 6911 | free(tep->cmdlines[i].comm); |
| 6912 | free(tep->cmdlines); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6913 | } |
| 6914 | |
| 6915 | while (cmdlist) { |
| 6916 | cmdnext = cmdlist->next; |
| 6917 | free(cmdlist->comm); |
| 6918 | free(cmdlist); |
| 6919 | cmdlist = cmdnext; |
| 6920 | } |
| 6921 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6922 | if (tep->func_map) { |
| 6923 | for (i = 0; i < (int)tep->func_count; i++) { |
| 6924 | free(tep->func_map[i].func); |
| 6925 | free(tep->func_map[i].mod); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6926 | } |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6927 | free(tep->func_map); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6928 | } |
| 6929 | |
| 6930 | while (funclist) { |
| 6931 | funcnext = funclist->next; |
| 6932 | free(funclist->func); |
| 6933 | free(funclist->mod); |
| 6934 | free(funclist); |
| 6935 | funclist = funcnext; |
| 6936 | } |
| 6937 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6938 | while (tep->func_handlers) { |
| 6939 | func_handler = tep->func_handlers; |
| 6940 | tep->func_handlers = func_handler->next; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6941 | free_func_handle(func_handler); |
| 6942 | } |
| 6943 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6944 | if (tep->printk_map) { |
| 6945 | for (i = 0; i < (int)tep->printk_count; i++) |
| 6946 | free(tep->printk_map[i].printk); |
| 6947 | free(tep->printk_map); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6948 | } |
| 6949 | |
| 6950 | while (printklist) { |
| 6951 | printknext = printklist->next; |
| 6952 | free(printklist->printk); |
| 6953 | free(printklist); |
| 6954 | printklist = printknext; |
| 6955 | } |
| 6956 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6957 | for (i = 0; i < tep->nr_events; i++) |
| 6958 | tep_free_event(tep->events[i]); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6959 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6960 | while (tep->handlers) { |
| 6961 | handle = tep->handlers; |
| 6962 | tep->handlers = handle->next; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6963 | free_handler(handle); |
| 6964 | } |
| 6965 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6966 | free(tep->trace_clock); |
| 6967 | free(tep->events); |
| 6968 | free(tep->sort_events); |
| 6969 | free(tep->func_resolver); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6970 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6971 | free(tep); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6972 | } |
| 6973 | |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6974 | void tep_unref(struct tep_handle *tep) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6975 | { |
Tzvetomir Stoyanov | 047ff22 | 2019-04-01 12:43:17 -0400 | [diff] [blame^] | 6976 | tep_free(tep); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 6977 | } |