Lines Matching +full:ch +full:- +full:func

1 // SPDX-License-Identifier: LGPL-2.1
8 * - Copyright (C) 2009 Frederic Weisbecker,
24 #include "event-parse.h"
26 #include "event-parse-local.h"
27 #include "event-utils.h"
28 #include "trace-seq.h"
51 warning("[%s:%s] " fmt, event->system, \
52 event->name, ##__VA_ARGS__); \
58 * init_input_buf - init buffer for parsing
86 tep_event_handler_func func; member
99 tep_func_handler func; member
108 static void free_func_handle(struct tep_function_handler *func);
131 if (ca->pid < cb->pid) in cmdline_cmp()
132 return -1; in cmdline_cmp()
133 if (ca->pid > cb->pid) in cmdline_cmp()
146 if (ca->pid < cb->pid) in cmdline_slot_cmp()
147 return -1; in cmdline_slot_cmp()
149 if (ca->pid > cb->pid) { in cmdline_slot_cmp()
150 if (ca->pid <= cb1->pid) in cmdline_slot_cmp()
166 struct cmdline_list *cmdlist = tep->cmdlist; in cmdline_init()
171 cmdlines = malloc(sizeof(*cmdlines) * tep->cmdline_count); in cmdline_init()
173 return -1; in cmdline_init()
177 cmdlines[i].pid = cmdlist->pid; in cmdline_init()
178 cmdlines[i].comm = cmdlist->comm; in cmdline_init()
181 cmdlist = cmdlist->next; in cmdline_init()
185 qsort(cmdlines, tep->cmdline_count, sizeof(*cmdlines), cmdline_cmp); in cmdline_init()
187 tep->cmdlines = cmdlines; in cmdline_init()
188 tep->cmdlist = NULL; in cmdline_init()
201 if (!tep->cmdlines && cmdline_init(tep)) in find_cmdline()
206 comm = bsearch(&key, tep->cmdlines, tep->cmdline_count, in find_cmdline()
207 sizeof(*tep->cmdlines), cmdline_cmp); in find_cmdline()
210 return comm->comm; in find_cmdline()
215 * tep_is_pid_registered - return if a pid has a cmdline registered
230 if (!tep->cmdlines && cmdline_init(tep)) in tep_is_pid_registered()
235 comm = bsearch(&key, tep->cmdlines, tep->cmdline_count, in tep_is_pid_registered()
236 sizeof(*tep->cmdlines), cmdline_cmp); in tep_is_pid_registered()
251 struct tep_cmdline *cmdlines = tep->cmdlines; in add_new_comm()
263 cmdline = bsearch(&key, tep->cmdlines, tep->cmdline_count, in add_new_comm()
264 sizeof(*tep->cmdlines), cmdline_cmp); in add_new_comm()
268 return -1; in add_new_comm()
273 return -1; in add_new_comm()
275 free(cmdline->comm); in add_new_comm()
276 cmdline->comm = new_comm; in add_new_comm()
281 cmdlines = realloc(cmdlines, sizeof(*cmdlines) * (tep->cmdline_count + 1)); in add_new_comm()
284 return -1; in add_new_comm()
286 tep->cmdlines = cmdlines; in add_new_comm()
291 return -1; in add_new_comm()
294 if (!tep->cmdline_count) { in add_new_comm()
296 tep->cmdlines[0] = key; in add_new_comm()
297 tep->cmdline_count++; in add_new_comm()
302 cmdline = bsearch(&key, tep->cmdlines, tep->cmdline_count - 1, in add_new_comm()
303 sizeof(*tep->cmdlines), cmdline_slot_cmp); in add_new_comm()
305 cnt = tep->cmdline_count; in add_new_comm()
309 cnt -= cmdline - tep->cmdlines; in add_new_comm()
313 if (key.pid > tep->cmdlines[tep->cmdline_count - 1].pid) { in add_new_comm()
314 tep->cmdlines[tep->cmdline_count++] = key; in add_new_comm()
317 cmdline = &tep->cmdlines[0]; in add_new_comm()
322 tep->cmdline_count++; in add_new_comm()
332 if (tep->cmdlines) in _tep_register_comm()
337 return -1; in _tep_register_comm()
340 item->comm = strdup(comm); in _tep_register_comm()
342 item->comm = strdup("<...>"); in _tep_register_comm()
343 if (!item->comm) { in _tep_register_comm()
345 return -1; in _tep_register_comm()
347 item->pid = pid; in _tep_register_comm()
348 item->next = tep->cmdlist; in _tep_register_comm()
350 tep->cmdlist = item; in _tep_register_comm()
351 tep->cmdline_count++; in _tep_register_comm()
357 * tep_register_comm - register a pid / comm mapping
364 * already exist, -1 is returned and errno is set to EEXIST
372 * tep_override_comm - register a pid / comm mapping
383 if (!tep->cmdlines && cmdline_init(tep)) { in tep_override_comm()
385 return -1; in tep_override_comm()
392 char *func; member
399 char *func; member
408 if (fa->addr < fb->addr) in func_cmp()
409 return -1; in func_cmp()
410 if (fa->addr > fb->addr) in func_cmp()
425 if ((fa->addr == fb->addr) || in func_bcmp()
427 (fa->addr > fb->addr && in func_bcmp()
428 fa->addr < (fb+1)->addr)) in func_bcmp()
431 if (fa->addr < fb->addr) in func_bcmp()
432 return -1; in func_bcmp()
444 func_map = malloc(sizeof(*func_map) * (tep->func_count + 1)); in func_map_init()
446 return -1; in func_map_init()
448 funclist = tep->funclist; in func_map_init()
452 func_map[i].func = funclist->func; in func_map_init()
453 func_map[i].addr = funclist->addr; in func_map_init()
454 func_map[i].mod = funclist->mod; in func_map_init()
457 funclist = funclist->next; in func_map_init()
461 qsort(func_map, tep->func_count, sizeof(*func_map), func_cmp); in func_map_init()
466 func_map[tep->func_count].func = NULL; in func_map_init()
467 func_map[tep->func_count].addr = 0; in func_map_init()
468 func_map[tep->func_count].mod = NULL; in func_map_init()
470 tep->func_map = func_map; in func_map_init()
471 tep->funclist = NULL; in func_map_init()
479 struct func_map *func; in __find_func() local
482 if (!tep->func_map) in __find_func()
487 func = bsearch(&key, tep->func_map, tep->func_count, in __find_func()
488 sizeof(*tep->func_map), func_bcmp); in __find_func()
490 return func; in __find_func()
494 tep_func_resolver_t *func; member
500 * tep_set_function_resolver - set an alternative function resolver
506 * keep using it instead of duplicating all the entries inside tep->funclist.
509 tep_func_resolver_t *func, void *priv) in tep_set_function_resolver() argument
514 return -1; in tep_set_function_resolver()
516 resolver->func = func; in tep_set_function_resolver()
517 resolver->priv = priv; in tep_set_function_resolver()
519 free(tep->func_resolver); in tep_set_function_resolver()
520 tep->func_resolver = resolver; in tep_set_function_resolver()
526 * tep_reset_function_resolver - reset alternative function resolver
534 free(tep->func_resolver); in tep_reset_function_resolver()
535 tep->func_resolver = NULL; in tep_reset_function_resolver()
543 if (!tep->func_resolver) in find_func()
546 map = &tep->func_resolver->map; in find_func()
547 map->mod = NULL; in find_func()
548 map->addr = addr; in find_func()
549 map->func = tep->func_resolver->func(tep->func_resolver->priv, in find_func()
550 &map->addr, &map->mod); in find_func()
551 if (map->func == NULL) in find_func()
558 * tep_find_function - find a function by a given address
574 return map->func; in tep_find_function()
578 * tep_find_function_address - find a function address by a given address
595 return map->addr; in tep_find_function_address()
599 * tep_register_function - register a function with a given address
606 * The @func passed in is duplicated.
608 int tep_register_function(struct tep_handle *tep, char *func, in tep_register_function() argument
614 return -1; in tep_register_function()
616 item->next = tep->funclist; in tep_register_function()
617 item->func = strdup(func); in tep_register_function()
618 if (!item->func) in tep_register_function()
622 item->mod = strdup(mod); in tep_register_function()
623 if (!item->mod) in tep_register_function()
626 item->mod = NULL; in tep_register_function()
627 item->addr = addr; in tep_register_function()
629 tep->funclist = item; in tep_register_function()
630 tep->func_count++; in tep_register_function()
635 free(item->func); in tep_register_function()
636 item->func = NULL; in tep_register_function()
640 return -1; in tep_register_function()
644 * tep_print_funcs - print out the stored functions
653 if (!tep->func_map) in tep_print_funcs()
656 for (i = 0; i < (int)tep->func_count; i++) { in tep_print_funcs()
658 tep->func_map[i].addr, in tep_print_funcs()
659 tep->func_map[i].func); in tep_print_funcs()
660 if (tep->func_map[i].mod) in tep_print_funcs()
661 printf(" [%s]\n", tep->func_map[i].mod); in tep_print_funcs()
683 if (pa->addr < pb->addr) in printk_cmp()
684 return -1; in printk_cmp()
685 if (pa->addr > pb->addr) in printk_cmp()
698 printk_map = malloc(sizeof(*printk_map) * (tep->printk_count + 1)); in printk_map_init()
700 return -1; in printk_map_init()
702 printklist = tep->printklist; in printk_map_init()
706 printk_map[i].printk = printklist->printk; in printk_map_init()
707 printk_map[i].addr = printklist->addr; in printk_map_init()
710 printklist = printklist->next; in printk_map_init()
714 qsort(printk_map, tep->printk_count, sizeof(*printk_map), printk_cmp); in printk_map_init()
716 tep->printk_map = printk_map; in printk_map_init()
717 tep->printklist = NULL; in printk_map_init()
728 if (!tep->printk_map && printk_map_init(tep)) in find_printk()
733 printk = bsearch(&key, tep->printk_map, tep->printk_count, in find_printk()
734 sizeof(*tep->printk_map), printk_cmp); in find_printk()
740 * tep_register_print_string - register a string by its address
755 return -1; in tep_register_print_string()
757 item->next = tep->printklist; in tep_register_print_string()
758 item->addr = addr; in tep_register_print_string()
763 item->printk = strdup(fmt); in tep_register_print_string()
764 if (!item->printk) in tep_register_print_string()
767 p = item->printk + strlen(item->printk) - 1; in tep_register_print_string()
771 p -= 2; in tep_register_print_string()
775 tep->printklist = item; in tep_register_print_string()
776 tep->printk_count++; in tep_register_print_string()
783 return -1; in tep_register_print_string()
787 * tep_print_printk - print out the stored strings
796 if (!tep->printk_map) in tep_print_printk()
799 for (i = 0; i < (int)tep->printk_count; i++) { in tep_print_printk()
801 tep->printk_map[i].addr, in tep_print_printk()
802 tep->printk_map[i].printk); in tep_print_printk()
814 struct tep_event **events = realloc(tep->events, sizeof(event) * in add_event()
815 (tep->nr_events + 1)); in add_event()
817 return -1; in add_event()
819 tep->events = events; in add_event()
821 for (i = 0; i < tep->nr_events; i++) { in add_event()
822 if (tep->events[i]->id > event->id) in add_event()
825 if (i < tep->nr_events) in add_event()
826 memmove(&tep->events[i + 1], in add_event()
827 &tep->events[i], in add_event()
828 sizeof(event) * (tep->nr_events - i)); in add_event()
830 tep->events[i] = event; in add_event()
831 tep->nr_events++; in add_event()
833 event->tep = tep; in add_event()
854 next = fsym->next; in free_flag_sym()
855 free(fsym->value); in free_flag_sym()
856 free(fsym->str); in free_flag_sym()
869 switch (arg->type) { in free_arg()
871 free(arg->atom.atom); in free_arg()
874 free(arg->field.name); in free_arg()
877 free_arg(arg->flags.field); in free_arg()
878 free(arg->flags.delim); in free_arg()
879 free_flag_sym(arg->flags.flags); in free_arg()
882 free_arg(arg->symbol.field); in free_arg()
883 free_flag_sym(arg->symbol.symbols); in free_arg()
887 free_arg(arg->hex.field); in free_arg()
888 free_arg(arg->hex.size); in free_arg()
891 free_arg(arg->int_array.field); in free_arg()
892 free_arg(arg->int_array.count); in free_arg()
893 free_arg(arg->int_array.el_size); in free_arg()
896 free(arg->typecast.type); in free_arg()
897 free_arg(arg->typecast.item); in free_arg()
901 free(arg->string.string); in free_arg()
904 free(arg->bitmask.bitmask); in free_arg()
908 free(arg->dynarray.index); in free_arg()
911 free(arg->op.op); in free_arg()
912 free_arg(arg->op.left); in free_arg()
913 free_arg(arg->op.right); in free_arg()
916 while (arg->func.args) { in free_arg()
917 farg = arg->func.args; in free_arg()
918 arg->func.args = farg->next; in free_arg()
931 static enum tep_event_type get_type(int ch) in get_type() argument
933 if (ch == '\n') in get_type()
935 if (isspace(ch)) in get_type()
937 if (isalnum(ch) || ch == '_') in get_type()
939 if (ch == '\'') in get_type()
941 if (ch == '"') in get_type()
943 if (!isprint(ch)) in get_type()
945 if (ch == '(' || ch == ')' || ch == ',') in get_type()
954 return -1; in __read_char()
960 * peek_char - peek at the next character that will be read
962 * Returns the next character read, or -1 if end of buffer.
967 return -1; in peek_char()
979 return -1; in extend_token()
996 int ch, last_ch, quote_ch, next_ch; in __read_token() local
1004 ch = __read_char(); in __read_token()
1005 if (ch < 0) in __read_token()
1008 type = get_type(ch); in __read_token()
1012 buf[i++] = ch; in __read_token()
1017 if (asprintf(tok, "%c", ch) < 0) in __read_token()
1023 switch (ch) { in __read_token()
1024 case '-': in __read_token()
1036 last_ch = ch; in __read_token()
1037 ch = peek_char(); in __read_token()
1038 if (ch != last_ch) in __read_token()
1060 ch = peek_char(); in __read_token()
1061 if (ch == '=') in __read_token()
1068 i--; in __read_token()
1069 quote_ch = ch; in __read_token()
1073 if (i == (BUFSIZ - 1)) { in __read_token()
1081 last_ch = ch; in __read_token()
1082 ch = __read_char(); in __read_token()
1083 buf[i++] = ch; in __read_token()
1085 if (ch == '\\' && last_ch == '\\') in __read_token()
1087 } while (ch != quote_ch || last_ch == '\\'); in __read_token()
1089 i--; in __read_token()
1099 ch = __read_char(); in __read_token()
1100 } while (isspace(ch)); in __read_token()
1101 if (ch == '"') in __read_token()
1115 if (i == (BUFSIZ - 1)) { in __read_token()
1123 ch = __read_char(); in __read_token()
1124 buf[i++] = ch; in __read_token()
1184 * free_token - free a token returned by tep_read_token
1194 * read_token - access to utilities to use the tep parser
1242 return -1; in test_type()
1253 return -1; in test_type_token()
1259 return -1; in test_type_token()
1335 return -1; in event_read_id()
1338 return -1; in event_read_id()
1349 return -1; in event_read_id()
1354 if ((field->flags & TEP_FIELD_IS_ARRAY) && in field_is_string()
1355 (strstr(field->type, "char") || strstr(field->type, "u8") || in field_is_string()
1356 strstr(field->type, "s8"))) in field_is_string()
1364 if (strncmp(field->type, "__data_loc", 10) == 0) in field_is_dynamic()
1372 if (strncmp(field->type, "__rel_loc", 9) == 0) in field_is_relative_dynamic()
1381 if (strstr(field->type, "long")) in field_is_long()
1421 return -1; in append()
1458 if (event->flags & TEP_EVENT_FL_ISFTRACE && in event_read_fields()
1477 field->event = event; in event_read_fields()
1488 (event->flags & TEP_EVENT_FL_ISFTRACE && in event_read_fields()
1492 field->flags |= TEP_FIELD_IS_POINTER; in event_read_fields()
1494 if (field->type) { in event_read_fields()
1495 ret = append(&field->type, delim, last_token); in event_read_fields()
1500 field->type = last_token; in event_read_fields()
1513 ret = append(&field->type, " ", last_token); in event_read_fields()
1514 ret |= append(&field->type, "", "("); in event_read_fields()
1524 depth--; in event_read_fields()
1527 ret = append(&field->type, "", token); in event_read_fields()
1530 ret = append(&field->type, delim, token); in event_read_fields()
1543 if (!field->type) { in event_read_fields()
1547 field->name = field->alias = last_token; in event_read_fields()
1556 field->flags |= TEP_FIELD_IS_ARRAY; in event_read_fields()
1561 field->arraylen = strtoul(token, NULL, 0); in event_read_fields()
1563 field->arraylen = 0; in event_read_fields()
1582 field->arraylen = strtoul(token, NULL, 0); in event_read_fields()
1608 ret = append(&field->type, " ", field->name); in event_read_fields()
1613 ret = append(&field->type, "", brackets); in event_read_fields()
1615 size_dynamic = type_size(field->name); in event_read_fields()
1616 free_token(field->name); in event_read_fields()
1617 field->name = field->alias = token; in event_read_fields()
1620 ret = append(&field->type, "", brackets); in event_read_fields()
1630 field->flags |= TEP_FIELD_IS_STRING; in event_read_fields()
1632 field->flags |= TEP_FIELD_IS_DYNAMIC; in event_read_fields()
1634 field->flags |= TEP_FIELD_IS_DYNAMIC | TEP_FIELD_IS_RELATIVE; in event_read_fields()
1636 field->flags |= TEP_FIELD_IS_LONG; in event_read_fields()
1650 field->offset = strtoul(token, NULL, 0); in event_read_fields()
1664 field->size = strtoul(token, NULL, 0); in event_read_fields()
1685 field->flags |= TEP_FIELD_IS_SIGNED; in event_read_fields()
1697 if (field->flags & TEP_FIELD_IS_ARRAY) { in event_read_fields()
1698 if (field->arraylen) in event_read_fields()
1699 field->elementsize = field->size / field->arraylen; in event_read_fields()
1700 else if (field->flags & TEP_FIELD_IS_DYNAMIC) in event_read_fields()
1701 field->elementsize = size_dynamic; in event_read_fields()
1702 else if (field->flags & TEP_FIELD_IS_STRING) in event_read_fields()
1703 field->elementsize = 1; in event_read_fields()
1704 else if (field->flags & TEP_FIELD_IS_LONG) in event_read_fields()
1705 field->elementsize = event->tep ? in event_read_fields()
1706 event->tep->long_size : in event_read_fields()
1709 field->elementsize = field->size; in event_read_fields()
1712 fields = &field->next; in event_read_fields()
1722 free(field->type); in event_read_fields()
1723 free(field->name); in event_read_fields()
1726 return -1; in event_read_fields()
1735 return -1; in event_read_format()
1738 return -1; in event_read_format()
1744 ret = event_read_fields(event, &event->format.common_fields); in event_read_format()
1747 event->format.nr_common = ret; in event_read_format()
1749 ret = event_read_fields(event, &event->format.fields); in event_read_format()
1752 event->format.nr_fields = ret; in event_read_format()
1758 return -1; in event_read_format()
1817 arg->type = TEP_PRINT_OP; in process_cond()
1818 arg->op.left = left; in process_cond()
1819 arg->op.right = right; in process_cond()
1837 arg->op.op = token; in process_cond()
1841 top->op.right = arg; in process_cond()
1848 top->op.right = NULL; in process_cond()
1864 /* '*tok' is set to top->op.op. No need to free. */ in process_array()
1874 top->op.right = arg; in process_array()
1900 case '-': in get_op_prio()
1917 return -1; in get_op_prio()
1921 strcmp(op, "--") == 0) { in get_op_prio()
1938 return -1; in get_op_prio()
1947 if (!arg->op.left || arg->op.left->type == TEP_PRINT_NULL) in set_op_prio()
1948 arg->op.prio = 0; in set_op_prio()
1950 arg->op.prio = get_op_prio(arg->op.op); in set_op_prio()
1952 return arg->op.prio; in set_op_prio()
1966 if (arg->type == TEP_PRINT_OP && !arg->op.left) { in process_op()
1976 case '-': in process_op()
1989 left->type = TEP_PRINT_NULL; in process_op()
1990 arg->op.left = left; in process_op()
1996 arg->op.right = right; in process_op()
2011 arg->type = TEP_PRINT_OP; in process_op()
2012 arg->op.op = token; in process_op()
2013 arg->op.left = left; in process_op()
2014 arg->op.prio = 0; in process_op()
2016 /* it will set arg->op.right */ in process_op()
2025 strcmp(token, "-") == 0 || in process_op()
2045 arg->type = TEP_PRINT_OP; in process_op()
2046 arg->op.op = token; in process_op()
2047 arg->op.left = left; in process_op()
2048 arg->op.right = NULL; in process_op()
2050 if (set_op_prio(arg) == -1) { in process_op()
2051 event->flags |= TEP_EVENT_FL_FAILED; in process_op()
2052 /* arg->op.op (= token) will be freed at out_free */ in process_op()
2053 arg->op.op = NULL; in process_op()
2061 if ((strcmp(arg->op.op, "*") == 0) && in process_op()
2065 if (left->type != TEP_PRINT_ATOM) { in process_op()
2069 ret = append(&left->atom.atom, " ", "*"); in process_op()
2073 free(arg->op.op); in process_op()
2092 if (right->type == TEP_PRINT_OP && in process_op()
2093 get_op_prio(arg->op.op) < get_op_prio(right->op.op)) { in process_op()
2097 arg->op.right = right->op.left; in process_op()
2103 arg->op.left = right; in process_op()
2105 arg->op.right = right; in process_op()
2116 arg->type = TEP_PRINT_OP; in process_op()
2117 arg->op.op = token; in process_op()
2118 arg->op.left = left; in process_op()
2120 arg->op.prio = 0; in process_op()
2122 /* it will set arg->op.right */ in process_op()
2127 event->flags |= TEP_EVENT_FL_FAILED; in process_op()
2138 if (prio > arg->op.prio) in process_op()
2162 if (read_expected(TEP_EVENT_OP, "->") < 0) in process_entry()
2169 arg->type = TEP_PRINT_FIELD; in process_entry()
2170 arg->field.name = field; in process_entry()
2173 arg->field.field = tep_find_any_field(event, arg->field.name); in process_entry()
2174 arg->field.field->flags |= TEP_FIELD_IS_FLAG; in process_entry()
2177 arg->field.field = tep_find_any_field(event, arg->field.name); in process_entry()
2178 arg->field.field->flags |= TEP_FIELD_IS_SYMBOLIC; in process_entry()
2206 return -1; in alloc_and_process_delim()
2213 ret = -1; in alloc_and_process_delim()
2239 if (type[len-1] != '*') { in eval_type_str()
2252 ref[len - 2] = 0; in eval_type_str()
2260 if (type[len - 1] == '*') in eval_type_str()
2325 if (arg->type != TEP_PRINT_TYPE) { in eval_type()
2330 return eval_type_str(val, arg->typecast.type, pointer); in eval_type()
2338 switch (arg->type) { in arg_num_eval()
2340 *val = strtoll(arg->atom.atom, NULL, 0); in arg_num_eval()
2343 ret = arg_num_eval(arg->typecast.item, val); in arg_num_eval()
2349 switch (arg->op.op[0]) { in arg_num_eval()
2351 ret = arg_num_eval(arg->op.left, &left); in arg_num_eval()
2354 ret = arg_num_eval(arg->op.right, &right); in arg_num_eval()
2357 if (arg->op.op[1]) in arg_num_eval()
2363 ret = arg_num_eval(arg->op.left, &left); in arg_num_eval()
2366 ret = arg_num_eval(arg->op.right, &right); in arg_num_eval()
2369 if (arg->op.op[1]) in arg_num_eval()
2375 ret = arg_num_eval(arg->op.left, &left); in arg_num_eval()
2378 ret = arg_num_eval(arg->op.right, &right); in arg_num_eval()
2381 switch (arg->op.op[1]) { in arg_num_eval()
2392 do_warning("unknown op '%s'", arg->op.op); in arg_num_eval()
2397 ret = arg_num_eval(arg->op.left, &left); in arg_num_eval()
2400 ret = arg_num_eval(arg->op.right, &right); in arg_num_eval()
2403 switch (arg->op.op[1]) { in arg_num_eval()
2414 do_warning("unknown op '%s'", arg->op.op); in arg_num_eval()
2419 ret = arg_num_eval(arg->op.left, &left); in arg_num_eval()
2422 ret = arg_num_eval(arg->op.right, &right); in arg_num_eval()
2426 if (arg->op.op[1] != '=') { in arg_num_eval()
2427 do_warning("unknown op '%s'", arg->op.op); in arg_num_eval()
2433 ret = arg_num_eval(arg->op.left, &left); in arg_num_eval()
2436 ret = arg_num_eval(arg->op.right, &right); in arg_num_eval()
2440 switch (arg->op.op[1]) { in arg_num_eval()
2445 do_warning("unknown op '%s'", arg->op.op); in arg_num_eval()
2449 case '-': in arg_num_eval()
2451 if (arg->op.left->type == TEP_PRINT_NULL) in arg_num_eval()
2454 ret = arg_num_eval(arg->op.left, &left); in arg_num_eval()
2457 ret = arg_num_eval(arg->op.right, &right); in arg_num_eval()
2460 *val = left - right; in arg_num_eval()
2463 if (arg->op.left->type == TEP_PRINT_NULL) in arg_num_eval()
2466 ret = arg_num_eval(arg->op.left, &left); in arg_num_eval()
2469 ret = arg_num_eval(arg->op.right, &right); in arg_num_eval()
2475 ret = arg_num_eval(arg->op.right, &right); in arg_num_eval()
2481 do_warning("unknown op '%s'", arg->op.op); in arg_num_eval()
2492 do_warning("invalid eval type %d", arg->type); in arg_num_eval()
2504 switch (arg->type) { in arg_eval()
2506 return arg->atom.atom; in arg_eval()
2508 return arg_eval(arg->typecast.item); in arg_eval()
2521 do_warning("invalid eval type %d", arg->type); in arg_eval()
2566 field->value = strdup(value); in process_fields()
2567 if (field->value == NULL) in process_fields()
2583 field->str = strdup(value); in process_fields()
2584 if (field->str == NULL) in process_fields()
2590 list = &field->next; in process_fields()
2617 arg->type = TEP_PRINT_FLAGS; in process_flags()
2635 arg->flags.field = field; in process_flags()
2639 arg->flags.delim = token; in process_flags()
2646 type = process_fields(event, &arg->flags.flags, &token); in process_flags()
2670 arg->type = TEP_PRINT_SYMBOL; in process_symbols()
2683 arg->symbol.field = field; in process_symbols()
2685 type = process_fields(event, &arg->symbol.symbols, &token); in process_symbols()
2706 arg->type = type; in process_hex_common()
2708 if (alloc_and_process_delim(event, ",", &arg->hex.field)) in process_hex_common()
2711 if (alloc_and_process_delim(event, ")", &arg->hex.size)) in process_hex_common()
2717 free_arg(arg->hex.field); in process_hex_common()
2718 arg->hex.field = NULL; in process_hex_common()
2741 arg->type = TEP_PRINT_INT_ARRAY; in process_int_array()
2743 if (alloc_and_process_delim(event, ",", &arg->int_array.field)) in process_int_array()
2746 if (alloc_and_process_delim(event, ",", &arg->int_array.count)) in process_int_array()
2749 if (alloc_and_process_delim(event, ")", &arg->int_array.el_size)) in process_int_array()
2755 free_arg(arg->int_array.count); in process_int_array()
2756 arg->int_array.count = NULL; in process_int_array()
2758 free_arg(arg->int_array.field); in process_int_array()
2759 arg->int_array.field = NULL; in process_int_array()
2773 arg->type = TEP_PRINT_DYNAMIC_ARRAY; in process_dynamic_array()
2790 arg->dynarray.field = field; in process_dynamic_array()
2791 arg->dynarray.index = 0; in process_dynamic_array()
2840 arg->type = TEP_PRINT_DYNAMIC_ARRAY_LEN; in process_dynamic_array_len()
2847 arg->dynarray.field = field; in process_dynamic_array_len()
2848 arg->dynarray.index = 0; in process_dynamic_array_len()
2900 if (arg->type != TEP_PRINT_ATOM) { in process_paren()
2912 arg->type = TEP_PRINT_TYPE; in process_paren()
2913 arg->typecast.type = arg->atom.atom; in process_paren()
2914 arg->typecast.item = item_arg; in process_paren()
2939 arg->type = TEP_PRINT_STRING; in process_str()
2940 arg->string.string = token; in process_str()
2941 arg->string.field = NULL; in process_str()
2968 arg->type = TEP_PRINT_BITMASK; in process_bitmask()
2969 arg->bitmask.bitmask = token; in process_bitmask()
2970 arg->bitmask.field = NULL; in process_bitmask()
2990 struct tep_function_handler *func; in find_func_handler() local
2995 for (func = tep->func_handlers; func; func = func->next) { in find_func_handler()
2996 if (strcmp(func->name, func_name) == 0) in find_func_handler()
3000 return func; in find_func_handler()
3005 struct tep_function_handler *func; in remove_func_handler() local
3008 next = &tep->func_handlers; in remove_func_handler()
3009 while ((func = *next)) { in remove_func_handler()
3010 if (strcmp(func->name, func_name) == 0) { in remove_func_handler()
3011 *next = func->next; in remove_func_handler()
3012 free_func_handle(func); in remove_func_handler()
3015 next = &func->next; in remove_func_handler()
3020 process_func_handler(struct tep_event *event, struct tep_function_handler *func, in process_func_handler() argument
3029 arg->type = TEP_PRINT_FUNC; in process_func_handler()
3030 arg->func.func = func; in process_func_handler()
3034 next_arg = &(arg->func.args); in process_func_handler()
3035 for (i = 0; i < func->nr_args; i++) { in process_func_handler()
3044 if (i < (func->nr_args - 1)) { in process_func_handler()
3048 func->name, func->nr_args, in process_func_handler()
3049 event->name, i + 1); in process_func_handler()
3056 func->name, func->nr_args, event->name); in process_func_handler()
3062 next_arg = &(farg->next); in process_func_handler()
3112 struct tep_function_handler *func; in process_function() local
3161 func = find_func_handler(event->tep, token); in process_function()
3162 if (func) { in process_function()
3164 return process_func_handler(event, func, arg, tok); in process_function()
3218 arg->type = TEP_PRINT_ATOM; in process_arg_token()
3219 arg->atom.atom = atom; in process_arg_token()
3224 arg->type = TEP_PRINT_ATOM; in process_arg_token()
3225 arg->atom.atom = token; in process_arg_token()
3236 arg->type = TEP_PRINT_OP; in process_arg_token()
3237 arg->op.op = token; in process_arg_token()
3238 arg->op.left = NULL; in process_arg_token()
3243 arg->op.op = NULL; in process_arg_token()
3275 return -1; in event_read_print_args()
3283 return -1; in event_read_print_args()
3295 return -1; in event_read_print_args()
3297 list = &arg->next; in event_read_print_args()
3304 list = &arg->next; in event_read_print_args()
3323 return -1; in event_read_print()
3326 return -1; in event_read_print()
3329 return -1; in event_read_print()
3335 event->print_fmt.format = token; in event_read_print()
3336 event->print_fmt.args = NULL; in event_read_print()
3348 if (asprintf(&cat, "%s%s", event->print_fmt.format, token) < 0) in event_read_print()
3351 free_token(event->print_fmt.format); in event_read_print()
3352 event->print_fmt.format = NULL; in event_read_print()
3362 ret = event_read_print_args(event, &event->print_fmt.args); in event_read_print()
3364 return -1; in event_read_print()
3370 return -1; in event_read_print()
3374 * tep_find_common_field - return a common field by event
3386 for (format = event->format.common_fields; in tep_find_common_field()
3387 format; format = format->next) { in tep_find_common_field()
3388 if (strcmp(format->name, name) == 0) in tep_find_common_field()
3396 * tep_find_field - find a non-common field
3398 * @name: the name of the non-common field
3400 * Returns a non-common field by the given @name.
3408 for (format = event->format.fields; in tep_find_field()
3409 format; format = format->next) { in tep_find_field()
3410 if (strcmp(format->name, name) == 0) in tep_find_field()
3418 * tep_find_any_field - find any field by name
3424 * the non-common ones if a common one was not found.
3438 * tep_read_number - read a number from data
3468 * tep_read_number_field - read a number from data
3476 * Returns 0 on success, -1 otherwise.
3482 return -1; in tep_read_number_field()
3483 switch (field->size) { in tep_read_number_field()
3488 *value = tep_read_number(field->event->tep, in tep_read_number_field()
3489 data + field->offset, field->size); in tep_read_number_field()
3492 return -1; in tep_read_number_field()
3506 if (!tep->events) { in get_common_info()
3508 return -1; in get_common_info()
3511 event = tep->events[0]; in get_common_info()
3514 return -1; in get_common_info()
3516 *offset = field->offset; in get_common_info()
3517 *size = field->size; in get_common_info()
3538 &tep->type_size, &tep->type_offset, in trace_parse_common_type()
3545 &tep->pid_size, &tep->pid_offset, in parse_common_pid()
3552 &tep->pc_size, &tep->pc_offset, in parse_common_pc()
3559 &tep->flags_size, &tep->flags_offset, in parse_common_flags()
3566 &tep->ld_size, &tep->ld_offset, in parse_common_lock_depth()
3573 &tep->ld_size, &tep->ld_offset, in parse_common_migrate_disable()
3580 * tep_find_event - find an event by given id
3593 if (tep->last_event && tep->last_event->id == id) in tep_find_event()
3594 return tep->last_event; in tep_find_event()
3598 eventptr = bsearch(&pkey, tep->events, tep->nr_events, in tep_find_event()
3599 sizeof(*tep->events), events_id_cmp); in tep_find_event()
3602 tep->last_event = *eventptr; in tep_find_event()
3610 * tep_find_event_by_name - find an event by given name
3625 if (tep->last_event && in tep_find_event_by_name()
3626 strcmp(tep->last_event->name, name) == 0 && in tep_find_event_by_name()
3627 (!sys || strcmp(tep->last_event->system, sys) == 0)) in tep_find_event_by_name()
3628 return tep->last_event; in tep_find_event_by_name()
3630 for (i = 0; i < tep->nr_events; i++) { in tep_find_event_by_name()
3631 event = tep->events[i]; in tep_find_event_by_name()
3632 if (strcmp(event->name, name) == 0) { in tep_find_event_by_name()
3635 if (strcmp(event->system, sys) == 0) in tep_find_event_by_name()
3639 if (i == tep->nr_events) in tep_find_event_by_name()
3642 tep->last_event = event; in tep_find_event_by_name()
3649 struct tep_handle *tep = event->tep; in eval_num_arg()
3657 switch (arg->type) { in eval_num_arg()
3662 return strtoull(arg->atom.atom, NULL, 0); in eval_num_arg()
3664 if (!arg->field.field) { in eval_num_arg()
3665 arg->field.field = tep_find_any_field(event, arg->field.name); in eval_num_arg()
3666 if (!arg->field.field) in eval_num_arg()
3671 val = tep_read_number(tep, data + arg->field.field->offset, in eval_num_arg()
3672 arg->field.field->size); in eval_num_arg()
3681 val = eval_num_arg(data, size, event, arg->typecast.item); in eval_num_arg()
3695 if (strcmp(arg->op.op, "[") == 0) { in eval_num_arg()
3700 right = eval_num_arg(data, size, event, arg->op.right); in eval_num_arg()
3703 larg = arg->op.left; in eval_num_arg()
3704 while (larg->type == TEP_PRINT_TYPE) { in eval_num_arg()
3707 larg = larg->typecast.item; in eval_num_arg()
3711 field_size = tep->long_size; in eval_num_arg()
3713 switch (larg->type) { in eval_num_arg()
3716 data + larg->dynarray.field->offset, in eval_num_arg()
3717 larg->dynarray.field->size); in eval_num_arg()
3718 if (larg->dynarray.field->elementsize) in eval_num_arg()
3719 field_size = larg->dynarray.field->elementsize; in eval_num_arg()
3729 if (!larg->field.field) { in eval_num_arg()
3730 larg->field.field = in eval_num_arg()
3731 tep_find_any_field(event, larg->field.name); in eval_num_arg()
3732 if (!larg->field.field) { in eval_num_arg()
3737 field_size = larg->field.field->elementsize; in eval_num_arg()
3738 offset = larg->field.field->offset + in eval_num_arg()
3739 right * larg->field.field->elementsize; in eval_num_arg()
3749 } else if (strcmp(arg->op.op, "?") == 0) { in eval_num_arg()
3750 left = eval_num_arg(data, size, event, arg->op.left); in eval_num_arg()
3751 arg = arg->op.right; in eval_num_arg()
3753 val = eval_num_arg(data, size, event, arg->op.left); in eval_num_arg()
3755 val = eval_num_arg(data, size, event, arg->op.right); in eval_num_arg()
3759 left = eval_num_arg(data, size, event, arg->op.left); in eval_num_arg()
3760 right = eval_num_arg(data, size, event, arg->op.right); in eval_num_arg()
3761 switch (arg->op.op[0]) { in eval_num_arg()
3763 switch (arg->op.op[1]) { in eval_num_arg()
3778 if (arg->op.op[1]) in eval_num_arg()
3784 if (arg->op.op[1]) in eval_num_arg()
3790 switch (arg->op.op[1]) { in eval_num_arg()
3805 switch (arg->op.op[1]) { in eval_num_arg()
3820 if (arg->op.op[1] != '=') in eval_num_arg()
3825 case '-': in eval_num_arg()
3826 val = left - right; in eval_num_arg()
3846 data + arg->dynarray.field->offset, in eval_num_arg()
3847 arg->dynarray.field->size); in eval_num_arg()
3858 data + arg->dynarray.field->offset, in eval_num_arg()
3859 arg->dynarray.field->size); in eval_num_arg()
3874 do_warning_event(event, "%s: unknown op '%s'", __func__, arg->op.op); in eval_num_arg()
3879 __func__, arg->field.name); in eval_num_arg()
3920 return -1LL; in eval_flag()
3948 str_size += (nr_bits - 1) / 32; in print_bitmask_to_seq()
3957 /* Start out with -2 for the two chars per byte */ in print_bitmask_to_seq()
3958 for (i = str_size - 2; i >= 0; i -= 2) { in print_bitmask_to_seq()
3964 if (tep->file_bigendian) in print_bitmask_to_seq()
3965 index = size - (len + 1); in print_bitmask_to_seq()
3973 i--; in print_bitmask_to_seq()
3990 struct tep_handle *tep = event->tep; in print_str_arg()
4001 switch (arg->type) { in print_str_arg()
4006 print_str_to_seq(s, format, len_arg, arg->atom.atom); in print_str_arg()
4009 field = arg->field.field; in print_str_arg()
4011 field = tep_find_any_field(event, arg->field.name); in print_str_arg()
4013 str = arg->field.name; in print_str_arg()
4016 arg->field.field = field; in print_str_arg()
4019 len = field->size ? : size - field->offset; in print_str_arg()
4026 if (!(field->flags & TEP_FIELD_IS_ARRAY) && in print_str_arg()
4027 field->size == tep->long_size) { in print_str_arg()
4033 * Traces recorded on 32-bit devices (32-bit in print_str_arg()
4034 * addressing) and processed on 64-bit devices: in print_str_arg()
4039 * on 32-bit devices: in print_str_arg()
4042 addr = (tep->long_size == 8) ? in print_str_arg()
4043 *(unsigned long long *)(data + field->offset) : in print_str_arg()
4044 (unsigned long long)*(unsigned int *)(data + field->offset); in print_str_arg()
4049 trace_seq_puts(s, printk->printk); in print_str_arg()
4060 memcpy(str, data + field->offset, len); in print_str_arg()
4066 val = eval_num_arg(data, size, event, arg->flags.field); in print_str_arg()
4068 for (flag = arg->flags.flags; flag; flag = flag->next) { in print_str_arg()
4069 fval = eval_flag(flag->value); in print_str_arg()
4071 print_str_to_seq(s, format, len_arg, flag->str); in print_str_arg()
4075 if (print && arg->flags.delim) in print_str_arg()
4076 trace_seq_puts(s, arg->flags.delim); in print_str_arg()
4077 print_str_to_seq(s, format, len_arg, flag->str); in print_str_arg()
4083 if (print && arg->flags.delim) in print_str_arg()
4084 trace_seq_puts(s, arg->flags.delim); in print_str_arg()
4089 val = eval_num_arg(data, size, event, arg->symbol.field); in print_str_arg()
4090 for (flag = arg->symbol.symbols; flag; flag = flag->next) { in print_str_arg()
4091 fval = eval_flag(flag->value); in print_str_arg()
4093 print_str_to_seq(s, format, len_arg, flag->str); in print_str_arg()
4102 if (arg->hex.field->type == TEP_PRINT_DYNAMIC_ARRAY) { in print_str_arg()
4105 data + arg->hex.field->dynarray.field->offset, in print_str_arg()
4106 arg->hex.field->dynarray.field->size); in print_str_arg()
4109 field = arg->hex.field->field.field; in print_str_arg()
4111 str = arg->hex.field->field.name; in print_str_arg()
4115 arg->hex.field->field.field = field; in print_str_arg()
4117 hex = data + field->offset; in print_str_arg()
4119 len = eval_num_arg(data, size, event, arg->hex.size); in print_str_arg()
4121 if (i && arg->type == TEP_PRINT_HEX) in print_str_arg()
4131 if (arg->int_array.field->type == TEP_PRINT_DYNAMIC_ARRAY) { in print_str_arg()
4134 arg->int_array.field->dynarray.field; in print_str_arg()
4136 data + field->offset, in print_str_arg()
4137 field->size); in print_str_arg()
4140 field = arg->int_array.field->field.field; in print_str_arg()
4142 str = arg->int_array.field->field.name; in print_str_arg()
4146 arg->int_array.field->field.field = field; in print_str_arg()
4148 num = data + field->offset; in print_str_arg()
4150 len = eval_num_arg(data, size, event, arg->int_array.count); in print_str_arg()
4152 arg->int_array.el_size); in print_str_arg()
4180 if (!arg->string.field) in print_str_arg()
4181 arg->string.field = tep_find_any_field(event, arg->string.string); in print_str_arg()
4182 if (!arg->string.field) in print_str_arg()
4186 *(unsigned int *)(data + arg->string.field->offset)); in print_str_arg()
4188 if (arg->string.field->flags & TEP_FIELD_IS_RELATIVE) in print_str_arg()
4189 str_offset += arg->string.field->offset + arg->string.field->size; in print_str_arg()
4194 print_str_to_seq(s, format, len_arg, arg->string.string); in print_str_arg()
4200 if (!arg->bitmask.field) in print_str_arg()
4201 arg->bitmask.field = tep_find_any_field(event, arg->bitmask.bitmask); in print_str_arg()
4202 if (!arg->bitmask.field) in print_str_arg()
4205 *(unsigned int *)(data + arg->bitmask.field->offset)); in print_str_arg()
4208 if (arg->bitmask.field->flags & TEP_FIELD_IS_RELATIVE) in print_str_arg()
4209 bitmask_offset += arg->bitmask.field->offset + arg->bitmask.field->size; in print_str_arg()
4218 if (arg->op.op[0] != '?') in print_str_arg()
4220 val = eval_num_arg(data, size, event, arg->op.left); in print_str_arg()
4223 format, len_arg, arg->op.right->op.left); in print_str_arg()
4226 format, len_arg, arg->op.right->op.right); in print_str_arg()
4240 __func__, arg->field.name); in print_str_arg()
4247 struct tep_function_handler *func_handle = arg->func.func; in process_defined_func()
4259 if (!func_handle->nr_args) { in process_defined_func()
4260 ret = (*func_handle->func)(s, NULL); in process_defined_func()
4264 farg = arg->func.args; in process_defined_func()
4265 param = func_handle->params; in process_defined_func()
4268 args = malloc(sizeof(*args) * func_handle->nr_args); in process_defined_func()
4272 for (i = 0; i < func_handle->nr_args; i++) { in process_defined_func()
4273 switch (param->type) { in process_defined_func()
4281 print_str_arg(&str, data, size, event, "%s", -1, farg); in process_defined_func()
4289 string->next = strings; in process_defined_func()
4290 string->str = strdup(str.buffer); in process_defined_func()
4291 if (!string->str) { in process_defined_func()
4297 args[i] = (uintptr_t)string->str; in process_defined_func()
4309 farg = farg->next; in process_defined_func()
4310 param = param->next; in process_defined_func()
4313 ret = (*func_handle->func)(s, args); in process_defined_func()
4318 strings = string->next; in process_defined_func()
4319 free(string->str); in process_defined_func()
4333 next = args->next; in free_args()
4342 struct tep_handle *tep = event->tep; in make_bprint_args()
4350 field = tep->bprint_buf_field; in make_bprint_args()
4351 ip_field = tep->bprint_ip_field; in make_bprint_args()
4364 tep->bprint_buf_field = field; in make_bprint_args()
4365 tep->bprint_ip_field = ip_field; in make_bprint_args()
4368 ip = tep_read_number(tep, data + ip_field->offset, ip_field->size); in make_bprint_args()
4380 arg->next = NULL; in make_bprint_args()
4381 next = &arg->next; in make_bprint_args()
4383 arg->type = TEP_PRINT_ATOM; in make_bprint_args()
4385 if (asprintf(&arg->atom.atom, "%lld", ip) < 0) in make_bprint_args()
4389 for (ptr = fmt + 5, bptr = data + field->offset; in make_bprint_args()
4426 * Pre-5.5 kernels use %pf and in make_bprint_args()
4458 vsize = tep->long_size; in make_bprint_args()
4483 arg->next = NULL; in make_bprint_args()
4484 arg->type = TEP_PRINT_ATOM; in make_bprint_args()
4485 if (asprintf(&arg->atom.atom, "%lld", val) < 0) { in make_bprint_args()
4490 next = &arg->next; in make_bprint_args()
4507 arg->next = NULL; in make_bprint_args()
4508 arg->type = TEP_PRINT_BSTRING; in make_bprint_args()
4509 arg->string.string = strdup(bptr); in make_bprint_args()
4510 if (!arg->string.string) in make_bprint_args()
4514 next = &arg->next; in make_bprint_args()
4532 struct tep_handle *tep = event->tep; in get_bprint_format()
4538 field = tep->bprint_fmt_field; in get_bprint_format()
4546 tep->bprint_fmt_field = field; in get_bprint_format()
4549 addr = tep_read_number(tep, data + field->offset, field->size); in get_bprint_format()
4558 if (asprintf(&format, "%s: %s", "%ps", printk->printk) < 0) in get_bprint_format()
4573 if (arg->type == TEP_PRINT_FUNC) { in print_mac_arg()
4578 if (arg->type != TEP_PRINT_FIELD) { in print_mac_arg()
4580 arg->type); in print_mac_arg()
4587 fmt = "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x"; in print_mac_arg()
4595 if (!arg->field.field) { in print_mac_arg()
4596 arg->field.field = in print_mac_arg()
4597 tep_find_any_field(event, arg->field.name); in print_mac_arg()
4598 if (!arg->field.field) { in print_mac_arg()
4600 __func__, arg->field.name); in print_mac_arg()
4604 if (arg->field.field->size != 6) { in print_mac_arg()
4609 buf = data + arg->field.field->offset; in print_mac_arg()
4628 if (tep->file_bigendian) in parse_ip4_print_args()
4668 return ((unsigned long)(a->s6_addr32[0] | a->s6_addr32[1]) | in ipv6_addr_v4mapped()
4669 (unsigned long)(a->s6_addr32[2] ^ htonl(0x0000ffff))) == 0UL; in ipv6_addr_v4mapped()
4674 return (addr->s6_addr32[2] | htonl(0x02000000)) == htonl(0x02005EFE); in ipv6_addr_is_isatap()
4682 int colonpos = -1; in print_ip6c_addr()
4715 colonpos = -1; in print_ip6c_addr()
4724 i += longest - 1; in print_ip6c_addr()
4779 ret = parse_ip4_print_args(event->tep, ptr, &reverse); in print_ipv4_arg()
4781 if (arg->type == TEP_PRINT_FUNC) { in print_ipv4_arg()
4786 if (arg->type != TEP_PRINT_FIELD) { in print_ipv4_arg()
4787 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); in print_ipv4_arg()
4791 if (!arg->field.field) { in print_ipv4_arg()
4792 arg->field.field = in print_ipv4_arg()
4793 tep_find_any_field(event, arg->field.name); in print_ipv4_arg()
4794 if (!arg->field.field) { in print_ipv4_arg()
4796 __func__, arg->field.name); in print_ipv4_arg()
4801 buf = data + arg->field.field->offset; in print_ipv4_arg()
4803 if (arg->field.field->size != 4) { in print_ipv4_arg()
4828 if (arg->type == TEP_PRINT_FUNC) { in print_ipv6_arg()
4833 if (arg->type != TEP_PRINT_FIELD) { in print_ipv6_arg()
4834 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); in print_ipv6_arg()
4838 if (!arg->field.field) { in print_ipv6_arg()
4839 arg->field.field = in print_ipv6_arg()
4840 tep_find_any_field(event, arg->field.name); in print_ipv6_arg()
4841 if (!arg->field.field) { in print_ipv6_arg()
4843 __func__, arg->field.name); in print_ipv6_arg()
4848 buf = data + arg->field.field->offset; in print_ipv6_arg()
4850 if (arg->field.field->size != 16) { in print_ipv6_arg()
4887 ret = parse_ip4_print_args(event->tep, ptr, &reverse); in print_ipsa_arg()
4891 if (arg->type == TEP_PRINT_FUNC) { in print_ipsa_arg()
4896 if (arg->type != TEP_PRINT_FIELD) { in print_ipsa_arg()
4897 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); in print_ipsa_arg()
4901 if (!arg->field.field) { in print_ipsa_arg()
4902 arg->field.field = in print_ipsa_arg()
4903 tep_find_any_field(event, arg->field.name); in print_ipsa_arg()
4904 if (!arg->field.field) { in print_ipsa_arg()
4906 __func__, arg->field.name); in print_ipsa_arg()
4911 sa = (struct sockaddr_storage *) (data + arg->field.field->offset); in print_ipsa_arg()
4913 if (sa->ss_family == AF_INET) { in print_ipsa_arg()
4916 if (arg->field.field->size < sizeof(struct sockaddr_in)) { in print_ipsa_arg()
4921 print_ip4_addr(s, i, reverse, (unsigned char *) &sa4->sin_addr); in print_ipsa_arg()
4923 trace_seq_printf(s, ":%d", ntohs(sa4->sin_port)); in print_ipsa_arg()
4926 } else if (sa->ss_family == AF_INET6) { in print_ipsa_arg()
4929 if (arg->field.field->size < sizeof(struct sockaddr_in6)) { in print_ipsa_arg()
4937 buf = (unsigned char *) &sa6->sin6_addr; in print_ipsa_arg()
4944 trace_seq_printf(s, "]:%d", ntohs(sa6->sin6_port)); in print_ipsa_arg()
5006 if (arg->type == TEP_PRINT_FUNC) { in print_uuid_arg()
5011 if (arg->type != TEP_PRINT_FIELD) { in print_uuid_arg()
5012 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); in print_uuid_arg()
5016 if (!arg->field.field) { in print_uuid_arg()
5017 arg->field.field = in print_uuid_arg()
5018 tep_find_any_field(event, arg->field.name); in print_uuid_arg()
5019 if (!arg->field.field) { in print_uuid_arg()
5021 __func__, arg->field.name); in print_uuid_arg()
5026 if (arg->field.field->size != 16) { in print_uuid_arg()
5031 buf = data + arg->field.field->offset; in print_uuid_arg()
5040 trace_seq_printf(s, "-"); in print_uuid_arg()
5066 delim = "-"; in print_raw_buff_arg()
5075 if (arg->type == TEP_PRINT_FUNC) { in print_raw_buff_arg()
5080 if (arg->type != TEP_PRINT_DYNAMIC_ARRAY) { in print_raw_buff_arg()
5081 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); in print_raw_buff_arg()
5085 offset = tep_read_number(event->tep, in print_raw_buff_arg()
5086 data + arg->dynarray.field->offset, in print_raw_buff_arg()
5087 arg->dynarray.field->size); in print_raw_buff_arg()
5119 struct tep_handle *tep = field->event->tep; in tep_print_field()
5121 if (field->flags & TEP_FIELD_IS_ARRAY) { in tep_print_field()
5122 offset = field->offset; in tep_print_field()
5123 len = field->size; in tep_print_field()
5124 if (field->flags & TEP_FIELD_IS_DYNAMIC) { in tep_print_field()
5129 if (field->flags & TEP_FIELD_IS_RELATIVE) in tep_print_field()
5130 offset += field->offset + field->size; in tep_print_field()
5132 if (field->flags & TEP_FIELD_IS_STRING && in tep_print_field()
5144 field->flags &= ~TEP_FIELD_IS_STRING; in tep_print_field()
5147 val = tep_read_number(tep, data + field->offset, in tep_print_field()
5148 field->size); in tep_print_field()
5149 if (field->flags & TEP_FIELD_IS_POINTER) { in tep_print_field()
5151 } else if (field->flags & TEP_FIELD_IS_SIGNED) { in tep_print_field()
5152 switch (field->size) { in tep_print_field()
5158 if (field->flags & TEP_FIELD_IS_LONG) in tep_print_field()
5173 if (field->flags & TEP_FIELD_IS_LONG) in tep_print_field()
5186 field = event->format.fields; in tep_print_fields()
5188 trace_seq_printf(s, " %s=", field->name); in tep_print_fields()
5190 field = field->next; in tep_print_fields()
5198 struct func_map *func; in print_function() local
5202 func = find_func(event->tep, val); in print_function()
5203 if (func) { in print_function()
5204 trace_seq_puts(s, func->func); in print_function()
5206 trace_seq_printf(s, "+0x%llx", val - func->addr); in print_function()
5208 if (event->tep->long_size == 4) in print_function()
5224 if (arg->type == TEP_PRINT_BSTRING) { in print_arg_pointer()
5225 trace_seq_puts(s, arg->string.string); in print_arg_pointer()
5277 case -2: in print_arg_number()
5283 case -1: in print_arg_number()
5309 event->flags |= TEP_EVENT_FL_FAILED; in print_arg_number()
5434 arg = del->next; in free_parse_args()
5435 free(del->format); in free_parse_args()
5451 parg->format = strdup(format); in parse_arg_add()
5452 if (!parg->format) in parse_arg_add()
5454 parg->type = type; in parse_arg_add()
5455 parg->arg = arg; in parse_arg_add()
5456 parg->len_as_arg = len_as_arg; in parse_arg_add()
5457 parg->ls = ls; in parse_arg_add()
5462 free(parg->format); in parse_arg_add()
5465 return -1; in parse_arg_add()
5488 ls--; in parse_arg_format()
5500 case '-': in parse_arg_format()
5506 event->flags |= TEP_EVENT_FL_FAILED; in parse_arg_format()
5511 event->flags |= TEP_EVENT_FL_FAILED; in parse_arg_format()
5515 *arg = (*arg)->next; in parse_arg_format()
5520 event->flags |= TEP_EVENT_FL_FAILED; in parse_arg_format()
5528 len = ((unsigned long)format + 1) - in parse_arg_format()
5533 event->flags |= TEP_EVENT_FL_FAILED; in parse_arg_format()
5541 *arg = (*arg)->next; in parse_arg_format()
5552 event->flags |= TEP_EVENT_FL_FAILED; in parse_arg_format()
5556 len = ((unsigned long)format + 1) - in parse_arg_format()
5562 event->flags |= TEP_EVENT_FL_FAILED; in parse_arg_format()
5568 if (event->tep->long_size == 8 && ls == 1 && in parse_arg_format()
5577 if (ls < -2 || ls > 2) { in parse_arg_format()
5579 event->flags |= TEP_EVENT_FL_FAILED; in parse_arg_format()
5583 *arg = (*arg)->next; in parse_arg_format()
5589 event->flags |= TEP_EVENT_FL_FAILED; in parse_arg_format()
5593 len = ((unsigned long)format + 1) - in parse_arg_format()
5599 event->flags |= TEP_EVENT_FL_FAILED; in parse_arg_format()
5608 *arg = (*arg)->next; in parse_arg_format()
5689 parse = &((*parse)->next); in parse_args()
5691 len -= ret; in parse_args()
5706 if (parse->len_as_arg) in print_event_cache()
5707 len_arg = eval_num_arg(data, size, event, parse->len_as_arg); in print_event_cache()
5708 switch (parse->type) { in print_event_cache()
5710 print_arg_number(s, parse->format, in print_event_cache()
5711 parse->len_as_arg ? len_arg : -1, data, in print_event_cache()
5712 size, parse->ls, event, parse->arg); in print_event_cache()
5715 print_arg_pointer(s, parse->format, in print_event_cache()
5716 parse->len_as_arg ? len_arg : 1, in print_event_cache()
5717 data, size, event, parse->arg); in print_event_cache()
5720 print_arg_string(s, parse->format, in print_event_cache()
5721 parse->len_as_arg ? len_arg : -1, in print_event_cache()
5722 data, size, event, parse->arg); in print_event_cache()
5726 trace_seq_printf(s, "%s", parse->format); in print_event_cache()
5729 parse = parse->next; in print_event_cache()
5735 struct tep_print_parse *parse = event->print_fmt.print_cache; in pretty_print()
5739 if (event->flags & TEP_EVENT_FL_FAILED) { in pretty_print()
5745 if (event->flags & TEP_EVENT_FL_ISBPRINT) { in pretty_print()
5753 if (event->flags & TEP_EVENT_FL_ISBPRINT) { in pretty_print()
5779 void *data = record->data; in data_latency_format()
5838 s->state = TRACE_SEQ__MEM_ALLOC_FAILED; in data_latency_format()
5849 * tep_data_type - parse out the given event type
5857 return trace_parse_common_type(tep, rec->data); in tep_data_type()
5861 * tep_data_pid - parse the PID from record
5869 return parse_common_pid(tep, rec->data); in tep_data_pid()
5873 * tep_data_preempt_count - parse the preempt count from the record
5881 return parse_common_pc(tep, rec->data); in tep_data_preempt_count()
5885 * tep_data_flags - parse the latency flags from the record
5891 * Use trace_flag_type enum for the flags (see event-parse.h).
5895 return parse_common_flags(tep, rec->data); in tep_data_flags()
5899 * tep_data_comm_from_pid - return the command line from PID
5920 cmdlist = cmdlist->next; in pid_from_cmdlist()
5922 cmdlist = tep->cmdlist; in pid_from_cmdlist()
5924 while (cmdlist && strcmp(cmdlist->comm, comm) != 0) in pid_from_cmdlist()
5925 cmdlist = cmdlist->next; in pid_from_cmdlist()
5931 * tep_data_pid_from_comm - return the pid from a given comm
5952 if (!tep->cmdlines) in tep_data_pid_from_comm()
5960 if (next < tep->cmdlines || in tep_data_pid_from_comm()
5961 next >= tep->cmdlines + tep->cmdline_count) in tep_data_pid_from_comm()
5968 cmdline = tep->cmdlines; in tep_data_pid_from_comm()
5970 while (cmdline < tep->cmdlines + tep->cmdline_count) { in tep_data_pid_from_comm()
5971 if (strcmp(cmdline->comm, comm) == 0) in tep_data_pid_from_comm()
5979 * tep_cmdline_pid - return the pid associated to a given cmdline
5984 * -1 is returned.
5991 return -1; in tep_cmdline_pid()
5997 if (!tep->cmdlines || in tep_cmdline_pid()
5998 cmdline < tep->cmdlines || in tep_cmdline_pid()
5999 cmdline >= tep->cmdlines + tep->cmdline_count) in tep_cmdline_pid()
6000 return cmdlist->pid; in tep_cmdline_pid()
6002 return cmdline->pid; in tep_cmdline_pid()
6014 if (raw || (event->flags & TEP_EVENT_FL_PRINTRAW)) in print_event_info()
6015 tep_print_fields(s, record->data, record->size, event); in print_event_info()
6018 if (event->handler && !(event->flags & TEP_EVENT_FL_NOHANDLE)) in print_event_info()
6019 print_pretty = event->handler(s, record, event, in print_event_info()
6020 event->context); in print_event_info()
6023 pretty_print(s, record->data, record->size, event); in print_event_info()
6030 * tep_find_event_by_record - return the event from a given record
6042 if (record->size < 0) { in tep_find_event_by_record()
6043 do_warning("ug! negative record size %d", record->size); in tep_find_event_by_record()
6047 type = trace_parse_common_type(tep, record->data); in tep_find_event_by_record()
6055 * "%3.1000d" - divide the time by 1000 and print the first 3 digits
6074 time = record->ts; in print_event_time()
6080 while (pr--) in print_event_time()
6106 data_latency_format(tep, s, type->format, record); in print_string()
6108 pid = parse_common_pid(tep, record->data); in print_string()
6110 trace_seq_printf(s, type->format, comm); in print_string()
6112 print_event_info(s, type->format, true, event, record); in print_string()
6114 print_event_info(s, type->format, false, event, record); in print_string()
6116 trace_seq_printf(s, type->format, event->name); in print_string()
6131 param = record->cpu; in print_int()
6134 param = parse_common_pid(tep, record->data); in print_int()
6137 return print_event_time(tep, s, type->format, event, record); in print_int()
6141 trace_seq_printf(s, type->format, param); in print_int()
6150 type->type = EVENT_TYPE_UNKNOWN; in tep_print_event_param_type()
6159 type->type = EVENT_TYPE_INT; in tep_print_event_param_type()
6162 type->type = EVENT_TYPE_STRING; in tep_print_event_param_type()
6167 if (type->type != EVENT_TYPE_UNKNOWN) in tep_print_event_param_type()
6170 memset(type->format, 0, 32); in tep_print_event_param_type()
6171 memcpy(type->format, format, i < 32 ? i : 31); in tep_print_event_param_type()
6176 * tep_print_event - Write various event information
6181 * TEP_PRINT_PID, "%d" - event PID
6182 * TEP_PRINT_CPU, "%d" - event CPU
6183 * TEP_PRINT_COMM, "%s" - event command string
6184 * TEP_PRINT_NAME, "%s" - event name
6185 * TEP_PRINT_LATENCY, "%s" - event latency
6186 * TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
6189 * "%3.1000d" - divide the time by 1000 and print the first
6192 * TEP_PRINT_INFO, "%s" - event information. If any width is specified in
6250 if ((*ea)->id < (*eb)->id) in events_id_cmp()
6251 return -1; in events_id_cmp()
6253 if ((*ea)->id > (*eb)->id) in events_id_cmp()
6265 res = strcmp((*ea)->name, (*eb)->name); in events_name_cmp()
6269 res = strcmp((*ea)->system, (*eb)->system); in events_name_cmp()
6282 res = strcmp((*ea)->system, (*eb)->system); in events_system_cmp()
6286 res = strcmp((*ea)->name, (*eb)->name); in events_system_cmp()
6300 events = malloc(sizeof(*events) * (tep->nr_events + 1)); in list_events_copy()
6304 memcpy(events, tep->events, sizeof(*events) * tep->nr_events); in list_events_copy()
6305 events[tep->nr_events] = NULL; in list_events_copy()
6333 * tep_list_events - Get events, sorted by given criteria.
6350 events = tep->sort_events; in tep_list_events()
6351 if (events && tep->last_type == sort_type) in tep_list_events()
6359 tep->sort_events = events; in tep_list_events()
6363 tep->last_type = sort_type; in tep_list_events()
6368 list_events_sort(events, tep->nr_events, sort_type); in tep_list_events()
6369 tep->last_type = sort_type; in tep_list_events()
6376 * tep_list_events_copy - Thread safe version of tep_list_events()
6400 list_events_sort(events, tep->nr_events, sort_type); in tep_list_events_copy()
6417 for (field = list; field; field = field->next) { in get_event_fields()
6422 i--; in get_event_fields()
6437 * tep_event_common_fields - return a list of common fields for an event
6445 return get_event_fields("common", event->name, in tep_event_common_fields()
6446 event->format.nr_common, in tep_event_common_fields()
6447 event->format.common_fields); in tep_event_common_fields()
6451 * tep_event_fields - return a list of event specific fields for an event
6459 return get_event_fields("event", event->name, in tep_event_fields()
6460 event->format.nr_fields, in tep_event_fields()
6461 event->format.fields); in tep_event_fields()
6466 trace_seq_printf(s, "{ %s, %s }", field->value, field->str); in print_fields()
6467 if (field->next) { in print_fields()
6469 print_fields(s, field->next); in print_fields()
6479 switch (args->type) { in print_args()
6484 printf("%s", args->atom.atom); in print_args()
6487 printf("REC->%s", args->field.name); in print_args()
6491 print_args(args->flags.field); in print_args()
6492 printf(", %s, ", args->flags.delim); in print_args()
6494 print_fields(&s, args->flags.flags); in print_args()
6501 print_args(args->symbol.field); in print_args()
6504 print_fields(&s, args->symbol.symbols); in print_args()
6511 print_args(args->hex.field); in print_args()
6513 print_args(args->hex.size); in print_args()
6518 print_args(args->hex.field); in print_args()
6520 print_args(args->hex.size); in print_args()
6525 print_args(args->int_array.field); in print_args()
6527 print_args(args->int_array.count); in print_args()
6529 print_args(args->int_array.el_size); in print_args()
6534 printf("__get_str(%s)", args->string.string); in print_args()
6537 printf("__get_bitmask(%s)", args->bitmask.bitmask); in print_args()
6540 printf("(%s)", args->typecast.type); in print_args()
6541 print_args(args->typecast.item); in print_args()
6544 if (strcmp(args->op.op, ":") == 0) in print_args()
6548 print_args(args->op.left); in print_args()
6549 printf(" %s ", args->op.op); in print_args()
6550 print_args(args->op.right); in print_args()
6558 if (args->next) { in print_args()
6560 print_args(args->next); in print_args()
6658 * tep_parse_header_page - parse the data stored in the header page
6679 tep->header_page_ts_size = sizeof(long long); in tep_parse_header_page()
6680 tep->header_page_size_size = long_size; in tep_parse_header_page()
6681 tep->header_page_data_offset = sizeof(long long) + long_size; in tep_parse_header_page()
6682 tep->old_format = 1; in tep_parse_header_page()
6683 return -1; in tep_parse_header_page()
6687 parse_header_field("timestamp", &tep->header_page_ts_offset, in tep_parse_header_page()
6688 &tep->header_page_ts_size, 1); in tep_parse_header_page()
6689 parse_header_field("commit", &tep->header_page_size_offset, in tep_parse_header_page()
6690 &tep->header_page_size_size, 1); in tep_parse_header_page()
6691 parse_header_field("overwrite", &tep->header_page_overwrite, in tep_parse_header_page()
6693 parse_header_field("data", &tep->header_page_data_offset, in tep_parse_header_page()
6694 &tep->header_page_data_size, 1); in tep_parse_header_page()
6703 if (id >= 0 && id != event->id) in event_matches()
6706 if (event_name && (strcmp(event_name, event->name) != 0)) in event_matches()
6709 if (sys_name && (strcmp(sys_name, event->system) != 0)) in event_matches()
6717 free((void *)handle->sys_name); in free_handler()
6718 free((void *)handle->event_name); in free_handler()
6726 for (next = &tep->handlers; *next; in find_event_handle()
6727 next = &(*next)->next) { in find_event_handle()
6729 if (event_matches(event, handle->id, in find_event_handle()
6730 handle->sys_name, in find_event_handle()
6731 handle->event_name)) in find_event_handle()
6739 event->id, event->system, event->name); in find_event_handle()
6741 event->handler = handle->func; in find_event_handle()
6742 event->context = handle->context; in find_event_handle()
6744 *next = handle->next; in find_event_handle()
6751 * parse_format - parse the event format
6776 event->name = event_read_name(); in parse_format()
6777 if (!event->name) { in parse_format()
6784 event->flags |= TEP_EVENT_FL_ISFTRACE; in parse_format()
6786 if (strcmp(event->name, "bprint") == 0) in parse_format()
6787 event->flags |= TEP_EVENT_FL_ISBPRINT; in parse_format()
6790 event->id = event_read_id(); in parse_format()
6791 if (event->id < 0) { in parse_format()
6800 event->system = strdup(sys); in parse_format()
6801 if (!event->system) { in parse_format()
6807 event->tep = tep; in parse_format()
6830 if (!ret && (event->flags & TEP_EVENT_FL_ISFTRACE)) { in parse_format()
6835 list = &event->print_fmt.args; in parse_format()
6836 for (field = event->format.fields; field; field = field->next) { in parse_format()
6839 event->flags |= TEP_EVENT_FL_FAILED; in parse_format()
6842 arg->type = TEP_PRINT_FIELD; in parse_format()
6843 arg->field.name = strdup(field->name); in parse_format()
6844 if (!arg->field.name) { in parse_format()
6845 event->flags |= TEP_EVENT_FL_FAILED; in parse_format()
6849 arg->field.field = field; in parse_format()
6851 list = &arg->next; in parse_format()
6855 if (!(event->flags & TEP_EVENT_FL_ISBPRINT)) in parse_format()
6856 event->print_fmt.print_cache = parse_args(event, in parse_format()
6857 event->print_fmt.format, in parse_format()
6858 event->print_fmt.args); in parse_format()
6863 event->flags |= TEP_EVENT_FL_FAILED; in parse_format()
6867 free(event->system); in parse_format()
6868 free(event->name); in parse_format()
6892 if (PRINT_ARGS && event->print_fmt.args) in __parse_event()
6893 print_args(event->print_fmt.args); in __parse_event()
6903 * tep_parse_format - parse the event format
6926 * tep_parse_event - parse the event format
6953 return -1; in get_field_val()
6956 if (tep_read_number_field(field, record->data, val)) { in get_field_val()
6959 return -1; in get_field_val()
6966 * tep_get_field_raw - return the raw pointer into the data field
6974 * Returns a pointer into record->data of the field and places
6984 void *data = record->data; in tep_get_field_raw()
7003 offset = field->offset; in tep_get_field_raw()
7004 if (field->flags & TEP_FIELD_IS_DYNAMIC) { in tep_get_field_raw()
7005 offset = tep_read_number(event->tep, in tep_get_field_raw()
7006 data + offset, field->size); in tep_get_field_raw()
7009 if (field->flags & TEP_FIELD_IS_RELATIVE) in tep_get_field_raw()
7010 offset += field->offset + field->size; in tep_get_field_raw()
7012 *len = field->size; in tep_get_field_raw()
7018 * tep_get_field_val - find a field and return its value
7026 * Returns 0 on success -1 on field not found.
7035 return -1; in tep_get_field_val()
7043 * tep_get_common_field_val - find a common field and return its value
7051 * Returns 0 on success -1 on field not found.
7060 return -1; in tep_get_common_field_val()
7068 * tep_get_any_field_val - find a any field and return its value
7076 * Returns 0 on success -1 on field not found.
7085 return -1; in tep_get_any_field_val()
7093 * tep_print_num_field - print a field and a format
7114 if (tep_read_number_field(field, record->data, &val)) in tep_print_num_field()
7122 return -1; in tep_print_num_field()
7126 * tep_print_func_field - print a field and a format for function pointers
7142 struct tep_handle *tep = event->tep; in tep_print_func_field()
7144 struct func_map *func; in tep_print_func_field() local
7150 if (tep_read_number_field(field, record->data, &val)) in tep_print_func_field()
7153 func = find_func(tep, val); in tep_print_func_field()
7155 if (func) in tep_print_func_field()
7156 snprintf(tmp, 128, "%s/0x%llx", func->func, func->addr - val); in tep_print_func_field()
7165 return -1; in tep_print_func_field()
7168 static void free_func_handle(struct tep_function_handler *func) in free_func_handle() argument
7172 free(func->name); in free_func_handle()
7174 while (func->params) { in free_func_handle()
7175 params = func->params; in free_func_handle()
7176 func->params = params->next; in free_func_handle()
7180 free(func); in free_func_handle()
7184 * tep_register_print_function - register a helper function
7186 * @func: the function to process the helper function
7199 tep_func_handler func, in tep_register_print_function() argument
7227 func_handle->ret_type = ret_type; in tep_register_print_function()
7228 func_handle->name = strdup(name); in tep_register_print_function()
7229 func_handle->func = func; in tep_register_print_function()
7230 if (!func_handle->name) { in tep_register_print_function()
7236 next_param = &(func_handle->params); in tep_register_print_function()
7255 param->type = type; in tep_register_print_function()
7256 param->next = NULL; in tep_register_print_function()
7259 next_param = &(param->next); in tep_register_print_function()
7261 func_handle->nr_args++; in tep_register_print_function()
7265 func_handle->next = tep->func_handlers; in tep_register_print_function()
7266 tep->func_handlers = func_handle; in tep_register_print_function()
7276 * tep_unregister_print_function - unregister a helper function
7278 * @func: the function to process the helper function
7283 * Returns 0 if the handler was removed successully, -1 otherwise.
7286 tep_func_handler func, char *name) in tep_unregister_print_function() argument
7291 if (func_handle && func_handle->func == func) { in tep_unregister_print_function()
7295 return -1; in tep_unregister_print_function()
7309 if (event_name && (strcmp(event_name, event->name) != 0)) in search_event()
7311 if (sys_name && (strcmp(sys_name, event->system) != 0)) in search_event()
7322 * tep_register_event_handler - register a way to parse an event
7327 * @func: the function to call to parse the event information
7328 * @context: the data to be passed to @func
7346 tep_event_handler_func func, void *context) in tep_register_event_handler() argument
7356 event->id, event->system, event->name); in tep_register_event_handler()
7358 event->handler = func; in tep_register_event_handler()
7359 event->context = context; in tep_register_event_handler()
7370 handle->id = id; in tep_register_event_handler()
7372 handle->event_name = strdup(event_name); in tep_register_event_handler()
7374 handle->sys_name = strdup(sys_name); in tep_register_event_handler()
7376 if ((event_name && !handle->event_name) || in tep_register_event_handler()
7377 (sys_name && !handle->sys_name)) { in tep_register_event_handler()
7379 free((void *)handle->event_name); in tep_register_event_handler()
7380 free((void *)handle->sys_name); in tep_register_event_handler()
7385 handle->func = func; in tep_register_event_handler()
7386 handle->next = tep->handlers; in tep_register_event_handler()
7387 tep->handlers = handle; in tep_register_event_handler()
7388 handle->context = context; in tep_register_event_handler()
7395 tep_event_handler_func func, void *context) in handle_matches() argument
7397 if (id >= 0 && id != handler->id) in handle_matches()
7400 if (event_name && (strcmp(event_name, handler->event_name) != 0)) in handle_matches()
7403 if (sys_name && (strcmp(sys_name, handler->sys_name) != 0)) in handle_matches()
7406 if (func != handler->func || context != handler->context) in handle_matches()
7413 * tep_unregister_event_handler - unregister an existing event handler
7418 * @func: the function to call to parse the event information
7419 * @context: the data to be passed to @func
7426 * Returns 0 if handler was removed successfully, -1 if event was not found.
7430 tep_event_handler_func func, void *context) in tep_unregister_event_handler() argument
7440 if (event->handler == func && event->context == context) { in tep_unregister_event_handler()
7442 event->id, event->system, event->name); in tep_unregister_event_handler()
7444 event->handler = NULL; in tep_unregister_event_handler()
7445 event->context = NULL; in tep_unregister_event_handler()
7450 for (next = &tep->handlers; *next; next = &(*next)->next) { in tep_unregister_event_handler()
7453 func, context)) in tep_unregister_event_handler()
7458 return -1; in tep_unregister_event_handler()
7460 *next = handle->next; in tep_unregister_event_handler()
7467 * tep_alloc - create a tep handle
7474 tep->ref_count = 1; in tep_alloc()
7475 tep->host_bigendian = tep_is_bigendian(); in tep_alloc()
7483 tep->ref_count++; in tep_ref()
7489 return tep->ref_count; in tep_get_ref()
7495 free(field->type); in free_tep_format_field()
7496 if (field->alias != field->name) in free_tep_format_field()
7497 free(field->alias); in free_tep_format_field()
7498 free(field->name); in free_tep_format_field()
7507 next = field->next; in free_format_fields()
7515 free_format_fields(format->common_fields); in free_formats()
7516 free_format_fields(format->fields); in free_formats()
7521 free(event->name); in free_tep_event()
7522 free(event->system); in free_tep_event()
7524 free_formats(&event->format); in free_tep_event()
7526 free(event->print_fmt.format); in free_tep_event()
7527 free_args(event->print_fmt.args); in free_tep_event()
7528 free_parse_args(event->print_fmt.print_cache); in free_tep_event()
7533 * tep_free - free a tep handle
7548 cmdlist = tep->cmdlist; in tep_free()
7549 funclist = tep->funclist; in tep_free()
7550 printklist = tep->printklist; in tep_free()
7552 tep->ref_count--; in tep_free()
7553 if (tep->ref_count) in tep_free()
7556 if (tep->cmdlines) { in tep_free()
7557 for (i = 0; i < tep->cmdline_count; i++) in tep_free()
7558 free(tep->cmdlines[i].comm); in tep_free()
7559 free(tep->cmdlines); in tep_free()
7563 cmdnext = cmdlist->next; in tep_free()
7564 free(cmdlist->comm); in tep_free()
7569 if (tep->func_map) { in tep_free()
7570 for (i = 0; i < (int)tep->func_count; i++) { in tep_free()
7571 free(tep->func_map[i].func); in tep_free()
7572 free(tep->func_map[i].mod); in tep_free()
7574 free(tep->func_map); in tep_free()
7578 funcnext = funclist->next; in tep_free()
7579 free(funclist->func); in tep_free()
7580 free(funclist->mod); in tep_free()
7585 while (tep->func_handlers) { in tep_free()
7586 func_handler = tep->func_handlers; in tep_free()
7587 tep->func_handlers = func_handler->next; in tep_free()
7591 if (tep->printk_map) { in tep_free()
7592 for (i = 0; i < (int)tep->printk_count; i++) in tep_free()
7593 free(tep->printk_map[i].printk); in tep_free()
7594 free(tep->printk_map); in tep_free()
7598 printknext = printklist->next; in tep_free()
7599 free(printklist->printk); in tep_free()
7604 for (i = 0; i < tep->nr_events; i++) in tep_free()
7605 free_tep_event(tep->events[i]); in tep_free()
7607 while (tep->handlers) { in tep_free()
7608 handle = tep->handlers; in tep_free()
7609 tep->handlers = handle->next; in tep_free()
7613 free(tep->events); in tep_free()
7614 free(tep->sort_events); in tep_free()
7615 free(tep->func_resolver); in tep_free()