2 * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
4 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation;
8 * version 2.1 of the License (not later!)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, see <http://www.gnu.org/licenses>
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 * The parts for function graph printing was taken and modified from the
21 * Linux Kernel that were written by
22 * - Copyright (C) 2009 Frederic Weisbecker,
23 * Frederic Weisbecker gave his permission to relicense the code to
24 * the Lesser General Public License.
35 #include <linux/string.h>
36 #include <linux/time64.h>
38 #include <netinet/in.h>
39 #include "event-parse.h"
40 #include "event-utils.h"
42 static const char *input_buf
;
43 static unsigned long long input_buf_ptr
;
44 static unsigned long long input_buf_siz
;
46 static int is_flag_field
;
47 static int is_symbolic_field
;
49 static int show_warning
= 1;
51 #define do_warning(fmt, ...) \
54 warning(fmt, ##__VA_ARGS__); \
57 #define do_warning_event(event, fmt, ...) \
63 warning("[%s:%s] " fmt, event->system, \
64 event->name, ##__VA_ARGS__); \
66 warning(fmt, ##__VA_ARGS__); \
69 static void init_input_buf(const char *buf
, unsigned long long size
)
76 const char *pevent_get_input_buf(void)
81 unsigned long long pevent_get_input_buf_ptr(void)
86 struct event_handler
{
87 struct event_handler
*next
;
90 const char *event_name
;
91 pevent_event_handler_func func
;
95 struct pevent_func_params
{
96 struct pevent_func_params
*next
;
97 enum pevent_func_arg_type type
;
100 struct pevent_function_handler
{
101 struct pevent_function_handler
*next
;
102 enum pevent_func_arg_type ret_type
;
104 pevent_func_handler func
;
105 struct pevent_func_params
*params
;
109 static unsigned long long
110 process_defined_func(struct trace_seq
*s
, void *data
, int size
,
111 struct event_format
*event
, struct print_arg
*arg
);
113 static void free_func_handle(struct pevent_function_handler
*func
);
116 * pevent_buffer_init - init buffer for parsing
117 * @buf: buffer to parse
118 * @size: the size of the buffer
120 * For use with pevent_read_token(), this initializes the internal
121 * buffer that pevent_read_token() will parse.
123 void pevent_buffer_init(const char *buf
, unsigned long long size
)
125 init_input_buf(buf
, size
);
128 void breakpoint(void)
134 struct print_arg
*alloc_arg(void)
136 return calloc(1, sizeof(struct print_arg
));
144 static int cmdline_cmp(const void *a
, const void *b
)
146 const struct cmdline
*ca
= a
;
147 const struct cmdline
*cb
= b
;
149 if (ca
->pid
< cb
->pid
)
151 if (ca
->pid
> cb
->pid
)
157 struct cmdline_list
{
158 struct cmdline_list
*next
;
163 static int cmdline_init(struct pevent
*pevent
)
165 struct cmdline_list
*cmdlist
= pevent
->cmdlist
;
166 struct cmdline_list
*item
;
167 struct cmdline
*cmdlines
;
170 cmdlines
= malloc(sizeof(*cmdlines
) * pevent
->cmdline_count
);
176 cmdlines
[i
].pid
= cmdlist
->pid
;
177 cmdlines
[i
].comm
= cmdlist
->comm
;
180 cmdlist
= cmdlist
->next
;
184 qsort(cmdlines
, pevent
->cmdline_count
, sizeof(*cmdlines
), cmdline_cmp
);
186 pevent
->cmdlines
= cmdlines
;
187 pevent
->cmdlist
= NULL
;
192 static const char *find_cmdline(struct pevent
*pevent
, int pid
)
194 const struct cmdline
*comm
;
200 if (!pevent
->cmdlines
&& cmdline_init(pevent
))
201 return "<not enough memory for cmdlines!>";
205 comm
= bsearch(&key
, pevent
->cmdlines
, pevent
->cmdline_count
,
206 sizeof(*pevent
->cmdlines
), cmdline_cmp
);
214 * pevent_pid_is_registered - return if a pid has a cmdline registered
215 * @pevent: handle for the pevent
216 * @pid: The pid to check if it has a cmdline registered with.
218 * Returns 1 if the pid has a cmdline mapped to it
221 int pevent_pid_is_registered(struct pevent
*pevent
, int pid
)
223 const struct cmdline
*comm
;
229 if (!pevent
->cmdlines
&& cmdline_init(pevent
))
234 comm
= bsearch(&key
, pevent
->cmdlines
, pevent
->cmdline_count
,
235 sizeof(*pevent
->cmdlines
), cmdline_cmp
);
243 * If the command lines have been converted to an array, then
244 * we must add this pid. This is much slower than when cmdlines
245 * are added before the array is initialized.
247 static int add_new_comm(struct pevent
*pevent
, const char *comm
, int pid
)
249 struct cmdline
*cmdlines
= pevent
->cmdlines
;
250 const struct cmdline
*cmdline
;
256 /* avoid duplicates */
259 cmdline
= bsearch(&key
, pevent
->cmdlines
, pevent
->cmdline_count
,
260 sizeof(*pevent
->cmdlines
), cmdline_cmp
);
266 cmdlines
= realloc(cmdlines
, sizeof(*cmdlines
) * (pevent
->cmdline_count
+ 1));
272 cmdlines
[pevent
->cmdline_count
].comm
= strdup(comm
);
273 if (!cmdlines
[pevent
->cmdline_count
].comm
) {
279 cmdlines
[pevent
->cmdline_count
].pid
= pid
;
281 if (cmdlines
[pevent
->cmdline_count
].comm
)
282 pevent
->cmdline_count
++;
284 qsort(cmdlines
, pevent
->cmdline_count
, sizeof(*cmdlines
), cmdline_cmp
);
285 pevent
->cmdlines
= cmdlines
;
291 * pevent_register_comm - register a pid / comm mapping
292 * @pevent: handle for the pevent
293 * @comm: the command line to register
294 * @pid: the pid to map the command line to
296 * This adds a mapping to search for command line names with
297 * a given pid. The comm is duplicated.
299 int pevent_register_comm(struct pevent
*pevent
, const char *comm
, int pid
)
301 struct cmdline_list
*item
;
303 if (pevent
->cmdlines
)
304 return add_new_comm(pevent
, comm
, pid
);
306 item
= malloc(sizeof(*item
));
311 item
->comm
= strdup(comm
);
313 item
->comm
= strdup("<...>");
319 item
->next
= pevent
->cmdlist
;
321 pevent
->cmdlist
= item
;
322 pevent
->cmdline_count
++;
327 int pevent_register_trace_clock(struct pevent
*pevent
, const char *trace_clock
)
329 pevent
->trace_clock
= strdup(trace_clock
);
330 if (!pevent
->trace_clock
) {
338 unsigned long long addr
;
344 struct func_list
*next
;
345 unsigned long long addr
;
350 static int func_cmp(const void *a
, const void *b
)
352 const struct func_map
*fa
= a
;
353 const struct func_map
*fb
= b
;
355 if (fa
->addr
< fb
->addr
)
357 if (fa
->addr
> fb
->addr
)
364 * We are searching for a record in between, not an exact
367 static int func_bcmp(const void *a
, const void *b
)
369 const struct func_map
*fa
= a
;
370 const struct func_map
*fb
= b
;
372 if ((fa
->addr
== fb
->addr
) ||
374 (fa
->addr
> fb
->addr
&&
375 fa
->addr
< (fb
+1)->addr
))
378 if (fa
->addr
< fb
->addr
)
384 static int func_map_init(struct pevent
*pevent
)
386 struct func_list
*funclist
;
387 struct func_list
*item
;
388 struct func_map
*func_map
;
391 func_map
= malloc(sizeof(*func_map
) * (pevent
->func_count
+ 1));
395 funclist
= pevent
->funclist
;
399 func_map
[i
].func
= funclist
->func
;
400 func_map
[i
].addr
= funclist
->addr
;
401 func_map
[i
].mod
= funclist
->mod
;
404 funclist
= funclist
->next
;
408 qsort(func_map
, pevent
->func_count
, sizeof(*func_map
), func_cmp
);
411 * Add a special record at the end.
413 func_map
[pevent
->func_count
].func
= NULL
;
414 func_map
[pevent
->func_count
].addr
= 0;
415 func_map
[pevent
->func_count
].mod
= NULL
;
417 pevent
->func_map
= func_map
;
418 pevent
->funclist
= NULL
;
423 static struct func_map
*
424 __find_func(struct pevent
*pevent
, unsigned long long addr
)
426 struct func_map
*func
;
429 if (!pevent
->func_map
)
430 func_map_init(pevent
);
434 func
= bsearch(&key
, pevent
->func_map
, pevent
->func_count
,
435 sizeof(*pevent
->func_map
), func_bcmp
);
440 struct func_resolver
{
441 pevent_func_resolver_t
*func
;
447 * pevent_set_function_resolver - set an alternative function resolver
448 * @pevent: handle for the pevent
449 * @resolver: function to be used
450 * @priv: resolver function private state.
452 * Some tools may have already a way to resolve kernel functions, allow them to
453 * keep using it instead of duplicating all the entries inside
456 int pevent_set_function_resolver(struct pevent
*pevent
,
457 pevent_func_resolver_t
*func
, void *priv
)
459 struct func_resolver
*resolver
= malloc(sizeof(*resolver
));
461 if (resolver
== NULL
)
464 resolver
->func
= func
;
465 resolver
->priv
= priv
;
467 free(pevent
->func_resolver
);
468 pevent
->func_resolver
= resolver
;
474 * pevent_reset_function_resolver - reset alternative function resolver
475 * @pevent: handle for the pevent
477 * Stop using whatever alternative resolver was set, use the default
480 void pevent_reset_function_resolver(struct pevent
*pevent
)
482 free(pevent
->func_resolver
);
483 pevent
->func_resolver
= NULL
;
486 static struct func_map
*
487 find_func(struct pevent
*pevent
, unsigned long long addr
)
489 struct func_map
*map
;
491 if (!pevent
->func_resolver
)
492 return __find_func(pevent
, addr
);
494 map
= &pevent
->func_resolver
->map
;
497 map
->func
= pevent
->func_resolver
->func(pevent
->func_resolver
->priv
,
498 &map
->addr
, &map
->mod
);
499 if (map
->func
== NULL
)
506 * pevent_find_function - find a function by a given address
507 * @pevent: handle for the pevent
508 * @addr: the address to find the function with
510 * Returns a pointer to the function stored that has the given
511 * address. Note, the address does not have to be exact, it
512 * will select the function that would contain the address.
514 const char *pevent_find_function(struct pevent
*pevent
, unsigned long long addr
)
516 struct func_map
*map
;
518 map
= find_func(pevent
, addr
);
526 * pevent_find_function_address - find a function address by a given address
527 * @pevent: handle for the pevent
528 * @addr: the address to find the function with
530 * Returns the address the function starts at. This can be used in
531 * conjunction with pevent_find_function to print both the function
532 * name and the function offset.
535 pevent_find_function_address(struct pevent
*pevent
, unsigned long long addr
)
537 struct func_map
*map
;
539 map
= find_func(pevent
, addr
);
547 * pevent_register_function - register a function with a given address
548 * @pevent: handle for the pevent
549 * @function: the function name to register
550 * @addr: the address the function starts at
551 * @mod: the kernel module the function may be in (NULL for none)
553 * This registers a function name with an address and module.
554 * The @func passed in is duplicated.
556 int pevent_register_function(struct pevent
*pevent
, char *func
,
557 unsigned long long addr
, char *mod
)
559 struct func_list
*item
= malloc(sizeof(*item
));
564 item
->next
= pevent
->funclist
;
565 item
->func
= strdup(func
);
570 item
->mod
= strdup(mod
);
577 pevent
->funclist
= item
;
578 pevent
->func_count
++;
592 * pevent_print_funcs - print out the stored functions
593 * @pevent: handle for the pevent
595 * This prints out the stored functions.
597 void pevent_print_funcs(struct pevent
*pevent
)
601 if (!pevent
->func_map
)
602 func_map_init(pevent
);
604 for (i
= 0; i
< (int)pevent
->func_count
; i
++) {
606 pevent
->func_map
[i
].addr
,
607 pevent
->func_map
[i
].func
);
608 if (pevent
->func_map
[i
].mod
)
609 printf(" [%s]\n", pevent
->func_map
[i
].mod
);
616 unsigned long long addr
;
621 struct printk_list
*next
;
622 unsigned long long addr
;
626 static int printk_cmp(const void *a
, const void *b
)
628 const struct printk_map
*pa
= a
;
629 const struct printk_map
*pb
= b
;
631 if (pa
->addr
< pb
->addr
)
633 if (pa
->addr
> pb
->addr
)
639 static int printk_map_init(struct pevent
*pevent
)
641 struct printk_list
*printklist
;
642 struct printk_list
*item
;
643 struct printk_map
*printk_map
;
646 printk_map
= malloc(sizeof(*printk_map
) * (pevent
->printk_count
+ 1));
650 printklist
= pevent
->printklist
;
654 printk_map
[i
].printk
= printklist
->printk
;
655 printk_map
[i
].addr
= printklist
->addr
;
658 printklist
= printklist
->next
;
662 qsort(printk_map
, pevent
->printk_count
, sizeof(*printk_map
), printk_cmp
);
664 pevent
->printk_map
= printk_map
;
665 pevent
->printklist
= NULL
;
670 static struct printk_map
*
671 find_printk(struct pevent
*pevent
, unsigned long long addr
)
673 struct printk_map
*printk
;
674 struct printk_map key
;
676 if (!pevent
->printk_map
&& printk_map_init(pevent
))
681 printk
= bsearch(&key
, pevent
->printk_map
, pevent
->printk_count
,
682 sizeof(*pevent
->printk_map
), printk_cmp
);
688 * pevent_register_print_string - register a string by its address
689 * @pevent: handle for the pevent
690 * @fmt: the string format to register
691 * @addr: the address the string was located at
693 * This registers a string by the address it was stored in the kernel.
694 * The @fmt passed in is duplicated.
696 int pevent_register_print_string(struct pevent
*pevent
, const char *fmt
,
697 unsigned long long addr
)
699 struct printk_list
*item
= malloc(sizeof(*item
));
705 item
->next
= pevent
->printklist
;
708 /* Strip off quotes and '\n' from the end */
711 item
->printk
= strdup(fmt
);
715 p
= item
->printk
+ strlen(item
->printk
) - 1;
720 if (strcmp(p
, "\\n") == 0)
723 pevent
->printklist
= item
;
724 pevent
->printk_count
++;
735 * pevent_print_printk - print out the stored strings
736 * @pevent: handle for the pevent
738 * This prints the string formats that were stored.
740 void pevent_print_printk(struct pevent
*pevent
)
744 if (!pevent
->printk_map
)
745 printk_map_init(pevent
);
747 for (i
= 0; i
< (int)pevent
->printk_count
; i
++) {
748 printf("%016llx %s\n",
749 pevent
->printk_map
[i
].addr
,
750 pevent
->printk_map
[i
].printk
);
754 static struct event_format
*alloc_event(void)
756 return calloc(1, sizeof(struct event_format
));
759 static int add_event(struct pevent
*pevent
, struct event_format
*event
)
762 struct event_format
**events
= realloc(pevent
->events
, sizeof(event
) *
763 (pevent
->nr_events
+ 1));
767 pevent
->events
= events
;
769 for (i
= 0; i
< pevent
->nr_events
; i
++) {
770 if (pevent
->events
[i
]->id
> event
->id
)
773 if (i
< pevent
->nr_events
)
774 memmove(&pevent
->events
[i
+ 1],
776 sizeof(event
) * (pevent
->nr_events
- i
));
778 pevent
->events
[i
] = event
;
781 event
->pevent
= pevent
;
786 static int event_item_type(enum event_type type
)
789 case EVENT_ITEM
... EVENT_SQUOTE
:
791 case EVENT_ERROR
... EVENT_DELIM
:
797 static void free_flag_sym(struct print_flag_sym
*fsym
)
799 struct print_flag_sym
*next
;
810 static void free_arg(struct print_arg
*arg
)
812 struct print_arg
*farg
;
819 free(arg
->atom
.atom
);
822 free(arg
->field
.name
);
825 free_arg(arg
->flags
.field
);
826 free(arg
->flags
.delim
);
827 free_flag_sym(arg
->flags
.flags
);
830 free_arg(arg
->symbol
.field
);
831 free_flag_sym(arg
->symbol
.symbols
);
834 free_arg(arg
->hex
.field
);
835 free_arg(arg
->hex
.size
);
837 case PRINT_INT_ARRAY
:
838 free_arg(arg
->int_array
.field
);
839 free_arg(arg
->int_array
.count
);
840 free_arg(arg
->int_array
.el_size
);
843 free(arg
->typecast
.type
);
844 free_arg(arg
->typecast
.item
);
848 free(arg
->string
.string
);
851 free(arg
->bitmask
.bitmask
);
853 case PRINT_DYNAMIC_ARRAY
:
854 case PRINT_DYNAMIC_ARRAY_LEN
:
855 free(arg
->dynarray
.index
);
859 free_arg(arg
->op
.left
);
860 free_arg(arg
->op
.right
);
863 while (arg
->func
.args
) {
864 farg
= arg
->func
.args
;
865 arg
->func
.args
= farg
->next
;
878 static enum event_type
get_type(int ch
)
881 return EVENT_NEWLINE
;
884 if (isalnum(ch
) || ch
== '_')
892 if (ch
== '(' || ch
== ')' || ch
== ',')
898 static int __read_char(void)
900 if (input_buf_ptr
>= input_buf_siz
)
903 return input_buf
[input_buf_ptr
++];
906 static int __peek_char(void)
908 if (input_buf_ptr
>= input_buf_siz
)
911 return input_buf
[input_buf_ptr
];
915 * pevent_peek_char - peek at the next character that will be read
917 * Returns the next character read, or -1 if end of buffer.
919 int pevent_peek_char(void)
921 return __peek_char();
924 static int extend_token(char **tok
, char *buf
, int size
)
926 char *newtok
= realloc(*tok
, size
);
943 static enum event_type
force_token(const char *str
, char **tok
);
945 static enum event_type
__read_token(char **tok
)
948 int ch
, last_ch
, quote_ch
, next_ch
;
951 enum event_type type
;
961 if (type
== EVENT_NONE
)
969 if (asprintf(tok
, "%c", ch
) < 0)
977 next_ch
= __peek_char();
978 if (next_ch
== '>') {
979 buf
[i
++] = __read_char();
992 buf
[i
++] = __read_char();
1004 default: /* what should we do instead? */
1014 buf
[i
++] = __read_char();
1019 /* don't keep quotes */
1025 if (i
== (BUFSIZ
- 1)) {
1029 if (extend_token(tok
, buf
, tok_size
) < 0)
1036 /* the '\' '\' will cancel itself */
1037 if (ch
== '\\' && last_ch
== '\\')
1039 } while (ch
!= quote_ch
|| last_ch
== '\\');
1040 /* remove the last quote */
1044 * For strings (double quotes) check the next token.
1045 * If it is another string, concatinate the two.
1047 if (type
== EVENT_DQUOTE
) {
1048 unsigned long long save_input_buf_ptr
= input_buf_ptr
;
1052 } while (isspace(ch
));
1055 input_buf_ptr
= save_input_buf_ptr
;
1060 case EVENT_ERROR
... EVENT_SPACE
:
1066 while (get_type(__peek_char()) == type
) {
1067 if (i
== (BUFSIZ
- 1)) {
1071 if (extend_token(tok
, buf
, tok_size
) < 0)
1081 if (extend_token(tok
, buf
, tok_size
+ i
+ 1) < 0)
1084 if (type
== EVENT_ITEM
) {
1086 * Older versions of the kernel has a bug that
1087 * creates invalid symbols and will break the mac80211
1088 * parsing. This is a work around to that bug.
1090 * See Linux kernel commit:
1091 * 811cb50baf63461ce0bdb234927046131fc7fa8b
1093 if (strcmp(*tok
, "LOCAL_PR_FMT") == 0) {
1096 return force_token("\"\%s\" ", tok
);
1097 } else if (strcmp(*tok
, "STA_PR_FMT") == 0) {
1100 return force_token("\" sta:%pM\" ", tok
);
1101 } else if (strcmp(*tok
, "VIF_PR_FMT") == 0) {
1104 return force_token("\" vif:%p(%d)\" ", tok
);
1111 static enum event_type
force_token(const char *str
, char **tok
)
1113 const char *save_input_buf
;
1114 unsigned long long save_input_buf_ptr
;
1115 unsigned long long save_input_buf_siz
;
1116 enum event_type type
;
1118 /* save off the current input pointers */
1119 save_input_buf
= input_buf
;
1120 save_input_buf_ptr
= input_buf_ptr
;
1121 save_input_buf_siz
= input_buf_siz
;
1123 init_input_buf(str
, strlen(str
));
1125 type
= __read_token(tok
);
1127 /* reset back to original token */
1128 input_buf
= save_input_buf
;
1129 input_buf_ptr
= save_input_buf_ptr
;
1130 input_buf_siz
= save_input_buf_siz
;
1135 static void free_token(char *tok
)
1141 static enum event_type
read_token(char **tok
)
1143 enum event_type type
;
1146 type
= __read_token(tok
);
1147 if (type
!= EVENT_SPACE
)
1159 * pevent_read_token - access to utilites to use the pevent parser
1160 * @tok: The token to return
1162 * This will parse tokens from the string given by
1163 * pevent_init_data().
1165 * Returns the token type.
1167 enum event_type
pevent_read_token(char **tok
)
1169 return read_token(tok
);
1173 * pevent_free_token - free a token returned by pevent_read_token
1174 * @token: the token to free
1176 void pevent_free_token(char *token
)
1182 static enum event_type
read_token_item(char **tok
)
1184 enum event_type type
;
1187 type
= __read_token(tok
);
1188 if (type
!= EVENT_SPACE
&& type
!= EVENT_NEWLINE
)
1199 static int test_type(enum event_type type
, enum event_type expect
)
1201 if (type
!= expect
) {
1202 do_warning("Error: expected type %d but read %d",
1209 static int test_type_token(enum event_type type
, const char *token
,
1210 enum event_type expect
, const char *expect_tok
)
1212 if (type
!= expect
) {
1213 do_warning("Error: expected type %d but read %d",
1218 if (strcmp(token
, expect_tok
) != 0) {
1219 do_warning("Error: expected '%s' but read '%s'",
1226 static int __read_expect_type(enum event_type expect
, char **tok
, int newline_ok
)
1228 enum event_type type
;
1231 type
= read_token(tok
);
1233 type
= read_token_item(tok
);
1234 return test_type(type
, expect
);
1237 static int read_expect_type(enum event_type expect
, char **tok
)
1239 return __read_expect_type(expect
, tok
, 1);
1242 static int __read_expected(enum event_type expect
, const char *str
,
1245 enum event_type type
;
1250 type
= read_token(&token
);
1252 type
= read_token_item(&token
);
1254 ret
= test_type_token(type
, token
, expect
, str
);
1261 static int read_expected(enum event_type expect
, const char *str
)
1263 return __read_expected(expect
, str
, 1);
1266 static int read_expected_item(enum event_type expect
, const char *str
)
1268 return __read_expected(expect
, str
, 0);
1271 static char *event_read_name(void)
1275 if (read_expected(EVENT_ITEM
, "name") < 0)
1278 if (read_expected(EVENT_OP
, ":") < 0)
1281 if (read_expect_type(EVENT_ITEM
, &token
) < 0)
1291 static int event_read_id(void)
1296 if (read_expected_item(EVENT_ITEM
, "ID") < 0)
1299 if (read_expected(EVENT_OP
, ":") < 0)
1302 if (read_expect_type(EVENT_ITEM
, &token
) < 0)
1305 id
= strtoul(token
, NULL
, 0);
1314 static int field_is_string(struct format_field
*field
)
1316 if ((field
->flags
& FIELD_IS_ARRAY
) &&
1317 (strstr(field
->type
, "char") || strstr(field
->type
, "u8") ||
1318 strstr(field
->type
, "s8")))
1324 static int field_is_dynamic(struct format_field
*field
)
1326 if (strncmp(field
->type
, "__data_loc", 10) == 0)
1332 static int field_is_long(struct format_field
*field
)
1334 /* includes long long */
1335 if (strstr(field
->type
, "long"))
1341 static unsigned int type_size(const char *name
)
1343 /* This covers all FIELD_IS_STRING types. */
1361 for (i
= 0; table
[i
].type
; i
++) {
1362 if (!strcmp(table
[i
].type
, name
))
1363 return table
[i
].size
;
1369 static int event_read_fields(struct event_format
*event
, struct format_field
**fields
)
1371 struct format_field
*field
= NULL
;
1372 enum event_type type
;
1378 unsigned int size_dynamic
= 0;
1380 type
= read_token(&token
);
1381 if (type
== EVENT_NEWLINE
) {
1388 if (test_type_token(type
, token
, EVENT_ITEM
, "field"))
1392 type
= read_token(&token
);
1394 * The ftrace fields may still use the "special" name.
1397 if (event
->flags
& EVENT_FL_ISFTRACE
&&
1398 type
== EVENT_ITEM
&& strcmp(token
, "special") == 0) {
1400 type
= read_token(&token
);
1403 if (test_type_token(type
, token
, EVENT_OP
, ":") < 0)
1407 if (read_expect_type(EVENT_ITEM
, &token
) < 0)
1412 field
= calloc(1, sizeof(*field
));
1416 field
->event
= event
;
1418 /* read the rest of the type */
1420 type
= read_token(&token
);
1421 if (type
== EVENT_ITEM
||
1422 (type
== EVENT_OP
&& strcmp(token
, "*") == 0) ||
1424 * Some of the ftrace fields are broken and have
1425 * an illegal "." in them.
1427 (event
->flags
& EVENT_FL_ISFTRACE
&&
1428 type
== EVENT_OP
&& strcmp(token
, ".") == 0)) {
1430 if (strcmp(token
, "*") == 0)
1431 field
->flags
|= FIELD_IS_POINTER
;
1435 new_type
= realloc(field
->type
,
1436 strlen(field
->type
) +
1437 strlen(last_token
) + 2);
1442 field
->type
= new_type
;
1443 strcat(field
->type
, " ");
1444 strcat(field
->type
, last_token
);
1447 field
->type
= last_token
;
1456 do_warning_event(event
, "%s: no type found", __func__
);
1459 field
->name
= field
->alias
= last_token
;
1461 if (test_type(type
, EVENT_OP
))
1464 if (strcmp(token
, "[") == 0) {
1465 enum event_type last_type
= type
;
1466 char *brackets
= token
;
1470 field
->flags
|= FIELD_IS_ARRAY
;
1472 type
= read_token(&token
);
1474 if (type
== EVENT_ITEM
)
1475 field
->arraylen
= strtoul(token
, NULL
, 0);
1477 field
->arraylen
= 0;
1479 while (strcmp(token
, "]") != 0) {
1480 if (last_type
== EVENT_ITEM
&&
1487 new_brackets
= realloc(brackets
,
1489 strlen(token
) + len
);
1490 if (!new_brackets
) {
1494 brackets
= new_brackets
;
1496 strcat(brackets
, " ");
1497 strcat(brackets
, token
);
1498 /* We only care about the last token */
1499 field
->arraylen
= strtoul(token
, NULL
, 0);
1501 type
= read_token(&token
);
1502 if (type
== EVENT_NONE
) {
1503 do_warning_event(event
, "failed to find token");
1510 new_brackets
= realloc(brackets
, strlen(brackets
) + 2);
1511 if (!new_brackets
) {
1515 brackets
= new_brackets
;
1516 strcat(brackets
, "]");
1518 /* add brackets to type */
1520 type
= read_token(&token
);
1522 * If the next token is not an OP, then it is of
1523 * the format: type [] item;
1525 if (type
== EVENT_ITEM
) {
1527 new_type
= realloc(field
->type
,
1528 strlen(field
->type
) +
1529 strlen(field
->name
) +
1530 strlen(brackets
) + 2);
1535 field
->type
= new_type
;
1536 strcat(field
->type
, " ");
1537 strcat(field
->type
, field
->name
);
1538 size_dynamic
= type_size(field
->name
);
1539 free_token(field
->name
);
1540 strcat(field
->type
, brackets
);
1541 field
->name
= field
->alias
= token
;
1542 type
= read_token(&token
);
1545 new_type
= realloc(field
->type
,
1546 strlen(field
->type
) +
1547 strlen(brackets
) + 1);
1552 field
->type
= new_type
;
1553 strcat(field
->type
, brackets
);
1558 if (field_is_string(field
))
1559 field
->flags
|= FIELD_IS_STRING
;
1560 if (field_is_dynamic(field
))
1561 field
->flags
|= FIELD_IS_DYNAMIC
;
1562 if (field_is_long(field
))
1563 field
->flags
|= FIELD_IS_LONG
;
1565 if (test_type_token(type
, token
, EVENT_OP
, ";"))
1569 if (read_expected(EVENT_ITEM
, "offset") < 0)
1572 if (read_expected(EVENT_OP
, ":") < 0)
1575 if (read_expect_type(EVENT_ITEM
, &token
))
1577 field
->offset
= strtoul(token
, NULL
, 0);
1580 if (read_expected(EVENT_OP
, ";") < 0)
1583 if (read_expected(EVENT_ITEM
, "size") < 0)
1586 if (read_expected(EVENT_OP
, ":") < 0)
1589 if (read_expect_type(EVENT_ITEM
, &token
))
1591 field
->size
= strtoul(token
, NULL
, 0);
1594 if (read_expected(EVENT_OP
, ";") < 0)
1597 type
= read_token(&token
);
1598 if (type
!= EVENT_NEWLINE
) {
1599 /* newer versions of the kernel have a "signed" type */
1600 if (test_type_token(type
, token
, EVENT_ITEM
, "signed"))
1605 if (read_expected(EVENT_OP
, ":") < 0)
1608 if (read_expect_type(EVENT_ITEM
, &token
))
1611 if (strtoul(token
, NULL
, 0))
1612 field
->flags
|= FIELD_IS_SIGNED
;
1615 if (read_expected(EVENT_OP
, ";") < 0)
1618 if (read_expect_type(EVENT_NEWLINE
, &token
))
1624 if (field
->flags
& FIELD_IS_ARRAY
) {
1625 if (field
->arraylen
)
1626 field
->elementsize
= field
->size
/ field
->arraylen
;
1627 else if (field
->flags
& FIELD_IS_DYNAMIC
)
1628 field
->elementsize
= size_dynamic
;
1629 else if (field
->flags
& FIELD_IS_STRING
)
1630 field
->elementsize
= 1;
1631 else if (field
->flags
& FIELD_IS_LONG
)
1632 field
->elementsize
= event
->pevent
?
1633 event
->pevent
->long_size
:
1636 field
->elementsize
= field
->size
;
1639 fields
= &field
->next
;
1656 static int event_read_format(struct event_format
*event
)
1661 if (read_expected_item(EVENT_ITEM
, "format") < 0)
1664 if (read_expected(EVENT_OP
, ":") < 0)
1667 if (read_expect_type(EVENT_NEWLINE
, &token
))
1671 ret
= event_read_fields(event
, &event
->format
.common_fields
);
1674 event
->format
.nr_common
= ret
;
1676 ret
= event_read_fields(event
, &event
->format
.fields
);
1679 event
->format
.nr_fields
= ret
;
1688 static enum event_type
1689 process_arg_token(struct event_format
*event
, struct print_arg
*arg
,
1690 char **tok
, enum event_type type
);
1692 static enum event_type
1693 process_arg(struct event_format
*event
, struct print_arg
*arg
, char **tok
)
1695 enum event_type type
;
1698 type
= read_token(&token
);
1701 return process_arg_token(event
, arg
, tok
, type
);
1704 static enum event_type
1705 process_op(struct event_format
*event
, struct print_arg
*arg
, char **tok
);
1708 * For __print_symbolic() and __print_flags, we need to completely
1709 * evaluate the first argument, which defines what to print next.
1711 static enum event_type
1712 process_field_arg(struct event_format
*event
, struct print_arg
*arg
, char **tok
)
1714 enum event_type type
;
1716 type
= process_arg(event
, arg
, tok
);
1718 while (type
== EVENT_OP
) {
1719 type
= process_op(event
, arg
, tok
);
1725 static enum event_type
1726 process_cond(struct event_format
*event
, struct print_arg
*top
, char **tok
)
1728 struct print_arg
*arg
, *left
, *right
;
1729 enum event_type type
;
1734 right
= alloc_arg();
1736 if (!arg
|| !left
|| !right
) {
1737 do_warning_event(event
, "%s: not enough memory!", __func__
);
1738 /* arg will be freed at out_free */
1744 arg
->type
= PRINT_OP
;
1745 arg
->op
.left
= left
;
1746 arg
->op
.right
= right
;
1749 type
= process_arg(event
, left
, &token
);
1752 if (type
== EVENT_ERROR
)
1755 /* Handle other operations in the arguments */
1756 if (type
== EVENT_OP
&& strcmp(token
, ":") != 0) {
1757 type
= process_op(event
, left
, &token
);
1761 if (test_type_token(type
, token
, EVENT_OP
, ":"))
1766 type
= process_arg(event
, right
, &token
);
1768 top
->op
.right
= arg
;
1774 /* Top may point to itself */
1775 top
->op
.right
= NULL
;
1781 static enum event_type
1782 process_array(struct event_format
*event
, struct print_arg
*top
, char **tok
)
1784 struct print_arg
*arg
;
1785 enum event_type type
;
1790 do_warning_event(event
, "%s: not enough memory!", __func__
);
1791 /* '*tok' is set to top->op.op. No need to free. */
1797 type
= process_arg(event
, arg
, &token
);
1798 if (test_type_token(type
, token
, EVENT_OP
, "]"))
1801 top
->op
.right
= arg
;
1804 type
= read_token_item(&token
);
1815 static int get_op_prio(char *op
)
1829 /* '>>' and '<<' are 8 */
1833 /* '==' and '!=' are 10 */
1843 do_warning("unknown op '%c'", op
[0]);
1847 if (strcmp(op
, "++") == 0 ||
1848 strcmp(op
, "--") == 0) {
1850 } else if (strcmp(op
, ">>") == 0 ||
1851 strcmp(op
, "<<") == 0) {
1853 } else if (strcmp(op
, ">=") == 0 ||
1854 strcmp(op
, "<=") == 0) {
1856 } else if (strcmp(op
, "==") == 0 ||
1857 strcmp(op
, "!=") == 0) {
1859 } else if (strcmp(op
, "&&") == 0) {
1861 } else if (strcmp(op
, "||") == 0) {
1864 do_warning("unknown op '%s'", op
);
1870 static int set_op_prio(struct print_arg
*arg
)
1873 /* single ops are the greatest */
1874 if (!arg
->op
.left
|| arg
->op
.left
->type
== PRINT_NULL
)
1877 arg
->op
.prio
= get_op_prio(arg
->op
.op
);
1879 return arg
->op
.prio
;
1882 /* Note, *tok does not get freed, but will most likely be saved */
1883 static enum event_type
1884 process_op(struct event_format
*event
, struct print_arg
*arg
, char **tok
)
1886 struct print_arg
*left
, *right
= NULL
;
1887 enum event_type type
;
1890 /* the op is passed in via tok */
1893 if (arg
->type
== PRINT_OP
&& !arg
->op
.left
) {
1894 /* handle single op */
1896 do_warning_event(event
, "bad op token %s", token
);
1906 do_warning_event(event
, "bad op token %s", token
);
1911 /* make an empty left */
1916 left
->type
= PRINT_NULL
;
1917 arg
->op
.left
= left
;
1919 right
= alloc_arg();
1923 arg
->op
.right
= right
;
1925 /* do not free the token, it belongs to an op */
1927 type
= process_arg(event
, right
, tok
);
1929 } else if (strcmp(token
, "?") == 0) {
1935 /* copy the top arg to the left */
1938 arg
->type
= PRINT_OP
;
1940 arg
->op
.left
= left
;
1943 /* it will set arg->op.right */
1944 type
= process_cond(event
, arg
, tok
);
1946 } else if (strcmp(token
, ">>") == 0 ||
1947 strcmp(token
, "<<") == 0 ||
1948 strcmp(token
, "&") == 0 ||
1949 strcmp(token
, "|") == 0 ||
1950 strcmp(token
, "&&") == 0 ||
1951 strcmp(token
, "||") == 0 ||
1952 strcmp(token
, "-") == 0 ||
1953 strcmp(token
, "+") == 0 ||
1954 strcmp(token
, "*") == 0 ||
1955 strcmp(token
, "^") == 0 ||
1956 strcmp(token
, "/") == 0 ||
1957 strcmp(token
, "%") == 0 ||
1958 strcmp(token
, "<") == 0 ||
1959 strcmp(token
, ">") == 0 ||
1960 strcmp(token
, "<=") == 0 ||
1961 strcmp(token
, ">=") == 0 ||
1962 strcmp(token
, "==") == 0 ||
1963 strcmp(token
, "!=") == 0) {
1969 /* copy the top arg to the left */
1972 arg
->type
= PRINT_OP
;
1974 arg
->op
.left
= left
;
1975 arg
->op
.right
= NULL
;
1977 if (set_op_prio(arg
) == -1) {
1978 event
->flags
|= EVENT_FL_FAILED
;
1979 /* arg->op.op (= token) will be freed at out_free */
1984 type
= read_token_item(&token
);
1987 /* could just be a type pointer */
1988 if ((strcmp(arg
->op
.op
, "*") == 0) &&
1989 type
== EVENT_DELIM
&& (strcmp(token
, ")") == 0)) {
1992 if (left
->type
!= PRINT_ATOM
) {
1993 do_warning_event(event
, "bad pointer type");
1996 new_atom
= realloc(left
->atom
.atom
,
1997 strlen(left
->atom
.atom
) + 3);
2001 left
->atom
.atom
= new_atom
;
2002 strcat(left
->atom
.atom
, " *");
2010 right
= alloc_arg();
2014 type
= process_arg_token(event
, right
, tok
, type
);
2015 if (type
== EVENT_ERROR
) {
2017 /* token was freed in process_arg_token() via *tok */
2022 if (right
->type
== PRINT_OP
&&
2023 get_op_prio(arg
->op
.op
) < get_op_prio(right
->op
.op
)) {
2024 struct print_arg tmp
;
2026 /* rotate ops according to the priority */
2027 arg
->op
.right
= right
->op
.left
;
2033 arg
->op
.left
= right
;
2035 arg
->op
.right
= right
;
2038 } else if (strcmp(token
, "[") == 0) {
2046 arg
->type
= PRINT_OP
;
2048 arg
->op
.left
= left
;
2052 /* it will set arg->op.right */
2053 type
= process_array(event
, arg
, tok
);
2056 do_warning_event(event
, "unknown op '%s'", token
);
2057 event
->flags
|= EVENT_FL_FAILED
;
2058 /* the arg is now the left side */
2062 if (type
== EVENT_OP
&& strcmp(*tok
, ":") != 0) {
2065 /* higher prios need to be closer to the root */
2066 prio
= get_op_prio(*tok
);
2068 if (prio
> arg
->op
.prio
)
2069 return process_op(event
, arg
, tok
);
2071 return process_op(event
, right
, tok
);
2077 do_warning_event(event
, "%s: not enough memory!", __func__
);
2084 static enum event_type
2085 process_entry(struct event_format
*event __maybe_unused
, struct print_arg
*arg
,
2088 enum event_type type
;
2092 if (read_expected(EVENT_OP
, "->") < 0)
2095 if (read_expect_type(EVENT_ITEM
, &token
) < 0)
2099 arg
->type
= PRINT_FIELD
;
2100 arg
->field
.name
= field
;
2102 if (is_flag_field
) {
2103 arg
->field
.field
= pevent_find_any_field(event
, arg
->field
.name
);
2104 arg
->field
.field
->flags
|= FIELD_IS_FLAG
;
2106 } else if (is_symbolic_field
) {
2107 arg
->field
.field
= pevent_find_any_field(event
, arg
->field
.name
);
2108 arg
->field
.field
->flags
|= FIELD_IS_SYMBOLIC
;
2109 is_symbolic_field
= 0;
2112 type
= read_token(&token
);
2124 static int alloc_and_process_delim(struct event_format
*event
, char *next_token
,
2125 struct print_arg
**print_arg
)
2127 struct print_arg
*field
;
2128 enum event_type type
;
2132 field
= alloc_arg();
2134 do_warning_event(event
, "%s: not enough memory!", __func__
);
2139 type
= process_arg(event
, field
, &token
);
2141 if (test_type_token(type
, token
, EVENT_DELIM
, next_token
)) {
2145 goto out_free_token
;
2156 static char *arg_eval (struct print_arg
*arg
);
2158 static unsigned long long
2159 eval_type_str(unsigned long long val
, const char *type
, int pointer
)
2169 if (type
[len
-1] != '*') {
2170 do_warning("pointer expected with non pointer type");
2176 do_warning("%s: not enough memory!", __func__
);
2179 memcpy(ref
, type
, len
);
2181 /* chop off the " *" */
2184 val
= eval_type_str(val
, ref
, 0);
2189 /* check if this is a pointer */
2190 if (type
[len
- 1] == '*')
2193 /* Try to figure out the arg size*/
2194 if (strncmp(type
, "struct", 6) == 0)
2198 if (strcmp(type
, "u8") == 0)
2201 if (strcmp(type
, "u16") == 0)
2202 return val
& 0xffff;
2204 if (strcmp(type
, "u32") == 0)
2205 return val
& 0xffffffff;
2207 if (strcmp(type
, "u64") == 0 ||
2208 strcmp(type
, "s64"))
2211 if (strcmp(type
, "s8") == 0)
2212 return (unsigned long long)(char)val
& 0xff;
2214 if (strcmp(type
, "s16") == 0)
2215 return (unsigned long long)(short)val
& 0xffff;
2217 if (strcmp(type
, "s32") == 0)
2218 return (unsigned long long)(int)val
& 0xffffffff;
2220 if (strncmp(type
, "unsigned ", 9) == 0) {
2225 if (strcmp(type
, "char") == 0) {
2227 return (unsigned long long)(char)val
& 0xff;
2232 if (strcmp(type
, "short") == 0) {
2234 return (unsigned long long)(short)val
& 0xffff;
2236 return val
& 0xffff;
2239 if (strcmp(type
, "int") == 0) {
2241 return (unsigned long long)(int)val
& 0xffffffff;
2243 return val
& 0xffffffff;
2250 * Try to figure out the type.
2252 static unsigned long long
2253 eval_type(unsigned long long val
, struct print_arg
*arg
, int pointer
)
2255 if (arg
->type
!= PRINT_TYPE
) {
2256 do_warning("expected type argument");
2260 return eval_type_str(val
, arg
->typecast
.type
, pointer
);
2263 static int arg_num_eval(struct print_arg
*arg
, long long *val
)
2265 long long left
, right
;
2268 switch (arg
->type
) {
2270 *val
= strtoll(arg
->atom
.atom
, NULL
, 0);
2273 ret
= arg_num_eval(arg
->typecast
.item
, val
);
2276 *val
= eval_type(*val
, arg
, 0);
2279 switch (arg
->op
.op
[0]) {
2281 ret
= arg_num_eval(arg
->op
.left
, &left
);
2284 ret
= arg_num_eval(arg
->op
.right
, &right
);
2288 *val
= left
|| right
;
2290 *val
= left
| right
;
2293 ret
= arg_num_eval(arg
->op
.left
, &left
);
2296 ret
= arg_num_eval(arg
->op
.right
, &right
);
2300 *val
= left
&& right
;
2302 *val
= left
& right
;
2305 ret
= arg_num_eval(arg
->op
.left
, &left
);
2308 ret
= arg_num_eval(arg
->op
.right
, &right
);
2311 switch (arg
->op
.op
[1]) {
2313 *val
= left
< right
;
2316 *val
= left
<< right
;
2319 *val
= left
<= right
;
2322 do_warning("unknown op '%s'", arg
->op
.op
);
2327 ret
= arg_num_eval(arg
->op
.left
, &left
);
2330 ret
= arg_num_eval(arg
->op
.right
, &right
);
2333 switch (arg
->op
.op
[1]) {
2335 *val
= left
> right
;
2338 *val
= left
>> right
;
2341 *val
= left
>= right
;
2344 do_warning("unknown op '%s'", arg
->op
.op
);
2349 ret
= arg_num_eval(arg
->op
.left
, &left
);
2352 ret
= arg_num_eval(arg
->op
.right
, &right
);
2356 if (arg
->op
.op
[1] != '=') {
2357 do_warning("unknown op '%s'", arg
->op
.op
);
2360 *val
= left
== right
;
2363 ret
= arg_num_eval(arg
->op
.left
, &left
);
2366 ret
= arg_num_eval(arg
->op
.right
, &right
);
2370 switch (arg
->op
.op
[1]) {
2372 *val
= left
!= right
;
2375 do_warning("unknown op '%s'", arg
->op
.op
);
2380 /* check for negative */
2381 if (arg
->op
.left
->type
== PRINT_NULL
)
2384 ret
= arg_num_eval(arg
->op
.left
, &left
);
2387 ret
= arg_num_eval(arg
->op
.right
, &right
);
2390 *val
= left
- right
;
2393 if (arg
->op
.left
->type
== PRINT_NULL
)
2396 ret
= arg_num_eval(arg
->op
.left
, &left
);
2399 ret
= arg_num_eval(arg
->op
.right
, &right
);
2402 *val
= left
+ right
;
2405 ret
= arg_num_eval(arg
->op
.right
, &right
);
2411 do_warning("unknown op '%s'", arg
->op
.op
);
2417 case PRINT_FIELD
... PRINT_SYMBOL
:
2422 do_warning("invalid eval type %d", arg
->type
);
2429 static char *arg_eval (struct print_arg
*arg
)
2432 static char buf
[20];
2434 switch (arg
->type
) {
2436 return arg
->atom
.atom
;
2438 return arg_eval(arg
->typecast
.item
);
2440 if (!arg_num_eval(arg
, &val
))
2442 sprintf(buf
, "%lld", val
);
2446 case PRINT_FIELD
... PRINT_SYMBOL
:
2451 do_warning("invalid eval type %d", arg
->type
);
2458 static enum event_type
2459 process_fields(struct event_format
*event
, struct print_flag_sym
**list
, char **tok
)
2461 enum event_type type
;
2462 struct print_arg
*arg
= NULL
;
2463 struct print_flag_sym
*field
;
2469 type
= read_token_item(&token
);
2470 if (test_type_token(type
, token
, EVENT_OP
, "{"))
2478 type
= process_arg(event
, arg
, &token
);
2480 if (type
== EVENT_OP
)
2481 type
= process_op(event
, arg
, &token
);
2483 if (type
== EVENT_ERROR
)
2486 if (test_type_token(type
, token
, EVENT_DELIM
, ","))
2489 field
= calloc(1, sizeof(*field
));
2493 value
= arg_eval(arg
);
2495 goto out_free_field
;
2496 field
->value
= strdup(value
);
2497 if (field
->value
== NULL
)
2498 goto out_free_field
;
2506 type
= process_arg(event
, arg
, &token
);
2507 if (test_type_token(type
, token
, EVENT_OP
, "}"))
2508 goto out_free_field
;
2510 value
= arg_eval(arg
);
2512 goto out_free_field
;
2513 field
->str
= strdup(value
);
2514 if (field
->str
== NULL
)
2515 goto out_free_field
;
2520 list
= &field
->next
;
2523 type
= read_token_item(&token
);
2524 } while (type
== EVENT_DELIM
&& strcmp(token
, ",") == 0);
2530 free_flag_sym(field
);
2539 static enum event_type
2540 process_flags(struct event_format
*event
, struct print_arg
*arg
, char **tok
)
2542 struct print_arg
*field
;
2543 enum event_type type
;
2546 memset(arg
, 0, sizeof(*arg
));
2547 arg
->type
= PRINT_FLAGS
;
2549 field
= alloc_arg();
2551 do_warning_event(event
, "%s: not enough memory!", __func__
);
2555 type
= process_field_arg(event
, field
, &token
);
2557 /* Handle operations in the first argument */
2558 while (type
== EVENT_OP
)
2559 type
= process_op(event
, field
, &token
);
2561 if (test_type_token(type
, token
, EVENT_DELIM
, ","))
2562 goto out_free_field
;
2565 arg
->flags
.field
= field
;
2567 type
= read_token_item(&token
);
2568 if (event_item_type(type
)) {
2569 arg
->flags
.delim
= token
;
2570 type
= read_token_item(&token
);
2573 if (test_type_token(type
, token
, EVENT_DELIM
, ","))
2576 type
= process_fields(event
, &arg
->flags
.flags
, &token
);
2577 if (test_type_token(type
, token
, EVENT_DELIM
, ")"))
2581 type
= read_token_item(tok
);
2592 static enum event_type
2593 process_symbols(struct event_format
*event
, struct print_arg
*arg
, char **tok
)
2595 struct print_arg
*field
;
2596 enum event_type type
;
2599 memset(arg
, 0, sizeof(*arg
));
2600 arg
->type
= PRINT_SYMBOL
;
2602 field
= alloc_arg();
2604 do_warning_event(event
, "%s: not enough memory!", __func__
);
2608 type
= process_field_arg(event
, field
, &token
);
2610 if (test_type_token(type
, token
, EVENT_DELIM
, ","))
2611 goto out_free_field
;
2613 arg
->symbol
.field
= field
;
2615 type
= process_fields(event
, &arg
->symbol
.symbols
, &token
);
2616 if (test_type_token(type
, token
, EVENT_DELIM
, ")"))
2620 type
= read_token_item(tok
);
2631 static enum event_type
2632 process_hex(struct event_format
*event
, struct print_arg
*arg
, char **tok
)
2634 memset(arg
, 0, sizeof(*arg
));
2635 arg
->type
= PRINT_HEX
;
2637 if (alloc_and_process_delim(event
, ",", &arg
->hex
.field
))
2640 if (alloc_and_process_delim(event
, ")", &arg
->hex
.size
))
2643 return read_token_item(tok
);
2646 free_arg(arg
->hex
.field
);
2647 arg
->hex
.field
= NULL
;
2653 static enum event_type
2654 process_int_array(struct event_format
*event
, struct print_arg
*arg
, char **tok
)
2656 memset(arg
, 0, sizeof(*arg
));
2657 arg
->type
= PRINT_INT_ARRAY
;
2659 if (alloc_and_process_delim(event
, ",", &arg
->int_array
.field
))
2662 if (alloc_and_process_delim(event
, ",", &arg
->int_array
.count
))
2665 if (alloc_and_process_delim(event
, ")", &arg
->int_array
.el_size
))
2668 return read_token_item(tok
);
2671 free_arg(arg
->int_array
.count
);
2672 arg
->int_array
.count
= NULL
;
2674 free_arg(arg
->int_array
.field
);
2675 arg
->int_array
.field
= NULL
;
2681 static enum event_type
2682 process_dynamic_array(struct event_format
*event
, struct print_arg
*arg
, char **tok
)
2684 struct format_field
*field
;
2685 enum event_type type
;
2688 memset(arg
, 0, sizeof(*arg
));
2689 arg
->type
= PRINT_DYNAMIC_ARRAY
;
2692 * The item within the parenthesis is another field that holds
2693 * the index into where the array starts.
2695 type
= read_token(&token
);
2697 if (type
!= EVENT_ITEM
)
2700 /* Find the field */
2702 field
= pevent_find_field(event
, token
);
2706 arg
->dynarray
.field
= field
;
2707 arg
->dynarray
.index
= 0;
2709 if (read_expected(EVENT_DELIM
, ")") < 0)
2713 type
= read_token_item(&token
);
2715 if (type
!= EVENT_OP
|| strcmp(token
, "[") != 0)
2721 do_warning_event(event
, "%s: not enough memory!", __func__
);
2726 type
= process_arg(event
, arg
, &token
);
2727 if (type
== EVENT_ERROR
)
2730 if (!test_type_token(type
, token
, EVENT_OP
, "]"))
2734 type
= read_token_item(tok
);
2745 static enum event_type
2746 process_dynamic_array_len(struct event_format
*event
, struct print_arg
*arg
,
2749 struct format_field
*field
;
2750 enum event_type type
;
2753 if (read_expect_type(EVENT_ITEM
, &token
) < 0)
2756 arg
->type
= PRINT_DYNAMIC_ARRAY_LEN
;
2758 /* Find the field */
2759 field
= pevent_find_field(event
, token
);
2763 arg
->dynarray
.field
= field
;
2764 arg
->dynarray
.index
= 0;
2766 if (read_expected(EVENT_DELIM
, ")") < 0)
2769 type
= read_token(&token
);
2781 static enum event_type
2782 process_paren(struct event_format
*event
, struct print_arg
*arg
, char **tok
)
2784 struct print_arg
*item_arg
;
2785 enum event_type type
;
2788 type
= process_arg(event
, arg
, &token
);
2790 if (type
== EVENT_ERROR
)
2793 if (type
== EVENT_OP
)
2794 type
= process_op(event
, arg
, &token
);
2796 if (type
== EVENT_ERROR
)
2799 if (test_type_token(type
, token
, EVENT_DELIM
, ")"))
2803 type
= read_token_item(&token
);
2806 * If the next token is an item or another open paren, then
2807 * this was a typecast.
2809 if (event_item_type(type
) ||
2810 (type
== EVENT_DELIM
&& strcmp(token
, "(") == 0)) {
2812 /* make this a typecast and contine */
2814 /* prevous must be an atom */
2815 if (arg
->type
!= PRINT_ATOM
) {
2816 do_warning_event(event
, "previous needed to be PRINT_ATOM");
2820 item_arg
= alloc_arg();
2822 do_warning_event(event
, "%s: not enough memory!",
2827 arg
->type
= PRINT_TYPE
;
2828 arg
->typecast
.type
= arg
->atom
.atom
;
2829 arg
->typecast
.item
= item_arg
;
2830 type
= process_arg_token(event
, item_arg
, &token
, type
);
2844 static enum event_type
2845 process_str(struct event_format
*event __maybe_unused
, struct print_arg
*arg
,
2848 enum event_type type
;
2851 if (read_expect_type(EVENT_ITEM
, &token
) < 0)
2854 arg
->type
= PRINT_STRING
;
2855 arg
->string
.string
= token
;
2856 arg
->string
.offset
= -1;
2858 if (read_expected(EVENT_DELIM
, ")") < 0)
2861 type
= read_token(&token
);
2873 static enum event_type
2874 process_bitmask(struct event_format
*event __maybe_unused
, struct print_arg
*arg
,
2877 enum event_type type
;
2880 if (read_expect_type(EVENT_ITEM
, &token
) < 0)
2883 arg
->type
= PRINT_BITMASK
;
2884 arg
->bitmask
.bitmask
= token
;
2885 arg
->bitmask
.offset
= -1;
2887 if (read_expected(EVENT_DELIM
, ")") < 0)
2890 type
= read_token(&token
);
2902 static struct pevent_function_handler
*
2903 find_func_handler(struct pevent
*pevent
, char *func_name
)
2905 struct pevent_function_handler
*func
;
2910 for (func
= pevent
->func_handlers
; func
; func
= func
->next
) {
2911 if (strcmp(func
->name
, func_name
) == 0)
2918 static void remove_func_handler(struct pevent
*pevent
, char *func_name
)
2920 struct pevent_function_handler
*func
;
2921 struct pevent_function_handler
**next
;
2923 next
= &pevent
->func_handlers
;
2924 while ((func
= *next
)) {
2925 if (strcmp(func
->name
, func_name
) == 0) {
2927 free_func_handle(func
);
2934 static enum event_type
2935 process_func_handler(struct event_format
*event
, struct pevent_function_handler
*func
,
2936 struct print_arg
*arg
, char **tok
)
2938 struct print_arg
**next_arg
;
2939 struct print_arg
*farg
;
2940 enum event_type type
;
2944 arg
->type
= PRINT_FUNC
;
2945 arg
->func
.func
= func
;
2949 next_arg
= &(arg
->func
.args
);
2950 for (i
= 0; i
< func
->nr_args
; i
++) {
2953 do_warning_event(event
, "%s: not enough memory!",
2958 type
= process_arg(event
, farg
, &token
);
2959 if (i
< (func
->nr_args
- 1)) {
2960 if (type
!= EVENT_DELIM
|| strcmp(token
, ",") != 0) {
2961 do_warning_event(event
,
2962 "Error: function '%s()' expects %d arguments but event %s only uses %d",
2963 func
->name
, func
->nr_args
,
2964 event
->name
, i
+ 1);
2968 if (type
!= EVENT_DELIM
|| strcmp(token
, ")") != 0) {
2969 do_warning_event(event
,
2970 "Error: function '%s()' only expects %d arguments but event %s has more",
2971 func
->name
, func
->nr_args
, event
->name
);
2977 next_arg
= &(farg
->next
);
2981 type
= read_token(&token
);
2992 static enum event_type
2993 process_function(struct event_format
*event
, struct print_arg
*arg
,
2994 char *token
, char **tok
)
2996 struct pevent_function_handler
*func
;
2998 if (strcmp(token
, "__print_flags") == 0) {
3001 return process_flags(event
, arg
, tok
);
3003 if (strcmp(token
, "__print_symbolic") == 0) {
3005 is_symbolic_field
= 1;
3006 return process_symbols(event
, arg
, tok
);
3008 if (strcmp(token
, "__print_hex") == 0) {
3010 return process_hex(event
, arg
, tok
);
3012 if (strcmp(token
, "__print_array") == 0) {
3014 return process_int_array(event
, arg
, tok
);
3016 if (strcmp(token
, "__get_str") == 0) {
3018 return process_str(event
, arg
, tok
);
3020 if (strcmp(token
, "__get_bitmask") == 0) {
3022 return process_bitmask(event
, arg
, tok
);
3024 if (strcmp(token
, "__get_dynamic_array") == 0) {
3026 return process_dynamic_array(event
, arg
, tok
);
3028 if (strcmp(token
, "__get_dynamic_array_len") == 0) {
3030 return process_dynamic_array_len(event
, arg
, tok
);
3033 func
= find_func_handler(event
->pevent
, token
);
3036 return process_func_handler(event
, func
, arg
, tok
);
3039 do_warning_event(event
, "function %s not defined", token
);
3044 static enum event_type
3045 process_arg_token(struct event_format
*event
, struct print_arg
*arg
,
3046 char **tok
, enum event_type type
)
3055 if (strcmp(token
, "REC") == 0) {
3057 type
= process_entry(event
, arg
, &token
);
3061 /* test the next token */
3062 type
= read_token_item(&token
);
3065 * If the next token is a parenthesis, then this
3068 if (type
== EVENT_DELIM
&& strcmp(token
, "(") == 0) {
3071 /* this will free atom. */
3072 type
= process_function(event
, arg
, atom
, &token
);
3075 /* atoms can be more than one token long */
3076 while (type
== EVENT_ITEM
) {
3078 new_atom
= realloc(atom
,
3079 strlen(atom
) + strlen(token
) + 2);
3088 strcat(atom
, token
);
3090 type
= read_token_item(&token
);
3093 arg
->type
= PRINT_ATOM
;
3094 arg
->atom
.atom
= atom
;
3099 arg
->type
= PRINT_ATOM
;
3100 arg
->atom
.atom
= token
;
3101 type
= read_token_item(&token
);
3104 if (strcmp(token
, "(") == 0) {
3106 type
= process_paren(event
, arg
, &token
);
3110 /* handle single ops */
3111 arg
->type
= PRINT_OP
;
3113 arg
->op
.left
= NULL
;
3114 type
= process_op(event
, arg
, &token
);
3116 /* On error, the op is freed */
3117 if (type
== EVENT_ERROR
)
3120 /* return error type if errored */
3123 case EVENT_ERROR
... EVENT_NEWLINE
:
3125 do_warning_event(event
, "unexpected type %d", type
);
3133 static int event_read_print_args(struct event_format
*event
, struct print_arg
**list
)
3135 enum event_type type
= EVENT_ERROR
;
3136 struct print_arg
*arg
;
3141 if (type
== EVENT_NEWLINE
) {
3142 type
= read_token_item(&token
);
3148 do_warning_event(event
, "%s: not enough memory!",
3153 type
= process_arg(event
, arg
, &token
);
3155 if (type
== EVENT_ERROR
) {
3164 if (type
== EVENT_OP
) {
3165 type
= process_op(event
, arg
, &token
);
3167 if (type
== EVENT_ERROR
) {
3176 if (type
== EVENT_DELIM
&& strcmp(token
, ",") == 0) {
3183 } while (type
!= EVENT_NONE
);
3185 if (type
!= EVENT_NONE
&& type
!= EVENT_ERROR
)
3191 static int event_read_print(struct event_format
*event
)
3193 enum event_type type
;
3197 if (read_expected_item(EVENT_ITEM
, "print") < 0)
3200 if (read_expected(EVENT_ITEM
, "fmt") < 0)
3203 if (read_expected(EVENT_OP
, ":") < 0)
3206 if (read_expect_type(EVENT_DQUOTE
, &token
) < 0)
3210 event
->print_fmt
.format
= token
;
3211 event
->print_fmt
.args
= NULL
;
3213 /* ok to have no arg */
3214 type
= read_token_item(&token
);
3216 if (type
== EVENT_NONE
)
3219 /* Handle concatenation of print lines */
3220 if (type
== EVENT_DQUOTE
) {
3223 if (asprintf(&cat
, "%s%s", event
->print_fmt
.format
, token
) < 0)
3226 free_token(event
->print_fmt
.format
);
3227 event
->print_fmt
.format
= NULL
;
3232 if (test_type_token(type
, token
, EVENT_DELIM
, ","))
3237 ret
= event_read_print_args(event
, &event
->print_fmt
.args
);
3249 * pevent_find_common_field - return a common field by event
3250 * @event: handle for the event
3251 * @name: the name of the common field to return
3253 * Returns a common field from the event by the given @name.
3254 * This only searchs the common fields and not all field.
3256 struct format_field
*
3257 pevent_find_common_field(struct event_format
*event
, const char *name
)
3259 struct format_field
*format
;
3261 for (format
= event
->format
.common_fields
;
3262 format
; format
= format
->next
) {
3263 if (strcmp(format
->name
, name
) == 0)
3271 * pevent_find_field - find a non-common field
3272 * @event: handle for the event
3273 * @name: the name of the non-common field
3275 * Returns a non-common field by the given @name.
3276 * This does not search common fields.
3278 struct format_field
*
3279 pevent_find_field(struct event_format
*event
, const char *name
)
3281 struct format_field
*format
;
3283 for (format
= event
->format
.fields
;
3284 format
; format
= format
->next
) {
3285 if (strcmp(format
->name
, name
) == 0)
3293 * pevent_find_any_field - find any field by name
3294 * @event: handle for the event
3295 * @name: the name of the field
3297 * Returns a field by the given @name.
3298 * This searchs the common field names first, then
3299 * the non-common ones if a common one was not found.
3301 struct format_field
*
3302 pevent_find_any_field(struct event_format
*event
, const char *name
)
3304 struct format_field
*format
;
3306 format
= pevent_find_common_field(event
, name
);
3309 return pevent_find_field(event
, name
);
3313 * pevent_read_number - read a number from data
3314 * @pevent: handle for the pevent
3315 * @ptr: the raw data
3316 * @size: the size of the data that holds the number
3318 * Returns the number (converted to host) from the
3321 unsigned long long pevent_read_number(struct pevent
*pevent
,
3322 const void *ptr
, int size
)
3326 return *(unsigned char *)ptr
;
3328 return data2host2(pevent
, ptr
);
3330 return data2host4(pevent
, ptr
);
3332 return data2host8(pevent
, ptr
);
3340 * pevent_read_number_field - read a number from data
3341 * @field: a handle to the field
3342 * @data: the raw data to read
3343 * @value: the value to place the number in
3345 * Reads raw data according to a field offset and size,
3346 * and translates it into @value.
3348 * Returns 0 on success, -1 otherwise.
3350 int pevent_read_number_field(struct format_field
*field
, const void *data
,
3351 unsigned long long *value
)
3355 switch (field
->size
) {
3360 *value
= pevent_read_number(field
->event
->pevent
,
3361 data
+ field
->offset
, field
->size
);
3368 static int get_common_info(struct pevent
*pevent
,
3369 const char *type
, int *offset
, int *size
)
3371 struct event_format
*event
;
3372 struct format_field
*field
;
3375 * All events should have the same common elements.
3376 * Pick any event to find where the type is;
3378 if (!pevent
->events
) {
3379 do_warning("no event_list!");
3383 event
= pevent
->events
[0];
3384 field
= pevent_find_common_field(event
, type
);
3388 *offset
= field
->offset
;
3389 *size
= field
->size
;
3394 static int __parse_common(struct pevent
*pevent
, void *data
,
3395 int *size
, int *offset
, const char *name
)
3400 ret
= get_common_info(pevent
, name
, offset
, size
);
3404 return pevent_read_number(pevent
, data
+ *offset
, *size
);
3407 static int trace_parse_common_type(struct pevent
*pevent
, void *data
)
3409 return __parse_common(pevent
, data
,
3410 &pevent
->type_size
, &pevent
->type_offset
,
3414 static int parse_common_pid(struct pevent
*pevent
, void *data
)
3416 return __parse_common(pevent
, data
,
3417 &pevent
->pid_size
, &pevent
->pid_offset
,
3421 static int parse_common_pc(struct pevent
*pevent
, void *data
)
3423 return __parse_common(pevent
, data
,
3424 &pevent
->pc_size
, &pevent
->pc_offset
,
3425 "common_preempt_count");
3428 static int parse_common_flags(struct pevent
*pevent
, void *data
)
3430 return __parse_common(pevent
, data
,
3431 &pevent
->flags_size
, &pevent
->flags_offset
,
3435 static int parse_common_lock_depth(struct pevent
*pevent
, void *data
)
3437 return __parse_common(pevent
, data
,
3438 &pevent
->ld_size
, &pevent
->ld_offset
,
3439 "common_lock_depth");
3442 static int parse_common_migrate_disable(struct pevent
*pevent
, void *data
)
3444 return __parse_common(pevent
, data
,
3445 &pevent
->ld_size
, &pevent
->ld_offset
,
3446 "common_migrate_disable");
3449 static int events_id_cmp(const void *a
, const void *b
);
3452 * pevent_find_event - find an event by given id
3453 * @pevent: a handle to the pevent
3454 * @id: the id of the event
3456 * Returns an event that has a given @id.
3458 struct event_format
*pevent_find_event(struct pevent
*pevent
, int id
)
3460 struct event_format
**eventptr
;
3461 struct event_format key
;
3462 struct event_format
*pkey
= &key
;
3464 /* Check cache first */
3465 if (pevent
->last_event
&& pevent
->last_event
->id
== id
)
3466 return pevent
->last_event
;
3470 eventptr
= bsearch(&pkey
, pevent
->events
, pevent
->nr_events
,
3471 sizeof(*pevent
->events
), events_id_cmp
);
3474 pevent
->last_event
= *eventptr
;
3482 * pevent_find_event_by_name - find an event by given name
3483 * @pevent: a handle to the pevent
3484 * @sys: the system name to search for
3485 * @name: the name of the event to search for
3487 * This returns an event with a given @name and under the system
3488 * @sys. If @sys is NULL the first event with @name is returned.
3490 struct event_format
*
3491 pevent_find_event_by_name(struct pevent
*pevent
,
3492 const char *sys
, const char *name
)
3494 struct event_format
*event
;
3497 if (pevent
->last_event
&&
3498 strcmp(pevent
->last_event
->name
, name
) == 0 &&
3499 (!sys
|| strcmp(pevent
->last_event
->system
, sys
) == 0))
3500 return pevent
->last_event
;
3502 for (i
= 0; i
< pevent
->nr_events
; i
++) {
3503 event
= pevent
->events
[i
];
3504 if (strcmp(event
->name
, name
) == 0) {
3507 if (strcmp(event
->system
, sys
) == 0)
3511 if (i
== pevent
->nr_events
)
3514 pevent
->last_event
= event
;
3518 static unsigned long long
3519 eval_num_arg(void *data
, int size
, struct event_format
*event
, struct print_arg
*arg
)
3521 struct pevent
*pevent
= event
->pevent
;
3522 unsigned long long val
= 0;
3523 unsigned long long left
, right
;
3524 struct print_arg
*typearg
= NULL
;
3525 struct print_arg
*larg
;
3526 unsigned long offset
;
3527 unsigned int field_size
;
3529 switch (arg
->type
) {
3534 return strtoull(arg
->atom
.atom
, NULL
, 0);
3536 if (!arg
->field
.field
) {
3537 arg
->field
.field
= pevent_find_any_field(event
, arg
->field
.name
);
3538 if (!arg
->field
.field
)
3539 goto out_warning_field
;
3542 /* must be a number */
3543 val
= pevent_read_number(pevent
, data
+ arg
->field
.field
->offset
,
3544 arg
->field
.field
->size
);
3548 case PRINT_INT_ARRAY
:
3552 val
= eval_num_arg(data
, size
, event
, arg
->typecast
.item
);
3553 return eval_type(val
, arg
, 0);
3561 val
= process_defined_func(&s
, data
, size
, event
, arg
);
3562 trace_seq_destroy(&s
);
3566 if (strcmp(arg
->op
.op
, "[") == 0) {
3568 * Arrays are special, since we don't want
3569 * to read the arg as is.
3571 right
= eval_num_arg(data
, size
, event
, arg
->op
.right
);
3573 /* handle typecasts */
3574 larg
= arg
->op
.left
;
3575 while (larg
->type
== PRINT_TYPE
) {
3578 larg
= larg
->typecast
.item
;
3581 /* Default to long size */
3582 field_size
= pevent
->long_size
;
3584 switch (larg
->type
) {
3585 case PRINT_DYNAMIC_ARRAY
:
3586 offset
= pevent_read_number(pevent
,
3587 data
+ larg
->dynarray
.field
->offset
,
3588 larg
->dynarray
.field
->size
);
3589 if (larg
->dynarray
.field
->elementsize
)
3590 field_size
= larg
->dynarray
.field
->elementsize
;
3592 * The actual length of the dynamic array is stored
3593 * in the top half of the field, and the offset
3594 * is in the bottom half of the 32 bit field.
3600 if (!larg
->field
.field
) {
3602 pevent_find_any_field(event
, larg
->field
.name
);
3603 if (!larg
->field
.field
) {
3605 goto out_warning_field
;
3608 field_size
= larg
->field
.field
->elementsize
;
3609 offset
= larg
->field
.field
->offset
+
3610 right
* larg
->field
.field
->elementsize
;
3613 goto default_op
; /* oops, all bets off */
3615 val
= pevent_read_number(pevent
,
3616 data
+ offset
, field_size
);
3618 val
= eval_type(val
, typearg
, 1);
3620 } else if (strcmp(arg
->op
.op
, "?") == 0) {
3621 left
= eval_num_arg(data
, size
, event
, arg
->op
.left
);
3622 arg
= arg
->op
.right
;
3624 val
= eval_num_arg(data
, size
, event
, arg
->op
.left
);
3626 val
= eval_num_arg(data
, size
, event
, arg
->op
.right
);
3630 left
= eval_num_arg(data
, size
, event
, arg
->op
.left
);
3631 right
= eval_num_arg(data
, size
, event
, arg
->op
.right
);
3632 switch (arg
->op
.op
[0]) {
3634 switch (arg
->op
.op
[1]) {
3639 val
= left
!= right
;
3642 goto out_warning_op
;
3650 val
= left
|| right
;
3656 val
= left
&& right
;
3661 switch (arg
->op
.op
[1]) {
3666 val
= left
<< right
;
3669 val
= left
<= right
;
3672 goto out_warning_op
;
3676 switch (arg
->op
.op
[1]) {
3681 val
= left
>> right
;
3684 val
= left
>= right
;
3687 goto out_warning_op
;
3691 if (arg
->op
.op
[1] != '=')
3692 goto out_warning_op
;
3694 val
= left
== right
;
3712 goto out_warning_op
;
3715 case PRINT_DYNAMIC_ARRAY_LEN
:
3716 offset
= pevent_read_number(pevent
,
3717 data
+ arg
->dynarray
.field
->offset
,
3718 arg
->dynarray
.field
->size
);
3720 * The total allocated length of the dynamic array is
3721 * stored in the top half of the field, and the offset
3722 * is in the bottom half of the 32 bit field.
3724 val
= (unsigned long long)(offset
>> 16);
3726 case PRINT_DYNAMIC_ARRAY
:
3727 /* Without [], we pass the address to the dynamic data */
3728 offset
= pevent_read_number(pevent
,
3729 data
+ arg
->dynarray
.field
->offset
,
3730 arg
->dynarray
.field
->size
);
3732 * The total allocated length of the dynamic array is
3733 * stored in the top half of the field, and the offset
3734 * is in the bottom half of the 32 bit field.
3737 val
= (unsigned long long)((unsigned long)data
+ offset
);
3739 default: /* not sure what to do there */
3745 do_warning_event(event
, "%s: unknown op '%s'", __func__
, arg
->op
.op
);
3749 do_warning_event(event
, "%s: field %s not found",
3750 __func__
, arg
->field
.name
);
3756 unsigned long long value
;
3759 static const struct flag flags
[] = {
3760 { "HI_SOFTIRQ", 0 },
3761 { "TIMER_SOFTIRQ", 1 },
3762 { "NET_TX_SOFTIRQ", 2 },
3763 { "NET_RX_SOFTIRQ", 3 },
3764 { "BLOCK_SOFTIRQ", 4 },
3765 { "IRQ_POLL_SOFTIRQ", 5 },
3766 { "TASKLET_SOFTIRQ", 6 },
3767 { "SCHED_SOFTIRQ", 7 },
3768 { "HRTIMER_SOFTIRQ", 8 },
3769 { "RCU_SOFTIRQ", 9 },
3771 { "HRTIMER_NORESTART", 0 },
3772 { "HRTIMER_RESTART", 1 },
3775 static long long eval_flag(const char *flag
)
3780 * Some flags in the format files do not get converted.
3781 * If the flag is not numeric, see if it is something that
3782 * we already know about.
3784 if (isdigit(flag
[0]))
3785 return strtoull(flag
, NULL
, 0);
3787 for (i
= 0; i
< (int)(sizeof(flags
)/sizeof(flags
[0])); i
++)
3788 if (strcmp(flags
[i
].name
, flag
) == 0)
3789 return flags
[i
].value
;
3794 static void print_str_to_seq(struct trace_seq
*s
, const char *format
,
3795 int len_arg
, const char *str
)
3798 trace_seq_printf(s
, format
, len_arg
, str
);
3800 trace_seq_printf(s
, format
, str
);
3803 static void print_bitmask_to_seq(struct pevent
*pevent
,
3804 struct trace_seq
*s
, const char *format
,
3805 int len_arg
, const void *data
, int size
)
3807 int nr_bits
= size
* 8;
3808 int str_size
= (nr_bits
+ 3) / 4;
3816 * The kernel likes to put in commas every 32 bits, we
3819 str_size
+= (nr_bits
- 1) / 32;
3821 str
= malloc(str_size
+ 1);
3823 do_warning("%s: not enough memory!", __func__
);
3828 /* Start out with -2 for the two chars per byte */
3829 for (i
= str_size
- 2; i
>= 0; i
-= 2) {
3831 * data points to a bit mask of size bytes.
3832 * In the kernel, this is an array of long words, thus
3833 * endianess is very important.
3835 if (pevent
->file_bigendian
)
3836 index
= size
- (len
+ 1);
3840 snprintf(buf
, 3, "%02x", *((unsigned char *)data
+ index
));
3841 memcpy(str
+ i
, buf
, 2);
3843 if (!(len
& 3) && i
> 0) {
3850 trace_seq_printf(s
, format
, len_arg
, str
);
3852 trace_seq_printf(s
, format
, str
);
3857 static void print_str_arg(struct trace_seq
*s
, void *data
, int size
,
3858 struct event_format
*event
, const char *format
,
3859 int len_arg
, struct print_arg
*arg
)
3861 struct pevent
*pevent
= event
->pevent
;
3862 struct print_flag_sym
*flag
;
3863 struct format_field
*field
;
3864 struct printk_map
*printk
;
3865 long long val
, fval
;
3866 unsigned long long addr
;
3872 switch (arg
->type
) {
3877 print_str_to_seq(s
, format
, len_arg
, arg
->atom
.atom
);
3880 field
= arg
->field
.field
;
3882 field
= pevent_find_any_field(event
, arg
->field
.name
);
3884 str
= arg
->field
.name
;
3885 goto out_warning_field
;
3887 arg
->field
.field
= field
;
3889 /* Zero sized fields, mean the rest of the data */
3890 len
= field
->size
? : size
- field
->offset
;
3893 * Some events pass in pointers. If this is not an array
3894 * and the size is the same as long_size, assume that it
3897 if (!(field
->flags
& FIELD_IS_ARRAY
) &&
3898 field
->size
== pevent
->long_size
) {
3900 /* Handle heterogeneous recording and processing
3904 * Traces recorded on 32-bit devices (32-bit
3905 * addressing) and processed on 64-bit devices:
3906 * In this case, only 32 bits should be read.
3909 * Traces recorded on 64 bit devices and processed
3910 * on 32-bit devices:
3911 * In this case, 64 bits must be read.
3913 addr
= (pevent
->long_size
== 8) ?
3914 *(unsigned long long *)(data
+ field
->offset
) :
3915 (unsigned long long)*(unsigned int *)(data
+ field
->offset
);
3917 /* Check if it matches a print format */
3918 printk
= find_printk(pevent
, addr
);
3920 trace_seq_puts(s
, printk
->printk
);
3922 trace_seq_printf(s
, "%llx", addr
);
3925 str
= malloc(len
+ 1);
3927 do_warning_event(event
, "%s: not enough memory!",
3931 memcpy(str
, data
+ field
->offset
, len
);
3933 print_str_to_seq(s
, format
, len_arg
, str
);
3937 val
= eval_num_arg(data
, size
, event
, arg
->flags
.field
);
3939 for (flag
= arg
->flags
.flags
; flag
; flag
= flag
->next
) {
3940 fval
= eval_flag(flag
->value
);
3941 if (!val
&& fval
< 0) {
3942 print_str_to_seq(s
, format
, len_arg
, flag
->str
);
3945 if (fval
> 0 && (val
& fval
) == fval
) {
3946 if (print
&& arg
->flags
.delim
)
3947 trace_seq_puts(s
, arg
->flags
.delim
);
3948 print_str_to_seq(s
, format
, len_arg
, flag
->str
);
3955 val
= eval_num_arg(data
, size
, event
, arg
->symbol
.field
);
3956 for (flag
= arg
->symbol
.symbols
; flag
; flag
= flag
->next
) {
3957 fval
= eval_flag(flag
->value
);
3959 print_str_to_seq(s
, format
, len_arg
, flag
->str
);
3965 if (arg
->hex
.field
->type
== PRINT_DYNAMIC_ARRAY
) {
3966 unsigned long offset
;
3967 offset
= pevent_read_number(pevent
,
3968 data
+ arg
->hex
.field
->dynarray
.field
->offset
,
3969 arg
->hex
.field
->dynarray
.field
->size
);
3970 hex
= data
+ (offset
& 0xffff);
3972 field
= arg
->hex
.field
->field
.field
;
3974 str
= arg
->hex
.field
->field
.name
;
3975 field
= pevent_find_any_field(event
, str
);
3977 goto out_warning_field
;
3978 arg
->hex
.field
->field
.field
= field
;
3980 hex
= data
+ field
->offset
;
3982 len
= eval_num_arg(data
, size
, event
, arg
->hex
.size
);
3983 for (i
= 0; i
< len
; i
++) {
3985 trace_seq_putc(s
, ' ');
3986 trace_seq_printf(s
, "%02x", hex
[i
]);
3990 case PRINT_INT_ARRAY
: {
3994 if (arg
->int_array
.field
->type
== PRINT_DYNAMIC_ARRAY
) {
3995 unsigned long offset
;
3996 struct format_field
*field
=
3997 arg
->int_array
.field
->dynarray
.field
;
3998 offset
= pevent_read_number(pevent
,
3999 data
+ field
->offset
,
4001 num
= data
+ (offset
& 0xffff);
4003 field
= arg
->int_array
.field
->field
.field
;
4005 str
= arg
->int_array
.field
->field
.name
;
4006 field
= pevent_find_any_field(event
, str
);
4008 goto out_warning_field
;
4009 arg
->int_array
.field
->field
.field
= field
;
4011 num
= data
+ field
->offset
;
4013 len
= eval_num_arg(data
, size
, event
, arg
->int_array
.count
);
4014 el_size
= eval_num_arg(data
, size
, event
,
4015 arg
->int_array
.el_size
);
4016 for (i
= 0; i
< len
; i
++) {
4018 trace_seq_putc(s
, ' ');
4021 trace_seq_printf(s
, "%u", *(uint8_t *)num
);
4022 } else if (el_size
== 2) {
4023 trace_seq_printf(s
, "%u", *(uint16_t *)num
);
4024 } else if (el_size
== 4) {
4025 trace_seq_printf(s
, "%u", *(uint32_t *)num
);
4026 } else if (el_size
== 8) {
4027 trace_seq_printf(s
, "%"PRIu64
, *(uint64_t *)num
);
4029 trace_seq_printf(s
, "BAD SIZE:%d 0x%x",
4030 el_size
, *(uint8_t *)num
);
4040 case PRINT_STRING
: {
4043 if (arg
->string
.offset
== -1) {
4044 struct format_field
*f
;
4046 f
= pevent_find_any_field(event
, arg
->string
.string
);
4047 arg
->string
.offset
= f
->offset
;
4049 str_offset
= data2host4(pevent
, data
+ arg
->string
.offset
);
4050 str_offset
&= 0xffff;
4051 print_str_to_seq(s
, format
, len_arg
, ((char *)data
) + str_offset
);
4055 print_str_to_seq(s
, format
, len_arg
, arg
->string
.string
);
4057 case PRINT_BITMASK
: {
4061 if (arg
->bitmask
.offset
== -1) {
4062 struct format_field
*f
;
4064 f
= pevent_find_any_field(event
, arg
->bitmask
.bitmask
);
4065 arg
->bitmask
.offset
= f
->offset
;
4067 bitmask_offset
= data2host4(pevent
, data
+ arg
->bitmask
.offset
);
4068 bitmask_size
= bitmask_offset
>> 16;
4069 bitmask_offset
&= 0xffff;
4070 print_bitmask_to_seq(pevent
, s
, format
, len_arg
,
4071 data
+ bitmask_offset
, bitmask_size
);
4076 * The only op for string should be ? :
4078 if (arg
->op
.op
[0] != '?')
4080 val
= eval_num_arg(data
, size
, event
, arg
->op
.left
);
4082 print_str_arg(s
, data
, size
, event
,
4083 format
, len_arg
, arg
->op
.right
->op
.left
);
4085 print_str_arg(s
, data
, size
, event
,
4086 format
, len_arg
, arg
->op
.right
->op
.right
);
4089 process_defined_func(s
, data
, size
, event
, arg
);
4099 do_warning_event(event
, "%s: field %s not found",
4100 __func__
, arg
->field
.name
);
4103 static unsigned long long
4104 process_defined_func(struct trace_seq
*s
, void *data
, int size
,
4105 struct event_format
*event
, struct print_arg
*arg
)
4107 struct pevent_function_handler
*func_handle
= arg
->func
.func
;
4108 struct pevent_func_params
*param
;
4109 unsigned long long *args
;
4110 unsigned long long ret
;
4111 struct print_arg
*farg
;
4112 struct trace_seq str
;
4114 struct save_str
*next
;
4116 } *strings
= NULL
, *string
;
4119 if (!func_handle
->nr_args
) {
4120 ret
= (*func_handle
->func
)(s
, NULL
);
4124 farg
= arg
->func
.args
;
4125 param
= func_handle
->params
;
4128 args
= malloc(sizeof(*args
) * func_handle
->nr_args
);
4132 for (i
= 0; i
< func_handle
->nr_args
; i
++) {
4133 switch (param
->type
) {
4134 case PEVENT_FUNC_ARG_INT
:
4135 case PEVENT_FUNC_ARG_LONG
:
4136 case PEVENT_FUNC_ARG_PTR
:
4137 args
[i
] = eval_num_arg(data
, size
, event
, farg
);
4139 case PEVENT_FUNC_ARG_STRING
:
4140 trace_seq_init(&str
);
4141 print_str_arg(&str
, data
, size
, event
, "%s", -1, farg
);
4142 trace_seq_terminate(&str
);
4143 string
= malloc(sizeof(*string
));
4145 do_warning_event(event
, "%s(%d): malloc str",
4146 __func__
, __LINE__
);
4149 string
->next
= strings
;
4150 string
->str
= strdup(str
.buffer
);
4153 do_warning_event(event
, "%s(%d): malloc str",
4154 __func__
, __LINE__
);
4157 args
[i
] = (uintptr_t)string
->str
;
4159 trace_seq_destroy(&str
);
4163 * Something went totally wrong, this is not
4164 * an input error, something in this code broke.
4166 do_warning_event(event
, "Unexpected end of arguments\n");
4170 param
= param
->next
;
4173 ret
= (*func_handle
->func
)(s
, args
);
4178 strings
= string
->next
;
4184 /* TBD : handle return type here */
4188 static void free_args(struct print_arg
*args
)
4190 struct print_arg
*next
;
4200 static struct print_arg
*make_bprint_args(char *fmt
, void *data
, int size
, struct event_format
*event
)
4202 struct pevent
*pevent
= event
->pevent
;
4203 struct format_field
*field
, *ip_field
;
4204 struct print_arg
*args
, *arg
, **next
;
4205 unsigned long long ip
, val
;
4210 field
= pevent
->bprint_buf_field
;
4211 ip_field
= pevent
->bprint_ip_field
;
4214 field
= pevent_find_field(event
, "buf");
4216 do_warning_event(event
, "can't find buffer field for binary printk");
4219 ip_field
= pevent_find_field(event
, "ip");
4221 do_warning_event(event
, "can't find ip field for binary printk");
4224 pevent
->bprint_buf_field
= field
;
4225 pevent
->bprint_ip_field
= ip_field
;
4228 ip
= pevent_read_number(pevent
, data
+ ip_field
->offset
, ip_field
->size
);
4231 * The first arg is the IP pointer.
4235 do_warning_event(event
, "%s(%d): not enough memory!",
4236 __func__
, __LINE__
);
4243 arg
->type
= PRINT_ATOM
;
4245 if (asprintf(&arg
->atom
.atom
, "%lld", ip
) < 0)
4248 /* skip the first "%ps: " */
4249 for (ptr
= fmt
+ 5, bptr
= data
+ field
->offset
;
4250 bptr
< data
+ size
&& *ptr
; ptr
++) {
4285 vsize
= pevent
->long_size
;
4299 /* the pointers are always 4 bytes aligned */
4300 bptr
= (void *)(((unsigned long)bptr
+ 3) &
4302 val
= pevent_read_number(pevent
, bptr
, vsize
);
4306 do_warning_event(event
, "%s(%d): not enough memory!",
4307 __func__
, __LINE__
);
4311 arg
->type
= PRINT_ATOM
;
4312 if (asprintf(&arg
->atom
.atom
, "%lld", val
) < 0) {
4319 * The '*' case means that an arg is used as the length.
4320 * We need to continue to figure out for what.
4329 do_warning_event(event
, "%s(%d): not enough memory!",
4330 __func__
, __LINE__
);
4334 arg
->type
= PRINT_BSTRING
;
4335 arg
->string
.string
= strdup(bptr
);
4336 if (!arg
->string
.string
)
4338 bptr
+= strlen(bptr
) + 1;
4355 get_bprint_format(void *data
, int size __maybe_unused
,
4356 struct event_format
*event
)
4358 struct pevent
*pevent
= event
->pevent
;
4359 unsigned long long addr
;
4360 struct format_field
*field
;
4361 struct printk_map
*printk
;
4364 field
= pevent
->bprint_fmt_field
;
4367 field
= pevent_find_field(event
, "fmt");
4369 do_warning_event(event
, "can't find format field for binary printk");
4372 pevent
->bprint_fmt_field
= field
;
4375 addr
= pevent_read_number(pevent
, data
+ field
->offset
, field
->size
);
4377 printk
= find_printk(pevent
, addr
);
4379 if (asprintf(&format
, "%%pf: (NO FORMAT FOUND at %llx)\n", addr
) < 0)
4384 if (asprintf(&format
, "%s: %s", "%pf", printk
->printk
) < 0)
4390 static void print_mac_arg(struct trace_seq
*s
, int mac
, void *data
, int size
,
4391 struct event_format
*event
, struct print_arg
*arg
)
4394 const char *fmt
= "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x";
4396 if (arg
->type
== PRINT_FUNC
) {
4397 process_defined_func(s
, data
, size
, event
, arg
);
4401 if (arg
->type
!= PRINT_FIELD
) {
4402 trace_seq_printf(s
, "ARG TYPE NOT FIELD BUT %d",
4408 fmt
= "%.2x%.2x%.2x%.2x%.2x%.2x";
4409 if (!arg
->field
.field
) {
4411 pevent_find_any_field(event
, arg
->field
.name
);
4412 if (!arg
->field
.field
) {
4413 do_warning_event(event
, "%s: field %s not found",
4414 __func__
, arg
->field
.name
);
4418 if (arg
->field
.field
->size
!= 6) {
4419 trace_seq_printf(s
, "INVALIDMAC");
4422 buf
= data
+ arg
->field
.field
->offset
;
4423 trace_seq_printf(s
, fmt
, buf
[0], buf
[1], buf
[2], buf
[3], buf
[4], buf
[5]);
4426 static void print_ip4_addr(struct trace_seq
*s
, char i
, unsigned char *buf
)
4431 fmt
= "%03d.%03d.%03d.%03d";
4433 fmt
= "%d.%d.%d.%d";
4435 trace_seq_printf(s
, fmt
, buf
[0], buf
[1], buf
[2], buf
[3]);
4438 static inline bool ipv6_addr_v4mapped(const struct in6_addr
*a
)
4440 return ((unsigned long)(a
->s6_addr32
[0] | a
->s6_addr32
[1]) |
4441 (unsigned long)(a
->s6_addr32
[2] ^ htonl(0x0000ffff))) == 0UL;
4444 static inline bool ipv6_addr_is_isatap(const struct in6_addr
*addr
)
4446 return (addr
->s6_addr32
[2] | htonl(0x02000000)) == htonl(0x02005EFE);
4449 static void print_ip6c_addr(struct trace_seq
*s
, unsigned char *addr
)
4452 unsigned char zerolength
[8];
4457 bool needcolon
= false;
4459 struct in6_addr in6
;
4461 memcpy(&in6
, addr
, sizeof(struct in6_addr
));
4463 useIPv4
= ipv6_addr_v4mapped(&in6
) || ipv6_addr_is_isatap(&in6
);
4465 memset(zerolength
, 0, sizeof(zerolength
));
4472 /* find position of longest 0 run */
4473 for (i
= 0; i
< range
; i
++) {
4474 for (j
= i
; j
< range
; j
++) {
4475 if (in6
.s6_addr16
[j
] != 0)
4480 for (i
= 0; i
< range
; i
++) {
4481 if (zerolength
[i
] > longest
) {
4482 longest
= zerolength
[i
];
4486 if (longest
== 1) /* don't compress a single 0 */
4490 for (i
= 0; i
< range
; i
++) {
4491 if (i
== colonpos
) {
4492 if (needcolon
|| i
== 0)
4493 trace_seq_printf(s
, ":");
4494 trace_seq_printf(s
, ":");
4500 trace_seq_printf(s
, ":");
4503 /* hex u16 without leading 0s */
4504 word
= ntohs(in6
.s6_addr16
[i
]);
4508 trace_seq_printf(s
, "%x%02x", hi
, lo
);
4510 trace_seq_printf(s
, "%x", lo
);
4517 trace_seq_printf(s
, ":");
4518 print_ip4_addr(s
, 'I', &in6
.s6_addr
[12]);
4524 static void print_ip6_addr(struct trace_seq
*s
, char i
, unsigned char *buf
)
4528 for (j
= 0; j
< 16; j
+= 2) {
4529 trace_seq_printf(s
, "%02x%02x", buf
[j
], buf
[j
+1]);
4530 if (i
== 'I' && j
< 14)
4531 trace_seq_printf(s
, ":");
4536 * %pi4 print an IPv4 address with leading zeros
4537 * %pI4 print an IPv4 address without leading zeros
4538 * %pi6 print an IPv6 address without colons
4539 * %pI6 print an IPv6 address with colons
4540 * %pI6c print an IPv6 address in compressed form with colons
4541 * %pISpc print an IP address based on sockaddr; p adds port.
4543 static int print_ipv4_arg(struct trace_seq
*s
, const char *ptr
, char i
,
4544 void *data
, int size
, struct event_format
*event
,
4545 struct print_arg
*arg
)
4549 if (arg
->type
== PRINT_FUNC
) {
4550 process_defined_func(s
, data
, size
, event
, arg
);
4554 if (arg
->type
!= PRINT_FIELD
) {
4555 trace_seq_printf(s
, "ARG TYPE NOT FIELD BUT %d", arg
->type
);
4559 if (!arg
->field
.field
) {
4561 pevent_find_any_field(event
, arg
->field
.name
);
4562 if (!arg
->field
.field
) {
4563 do_warning("%s: field %s not found",
4564 __func__
, arg
->field
.name
);
4569 buf
= data
+ arg
->field
.field
->offset
;
4571 if (arg
->field
.field
->size
!= 4) {
4572 trace_seq_printf(s
, "INVALIDIPv4");
4575 print_ip4_addr(s
, i
, buf
);
4580 static int print_ipv6_arg(struct trace_seq
*s
, const char *ptr
, char i
,
4581 void *data
, int size
, struct event_format
*event
,
4582 struct print_arg
*arg
)
4589 if (i
== 'I' && *ptr
== 'c') {
4595 if (arg
->type
== PRINT_FUNC
) {
4596 process_defined_func(s
, data
, size
, event
, arg
);
4600 if (arg
->type
!= PRINT_FIELD
) {
4601 trace_seq_printf(s
, "ARG TYPE NOT FIELD BUT %d", arg
->type
);
4605 if (!arg
->field
.field
) {
4607 pevent_find_any_field(event
, arg
->field
.name
);
4608 if (!arg
->field
.field
) {
4609 do_warning("%s: field %s not found",
4610 __func__
, arg
->field
.name
);
4615 buf
= data
+ arg
->field
.field
->offset
;
4617 if (arg
->field
.field
->size
!= 16) {
4618 trace_seq_printf(s
, "INVALIDIPv6");
4623 print_ip6c_addr(s
, buf
);
4625 print_ip6_addr(s
, i
, buf
);
4630 static int print_ipsa_arg(struct trace_seq
*s
, const char *ptr
, char i
,
4631 void *data
, int size
, struct event_format
*event
,
4632 struct print_arg
*arg
)
4634 char have_c
= 0, have_p
= 0;
4636 struct sockaddr_storage
*sa
;
4653 if (arg
->type
== PRINT_FUNC
) {
4654 process_defined_func(s
, data
, size
, event
, arg
);
4658 if (arg
->type
!= PRINT_FIELD
) {
4659 trace_seq_printf(s
, "ARG TYPE NOT FIELD BUT %d", arg
->type
);
4663 if (!arg
->field
.field
) {
4665 pevent_find_any_field(event
, arg
->field
.name
);
4666 if (!arg
->field
.field
) {
4667 do_warning("%s: field %s not found",
4668 __func__
, arg
->field
.name
);
4673 sa
= (struct sockaddr_storage
*) (data
+ arg
->field
.field
->offset
);
4675 if (sa
->ss_family
== AF_INET
) {
4676 struct sockaddr_in
*sa4
= (struct sockaddr_in
*) sa
;
4678 if (arg
->field
.field
->size
< sizeof(struct sockaddr_in
)) {
4679 trace_seq_printf(s
, "INVALIDIPv4");
4683 print_ip4_addr(s
, i
, (unsigned char *) &sa4
->sin_addr
);
4685 trace_seq_printf(s
, ":%d", ntohs(sa4
->sin_port
));
4688 } else if (sa
->ss_family
== AF_INET6
) {
4689 struct sockaddr_in6
*sa6
= (struct sockaddr_in6
*) sa
;
4691 if (arg
->field
.field
->size
< sizeof(struct sockaddr_in6
)) {
4692 trace_seq_printf(s
, "INVALIDIPv6");
4697 trace_seq_printf(s
, "[");
4699 buf
= (unsigned char *) &sa6
->sin6_addr
;
4701 print_ip6c_addr(s
, buf
);
4703 print_ip6_addr(s
, i
, buf
);
4706 trace_seq_printf(s
, "]:%d", ntohs(sa6
->sin6_port
));
4712 static int print_ip_arg(struct trace_seq
*s
, const char *ptr
,
4713 void *data
, int size
, struct event_format
*event
,
4714 struct print_arg
*arg
)
4716 char i
= *ptr
; /* 'i' or 'I' */
4729 rc
+= print_ipv4_arg(s
, ptr
, i
, data
, size
, event
, arg
);
4732 rc
+= print_ipv6_arg(s
, ptr
, i
, data
, size
, event
, arg
);
4735 rc
+= print_ipsa_arg(s
, ptr
, i
, data
, size
, event
, arg
);
4744 static int is_printable_array(char *p
, unsigned int len
)
4748 for (i
= 0; i
< len
&& p
[i
]; i
++)
4749 if (!isprint(p
[i
]) && !isspace(p
[i
]))
4754 void pevent_print_field(struct trace_seq
*s
, void *data
,
4755 struct format_field
*field
)
4757 unsigned long long val
;
4758 unsigned int offset
, len
, i
;
4759 struct pevent
*pevent
= field
->event
->pevent
;
4761 if (field
->flags
& FIELD_IS_ARRAY
) {
4762 offset
= field
->offset
;
4764 if (field
->flags
& FIELD_IS_DYNAMIC
) {
4765 val
= pevent_read_number(pevent
, data
+ offset
, len
);
4770 if (field
->flags
& FIELD_IS_STRING
&&
4771 is_printable_array(data
+ offset
, len
)) {
4772 trace_seq_printf(s
, "%s", (char *)data
+ offset
);
4774 trace_seq_puts(s
, "ARRAY[");
4775 for (i
= 0; i
< len
; i
++) {
4777 trace_seq_puts(s
, ", ");
4778 trace_seq_printf(s
, "%02x",
4779 *((unsigned char *)data
+ offset
+ i
));
4781 trace_seq_putc(s
, ']');
4782 field
->flags
&= ~FIELD_IS_STRING
;
4785 val
= pevent_read_number(pevent
, data
+ field
->offset
,
4787 if (field
->flags
& FIELD_IS_POINTER
) {
4788 trace_seq_printf(s
, "0x%llx", val
);
4789 } else if (field
->flags
& FIELD_IS_SIGNED
) {
4790 switch (field
->size
) {
4793 * If field is long then print it in hex.
4794 * A long usually stores pointers.
4796 if (field
->flags
& FIELD_IS_LONG
)
4797 trace_seq_printf(s
, "0x%x", (int)val
);
4799 trace_seq_printf(s
, "%d", (int)val
);
4802 trace_seq_printf(s
, "%2d", (short)val
);
4805 trace_seq_printf(s
, "%1d", (char)val
);
4808 trace_seq_printf(s
, "%lld", val
);
4811 if (field
->flags
& FIELD_IS_LONG
)
4812 trace_seq_printf(s
, "0x%llx", val
);
4814 trace_seq_printf(s
, "%llu", val
);
4819 void pevent_print_fields(struct trace_seq
*s
, void *data
,
4820 int size __maybe_unused
, struct event_format
*event
)
4822 struct format_field
*field
;
4824 field
= event
->format
.fields
;
4826 trace_seq_printf(s
, " %s=", field
->name
);
4827 pevent_print_field(s
, data
, field
);
4828 field
= field
->next
;
4832 static void pretty_print(struct trace_seq
*s
, void *data
, int size
, struct event_format
*event
)
4834 struct pevent
*pevent
= event
->pevent
;
4835 struct print_fmt
*print_fmt
= &event
->print_fmt
;
4836 struct print_arg
*arg
= print_fmt
->args
;
4837 struct print_arg
*args
= NULL
;
4838 const char *ptr
= print_fmt
->format
;
4839 unsigned long long val
;
4840 struct func_map
*func
;
4841 const char *saveptr
;
4843 char *bprint_fmt
= NULL
;
4851 if (event
->flags
& EVENT_FL_FAILED
) {
4852 trace_seq_printf(s
, "[FAILED TO PARSE]");
4853 pevent_print_fields(s
, data
, size
, event
);
4857 if (event
->flags
& EVENT_FL_ISBPRINT
) {
4858 bprint_fmt
= get_bprint_format(data
, size
, event
);
4859 args
= make_bprint_args(bprint_fmt
, data
, size
, event
);
4864 for (; *ptr
; ptr
++) {
4870 trace_seq_putc(s
, '\n');
4873 trace_seq_putc(s
, '\t');
4876 trace_seq_putc(s
, '\r');
4879 trace_seq_putc(s
, '\\');
4882 trace_seq_putc(s
, *ptr
);
4886 } else if (*ptr
== '%') {
4894 trace_seq_putc(s
, '%');
4897 /* FIXME: need to handle properly */
4909 /* The argument is the length. */
4911 do_warning_event(event
, "no argument match");
4912 event
->flags
|= EVENT_FL_FAILED
;
4915 len_arg
= eval_num_arg(data
, size
, event
, arg
);
4926 if (pevent
->long_size
== 4)
4931 if (*(ptr
+1) == 'F' || *(ptr
+1) == 'f' ||
4932 *(ptr
+1) == 'S' || *(ptr
+1) == 's') {
4935 } else if (*(ptr
+1) == 'M' || *(ptr
+1) == 'm') {
4936 print_mac_arg(s
, *(ptr
+1), data
, size
, event
, arg
);
4940 } else if (*(ptr
+1) == 'I' || *(ptr
+1) == 'i') {
4943 n
= print_ip_arg(s
, ptr
+1, data
, size
, event
, arg
);
4958 do_warning_event(event
, "no argument match");
4959 event
->flags
|= EVENT_FL_FAILED
;
4963 len
= ((unsigned long)ptr
+ 1) -
4964 (unsigned long)saveptr
;
4966 /* should never happen */
4968 do_warning_event(event
, "bad format!");
4969 event
->flags
|= EVENT_FL_FAILED
;
4973 memcpy(format
, saveptr
, len
);
4976 val
= eval_num_arg(data
, size
, event
, arg
);
4980 func
= find_func(pevent
, val
);
4982 trace_seq_puts(s
, func
->func
);
4983 if (show_func
== 'F')
4990 if (pevent
->long_size
== 8 && ls
== 1 &&
4991 sizeof(long) != 8) {
4994 /* make %l into %ll */
4995 if (ls
== 1 && (p
= strchr(format
, 'l')))
4996 memmove(p
+1, p
, strlen(p
)+1);
4997 else if (strcmp(format
, "%p") == 0)
4998 strcpy(format
, "0x%llx");
5004 trace_seq_printf(s
, format
, len_arg
, (char)val
);
5006 trace_seq_printf(s
, format
, (char)val
);
5010 trace_seq_printf(s
, format
, len_arg
, (short)val
);
5012 trace_seq_printf(s
, format
, (short)val
);
5016 trace_seq_printf(s
, format
, len_arg
, (int)val
);
5018 trace_seq_printf(s
, format
, (int)val
);
5022 trace_seq_printf(s
, format
, len_arg
, (long)val
);
5024 trace_seq_printf(s
, format
, (long)val
);
5028 trace_seq_printf(s
, format
, len_arg
,
5031 trace_seq_printf(s
, format
, (long long)val
);
5034 do_warning_event(event
, "bad count (%d)", ls
);
5035 event
->flags
|= EVENT_FL_FAILED
;
5040 do_warning_event(event
, "no matching argument");
5041 event
->flags
|= EVENT_FL_FAILED
;
5045 len
= ((unsigned long)ptr
+ 1) -
5046 (unsigned long)saveptr
;
5048 /* should never happen */
5050 do_warning_event(event
, "bad format!");
5051 event
->flags
|= EVENT_FL_FAILED
;
5055 memcpy(format
, saveptr
, len
);
5059 /* Use helper trace_seq */
5061 print_str_arg(&p
, data
, size
, event
,
5062 format
, len_arg
, arg
);
5063 trace_seq_terminate(&p
);
5064 trace_seq_puts(s
, p
.buffer
);
5065 trace_seq_destroy(&p
);
5069 trace_seq_printf(s
, ">%c<", *ptr
);
5073 trace_seq_putc(s
, *ptr
);
5076 if (event
->flags
& EVENT_FL_FAILED
) {
5078 trace_seq_printf(s
, "[FAILED TO PARSE]");
5088 * pevent_data_lat_fmt - parse the data for the latency format
5089 * @pevent: a handle to the pevent
5090 * @s: the trace_seq to write to
5091 * @record: the record to read from
5093 * This parses out the Latency format (interrupts disabled,
5094 * need rescheduling, in hard/soft interrupt, preempt count
5095 * and lock depth) and places it into the trace_seq.
5097 void pevent_data_lat_fmt(struct pevent
*pevent
,
5098 struct trace_seq
*s
, struct pevent_record
*record
)
5100 static int check_lock_depth
= 1;
5101 static int check_migrate_disable
= 1;
5102 static int lock_depth_exists
;
5103 static int migrate_disable_exists
;
5104 unsigned int lat_flags
;
5107 int migrate_disable
;
5110 void *data
= record
->data
;
5112 lat_flags
= parse_common_flags(pevent
, data
);
5113 pc
= parse_common_pc(pevent
, data
);
5114 /* lock_depth may not always exist */
5115 if (lock_depth_exists
)
5116 lock_depth
= parse_common_lock_depth(pevent
, data
);
5117 else if (check_lock_depth
) {
5118 lock_depth
= parse_common_lock_depth(pevent
, data
);
5120 check_lock_depth
= 0;
5122 lock_depth_exists
= 1;
5125 /* migrate_disable may not always exist */
5126 if (migrate_disable_exists
)
5127 migrate_disable
= parse_common_migrate_disable(pevent
, data
);
5128 else if (check_migrate_disable
) {
5129 migrate_disable
= parse_common_migrate_disable(pevent
, data
);
5130 if (migrate_disable
< 0)
5131 check_migrate_disable
= 0;
5133 migrate_disable_exists
= 1;
5136 hardirq
= lat_flags
& TRACE_FLAG_HARDIRQ
;
5137 softirq
= lat_flags
& TRACE_FLAG_SOFTIRQ
;
5139 trace_seq_printf(s
, "%c%c%c",
5140 (lat_flags
& TRACE_FLAG_IRQS_OFF
) ? 'd' :
5141 (lat_flags
& TRACE_FLAG_IRQS_NOSUPPORT
) ?
5143 (lat_flags
& TRACE_FLAG_NEED_RESCHED
) ?
5145 (hardirq
&& softirq
) ? 'H' :
5146 hardirq
? 'h' : softirq
? 's' : '.');
5149 trace_seq_printf(s
, "%x", pc
);
5151 trace_seq_putc(s
, '.');
5153 if (migrate_disable_exists
) {
5154 if (migrate_disable
< 0)
5155 trace_seq_putc(s
, '.');
5157 trace_seq_printf(s
, "%d", migrate_disable
);
5160 if (lock_depth_exists
) {
5162 trace_seq_putc(s
, '.');
5164 trace_seq_printf(s
, "%d", lock_depth
);
5167 trace_seq_terminate(s
);
5171 * pevent_data_type - parse out the given event type
5172 * @pevent: a handle to the pevent
5173 * @rec: the record to read from
5175 * This returns the event id from the @rec.
5177 int pevent_data_type(struct pevent
*pevent
, struct pevent_record
*rec
)
5179 return trace_parse_common_type(pevent
, rec
->data
);
5183 * pevent_data_event_from_type - find the event by a given type
5184 * @pevent: a handle to the pevent
5185 * @type: the type of the event.
5187 * This returns the event form a given @type;
5189 struct event_format
*pevent_data_event_from_type(struct pevent
*pevent
, int type
)
5191 return pevent_find_event(pevent
, type
);
5195 * pevent_data_pid - parse the PID from record
5196 * @pevent: a handle to the pevent
5197 * @rec: the record to parse
5199 * This returns the PID from a record.
5201 int pevent_data_pid(struct pevent
*pevent
, struct pevent_record
*rec
)
5203 return parse_common_pid(pevent
, rec
->data
);
5207 * pevent_data_prempt_count - parse the preempt count from the record
5208 * @pevent: a handle to the pevent
5209 * @rec: the record to parse
5211 * This returns the preempt count from a record.
5213 int pevent_data_prempt_count(struct pevent
*pevent
, struct pevent_record
*rec
)
5215 return parse_common_pc(pevent
, rec
->data
);
5219 * pevent_data_flags - parse the latency flags from the record
5220 * @pevent: a handle to the pevent
5221 * @rec: the record to parse
5223 * This returns the latency flags from a record.
5225 * Use trace_flag_type enum for the flags (see event-parse.h).
5227 int pevent_data_flags(struct pevent
*pevent
, struct pevent_record
*rec
)
5229 return parse_common_flags(pevent
, rec
->data
);
5233 * pevent_data_comm_from_pid - return the command line from PID
5234 * @pevent: a handle to the pevent
5235 * @pid: the PID of the task to search for
5237 * This returns a pointer to the command line that has the given
5240 const char *pevent_data_comm_from_pid(struct pevent
*pevent
, int pid
)
5244 comm
= find_cmdline(pevent
, pid
);
5248 static struct cmdline
*
5249 pid_from_cmdlist(struct pevent
*pevent
, const char *comm
, struct cmdline
*next
)
5251 struct cmdline_list
*cmdlist
= (struct cmdline_list
*)next
;
5254 cmdlist
= cmdlist
->next
;
5256 cmdlist
= pevent
->cmdlist
;
5258 while (cmdlist
&& strcmp(cmdlist
->comm
, comm
) != 0)
5259 cmdlist
= cmdlist
->next
;
5261 return (struct cmdline
*)cmdlist
;
5265 * pevent_data_pid_from_comm - return the pid from a given comm
5266 * @pevent: a handle to the pevent
5267 * @comm: the cmdline to find the pid from
5268 * @next: the cmdline structure to find the next comm
5270 * This returns the cmdline structure that holds a pid for a given
5271 * comm, or NULL if none found. As there may be more than one pid for
5272 * a given comm, the result of this call can be passed back into
5273 * a recurring call in the @next paramater, and then it will find the
5275 * Also, it does a linear seach, so it may be slow.
5277 struct cmdline
*pevent_data_pid_from_comm(struct pevent
*pevent
, const char *comm
,
5278 struct cmdline
*next
)
5280 struct cmdline
*cmdline
;
5283 * If the cmdlines have not been converted yet, then use
5286 if (!pevent
->cmdlines
)
5287 return pid_from_cmdlist(pevent
, comm
, next
);
5291 * The next pointer could have been still from
5292 * a previous call before cmdlines were created
5294 if (next
< pevent
->cmdlines
||
5295 next
>= pevent
->cmdlines
+ pevent
->cmdline_count
)
5302 cmdline
= pevent
->cmdlines
;
5304 while (cmdline
< pevent
->cmdlines
+ pevent
->cmdline_count
) {
5305 if (strcmp(cmdline
->comm
, comm
) == 0)
5313 * pevent_cmdline_pid - return the pid associated to a given cmdline
5314 * @cmdline: The cmdline structure to get the pid from
5316 * Returns the pid for a give cmdline. If @cmdline is NULL, then
5319 int pevent_cmdline_pid(struct pevent
*pevent
, struct cmdline
*cmdline
)
5321 struct cmdline_list
*cmdlist
= (struct cmdline_list
*)cmdline
;
5327 * If cmdlines have not been created yet, or cmdline is
5328 * not part of the array, then treat it as a cmdlist instead.
5330 if (!pevent
->cmdlines
||
5331 cmdline
< pevent
->cmdlines
||
5332 cmdline
>= pevent
->cmdlines
+ pevent
->cmdline_count
)
5333 return cmdlist
->pid
;
5335 return cmdline
->pid
;
5339 * pevent_data_comm_from_pid - parse the data into the print format
5340 * @s: the trace_seq to write to
5341 * @event: the handle to the event
5342 * @record: the record to read from
5344 * This parses the raw @data using the given @event information and
5345 * writes the print format into the trace_seq.
5347 void pevent_event_info(struct trace_seq
*s
, struct event_format
*event
,
5348 struct pevent_record
*record
)
5350 int print_pretty
= 1;
5352 if (event
->pevent
->print_raw
|| (event
->flags
& EVENT_FL_PRINTRAW
))
5353 pevent_print_fields(s
, record
->data
, record
->size
, event
);
5356 if (event
->handler
&& !(event
->flags
& EVENT_FL_NOHANDLE
))
5357 print_pretty
= event
->handler(s
, record
, event
,
5361 pretty_print(s
, record
->data
, record
->size
, event
);
5364 trace_seq_terminate(s
);
5367 static bool is_timestamp_in_us(char *trace_clock
, bool use_trace_clock
)
5369 if (!use_trace_clock
)
5372 if (!strcmp(trace_clock
, "local") || !strcmp(trace_clock
, "global")
5373 || !strcmp(trace_clock
, "uptime") || !strcmp(trace_clock
, "perf"))
5376 /* trace_clock is setting in tsc or counter mode */
5381 * pevent_find_event_by_record - return the event from a given record
5382 * @pevent: a handle to the pevent
5383 * @record: The record to get the event from
5385 * Returns the associated event for a given record, or NULL if non is
5388 struct event_format
*
5389 pevent_find_event_by_record(struct pevent
*pevent
, struct pevent_record
*record
)
5393 if (record
->size
< 0) {
5394 do_warning("ug! negative record size %d", record
->size
);
5398 type
= trace_parse_common_type(pevent
, record
->data
);
5400 return pevent_find_event(pevent
, type
);
5404 * pevent_print_event_task - Write the event task comm, pid and CPU
5405 * @pevent: a handle to the pevent
5406 * @s: the trace_seq to write to
5407 * @event: the handle to the record's event
5408 * @record: The record to get the event from
5410 * Writes the tasks comm, pid and CPU to @s.
5412 void pevent_print_event_task(struct pevent
*pevent
, struct trace_seq
*s
,
5413 struct event_format
*event
,
5414 struct pevent_record
*record
)
5416 void *data
= record
->data
;
5420 pid
= parse_common_pid(pevent
, data
);
5421 comm
= find_cmdline(pevent
, pid
);
5423 if (pevent
->latency_format
) {
5424 trace_seq_printf(s
, "%8.8s-%-5d %3d",
5425 comm
, pid
, record
->cpu
);
5427 trace_seq_printf(s
, "%16s-%-5d [%03d]", comm
, pid
, record
->cpu
);
5431 * pevent_print_event_time - Write the event timestamp
5432 * @pevent: a handle to the pevent
5433 * @s: the trace_seq to write to
5434 * @event: the handle to the record's event
5435 * @record: The record to get the event from
5436 * @use_trace_clock: Set to parse according to the @pevent->trace_clock
5438 * Writes the timestamp of the record into @s.
5440 void pevent_print_event_time(struct pevent
*pevent
, struct trace_seq
*s
,
5441 struct event_format
*event
,
5442 struct pevent_record
*record
,
5443 bool use_trace_clock
)
5446 unsigned long usecs
;
5447 unsigned long nsecs
;
5449 bool use_usec_format
;
5451 use_usec_format
= is_timestamp_in_us(pevent
->trace_clock
,
5453 if (use_usec_format
) {
5454 secs
= record
->ts
/ NSEC_PER_SEC
;
5455 nsecs
= record
->ts
- secs
* NSEC_PER_SEC
;
5458 if (pevent
->latency_format
) {
5459 pevent_data_lat_fmt(pevent
, s
, record
);
5462 if (use_usec_format
) {
5463 if (pevent
->flags
& PEVENT_NSEC_OUTPUT
) {
5467 usecs
= (nsecs
+ 500) / NSEC_PER_USEC
;
5468 /* To avoid usecs larger than 1 sec */
5469 if (usecs
>= USEC_PER_SEC
) {
5470 usecs
-= USEC_PER_SEC
;
5476 trace_seq_printf(s
, " %5lu.%0*lu:", secs
, p
, usecs
);
5478 trace_seq_printf(s
, " %12llu:", record
->ts
);
5482 * pevent_print_event_data - Write the event data section
5483 * @pevent: a handle to the pevent
5484 * @s: the trace_seq to write to
5485 * @event: the handle to the record's event
5486 * @record: The record to get the event from
5488 * Writes the parsing of the record's data to @s.
5490 void pevent_print_event_data(struct pevent
*pevent
, struct trace_seq
*s
,
5491 struct event_format
*event
,
5492 struct pevent_record
*record
)
5494 static const char *spaces
= " "; /* 20 spaces */
5497 trace_seq_printf(s
, " %s: ", event
->name
);
5499 /* Space out the event names evenly. */
5500 len
= strlen(event
->name
);
5502 trace_seq_printf(s
, "%.*s", 20 - len
, spaces
);
5504 pevent_event_info(s
, event
, record
);
5507 void pevent_print_event(struct pevent
*pevent
, struct trace_seq
*s
,
5508 struct pevent_record
*record
, bool use_trace_clock
)
5510 struct event_format
*event
;
5512 event
= pevent_find_event_by_record(pevent
, record
);
5514 do_warning("ug! no event found for type %d",
5515 trace_parse_common_type(pevent
, record
->data
));
5519 pevent_print_event_task(pevent
, s
, event
, record
);
5520 pevent_print_event_time(pevent
, s
, event
, record
, use_trace_clock
);
5521 pevent_print_event_data(pevent
, s
, event
, record
);
5524 static int events_id_cmp(const void *a
, const void *b
)
5526 struct event_format
* const * ea
= a
;
5527 struct event_format
* const * eb
= b
;
5529 if ((*ea
)->id
< (*eb
)->id
)
5532 if ((*ea
)->id
> (*eb
)->id
)
5538 static int events_name_cmp(const void *a
, const void *b
)
5540 struct event_format
* const * ea
= a
;
5541 struct event_format
* const * eb
= b
;
5544 res
= strcmp((*ea
)->name
, (*eb
)->name
);
5548 res
= strcmp((*ea
)->system
, (*eb
)->system
);
5552 return events_id_cmp(a
, b
);
5555 static int events_system_cmp(const void *a
, const void *b
)
5557 struct event_format
* const * ea
= a
;
5558 struct event_format
* const * eb
= b
;
5561 res
= strcmp((*ea
)->system
, (*eb
)->system
);
5565 res
= strcmp((*ea
)->name
, (*eb
)->name
);
5569 return events_id_cmp(a
, b
);
5572 struct event_format
**pevent_list_events(struct pevent
*pevent
, enum event_sort_type sort_type
)
5574 struct event_format
**events
;
5575 int (*sort
)(const void *a
, const void *b
);
5577 events
= pevent
->sort_events
;
5579 if (events
&& pevent
->last_type
== sort_type
)
5583 events
= malloc(sizeof(*events
) * (pevent
->nr_events
+ 1));
5587 memcpy(events
, pevent
->events
, sizeof(*events
) * pevent
->nr_events
);
5588 events
[pevent
->nr_events
] = NULL
;
5590 pevent
->sort_events
= events
;
5592 /* the internal events are sorted by id */
5593 if (sort_type
== EVENT_SORT_ID
) {
5594 pevent
->last_type
= sort_type
;
5599 switch (sort_type
) {
5601 sort
= events_id_cmp
;
5603 case EVENT_SORT_NAME
:
5604 sort
= events_name_cmp
;
5606 case EVENT_SORT_SYSTEM
:
5607 sort
= events_system_cmp
;
5613 qsort(events
, pevent
->nr_events
, sizeof(*events
), sort
);
5614 pevent
->last_type
= sort_type
;
5619 static struct format_field
**
5620 get_event_fields(const char *type
, const char *name
,
5621 int count
, struct format_field
*list
)
5623 struct format_field
**fields
;
5624 struct format_field
*field
;
5627 fields
= malloc(sizeof(*fields
) * (count
+ 1));
5631 for (field
= list
; field
; field
= field
->next
) {
5632 fields
[i
++] = field
;
5633 if (i
== count
+ 1) {
5634 do_warning("event %s has more %s fields than specified",
5642 do_warning("event %s has less %s fields than specified",
5651 * pevent_event_common_fields - return a list of common fields for an event
5652 * @event: the event to return the common fields of.
5654 * Returns an allocated array of fields. The last item in the array is NULL.
5655 * The array must be freed with free().
5657 struct format_field
**pevent_event_common_fields(struct event_format
*event
)
5659 return get_event_fields("common", event
->name
,
5660 event
->format
.nr_common
,
5661 event
->format
.common_fields
);
5665 * pevent_event_fields - return a list of event specific fields for an event
5666 * @event: the event to return the fields of.
5668 * Returns an allocated array of fields. The last item in the array is NULL.
5669 * The array must be freed with free().
5671 struct format_field
**pevent_event_fields(struct event_format
*event
)
5673 return get_event_fields("event", event
->name
,
5674 event
->format
.nr_fields
,
5675 event
->format
.fields
);
5678 static void print_fields(struct trace_seq
*s
, struct print_flag_sym
*field
)
5680 trace_seq_printf(s
, "{ %s, %s }", field
->value
, field
->str
);
5682 trace_seq_puts(s
, ", ");
5683 print_fields(s
, field
->next
);
5688 static void print_args(struct print_arg
*args
)
5690 int print_paren
= 1;
5693 switch (args
->type
) {
5698 printf("%s", args
->atom
.atom
);
5701 printf("REC->%s", args
->field
.name
);
5704 printf("__print_flags(");
5705 print_args(args
->flags
.field
);
5706 printf(", %s, ", args
->flags
.delim
);
5708 print_fields(&s
, args
->flags
.flags
);
5709 trace_seq_do_printf(&s
);
5710 trace_seq_destroy(&s
);
5714 printf("__print_symbolic(");
5715 print_args(args
->symbol
.field
);
5718 print_fields(&s
, args
->symbol
.symbols
);
5719 trace_seq_do_printf(&s
);
5720 trace_seq_destroy(&s
);
5724 printf("__print_hex(");
5725 print_args(args
->hex
.field
);
5727 print_args(args
->hex
.size
);
5730 case PRINT_INT_ARRAY
:
5731 printf("__print_array(");
5732 print_args(args
->int_array
.field
);
5734 print_args(args
->int_array
.count
);
5736 print_args(args
->int_array
.el_size
);
5741 printf("__get_str(%s)", args
->string
.string
);
5744 printf("__get_bitmask(%s)", args
->bitmask
.bitmask
);
5747 printf("(%s)", args
->typecast
.type
);
5748 print_args(args
->typecast
.item
);
5751 if (strcmp(args
->op
.op
, ":") == 0)
5755 print_args(args
->op
.left
);
5756 printf(" %s ", args
->op
.op
);
5757 print_args(args
->op
.right
);
5762 /* we should warn... */
5767 print_args(args
->next
);
5771 static void parse_header_field(const char *field
,
5772 int *offset
, int *size
, int mandatory
)
5774 unsigned long long save_input_buf_ptr
;
5775 unsigned long long save_input_buf_siz
;
5779 save_input_buf_ptr
= input_buf_ptr
;
5780 save_input_buf_siz
= input_buf_siz
;
5782 if (read_expected(EVENT_ITEM
, "field") < 0)
5784 if (read_expected(EVENT_OP
, ":") < 0)
5788 if (read_expect_type(EVENT_ITEM
, &token
) < 0)
5793 * If this is not a mandatory field, then test it first.
5796 if (read_expected(EVENT_ITEM
, field
) < 0)
5799 if (read_expect_type(EVENT_ITEM
, &token
) < 0)
5801 if (strcmp(token
, field
) != 0)
5806 if (read_expected(EVENT_OP
, ";") < 0)
5808 if (read_expected(EVENT_ITEM
, "offset") < 0)
5810 if (read_expected(EVENT_OP
, ":") < 0)
5812 if (read_expect_type(EVENT_ITEM
, &token
) < 0)
5814 *offset
= atoi(token
);
5816 if (read_expected(EVENT_OP
, ";") < 0)
5818 if (read_expected(EVENT_ITEM
, "size") < 0)
5820 if (read_expected(EVENT_OP
, ":") < 0)
5822 if (read_expect_type(EVENT_ITEM
, &token
) < 0)
5824 *size
= atoi(token
);
5826 if (read_expected(EVENT_OP
, ";") < 0)
5828 type
= read_token(&token
);
5829 if (type
!= EVENT_NEWLINE
) {
5830 /* newer versions of the kernel have a "signed" type */
5831 if (type
!= EVENT_ITEM
)
5834 if (strcmp(token
, "signed") != 0)
5839 if (read_expected(EVENT_OP
, ":") < 0)
5842 if (read_expect_type(EVENT_ITEM
, &token
))
5846 if (read_expected(EVENT_OP
, ";") < 0)
5849 if (read_expect_type(EVENT_NEWLINE
, &token
))
5857 input_buf_ptr
= save_input_buf_ptr
;
5858 input_buf_siz
= save_input_buf_siz
;
5865 * pevent_parse_header_page - parse the data stored in the header page
5866 * @pevent: the handle to the pevent
5867 * @buf: the buffer storing the header page format string
5868 * @size: the size of @buf
5869 * @long_size: the long size to use if there is no header
5871 * This parses the header page format for information on the
5872 * ring buffer used. The @buf should be copied from
5874 * /sys/kernel/debug/tracing/events/header_page
5876 int pevent_parse_header_page(struct pevent
*pevent
, char *buf
, unsigned long size
,
5883 * Old kernels did not have header page info.
5884 * Sorry but we just use what we find here in user space.
5886 pevent
->header_page_ts_size
= sizeof(long long);
5887 pevent
->header_page_size_size
= long_size
;
5888 pevent
->header_page_data_offset
= sizeof(long long) + long_size
;
5889 pevent
->old_format
= 1;
5892 init_input_buf(buf
, size
);
5894 parse_header_field("timestamp", &pevent
->header_page_ts_offset
,
5895 &pevent
->header_page_ts_size
, 1);
5896 parse_header_field("commit", &pevent
->header_page_size_offset
,
5897 &pevent
->header_page_size_size
, 1);
5898 parse_header_field("overwrite", &pevent
->header_page_overwrite
,
5900 parse_header_field("data", &pevent
->header_page_data_offset
,
5901 &pevent
->header_page_data_size
, 1);
5906 static int event_matches(struct event_format
*event
,
5907 int id
, const char *sys_name
,
5908 const char *event_name
)
5910 if (id
>= 0 && id
!= event
->id
)
5913 if (event_name
&& (strcmp(event_name
, event
->name
) != 0))
5916 if (sys_name
&& (strcmp(sys_name
, event
->system
) != 0))
5922 static void free_handler(struct event_handler
*handle
)
5924 free((void *)handle
->sys_name
);
5925 free((void *)handle
->event_name
);
5929 static int find_event_handle(struct pevent
*pevent
, struct event_format
*event
)
5931 struct event_handler
*handle
, **next
;
5933 for (next
= &pevent
->handlers
; *next
;
5934 next
= &(*next
)->next
) {
5936 if (event_matches(event
, handle
->id
,
5938 handle
->event_name
))
5945 pr_stat("overriding event (%d) %s:%s with new print handler",
5946 event
->id
, event
->system
, event
->name
);
5948 event
->handler
= handle
->func
;
5949 event
->context
= handle
->context
;
5951 *next
= handle
->next
;
5952 free_handler(handle
);
5958 * __pevent_parse_format - parse the event format
5959 * @buf: the buffer storing the event format string
5960 * @size: the size of @buf
5961 * @sys: the system the event belongs to
5963 * This parses the event format and creates an event structure
5964 * to quickly parse raw data for a given event.
5966 * These files currently come from:
5968 * /sys/kernel/debug/tracing/events/.../.../format
5970 enum pevent_errno
__pevent_parse_format(struct event_format
**eventp
,
5971 struct pevent
*pevent
, const char *buf
,
5972 unsigned long size
, const char *sys
)
5974 struct event_format
*event
;
5977 init_input_buf(buf
, size
);
5979 *eventp
= event
= alloc_event();
5981 return PEVENT_ERRNO__MEM_ALLOC_FAILED
;
5983 event
->name
= event_read_name();
5986 ret
= PEVENT_ERRNO__MEM_ALLOC_FAILED
;
5987 goto event_alloc_failed
;
5990 if (strcmp(sys
, "ftrace") == 0) {
5991 event
->flags
|= EVENT_FL_ISFTRACE
;
5993 if (strcmp(event
->name
, "bprint") == 0)
5994 event
->flags
|= EVENT_FL_ISBPRINT
;
5997 event
->id
= event_read_id();
5998 if (event
->id
< 0) {
5999 ret
= PEVENT_ERRNO__READ_ID_FAILED
;
6001 * This isn't an allocation error actually.
6002 * But as the ID is critical, just bail out.
6004 goto event_alloc_failed
;
6007 event
->system
= strdup(sys
);
6008 if (!event
->system
) {
6009 ret
= PEVENT_ERRNO__MEM_ALLOC_FAILED
;
6010 goto event_alloc_failed
;
6013 /* Add pevent to event so that it can be referenced */
6014 event
->pevent
= pevent
;
6016 ret
= event_read_format(event
);
6018 ret
= PEVENT_ERRNO__READ_FORMAT_FAILED
;
6019 goto event_parse_failed
;
6023 * If the event has an override, don't print warnings if the event
6024 * print format fails to parse.
6026 if (pevent
&& find_event_handle(pevent
, event
))
6029 ret
= event_read_print(event
);
6033 ret
= PEVENT_ERRNO__READ_PRINT_FAILED
;
6034 goto event_parse_failed
;
6037 if (!ret
&& (event
->flags
& EVENT_FL_ISFTRACE
)) {
6038 struct format_field
*field
;
6039 struct print_arg
*arg
, **list
;
6041 /* old ftrace had no args */
6042 list
= &event
->print_fmt
.args
;
6043 for (field
= event
->format
.fields
; field
; field
= field
->next
) {
6046 event
->flags
|= EVENT_FL_FAILED
;
6047 return PEVENT_ERRNO__OLD_FTRACE_ARG_FAILED
;
6049 arg
->type
= PRINT_FIELD
;
6050 arg
->field
.name
= strdup(field
->name
);
6051 if (!arg
->field
.name
) {
6052 event
->flags
|= EVENT_FL_FAILED
;
6054 return PEVENT_ERRNO__OLD_FTRACE_ARG_FAILED
;
6056 arg
->field
.field
= field
;
6066 event
->flags
|= EVENT_FL_FAILED
;
6070 free(event
->system
);
6077 static enum pevent_errno
6078 __pevent_parse_event(struct pevent
*pevent
,
6079 struct event_format
**eventp
,
6080 const char *buf
, unsigned long size
,
6083 int ret
= __pevent_parse_format(eventp
, pevent
, buf
, size
, sys
);
6084 struct event_format
*event
= *eventp
;
6089 if (pevent
&& add_event(pevent
, event
)) {
6090 ret
= PEVENT_ERRNO__MEM_ALLOC_FAILED
;
6091 goto event_add_failed
;
6094 #define PRINT_ARGS 0
6095 if (PRINT_ARGS
&& event
->print_fmt
.args
)
6096 print_args(event
->print_fmt
.args
);
6101 pevent_free_format(event
);
6106 * pevent_parse_format - parse the event format
6107 * @pevent: the handle to the pevent
6108 * @eventp: returned format
6109 * @buf: the buffer storing the event format string
6110 * @size: the size of @buf
6111 * @sys: the system the event belongs to
6113 * This parses the event format and creates an event structure
6114 * to quickly parse raw data for a given event.
6116 * These files currently come from:
6118 * /sys/kernel/debug/tracing/events/.../.../format
6120 enum pevent_errno
pevent_parse_format(struct pevent
*pevent
,
6121 struct event_format
**eventp
,
6123 unsigned long size
, const char *sys
)
6125 return __pevent_parse_event(pevent
, eventp
, buf
, size
, sys
);
6129 * pevent_parse_event - parse the event format
6130 * @pevent: the handle to the pevent
6131 * @buf: the buffer storing the event format string
6132 * @size: the size of @buf
6133 * @sys: the system the event belongs to
6135 * This parses the event format and creates an event structure
6136 * to quickly parse raw data for a given event.
6138 * These files currently come from:
6140 * /sys/kernel/debug/tracing/events/.../.../format
6142 enum pevent_errno
pevent_parse_event(struct pevent
*pevent
, const char *buf
,
6143 unsigned long size
, const char *sys
)
6145 struct event_format
*event
= NULL
;
6146 return __pevent_parse_event(pevent
, &event
, buf
, size
, sys
);
6150 #define _PE(code, str) str
6151 static const char * const pevent_error_str
[] = {
6156 int pevent_strerror(struct pevent
*pevent __maybe_unused
,
6157 enum pevent_errno errnum
, char *buf
, size_t buflen
)
6163 str_error_r(errnum
, buf
, buflen
);
6167 if (errnum
<= __PEVENT_ERRNO__START
||
6168 errnum
>= __PEVENT_ERRNO__END
)
6171 idx
= errnum
- __PEVENT_ERRNO__START
- 1;
6172 msg
= pevent_error_str
[idx
];
6173 snprintf(buf
, buflen
, "%s", msg
);
6178 int get_field_val(struct trace_seq
*s
, struct format_field
*field
,
6179 const char *name
, struct pevent_record
*record
,
6180 unsigned long long *val
, int err
)
6184 trace_seq_printf(s
, "<CANT FIND FIELD %s>", name
);
6188 if (pevent_read_number_field(field
, record
->data
, val
)) {
6190 trace_seq_printf(s
, " %s=INVALID", name
);
6198 * pevent_get_field_raw - return the raw pointer into the data field
6199 * @s: The seq to print to on error
6200 * @event: the event that the field is for
6201 * @name: The name of the field
6202 * @record: The record with the field name.
6203 * @len: place to store the field length.
6204 * @err: print default error if failed.
6206 * Returns a pointer into record->data of the field and places
6207 * the length of the field in @len.
6209 * On failure, it returns NULL.
6211 void *pevent_get_field_raw(struct trace_seq
*s
, struct event_format
*event
,
6212 const char *name
, struct pevent_record
*record
,
6215 struct format_field
*field
;
6216 void *data
= record
->data
;
6223 field
= pevent_find_field(event
, name
);
6227 trace_seq_printf(s
, "<CANT FIND FIELD %s>", name
);
6231 /* Allow @len to be NULL */
6235 offset
= field
->offset
;
6236 if (field
->flags
& FIELD_IS_DYNAMIC
) {
6237 offset
= pevent_read_number(event
->pevent
,
6238 data
+ offset
, field
->size
);
6239 *len
= offset
>> 16;
6244 return data
+ offset
;
6248 * pevent_get_field_val - find a field and return its value
6249 * @s: The seq to print to on error
6250 * @event: the event that the field is for
6251 * @name: The name of the field
6252 * @record: The record with the field name.
6253 * @val: place to store the value of the field.
6254 * @err: print default error if failed.
6256 * Returns 0 on success -1 on field not found.
6258 int pevent_get_field_val(struct trace_seq
*s
, struct event_format
*event
,
6259 const char *name
, struct pevent_record
*record
,
6260 unsigned long long *val
, int err
)
6262 struct format_field
*field
;
6267 field
= pevent_find_field(event
, name
);
6269 return get_field_val(s
, field
, name
, record
, val
, err
);
6273 * pevent_get_common_field_val - find a common field and return its value
6274 * @s: The seq to print to on error
6275 * @event: the event that the field is for
6276 * @name: The name of the field
6277 * @record: The record with the field name.
6278 * @val: place to store the value of the field.
6279 * @err: print default error if failed.
6281 * Returns 0 on success -1 on field not found.
6283 int pevent_get_common_field_val(struct trace_seq
*s
, struct event_format
*event
,
6284 const char *name
, struct pevent_record
*record
,
6285 unsigned long long *val
, int err
)
6287 struct format_field
*field
;
6292 field
= pevent_find_common_field(event
, name
);
6294 return get_field_val(s
, field
, name
, record
, val
, err
);
6298 * pevent_get_any_field_val - find a any field and return its value
6299 * @s: The seq to print to on error
6300 * @event: the event that the field is for
6301 * @name: The name of the field
6302 * @record: The record with the field name.
6303 * @val: place to store the value of the field.
6304 * @err: print default error if failed.
6306 * Returns 0 on success -1 on field not found.
6308 int pevent_get_any_field_val(struct trace_seq
*s
, struct event_format
*event
,
6309 const char *name
, struct pevent_record
*record
,
6310 unsigned long long *val
, int err
)
6312 struct format_field
*field
;
6317 field
= pevent_find_any_field(event
, name
);
6319 return get_field_val(s
, field
, name
, record
, val
, err
);
6323 * pevent_print_num_field - print a field and a format
6324 * @s: The seq to print to
6325 * @fmt: The printf format to print the field with.
6326 * @event: the event that the field is for
6327 * @name: The name of the field
6328 * @record: The record with the field name.
6329 * @err: print default error if failed.
6331 * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
6333 int pevent_print_num_field(struct trace_seq
*s
, const char *fmt
,
6334 struct event_format
*event
, const char *name
,
6335 struct pevent_record
*record
, int err
)
6337 struct format_field
*field
= pevent_find_field(event
, name
);
6338 unsigned long long val
;
6343 if (pevent_read_number_field(field
, record
->data
, &val
))
6346 return trace_seq_printf(s
, fmt
, val
);
6350 trace_seq_printf(s
, "CAN'T FIND FIELD \"%s\"", name
);
6355 * pevent_print_func_field - print a field and a format for function pointers
6356 * @s: The seq to print to
6357 * @fmt: The printf format to print the field with.
6358 * @event: the event that the field is for
6359 * @name: The name of the field
6360 * @record: The record with the field name.
6361 * @err: print default error if failed.
6363 * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
6365 int pevent_print_func_field(struct trace_seq
*s
, const char *fmt
,
6366 struct event_format
*event
, const char *name
,
6367 struct pevent_record
*record
, int err
)
6369 struct format_field
*field
= pevent_find_field(event
, name
);
6370 struct pevent
*pevent
= event
->pevent
;
6371 unsigned long long val
;
6372 struct func_map
*func
;
6378 if (pevent_read_number_field(field
, record
->data
, &val
))
6381 func
= find_func(pevent
, val
);
6384 snprintf(tmp
, 128, "%s/0x%llx", func
->func
, func
->addr
- val
);
6386 sprintf(tmp
, "0x%08llx", val
);
6388 return trace_seq_printf(s
, fmt
, tmp
);
6392 trace_seq_printf(s
, "CAN'T FIND FIELD \"%s\"", name
);
6396 static void free_func_handle(struct pevent_function_handler
*func
)
6398 struct pevent_func_params
*params
;
6402 while (func
->params
) {
6403 params
= func
->params
;
6404 func
->params
= params
->next
;
6412 * pevent_register_print_function - register a helper function
6413 * @pevent: the handle to the pevent
6414 * @func: the function to process the helper function
6415 * @ret_type: the return type of the helper function
6416 * @name: the name of the helper function
6417 * @parameters: A list of enum pevent_func_arg_type
6419 * Some events may have helper functions in the print format arguments.
6420 * This allows a plugin to dynamically create a way to process one
6421 * of these functions.
6423 * The @parameters is a variable list of pevent_func_arg_type enums that
6424 * must end with PEVENT_FUNC_ARG_VOID.
6426 int pevent_register_print_function(struct pevent
*pevent
,
6427 pevent_func_handler func
,
6428 enum pevent_func_arg_type ret_type
,
6431 struct pevent_function_handler
*func_handle
;
6432 struct pevent_func_params
**next_param
;
6433 struct pevent_func_params
*param
;
6434 enum pevent_func_arg_type type
;
6438 func_handle
= find_func_handler(pevent
, name
);
6441 * This is most like caused by the users own
6442 * plugins updating the function. This overrides the
6445 pr_stat("override of function helper '%s'", name
);
6446 remove_func_handler(pevent
, name
);
6449 func_handle
= calloc(1, sizeof(*func_handle
));
6451 do_warning("Failed to allocate function handler");
6452 return PEVENT_ERRNO__MEM_ALLOC_FAILED
;
6455 func_handle
->ret_type
= ret_type
;
6456 func_handle
->name
= strdup(name
);
6457 func_handle
->func
= func
;
6458 if (!func_handle
->name
) {
6459 do_warning("Failed to allocate function name");
6461 return PEVENT_ERRNO__MEM_ALLOC_FAILED
;
6464 next_param
= &(func_handle
->params
);
6467 type
= va_arg(ap
, enum pevent_func_arg_type
);
6468 if (type
== PEVENT_FUNC_ARG_VOID
)
6471 if (type
>= PEVENT_FUNC_ARG_MAX_TYPES
) {
6472 do_warning("Invalid argument type %d", type
);
6473 ret
= PEVENT_ERRNO__INVALID_ARG_TYPE
;
6477 param
= malloc(sizeof(*param
));
6479 do_warning("Failed to allocate function param");
6480 ret
= PEVENT_ERRNO__MEM_ALLOC_FAILED
;
6486 *next_param
= param
;
6487 next_param
= &(param
->next
);
6489 func_handle
->nr_args
++;
6493 func_handle
->next
= pevent
->func_handlers
;
6494 pevent
->func_handlers
= func_handle
;
6499 free_func_handle(func_handle
);
6504 * pevent_unregister_print_function - unregister a helper function
6505 * @pevent: the handle to the pevent
6506 * @func: the function to process the helper function
6507 * @name: the name of the helper function
6509 * This function removes existing print handler for function @name.
6511 * Returns 0 if the handler was removed successully, -1 otherwise.
6513 int pevent_unregister_print_function(struct pevent
*pevent
,
6514 pevent_func_handler func
, char *name
)
6516 struct pevent_function_handler
*func_handle
;
6518 func_handle
= find_func_handler(pevent
, name
);
6519 if (func_handle
&& func_handle
->func
== func
) {
6520 remove_func_handler(pevent
, name
);
6526 static struct event_format
*pevent_search_event(struct pevent
*pevent
, int id
,
6527 const char *sys_name
,
6528 const char *event_name
)
6530 struct event_format
*event
;
6534 event
= pevent_find_event(pevent
, id
);
6537 if (event_name
&& (strcmp(event_name
, event
->name
) != 0))
6539 if (sys_name
&& (strcmp(sys_name
, event
->system
) != 0))
6542 event
= pevent_find_event_by_name(pevent
, sys_name
, event_name
);
6550 * pevent_register_event_handler - register a way to parse an event
6551 * @pevent: the handle to the pevent
6552 * @id: the id of the event to register
6553 * @sys_name: the system name the event belongs to
6554 * @event_name: the name of the event
6555 * @func: the function to call to parse the event information
6556 * @context: the data to be passed to @func
6558 * This function allows a developer to override the parsing of
6559 * a given event. If for some reason the default print format
6560 * is not sufficient, this function will register a function
6561 * for an event to be used to parse the data instead.
6563 * If @id is >= 0, then it is used to find the event.
6564 * else @sys_name and @event_name are used.
6566 int pevent_register_event_handler(struct pevent
*pevent
, int id
,
6567 const char *sys_name
, const char *event_name
,
6568 pevent_event_handler_func func
, void *context
)
6570 struct event_format
*event
;
6571 struct event_handler
*handle
;
6573 event
= pevent_search_event(pevent
, id
, sys_name
, event_name
);
6577 pr_stat("overriding event (%d) %s:%s with new print handler",
6578 event
->id
, event
->system
, event
->name
);
6580 event
->handler
= func
;
6581 event
->context
= context
;
6585 /* Save for later use. */
6586 handle
= calloc(1, sizeof(*handle
));
6588 do_warning("Failed to allocate event handler");
6589 return PEVENT_ERRNO__MEM_ALLOC_FAILED
;
6594 handle
->event_name
= strdup(event_name
);
6596 handle
->sys_name
= strdup(sys_name
);
6598 if ((event_name
&& !handle
->event_name
) ||
6599 (sys_name
&& !handle
->sys_name
)) {
6600 do_warning("Failed to allocate event/sys name");
6601 free((void *)handle
->event_name
);
6602 free((void *)handle
->sys_name
);
6604 return PEVENT_ERRNO__MEM_ALLOC_FAILED
;
6607 handle
->func
= func
;
6608 handle
->next
= pevent
->handlers
;
6609 pevent
->handlers
= handle
;
6610 handle
->context
= context
;
6615 static int handle_matches(struct event_handler
*handler
, int id
,
6616 const char *sys_name
, const char *event_name
,
6617 pevent_event_handler_func func
, void *context
)
6619 if (id
>= 0 && id
!= handler
->id
)
6622 if (event_name
&& (strcmp(event_name
, handler
->event_name
) != 0))
6625 if (sys_name
&& (strcmp(sys_name
, handler
->sys_name
) != 0))
6628 if (func
!= handler
->func
|| context
!= handler
->context
)
6635 * pevent_unregister_event_handler - unregister an existing event handler
6636 * @pevent: the handle to the pevent
6637 * @id: the id of the event to unregister
6638 * @sys_name: the system name the handler belongs to
6639 * @event_name: the name of the event handler
6640 * @func: the function to call to parse the event information
6641 * @context: the data to be passed to @func
6643 * This function removes existing event handler (parser).
6645 * If @id is >= 0, then it is used to find the event.
6646 * else @sys_name and @event_name are used.
6648 * Returns 0 if handler was removed successfully, -1 if event was not found.
6650 int pevent_unregister_event_handler(struct pevent
*pevent
, int id
,
6651 const char *sys_name
, const char *event_name
,
6652 pevent_event_handler_func func
, void *context
)
6654 struct event_format
*event
;
6655 struct event_handler
*handle
;
6656 struct event_handler
**next
;
6658 event
= pevent_search_event(pevent
, id
, sys_name
, event_name
);
6662 if (event
->handler
== func
&& event
->context
== context
) {
6663 pr_stat("removing override handler for event (%d) %s:%s. Going back to default handler.",
6664 event
->id
, event
->system
, event
->name
);
6666 event
->handler
= NULL
;
6667 event
->context
= NULL
;
6672 for (next
= &pevent
->handlers
; *next
; next
= &(*next
)->next
) {
6674 if (handle_matches(handle
, id
, sys_name
, event_name
,
6682 *next
= handle
->next
;
6683 free_handler(handle
);
6689 * pevent_alloc - create a pevent handle
6691 struct pevent
*pevent_alloc(void)
6693 struct pevent
*pevent
= calloc(1, sizeof(*pevent
));
6696 pevent
->ref_count
= 1;
6701 void pevent_ref(struct pevent
*pevent
)
6703 pevent
->ref_count
++;
6706 void pevent_free_format_field(struct format_field
*field
)
6709 if (field
->alias
!= field
->name
)
6715 static void free_format_fields(struct format_field
*field
)
6717 struct format_field
*next
;
6721 pevent_free_format_field(field
);
6726 static void free_formats(struct format
*format
)
6728 free_format_fields(format
->common_fields
);
6729 free_format_fields(format
->fields
);
6732 void pevent_free_format(struct event_format
*event
)
6735 free(event
->system
);
6737 free_formats(&event
->format
);
6739 free(event
->print_fmt
.format
);
6740 free_args(event
->print_fmt
.args
);
6746 * pevent_free - free a pevent handle
6747 * @pevent: the pevent handle to free
6749 void pevent_free(struct pevent
*pevent
)
6751 struct cmdline_list
*cmdlist
, *cmdnext
;
6752 struct func_list
*funclist
, *funcnext
;
6753 struct printk_list
*printklist
, *printknext
;
6754 struct pevent_function_handler
*func_handler
;
6755 struct event_handler
*handle
;
6761 cmdlist
= pevent
->cmdlist
;
6762 funclist
= pevent
->funclist
;
6763 printklist
= pevent
->printklist
;
6765 pevent
->ref_count
--;
6766 if (pevent
->ref_count
)
6769 if (pevent
->cmdlines
) {
6770 for (i
= 0; i
< pevent
->cmdline_count
; i
++)
6771 free(pevent
->cmdlines
[i
].comm
);
6772 free(pevent
->cmdlines
);
6776 cmdnext
= cmdlist
->next
;
6777 free(cmdlist
->comm
);
6782 if (pevent
->func_map
) {
6783 for (i
= 0; i
< (int)pevent
->func_count
; i
++) {
6784 free(pevent
->func_map
[i
].func
);
6785 free(pevent
->func_map
[i
].mod
);
6787 free(pevent
->func_map
);
6791 funcnext
= funclist
->next
;
6792 free(funclist
->func
);
6793 free(funclist
->mod
);
6795 funclist
= funcnext
;
6798 while (pevent
->func_handlers
) {
6799 func_handler
= pevent
->func_handlers
;
6800 pevent
->func_handlers
= func_handler
->next
;
6801 free_func_handle(func_handler
);
6804 if (pevent
->printk_map
) {
6805 for (i
= 0; i
< (int)pevent
->printk_count
; i
++)
6806 free(pevent
->printk_map
[i
].printk
);
6807 free(pevent
->printk_map
);
6810 while (printklist
) {
6811 printknext
= printklist
->next
;
6812 free(printklist
->printk
);
6814 printklist
= printknext
;
6817 for (i
= 0; i
< pevent
->nr_events
; i
++)
6818 pevent_free_format(pevent
->events
[i
]);
6820 while (pevent
->handlers
) {
6821 handle
= pevent
->handlers
;
6822 pevent
->handlers
= handle
->next
;
6823 free_handler(handle
);
6826 free(pevent
->trace_clock
);
6827 free(pevent
->events
);
6828 free(pevent
->sort_events
);
6829 free(pevent
->func_resolver
);
6834 void pevent_unref(struct pevent
*pevent
)
6836 pevent_free(pevent
);