| .. | .. |
|---|
| 18 | 18 | #include <errno.h> |
|---|
| 19 | 19 | #include <stdint.h> |
|---|
| 20 | 20 | #include <limits.h> |
|---|
| 21 | | -#include <linux/string.h> |
|---|
| 22 | 21 | #include <linux/time64.h> |
|---|
| 23 | 22 | |
|---|
| 24 | 23 | #include <netinet/in.h> |
|---|
| 25 | 24 | #include "event-parse.h" |
|---|
| 25 | + |
|---|
| 26 | +#include "event-parse-local.h" |
|---|
| 26 | 27 | #include "event-utils.h" |
|---|
| 28 | +#include "trace-seq.h" |
|---|
| 27 | 29 | |
|---|
| 28 | 30 | static const char *input_buf; |
|---|
| 29 | 31 | static unsigned long long input_buf_ptr; |
|---|
| .. | .. |
|---|
| 52 | 54 | warning(fmt, ##__VA_ARGS__); \ |
|---|
| 53 | 55 | } while (0) |
|---|
| 54 | 56 | |
|---|
| 55 | | -static void init_input_buf(const char *buf, unsigned long long size) |
|---|
| 57 | +/** |
|---|
| 58 | + * init_input_buf - init buffer for parsing |
|---|
| 59 | + * @buf: buffer to parse |
|---|
| 60 | + * @size: the size of the buffer |
|---|
| 61 | + * |
|---|
| 62 | + * Initializes the internal buffer that tep_read_token() will parse. |
|---|
| 63 | + */ |
|---|
| 64 | +__hidden void init_input_buf(const char *buf, unsigned long long size) |
|---|
| 56 | 65 | { |
|---|
| 57 | 66 | input_buf = buf; |
|---|
| 58 | 67 | input_buf_siz = size; |
|---|
| 59 | 68 | input_buf_ptr = 0; |
|---|
| 60 | 69 | } |
|---|
| 61 | 70 | |
|---|
| 62 | | -const char *tep_get_input_buf(void) |
|---|
| 71 | +__hidden const char *get_input_buf(void) |
|---|
| 63 | 72 | { |
|---|
| 64 | 73 | return input_buf; |
|---|
| 65 | 74 | } |
|---|
| 66 | 75 | |
|---|
| 67 | | -unsigned long long tep_get_input_buf_ptr(void) |
|---|
| 76 | +__hidden unsigned long long get_input_buf_ptr(void) |
|---|
| 68 | 77 | { |
|---|
| 69 | 78 | return input_buf_ptr; |
|---|
| 70 | 79 | } |
|---|
| .. | .. |
|---|
| 94 | 103 | |
|---|
| 95 | 104 | static unsigned long long |
|---|
| 96 | 105 | process_defined_func(struct trace_seq *s, void *data, int size, |
|---|
| 97 | | - struct event_format *event, struct print_arg *arg); |
|---|
| 106 | + struct tep_event *event, struct tep_print_arg *arg); |
|---|
| 98 | 107 | |
|---|
| 99 | 108 | static void free_func_handle(struct tep_function_handler *func); |
|---|
| 100 | | - |
|---|
| 101 | | -/** |
|---|
| 102 | | - * tep_buffer_init - init buffer for parsing |
|---|
| 103 | | - * @buf: buffer to parse |
|---|
| 104 | | - * @size: the size of the buffer |
|---|
| 105 | | - * |
|---|
| 106 | | - * For use with tep_read_token(), this initializes the internal |
|---|
| 107 | | - * buffer that tep_read_token() will parse. |
|---|
| 108 | | - */ |
|---|
| 109 | | -void tep_buffer_init(const char *buf, unsigned long long size) |
|---|
| 110 | | -{ |
|---|
| 111 | | - init_input_buf(buf, size); |
|---|
| 112 | | -} |
|---|
| 113 | 109 | |
|---|
| 114 | 110 | void breakpoint(void) |
|---|
| 115 | 111 | { |
|---|
| .. | .. |
|---|
| 117 | 113 | x++; |
|---|
| 118 | 114 | } |
|---|
| 119 | 115 | |
|---|
| 120 | | -struct print_arg *alloc_arg(void) |
|---|
| 116 | +static struct tep_print_arg *alloc_arg(void) |
|---|
| 121 | 117 | { |
|---|
| 122 | | - return calloc(1, sizeof(struct print_arg)); |
|---|
| 118 | + return calloc(1, sizeof(struct tep_print_arg)); |
|---|
| 123 | 119 | } |
|---|
| 124 | 120 | |
|---|
| 125 | | -struct cmdline { |
|---|
| 121 | +struct tep_cmdline { |
|---|
| 126 | 122 | char *comm; |
|---|
| 127 | 123 | int pid; |
|---|
| 128 | 124 | }; |
|---|
| 129 | 125 | |
|---|
| 130 | 126 | static int cmdline_cmp(const void *a, const void *b) |
|---|
| 131 | 127 | { |
|---|
| 132 | | - const struct cmdline *ca = a; |
|---|
| 133 | | - const struct cmdline *cb = b; |
|---|
| 128 | + const struct tep_cmdline *ca = a; |
|---|
| 129 | + const struct tep_cmdline *cb = b; |
|---|
| 134 | 130 | |
|---|
| 135 | 131 | if (ca->pid < cb->pid) |
|---|
| 136 | 132 | return -1; |
|---|
| 137 | 133 | if (ca->pid > cb->pid) |
|---|
| 138 | 134 | return 1; |
|---|
| 135 | + |
|---|
| 136 | + return 0; |
|---|
| 137 | +} |
|---|
| 138 | + |
|---|
| 139 | +/* Looking for where to place the key */ |
|---|
| 140 | +static int cmdline_slot_cmp(const void *a, const void *b) |
|---|
| 141 | +{ |
|---|
| 142 | + const struct tep_cmdline *ca = a; |
|---|
| 143 | + const struct tep_cmdline *cb = b; |
|---|
| 144 | + const struct tep_cmdline *cb1 = cb + 1; |
|---|
| 145 | + |
|---|
| 146 | + if (ca->pid < cb->pid) |
|---|
| 147 | + return -1; |
|---|
| 148 | + |
|---|
| 149 | + if (ca->pid > cb->pid) { |
|---|
| 150 | + if (ca->pid <= cb1->pid) |
|---|
| 151 | + return 0; |
|---|
| 152 | + return 1; |
|---|
| 153 | + } |
|---|
| 139 | 154 | |
|---|
| 140 | 155 | return 0; |
|---|
| 141 | 156 | } |
|---|
| .. | .. |
|---|
| 146 | 161 | int pid; |
|---|
| 147 | 162 | }; |
|---|
| 148 | 163 | |
|---|
| 149 | | -static int cmdline_init(struct tep_handle *pevent) |
|---|
| 164 | +static int cmdline_init(struct tep_handle *tep) |
|---|
| 150 | 165 | { |
|---|
| 151 | | - struct cmdline_list *cmdlist = pevent->cmdlist; |
|---|
| 166 | + struct cmdline_list *cmdlist = tep->cmdlist; |
|---|
| 152 | 167 | struct cmdline_list *item; |
|---|
| 153 | | - struct cmdline *cmdlines; |
|---|
| 168 | + struct tep_cmdline *cmdlines; |
|---|
| 154 | 169 | int i; |
|---|
| 155 | 170 | |
|---|
| 156 | | - cmdlines = malloc(sizeof(*cmdlines) * pevent->cmdline_count); |
|---|
| 171 | + cmdlines = malloc(sizeof(*cmdlines) * tep->cmdline_count); |
|---|
| 157 | 172 | if (!cmdlines) |
|---|
| 158 | 173 | return -1; |
|---|
| 159 | 174 | |
|---|
| .. | .. |
|---|
| 167 | 182 | free(item); |
|---|
| 168 | 183 | } |
|---|
| 169 | 184 | |
|---|
| 170 | | - qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp); |
|---|
| 185 | + qsort(cmdlines, tep->cmdline_count, sizeof(*cmdlines), cmdline_cmp); |
|---|
| 171 | 186 | |
|---|
| 172 | | - pevent->cmdlines = cmdlines; |
|---|
| 173 | | - pevent->cmdlist = NULL; |
|---|
| 187 | + tep->cmdlines = cmdlines; |
|---|
| 188 | + tep->cmdlist = NULL; |
|---|
| 174 | 189 | |
|---|
| 175 | 190 | return 0; |
|---|
| 176 | 191 | } |
|---|
| 177 | 192 | |
|---|
| 178 | | -static const char *find_cmdline(struct tep_handle *pevent, int pid) |
|---|
| 193 | +static const char *find_cmdline(struct tep_handle *tep, int pid) |
|---|
| 179 | 194 | { |
|---|
| 180 | | - const struct cmdline *comm; |
|---|
| 181 | | - struct cmdline key; |
|---|
| 195 | + const struct tep_cmdline *comm; |
|---|
| 196 | + struct tep_cmdline key; |
|---|
| 182 | 197 | |
|---|
| 183 | 198 | if (!pid) |
|---|
| 184 | 199 | return "<idle>"; |
|---|
| 185 | 200 | |
|---|
| 186 | | - if (!pevent->cmdlines && cmdline_init(pevent)) |
|---|
| 201 | + if (!tep->cmdlines && cmdline_init(tep)) |
|---|
| 187 | 202 | return "<not enough memory for cmdlines!>"; |
|---|
| 188 | 203 | |
|---|
| 189 | 204 | key.pid = pid; |
|---|
| 190 | 205 | |
|---|
| 191 | | - comm = bsearch(&key, pevent->cmdlines, pevent->cmdline_count, |
|---|
| 192 | | - sizeof(*pevent->cmdlines), cmdline_cmp); |
|---|
| 206 | + comm = bsearch(&key, tep->cmdlines, tep->cmdline_count, |
|---|
| 207 | + sizeof(*tep->cmdlines), cmdline_cmp); |
|---|
| 193 | 208 | |
|---|
| 194 | 209 | if (comm) |
|---|
| 195 | 210 | return comm->comm; |
|---|
| .. | .. |
|---|
| 197 | 212 | } |
|---|
| 198 | 213 | |
|---|
| 199 | 214 | /** |
|---|
| 200 | | - * tep_pid_is_registered - return if a pid has a cmdline registered |
|---|
| 201 | | - * @pevent: handle for the pevent |
|---|
| 215 | + * tep_is_pid_registered - return if a pid has a cmdline registered |
|---|
| 216 | + * @tep: a handle to the trace event parser context |
|---|
| 202 | 217 | * @pid: The pid to check if it has a cmdline registered with. |
|---|
| 203 | 218 | * |
|---|
| 204 | | - * Returns 1 if the pid has a cmdline mapped to it |
|---|
| 205 | | - * 0 otherwise. |
|---|
| 219 | + * Returns true if the pid has a cmdline mapped to it |
|---|
| 220 | + * false otherwise. |
|---|
| 206 | 221 | */ |
|---|
| 207 | | -int tep_pid_is_registered(struct tep_handle *pevent, int pid) |
|---|
| 222 | +bool tep_is_pid_registered(struct tep_handle *tep, int pid) |
|---|
| 208 | 223 | { |
|---|
| 209 | | - const struct cmdline *comm; |
|---|
| 210 | | - struct cmdline key; |
|---|
| 224 | + const struct tep_cmdline *comm; |
|---|
| 225 | + struct tep_cmdline key; |
|---|
| 211 | 226 | |
|---|
| 212 | 227 | if (!pid) |
|---|
| 213 | | - return 1; |
|---|
| 228 | + return true; |
|---|
| 214 | 229 | |
|---|
| 215 | | - if (!pevent->cmdlines && cmdline_init(pevent)) |
|---|
| 216 | | - return 0; |
|---|
| 230 | + if (!tep->cmdlines && cmdline_init(tep)) |
|---|
| 231 | + return false; |
|---|
| 217 | 232 | |
|---|
| 218 | 233 | key.pid = pid; |
|---|
| 219 | 234 | |
|---|
| 220 | | - comm = bsearch(&key, pevent->cmdlines, pevent->cmdline_count, |
|---|
| 221 | | - sizeof(*pevent->cmdlines), cmdline_cmp); |
|---|
| 235 | + comm = bsearch(&key, tep->cmdlines, tep->cmdline_count, |
|---|
| 236 | + sizeof(*tep->cmdlines), cmdline_cmp); |
|---|
| 222 | 237 | |
|---|
| 223 | 238 | if (comm) |
|---|
| 224 | | - return 1; |
|---|
| 225 | | - return 0; |
|---|
| 239 | + return true; |
|---|
| 240 | + return false; |
|---|
| 226 | 241 | } |
|---|
| 227 | 242 | |
|---|
| 228 | 243 | /* |
|---|
| .. | .. |
|---|
| 230 | 245 | * we must add this pid. This is much slower than when cmdlines |
|---|
| 231 | 246 | * are added before the array is initialized. |
|---|
| 232 | 247 | */ |
|---|
| 233 | | -static int add_new_comm(struct tep_handle *pevent, const char *comm, int pid) |
|---|
| 248 | +static int add_new_comm(struct tep_handle *tep, |
|---|
| 249 | + const char *comm, int pid, bool override) |
|---|
| 234 | 250 | { |
|---|
| 235 | | - struct cmdline *cmdlines = pevent->cmdlines; |
|---|
| 236 | | - const struct cmdline *cmdline; |
|---|
| 237 | | - struct cmdline key; |
|---|
| 251 | + struct tep_cmdline *cmdlines = tep->cmdlines; |
|---|
| 252 | + struct tep_cmdline *cmdline; |
|---|
| 253 | + struct tep_cmdline key; |
|---|
| 254 | + char *new_comm; |
|---|
| 255 | + int cnt; |
|---|
| 238 | 256 | |
|---|
| 239 | 257 | if (!pid) |
|---|
| 240 | 258 | return 0; |
|---|
| .. | .. |
|---|
| 242 | 260 | /* avoid duplicates */ |
|---|
| 243 | 261 | key.pid = pid; |
|---|
| 244 | 262 | |
|---|
| 245 | | - cmdline = bsearch(&key, pevent->cmdlines, pevent->cmdline_count, |
|---|
| 246 | | - sizeof(*pevent->cmdlines), cmdline_cmp); |
|---|
| 263 | + cmdline = bsearch(&key, tep->cmdlines, tep->cmdline_count, |
|---|
| 264 | + sizeof(*tep->cmdlines), cmdline_cmp); |
|---|
| 247 | 265 | if (cmdline) { |
|---|
| 248 | | - errno = EEXIST; |
|---|
| 249 | | - return -1; |
|---|
| 266 | + if (!override) { |
|---|
| 267 | + errno = EEXIST; |
|---|
| 268 | + return -1; |
|---|
| 269 | + } |
|---|
| 270 | + new_comm = strdup(comm); |
|---|
| 271 | + if (!new_comm) { |
|---|
| 272 | + errno = ENOMEM; |
|---|
| 273 | + return -1; |
|---|
| 274 | + } |
|---|
| 275 | + free(cmdline->comm); |
|---|
| 276 | + cmdline->comm = new_comm; |
|---|
| 277 | + |
|---|
| 278 | + return 0; |
|---|
| 250 | 279 | } |
|---|
| 251 | 280 | |
|---|
| 252 | | - cmdlines = realloc(cmdlines, sizeof(*cmdlines) * (pevent->cmdline_count + 1)); |
|---|
| 281 | + cmdlines = realloc(cmdlines, sizeof(*cmdlines) * (tep->cmdline_count + 1)); |
|---|
| 253 | 282 | if (!cmdlines) { |
|---|
| 254 | 283 | errno = ENOMEM; |
|---|
| 255 | 284 | return -1; |
|---|
| 256 | 285 | } |
|---|
| 257 | | - pevent->cmdlines = cmdlines; |
|---|
| 286 | + tep->cmdlines = cmdlines; |
|---|
| 258 | 287 | |
|---|
| 259 | | - cmdlines[pevent->cmdline_count].comm = strdup(comm); |
|---|
| 260 | | - if (!cmdlines[pevent->cmdline_count].comm) { |
|---|
| 288 | + key.comm = strdup(comm); |
|---|
| 289 | + if (!key.comm) { |
|---|
| 261 | 290 | errno = ENOMEM; |
|---|
| 262 | 291 | return -1; |
|---|
| 263 | 292 | } |
|---|
| 264 | 293 | |
|---|
| 265 | | - cmdlines[pevent->cmdline_count].pid = pid; |
|---|
| 266 | | - |
|---|
| 267 | | - if (cmdlines[pevent->cmdline_count].comm) |
|---|
| 268 | | - pevent->cmdline_count++; |
|---|
| 294 | + if (!tep->cmdline_count) { |
|---|
| 295 | + /* no entries yet */ |
|---|
| 296 | + tep->cmdlines[0] = key; |
|---|
| 297 | + tep->cmdline_count++; |
|---|
| 298 | + return 0; |
|---|
| 299 | + } |
|---|
| 269 | 300 | |
|---|
| 270 | | - qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp); |
|---|
| 301 | + /* Now find where we want to store the new cmdline */ |
|---|
| 302 | + cmdline = bsearch(&key, tep->cmdlines, tep->cmdline_count - 1, |
|---|
| 303 | + sizeof(*tep->cmdlines), cmdline_slot_cmp); |
|---|
| 304 | + |
|---|
| 305 | + cnt = tep->cmdline_count; |
|---|
| 306 | + if (cmdline) { |
|---|
| 307 | + /* cmdline points to the one before the spot we want */ |
|---|
| 308 | + cmdline++; |
|---|
| 309 | + cnt -= cmdline - tep->cmdlines; |
|---|
| 310 | + |
|---|
| 311 | + } else { |
|---|
| 312 | + /* The new entry is either before or after the list */ |
|---|
| 313 | + if (key.pid > tep->cmdlines[tep->cmdline_count - 1].pid) { |
|---|
| 314 | + tep->cmdlines[tep->cmdline_count++] = key; |
|---|
| 315 | + return 0; |
|---|
| 316 | + } |
|---|
| 317 | + cmdline = &tep->cmdlines[0]; |
|---|
| 318 | + } |
|---|
| 319 | + memmove(cmdline + 1, cmdline, (cnt * sizeof(*cmdline))); |
|---|
| 320 | + *cmdline = key; |
|---|
| 321 | + |
|---|
| 322 | + tep->cmdline_count++; |
|---|
| 271 | 323 | |
|---|
| 272 | 324 | return 0; |
|---|
| 273 | 325 | } |
|---|
| 274 | 326 | |
|---|
| 275 | | -/** |
|---|
| 276 | | - * tep_register_comm - register a pid / comm mapping |
|---|
| 277 | | - * @pevent: handle for the pevent |
|---|
| 278 | | - * @comm: the command line to register |
|---|
| 279 | | - * @pid: the pid to map the command line to |
|---|
| 280 | | - * |
|---|
| 281 | | - * This adds a mapping to search for command line names with |
|---|
| 282 | | - * a given pid. The comm is duplicated. |
|---|
| 283 | | - */ |
|---|
| 284 | | -int tep_register_comm(struct tep_handle *pevent, const char *comm, int pid) |
|---|
| 327 | +static int _tep_register_comm(struct tep_handle *tep, |
|---|
| 328 | + const char *comm, int pid, bool override) |
|---|
| 285 | 329 | { |
|---|
| 286 | 330 | struct cmdline_list *item; |
|---|
| 287 | 331 | |
|---|
| 288 | | - if (pevent->cmdlines) |
|---|
| 289 | | - return add_new_comm(pevent, comm, pid); |
|---|
| 332 | + if (tep->cmdlines) |
|---|
| 333 | + return add_new_comm(tep, comm, pid, override); |
|---|
| 290 | 334 | |
|---|
| 291 | 335 | item = malloc(sizeof(*item)); |
|---|
| 292 | 336 | if (!item) |
|---|
| .. | .. |
|---|
| 301 | 345 | return -1; |
|---|
| 302 | 346 | } |
|---|
| 303 | 347 | item->pid = pid; |
|---|
| 304 | | - item->next = pevent->cmdlist; |
|---|
| 348 | + item->next = tep->cmdlist; |
|---|
| 305 | 349 | |
|---|
| 306 | | - pevent->cmdlist = item; |
|---|
| 307 | | - pevent->cmdline_count++; |
|---|
| 350 | + tep->cmdlist = item; |
|---|
| 351 | + tep->cmdline_count++; |
|---|
| 308 | 352 | |
|---|
| 309 | 353 | return 0; |
|---|
| 310 | 354 | } |
|---|
| 311 | 355 | |
|---|
| 312 | | -int tep_register_trace_clock(struct tep_handle *pevent, const char *trace_clock) |
|---|
| 356 | +/** |
|---|
| 357 | + * tep_register_comm - register a pid / comm mapping |
|---|
| 358 | + * @tep: a handle to the trace event parser context |
|---|
| 359 | + * @comm: the command line to register |
|---|
| 360 | + * @pid: the pid to map the command line to |
|---|
| 361 | + * |
|---|
| 362 | + * This adds a mapping to search for command line names with |
|---|
| 363 | + * a given pid. The comm is duplicated. If a command with the same pid |
|---|
| 364 | + * already exist, -1 is returned and errno is set to EEXIST |
|---|
| 365 | + */ |
|---|
| 366 | +int tep_register_comm(struct tep_handle *tep, const char *comm, int pid) |
|---|
| 313 | 367 | { |
|---|
| 314 | | - pevent->trace_clock = strdup(trace_clock); |
|---|
| 315 | | - if (!pevent->trace_clock) { |
|---|
| 368 | + return _tep_register_comm(tep, comm, pid, false); |
|---|
| 369 | +} |
|---|
| 370 | + |
|---|
| 371 | +/** |
|---|
| 372 | + * tep_override_comm - register a pid / comm mapping |
|---|
| 373 | + * @tep: a handle to the trace event parser context |
|---|
| 374 | + * @comm: the command line to register |
|---|
| 375 | + * @pid: the pid to map the command line to |
|---|
| 376 | + * |
|---|
| 377 | + * This adds a mapping to search for command line names with |
|---|
| 378 | + * a given pid. The comm is duplicated. If a command with the same pid |
|---|
| 379 | + * already exist, the command string is udapted with the new one |
|---|
| 380 | + */ |
|---|
| 381 | +int tep_override_comm(struct tep_handle *tep, const char *comm, int pid) |
|---|
| 382 | +{ |
|---|
| 383 | + if (!tep->cmdlines && cmdline_init(tep)) { |
|---|
| 316 | 384 | errno = ENOMEM; |
|---|
| 317 | 385 | return -1; |
|---|
| 318 | 386 | } |
|---|
| 319 | | - return 0; |
|---|
| 387 | + return _tep_register_comm(tep, comm, pid, true); |
|---|
| 320 | 388 | } |
|---|
| 321 | 389 | |
|---|
| 322 | 390 | struct func_map { |
|---|
| .. | .. |
|---|
| 366 | 434 | return 1; |
|---|
| 367 | 435 | } |
|---|
| 368 | 436 | |
|---|
| 369 | | -static int func_map_init(struct tep_handle *pevent) |
|---|
| 437 | +static int func_map_init(struct tep_handle *tep) |
|---|
| 370 | 438 | { |
|---|
| 371 | 439 | struct func_list *funclist; |
|---|
| 372 | 440 | struct func_list *item; |
|---|
| 373 | 441 | struct func_map *func_map; |
|---|
| 374 | 442 | int i; |
|---|
| 375 | 443 | |
|---|
| 376 | | - func_map = malloc(sizeof(*func_map) * (pevent->func_count + 1)); |
|---|
| 444 | + func_map = malloc(sizeof(*func_map) * (tep->func_count + 1)); |
|---|
| 377 | 445 | if (!func_map) |
|---|
| 378 | 446 | return -1; |
|---|
| 379 | 447 | |
|---|
| 380 | | - funclist = pevent->funclist; |
|---|
| 448 | + funclist = tep->funclist; |
|---|
| 381 | 449 | |
|---|
| 382 | 450 | i = 0; |
|---|
| 383 | 451 | while (funclist) { |
|---|
| .. | .. |
|---|
| 390 | 458 | free(item); |
|---|
| 391 | 459 | } |
|---|
| 392 | 460 | |
|---|
| 393 | | - qsort(func_map, pevent->func_count, sizeof(*func_map), func_cmp); |
|---|
| 461 | + qsort(func_map, tep->func_count, sizeof(*func_map), func_cmp); |
|---|
| 394 | 462 | |
|---|
| 395 | 463 | /* |
|---|
| 396 | 464 | * Add a special record at the end. |
|---|
| 397 | 465 | */ |
|---|
| 398 | | - func_map[pevent->func_count].func = NULL; |
|---|
| 399 | | - func_map[pevent->func_count].addr = 0; |
|---|
| 400 | | - func_map[pevent->func_count].mod = NULL; |
|---|
| 466 | + func_map[tep->func_count].func = NULL; |
|---|
| 467 | + func_map[tep->func_count].addr = 0; |
|---|
| 468 | + func_map[tep->func_count].mod = NULL; |
|---|
| 401 | 469 | |
|---|
| 402 | | - pevent->func_map = func_map; |
|---|
| 403 | | - pevent->funclist = NULL; |
|---|
| 470 | + tep->func_map = func_map; |
|---|
| 471 | + tep->funclist = NULL; |
|---|
| 404 | 472 | |
|---|
| 405 | 473 | return 0; |
|---|
| 406 | 474 | } |
|---|
| 407 | 475 | |
|---|
| 408 | 476 | static struct func_map * |
|---|
| 409 | | -__find_func(struct tep_handle *pevent, unsigned long long addr) |
|---|
| 477 | +__find_func(struct tep_handle *tep, unsigned long long addr) |
|---|
| 410 | 478 | { |
|---|
| 411 | 479 | struct func_map *func; |
|---|
| 412 | 480 | struct func_map key; |
|---|
| 413 | 481 | |
|---|
| 414 | | - if (!pevent->func_map) |
|---|
| 415 | | - func_map_init(pevent); |
|---|
| 482 | + if (!tep->func_map) |
|---|
| 483 | + func_map_init(tep); |
|---|
| 416 | 484 | |
|---|
| 417 | 485 | key.addr = addr; |
|---|
| 418 | 486 | |
|---|
| 419 | | - func = bsearch(&key, pevent->func_map, pevent->func_count, |
|---|
| 420 | | - sizeof(*pevent->func_map), func_bcmp); |
|---|
| 487 | + func = bsearch(&key, tep->func_map, tep->func_count, |
|---|
| 488 | + sizeof(*tep->func_map), func_bcmp); |
|---|
| 421 | 489 | |
|---|
| 422 | 490 | return func; |
|---|
| 423 | 491 | } |
|---|
| .. | .. |
|---|
| 430 | 498 | |
|---|
| 431 | 499 | /** |
|---|
| 432 | 500 | * tep_set_function_resolver - set an alternative function resolver |
|---|
| 433 | | - * @pevent: handle for the pevent |
|---|
| 501 | + * @tep: a handle to the trace event parser context |
|---|
| 434 | 502 | * @resolver: function to be used |
|---|
| 435 | 503 | * @priv: resolver function private state. |
|---|
| 436 | 504 | * |
|---|
| 437 | 505 | * Some tools may have already a way to resolve kernel functions, allow them to |
|---|
| 438 | | - * keep using it instead of duplicating all the entries inside |
|---|
| 439 | | - * pevent->funclist. |
|---|
| 506 | + * keep using it instead of duplicating all the entries inside tep->funclist. |
|---|
| 440 | 507 | */ |
|---|
| 441 | | -int tep_set_function_resolver(struct tep_handle *pevent, |
|---|
| 508 | +int tep_set_function_resolver(struct tep_handle *tep, |
|---|
| 442 | 509 | tep_func_resolver_t *func, void *priv) |
|---|
| 443 | 510 | { |
|---|
| 444 | 511 | struct func_resolver *resolver = malloc(sizeof(*resolver)); |
|---|
| .. | .. |
|---|
| 449 | 516 | resolver->func = func; |
|---|
| 450 | 517 | resolver->priv = priv; |
|---|
| 451 | 518 | |
|---|
| 452 | | - free(pevent->func_resolver); |
|---|
| 453 | | - pevent->func_resolver = resolver; |
|---|
| 519 | + free(tep->func_resolver); |
|---|
| 520 | + tep->func_resolver = resolver; |
|---|
| 454 | 521 | |
|---|
| 455 | 522 | return 0; |
|---|
| 456 | 523 | } |
|---|
| 457 | 524 | |
|---|
| 458 | 525 | /** |
|---|
| 459 | 526 | * tep_reset_function_resolver - reset alternative function resolver |
|---|
| 460 | | - * @pevent: handle for the pevent |
|---|
| 527 | + * @tep: a handle to the trace event parser context |
|---|
| 461 | 528 | * |
|---|
| 462 | 529 | * Stop using whatever alternative resolver was set, use the default |
|---|
| 463 | 530 | * one instead. |
|---|
| 464 | 531 | */ |
|---|
| 465 | | -void tep_reset_function_resolver(struct tep_handle *pevent) |
|---|
| 532 | +void tep_reset_function_resolver(struct tep_handle *tep) |
|---|
| 466 | 533 | { |
|---|
| 467 | | - free(pevent->func_resolver); |
|---|
| 468 | | - pevent->func_resolver = NULL; |
|---|
| 534 | + free(tep->func_resolver); |
|---|
| 535 | + tep->func_resolver = NULL; |
|---|
| 469 | 536 | } |
|---|
| 470 | 537 | |
|---|
| 471 | 538 | static struct func_map * |
|---|
| 472 | | -find_func(struct tep_handle *pevent, unsigned long long addr) |
|---|
| 539 | +find_func(struct tep_handle *tep, unsigned long long addr) |
|---|
| 473 | 540 | { |
|---|
| 474 | 541 | struct func_map *map; |
|---|
| 475 | 542 | |
|---|
| 476 | | - if (!pevent->func_resolver) |
|---|
| 477 | | - return __find_func(pevent, addr); |
|---|
| 543 | + if (!tep->func_resolver) |
|---|
| 544 | + return __find_func(tep, addr); |
|---|
| 478 | 545 | |
|---|
| 479 | | - map = &pevent->func_resolver->map; |
|---|
| 546 | + map = &tep->func_resolver->map; |
|---|
| 480 | 547 | map->mod = NULL; |
|---|
| 481 | 548 | map->addr = addr; |
|---|
| 482 | | - map->func = pevent->func_resolver->func(pevent->func_resolver->priv, |
|---|
| 483 | | - &map->addr, &map->mod); |
|---|
| 549 | + map->func = tep->func_resolver->func(tep->func_resolver->priv, |
|---|
| 550 | + &map->addr, &map->mod); |
|---|
| 484 | 551 | if (map->func == NULL) |
|---|
| 485 | 552 | return NULL; |
|---|
| 486 | 553 | |
|---|
| .. | .. |
|---|
| 489 | 556 | |
|---|
| 490 | 557 | /** |
|---|
| 491 | 558 | * tep_find_function - find a function by a given address |
|---|
| 492 | | - * @pevent: handle for the pevent |
|---|
| 559 | + * @tep: a handle to the trace event parser context |
|---|
| 493 | 560 | * @addr: the address to find the function with |
|---|
| 494 | 561 | * |
|---|
| 495 | 562 | * Returns a pointer to the function stored that has the given |
|---|
| 496 | 563 | * address. Note, the address does not have to be exact, it |
|---|
| 497 | 564 | * will select the function that would contain the address. |
|---|
| 498 | 565 | */ |
|---|
| 499 | | -const char *tep_find_function(struct tep_handle *pevent, unsigned long long addr) |
|---|
| 566 | +const char *tep_find_function(struct tep_handle *tep, unsigned long long addr) |
|---|
| 500 | 567 | { |
|---|
| 501 | 568 | struct func_map *map; |
|---|
| 502 | 569 | |
|---|
| 503 | | - map = find_func(pevent, addr); |
|---|
| 570 | + map = find_func(tep, addr); |
|---|
| 504 | 571 | if (!map) |
|---|
| 505 | 572 | return NULL; |
|---|
| 506 | 573 | |
|---|
| .. | .. |
|---|
| 509 | 576 | |
|---|
| 510 | 577 | /** |
|---|
| 511 | 578 | * tep_find_function_address - find a function address by a given address |
|---|
| 512 | | - * @pevent: handle for the pevent |
|---|
| 579 | + * @tep: a handle to the trace event parser context |
|---|
| 513 | 580 | * @addr: the address to find the function with |
|---|
| 514 | 581 | * |
|---|
| 515 | 582 | * Returns the address the function starts at. This can be used in |
|---|
| .. | .. |
|---|
| 517 | 584 | * name and the function offset. |
|---|
| 518 | 585 | */ |
|---|
| 519 | 586 | unsigned long long |
|---|
| 520 | | -tep_find_function_address(struct tep_handle *pevent, unsigned long long addr) |
|---|
| 587 | +tep_find_function_address(struct tep_handle *tep, unsigned long long addr) |
|---|
| 521 | 588 | { |
|---|
| 522 | 589 | struct func_map *map; |
|---|
| 523 | 590 | |
|---|
| 524 | | - map = find_func(pevent, addr); |
|---|
| 591 | + map = find_func(tep, addr); |
|---|
| 525 | 592 | if (!map) |
|---|
| 526 | 593 | return 0; |
|---|
| 527 | 594 | |
|---|
| .. | .. |
|---|
| 530 | 597 | |
|---|
| 531 | 598 | /** |
|---|
| 532 | 599 | * tep_register_function - register a function with a given address |
|---|
| 533 | | - * @pevent: handle for the pevent |
|---|
| 600 | + * @tep: a handle to the trace event parser context |
|---|
| 534 | 601 | * @function: the function name to register |
|---|
| 535 | 602 | * @addr: the address the function starts at |
|---|
| 536 | 603 | * @mod: the kernel module the function may be in (NULL for none) |
|---|
| .. | .. |
|---|
| 538 | 605 | * This registers a function name with an address and module. |
|---|
| 539 | 606 | * The @func passed in is duplicated. |
|---|
| 540 | 607 | */ |
|---|
| 541 | | -int tep_register_function(struct tep_handle *pevent, char *func, |
|---|
| 608 | +int tep_register_function(struct tep_handle *tep, char *func, |
|---|
| 542 | 609 | unsigned long long addr, char *mod) |
|---|
| 543 | 610 | { |
|---|
| 544 | 611 | struct func_list *item = malloc(sizeof(*item)); |
|---|
| .. | .. |
|---|
| 546 | 613 | if (!item) |
|---|
| 547 | 614 | return -1; |
|---|
| 548 | 615 | |
|---|
| 549 | | - item->next = pevent->funclist; |
|---|
| 616 | + item->next = tep->funclist; |
|---|
| 550 | 617 | item->func = strdup(func); |
|---|
| 551 | 618 | if (!item->func) |
|---|
| 552 | 619 | goto out_free; |
|---|
| .. | .. |
|---|
| 559 | 626 | item->mod = NULL; |
|---|
| 560 | 627 | item->addr = addr; |
|---|
| 561 | 628 | |
|---|
| 562 | | - pevent->funclist = item; |
|---|
| 563 | | - pevent->func_count++; |
|---|
| 629 | + tep->funclist = item; |
|---|
| 630 | + tep->func_count++; |
|---|
| 564 | 631 | |
|---|
| 565 | 632 | return 0; |
|---|
| 566 | 633 | |
|---|
| .. | .. |
|---|
| 575 | 642 | |
|---|
| 576 | 643 | /** |
|---|
| 577 | 644 | * tep_print_funcs - print out the stored functions |
|---|
| 578 | | - * @pevent: handle for the pevent |
|---|
| 645 | + * @tep: a handle to the trace event parser context |
|---|
| 579 | 646 | * |
|---|
| 580 | 647 | * This prints out the stored functions. |
|---|
| 581 | 648 | */ |
|---|
| 582 | | -void tep_print_funcs(struct tep_handle *pevent) |
|---|
| 649 | +void tep_print_funcs(struct tep_handle *tep) |
|---|
| 583 | 650 | { |
|---|
| 584 | 651 | int i; |
|---|
| 585 | 652 | |
|---|
| 586 | | - if (!pevent->func_map) |
|---|
| 587 | | - func_map_init(pevent); |
|---|
| 653 | + if (!tep->func_map) |
|---|
| 654 | + func_map_init(tep); |
|---|
| 588 | 655 | |
|---|
| 589 | | - for (i = 0; i < (int)pevent->func_count; i++) { |
|---|
| 656 | + for (i = 0; i < (int)tep->func_count; i++) { |
|---|
| 590 | 657 | printf("%016llx %s", |
|---|
| 591 | | - pevent->func_map[i].addr, |
|---|
| 592 | | - pevent->func_map[i].func); |
|---|
| 593 | | - if (pevent->func_map[i].mod) |
|---|
| 594 | | - printf(" [%s]\n", pevent->func_map[i].mod); |
|---|
| 658 | + tep->func_map[i].addr, |
|---|
| 659 | + tep->func_map[i].func); |
|---|
| 660 | + if (tep->func_map[i].mod) |
|---|
| 661 | + printf(" [%s]\n", tep->func_map[i].mod); |
|---|
| 595 | 662 | else |
|---|
| 596 | 663 | printf("\n"); |
|---|
| 597 | 664 | } |
|---|
| .. | .. |
|---|
| 621 | 688 | return 0; |
|---|
| 622 | 689 | } |
|---|
| 623 | 690 | |
|---|
| 624 | | -static int printk_map_init(struct tep_handle *pevent) |
|---|
| 691 | +static int printk_map_init(struct tep_handle *tep) |
|---|
| 625 | 692 | { |
|---|
| 626 | 693 | struct printk_list *printklist; |
|---|
| 627 | 694 | struct printk_list *item; |
|---|
| 628 | 695 | struct printk_map *printk_map; |
|---|
| 629 | 696 | int i; |
|---|
| 630 | 697 | |
|---|
| 631 | | - printk_map = malloc(sizeof(*printk_map) * (pevent->printk_count + 1)); |
|---|
| 698 | + printk_map = malloc(sizeof(*printk_map) * (tep->printk_count + 1)); |
|---|
| 632 | 699 | if (!printk_map) |
|---|
| 633 | 700 | return -1; |
|---|
| 634 | 701 | |
|---|
| 635 | | - printklist = pevent->printklist; |
|---|
| 702 | + printklist = tep->printklist; |
|---|
| 636 | 703 | |
|---|
| 637 | 704 | i = 0; |
|---|
| 638 | 705 | while (printklist) { |
|---|
| .. | .. |
|---|
| 644 | 711 | free(item); |
|---|
| 645 | 712 | } |
|---|
| 646 | 713 | |
|---|
| 647 | | - qsort(printk_map, pevent->printk_count, sizeof(*printk_map), printk_cmp); |
|---|
| 714 | + qsort(printk_map, tep->printk_count, sizeof(*printk_map), printk_cmp); |
|---|
| 648 | 715 | |
|---|
| 649 | | - pevent->printk_map = printk_map; |
|---|
| 650 | | - pevent->printklist = NULL; |
|---|
| 716 | + tep->printk_map = printk_map; |
|---|
| 717 | + tep->printklist = NULL; |
|---|
| 651 | 718 | |
|---|
| 652 | 719 | return 0; |
|---|
| 653 | 720 | } |
|---|
| 654 | 721 | |
|---|
| 655 | 722 | static struct printk_map * |
|---|
| 656 | | -find_printk(struct tep_handle *pevent, unsigned long long addr) |
|---|
| 723 | +find_printk(struct tep_handle *tep, unsigned long long addr) |
|---|
| 657 | 724 | { |
|---|
| 658 | 725 | struct printk_map *printk; |
|---|
| 659 | 726 | struct printk_map key; |
|---|
| 660 | 727 | |
|---|
| 661 | | - if (!pevent->printk_map && printk_map_init(pevent)) |
|---|
| 728 | + if (!tep->printk_map && printk_map_init(tep)) |
|---|
| 662 | 729 | return NULL; |
|---|
| 663 | 730 | |
|---|
| 664 | 731 | key.addr = addr; |
|---|
| 665 | 732 | |
|---|
| 666 | | - printk = bsearch(&key, pevent->printk_map, pevent->printk_count, |
|---|
| 667 | | - sizeof(*pevent->printk_map), printk_cmp); |
|---|
| 733 | + printk = bsearch(&key, tep->printk_map, tep->printk_count, |
|---|
| 734 | + sizeof(*tep->printk_map), printk_cmp); |
|---|
| 668 | 735 | |
|---|
| 669 | 736 | return printk; |
|---|
| 670 | 737 | } |
|---|
| 671 | 738 | |
|---|
| 672 | 739 | /** |
|---|
| 673 | 740 | * tep_register_print_string - register a string by its address |
|---|
| 674 | | - * @pevent: handle for the pevent |
|---|
| 741 | + * @tep: a handle to the trace event parser context |
|---|
| 675 | 742 | * @fmt: the string format to register |
|---|
| 676 | 743 | * @addr: the address the string was located at |
|---|
| 677 | 744 | * |
|---|
| 678 | 745 | * This registers a string by the address it was stored in the kernel. |
|---|
| 679 | 746 | * The @fmt passed in is duplicated. |
|---|
| 680 | 747 | */ |
|---|
| 681 | | -int tep_register_print_string(struct tep_handle *pevent, const char *fmt, |
|---|
| 748 | +int tep_register_print_string(struct tep_handle *tep, const char *fmt, |
|---|
| 682 | 749 | unsigned long long addr) |
|---|
| 683 | 750 | { |
|---|
| 684 | 751 | struct printk_list *item = malloc(sizeof(*item)); |
|---|
| .. | .. |
|---|
| 687 | 754 | if (!item) |
|---|
| 688 | 755 | return -1; |
|---|
| 689 | 756 | |
|---|
| 690 | | - item->next = pevent->printklist; |
|---|
| 757 | + item->next = tep->printklist; |
|---|
| 691 | 758 | item->addr = addr; |
|---|
| 692 | 759 | |
|---|
| 693 | 760 | /* Strip off quotes and '\n' from the end */ |
|---|
| .. | .. |
|---|
| 705 | 772 | if (strcmp(p, "\\n") == 0) |
|---|
| 706 | 773 | *p = 0; |
|---|
| 707 | 774 | |
|---|
| 708 | | - pevent->printklist = item; |
|---|
| 709 | | - pevent->printk_count++; |
|---|
| 775 | + tep->printklist = item; |
|---|
| 776 | + tep->printk_count++; |
|---|
| 710 | 777 | |
|---|
| 711 | 778 | return 0; |
|---|
| 712 | 779 | |
|---|
| .. | .. |
|---|
| 718 | 785 | |
|---|
| 719 | 786 | /** |
|---|
| 720 | 787 | * tep_print_printk - print out the stored strings |
|---|
| 721 | | - * @pevent: handle for the pevent |
|---|
| 788 | + * @tep: a handle to the trace event parser context |
|---|
| 722 | 789 | * |
|---|
| 723 | 790 | * This prints the string formats that were stored. |
|---|
| 724 | 791 | */ |
|---|
| 725 | | -void tep_print_printk(struct tep_handle *pevent) |
|---|
| 792 | +void tep_print_printk(struct tep_handle *tep) |
|---|
| 726 | 793 | { |
|---|
| 727 | 794 | int i; |
|---|
| 728 | 795 | |
|---|
| 729 | | - if (!pevent->printk_map) |
|---|
| 730 | | - printk_map_init(pevent); |
|---|
| 796 | + if (!tep->printk_map) |
|---|
| 797 | + printk_map_init(tep); |
|---|
| 731 | 798 | |
|---|
| 732 | | - for (i = 0; i < (int)pevent->printk_count; i++) { |
|---|
| 799 | + for (i = 0; i < (int)tep->printk_count; i++) { |
|---|
| 733 | 800 | printf("%016llx %s\n", |
|---|
| 734 | | - pevent->printk_map[i].addr, |
|---|
| 735 | | - pevent->printk_map[i].printk); |
|---|
| 801 | + tep->printk_map[i].addr, |
|---|
| 802 | + tep->printk_map[i].printk); |
|---|
| 736 | 803 | } |
|---|
| 737 | 804 | } |
|---|
| 738 | 805 | |
|---|
| 739 | | -static struct event_format *alloc_event(void) |
|---|
| 806 | +static struct tep_event *alloc_event(void) |
|---|
| 740 | 807 | { |
|---|
| 741 | | - return calloc(1, sizeof(struct event_format)); |
|---|
| 808 | + return calloc(1, sizeof(struct tep_event)); |
|---|
| 742 | 809 | } |
|---|
| 743 | 810 | |
|---|
| 744 | | -static int add_event(struct tep_handle *pevent, struct event_format *event) |
|---|
| 811 | +static int add_event(struct tep_handle *tep, struct tep_event *event) |
|---|
| 745 | 812 | { |
|---|
| 746 | 813 | int i; |
|---|
| 747 | | - struct event_format **events = realloc(pevent->events, sizeof(event) * |
|---|
| 748 | | - (pevent->nr_events + 1)); |
|---|
| 814 | + struct tep_event **events = realloc(tep->events, sizeof(event) * |
|---|
| 815 | + (tep->nr_events + 1)); |
|---|
| 749 | 816 | if (!events) |
|---|
| 750 | 817 | return -1; |
|---|
| 751 | 818 | |
|---|
| 752 | | - pevent->events = events; |
|---|
| 819 | + tep->events = events; |
|---|
| 753 | 820 | |
|---|
| 754 | | - for (i = 0; i < pevent->nr_events; i++) { |
|---|
| 755 | | - if (pevent->events[i]->id > event->id) |
|---|
| 821 | + for (i = 0; i < tep->nr_events; i++) { |
|---|
| 822 | + if (tep->events[i]->id > event->id) |
|---|
| 756 | 823 | break; |
|---|
| 757 | 824 | } |
|---|
| 758 | | - if (i < pevent->nr_events) |
|---|
| 759 | | - memmove(&pevent->events[i + 1], |
|---|
| 760 | | - &pevent->events[i], |
|---|
| 761 | | - sizeof(event) * (pevent->nr_events - i)); |
|---|
| 825 | + if (i < tep->nr_events) |
|---|
| 826 | + memmove(&tep->events[i + 1], |
|---|
| 827 | + &tep->events[i], |
|---|
| 828 | + sizeof(event) * (tep->nr_events - i)); |
|---|
| 762 | 829 | |
|---|
| 763 | | - pevent->events[i] = event; |
|---|
| 764 | | - pevent->nr_events++; |
|---|
| 830 | + tep->events[i] = event; |
|---|
| 831 | + tep->nr_events++; |
|---|
| 765 | 832 | |
|---|
| 766 | | - event->pevent = pevent; |
|---|
| 833 | + event->tep = tep; |
|---|
| 767 | 834 | |
|---|
| 768 | 835 | return 0; |
|---|
| 769 | 836 | } |
|---|
| 770 | 837 | |
|---|
| 771 | | -static int event_item_type(enum event_type type) |
|---|
| 838 | +static int event_item_type(enum tep_event_type type) |
|---|
| 772 | 839 | { |
|---|
| 773 | 840 | switch (type) { |
|---|
| 774 | | - case EVENT_ITEM ... EVENT_SQUOTE: |
|---|
| 841 | + case TEP_EVENT_ITEM ... TEP_EVENT_SQUOTE: |
|---|
| 775 | 842 | return 1; |
|---|
| 776 | | - case EVENT_ERROR ... EVENT_DELIM: |
|---|
| 843 | + case TEP_EVENT_ERROR ... TEP_EVENT_DELIM: |
|---|
| 777 | 844 | default: |
|---|
| 778 | 845 | return 0; |
|---|
| 779 | 846 | } |
|---|
| 780 | 847 | } |
|---|
| 781 | 848 | |
|---|
| 782 | | -static void free_flag_sym(struct print_flag_sym *fsym) |
|---|
| 849 | +static void free_flag_sym(struct tep_print_flag_sym *fsym) |
|---|
| 783 | 850 | { |
|---|
| 784 | | - struct print_flag_sym *next; |
|---|
| 851 | + struct tep_print_flag_sym *next; |
|---|
| 785 | 852 | |
|---|
| 786 | 853 | while (fsym) { |
|---|
| 787 | 854 | next = fsym->next; |
|---|
| .. | .. |
|---|
| 792 | 859 | } |
|---|
| 793 | 860 | } |
|---|
| 794 | 861 | |
|---|
| 795 | | -static void free_arg(struct print_arg *arg) |
|---|
| 862 | +static void free_arg(struct tep_print_arg *arg) |
|---|
| 796 | 863 | { |
|---|
| 797 | | - struct print_arg *farg; |
|---|
| 864 | + struct tep_print_arg *farg; |
|---|
| 798 | 865 | |
|---|
| 799 | 866 | if (!arg) |
|---|
| 800 | 867 | return; |
|---|
| 801 | 868 | |
|---|
| 802 | 869 | switch (arg->type) { |
|---|
| 803 | | - case PRINT_ATOM: |
|---|
| 870 | + case TEP_PRINT_ATOM: |
|---|
| 804 | 871 | free(arg->atom.atom); |
|---|
| 805 | 872 | break; |
|---|
| 806 | | - case PRINT_FIELD: |
|---|
| 873 | + case TEP_PRINT_FIELD: |
|---|
| 807 | 874 | free(arg->field.name); |
|---|
| 808 | 875 | break; |
|---|
| 809 | | - case PRINT_FLAGS: |
|---|
| 876 | + case TEP_PRINT_FLAGS: |
|---|
| 810 | 877 | free_arg(arg->flags.field); |
|---|
| 811 | 878 | free(arg->flags.delim); |
|---|
| 812 | 879 | free_flag_sym(arg->flags.flags); |
|---|
| 813 | 880 | break; |
|---|
| 814 | | - case PRINT_SYMBOL: |
|---|
| 881 | + case TEP_PRINT_SYMBOL: |
|---|
| 815 | 882 | free_arg(arg->symbol.field); |
|---|
| 816 | 883 | free_flag_sym(arg->symbol.symbols); |
|---|
| 817 | 884 | break; |
|---|
| 818 | | - case PRINT_HEX: |
|---|
| 819 | | - case PRINT_HEX_STR: |
|---|
| 885 | + case TEP_PRINT_HEX: |
|---|
| 886 | + case TEP_PRINT_HEX_STR: |
|---|
| 820 | 887 | free_arg(arg->hex.field); |
|---|
| 821 | 888 | free_arg(arg->hex.size); |
|---|
| 822 | 889 | break; |
|---|
| 823 | | - case PRINT_INT_ARRAY: |
|---|
| 890 | + case TEP_PRINT_INT_ARRAY: |
|---|
| 824 | 891 | free_arg(arg->int_array.field); |
|---|
| 825 | 892 | free_arg(arg->int_array.count); |
|---|
| 826 | 893 | free_arg(arg->int_array.el_size); |
|---|
| 827 | 894 | break; |
|---|
| 828 | | - case PRINT_TYPE: |
|---|
| 895 | + case TEP_PRINT_TYPE: |
|---|
| 829 | 896 | free(arg->typecast.type); |
|---|
| 830 | 897 | free_arg(arg->typecast.item); |
|---|
| 831 | 898 | break; |
|---|
| 832 | | - case PRINT_STRING: |
|---|
| 833 | | - case PRINT_BSTRING: |
|---|
| 899 | + case TEP_PRINT_STRING: |
|---|
| 900 | + case TEP_PRINT_BSTRING: |
|---|
| 834 | 901 | free(arg->string.string); |
|---|
| 835 | 902 | break; |
|---|
| 836 | | - case PRINT_BITMASK: |
|---|
| 903 | + case TEP_PRINT_BITMASK: |
|---|
| 837 | 904 | free(arg->bitmask.bitmask); |
|---|
| 838 | 905 | break; |
|---|
| 839 | | - case PRINT_DYNAMIC_ARRAY: |
|---|
| 840 | | - case PRINT_DYNAMIC_ARRAY_LEN: |
|---|
| 906 | + case TEP_PRINT_DYNAMIC_ARRAY: |
|---|
| 907 | + case TEP_PRINT_DYNAMIC_ARRAY_LEN: |
|---|
| 841 | 908 | free(arg->dynarray.index); |
|---|
| 842 | 909 | break; |
|---|
| 843 | | - case PRINT_OP: |
|---|
| 910 | + case TEP_PRINT_OP: |
|---|
| 844 | 911 | free(arg->op.op); |
|---|
| 845 | 912 | free_arg(arg->op.left); |
|---|
| 846 | 913 | free_arg(arg->op.right); |
|---|
| 847 | 914 | break; |
|---|
| 848 | | - case PRINT_FUNC: |
|---|
| 915 | + case TEP_PRINT_FUNC: |
|---|
| 849 | 916 | while (arg->func.args) { |
|---|
| 850 | 917 | farg = arg->func.args; |
|---|
| 851 | 918 | arg->func.args = farg->next; |
|---|
| .. | .. |
|---|
| 853 | 920 | } |
|---|
| 854 | 921 | break; |
|---|
| 855 | 922 | |
|---|
| 856 | | - case PRINT_NULL: |
|---|
| 923 | + case TEP_PRINT_NULL: |
|---|
| 857 | 924 | default: |
|---|
| 858 | 925 | break; |
|---|
| 859 | 926 | } |
|---|
| .. | .. |
|---|
| 861 | 928 | free(arg); |
|---|
| 862 | 929 | } |
|---|
| 863 | 930 | |
|---|
| 864 | | -static enum event_type get_type(int ch) |
|---|
| 931 | +static enum tep_event_type get_type(int ch) |
|---|
| 865 | 932 | { |
|---|
| 866 | 933 | if (ch == '\n') |
|---|
| 867 | | - return EVENT_NEWLINE; |
|---|
| 934 | + return TEP_EVENT_NEWLINE; |
|---|
| 868 | 935 | if (isspace(ch)) |
|---|
| 869 | | - return EVENT_SPACE; |
|---|
| 936 | + return TEP_EVENT_SPACE; |
|---|
| 870 | 937 | if (isalnum(ch) || ch == '_') |
|---|
| 871 | | - return EVENT_ITEM; |
|---|
| 938 | + return TEP_EVENT_ITEM; |
|---|
| 872 | 939 | if (ch == '\'') |
|---|
| 873 | | - return EVENT_SQUOTE; |
|---|
| 940 | + return TEP_EVENT_SQUOTE; |
|---|
| 874 | 941 | if (ch == '"') |
|---|
| 875 | | - return EVENT_DQUOTE; |
|---|
| 942 | + return TEP_EVENT_DQUOTE; |
|---|
| 876 | 943 | if (!isprint(ch)) |
|---|
| 877 | | - return EVENT_NONE; |
|---|
| 944 | + return TEP_EVENT_NONE; |
|---|
| 878 | 945 | if (ch == '(' || ch == ')' || ch == ',') |
|---|
| 879 | | - return EVENT_DELIM; |
|---|
| 946 | + return TEP_EVENT_DELIM; |
|---|
| 880 | 947 | |
|---|
| 881 | | - return EVENT_OP; |
|---|
| 948 | + return TEP_EVENT_OP; |
|---|
| 882 | 949 | } |
|---|
| 883 | 950 | |
|---|
| 884 | 951 | static int __read_char(void) |
|---|
| .. | .. |
|---|
| 889 | 956 | return input_buf[input_buf_ptr++]; |
|---|
| 890 | 957 | } |
|---|
| 891 | 958 | |
|---|
| 892 | | -static int __peek_char(void) |
|---|
| 959 | +/** |
|---|
| 960 | + * peek_char - peek at the next character that will be read |
|---|
| 961 | + * |
|---|
| 962 | + * Returns the next character read, or -1 if end of buffer. |
|---|
| 963 | + */ |
|---|
| 964 | +__hidden int peek_char(void) |
|---|
| 893 | 965 | { |
|---|
| 894 | 966 | if (input_buf_ptr >= input_buf_siz) |
|---|
| 895 | 967 | return -1; |
|---|
| 896 | 968 | |
|---|
| 897 | 969 | return input_buf[input_buf_ptr]; |
|---|
| 898 | | -} |
|---|
| 899 | | - |
|---|
| 900 | | -/** |
|---|
| 901 | | - * tep_peek_char - peek at the next character that will be read |
|---|
| 902 | | - * |
|---|
| 903 | | - * Returns the next character read, or -1 if end of buffer. |
|---|
| 904 | | - */ |
|---|
| 905 | | -int tep_peek_char(void) |
|---|
| 906 | | -{ |
|---|
| 907 | | - return __peek_char(); |
|---|
| 908 | 970 | } |
|---|
| 909 | 971 | |
|---|
| 910 | 972 | static int extend_token(char **tok, char *buf, int size) |
|---|
| .. | .. |
|---|
| 926 | 988 | return 0; |
|---|
| 927 | 989 | } |
|---|
| 928 | 990 | |
|---|
| 929 | | -static enum event_type force_token(const char *str, char **tok); |
|---|
| 991 | +static enum tep_event_type force_token(const char *str, char **tok); |
|---|
| 930 | 992 | |
|---|
| 931 | | -static enum event_type __read_token(char **tok) |
|---|
| 993 | +static enum tep_event_type __read_token(char **tok) |
|---|
| 932 | 994 | { |
|---|
| 933 | 995 | char buf[BUFSIZ]; |
|---|
| 934 | 996 | int ch, last_ch, quote_ch, next_ch; |
|---|
| 935 | 997 | int i = 0; |
|---|
| 936 | 998 | int tok_size = 0; |
|---|
| 937 | | - enum event_type type; |
|---|
| 999 | + enum tep_event_type type; |
|---|
| 938 | 1000 | |
|---|
| 939 | 1001 | *tok = NULL; |
|---|
| 940 | 1002 | |
|---|
| 941 | 1003 | |
|---|
| 942 | 1004 | ch = __read_char(); |
|---|
| 943 | 1005 | if (ch < 0) |
|---|
| 944 | | - return EVENT_NONE; |
|---|
| 1006 | + return TEP_EVENT_NONE; |
|---|
| 945 | 1007 | |
|---|
| 946 | 1008 | type = get_type(ch); |
|---|
| 947 | | - if (type == EVENT_NONE) |
|---|
| 1009 | + if (type == TEP_EVENT_NONE) |
|---|
| 948 | 1010 | return type; |
|---|
| 949 | 1011 | |
|---|
| 950 | 1012 | buf[i++] = ch; |
|---|
| 951 | 1013 | |
|---|
| 952 | 1014 | switch (type) { |
|---|
| 953 | | - case EVENT_NEWLINE: |
|---|
| 954 | | - case EVENT_DELIM: |
|---|
| 1015 | + case TEP_EVENT_NEWLINE: |
|---|
| 1016 | + case TEP_EVENT_DELIM: |
|---|
| 955 | 1017 | if (asprintf(tok, "%c", ch) < 0) |
|---|
| 956 | | - return EVENT_ERROR; |
|---|
| 1018 | + return TEP_EVENT_ERROR; |
|---|
| 957 | 1019 | |
|---|
| 958 | 1020 | return type; |
|---|
| 959 | 1021 | |
|---|
| 960 | | - case EVENT_OP: |
|---|
| 1022 | + case TEP_EVENT_OP: |
|---|
| 961 | 1023 | switch (ch) { |
|---|
| 962 | 1024 | case '-': |
|---|
| 963 | | - next_ch = __peek_char(); |
|---|
| 1025 | + next_ch = peek_char(); |
|---|
| 964 | 1026 | if (next_ch == '>') { |
|---|
| 965 | 1027 | buf[i++] = __read_char(); |
|---|
| 966 | 1028 | break; |
|---|
| .. | .. |
|---|
| 972 | 1034 | case '>': |
|---|
| 973 | 1035 | case '<': |
|---|
| 974 | 1036 | last_ch = ch; |
|---|
| 975 | | - ch = __peek_char(); |
|---|
| 1037 | + ch = peek_char(); |
|---|
| 976 | 1038 | if (ch != last_ch) |
|---|
| 977 | 1039 | goto test_equal; |
|---|
| 978 | 1040 | buf[i++] = __read_char(); |
|---|
| .. | .. |
|---|
| 995 | 1057 | return type; |
|---|
| 996 | 1058 | |
|---|
| 997 | 1059 | test_equal: |
|---|
| 998 | | - ch = __peek_char(); |
|---|
| 1060 | + ch = peek_char(); |
|---|
| 999 | 1061 | if (ch == '=') |
|---|
| 1000 | 1062 | buf[i++] = __read_char(); |
|---|
| 1001 | 1063 | goto out; |
|---|
| 1002 | 1064 | |
|---|
| 1003 | | - case EVENT_DQUOTE: |
|---|
| 1004 | | - case EVENT_SQUOTE: |
|---|
| 1065 | + case TEP_EVENT_DQUOTE: |
|---|
| 1066 | + case TEP_EVENT_SQUOTE: |
|---|
| 1005 | 1067 | /* don't keep quotes */ |
|---|
| 1006 | 1068 | i--; |
|---|
| 1007 | 1069 | quote_ch = ch; |
|---|
| .. | .. |
|---|
| 1013 | 1075 | tok_size += BUFSIZ; |
|---|
| 1014 | 1076 | |
|---|
| 1015 | 1077 | if (extend_token(tok, buf, tok_size) < 0) |
|---|
| 1016 | | - return EVENT_NONE; |
|---|
| 1078 | + return TEP_EVENT_NONE; |
|---|
| 1017 | 1079 | i = 0; |
|---|
| 1018 | 1080 | } |
|---|
| 1019 | 1081 | last_ch = ch; |
|---|
| .. | .. |
|---|
| 1030 | 1092 | * For strings (double quotes) check the next token. |
|---|
| 1031 | 1093 | * If it is another string, concatinate the two. |
|---|
| 1032 | 1094 | */ |
|---|
| 1033 | | - if (type == EVENT_DQUOTE) { |
|---|
| 1095 | + if (type == TEP_EVENT_DQUOTE) { |
|---|
| 1034 | 1096 | unsigned long long save_input_buf_ptr = input_buf_ptr; |
|---|
| 1035 | 1097 | |
|---|
| 1036 | 1098 | do { |
|---|
| .. | .. |
|---|
| 1043 | 1105 | |
|---|
| 1044 | 1106 | goto out; |
|---|
| 1045 | 1107 | |
|---|
| 1046 | | - case EVENT_ERROR ... EVENT_SPACE: |
|---|
| 1047 | | - case EVENT_ITEM: |
|---|
| 1108 | + case TEP_EVENT_ERROR ... TEP_EVENT_SPACE: |
|---|
| 1109 | + case TEP_EVENT_ITEM: |
|---|
| 1048 | 1110 | default: |
|---|
| 1049 | 1111 | break; |
|---|
| 1050 | 1112 | } |
|---|
| 1051 | 1113 | |
|---|
| 1052 | | - while (get_type(__peek_char()) == type) { |
|---|
| 1114 | + while (get_type(peek_char()) == type) { |
|---|
| 1053 | 1115 | if (i == (BUFSIZ - 1)) { |
|---|
| 1054 | 1116 | buf[i] = 0; |
|---|
| 1055 | 1117 | tok_size += BUFSIZ; |
|---|
| 1056 | 1118 | |
|---|
| 1057 | 1119 | if (extend_token(tok, buf, tok_size) < 0) |
|---|
| 1058 | | - return EVENT_NONE; |
|---|
| 1120 | + return TEP_EVENT_NONE; |
|---|
| 1059 | 1121 | i = 0; |
|---|
| 1060 | 1122 | } |
|---|
| 1061 | 1123 | ch = __read_char(); |
|---|
| .. | .. |
|---|
| 1065 | 1127 | out: |
|---|
| 1066 | 1128 | buf[i] = 0; |
|---|
| 1067 | 1129 | if (extend_token(tok, buf, tok_size + i + 1) < 0) |
|---|
| 1068 | | - return EVENT_NONE; |
|---|
| 1130 | + return TEP_EVENT_NONE; |
|---|
| 1069 | 1131 | |
|---|
| 1070 | | - if (type == EVENT_ITEM) { |
|---|
| 1132 | + if (type == TEP_EVENT_ITEM) { |
|---|
| 1071 | 1133 | /* |
|---|
| 1072 | 1134 | * Older versions of the kernel has a bug that |
|---|
| 1073 | 1135 | * creates invalid symbols and will break the mac80211 |
|---|
| .. | .. |
|---|
| 1094 | 1156 | return type; |
|---|
| 1095 | 1157 | } |
|---|
| 1096 | 1158 | |
|---|
| 1097 | | -static enum event_type force_token(const char *str, char **tok) |
|---|
| 1159 | +static enum tep_event_type force_token(const char *str, char **tok) |
|---|
| 1098 | 1160 | { |
|---|
| 1099 | 1161 | const char *save_input_buf; |
|---|
| 1100 | 1162 | unsigned long long save_input_buf_ptr; |
|---|
| 1101 | 1163 | unsigned long long save_input_buf_siz; |
|---|
| 1102 | | - enum event_type type; |
|---|
| 1164 | + enum tep_event_type type; |
|---|
| 1103 | 1165 | |
|---|
| 1104 | 1166 | /* save off the current input pointers */ |
|---|
| 1105 | 1167 | save_input_buf = input_buf; |
|---|
| .. | .. |
|---|
| 1118 | 1180 | return type; |
|---|
| 1119 | 1181 | } |
|---|
| 1120 | 1182 | |
|---|
| 1121 | | -static void free_token(char *tok) |
|---|
| 1183 | +/** |
|---|
| 1184 | + * free_token - free a token returned by tep_read_token |
|---|
| 1185 | + * @token: the token to free |
|---|
| 1186 | + */ |
|---|
| 1187 | +__hidden void free_token(char *tok) |
|---|
| 1122 | 1188 | { |
|---|
| 1123 | 1189 | if (tok) |
|---|
| 1124 | 1190 | free(tok); |
|---|
| 1125 | 1191 | } |
|---|
| 1126 | 1192 | |
|---|
| 1127 | | -static enum event_type read_token(char **tok) |
|---|
| 1128 | | -{ |
|---|
| 1129 | | - enum event_type type; |
|---|
| 1130 | | - |
|---|
| 1131 | | - for (;;) { |
|---|
| 1132 | | - type = __read_token(tok); |
|---|
| 1133 | | - if (type != EVENT_SPACE) |
|---|
| 1134 | | - return type; |
|---|
| 1135 | | - |
|---|
| 1136 | | - free_token(*tok); |
|---|
| 1137 | | - } |
|---|
| 1138 | | - |
|---|
| 1139 | | - /* not reached */ |
|---|
| 1140 | | - *tok = NULL; |
|---|
| 1141 | | - return EVENT_NONE; |
|---|
| 1142 | | -} |
|---|
| 1143 | | - |
|---|
| 1144 | 1193 | /** |
|---|
| 1145 | | - * tep_read_token - access to utilites to use the pevent parser |
|---|
| 1194 | + * read_token - access to utilities to use the tep parser |
|---|
| 1146 | 1195 | * @tok: The token to return |
|---|
| 1147 | 1196 | * |
|---|
| 1148 | 1197 | * This will parse tokens from the string given by |
|---|
| .. | .. |
|---|
| 1150 | 1199 | * |
|---|
| 1151 | 1200 | * Returns the token type. |
|---|
| 1152 | 1201 | */ |
|---|
| 1153 | | -enum event_type tep_read_token(char **tok) |
|---|
| 1202 | +__hidden enum tep_event_type read_token(char **tok) |
|---|
| 1154 | 1203 | { |
|---|
| 1155 | | - return read_token(tok); |
|---|
| 1156 | | -} |
|---|
| 1157 | | - |
|---|
| 1158 | | -/** |
|---|
| 1159 | | - * tep_free_token - free a token returned by tep_read_token |
|---|
| 1160 | | - * @token: the token to free |
|---|
| 1161 | | - */ |
|---|
| 1162 | | -void tep_free_token(char *token) |
|---|
| 1163 | | -{ |
|---|
| 1164 | | - free_token(token); |
|---|
| 1165 | | -} |
|---|
| 1166 | | - |
|---|
| 1167 | | -/* no newline */ |
|---|
| 1168 | | -static enum event_type read_token_item(char **tok) |
|---|
| 1169 | | -{ |
|---|
| 1170 | | - enum event_type type; |
|---|
| 1204 | + enum tep_event_type type; |
|---|
| 1171 | 1205 | |
|---|
| 1172 | 1206 | for (;;) { |
|---|
| 1173 | 1207 | type = __read_token(tok); |
|---|
| 1174 | | - if (type != EVENT_SPACE && type != EVENT_NEWLINE) |
|---|
| 1208 | + if (type != TEP_EVENT_SPACE) |
|---|
| 1209 | + return type; |
|---|
| 1210 | + |
|---|
| 1211 | + free_token(*tok); |
|---|
| 1212 | + } |
|---|
| 1213 | + |
|---|
| 1214 | + /* not reached */ |
|---|
| 1215 | + *tok = NULL; |
|---|
| 1216 | + return TEP_EVENT_NONE; |
|---|
| 1217 | +} |
|---|
| 1218 | + |
|---|
| 1219 | +/* no newline */ |
|---|
| 1220 | +static enum tep_event_type read_token_item(char **tok) |
|---|
| 1221 | +{ |
|---|
| 1222 | + enum tep_event_type type; |
|---|
| 1223 | + |
|---|
| 1224 | + for (;;) { |
|---|
| 1225 | + type = __read_token(tok); |
|---|
| 1226 | + if (type != TEP_EVENT_SPACE && type != TEP_EVENT_NEWLINE) |
|---|
| 1175 | 1227 | return type; |
|---|
| 1176 | 1228 | free_token(*tok); |
|---|
| 1177 | 1229 | *tok = NULL; |
|---|
| .. | .. |
|---|
| 1179 | 1231 | |
|---|
| 1180 | 1232 | /* not reached */ |
|---|
| 1181 | 1233 | *tok = NULL; |
|---|
| 1182 | | - return EVENT_NONE; |
|---|
| 1234 | + return TEP_EVENT_NONE; |
|---|
| 1183 | 1235 | } |
|---|
| 1184 | 1236 | |
|---|
| 1185 | | -static int test_type(enum event_type type, enum event_type expect) |
|---|
| 1237 | +static int test_type(enum tep_event_type type, enum tep_event_type expect) |
|---|
| 1186 | 1238 | { |
|---|
| 1187 | 1239 | if (type != expect) { |
|---|
| 1188 | 1240 | do_warning("Error: expected type %d but read %d", |
|---|
| .. | .. |
|---|
| 1192 | 1244 | return 0; |
|---|
| 1193 | 1245 | } |
|---|
| 1194 | 1246 | |
|---|
| 1195 | | -static int test_type_token(enum event_type type, const char *token, |
|---|
| 1196 | | - enum event_type expect, const char *expect_tok) |
|---|
| 1247 | +static int test_type_token(enum tep_event_type type, const char *token, |
|---|
| 1248 | + enum tep_event_type expect, const char *expect_tok) |
|---|
| 1197 | 1249 | { |
|---|
| 1198 | 1250 | if (type != expect) { |
|---|
| 1199 | 1251 | do_warning("Error: expected type %d but read %d", |
|---|
| .. | .. |
|---|
| 1209 | 1261 | return 0; |
|---|
| 1210 | 1262 | } |
|---|
| 1211 | 1263 | |
|---|
| 1212 | | -static int __read_expect_type(enum event_type expect, char **tok, int newline_ok) |
|---|
| 1264 | +static int __read_expect_type(enum tep_event_type expect, char **tok, int newline_ok) |
|---|
| 1213 | 1265 | { |
|---|
| 1214 | | - enum event_type type; |
|---|
| 1266 | + enum tep_event_type type; |
|---|
| 1215 | 1267 | |
|---|
| 1216 | 1268 | if (newline_ok) |
|---|
| 1217 | 1269 | type = read_token(tok); |
|---|
| .. | .. |
|---|
| 1220 | 1272 | return test_type(type, expect); |
|---|
| 1221 | 1273 | } |
|---|
| 1222 | 1274 | |
|---|
| 1223 | | -static int read_expect_type(enum event_type expect, char **tok) |
|---|
| 1275 | +static int read_expect_type(enum tep_event_type expect, char **tok) |
|---|
| 1224 | 1276 | { |
|---|
| 1225 | 1277 | return __read_expect_type(expect, tok, 1); |
|---|
| 1226 | 1278 | } |
|---|
| 1227 | 1279 | |
|---|
| 1228 | | -static int __read_expected(enum event_type expect, const char *str, |
|---|
| 1280 | +static int __read_expected(enum tep_event_type expect, const char *str, |
|---|
| 1229 | 1281 | int newline_ok) |
|---|
| 1230 | 1282 | { |
|---|
| 1231 | | - enum event_type type; |
|---|
| 1283 | + enum tep_event_type type; |
|---|
| 1232 | 1284 | char *token; |
|---|
| 1233 | 1285 | int ret; |
|---|
| 1234 | 1286 | |
|---|
| .. | .. |
|---|
| 1244 | 1296 | return ret; |
|---|
| 1245 | 1297 | } |
|---|
| 1246 | 1298 | |
|---|
| 1247 | | -static int read_expected(enum event_type expect, const char *str) |
|---|
| 1299 | +static int read_expected(enum tep_event_type expect, const char *str) |
|---|
| 1248 | 1300 | { |
|---|
| 1249 | 1301 | return __read_expected(expect, str, 1); |
|---|
| 1250 | 1302 | } |
|---|
| 1251 | 1303 | |
|---|
| 1252 | | -static int read_expected_item(enum event_type expect, const char *str) |
|---|
| 1304 | +static int read_expected_item(enum tep_event_type expect, const char *str) |
|---|
| 1253 | 1305 | { |
|---|
| 1254 | 1306 | return __read_expected(expect, str, 0); |
|---|
| 1255 | 1307 | } |
|---|
| .. | .. |
|---|
| 1258 | 1310 | { |
|---|
| 1259 | 1311 | char *token; |
|---|
| 1260 | 1312 | |
|---|
| 1261 | | - if (read_expected(EVENT_ITEM, "name") < 0) |
|---|
| 1313 | + if (read_expected(TEP_EVENT_ITEM, "name") < 0) |
|---|
| 1262 | 1314 | return NULL; |
|---|
| 1263 | 1315 | |
|---|
| 1264 | | - if (read_expected(EVENT_OP, ":") < 0) |
|---|
| 1316 | + if (read_expected(TEP_EVENT_OP, ":") < 0) |
|---|
| 1265 | 1317 | return NULL; |
|---|
| 1266 | 1318 | |
|---|
| 1267 | | - if (read_expect_type(EVENT_ITEM, &token) < 0) |
|---|
| 1319 | + if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
|---|
| 1268 | 1320 | goto fail; |
|---|
| 1269 | 1321 | |
|---|
| 1270 | 1322 | return token; |
|---|
| .. | .. |
|---|
| 1279 | 1331 | char *token; |
|---|
| 1280 | 1332 | int id; |
|---|
| 1281 | 1333 | |
|---|
| 1282 | | - if (read_expected_item(EVENT_ITEM, "ID") < 0) |
|---|
| 1334 | + if (read_expected_item(TEP_EVENT_ITEM, "ID") < 0) |
|---|
| 1283 | 1335 | return -1; |
|---|
| 1284 | 1336 | |
|---|
| 1285 | | - if (read_expected(EVENT_OP, ":") < 0) |
|---|
| 1337 | + if (read_expected(TEP_EVENT_OP, ":") < 0) |
|---|
| 1286 | 1338 | return -1; |
|---|
| 1287 | 1339 | |
|---|
| 1288 | | - if (read_expect_type(EVENT_ITEM, &token) < 0) |
|---|
| 1340 | + if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
|---|
| 1289 | 1341 | goto fail; |
|---|
| 1290 | 1342 | |
|---|
| 1291 | 1343 | id = strtoul(token, NULL, 0); |
|---|
| .. | .. |
|---|
| 1297 | 1349 | return -1; |
|---|
| 1298 | 1350 | } |
|---|
| 1299 | 1351 | |
|---|
| 1300 | | -static int field_is_string(struct format_field *field) |
|---|
| 1352 | +static int field_is_string(struct tep_format_field *field) |
|---|
| 1301 | 1353 | { |
|---|
| 1302 | | - if ((field->flags & FIELD_IS_ARRAY) && |
|---|
| 1354 | + if ((field->flags & TEP_FIELD_IS_ARRAY) && |
|---|
| 1303 | 1355 | (strstr(field->type, "char") || strstr(field->type, "u8") || |
|---|
| 1304 | 1356 | strstr(field->type, "s8"))) |
|---|
| 1305 | 1357 | return 1; |
|---|
| .. | .. |
|---|
| 1307 | 1359 | return 0; |
|---|
| 1308 | 1360 | } |
|---|
| 1309 | 1361 | |
|---|
| 1310 | | -static int field_is_dynamic(struct format_field *field) |
|---|
| 1362 | +static int field_is_dynamic(struct tep_format_field *field) |
|---|
| 1311 | 1363 | { |
|---|
| 1312 | 1364 | if (strncmp(field->type, "__data_loc", 10) == 0) |
|---|
| 1313 | 1365 | return 1; |
|---|
| .. | .. |
|---|
| 1315 | 1367 | return 0; |
|---|
| 1316 | 1368 | } |
|---|
| 1317 | 1369 | |
|---|
| 1318 | | -static int field_is_long(struct format_field *field) |
|---|
| 1370 | +static int field_is_long(struct tep_format_field *field) |
|---|
| 1319 | 1371 | { |
|---|
| 1320 | 1372 | /* includes long long */ |
|---|
| 1321 | 1373 | if (strstr(field->type, "long")) |
|---|
| .. | .. |
|---|
| 1326 | 1378 | |
|---|
| 1327 | 1379 | static unsigned int type_size(const char *name) |
|---|
| 1328 | 1380 | { |
|---|
| 1329 | | - /* This covers all FIELD_IS_STRING types. */ |
|---|
| 1381 | + /* This covers all TEP_FIELD_IS_STRING types. */ |
|---|
| 1330 | 1382 | static struct { |
|---|
| 1331 | 1383 | const char *type; |
|---|
| 1332 | 1384 | unsigned int size; |
|---|
| .. | .. |
|---|
| 1352 | 1404 | return 0; |
|---|
| 1353 | 1405 | } |
|---|
| 1354 | 1406 | |
|---|
| 1355 | | -static int event_read_fields(struct event_format *event, struct format_field **fields) |
|---|
| 1407 | +static int append(char **buf, const char *delim, const char *str) |
|---|
| 1356 | 1408 | { |
|---|
| 1357 | | - struct format_field *field = NULL; |
|---|
| 1358 | | - enum event_type type; |
|---|
| 1409 | + char *new_buf; |
|---|
| 1410 | + |
|---|
| 1411 | + new_buf = realloc(*buf, strlen(*buf) + strlen(delim) + strlen(str) + 1); |
|---|
| 1412 | + if (!new_buf) |
|---|
| 1413 | + return -1; |
|---|
| 1414 | + strcat(new_buf, delim); |
|---|
| 1415 | + strcat(new_buf, str); |
|---|
| 1416 | + *buf = new_buf; |
|---|
| 1417 | + return 0; |
|---|
| 1418 | +} |
|---|
| 1419 | + |
|---|
| 1420 | +static int event_read_fields(struct tep_event *event, struct tep_format_field **fields) |
|---|
| 1421 | +{ |
|---|
| 1422 | + struct tep_format_field *field = NULL; |
|---|
| 1423 | + enum tep_event_type type; |
|---|
| 1359 | 1424 | char *token; |
|---|
| 1360 | 1425 | char *last_token; |
|---|
| 1426 | + char *delim = " "; |
|---|
| 1361 | 1427 | int count = 0; |
|---|
| 1428 | + int ret; |
|---|
| 1362 | 1429 | |
|---|
| 1363 | 1430 | do { |
|---|
| 1364 | 1431 | unsigned int size_dynamic = 0; |
|---|
| 1365 | 1432 | |
|---|
| 1366 | 1433 | type = read_token(&token); |
|---|
| 1367 | | - if (type == EVENT_NEWLINE) { |
|---|
| 1434 | + if (type == TEP_EVENT_NEWLINE) { |
|---|
| 1368 | 1435 | free_token(token); |
|---|
| 1369 | 1436 | return count; |
|---|
| 1370 | 1437 | } |
|---|
| 1371 | 1438 | |
|---|
| 1372 | 1439 | count++; |
|---|
| 1373 | 1440 | |
|---|
| 1374 | | - if (test_type_token(type, token, EVENT_ITEM, "field")) |
|---|
| 1441 | + if (test_type_token(type, token, TEP_EVENT_ITEM, "field")) |
|---|
| 1375 | 1442 | goto fail; |
|---|
| 1376 | 1443 | free_token(token); |
|---|
| 1377 | 1444 | |
|---|
| .. | .. |
|---|
| 1380 | 1447 | * The ftrace fields may still use the "special" name. |
|---|
| 1381 | 1448 | * Just ignore it. |
|---|
| 1382 | 1449 | */ |
|---|
| 1383 | | - if (event->flags & EVENT_FL_ISFTRACE && |
|---|
| 1384 | | - type == EVENT_ITEM && strcmp(token, "special") == 0) { |
|---|
| 1450 | + if (event->flags & TEP_EVENT_FL_ISFTRACE && |
|---|
| 1451 | + type == TEP_EVENT_ITEM && strcmp(token, "special") == 0) { |
|---|
| 1385 | 1452 | free_token(token); |
|---|
| 1386 | 1453 | type = read_token(&token); |
|---|
| 1387 | 1454 | } |
|---|
| 1388 | 1455 | |
|---|
| 1389 | | - if (test_type_token(type, token, EVENT_OP, ":") < 0) |
|---|
| 1456 | + if (test_type_token(type, token, TEP_EVENT_OP, ":") < 0) |
|---|
| 1390 | 1457 | goto fail; |
|---|
| 1391 | 1458 | |
|---|
| 1392 | 1459 | free_token(token); |
|---|
| 1393 | | - if (read_expect_type(EVENT_ITEM, &token) < 0) |
|---|
| 1460 | + if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
|---|
| 1394 | 1461 | goto fail; |
|---|
| 1395 | 1462 | |
|---|
| 1396 | 1463 | last_token = token; |
|---|
| .. | .. |
|---|
| 1404 | 1471 | /* read the rest of the type */ |
|---|
| 1405 | 1472 | for (;;) { |
|---|
| 1406 | 1473 | type = read_token(&token); |
|---|
| 1407 | | - if (type == EVENT_ITEM || |
|---|
| 1408 | | - (type == EVENT_OP && strcmp(token, "*") == 0) || |
|---|
| 1474 | + if (type == TEP_EVENT_ITEM || |
|---|
| 1475 | + (type == TEP_EVENT_OP && strcmp(token, "*") == 0) || |
|---|
| 1409 | 1476 | /* |
|---|
| 1410 | 1477 | * Some of the ftrace fields are broken and have |
|---|
| 1411 | 1478 | * an illegal "." in them. |
|---|
| 1412 | 1479 | */ |
|---|
| 1413 | | - (event->flags & EVENT_FL_ISFTRACE && |
|---|
| 1414 | | - type == EVENT_OP && strcmp(token, ".") == 0)) { |
|---|
| 1480 | + (event->flags & TEP_EVENT_FL_ISFTRACE && |
|---|
| 1481 | + type == TEP_EVENT_OP && strcmp(token, ".") == 0)) { |
|---|
| 1415 | 1482 | |
|---|
| 1416 | 1483 | if (strcmp(token, "*") == 0) |
|---|
| 1417 | | - field->flags |= FIELD_IS_POINTER; |
|---|
| 1484 | + field->flags |= TEP_FIELD_IS_POINTER; |
|---|
| 1418 | 1485 | |
|---|
| 1419 | 1486 | if (field->type) { |
|---|
| 1420 | | - char *new_type; |
|---|
| 1421 | | - new_type = realloc(field->type, |
|---|
| 1422 | | - strlen(field->type) + |
|---|
| 1423 | | - strlen(last_token) + 2); |
|---|
| 1424 | | - if (!new_type) { |
|---|
| 1425 | | - free(last_token); |
|---|
| 1426 | | - goto fail; |
|---|
| 1427 | | - } |
|---|
| 1428 | | - field->type = new_type; |
|---|
| 1429 | | - strcat(field->type, " "); |
|---|
| 1430 | | - strcat(field->type, last_token); |
|---|
| 1487 | + ret = append(&field->type, delim, last_token); |
|---|
| 1431 | 1488 | free(last_token); |
|---|
| 1489 | + if (ret < 0) |
|---|
| 1490 | + goto fail; |
|---|
| 1432 | 1491 | } else |
|---|
| 1433 | 1492 | field->type = last_token; |
|---|
| 1434 | 1493 | last_token = token; |
|---|
| 1494 | + delim = " "; |
|---|
| 1435 | 1495 | continue; |
|---|
| 1436 | 1496 | } |
|---|
| 1437 | 1497 | |
|---|
| 1498 | + /* Handle __attribute__((user)) */ |
|---|
| 1499 | + if ((type == TEP_EVENT_DELIM) && |
|---|
| 1500 | + strcmp("__attribute__", last_token) == 0 && |
|---|
| 1501 | + token[0] == '(') { |
|---|
| 1502 | + int depth = 1; |
|---|
| 1503 | + int ret; |
|---|
| 1504 | + |
|---|
| 1505 | + ret = append(&field->type, " ", last_token); |
|---|
| 1506 | + ret |= append(&field->type, "", "("); |
|---|
| 1507 | + if (ret < 0) |
|---|
| 1508 | + goto fail; |
|---|
| 1509 | + |
|---|
| 1510 | + delim = " "; |
|---|
| 1511 | + while ((type = read_token(&token)) != TEP_EVENT_NONE) { |
|---|
| 1512 | + if (type == TEP_EVENT_DELIM) { |
|---|
| 1513 | + if (token[0] == '(') |
|---|
| 1514 | + depth++; |
|---|
| 1515 | + else if (token[0] == ')') |
|---|
| 1516 | + depth--; |
|---|
| 1517 | + if (!depth) |
|---|
| 1518 | + break; |
|---|
| 1519 | + ret = append(&field->type, "", token); |
|---|
| 1520 | + delim = ""; |
|---|
| 1521 | + } else { |
|---|
| 1522 | + ret = append(&field->type, delim, token); |
|---|
| 1523 | + delim = " "; |
|---|
| 1524 | + } |
|---|
| 1525 | + if (ret < 0) |
|---|
| 1526 | + goto fail; |
|---|
| 1527 | + free(last_token); |
|---|
| 1528 | + last_token = token; |
|---|
| 1529 | + } |
|---|
| 1530 | + continue; |
|---|
| 1531 | + } |
|---|
| 1438 | 1532 | break; |
|---|
| 1439 | 1533 | } |
|---|
| 1440 | 1534 | |
|---|
| .. | .. |
|---|
| 1444 | 1538 | } |
|---|
| 1445 | 1539 | field->name = field->alias = last_token; |
|---|
| 1446 | 1540 | |
|---|
| 1447 | | - if (test_type(type, EVENT_OP)) |
|---|
| 1541 | + if (test_type(type, TEP_EVENT_OP)) |
|---|
| 1448 | 1542 | goto fail; |
|---|
| 1449 | 1543 | |
|---|
| 1450 | 1544 | if (strcmp(token, "[") == 0) { |
|---|
| 1451 | | - enum event_type last_type = type; |
|---|
| 1545 | + enum tep_event_type last_type = type; |
|---|
| 1452 | 1546 | char *brackets = token; |
|---|
| 1453 | | - char *new_brackets; |
|---|
| 1454 | | - int len; |
|---|
| 1455 | 1547 | |
|---|
| 1456 | | - field->flags |= FIELD_IS_ARRAY; |
|---|
| 1548 | + field->flags |= TEP_FIELD_IS_ARRAY; |
|---|
| 1457 | 1549 | |
|---|
| 1458 | 1550 | type = read_token(&token); |
|---|
| 1459 | 1551 | |
|---|
| 1460 | | - if (type == EVENT_ITEM) |
|---|
| 1552 | + if (type == TEP_EVENT_ITEM) |
|---|
| 1461 | 1553 | field->arraylen = strtoul(token, NULL, 0); |
|---|
| 1462 | 1554 | else |
|---|
| 1463 | 1555 | field->arraylen = 0; |
|---|
| 1464 | 1556 | |
|---|
| 1465 | 1557 | while (strcmp(token, "]") != 0) { |
|---|
| 1466 | | - if (last_type == EVENT_ITEM && |
|---|
| 1467 | | - type == EVENT_ITEM) |
|---|
| 1468 | | - len = 2; |
|---|
| 1558 | + const char *delim; |
|---|
| 1559 | + |
|---|
| 1560 | + if (last_type == TEP_EVENT_ITEM && |
|---|
| 1561 | + type == TEP_EVENT_ITEM) |
|---|
| 1562 | + delim = " "; |
|---|
| 1469 | 1563 | else |
|---|
| 1470 | | - len = 1; |
|---|
| 1564 | + delim = ""; |
|---|
| 1565 | + |
|---|
| 1471 | 1566 | last_type = type; |
|---|
| 1472 | 1567 | |
|---|
| 1473 | | - new_brackets = realloc(brackets, |
|---|
| 1474 | | - strlen(brackets) + |
|---|
| 1475 | | - strlen(token) + len); |
|---|
| 1476 | | - if (!new_brackets) { |
|---|
| 1568 | + ret = append(&brackets, delim, token); |
|---|
| 1569 | + if (ret < 0) { |
|---|
| 1477 | 1570 | free(brackets); |
|---|
| 1478 | 1571 | goto fail; |
|---|
| 1479 | 1572 | } |
|---|
| 1480 | | - brackets = new_brackets; |
|---|
| 1481 | | - if (len == 2) |
|---|
| 1482 | | - strcat(brackets, " "); |
|---|
| 1483 | | - strcat(brackets, token); |
|---|
| 1484 | 1573 | /* We only care about the last token */ |
|---|
| 1485 | 1574 | field->arraylen = strtoul(token, NULL, 0); |
|---|
| 1486 | 1575 | free_token(token); |
|---|
| 1487 | 1576 | type = read_token(&token); |
|---|
| 1488 | | - if (type == EVENT_NONE) { |
|---|
| 1577 | + if (type == TEP_EVENT_NONE) { |
|---|
| 1578 | + free(brackets); |
|---|
| 1489 | 1579 | do_warning_event(event, "failed to find token"); |
|---|
| 1490 | 1580 | goto fail; |
|---|
| 1491 | 1581 | } |
|---|
| .. | .. |
|---|
| 1493 | 1583 | |
|---|
| 1494 | 1584 | free_token(token); |
|---|
| 1495 | 1585 | |
|---|
| 1496 | | - new_brackets = realloc(brackets, strlen(brackets) + 2); |
|---|
| 1497 | | - if (!new_brackets) { |
|---|
| 1586 | + ret = append(&brackets, "", "]"); |
|---|
| 1587 | + if (ret < 0) { |
|---|
| 1498 | 1588 | free(brackets); |
|---|
| 1499 | 1589 | goto fail; |
|---|
| 1500 | 1590 | } |
|---|
| 1501 | | - brackets = new_brackets; |
|---|
| 1502 | | - strcat(brackets, "]"); |
|---|
| 1503 | 1591 | |
|---|
| 1504 | 1592 | /* add brackets to type */ |
|---|
| 1505 | 1593 | |
|---|
| .. | .. |
|---|
| 1508 | 1596 | * If the next token is not an OP, then it is of |
|---|
| 1509 | 1597 | * the format: type [] item; |
|---|
| 1510 | 1598 | */ |
|---|
| 1511 | | - if (type == EVENT_ITEM) { |
|---|
| 1512 | | - char *new_type; |
|---|
| 1513 | | - new_type = realloc(field->type, |
|---|
| 1514 | | - strlen(field->type) + |
|---|
| 1515 | | - strlen(field->name) + |
|---|
| 1516 | | - strlen(brackets) + 2); |
|---|
| 1517 | | - if (!new_type) { |
|---|
| 1599 | + if (type == TEP_EVENT_ITEM) { |
|---|
| 1600 | + ret = append(&field->type, " ", field->name); |
|---|
| 1601 | + if (ret < 0) { |
|---|
| 1518 | 1602 | free(brackets); |
|---|
| 1519 | 1603 | goto fail; |
|---|
| 1520 | 1604 | } |
|---|
| 1521 | | - field->type = new_type; |
|---|
| 1522 | | - strcat(field->type, " "); |
|---|
| 1523 | | - strcat(field->type, field->name); |
|---|
| 1605 | + ret = append(&field->type, "", brackets); |
|---|
| 1606 | + |
|---|
| 1524 | 1607 | size_dynamic = type_size(field->name); |
|---|
| 1525 | 1608 | free_token(field->name); |
|---|
| 1526 | | - strcat(field->type, brackets); |
|---|
| 1527 | 1609 | field->name = field->alias = token; |
|---|
| 1528 | 1610 | type = read_token(&token); |
|---|
| 1529 | 1611 | } else { |
|---|
| 1530 | | - char *new_type; |
|---|
| 1531 | | - new_type = realloc(field->type, |
|---|
| 1532 | | - strlen(field->type) + |
|---|
| 1533 | | - strlen(brackets) + 1); |
|---|
| 1534 | | - if (!new_type) { |
|---|
| 1612 | + ret = append(&field->type, "", brackets); |
|---|
| 1613 | + if (ret < 0) { |
|---|
| 1535 | 1614 | free(brackets); |
|---|
| 1536 | 1615 | goto fail; |
|---|
| 1537 | 1616 | } |
|---|
| 1538 | | - field->type = new_type; |
|---|
| 1539 | | - strcat(field->type, brackets); |
|---|
| 1540 | 1617 | } |
|---|
| 1541 | 1618 | free(brackets); |
|---|
| 1542 | 1619 | } |
|---|
| 1543 | 1620 | |
|---|
| 1544 | 1621 | if (field_is_string(field)) |
|---|
| 1545 | | - field->flags |= FIELD_IS_STRING; |
|---|
| 1622 | + field->flags |= TEP_FIELD_IS_STRING; |
|---|
| 1546 | 1623 | if (field_is_dynamic(field)) |
|---|
| 1547 | | - field->flags |= FIELD_IS_DYNAMIC; |
|---|
| 1624 | + field->flags |= TEP_FIELD_IS_DYNAMIC; |
|---|
| 1548 | 1625 | if (field_is_long(field)) |
|---|
| 1549 | | - field->flags |= FIELD_IS_LONG; |
|---|
| 1626 | + field->flags |= TEP_FIELD_IS_LONG; |
|---|
| 1550 | 1627 | |
|---|
| 1551 | | - if (test_type_token(type, token, EVENT_OP, ";")) |
|---|
| 1628 | + if (test_type_token(type, token, TEP_EVENT_OP, ";")) |
|---|
| 1552 | 1629 | goto fail; |
|---|
| 1553 | 1630 | free_token(token); |
|---|
| 1554 | 1631 | |
|---|
| 1555 | | - if (read_expected(EVENT_ITEM, "offset") < 0) |
|---|
| 1632 | + if (read_expected(TEP_EVENT_ITEM, "offset") < 0) |
|---|
| 1556 | 1633 | goto fail_expect; |
|---|
| 1557 | 1634 | |
|---|
| 1558 | | - if (read_expected(EVENT_OP, ":") < 0) |
|---|
| 1635 | + if (read_expected(TEP_EVENT_OP, ":") < 0) |
|---|
| 1559 | 1636 | goto fail_expect; |
|---|
| 1560 | 1637 | |
|---|
| 1561 | | - if (read_expect_type(EVENT_ITEM, &token)) |
|---|
| 1638 | + if (read_expect_type(TEP_EVENT_ITEM, &token)) |
|---|
| 1562 | 1639 | goto fail; |
|---|
| 1563 | 1640 | field->offset = strtoul(token, NULL, 0); |
|---|
| 1564 | 1641 | free_token(token); |
|---|
| 1565 | 1642 | |
|---|
| 1566 | | - if (read_expected(EVENT_OP, ";") < 0) |
|---|
| 1643 | + if (read_expected(TEP_EVENT_OP, ";") < 0) |
|---|
| 1567 | 1644 | goto fail_expect; |
|---|
| 1568 | 1645 | |
|---|
| 1569 | | - if (read_expected(EVENT_ITEM, "size") < 0) |
|---|
| 1646 | + if (read_expected(TEP_EVENT_ITEM, "size") < 0) |
|---|
| 1570 | 1647 | goto fail_expect; |
|---|
| 1571 | 1648 | |
|---|
| 1572 | | - if (read_expected(EVENT_OP, ":") < 0) |
|---|
| 1649 | + if (read_expected(TEP_EVENT_OP, ":") < 0) |
|---|
| 1573 | 1650 | goto fail_expect; |
|---|
| 1574 | 1651 | |
|---|
| 1575 | | - if (read_expect_type(EVENT_ITEM, &token)) |
|---|
| 1652 | + if (read_expect_type(TEP_EVENT_ITEM, &token)) |
|---|
| 1576 | 1653 | goto fail; |
|---|
| 1577 | 1654 | field->size = strtoul(token, NULL, 0); |
|---|
| 1578 | 1655 | free_token(token); |
|---|
| 1579 | 1656 | |
|---|
| 1580 | | - if (read_expected(EVENT_OP, ";") < 0) |
|---|
| 1657 | + if (read_expected(TEP_EVENT_OP, ";") < 0) |
|---|
| 1581 | 1658 | goto fail_expect; |
|---|
| 1582 | 1659 | |
|---|
| 1583 | 1660 | type = read_token(&token); |
|---|
| 1584 | | - if (type != EVENT_NEWLINE) { |
|---|
| 1661 | + if (type != TEP_EVENT_NEWLINE) { |
|---|
| 1585 | 1662 | /* newer versions of the kernel have a "signed" type */ |
|---|
| 1586 | | - if (test_type_token(type, token, EVENT_ITEM, "signed")) |
|---|
| 1663 | + if (test_type_token(type, token, TEP_EVENT_ITEM, "signed")) |
|---|
| 1587 | 1664 | goto fail; |
|---|
| 1588 | 1665 | |
|---|
| 1589 | 1666 | free_token(token); |
|---|
| 1590 | 1667 | |
|---|
| 1591 | | - if (read_expected(EVENT_OP, ":") < 0) |
|---|
| 1668 | + if (read_expected(TEP_EVENT_OP, ":") < 0) |
|---|
| 1592 | 1669 | goto fail_expect; |
|---|
| 1593 | 1670 | |
|---|
| 1594 | | - if (read_expect_type(EVENT_ITEM, &token)) |
|---|
| 1671 | + if (read_expect_type(TEP_EVENT_ITEM, &token)) |
|---|
| 1595 | 1672 | goto fail; |
|---|
| 1596 | 1673 | |
|---|
| 1597 | 1674 | if (strtoul(token, NULL, 0)) |
|---|
| 1598 | | - field->flags |= FIELD_IS_SIGNED; |
|---|
| 1675 | + field->flags |= TEP_FIELD_IS_SIGNED; |
|---|
| 1599 | 1676 | |
|---|
| 1600 | 1677 | free_token(token); |
|---|
| 1601 | | - if (read_expected(EVENT_OP, ";") < 0) |
|---|
| 1678 | + if (read_expected(TEP_EVENT_OP, ";") < 0) |
|---|
| 1602 | 1679 | goto fail_expect; |
|---|
| 1603 | 1680 | |
|---|
| 1604 | | - if (read_expect_type(EVENT_NEWLINE, &token)) |
|---|
| 1681 | + if (read_expect_type(TEP_EVENT_NEWLINE, &token)) |
|---|
| 1605 | 1682 | goto fail; |
|---|
| 1606 | 1683 | } |
|---|
| 1607 | 1684 | |
|---|
| 1608 | 1685 | free_token(token); |
|---|
| 1609 | 1686 | |
|---|
| 1610 | | - if (field->flags & FIELD_IS_ARRAY) { |
|---|
| 1687 | + if (field->flags & TEP_FIELD_IS_ARRAY) { |
|---|
| 1611 | 1688 | if (field->arraylen) |
|---|
| 1612 | 1689 | field->elementsize = field->size / field->arraylen; |
|---|
| 1613 | | - else if (field->flags & FIELD_IS_DYNAMIC) |
|---|
| 1690 | + else if (field->flags & TEP_FIELD_IS_DYNAMIC) |
|---|
| 1614 | 1691 | field->elementsize = size_dynamic; |
|---|
| 1615 | | - else if (field->flags & FIELD_IS_STRING) |
|---|
| 1692 | + else if (field->flags & TEP_FIELD_IS_STRING) |
|---|
| 1616 | 1693 | field->elementsize = 1; |
|---|
| 1617 | | - else if (field->flags & FIELD_IS_LONG) |
|---|
| 1618 | | - field->elementsize = event->pevent ? |
|---|
| 1619 | | - event->pevent->long_size : |
|---|
| 1694 | + else if (field->flags & TEP_FIELD_IS_LONG) |
|---|
| 1695 | + field->elementsize = event->tep ? |
|---|
| 1696 | + event->tep->long_size : |
|---|
| 1620 | 1697 | sizeof(long); |
|---|
| 1621 | 1698 | } else |
|---|
| 1622 | 1699 | field->elementsize = field->size; |
|---|
| .. | .. |
|---|
| 1639 | 1716 | return -1; |
|---|
| 1640 | 1717 | } |
|---|
| 1641 | 1718 | |
|---|
| 1642 | | -static int event_read_format(struct event_format *event) |
|---|
| 1719 | +static int event_read_format(struct tep_event *event) |
|---|
| 1643 | 1720 | { |
|---|
| 1644 | 1721 | char *token; |
|---|
| 1645 | 1722 | int ret; |
|---|
| 1646 | 1723 | |
|---|
| 1647 | | - if (read_expected_item(EVENT_ITEM, "format") < 0) |
|---|
| 1724 | + if (read_expected_item(TEP_EVENT_ITEM, "format") < 0) |
|---|
| 1648 | 1725 | return -1; |
|---|
| 1649 | 1726 | |
|---|
| 1650 | | - if (read_expected(EVENT_OP, ":") < 0) |
|---|
| 1727 | + if (read_expected(TEP_EVENT_OP, ":") < 0) |
|---|
| 1651 | 1728 | return -1; |
|---|
| 1652 | 1729 | |
|---|
| 1653 | | - if (read_expect_type(EVENT_NEWLINE, &token)) |
|---|
| 1730 | + if (read_expect_type(TEP_EVENT_NEWLINE, &token)) |
|---|
| 1654 | 1731 | goto fail; |
|---|
| 1655 | 1732 | free_token(token); |
|---|
| 1656 | 1733 | |
|---|
| .. | .. |
|---|
| 1671 | 1748 | return -1; |
|---|
| 1672 | 1749 | } |
|---|
| 1673 | 1750 | |
|---|
| 1674 | | -static enum event_type |
|---|
| 1675 | | -process_arg_token(struct event_format *event, struct print_arg *arg, |
|---|
| 1676 | | - char **tok, enum event_type type); |
|---|
| 1751 | +static enum tep_event_type |
|---|
| 1752 | +process_arg_token(struct tep_event *event, struct tep_print_arg *arg, |
|---|
| 1753 | + char **tok, enum tep_event_type type); |
|---|
| 1677 | 1754 | |
|---|
| 1678 | | -static enum event_type |
|---|
| 1679 | | -process_arg(struct event_format *event, struct print_arg *arg, char **tok) |
|---|
| 1755 | +static enum tep_event_type |
|---|
| 1756 | +process_arg(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
|---|
| 1680 | 1757 | { |
|---|
| 1681 | | - enum event_type type; |
|---|
| 1758 | + enum tep_event_type type; |
|---|
| 1682 | 1759 | char *token; |
|---|
| 1683 | 1760 | |
|---|
| 1684 | 1761 | type = read_token(&token); |
|---|
| .. | .. |
|---|
| 1687 | 1764 | return process_arg_token(event, arg, tok, type); |
|---|
| 1688 | 1765 | } |
|---|
| 1689 | 1766 | |
|---|
| 1690 | | -static enum event_type |
|---|
| 1691 | | -process_op(struct event_format *event, struct print_arg *arg, char **tok); |
|---|
| 1767 | +static enum tep_event_type |
|---|
| 1768 | +process_op(struct tep_event *event, struct tep_print_arg *arg, char **tok); |
|---|
| 1692 | 1769 | |
|---|
| 1693 | 1770 | /* |
|---|
| 1694 | 1771 | * For __print_symbolic() and __print_flags, we need to completely |
|---|
| 1695 | 1772 | * evaluate the first argument, which defines what to print next. |
|---|
| 1696 | 1773 | */ |
|---|
| 1697 | | -static enum event_type |
|---|
| 1698 | | -process_field_arg(struct event_format *event, struct print_arg *arg, char **tok) |
|---|
| 1774 | +static enum tep_event_type |
|---|
| 1775 | +process_field_arg(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
|---|
| 1699 | 1776 | { |
|---|
| 1700 | | - enum event_type type; |
|---|
| 1777 | + enum tep_event_type type; |
|---|
| 1701 | 1778 | |
|---|
| 1702 | 1779 | type = process_arg(event, arg, tok); |
|---|
| 1703 | 1780 | |
|---|
| 1704 | | - while (type == EVENT_OP) { |
|---|
| 1781 | + while (type == TEP_EVENT_OP) { |
|---|
| 1705 | 1782 | type = process_op(event, arg, tok); |
|---|
| 1706 | 1783 | } |
|---|
| 1707 | 1784 | |
|---|
| 1708 | 1785 | return type; |
|---|
| 1709 | 1786 | } |
|---|
| 1710 | 1787 | |
|---|
| 1711 | | -static enum event_type |
|---|
| 1712 | | -process_cond(struct event_format *event, struct print_arg *top, char **tok) |
|---|
| 1788 | +static enum tep_event_type |
|---|
| 1789 | +process_cond(struct tep_event *event, struct tep_print_arg *top, char **tok) |
|---|
| 1713 | 1790 | { |
|---|
| 1714 | | - struct print_arg *arg, *left, *right; |
|---|
| 1715 | | - enum event_type type; |
|---|
| 1791 | + struct tep_print_arg *arg, *left, *right; |
|---|
| 1792 | + enum tep_event_type type; |
|---|
| 1716 | 1793 | char *token = NULL; |
|---|
| 1717 | 1794 | |
|---|
| 1718 | 1795 | arg = alloc_arg(); |
|---|
| .. | .. |
|---|
| 1727 | 1804 | goto out_free; |
|---|
| 1728 | 1805 | } |
|---|
| 1729 | 1806 | |
|---|
| 1730 | | - arg->type = PRINT_OP; |
|---|
| 1807 | + arg->type = TEP_PRINT_OP; |
|---|
| 1731 | 1808 | arg->op.left = left; |
|---|
| 1732 | 1809 | arg->op.right = right; |
|---|
| 1733 | 1810 | |
|---|
| .. | .. |
|---|
| 1735 | 1812 | type = process_arg(event, left, &token); |
|---|
| 1736 | 1813 | |
|---|
| 1737 | 1814 | again: |
|---|
| 1738 | | - if (type == EVENT_ERROR) |
|---|
| 1815 | + if (type == TEP_EVENT_ERROR) |
|---|
| 1739 | 1816 | goto out_free; |
|---|
| 1740 | 1817 | |
|---|
| 1741 | 1818 | /* Handle other operations in the arguments */ |
|---|
| 1742 | | - if (type == EVENT_OP && strcmp(token, ":") != 0) { |
|---|
| 1819 | + if (type == TEP_EVENT_OP && strcmp(token, ":") != 0) { |
|---|
| 1743 | 1820 | type = process_op(event, left, &token); |
|---|
| 1744 | 1821 | goto again; |
|---|
| 1745 | 1822 | } |
|---|
| 1746 | 1823 | |
|---|
| 1747 | | - if (test_type_token(type, token, EVENT_OP, ":")) |
|---|
| 1824 | + if (test_type_token(type, token, TEP_EVENT_OP, ":")) |
|---|
| 1748 | 1825 | goto out_free; |
|---|
| 1749 | 1826 | |
|---|
| 1750 | 1827 | arg->op.op = token; |
|---|
| .. | .. |
|---|
| 1761 | 1838 | top->op.right = NULL; |
|---|
| 1762 | 1839 | free_token(token); |
|---|
| 1763 | 1840 | free_arg(arg); |
|---|
| 1764 | | - return EVENT_ERROR; |
|---|
| 1841 | + return TEP_EVENT_ERROR; |
|---|
| 1765 | 1842 | } |
|---|
| 1766 | 1843 | |
|---|
| 1767 | | -static enum event_type |
|---|
| 1768 | | -process_array(struct event_format *event, struct print_arg *top, char **tok) |
|---|
| 1844 | +static enum tep_event_type |
|---|
| 1845 | +process_array(struct tep_event *event, struct tep_print_arg *top, char **tok) |
|---|
| 1769 | 1846 | { |
|---|
| 1770 | | - struct print_arg *arg; |
|---|
| 1771 | | - enum event_type type; |
|---|
| 1847 | + struct tep_print_arg *arg; |
|---|
| 1848 | + enum tep_event_type type; |
|---|
| 1772 | 1849 | char *token = NULL; |
|---|
| 1773 | 1850 | |
|---|
| 1774 | 1851 | arg = alloc_arg(); |
|---|
| .. | .. |
|---|
| 1776 | 1853 | do_warning_event(event, "%s: not enough memory!", __func__); |
|---|
| 1777 | 1854 | /* '*tok' is set to top->op.op. No need to free. */ |
|---|
| 1778 | 1855 | *tok = NULL; |
|---|
| 1779 | | - return EVENT_ERROR; |
|---|
| 1856 | + return TEP_EVENT_ERROR; |
|---|
| 1780 | 1857 | } |
|---|
| 1781 | 1858 | |
|---|
| 1782 | 1859 | *tok = NULL; |
|---|
| 1783 | 1860 | type = process_arg(event, arg, &token); |
|---|
| 1784 | | - if (test_type_token(type, token, EVENT_OP, "]")) |
|---|
| 1861 | + if (test_type_token(type, token, TEP_EVENT_OP, "]")) |
|---|
| 1785 | 1862 | goto out_free; |
|---|
| 1786 | 1863 | |
|---|
| 1787 | 1864 | top->op.right = arg; |
|---|
| .. | .. |
|---|
| 1795 | 1872 | out_free: |
|---|
| 1796 | 1873 | free_token(token); |
|---|
| 1797 | 1874 | free_arg(arg); |
|---|
| 1798 | | - return EVENT_ERROR; |
|---|
| 1875 | + return TEP_EVENT_ERROR; |
|---|
| 1799 | 1876 | } |
|---|
| 1800 | 1877 | |
|---|
| 1801 | 1878 | static int get_op_prio(char *op) |
|---|
| .. | .. |
|---|
| 1853 | 1930 | } |
|---|
| 1854 | 1931 | } |
|---|
| 1855 | 1932 | |
|---|
| 1856 | | -static int set_op_prio(struct print_arg *arg) |
|---|
| 1933 | +static int set_op_prio(struct tep_print_arg *arg) |
|---|
| 1857 | 1934 | { |
|---|
| 1858 | 1935 | |
|---|
| 1859 | 1936 | /* single ops are the greatest */ |
|---|
| 1860 | | - if (!arg->op.left || arg->op.left->type == PRINT_NULL) |
|---|
| 1937 | + if (!arg->op.left || arg->op.left->type == TEP_PRINT_NULL) |
|---|
| 1861 | 1938 | arg->op.prio = 0; |
|---|
| 1862 | 1939 | else |
|---|
| 1863 | 1940 | arg->op.prio = get_op_prio(arg->op.op); |
|---|
| .. | .. |
|---|
| 1866 | 1943 | } |
|---|
| 1867 | 1944 | |
|---|
| 1868 | 1945 | /* Note, *tok does not get freed, but will most likely be saved */ |
|---|
| 1869 | | -static enum event_type |
|---|
| 1870 | | -process_op(struct event_format *event, struct print_arg *arg, char **tok) |
|---|
| 1946 | +static enum tep_event_type |
|---|
| 1947 | +process_op(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
|---|
| 1871 | 1948 | { |
|---|
| 1872 | | - struct print_arg *left, *right = NULL; |
|---|
| 1873 | | - enum event_type type; |
|---|
| 1949 | + struct tep_print_arg *left, *right = NULL; |
|---|
| 1950 | + enum tep_event_type type; |
|---|
| 1874 | 1951 | char *token; |
|---|
| 1875 | 1952 | |
|---|
| 1876 | 1953 | /* the op is passed in via tok */ |
|---|
| 1877 | 1954 | token = *tok; |
|---|
| 1878 | 1955 | |
|---|
| 1879 | | - if (arg->type == PRINT_OP && !arg->op.left) { |
|---|
| 1956 | + if (arg->type == TEP_PRINT_OP && !arg->op.left) { |
|---|
| 1880 | 1957 | /* handle single op */ |
|---|
| 1881 | 1958 | if (token[1]) { |
|---|
| 1882 | 1959 | do_warning_event(event, "bad op token %s", token); |
|---|
| .. | .. |
|---|
| 1899 | 1976 | if (!left) |
|---|
| 1900 | 1977 | goto out_warn_free; |
|---|
| 1901 | 1978 | |
|---|
| 1902 | | - left->type = PRINT_NULL; |
|---|
| 1979 | + left->type = TEP_PRINT_NULL; |
|---|
| 1903 | 1980 | arg->op.left = left; |
|---|
| 1904 | 1981 | |
|---|
| 1905 | 1982 | right = alloc_arg(); |
|---|
| .. | .. |
|---|
| 1921 | 1998 | /* copy the top arg to the left */ |
|---|
| 1922 | 1999 | *left = *arg; |
|---|
| 1923 | 2000 | |
|---|
| 1924 | | - arg->type = PRINT_OP; |
|---|
| 2001 | + arg->type = TEP_PRINT_OP; |
|---|
| 1925 | 2002 | arg->op.op = token; |
|---|
| 1926 | 2003 | arg->op.left = left; |
|---|
| 1927 | 2004 | arg->op.prio = 0; |
|---|
| .. | .. |
|---|
| 1955 | 2032 | /* copy the top arg to the left */ |
|---|
| 1956 | 2033 | *left = *arg; |
|---|
| 1957 | 2034 | |
|---|
| 1958 | | - arg->type = PRINT_OP; |
|---|
| 2035 | + arg->type = TEP_PRINT_OP; |
|---|
| 1959 | 2036 | arg->op.op = token; |
|---|
| 1960 | 2037 | arg->op.left = left; |
|---|
| 1961 | 2038 | arg->op.right = NULL; |
|---|
| 1962 | 2039 | |
|---|
| 1963 | 2040 | if (set_op_prio(arg) == -1) { |
|---|
| 1964 | | - event->flags |= EVENT_FL_FAILED; |
|---|
| 2041 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 1965 | 2042 | /* arg->op.op (= token) will be freed at out_free */ |
|---|
| 1966 | 2043 | arg->op.op = NULL; |
|---|
| 1967 | 2044 | goto out_free; |
|---|
| .. | .. |
|---|
| 1972 | 2049 | |
|---|
| 1973 | 2050 | /* could just be a type pointer */ |
|---|
| 1974 | 2051 | if ((strcmp(arg->op.op, "*") == 0) && |
|---|
| 1975 | | - type == EVENT_DELIM && (strcmp(token, ")") == 0)) { |
|---|
| 1976 | | - char *new_atom; |
|---|
| 2052 | + type == TEP_EVENT_DELIM && (strcmp(token, ")") == 0)) { |
|---|
| 2053 | + int ret; |
|---|
| 1977 | 2054 | |
|---|
| 1978 | | - if (left->type != PRINT_ATOM) { |
|---|
| 2055 | + if (left->type != TEP_PRINT_ATOM) { |
|---|
| 1979 | 2056 | do_warning_event(event, "bad pointer type"); |
|---|
| 1980 | 2057 | goto out_free; |
|---|
| 1981 | 2058 | } |
|---|
| 1982 | | - new_atom = realloc(left->atom.atom, |
|---|
| 1983 | | - strlen(left->atom.atom) + 3); |
|---|
| 1984 | | - if (!new_atom) |
|---|
| 2059 | + ret = append(&left->atom.atom, " ", "*"); |
|---|
| 2060 | + if (ret < 0) |
|---|
| 1985 | 2061 | goto out_warn_free; |
|---|
| 1986 | 2062 | |
|---|
| 1987 | | - left->atom.atom = new_atom; |
|---|
| 1988 | | - strcat(left->atom.atom, " *"); |
|---|
| 1989 | 2063 | free(arg->op.op); |
|---|
| 1990 | 2064 | *arg = *left; |
|---|
| 1991 | 2065 | free(left); |
|---|
| .. | .. |
|---|
| 1998 | 2072 | goto out_warn_free; |
|---|
| 1999 | 2073 | |
|---|
| 2000 | 2074 | type = process_arg_token(event, right, tok, type); |
|---|
| 2001 | | - if (type == EVENT_ERROR) { |
|---|
| 2075 | + if (type == TEP_EVENT_ERROR) { |
|---|
| 2002 | 2076 | free_arg(right); |
|---|
| 2003 | 2077 | /* token was freed in process_arg_token() via *tok */ |
|---|
| 2004 | 2078 | token = NULL; |
|---|
| 2005 | 2079 | goto out_free; |
|---|
| 2006 | 2080 | } |
|---|
| 2007 | 2081 | |
|---|
| 2008 | | - if (right->type == PRINT_OP && |
|---|
| 2082 | + if (right->type == TEP_PRINT_OP && |
|---|
| 2009 | 2083 | get_op_prio(arg->op.op) < get_op_prio(right->op.op)) { |
|---|
| 2010 | | - struct print_arg tmp; |
|---|
| 2084 | + struct tep_print_arg tmp; |
|---|
| 2011 | 2085 | |
|---|
| 2012 | 2086 | /* rotate ops according to the priority */ |
|---|
| 2013 | 2087 | arg->op.right = right->op.left; |
|---|
| .. | .. |
|---|
| 2029 | 2103 | |
|---|
| 2030 | 2104 | *left = *arg; |
|---|
| 2031 | 2105 | |
|---|
| 2032 | | - arg->type = PRINT_OP; |
|---|
| 2106 | + arg->type = TEP_PRINT_OP; |
|---|
| 2033 | 2107 | arg->op.op = token; |
|---|
| 2034 | 2108 | arg->op.left = left; |
|---|
| 2035 | 2109 | |
|---|
| .. | .. |
|---|
| 2040 | 2114 | |
|---|
| 2041 | 2115 | } else { |
|---|
| 2042 | 2116 | do_warning_event(event, "unknown op '%s'", token); |
|---|
| 2043 | | - event->flags |= EVENT_FL_FAILED; |
|---|
| 2117 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 2044 | 2118 | /* the arg is now the left side */ |
|---|
| 2045 | 2119 | goto out_free; |
|---|
| 2046 | 2120 | } |
|---|
| 2047 | 2121 | |
|---|
| 2048 | | - if (type == EVENT_OP && strcmp(*tok, ":") != 0) { |
|---|
| 2122 | + if (type == TEP_EVENT_OP && strcmp(*tok, ":") != 0) { |
|---|
| 2049 | 2123 | int prio; |
|---|
| 2050 | 2124 | |
|---|
| 2051 | 2125 | /* higher prios need to be closer to the root */ |
|---|
| .. | .. |
|---|
| 2064 | 2138 | out_free: |
|---|
| 2065 | 2139 | free_token(token); |
|---|
| 2066 | 2140 | *tok = NULL; |
|---|
| 2067 | | - return EVENT_ERROR; |
|---|
| 2141 | + return TEP_EVENT_ERROR; |
|---|
| 2068 | 2142 | } |
|---|
| 2069 | 2143 | |
|---|
| 2070 | | -static enum event_type |
|---|
| 2071 | | -process_entry(struct event_format *event __maybe_unused, struct print_arg *arg, |
|---|
| 2144 | +static enum tep_event_type |
|---|
| 2145 | +process_entry(struct tep_event *event __maybe_unused, struct tep_print_arg *arg, |
|---|
| 2072 | 2146 | char **tok) |
|---|
| 2073 | 2147 | { |
|---|
| 2074 | | - enum event_type type; |
|---|
| 2148 | + enum tep_event_type type; |
|---|
| 2075 | 2149 | char *field; |
|---|
| 2076 | 2150 | char *token; |
|---|
| 2077 | 2151 | |
|---|
| 2078 | | - if (read_expected(EVENT_OP, "->") < 0) |
|---|
| 2152 | + if (read_expected(TEP_EVENT_OP, "->") < 0) |
|---|
| 2079 | 2153 | goto out_err; |
|---|
| 2080 | 2154 | |
|---|
| 2081 | | - if (read_expect_type(EVENT_ITEM, &token) < 0) |
|---|
| 2155 | + if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
|---|
| 2082 | 2156 | goto out_free; |
|---|
| 2083 | 2157 | field = token; |
|---|
| 2084 | 2158 | |
|---|
| 2085 | | - arg->type = PRINT_FIELD; |
|---|
| 2159 | + arg->type = TEP_PRINT_FIELD; |
|---|
| 2086 | 2160 | arg->field.name = field; |
|---|
| 2087 | 2161 | |
|---|
| 2088 | 2162 | if (is_flag_field) { |
|---|
| 2089 | 2163 | arg->field.field = tep_find_any_field(event, arg->field.name); |
|---|
| 2090 | | - arg->field.field->flags |= FIELD_IS_FLAG; |
|---|
| 2164 | + arg->field.field->flags |= TEP_FIELD_IS_FLAG; |
|---|
| 2091 | 2165 | is_flag_field = 0; |
|---|
| 2092 | 2166 | } else if (is_symbolic_field) { |
|---|
| 2093 | 2167 | arg->field.field = tep_find_any_field(event, arg->field.name); |
|---|
| 2094 | | - arg->field.field->flags |= FIELD_IS_SYMBOLIC; |
|---|
| 2168 | + arg->field.field->flags |= TEP_FIELD_IS_SYMBOLIC; |
|---|
| 2095 | 2169 | is_symbolic_field = 0; |
|---|
| 2096 | 2170 | } |
|---|
| 2097 | 2171 | |
|---|
| .. | .. |
|---|
| 2104 | 2178 | free_token(token); |
|---|
| 2105 | 2179 | out_err: |
|---|
| 2106 | 2180 | *tok = NULL; |
|---|
| 2107 | | - return EVENT_ERROR; |
|---|
| 2181 | + return TEP_EVENT_ERROR; |
|---|
| 2108 | 2182 | } |
|---|
| 2109 | 2183 | |
|---|
| 2110 | | -static int alloc_and_process_delim(struct event_format *event, char *next_token, |
|---|
| 2111 | | - struct print_arg **print_arg) |
|---|
| 2184 | +static int alloc_and_process_delim(struct tep_event *event, char *next_token, |
|---|
| 2185 | + struct tep_print_arg **print_arg) |
|---|
| 2112 | 2186 | { |
|---|
| 2113 | | - struct print_arg *field; |
|---|
| 2114 | | - enum event_type type; |
|---|
| 2187 | + struct tep_print_arg *field; |
|---|
| 2188 | + enum tep_event_type type; |
|---|
| 2115 | 2189 | char *token; |
|---|
| 2116 | 2190 | int ret = 0; |
|---|
| 2117 | 2191 | |
|---|
| .. | .. |
|---|
| 2124 | 2198 | |
|---|
| 2125 | 2199 | type = process_arg(event, field, &token); |
|---|
| 2126 | 2200 | |
|---|
| 2127 | | - if (test_type_token(type, token, EVENT_DELIM, next_token)) { |
|---|
| 2201 | + if (test_type_token(type, token, TEP_EVENT_DELIM, next_token)) { |
|---|
| 2128 | 2202 | errno = EINVAL; |
|---|
| 2129 | 2203 | ret = -1; |
|---|
| 2130 | 2204 | free_arg(field); |
|---|
| .. | .. |
|---|
| 2139 | 2213 | return ret; |
|---|
| 2140 | 2214 | } |
|---|
| 2141 | 2215 | |
|---|
| 2142 | | -static char *arg_eval (struct print_arg *arg); |
|---|
| 2216 | +static char *arg_eval (struct tep_print_arg *arg); |
|---|
| 2143 | 2217 | |
|---|
| 2144 | 2218 | static unsigned long long |
|---|
| 2145 | 2219 | eval_type_str(unsigned long long val, const char *type, int pointer) |
|---|
| .. | .. |
|---|
| 2236 | 2310 | * Try to figure out the type. |
|---|
| 2237 | 2311 | */ |
|---|
| 2238 | 2312 | static unsigned long long |
|---|
| 2239 | | -eval_type(unsigned long long val, struct print_arg *arg, int pointer) |
|---|
| 2313 | +eval_type(unsigned long long val, struct tep_print_arg *arg, int pointer) |
|---|
| 2240 | 2314 | { |
|---|
| 2241 | | - if (arg->type != PRINT_TYPE) { |
|---|
| 2315 | + if (arg->type != TEP_PRINT_TYPE) { |
|---|
| 2242 | 2316 | do_warning("expected type argument"); |
|---|
| 2243 | 2317 | return 0; |
|---|
| 2244 | 2318 | } |
|---|
| .. | .. |
|---|
| 2246 | 2320 | return eval_type_str(val, arg->typecast.type, pointer); |
|---|
| 2247 | 2321 | } |
|---|
| 2248 | 2322 | |
|---|
| 2249 | | -static int arg_num_eval(struct print_arg *arg, long long *val) |
|---|
| 2323 | +static int arg_num_eval(struct tep_print_arg *arg, long long *val) |
|---|
| 2250 | 2324 | { |
|---|
| 2251 | 2325 | long long left, right; |
|---|
| 2252 | 2326 | int ret = 1; |
|---|
| 2253 | 2327 | |
|---|
| 2254 | 2328 | switch (arg->type) { |
|---|
| 2255 | | - case PRINT_ATOM: |
|---|
| 2329 | + case TEP_PRINT_ATOM: |
|---|
| 2256 | 2330 | *val = strtoll(arg->atom.atom, NULL, 0); |
|---|
| 2257 | 2331 | break; |
|---|
| 2258 | | - case PRINT_TYPE: |
|---|
| 2332 | + case TEP_PRINT_TYPE: |
|---|
| 2259 | 2333 | ret = arg_num_eval(arg->typecast.item, val); |
|---|
| 2260 | 2334 | if (!ret) |
|---|
| 2261 | 2335 | break; |
|---|
| 2262 | 2336 | *val = eval_type(*val, arg, 0); |
|---|
| 2263 | 2337 | break; |
|---|
| 2264 | | - case PRINT_OP: |
|---|
| 2338 | + case TEP_PRINT_OP: |
|---|
| 2265 | 2339 | switch (arg->op.op[0]) { |
|---|
| 2266 | 2340 | case '|': |
|---|
| 2267 | 2341 | ret = arg_num_eval(arg->op.left, &left); |
|---|
| .. | .. |
|---|
| 2364 | 2438 | break; |
|---|
| 2365 | 2439 | case '-': |
|---|
| 2366 | 2440 | /* check for negative */ |
|---|
| 2367 | | - if (arg->op.left->type == PRINT_NULL) |
|---|
| 2441 | + if (arg->op.left->type == TEP_PRINT_NULL) |
|---|
| 2368 | 2442 | left = 0; |
|---|
| 2369 | 2443 | else |
|---|
| 2370 | 2444 | ret = arg_num_eval(arg->op.left, &left); |
|---|
| .. | .. |
|---|
| 2376 | 2450 | *val = left - right; |
|---|
| 2377 | 2451 | break; |
|---|
| 2378 | 2452 | case '+': |
|---|
| 2379 | | - if (arg->op.left->type == PRINT_NULL) |
|---|
| 2453 | + if (arg->op.left->type == TEP_PRINT_NULL) |
|---|
| 2380 | 2454 | left = 0; |
|---|
| 2381 | 2455 | else |
|---|
| 2382 | 2456 | ret = arg_num_eval(arg->op.left, &left); |
|---|
| .. | .. |
|---|
| 2399 | 2473 | } |
|---|
| 2400 | 2474 | break; |
|---|
| 2401 | 2475 | |
|---|
| 2402 | | - case PRINT_NULL: |
|---|
| 2403 | | - case PRINT_FIELD ... PRINT_SYMBOL: |
|---|
| 2404 | | - case PRINT_STRING: |
|---|
| 2405 | | - case PRINT_BSTRING: |
|---|
| 2406 | | - case PRINT_BITMASK: |
|---|
| 2476 | + case TEP_PRINT_NULL: |
|---|
| 2477 | + case TEP_PRINT_FIELD ... TEP_PRINT_SYMBOL: |
|---|
| 2478 | + case TEP_PRINT_STRING: |
|---|
| 2479 | + case TEP_PRINT_BSTRING: |
|---|
| 2480 | + case TEP_PRINT_BITMASK: |
|---|
| 2407 | 2481 | default: |
|---|
| 2408 | 2482 | do_warning("invalid eval type %d", arg->type); |
|---|
| 2409 | 2483 | ret = 0; |
|---|
| .. | .. |
|---|
| 2412 | 2486 | return ret; |
|---|
| 2413 | 2487 | } |
|---|
| 2414 | 2488 | |
|---|
| 2415 | | -static char *arg_eval (struct print_arg *arg) |
|---|
| 2489 | +static char *arg_eval (struct tep_print_arg *arg) |
|---|
| 2416 | 2490 | { |
|---|
| 2417 | 2491 | long long val; |
|---|
| 2418 | 2492 | static char buf[24]; |
|---|
| 2419 | 2493 | |
|---|
| 2420 | 2494 | switch (arg->type) { |
|---|
| 2421 | | - case PRINT_ATOM: |
|---|
| 2495 | + case TEP_PRINT_ATOM: |
|---|
| 2422 | 2496 | return arg->atom.atom; |
|---|
| 2423 | | - case PRINT_TYPE: |
|---|
| 2497 | + case TEP_PRINT_TYPE: |
|---|
| 2424 | 2498 | return arg_eval(arg->typecast.item); |
|---|
| 2425 | | - case PRINT_OP: |
|---|
| 2499 | + case TEP_PRINT_OP: |
|---|
| 2426 | 2500 | if (!arg_num_eval(arg, &val)) |
|---|
| 2427 | 2501 | break; |
|---|
| 2428 | 2502 | sprintf(buf, "%lld", val); |
|---|
| 2429 | 2503 | return buf; |
|---|
| 2430 | 2504 | |
|---|
| 2431 | | - case PRINT_NULL: |
|---|
| 2432 | | - case PRINT_FIELD ... PRINT_SYMBOL: |
|---|
| 2433 | | - case PRINT_STRING: |
|---|
| 2434 | | - case PRINT_BSTRING: |
|---|
| 2435 | | - case PRINT_BITMASK: |
|---|
| 2505 | + case TEP_PRINT_NULL: |
|---|
| 2506 | + case TEP_PRINT_FIELD ... TEP_PRINT_SYMBOL: |
|---|
| 2507 | + case TEP_PRINT_STRING: |
|---|
| 2508 | + case TEP_PRINT_BSTRING: |
|---|
| 2509 | + case TEP_PRINT_BITMASK: |
|---|
| 2436 | 2510 | default: |
|---|
| 2437 | 2511 | do_warning("invalid eval type %d", arg->type); |
|---|
| 2438 | 2512 | break; |
|---|
| .. | .. |
|---|
| 2441 | 2515 | return NULL; |
|---|
| 2442 | 2516 | } |
|---|
| 2443 | 2517 | |
|---|
| 2444 | | -static enum event_type |
|---|
| 2445 | | -process_fields(struct event_format *event, struct print_flag_sym **list, char **tok) |
|---|
| 2518 | +static enum tep_event_type |
|---|
| 2519 | +process_fields(struct tep_event *event, struct tep_print_flag_sym **list, char **tok) |
|---|
| 2446 | 2520 | { |
|---|
| 2447 | | - enum event_type type; |
|---|
| 2448 | | - struct print_arg *arg = NULL; |
|---|
| 2449 | | - struct print_flag_sym *field; |
|---|
| 2521 | + enum tep_event_type type; |
|---|
| 2522 | + struct tep_print_arg *arg = NULL; |
|---|
| 2523 | + struct tep_print_flag_sym *field; |
|---|
| 2450 | 2524 | char *token = *tok; |
|---|
| 2451 | 2525 | char *value; |
|---|
| 2452 | 2526 | |
|---|
| 2453 | 2527 | do { |
|---|
| 2454 | 2528 | free_token(token); |
|---|
| 2455 | 2529 | type = read_token_item(&token); |
|---|
| 2456 | | - if (test_type_token(type, token, EVENT_OP, "{")) |
|---|
| 2530 | + if (test_type_token(type, token, TEP_EVENT_OP, "{")) |
|---|
| 2457 | 2531 | break; |
|---|
| 2458 | 2532 | |
|---|
| 2459 | 2533 | arg = alloc_arg(); |
|---|
| .. | .. |
|---|
| 2463 | 2537 | free_token(token); |
|---|
| 2464 | 2538 | type = process_arg(event, arg, &token); |
|---|
| 2465 | 2539 | |
|---|
| 2466 | | - if (type == EVENT_OP) |
|---|
| 2540 | + if (type == TEP_EVENT_OP) |
|---|
| 2467 | 2541 | type = process_op(event, arg, &token); |
|---|
| 2468 | 2542 | |
|---|
| 2469 | | - if (type == EVENT_ERROR) |
|---|
| 2543 | + if (type == TEP_EVENT_ERROR) |
|---|
| 2470 | 2544 | goto out_free; |
|---|
| 2471 | 2545 | |
|---|
| 2472 | | - if (test_type_token(type, token, EVENT_DELIM, ",")) |
|---|
| 2546 | + if (test_type_token(type, token, TEP_EVENT_DELIM, ",")) |
|---|
| 2473 | 2547 | goto out_free; |
|---|
| 2474 | 2548 | |
|---|
| 2475 | 2549 | field = calloc(1, sizeof(*field)); |
|---|
| .. | .. |
|---|
| 2490 | 2564 | |
|---|
| 2491 | 2565 | free_token(token); |
|---|
| 2492 | 2566 | type = process_arg(event, arg, &token); |
|---|
| 2493 | | - if (test_type_token(type, token, EVENT_OP, "}")) |
|---|
| 2567 | + if (test_type_token(type, token, TEP_EVENT_OP, "}")) |
|---|
| 2494 | 2568 | goto out_free_field; |
|---|
| 2495 | 2569 | |
|---|
| 2496 | 2570 | value = arg_eval(arg); |
|---|
| .. | .. |
|---|
| 2507 | 2581 | |
|---|
| 2508 | 2582 | free_token(token); |
|---|
| 2509 | 2583 | type = read_token_item(&token); |
|---|
| 2510 | | - } while (type == EVENT_DELIM && strcmp(token, ",") == 0); |
|---|
| 2584 | + } while (type == TEP_EVENT_DELIM && strcmp(token, ",") == 0); |
|---|
| 2511 | 2585 | |
|---|
| 2512 | 2586 | *tok = token; |
|---|
| 2513 | 2587 | return type; |
|---|
| .. | .. |
|---|
| 2519 | 2593 | free_token(token); |
|---|
| 2520 | 2594 | *tok = NULL; |
|---|
| 2521 | 2595 | |
|---|
| 2522 | | - return EVENT_ERROR; |
|---|
| 2596 | + return TEP_EVENT_ERROR; |
|---|
| 2523 | 2597 | } |
|---|
| 2524 | 2598 | |
|---|
| 2525 | | -static enum event_type |
|---|
| 2526 | | -process_flags(struct event_format *event, struct print_arg *arg, char **tok) |
|---|
| 2599 | +static enum tep_event_type |
|---|
| 2600 | +process_flags(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
|---|
| 2527 | 2601 | { |
|---|
| 2528 | | - struct print_arg *field; |
|---|
| 2529 | | - enum event_type type; |
|---|
| 2602 | + struct tep_print_arg *field; |
|---|
| 2603 | + enum tep_event_type type; |
|---|
| 2530 | 2604 | char *token = NULL; |
|---|
| 2531 | 2605 | |
|---|
| 2532 | 2606 | memset(arg, 0, sizeof(*arg)); |
|---|
| 2533 | | - arg->type = PRINT_FLAGS; |
|---|
| 2607 | + arg->type = TEP_PRINT_FLAGS; |
|---|
| 2534 | 2608 | |
|---|
| 2535 | 2609 | field = alloc_arg(); |
|---|
| 2536 | 2610 | if (!field) { |
|---|
| .. | .. |
|---|
| 2541 | 2615 | type = process_field_arg(event, field, &token); |
|---|
| 2542 | 2616 | |
|---|
| 2543 | 2617 | /* Handle operations in the first argument */ |
|---|
| 2544 | | - while (type == EVENT_OP) |
|---|
| 2618 | + while (type == TEP_EVENT_OP) |
|---|
| 2545 | 2619 | type = process_op(event, field, &token); |
|---|
| 2546 | 2620 | |
|---|
| 2547 | | - if (test_type_token(type, token, EVENT_DELIM, ",")) |
|---|
| 2621 | + if (test_type_token(type, token, TEP_EVENT_DELIM, ",")) |
|---|
| 2548 | 2622 | goto out_free_field; |
|---|
| 2549 | 2623 | free_token(token); |
|---|
| 2550 | 2624 | |
|---|
| .. | .. |
|---|
| 2556 | 2630 | type = read_token_item(&token); |
|---|
| 2557 | 2631 | } |
|---|
| 2558 | 2632 | |
|---|
| 2559 | | - if (test_type_token(type, token, EVENT_DELIM, ",")) |
|---|
| 2633 | + if (test_type_token(type, token, TEP_EVENT_DELIM, ",")) |
|---|
| 2560 | 2634 | goto out_free; |
|---|
| 2561 | 2635 | |
|---|
| 2562 | 2636 | type = process_fields(event, &arg->flags.flags, &token); |
|---|
| 2563 | | - if (test_type_token(type, token, EVENT_DELIM, ")")) |
|---|
| 2637 | + if (test_type_token(type, token, TEP_EVENT_DELIM, ")")) |
|---|
| 2564 | 2638 | goto out_free; |
|---|
| 2565 | 2639 | |
|---|
| 2566 | 2640 | free_token(token); |
|---|
| .. | .. |
|---|
| 2572 | 2646 | out_free: |
|---|
| 2573 | 2647 | free_token(token); |
|---|
| 2574 | 2648 | *tok = NULL; |
|---|
| 2575 | | - return EVENT_ERROR; |
|---|
| 2649 | + return TEP_EVENT_ERROR; |
|---|
| 2576 | 2650 | } |
|---|
| 2577 | 2651 | |
|---|
| 2578 | | -static enum event_type |
|---|
| 2579 | | -process_symbols(struct event_format *event, struct print_arg *arg, char **tok) |
|---|
| 2652 | +static enum tep_event_type |
|---|
| 2653 | +process_symbols(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
|---|
| 2580 | 2654 | { |
|---|
| 2581 | | - struct print_arg *field; |
|---|
| 2582 | | - enum event_type type; |
|---|
| 2655 | + struct tep_print_arg *field; |
|---|
| 2656 | + enum tep_event_type type; |
|---|
| 2583 | 2657 | char *token = NULL; |
|---|
| 2584 | 2658 | |
|---|
| 2585 | 2659 | memset(arg, 0, sizeof(*arg)); |
|---|
| 2586 | | - arg->type = PRINT_SYMBOL; |
|---|
| 2660 | + arg->type = TEP_PRINT_SYMBOL; |
|---|
| 2587 | 2661 | |
|---|
| 2588 | 2662 | field = alloc_arg(); |
|---|
| 2589 | 2663 | if (!field) { |
|---|
| .. | .. |
|---|
| 2593 | 2667 | |
|---|
| 2594 | 2668 | type = process_field_arg(event, field, &token); |
|---|
| 2595 | 2669 | |
|---|
| 2596 | | - if (test_type_token(type, token, EVENT_DELIM, ",")) |
|---|
| 2670 | + if (test_type_token(type, token, TEP_EVENT_DELIM, ",")) |
|---|
| 2597 | 2671 | goto out_free_field; |
|---|
| 2598 | 2672 | |
|---|
| 2599 | 2673 | arg->symbol.field = field; |
|---|
| 2600 | 2674 | |
|---|
| 2601 | 2675 | type = process_fields(event, &arg->symbol.symbols, &token); |
|---|
| 2602 | | - if (test_type_token(type, token, EVENT_DELIM, ")")) |
|---|
| 2676 | + if (test_type_token(type, token, TEP_EVENT_DELIM, ")")) |
|---|
| 2603 | 2677 | goto out_free; |
|---|
| 2604 | 2678 | |
|---|
| 2605 | 2679 | free_token(token); |
|---|
| .. | .. |
|---|
| 2611 | 2685 | out_free: |
|---|
| 2612 | 2686 | free_token(token); |
|---|
| 2613 | 2687 | *tok = NULL; |
|---|
| 2614 | | - return EVENT_ERROR; |
|---|
| 2688 | + return TEP_EVENT_ERROR; |
|---|
| 2615 | 2689 | } |
|---|
| 2616 | 2690 | |
|---|
| 2617 | | -static enum event_type |
|---|
| 2618 | | -process_hex_common(struct event_format *event, struct print_arg *arg, |
|---|
| 2619 | | - char **tok, enum print_arg_type type) |
|---|
| 2691 | +static enum tep_event_type |
|---|
| 2692 | +process_hex_common(struct tep_event *event, struct tep_print_arg *arg, |
|---|
| 2693 | + char **tok, enum tep_print_arg_type type) |
|---|
| 2620 | 2694 | { |
|---|
| 2621 | 2695 | memset(arg, 0, sizeof(*arg)); |
|---|
| 2622 | 2696 | arg->type = type; |
|---|
| .. | .. |
|---|
| 2634 | 2708 | arg->hex.field = NULL; |
|---|
| 2635 | 2709 | out: |
|---|
| 2636 | 2710 | *tok = NULL; |
|---|
| 2637 | | - return EVENT_ERROR; |
|---|
| 2711 | + return TEP_EVENT_ERROR; |
|---|
| 2638 | 2712 | } |
|---|
| 2639 | 2713 | |
|---|
| 2640 | | -static enum event_type |
|---|
| 2641 | | -process_hex(struct event_format *event, struct print_arg *arg, char **tok) |
|---|
| 2714 | +static enum tep_event_type |
|---|
| 2715 | +process_hex(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
|---|
| 2642 | 2716 | { |
|---|
| 2643 | | - return process_hex_common(event, arg, tok, PRINT_HEX); |
|---|
| 2717 | + return process_hex_common(event, arg, tok, TEP_PRINT_HEX); |
|---|
| 2644 | 2718 | } |
|---|
| 2645 | 2719 | |
|---|
| 2646 | | -static enum event_type |
|---|
| 2647 | | -process_hex_str(struct event_format *event, struct print_arg *arg, |
|---|
| 2720 | +static enum tep_event_type |
|---|
| 2721 | +process_hex_str(struct tep_event *event, struct tep_print_arg *arg, |
|---|
| 2648 | 2722 | char **tok) |
|---|
| 2649 | 2723 | { |
|---|
| 2650 | | - return process_hex_common(event, arg, tok, PRINT_HEX_STR); |
|---|
| 2724 | + return process_hex_common(event, arg, tok, TEP_PRINT_HEX_STR); |
|---|
| 2651 | 2725 | } |
|---|
| 2652 | 2726 | |
|---|
| 2653 | | -static enum event_type |
|---|
| 2654 | | -process_int_array(struct event_format *event, struct print_arg *arg, char **tok) |
|---|
| 2727 | +static enum tep_event_type |
|---|
| 2728 | +process_int_array(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
|---|
| 2655 | 2729 | { |
|---|
| 2656 | 2730 | memset(arg, 0, sizeof(*arg)); |
|---|
| 2657 | | - arg->type = PRINT_INT_ARRAY; |
|---|
| 2731 | + arg->type = TEP_PRINT_INT_ARRAY; |
|---|
| 2658 | 2732 | |
|---|
| 2659 | 2733 | if (alloc_and_process_delim(event, ",", &arg->int_array.field)) |
|---|
| 2660 | 2734 | goto out; |
|---|
| .. | .. |
|---|
| 2675 | 2749 | arg->int_array.field = NULL; |
|---|
| 2676 | 2750 | out: |
|---|
| 2677 | 2751 | *tok = NULL; |
|---|
| 2678 | | - return EVENT_ERROR; |
|---|
| 2752 | + return TEP_EVENT_ERROR; |
|---|
| 2679 | 2753 | } |
|---|
| 2680 | 2754 | |
|---|
| 2681 | | -static enum event_type |
|---|
| 2682 | | -process_dynamic_array(struct event_format *event, struct print_arg *arg, char **tok) |
|---|
| 2755 | +static enum tep_event_type |
|---|
| 2756 | +process_dynamic_array(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
|---|
| 2683 | 2757 | { |
|---|
| 2684 | | - struct format_field *field; |
|---|
| 2685 | | - enum event_type type; |
|---|
| 2758 | + struct tep_format_field *field; |
|---|
| 2759 | + enum tep_event_type type; |
|---|
| 2686 | 2760 | char *token; |
|---|
| 2687 | 2761 | |
|---|
| 2688 | 2762 | memset(arg, 0, sizeof(*arg)); |
|---|
| 2689 | | - arg->type = PRINT_DYNAMIC_ARRAY; |
|---|
| 2763 | + arg->type = TEP_PRINT_DYNAMIC_ARRAY; |
|---|
| 2690 | 2764 | |
|---|
| 2691 | 2765 | /* |
|---|
| 2692 | 2766 | * The item within the parenthesis is another field that holds |
|---|
| .. | .. |
|---|
| 2694 | 2768 | */ |
|---|
| 2695 | 2769 | type = read_token(&token); |
|---|
| 2696 | 2770 | *tok = token; |
|---|
| 2697 | | - if (type != EVENT_ITEM) |
|---|
| 2771 | + if (type != TEP_EVENT_ITEM) |
|---|
| 2698 | 2772 | goto out_free; |
|---|
| 2699 | 2773 | |
|---|
| 2700 | 2774 | /* Find the field */ |
|---|
| .. | .. |
|---|
| 2706 | 2780 | arg->dynarray.field = field; |
|---|
| 2707 | 2781 | arg->dynarray.index = 0; |
|---|
| 2708 | 2782 | |
|---|
| 2709 | | - if (read_expected(EVENT_DELIM, ")") < 0) |
|---|
| 2783 | + if (read_expected(TEP_EVENT_DELIM, ")") < 0) |
|---|
| 2710 | 2784 | goto out_free; |
|---|
| 2711 | 2785 | |
|---|
| 2712 | 2786 | free_token(token); |
|---|
| 2713 | 2787 | type = read_token_item(&token); |
|---|
| 2714 | 2788 | *tok = token; |
|---|
| 2715 | | - if (type != EVENT_OP || strcmp(token, "[") != 0) |
|---|
| 2789 | + if (type != TEP_EVENT_OP || strcmp(token, "[") != 0) |
|---|
| 2716 | 2790 | return type; |
|---|
| 2717 | 2791 | |
|---|
| 2718 | 2792 | free_token(token); |
|---|
| .. | .. |
|---|
| 2720 | 2794 | if (!arg) { |
|---|
| 2721 | 2795 | do_warning_event(event, "%s: not enough memory!", __func__); |
|---|
| 2722 | 2796 | *tok = NULL; |
|---|
| 2723 | | - return EVENT_ERROR; |
|---|
| 2797 | + return TEP_EVENT_ERROR; |
|---|
| 2724 | 2798 | } |
|---|
| 2725 | 2799 | |
|---|
| 2726 | 2800 | type = process_arg(event, arg, &token); |
|---|
| 2727 | | - if (type == EVENT_ERROR) |
|---|
| 2801 | + if (type == TEP_EVENT_ERROR) |
|---|
| 2728 | 2802 | goto out_free_arg; |
|---|
| 2729 | 2803 | |
|---|
| 2730 | | - if (!test_type_token(type, token, EVENT_OP, "]")) |
|---|
| 2804 | + if (!test_type_token(type, token, TEP_EVENT_OP, "]")) |
|---|
| 2731 | 2805 | goto out_free_arg; |
|---|
| 2732 | 2806 | |
|---|
| 2733 | 2807 | free_token(token); |
|---|
| .. | .. |
|---|
| 2739 | 2813 | out_free: |
|---|
| 2740 | 2814 | free_token(token); |
|---|
| 2741 | 2815 | *tok = NULL; |
|---|
| 2742 | | - return EVENT_ERROR; |
|---|
| 2816 | + return TEP_EVENT_ERROR; |
|---|
| 2743 | 2817 | } |
|---|
| 2744 | 2818 | |
|---|
| 2745 | | -static enum event_type |
|---|
| 2746 | | -process_dynamic_array_len(struct event_format *event, struct print_arg *arg, |
|---|
| 2819 | +static enum tep_event_type |
|---|
| 2820 | +process_dynamic_array_len(struct tep_event *event, struct tep_print_arg *arg, |
|---|
| 2747 | 2821 | char **tok) |
|---|
| 2748 | 2822 | { |
|---|
| 2749 | | - struct format_field *field; |
|---|
| 2750 | | - enum event_type type; |
|---|
| 2823 | + struct tep_format_field *field; |
|---|
| 2824 | + enum tep_event_type type; |
|---|
| 2751 | 2825 | char *token; |
|---|
| 2752 | 2826 | |
|---|
| 2753 | | - if (read_expect_type(EVENT_ITEM, &token) < 0) |
|---|
| 2827 | + if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
|---|
| 2754 | 2828 | goto out_free; |
|---|
| 2755 | 2829 | |
|---|
| 2756 | | - arg->type = PRINT_DYNAMIC_ARRAY_LEN; |
|---|
| 2830 | + arg->type = TEP_PRINT_DYNAMIC_ARRAY_LEN; |
|---|
| 2757 | 2831 | |
|---|
| 2758 | 2832 | /* Find the field */ |
|---|
| 2759 | 2833 | field = tep_find_field(event, token); |
|---|
| .. | .. |
|---|
| 2763 | 2837 | arg->dynarray.field = field; |
|---|
| 2764 | 2838 | arg->dynarray.index = 0; |
|---|
| 2765 | 2839 | |
|---|
| 2766 | | - if (read_expected(EVENT_DELIM, ")") < 0) |
|---|
| 2840 | + if (read_expected(TEP_EVENT_DELIM, ")") < 0) |
|---|
| 2767 | 2841 | goto out_err; |
|---|
| 2768 | 2842 | |
|---|
| 2769 | 2843 | free_token(token); |
|---|
| .. | .. |
|---|
| 2776 | 2850 | free_token(token); |
|---|
| 2777 | 2851 | out_err: |
|---|
| 2778 | 2852 | *tok = NULL; |
|---|
| 2779 | | - return EVENT_ERROR; |
|---|
| 2853 | + return TEP_EVENT_ERROR; |
|---|
| 2780 | 2854 | } |
|---|
| 2781 | 2855 | |
|---|
| 2782 | | -static enum event_type |
|---|
| 2783 | | -process_paren(struct event_format *event, struct print_arg *arg, char **tok) |
|---|
| 2856 | +static enum tep_event_type |
|---|
| 2857 | +process_paren(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
|---|
| 2784 | 2858 | { |
|---|
| 2785 | | - struct print_arg *item_arg; |
|---|
| 2786 | | - enum event_type type; |
|---|
| 2859 | + struct tep_print_arg *item_arg; |
|---|
| 2860 | + enum tep_event_type type; |
|---|
| 2787 | 2861 | char *token; |
|---|
| 2788 | 2862 | |
|---|
| 2789 | 2863 | type = process_arg(event, arg, &token); |
|---|
| 2790 | 2864 | |
|---|
| 2791 | | - if (type == EVENT_ERROR) |
|---|
| 2865 | + if (type == TEP_EVENT_ERROR) |
|---|
| 2792 | 2866 | goto out_free; |
|---|
| 2793 | 2867 | |
|---|
| 2794 | | - if (type == EVENT_OP) |
|---|
| 2868 | + if (type == TEP_EVENT_OP) |
|---|
| 2795 | 2869 | type = process_op(event, arg, &token); |
|---|
| 2796 | 2870 | |
|---|
| 2797 | | - if (type == EVENT_ERROR) |
|---|
| 2871 | + if (type == TEP_EVENT_ERROR) |
|---|
| 2798 | 2872 | goto out_free; |
|---|
| 2799 | 2873 | |
|---|
| 2800 | | - if (test_type_token(type, token, EVENT_DELIM, ")")) |
|---|
| 2874 | + if (test_type_token(type, token, TEP_EVENT_DELIM, ")")) |
|---|
| 2801 | 2875 | goto out_free; |
|---|
| 2802 | 2876 | |
|---|
| 2803 | 2877 | free_token(token); |
|---|
| .. | .. |
|---|
| 2808 | 2882 | * this was a typecast. |
|---|
| 2809 | 2883 | */ |
|---|
| 2810 | 2884 | if (event_item_type(type) || |
|---|
| 2811 | | - (type == EVENT_DELIM && strcmp(token, "(") == 0)) { |
|---|
| 2885 | + (type == TEP_EVENT_DELIM && strcmp(token, "(") == 0)) { |
|---|
| 2812 | 2886 | |
|---|
| 2813 | 2887 | /* make this a typecast and contine */ |
|---|
| 2814 | 2888 | |
|---|
| 2815 | 2889 | /* prevous must be an atom */ |
|---|
| 2816 | | - if (arg->type != PRINT_ATOM) { |
|---|
| 2817 | | - do_warning_event(event, "previous needed to be PRINT_ATOM"); |
|---|
| 2890 | + if (arg->type != TEP_PRINT_ATOM) { |
|---|
| 2891 | + do_warning_event(event, "previous needed to be TEP_PRINT_ATOM"); |
|---|
| 2818 | 2892 | goto out_free; |
|---|
| 2819 | 2893 | } |
|---|
| 2820 | 2894 | |
|---|
| .. | .. |
|---|
| 2825 | 2899 | goto out_free; |
|---|
| 2826 | 2900 | } |
|---|
| 2827 | 2901 | |
|---|
| 2828 | | - arg->type = PRINT_TYPE; |
|---|
| 2902 | + arg->type = TEP_PRINT_TYPE; |
|---|
| 2829 | 2903 | arg->typecast.type = arg->atom.atom; |
|---|
| 2830 | 2904 | arg->typecast.item = item_arg; |
|---|
| 2831 | 2905 | type = process_arg_token(event, item_arg, &token, type); |
|---|
| .. | .. |
|---|
| 2838 | 2912 | out_free: |
|---|
| 2839 | 2913 | free_token(token); |
|---|
| 2840 | 2914 | *tok = NULL; |
|---|
| 2841 | | - return EVENT_ERROR; |
|---|
| 2915 | + return TEP_EVENT_ERROR; |
|---|
| 2842 | 2916 | } |
|---|
| 2843 | 2917 | |
|---|
| 2844 | 2918 | |
|---|
| 2845 | | -static enum event_type |
|---|
| 2846 | | -process_str(struct event_format *event __maybe_unused, struct print_arg *arg, |
|---|
| 2919 | +static enum tep_event_type |
|---|
| 2920 | +process_str(struct tep_event *event __maybe_unused, struct tep_print_arg *arg, |
|---|
| 2847 | 2921 | char **tok) |
|---|
| 2848 | 2922 | { |
|---|
| 2849 | | - enum event_type type; |
|---|
| 2923 | + enum tep_event_type type; |
|---|
| 2850 | 2924 | char *token; |
|---|
| 2851 | 2925 | |
|---|
| 2852 | | - if (read_expect_type(EVENT_ITEM, &token) < 0) |
|---|
| 2926 | + if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
|---|
| 2853 | 2927 | goto out_free; |
|---|
| 2854 | 2928 | |
|---|
| 2855 | | - arg->type = PRINT_STRING; |
|---|
| 2929 | + arg->type = TEP_PRINT_STRING; |
|---|
| 2856 | 2930 | arg->string.string = token; |
|---|
| 2857 | 2931 | arg->string.offset = -1; |
|---|
| 2858 | 2932 | |
|---|
| 2859 | | - if (read_expected(EVENT_DELIM, ")") < 0) |
|---|
| 2933 | + if (read_expected(TEP_EVENT_DELIM, ")") < 0) |
|---|
| 2860 | 2934 | goto out_err; |
|---|
| 2861 | 2935 | |
|---|
| 2862 | 2936 | type = read_token(&token); |
|---|
| .. | .. |
|---|
| 2868 | 2942 | free_token(token); |
|---|
| 2869 | 2943 | out_err: |
|---|
| 2870 | 2944 | *tok = NULL; |
|---|
| 2871 | | - return EVENT_ERROR; |
|---|
| 2945 | + return TEP_EVENT_ERROR; |
|---|
| 2872 | 2946 | } |
|---|
| 2873 | 2947 | |
|---|
| 2874 | | -static enum event_type |
|---|
| 2875 | | -process_bitmask(struct event_format *event __maybe_unused, struct print_arg *arg, |
|---|
| 2876 | | - char **tok) |
|---|
| 2948 | +static enum tep_event_type |
|---|
| 2949 | +process_bitmask(struct tep_event *event __maybe_unused, struct tep_print_arg *arg, |
|---|
| 2950 | + char **tok) |
|---|
| 2877 | 2951 | { |
|---|
| 2878 | | - enum event_type type; |
|---|
| 2952 | + enum tep_event_type type; |
|---|
| 2879 | 2953 | char *token; |
|---|
| 2880 | 2954 | |
|---|
| 2881 | | - if (read_expect_type(EVENT_ITEM, &token) < 0) |
|---|
| 2955 | + if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
|---|
| 2882 | 2956 | goto out_free; |
|---|
| 2883 | 2957 | |
|---|
| 2884 | | - arg->type = PRINT_BITMASK; |
|---|
| 2958 | + arg->type = TEP_PRINT_BITMASK; |
|---|
| 2885 | 2959 | arg->bitmask.bitmask = token; |
|---|
| 2886 | 2960 | arg->bitmask.offset = -1; |
|---|
| 2887 | 2961 | |
|---|
| 2888 | | - if (read_expected(EVENT_DELIM, ")") < 0) |
|---|
| 2962 | + if (read_expected(TEP_EVENT_DELIM, ")") < 0) |
|---|
| 2889 | 2963 | goto out_err; |
|---|
| 2890 | 2964 | |
|---|
| 2891 | 2965 | type = read_token(&token); |
|---|
| .. | .. |
|---|
| 2897 | 2971 | free_token(token); |
|---|
| 2898 | 2972 | out_err: |
|---|
| 2899 | 2973 | *tok = NULL; |
|---|
| 2900 | | - return EVENT_ERROR; |
|---|
| 2974 | + return TEP_EVENT_ERROR; |
|---|
| 2901 | 2975 | } |
|---|
| 2902 | 2976 | |
|---|
| 2903 | 2977 | static struct tep_function_handler * |
|---|
| 2904 | | -find_func_handler(struct tep_handle *pevent, char *func_name) |
|---|
| 2978 | +find_func_handler(struct tep_handle *tep, char *func_name) |
|---|
| 2905 | 2979 | { |
|---|
| 2906 | 2980 | struct tep_function_handler *func; |
|---|
| 2907 | 2981 | |
|---|
| 2908 | | - if (!pevent) |
|---|
| 2982 | + if (!tep) |
|---|
| 2909 | 2983 | return NULL; |
|---|
| 2910 | 2984 | |
|---|
| 2911 | | - for (func = pevent->func_handlers; func; func = func->next) { |
|---|
| 2985 | + for (func = tep->func_handlers; func; func = func->next) { |
|---|
| 2912 | 2986 | if (strcmp(func->name, func_name) == 0) |
|---|
| 2913 | 2987 | break; |
|---|
| 2914 | 2988 | } |
|---|
| .. | .. |
|---|
| 2916 | 2990 | return func; |
|---|
| 2917 | 2991 | } |
|---|
| 2918 | 2992 | |
|---|
| 2919 | | -static void remove_func_handler(struct tep_handle *pevent, char *func_name) |
|---|
| 2993 | +static void remove_func_handler(struct tep_handle *tep, char *func_name) |
|---|
| 2920 | 2994 | { |
|---|
| 2921 | 2995 | struct tep_function_handler *func; |
|---|
| 2922 | 2996 | struct tep_function_handler **next; |
|---|
| 2923 | 2997 | |
|---|
| 2924 | | - next = &pevent->func_handlers; |
|---|
| 2998 | + next = &tep->func_handlers; |
|---|
| 2925 | 2999 | while ((func = *next)) { |
|---|
| 2926 | 3000 | if (strcmp(func->name, func_name) == 0) { |
|---|
| 2927 | 3001 | *next = func->next; |
|---|
| .. | .. |
|---|
| 2932 | 3006 | } |
|---|
| 2933 | 3007 | } |
|---|
| 2934 | 3008 | |
|---|
| 2935 | | -static enum event_type |
|---|
| 2936 | | -process_func_handler(struct event_format *event, struct tep_function_handler *func, |
|---|
| 2937 | | - struct print_arg *arg, char **tok) |
|---|
| 3009 | +static enum tep_event_type |
|---|
| 3010 | +process_func_handler(struct tep_event *event, struct tep_function_handler *func, |
|---|
| 3011 | + struct tep_print_arg *arg, char **tok) |
|---|
| 2938 | 3012 | { |
|---|
| 2939 | | - struct print_arg **next_arg; |
|---|
| 2940 | | - struct print_arg *farg; |
|---|
| 2941 | | - enum event_type type; |
|---|
| 3013 | + struct tep_print_arg **next_arg; |
|---|
| 3014 | + struct tep_print_arg *farg; |
|---|
| 3015 | + enum tep_event_type type; |
|---|
| 2942 | 3016 | char *token; |
|---|
| 2943 | 3017 | int i; |
|---|
| 2944 | 3018 | |
|---|
| 2945 | | - arg->type = PRINT_FUNC; |
|---|
| 3019 | + arg->type = TEP_PRINT_FUNC; |
|---|
| 2946 | 3020 | arg->func.func = func; |
|---|
| 2947 | 3021 | |
|---|
| 2948 | 3022 | *tok = NULL; |
|---|
| .. | .. |
|---|
| 2953 | 3027 | if (!farg) { |
|---|
| 2954 | 3028 | do_warning_event(event, "%s: not enough memory!", |
|---|
| 2955 | 3029 | __func__); |
|---|
| 2956 | | - return EVENT_ERROR; |
|---|
| 3030 | + return TEP_EVENT_ERROR; |
|---|
| 2957 | 3031 | } |
|---|
| 2958 | 3032 | |
|---|
| 2959 | 3033 | type = process_arg(event, farg, &token); |
|---|
| 2960 | 3034 | if (i < (func->nr_args - 1)) { |
|---|
| 2961 | | - if (type != EVENT_DELIM || strcmp(token, ",") != 0) { |
|---|
| 3035 | + if (type != TEP_EVENT_DELIM || strcmp(token, ",") != 0) { |
|---|
| 2962 | 3036 | do_warning_event(event, |
|---|
| 2963 | 3037 | "Error: function '%s()' expects %d arguments but event %s only uses %d", |
|---|
| 2964 | 3038 | func->name, func->nr_args, |
|---|
| .. | .. |
|---|
| 2966 | 3040 | goto err; |
|---|
| 2967 | 3041 | } |
|---|
| 2968 | 3042 | } else { |
|---|
| 2969 | | - if (type != EVENT_DELIM || strcmp(token, ")") != 0) { |
|---|
| 3043 | + if (type != TEP_EVENT_DELIM || strcmp(token, ")") != 0) { |
|---|
| 2970 | 3044 | do_warning_event(event, |
|---|
| 2971 | 3045 | "Error: function '%s()' only expects %d arguments but event %s has more", |
|---|
| 2972 | 3046 | func->name, func->nr_args, event->name); |
|---|
| .. | .. |
|---|
| 2987 | 3061 | err: |
|---|
| 2988 | 3062 | free_arg(farg); |
|---|
| 2989 | 3063 | free_token(token); |
|---|
| 2990 | | - return EVENT_ERROR; |
|---|
| 3064 | + return TEP_EVENT_ERROR; |
|---|
| 2991 | 3065 | } |
|---|
| 2992 | 3066 | |
|---|
| 2993 | | -static enum event_type |
|---|
| 2994 | | -process_function(struct event_format *event, struct print_arg *arg, |
|---|
| 3067 | +static enum tep_event_type |
|---|
| 3068 | +process_builtin_expect(struct tep_event *event, struct tep_print_arg *arg, char **tok) |
|---|
| 3069 | +{ |
|---|
| 3070 | + enum tep_event_type type; |
|---|
| 3071 | + char *token = NULL; |
|---|
| 3072 | + |
|---|
| 3073 | + /* Handle __builtin_expect( cond, #) */ |
|---|
| 3074 | + type = process_arg(event, arg, &token); |
|---|
| 3075 | + |
|---|
| 3076 | + if (type != TEP_EVENT_DELIM || token[0] != ',') |
|---|
| 3077 | + goto out_free; |
|---|
| 3078 | + |
|---|
| 3079 | + free_token(token); |
|---|
| 3080 | + |
|---|
| 3081 | + /* We don't care what the second parameter is of the __builtin_expect() */ |
|---|
| 3082 | + if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
|---|
| 3083 | + goto out_free; |
|---|
| 3084 | + |
|---|
| 3085 | + if (read_expected(TEP_EVENT_DELIM, ")") < 0) |
|---|
| 3086 | + goto out_free; |
|---|
| 3087 | + |
|---|
| 3088 | + free_token(token); |
|---|
| 3089 | + type = read_token_item(tok); |
|---|
| 3090 | + return type; |
|---|
| 3091 | + |
|---|
| 3092 | +out_free: |
|---|
| 3093 | + free_token(token); |
|---|
| 3094 | + *tok = NULL; |
|---|
| 3095 | + return TEP_EVENT_ERROR; |
|---|
| 3096 | +} |
|---|
| 3097 | + |
|---|
| 3098 | +static enum tep_event_type |
|---|
| 3099 | +process_function(struct tep_event *event, struct tep_print_arg *arg, |
|---|
| 2995 | 3100 | char *token, char **tok) |
|---|
| 2996 | 3101 | { |
|---|
| 2997 | 3102 | struct tep_function_handler *func; |
|---|
| .. | .. |
|---|
| 3034 | 3139 | free_token(token); |
|---|
| 3035 | 3140 | return process_dynamic_array_len(event, arg, tok); |
|---|
| 3036 | 3141 | } |
|---|
| 3142 | + if (strcmp(token, "__builtin_expect") == 0) { |
|---|
| 3143 | + free_token(token); |
|---|
| 3144 | + return process_builtin_expect(event, arg, tok); |
|---|
| 3145 | + } |
|---|
| 3037 | 3146 | |
|---|
| 3038 | | - func = find_func_handler(event->pevent, token); |
|---|
| 3147 | + func = find_func_handler(event->tep, token); |
|---|
| 3039 | 3148 | if (func) { |
|---|
| 3040 | 3149 | free_token(token); |
|---|
| 3041 | 3150 | return process_func_handler(event, func, arg, tok); |
|---|
| .. | .. |
|---|
| 3043 | 3152 | |
|---|
| 3044 | 3153 | do_warning_event(event, "function %s not defined", token); |
|---|
| 3045 | 3154 | free_token(token); |
|---|
| 3046 | | - return EVENT_ERROR; |
|---|
| 3155 | + return TEP_EVENT_ERROR; |
|---|
| 3047 | 3156 | } |
|---|
| 3048 | 3157 | |
|---|
| 3049 | | -static enum event_type |
|---|
| 3050 | | -process_arg_token(struct event_format *event, struct print_arg *arg, |
|---|
| 3051 | | - char **tok, enum event_type type) |
|---|
| 3158 | +static enum tep_event_type |
|---|
| 3159 | +process_arg_token(struct tep_event *event, struct tep_print_arg *arg, |
|---|
| 3160 | + char **tok, enum tep_event_type type) |
|---|
| 3052 | 3161 | { |
|---|
| 3053 | 3162 | char *token; |
|---|
| 3054 | 3163 | char *atom; |
|---|
| .. | .. |
|---|
| 3056 | 3165 | token = *tok; |
|---|
| 3057 | 3166 | |
|---|
| 3058 | 3167 | switch (type) { |
|---|
| 3059 | | - case EVENT_ITEM: |
|---|
| 3168 | + case TEP_EVENT_ITEM: |
|---|
| 3060 | 3169 | if (strcmp(token, "REC") == 0) { |
|---|
| 3061 | 3170 | free_token(token); |
|---|
| 3062 | 3171 | type = process_entry(event, arg, &token); |
|---|
| .. | .. |
|---|
| 3070 | 3179 | * If the next token is a parenthesis, then this |
|---|
| 3071 | 3180 | * is a function. |
|---|
| 3072 | 3181 | */ |
|---|
| 3073 | | - if (type == EVENT_DELIM && strcmp(token, "(") == 0) { |
|---|
| 3182 | + if (type == TEP_EVENT_DELIM && strcmp(token, "(") == 0) { |
|---|
| 3074 | 3183 | free_token(token); |
|---|
| 3075 | 3184 | token = NULL; |
|---|
| 3076 | 3185 | /* this will free atom. */ |
|---|
| .. | .. |
|---|
| 3078 | 3187 | break; |
|---|
| 3079 | 3188 | } |
|---|
| 3080 | 3189 | /* atoms can be more than one token long */ |
|---|
| 3081 | | - while (type == EVENT_ITEM) { |
|---|
| 3082 | | - char *new_atom; |
|---|
| 3083 | | - new_atom = realloc(atom, |
|---|
| 3084 | | - strlen(atom) + strlen(token) + 2); |
|---|
| 3085 | | - if (!new_atom) { |
|---|
| 3190 | + while (type == TEP_EVENT_ITEM) { |
|---|
| 3191 | + int ret; |
|---|
| 3192 | + |
|---|
| 3193 | + ret = append(&atom, " ", token); |
|---|
| 3194 | + if (ret < 0) { |
|---|
| 3086 | 3195 | free(atom); |
|---|
| 3087 | 3196 | *tok = NULL; |
|---|
| 3088 | 3197 | free_token(token); |
|---|
| 3089 | | - return EVENT_ERROR; |
|---|
| 3198 | + return TEP_EVENT_ERROR; |
|---|
| 3090 | 3199 | } |
|---|
| 3091 | | - atom = new_atom; |
|---|
| 3092 | | - strcat(atom, " "); |
|---|
| 3093 | | - strcat(atom, token); |
|---|
| 3094 | 3200 | free_token(token); |
|---|
| 3095 | 3201 | type = read_token_item(&token); |
|---|
| 3096 | 3202 | } |
|---|
| 3097 | 3203 | |
|---|
| 3098 | | - arg->type = PRINT_ATOM; |
|---|
| 3204 | + arg->type = TEP_PRINT_ATOM; |
|---|
| 3099 | 3205 | arg->atom.atom = atom; |
|---|
| 3100 | 3206 | break; |
|---|
| 3101 | 3207 | |
|---|
| 3102 | | - case EVENT_DQUOTE: |
|---|
| 3103 | | - case EVENT_SQUOTE: |
|---|
| 3104 | | - arg->type = PRINT_ATOM; |
|---|
| 3208 | + case TEP_EVENT_DQUOTE: |
|---|
| 3209 | + case TEP_EVENT_SQUOTE: |
|---|
| 3210 | + arg->type = TEP_PRINT_ATOM; |
|---|
| 3105 | 3211 | arg->atom.atom = token; |
|---|
| 3106 | 3212 | type = read_token_item(&token); |
|---|
| 3107 | 3213 | break; |
|---|
| 3108 | | - case EVENT_DELIM: |
|---|
| 3214 | + case TEP_EVENT_DELIM: |
|---|
| 3109 | 3215 | if (strcmp(token, "(") == 0) { |
|---|
| 3110 | 3216 | free_token(token); |
|---|
| 3111 | 3217 | type = process_paren(event, arg, &token); |
|---|
| 3112 | 3218 | break; |
|---|
| 3113 | 3219 | } |
|---|
| 3114 | | - case EVENT_OP: |
|---|
| 3220 | + case TEP_EVENT_OP: |
|---|
| 3115 | 3221 | /* handle single ops */ |
|---|
| 3116 | | - arg->type = PRINT_OP; |
|---|
| 3222 | + arg->type = TEP_PRINT_OP; |
|---|
| 3117 | 3223 | arg->op.op = token; |
|---|
| 3118 | 3224 | arg->op.left = NULL; |
|---|
| 3119 | 3225 | type = process_op(event, arg, &token); |
|---|
| 3120 | 3226 | |
|---|
| 3121 | 3227 | /* On error, the op is freed */ |
|---|
| 3122 | | - if (type == EVENT_ERROR) |
|---|
| 3228 | + if (type == TEP_EVENT_ERROR) |
|---|
| 3123 | 3229 | arg->op.op = NULL; |
|---|
| 3124 | 3230 | |
|---|
| 3125 | 3231 | /* return error type if errored */ |
|---|
| 3126 | 3232 | break; |
|---|
| 3127 | 3233 | |
|---|
| 3128 | | - case EVENT_ERROR ... EVENT_NEWLINE: |
|---|
| 3234 | + case TEP_EVENT_ERROR ... TEP_EVENT_NEWLINE: |
|---|
| 3129 | 3235 | default: |
|---|
| 3130 | 3236 | do_warning_event(event, "unexpected type %d", type); |
|---|
| 3131 | | - return EVENT_ERROR; |
|---|
| 3237 | + return TEP_EVENT_ERROR; |
|---|
| 3132 | 3238 | } |
|---|
| 3133 | 3239 | *tok = token; |
|---|
| 3134 | 3240 | |
|---|
| 3135 | 3241 | return type; |
|---|
| 3136 | 3242 | } |
|---|
| 3137 | 3243 | |
|---|
| 3138 | | -static int event_read_print_args(struct event_format *event, struct print_arg **list) |
|---|
| 3244 | +static int event_read_print_args(struct tep_event *event, struct tep_print_arg **list) |
|---|
| 3139 | 3245 | { |
|---|
| 3140 | | - enum event_type type = EVENT_ERROR; |
|---|
| 3141 | | - struct print_arg *arg; |
|---|
| 3246 | + enum tep_event_type type = TEP_EVENT_ERROR; |
|---|
| 3247 | + struct tep_print_arg *arg; |
|---|
| 3142 | 3248 | char *token; |
|---|
| 3143 | 3249 | int args = 0; |
|---|
| 3144 | 3250 | |
|---|
| 3145 | 3251 | do { |
|---|
| 3146 | | - if (type == EVENT_NEWLINE) { |
|---|
| 3252 | + if (type == TEP_EVENT_NEWLINE) { |
|---|
| 3147 | 3253 | type = read_token_item(&token); |
|---|
| 3148 | 3254 | continue; |
|---|
| 3149 | 3255 | } |
|---|
| .. | .. |
|---|
| 3157 | 3263 | |
|---|
| 3158 | 3264 | type = process_arg(event, arg, &token); |
|---|
| 3159 | 3265 | |
|---|
| 3160 | | - if (type == EVENT_ERROR) { |
|---|
| 3266 | + if (type == TEP_EVENT_ERROR) { |
|---|
| 3161 | 3267 | free_token(token); |
|---|
| 3162 | 3268 | free_arg(arg); |
|---|
| 3163 | 3269 | return -1; |
|---|
| .. | .. |
|---|
| 3166 | 3272 | *list = arg; |
|---|
| 3167 | 3273 | args++; |
|---|
| 3168 | 3274 | |
|---|
| 3169 | | - if (type == EVENT_OP) { |
|---|
| 3275 | + if (type == TEP_EVENT_OP) { |
|---|
| 3170 | 3276 | type = process_op(event, arg, &token); |
|---|
| 3171 | 3277 | free_token(token); |
|---|
| 3172 | | - if (type == EVENT_ERROR) { |
|---|
| 3278 | + if (type == TEP_EVENT_ERROR) { |
|---|
| 3173 | 3279 | *list = NULL; |
|---|
| 3174 | 3280 | free_arg(arg); |
|---|
| 3175 | 3281 | return -1; |
|---|
| .. | .. |
|---|
| 3178 | 3284 | continue; |
|---|
| 3179 | 3285 | } |
|---|
| 3180 | 3286 | |
|---|
| 3181 | | - if (type == EVENT_DELIM && strcmp(token, ",") == 0) { |
|---|
| 3287 | + if (type == TEP_EVENT_DELIM && strcmp(token, ",") == 0) { |
|---|
| 3182 | 3288 | free_token(token); |
|---|
| 3183 | 3289 | *list = arg; |
|---|
| 3184 | 3290 | list = &arg->next; |
|---|
| 3185 | 3291 | continue; |
|---|
| 3186 | 3292 | } |
|---|
| 3187 | 3293 | break; |
|---|
| 3188 | | - } while (type != EVENT_NONE); |
|---|
| 3294 | + } while (type != TEP_EVENT_NONE); |
|---|
| 3189 | 3295 | |
|---|
| 3190 | | - if (type != EVENT_NONE && type != EVENT_ERROR) |
|---|
| 3296 | + if (type != TEP_EVENT_NONE && type != TEP_EVENT_ERROR) |
|---|
| 3191 | 3297 | free_token(token); |
|---|
| 3192 | 3298 | |
|---|
| 3193 | 3299 | return args; |
|---|
| 3194 | 3300 | } |
|---|
| 3195 | 3301 | |
|---|
| 3196 | | -static int event_read_print(struct event_format *event) |
|---|
| 3302 | +static int event_read_print(struct tep_event *event) |
|---|
| 3197 | 3303 | { |
|---|
| 3198 | | - enum event_type type; |
|---|
| 3304 | + enum tep_event_type type; |
|---|
| 3199 | 3305 | char *token; |
|---|
| 3200 | 3306 | int ret; |
|---|
| 3201 | 3307 | |
|---|
| 3202 | | - if (read_expected_item(EVENT_ITEM, "print") < 0) |
|---|
| 3308 | + if (read_expected_item(TEP_EVENT_ITEM, "print") < 0) |
|---|
| 3203 | 3309 | return -1; |
|---|
| 3204 | 3310 | |
|---|
| 3205 | | - if (read_expected(EVENT_ITEM, "fmt") < 0) |
|---|
| 3311 | + if (read_expected(TEP_EVENT_ITEM, "fmt") < 0) |
|---|
| 3206 | 3312 | return -1; |
|---|
| 3207 | 3313 | |
|---|
| 3208 | | - if (read_expected(EVENT_OP, ":") < 0) |
|---|
| 3314 | + if (read_expected(TEP_EVENT_OP, ":") < 0) |
|---|
| 3209 | 3315 | return -1; |
|---|
| 3210 | 3316 | |
|---|
| 3211 | | - if (read_expect_type(EVENT_DQUOTE, &token) < 0) |
|---|
| 3317 | + if (read_expect_type(TEP_EVENT_DQUOTE, &token) < 0) |
|---|
| 3212 | 3318 | goto fail; |
|---|
| 3213 | 3319 | |
|---|
| 3214 | 3320 | concat: |
|---|
| .. | .. |
|---|
| 3218 | 3324 | /* ok to have no arg */ |
|---|
| 3219 | 3325 | type = read_token_item(&token); |
|---|
| 3220 | 3326 | |
|---|
| 3221 | | - if (type == EVENT_NONE) |
|---|
| 3327 | + if (type == TEP_EVENT_NONE) |
|---|
| 3222 | 3328 | return 0; |
|---|
| 3223 | 3329 | |
|---|
| 3224 | 3330 | /* Handle concatenation of print lines */ |
|---|
| 3225 | | - if (type == EVENT_DQUOTE) { |
|---|
| 3331 | + if (type == TEP_EVENT_DQUOTE) { |
|---|
| 3226 | 3332 | char *cat; |
|---|
| 3227 | 3333 | |
|---|
| 3228 | 3334 | if (asprintf(&cat, "%s%s", event->print_fmt.format, token) < 0) |
|---|
| .. | .. |
|---|
| 3234 | 3340 | goto concat; |
|---|
| 3235 | 3341 | } |
|---|
| 3236 | 3342 | |
|---|
| 3237 | | - if (test_type_token(type, token, EVENT_DELIM, ",")) |
|---|
| 3343 | + if (test_type_token(type, token, TEP_EVENT_DELIM, ",")) |
|---|
| 3238 | 3344 | goto fail; |
|---|
| 3239 | 3345 | |
|---|
| 3240 | 3346 | free_token(token); |
|---|
| .. | .. |
|---|
| 3256 | 3362 | * @name: the name of the common field to return |
|---|
| 3257 | 3363 | * |
|---|
| 3258 | 3364 | * Returns a common field from the event by the given @name. |
|---|
| 3259 | | - * This only searchs the common fields and not all field. |
|---|
| 3365 | + * This only searches the common fields and not all field. |
|---|
| 3260 | 3366 | */ |
|---|
| 3261 | | -struct format_field * |
|---|
| 3262 | | -tep_find_common_field(struct event_format *event, const char *name) |
|---|
| 3367 | +struct tep_format_field * |
|---|
| 3368 | +tep_find_common_field(struct tep_event *event, const char *name) |
|---|
| 3263 | 3369 | { |
|---|
| 3264 | | - struct format_field *format; |
|---|
| 3370 | + struct tep_format_field *format; |
|---|
| 3265 | 3371 | |
|---|
| 3266 | 3372 | for (format = event->format.common_fields; |
|---|
| 3267 | 3373 | format; format = format->next) { |
|---|
| .. | .. |
|---|
| 3280 | 3386 | * Returns a non-common field by the given @name. |
|---|
| 3281 | 3387 | * This does not search common fields. |
|---|
| 3282 | 3388 | */ |
|---|
| 3283 | | -struct format_field * |
|---|
| 3284 | | -tep_find_field(struct event_format *event, const char *name) |
|---|
| 3389 | +struct tep_format_field * |
|---|
| 3390 | +tep_find_field(struct tep_event *event, const char *name) |
|---|
| 3285 | 3391 | { |
|---|
| 3286 | | - struct format_field *format; |
|---|
| 3392 | + struct tep_format_field *format; |
|---|
| 3287 | 3393 | |
|---|
| 3288 | 3394 | for (format = event->format.fields; |
|---|
| 3289 | 3395 | format; format = format->next) { |
|---|
| .. | .. |
|---|
| 3300 | 3406 | * @name: the name of the field |
|---|
| 3301 | 3407 | * |
|---|
| 3302 | 3408 | * Returns a field by the given @name. |
|---|
| 3303 | | - * This searchs the common field names first, then |
|---|
| 3409 | + * This searches the common field names first, then |
|---|
| 3304 | 3410 | * the non-common ones if a common one was not found. |
|---|
| 3305 | 3411 | */ |
|---|
| 3306 | | -struct format_field * |
|---|
| 3307 | | -tep_find_any_field(struct event_format *event, const char *name) |
|---|
| 3412 | +struct tep_format_field * |
|---|
| 3413 | +tep_find_any_field(struct tep_event *event, const char *name) |
|---|
| 3308 | 3414 | { |
|---|
| 3309 | | - struct format_field *format; |
|---|
| 3415 | + struct tep_format_field *format; |
|---|
| 3310 | 3416 | |
|---|
| 3311 | 3417 | format = tep_find_common_field(event, name); |
|---|
| 3312 | 3418 | if (format) |
|---|
| .. | .. |
|---|
| 3316 | 3422 | |
|---|
| 3317 | 3423 | /** |
|---|
| 3318 | 3424 | * tep_read_number - read a number from data |
|---|
| 3319 | | - * @pevent: handle for the pevent |
|---|
| 3425 | + * @tep: a handle to the trace event parser context |
|---|
| 3320 | 3426 | * @ptr: the raw data |
|---|
| 3321 | 3427 | * @size: the size of the data that holds the number |
|---|
| 3322 | 3428 | * |
|---|
| 3323 | 3429 | * Returns the number (converted to host) from the |
|---|
| 3324 | 3430 | * raw data. |
|---|
| 3325 | 3431 | */ |
|---|
| 3326 | | -unsigned long long tep_read_number(struct tep_handle *pevent, |
|---|
| 3432 | +unsigned long long tep_read_number(struct tep_handle *tep, |
|---|
| 3327 | 3433 | const void *ptr, int size) |
|---|
| 3328 | 3434 | { |
|---|
| 3435 | + unsigned long long val; |
|---|
| 3436 | + |
|---|
| 3329 | 3437 | switch (size) { |
|---|
| 3330 | 3438 | case 1: |
|---|
| 3331 | 3439 | return *(unsigned char *)ptr; |
|---|
| 3332 | 3440 | case 2: |
|---|
| 3333 | | - return data2host2(pevent, ptr); |
|---|
| 3441 | + return data2host2(tep, *(unsigned short *)ptr); |
|---|
| 3334 | 3442 | case 4: |
|---|
| 3335 | | - return data2host4(pevent, ptr); |
|---|
| 3443 | + return data2host4(tep, *(unsigned int *)ptr); |
|---|
| 3336 | 3444 | case 8: |
|---|
| 3337 | | - return data2host8(pevent, ptr); |
|---|
| 3445 | + memcpy(&val, (ptr), sizeof(unsigned long long)); |
|---|
| 3446 | + return data2host8(tep, val); |
|---|
| 3338 | 3447 | default: |
|---|
| 3339 | 3448 | /* BUG! */ |
|---|
| 3340 | 3449 | return 0; |
|---|
| .. | .. |
|---|
| 3352 | 3461 | * |
|---|
| 3353 | 3462 | * Returns 0 on success, -1 otherwise. |
|---|
| 3354 | 3463 | */ |
|---|
| 3355 | | -int tep_read_number_field(struct format_field *field, const void *data, |
|---|
| 3464 | +int tep_read_number_field(struct tep_format_field *field, const void *data, |
|---|
| 3356 | 3465 | unsigned long long *value) |
|---|
| 3357 | 3466 | { |
|---|
| 3358 | 3467 | if (!field) |
|---|
| .. | .. |
|---|
| 3362 | 3471 | case 2: |
|---|
| 3363 | 3472 | case 4: |
|---|
| 3364 | 3473 | case 8: |
|---|
| 3365 | | - *value = tep_read_number(field->event->pevent, |
|---|
| 3474 | + *value = tep_read_number(field->event->tep, |
|---|
| 3366 | 3475 | data + field->offset, field->size); |
|---|
| 3367 | 3476 | return 0; |
|---|
| 3368 | 3477 | default: |
|---|
| .. | .. |
|---|
| 3370 | 3479 | } |
|---|
| 3371 | 3480 | } |
|---|
| 3372 | 3481 | |
|---|
| 3373 | | -static int get_common_info(struct tep_handle *pevent, |
|---|
| 3482 | +static int get_common_info(struct tep_handle *tep, |
|---|
| 3374 | 3483 | const char *type, int *offset, int *size) |
|---|
| 3375 | 3484 | { |
|---|
| 3376 | | - struct event_format *event; |
|---|
| 3377 | | - struct format_field *field; |
|---|
| 3485 | + struct tep_event *event; |
|---|
| 3486 | + struct tep_format_field *field; |
|---|
| 3378 | 3487 | |
|---|
| 3379 | 3488 | /* |
|---|
| 3380 | 3489 | * All events should have the same common elements. |
|---|
| 3381 | 3490 | * Pick any event to find where the type is; |
|---|
| 3382 | 3491 | */ |
|---|
| 3383 | | - if (!pevent->events) { |
|---|
| 3492 | + if (!tep->events) { |
|---|
| 3384 | 3493 | do_warning("no event_list!"); |
|---|
| 3385 | 3494 | return -1; |
|---|
| 3386 | 3495 | } |
|---|
| 3387 | 3496 | |
|---|
| 3388 | | - event = pevent->events[0]; |
|---|
| 3497 | + event = tep->events[0]; |
|---|
| 3389 | 3498 | field = tep_find_common_field(event, type); |
|---|
| 3390 | 3499 | if (!field) |
|---|
| 3391 | 3500 | return -1; |
|---|
| .. | .. |
|---|
| 3396 | 3505 | return 0; |
|---|
| 3397 | 3506 | } |
|---|
| 3398 | 3507 | |
|---|
| 3399 | | -static int __parse_common(struct tep_handle *pevent, void *data, |
|---|
| 3508 | +static int __parse_common(struct tep_handle *tep, void *data, |
|---|
| 3400 | 3509 | int *size, int *offset, const char *name) |
|---|
| 3401 | 3510 | { |
|---|
| 3402 | 3511 | int ret; |
|---|
| 3403 | 3512 | |
|---|
| 3404 | 3513 | if (!*size) { |
|---|
| 3405 | | - ret = get_common_info(pevent, name, offset, size); |
|---|
| 3514 | + ret = get_common_info(tep, name, offset, size); |
|---|
| 3406 | 3515 | if (ret < 0) |
|---|
| 3407 | 3516 | return ret; |
|---|
| 3408 | 3517 | } |
|---|
| 3409 | | - return tep_read_number(pevent, data + *offset, *size); |
|---|
| 3518 | + return tep_read_number(tep, data + *offset, *size); |
|---|
| 3410 | 3519 | } |
|---|
| 3411 | 3520 | |
|---|
| 3412 | | -static int trace_parse_common_type(struct tep_handle *pevent, void *data) |
|---|
| 3521 | +static int trace_parse_common_type(struct tep_handle *tep, void *data) |
|---|
| 3413 | 3522 | { |
|---|
| 3414 | | - return __parse_common(pevent, data, |
|---|
| 3415 | | - &pevent->type_size, &pevent->type_offset, |
|---|
| 3523 | + return __parse_common(tep, data, |
|---|
| 3524 | + &tep->type_size, &tep->type_offset, |
|---|
| 3416 | 3525 | "common_type"); |
|---|
| 3417 | 3526 | } |
|---|
| 3418 | 3527 | |
|---|
| 3419 | | -static int parse_common_pid(struct tep_handle *pevent, void *data) |
|---|
| 3528 | +static int parse_common_pid(struct tep_handle *tep, void *data) |
|---|
| 3420 | 3529 | { |
|---|
| 3421 | | - return __parse_common(pevent, data, |
|---|
| 3422 | | - &pevent->pid_size, &pevent->pid_offset, |
|---|
| 3530 | + return __parse_common(tep, data, |
|---|
| 3531 | + &tep->pid_size, &tep->pid_offset, |
|---|
| 3423 | 3532 | "common_pid"); |
|---|
| 3424 | 3533 | } |
|---|
| 3425 | 3534 | |
|---|
| 3426 | | -static int parse_common_pc(struct tep_handle *pevent, void *data) |
|---|
| 3535 | +static int parse_common_pc(struct tep_handle *tep, void *data) |
|---|
| 3427 | 3536 | { |
|---|
| 3428 | | - return __parse_common(pevent, data, |
|---|
| 3429 | | - &pevent->pc_size, &pevent->pc_offset, |
|---|
| 3537 | + return __parse_common(tep, data, |
|---|
| 3538 | + &tep->pc_size, &tep->pc_offset, |
|---|
| 3430 | 3539 | "common_preempt_count"); |
|---|
| 3431 | 3540 | } |
|---|
| 3432 | 3541 | |
|---|
| 3433 | | -static int parse_common_flags(struct tep_handle *pevent, void *data) |
|---|
| 3542 | +static int parse_common_flags(struct tep_handle *tep, void *data) |
|---|
| 3434 | 3543 | { |
|---|
| 3435 | | - return __parse_common(pevent, data, |
|---|
| 3436 | | - &pevent->flags_size, &pevent->flags_offset, |
|---|
| 3544 | + return __parse_common(tep, data, |
|---|
| 3545 | + &tep->flags_size, &tep->flags_offset, |
|---|
| 3437 | 3546 | "common_flags"); |
|---|
| 3438 | 3547 | } |
|---|
| 3439 | 3548 | |
|---|
| 3440 | | -static int parse_common_lock_depth(struct tep_handle *pevent, void *data) |
|---|
| 3549 | +static int parse_common_lock_depth(struct tep_handle *tep, void *data) |
|---|
| 3441 | 3550 | { |
|---|
| 3442 | | - return __parse_common(pevent, data, |
|---|
| 3443 | | - &pevent->ld_size, &pevent->ld_offset, |
|---|
| 3551 | + return __parse_common(tep, data, |
|---|
| 3552 | + &tep->ld_size, &tep->ld_offset, |
|---|
| 3444 | 3553 | "common_lock_depth"); |
|---|
| 3445 | 3554 | } |
|---|
| 3446 | 3555 | |
|---|
| 3447 | | -static int parse_common_migrate_disable(struct tep_handle *pevent, void *data) |
|---|
| 3556 | +static int parse_common_migrate_disable(struct tep_handle *tep, void *data) |
|---|
| 3448 | 3557 | { |
|---|
| 3449 | | - return __parse_common(pevent, data, |
|---|
| 3450 | | - &pevent->ld_size, &pevent->ld_offset, |
|---|
| 3558 | + return __parse_common(tep, data, |
|---|
| 3559 | + &tep->ld_size, &tep->ld_offset, |
|---|
| 3451 | 3560 | "common_migrate_disable"); |
|---|
| 3452 | 3561 | } |
|---|
| 3453 | 3562 | |
|---|
| .. | .. |
|---|
| 3455 | 3564 | |
|---|
| 3456 | 3565 | /** |
|---|
| 3457 | 3566 | * tep_find_event - find an event by given id |
|---|
| 3458 | | - * @pevent: a handle to the pevent |
|---|
| 3567 | + * @tep: a handle to the trace event parser context |
|---|
| 3459 | 3568 | * @id: the id of the event |
|---|
| 3460 | 3569 | * |
|---|
| 3461 | 3570 | * Returns an event that has a given @id. |
|---|
| 3462 | 3571 | */ |
|---|
| 3463 | | -struct event_format *tep_find_event(struct tep_handle *pevent, int id) |
|---|
| 3572 | +struct tep_event *tep_find_event(struct tep_handle *tep, int id) |
|---|
| 3464 | 3573 | { |
|---|
| 3465 | | - struct event_format **eventptr; |
|---|
| 3466 | | - struct event_format key; |
|---|
| 3467 | | - struct event_format *pkey = &key; |
|---|
| 3574 | + struct tep_event **eventptr; |
|---|
| 3575 | + struct tep_event key; |
|---|
| 3576 | + struct tep_event *pkey = &key; |
|---|
| 3468 | 3577 | |
|---|
| 3469 | 3578 | /* Check cache first */ |
|---|
| 3470 | | - if (pevent->last_event && pevent->last_event->id == id) |
|---|
| 3471 | | - return pevent->last_event; |
|---|
| 3579 | + if (tep->last_event && tep->last_event->id == id) |
|---|
| 3580 | + return tep->last_event; |
|---|
| 3472 | 3581 | |
|---|
| 3473 | 3582 | key.id = id; |
|---|
| 3474 | 3583 | |
|---|
| 3475 | | - eventptr = bsearch(&pkey, pevent->events, pevent->nr_events, |
|---|
| 3476 | | - sizeof(*pevent->events), events_id_cmp); |
|---|
| 3584 | + eventptr = bsearch(&pkey, tep->events, tep->nr_events, |
|---|
| 3585 | + sizeof(*tep->events), events_id_cmp); |
|---|
| 3477 | 3586 | |
|---|
| 3478 | 3587 | if (eventptr) { |
|---|
| 3479 | | - pevent->last_event = *eventptr; |
|---|
| 3588 | + tep->last_event = *eventptr; |
|---|
| 3480 | 3589 | return *eventptr; |
|---|
| 3481 | 3590 | } |
|---|
| 3482 | 3591 | |
|---|
| .. | .. |
|---|
| 3485 | 3594 | |
|---|
| 3486 | 3595 | /** |
|---|
| 3487 | 3596 | * tep_find_event_by_name - find an event by given name |
|---|
| 3488 | | - * @pevent: a handle to the pevent |
|---|
| 3597 | + * @tep: a handle to the trace event parser context |
|---|
| 3489 | 3598 | * @sys: the system name to search for |
|---|
| 3490 | 3599 | * @name: the name of the event to search for |
|---|
| 3491 | 3600 | * |
|---|
| 3492 | 3601 | * This returns an event with a given @name and under the system |
|---|
| 3493 | 3602 | * @sys. If @sys is NULL the first event with @name is returned. |
|---|
| 3494 | 3603 | */ |
|---|
| 3495 | | -struct event_format * |
|---|
| 3496 | | -tep_find_event_by_name(struct tep_handle *pevent, |
|---|
| 3604 | +struct tep_event * |
|---|
| 3605 | +tep_find_event_by_name(struct tep_handle *tep, |
|---|
| 3497 | 3606 | const char *sys, const char *name) |
|---|
| 3498 | 3607 | { |
|---|
| 3499 | | - struct event_format *event; |
|---|
| 3608 | + struct tep_event *event = NULL; |
|---|
| 3500 | 3609 | int i; |
|---|
| 3501 | 3610 | |
|---|
| 3502 | | - if (pevent->last_event && |
|---|
| 3503 | | - strcmp(pevent->last_event->name, name) == 0 && |
|---|
| 3504 | | - (!sys || strcmp(pevent->last_event->system, sys) == 0)) |
|---|
| 3505 | | - return pevent->last_event; |
|---|
| 3611 | + if (tep->last_event && |
|---|
| 3612 | + strcmp(tep->last_event->name, name) == 0 && |
|---|
| 3613 | + (!sys || strcmp(tep->last_event->system, sys) == 0)) |
|---|
| 3614 | + return tep->last_event; |
|---|
| 3506 | 3615 | |
|---|
| 3507 | | - for (i = 0; i < pevent->nr_events; i++) { |
|---|
| 3508 | | - event = pevent->events[i]; |
|---|
| 3616 | + for (i = 0; i < tep->nr_events; i++) { |
|---|
| 3617 | + event = tep->events[i]; |
|---|
| 3509 | 3618 | if (strcmp(event->name, name) == 0) { |
|---|
| 3510 | 3619 | if (!sys) |
|---|
| 3511 | 3620 | break; |
|---|
| .. | .. |
|---|
| 3513 | 3622 | break; |
|---|
| 3514 | 3623 | } |
|---|
| 3515 | 3624 | } |
|---|
| 3516 | | - if (i == pevent->nr_events) |
|---|
| 3625 | + if (i == tep->nr_events) |
|---|
| 3517 | 3626 | event = NULL; |
|---|
| 3518 | 3627 | |
|---|
| 3519 | | - pevent->last_event = event; |
|---|
| 3628 | + tep->last_event = event; |
|---|
| 3520 | 3629 | return event; |
|---|
| 3521 | 3630 | } |
|---|
| 3522 | 3631 | |
|---|
| 3523 | 3632 | static unsigned long long |
|---|
| 3524 | | -eval_num_arg(void *data, int size, struct event_format *event, struct print_arg *arg) |
|---|
| 3633 | +eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg *arg) |
|---|
| 3525 | 3634 | { |
|---|
| 3526 | | - struct tep_handle *pevent = event->pevent; |
|---|
| 3635 | + struct tep_handle *tep = event->tep; |
|---|
| 3527 | 3636 | unsigned long long val = 0; |
|---|
| 3528 | 3637 | unsigned long long left, right; |
|---|
| 3529 | | - struct print_arg *typearg = NULL; |
|---|
| 3530 | | - struct print_arg *larg; |
|---|
| 3638 | + struct tep_print_arg *typearg = NULL; |
|---|
| 3639 | + struct tep_print_arg *larg; |
|---|
| 3531 | 3640 | unsigned long offset; |
|---|
| 3532 | 3641 | unsigned int field_size; |
|---|
| 3533 | 3642 | |
|---|
| 3534 | 3643 | switch (arg->type) { |
|---|
| 3535 | | - case PRINT_NULL: |
|---|
| 3644 | + case TEP_PRINT_NULL: |
|---|
| 3536 | 3645 | /* ?? */ |
|---|
| 3537 | 3646 | return 0; |
|---|
| 3538 | | - case PRINT_ATOM: |
|---|
| 3647 | + case TEP_PRINT_ATOM: |
|---|
| 3539 | 3648 | return strtoull(arg->atom.atom, NULL, 0); |
|---|
| 3540 | | - case PRINT_FIELD: |
|---|
| 3649 | + case TEP_PRINT_FIELD: |
|---|
| 3541 | 3650 | if (!arg->field.field) { |
|---|
| 3542 | 3651 | arg->field.field = tep_find_any_field(event, arg->field.name); |
|---|
| 3543 | 3652 | if (!arg->field.field) |
|---|
| .. | .. |
|---|
| 3545 | 3654 | |
|---|
| 3546 | 3655 | } |
|---|
| 3547 | 3656 | /* must be a number */ |
|---|
| 3548 | | - val = tep_read_number(pevent, data + arg->field.field->offset, |
|---|
| 3657 | + val = tep_read_number(tep, data + arg->field.field->offset, |
|---|
| 3549 | 3658 | arg->field.field->size); |
|---|
| 3550 | 3659 | break; |
|---|
| 3551 | | - case PRINT_FLAGS: |
|---|
| 3552 | | - case PRINT_SYMBOL: |
|---|
| 3553 | | - case PRINT_INT_ARRAY: |
|---|
| 3554 | | - case PRINT_HEX: |
|---|
| 3555 | | - case PRINT_HEX_STR: |
|---|
| 3660 | + case TEP_PRINT_FLAGS: |
|---|
| 3661 | + case TEP_PRINT_SYMBOL: |
|---|
| 3662 | + case TEP_PRINT_INT_ARRAY: |
|---|
| 3663 | + case TEP_PRINT_HEX: |
|---|
| 3664 | + case TEP_PRINT_HEX_STR: |
|---|
| 3556 | 3665 | break; |
|---|
| 3557 | | - case PRINT_TYPE: |
|---|
| 3666 | + case TEP_PRINT_TYPE: |
|---|
| 3558 | 3667 | val = eval_num_arg(data, size, event, arg->typecast.item); |
|---|
| 3559 | 3668 | return eval_type(val, arg, 0); |
|---|
| 3560 | | - case PRINT_STRING: |
|---|
| 3561 | | - case PRINT_BSTRING: |
|---|
| 3562 | | - case PRINT_BITMASK: |
|---|
| 3669 | + case TEP_PRINT_STRING: |
|---|
| 3670 | + case TEP_PRINT_BSTRING: |
|---|
| 3671 | + case TEP_PRINT_BITMASK: |
|---|
| 3563 | 3672 | return 0; |
|---|
| 3564 | | - case PRINT_FUNC: { |
|---|
| 3673 | + case TEP_PRINT_FUNC: { |
|---|
| 3565 | 3674 | struct trace_seq s; |
|---|
| 3566 | 3675 | trace_seq_init(&s); |
|---|
| 3567 | 3676 | val = process_defined_func(&s, data, size, event, arg); |
|---|
| 3568 | 3677 | trace_seq_destroy(&s); |
|---|
| 3569 | 3678 | return val; |
|---|
| 3570 | 3679 | } |
|---|
| 3571 | | - case PRINT_OP: |
|---|
| 3680 | + case TEP_PRINT_OP: |
|---|
| 3572 | 3681 | if (strcmp(arg->op.op, "[") == 0) { |
|---|
| 3573 | 3682 | /* |
|---|
| 3574 | 3683 | * Arrays are special, since we don't want |
|---|
| .. | .. |
|---|
| 3578 | 3687 | |
|---|
| 3579 | 3688 | /* handle typecasts */ |
|---|
| 3580 | 3689 | larg = arg->op.left; |
|---|
| 3581 | | - while (larg->type == PRINT_TYPE) { |
|---|
| 3690 | + while (larg->type == TEP_PRINT_TYPE) { |
|---|
| 3582 | 3691 | if (!typearg) |
|---|
| 3583 | 3692 | typearg = larg; |
|---|
| 3584 | 3693 | larg = larg->typecast.item; |
|---|
| 3585 | 3694 | } |
|---|
| 3586 | 3695 | |
|---|
| 3587 | 3696 | /* Default to long size */ |
|---|
| 3588 | | - field_size = pevent->long_size; |
|---|
| 3697 | + field_size = tep->long_size; |
|---|
| 3589 | 3698 | |
|---|
| 3590 | 3699 | switch (larg->type) { |
|---|
| 3591 | | - case PRINT_DYNAMIC_ARRAY: |
|---|
| 3592 | | - offset = tep_read_number(pevent, |
|---|
| 3700 | + case TEP_PRINT_DYNAMIC_ARRAY: |
|---|
| 3701 | + offset = tep_read_number(tep, |
|---|
| 3593 | 3702 | data + larg->dynarray.field->offset, |
|---|
| 3594 | 3703 | larg->dynarray.field->size); |
|---|
| 3595 | 3704 | if (larg->dynarray.field->elementsize) |
|---|
| .. | .. |
|---|
| 3602 | 3711 | offset &= 0xffff; |
|---|
| 3603 | 3712 | offset += right; |
|---|
| 3604 | 3713 | break; |
|---|
| 3605 | | - case PRINT_FIELD: |
|---|
| 3714 | + case TEP_PRINT_FIELD: |
|---|
| 3606 | 3715 | if (!larg->field.field) { |
|---|
| 3607 | 3716 | larg->field.field = |
|---|
| 3608 | 3717 | tep_find_any_field(event, larg->field.name); |
|---|
| .. | .. |
|---|
| 3618 | 3727 | default: |
|---|
| 3619 | 3728 | goto default_op; /* oops, all bets off */ |
|---|
| 3620 | 3729 | } |
|---|
| 3621 | | - val = tep_read_number(pevent, |
|---|
| 3730 | + val = tep_read_number(tep, |
|---|
| 3622 | 3731 | data + offset, field_size); |
|---|
| 3623 | 3732 | if (typearg) |
|---|
| 3624 | 3733 | val = eval_type(val, typearg, 1); |
|---|
| .. | .. |
|---|
| 3718 | 3827 | goto out_warning_op; |
|---|
| 3719 | 3828 | } |
|---|
| 3720 | 3829 | break; |
|---|
| 3721 | | - case PRINT_DYNAMIC_ARRAY_LEN: |
|---|
| 3722 | | - offset = tep_read_number(pevent, |
|---|
| 3830 | + case TEP_PRINT_DYNAMIC_ARRAY_LEN: |
|---|
| 3831 | + offset = tep_read_number(tep, |
|---|
| 3723 | 3832 | data + arg->dynarray.field->offset, |
|---|
| 3724 | 3833 | arg->dynarray.field->size); |
|---|
| 3725 | 3834 | /* |
|---|
| .. | .. |
|---|
| 3729 | 3838 | */ |
|---|
| 3730 | 3839 | val = (unsigned long long)(offset >> 16); |
|---|
| 3731 | 3840 | break; |
|---|
| 3732 | | - case PRINT_DYNAMIC_ARRAY: |
|---|
| 3841 | + case TEP_PRINT_DYNAMIC_ARRAY: |
|---|
| 3733 | 3842 | /* Without [], we pass the address to the dynamic data */ |
|---|
| 3734 | | - offset = tep_read_number(pevent, |
|---|
| 3843 | + offset = tep_read_number(tep, |
|---|
| 3735 | 3844 | data + arg->dynarray.field->offset, |
|---|
| 3736 | 3845 | arg->dynarray.field->size); |
|---|
| 3737 | 3846 | /* |
|---|
| .. | .. |
|---|
| 3806 | 3915 | trace_seq_printf(s, format, str); |
|---|
| 3807 | 3916 | } |
|---|
| 3808 | 3917 | |
|---|
| 3809 | | -static void print_bitmask_to_seq(struct tep_handle *pevent, |
|---|
| 3918 | +static void print_bitmask_to_seq(struct tep_handle *tep, |
|---|
| 3810 | 3919 | struct trace_seq *s, const char *format, |
|---|
| 3811 | 3920 | int len_arg, const void *data, int size) |
|---|
| 3812 | 3921 | { |
|---|
| .. | .. |
|---|
| 3836 | 3945 | /* |
|---|
| 3837 | 3946 | * data points to a bit mask of size bytes. |
|---|
| 3838 | 3947 | * In the kernel, this is an array of long words, thus |
|---|
| 3839 | | - * endianess is very important. |
|---|
| 3948 | + * endianness is very important. |
|---|
| 3840 | 3949 | */ |
|---|
| 3841 | | - if (pevent->file_bigendian) |
|---|
| 3950 | + if (tep->file_bigendian) |
|---|
| 3842 | 3951 | index = size - (len + 1); |
|---|
| 3843 | 3952 | else |
|---|
| 3844 | 3953 | index = len; |
|---|
| .. | .. |
|---|
| 3861 | 3970 | } |
|---|
| 3862 | 3971 | |
|---|
| 3863 | 3972 | static void print_str_arg(struct trace_seq *s, void *data, int size, |
|---|
| 3864 | | - struct event_format *event, const char *format, |
|---|
| 3865 | | - int len_arg, struct print_arg *arg) |
|---|
| 3973 | + struct tep_event *event, const char *format, |
|---|
| 3974 | + int len_arg, struct tep_print_arg *arg) |
|---|
| 3866 | 3975 | { |
|---|
| 3867 | | - struct tep_handle *pevent = event->pevent; |
|---|
| 3868 | | - struct print_flag_sym *flag; |
|---|
| 3869 | | - struct format_field *field; |
|---|
| 3976 | + struct tep_handle *tep = event->tep; |
|---|
| 3977 | + struct tep_print_flag_sym *flag; |
|---|
| 3978 | + struct tep_format_field *field; |
|---|
| 3870 | 3979 | struct printk_map *printk; |
|---|
| 3871 | 3980 | long long val, fval; |
|---|
| 3872 | 3981 | unsigned long long addr; |
|---|
| .. | .. |
|---|
| 3876 | 3985 | int i, len; |
|---|
| 3877 | 3986 | |
|---|
| 3878 | 3987 | switch (arg->type) { |
|---|
| 3879 | | - case PRINT_NULL: |
|---|
| 3988 | + case TEP_PRINT_NULL: |
|---|
| 3880 | 3989 | /* ?? */ |
|---|
| 3881 | 3990 | return; |
|---|
| 3882 | | - case PRINT_ATOM: |
|---|
| 3991 | + case TEP_PRINT_ATOM: |
|---|
| 3883 | 3992 | print_str_to_seq(s, format, len_arg, arg->atom.atom); |
|---|
| 3884 | 3993 | return; |
|---|
| 3885 | | - case PRINT_FIELD: |
|---|
| 3994 | + case TEP_PRINT_FIELD: |
|---|
| 3886 | 3995 | field = arg->field.field; |
|---|
| 3887 | 3996 | if (!field) { |
|---|
| 3888 | 3997 | field = tep_find_any_field(event, arg->field.name); |
|---|
| .. | .. |
|---|
| 3900 | 4009 | * and the size is the same as long_size, assume that it |
|---|
| 3901 | 4010 | * is a pointer. |
|---|
| 3902 | 4011 | */ |
|---|
| 3903 | | - if (!(field->flags & FIELD_IS_ARRAY) && |
|---|
| 3904 | | - field->size == pevent->long_size) { |
|---|
| 4012 | + if (!(field->flags & TEP_FIELD_IS_ARRAY) && |
|---|
| 4013 | + field->size == tep->long_size) { |
|---|
| 3905 | 4014 | |
|---|
| 3906 | 4015 | /* Handle heterogeneous recording and processing |
|---|
| 3907 | 4016 | * architectures |
|---|
| .. | .. |
|---|
| 3916 | 4025 | * on 32-bit devices: |
|---|
| 3917 | 4026 | * In this case, 64 bits must be read. |
|---|
| 3918 | 4027 | */ |
|---|
| 3919 | | - addr = (pevent->long_size == 8) ? |
|---|
| 4028 | + addr = (tep->long_size == 8) ? |
|---|
| 3920 | 4029 | *(unsigned long long *)(data + field->offset) : |
|---|
| 3921 | 4030 | (unsigned long long)*(unsigned int *)(data + field->offset); |
|---|
| 3922 | 4031 | |
|---|
| 3923 | 4032 | /* Check if it matches a print format */ |
|---|
| 3924 | | - printk = find_printk(pevent, addr); |
|---|
| 4033 | + printk = find_printk(tep, addr); |
|---|
| 3925 | 4034 | if (printk) |
|---|
| 3926 | 4035 | trace_seq_puts(s, printk->printk); |
|---|
| 3927 | 4036 | else |
|---|
| .. | .. |
|---|
| 3939 | 4048 | print_str_to_seq(s, format, len_arg, str); |
|---|
| 3940 | 4049 | free(str); |
|---|
| 3941 | 4050 | break; |
|---|
| 3942 | | - case PRINT_FLAGS: |
|---|
| 4051 | + case TEP_PRINT_FLAGS: |
|---|
| 3943 | 4052 | val = eval_num_arg(data, size, event, arg->flags.field); |
|---|
| 3944 | 4053 | print = 0; |
|---|
| 3945 | 4054 | for (flag = arg->flags.flags; flag; flag = flag->next) { |
|---|
| .. | .. |
|---|
| 3962 | 4071 | trace_seq_printf(s, "0x%llx", val); |
|---|
| 3963 | 4072 | } |
|---|
| 3964 | 4073 | break; |
|---|
| 3965 | | - case PRINT_SYMBOL: |
|---|
| 4074 | + case TEP_PRINT_SYMBOL: |
|---|
| 3966 | 4075 | val = eval_num_arg(data, size, event, arg->symbol.field); |
|---|
| 3967 | 4076 | for (flag = arg->symbol.symbols; flag; flag = flag->next) { |
|---|
| 3968 | 4077 | fval = eval_flag(flag->value); |
|---|
| .. | .. |
|---|
| 3974 | 4083 | if (!flag) |
|---|
| 3975 | 4084 | trace_seq_printf(s, "0x%llx", val); |
|---|
| 3976 | 4085 | break; |
|---|
| 3977 | | - case PRINT_HEX: |
|---|
| 3978 | | - case PRINT_HEX_STR: |
|---|
| 3979 | | - if (arg->hex.field->type == PRINT_DYNAMIC_ARRAY) { |
|---|
| 4086 | + case TEP_PRINT_HEX: |
|---|
| 4087 | + case TEP_PRINT_HEX_STR: |
|---|
| 4088 | + if (arg->hex.field->type == TEP_PRINT_DYNAMIC_ARRAY) { |
|---|
| 3980 | 4089 | unsigned long offset; |
|---|
| 3981 | | - offset = tep_read_number(pevent, |
|---|
| 4090 | + offset = tep_read_number(tep, |
|---|
| 3982 | 4091 | data + arg->hex.field->dynarray.field->offset, |
|---|
| 3983 | 4092 | arg->hex.field->dynarray.field->size); |
|---|
| 3984 | 4093 | hex = data + (offset & 0xffff); |
|---|
| .. | .. |
|---|
| 3995 | 4104 | } |
|---|
| 3996 | 4105 | len = eval_num_arg(data, size, event, arg->hex.size); |
|---|
| 3997 | 4106 | for (i = 0; i < len; i++) { |
|---|
| 3998 | | - if (i && arg->type == PRINT_HEX) |
|---|
| 4107 | + if (i && arg->type == TEP_PRINT_HEX) |
|---|
| 3999 | 4108 | trace_seq_putc(s, ' '); |
|---|
| 4000 | 4109 | trace_seq_printf(s, "%02x", hex[i]); |
|---|
| 4001 | 4110 | } |
|---|
| 4002 | 4111 | break; |
|---|
| 4003 | 4112 | |
|---|
| 4004 | | - case PRINT_INT_ARRAY: { |
|---|
| 4113 | + case TEP_PRINT_INT_ARRAY: { |
|---|
| 4005 | 4114 | void *num; |
|---|
| 4006 | 4115 | int el_size; |
|---|
| 4007 | 4116 | |
|---|
| 4008 | | - if (arg->int_array.field->type == PRINT_DYNAMIC_ARRAY) { |
|---|
| 4117 | + if (arg->int_array.field->type == TEP_PRINT_DYNAMIC_ARRAY) { |
|---|
| 4009 | 4118 | unsigned long offset; |
|---|
| 4010 | | - struct format_field *field = |
|---|
| 4119 | + struct tep_format_field *field = |
|---|
| 4011 | 4120 | arg->int_array.field->dynarray.field; |
|---|
| 4012 | | - offset = tep_read_number(pevent, |
|---|
| 4121 | + offset = tep_read_number(tep, |
|---|
| 4013 | 4122 | data + field->offset, |
|---|
| 4014 | 4123 | field->size); |
|---|
| 4015 | 4124 | num = data + (offset & 0xffff); |
|---|
| .. | .. |
|---|
| 4049 | 4158 | } |
|---|
| 4050 | 4159 | break; |
|---|
| 4051 | 4160 | } |
|---|
| 4052 | | - case PRINT_TYPE: |
|---|
| 4161 | + case TEP_PRINT_TYPE: |
|---|
| 4053 | 4162 | break; |
|---|
| 4054 | | - case PRINT_STRING: { |
|---|
| 4163 | + case TEP_PRINT_STRING: { |
|---|
| 4055 | 4164 | int str_offset; |
|---|
| 4056 | 4165 | |
|---|
| 4057 | 4166 | if (arg->string.offset == -1) { |
|---|
| 4058 | | - struct format_field *f; |
|---|
| 4167 | + struct tep_format_field *f; |
|---|
| 4059 | 4168 | |
|---|
| 4060 | 4169 | f = tep_find_any_field(event, arg->string.string); |
|---|
| 4061 | 4170 | arg->string.offset = f->offset; |
|---|
| 4062 | 4171 | } |
|---|
| 4063 | | - str_offset = data2host4(pevent, data + arg->string.offset); |
|---|
| 4172 | + str_offset = data2host4(tep, *(unsigned int *)(data + arg->string.offset)); |
|---|
| 4064 | 4173 | str_offset &= 0xffff; |
|---|
| 4065 | 4174 | print_str_to_seq(s, format, len_arg, ((char *)data) + str_offset); |
|---|
| 4066 | 4175 | break; |
|---|
| 4067 | 4176 | } |
|---|
| 4068 | | - case PRINT_BSTRING: |
|---|
| 4177 | + case TEP_PRINT_BSTRING: |
|---|
| 4069 | 4178 | print_str_to_seq(s, format, len_arg, arg->string.string); |
|---|
| 4070 | 4179 | break; |
|---|
| 4071 | | - case PRINT_BITMASK: { |
|---|
| 4180 | + case TEP_PRINT_BITMASK: { |
|---|
| 4072 | 4181 | int bitmask_offset; |
|---|
| 4073 | 4182 | int bitmask_size; |
|---|
| 4074 | 4183 | |
|---|
| 4075 | 4184 | if (arg->bitmask.offset == -1) { |
|---|
| 4076 | | - struct format_field *f; |
|---|
| 4185 | + struct tep_format_field *f; |
|---|
| 4077 | 4186 | |
|---|
| 4078 | 4187 | f = tep_find_any_field(event, arg->bitmask.bitmask); |
|---|
| 4079 | 4188 | arg->bitmask.offset = f->offset; |
|---|
| 4080 | 4189 | } |
|---|
| 4081 | | - bitmask_offset = data2host4(pevent, data + arg->bitmask.offset); |
|---|
| 4190 | + bitmask_offset = data2host4(tep, *(unsigned int *)(data + arg->bitmask.offset)); |
|---|
| 4082 | 4191 | bitmask_size = bitmask_offset >> 16; |
|---|
| 4083 | 4192 | bitmask_offset &= 0xffff; |
|---|
| 4084 | | - print_bitmask_to_seq(pevent, s, format, len_arg, |
|---|
| 4193 | + print_bitmask_to_seq(tep, s, format, len_arg, |
|---|
| 4085 | 4194 | data + bitmask_offset, bitmask_size); |
|---|
| 4086 | 4195 | break; |
|---|
| 4087 | 4196 | } |
|---|
| 4088 | | - case PRINT_OP: |
|---|
| 4197 | + case TEP_PRINT_OP: |
|---|
| 4089 | 4198 | /* |
|---|
| 4090 | 4199 | * The only op for string should be ? : |
|---|
| 4091 | 4200 | */ |
|---|
| .. | .. |
|---|
| 4099 | 4208 | print_str_arg(s, data, size, event, |
|---|
| 4100 | 4209 | format, len_arg, arg->op.right->op.right); |
|---|
| 4101 | 4210 | break; |
|---|
| 4102 | | - case PRINT_FUNC: |
|---|
| 4211 | + case TEP_PRINT_FUNC: |
|---|
| 4103 | 4212 | process_defined_func(s, data, size, event, arg); |
|---|
| 4104 | 4213 | break; |
|---|
| 4105 | 4214 | default: |
|---|
| .. | .. |
|---|
| 4116 | 4225 | |
|---|
| 4117 | 4226 | static unsigned long long |
|---|
| 4118 | 4227 | process_defined_func(struct trace_seq *s, void *data, int size, |
|---|
| 4119 | | - struct event_format *event, struct print_arg *arg) |
|---|
| 4228 | + struct tep_event *event, struct tep_print_arg *arg) |
|---|
| 4120 | 4229 | { |
|---|
| 4121 | 4230 | struct tep_function_handler *func_handle = arg->func.func; |
|---|
| 4122 | 4231 | struct func_params *param; |
|---|
| 4123 | 4232 | unsigned long long *args; |
|---|
| 4124 | 4233 | unsigned long long ret; |
|---|
| 4125 | | - struct print_arg *farg; |
|---|
| 4234 | + struct tep_print_arg *farg; |
|---|
| 4126 | 4235 | struct trace_seq str; |
|---|
| 4127 | 4236 | struct save_str { |
|---|
| 4128 | 4237 | struct save_str *next; |
|---|
| .. | .. |
|---|
| 4199 | 4308 | return ret; |
|---|
| 4200 | 4309 | } |
|---|
| 4201 | 4310 | |
|---|
| 4202 | | -static void free_args(struct print_arg *args) |
|---|
| 4311 | +static void free_args(struct tep_print_arg *args) |
|---|
| 4203 | 4312 | { |
|---|
| 4204 | | - struct print_arg *next; |
|---|
| 4313 | + struct tep_print_arg *next; |
|---|
| 4205 | 4314 | |
|---|
| 4206 | 4315 | while (args) { |
|---|
| 4207 | 4316 | next = args->next; |
|---|
| .. | .. |
|---|
| 4211 | 4320 | } |
|---|
| 4212 | 4321 | } |
|---|
| 4213 | 4322 | |
|---|
| 4214 | | -static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event_format *event) |
|---|
| 4323 | +static struct tep_print_arg *make_bprint_args(char *fmt, void *data, int size, struct tep_event *event) |
|---|
| 4215 | 4324 | { |
|---|
| 4216 | | - struct tep_handle *pevent = event->pevent; |
|---|
| 4217 | | - struct format_field *field, *ip_field; |
|---|
| 4218 | | - struct print_arg *args, *arg, **next; |
|---|
| 4325 | + struct tep_handle *tep = event->tep; |
|---|
| 4326 | + struct tep_format_field *field, *ip_field; |
|---|
| 4327 | + struct tep_print_arg *args, *arg, **next; |
|---|
| 4219 | 4328 | unsigned long long ip, val; |
|---|
| 4220 | 4329 | char *ptr; |
|---|
| 4221 | 4330 | void *bptr; |
|---|
| 4222 | | - int vsize; |
|---|
| 4331 | + int vsize = 0; |
|---|
| 4223 | 4332 | |
|---|
| 4224 | | - field = pevent->bprint_buf_field; |
|---|
| 4225 | | - ip_field = pevent->bprint_ip_field; |
|---|
| 4333 | + field = tep->bprint_buf_field; |
|---|
| 4334 | + ip_field = tep->bprint_ip_field; |
|---|
| 4226 | 4335 | |
|---|
| 4227 | 4336 | if (!field) { |
|---|
| 4228 | 4337 | field = tep_find_field(event, "buf"); |
|---|
| .. | .. |
|---|
| 4235 | 4344 | do_warning_event(event, "can't find ip field for binary printk"); |
|---|
| 4236 | 4345 | return NULL; |
|---|
| 4237 | 4346 | } |
|---|
| 4238 | | - pevent->bprint_buf_field = field; |
|---|
| 4239 | | - pevent->bprint_ip_field = ip_field; |
|---|
| 4347 | + tep->bprint_buf_field = field; |
|---|
| 4348 | + tep->bprint_ip_field = ip_field; |
|---|
| 4240 | 4349 | } |
|---|
| 4241 | 4350 | |
|---|
| 4242 | | - ip = tep_read_number(pevent, data + ip_field->offset, ip_field->size); |
|---|
| 4351 | + ip = tep_read_number(tep, data + ip_field->offset, ip_field->size); |
|---|
| 4243 | 4352 | |
|---|
| 4244 | 4353 | /* |
|---|
| 4245 | 4354 | * The first arg is the IP pointer. |
|---|
| .. | .. |
|---|
| 4254 | 4363 | arg->next = NULL; |
|---|
| 4255 | 4364 | next = &arg->next; |
|---|
| 4256 | 4365 | |
|---|
| 4257 | | - arg->type = PRINT_ATOM; |
|---|
| 4366 | + arg->type = TEP_PRINT_ATOM; |
|---|
| 4258 | 4367 | |
|---|
| 4259 | 4368 | if (asprintf(&arg->atom.atom, "%lld", ip) < 0) |
|---|
| 4260 | 4369 | goto out_free; |
|---|
| .. | .. |
|---|
| 4292 | 4401 | switch (*ptr) { |
|---|
| 4293 | 4402 | case 's': |
|---|
| 4294 | 4403 | case 'S': |
|---|
| 4404 | + case 'x': |
|---|
| 4405 | + break; |
|---|
| 4295 | 4406 | case 'f': |
|---|
| 4296 | 4407 | case 'F': |
|---|
| 4297 | | - break; |
|---|
| 4408 | + /* |
|---|
| 4409 | + * Pre-5.5 kernels use %pf and |
|---|
| 4410 | + * %pF for printing symbols |
|---|
| 4411 | + * while kernels since 5.5 use |
|---|
| 4412 | + * %pfw for fwnodes. So check |
|---|
| 4413 | + * %p[fF] isn't followed by 'w'. |
|---|
| 4414 | + */ |
|---|
| 4415 | + if (ptr[1] != 'w') |
|---|
| 4416 | + break; |
|---|
| 4417 | + /* fall through */ |
|---|
| 4298 | 4418 | default: |
|---|
| 4299 | 4419 | /* |
|---|
| 4300 | 4420 | * Older kernels do not process |
|---|
| .. | .. |
|---|
| 4309 | 4429 | /* fall through */ |
|---|
| 4310 | 4430 | case 'd': |
|---|
| 4311 | 4431 | case 'u': |
|---|
| 4312 | | - case 'x': |
|---|
| 4313 | 4432 | case 'i': |
|---|
| 4433 | + case 'x': |
|---|
| 4434 | + case 'X': |
|---|
| 4435 | + case 'o': |
|---|
| 4314 | 4436 | switch (ls) { |
|---|
| 4315 | 4437 | case 0: |
|---|
| 4316 | 4438 | vsize = 4; |
|---|
| 4317 | 4439 | break; |
|---|
| 4318 | 4440 | case 1: |
|---|
| 4319 | | - vsize = pevent->long_size; |
|---|
| 4441 | + vsize = tep->long_size; |
|---|
| 4320 | 4442 | break; |
|---|
| 4321 | 4443 | case 2: |
|---|
| 4322 | 4444 | vsize = 8; |
|---|
| .. | .. |
|---|
| 4333 | 4455 | /* the pointers are always 4 bytes aligned */ |
|---|
| 4334 | 4456 | bptr = (void *)(((unsigned long)bptr + 3) & |
|---|
| 4335 | 4457 | ~3); |
|---|
| 4336 | | - val = tep_read_number(pevent, bptr, vsize); |
|---|
| 4458 | + val = tep_read_number(tep, bptr, vsize); |
|---|
| 4337 | 4459 | bptr += vsize; |
|---|
| 4338 | 4460 | arg = alloc_arg(); |
|---|
| 4339 | 4461 | if (!arg) { |
|---|
| .. | .. |
|---|
| 4342 | 4464 | goto out_free; |
|---|
| 4343 | 4465 | } |
|---|
| 4344 | 4466 | arg->next = NULL; |
|---|
| 4345 | | - arg->type = PRINT_ATOM; |
|---|
| 4467 | + arg->type = TEP_PRINT_ATOM; |
|---|
| 4346 | 4468 | if (asprintf(&arg->atom.atom, "%lld", val) < 0) { |
|---|
| 4347 | 4469 | free(arg); |
|---|
| 4348 | 4470 | goto out_free; |
|---|
| .. | .. |
|---|
| 4366 | 4488 | goto out_free; |
|---|
| 4367 | 4489 | } |
|---|
| 4368 | 4490 | arg->next = NULL; |
|---|
| 4369 | | - arg->type = PRINT_BSTRING; |
|---|
| 4491 | + arg->type = TEP_PRINT_BSTRING; |
|---|
| 4370 | 4492 | arg->string.string = strdup(bptr); |
|---|
| 4371 | 4493 | if (!arg->string.string) |
|---|
| 4372 | 4494 | goto out_free; |
|---|
| .. | .. |
|---|
| 4388 | 4510 | |
|---|
| 4389 | 4511 | static char * |
|---|
| 4390 | 4512 | get_bprint_format(void *data, int size __maybe_unused, |
|---|
| 4391 | | - struct event_format *event) |
|---|
| 4513 | + struct tep_event *event) |
|---|
| 4392 | 4514 | { |
|---|
| 4393 | | - struct tep_handle *pevent = event->pevent; |
|---|
| 4515 | + struct tep_handle *tep = event->tep; |
|---|
| 4394 | 4516 | unsigned long long addr; |
|---|
| 4395 | | - struct format_field *field; |
|---|
| 4517 | + struct tep_format_field *field; |
|---|
| 4396 | 4518 | struct printk_map *printk; |
|---|
| 4397 | 4519 | char *format; |
|---|
| 4398 | 4520 | |
|---|
| 4399 | | - field = pevent->bprint_fmt_field; |
|---|
| 4521 | + field = tep->bprint_fmt_field; |
|---|
| 4400 | 4522 | |
|---|
| 4401 | 4523 | if (!field) { |
|---|
| 4402 | 4524 | field = tep_find_field(event, "fmt"); |
|---|
| .. | .. |
|---|
| 4404 | 4526 | do_warning_event(event, "can't find format field for binary printk"); |
|---|
| 4405 | 4527 | return NULL; |
|---|
| 4406 | 4528 | } |
|---|
| 4407 | | - pevent->bprint_fmt_field = field; |
|---|
| 4529 | + tep->bprint_fmt_field = field; |
|---|
| 4408 | 4530 | } |
|---|
| 4409 | 4531 | |
|---|
| 4410 | | - addr = tep_read_number(pevent, data + field->offset, field->size); |
|---|
| 4532 | + addr = tep_read_number(tep, data + field->offset, field->size); |
|---|
| 4411 | 4533 | |
|---|
| 4412 | | - printk = find_printk(pevent, addr); |
|---|
| 4534 | + printk = find_printk(tep, addr); |
|---|
| 4413 | 4535 | if (!printk) { |
|---|
| 4414 | | - if (asprintf(&format, "%%pf: (NO FORMAT FOUND at %llx)\n", addr) < 0) |
|---|
| 4536 | + if (asprintf(&format, "%%ps: (NO FORMAT FOUND at %llx)\n", addr) < 0) |
|---|
| 4415 | 4537 | return NULL; |
|---|
| 4416 | 4538 | return format; |
|---|
| 4417 | 4539 | } |
|---|
| 4418 | 4540 | |
|---|
| 4419 | | - if (asprintf(&format, "%s: %s", "%pf", printk->printk) < 0) |
|---|
| 4541 | + if (asprintf(&format, "%s: %s", "%ps", printk->printk) < 0) |
|---|
| 4420 | 4542 | return NULL; |
|---|
| 4421 | 4543 | |
|---|
| 4422 | 4544 | return format; |
|---|
| 4423 | 4545 | } |
|---|
| 4424 | 4546 | |
|---|
| 4425 | | -static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size, |
|---|
| 4426 | | - struct event_format *event, struct print_arg *arg) |
|---|
| 4547 | +static int print_mac_arg(struct trace_seq *s, const char *format, |
|---|
| 4548 | + void *data, int size, struct tep_event *event, |
|---|
| 4549 | + struct tep_print_arg *arg) |
|---|
| 4427 | 4550 | { |
|---|
| 4428 | | - unsigned char *buf; |
|---|
| 4429 | 4551 | const char *fmt = "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x"; |
|---|
| 4552 | + bool reverse = false; |
|---|
| 4553 | + unsigned char *buf; |
|---|
| 4554 | + int ret = 0; |
|---|
| 4430 | 4555 | |
|---|
| 4431 | | - if (arg->type == PRINT_FUNC) { |
|---|
| 4556 | + if (arg->type == TEP_PRINT_FUNC) { |
|---|
| 4432 | 4557 | process_defined_func(s, data, size, event, arg); |
|---|
| 4433 | | - return; |
|---|
| 4558 | + return 0; |
|---|
| 4434 | 4559 | } |
|---|
| 4435 | 4560 | |
|---|
| 4436 | | - if (arg->type != PRINT_FIELD) { |
|---|
| 4561 | + if (arg->type != TEP_PRINT_FIELD) { |
|---|
| 4437 | 4562 | trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", |
|---|
| 4438 | 4563 | arg->type); |
|---|
| 4439 | | - return; |
|---|
| 4564 | + return 0; |
|---|
| 4440 | 4565 | } |
|---|
| 4441 | 4566 | |
|---|
| 4442 | | - if (mac == 'm') |
|---|
| 4567 | + if (format[0] == 'm') { |
|---|
| 4443 | 4568 | fmt = "%.2x%.2x%.2x%.2x%.2x%.2x"; |
|---|
| 4569 | + } else if (format[0] == 'M' && format[1] == 'F') { |
|---|
| 4570 | + fmt = "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x"; |
|---|
| 4571 | + ret++; |
|---|
| 4572 | + } |
|---|
| 4573 | + if (format[1] == 'R') { |
|---|
| 4574 | + reverse = true; |
|---|
| 4575 | + ret++; |
|---|
| 4576 | + } |
|---|
| 4577 | + |
|---|
| 4444 | 4578 | if (!arg->field.field) { |
|---|
| 4445 | 4579 | arg->field.field = |
|---|
| 4446 | 4580 | tep_find_any_field(event, arg->field.name); |
|---|
| 4447 | 4581 | if (!arg->field.field) { |
|---|
| 4448 | 4582 | do_warning_event(event, "%s: field %s not found", |
|---|
| 4449 | 4583 | __func__, arg->field.name); |
|---|
| 4450 | | - return; |
|---|
| 4584 | + return ret; |
|---|
| 4451 | 4585 | } |
|---|
| 4452 | 4586 | } |
|---|
| 4453 | 4587 | if (arg->field.field->size != 6) { |
|---|
| 4454 | 4588 | trace_seq_printf(s, "INVALIDMAC"); |
|---|
| 4455 | | - return; |
|---|
| 4589 | + return ret; |
|---|
| 4456 | 4590 | } |
|---|
| 4591 | + |
|---|
| 4457 | 4592 | buf = data + arg->field.field->offset; |
|---|
| 4458 | | - trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); |
|---|
| 4593 | + if (reverse) |
|---|
| 4594 | + trace_seq_printf(s, fmt, buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]); |
|---|
| 4595 | + else |
|---|
| 4596 | + trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); |
|---|
| 4597 | + |
|---|
| 4598 | + return ret; |
|---|
| 4459 | 4599 | } |
|---|
| 4460 | 4600 | |
|---|
| 4461 | | -static void print_ip4_addr(struct trace_seq *s, char i, unsigned char *buf) |
|---|
| 4601 | +static int parse_ip4_print_args(struct tep_handle *tep, |
|---|
| 4602 | + const char *ptr, bool *reverse) |
|---|
| 4603 | +{ |
|---|
| 4604 | + int ret = 0; |
|---|
| 4605 | + |
|---|
| 4606 | + *reverse = false; |
|---|
| 4607 | + |
|---|
| 4608 | + /* hnbl */ |
|---|
| 4609 | + switch (*ptr) { |
|---|
| 4610 | + case 'h': |
|---|
| 4611 | + if (tep->file_bigendian) |
|---|
| 4612 | + *reverse = false; |
|---|
| 4613 | + else |
|---|
| 4614 | + *reverse = true; |
|---|
| 4615 | + ret++; |
|---|
| 4616 | + break; |
|---|
| 4617 | + case 'l': |
|---|
| 4618 | + *reverse = true; |
|---|
| 4619 | + ret++; |
|---|
| 4620 | + break; |
|---|
| 4621 | + case 'n': |
|---|
| 4622 | + case 'b': |
|---|
| 4623 | + ret++; |
|---|
| 4624 | + /* fall through */ |
|---|
| 4625 | + default: |
|---|
| 4626 | + *reverse = false; |
|---|
| 4627 | + break; |
|---|
| 4628 | + } |
|---|
| 4629 | + |
|---|
| 4630 | + return ret; |
|---|
| 4631 | +} |
|---|
| 4632 | + |
|---|
| 4633 | +static void print_ip4_addr(struct trace_seq *s, char i, bool reverse, unsigned char *buf) |
|---|
| 4462 | 4634 | { |
|---|
| 4463 | 4635 | const char *fmt; |
|---|
| 4464 | 4636 | |
|---|
| .. | .. |
|---|
| 4467 | 4639 | else |
|---|
| 4468 | 4640 | fmt = "%d.%d.%d.%d"; |
|---|
| 4469 | 4641 | |
|---|
| 4470 | | - trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3]); |
|---|
| 4642 | + if (reverse) |
|---|
| 4643 | + trace_seq_printf(s, fmt, buf[3], buf[2], buf[1], buf[0]); |
|---|
| 4644 | + else |
|---|
| 4645 | + trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3]); |
|---|
| 4646 | + |
|---|
| 4471 | 4647 | } |
|---|
| 4472 | 4648 | |
|---|
| 4473 | 4649 | static inline bool ipv6_addr_v4mapped(const struct in6_addr *a) |
|---|
| .. | .. |
|---|
| 4550 | 4726 | if (useIPv4) { |
|---|
| 4551 | 4727 | if (needcolon) |
|---|
| 4552 | 4728 | trace_seq_printf(s, ":"); |
|---|
| 4553 | | - print_ip4_addr(s, 'I', &in6.s6_addr[12]); |
|---|
| 4729 | + print_ip4_addr(s, 'I', false, &in6.s6_addr[12]); |
|---|
| 4554 | 4730 | } |
|---|
| 4555 | 4731 | |
|---|
| 4556 | 4732 | return; |
|---|
| .. | .. |
|---|
| 4576 | 4752 | * %pISpc print an IP address based on sockaddr; p adds port. |
|---|
| 4577 | 4753 | */ |
|---|
| 4578 | 4754 | static int print_ipv4_arg(struct trace_seq *s, const char *ptr, char i, |
|---|
| 4579 | | - void *data, int size, struct event_format *event, |
|---|
| 4580 | | - struct print_arg *arg) |
|---|
| 4755 | + void *data, int size, struct tep_event *event, |
|---|
| 4756 | + struct tep_print_arg *arg) |
|---|
| 4581 | 4757 | { |
|---|
| 4758 | + bool reverse = false; |
|---|
| 4582 | 4759 | unsigned char *buf; |
|---|
| 4760 | + int ret; |
|---|
| 4583 | 4761 | |
|---|
| 4584 | | - if (arg->type == PRINT_FUNC) { |
|---|
| 4762 | + ret = parse_ip4_print_args(event->tep, ptr, &reverse); |
|---|
| 4763 | + |
|---|
| 4764 | + if (arg->type == TEP_PRINT_FUNC) { |
|---|
| 4585 | 4765 | process_defined_func(s, data, size, event, arg); |
|---|
| 4586 | | - return 0; |
|---|
| 4766 | + return ret; |
|---|
| 4587 | 4767 | } |
|---|
| 4588 | 4768 | |
|---|
| 4589 | | - if (arg->type != PRINT_FIELD) { |
|---|
| 4769 | + if (arg->type != TEP_PRINT_FIELD) { |
|---|
| 4590 | 4770 | trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); |
|---|
| 4591 | | - return 0; |
|---|
| 4771 | + return ret; |
|---|
| 4592 | 4772 | } |
|---|
| 4593 | 4773 | |
|---|
| 4594 | 4774 | if (!arg->field.field) { |
|---|
| .. | .. |
|---|
| 4597 | 4777 | if (!arg->field.field) { |
|---|
| 4598 | 4778 | do_warning("%s: field %s not found", |
|---|
| 4599 | 4779 | __func__, arg->field.name); |
|---|
| 4600 | | - return 0; |
|---|
| 4780 | + return ret; |
|---|
| 4601 | 4781 | } |
|---|
| 4602 | 4782 | } |
|---|
| 4603 | 4783 | |
|---|
| .. | .. |
|---|
| 4605 | 4785 | |
|---|
| 4606 | 4786 | if (arg->field.field->size != 4) { |
|---|
| 4607 | 4787 | trace_seq_printf(s, "INVALIDIPv4"); |
|---|
| 4608 | | - return 0; |
|---|
| 4788 | + return ret; |
|---|
| 4609 | 4789 | } |
|---|
| 4610 | | - print_ip4_addr(s, i, buf); |
|---|
| 4611 | 4790 | |
|---|
| 4612 | | - return 0; |
|---|
| 4791 | + print_ip4_addr(s, i, reverse, buf); |
|---|
| 4792 | + return ret; |
|---|
| 4793 | + |
|---|
| 4613 | 4794 | } |
|---|
| 4614 | 4795 | |
|---|
| 4615 | 4796 | static int print_ipv6_arg(struct trace_seq *s, const char *ptr, char i, |
|---|
| 4616 | | - void *data, int size, struct event_format *event, |
|---|
| 4617 | | - struct print_arg *arg) |
|---|
| 4797 | + void *data, int size, struct tep_event *event, |
|---|
| 4798 | + struct tep_print_arg *arg) |
|---|
| 4618 | 4799 | { |
|---|
| 4619 | 4800 | char have_c = 0; |
|---|
| 4620 | 4801 | unsigned char *buf; |
|---|
| .. | .. |
|---|
| 4627 | 4808 | rc++; |
|---|
| 4628 | 4809 | } |
|---|
| 4629 | 4810 | |
|---|
| 4630 | | - if (arg->type == PRINT_FUNC) { |
|---|
| 4811 | + if (arg->type == TEP_PRINT_FUNC) { |
|---|
| 4631 | 4812 | process_defined_func(s, data, size, event, arg); |
|---|
| 4632 | 4813 | return rc; |
|---|
| 4633 | 4814 | } |
|---|
| 4634 | 4815 | |
|---|
| 4635 | | - if (arg->type != PRINT_FIELD) { |
|---|
| 4816 | + if (arg->type != TEP_PRINT_FIELD) { |
|---|
| 4636 | 4817 | trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); |
|---|
| 4637 | 4818 | return rc; |
|---|
| 4638 | 4819 | } |
|---|
| .. | .. |
|---|
| 4663 | 4844 | } |
|---|
| 4664 | 4845 | |
|---|
| 4665 | 4846 | static int print_ipsa_arg(struct trace_seq *s, const char *ptr, char i, |
|---|
| 4666 | | - void *data, int size, struct event_format *event, |
|---|
| 4667 | | - struct print_arg *arg) |
|---|
| 4847 | + void *data, int size, struct tep_event *event, |
|---|
| 4848 | + struct tep_print_arg *arg) |
|---|
| 4668 | 4849 | { |
|---|
| 4669 | 4850 | char have_c = 0, have_p = 0; |
|---|
| 4670 | 4851 | unsigned char *buf; |
|---|
| 4671 | 4852 | struct sockaddr_storage *sa; |
|---|
| 4853 | + bool reverse = false; |
|---|
| 4672 | 4854 | int rc = 0; |
|---|
| 4855 | + int ret; |
|---|
| 4673 | 4856 | |
|---|
| 4674 | 4857 | /* pISpc */ |
|---|
| 4675 | 4858 | if (i == 'I') { |
|---|
| .. | .. |
|---|
| 4684 | 4867 | rc++; |
|---|
| 4685 | 4868 | } |
|---|
| 4686 | 4869 | } |
|---|
| 4870 | + ret = parse_ip4_print_args(event->tep, ptr, &reverse); |
|---|
| 4871 | + ptr += ret; |
|---|
| 4872 | + rc += ret; |
|---|
| 4687 | 4873 | |
|---|
| 4688 | | - if (arg->type == PRINT_FUNC) { |
|---|
| 4874 | + if (arg->type == TEP_PRINT_FUNC) { |
|---|
| 4689 | 4875 | process_defined_func(s, data, size, event, arg); |
|---|
| 4690 | 4876 | return rc; |
|---|
| 4691 | 4877 | } |
|---|
| 4692 | 4878 | |
|---|
| 4693 | | - if (arg->type != PRINT_FIELD) { |
|---|
| 4879 | + if (arg->type != TEP_PRINT_FIELD) { |
|---|
| 4694 | 4880 | trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); |
|---|
| 4695 | 4881 | return rc; |
|---|
| 4696 | 4882 | } |
|---|
| .. | .. |
|---|
| 4715 | 4901 | return rc; |
|---|
| 4716 | 4902 | } |
|---|
| 4717 | 4903 | |
|---|
| 4718 | | - print_ip4_addr(s, i, (unsigned char *) &sa4->sin_addr); |
|---|
| 4904 | + print_ip4_addr(s, i, reverse, (unsigned char *) &sa4->sin_addr); |
|---|
| 4719 | 4905 | if (have_p) |
|---|
| 4720 | 4906 | trace_seq_printf(s, ":%d", ntohs(sa4->sin_port)); |
|---|
| 4721 | 4907 | |
|---|
| .. | .. |
|---|
| 4745 | 4931 | } |
|---|
| 4746 | 4932 | |
|---|
| 4747 | 4933 | static int print_ip_arg(struct trace_seq *s, const char *ptr, |
|---|
| 4748 | | - void *data, int size, struct event_format *event, |
|---|
| 4749 | | - struct print_arg *arg) |
|---|
| 4934 | + void *data, int size, struct tep_event *event, |
|---|
| 4935 | + struct tep_print_arg *arg) |
|---|
| 4750 | 4936 | { |
|---|
| 4751 | 4937 | char i = *ptr; /* 'i' or 'I' */ |
|---|
| 4752 | | - char ver; |
|---|
| 4753 | | - int rc = 0; |
|---|
| 4938 | + int rc = 1; |
|---|
| 4754 | 4939 | |
|---|
| 4940 | + /* IP version */ |
|---|
| 4755 | 4941 | ptr++; |
|---|
| 4756 | | - rc++; |
|---|
| 4757 | 4942 | |
|---|
| 4758 | | - ver = *ptr; |
|---|
| 4759 | | - ptr++; |
|---|
| 4760 | | - rc++; |
|---|
| 4761 | | - |
|---|
| 4762 | | - switch (ver) { |
|---|
| 4943 | + switch (*ptr) { |
|---|
| 4763 | 4944 | case '4': |
|---|
| 4764 | | - rc += print_ipv4_arg(s, ptr, i, data, size, event, arg); |
|---|
| 4945 | + rc += print_ipv4_arg(s, ptr + 1, i, data, size, event, arg); |
|---|
| 4765 | 4946 | break; |
|---|
| 4766 | 4947 | case '6': |
|---|
| 4767 | | - rc += print_ipv6_arg(s, ptr, i, data, size, event, arg); |
|---|
| 4948 | + rc += print_ipv6_arg(s, ptr + 1, i, data, size, event, arg); |
|---|
| 4768 | 4949 | break; |
|---|
| 4769 | 4950 | case 'S': |
|---|
| 4770 | | - rc += print_ipsa_arg(s, ptr, i, data, size, event, arg); |
|---|
| 4951 | + rc += print_ipsa_arg(s, ptr + 1, i, data, size, event, arg); |
|---|
| 4771 | 4952 | break; |
|---|
| 4772 | 4953 | default: |
|---|
| 4773 | 4954 | return 0; |
|---|
| 4774 | 4955 | } |
|---|
| 4775 | 4956 | |
|---|
| 4776 | 4957 | return rc; |
|---|
| 4958 | +} |
|---|
| 4959 | + |
|---|
| 4960 | +static const int guid_index[16] = {3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15}; |
|---|
| 4961 | +static const int uuid_index[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; |
|---|
| 4962 | + |
|---|
| 4963 | +static int print_uuid_arg(struct trace_seq *s, const char *ptr, |
|---|
| 4964 | + void *data, int size, struct tep_event *event, |
|---|
| 4965 | + struct tep_print_arg *arg) |
|---|
| 4966 | +{ |
|---|
| 4967 | + const int *index = uuid_index; |
|---|
| 4968 | + char *format = "%02x"; |
|---|
| 4969 | + int ret = 0; |
|---|
| 4970 | + char *buf; |
|---|
| 4971 | + int i; |
|---|
| 4972 | + |
|---|
| 4973 | + switch (*(ptr + 1)) { |
|---|
| 4974 | + case 'L': |
|---|
| 4975 | + format = "%02X"; |
|---|
| 4976 | + /* fall through */ |
|---|
| 4977 | + case 'l': |
|---|
| 4978 | + index = guid_index; |
|---|
| 4979 | + ret++; |
|---|
| 4980 | + break; |
|---|
| 4981 | + case 'B': |
|---|
| 4982 | + format = "%02X"; |
|---|
| 4983 | + /* fall through */ |
|---|
| 4984 | + case 'b': |
|---|
| 4985 | + ret++; |
|---|
| 4986 | + break; |
|---|
| 4987 | + } |
|---|
| 4988 | + |
|---|
| 4989 | + if (arg->type == TEP_PRINT_FUNC) { |
|---|
| 4990 | + process_defined_func(s, data, size, event, arg); |
|---|
| 4991 | + return ret; |
|---|
| 4992 | + } |
|---|
| 4993 | + |
|---|
| 4994 | + if (arg->type != TEP_PRINT_FIELD) { |
|---|
| 4995 | + trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); |
|---|
| 4996 | + return ret; |
|---|
| 4997 | + } |
|---|
| 4998 | + |
|---|
| 4999 | + if (!arg->field.field) { |
|---|
| 5000 | + arg->field.field = |
|---|
| 5001 | + tep_find_any_field(event, arg->field.name); |
|---|
| 5002 | + if (!arg->field.field) { |
|---|
| 5003 | + do_warning("%s: field %s not found", |
|---|
| 5004 | + __func__, arg->field.name); |
|---|
| 5005 | + return ret; |
|---|
| 5006 | + } |
|---|
| 5007 | + } |
|---|
| 5008 | + |
|---|
| 5009 | + if (arg->field.field->size != 16) { |
|---|
| 5010 | + trace_seq_printf(s, "INVALIDUUID"); |
|---|
| 5011 | + return ret; |
|---|
| 5012 | + } |
|---|
| 5013 | + |
|---|
| 5014 | + buf = data + arg->field.field->offset; |
|---|
| 5015 | + |
|---|
| 5016 | + for (i = 0; i < 16; i++) { |
|---|
| 5017 | + trace_seq_printf(s, format, buf[index[i]] & 0xff); |
|---|
| 5018 | + switch (i) { |
|---|
| 5019 | + case 3: |
|---|
| 5020 | + case 5: |
|---|
| 5021 | + case 7: |
|---|
| 5022 | + case 9: |
|---|
| 5023 | + trace_seq_printf(s, "-"); |
|---|
| 5024 | + break; |
|---|
| 5025 | + } |
|---|
| 5026 | + } |
|---|
| 5027 | + |
|---|
| 5028 | + return ret; |
|---|
| 5029 | +} |
|---|
| 5030 | + |
|---|
| 5031 | +static int print_raw_buff_arg(struct trace_seq *s, const char *ptr, |
|---|
| 5032 | + void *data, int size, struct tep_event *event, |
|---|
| 5033 | + struct tep_print_arg *arg, int print_len) |
|---|
| 5034 | +{ |
|---|
| 5035 | + int plen = print_len; |
|---|
| 5036 | + char *delim = " "; |
|---|
| 5037 | + int ret = 0; |
|---|
| 5038 | + char *buf; |
|---|
| 5039 | + int i; |
|---|
| 5040 | + unsigned long offset; |
|---|
| 5041 | + int arr_len; |
|---|
| 5042 | + |
|---|
| 5043 | + switch (*(ptr + 1)) { |
|---|
| 5044 | + case 'C': |
|---|
| 5045 | + delim = ":"; |
|---|
| 5046 | + ret++; |
|---|
| 5047 | + break; |
|---|
| 5048 | + case 'D': |
|---|
| 5049 | + delim = "-"; |
|---|
| 5050 | + ret++; |
|---|
| 5051 | + break; |
|---|
| 5052 | + case 'N': |
|---|
| 5053 | + delim = ""; |
|---|
| 5054 | + ret++; |
|---|
| 5055 | + break; |
|---|
| 5056 | + } |
|---|
| 5057 | + |
|---|
| 5058 | + if (arg->type == TEP_PRINT_FUNC) { |
|---|
| 5059 | + process_defined_func(s, data, size, event, arg); |
|---|
| 5060 | + return ret; |
|---|
| 5061 | + } |
|---|
| 5062 | + |
|---|
| 5063 | + if (arg->type != TEP_PRINT_DYNAMIC_ARRAY) { |
|---|
| 5064 | + trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); |
|---|
| 5065 | + return ret; |
|---|
| 5066 | + } |
|---|
| 5067 | + |
|---|
| 5068 | + offset = tep_read_number(event->tep, |
|---|
| 5069 | + data + arg->dynarray.field->offset, |
|---|
| 5070 | + arg->dynarray.field->size); |
|---|
| 5071 | + arr_len = (unsigned long long)(offset >> 16); |
|---|
| 5072 | + buf = data + (offset & 0xffff); |
|---|
| 5073 | + |
|---|
| 5074 | + if (arr_len < plen) |
|---|
| 5075 | + plen = arr_len; |
|---|
| 5076 | + |
|---|
| 5077 | + if (plen < 1) |
|---|
| 5078 | + return ret; |
|---|
| 5079 | + |
|---|
| 5080 | + trace_seq_printf(s, "%02x", buf[0] & 0xff); |
|---|
| 5081 | + for (i = 1; i < plen; i++) |
|---|
| 5082 | + trace_seq_printf(s, "%s%02x", delim, buf[i] & 0xff); |
|---|
| 5083 | + |
|---|
| 5084 | + return ret; |
|---|
| 4777 | 5085 | } |
|---|
| 4778 | 5086 | |
|---|
| 4779 | 5087 | static int is_printable_array(char *p, unsigned int len) |
|---|
| .. | .. |
|---|
| 4787 | 5095 | } |
|---|
| 4788 | 5096 | |
|---|
| 4789 | 5097 | void tep_print_field(struct trace_seq *s, void *data, |
|---|
| 4790 | | - struct format_field *field) |
|---|
| 5098 | + struct tep_format_field *field) |
|---|
| 4791 | 5099 | { |
|---|
| 4792 | 5100 | unsigned long long val; |
|---|
| 4793 | 5101 | unsigned int offset, len, i; |
|---|
| 4794 | | - struct tep_handle *pevent = field->event->pevent; |
|---|
| 5102 | + struct tep_handle *tep = field->event->tep; |
|---|
| 4795 | 5103 | |
|---|
| 4796 | | - if (field->flags & FIELD_IS_ARRAY) { |
|---|
| 5104 | + if (field->flags & TEP_FIELD_IS_ARRAY) { |
|---|
| 4797 | 5105 | offset = field->offset; |
|---|
| 4798 | 5106 | len = field->size; |
|---|
| 4799 | | - if (field->flags & FIELD_IS_DYNAMIC) { |
|---|
| 4800 | | - val = tep_read_number(pevent, data + offset, len); |
|---|
| 5107 | + if (field->flags & TEP_FIELD_IS_DYNAMIC) { |
|---|
| 5108 | + val = tep_read_number(tep, data + offset, len); |
|---|
| 4801 | 5109 | offset = val; |
|---|
| 4802 | 5110 | len = offset >> 16; |
|---|
| 4803 | 5111 | offset &= 0xffff; |
|---|
| 4804 | 5112 | } |
|---|
| 4805 | | - if (field->flags & FIELD_IS_STRING && |
|---|
| 5113 | + if (field->flags & TEP_FIELD_IS_STRING && |
|---|
| 4806 | 5114 | is_printable_array(data + offset, len)) { |
|---|
| 4807 | 5115 | trace_seq_printf(s, "%s", (char *)data + offset); |
|---|
| 4808 | 5116 | } else { |
|---|
| .. | .. |
|---|
| 4814 | 5122 | *((unsigned char *)data + offset + i)); |
|---|
| 4815 | 5123 | } |
|---|
| 4816 | 5124 | trace_seq_putc(s, ']'); |
|---|
| 4817 | | - field->flags &= ~FIELD_IS_STRING; |
|---|
| 5125 | + field->flags &= ~TEP_FIELD_IS_STRING; |
|---|
| 4818 | 5126 | } |
|---|
| 4819 | 5127 | } else { |
|---|
| 4820 | | - val = tep_read_number(pevent, data + field->offset, |
|---|
| 5128 | + val = tep_read_number(tep, data + field->offset, |
|---|
| 4821 | 5129 | field->size); |
|---|
| 4822 | | - if (field->flags & FIELD_IS_POINTER) { |
|---|
| 5130 | + if (field->flags & TEP_FIELD_IS_POINTER) { |
|---|
| 4823 | 5131 | trace_seq_printf(s, "0x%llx", val); |
|---|
| 4824 | | - } else if (field->flags & FIELD_IS_SIGNED) { |
|---|
| 5132 | + } else if (field->flags & TEP_FIELD_IS_SIGNED) { |
|---|
| 4825 | 5133 | switch (field->size) { |
|---|
| 4826 | 5134 | case 4: |
|---|
| 4827 | 5135 | /* |
|---|
| 4828 | 5136 | * If field is long then print it in hex. |
|---|
| 4829 | 5137 | * A long usually stores pointers. |
|---|
| 4830 | 5138 | */ |
|---|
| 4831 | | - if (field->flags & FIELD_IS_LONG) |
|---|
| 5139 | + if (field->flags & TEP_FIELD_IS_LONG) |
|---|
| 4832 | 5140 | trace_seq_printf(s, "0x%x", (int)val); |
|---|
| 4833 | 5141 | else |
|---|
| 4834 | 5142 | trace_seq_printf(s, "%d", (int)val); |
|---|
| .. | .. |
|---|
| 4843 | 5151 | trace_seq_printf(s, "%lld", val); |
|---|
| 4844 | 5152 | } |
|---|
| 4845 | 5153 | } else { |
|---|
| 4846 | | - if (field->flags & FIELD_IS_LONG) |
|---|
| 5154 | + if (field->flags & TEP_FIELD_IS_LONG) |
|---|
| 4847 | 5155 | trace_seq_printf(s, "0x%llx", val); |
|---|
| 4848 | 5156 | else |
|---|
| 4849 | 5157 | trace_seq_printf(s, "%llu", val); |
|---|
| .. | .. |
|---|
| 4852 | 5160 | } |
|---|
| 4853 | 5161 | |
|---|
| 4854 | 5162 | void tep_print_fields(struct trace_seq *s, void *data, |
|---|
| 4855 | | - int size __maybe_unused, struct event_format *event) |
|---|
| 5163 | + int size __maybe_unused, struct tep_event *event) |
|---|
| 4856 | 5164 | { |
|---|
| 4857 | | - struct format_field *field; |
|---|
| 5165 | + struct tep_format_field *field; |
|---|
| 4858 | 5166 | |
|---|
| 4859 | 5167 | field = event->format.fields; |
|---|
| 4860 | 5168 | while (field) { |
|---|
| .. | .. |
|---|
| 4864 | 5172 | } |
|---|
| 4865 | 5173 | } |
|---|
| 4866 | 5174 | |
|---|
| 4867 | | -static void pretty_print(struct trace_seq *s, void *data, int size, struct event_format *event) |
|---|
| 5175 | +static int print_function(struct trace_seq *s, const char *format, |
|---|
| 5176 | + void *data, int size, struct tep_event *event, |
|---|
| 5177 | + struct tep_print_arg *arg) |
|---|
| 4868 | 5178 | { |
|---|
| 4869 | | - struct tep_handle *pevent = event->pevent; |
|---|
| 4870 | | - struct print_fmt *print_fmt = &event->print_fmt; |
|---|
| 4871 | | - struct print_arg *arg = print_fmt->args; |
|---|
| 4872 | | - struct print_arg *args = NULL; |
|---|
| 4873 | | - const char *ptr = print_fmt->format; |
|---|
| 4874 | | - unsigned long long val; |
|---|
| 4875 | 5179 | struct func_map *func; |
|---|
| 4876 | | - const char *saveptr; |
|---|
| 4877 | | - struct trace_seq p; |
|---|
| 4878 | | - char *bprint_fmt = NULL; |
|---|
| 4879 | | - char format[32]; |
|---|
| 4880 | | - int show_func; |
|---|
| 4881 | | - int len_as_arg; |
|---|
| 4882 | | - int len_arg; |
|---|
| 4883 | | - int len; |
|---|
| 4884 | | - int ls; |
|---|
| 5180 | + unsigned long long val; |
|---|
| 4885 | 5181 | |
|---|
| 4886 | | - if (event->flags & EVENT_FL_FAILED) { |
|---|
| 5182 | + val = eval_num_arg(data, size, event, arg); |
|---|
| 5183 | + func = find_func(event->tep, val); |
|---|
| 5184 | + if (func) { |
|---|
| 5185 | + trace_seq_puts(s, func->func); |
|---|
| 5186 | + if (*format == 'F' || *format == 'S') |
|---|
| 5187 | + trace_seq_printf(s, "+0x%llx", val - func->addr); |
|---|
| 5188 | + } else { |
|---|
| 5189 | + if (event->tep->long_size == 4) |
|---|
| 5190 | + trace_seq_printf(s, "0x%lx", (long)val); |
|---|
| 5191 | + else |
|---|
| 5192 | + trace_seq_printf(s, "0x%llx", (long long)val); |
|---|
| 5193 | + } |
|---|
| 5194 | + |
|---|
| 5195 | + return 0; |
|---|
| 5196 | +} |
|---|
| 5197 | + |
|---|
| 5198 | +static int print_arg_pointer(struct trace_seq *s, const char *format, int plen, |
|---|
| 5199 | + void *data, int size, |
|---|
| 5200 | + struct tep_event *event, struct tep_print_arg *arg) |
|---|
| 5201 | +{ |
|---|
| 5202 | + unsigned long long val; |
|---|
| 5203 | + int ret = 1; |
|---|
| 5204 | + |
|---|
| 5205 | + if (arg->type == TEP_PRINT_BSTRING) { |
|---|
| 5206 | + trace_seq_puts(s, arg->string.string); |
|---|
| 5207 | + return 0; |
|---|
| 5208 | + } |
|---|
| 5209 | + while (*format) { |
|---|
| 5210 | + if (*format == 'p') { |
|---|
| 5211 | + format++; |
|---|
| 5212 | + break; |
|---|
| 5213 | + } |
|---|
| 5214 | + format++; |
|---|
| 5215 | + } |
|---|
| 5216 | + |
|---|
| 5217 | + switch (*format) { |
|---|
| 5218 | + case 'F': |
|---|
| 5219 | + case 'f': |
|---|
| 5220 | + case 'S': |
|---|
| 5221 | + case 's': |
|---|
| 5222 | + ret += print_function(s, format, data, size, event, arg); |
|---|
| 5223 | + break; |
|---|
| 5224 | + case 'M': |
|---|
| 5225 | + case 'm': |
|---|
| 5226 | + ret += print_mac_arg(s, format, data, size, event, arg); |
|---|
| 5227 | + break; |
|---|
| 5228 | + case 'I': |
|---|
| 5229 | + case 'i': |
|---|
| 5230 | + ret += print_ip_arg(s, format, data, size, event, arg); |
|---|
| 5231 | + break; |
|---|
| 5232 | + case 'U': |
|---|
| 5233 | + ret += print_uuid_arg(s, format, data, size, event, arg); |
|---|
| 5234 | + break; |
|---|
| 5235 | + case 'h': |
|---|
| 5236 | + ret += print_raw_buff_arg(s, format, data, size, event, arg, plen); |
|---|
| 5237 | + break; |
|---|
| 5238 | + default: |
|---|
| 5239 | + ret = 0; |
|---|
| 5240 | + val = eval_num_arg(data, size, event, arg); |
|---|
| 5241 | + trace_seq_printf(s, "%p", (void *)(intptr_t)val); |
|---|
| 5242 | + break; |
|---|
| 5243 | + } |
|---|
| 5244 | + |
|---|
| 5245 | + return ret; |
|---|
| 5246 | + |
|---|
| 5247 | +} |
|---|
| 5248 | + |
|---|
| 5249 | +static int print_arg_number(struct trace_seq *s, const char *format, int plen, |
|---|
| 5250 | + void *data, int size, int ls, |
|---|
| 5251 | + struct tep_event *event, struct tep_print_arg *arg) |
|---|
| 5252 | +{ |
|---|
| 5253 | + unsigned long long val; |
|---|
| 5254 | + |
|---|
| 5255 | + val = eval_num_arg(data, size, event, arg); |
|---|
| 5256 | + |
|---|
| 5257 | + switch (ls) { |
|---|
| 5258 | + case -2: |
|---|
| 5259 | + if (plen >= 0) |
|---|
| 5260 | + trace_seq_printf(s, format, plen, (char)val); |
|---|
| 5261 | + else |
|---|
| 5262 | + trace_seq_printf(s, format, (char)val); |
|---|
| 5263 | + break; |
|---|
| 5264 | + case -1: |
|---|
| 5265 | + if (plen >= 0) |
|---|
| 5266 | + trace_seq_printf(s, format, plen, (short)val); |
|---|
| 5267 | + else |
|---|
| 5268 | + trace_seq_printf(s, format, (short)val); |
|---|
| 5269 | + break; |
|---|
| 5270 | + case 0: |
|---|
| 5271 | + if (plen >= 0) |
|---|
| 5272 | + trace_seq_printf(s, format, plen, (int)val); |
|---|
| 5273 | + else |
|---|
| 5274 | + trace_seq_printf(s, format, (int)val); |
|---|
| 5275 | + break; |
|---|
| 5276 | + case 1: |
|---|
| 5277 | + if (plen >= 0) |
|---|
| 5278 | + trace_seq_printf(s, format, plen, (long)val); |
|---|
| 5279 | + else |
|---|
| 5280 | + trace_seq_printf(s, format, (long)val); |
|---|
| 5281 | + break; |
|---|
| 5282 | + case 2: |
|---|
| 5283 | + if (plen >= 0) |
|---|
| 5284 | + trace_seq_printf(s, format, plen, (long long)val); |
|---|
| 5285 | + else |
|---|
| 5286 | + trace_seq_printf(s, format, (long long)val); |
|---|
| 5287 | + break; |
|---|
| 5288 | + default: |
|---|
| 5289 | + do_warning_event(event, "bad count (%d)", ls); |
|---|
| 5290 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 5291 | + } |
|---|
| 5292 | + return 0; |
|---|
| 5293 | +} |
|---|
| 5294 | + |
|---|
| 5295 | + |
|---|
| 5296 | +static void print_arg_string(struct trace_seq *s, const char *format, int plen, |
|---|
| 5297 | + void *data, int size, |
|---|
| 5298 | + struct tep_event *event, struct tep_print_arg *arg) |
|---|
| 5299 | +{ |
|---|
| 5300 | + struct trace_seq p; |
|---|
| 5301 | + |
|---|
| 5302 | + /* Use helper trace_seq */ |
|---|
| 5303 | + trace_seq_init(&p); |
|---|
| 5304 | + print_str_arg(&p, data, size, event, |
|---|
| 5305 | + format, plen, arg); |
|---|
| 5306 | + trace_seq_terminate(&p); |
|---|
| 5307 | + trace_seq_puts(s, p.buffer); |
|---|
| 5308 | + trace_seq_destroy(&p); |
|---|
| 5309 | +} |
|---|
| 5310 | + |
|---|
| 5311 | +static int parse_arg_format_pointer(const char *format) |
|---|
| 5312 | +{ |
|---|
| 5313 | + int ret = 0; |
|---|
| 5314 | + int index; |
|---|
| 5315 | + int loop; |
|---|
| 5316 | + |
|---|
| 5317 | + switch (*format) { |
|---|
| 5318 | + case 'F': |
|---|
| 5319 | + case 'S': |
|---|
| 5320 | + case 'f': |
|---|
| 5321 | + case 's': |
|---|
| 5322 | + ret++; |
|---|
| 5323 | + break; |
|---|
| 5324 | + case 'M': |
|---|
| 5325 | + case 'm': |
|---|
| 5326 | + /* [mM]R , [mM]F */ |
|---|
| 5327 | + switch (format[1]) { |
|---|
| 5328 | + case 'R': |
|---|
| 5329 | + case 'F': |
|---|
| 5330 | + ret++; |
|---|
| 5331 | + break; |
|---|
| 5332 | + } |
|---|
| 5333 | + ret++; |
|---|
| 5334 | + break; |
|---|
| 5335 | + case 'I': |
|---|
| 5336 | + case 'i': |
|---|
| 5337 | + index = 2; |
|---|
| 5338 | + loop = 1; |
|---|
| 5339 | + switch (format[1]) { |
|---|
| 5340 | + case 'S': |
|---|
| 5341 | + /*[S][pfs]*/ |
|---|
| 5342 | + while (loop) { |
|---|
| 5343 | + switch (format[index]) { |
|---|
| 5344 | + case 'p': |
|---|
| 5345 | + case 'f': |
|---|
| 5346 | + case 's': |
|---|
| 5347 | + ret++; |
|---|
| 5348 | + index++; |
|---|
| 5349 | + break; |
|---|
| 5350 | + default: |
|---|
| 5351 | + loop = 0; |
|---|
| 5352 | + break; |
|---|
| 5353 | + } |
|---|
| 5354 | + } |
|---|
| 5355 | + /* fall through */ |
|---|
| 5356 | + case '4': |
|---|
| 5357 | + /* [4S][hnbl] */ |
|---|
| 5358 | + switch (format[index]) { |
|---|
| 5359 | + case 'h': |
|---|
| 5360 | + case 'n': |
|---|
| 5361 | + case 'l': |
|---|
| 5362 | + case 'b': |
|---|
| 5363 | + ret++; |
|---|
| 5364 | + index++; |
|---|
| 5365 | + break; |
|---|
| 5366 | + } |
|---|
| 5367 | + if (format[1] == '4') { |
|---|
| 5368 | + ret++; |
|---|
| 5369 | + break; |
|---|
| 5370 | + } |
|---|
| 5371 | + /* fall through */ |
|---|
| 5372 | + case '6': |
|---|
| 5373 | + /* [6S]c */ |
|---|
| 5374 | + if (format[index] == 'c') |
|---|
| 5375 | + ret++; |
|---|
| 5376 | + ret++; |
|---|
| 5377 | + break; |
|---|
| 5378 | + } |
|---|
| 5379 | + ret++; |
|---|
| 5380 | + break; |
|---|
| 5381 | + case 'U': |
|---|
| 5382 | + switch (format[1]) { |
|---|
| 5383 | + case 'L': |
|---|
| 5384 | + case 'l': |
|---|
| 5385 | + case 'B': |
|---|
| 5386 | + case 'b': |
|---|
| 5387 | + ret++; |
|---|
| 5388 | + break; |
|---|
| 5389 | + } |
|---|
| 5390 | + ret++; |
|---|
| 5391 | + break; |
|---|
| 5392 | + case 'h': |
|---|
| 5393 | + switch (format[1]) { |
|---|
| 5394 | + case 'C': |
|---|
| 5395 | + case 'D': |
|---|
| 5396 | + case 'N': |
|---|
| 5397 | + ret++; |
|---|
| 5398 | + break; |
|---|
| 5399 | + } |
|---|
| 5400 | + ret++; |
|---|
| 5401 | + break; |
|---|
| 5402 | + default: |
|---|
| 5403 | + break; |
|---|
| 5404 | + } |
|---|
| 5405 | + |
|---|
| 5406 | + return ret; |
|---|
| 5407 | +} |
|---|
| 5408 | + |
|---|
| 5409 | +static void free_parse_args(struct tep_print_parse *arg) |
|---|
| 5410 | +{ |
|---|
| 5411 | + struct tep_print_parse *del; |
|---|
| 5412 | + |
|---|
| 5413 | + while (arg) { |
|---|
| 5414 | + del = arg; |
|---|
| 5415 | + arg = del->next; |
|---|
| 5416 | + free(del->format); |
|---|
| 5417 | + free(del); |
|---|
| 5418 | + } |
|---|
| 5419 | +} |
|---|
| 5420 | + |
|---|
| 5421 | +static int parse_arg_add(struct tep_print_parse **parse, char *format, |
|---|
| 5422 | + enum tep_print_parse_type type, |
|---|
| 5423 | + struct tep_print_arg *arg, |
|---|
| 5424 | + struct tep_print_arg *len_as_arg, |
|---|
| 5425 | + int ls) |
|---|
| 5426 | +{ |
|---|
| 5427 | + struct tep_print_parse *parg = NULL; |
|---|
| 5428 | + |
|---|
| 5429 | + parg = calloc(1, sizeof(*parg)); |
|---|
| 5430 | + if (!parg) |
|---|
| 5431 | + goto error; |
|---|
| 5432 | + parg->format = strdup(format); |
|---|
| 5433 | + if (!parg->format) |
|---|
| 5434 | + goto error; |
|---|
| 5435 | + parg->type = type; |
|---|
| 5436 | + parg->arg = arg; |
|---|
| 5437 | + parg->len_as_arg = len_as_arg; |
|---|
| 5438 | + parg->ls = ls; |
|---|
| 5439 | + *parse = parg; |
|---|
| 5440 | + return 0; |
|---|
| 5441 | +error: |
|---|
| 5442 | + if (parg) { |
|---|
| 5443 | + free(parg->format); |
|---|
| 5444 | + free(parg); |
|---|
| 5445 | + } |
|---|
| 5446 | + return -1; |
|---|
| 5447 | +} |
|---|
| 5448 | + |
|---|
| 5449 | +static int parse_arg_format(struct tep_print_parse **parse, |
|---|
| 5450 | + struct tep_event *event, |
|---|
| 5451 | + const char *format, struct tep_print_arg **arg) |
|---|
| 5452 | +{ |
|---|
| 5453 | + struct tep_print_arg *len_arg = NULL; |
|---|
| 5454 | + char print_format[32]; |
|---|
| 5455 | + const char *start = format; |
|---|
| 5456 | + int ret = 0; |
|---|
| 5457 | + int ls = 0; |
|---|
| 5458 | + int res; |
|---|
| 5459 | + int len; |
|---|
| 5460 | + |
|---|
| 5461 | + format++; |
|---|
| 5462 | + ret++; |
|---|
| 5463 | + for (; *format; format++) { |
|---|
| 5464 | + switch (*format) { |
|---|
| 5465 | + case '#': |
|---|
| 5466 | + /* FIXME: need to handle properly */ |
|---|
| 5467 | + break; |
|---|
| 5468 | + case 'h': |
|---|
| 5469 | + ls--; |
|---|
| 5470 | + break; |
|---|
| 5471 | + case 'l': |
|---|
| 5472 | + ls++; |
|---|
| 5473 | + break; |
|---|
| 5474 | + case 'L': |
|---|
| 5475 | + ls = 2; |
|---|
| 5476 | + break; |
|---|
| 5477 | + case '.': |
|---|
| 5478 | + case 'z': |
|---|
| 5479 | + case 'Z': |
|---|
| 5480 | + case '0' ... '9': |
|---|
| 5481 | + case '-': |
|---|
| 5482 | + break; |
|---|
| 5483 | + case '*': |
|---|
| 5484 | + /* The argument is the length. */ |
|---|
| 5485 | + if (!*arg) { |
|---|
| 5486 | + do_warning_event(event, "no argument match"); |
|---|
| 5487 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 5488 | + goto out_failed; |
|---|
| 5489 | + } |
|---|
| 5490 | + if (len_arg) { |
|---|
| 5491 | + do_warning_event(event, "argument already matched"); |
|---|
| 5492 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 5493 | + goto out_failed; |
|---|
| 5494 | + } |
|---|
| 5495 | + len_arg = *arg; |
|---|
| 5496 | + *arg = (*arg)->next; |
|---|
| 5497 | + break; |
|---|
| 5498 | + case 'p': |
|---|
| 5499 | + if (!*arg) { |
|---|
| 5500 | + do_warning_event(event, "no argument match"); |
|---|
| 5501 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 5502 | + goto out_failed; |
|---|
| 5503 | + } |
|---|
| 5504 | + res = parse_arg_format_pointer(format + 1); |
|---|
| 5505 | + if (res > 0) { |
|---|
| 5506 | + format += res; |
|---|
| 5507 | + ret += res; |
|---|
| 5508 | + } |
|---|
| 5509 | + len = ((unsigned long)format + 1) - |
|---|
| 5510 | + (unsigned long)start; |
|---|
| 5511 | + /* should never happen */ |
|---|
| 5512 | + if (len > 31) { |
|---|
| 5513 | + do_warning_event(event, "bad format!"); |
|---|
| 5514 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 5515 | + len = 31; |
|---|
| 5516 | + } |
|---|
| 5517 | + memcpy(print_format, start, len); |
|---|
| 5518 | + print_format[len] = 0; |
|---|
| 5519 | + |
|---|
| 5520 | + parse_arg_add(parse, print_format, |
|---|
| 5521 | + PRINT_FMT_ARG_POINTER, *arg, len_arg, ls); |
|---|
| 5522 | + *arg = (*arg)->next; |
|---|
| 5523 | + ret++; |
|---|
| 5524 | + return ret; |
|---|
| 5525 | + case 'd': |
|---|
| 5526 | + case 'u': |
|---|
| 5527 | + case 'i': |
|---|
| 5528 | + case 'x': |
|---|
| 5529 | + case 'X': |
|---|
| 5530 | + case 'o': |
|---|
| 5531 | + if (!*arg) { |
|---|
| 5532 | + do_warning_event(event, "no argument match"); |
|---|
| 5533 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 5534 | + goto out_failed; |
|---|
| 5535 | + } |
|---|
| 5536 | + |
|---|
| 5537 | + len = ((unsigned long)format + 1) - |
|---|
| 5538 | + (unsigned long)start; |
|---|
| 5539 | + |
|---|
| 5540 | + /* should never happen */ |
|---|
| 5541 | + if (len > 30) { |
|---|
| 5542 | + do_warning_event(event, "bad format!"); |
|---|
| 5543 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 5544 | + len = 31; |
|---|
| 5545 | + } |
|---|
| 5546 | + memcpy(print_format, start, len); |
|---|
| 5547 | + print_format[len] = 0; |
|---|
| 5548 | + |
|---|
| 5549 | + if (event->tep->long_size == 8 && ls == 1 && |
|---|
| 5550 | + sizeof(long) != 8) { |
|---|
| 5551 | + char *p; |
|---|
| 5552 | + |
|---|
| 5553 | + /* make %l into %ll */ |
|---|
| 5554 | + if (ls == 1 && (p = strchr(print_format, 'l'))) |
|---|
| 5555 | + memmove(p+1, p, strlen(p)+1); |
|---|
| 5556 | + ls = 2; |
|---|
| 5557 | + } |
|---|
| 5558 | + if (ls < -2 || ls > 2) { |
|---|
| 5559 | + do_warning_event(event, "bad count (%d)", ls); |
|---|
| 5560 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 5561 | + } |
|---|
| 5562 | + parse_arg_add(parse, print_format, |
|---|
| 5563 | + PRINT_FMT_ARG_DIGIT, *arg, len_arg, ls); |
|---|
| 5564 | + *arg = (*arg)->next; |
|---|
| 5565 | + ret++; |
|---|
| 5566 | + return ret; |
|---|
| 5567 | + case 's': |
|---|
| 5568 | + if (!*arg) { |
|---|
| 5569 | + do_warning_event(event, "no matching argument"); |
|---|
| 5570 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 5571 | + goto out_failed; |
|---|
| 5572 | + } |
|---|
| 5573 | + |
|---|
| 5574 | + len = ((unsigned long)format + 1) - |
|---|
| 5575 | + (unsigned long)start; |
|---|
| 5576 | + |
|---|
| 5577 | + /* should never happen */ |
|---|
| 5578 | + if (len > 31) { |
|---|
| 5579 | + do_warning_event(event, "bad format!"); |
|---|
| 5580 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 5581 | + len = 31; |
|---|
| 5582 | + } |
|---|
| 5583 | + |
|---|
| 5584 | + memcpy(print_format, start, len); |
|---|
| 5585 | + print_format[len] = 0; |
|---|
| 5586 | + |
|---|
| 5587 | + parse_arg_add(parse, print_format, |
|---|
| 5588 | + PRINT_FMT_ARG_STRING, *arg, len_arg, 0); |
|---|
| 5589 | + *arg = (*arg)->next; |
|---|
| 5590 | + ret++; |
|---|
| 5591 | + return ret; |
|---|
| 5592 | + default: |
|---|
| 5593 | + snprintf(print_format, 32, ">%c<", *format); |
|---|
| 5594 | + parse_arg_add(parse, print_format, |
|---|
| 5595 | + PRINT_FMT_STRING, NULL, NULL, 0); |
|---|
| 5596 | + ret++; |
|---|
| 5597 | + return ret; |
|---|
| 5598 | + } |
|---|
| 5599 | + ret++; |
|---|
| 5600 | + } |
|---|
| 5601 | + |
|---|
| 5602 | +out_failed: |
|---|
| 5603 | + return ret; |
|---|
| 5604 | + |
|---|
| 5605 | +} |
|---|
| 5606 | + |
|---|
| 5607 | +static int parse_arg_string(struct tep_print_parse **parse, const char *format) |
|---|
| 5608 | +{ |
|---|
| 5609 | + struct trace_seq s; |
|---|
| 5610 | + int ret = 0; |
|---|
| 5611 | + |
|---|
| 5612 | + trace_seq_init(&s); |
|---|
| 5613 | + for (; *format; format++) { |
|---|
| 5614 | + if (*format == '\\') { |
|---|
| 5615 | + format++; |
|---|
| 5616 | + ret++; |
|---|
| 5617 | + switch (*format) { |
|---|
| 5618 | + case 'n': |
|---|
| 5619 | + trace_seq_putc(&s, '\n'); |
|---|
| 5620 | + break; |
|---|
| 5621 | + case 't': |
|---|
| 5622 | + trace_seq_putc(&s, '\t'); |
|---|
| 5623 | + break; |
|---|
| 5624 | + case 'r': |
|---|
| 5625 | + trace_seq_putc(&s, '\r'); |
|---|
| 5626 | + break; |
|---|
| 5627 | + case '\\': |
|---|
| 5628 | + trace_seq_putc(&s, '\\'); |
|---|
| 5629 | + break; |
|---|
| 5630 | + default: |
|---|
| 5631 | + trace_seq_putc(&s, *format); |
|---|
| 5632 | + break; |
|---|
| 5633 | + } |
|---|
| 5634 | + } else if (*format == '%') { |
|---|
| 5635 | + if (*(format + 1) == '%') { |
|---|
| 5636 | + trace_seq_putc(&s, '%'); |
|---|
| 5637 | + format++; |
|---|
| 5638 | + ret++; |
|---|
| 5639 | + } else |
|---|
| 5640 | + break; |
|---|
| 5641 | + } else |
|---|
| 5642 | + trace_seq_putc(&s, *format); |
|---|
| 5643 | + |
|---|
| 5644 | + ret++; |
|---|
| 5645 | + } |
|---|
| 5646 | + trace_seq_terminate(&s); |
|---|
| 5647 | + parse_arg_add(parse, s.buffer, PRINT_FMT_STRING, NULL, NULL, 0); |
|---|
| 5648 | + trace_seq_destroy(&s); |
|---|
| 5649 | + |
|---|
| 5650 | + return ret; |
|---|
| 5651 | +} |
|---|
| 5652 | + |
|---|
| 5653 | +static struct tep_print_parse * |
|---|
| 5654 | +parse_args(struct tep_event *event, const char *format, struct tep_print_arg *arg) |
|---|
| 5655 | +{ |
|---|
| 5656 | + struct tep_print_parse *parse_ret = NULL; |
|---|
| 5657 | + struct tep_print_parse **parse = NULL; |
|---|
| 5658 | + int ret; |
|---|
| 5659 | + int len; |
|---|
| 5660 | + |
|---|
| 5661 | + len = strlen(format); |
|---|
| 5662 | + while (*format) { |
|---|
| 5663 | + if (!parse_ret) |
|---|
| 5664 | + parse = &parse_ret; |
|---|
| 5665 | + if (*format == '%' && *(format + 1) != '%') |
|---|
| 5666 | + ret = parse_arg_format(parse, event, format, &arg); |
|---|
| 5667 | + else |
|---|
| 5668 | + ret = parse_arg_string(parse, format); |
|---|
| 5669 | + if (*parse) |
|---|
| 5670 | + parse = &((*parse)->next); |
|---|
| 5671 | + |
|---|
| 5672 | + len -= ret; |
|---|
| 5673 | + if (len > 0) |
|---|
| 5674 | + format += ret; |
|---|
| 5675 | + else |
|---|
| 5676 | + break; |
|---|
| 5677 | + } |
|---|
| 5678 | + return parse_ret; |
|---|
| 5679 | +} |
|---|
| 5680 | + |
|---|
| 5681 | +static void print_event_cache(struct tep_print_parse *parse, struct trace_seq *s, |
|---|
| 5682 | + void *data, int size, struct tep_event *event) |
|---|
| 5683 | +{ |
|---|
| 5684 | + int len_arg; |
|---|
| 5685 | + |
|---|
| 5686 | + while (parse) { |
|---|
| 5687 | + if (parse->len_as_arg) |
|---|
| 5688 | + len_arg = eval_num_arg(data, size, event, parse->len_as_arg); |
|---|
| 5689 | + switch (parse->type) { |
|---|
| 5690 | + case PRINT_FMT_ARG_DIGIT: |
|---|
| 5691 | + print_arg_number(s, parse->format, |
|---|
| 5692 | + parse->len_as_arg ? len_arg : -1, data, |
|---|
| 5693 | + size, parse->ls, event, parse->arg); |
|---|
| 5694 | + break; |
|---|
| 5695 | + case PRINT_FMT_ARG_POINTER: |
|---|
| 5696 | + print_arg_pointer(s, parse->format, |
|---|
| 5697 | + parse->len_as_arg ? len_arg : 1, |
|---|
| 5698 | + data, size, event, parse->arg); |
|---|
| 5699 | + break; |
|---|
| 5700 | + case PRINT_FMT_ARG_STRING: |
|---|
| 5701 | + print_arg_string(s, parse->format, |
|---|
| 5702 | + parse->len_as_arg ? len_arg : -1, |
|---|
| 5703 | + data, size, event, parse->arg); |
|---|
| 5704 | + break; |
|---|
| 5705 | + case PRINT_FMT_STRING: |
|---|
| 5706 | + default: |
|---|
| 5707 | + trace_seq_printf(s, "%s", parse->format); |
|---|
| 5708 | + break; |
|---|
| 5709 | + } |
|---|
| 5710 | + parse = parse->next; |
|---|
| 5711 | + } |
|---|
| 5712 | +} |
|---|
| 5713 | + |
|---|
| 5714 | +static void pretty_print(struct trace_seq *s, void *data, int size, struct tep_event *event) |
|---|
| 5715 | +{ |
|---|
| 5716 | + struct tep_print_parse *parse = event->print_fmt.print_cache; |
|---|
| 5717 | + struct tep_print_arg *args = NULL; |
|---|
| 5718 | + char *bprint_fmt = NULL; |
|---|
| 5719 | + |
|---|
| 5720 | + if (event->flags & TEP_EVENT_FL_FAILED) { |
|---|
| 4887 | 5721 | trace_seq_printf(s, "[FAILED TO PARSE]"); |
|---|
| 4888 | 5722 | tep_print_fields(s, data, size, event); |
|---|
| 4889 | 5723 | return; |
|---|
| 4890 | 5724 | } |
|---|
| 4891 | 5725 | |
|---|
| 4892 | | - if (event->flags & EVENT_FL_ISBPRINT) { |
|---|
| 5726 | + if (event->flags & TEP_EVENT_FL_ISBPRINT) { |
|---|
| 4893 | 5727 | bprint_fmt = get_bprint_format(data, size, event); |
|---|
| 4894 | 5728 | args = make_bprint_args(bprint_fmt, data, size, event); |
|---|
| 4895 | | - arg = args; |
|---|
| 4896 | | - ptr = bprint_fmt; |
|---|
| 5729 | + parse = parse_args(event, bprint_fmt, args); |
|---|
| 4897 | 5730 | } |
|---|
| 4898 | 5731 | |
|---|
| 4899 | | - for (; *ptr; ptr++) { |
|---|
| 4900 | | - ls = 0; |
|---|
| 4901 | | - if (*ptr == '\\') { |
|---|
| 4902 | | - ptr++; |
|---|
| 4903 | | - switch (*ptr) { |
|---|
| 4904 | | - case 'n': |
|---|
| 4905 | | - trace_seq_putc(s, '\n'); |
|---|
| 4906 | | - break; |
|---|
| 4907 | | - case 't': |
|---|
| 4908 | | - trace_seq_putc(s, '\t'); |
|---|
| 4909 | | - break; |
|---|
| 4910 | | - case 'r': |
|---|
| 4911 | | - trace_seq_putc(s, '\r'); |
|---|
| 4912 | | - break; |
|---|
| 4913 | | - case '\\': |
|---|
| 4914 | | - trace_seq_putc(s, '\\'); |
|---|
| 4915 | | - break; |
|---|
| 4916 | | - default: |
|---|
| 4917 | | - trace_seq_putc(s, *ptr); |
|---|
| 4918 | | - break; |
|---|
| 4919 | | - } |
|---|
| 5732 | + print_event_cache(parse, s, data, size, event); |
|---|
| 4920 | 5733 | |
|---|
| 4921 | | - } else if (*ptr == '%') { |
|---|
| 4922 | | - saveptr = ptr; |
|---|
| 4923 | | - show_func = 0; |
|---|
| 4924 | | - len_as_arg = 0; |
|---|
| 4925 | | - cont_process: |
|---|
| 4926 | | - ptr++; |
|---|
| 4927 | | - switch (*ptr) { |
|---|
| 4928 | | - case '%': |
|---|
| 4929 | | - trace_seq_putc(s, '%'); |
|---|
| 4930 | | - break; |
|---|
| 4931 | | - case '#': |
|---|
| 4932 | | - /* FIXME: need to handle properly */ |
|---|
| 4933 | | - goto cont_process; |
|---|
| 4934 | | - case 'h': |
|---|
| 4935 | | - ls--; |
|---|
| 4936 | | - goto cont_process; |
|---|
| 4937 | | - case 'l': |
|---|
| 4938 | | - ls++; |
|---|
| 4939 | | - goto cont_process; |
|---|
| 4940 | | - case 'L': |
|---|
| 4941 | | - ls = 2; |
|---|
| 4942 | | - goto cont_process; |
|---|
| 4943 | | - case '*': |
|---|
| 4944 | | - /* The argument is the length. */ |
|---|
| 4945 | | - if (!arg) { |
|---|
| 4946 | | - do_warning_event(event, "no argument match"); |
|---|
| 4947 | | - event->flags |= EVENT_FL_FAILED; |
|---|
| 4948 | | - goto out_failed; |
|---|
| 4949 | | - } |
|---|
| 4950 | | - len_arg = eval_num_arg(data, size, event, arg); |
|---|
| 4951 | | - len_as_arg = 1; |
|---|
| 4952 | | - arg = arg->next; |
|---|
| 4953 | | - goto cont_process; |
|---|
| 4954 | | - case '.': |
|---|
| 4955 | | - case 'z': |
|---|
| 4956 | | - case 'Z': |
|---|
| 4957 | | - case '0' ... '9': |
|---|
| 4958 | | - case '-': |
|---|
| 4959 | | - goto cont_process; |
|---|
| 4960 | | - case 'p': |
|---|
| 4961 | | - if (pevent->long_size == 4) |
|---|
| 4962 | | - ls = 1; |
|---|
| 4963 | | - else |
|---|
| 4964 | | - ls = 2; |
|---|
| 4965 | | - |
|---|
| 4966 | | - if (isalnum(ptr[1])) |
|---|
| 4967 | | - ptr++; |
|---|
| 4968 | | - |
|---|
| 4969 | | - if (arg->type == PRINT_BSTRING) { |
|---|
| 4970 | | - trace_seq_puts(s, arg->string.string); |
|---|
| 4971 | | - arg = arg->next; |
|---|
| 4972 | | - break; |
|---|
| 4973 | | - } |
|---|
| 4974 | | - |
|---|
| 4975 | | - if (*ptr == 'F' || *ptr == 'f' || |
|---|
| 4976 | | - *ptr == 'S' || *ptr == 's') { |
|---|
| 4977 | | - show_func = *ptr; |
|---|
| 4978 | | - } else if (*ptr == 'M' || *ptr == 'm') { |
|---|
| 4979 | | - print_mac_arg(s, *ptr, data, size, event, arg); |
|---|
| 4980 | | - arg = arg->next; |
|---|
| 4981 | | - break; |
|---|
| 4982 | | - } else if (*ptr == 'I' || *ptr == 'i') { |
|---|
| 4983 | | - int n; |
|---|
| 4984 | | - |
|---|
| 4985 | | - n = print_ip_arg(s, ptr, data, size, event, arg); |
|---|
| 4986 | | - if (n > 0) { |
|---|
| 4987 | | - ptr += n - 1; |
|---|
| 4988 | | - arg = arg->next; |
|---|
| 4989 | | - break; |
|---|
| 4990 | | - } |
|---|
| 4991 | | - } |
|---|
| 4992 | | - |
|---|
| 4993 | | - /* fall through */ |
|---|
| 4994 | | - case 'd': |
|---|
| 4995 | | - case 'i': |
|---|
| 4996 | | - case 'x': |
|---|
| 4997 | | - case 'X': |
|---|
| 4998 | | - case 'u': |
|---|
| 4999 | | - if (!arg) { |
|---|
| 5000 | | - do_warning_event(event, "no argument match"); |
|---|
| 5001 | | - event->flags |= EVENT_FL_FAILED; |
|---|
| 5002 | | - goto out_failed; |
|---|
| 5003 | | - } |
|---|
| 5004 | | - |
|---|
| 5005 | | - len = ((unsigned long)ptr + 1) - |
|---|
| 5006 | | - (unsigned long)saveptr; |
|---|
| 5007 | | - |
|---|
| 5008 | | - /* should never happen */ |
|---|
| 5009 | | - if (len > 31) { |
|---|
| 5010 | | - do_warning_event(event, "bad format!"); |
|---|
| 5011 | | - event->flags |= EVENT_FL_FAILED; |
|---|
| 5012 | | - len = 31; |
|---|
| 5013 | | - } |
|---|
| 5014 | | - |
|---|
| 5015 | | - memcpy(format, saveptr, len); |
|---|
| 5016 | | - format[len] = 0; |
|---|
| 5017 | | - |
|---|
| 5018 | | - val = eval_num_arg(data, size, event, arg); |
|---|
| 5019 | | - arg = arg->next; |
|---|
| 5020 | | - |
|---|
| 5021 | | - if (show_func) { |
|---|
| 5022 | | - func = find_func(pevent, val); |
|---|
| 5023 | | - if (func) { |
|---|
| 5024 | | - trace_seq_puts(s, func->func); |
|---|
| 5025 | | - if (show_func == 'F') |
|---|
| 5026 | | - trace_seq_printf(s, |
|---|
| 5027 | | - "+0x%llx", |
|---|
| 5028 | | - val - func->addr); |
|---|
| 5029 | | - break; |
|---|
| 5030 | | - } |
|---|
| 5031 | | - } |
|---|
| 5032 | | - if (pevent->long_size == 8 && ls == 1 && |
|---|
| 5033 | | - sizeof(long) != 8) { |
|---|
| 5034 | | - char *p; |
|---|
| 5035 | | - |
|---|
| 5036 | | - /* make %l into %ll */ |
|---|
| 5037 | | - if (ls == 1 && (p = strchr(format, 'l'))) |
|---|
| 5038 | | - memmove(p+1, p, strlen(p)+1); |
|---|
| 5039 | | - else if (strcmp(format, "%p") == 0) |
|---|
| 5040 | | - strcpy(format, "0x%llx"); |
|---|
| 5041 | | - ls = 2; |
|---|
| 5042 | | - } |
|---|
| 5043 | | - switch (ls) { |
|---|
| 5044 | | - case -2: |
|---|
| 5045 | | - if (len_as_arg) |
|---|
| 5046 | | - trace_seq_printf(s, format, len_arg, (char)val); |
|---|
| 5047 | | - else |
|---|
| 5048 | | - trace_seq_printf(s, format, (char)val); |
|---|
| 5049 | | - break; |
|---|
| 5050 | | - case -1: |
|---|
| 5051 | | - if (len_as_arg) |
|---|
| 5052 | | - trace_seq_printf(s, format, len_arg, (short)val); |
|---|
| 5053 | | - else |
|---|
| 5054 | | - trace_seq_printf(s, format, (short)val); |
|---|
| 5055 | | - break; |
|---|
| 5056 | | - case 0: |
|---|
| 5057 | | - if (len_as_arg) |
|---|
| 5058 | | - trace_seq_printf(s, format, len_arg, (int)val); |
|---|
| 5059 | | - else |
|---|
| 5060 | | - trace_seq_printf(s, format, (int)val); |
|---|
| 5061 | | - break; |
|---|
| 5062 | | - case 1: |
|---|
| 5063 | | - if (len_as_arg) |
|---|
| 5064 | | - trace_seq_printf(s, format, len_arg, (long)val); |
|---|
| 5065 | | - else |
|---|
| 5066 | | - trace_seq_printf(s, format, (long)val); |
|---|
| 5067 | | - break; |
|---|
| 5068 | | - case 2: |
|---|
| 5069 | | - if (len_as_arg) |
|---|
| 5070 | | - trace_seq_printf(s, format, len_arg, |
|---|
| 5071 | | - (long long)val); |
|---|
| 5072 | | - else |
|---|
| 5073 | | - trace_seq_printf(s, format, (long long)val); |
|---|
| 5074 | | - break; |
|---|
| 5075 | | - default: |
|---|
| 5076 | | - do_warning_event(event, "bad count (%d)", ls); |
|---|
| 5077 | | - event->flags |= EVENT_FL_FAILED; |
|---|
| 5078 | | - } |
|---|
| 5079 | | - break; |
|---|
| 5080 | | - case 's': |
|---|
| 5081 | | - if (!arg) { |
|---|
| 5082 | | - do_warning_event(event, "no matching argument"); |
|---|
| 5083 | | - event->flags |= EVENT_FL_FAILED; |
|---|
| 5084 | | - goto out_failed; |
|---|
| 5085 | | - } |
|---|
| 5086 | | - |
|---|
| 5087 | | - len = ((unsigned long)ptr + 1) - |
|---|
| 5088 | | - (unsigned long)saveptr; |
|---|
| 5089 | | - |
|---|
| 5090 | | - /* should never happen */ |
|---|
| 5091 | | - if (len > 31) { |
|---|
| 5092 | | - do_warning_event(event, "bad format!"); |
|---|
| 5093 | | - event->flags |= EVENT_FL_FAILED; |
|---|
| 5094 | | - len = 31; |
|---|
| 5095 | | - } |
|---|
| 5096 | | - |
|---|
| 5097 | | - memcpy(format, saveptr, len); |
|---|
| 5098 | | - format[len] = 0; |
|---|
| 5099 | | - if (!len_as_arg) |
|---|
| 5100 | | - len_arg = -1; |
|---|
| 5101 | | - /* Use helper trace_seq */ |
|---|
| 5102 | | - trace_seq_init(&p); |
|---|
| 5103 | | - print_str_arg(&p, data, size, event, |
|---|
| 5104 | | - format, len_arg, arg); |
|---|
| 5105 | | - trace_seq_terminate(&p); |
|---|
| 5106 | | - trace_seq_puts(s, p.buffer); |
|---|
| 5107 | | - trace_seq_destroy(&p); |
|---|
| 5108 | | - arg = arg->next; |
|---|
| 5109 | | - break; |
|---|
| 5110 | | - default: |
|---|
| 5111 | | - trace_seq_printf(s, ">%c<", *ptr); |
|---|
| 5112 | | - |
|---|
| 5113 | | - } |
|---|
| 5114 | | - } else |
|---|
| 5115 | | - trace_seq_putc(s, *ptr); |
|---|
| 5116 | | - } |
|---|
| 5117 | | - |
|---|
| 5118 | | - if (event->flags & EVENT_FL_FAILED) { |
|---|
| 5119 | | -out_failed: |
|---|
| 5120 | | - trace_seq_printf(s, "[FAILED TO PARSE]"); |
|---|
| 5121 | | - } |
|---|
| 5122 | | - |
|---|
| 5123 | | - if (args) { |
|---|
| 5734 | + if (event->flags & TEP_EVENT_FL_ISBPRINT) { |
|---|
| 5735 | + free_parse_args(parse); |
|---|
| 5124 | 5736 | free_args(args); |
|---|
| 5125 | 5737 | free(bprint_fmt); |
|---|
| 5126 | 5738 | } |
|---|
| 5127 | 5739 | } |
|---|
| 5128 | 5740 | |
|---|
| 5129 | | -/** |
|---|
| 5130 | | - * tep_data_lat_fmt - parse the data for the latency format |
|---|
| 5131 | | - * @pevent: a handle to the pevent |
|---|
| 5132 | | - * @s: the trace_seq to write to |
|---|
| 5133 | | - * @record: the record to read from |
|---|
| 5134 | | - * |
|---|
| 5741 | +/* |
|---|
| 5135 | 5742 | * This parses out the Latency format (interrupts disabled, |
|---|
| 5136 | 5743 | * need rescheduling, in hard/soft interrupt, preempt count |
|---|
| 5137 | 5744 | * and lock depth) and places it into the trace_seq. |
|---|
| 5138 | 5745 | */ |
|---|
| 5139 | | -void tep_data_lat_fmt(struct tep_handle *pevent, |
|---|
| 5140 | | - struct trace_seq *s, struct tep_record *record) |
|---|
| 5746 | +static void data_latency_format(struct tep_handle *tep, struct trace_seq *s, |
|---|
| 5747 | + char *format, struct tep_record *record) |
|---|
| 5141 | 5748 | { |
|---|
| 5142 | 5749 | static int check_lock_depth = 1; |
|---|
| 5143 | 5750 | static int check_migrate_disable = 1; |
|---|
| 5144 | 5751 | static int lock_depth_exists; |
|---|
| 5145 | 5752 | static int migrate_disable_exists; |
|---|
| 5146 | 5753 | unsigned int lat_flags; |
|---|
| 5754 | + struct trace_seq sq; |
|---|
| 5147 | 5755 | unsigned int pc; |
|---|
| 5148 | | - int lock_depth; |
|---|
| 5149 | | - int migrate_disable; |
|---|
| 5756 | + int lock_depth = 0; |
|---|
| 5757 | + int migrate_disable = 0; |
|---|
| 5150 | 5758 | int hardirq; |
|---|
| 5151 | 5759 | int softirq; |
|---|
| 5152 | 5760 | void *data = record->data; |
|---|
| 5153 | 5761 | |
|---|
| 5154 | | - lat_flags = parse_common_flags(pevent, data); |
|---|
| 5155 | | - pc = parse_common_pc(pevent, data); |
|---|
| 5762 | + trace_seq_init(&sq); |
|---|
| 5763 | + lat_flags = parse_common_flags(tep, data); |
|---|
| 5764 | + pc = parse_common_pc(tep, data); |
|---|
| 5156 | 5765 | /* lock_depth may not always exist */ |
|---|
| 5157 | 5766 | if (lock_depth_exists) |
|---|
| 5158 | | - lock_depth = parse_common_lock_depth(pevent, data); |
|---|
| 5767 | + lock_depth = parse_common_lock_depth(tep, data); |
|---|
| 5159 | 5768 | else if (check_lock_depth) { |
|---|
| 5160 | | - lock_depth = parse_common_lock_depth(pevent, data); |
|---|
| 5769 | + lock_depth = parse_common_lock_depth(tep, data); |
|---|
| 5161 | 5770 | if (lock_depth < 0) |
|---|
| 5162 | 5771 | check_lock_depth = 0; |
|---|
| 5163 | 5772 | else |
|---|
| .. | .. |
|---|
| 5166 | 5775 | |
|---|
| 5167 | 5776 | /* migrate_disable may not always exist */ |
|---|
| 5168 | 5777 | if (migrate_disable_exists) |
|---|
| 5169 | | - migrate_disable = parse_common_migrate_disable(pevent, data); |
|---|
| 5778 | + migrate_disable = parse_common_migrate_disable(tep, data); |
|---|
| 5170 | 5779 | else if (check_migrate_disable) { |
|---|
| 5171 | | - migrate_disable = parse_common_migrate_disable(pevent, data); |
|---|
| 5780 | + migrate_disable = parse_common_migrate_disable(tep, data); |
|---|
| 5172 | 5781 | if (migrate_disable < 0) |
|---|
| 5173 | 5782 | check_migrate_disable = 0; |
|---|
| 5174 | 5783 | else |
|---|
| .. | .. |
|---|
| 5178 | 5787 | hardirq = lat_flags & TRACE_FLAG_HARDIRQ; |
|---|
| 5179 | 5788 | softirq = lat_flags & TRACE_FLAG_SOFTIRQ; |
|---|
| 5180 | 5789 | |
|---|
| 5181 | | - trace_seq_printf(s, "%c%c%c", |
|---|
| 5790 | + trace_seq_printf(&sq, "%c%c%c", |
|---|
| 5182 | 5791 | (lat_flags & TRACE_FLAG_IRQS_OFF) ? 'd' : |
|---|
| 5183 | 5792 | (lat_flags & TRACE_FLAG_IRQS_NOSUPPORT) ? |
|---|
| 5184 | 5793 | 'X' : '.', |
|---|
| .. | .. |
|---|
| 5188 | 5797 | hardirq ? 'h' : softirq ? 's' : '.'); |
|---|
| 5189 | 5798 | |
|---|
| 5190 | 5799 | if (pc) |
|---|
| 5191 | | - trace_seq_printf(s, "%x", pc); |
|---|
| 5800 | + trace_seq_printf(&sq, "%x", pc); |
|---|
| 5192 | 5801 | else |
|---|
| 5193 | | - trace_seq_putc(s, '.'); |
|---|
| 5802 | + trace_seq_printf(&sq, "."); |
|---|
| 5194 | 5803 | |
|---|
| 5195 | 5804 | if (migrate_disable_exists) { |
|---|
| 5196 | 5805 | if (migrate_disable < 0) |
|---|
| 5197 | | - trace_seq_putc(s, '.'); |
|---|
| 5806 | + trace_seq_printf(&sq, "."); |
|---|
| 5198 | 5807 | else |
|---|
| 5199 | | - trace_seq_printf(s, "%d", migrate_disable); |
|---|
| 5808 | + trace_seq_printf(&sq, "%d", migrate_disable); |
|---|
| 5200 | 5809 | } |
|---|
| 5201 | 5810 | |
|---|
| 5202 | 5811 | if (lock_depth_exists) { |
|---|
| 5203 | 5812 | if (lock_depth < 0) |
|---|
| 5204 | | - trace_seq_putc(s, '.'); |
|---|
| 5813 | + trace_seq_printf(&sq, "."); |
|---|
| 5205 | 5814 | else |
|---|
| 5206 | | - trace_seq_printf(s, "%d", lock_depth); |
|---|
| 5815 | + trace_seq_printf(&sq, "%d", lock_depth); |
|---|
| 5207 | 5816 | } |
|---|
| 5208 | 5817 | |
|---|
| 5818 | + if (sq.state == TRACE_SEQ__MEM_ALLOC_FAILED) { |
|---|
| 5819 | + s->state = TRACE_SEQ__MEM_ALLOC_FAILED; |
|---|
| 5820 | + return; |
|---|
| 5821 | + } |
|---|
| 5822 | + |
|---|
| 5823 | + trace_seq_terminate(&sq); |
|---|
| 5824 | + trace_seq_puts(s, sq.buffer); |
|---|
| 5825 | + trace_seq_destroy(&sq); |
|---|
| 5209 | 5826 | trace_seq_terminate(s); |
|---|
| 5210 | 5827 | } |
|---|
| 5211 | 5828 | |
|---|
| 5212 | 5829 | /** |
|---|
| 5213 | 5830 | * tep_data_type - parse out the given event type |
|---|
| 5214 | | - * @pevent: a handle to the pevent |
|---|
| 5831 | + * @tep: a handle to the trace event parser context |
|---|
| 5215 | 5832 | * @rec: the record to read from |
|---|
| 5216 | 5833 | * |
|---|
| 5217 | 5834 | * This returns the event id from the @rec. |
|---|
| 5218 | 5835 | */ |
|---|
| 5219 | | -int tep_data_type(struct tep_handle *pevent, struct tep_record *rec) |
|---|
| 5836 | +int tep_data_type(struct tep_handle *tep, struct tep_record *rec) |
|---|
| 5220 | 5837 | { |
|---|
| 5221 | | - return trace_parse_common_type(pevent, rec->data); |
|---|
| 5222 | | -} |
|---|
| 5223 | | - |
|---|
| 5224 | | -/** |
|---|
| 5225 | | - * tep_data_event_from_type - find the event by a given type |
|---|
| 5226 | | - * @pevent: a handle to the pevent |
|---|
| 5227 | | - * @type: the type of the event. |
|---|
| 5228 | | - * |
|---|
| 5229 | | - * This returns the event form a given @type; |
|---|
| 5230 | | - */ |
|---|
| 5231 | | -struct event_format *tep_data_event_from_type(struct tep_handle *pevent, int type) |
|---|
| 5232 | | -{ |
|---|
| 5233 | | - return tep_find_event(pevent, type); |
|---|
| 5838 | + return trace_parse_common_type(tep, rec->data); |
|---|
| 5234 | 5839 | } |
|---|
| 5235 | 5840 | |
|---|
| 5236 | 5841 | /** |
|---|
| 5237 | 5842 | * tep_data_pid - parse the PID from record |
|---|
| 5238 | | - * @pevent: a handle to the pevent |
|---|
| 5843 | + * @tep: a handle to the trace event parser context |
|---|
| 5239 | 5844 | * @rec: the record to parse |
|---|
| 5240 | 5845 | * |
|---|
| 5241 | 5846 | * This returns the PID from a record. |
|---|
| 5242 | 5847 | */ |
|---|
| 5243 | | -int tep_data_pid(struct tep_handle *pevent, struct tep_record *rec) |
|---|
| 5848 | +int tep_data_pid(struct tep_handle *tep, struct tep_record *rec) |
|---|
| 5244 | 5849 | { |
|---|
| 5245 | | - return parse_common_pid(pevent, rec->data); |
|---|
| 5850 | + return parse_common_pid(tep, rec->data); |
|---|
| 5246 | 5851 | } |
|---|
| 5247 | 5852 | |
|---|
| 5248 | 5853 | /** |
|---|
| 5249 | 5854 | * tep_data_preempt_count - parse the preempt count from the record |
|---|
| 5250 | | - * @pevent: a handle to the pevent |
|---|
| 5855 | + * @tep: a handle to the trace event parser context |
|---|
| 5251 | 5856 | * @rec: the record to parse |
|---|
| 5252 | 5857 | * |
|---|
| 5253 | 5858 | * This returns the preempt count from a record. |
|---|
| 5254 | 5859 | */ |
|---|
| 5255 | | -int tep_data_preempt_count(struct tep_handle *pevent, struct tep_record *rec) |
|---|
| 5860 | +int tep_data_preempt_count(struct tep_handle *tep, struct tep_record *rec) |
|---|
| 5256 | 5861 | { |
|---|
| 5257 | | - return parse_common_pc(pevent, rec->data); |
|---|
| 5862 | + return parse_common_pc(tep, rec->data); |
|---|
| 5258 | 5863 | } |
|---|
| 5259 | 5864 | |
|---|
| 5260 | 5865 | /** |
|---|
| 5261 | 5866 | * tep_data_flags - parse the latency flags from the record |
|---|
| 5262 | | - * @pevent: a handle to the pevent |
|---|
| 5867 | + * @tep: a handle to the trace event parser context |
|---|
| 5263 | 5868 | * @rec: the record to parse |
|---|
| 5264 | 5869 | * |
|---|
| 5265 | 5870 | * This returns the latency flags from a record. |
|---|
| 5266 | 5871 | * |
|---|
| 5267 | 5872 | * Use trace_flag_type enum for the flags (see event-parse.h). |
|---|
| 5268 | 5873 | */ |
|---|
| 5269 | | -int tep_data_flags(struct tep_handle *pevent, struct tep_record *rec) |
|---|
| 5874 | +int tep_data_flags(struct tep_handle *tep, struct tep_record *rec) |
|---|
| 5270 | 5875 | { |
|---|
| 5271 | | - return parse_common_flags(pevent, rec->data); |
|---|
| 5876 | + return parse_common_flags(tep, rec->data); |
|---|
| 5272 | 5877 | } |
|---|
| 5273 | 5878 | |
|---|
| 5274 | 5879 | /** |
|---|
| 5275 | 5880 | * tep_data_comm_from_pid - return the command line from PID |
|---|
| 5276 | | - * @pevent: a handle to the pevent |
|---|
| 5881 | + * @tep: a handle to the trace event parser context |
|---|
| 5277 | 5882 | * @pid: the PID of the task to search for |
|---|
| 5278 | 5883 | * |
|---|
| 5279 | 5884 | * This returns a pointer to the command line that has the given |
|---|
| 5280 | 5885 | * @pid. |
|---|
| 5281 | 5886 | */ |
|---|
| 5282 | | -const char *tep_data_comm_from_pid(struct tep_handle *pevent, int pid) |
|---|
| 5887 | +const char *tep_data_comm_from_pid(struct tep_handle *tep, int pid) |
|---|
| 5283 | 5888 | { |
|---|
| 5284 | 5889 | const char *comm; |
|---|
| 5285 | 5890 | |
|---|
| 5286 | | - comm = find_cmdline(pevent, pid); |
|---|
| 5891 | + comm = find_cmdline(tep, pid); |
|---|
| 5287 | 5892 | return comm; |
|---|
| 5288 | 5893 | } |
|---|
| 5289 | 5894 | |
|---|
| 5290 | | -static struct cmdline * |
|---|
| 5291 | | -pid_from_cmdlist(struct tep_handle *pevent, const char *comm, struct cmdline *next) |
|---|
| 5895 | +static struct tep_cmdline * |
|---|
| 5896 | +pid_from_cmdlist(struct tep_handle *tep, const char *comm, struct tep_cmdline *next) |
|---|
| 5292 | 5897 | { |
|---|
| 5293 | 5898 | struct cmdline_list *cmdlist = (struct cmdline_list *)next; |
|---|
| 5294 | 5899 | |
|---|
| 5295 | 5900 | if (cmdlist) |
|---|
| 5296 | 5901 | cmdlist = cmdlist->next; |
|---|
| 5297 | 5902 | else |
|---|
| 5298 | | - cmdlist = pevent->cmdlist; |
|---|
| 5903 | + cmdlist = tep->cmdlist; |
|---|
| 5299 | 5904 | |
|---|
| 5300 | 5905 | while (cmdlist && strcmp(cmdlist->comm, comm) != 0) |
|---|
| 5301 | 5906 | cmdlist = cmdlist->next; |
|---|
| 5302 | 5907 | |
|---|
| 5303 | | - return (struct cmdline *)cmdlist; |
|---|
| 5908 | + return (struct tep_cmdline *)cmdlist; |
|---|
| 5304 | 5909 | } |
|---|
| 5305 | 5910 | |
|---|
| 5306 | 5911 | /** |
|---|
| 5307 | 5912 | * tep_data_pid_from_comm - return the pid from a given comm |
|---|
| 5308 | | - * @pevent: a handle to the pevent |
|---|
| 5913 | + * @tep: a handle to the trace event parser context |
|---|
| 5309 | 5914 | * @comm: the cmdline to find the pid from |
|---|
| 5310 | 5915 | * @next: the cmdline structure to find the next comm |
|---|
| 5311 | 5916 | * |
|---|
| 5312 | 5917 | * This returns the cmdline structure that holds a pid for a given |
|---|
| 5313 | 5918 | * comm, or NULL if none found. As there may be more than one pid for |
|---|
| 5314 | 5919 | * a given comm, the result of this call can be passed back into |
|---|
| 5315 | | - * a recurring call in the @next paramater, and then it will find the |
|---|
| 5920 | + * a recurring call in the @next parameter, and then it will find the |
|---|
| 5316 | 5921 | * next pid. |
|---|
| 5317 | | - * Also, it does a linear seach, so it may be slow. |
|---|
| 5922 | + * Also, it does a linear search, so it may be slow. |
|---|
| 5318 | 5923 | */ |
|---|
| 5319 | | -struct cmdline *tep_data_pid_from_comm(struct tep_handle *pevent, const char *comm, |
|---|
| 5320 | | - struct cmdline *next) |
|---|
| 5924 | +struct tep_cmdline *tep_data_pid_from_comm(struct tep_handle *tep, const char *comm, |
|---|
| 5925 | + struct tep_cmdline *next) |
|---|
| 5321 | 5926 | { |
|---|
| 5322 | | - struct cmdline *cmdline; |
|---|
| 5927 | + struct tep_cmdline *cmdline; |
|---|
| 5323 | 5928 | |
|---|
| 5324 | 5929 | /* |
|---|
| 5325 | 5930 | * If the cmdlines have not been converted yet, then use |
|---|
| 5326 | 5931 | * the list. |
|---|
| 5327 | 5932 | */ |
|---|
| 5328 | | - if (!pevent->cmdlines) |
|---|
| 5329 | | - return pid_from_cmdlist(pevent, comm, next); |
|---|
| 5933 | + if (!tep->cmdlines) |
|---|
| 5934 | + return pid_from_cmdlist(tep, comm, next); |
|---|
| 5330 | 5935 | |
|---|
| 5331 | 5936 | if (next) { |
|---|
| 5332 | 5937 | /* |
|---|
| 5333 | 5938 | * The next pointer could have been still from |
|---|
| 5334 | 5939 | * a previous call before cmdlines were created |
|---|
| 5335 | 5940 | */ |
|---|
| 5336 | | - if (next < pevent->cmdlines || |
|---|
| 5337 | | - next >= pevent->cmdlines + pevent->cmdline_count) |
|---|
| 5941 | + if (next < tep->cmdlines || |
|---|
| 5942 | + next >= tep->cmdlines + tep->cmdline_count) |
|---|
| 5338 | 5943 | next = NULL; |
|---|
| 5339 | 5944 | else |
|---|
| 5340 | 5945 | cmdline = next++; |
|---|
| 5341 | 5946 | } |
|---|
| 5342 | 5947 | |
|---|
| 5343 | 5948 | if (!next) |
|---|
| 5344 | | - cmdline = pevent->cmdlines; |
|---|
| 5949 | + cmdline = tep->cmdlines; |
|---|
| 5345 | 5950 | |
|---|
| 5346 | | - while (cmdline < pevent->cmdlines + pevent->cmdline_count) { |
|---|
| 5951 | + while (cmdline < tep->cmdlines + tep->cmdline_count) { |
|---|
| 5347 | 5952 | if (strcmp(cmdline->comm, comm) == 0) |
|---|
| 5348 | 5953 | return cmdline; |
|---|
| 5349 | 5954 | cmdline++; |
|---|
| .. | .. |
|---|
| 5353 | 5958 | |
|---|
| 5354 | 5959 | /** |
|---|
| 5355 | 5960 | * tep_cmdline_pid - return the pid associated to a given cmdline |
|---|
| 5961 | + * @tep: a handle to the trace event parser context |
|---|
| 5356 | 5962 | * @cmdline: The cmdline structure to get the pid from |
|---|
| 5357 | 5963 | * |
|---|
| 5358 | 5964 | * Returns the pid for a give cmdline. If @cmdline is NULL, then |
|---|
| 5359 | 5965 | * -1 is returned. |
|---|
| 5360 | 5966 | */ |
|---|
| 5361 | | -int tep_cmdline_pid(struct tep_handle *pevent, struct cmdline *cmdline) |
|---|
| 5967 | +int tep_cmdline_pid(struct tep_handle *tep, struct tep_cmdline *cmdline) |
|---|
| 5362 | 5968 | { |
|---|
| 5363 | 5969 | struct cmdline_list *cmdlist = (struct cmdline_list *)cmdline; |
|---|
| 5364 | 5970 | |
|---|
| .. | .. |
|---|
| 5369 | 5975 | * If cmdlines have not been created yet, or cmdline is |
|---|
| 5370 | 5976 | * not part of the array, then treat it as a cmdlist instead. |
|---|
| 5371 | 5977 | */ |
|---|
| 5372 | | - if (!pevent->cmdlines || |
|---|
| 5373 | | - cmdline < pevent->cmdlines || |
|---|
| 5374 | | - cmdline >= pevent->cmdlines + pevent->cmdline_count) |
|---|
| 5978 | + if (!tep->cmdlines || |
|---|
| 5979 | + cmdline < tep->cmdlines || |
|---|
| 5980 | + cmdline >= tep->cmdlines + tep->cmdline_count) |
|---|
| 5375 | 5981 | return cmdlist->pid; |
|---|
| 5376 | 5982 | |
|---|
| 5377 | 5983 | return cmdline->pid; |
|---|
| 5378 | 5984 | } |
|---|
| 5379 | 5985 | |
|---|
| 5380 | | -/** |
|---|
| 5381 | | - * tep_event_info - parse the data into the print format |
|---|
| 5382 | | - * @s: the trace_seq to write to |
|---|
| 5383 | | - * @event: the handle to the event |
|---|
| 5384 | | - * @record: the record to read from |
|---|
| 5385 | | - * |
|---|
| 5986 | +/* |
|---|
| 5386 | 5987 | * This parses the raw @data using the given @event information and |
|---|
| 5387 | 5988 | * writes the print format into the trace_seq. |
|---|
| 5388 | 5989 | */ |
|---|
| 5389 | | -void tep_event_info(struct trace_seq *s, struct event_format *event, |
|---|
| 5390 | | - struct tep_record *record) |
|---|
| 5990 | +static void print_event_info(struct trace_seq *s, char *format, bool raw, |
|---|
| 5991 | + struct tep_event *event, struct tep_record *record) |
|---|
| 5391 | 5992 | { |
|---|
| 5392 | 5993 | int print_pretty = 1; |
|---|
| 5393 | 5994 | |
|---|
| 5394 | | - if (event->pevent->print_raw || (event->flags & EVENT_FL_PRINTRAW)) |
|---|
| 5995 | + if (raw || (event->flags & TEP_EVENT_FL_PRINTRAW)) |
|---|
| 5395 | 5996 | tep_print_fields(s, record->data, record->size, event); |
|---|
| 5396 | 5997 | else { |
|---|
| 5397 | 5998 | |
|---|
| 5398 | | - if (event->handler && !(event->flags & EVENT_FL_NOHANDLE)) |
|---|
| 5999 | + if (event->handler && !(event->flags & TEP_EVENT_FL_NOHANDLE)) |
|---|
| 5399 | 6000 | print_pretty = event->handler(s, record, event, |
|---|
| 5400 | 6001 | event->context); |
|---|
| 5401 | 6002 | |
|---|
| .. | .. |
|---|
| 5406 | 6007 | trace_seq_terminate(s); |
|---|
| 5407 | 6008 | } |
|---|
| 5408 | 6009 | |
|---|
| 5409 | | -static bool is_timestamp_in_us(char *trace_clock, bool use_trace_clock) |
|---|
| 5410 | | -{ |
|---|
| 5411 | | - if (!use_trace_clock) |
|---|
| 5412 | | - return true; |
|---|
| 5413 | | - |
|---|
| 5414 | | - if (!strcmp(trace_clock, "local") || !strcmp(trace_clock, "global") |
|---|
| 5415 | | - || !strcmp(trace_clock, "uptime") || !strcmp(trace_clock, "perf")) |
|---|
| 5416 | | - return true; |
|---|
| 5417 | | - |
|---|
| 5418 | | - /* trace_clock is setting in tsc or counter mode */ |
|---|
| 5419 | | - return false; |
|---|
| 5420 | | -} |
|---|
| 5421 | | - |
|---|
| 5422 | 6010 | /** |
|---|
| 5423 | 6011 | * tep_find_event_by_record - return the event from a given record |
|---|
| 5424 | | - * @pevent: a handle to the pevent |
|---|
| 6012 | + * @tep: a handle to the trace event parser context |
|---|
| 5425 | 6013 | * @record: The record to get the event from |
|---|
| 5426 | 6014 | * |
|---|
| 5427 | 6015 | * Returns the associated event for a given record, or NULL if non is |
|---|
| 5428 | 6016 | * is found. |
|---|
| 5429 | 6017 | */ |
|---|
| 5430 | | -struct event_format * |
|---|
| 5431 | | -tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record) |
|---|
| 6018 | +struct tep_event * |
|---|
| 6019 | +tep_find_event_by_record(struct tep_handle *tep, struct tep_record *record) |
|---|
| 5432 | 6020 | { |
|---|
| 5433 | 6021 | int type; |
|---|
| 5434 | 6022 | |
|---|
| .. | .. |
|---|
| 5437 | 6025 | return NULL; |
|---|
| 5438 | 6026 | } |
|---|
| 5439 | 6027 | |
|---|
| 5440 | | - type = trace_parse_common_type(pevent, record->data); |
|---|
| 6028 | + type = trace_parse_common_type(tep, record->data); |
|---|
| 5441 | 6029 | |
|---|
| 5442 | | - return tep_find_event(pevent, type); |
|---|
| 6030 | + return tep_find_event(tep, type); |
|---|
| 5443 | 6031 | } |
|---|
| 5444 | 6032 | |
|---|
| 5445 | | -/** |
|---|
| 5446 | | - * tep_print_event_task - Write the event task comm, pid and CPU |
|---|
| 5447 | | - * @pevent: a handle to the pevent |
|---|
| 5448 | | - * @s: the trace_seq to write to |
|---|
| 5449 | | - * @event: the handle to the record's event |
|---|
| 5450 | | - * @record: The record to get the event from |
|---|
| 5451 | | - * |
|---|
| 5452 | | - * Writes the tasks comm, pid and CPU to @s. |
|---|
| 6033 | +/* |
|---|
| 6034 | + * Writes the timestamp of the record into @s. Time divisor and precision can be |
|---|
| 6035 | + * specified as part of printf @format string. Example: |
|---|
| 6036 | + * "%3.1000d" - divide the time by 1000 and print the first 3 digits |
|---|
| 6037 | + * before the dot. Thus, the timestamp "123456000" will be printed as |
|---|
| 6038 | + * "123.456" |
|---|
| 5453 | 6039 | */ |
|---|
| 5454 | | -void tep_print_event_task(struct tep_handle *pevent, struct trace_seq *s, |
|---|
| 5455 | | - struct event_format *event, |
|---|
| 5456 | | - struct tep_record *record) |
|---|
| 6040 | +static void print_event_time(struct tep_handle *tep, struct trace_seq *s, |
|---|
| 6041 | + char *format, struct tep_event *event, |
|---|
| 6042 | + struct tep_record *record) |
|---|
| 5457 | 6043 | { |
|---|
| 5458 | | - void *data = record->data; |
|---|
| 6044 | + unsigned long long time; |
|---|
| 6045 | + char *divstr; |
|---|
| 6046 | + int prec = 0, pr; |
|---|
| 6047 | + int div = 0; |
|---|
| 6048 | + int p10 = 1; |
|---|
| 6049 | + |
|---|
| 6050 | + if (isdigit(*(format + 1))) |
|---|
| 6051 | + prec = atoi(format + 1); |
|---|
| 6052 | + divstr = strchr(format, '.'); |
|---|
| 6053 | + if (divstr && isdigit(*(divstr + 1))) |
|---|
| 6054 | + div = atoi(divstr + 1); |
|---|
| 6055 | + time = record->ts; |
|---|
| 6056 | + if (div) { |
|---|
| 6057 | + time += div / 2; |
|---|
| 6058 | + time /= div; |
|---|
| 6059 | + } |
|---|
| 6060 | + pr = prec; |
|---|
| 6061 | + while (pr--) |
|---|
| 6062 | + p10 *= 10; |
|---|
| 6063 | + |
|---|
| 6064 | + if (p10 > 1 && p10 < time) |
|---|
| 6065 | + trace_seq_printf(s, "%5llu.%0*llu", time / p10, prec, time % p10); |
|---|
| 6066 | + else |
|---|
| 6067 | + trace_seq_printf(s, "%12llu", time); |
|---|
| 6068 | +} |
|---|
| 6069 | + |
|---|
| 6070 | +struct print_event_type { |
|---|
| 6071 | + enum { |
|---|
| 6072 | + EVENT_TYPE_INT = 1, |
|---|
| 6073 | + EVENT_TYPE_STRING, |
|---|
| 6074 | + EVENT_TYPE_UNKNOWN, |
|---|
| 6075 | + } type; |
|---|
| 6076 | + char format[32]; |
|---|
| 6077 | +}; |
|---|
| 6078 | + |
|---|
| 6079 | +static void print_string(struct tep_handle *tep, struct trace_seq *s, |
|---|
| 6080 | + struct tep_record *record, struct tep_event *event, |
|---|
| 6081 | + const char *arg, struct print_event_type *type) |
|---|
| 6082 | +{ |
|---|
| 5459 | 6083 | const char *comm; |
|---|
| 5460 | 6084 | int pid; |
|---|
| 5461 | 6085 | |
|---|
| 5462 | | - pid = parse_common_pid(pevent, data); |
|---|
| 5463 | | - comm = find_cmdline(pevent, pid); |
|---|
| 5464 | | - |
|---|
| 5465 | | - if (pevent->latency_format) { |
|---|
| 5466 | | - trace_seq_printf(s, "%8.8s-%-5d %3d", |
|---|
| 5467 | | - comm, pid, record->cpu); |
|---|
| 5468 | | - } else |
|---|
| 5469 | | - trace_seq_printf(s, "%16s-%-5d [%03d]", comm, pid, record->cpu); |
|---|
| 5470 | | -} |
|---|
| 5471 | | - |
|---|
| 5472 | | -/** |
|---|
| 5473 | | - * tep_print_event_time - Write the event timestamp |
|---|
| 5474 | | - * @pevent: a handle to the pevent |
|---|
| 5475 | | - * @s: the trace_seq to write to |
|---|
| 5476 | | - * @event: the handle to the record's event |
|---|
| 5477 | | - * @record: The record to get the event from |
|---|
| 5478 | | - * @use_trace_clock: Set to parse according to the @pevent->trace_clock |
|---|
| 5479 | | - * |
|---|
| 5480 | | - * Writes the timestamp of the record into @s. |
|---|
| 5481 | | - */ |
|---|
| 5482 | | -void tep_print_event_time(struct tep_handle *pevent, struct trace_seq *s, |
|---|
| 5483 | | - struct event_format *event, |
|---|
| 5484 | | - struct tep_record *record, |
|---|
| 5485 | | - bool use_trace_clock) |
|---|
| 5486 | | -{ |
|---|
| 5487 | | - unsigned long secs; |
|---|
| 5488 | | - unsigned long usecs; |
|---|
| 5489 | | - unsigned long nsecs; |
|---|
| 5490 | | - int p; |
|---|
| 5491 | | - bool use_usec_format; |
|---|
| 5492 | | - |
|---|
| 5493 | | - use_usec_format = is_timestamp_in_us(pevent->trace_clock, |
|---|
| 5494 | | - use_trace_clock); |
|---|
| 5495 | | - if (use_usec_format) { |
|---|
| 5496 | | - secs = record->ts / NSEC_PER_SEC; |
|---|
| 5497 | | - nsecs = record->ts - secs * NSEC_PER_SEC; |
|---|
| 6086 | + if (strncmp(arg, TEP_PRINT_LATENCY, strlen(TEP_PRINT_LATENCY)) == 0) { |
|---|
| 6087 | + data_latency_format(tep, s, type->format, record); |
|---|
| 6088 | + } else if (strncmp(arg, TEP_PRINT_COMM, strlen(TEP_PRINT_COMM)) == 0) { |
|---|
| 6089 | + pid = parse_common_pid(tep, record->data); |
|---|
| 6090 | + comm = find_cmdline(tep, pid); |
|---|
| 6091 | + trace_seq_printf(s, type->format, comm); |
|---|
| 6092 | + } else if (strncmp(arg, TEP_PRINT_INFO_RAW, strlen(TEP_PRINT_INFO_RAW)) == 0) { |
|---|
| 6093 | + print_event_info(s, type->format, true, event, record); |
|---|
| 6094 | + } else if (strncmp(arg, TEP_PRINT_INFO, strlen(TEP_PRINT_INFO)) == 0) { |
|---|
| 6095 | + print_event_info(s, type->format, false, event, record); |
|---|
| 6096 | + } else if (strncmp(arg, TEP_PRINT_NAME, strlen(TEP_PRINT_NAME)) == 0) { |
|---|
| 6097 | + trace_seq_printf(s, type->format, event->name); |
|---|
| 6098 | + } else { |
|---|
| 6099 | + trace_seq_printf(s, "[UNKNOWN TEP TYPE %s]", arg); |
|---|
| 5498 | 6100 | } |
|---|
| 5499 | 6101 | |
|---|
| 5500 | | - if (pevent->latency_format) { |
|---|
| 5501 | | - tep_data_lat_fmt(pevent, s, record); |
|---|
| 5502 | | - } |
|---|
| 5503 | | - |
|---|
| 5504 | | - if (use_usec_format) { |
|---|
| 5505 | | - if (pevent->flags & TEP_NSEC_OUTPUT) { |
|---|
| 5506 | | - usecs = nsecs; |
|---|
| 5507 | | - p = 9; |
|---|
| 5508 | | - } else { |
|---|
| 5509 | | - usecs = (nsecs + 500) / NSEC_PER_USEC; |
|---|
| 5510 | | - /* To avoid usecs larger than 1 sec */ |
|---|
| 5511 | | - if (usecs >= USEC_PER_SEC) { |
|---|
| 5512 | | - usecs -= USEC_PER_SEC; |
|---|
| 5513 | | - secs++; |
|---|
| 5514 | | - } |
|---|
| 5515 | | - p = 6; |
|---|
| 5516 | | - } |
|---|
| 5517 | | - |
|---|
| 5518 | | - trace_seq_printf(s, " %5lu.%0*lu:", secs, p, usecs); |
|---|
| 5519 | | - } else |
|---|
| 5520 | | - trace_seq_printf(s, " %12llu:", record->ts); |
|---|
| 5521 | 6102 | } |
|---|
| 5522 | 6103 | |
|---|
| 5523 | | -/** |
|---|
| 5524 | | - * tep_print_event_data - Write the event data section |
|---|
| 5525 | | - * @pevent: a handle to the pevent |
|---|
| 5526 | | - * @s: the trace_seq to write to |
|---|
| 5527 | | - * @event: the handle to the record's event |
|---|
| 5528 | | - * @record: The record to get the event from |
|---|
| 5529 | | - * |
|---|
| 5530 | | - * Writes the parsing of the record's data to @s. |
|---|
| 5531 | | - */ |
|---|
| 5532 | | -void tep_print_event_data(struct tep_handle *pevent, struct trace_seq *s, |
|---|
| 5533 | | - struct event_format *event, |
|---|
| 5534 | | - struct tep_record *record) |
|---|
| 6104 | +static void print_int(struct tep_handle *tep, struct trace_seq *s, |
|---|
| 6105 | + struct tep_record *record, struct tep_event *event, |
|---|
| 6106 | + int arg, struct print_event_type *type) |
|---|
| 5535 | 6107 | { |
|---|
| 5536 | | - static const char *spaces = " "; /* 20 spaces */ |
|---|
| 5537 | | - int len; |
|---|
| 6108 | + int param; |
|---|
| 5538 | 6109 | |
|---|
| 5539 | | - trace_seq_printf(s, " %s: ", event->name); |
|---|
| 5540 | | - |
|---|
| 5541 | | - /* Space out the event names evenly. */ |
|---|
| 5542 | | - len = strlen(event->name); |
|---|
| 5543 | | - if (len < 20) |
|---|
| 5544 | | - trace_seq_printf(s, "%.*s", 20 - len, spaces); |
|---|
| 5545 | | - |
|---|
| 5546 | | - tep_event_info(s, event, record); |
|---|
| 5547 | | -} |
|---|
| 5548 | | - |
|---|
| 5549 | | -void tep_print_event(struct tep_handle *pevent, struct trace_seq *s, |
|---|
| 5550 | | - struct tep_record *record, bool use_trace_clock) |
|---|
| 5551 | | -{ |
|---|
| 5552 | | - struct event_format *event; |
|---|
| 5553 | | - |
|---|
| 5554 | | - event = tep_find_event_by_record(pevent, record); |
|---|
| 5555 | | - if (!event) { |
|---|
| 5556 | | - int i; |
|---|
| 5557 | | - int type = trace_parse_common_type(pevent, record->data); |
|---|
| 5558 | | - |
|---|
| 5559 | | - do_warning("ug! no event found for type %d", type); |
|---|
| 5560 | | - trace_seq_printf(s, "[UNKNOWN TYPE %d]", type); |
|---|
| 5561 | | - for (i = 0; i < record->size; i++) |
|---|
| 5562 | | - trace_seq_printf(s, " %02x", |
|---|
| 5563 | | - ((unsigned char *)record->data)[i]); |
|---|
| 6110 | + switch (arg) { |
|---|
| 6111 | + case TEP_PRINT_CPU: |
|---|
| 6112 | + param = record->cpu; |
|---|
| 6113 | + break; |
|---|
| 6114 | + case TEP_PRINT_PID: |
|---|
| 6115 | + param = parse_common_pid(tep, record->data); |
|---|
| 6116 | + break; |
|---|
| 6117 | + case TEP_PRINT_TIME: |
|---|
| 6118 | + return print_event_time(tep, s, type->format, event, record); |
|---|
| 6119 | + default: |
|---|
| 5564 | 6120 | return; |
|---|
| 5565 | 6121 | } |
|---|
| 6122 | + trace_seq_printf(s, type->format, param); |
|---|
| 6123 | +} |
|---|
| 5566 | 6124 | |
|---|
| 5567 | | - tep_print_event_task(pevent, s, event, record); |
|---|
| 5568 | | - tep_print_event_time(pevent, s, event, record, use_trace_clock); |
|---|
| 5569 | | - tep_print_event_data(pevent, s, event, record); |
|---|
| 6125 | +static int tep_print_event_param_type(char *format, |
|---|
| 6126 | + struct print_event_type *type) |
|---|
| 6127 | +{ |
|---|
| 6128 | + char *str = format + 1; |
|---|
| 6129 | + int i = 1; |
|---|
| 6130 | + |
|---|
| 6131 | + type->type = EVENT_TYPE_UNKNOWN; |
|---|
| 6132 | + while (*str) { |
|---|
| 6133 | + switch (*str) { |
|---|
| 6134 | + case 'd': |
|---|
| 6135 | + case 'u': |
|---|
| 6136 | + case 'i': |
|---|
| 6137 | + case 'x': |
|---|
| 6138 | + case 'X': |
|---|
| 6139 | + case 'o': |
|---|
| 6140 | + type->type = EVENT_TYPE_INT; |
|---|
| 6141 | + break; |
|---|
| 6142 | + case 's': |
|---|
| 6143 | + type->type = EVENT_TYPE_STRING; |
|---|
| 6144 | + break; |
|---|
| 6145 | + } |
|---|
| 6146 | + str++; |
|---|
| 6147 | + i++; |
|---|
| 6148 | + if (type->type != EVENT_TYPE_UNKNOWN) |
|---|
| 6149 | + break; |
|---|
| 6150 | + } |
|---|
| 6151 | + memset(type->format, 0, 32); |
|---|
| 6152 | + memcpy(type->format, format, i < 32 ? i : 31); |
|---|
| 6153 | + return i; |
|---|
| 6154 | +} |
|---|
| 6155 | + |
|---|
| 6156 | +/** |
|---|
| 6157 | + * tep_print_event - Write various event information |
|---|
| 6158 | + * @tep: a handle to the trace event parser context |
|---|
| 6159 | + * @s: the trace_seq to write to |
|---|
| 6160 | + * @record: The record to get the event from |
|---|
| 6161 | + * @format: a printf format string. Supported event fileds: |
|---|
| 6162 | + * TEP_PRINT_PID, "%d" - event PID |
|---|
| 6163 | + * TEP_PRINT_CPU, "%d" - event CPU |
|---|
| 6164 | + * TEP_PRINT_COMM, "%s" - event command string |
|---|
| 6165 | + * TEP_PRINT_NAME, "%s" - event name |
|---|
| 6166 | + * TEP_PRINT_LATENCY, "%s" - event latency |
|---|
| 6167 | + * TEP_PRINT_TIME, %d - event time stamp. A divisor and precision |
|---|
| 6168 | + * can be specified as part of this format string: |
|---|
| 6169 | + * "%precision.divisord". Example: |
|---|
| 6170 | + * "%3.1000d" - divide the time by 1000 and print the first |
|---|
| 6171 | + * 3 digits before the dot. Thus, the time stamp |
|---|
| 6172 | + * "123456000" will be printed as "123.456" |
|---|
| 6173 | + * TEP_PRINT_INFO, "%s" - event information. If any width is specified in |
|---|
| 6174 | + * the format string, the event information will be printed |
|---|
| 6175 | + * in raw format. |
|---|
| 6176 | + * Writes the specified event information into @s. |
|---|
| 6177 | + */ |
|---|
| 6178 | +void tep_print_event(struct tep_handle *tep, struct trace_seq *s, |
|---|
| 6179 | + struct tep_record *record, const char *fmt, ...) |
|---|
| 6180 | +{ |
|---|
| 6181 | + struct print_event_type type; |
|---|
| 6182 | + char *format = strdup(fmt); |
|---|
| 6183 | + char *current = format; |
|---|
| 6184 | + char *str = format; |
|---|
| 6185 | + int offset; |
|---|
| 6186 | + va_list args; |
|---|
| 6187 | + struct tep_event *event; |
|---|
| 6188 | + |
|---|
| 6189 | + if (!format) |
|---|
| 6190 | + return; |
|---|
| 6191 | + |
|---|
| 6192 | + event = tep_find_event_by_record(tep, record); |
|---|
| 6193 | + va_start(args, fmt); |
|---|
| 6194 | + while (*current) { |
|---|
| 6195 | + current = strchr(str, '%'); |
|---|
| 6196 | + if (!current) { |
|---|
| 6197 | + trace_seq_puts(s, str); |
|---|
| 6198 | + break; |
|---|
| 6199 | + } |
|---|
| 6200 | + memset(&type, 0, sizeof(type)); |
|---|
| 6201 | + offset = tep_print_event_param_type(current, &type); |
|---|
| 6202 | + *current = '\0'; |
|---|
| 6203 | + trace_seq_puts(s, str); |
|---|
| 6204 | + current += offset; |
|---|
| 6205 | + switch (type.type) { |
|---|
| 6206 | + case EVENT_TYPE_STRING: |
|---|
| 6207 | + print_string(tep, s, record, event, |
|---|
| 6208 | + va_arg(args, char*), &type); |
|---|
| 6209 | + break; |
|---|
| 6210 | + case EVENT_TYPE_INT: |
|---|
| 6211 | + print_int(tep, s, record, event, |
|---|
| 6212 | + va_arg(args, int), &type); |
|---|
| 6213 | + break; |
|---|
| 6214 | + case EVENT_TYPE_UNKNOWN: |
|---|
| 6215 | + default: |
|---|
| 6216 | + trace_seq_printf(s, "[UNKNOWN TYPE]"); |
|---|
| 6217 | + break; |
|---|
| 6218 | + } |
|---|
| 6219 | + str = current; |
|---|
| 6220 | + |
|---|
| 6221 | + } |
|---|
| 6222 | + va_end(args); |
|---|
| 6223 | + free(format); |
|---|
| 5570 | 6224 | } |
|---|
| 5571 | 6225 | |
|---|
| 5572 | 6226 | static int events_id_cmp(const void *a, const void *b) |
|---|
| 5573 | 6227 | { |
|---|
| 5574 | | - struct event_format * const * ea = a; |
|---|
| 5575 | | - struct event_format * const * eb = b; |
|---|
| 6228 | + struct tep_event * const * ea = a; |
|---|
| 6229 | + struct tep_event * const * eb = b; |
|---|
| 5576 | 6230 | |
|---|
| 5577 | 6231 | if ((*ea)->id < (*eb)->id) |
|---|
| 5578 | 6232 | return -1; |
|---|
| .. | .. |
|---|
| 5585 | 6239 | |
|---|
| 5586 | 6240 | static int events_name_cmp(const void *a, const void *b) |
|---|
| 5587 | 6241 | { |
|---|
| 5588 | | - struct event_format * const * ea = a; |
|---|
| 5589 | | - struct event_format * const * eb = b; |
|---|
| 6242 | + struct tep_event * const * ea = a; |
|---|
| 6243 | + struct tep_event * const * eb = b; |
|---|
| 5590 | 6244 | int res; |
|---|
| 5591 | 6245 | |
|---|
| 5592 | 6246 | res = strcmp((*ea)->name, (*eb)->name); |
|---|
| .. | .. |
|---|
| 5602 | 6256 | |
|---|
| 5603 | 6257 | static int events_system_cmp(const void *a, const void *b) |
|---|
| 5604 | 6258 | { |
|---|
| 5605 | | - struct event_format * const * ea = a; |
|---|
| 5606 | | - struct event_format * const * eb = b; |
|---|
| 6259 | + struct tep_event * const * ea = a; |
|---|
| 6260 | + struct tep_event * const * eb = b; |
|---|
| 5607 | 6261 | int res; |
|---|
| 5608 | 6262 | |
|---|
| 5609 | 6263 | res = strcmp((*ea)->system, (*eb)->system); |
|---|
| .. | .. |
|---|
| 5617 | 6271 | return events_id_cmp(a, b); |
|---|
| 5618 | 6272 | } |
|---|
| 5619 | 6273 | |
|---|
| 5620 | | -struct event_format **tep_list_events(struct tep_handle *pevent, enum event_sort_type sort_type) |
|---|
| 6274 | +static struct tep_event **list_events_copy(struct tep_handle *tep) |
|---|
| 5621 | 6275 | { |
|---|
| 5622 | | - struct event_format **events; |
|---|
| 6276 | + struct tep_event **events; |
|---|
| 6277 | + |
|---|
| 6278 | + if (!tep) |
|---|
| 6279 | + return NULL; |
|---|
| 6280 | + |
|---|
| 6281 | + events = malloc(sizeof(*events) * (tep->nr_events + 1)); |
|---|
| 6282 | + if (!events) |
|---|
| 6283 | + return NULL; |
|---|
| 6284 | + |
|---|
| 6285 | + memcpy(events, tep->events, sizeof(*events) * tep->nr_events); |
|---|
| 6286 | + events[tep->nr_events] = NULL; |
|---|
| 6287 | + return events; |
|---|
| 6288 | +} |
|---|
| 6289 | + |
|---|
| 6290 | +static void list_events_sort(struct tep_event **events, int nr_events, |
|---|
| 6291 | + enum tep_event_sort_type sort_type) |
|---|
| 6292 | +{ |
|---|
| 5623 | 6293 | int (*sort)(const void *a, const void *b); |
|---|
| 5624 | 6294 | |
|---|
| 5625 | | - events = pevent->sort_events; |
|---|
| 6295 | + switch (sort_type) { |
|---|
| 6296 | + case TEP_EVENT_SORT_ID: |
|---|
| 6297 | + sort = events_id_cmp; |
|---|
| 6298 | + break; |
|---|
| 6299 | + case TEP_EVENT_SORT_NAME: |
|---|
| 6300 | + sort = events_name_cmp; |
|---|
| 6301 | + break; |
|---|
| 6302 | + case TEP_EVENT_SORT_SYSTEM: |
|---|
| 6303 | + sort = events_system_cmp; |
|---|
| 6304 | + break; |
|---|
| 6305 | + default: |
|---|
| 6306 | + sort = NULL; |
|---|
| 6307 | + } |
|---|
| 5626 | 6308 | |
|---|
| 5627 | | - if (events && pevent->last_type == sort_type) |
|---|
| 6309 | + if (sort) |
|---|
| 6310 | + qsort(events, nr_events, sizeof(*events), sort); |
|---|
| 6311 | +} |
|---|
| 6312 | + |
|---|
| 6313 | +/** |
|---|
| 6314 | + * tep_list_events - Get events, sorted by given criteria. |
|---|
| 6315 | + * @tep: a handle to the tep context |
|---|
| 6316 | + * @sort_type: desired sort order of the events in the array |
|---|
| 6317 | + * |
|---|
| 6318 | + * Returns an array of pointers to all events, sorted by the given |
|---|
| 6319 | + * @sort_type criteria. The last element of the array is NULL. The returned |
|---|
| 6320 | + * memory must not be freed, it is managed by the library. |
|---|
| 6321 | + * The function is not thread safe. |
|---|
| 6322 | + */ |
|---|
| 6323 | +struct tep_event **tep_list_events(struct tep_handle *tep, |
|---|
| 6324 | + enum tep_event_sort_type sort_type) |
|---|
| 6325 | +{ |
|---|
| 6326 | + struct tep_event **events; |
|---|
| 6327 | + |
|---|
| 6328 | + if (!tep) |
|---|
| 6329 | + return NULL; |
|---|
| 6330 | + |
|---|
| 6331 | + events = tep->sort_events; |
|---|
| 6332 | + if (events && tep->last_type == sort_type) |
|---|
| 5628 | 6333 | return events; |
|---|
| 5629 | 6334 | |
|---|
| 5630 | 6335 | if (!events) { |
|---|
| 5631 | | - events = malloc(sizeof(*events) * (pevent->nr_events + 1)); |
|---|
| 6336 | + events = list_events_copy(tep); |
|---|
| 5632 | 6337 | if (!events) |
|---|
| 5633 | 6338 | return NULL; |
|---|
| 5634 | 6339 | |
|---|
| 5635 | | - memcpy(events, pevent->events, sizeof(*events) * pevent->nr_events); |
|---|
| 5636 | | - events[pevent->nr_events] = NULL; |
|---|
| 5637 | | - |
|---|
| 5638 | | - pevent->sort_events = events; |
|---|
| 6340 | + tep->sort_events = events; |
|---|
| 5639 | 6341 | |
|---|
| 5640 | 6342 | /* the internal events are sorted by id */ |
|---|
| 5641 | | - if (sort_type == EVENT_SORT_ID) { |
|---|
| 5642 | | - pevent->last_type = sort_type; |
|---|
| 6343 | + if (sort_type == TEP_EVENT_SORT_ID) { |
|---|
| 6344 | + tep->last_type = sort_type; |
|---|
| 5643 | 6345 | return events; |
|---|
| 5644 | 6346 | } |
|---|
| 5645 | 6347 | } |
|---|
| 5646 | 6348 | |
|---|
| 5647 | | - switch (sort_type) { |
|---|
| 5648 | | - case EVENT_SORT_ID: |
|---|
| 5649 | | - sort = events_id_cmp; |
|---|
| 5650 | | - break; |
|---|
| 5651 | | - case EVENT_SORT_NAME: |
|---|
| 5652 | | - sort = events_name_cmp; |
|---|
| 5653 | | - break; |
|---|
| 5654 | | - case EVENT_SORT_SYSTEM: |
|---|
| 5655 | | - sort = events_system_cmp; |
|---|
| 5656 | | - break; |
|---|
| 5657 | | - default: |
|---|
| 5658 | | - return events; |
|---|
| 5659 | | - } |
|---|
| 5660 | | - |
|---|
| 5661 | | - qsort(events, pevent->nr_events, sizeof(*events), sort); |
|---|
| 5662 | | - pevent->last_type = sort_type; |
|---|
| 6349 | + list_events_sort(events, tep->nr_events, sort_type); |
|---|
| 6350 | + tep->last_type = sort_type; |
|---|
| 5663 | 6351 | |
|---|
| 5664 | 6352 | return events; |
|---|
| 5665 | 6353 | } |
|---|
| 5666 | 6354 | |
|---|
| 5667 | | -static struct format_field ** |
|---|
| 5668 | | -get_event_fields(const char *type, const char *name, |
|---|
| 5669 | | - int count, struct format_field *list) |
|---|
| 6355 | + |
|---|
| 6356 | +/** |
|---|
| 6357 | + * tep_list_events_copy - Thread safe version of tep_list_events() |
|---|
| 6358 | + * @tep: a handle to the tep context |
|---|
| 6359 | + * @sort_type: desired sort order of the events in the array |
|---|
| 6360 | + * |
|---|
| 6361 | + * Returns an array of pointers to all events, sorted by the given |
|---|
| 6362 | + * @sort_type criteria. The last element of the array is NULL. The returned |
|---|
| 6363 | + * array is newly allocated inside the function and must be freed by the caller |
|---|
| 6364 | + */ |
|---|
| 6365 | +struct tep_event **tep_list_events_copy(struct tep_handle *tep, |
|---|
| 6366 | + enum tep_event_sort_type sort_type) |
|---|
| 5670 | 6367 | { |
|---|
| 5671 | | - struct format_field **fields; |
|---|
| 5672 | | - struct format_field *field; |
|---|
| 6368 | + struct tep_event **events; |
|---|
| 6369 | + |
|---|
| 6370 | + if (!tep) |
|---|
| 6371 | + return NULL; |
|---|
| 6372 | + |
|---|
| 6373 | + events = list_events_copy(tep); |
|---|
| 6374 | + if (!events) |
|---|
| 6375 | + return NULL; |
|---|
| 6376 | + |
|---|
| 6377 | + /* the internal events are sorted by id */ |
|---|
| 6378 | + if (sort_type == TEP_EVENT_SORT_ID) |
|---|
| 6379 | + return events; |
|---|
| 6380 | + |
|---|
| 6381 | + list_events_sort(events, tep->nr_events, sort_type); |
|---|
| 6382 | + |
|---|
| 6383 | + return events; |
|---|
| 6384 | +} |
|---|
| 6385 | + |
|---|
| 6386 | +static struct tep_format_field ** |
|---|
| 6387 | +get_event_fields(const char *type, const char *name, |
|---|
| 6388 | + int count, struct tep_format_field *list) |
|---|
| 6389 | +{ |
|---|
| 6390 | + struct tep_format_field **fields; |
|---|
| 6391 | + struct tep_format_field *field; |
|---|
| 5673 | 6392 | int i = 0; |
|---|
| 5674 | 6393 | |
|---|
| 5675 | 6394 | fields = malloc(sizeof(*fields) * (count + 1)); |
|---|
| .. | .. |
|---|
| 5702 | 6421 | * Returns an allocated array of fields. The last item in the array is NULL. |
|---|
| 5703 | 6422 | * The array must be freed with free(). |
|---|
| 5704 | 6423 | */ |
|---|
| 5705 | | -struct format_field **tep_event_common_fields(struct event_format *event) |
|---|
| 6424 | +struct tep_format_field **tep_event_common_fields(struct tep_event *event) |
|---|
| 5706 | 6425 | { |
|---|
| 5707 | 6426 | return get_event_fields("common", event->name, |
|---|
| 5708 | 6427 | event->format.nr_common, |
|---|
| .. | .. |
|---|
| 5716 | 6435 | * Returns an allocated array of fields. The last item in the array is NULL. |
|---|
| 5717 | 6436 | * The array must be freed with free(). |
|---|
| 5718 | 6437 | */ |
|---|
| 5719 | | -struct format_field **tep_event_fields(struct event_format *event) |
|---|
| 6438 | +struct tep_format_field **tep_event_fields(struct tep_event *event) |
|---|
| 5720 | 6439 | { |
|---|
| 5721 | 6440 | return get_event_fields("event", event->name, |
|---|
| 5722 | 6441 | event->format.nr_fields, |
|---|
| 5723 | 6442 | event->format.fields); |
|---|
| 5724 | 6443 | } |
|---|
| 5725 | 6444 | |
|---|
| 5726 | | -static void print_fields(struct trace_seq *s, struct print_flag_sym *field) |
|---|
| 6445 | +static void print_fields(struct trace_seq *s, struct tep_print_flag_sym *field) |
|---|
| 5727 | 6446 | { |
|---|
| 5728 | 6447 | trace_seq_printf(s, "{ %s, %s }", field->value, field->str); |
|---|
| 5729 | 6448 | if (field->next) { |
|---|
| .. | .. |
|---|
| 5733 | 6452 | } |
|---|
| 5734 | 6453 | |
|---|
| 5735 | 6454 | /* for debugging */ |
|---|
| 5736 | | -static void print_args(struct print_arg *args) |
|---|
| 6455 | +static void print_args(struct tep_print_arg *args) |
|---|
| 5737 | 6456 | { |
|---|
| 5738 | 6457 | int print_paren = 1; |
|---|
| 5739 | 6458 | struct trace_seq s; |
|---|
| 5740 | 6459 | |
|---|
| 5741 | 6460 | switch (args->type) { |
|---|
| 5742 | | - case PRINT_NULL: |
|---|
| 6461 | + case TEP_PRINT_NULL: |
|---|
| 5743 | 6462 | printf("null"); |
|---|
| 5744 | 6463 | break; |
|---|
| 5745 | | - case PRINT_ATOM: |
|---|
| 6464 | + case TEP_PRINT_ATOM: |
|---|
| 5746 | 6465 | printf("%s", args->atom.atom); |
|---|
| 5747 | 6466 | break; |
|---|
| 5748 | | - case PRINT_FIELD: |
|---|
| 6467 | + case TEP_PRINT_FIELD: |
|---|
| 5749 | 6468 | printf("REC->%s", args->field.name); |
|---|
| 5750 | 6469 | break; |
|---|
| 5751 | | - case PRINT_FLAGS: |
|---|
| 6470 | + case TEP_PRINT_FLAGS: |
|---|
| 5752 | 6471 | printf("__print_flags("); |
|---|
| 5753 | 6472 | print_args(args->flags.field); |
|---|
| 5754 | 6473 | printf(", %s, ", args->flags.delim); |
|---|
| .. | .. |
|---|
| 5758 | 6477 | trace_seq_destroy(&s); |
|---|
| 5759 | 6478 | printf(")"); |
|---|
| 5760 | 6479 | break; |
|---|
| 5761 | | - case PRINT_SYMBOL: |
|---|
| 6480 | + case TEP_PRINT_SYMBOL: |
|---|
| 5762 | 6481 | printf("__print_symbolic("); |
|---|
| 5763 | 6482 | print_args(args->symbol.field); |
|---|
| 5764 | 6483 | printf(", "); |
|---|
| .. | .. |
|---|
| 5768 | 6487 | trace_seq_destroy(&s); |
|---|
| 5769 | 6488 | printf(")"); |
|---|
| 5770 | 6489 | break; |
|---|
| 5771 | | - case PRINT_HEX: |
|---|
| 6490 | + case TEP_PRINT_HEX: |
|---|
| 5772 | 6491 | printf("__print_hex("); |
|---|
| 5773 | 6492 | print_args(args->hex.field); |
|---|
| 5774 | 6493 | printf(", "); |
|---|
| 5775 | 6494 | print_args(args->hex.size); |
|---|
| 5776 | 6495 | printf(")"); |
|---|
| 5777 | 6496 | break; |
|---|
| 5778 | | - case PRINT_HEX_STR: |
|---|
| 6497 | + case TEP_PRINT_HEX_STR: |
|---|
| 5779 | 6498 | printf("__print_hex_str("); |
|---|
| 5780 | 6499 | print_args(args->hex.field); |
|---|
| 5781 | 6500 | printf(", "); |
|---|
| 5782 | 6501 | print_args(args->hex.size); |
|---|
| 5783 | 6502 | printf(")"); |
|---|
| 5784 | 6503 | break; |
|---|
| 5785 | | - case PRINT_INT_ARRAY: |
|---|
| 6504 | + case TEP_PRINT_INT_ARRAY: |
|---|
| 5786 | 6505 | printf("__print_array("); |
|---|
| 5787 | 6506 | print_args(args->int_array.field); |
|---|
| 5788 | 6507 | printf(", "); |
|---|
| .. | .. |
|---|
| 5791 | 6510 | print_args(args->int_array.el_size); |
|---|
| 5792 | 6511 | printf(")"); |
|---|
| 5793 | 6512 | break; |
|---|
| 5794 | | - case PRINT_STRING: |
|---|
| 5795 | | - case PRINT_BSTRING: |
|---|
| 6513 | + case TEP_PRINT_STRING: |
|---|
| 6514 | + case TEP_PRINT_BSTRING: |
|---|
| 5796 | 6515 | printf("__get_str(%s)", args->string.string); |
|---|
| 5797 | 6516 | break; |
|---|
| 5798 | | - case PRINT_BITMASK: |
|---|
| 6517 | + case TEP_PRINT_BITMASK: |
|---|
| 5799 | 6518 | printf("__get_bitmask(%s)", args->bitmask.bitmask); |
|---|
| 5800 | 6519 | break; |
|---|
| 5801 | | - case PRINT_TYPE: |
|---|
| 6520 | + case TEP_PRINT_TYPE: |
|---|
| 5802 | 6521 | printf("(%s)", args->typecast.type); |
|---|
| 5803 | 6522 | print_args(args->typecast.item); |
|---|
| 5804 | 6523 | break; |
|---|
| 5805 | | - case PRINT_OP: |
|---|
| 6524 | + case TEP_PRINT_OP: |
|---|
| 5806 | 6525 | if (strcmp(args->op.op, ":") == 0) |
|---|
| 5807 | 6526 | print_paren = 0; |
|---|
| 5808 | 6527 | if (print_paren) |
|---|
| .. | .. |
|---|
| 5834 | 6553 | save_input_buf_ptr = input_buf_ptr; |
|---|
| 5835 | 6554 | save_input_buf_siz = input_buf_siz; |
|---|
| 5836 | 6555 | |
|---|
| 5837 | | - if (read_expected(EVENT_ITEM, "field") < 0) |
|---|
| 6556 | + if (read_expected(TEP_EVENT_ITEM, "field") < 0) |
|---|
| 5838 | 6557 | return; |
|---|
| 5839 | | - if (read_expected(EVENT_OP, ":") < 0) |
|---|
| 6558 | + if (read_expected(TEP_EVENT_OP, ":") < 0) |
|---|
| 5840 | 6559 | return; |
|---|
| 5841 | 6560 | |
|---|
| 5842 | 6561 | /* type */ |
|---|
| 5843 | | - if (read_expect_type(EVENT_ITEM, &token) < 0) |
|---|
| 6562 | + if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
|---|
| 5844 | 6563 | goto fail; |
|---|
| 5845 | 6564 | free_token(token); |
|---|
| 5846 | 6565 | |
|---|
| .. | .. |
|---|
| 5848 | 6567 | * If this is not a mandatory field, then test it first. |
|---|
| 5849 | 6568 | */ |
|---|
| 5850 | 6569 | if (mandatory) { |
|---|
| 5851 | | - if (read_expected(EVENT_ITEM, field) < 0) |
|---|
| 6570 | + if (read_expected(TEP_EVENT_ITEM, field) < 0) |
|---|
| 5852 | 6571 | return; |
|---|
| 5853 | 6572 | } else { |
|---|
| 5854 | | - if (read_expect_type(EVENT_ITEM, &token) < 0) |
|---|
| 6573 | + if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
|---|
| 5855 | 6574 | goto fail; |
|---|
| 5856 | 6575 | if (strcmp(token, field) != 0) |
|---|
| 5857 | 6576 | goto discard; |
|---|
| 5858 | 6577 | free_token(token); |
|---|
| 5859 | 6578 | } |
|---|
| 5860 | 6579 | |
|---|
| 5861 | | - if (read_expected(EVENT_OP, ";") < 0) |
|---|
| 6580 | + if (read_expected(TEP_EVENT_OP, ";") < 0) |
|---|
| 5862 | 6581 | return; |
|---|
| 5863 | | - if (read_expected(EVENT_ITEM, "offset") < 0) |
|---|
| 6582 | + if (read_expected(TEP_EVENT_ITEM, "offset") < 0) |
|---|
| 5864 | 6583 | return; |
|---|
| 5865 | | - if (read_expected(EVENT_OP, ":") < 0) |
|---|
| 6584 | + if (read_expected(TEP_EVENT_OP, ":") < 0) |
|---|
| 5866 | 6585 | return; |
|---|
| 5867 | | - if (read_expect_type(EVENT_ITEM, &token) < 0) |
|---|
| 6586 | + if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
|---|
| 5868 | 6587 | goto fail; |
|---|
| 5869 | 6588 | *offset = atoi(token); |
|---|
| 5870 | 6589 | free_token(token); |
|---|
| 5871 | | - if (read_expected(EVENT_OP, ";") < 0) |
|---|
| 6590 | + if (read_expected(TEP_EVENT_OP, ";") < 0) |
|---|
| 5872 | 6591 | return; |
|---|
| 5873 | | - if (read_expected(EVENT_ITEM, "size") < 0) |
|---|
| 6592 | + if (read_expected(TEP_EVENT_ITEM, "size") < 0) |
|---|
| 5874 | 6593 | return; |
|---|
| 5875 | | - if (read_expected(EVENT_OP, ":") < 0) |
|---|
| 6594 | + if (read_expected(TEP_EVENT_OP, ":") < 0) |
|---|
| 5876 | 6595 | return; |
|---|
| 5877 | | - if (read_expect_type(EVENT_ITEM, &token) < 0) |
|---|
| 6596 | + if (read_expect_type(TEP_EVENT_ITEM, &token) < 0) |
|---|
| 5878 | 6597 | goto fail; |
|---|
| 5879 | 6598 | *size = atoi(token); |
|---|
| 5880 | 6599 | free_token(token); |
|---|
| 5881 | | - if (read_expected(EVENT_OP, ";") < 0) |
|---|
| 6600 | + if (read_expected(TEP_EVENT_OP, ";") < 0) |
|---|
| 5882 | 6601 | return; |
|---|
| 5883 | 6602 | type = read_token(&token); |
|---|
| 5884 | | - if (type != EVENT_NEWLINE) { |
|---|
| 6603 | + if (type != TEP_EVENT_NEWLINE) { |
|---|
| 5885 | 6604 | /* newer versions of the kernel have a "signed" type */ |
|---|
| 5886 | | - if (type != EVENT_ITEM) |
|---|
| 6605 | + if (type != TEP_EVENT_ITEM) |
|---|
| 5887 | 6606 | goto fail; |
|---|
| 5888 | 6607 | |
|---|
| 5889 | 6608 | if (strcmp(token, "signed") != 0) |
|---|
| .. | .. |
|---|
| 5891 | 6610 | |
|---|
| 5892 | 6611 | free_token(token); |
|---|
| 5893 | 6612 | |
|---|
| 5894 | | - if (read_expected(EVENT_OP, ":") < 0) |
|---|
| 6613 | + if (read_expected(TEP_EVENT_OP, ":") < 0) |
|---|
| 5895 | 6614 | return; |
|---|
| 5896 | 6615 | |
|---|
| 5897 | | - if (read_expect_type(EVENT_ITEM, &token)) |
|---|
| 6616 | + if (read_expect_type(TEP_EVENT_ITEM, &token)) |
|---|
| 5898 | 6617 | goto fail; |
|---|
| 5899 | 6618 | |
|---|
| 5900 | 6619 | free_token(token); |
|---|
| 5901 | | - if (read_expected(EVENT_OP, ";") < 0) |
|---|
| 6620 | + if (read_expected(TEP_EVENT_OP, ";") < 0) |
|---|
| 5902 | 6621 | return; |
|---|
| 5903 | 6622 | |
|---|
| 5904 | | - if (read_expect_type(EVENT_NEWLINE, &token)) |
|---|
| 6623 | + if (read_expect_type(TEP_EVENT_NEWLINE, &token)) |
|---|
| 5905 | 6624 | goto fail; |
|---|
| 5906 | 6625 | } |
|---|
| 5907 | 6626 | fail: |
|---|
| .. | .. |
|---|
| 5918 | 6637 | |
|---|
| 5919 | 6638 | /** |
|---|
| 5920 | 6639 | * tep_parse_header_page - parse the data stored in the header page |
|---|
| 5921 | | - * @pevent: the handle to the pevent |
|---|
| 6640 | + * @tep: a handle to the trace event parser context |
|---|
| 5922 | 6641 | * @buf: the buffer storing the header page format string |
|---|
| 5923 | 6642 | * @size: the size of @buf |
|---|
| 5924 | 6643 | * @long_size: the long size to use if there is no header |
|---|
| .. | .. |
|---|
| 5928 | 6647 | * |
|---|
| 5929 | 6648 | * /sys/kernel/debug/tracing/events/header_page |
|---|
| 5930 | 6649 | */ |
|---|
| 5931 | | -int tep_parse_header_page(struct tep_handle *pevent, char *buf, unsigned long size, |
|---|
| 6650 | +int tep_parse_header_page(struct tep_handle *tep, char *buf, unsigned long size, |
|---|
| 5932 | 6651 | int long_size) |
|---|
| 5933 | 6652 | { |
|---|
| 5934 | 6653 | int ignore; |
|---|
| .. | .. |
|---|
| 5938 | 6657 | * Old kernels did not have header page info. |
|---|
| 5939 | 6658 | * Sorry but we just use what we find here in user space. |
|---|
| 5940 | 6659 | */ |
|---|
| 5941 | | - pevent->header_page_ts_size = sizeof(long long); |
|---|
| 5942 | | - pevent->header_page_size_size = long_size; |
|---|
| 5943 | | - pevent->header_page_data_offset = sizeof(long long) + long_size; |
|---|
| 5944 | | - pevent->old_format = 1; |
|---|
| 6660 | + tep->header_page_ts_size = sizeof(long long); |
|---|
| 6661 | + tep->header_page_size_size = long_size; |
|---|
| 6662 | + tep->header_page_data_offset = sizeof(long long) + long_size; |
|---|
| 6663 | + tep->old_format = 1; |
|---|
| 5945 | 6664 | return -1; |
|---|
| 5946 | 6665 | } |
|---|
| 5947 | 6666 | init_input_buf(buf, size); |
|---|
| 5948 | 6667 | |
|---|
| 5949 | | - parse_header_field("timestamp", &pevent->header_page_ts_offset, |
|---|
| 5950 | | - &pevent->header_page_ts_size, 1); |
|---|
| 5951 | | - parse_header_field("commit", &pevent->header_page_size_offset, |
|---|
| 5952 | | - &pevent->header_page_size_size, 1); |
|---|
| 5953 | | - parse_header_field("overwrite", &pevent->header_page_overwrite, |
|---|
| 6668 | + parse_header_field("timestamp", &tep->header_page_ts_offset, |
|---|
| 6669 | + &tep->header_page_ts_size, 1); |
|---|
| 6670 | + parse_header_field("commit", &tep->header_page_size_offset, |
|---|
| 6671 | + &tep->header_page_size_size, 1); |
|---|
| 6672 | + parse_header_field("overwrite", &tep->header_page_overwrite, |
|---|
| 5954 | 6673 | &ignore, 0); |
|---|
| 5955 | | - parse_header_field("data", &pevent->header_page_data_offset, |
|---|
| 5956 | | - &pevent->header_page_data_size, 1); |
|---|
| 6674 | + parse_header_field("data", &tep->header_page_data_offset, |
|---|
| 6675 | + &tep->header_page_data_size, 1); |
|---|
| 5957 | 6676 | |
|---|
| 5958 | 6677 | return 0; |
|---|
| 5959 | 6678 | } |
|---|
| 5960 | 6679 | |
|---|
| 5961 | | -static int event_matches(struct event_format *event, |
|---|
| 6680 | +static int event_matches(struct tep_event *event, |
|---|
| 5962 | 6681 | int id, const char *sys_name, |
|---|
| 5963 | 6682 | const char *event_name) |
|---|
| 5964 | 6683 | { |
|---|
| .. | .. |
|---|
| 5981 | 6700 | free(handle); |
|---|
| 5982 | 6701 | } |
|---|
| 5983 | 6702 | |
|---|
| 5984 | | -static int find_event_handle(struct tep_handle *pevent, struct event_format *event) |
|---|
| 6703 | +static int find_event_handle(struct tep_handle *tep, struct tep_event *event) |
|---|
| 5985 | 6704 | { |
|---|
| 5986 | 6705 | struct event_handler *handle, **next; |
|---|
| 5987 | 6706 | |
|---|
| 5988 | | - for (next = &pevent->handlers; *next; |
|---|
| 6707 | + for (next = &tep->handlers; *next; |
|---|
| 5989 | 6708 | next = &(*next)->next) { |
|---|
| 5990 | 6709 | handle = *next; |
|---|
| 5991 | 6710 | if (event_matches(event, handle->id, |
|---|
| .. | .. |
|---|
| 6010 | 6729 | } |
|---|
| 6011 | 6730 | |
|---|
| 6012 | 6731 | /** |
|---|
| 6013 | | - * __tep_parse_format - parse the event format |
|---|
| 6732 | + * parse_format - parse the event format |
|---|
| 6014 | 6733 | * @buf: the buffer storing the event format string |
|---|
| 6015 | 6734 | * @size: the size of @buf |
|---|
| 6016 | 6735 | * @sys: the system the event belongs to |
|---|
| .. | .. |
|---|
| 6022 | 6741 | * |
|---|
| 6023 | 6742 | * /sys/kernel/debug/tracing/events/.../.../format |
|---|
| 6024 | 6743 | */ |
|---|
| 6025 | | -enum tep_errno __tep_parse_format(struct event_format **eventp, |
|---|
| 6026 | | - struct tep_handle *pevent, const char *buf, |
|---|
| 6027 | | - unsigned long size, const char *sys) |
|---|
| 6744 | +static enum tep_errno parse_format(struct tep_event **eventp, |
|---|
| 6745 | + struct tep_handle *tep, const char *buf, |
|---|
| 6746 | + unsigned long size, const char *sys) |
|---|
| 6028 | 6747 | { |
|---|
| 6029 | | - struct event_format *event; |
|---|
| 6748 | + struct tep_event *event; |
|---|
| 6030 | 6749 | int ret; |
|---|
| 6031 | 6750 | |
|---|
| 6032 | 6751 | init_input_buf(buf, size); |
|---|
| .. | .. |
|---|
| 6043 | 6762 | } |
|---|
| 6044 | 6763 | |
|---|
| 6045 | 6764 | if (strcmp(sys, "ftrace") == 0) { |
|---|
| 6046 | | - event->flags |= EVENT_FL_ISFTRACE; |
|---|
| 6765 | + event->flags |= TEP_EVENT_FL_ISFTRACE; |
|---|
| 6047 | 6766 | |
|---|
| 6048 | 6767 | if (strcmp(event->name, "bprint") == 0) |
|---|
| 6049 | | - event->flags |= EVENT_FL_ISBPRINT; |
|---|
| 6768 | + event->flags |= TEP_EVENT_FL_ISBPRINT; |
|---|
| 6050 | 6769 | } |
|---|
| 6051 | 6770 | |
|---|
| 6052 | 6771 | event->id = event_read_id(); |
|---|
| .. | .. |
|---|
| 6065 | 6784 | goto event_alloc_failed; |
|---|
| 6066 | 6785 | } |
|---|
| 6067 | 6786 | |
|---|
| 6068 | | - /* Add pevent to event so that it can be referenced */ |
|---|
| 6069 | | - event->pevent = pevent; |
|---|
| 6787 | + /* Add tep to event so that it can be referenced */ |
|---|
| 6788 | + event->tep = tep; |
|---|
| 6070 | 6789 | |
|---|
| 6071 | 6790 | ret = event_read_format(event); |
|---|
| 6072 | 6791 | if (ret < 0) { |
|---|
| .. | .. |
|---|
| 6078 | 6797 | * If the event has an override, don't print warnings if the event |
|---|
| 6079 | 6798 | * print format fails to parse. |
|---|
| 6080 | 6799 | */ |
|---|
| 6081 | | - if (pevent && find_event_handle(pevent, event)) |
|---|
| 6800 | + if (tep && find_event_handle(tep, event)) |
|---|
| 6082 | 6801 | show_warning = 0; |
|---|
| 6083 | 6802 | |
|---|
| 6084 | 6803 | ret = event_read_print(event); |
|---|
| .. | .. |
|---|
| 6089 | 6808 | goto event_parse_failed; |
|---|
| 6090 | 6809 | } |
|---|
| 6091 | 6810 | |
|---|
| 6092 | | - if (!ret && (event->flags & EVENT_FL_ISFTRACE)) { |
|---|
| 6093 | | - struct format_field *field; |
|---|
| 6094 | | - struct print_arg *arg, **list; |
|---|
| 6811 | + if (!ret && (event->flags & TEP_EVENT_FL_ISFTRACE)) { |
|---|
| 6812 | + struct tep_format_field *field; |
|---|
| 6813 | + struct tep_print_arg *arg, **list; |
|---|
| 6095 | 6814 | |
|---|
| 6096 | 6815 | /* old ftrace had no args */ |
|---|
| 6097 | 6816 | list = &event->print_fmt.args; |
|---|
| 6098 | 6817 | for (field = event->format.fields; field; field = field->next) { |
|---|
| 6099 | 6818 | arg = alloc_arg(); |
|---|
| 6100 | 6819 | if (!arg) { |
|---|
| 6101 | | - event->flags |= EVENT_FL_FAILED; |
|---|
| 6820 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 6102 | 6821 | return TEP_ERRNO__OLD_FTRACE_ARG_FAILED; |
|---|
| 6103 | 6822 | } |
|---|
| 6104 | | - arg->type = PRINT_FIELD; |
|---|
| 6823 | + arg->type = TEP_PRINT_FIELD; |
|---|
| 6105 | 6824 | arg->field.name = strdup(field->name); |
|---|
| 6106 | 6825 | if (!arg->field.name) { |
|---|
| 6107 | | - event->flags |= EVENT_FL_FAILED; |
|---|
| 6826 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 6108 | 6827 | free_arg(arg); |
|---|
| 6109 | 6828 | return TEP_ERRNO__OLD_FTRACE_ARG_FAILED; |
|---|
| 6110 | 6829 | } |
|---|
| .. | .. |
|---|
| 6112 | 6831 | *list = arg; |
|---|
| 6113 | 6832 | list = &arg->next; |
|---|
| 6114 | 6833 | } |
|---|
| 6115 | | - return 0; |
|---|
| 6116 | 6834 | } |
|---|
| 6835 | + |
|---|
| 6836 | + if (!(event->flags & TEP_EVENT_FL_ISBPRINT)) |
|---|
| 6837 | + event->print_fmt.print_cache = parse_args(event, |
|---|
| 6838 | + event->print_fmt.format, |
|---|
| 6839 | + event->print_fmt.args); |
|---|
| 6117 | 6840 | |
|---|
| 6118 | 6841 | return 0; |
|---|
| 6119 | 6842 | |
|---|
| 6120 | 6843 | event_parse_failed: |
|---|
| 6121 | | - event->flags |= EVENT_FL_FAILED; |
|---|
| 6844 | + event->flags |= TEP_EVENT_FL_FAILED; |
|---|
| 6122 | 6845 | return ret; |
|---|
| 6123 | 6846 | |
|---|
| 6124 | 6847 | event_alloc_failed: |
|---|
| .. | .. |
|---|
| 6130 | 6853 | } |
|---|
| 6131 | 6854 | |
|---|
| 6132 | 6855 | static enum tep_errno |
|---|
| 6133 | | -__parse_event(struct tep_handle *pevent, |
|---|
| 6134 | | - struct event_format **eventp, |
|---|
| 6856 | +__parse_event(struct tep_handle *tep, |
|---|
| 6857 | + struct tep_event **eventp, |
|---|
| 6135 | 6858 | const char *buf, unsigned long size, |
|---|
| 6136 | 6859 | const char *sys) |
|---|
| 6137 | 6860 | { |
|---|
| 6138 | | - int ret = __tep_parse_format(eventp, pevent, buf, size, sys); |
|---|
| 6139 | | - struct event_format *event = *eventp; |
|---|
| 6861 | + int ret = parse_format(eventp, tep, buf, size, sys); |
|---|
| 6862 | + struct tep_event *event = *eventp; |
|---|
| 6140 | 6863 | |
|---|
| 6141 | 6864 | if (event == NULL) |
|---|
| 6142 | 6865 | return ret; |
|---|
| 6143 | 6866 | |
|---|
| 6144 | | - if (pevent && add_event(pevent, event)) { |
|---|
| 6867 | + if (tep && add_event(tep, event)) { |
|---|
| 6145 | 6868 | ret = TEP_ERRNO__MEM_ALLOC_FAILED; |
|---|
| 6146 | 6869 | goto event_add_failed; |
|---|
| 6147 | 6870 | } |
|---|
| .. | .. |
|---|
| 6153 | 6876 | return 0; |
|---|
| 6154 | 6877 | |
|---|
| 6155 | 6878 | event_add_failed: |
|---|
| 6156 | | - tep_free_format(event); |
|---|
| 6879 | + free_tep_event(event); |
|---|
| 6157 | 6880 | return ret; |
|---|
| 6158 | 6881 | } |
|---|
| 6159 | 6882 | |
|---|
| 6160 | 6883 | /** |
|---|
| 6161 | 6884 | * tep_parse_format - parse the event format |
|---|
| 6162 | | - * @pevent: the handle to the pevent |
|---|
| 6885 | + * @tep: a handle to the trace event parser context |
|---|
| 6163 | 6886 | * @eventp: returned format |
|---|
| 6164 | 6887 | * @buf: the buffer storing the event format string |
|---|
| 6165 | 6888 | * @size: the size of @buf |
|---|
| .. | .. |
|---|
| 6172 | 6895 | * |
|---|
| 6173 | 6896 | * /sys/kernel/debug/tracing/events/.../.../format |
|---|
| 6174 | 6897 | */ |
|---|
| 6175 | | -enum tep_errno tep_parse_format(struct tep_handle *pevent, |
|---|
| 6176 | | - struct event_format **eventp, |
|---|
| 6898 | +enum tep_errno tep_parse_format(struct tep_handle *tep, |
|---|
| 6899 | + struct tep_event **eventp, |
|---|
| 6177 | 6900 | const char *buf, |
|---|
| 6178 | 6901 | unsigned long size, const char *sys) |
|---|
| 6179 | 6902 | { |
|---|
| 6180 | | - return __parse_event(pevent, eventp, buf, size, sys); |
|---|
| 6903 | + return __parse_event(tep, eventp, buf, size, sys); |
|---|
| 6181 | 6904 | } |
|---|
| 6182 | 6905 | |
|---|
| 6183 | 6906 | /** |
|---|
| 6184 | 6907 | * tep_parse_event - parse the event format |
|---|
| 6185 | | - * @pevent: the handle to the pevent |
|---|
| 6908 | + * @tep: a handle to the trace event parser context |
|---|
| 6186 | 6909 | * @buf: the buffer storing the event format string |
|---|
| 6187 | 6910 | * @size: the size of @buf |
|---|
| 6188 | 6911 | * @sys: the system the event belongs to |
|---|
| .. | .. |
|---|
| 6194 | 6917 | * |
|---|
| 6195 | 6918 | * /sys/kernel/debug/tracing/events/.../.../format |
|---|
| 6196 | 6919 | */ |
|---|
| 6197 | | -enum tep_errno tep_parse_event(struct tep_handle *pevent, const char *buf, |
|---|
| 6920 | +enum tep_errno tep_parse_event(struct tep_handle *tep, const char *buf, |
|---|
| 6198 | 6921 | unsigned long size, const char *sys) |
|---|
| 6199 | 6922 | { |
|---|
| 6200 | | - struct event_format *event = NULL; |
|---|
| 6201 | | - return __parse_event(pevent, &event, buf, size, sys); |
|---|
| 6923 | + struct tep_event *event = NULL; |
|---|
| 6924 | + return __parse_event(tep, &event, buf, size, sys); |
|---|
| 6202 | 6925 | } |
|---|
| 6203 | 6926 | |
|---|
| 6204 | | -#undef _PE |
|---|
| 6205 | | -#define _PE(code, str) str |
|---|
| 6206 | | -static const char * const tep_error_str[] = { |
|---|
| 6207 | | - TEP_ERRORS |
|---|
| 6208 | | -}; |
|---|
| 6209 | | -#undef _PE |
|---|
| 6210 | | - |
|---|
| 6211 | | -int tep_strerror(struct tep_handle *pevent __maybe_unused, |
|---|
| 6212 | | - enum tep_errno errnum, char *buf, size_t buflen) |
|---|
| 6213 | | -{ |
|---|
| 6214 | | - int idx; |
|---|
| 6215 | | - const char *msg; |
|---|
| 6216 | | - |
|---|
| 6217 | | - if (errnum >= 0) { |
|---|
| 6218 | | - str_error_r(errnum, buf, buflen); |
|---|
| 6219 | | - return 0; |
|---|
| 6220 | | - } |
|---|
| 6221 | | - |
|---|
| 6222 | | - if (errnum <= __TEP_ERRNO__START || |
|---|
| 6223 | | - errnum >= __TEP_ERRNO__END) |
|---|
| 6224 | | - return -1; |
|---|
| 6225 | | - |
|---|
| 6226 | | - idx = errnum - __TEP_ERRNO__START - 1; |
|---|
| 6227 | | - msg = tep_error_str[idx]; |
|---|
| 6228 | | - snprintf(buf, buflen, "%s", msg); |
|---|
| 6229 | | - |
|---|
| 6230 | | - return 0; |
|---|
| 6231 | | -} |
|---|
| 6232 | | - |
|---|
| 6233 | | -int get_field_val(struct trace_seq *s, struct format_field *field, |
|---|
| 6927 | +int get_field_val(struct trace_seq *s, struct tep_format_field *field, |
|---|
| 6234 | 6928 | const char *name, struct tep_record *record, |
|---|
| 6235 | 6929 | unsigned long long *val, int err) |
|---|
| 6236 | 6930 | { |
|---|
| .. | .. |
|---|
| 6263 | 6957 | * |
|---|
| 6264 | 6958 | * On failure, it returns NULL. |
|---|
| 6265 | 6959 | */ |
|---|
| 6266 | | -void *tep_get_field_raw(struct trace_seq *s, struct event_format *event, |
|---|
| 6960 | +void *tep_get_field_raw(struct trace_seq *s, struct tep_event *event, |
|---|
| 6267 | 6961 | const char *name, struct tep_record *record, |
|---|
| 6268 | 6962 | int *len, int err) |
|---|
| 6269 | 6963 | { |
|---|
| 6270 | | - struct format_field *field; |
|---|
| 6964 | + struct tep_format_field *field; |
|---|
| 6271 | 6965 | void *data = record->data; |
|---|
| 6272 | 6966 | unsigned offset; |
|---|
| 6273 | 6967 | int dummy; |
|---|
| .. | .. |
|---|
| 6288 | 6982 | len = &dummy; |
|---|
| 6289 | 6983 | |
|---|
| 6290 | 6984 | offset = field->offset; |
|---|
| 6291 | | - if (field->flags & FIELD_IS_DYNAMIC) { |
|---|
| 6292 | | - offset = tep_read_number(event->pevent, |
|---|
| 6293 | | - data + offset, field->size); |
|---|
| 6985 | + if (field->flags & TEP_FIELD_IS_DYNAMIC) { |
|---|
| 6986 | + offset = tep_read_number(event->tep, |
|---|
| 6987 | + data + offset, field->size); |
|---|
| 6294 | 6988 | *len = offset >> 16; |
|---|
| 6295 | 6989 | offset &= 0xffff; |
|---|
| 6296 | 6990 | } else |
|---|
| .. | .. |
|---|
| 6310 | 7004 | * |
|---|
| 6311 | 7005 | * Returns 0 on success -1 on field not found. |
|---|
| 6312 | 7006 | */ |
|---|
| 6313 | | -int tep_get_field_val(struct trace_seq *s, struct event_format *event, |
|---|
| 7007 | +int tep_get_field_val(struct trace_seq *s, struct tep_event *event, |
|---|
| 6314 | 7008 | const char *name, struct tep_record *record, |
|---|
| 6315 | 7009 | unsigned long long *val, int err) |
|---|
| 6316 | 7010 | { |
|---|
| 6317 | | - struct format_field *field; |
|---|
| 7011 | + struct tep_format_field *field; |
|---|
| 6318 | 7012 | |
|---|
| 6319 | 7013 | if (!event) |
|---|
| 6320 | 7014 | return -1; |
|---|
| .. | .. |
|---|
| 6335 | 7029 | * |
|---|
| 6336 | 7030 | * Returns 0 on success -1 on field not found. |
|---|
| 6337 | 7031 | */ |
|---|
| 6338 | | -int tep_get_common_field_val(struct trace_seq *s, struct event_format *event, |
|---|
| 7032 | +int tep_get_common_field_val(struct trace_seq *s, struct tep_event *event, |
|---|
| 6339 | 7033 | const char *name, struct tep_record *record, |
|---|
| 6340 | 7034 | unsigned long long *val, int err) |
|---|
| 6341 | 7035 | { |
|---|
| 6342 | | - struct format_field *field; |
|---|
| 7036 | + struct tep_format_field *field; |
|---|
| 6343 | 7037 | |
|---|
| 6344 | 7038 | if (!event) |
|---|
| 6345 | 7039 | return -1; |
|---|
| .. | .. |
|---|
| 6360 | 7054 | * |
|---|
| 6361 | 7055 | * Returns 0 on success -1 on field not found. |
|---|
| 6362 | 7056 | */ |
|---|
| 6363 | | -int tep_get_any_field_val(struct trace_seq *s, struct event_format *event, |
|---|
| 7057 | +int tep_get_any_field_val(struct trace_seq *s, struct tep_event *event, |
|---|
| 6364 | 7058 | const char *name, struct tep_record *record, |
|---|
| 6365 | 7059 | unsigned long long *val, int err) |
|---|
| 6366 | 7060 | { |
|---|
| 6367 | | - struct format_field *field; |
|---|
| 7061 | + struct tep_format_field *field; |
|---|
| 6368 | 7062 | |
|---|
| 6369 | 7063 | if (!event) |
|---|
| 6370 | 7064 | return -1; |
|---|
| .. | .. |
|---|
| 6383 | 7077 | * @record: The record with the field name. |
|---|
| 6384 | 7078 | * @err: print default error if failed. |
|---|
| 6385 | 7079 | * |
|---|
| 6386 | | - * Returns: 0 on success, -1 field not found, or 1 if buffer is full. |
|---|
| 7080 | + * Returns positive value on success, negative in case of an error, |
|---|
| 7081 | + * or 0 if buffer is full. |
|---|
| 6387 | 7082 | */ |
|---|
| 6388 | 7083 | int tep_print_num_field(struct trace_seq *s, const char *fmt, |
|---|
| 6389 | | - struct event_format *event, const char *name, |
|---|
| 7084 | + struct tep_event *event, const char *name, |
|---|
| 6390 | 7085 | struct tep_record *record, int err) |
|---|
| 6391 | 7086 | { |
|---|
| 6392 | | - struct format_field *field = tep_find_field(event, name); |
|---|
| 7087 | + struct tep_format_field *field = tep_find_field(event, name); |
|---|
| 6393 | 7088 | unsigned long long val; |
|---|
| 6394 | 7089 | |
|---|
| 6395 | 7090 | if (!field) |
|---|
| .. | .. |
|---|
| 6415 | 7110 | * @record: The record with the field name. |
|---|
| 6416 | 7111 | * @err: print default error if failed. |
|---|
| 6417 | 7112 | * |
|---|
| 6418 | | - * Returns: 0 on success, -1 field not found, or 1 if buffer is full. |
|---|
| 7113 | + * Returns positive value on success, negative in case of an error, |
|---|
| 7114 | + * or 0 if buffer is full. |
|---|
| 6419 | 7115 | */ |
|---|
| 6420 | 7116 | int tep_print_func_field(struct trace_seq *s, const char *fmt, |
|---|
| 6421 | | - struct event_format *event, const char *name, |
|---|
| 7117 | + struct tep_event *event, const char *name, |
|---|
| 6422 | 7118 | struct tep_record *record, int err) |
|---|
| 6423 | 7119 | { |
|---|
| 6424 | | - struct format_field *field = tep_find_field(event, name); |
|---|
| 6425 | | - struct tep_handle *pevent = event->pevent; |
|---|
| 7120 | + struct tep_format_field *field = tep_find_field(event, name); |
|---|
| 7121 | + struct tep_handle *tep = event->tep; |
|---|
| 6426 | 7122 | unsigned long long val; |
|---|
| 6427 | 7123 | struct func_map *func; |
|---|
| 6428 | 7124 | char tmp[128]; |
|---|
| .. | .. |
|---|
| 6433 | 7129 | if (tep_read_number_field(field, record->data, &val)) |
|---|
| 6434 | 7130 | goto failed; |
|---|
| 6435 | 7131 | |
|---|
| 6436 | | - func = find_func(pevent, val); |
|---|
| 7132 | + func = find_func(tep, val); |
|---|
| 6437 | 7133 | |
|---|
| 6438 | 7134 | if (func) |
|---|
| 6439 | 7135 | snprintf(tmp, 128, "%s/0x%llx", func->func, func->addr - val); |
|---|
| .. | .. |
|---|
| 6465 | 7161 | |
|---|
| 6466 | 7162 | /** |
|---|
| 6467 | 7163 | * tep_register_print_function - register a helper function |
|---|
| 6468 | | - * @pevent: the handle to the pevent |
|---|
| 7164 | + * @tep: a handle to the trace event parser context |
|---|
| 6469 | 7165 | * @func: the function to process the helper function |
|---|
| 6470 | 7166 | * @ret_type: the return type of the helper function |
|---|
| 6471 | 7167 | * @name: the name of the helper function |
|---|
| .. | .. |
|---|
| 6478 | 7174 | * The @parameters is a variable list of tep_func_arg_type enums that |
|---|
| 6479 | 7175 | * must end with TEP_FUNC_ARG_VOID. |
|---|
| 6480 | 7176 | */ |
|---|
| 6481 | | -int tep_register_print_function(struct tep_handle *pevent, |
|---|
| 7177 | +int tep_register_print_function(struct tep_handle *tep, |
|---|
| 6482 | 7178 | tep_func_handler func, |
|---|
| 6483 | 7179 | enum tep_func_arg_type ret_type, |
|---|
| 6484 | 7180 | char *name, ...) |
|---|
| .. | .. |
|---|
| 6490 | 7186 | va_list ap; |
|---|
| 6491 | 7187 | int ret; |
|---|
| 6492 | 7188 | |
|---|
| 6493 | | - func_handle = find_func_handler(pevent, name); |
|---|
| 7189 | + func_handle = find_func_handler(tep, name); |
|---|
| 6494 | 7190 | if (func_handle) { |
|---|
| 6495 | 7191 | /* |
|---|
| 6496 | 7192 | * This is most like caused by the users own |
|---|
| .. | .. |
|---|
| 6498 | 7194 | * system defaults. |
|---|
| 6499 | 7195 | */ |
|---|
| 6500 | 7196 | pr_stat("override of function helper '%s'", name); |
|---|
| 6501 | | - remove_func_handler(pevent, name); |
|---|
| 7197 | + remove_func_handler(tep, name); |
|---|
| 6502 | 7198 | } |
|---|
| 6503 | 7199 | |
|---|
| 6504 | 7200 | func_handle = calloc(1, sizeof(*func_handle)); |
|---|
| .. | .. |
|---|
| 6545 | 7241 | } |
|---|
| 6546 | 7242 | va_end(ap); |
|---|
| 6547 | 7243 | |
|---|
| 6548 | | - func_handle->next = pevent->func_handlers; |
|---|
| 6549 | | - pevent->func_handlers = func_handle; |
|---|
| 7244 | + func_handle->next = tep->func_handlers; |
|---|
| 7245 | + tep->func_handlers = func_handle; |
|---|
| 6550 | 7246 | |
|---|
| 6551 | 7247 | return 0; |
|---|
| 6552 | 7248 | out_free: |
|---|
| .. | .. |
|---|
| 6557 | 7253 | |
|---|
| 6558 | 7254 | /** |
|---|
| 6559 | 7255 | * tep_unregister_print_function - unregister a helper function |
|---|
| 6560 | | - * @pevent: the handle to the pevent |
|---|
| 7256 | + * @tep: a handle to the trace event parser context |
|---|
| 6561 | 7257 | * @func: the function to process the helper function |
|---|
| 6562 | 7258 | * @name: the name of the helper function |
|---|
| 6563 | 7259 | * |
|---|
| .. | .. |
|---|
| 6565 | 7261 | * |
|---|
| 6566 | 7262 | * Returns 0 if the handler was removed successully, -1 otherwise. |
|---|
| 6567 | 7263 | */ |
|---|
| 6568 | | -int tep_unregister_print_function(struct tep_handle *pevent, |
|---|
| 7264 | +int tep_unregister_print_function(struct tep_handle *tep, |
|---|
| 6569 | 7265 | tep_func_handler func, char *name) |
|---|
| 6570 | 7266 | { |
|---|
| 6571 | 7267 | struct tep_function_handler *func_handle; |
|---|
| 6572 | 7268 | |
|---|
| 6573 | | - func_handle = find_func_handler(pevent, name); |
|---|
| 7269 | + func_handle = find_func_handler(tep, name); |
|---|
| 6574 | 7270 | if (func_handle && func_handle->func == func) { |
|---|
| 6575 | | - remove_func_handler(pevent, name); |
|---|
| 7271 | + remove_func_handler(tep, name); |
|---|
| 6576 | 7272 | return 0; |
|---|
| 6577 | 7273 | } |
|---|
| 6578 | 7274 | return -1; |
|---|
| 6579 | 7275 | } |
|---|
| 6580 | 7276 | |
|---|
| 6581 | | -static struct event_format *search_event(struct tep_handle *pevent, int id, |
|---|
| 6582 | | - const char *sys_name, |
|---|
| 6583 | | - const char *event_name) |
|---|
| 7277 | +static struct tep_event *search_event(struct tep_handle *tep, int id, |
|---|
| 7278 | + const char *sys_name, |
|---|
| 7279 | + const char *event_name) |
|---|
| 6584 | 7280 | { |
|---|
| 6585 | | - struct event_format *event; |
|---|
| 7281 | + struct tep_event *event; |
|---|
| 6586 | 7282 | |
|---|
| 6587 | 7283 | if (id >= 0) { |
|---|
| 6588 | 7284 | /* search by id */ |
|---|
| 6589 | | - event = tep_find_event(pevent, id); |
|---|
| 7285 | + event = tep_find_event(tep, id); |
|---|
| 6590 | 7286 | if (!event) |
|---|
| 6591 | 7287 | return NULL; |
|---|
| 6592 | 7288 | if (event_name && (strcmp(event_name, event->name) != 0)) |
|---|
| .. | .. |
|---|
| 6594 | 7290 | if (sys_name && (strcmp(sys_name, event->system) != 0)) |
|---|
| 6595 | 7291 | return NULL; |
|---|
| 6596 | 7292 | } else { |
|---|
| 6597 | | - event = tep_find_event_by_name(pevent, sys_name, event_name); |
|---|
| 7293 | + event = tep_find_event_by_name(tep, sys_name, event_name); |
|---|
| 6598 | 7294 | if (!event) |
|---|
| 6599 | 7295 | return NULL; |
|---|
| 6600 | 7296 | } |
|---|
| .. | .. |
|---|
| 6603 | 7299 | |
|---|
| 6604 | 7300 | /** |
|---|
| 6605 | 7301 | * tep_register_event_handler - register a way to parse an event |
|---|
| 6606 | | - * @pevent: the handle to the pevent |
|---|
| 7302 | + * @tep: a handle to the trace event parser context |
|---|
| 6607 | 7303 | * @id: the id of the event to register |
|---|
| 6608 | 7304 | * @sys_name: the system name the event belongs to |
|---|
| 6609 | 7305 | * @event_name: the name of the event |
|---|
| .. | .. |
|---|
| 6617 | 7313 | * |
|---|
| 6618 | 7314 | * If @id is >= 0, then it is used to find the event. |
|---|
| 6619 | 7315 | * else @sys_name and @event_name are used. |
|---|
| 7316 | + * |
|---|
| 7317 | + * Returns: |
|---|
| 7318 | + * TEP_REGISTER_SUCCESS_OVERWRITE if an existing handler is overwritten |
|---|
| 7319 | + * TEP_REGISTER_SUCCESS if a new handler is registered successfully |
|---|
| 7320 | + * negative TEP_ERRNO_... in case of an error |
|---|
| 7321 | + * |
|---|
| 6620 | 7322 | */ |
|---|
| 6621 | | -int tep_register_event_handler(struct tep_handle *pevent, int id, |
|---|
| 7323 | +int tep_register_event_handler(struct tep_handle *tep, int id, |
|---|
| 6622 | 7324 | const char *sys_name, const char *event_name, |
|---|
| 6623 | 7325 | tep_event_handler_func func, void *context) |
|---|
| 6624 | 7326 | { |
|---|
| 6625 | | - struct event_format *event; |
|---|
| 7327 | + struct tep_event *event; |
|---|
| 6626 | 7328 | struct event_handler *handle; |
|---|
| 6627 | 7329 | |
|---|
| 6628 | | - event = search_event(pevent, id, sys_name, event_name); |
|---|
| 7330 | + event = search_event(tep, id, sys_name, event_name); |
|---|
| 6629 | 7331 | if (event == NULL) |
|---|
| 6630 | 7332 | goto not_found; |
|---|
| 6631 | 7333 | |
|---|
| .. | .. |
|---|
| 6634 | 7336 | |
|---|
| 6635 | 7337 | event->handler = func; |
|---|
| 6636 | 7338 | event->context = context; |
|---|
| 6637 | | - return 0; |
|---|
| 7339 | + return TEP_REGISTER_SUCCESS_OVERWRITE; |
|---|
| 6638 | 7340 | |
|---|
| 6639 | 7341 | not_found: |
|---|
| 6640 | 7342 | /* Save for later use. */ |
|---|
| .. | .. |
|---|
| 6660 | 7362 | } |
|---|
| 6661 | 7363 | |
|---|
| 6662 | 7364 | handle->func = func; |
|---|
| 6663 | | - handle->next = pevent->handlers; |
|---|
| 6664 | | - pevent->handlers = handle; |
|---|
| 7365 | + handle->next = tep->handlers; |
|---|
| 7366 | + tep->handlers = handle; |
|---|
| 6665 | 7367 | handle->context = context; |
|---|
| 6666 | 7368 | |
|---|
| 6667 | | - return -1; |
|---|
| 7369 | + return TEP_REGISTER_SUCCESS; |
|---|
| 6668 | 7370 | } |
|---|
| 6669 | 7371 | |
|---|
| 6670 | 7372 | static int handle_matches(struct event_handler *handler, int id, |
|---|
| .. | .. |
|---|
| 6688 | 7390 | |
|---|
| 6689 | 7391 | /** |
|---|
| 6690 | 7392 | * tep_unregister_event_handler - unregister an existing event handler |
|---|
| 6691 | | - * @pevent: the handle to the pevent |
|---|
| 7393 | + * @tep: a handle to the trace event parser context |
|---|
| 6692 | 7394 | * @id: the id of the event to unregister |
|---|
| 6693 | 7395 | * @sys_name: the system name the handler belongs to |
|---|
| 6694 | 7396 | * @event_name: the name of the event handler |
|---|
| .. | .. |
|---|
| 6702 | 7404 | * |
|---|
| 6703 | 7405 | * Returns 0 if handler was removed successfully, -1 if event was not found. |
|---|
| 6704 | 7406 | */ |
|---|
| 6705 | | -int tep_unregister_event_handler(struct tep_handle *pevent, int id, |
|---|
| 7407 | +int tep_unregister_event_handler(struct tep_handle *tep, int id, |
|---|
| 6706 | 7408 | const char *sys_name, const char *event_name, |
|---|
| 6707 | 7409 | tep_event_handler_func func, void *context) |
|---|
| 6708 | 7410 | { |
|---|
| 6709 | | - struct event_format *event; |
|---|
| 7411 | + struct tep_event *event; |
|---|
| 6710 | 7412 | struct event_handler *handle; |
|---|
| 6711 | 7413 | struct event_handler **next; |
|---|
| 6712 | 7414 | |
|---|
| 6713 | | - event = search_event(pevent, id, sys_name, event_name); |
|---|
| 7415 | + event = search_event(tep, id, sys_name, event_name); |
|---|
| 6714 | 7416 | if (event == NULL) |
|---|
| 6715 | 7417 | goto not_found; |
|---|
| 6716 | 7418 | |
|---|
| .. | .. |
|---|
| 6724 | 7426 | } |
|---|
| 6725 | 7427 | |
|---|
| 6726 | 7428 | not_found: |
|---|
| 6727 | | - for (next = &pevent->handlers; *next; next = &(*next)->next) { |
|---|
| 7429 | + for (next = &tep->handlers; *next; next = &(*next)->next) { |
|---|
| 6728 | 7430 | handle = *next; |
|---|
| 6729 | 7431 | if (handle_matches(handle, id, sys_name, event_name, |
|---|
| 6730 | 7432 | func, context)) |
|---|
| .. | .. |
|---|
| 6741 | 7443 | } |
|---|
| 6742 | 7444 | |
|---|
| 6743 | 7445 | /** |
|---|
| 6744 | | - * tep_alloc - create a pevent handle |
|---|
| 7446 | + * tep_alloc - create a tep handle |
|---|
| 6745 | 7447 | */ |
|---|
| 6746 | 7448 | struct tep_handle *tep_alloc(void) |
|---|
| 6747 | 7449 | { |
|---|
| 6748 | | - struct tep_handle *pevent = calloc(1, sizeof(*pevent)); |
|---|
| 7450 | + struct tep_handle *tep = calloc(1, sizeof(*tep)); |
|---|
| 6749 | 7451 | |
|---|
| 6750 | | - if (pevent) |
|---|
| 6751 | | - pevent->ref_count = 1; |
|---|
| 7452 | + if (tep) { |
|---|
| 7453 | + tep->ref_count = 1; |
|---|
| 7454 | + tep->host_bigendian = tep_is_bigendian(); |
|---|
| 7455 | + } |
|---|
| 6752 | 7456 | |
|---|
| 6753 | | - return pevent; |
|---|
| 7457 | + return tep; |
|---|
| 6754 | 7458 | } |
|---|
| 6755 | 7459 | |
|---|
| 6756 | | -void tep_ref(struct tep_handle *pevent) |
|---|
| 7460 | +void tep_ref(struct tep_handle *tep) |
|---|
| 6757 | 7461 | { |
|---|
| 6758 | | - pevent->ref_count++; |
|---|
| 7462 | + tep->ref_count++; |
|---|
| 6759 | 7463 | } |
|---|
| 6760 | 7464 | |
|---|
| 6761 | | -void tep_free_format_field(struct format_field *field) |
|---|
| 7465 | +int tep_get_ref(struct tep_handle *tep) |
|---|
| 7466 | +{ |
|---|
| 7467 | + if (tep) |
|---|
| 7468 | + return tep->ref_count; |
|---|
| 7469 | + return 0; |
|---|
| 7470 | +} |
|---|
| 7471 | + |
|---|
| 7472 | +__hidden void free_tep_format_field(struct tep_format_field *field) |
|---|
| 6762 | 7473 | { |
|---|
| 6763 | 7474 | free(field->type); |
|---|
| 6764 | 7475 | if (field->alias != field->name) |
|---|
| .. | .. |
|---|
| 6767 | 7478 | free(field); |
|---|
| 6768 | 7479 | } |
|---|
| 6769 | 7480 | |
|---|
| 6770 | | -static void free_format_fields(struct format_field *field) |
|---|
| 7481 | +static void free_format_fields(struct tep_format_field *field) |
|---|
| 6771 | 7482 | { |
|---|
| 6772 | | - struct format_field *next; |
|---|
| 7483 | + struct tep_format_field *next; |
|---|
| 6773 | 7484 | |
|---|
| 6774 | 7485 | while (field) { |
|---|
| 6775 | 7486 | next = field->next; |
|---|
| 6776 | | - tep_free_format_field(field); |
|---|
| 7487 | + free_tep_format_field(field); |
|---|
| 6777 | 7488 | field = next; |
|---|
| 6778 | 7489 | } |
|---|
| 6779 | 7490 | } |
|---|
| 6780 | 7491 | |
|---|
| 6781 | | -static void free_formats(struct format *format) |
|---|
| 7492 | +static void free_formats(struct tep_format *format) |
|---|
| 6782 | 7493 | { |
|---|
| 6783 | 7494 | free_format_fields(format->common_fields); |
|---|
| 6784 | 7495 | free_format_fields(format->fields); |
|---|
| 6785 | 7496 | } |
|---|
| 6786 | 7497 | |
|---|
| 6787 | | -void tep_free_format(struct event_format *event) |
|---|
| 7498 | +__hidden void free_tep_event(struct tep_event *event) |
|---|
| 6788 | 7499 | { |
|---|
| 6789 | 7500 | free(event->name); |
|---|
| 6790 | 7501 | free(event->system); |
|---|
| .. | .. |
|---|
| 6793 | 7504 | |
|---|
| 6794 | 7505 | free(event->print_fmt.format); |
|---|
| 6795 | 7506 | free_args(event->print_fmt.args); |
|---|
| 6796 | | - |
|---|
| 7507 | + free_parse_args(event->print_fmt.print_cache); |
|---|
| 6797 | 7508 | free(event); |
|---|
| 6798 | 7509 | } |
|---|
| 6799 | 7510 | |
|---|
| 6800 | 7511 | /** |
|---|
| 6801 | | - * tep_free - free a pevent handle |
|---|
| 6802 | | - * @pevent: the pevent handle to free |
|---|
| 7512 | + * tep_free - free a tep handle |
|---|
| 7513 | + * @tep: the tep handle to free |
|---|
| 6803 | 7514 | */ |
|---|
| 6804 | | -void tep_free(struct tep_handle *pevent) |
|---|
| 7515 | +void tep_free(struct tep_handle *tep) |
|---|
| 6805 | 7516 | { |
|---|
| 6806 | 7517 | struct cmdline_list *cmdlist, *cmdnext; |
|---|
| 6807 | 7518 | struct func_list *funclist, *funcnext; |
|---|
| .. | .. |
|---|
| 6810 | 7521 | struct event_handler *handle; |
|---|
| 6811 | 7522 | int i; |
|---|
| 6812 | 7523 | |
|---|
| 6813 | | - if (!pevent) |
|---|
| 7524 | + if (!tep) |
|---|
| 6814 | 7525 | return; |
|---|
| 6815 | 7526 | |
|---|
| 6816 | | - cmdlist = pevent->cmdlist; |
|---|
| 6817 | | - funclist = pevent->funclist; |
|---|
| 6818 | | - printklist = pevent->printklist; |
|---|
| 7527 | + cmdlist = tep->cmdlist; |
|---|
| 7528 | + funclist = tep->funclist; |
|---|
| 7529 | + printklist = tep->printklist; |
|---|
| 6819 | 7530 | |
|---|
| 6820 | | - pevent->ref_count--; |
|---|
| 6821 | | - if (pevent->ref_count) |
|---|
| 7531 | + tep->ref_count--; |
|---|
| 7532 | + if (tep->ref_count) |
|---|
| 6822 | 7533 | return; |
|---|
| 6823 | 7534 | |
|---|
| 6824 | | - if (pevent->cmdlines) { |
|---|
| 6825 | | - for (i = 0; i < pevent->cmdline_count; i++) |
|---|
| 6826 | | - free(pevent->cmdlines[i].comm); |
|---|
| 6827 | | - free(pevent->cmdlines); |
|---|
| 7535 | + if (tep->cmdlines) { |
|---|
| 7536 | + for (i = 0; i < tep->cmdline_count; i++) |
|---|
| 7537 | + free(tep->cmdlines[i].comm); |
|---|
| 7538 | + free(tep->cmdlines); |
|---|
| 6828 | 7539 | } |
|---|
| 6829 | 7540 | |
|---|
| 6830 | 7541 | while (cmdlist) { |
|---|
| .. | .. |
|---|
| 6834 | 7545 | cmdlist = cmdnext; |
|---|
| 6835 | 7546 | } |
|---|
| 6836 | 7547 | |
|---|
| 6837 | | - if (pevent->func_map) { |
|---|
| 6838 | | - for (i = 0; i < (int)pevent->func_count; i++) { |
|---|
| 6839 | | - free(pevent->func_map[i].func); |
|---|
| 6840 | | - free(pevent->func_map[i].mod); |
|---|
| 7548 | + if (tep->func_map) { |
|---|
| 7549 | + for (i = 0; i < (int)tep->func_count; i++) { |
|---|
| 7550 | + free(tep->func_map[i].func); |
|---|
| 7551 | + free(tep->func_map[i].mod); |
|---|
| 6841 | 7552 | } |
|---|
| 6842 | | - free(pevent->func_map); |
|---|
| 7553 | + free(tep->func_map); |
|---|
| 6843 | 7554 | } |
|---|
| 6844 | 7555 | |
|---|
| 6845 | 7556 | while (funclist) { |
|---|
| .. | .. |
|---|
| 6850 | 7561 | funclist = funcnext; |
|---|
| 6851 | 7562 | } |
|---|
| 6852 | 7563 | |
|---|
| 6853 | | - while (pevent->func_handlers) { |
|---|
| 6854 | | - func_handler = pevent->func_handlers; |
|---|
| 6855 | | - pevent->func_handlers = func_handler->next; |
|---|
| 7564 | + while (tep->func_handlers) { |
|---|
| 7565 | + func_handler = tep->func_handlers; |
|---|
| 7566 | + tep->func_handlers = func_handler->next; |
|---|
| 6856 | 7567 | free_func_handle(func_handler); |
|---|
| 6857 | 7568 | } |
|---|
| 6858 | 7569 | |
|---|
| 6859 | | - if (pevent->printk_map) { |
|---|
| 6860 | | - for (i = 0; i < (int)pevent->printk_count; i++) |
|---|
| 6861 | | - free(pevent->printk_map[i].printk); |
|---|
| 6862 | | - free(pevent->printk_map); |
|---|
| 7570 | + if (tep->printk_map) { |
|---|
| 7571 | + for (i = 0; i < (int)tep->printk_count; i++) |
|---|
| 7572 | + free(tep->printk_map[i].printk); |
|---|
| 7573 | + free(tep->printk_map); |
|---|
| 6863 | 7574 | } |
|---|
| 6864 | 7575 | |
|---|
| 6865 | 7576 | while (printklist) { |
|---|
| .. | .. |
|---|
| 6869 | 7580 | printklist = printknext; |
|---|
| 6870 | 7581 | } |
|---|
| 6871 | 7582 | |
|---|
| 6872 | | - for (i = 0; i < pevent->nr_events; i++) |
|---|
| 6873 | | - tep_free_format(pevent->events[i]); |
|---|
| 7583 | + for (i = 0; i < tep->nr_events; i++) |
|---|
| 7584 | + free_tep_event(tep->events[i]); |
|---|
| 6874 | 7585 | |
|---|
| 6875 | | - while (pevent->handlers) { |
|---|
| 6876 | | - handle = pevent->handlers; |
|---|
| 6877 | | - pevent->handlers = handle->next; |
|---|
| 7586 | + while (tep->handlers) { |
|---|
| 7587 | + handle = tep->handlers; |
|---|
| 7588 | + tep->handlers = handle->next; |
|---|
| 6878 | 7589 | free_handler(handle); |
|---|
| 6879 | 7590 | } |
|---|
| 6880 | 7591 | |
|---|
| 6881 | | - free(pevent->trace_clock); |
|---|
| 6882 | | - free(pevent->events); |
|---|
| 6883 | | - free(pevent->sort_events); |
|---|
| 6884 | | - free(pevent->func_resolver); |
|---|
| 7592 | + free(tep->events); |
|---|
| 7593 | + free(tep->sort_events); |
|---|
| 7594 | + free(tep->func_resolver); |
|---|
| 7595 | + free_tep_plugin_paths(tep); |
|---|
| 6885 | 7596 | |
|---|
| 6886 | | - free(pevent); |
|---|
| 7597 | + free(tep); |
|---|
| 6887 | 7598 | } |
|---|
| 6888 | 7599 | |
|---|
| 6889 | | -void tep_unref(struct tep_handle *pevent) |
|---|
| 7600 | +void tep_unref(struct tep_handle *tep) |
|---|
| 6890 | 7601 | { |
|---|
| 6891 | | - tep_free(pevent); |
|---|
| 7602 | + tep_free(tep); |
|---|
| 6892 | 7603 | } |
|---|