hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/tools/lib/traceevent/event-parse.c
....@@ -18,12 +18,14 @@
1818 #include <errno.h>
1919 #include <stdint.h>
2020 #include <limits.h>
21
-#include <linux/string.h>
2221 #include <linux/time64.h>
2322
2423 #include <netinet/in.h>
2524 #include "event-parse.h"
25
+
26
+#include "event-parse-local.h"
2627 #include "event-utils.h"
28
+#include "trace-seq.h"
2729
2830 static const char *input_buf;
2931 static unsigned long long input_buf_ptr;
....@@ -52,19 +54,26 @@
5254 warning(fmt, ##__VA_ARGS__); \
5355 } while (0)
5456
55
-static void init_input_buf(const char *buf, unsigned long long size)
57
+/**
58
+ * init_input_buf - init buffer for parsing
59
+ * @buf: buffer to parse
60
+ * @size: the size of the buffer
61
+ *
62
+ * Initializes the internal buffer that tep_read_token() will parse.
63
+ */
64
+__hidden void init_input_buf(const char *buf, unsigned long long size)
5665 {
5766 input_buf = buf;
5867 input_buf_siz = size;
5968 input_buf_ptr = 0;
6069 }
6170
62
-const char *tep_get_input_buf(void)
71
+__hidden const char *get_input_buf(void)
6372 {
6473 return input_buf;
6574 }
6675
67
-unsigned long long tep_get_input_buf_ptr(void)
76
+__hidden unsigned long long get_input_buf_ptr(void)
6877 {
6978 return input_buf_ptr;
7079 }
....@@ -94,22 +103,9 @@
94103
95104 static unsigned long long
96105 process_defined_func(struct trace_seq *s, void *data, int size,
97
- struct event_format *event, struct print_arg *arg);
106
+ struct tep_event *event, struct tep_print_arg *arg);
98107
99108 static void free_func_handle(struct tep_function_handler *func);
100
-
101
-/**
102
- * tep_buffer_init - init buffer for parsing
103
- * @buf: buffer to parse
104
- * @size: the size of the buffer
105
- *
106
- * For use with tep_read_token(), this initializes the internal
107
- * buffer that tep_read_token() will parse.
108
- */
109
-void tep_buffer_init(const char *buf, unsigned long long size)
110
-{
111
- init_input_buf(buf, size);
112
-}
113109
114110 void breakpoint(void)
115111 {
....@@ -117,25 +113,44 @@
117113 x++;
118114 }
119115
120
-struct print_arg *alloc_arg(void)
116
+static struct tep_print_arg *alloc_arg(void)
121117 {
122
- return calloc(1, sizeof(struct print_arg));
118
+ return calloc(1, sizeof(struct tep_print_arg));
123119 }
124120
125
-struct cmdline {
121
+struct tep_cmdline {
126122 char *comm;
127123 int pid;
128124 };
129125
130126 static int cmdline_cmp(const void *a, const void *b)
131127 {
132
- const struct cmdline *ca = a;
133
- const struct cmdline *cb = b;
128
+ const struct tep_cmdline *ca = a;
129
+ const struct tep_cmdline *cb = b;
134130
135131 if (ca->pid < cb->pid)
136132 return -1;
137133 if (ca->pid > cb->pid)
138134 return 1;
135
+
136
+ return 0;
137
+}
138
+
139
+/* Looking for where to place the key */
140
+static int cmdline_slot_cmp(const void *a, const void *b)
141
+{
142
+ const struct tep_cmdline *ca = a;
143
+ const struct tep_cmdline *cb = b;
144
+ const struct tep_cmdline *cb1 = cb + 1;
145
+
146
+ if (ca->pid < cb->pid)
147
+ return -1;
148
+
149
+ if (ca->pid > cb->pid) {
150
+ if (ca->pid <= cb1->pid)
151
+ return 0;
152
+ return 1;
153
+ }
139154
140155 return 0;
141156 }
....@@ -146,14 +161,14 @@
146161 int pid;
147162 };
148163
149
-static int cmdline_init(struct tep_handle *pevent)
164
+static int cmdline_init(struct tep_handle *tep)
150165 {
151
- struct cmdline_list *cmdlist = pevent->cmdlist;
166
+ struct cmdline_list *cmdlist = tep->cmdlist;
152167 struct cmdline_list *item;
153
- struct cmdline *cmdlines;
168
+ struct tep_cmdline *cmdlines;
154169 int i;
155170
156
- cmdlines = malloc(sizeof(*cmdlines) * pevent->cmdline_count);
171
+ cmdlines = malloc(sizeof(*cmdlines) * tep->cmdline_count);
157172 if (!cmdlines)
158173 return -1;
159174
....@@ -167,29 +182,29 @@
167182 free(item);
168183 }
169184
170
- qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp);
185
+ qsort(cmdlines, tep->cmdline_count, sizeof(*cmdlines), cmdline_cmp);
171186
172
- pevent->cmdlines = cmdlines;
173
- pevent->cmdlist = NULL;
187
+ tep->cmdlines = cmdlines;
188
+ tep->cmdlist = NULL;
174189
175190 return 0;
176191 }
177192
178
-static const char *find_cmdline(struct tep_handle *pevent, int pid)
193
+static const char *find_cmdline(struct tep_handle *tep, int pid)
179194 {
180
- const struct cmdline *comm;
181
- struct cmdline key;
195
+ const struct tep_cmdline *comm;
196
+ struct tep_cmdline key;
182197
183198 if (!pid)
184199 return "<idle>";
185200
186
- if (!pevent->cmdlines && cmdline_init(pevent))
201
+ if (!tep->cmdlines && cmdline_init(tep))
187202 return "<not enough memory for cmdlines!>";
188203
189204 key.pid = pid;
190205
191
- comm = bsearch(&key, pevent->cmdlines, pevent->cmdline_count,
192
- sizeof(*pevent->cmdlines), cmdline_cmp);
206
+ comm = bsearch(&key, tep->cmdlines, tep->cmdline_count,
207
+ sizeof(*tep->cmdlines), cmdline_cmp);
193208
194209 if (comm)
195210 return comm->comm;
....@@ -197,32 +212,32 @@
197212 }
198213
199214 /**
200
- * tep_pid_is_registered - return if a pid has a cmdline registered
201
- * @pevent: handle for the pevent
215
+ * tep_is_pid_registered - return if a pid has a cmdline registered
216
+ * @tep: a handle to the trace event parser context
202217 * @pid: The pid to check if it has a cmdline registered with.
203218 *
204
- * Returns 1 if the pid has a cmdline mapped to it
205
- * 0 otherwise.
219
+ * Returns true if the pid has a cmdline mapped to it
220
+ * false otherwise.
206221 */
207
-int tep_pid_is_registered(struct tep_handle *pevent, int pid)
222
+bool tep_is_pid_registered(struct tep_handle *tep, int pid)
208223 {
209
- const struct cmdline *comm;
210
- struct cmdline key;
224
+ const struct tep_cmdline *comm;
225
+ struct tep_cmdline key;
211226
212227 if (!pid)
213
- return 1;
228
+ return true;
214229
215
- if (!pevent->cmdlines && cmdline_init(pevent))
216
- return 0;
230
+ if (!tep->cmdlines && cmdline_init(tep))
231
+ return false;
217232
218233 key.pid = pid;
219234
220
- comm = bsearch(&key, pevent->cmdlines, pevent->cmdline_count,
221
- sizeof(*pevent->cmdlines), cmdline_cmp);
235
+ comm = bsearch(&key, tep->cmdlines, tep->cmdline_count,
236
+ sizeof(*tep->cmdlines), cmdline_cmp);
222237
223238 if (comm)
224
- return 1;
225
- return 0;
239
+ return true;
240
+ return false;
226241 }
227242
228243 /*
....@@ -230,11 +245,14 @@
230245 * we must add this pid. This is much slower than when cmdlines
231246 * are added before the array is initialized.
232247 */
233
-static int add_new_comm(struct tep_handle *pevent, const char *comm, int pid)
248
+static int add_new_comm(struct tep_handle *tep,
249
+ const char *comm, int pid, bool override)
234250 {
235
- struct cmdline *cmdlines = pevent->cmdlines;
236
- const struct cmdline *cmdline;
237
- struct cmdline key;
251
+ struct tep_cmdline *cmdlines = tep->cmdlines;
252
+ struct tep_cmdline *cmdline;
253
+ struct tep_cmdline key;
254
+ char *new_comm;
255
+ int cnt;
238256
239257 if (!pid)
240258 return 0;
....@@ -242,51 +260,77 @@
242260 /* avoid duplicates */
243261 key.pid = pid;
244262
245
- cmdline = bsearch(&key, pevent->cmdlines, pevent->cmdline_count,
246
- sizeof(*pevent->cmdlines), cmdline_cmp);
263
+ cmdline = bsearch(&key, tep->cmdlines, tep->cmdline_count,
264
+ sizeof(*tep->cmdlines), cmdline_cmp);
247265 if (cmdline) {
248
- errno = EEXIST;
249
- return -1;
266
+ if (!override) {
267
+ errno = EEXIST;
268
+ return -1;
269
+ }
270
+ new_comm = strdup(comm);
271
+ if (!new_comm) {
272
+ errno = ENOMEM;
273
+ return -1;
274
+ }
275
+ free(cmdline->comm);
276
+ cmdline->comm = new_comm;
277
+
278
+ return 0;
250279 }
251280
252
- cmdlines = realloc(cmdlines, sizeof(*cmdlines) * (pevent->cmdline_count + 1));
281
+ cmdlines = realloc(cmdlines, sizeof(*cmdlines) * (tep->cmdline_count + 1));
253282 if (!cmdlines) {
254283 errno = ENOMEM;
255284 return -1;
256285 }
257
- pevent->cmdlines = cmdlines;
286
+ tep->cmdlines = cmdlines;
258287
259
- cmdlines[pevent->cmdline_count].comm = strdup(comm);
260
- if (!cmdlines[pevent->cmdline_count].comm) {
288
+ key.comm = strdup(comm);
289
+ if (!key.comm) {
261290 errno = ENOMEM;
262291 return -1;
263292 }
264293
265
- cmdlines[pevent->cmdline_count].pid = pid;
266
-
267
- if (cmdlines[pevent->cmdline_count].comm)
268
- pevent->cmdline_count++;
294
+ if (!tep->cmdline_count) {
295
+ /* no entries yet */
296
+ tep->cmdlines[0] = key;
297
+ tep->cmdline_count++;
298
+ return 0;
299
+ }
269300
270
- qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp);
301
+ /* Now find where we want to store the new cmdline */
302
+ cmdline = bsearch(&key, tep->cmdlines, tep->cmdline_count - 1,
303
+ sizeof(*tep->cmdlines), cmdline_slot_cmp);
304
+
305
+ cnt = tep->cmdline_count;
306
+ if (cmdline) {
307
+ /* cmdline points to the one before the spot we want */
308
+ cmdline++;
309
+ cnt -= cmdline - tep->cmdlines;
310
+
311
+ } else {
312
+ /* The new entry is either before or after the list */
313
+ if (key.pid > tep->cmdlines[tep->cmdline_count - 1].pid) {
314
+ tep->cmdlines[tep->cmdline_count++] = key;
315
+ return 0;
316
+ }
317
+ cmdline = &tep->cmdlines[0];
318
+ }
319
+ memmove(cmdline + 1, cmdline, (cnt * sizeof(*cmdline)));
320
+ *cmdline = key;
321
+
322
+ tep->cmdline_count++;
271323
272324 return 0;
273325 }
274326
275
-/**
276
- * tep_register_comm - register a pid / comm mapping
277
- * @pevent: handle for the pevent
278
- * @comm: the command line to register
279
- * @pid: the pid to map the command line to
280
- *
281
- * This adds a mapping to search for command line names with
282
- * a given pid. The comm is duplicated.
283
- */
284
-int tep_register_comm(struct tep_handle *pevent, const char *comm, int pid)
327
+static int _tep_register_comm(struct tep_handle *tep,
328
+ const char *comm, int pid, bool override)
285329 {
286330 struct cmdline_list *item;
287331
288
- if (pevent->cmdlines)
289
- return add_new_comm(pevent, comm, pid);
332
+ if (tep->cmdlines)
333
+ return add_new_comm(tep, comm, pid, override);
290334
291335 item = malloc(sizeof(*item));
292336 if (!item)
....@@ -301,22 +345,46 @@
301345 return -1;
302346 }
303347 item->pid = pid;
304
- item->next = pevent->cmdlist;
348
+ item->next = tep->cmdlist;
305349
306
- pevent->cmdlist = item;
307
- pevent->cmdline_count++;
350
+ tep->cmdlist = item;
351
+ tep->cmdline_count++;
308352
309353 return 0;
310354 }
311355
312
-int tep_register_trace_clock(struct tep_handle *pevent, const char *trace_clock)
356
+/**
357
+ * tep_register_comm - register a pid / comm mapping
358
+ * @tep: a handle to the trace event parser context
359
+ * @comm: the command line to register
360
+ * @pid: the pid to map the command line to
361
+ *
362
+ * This adds a mapping to search for command line names with
363
+ * a given pid. The comm is duplicated. If a command with the same pid
364
+ * already exist, -1 is returned and errno is set to EEXIST
365
+ */
366
+int tep_register_comm(struct tep_handle *tep, const char *comm, int pid)
313367 {
314
- pevent->trace_clock = strdup(trace_clock);
315
- if (!pevent->trace_clock) {
368
+ return _tep_register_comm(tep, comm, pid, false);
369
+}
370
+
371
+/**
372
+ * tep_override_comm - register a pid / comm mapping
373
+ * @tep: a handle to the trace event parser context
374
+ * @comm: the command line to register
375
+ * @pid: the pid to map the command line to
376
+ *
377
+ * This adds a mapping to search for command line names with
378
+ * a given pid. The comm is duplicated. If a command with the same pid
379
+ * already exist, the command string is udapted with the new one
380
+ */
381
+int tep_override_comm(struct tep_handle *tep, const char *comm, int pid)
382
+{
383
+ if (!tep->cmdlines && cmdline_init(tep)) {
316384 errno = ENOMEM;
317385 return -1;
318386 }
319
- return 0;
387
+ return _tep_register_comm(tep, comm, pid, true);
320388 }
321389
322390 struct func_map {
....@@ -366,18 +434,18 @@
366434 return 1;
367435 }
368436
369
-static int func_map_init(struct tep_handle *pevent)
437
+static int func_map_init(struct tep_handle *tep)
370438 {
371439 struct func_list *funclist;
372440 struct func_list *item;
373441 struct func_map *func_map;
374442 int i;
375443
376
- func_map = malloc(sizeof(*func_map) * (pevent->func_count + 1));
444
+ func_map = malloc(sizeof(*func_map) * (tep->func_count + 1));
377445 if (!func_map)
378446 return -1;
379447
380
- funclist = pevent->funclist;
448
+ funclist = tep->funclist;
381449
382450 i = 0;
383451 while (funclist) {
....@@ -390,34 +458,34 @@
390458 free(item);
391459 }
392460
393
- qsort(func_map, pevent->func_count, sizeof(*func_map), func_cmp);
461
+ qsort(func_map, tep->func_count, sizeof(*func_map), func_cmp);
394462
395463 /*
396464 * Add a special record at the end.
397465 */
398
- func_map[pevent->func_count].func = NULL;
399
- func_map[pevent->func_count].addr = 0;
400
- func_map[pevent->func_count].mod = NULL;
466
+ func_map[tep->func_count].func = NULL;
467
+ func_map[tep->func_count].addr = 0;
468
+ func_map[tep->func_count].mod = NULL;
401469
402
- pevent->func_map = func_map;
403
- pevent->funclist = NULL;
470
+ tep->func_map = func_map;
471
+ tep->funclist = NULL;
404472
405473 return 0;
406474 }
407475
408476 static struct func_map *
409
-__find_func(struct tep_handle *pevent, unsigned long long addr)
477
+__find_func(struct tep_handle *tep, unsigned long long addr)
410478 {
411479 struct func_map *func;
412480 struct func_map key;
413481
414
- if (!pevent->func_map)
415
- func_map_init(pevent);
482
+ if (!tep->func_map)
483
+ func_map_init(tep);
416484
417485 key.addr = addr;
418486
419
- func = bsearch(&key, pevent->func_map, pevent->func_count,
420
- sizeof(*pevent->func_map), func_bcmp);
487
+ func = bsearch(&key, tep->func_map, tep->func_count,
488
+ sizeof(*tep->func_map), func_bcmp);
421489
422490 return func;
423491 }
....@@ -430,15 +498,14 @@
430498
431499 /**
432500 * tep_set_function_resolver - set an alternative function resolver
433
- * @pevent: handle for the pevent
501
+ * @tep: a handle to the trace event parser context
434502 * @resolver: function to be used
435503 * @priv: resolver function private state.
436504 *
437505 * Some tools may have already a way to resolve kernel functions, allow them to
438
- * keep using it instead of duplicating all the entries inside
439
- * pevent->funclist.
506
+ * keep using it instead of duplicating all the entries inside tep->funclist.
440507 */
441
-int tep_set_function_resolver(struct tep_handle *pevent,
508
+int tep_set_function_resolver(struct tep_handle *tep,
442509 tep_func_resolver_t *func, void *priv)
443510 {
444511 struct func_resolver *resolver = malloc(sizeof(*resolver));
....@@ -449,38 +516,38 @@
449516 resolver->func = func;
450517 resolver->priv = priv;
451518
452
- free(pevent->func_resolver);
453
- pevent->func_resolver = resolver;
519
+ free(tep->func_resolver);
520
+ tep->func_resolver = resolver;
454521
455522 return 0;
456523 }
457524
458525 /**
459526 * tep_reset_function_resolver - reset alternative function resolver
460
- * @pevent: handle for the pevent
527
+ * @tep: a handle to the trace event parser context
461528 *
462529 * Stop using whatever alternative resolver was set, use the default
463530 * one instead.
464531 */
465
-void tep_reset_function_resolver(struct tep_handle *pevent)
532
+void tep_reset_function_resolver(struct tep_handle *tep)
466533 {
467
- free(pevent->func_resolver);
468
- pevent->func_resolver = NULL;
534
+ free(tep->func_resolver);
535
+ tep->func_resolver = NULL;
469536 }
470537
471538 static struct func_map *
472
-find_func(struct tep_handle *pevent, unsigned long long addr)
539
+find_func(struct tep_handle *tep, unsigned long long addr)
473540 {
474541 struct func_map *map;
475542
476
- if (!pevent->func_resolver)
477
- return __find_func(pevent, addr);
543
+ if (!tep->func_resolver)
544
+ return __find_func(tep, addr);
478545
479
- map = &pevent->func_resolver->map;
546
+ map = &tep->func_resolver->map;
480547 map->mod = NULL;
481548 map->addr = addr;
482
- map->func = pevent->func_resolver->func(pevent->func_resolver->priv,
483
- &map->addr, &map->mod);
549
+ map->func = tep->func_resolver->func(tep->func_resolver->priv,
550
+ &map->addr, &map->mod);
484551 if (map->func == NULL)
485552 return NULL;
486553
....@@ -489,18 +556,18 @@
489556
490557 /**
491558 * tep_find_function - find a function by a given address
492
- * @pevent: handle for the pevent
559
+ * @tep: a handle to the trace event parser context
493560 * @addr: the address to find the function with
494561 *
495562 * Returns a pointer to the function stored that has the given
496563 * address. Note, the address does not have to be exact, it
497564 * will select the function that would contain the address.
498565 */
499
-const char *tep_find_function(struct tep_handle *pevent, unsigned long long addr)
566
+const char *tep_find_function(struct tep_handle *tep, unsigned long long addr)
500567 {
501568 struct func_map *map;
502569
503
- map = find_func(pevent, addr);
570
+ map = find_func(tep, addr);
504571 if (!map)
505572 return NULL;
506573
....@@ -509,7 +576,7 @@
509576
510577 /**
511578 * tep_find_function_address - find a function address by a given address
512
- * @pevent: handle for the pevent
579
+ * @tep: a handle to the trace event parser context
513580 * @addr: the address to find the function with
514581 *
515582 * Returns the address the function starts at. This can be used in
....@@ -517,11 +584,11 @@
517584 * name and the function offset.
518585 */
519586 unsigned long long
520
-tep_find_function_address(struct tep_handle *pevent, unsigned long long addr)
587
+tep_find_function_address(struct tep_handle *tep, unsigned long long addr)
521588 {
522589 struct func_map *map;
523590
524
- map = find_func(pevent, addr);
591
+ map = find_func(tep, addr);
525592 if (!map)
526593 return 0;
527594
....@@ -530,7 +597,7 @@
530597
531598 /**
532599 * tep_register_function - register a function with a given address
533
- * @pevent: handle for the pevent
600
+ * @tep: a handle to the trace event parser context
534601 * @function: the function name to register
535602 * @addr: the address the function starts at
536603 * @mod: the kernel module the function may be in (NULL for none)
....@@ -538,7 +605,7 @@
538605 * This registers a function name with an address and module.
539606 * The @func passed in is duplicated.
540607 */
541
-int tep_register_function(struct tep_handle *pevent, char *func,
608
+int tep_register_function(struct tep_handle *tep, char *func,
542609 unsigned long long addr, char *mod)
543610 {
544611 struct func_list *item = malloc(sizeof(*item));
....@@ -546,7 +613,7 @@
546613 if (!item)
547614 return -1;
548615
549
- item->next = pevent->funclist;
616
+ item->next = tep->funclist;
550617 item->func = strdup(func);
551618 if (!item->func)
552619 goto out_free;
....@@ -559,8 +626,8 @@
559626 item->mod = NULL;
560627 item->addr = addr;
561628
562
- pevent->funclist = item;
563
- pevent->func_count++;
629
+ tep->funclist = item;
630
+ tep->func_count++;
564631
565632 return 0;
566633
....@@ -575,23 +642,23 @@
575642
576643 /**
577644 * tep_print_funcs - print out the stored functions
578
- * @pevent: handle for the pevent
645
+ * @tep: a handle to the trace event parser context
579646 *
580647 * This prints out the stored functions.
581648 */
582
-void tep_print_funcs(struct tep_handle *pevent)
649
+void tep_print_funcs(struct tep_handle *tep)
583650 {
584651 int i;
585652
586
- if (!pevent->func_map)
587
- func_map_init(pevent);
653
+ if (!tep->func_map)
654
+ func_map_init(tep);
588655
589
- for (i = 0; i < (int)pevent->func_count; i++) {
656
+ for (i = 0; i < (int)tep->func_count; i++) {
590657 printf("%016llx %s",
591
- pevent->func_map[i].addr,
592
- pevent->func_map[i].func);
593
- if (pevent->func_map[i].mod)
594
- printf(" [%s]\n", pevent->func_map[i].mod);
658
+ tep->func_map[i].addr,
659
+ tep->func_map[i].func);
660
+ if (tep->func_map[i].mod)
661
+ printf(" [%s]\n", tep->func_map[i].mod);
595662 else
596663 printf("\n");
597664 }
....@@ -621,18 +688,18 @@
621688 return 0;
622689 }
623690
624
-static int printk_map_init(struct tep_handle *pevent)
691
+static int printk_map_init(struct tep_handle *tep)
625692 {
626693 struct printk_list *printklist;
627694 struct printk_list *item;
628695 struct printk_map *printk_map;
629696 int i;
630697
631
- printk_map = malloc(sizeof(*printk_map) * (pevent->printk_count + 1));
698
+ printk_map = malloc(sizeof(*printk_map) * (tep->printk_count + 1));
632699 if (!printk_map)
633700 return -1;
634701
635
- printklist = pevent->printklist;
702
+ printklist = tep->printklist;
636703
637704 i = 0;
638705 while (printklist) {
....@@ -644,41 +711,41 @@
644711 free(item);
645712 }
646713
647
- qsort(printk_map, pevent->printk_count, sizeof(*printk_map), printk_cmp);
714
+ qsort(printk_map, tep->printk_count, sizeof(*printk_map), printk_cmp);
648715
649
- pevent->printk_map = printk_map;
650
- pevent->printklist = NULL;
716
+ tep->printk_map = printk_map;
717
+ tep->printklist = NULL;
651718
652719 return 0;
653720 }
654721
655722 static struct printk_map *
656
-find_printk(struct tep_handle *pevent, unsigned long long addr)
723
+find_printk(struct tep_handle *tep, unsigned long long addr)
657724 {
658725 struct printk_map *printk;
659726 struct printk_map key;
660727
661
- if (!pevent->printk_map && printk_map_init(pevent))
728
+ if (!tep->printk_map && printk_map_init(tep))
662729 return NULL;
663730
664731 key.addr = addr;
665732
666
- printk = bsearch(&key, pevent->printk_map, pevent->printk_count,
667
- sizeof(*pevent->printk_map), printk_cmp);
733
+ printk = bsearch(&key, tep->printk_map, tep->printk_count,
734
+ sizeof(*tep->printk_map), printk_cmp);
668735
669736 return printk;
670737 }
671738
672739 /**
673740 * tep_register_print_string - register a string by its address
674
- * @pevent: handle for the pevent
741
+ * @tep: a handle to the trace event parser context
675742 * @fmt: the string format to register
676743 * @addr: the address the string was located at
677744 *
678745 * This registers a string by the address it was stored in the kernel.
679746 * The @fmt passed in is duplicated.
680747 */
681
-int tep_register_print_string(struct tep_handle *pevent, const char *fmt,
748
+int tep_register_print_string(struct tep_handle *tep, const char *fmt,
682749 unsigned long long addr)
683750 {
684751 struct printk_list *item = malloc(sizeof(*item));
....@@ -687,7 +754,7 @@
687754 if (!item)
688755 return -1;
689756
690
- item->next = pevent->printklist;
757
+ item->next = tep->printklist;
691758 item->addr = addr;
692759
693760 /* Strip off quotes and '\n' from the end */
....@@ -705,8 +772,8 @@
705772 if (strcmp(p, "\\n") == 0)
706773 *p = 0;
707774
708
- pevent->printklist = item;
709
- pevent->printk_count++;
775
+ tep->printklist = item;
776
+ tep->printk_count++;
710777
711778 return 0;
712779
....@@ -718,70 +785,70 @@
718785
719786 /**
720787 * tep_print_printk - print out the stored strings
721
- * @pevent: handle for the pevent
788
+ * @tep: a handle to the trace event parser context
722789 *
723790 * This prints the string formats that were stored.
724791 */
725
-void tep_print_printk(struct tep_handle *pevent)
792
+void tep_print_printk(struct tep_handle *tep)
726793 {
727794 int i;
728795
729
- if (!pevent->printk_map)
730
- printk_map_init(pevent);
796
+ if (!tep->printk_map)
797
+ printk_map_init(tep);
731798
732
- for (i = 0; i < (int)pevent->printk_count; i++) {
799
+ for (i = 0; i < (int)tep->printk_count; i++) {
733800 printf("%016llx %s\n",
734
- pevent->printk_map[i].addr,
735
- pevent->printk_map[i].printk);
801
+ tep->printk_map[i].addr,
802
+ tep->printk_map[i].printk);
736803 }
737804 }
738805
739
-static struct event_format *alloc_event(void)
806
+static struct tep_event *alloc_event(void)
740807 {
741
- return calloc(1, sizeof(struct event_format));
808
+ return calloc(1, sizeof(struct tep_event));
742809 }
743810
744
-static int add_event(struct tep_handle *pevent, struct event_format *event)
811
+static int add_event(struct tep_handle *tep, struct tep_event *event)
745812 {
746813 int i;
747
- struct event_format **events = realloc(pevent->events, sizeof(event) *
748
- (pevent->nr_events + 1));
814
+ struct tep_event **events = realloc(tep->events, sizeof(event) *
815
+ (tep->nr_events + 1));
749816 if (!events)
750817 return -1;
751818
752
- pevent->events = events;
819
+ tep->events = events;
753820
754
- for (i = 0; i < pevent->nr_events; i++) {
755
- if (pevent->events[i]->id > event->id)
821
+ for (i = 0; i < tep->nr_events; i++) {
822
+ if (tep->events[i]->id > event->id)
756823 break;
757824 }
758
- if (i < pevent->nr_events)
759
- memmove(&pevent->events[i + 1],
760
- &pevent->events[i],
761
- sizeof(event) * (pevent->nr_events - i));
825
+ if (i < tep->nr_events)
826
+ memmove(&tep->events[i + 1],
827
+ &tep->events[i],
828
+ sizeof(event) * (tep->nr_events - i));
762829
763
- pevent->events[i] = event;
764
- pevent->nr_events++;
830
+ tep->events[i] = event;
831
+ tep->nr_events++;
765832
766
- event->pevent = pevent;
833
+ event->tep = tep;
767834
768835 return 0;
769836 }
770837
771
-static int event_item_type(enum event_type type)
838
+static int event_item_type(enum tep_event_type type)
772839 {
773840 switch (type) {
774
- case EVENT_ITEM ... EVENT_SQUOTE:
841
+ case TEP_EVENT_ITEM ... TEP_EVENT_SQUOTE:
775842 return 1;
776
- case EVENT_ERROR ... EVENT_DELIM:
843
+ case TEP_EVENT_ERROR ... TEP_EVENT_DELIM:
777844 default:
778845 return 0;
779846 }
780847 }
781848
782
-static void free_flag_sym(struct print_flag_sym *fsym)
849
+static void free_flag_sym(struct tep_print_flag_sym *fsym)
783850 {
784
- struct print_flag_sym *next;
851
+ struct tep_print_flag_sym *next;
785852
786853 while (fsym) {
787854 next = fsym->next;
....@@ -792,60 +859,60 @@
792859 }
793860 }
794861
795
-static void free_arg(struct print_arg *arg)
862
+static void free_arg(struct tep_print_arg *arg)
796863 {
797
- struct print_arg *farg;
864
+ struct tep_print_arg *farg;
798865
799866 if (!arg)
800867 return;
801868
802869 switch (arg->type) {
803
- case PRINT_ATOM:
870
+ case TEP_PRINT_ATOM:
804871 free(arg->atom.atom);
805872 break;
806
- case PRINT_FIELD:
873
+ case TEP_PRINT_FIELD:
807874 free(arg->field.name);
808875 break;
809
- case PRINT_FLAGS:
876
+ case TEP_PRINT_FLAGS:
810877 free_arg(arg->flags.field);
811878 free(arg->flags.delim);
812879 free_flag_sym(arg->flags.flags);
813880 break;
814
- case PRINT_SYMBOL:
881
+ case TEP_PRINT_SYMBOL:
815882 free_arg(arg->symbol.field);
816883 free_flag_sym(arg->symbol.symbols);
817884 break;
818
- case PRINT_HEX:
819
- case PRINT_HEX_STR:
885
+ case TEP_PRINT_HEX:
886
+ case TEP_PRINT_HEX_STR:
820887 free_arg(arg->hex.field);
821888 free_arg(arg->hex.size);
822889 break;
823
- case PRINT_INT_ARRAY:
890
+ case TEP_PRINT_INT_ARRAY:
824891 free_arg(arg->int_array.field);
825892 free_arg(arg->int_array.count);
826893 free_arg(arg->int_array.el_size);
827894 break;
828
- case PRINT_TYPE:
895
+ case TEP_PRINT_TYPE:
829896 free(arg->typecast.type);
830897 free_arg(arg->typecast.item);
831898 break;
832
- case PRINT_STRING:
833
- case PRINT_BSTRING:
899
+ case TEP_PRINT_STRING:
900
+ case TEP_PRINT_BSTRING:
834901 free(arg->string.string);
835902 break;
836
- case PRINT_BITMASK:
903
+ case TEP_PRINT_BITMASK:
837904 free(arg->bitmask.bitmask);
838905 break;
839
- case PRINT_DYNAMIC_ARRAY:
840
- case PRINT_DYNAMIC_ARRAY_LEN:
906
+ case TEP_PRINT_DYNAMIC_ARRAY:
907
+ case TEP_PRINT_DYNAMIC_ARRAY_LEN:
841908 free(arg->dynarray.index);
842909 break;
843
- case PRINT_OP:
910
+ case TEP_PRINT_OP:
844911 free(arg->op.op);
845912 free_arg(arg->op.left);
846913 free_arg(arg->op.right);
847914 break;
848
- case PRINT_FUNC:
915
+ case TEP_PRINT_FUNC:
849916 while (arg->func.args) {
850917 farg = arg->func.args;
851918 arg->func.args = farg->next;
....@@ -853,7 +920,7 @@
853920 }
854921 break;
855922
856
- case PRINT_NULL:
923
+ case TEP_PRINT_NULL:
857924 default:
858925 break;
859926 }
....@@ -861,24 +928,24 @@
861928 free(arg);
862929 }
863930
864
-static enum event_type get_type(int ch)
931
+static enum tep_event_type get_type(int ch)
865932 {
866933 if (ch == '\n')
867
- return EVENT_NEWLINE;
934
+ return TEP_EVENT_NEWLINE;
868935 if (isspace(ch))
869
- return EVENT_SPACE;
936
+ return TEP_EVENT_SPACE;
870937 if (isalnum(ch) || ch == '_')
871
- return EVENT_ITEM;
938
+ return TEP_EVENT_ITEM;
872939 if (ch == '\'')
873
- return EVENT_SQUOTE;
940
+ return TEP_EVENT_SQUOTE;
874941 if (ch == '"')
875
- return EVENT_DQUOTE;
942
+ return TEP_EVENT_DQUOTE;
876943 if (!isprint(ch))
877
- return EVENT_NONE;
944
+ return TEP_EVENT_NONE;
878945 if (ch == '(' || ch == ')' || ch == ',')
879
- return EVENT_DELIM;
946
+ return TEP_EVENT_DELIM;
880947
881
- return EVENT_OP;
948
+ return TEP_EVENT_OP;
882949 }
883950
884951 static int __read_char(void)
....@@ -889,22 +956,17 @@
889956 return input_buf[input_buf_ptr++];
890957 }
891958
892
-static int __peek_char(void)
959
+/**
960
+ * peek_char - peek at the next character that will be read
961
+ *
962
+ * Returns the next character read, or -1 if end of buffer.
963
+ */
964
+__hidden int peek_char(void)
893965 {
894966 if (input_buf_ptr >= input_buf_siz)
895967 return -1;
896968
897969 return input_buf[input_buf_ptr];
898
-}
899
-
900
-/**
901
- * tep_peek_char - peek at the next character that will be read
902
- *
903
- * Returns the next character read, or -1 if end of buffer.
904
- */
905
-int tep_peek_char(void)
906
-{
907
- return __peek_char();
908970 }
909971
910972 static int extend_token(char **tok, char *buf, int size)
....@@ -926,41 +988,41 @@
926988 return 0;
927989 }
928990
929
-static enum event_type force_token(const char *str, char **tok);
991
+static enum tep_event_type force_token(const char *str, char **tok);
930992
931
-static enum event_type __read_token(char **tok)
993
+static enum tep_event_type __read_token(char **tok)
932994 {
933995 char buf[BUFSIZ];
934996 int ch, last_ch, quote_ch, next_ch;
935997 int i = 0;
936998 int tok_size = 0;
937
- enum event_type type;
999
+ enum tep_event_type type;
9381000
9391001 *tok = NULL;
9401002
9411003
9421004 ch = __read_char();
9431005 if (ch < 0)
944
- return EVENT_NONE;
1006
+ return TEP_EVENT_NONE;
9451007
9461008 type = get_type(ch);
947
- if (type == EVENT_NONE)
1009
+ if (type == TEP_EVENT_NONE)
9481010 return type;
9491011
9501012 buf[i++] = ch;
9511013
9521014 switch (type) {
953
- case EVENT_NEWLINE:
954
- case EVENT_DELIM:
1015
+ case TEP_EVENT_NEWLINE:
1016
+ case TEP_EVENT_DELIM:
9551017 if (asprintf(tok, "%c", ch) < 0)
956
- return EVENT_ERROR;
1018
+ return TEP_EVENT_ERROR;
9571019
9581020 return type;
9591021
960
- case EVENT_OP:
1022
+ case TEP_EVENT_OP:
9611023 switch (ch) {
9621024 case '-':
963
- next_ch = __peek_char();
1025
+ next_ch = peek_char();
9641026 if (next_ch == '>') {
9651027 buf[i++] = __read_char();
9661028 break;
....@@ -972,7 +1034,7 @@
9721034 case '>':
9731035 case '<':
9741036 last_ch = ch;
975
- ch = __peek_char();
1037
+ ch = peek_char();
9761038 if (ch != last_ch)
9771039 goto test_equal;
9781040 buf[i++] = __read_char();
....@@ -995,13 +1057,13 @@
9951057 return type;
9961058
9971059 test_equal:
998
- ch = __peek_char();
1060
+ ch = peek_char();
9991061 if (ch == '=')
10001062 buf[i++] = __read_char();
10011063 goto out;
10021064
1003
- case EVENT_DQUOTE:
1004
- case EVENT_SQUOTE:
1065
+ case TEP_EVENT_DQUOTE:
1066
+ case TEP_EVENT_SQUOTE:
10051067 /* don't keep quotes */
10061068 i--;
10071069 quote_ch = ch;
....@@ -1013,7 +1075,7 @@
10131075 tok_size += BUFSIZ;
10141076
10151077 if (extend_token(tok, buf, tok_size) < 0)
1016
- return EVENT_NONE;
1078
+ return TEP_EVENT_NONE;
10171079 i = 0;
10181080 }
10191081 last_ch = ch;
....@@ -1030,7 +1092,7 @@
10301092 * For strings (double quotes) check the next token.
10311093 * If it is another string, concatinate the two.
10321094 */
1033
- if (type == EVENT_DQUOTE) {
1095
+ if (type == TEP_EVENT_DQUOTE) {
10341096 unsigned long long save_input_buf_ptr = input_buf_ptr;
10351097
10361098 do {
....@@ -1043,19 +1105,19 @@
10431105
10441106 goto out;
10451107
1046
- case EVENT_ERROR ... EVENT_SPACE:
1047
- case EVENT_ITEM:
1108
+ case TEP_EVENT_ERROR ... TEP_EVENT_SPACE:
1109
+ case TEP_EVENT_ITEM:
10481110 default:
10491111 break;
10501112 }
10511113
1052
- while (get_type(__peek_char()) == type) {
1114
+ while (get_type(peek_char()) == type) {
10531115 if (i == (BUFSIZ - 1)) {
10541116 buf[i] = 0;
10551117 tok_size += BUFSIZ;
10561118
10571119 if (extend_token(tok, buf, tok_size) < 0)
1058
- return EVENT_NONE;
1120
+ return TEP_EVENT_NONE;
10591121 i = 0;
10601122 }
10611123 ch = __read_char();
....@@ -1065,9 +1127,9 @@
10651127 out:
10661128 buf[i] = 0;
10671129 if (extend_token(tok, buf, tok_size + i + 1) < 0)
1068
- return EVENT_NONE;
1130
+ return TEP_EVENT_NONE;
10691131
1070
- if (type == EVENT_ITEM) {
1132
+ if (type == TEP_EVENT_ITEM) {
10711133 /*
10721134 * Older versions of the kernel has a bug that
10731135 * creates invalid symbols and will break the mac80211
....@@ -1094,12 +1156,12 @@
10941156 return type;
10951157 }
10961158
1097
-static enum event_type force_token(const char *str, char **tok)
1159
+static enum tep_event_type force_token(const char *str, char **tok)
10981160 {
10991161 const char *save_input_buf;
11001162 unsigned long long save_input_buf_ptr;
11011163 unsigned long long save_input_buf_siz;
1102
- enum event_type type;
1164
+ enum tep_event_type type;
11031165
11041166 /* save off the current input pointers */
11051167 save_input_buf = input_buf;
....@@ -1118,31 +1180,18 @@
11181180 return type;
11191181 }
11201182
1121
-static void free_token(char *tok)
1183
+/**
1184
+ * free_token - free a token returned by tep_read_token
1185
+ * @token: the token to free
1186
+ */
1187
+__hidden void free_token(char *tok)
11221188 {
11231189 if (tok)
11241190 free(tok);
11251191 }
11261192
1127
-static enum event_type read_token(char **tok)
1128
-{
1129
- enum event_type type;
1130
-
1131
- for (;;) {
1132
- type = __read_token(tok);
1133
- if (type != EVENT_SPACE)
1134
- return type;
1135
-
1136
- free_token(*tok);
1137
- }
1138
-
1139
- /* not reached */
1140
- *tok = NULL;
1141
- return EVENT_NONE;
1142
-}
1143
-
11441193 /**
1145
- * tep_read_token - access to utilites to use the pevent parser
1194
+ * read_token - access to utilities to use the tep parser
11461195 * @tok: The token to return
11471196 *
11481197 * This will parse tokens from the string given by
....@@ -1150,28 +1199,31 @@
11501199 *
11511200 * Returns the token type.
11521201 */
1153
-enum event_type tep_read_token(char **tok)
1202
+__hidden enum tep_event_type read_token(char **tok)
11541203 {
1155
- return read_token(tok);
1156
-}
1157
-
1158
-/**
1159
- * tep_free_token - free a token returned by tep_read_token
1160
- * @token: the token to free
1161
- */
1162
-void tep_free_token(char *token)
1163
-{
1164
- free_token(token);
1165
-}
1166
-
1167
-/* no newline */
1168
-static enum event_type read_token_item(char **tok)
1169
-{
1170
- enum event_type type;
1204
+ enum tep_event_type type;
11711205
11721206 for (;;) {
11731207 type = __read_token(tok);
1174
- if (type != EVENT_SPACE && type != EVENT_NEWLINE)
1208
+ if (type != TEP_EVENT_SPACE)
1209
+ return type;
1210
+
1211
+ free_token(*tok);
1212
+ }
1213
+
1214
+ /* not reached */
1215
+ *tok = NULL;
1216
+ return TEP_EVENT_NONE;
1217
+}
1218
+
1219
+/* no newline */
1220
+static enum tep_event_type read_token_item(char **tok)
1221
+{
1222
+ enum tep_event_type type;
1223
+
1224
+ for (;;) {
1225
+ type = __read_token(tok);
1226
+ if (type != TEP_EVENT_SPACE && type != TEP_EVENT_NEWLINE)
11751227 return type;
11761228 free_token(*tok);
11771229 *tok = NULL;
....@@ -1179,10 +1231,10 @@
11791231
11801232 /* not reached */
11811233 *tok = NULL;
1182
- return EVENT_NONE;
1234
+ return TEP_EVENT_NONE;
11831235 }
11841236
1185
-static int test_type(enum event_type type, enum event_type expect)
1237
+static int test_type(enum tep_event_type type, enum tep_event_type expect)
11861238 {
11871239 if (type != expect) {
11881240 do_warning("Error: expected type %d but read %d",
....@@ -1192,8 +1244,8 @@
11921244 return 0;
11931245 }
11941246
1195
-static int test_type_token(enum event_type type, const char *token,
1196
- enum event_type expect, const char *expect_tok)
1247
+static int test_type_token(enum tep_event_type type, const char *token,
1248
+ enum tep_event_type expect, const char *expect_tok)
11971249 {
11981250 if (type != expect) {
11991251 do_warning("Error: expected type %d but read %d",
....@@ -1209,9 +1261,9 @@
12091261 return 0;
12101262 }
12111263
1212
-static int __read_expect_type(enum event_type expect, char **tok, int newline_ok)
1264
+static int __read_expect_type(enum tep_event_type expect, char **tok, int newline_ok)
12131265 {
1214
- enum event_type type;
1266
+ enum tep_event_type type;
12151267
12161268 if (newline_ok)
12171269 type = read_token(tok);
....@@ -1220,15 +1272,15 @@
12201272 return test_type(type, expect);
12211273 }
12221274
1223
-static int read_expect_type(enum event_type expect, char **tok)
1275
+static int read_expect_type(enum tep_event_type expect, char **tok)
12241276 {
12251277 return __read_expect_type(expect, tok, 1);
12261278 }
12271279
1228
-static int __read_expected(enum event_type expect, const char *str,
1280
+static int __read_expected(enum tep_event_type expect, const char *str,
12291281 int newline_ok)
12301282 {
1231
- enum event_type type;
1283
+ enum tep_event_type type;
12321284 char *token;
12331285 int ret;
12341286
....@@ -1244,12 +1296,12 @@
12441296 return ret;
12451297 }
12461298
1247
-static int read_expected(enum event_type expect, const char *str)
1299
+static int read_expected(enum tep_event_type expect, const char *str)
12481300 {
12491301 return __read_expected(expect, str, 1);
12501302 }
12511303
1252
-static int read_expected_item(enum event_type expect, const char *str)
1304
+static int read_expected_item(enum tep_event_type expect, const char *str)
12531305 {
12541306 return __read_expected(expect, str, 0);
12551307 }
....@@ -1258,13 +1310,13 @@
12581310 {
12591311 char *token;
12601312
1261
- if (read_expected(EVENT_ITEM, "name") < 0)
1313
+ if (read_expected(TEP_EVENT_ITEM, "name") < 0)
12621314 return NULL;
12631315
1264
- if (read_expected(EVENT_OP, ":") < 0)
1316
+ if (read_expected(TEP_EVENT_OP, ":") < 0)
12651317 return NULL;
12661318
1267
- if (read_expect_type(EVENT_ITEM, &token) < 0)
1319
+ if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
12681320 goto fail;
12691321
12701322 return token;
....@@ -1279,13 +1331,13 @@
12791331 char *token;
12801332 int id;
12811333
1282
- if (read_expected_item(EVENT_ITEM, "ID") < 0)
1334
+ if (read_expected_item(TEP_EVENT_ITEM, "ID") < 0)
12831335 return -1;
12841336
1285
- if (read_expected(EVENT_OP, ":") < 0)
1337
+ if (read_expected(TEP_EVENT_OP, ":") < 0)
12861338 return -1;
12871339
1288
- if (read_expect_type(EVENT_ITEM, &token) < 0)
1340
+ if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
12891341 goto fail;
12901342
12911343 id = strtoul(token, NULL, 0);
....@@ -1297,9 +1349,9 @@
12971349 return -1;
12981350 }
12991351
1300
-static int field_is_string(struct format_field *field)
1352
+static int field_is_string(struct tep_format_field *field)
13011353 {
1302
- if ((field->flags & FIELD_IS_ARRAY) &&
1354
+ if ((field->flags & TEP_FIELD_IS_ARRAY) &&
13031355 (strstr(field->type, "char") || strstr(field->type, "u8") ||
13041356 strstr(field->type, "s8")))
13051357 return 1;
....@@ -1307,7 +1359,7 @@
13071359 return 0;
13081360 }
13091361
1310
-static int field_is_dynamic(struct format_field *field)
1362
+static int field_is_dynamic(struct tep_format_field *field)
13111363 {
13121364 if (strncmp(field->type, "__data_loc", 10) == 0)
13131365 return 1;
....@@ -1315,7 +1367,7 @@
13151367 return 0;
13161368 }
13171369
1318
-static int field_is_long(struct format_field *field)
1370
+static int field_is_long(struct tep_format_field *field)
13191371 {
13201372 /* includes long long */
13211373 if (strstr(field->type, "long"))
....@@ -1326,7 +1378,7 @@
13261378
13271379 static unsigned int type_size(const char *name)
13281380 {
1329
- /* This covers all FIELD_IS_STRING types. */
1381
+ /* This covers all TEP_FIELD_IS_STRING types. */
13301382 static struct {
13311383 const char *type;
13321384 unsigned int size;
....@@ -1352,26 +1404,41 @@
13521404 return 0;
13531405 }
13541406
1355
-static int event_read_fields(struct event_format *event, struct format_field **fields)
1407
+static int append(char **buf, const char *delim, const char *str)
13561408 {
1357
- struct format_field *field = NULL;
1358
- enum event_type type;
1409
+ char *new_buf;
1410
+
1411
+ new_buf = realloc(*buf, strlen(*buf) + strlen(delim) + strlen(str) + 1);
1412
+ if (!new_buf)
1413
+ return -1;
1414
+ strcat(new_buf, delim);
1415
+ strcat(new_buf, str);
1416
+ *buf = new_buf;
1417
+ return 0;
1418
+}
1419
+
1420
+static int event_read_fields(struct tep_event *event, struct tep_format_field **fields)
1421
+{
1422
+ struct tep_format_field *field = NULL;
1423
+ enum tep_event_type type;
13591424 char *token;
13601425 char *last_token;
1426
+ char *delim = " ";
13611427 int count = 0;
1428
+ int ret;
13621429
13631430 do {
13641431 unsigned int size_dynamic = 0;
13651432
13661433 type = read_token(&token);
1367
- if (type == EVENT_NEWLINE) {
1434
+ if (type == TEP_EVENT_NEWLINE) {
13681435 free_token(token);
13691436 return count;
13701437 }
13711438
13721439 count++;
13731440
1374
- if (test_type_token(type, token, EVENT_ITEM, "field"))
1441
+ if (test_type_token(type, token, TEP_EVENT_ITEM, "field"))
13751442 goto fail;
13761443 free_token(token);
13771444
....@@ -1380,17 +1447,17 @@
13801447 * The ftrace fields may still use the "special" name.
13811448 * Just ignore it.
13821449 */
1383
- if (event->flags & EVENT_FL_ISFTRACE &&
1384
- type == EVENT_ITEM && strcmp(token, "special") == 0) {
1450
+ if (event->flags & TEP_EVENT_FL_ISFTRACE &&
1451
+ type == TEP_EVENT_ITEM && strcmp(token, "special") == 0) {
13851452 free_token(token);
13861453 type = read_token(&token);
13871454 }
13881455
1389
- if (test_type_token(type, token, EVENT_OP, ":") < 0)
1456
+ if (test_type_token(type, token, TEP_EVENT_OP, ":") < 0)
13901457 goto fail;
13911458
13921459 free_token(token);
1393
- if (read_expect_type(EVENT_ITEM, &token) < 0)
1460
+ if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
13941461 goto fail;
13951462
13961463 last_token = token;
....@@ -1404,37 +1471,64 @@
14041471 /* read the rest of the type */
14051472 for (;;) {
14061473 type = read_token(&token);
1407
- if (type == EVENT_ITEM ||
1408
- (type == EVENT_OP && strcmp(token, "*") == 0) ||
1474
+ if (type == TEP_EVENT_ITEM ||
1475
+ (type == TEP_EVENT_OP && strcmp(token, "*") == 0) ||
14091476 /*
14101477 * Some of the ftrace fields are broken and have
14111478 * an illegal "." in them.
14121479 */
1413
- (event->flags & EVENT_FL_ISFTRACE &&
1414
- type == EVENT_OP && strcmp(token, ".") == 0)) {
1480
+ (event->flags & TEP_EVENT_FL_ISFTRACE &&
1481
+ type == TEP_EVENT_OP && strcmp(token, ".") == 0)) {
14151482
14161483 if (strcmp(token, "*") == 0)
1417
- field->flags |= FIELD_IS_POINTER;
1484
+ field->flags |= TEP_FIELD_IS_POINTER;
14181485
14191486 if (field->type) {
1420
- char *new_type;
1421
- new_type = realloc(field->type,
1422
- strlen(field->type) +
1423
- strlen(last_token) + 2);
1424
- if (!new_type) {
1425
- free(last_token);
1426
- goto fail;
1427
- }
1428
- field->type = new_type;
1429
- strcat(field->type, " ");
1430
- strcat(field->type, last_token);
1487
+ ret = append(&field->type, delim, last_token);
14311488 free(last_token);
1489
+ if (ret < 0)
1490
+ goto fail;
14321491 } else
14331492 field->type = last_token;
14341493 last_token = token;
1494
+ delim = " ";
14351495 continue;
14361496 }
14371497
1498
+ /* Handle __attribute__((user)) */
1499
+ if ((type == TEP_EVENT_DELIM) &&
1500
+ strcmp("__attribute__", last_token) == 0 &&
1501
+ token[0] == '(') {
1502
+ int depth = 1;
1503
+ int ret;
1504
+
1505
+ ret = append(&field->type, " ", last_token);
1506
+ ret |= append(&field->type, "", "(");
1507
+ if (ret < 0)
1508
+ goto fail;
1509
+
1510
+ delim = " ";
1511
+ while ((type = read_token(&token)) != TEP_EVENT_NONE) {
1512
+ if (type == TEP_EVENT_DELIM) {
1513
+ if (token[0] == '(')
1514
+ depth++;
1515
+ else if (token[0] == ')')
1516
+ depth--;
1517
+ if (!depth)
1518
+ break;
1519
+ ret = append(&field->type, "", token);
1520
+ delim = "";
1521
+ } else {
1522
+ ret = append(&field->type, delim, token);
1523
+ delim = " ";
1524
+ }
1525
+ if (ret < 0)
1526
+ goto fail;
1527
+ free(last_token);
1528
+ last_token = token;
1529
+ }
1530
+ continue;
1531
+ }
14381532 break;
14391533 }
14401534
....@@ -1444,48 +1538,44 @@
14441538 }
14451539 field->name = field->alias = last_token;
14461540
1447
- if (test_type(type, EVENT_OP))
1541
+ if (test_type(type, TEP_EVENT_OP))
14481542 goto fail;
14491543
14501544 if (strcmp(token, "[") == 0) {
1451
- enum event_type last_type = type;
1545
+ enum tep_event_type last_type = type;
14521546 char *brackets = token;
1453
- char *new_brackets;
1454
- int len;
14551547
1456
- field->flags |= FIELD_IS_ARRAY;
1548
+ field->flags |= TEP_FIELD_IS_ARRAY;
14571549
14581550 type = read_token(&token);
14591551
1460
- if (type == EVENT_ITEM)
1552
+ if (type == TEP_EVENT_ITEM)
14611553 field->arraylen = strtoul(token, NULL, 0);
14621554 else
14631555 field->arraylen = 0;
14641556
14651557 while (strcmp(token, "]") != 0) {
1466
- if (last_type == EVENT_ITEM &&
1467
- type == EVENT_ITEM)
1468
- len = 2;
1558
+ const char *delim;
1559
+
1560
+ if (last_type == TEP_EVENT_ITEM &&
1561
+ type == TEP_EVENT_ITEM)
1562
+ delim = " ";
14691563 else
1470
- len = 1;
1564
+ delim = "";
1565
+
14711566 last_type = type;
14721567
1473
- new_brackets = realloc(brackets,
1474
- strlen(brackets) +
1475
- strlen(token) + len);
1476
- if (!new_brackets) {
1568
+ ret = append(&brackets, delim, token);
1569
+ if (ret < 0) {
14771570 free(brackets);
14781571 goto fail;
14791572 }
1480
- brackets = new_brackets;
1481
- if (len == 2)
1482
- strcat(brackets, " ");
1483
- strcat(brackets, token);
14841573 /* We only care about the last token */
14851574 field->arraylen = strtoul(token, NULL, 0);
14861575 free_token(token);
14871576 type = read_token(&token);
1488
- if (type == EVENT_NONE) {
1577
+ if (type == TEP_EVENT_NONE) {
1578
+ free(brackets);
14891579 do_warning_event(event, "failed to find token");
14901580 goto fail;
14911581 }
....@@ -1493,13 +1583,11 @@
14931583
14941584 free_token(token);
14951585
1496
- new_brackets = realloc(brackets, strlen(brackets) + 2);
1497
- if (!new_brackets) {
1586
+ ret = append(&brackets, "", "]");
1587
+ if (ret < 0) {
14981588 free(brackets);
14991589 goto fail;
15001590 }
1501
- brackets = new_brackets;
1502
- strcat(brackets, "]");
15031591
15041592 /* add brackets to type */
15051593
....@@ -1508,115 +1596,104 @@
15081596 * If the next token is not an OP, then it is of
15091597 * the format: type [] item;
15101598 */
1511
- if (type == EVENT_ITEM) {
1512
- char *new_type;
1513
- new_type = realloc(field->type,
1514
- strlen(field->type) +
1515
- strlen(field->name) +
1516
- strlen(brackets) + 2);
1517
- if (!new_type) {
1599
+ if (type == TEP_EVENT_ITEM) {
1600
+ ret = append(&field->type, " ", field->name);
1601
+ if (ret < 0) {
15181602 free(brackets);
15191603 goto fail;
15201604 }
1521
- field->type = new_type;
1522
- strcat(field->type, " ");
1523
- strcat(field->type, field->name);
1605
+ ret = append(&field->type, "", brackets);
1606
+
15241607 size_dynamic = type_size(field->name);
15251608 free_token(field->name);
1526
- strcat(field->type, brackets);
15271609 field->name = field->alias = token;
15281610 type = read_token(&token);
15291611 } else {
1530
- char *new_type;
1531
- new_type = realloc(field->type,
1532
- strlen(field->type) +
1533
- strlen(brackets) + 1);
1534
- if (!new_type) {
1612
+ ret = append(&field->type, "", brackets);
1613
+ if (ret < 0) {
15351614 free(brackets);
15361615 goto fail;
15371616 }
1538
- field->type = new_type;
1539
- strcat(field->type, brackets);
15401617 }
15411618 free(brackets);
15421619 }
15431620
15441621 if (field_is_string(field))
1545
- field->flags |= FIELD_IS_STRING;
1622
+ field->flags |= TEP_FIELD_IS_STRING;
15461623 if (field_is_dynamic(field))
1547
- field->flags |= FIELD_IS_DYNAMIC;
1624
+ field->flags |= TEP_FIELD_IS_DYNAMIC;
15481625 if (field_is_long(field))
1549
- field->flags |= FIELD_IS_LONG;
1626
+ field->flags |= TEP_FIELD_IS_LONG;
15501627
1551
- if (test_type_token(type, token, EVENT_OP, ";"))
1628
+ if (test_type_token(type, token, TEP_EVENT_OP, ";"))
15521629 goto fail;
15531630 free_token(token);
15541631
1555
- if (read_expected(EVENT_ITEM, "offset") < 0)
1632
+ if (read_expected(TEP_EVENT_ITEM, "offset") < 0)
15561633 goto fail_expect;
15571634
1558
- if (read_expected(EVENT_OP, ":") < 0)
1635
+ if (read_expected(TEP_EVENT_OP, ":") < 0)
15591636 goto fail_expect;
15601637
1561
- if (read_expect_type(EVENT_ITEM, &token))
1638
+ if (read_expect_type(TEP_EVENT_ITEM, &token))
15621639 goto fail;
15631640 field->offset = strtoul(token, NULL, 0);
15641641 free_token(token);
15651642
1566
- if (read_expected(EVENT_OP, ";") < 0)
1643
+ if (read_expected(TEP_EVENT_OP, ";") < 0)
15671644 goto fail_expect;
15681645
1569
- if (read_expected(EVENT_ITEM, "size") < 0)
1646
+ if (read_expected(TEP_EVENT_ITEM, "size") < 0)
15701647 goto fail_expect;
15711648
1572
- if (read_expected(EVENT_OP, ":") < 0)
1649
+ if (read_expected(TEP_EVENT_OP, ":") < 0)
15731650 goto fail_expect;
15741651
1575
- if (read_expect_type(EVENT_ITEM, &token))
1652
+ if (read_expect_type(TEP_EVENT_ITEM, &token))
15761653 goto fail;
15771654 field->size = strtoul(token, NULL, 0);
15781655 free_token(token);
15791656
1580
- if (read_expected(EVENT_OP, ";") < 0)
1657
+ if (read_expected(TEP_EVENT_OP, ";") < 0)
15811658 goto fail_expect;
15821659
15831660 type = read_token(&token);
1584
- if (type != EVENT_NEWLINE) {
1661
+ if (type != TEP_EVENT_NEWLINE) {
15851662 /* newer versions of the kernel have a "signed" type */
1586
- if (test_type_token(type, token, EVENT_ITEM, "signed"))
1663
+ if (test_type_token(type, token, TEP_EVENT_ITEM, "signed"))
15871664 goto fail;
15881665
15891666 free_token(token);
15901667
1591
- if (read_expected(EVENT_OP, ":") < 0)
1668
+ if (read_expected(TEP_EVENT_OP, ":") < 0)
15921669 goto fail_expect;
15931670
1594
- if (read_expect_type(EVENT_ITEM, &token))
1671
+ if (read_expect_type(TEP_EVENT_ITEM, &token))
15951672 goto fail;
15961673
15971674 if (strtoul(token, NULL, 0))
1598
- field->flags |= FIELD_IS_SIGNED;
1675
+ field->flags |= TEP_FIELD_IS_SIGNED;
15991676
16001677 free_token(token);
1601
- if (read_expected(EVENT_OP, ";") < 0)
1678
+ if (read_expected(TEP_EVENT_OP, ";") < 0)
16021679 goto fail_expect;
16031680
1604
- if (read_expect_type(EVENT_NEWLINE, &token))
1681
+ if (read_expect_type(TEP_EVENT_NEWLINE, &token))
16051682 goto fail;
16061683 }
16071684
16081685 free_token(token);
16091686
1610
- if (field->flags & FIELD_IS_ARRAY) {
1687
+ if (field->flags & TEP_FIELD_IS_ARRAY) {
16111688 if (field->arraylen)
16121689 field->elementsize = field->size / field->arraylen;
1613
- else if (field->flags & FIELD_IS_DYNAMIC)
1690
+ else if (field->flags & TEP_FIELD_IS_DYNAMIC)
16141691 field->elementsize = size_dynamic;
1615
- else if (field->flags & FIELD_IS_STRING)
1692
+ else if (field->flags & TEP_FIELD_IS_STRING)
16161693 field->elementsize = 1;
1617
- else if (field->flags & FIELD_IS_LONG)
1618
- field->elementsize = event->pevent ?
1619
- event->pevent->long_size :
1694
+ else if (field->flags & TEP_FIELD_IS_LONG)
1695
+ field->elementsize = event->tep ?
1696
+ event->tep->long_size :
16201697 sizeof(long);
16211698 } else
16221699 field->elementsize = field->size;
....@@ -1639,18 +1716,18 @@
16391716 return -1;
16401717 }
16411718
1642
-static int event_read_format(struct event_format *event)
1719
+static int event_read_format(struct tep_event *event)
16431720 {
16441721 char *token;
16451722 int ret;
16461723
1647
- if (read_expected_item(EVENT_ITEM, "format") < 0)
1724
+ if (read_expected_item(TEP_EVENT_ITEM, "format") < 0)
16481725 return -1;
16491726
1650
- if (read_expected(EVENT_OP, ":") < 0)
1727
+ if (read_expected(TEP_EVENT_OP, ":") < 0)
16511728 return -1;
16521729
1653
- if (read_expect_type(EVENT_NEWLINE, &token))
1730
+ if (read_expect_type(TEP_EVENT_NEWLINE, &token))
16541731 goto fail;
16551732 free_token(token);
16561733
....@@ -1671,14 +1748,14 @@
16711748 return -1;
16721749 }
16731750
1674
-static enum event_type
1675
-process_arg_token(struct event_format *event, struct print_arg *arg,
1676
- char **tok, enum event_type type);
1751
+static enum tep_event_type
1752
+process_arg_token(struct tep_event *event, struct tep_print_arg *arg,
1753
+ char **tok, enum tep_event_type type);
16771754
1678
-static enum event_type
1679
-process_arg(struct event_format *event, struct print_arg *arg, char **tok)
1755
+static enum tep_event_type
1756
+process_arg(struct tep_event *event, struct tep_print_arg *arg, char **tok)
16801757 {
1681
- enum event_type type;
1758
+ enum tep_event_type type;
16821759 char *token;
16831760
16841761 type = read_token(&token);
....@@ -1687,32 +1764,32 @@
16871764 return process_arg_token(event, arg, tok, type);
16881765 }
16891766
1690
-static enum event_type
1691
-process_op(struct event_format *event, struct print_arg *arg, char **tok);
1767
+static enum tep_event_type
1768
+process_op(struct tep_event *event, struct tep_print_arg *arg, char **tok);
16921769
16931770 /*
16941771 * For __print_symbolic() and __print_flags, we need to completely
16951772 * evaluate the first argument, which defines what to print next.
16961773 */
1697
-static enum event_type
1698
-process_field_arg(struct event_format *event, struct print_arg *arg, char **tok)
1774
+static enum tep_event_type
1775
+process_field_arg(struct tep_event *event, struct tep_print_arg *arg, char **tok)
16991776 {
1700
- enum event_type type;
1777
+ enum tep_event_type type;
17011778
17021779 type = process_arg(event, arg, tok);
17031780
1704
- while (type == EVENT_OP) {
1781
+ while (type == TEP_EVENT_OP) {
17051782 type = process_op(event, arg, tok);
17061783 }
17071784
17081785 return type;
17091786 }
17101787
1711
-static enum event_type
1712
-process_cond(struct event_format *event, struct print_arg *top, char **tok)
1788
+static enum tep_event_type
1789
+process_cond(struct tep_event *event, struct tep_print_arg *top, char **tok)
17131790 {
1714
- struct print_arg *arg, *left, *right;
1715
- enum event_type type;
1791
+ struct tep_print_arg *arg, *left, *right;
1792
+ enum tep_event_type type;
17161793 char *token = NULL;
17171794
17181795 arg = alloc_arg();
....@@ -1727,7 +1804,7 @@
17271804 goto out_free;
17281805 }
17291806
1730
- arg->type = PRINT_OP;
1807
+ arg->type = TEP_PRINT_OP;
17311808 arg->op.left = left;
17321809 arg->op.right = right;
17331810
....@@ -1735,16 +1812,16 @@
17351812 type = process_arg(event, left, &token);
17361813
17371814 again:
1738
- if (type == EVENT_ERROR)
1815
+ if (type == TEP_EVENT_ERROR)
17391816 goto out_free;
17401817
17411818 /* Handle other operations in the arguments */
1742
- if (type == EVENT_OP && strcmp(token, ":") != 0) {
1819
+ if (type == TEP_EVENT_OP && strcmp(token, ":") != 0) {
17431820 type = process_op(event, left, &token);
17441821 goto again;
17451822 }
17461823
1747
- if (test_type_token(type, token, EVENT_OP, ":"))
1824
+ if (test_type_token(type, token, TEP_EVENT_OP, ":"))
17481825 goto out_free;
17491826
17501827 arg->op.op = token;
....@@ -1761,14 +1838,14 @@
17611838 top->op.right = NULL;
17621839 free_token(token);
17631840 free_arg(arg);
1764
- return EVENT_ERROR;
1841
+ return TEP_EVENT_ERROR;
17651842 }
17661843
1767
-static enum event_type
1768
-process_array(struct event_format *event, struct print_arg *top, char **tok)
1844
+static enum tep_event_type
1845
+process_array(struct tep_event *event, struct tep_print_arg *top, char **tok)
17691846 {
1770
- struct print_arg *arg;
1771
- enum event_type type;
1847
+ struct tep_print_arg *arg;
1848
+ enum tep_event_type type;
17721849 char *token = NULL;
17731850
17741851 arg = alloc_arg();
....@@ -1776,12 +1853,12 @@
17761853 do_warning_event(event, "%s: not enough memory!", __func__);
17771854 /* '*tok' is set to top->op.op. No need to free. */
17781855 *tok = NULL;
1779
- return EVENT_ERROR;
1856
+ return TEP_EVENT_ERROR;
17801857 }
17811858
17821859 *tok = NULL;
17831860 type = process_arg(event, arg, &token);
1784
- if (test_type_token(type, token, EVENT_OP, "]"))
1861
+ if (test_type_token(type, token, TEP_EVENT_OP, "]"))
17851862 goto out_free;
17861863
17871864 top->op.right = arg;
....@@ -1795,7 +1872,7 @@
17951872 out_free:
17961873 free_token(token);
17971874 free_arg(arg);
1798
- return EVENT_ERROR;
1875
+ return TEP_EVENT_ERROR;
17991876 }
18001877
18011878 static int get_op_prio(char *op)
....@@ -1853,11 +1930,11 @@
18531930 }
18541931 }
18551932
1856
-static int set_op_prio(struct print_arg *arg)
1933
+static int set_op_prio(struct tep_print_arg *arg)
18571934 {
18581935
18591936 /* single ops are the greatest */
1860
- if (!arg->op.left || arg->op.left->type == PRINT_NULL)
1937
+ if (!arg->op.left || arg->op.left->type == TEP_PRINT_NULL)
18611938 arg->op.prio = 0;
18621939 else
18631940 arg->op.prio = get_op_prio(arg->op.op);
....@@ -1866,17 +1943,17 @@
18661943 }
18671944
18681945 /* Note, *tok does not get freed, but will most likely be saved */
1869
-static enum event_type
1870
-process_op(struct event_format *event, struct print_arg *arg, char **tok)
1946
+static enum tep_event_type
1947
+process_op(struct tep_event *event, struct tep_print_arg *arg, char **tok)
18711948 {
1872
- struct print_arg *left, *right = NULL;
1873
- enum event_type type;
1949
+ struct tep_print_arg *left, *right = NULL;
1950
+ enum tep_event_type type;
18741951 char *token;
18751952
18761953 /* the op is passed in via tok */
18771954 token = *tok;
18781955
1879
- if (arg->type == PRINT_OP && !arg->op.left) {
1956
+ if (arg->type == TEP_PRINT_OP && !arg->op.left) {
18801957 /* handle single op */
18811958 if (token[1]) {
18821959 do_warning_event(event, "bad op token %s", token);
....@@ -1899,7 +1976,7 @@
18991976 if (!left)
19001977 goto out_warn_free;
19011978
1902
- left->type = PRINT_NULL;
1979
+ left->type = TEP_PRINT_NULL;
19031980 arg->op.left = left;
19041981
19051982 right = alloc_arg();
....@@ -1921,7 +1998,7 @@
19211998 /* copy the top arg to the left */
19221999 *left = *arg;
19232000
1924
- arg->type = PRINT_OP;
2001
+ arg->type = TEP_PRINT_OP;
19252002 arg->op.op = token;
19262003 arg->op.left = left;
19272004 arg->op.prio = 0;
....@@ -1955,13 +2032,13 @@
19552032 /* copy the top arg to the left */
19562033 *left = *arg;
19572034
1958
- arg->type = PRINT_OP;
2035
+ arg->type = TEP_PRINT_OP;
19592036 arg->op.op = token;
19602037 arg->op.left = left;
19612038 arg->op.right = NULL;
19622039
19632040 if (set_op_prio(arg) == -1) {
1964
- event->flags |= EVENT_FL_FAILED;
2041
+ event->flags |= TEP_EVENT_FL_FAILED;
19652042 /* arg->op.op (= token) will be freed at out_free */
19662043 arg->op.op = NULL;
19672044 goto out_free;
....@@ -1972,20 +2049,17 @@
19722049
19732050 /* could just be a type pointer */
19742051 if ((strcmp(arg->op.op, "*") == 0) &&
1975
- type == EVENT_DELIM && (strcmp(token, ")") == 0)) {
1976
- char *new_atom;
2052
+ type == TEP_EVENT_DELIM && (strcmp(token, ")") == 0)) {
2053
+ int ret;
19772054
1978
- if (left->type != PRINT_ATOM) {
2055
+ if (left->type != TEP_PRINT_ATOM) {
19792056 do_warning_event(event, "bad pointer type");
19802057 goto out_free;
19812058 }
1982
- new_atom = realloc(left->atom.atom,
1983
- strlen(left->atom.atom) + 3);
1984
- if (!new_atom)
2059
+ ret = append(&left->atom.atom, " ", "*");
2060
+ if (ret < 0)
19852061 goto out_warn_free;
19862062
1987
- left->atom.atom = new_atom;
1988
- strcat(left->atom.atom, " *");
19892063 free(arg->op.op);
19902064 *arg = *left;
19912065 free(left);
....@@ -1998,16 +2072,16 @@
19982072 goto out_warn_free;
19992073
20002074 type = process_arg_token(event, right, tok, type);
2001
- if (type == EVENT_ERROR) {
2075
+ if (type == TEP_EVENT_ERROR) {
20022076 free_arg(right);
20032077 /* token was freed in process_arg_token() via *tok */
20042078 token = NULL;
20052079 goto out_free;
20062080 }
20072081
2008
- if (right->type == PRINT_OP &&
2082
+ if (right->type == TEP_PRINT_OP &&
20092083 get_op_prio(arg->op.op) < get_op_prio(right->op.op)) {
2010
- struct print_arg tmp;
2084
+ struct tep_print_arg tmp;
20112085
20122086 /* rotate ops according to the priority */
20132087 arg->op.right = right->op.left;
....@@ -2029,7 +2103,7 @@
20292103
20302104 *left = *arg;
20312105
2032
- arg->type = PRINT_OP;
2106
+ arg->type = TEP_PRINT_OP;
20332107 arg->op.op = token;
20342108 arg->op.left = left;
20352109
....@@ -2040,12 +2114,12 @@
20402114
20412115 } else {
20422116 do_warning_event(event, "unknown op '%s'", token);
2043
- event->flags |= EVENT_FL_FAILED;
2117
+ event->flags |= TEP_EVENT_FL_FAILED;
20442118 /* the arg is now the left side */
20452119 goto out_free;
20462120 }
20472121
2048
- if (type == EVENT_OP && strcmp(*tok, ":") != 0) {
2122
+ if (type == TEP_EVENT_OP && strcmp(*tok, ":") != 0) {
20492123 int prio;
20502124
20512125 /* higher prios need to be closer to the root */
....@@ -2064,34 +2138,34 @@
20642138 out_free:
20652139 free_token(token);
20662140 *tok = NULL;
2067
- return EVENT_ERROR;
2141
+ return TEP_EVENT_ERROR;
20682142 }
20692143
2070
-static enum event_type
2071
-process_entry(struct event_format *event __maybe_unused, struct print_arg *arg,
2144
+static enum tep_event_type
2145
+process_entry(struct tep_event *event __maybe_unused, struct tep_print_arg *arg,
20722146 char **tok)
20732147 {
2074
- enum event_type type;
2148
+ enum tep_event_type type;
20752149 char *field;
20762150 char *token;
20772151
2078
- if (read_expected(EVENT_OP, "->") < 0)
2152
+ if (read_expected(TEP_EVENT_OP, "->") < 0)
20792153 goto out_err;
20802154
2081
- if (read_expect_type(EVENT_ITEM, &token) < 0)
2155
+ if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
20822156 goto out_free;
20832157 field = token;
20842158
2085
- arg->type = PRINT_FIELD;
2159
+ arg->type = TEP_PRINT_FIELD;
20862160 arg->field.name = field;
20872161
20882162 if (is_flag_field) {
20892163 arg->field.field = tep_find_any_field(event, arg->field.name);
2090
- arg->field.field->flags |= FIELD_IS_FLAG;
2164
+ arg->field.field->flags |= TEP_FIELD_IS_FLAG;
20912165 is_flag_field = 0;
20922166 } else if (is_symbolic_field) {
20932167 arg->field.field = tep_find_any_field(event, arg->field.name);
2094
- arg->field.field->flags |= FIELD_IS_SYMBOLIC;
2168
+ arg->field.field->flags |= TEP_FIELD_IS_SYMBOLIC;
20952169 is_symbolic_field = 0;
20962170 }
20972171
....@@ -2104,14 +2178,14 @@
21042178 free_token(token);
21052179 out_err:
21062180 *tok = NULL;
2107
- return EVENT_ERROR;
2181
+ return TEP_EVENT_ERROR;
21082182 }
21092183
2110
-static int alloc_and_process_delim(struct event_format *event, char *next_token,
2111
- struct print_arg **print_arg)
2184
+static int alloc_and_process_delim(struct tep_event *event, char *next_token,
2185
+ struct tep_print_arg **print_arg)
21122186 {
2113
- struct print_arg *field;
2114
- enum event_type type;
2187
+ struct tep_print_arg *field;
2188
+ enum tep_event_type type;
21152189 char *token;
21162190 int ret = 0;
21172191
....@@ -2124,7 +2198,7 @@
21242198
21252199 type = process_arg(event, field, &token);
21262200
2127
- if (test_type_token(type, token, EVENT_DELIM, next_token)) {
2201
+ if (test_type_token(type, token, TEP_EVENT_DELIM, next_token)) {
21282202 errno = EINVAL;
21292203 ret = -1;
21302204 free_arg(field);
....@@ -2139,7 +2213,7 @@
21392213 return ret;
21402214 }
21412215
2142
-static char *arg_eval (struct print_arg *arg);
2216
+static char *arg_eval (struct tep_print_arg *arg);
21432217
21442218 static unsigned long long
21452219 eval_type_str(unsigned long long val, const char *type, int pointer)
....@@ -2236,9 +2310,9 @@
22362310 * Try to figure out the type.
22372311 */
22382312 static unsigned long long
2239
-eval_type(unsigned long long val, struct print_arg *arg, int pointer)
2313
+eval_type(unsigned long long val, struct tep_print_arg *arg, int pointer)
22402314 {
2241
- if (arg->type != PRINT_TYPE) {
2315
+ if (arg->type != TEP_PRINT_TYPE) {
22422316 do_warning("expected type argument");
22432317 return 0;
22442318 }
....@@ -2246,22 +2320,22 @@
22462320 return eval_type_str(val, arg->typecast.type, pointer);
22472321 }
22482322
2249
-static int arg_num_eval(struct print_arg *arg, long long *val)
2323
+static int arg_num_eval(struct tep_print_arg *arg, long long *val)
22502324 {
22512325 long long left, right;
22522326 int ret = 1;
22532327
22542328 switch (arg->type) {
2255
- case PRINT_ATOM:
2329
+ case TEP_PRINT_ATOM:
22562330 *val = strtoll(arg->atom.atom, NULL, 0);
22572331 break;
2258
- case PRINT_TYPE:
2332
+ case TEP_PRINT_TYPE:
22592333 ret = arg_num_eval(arg->typecast.item, val);
22602334 if (!ret)
22612335 break;
22622336 *val = eval_type(*val, arg, 0);
22632337 break;
2264
- case PRINT_OP:
2338
+ case TEP_PRINT_OP:
22652339 switch (arg->op.op[0]) {
22662340 case '|':
22672341 ret = arg_num_eval(arg->op.left, &left);
....@@ -2364,7 +2438,7 @@
23642438 break;
23652439 case '-':
23662440 /* check for negative */
2367
- if (arg->op.left->type == PRINT_NULL)
2441
+ if (arg->op.left->type == TEP_PRINT_NULL)
23682442 left = 0;
23692443 else
23702444 ret = arg_num_eval(arg->op.left, &left);
....@@ -2376,7 +2450,7 @@
23762450 *val = left - right;
23772451 break;
23782452 case '+':
2379
- if (arg->op.left->type == PRINT_NULL)
2453
+ if (arg->op.left->type == TEP_PRINT_NULL)
23802454 left = 0;
23812455 else
23822456 ret = arg_num_eval(arg->op.left, &left);
....@@ -2399,11 +2473,11 @@
23992473 }
24002474 break;
24012475
2402
- case PRINT_NULL:
2403
- case PRINT_FIELD ... PRINT_SYMBOL:
2404
- case PRINT_STRING:
2405
- case PRINT_BSTRING:
2406
- case PRINT_BITMASK:
2476
+ case TEP_PRINT_NULL:
2477
+ case TEP_PRINT_FIELD ... TEP_PRINT_SYMBOL:
2478
+ case TEP_PRINT_STRING:
2479
+ case TEP_PRINT_BSTRING:
2480
+ case TEP_PRINT_BITMASK:
24072481 default:
24082482 do_warning("invalid eval type %d", arg->type);
24092483 ret = 0;
....@@ -2412,27 +2486,27 @@
24122486 return ret;
24132487 }
24142488
2415
-static char *arg_eval (struct print_arg *arg)
2489
+static char *arg_eval (struct tep_print_arg *arg)
24162490 {
24172491 long long val;
24182492 static char buf[24];
24192493
24202494 switch (arg->type) {
2421
- case PRINT_ATOM:
2495
+ case TEP_PRINT_ATOM:
24222496 return arg->atom.atom;
2423
- case PRINT_TYPE:
2497
+ case TEP_PRINT_TYPE:
24242498 return arg_eval(arg->typecast.item);
2425
- case PRINT_OP:
2499
+ case TEP_PRINT_OP:
24262500 if (!arg_num_eval(arg, &val))
24272501 break;
24282502 sprintf(buf, "%lld", val);
24292503 return buf;
24302504
2431
- case PRINT_NULL:
2432
- case PRINT_FIELD ... PRINT_SYMBOL:
2433
- case PRINT_STRING:
2434
- case PRINT_BSTRING:
2435
- case PRINT_BITMASK:
2505
+ case TEP_PRINT_NULL:
2506
+ case TEP_PRINT_FIELD ... TEP_PRINT_SYMBOL:
2507
+ case TEP_PRINT_STRING:
2508
+ case TEP_PRINT_BSTRING:
2509
+ case TEP_PRINT_BITMASK:
24362510 default:
24372511 do_warning("invalid eval type %d", arg->type);
24382512 break;
....@@ -2441,19 +2515,19 @@
24412515 return NULL;
24422516 }
24432517
2444
-static enum event_type
2445
-process_fields(struct event_format *event, struct print_flag_sym **list, char **tok)
2518
+static enum tep_event_type
2519
+process_fields(struct tep_event *event, struct tep_print_flag_sym **list, char **tok)
24462520 {
2447
- enum event_type type;
2448
- struct print_arg *arg = NULL;
2449
- struct print_flag_sym *field;
2521
+ enum tep_event_type type;
2522
+ struct tep_print_arg *arg = NULL;
2523
+ struct tep_print_flag_sym *field;
24502524 char *token = *tok;
24512525 char *value;
24522526
24532527 do {
24542528 free_token(token);
24552529 type = read_token_item(&token);
2456
- if (test_type_token(type, token, EVENT_OP, "{"))
2530
+ if (test_type_token(type, token, TEP_EVENT_OP, "{"))
24572531 break;
24582532
24592533 arg = alloc_arg();
....@@ -2463,13 +2537,13 @@
24632537 free_token(token);
24642538 type = process_arg(event, arg, &token);
24652539
2466
- if (type == EVENT_OP)
2540
+ if (type == TEP_EVENT_OP)
24672541 type = process_op(event, arg, &token);
24682542
2469
- if (type == EVENT_ERROR)
2543
+ if (type == TEP_EVENT_ERROR)
24702544 goto out_free;
24712545
2472
- if (test_type_token(type, token, EVENT_DELIM, ","))
2546
+ if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
24732547 goto out_free;
24742548
24752549 field = calloc(1, sizeof(*field));
....@@ -2490,7 +2564,7 @@
24902564
24912565 free_token(token);
24922566 type = process_arg(event, arg, &token);
2493
- if (test_type_token(type, token, EVENT_OP, "}"))
2567
+ if (test_type_token(type, token, TEP_EVENT_OP, "}"))
24942568 goto out_free_field;
24952569
24962570 value = arg_eval(arg);
....@@ -2507,7 +2581,7 @@
25072581
25082582 free_token(token);
25092583 type = read_token_item(&token);
2510
- } while (type == EVENT_DELIM && strcmp(token, ",") == 0);
2584
+ } while (type == TEP_EVENT_DELIM && strcmp(token, ",") == 0);
25112585
25122586 *tok = token;
25132587 return type;
....@@ -2519,18 +2593,18 @@
25192593 free_token(token);
25202594 *tok = NULL;
25212595
2522
- return EVENT_ERROR;
2596
+ return TEP_EVENT_ERROR;
25232597 }
25242598
2525
-static enum event_type
2526
-process_flags(struct event_format *event, struct print_arg *arg, char **tok)
2599
+static enum tep_event_type
2600
+process_flags(struct tep_event *event, struct tep_print_arg *arg, char **tok)
25272601 {
2528
- struct print_arg *field;
2529
- enum event_type type;
2602
+ struct tep_print_arg *field;
2603
+ enum tep_event_type type;
25302604 char *token = NULL;
25312605
25322606 memset(arg, 0, sizeof(*arg));
2533
- arg->type = PRINT_FLAGS;
2607
+ arg->type = TEP_PRINT_FLAGS;
25342608
25352609 field = alloc_arg();
25362610 if (!field) {
....@@ -2541,10 +2615,10 @@
25412615 type = process_field_arg(event, field, &token);
25422616
25432617 /* Handle operations in the first argument */
2544
- while (type == EVENT_OP)
2618
+ while (type == TEP_EVENT_OP)
25452619 type = process_op(event, field, &token);
25462620
2547
- if (test_type_token(type, token, EVENT_DELIM, ","))
2621
+ if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
25482622 goto out_free_field;
25492623 free_token(token);
25502624
....@@ -2556,11 +2630,11 @@
25562630 type = read_token_item(&token);
25572631 }
25582632
2559
- if (test_type_token(type, token, EVENT_DELIM, ","))
2633
+ if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
25602634 goto out_free;
25612635
25622636 type = process_fields(event, &arg->flags.flags, &token);
2563
- if (test_type_token(type, token, EVENT_DELIM, ")"))
2637
+ if (test_type_token(type, token, TEP_EVENT_DELIM, ")"))
25642638 goto out_free;
25652639
25662640 free_token(token);
....@@ -2572,18 +2646,18 @@
25722646 out_free:
25732647 free_token(token);
25742648 *tok = NULL;
2575
- return EVENT_ERROR;
2649
+ return TEP_EVENT_ERROR;
25762650 }
25772651
2578
-static enum event_type
2579
-process_symbols(struct event_format *event, struct print_arg *arg, char **tok)
2652
+static enum tep_event_type
2653
+process_symbols(struct tep_event *event, struct tep_print_arg *arg, char **tok)
25802654 {
2581
- struct print_arg *field;
2582
- enum event_type type;
2655
+ struct tep_print_arg *field;
2656
+ enum tep_event_type type;
25832657 char *token = NULL;
25842658
25852659 memset(arg, 0, sizeof(*arg));
2586
- arg->type = PRINT_SYMBOL;
2660
+ arg->type = TEP_PRINT_SYMBOL;
25872661
25882662 field = alloc_arg();
25892663 if (!field) {
....@@ -2593,13 +2667,13 @@
25932667
25942668 type = process_field_arg(event, field, &token);
25952669
2596
- if (test_type_token(type, token, EVENT_DELIM, ","))
2670
+ if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
25972671 goto out_free_field;
25982672
25992673 arg->symbol.field = field;
26002674
26012675 type = process_fields(event, &arg->symbol.symbols, &token);
2602
- if (test_type_token(type, token, EVENT_DELIM, ")"))
2676
+ if (test_type_token(type, token, TEP_EVENT_DELIM, ")"))
26032677 goto out_free;
26042678
26052679 free_token(token);
....@@ -2611,12 +2685,12 @@
26112685 out_free:
26122686 free_token(token);
26132687 *tok = NULL;
2614
- return EVENT_ERROR;
2688
+ return TEP_EVENT_ERROR;
26152689 }
26162690
2617
-static enum event_type
2618
-process_hex_common(struct event_format *event, struct print_arg *arg,
2619
- char **tok, enum print_arg_type type)
2691
+static enum tep_event_type
2692
+process_hex_common(struct tep_event *event, struct tep_print_arg *arg,
2693
+ char **tok, enum tep_print_arg_type type)
26202694 {
26212695 memset(arg, 0, sizeof(*arg));
26222696 arg->type = type;
....@@ -2634,27 +2708,27 @@
26342708 arg->hex.field = NULL;
26352709 out:
26362710 *tok = NULL;
2637
- return EVENT_ERROR;
2711
+ return TEP_EVENT_ERROR;
26382712 }
26392713
2640
-static enum event_type
2641
-process_hex(struct event_format *event, struct print_arg *arg, char **tok)
2714
+static enum tep_event_type
2715
+process_hex(struct tep_event *event, struct tep_print_arg *arg, char **tok)
26422716 {
2643
- return process_hex_common(event, arg, tok, PRINT_HEX);
2717
+ return process_hex_common(event, arg, tok, TEP_PRINT_HEX);
26442718 }
26452719
2646
-static enum event_type
2647
-process_hex_str(struct event_format *event, struct print_arg *arg,
2720
+static enum tep_event_type
2721
+process_hex_str(struct tep_event *event, struct tep_print_arg *arg,
26482722 char **tok)
26492723 {
2650
- return process_hex_common(event, arg, tok, PRINT_HEX_STR);
2724
+ return process_hex_common(event, arg, tok, TEP_PRINT_HEX_STR);
26512725 }
26522726
2653
-static enum event_type
2654
-process_int_array(struct event_format *event, struct print_arg *arg, char **tok)
2727
+static enum tep_event_type
2728
+process_int_array(struct tep_event *event, struct tep_print_arg *arg, char **tok)
26552729 {
26562730 memset(arg, 0, sizeof(*arg));
2657
- arg->type = PRINT_INT_ARRAY;
2731
+ arg->type = TEP_PRINT_INT_ARRAY;
26582732
26592733 if (alloc_and_process_delim(event, ",", &arg->int_array.field))
26602734 goto out;
....@@ -2675,18 +2749,18 @@
26752749 arg->int_array.field = NULL;
26762750 out:
26772751 *tok = NULL;
2678
- return EVENT_ERROR;
2752
+ return TEP_EVENT_ERROR;
26792753 }
26802754
2681
-static enum event_type
2682
-process_dynamic_array(struct event_format *event, struct print_arg *arg, char **tok)
2755
+static enum tep_event_type
2756
+process_dynamic_array(struct tep_event *event, struct tep_print_arg *arg, char **tok)
26832757 {
2684
- struct format_field *field;
2685
- enum event_type type;
2758
+ struct tep_format_field *field;
2759
+ enum tep_event_type type;
26862760 char *token;
26872761
26882762 memset(arg, 0, sizeof(*arg));
2689
- arg->type = PRINT_DYNAMIC_ARRAY;
2763
+ arg->type = TEP_PRINT_DYNAMIC_ARRAY;
26902764
26912765 /*
26922766 * The item within the parenthesis is another field that holds
....@@ -2694,7 +2768,7 @@
26942768 */
26952769 type = read_token(&token);
26962770 *tok = token;
2697
- if (type != EVENT_ITEM)
2771
+ if (type != TEP_EVENT_ITEM)
26982772 goto out_free;
26992773
27002774 /* Find the field */
....@@ -2706,13 +2780,13 @@
27062780 arg->dynarray.field = field;
27072781 arg->dynarray.index = 0;
27082782
2709
- if (read_expected(EVENT_DELIM, ")") < 0)
2783
+ if (read_expected(TEP_EVENT_DELIM, ")") < 0)
27102784 goto out_free;
27112785
27122786 free_token(token);
27132787 type = read_token_item(&token);
27142788 *tok = token;
2715
- if (type != EVENT_OP || strcmp(token, "[") != 0)
2789
+ if (type != TEP_EVENT_OP || strcmp(token, "[") != 0)
27162790 return type;
27172791
27182792 free_token(token);
....@@ -2720,14 +2794,14 @@
27202794 if (!arg) {
27212795 do_warning_event(event, "%s: not enough memory!", __func__);
27222796 *tok = NULL;
2723
- return EVENT_ERROR;
2797
+ return TEP_EVENT_ERROR;
27242798 }
27252799
27262800 type = process_arg(event, arg, &token);
2727
- if (type == EVENT_ERROR)
2801
+ if (type == TEP_EVENT_ERROR)
27282802 goto out_free_arg;
27292803
2730
- if (!test_type_token(type, token, EVENT_OP, "]"))
2804
+ if (!test_type_token(type, token, TEP_EVENT_OP, "]"))
27312805 goto out_free_arg;
27322806
27332807 free_token(token);
....@@ -2739,21 +2813,21 @@
27392813 out_free:
27402814 free_token(token);
27412815 *tok = NULL;
2742
- return EVENT_ERROR;
2816
+ return TEP_EVENT_ERROR;
27432817 }
27442818
2745
-static enum event_type
2746
-process_dynamic_array_len(struct event_format *event, struct print_arg *arg,
2819
+static enum tep_event_type
2820
+process_dynamic_array_len(struct tep_event *event, struct tep_print_arg *arg,
27472821 char **tok)
27482822 {
2749
- struct format_field *field;
2750
- enum event_type type;
2823
+ struct tep_format_field *field;
2824
+ enum tep_event_type type;
27512825 char *token;
27522826
2753
- if (read_expect_type(EVENT_ITEM, &token) < 0)
2827
+ if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
27542828 goto out_free;
27552829
2756
- arg->type = PRINT_DYNAMIC_ARRAY_LEN;
2830
+ arg->type = TEP_PRINT_DYNAMIC_ARRAY_LEN;
27572831
27582832 /* Find the field */
27592833 field = tep_find_field(event, token);
....@@ -2763,7 +2837,7 @@
27632837 arg->dynarray.field = field;
27642838 arg->dynarray.index = 0;
27652839
2766
- if (read_expected(EVENT_DELIM, ")") < 0)
2840
+ if (read_expected(TEP_EVENT_DELIM, ")") < 0)
27672841 goto out_err;
27682842
27692843 free_token(token);
....@@ -2776,28 +2850,28 @@
27762850 free_token(token);
27772851 out_err:
27782852 *tok = NULL;
2779
- return EVENT_ERROR;
2853
+ return TEP_EVENT_ERROR;
27802854 }
27812855
2782
-static enum event_type
2783
-process_paren(struct event_format *event, struct print_arg *arg, char **tok)
2856
+static enum tep_event_type
2857
+process_paren(struct tep_event *event, struct tep_print_arg *arg, char **tok)
27842858 {
2785
- struct print_arg *item_arg;
2786
- enum event_type type;
2859
+ struct tep_print_arg *item_arg;
2860
+ enum tep_event_type type;
27872861 char *token;
27882862
27892863 type = process_arg(event, arg, &token);
27902864
2791
- if (type == EVENT_ERROR)
2865
+ if (type == TEP_EVENT_ERROR)
27922866 goto out_free;
27932867
2794
- if (type == EVENT_OP)
2868
+ if (type == TEP_EVENT_OP)
27952869 type = process_op(event, arg, &token);
27962870
2797
- if (type == EVENT_ERROR)
2871
+ if (type == TEP_EVENT_ERROR)
27982872 goto out_free;
27992873
2800
- if (test_type_token(type, token, EVENT_DELIM, ")"))
2874
+ if (test_type_token(type, token, TEP_EVENT_DELIM, ")"))
28012875 goto out_free;
28022876
28032877 free_token(token);
....@@ -2808,13 +2882,13 @@
28082882 * this was a typecast.
28092883 */
28102884 if (event_item_type(type) ||
2811
- (type == EVENT_DELIM && strcmp(token, "(") == 0)) {
2885
+ (type == TEP_EVENT_DELIM && strcmp(token, "(") == 0)) {
28122886
28132887 /* make this a typecast and contine */
28142888
28152889 /* prevous must be an atom */
2816
- if (arg->type != PRINT_ATOM) {
2817
- do_warning_event(event, "previous needed to be PRINT_ATOM");
2890
+ if (arg->type != TEP_PRINT_ATOM) {
2891
+ do_warning_event(event, "previous needed to be TEP_PRINT_ATOM");
28182892 goto out_free;
28192893 }
28202894
....@@ -2825,7 +2899,7 @@
28252899 goto out_free;
28262900 }
28272901
2828
- arg->type = PRINT_TYPE;
2902
+ arg->type = TEP_PRINT_TYPE;
28292903 arg->typecast.type = arg->atom.atom;
28302904 arg->typecast.item = item_arg;
28312905 type = process_arg_token(event, item_arg, &token, type);
....@@ -2838,25 +2912,25 @@
28382912 out_free:
28392913 free_token(token);
28402914 *tok = NULL;
2841
- return EVENT_ERROR;
2915
+ return TEP_EVENT_ERROR;
28422916 }
28432917
28442918
2845
-static enum event_type
2846
-process_str(struct event_format *event __maybe_unused, struct print_arg *arg,
2919
+static enum tep_event_type
2920
+process_str(struct tep_event *event __maybe_unused, struct tep_print_arg *arg,
28472921 char **tok)
28482922 {
2849
- enum event_type type;
2923
+ enum tep_event_type type;
28502924 char *token;
28512925
2852
- if (read_expect_type(EVENT_ITEM, &token) < 0)
2926
+ if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
28532927 goto out_free;
28542928
2855
- arg->type = PRINT_STRING;
2929
+ arg->type = TEP_PRINT_STRING;
28562930 arg->string.string = token;
28572931 arg->string.offset = -1;
28582932
2859
- if (read_expected(EVENT_DELIM, ")") < 0)
2933
+ if (read_expected(TEP_EVENT_DELIM, ")") < 0)
28602934 goto out_err;
28612935
28622936 type = read_token(&token);
....@@ -2868,24 +2942,24 @@
28682942 free_token(token);
28692943 out_err:
28702944 *tok = NULL;
2871
- return EVENT_ERROR;
2945
+ return TEP_EVENT_ERROR;
28722946 }
28732947
2874
-static enum event_type
2875
-process_bitmask(struct event_format *event __maybe_unused, struct print_arg *arg,
2876
- char **tok)
2948
+static enum tep_event_type
2949
+process_bitmask(struct tep_event *event __maybe_unused, struct tep_print_arg *arg,
2950
+ char **tok)
28772951 {
2878
- enum event_type type;
2952
+ enum tep_event_type type;
28792953 char *token;
28802954
2881
- if (read_expect_type(EVENT_ITEM, &token) < 0)
2955
+ if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
28822956 goto out_free;
28832957
2884
- arg->type = PRINT_BITMASK;
2958
+ arg->type = TEP_PRINT_BITMASK;
28852959 arg->bitmask.bitmask = token;
28862960 arg->bitmask.offset = -1;
28872961
2888
- if (read_expected(EVENT_DELIM, ")") < 0)
2962
+ if (read_expected(TEP_EVENT_DELIM, ")") < 0)
28892963 goto out_err;
28902964
28912965 type = read_token(&token);
....@@ -2897,18 +2971,18 @@
28972971 free_token(token);
28982972 out_err:
28992973 *tok = NULL;
2900
- return EVENT_ERROR;
2974
+ return TEP_EVENT_ERROR;
29012975 }
29022976
29032977 static struct tep_function_handler *
2904
-find_func_handler(struct tep_handle *pevent, char *func_name)
2978
+find_func_handler(struct tep_handle *tep, char *func_name)
29052979 {
29062980 struct tep_function_handler *func;
29072981
2908
- if (!pevent)
2982
+ if (!tep)
29092983 return NULL;
29102984
2911
- for (func = pevent->func_handlers; func; func = func->next) {
2985
+ for (func = tep->func_handlers; func; func = func->next) {
29122986 if (strcmp(func->name, func_name) == 0)
29132987 break;
29142988 }
....@@ -2916,12 +2990,12 @@
29162990 return func;
29172991 }
29182992
2919
-static void remove_func_handler(struct tep_handle *pevent, char *func_name)
2993
+static void remove_func_handler(struct tep_handle *tep, char *func_name)
29202994 {
29212995 struct tep_function_handler *func;
29222996 struct tep_function_handler **next;
29232997
2924
- next = &pevent->func_handlers;
2998
+ next = &tep->func_handlers;
29252999 while ((func = *next)) {
29263000 if (strcmp(func->name, func_name) == 0) {
29273001 *next = func->next;
....@@ -2932,17 +3006,17 @@
29323006 }
29333007 }
29343008
2935
-static enum event_type
2936
-process_func_handler(struct event_format *event, struct tep_function_handler *func,
2937
- struct print_arg *arg, char **tok)
3009
+static enum tep_event_type
3010
+process_func_handler(struct tep_event *event, struct tep_function_handler *func,
3011
+ struct tep_print_arg *arg, char **tok)
29383012 {
2939
- struct print_arg **next_arg;
2940
- struct print_arg *farg;
2941
- enum event_type type;
3013
+ struct tep_print_arg **next_arg;
3014
+ struct tep_print_arg *farg;
3015
+ enum tep_event_type type;
29423016 char *token;
29433017 int i;
29443018
2945
- arg->type = PRINT_FUNC;
3019
+ arg->type = TEP_PRINT_FUNC;
29463020 arg->func.func = func;
29473021
29483022 *tok = NULL;
....@@ -2953,12 +3027,12 @@
29533027 if (!farg) {
29543028 do_warning_event(event, "%s: not enough memory!",
29553029 __func__);
2956
- return EVENT_ERROR;
3030
+ return TEP_EVENT_ERROR;
29573031 }
29583032
29593033 type = process_arg(event, farg, &token);
29603034 if (i < (func->nr_args - 1)) {
2961
- if (type != EVENT_DELIM || strcmp(token, ",") != 0) {
3035
+ if (type != TEP_EVENT_DELIM || strcmp(token, ",") != 0) {
29623036 do_warning_event(event,
29633037 "Error: function '%s()' expects %d arguments but event %s only uses %d",
29643038 func->name, func->nr_args,
....@@ -2966,7 +3040,7 @@
29663040 goto err;
29673041 }
29683042 } else {
2969
- if (type != EVENT_DELIM || strcmp(token, ")") != 0) {
3043
+ if (type != TEP_EVENT_DELIM || strcmp(token, ")") != 0) {
29703044 do_warning_event(event,
29713045 "Error: function '%s()' only expects %d arguments but event %s has more",
29723046 func->name, func->nr_args, event->name);
....@@ -2987,11 +3061,42 @@
29873061 err:
29883062 free_arg(farg);
29893063 free_token(token);
2990
- return EVENT_ERROR;
3064
+ return TEP_EVENT_ERROR;
29913065 }
29923066
2993
-static enum event_type
2994
-process_function(struct event_format *event, struct print_arg *arg,
3067
+static enum tep_event_type
3068
+process_builtin_expect(struct tep_event *event, struct tep_print_arg *arg, char **tok)
3069
+{
3070
+ enum tep_event_type type;
3071
+ char *token = NULL;
3072
+
3073
+ /* Handle __builtin_expect( cond, #) */
3074
+ type = process_arg(event, arg, &token);
3075
+
3076
+ if (type != TEP_EVENT_DELIM || token[0] != ',')
3077
+ goto out_free;
3078
+
3079
+ free_token(token);
3080
+
3081
+ /* We don't care what the second parameter is of the __builtin_expect() */
3082
+ if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
3083
+ goto out_free;
3084
+
3085
+ if (read_expected(TEP_EVENT_DELIM, ")") < 0)
3086
+ goto out_free;
3087
+
3088
+ free_token(token);
3089
+ type = read_token_item(tok);
3090
+ return type;
3091
+
3092
+out_free:
3093
+ free_token(token);
3094
+ *tok = NULL;
3095
+ return TEP_EVENT_ERROR;
3096
+}
3097
+
3098
+static enum tep_event_type
3099
+process_function(struct tep_event *event, struct tep_print_arg *arg,
29953100 char *token, char **tok)
29963101 {
29973102 struct tep_function_handler *func;
....@@ -3034,8 +3139,12 @@
30343139 free_token(token);
30353140 return process_dynamic_array_len(event, arg, tok);
30363141 }
3142
+ if (strcmp(token, "__builtin_expect") == 0) {
3143
+ free_token(token);
3144
+ return process_builtin_expect(event, arg, tok);
3145
+ }
30373146
3038
- func = find_func_handler(event->pevent, token);
3147
+ func = find_func_handler(event->tep, token);
30393148 if (func) {
30403149 free_token(token);
30413150 return process_func_handler(event, func, arg, tok);
....@@ -3043,12 +3152,12 @@
30433152
30443153 do_warning_event(event, "function %s not defined", token);
30453154 free_token(token);
3046
- return EVENT_ERROR;
3155
+ return TEP_EVENT_ERROR;
30473156 }
30483157
3049
-static enum event_type
3050
-process_arg_token(struct event_format *event, struct print_arg *arg,
3051
- char **tok, enum event_type type)
3158
+static enum tep_event_type
3159
+process_arg_token(struct tep_event *event, struct tep_print_arg *arg,
3160
+ char **tok, enum tep_event_type type)
30523161 {
30533162 char *token;
30543163 char *atom;
....@@ -3056,7 +3165,7 @@
30563165 token = *tok;
30573166
30583167 switch (type) {
3059
- case EVENT_ITEM:
3168
+ case TEP_EVENT_ITEM:
30603169 if (strcmp(token, "REC") == 0) {
30613170 free_token(token);
30623171 type = process_entry(event, arg, &token);
....@@ -3070,7 +3179,7 @@
30703179 * If the next token is a parenthesis, then this
30713180 * is a function.
30723181 */
3073
- if (type == EVENT_DELIM && strcmp(token, "(") == 0) {
3182
+ if (type == TEP_EVENT_DELIM && strcmp(token, "(") == 0) {
30743183 free_token(token);
30753184 token = NULL;
30763185 /* this will free atom. */
....@@ -3078,72 +3187,69 @@
30783187 break;
30793188 }
30803189 /* atoms can be more than one token long */
3081
- while (type == EVENT_ITEM) {
3082
- char *new_atom;
3083
- new_atom = realloc(atom,
3084
- strlen(atom) + strlen(token) + 2);
3085
- if (!new_atom) {
3190
+ while (type == TEP_EVENT_ITEM) {
3191
+ int ret;
3192
+
3193
+ ret = append(&atom, " ", token);
3194
+ if (ret < 0) {
30863195 free(atom);
30873196 *tok = NULL;
30883197 free_token(token);
3089
- return EVENT_ERROR;
3198
+ return TEP_EVENT_ERROR;
30903199 }
3091
- atom = new_atom;
3092
- strcat(atom, " ");
3093
- strcat(atom, token);
30943200 free_token(token);
30953201 type = read_token_item(&token);
30963202 }
30973203
3098
- arg->type = PRINT_ATOM;
3204
+ arg->type = TEP_PRINT_ATOM;
30993205 arg->atom.atom = atom;
31003206 break;
31013207
3102
- case EVENT_DQUOTE:
3103
- case EVENT_SQUOTE:
3104
- arg->type = PRINT_ATOM;
3208
+ case TEP_EVENT_DQUOTE:
3209
+ case TEP_EVENT_SQUOTE:
3210
+ arg->type = TEP_PRINT_ATOM;
31053211 arg->atom.atom = token;
31063212 type = read_token_item(&token);
31073213 break;
3108
- case EVENT_DELIM:
3214
+ case TEP_EVENT_DELIM:
31093215 if (strcmp(token, "(") == 0) {
31103216 free_token(token);
31113217 type = process_paren(event, arg, &token);
31123218 break;
31133219 }
3114
- case EVENT_OP:
3220
+ case TEP_EVENT_OP:
31153221 /* handle single ops */
3116
- arg->type = PRINT_OP;
3222
+ arg->type = TEP_PRINT_OP;
31173223 arg->op.op = token;
31183224 arg->op.left = NULL;
31193225 type = process_op(event, arg, &token);
31203226
31213227 /* On error, the op is freed */
3122
- if (type == EVENT_ERROR)
3228
+ if (type == TEP_EVENT_ERROR)
31233229 arg->op.op = NULL;
31243230
31253231 /* return error type if errored */
31263232 break;
31273233
3128
- case EVENT_ERROR ... EVENT_NEWLINE:
3234
+ case TEP_EVENT_ERROR ... TEP_EVENT_NEWLINE:
31293235 default:
31303236 do_warning_event(event, "unexpected type %d", type);
3131
- return EVENT_ERROR;
3237
+ return TEP_EVENT_ERROR;
31323238 }
31333239 *tok = token;
31343240
31353241 return type;
31363242 }
31373243
3138
-static int event_read_print_args(struct event_format *event, struct print_arg **list)
3244
+static int event_read_print_args(struct tep_event *event, struct tep_print_arg **list)
31393245 {
3140
- enum event_type type = EVENT_ERROR;
3141
- struct print_arg *arg;
3246
+ enum tep_event_type type = TEP_EVENT_ERROR;
3247
+ struct tep_print_arg *arg;
31423248 char *token;
31433249 int args = 0;
31443250
31453251 do {
3146
- if (type == EVENT_NEWLINE) {
3252
+ if (type == TEP_EVENT_NEWLINE) {
31473253 type = read_token_item(&token);
31483254 continue;
31493255 }
....@@ -3157,7 +3263,7 @@
31573263
31583264 type = process_arg(event, arg, &token);
31593265
3160
- if (type == EVENT_ERROR) {
3266
+ if (type == TEP_EVENT_ERROR) {
31613267 free_token(token);
31623268 free_arg(arg);
31633269 return -1;
....@@ -3166,10 +3272,10 @@
31663272 *list = arg;
31673273 args++;
31683274
3169
- if (type == EVENT_OP) {
3275
+ if (type == TEP_EVENT_OP) {
31703276 type = process_op(event, arg, &token);
31713277 free_token(token);
3172
- if (type == EVENT_ERROR) {
3278
+ if (type == TEP_EVENT_ERROR) {
31733279 *list = NULL;
31743280 free_arg(arg);
31753281 return -1;
....@@ -3178,37 +3284,37 @@
31783284 continue;
31793285 }
31803286
3181
- if (type == EVENT_DELIM && strcmp(token, ",") == 0) {
3287
+ if (type == TEP_EVENT_DELIM && strcmp(token, ",") == 0) {
31823288 free_token(token);
31833289 *list = arg;
31843290 list = &arg->next;
31853291 continue;
31863292 }
31873293 break;
3188
- } while (type != EVENT_NONE);
3294
+ } while (type != TEP_EVENT_NONE);
31893295
3190
- if (type != EVENT_NONE && type != EVENT_ERROR)
3296
+ if (type != TEP_EVENT_NONE && type != TEP_EVENT_ERROR)
31913297 free_token(token);
31923298
31933299 return args;
31943300 }
31953301
3196
-static int event_read_print(struct event_format *event)
3302
+static int event_read_print(struct tep_event *event)
31973303 {
3198
- enum event_type type;
3304
+ enum tep_event_type type;
31993305 char *token;
32003306 int ret;
32013307
3202
- if (read_expected_item(EVENT_ITEM, "print") < 0)
3308
+ if (read_expected_item(TEP_EVENT_ITEM, "print") < 0)
32033309 return -1;
32043310
3205
- if (read_expected(EVENT_ITEM, "fmt") < 0)
3311
+ if (read_expected(TEP_EVENT_ITEM, "fmt") < 0)
32063312 return -1;
32073313
3208
- if (read_expected(EVENT_OP, ":") < 0)
3314
+ if (read_expected(TEP_EVENT_OP, ":") < 0)
32093315 return -1;
32103316
3211
- if (read_expect_type(EVENT_DQUOTE, &token) < 0)
3317
+ if (read_expect_type(TEP_EVENT_DQUOTE, &token) < 0)
32123318 goto fail;
32133319
32143320 concat:
....@@ -3218,11 +3324,11 @@
32183324 /* ok to have no arg */
32193325 type = read_token_item(&token);
32203326
3221
- if (type == EVENT_NONE)
3327
+ if (type == TEP_EVENT_NONE)
32223328 return 0;
32233329
32243330 /* Handle concatenation of print lines */
3225
- if (type == EVENT_DQUOTE) {
3331
+ if (type == TEP_EVENT_DQUOTE) {
32263332 char *cat;
32273333
32283334 if (asprintf(&cat, "%s%s", event->print_fmt.format, token) < 0)
....@@ -3234,7 +3340,7 @@
32343340 goto concat;
32353341 }
32363342
3237
- if (test_type_token(type, token, EVENT_DELIM, ","))
3343
+ if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
32383344 goto fail;
32393345
32403346 free_token(token);
....@@ -3256,12 +3362,12 @@
32563362 * @name: the name of the common field to return
32573363 *
32583364 * Returns a common field from the event by the given @name.
3259
- * This only searchs the common fields and not all field.
3365
+ * This only searches the common fields and not all field.
32603366 */
3261
-struct format_field *
3262
-tep_find_common_field(struct event_format *event, const char *name)
3367
+struct tep_format_field *
3368
+tep_find_common_field(struct tep_event *event, const char *name)
32633369 {
3264
- struct format_field *format;
3370
+ struct tep_format_field *format;
32653371
32663372 for (format = event->format.common_fields;
32673373 format; format = format->next) {
....@@ -3280,10 +3386,10 @@
32803386 * Returns a non-common field by the given @name.
32813387 * This does not search common fields.
32823388 */
3283
-struct format_field *
3284
-tep_find_field(struct event_format *event, const char *name)
3389
+struct tep_format_field *
3390
+tep_find_field(struct tep_event *event, const char *name)
32853391 {
3286
- struct format_field *format;
3392
+ struct tep_format_field *format;
32873393
32883394 for (format = event->format.fields;
32893395 format; format = format->next) {
....@@ -3300,13 +3406,13 @@
33003406 * @name: the name of the field
33013407 *
33023408 * Returns a field by the given @name.
3303
- * This searchs the common field names first, then
3409
+ * This searches the common field names first, then
33043410 * the non-common ones if a common one was not found.
33053411 */
3306
-struct format_field *
3307
-tep_find_any_field(struct event_format *event, const char *name)
3412
+struct tep_format_field *
3413
+tep_find_any_field(struct tep_event *event, const char *name)
33083414 {
3309
- struct format_field *format;
3415
+ struct tep_format_field *format;
33103416
33113417 format = tep_find_common_field(event, name);
33123418 if (format)
....@@ -3316,25 +3422,28 @@
33163422
33173423 /**
33183424 * tep_read_number - read a number from data
3319
- * @pevent: handle for the pevent
3425
+ * @tep: a handle to the trace event parser context
33203426 * @ptr: the raw data
33213427 * @size: the size of the data that holds the number
33223428 *
33233429 * Returns the number (converted to host) from the
33243430 * raw data.
33253431 */
3326
-unsigned long long tep_read_number(struct tep_handle *pevent,
3432
+unsigned long long tep_read_number(struct tep_handle *tep,
33273433 const void *ptr, int size)
33283434 {
3435
+ unsigned long long val;
3436
+
33293437 switch (size) {
33303438 case 1:
33313439 return *(unsigned char *)ptr;
33323440 case 2:
3333
- return data2host2(pevent, ptr);
3441
+ return data2host2(tep, *(unsigned short *)ptr);
33343442 case 4:
3335
- return data2host4(pevent, ptr);
3443
+ return data2host4(tep, *(unsigned int *)ptr);
33363444 case 8:
3337
- return data2host8(pevent, ptr);
3445
+ memcpy(&val, (ptr), sizeof(unsigned long long));
3446
+ return data2host8(tep, val);
33383447 default:
33393448 /* BUG! */
33403449 return 0;
....@@ -3352,7 +3461,7 @@
33523461 *
33533462 * Returns 0 on success, -1 otherwise.
33543463 */
3355
-int tep_read_number_field(struct format_field *field, const void *data,
3464
+int tep_read_number_field(struct tep_format_field *field, const void *data,
33563465 unsigned long long *value)
33573466 {
33583467 if (!field)
....@@ -3362,7 +3471,7 @@
33623471 case 2:
33633472 case 4:
33643473 case 8:
3365
- *value = tep_read_number(field->event->pevent,
3474
+ *value = tep_read_number(field->event->tep,
33663475 data + field->offset, field->size);
33673476 return 0;
33683477 default:
....@@ -3370,22 +3479,22 @@
33703479 }
33713480 }
33723481
3373
-static int get_common_info(struct tep_handle *pevent,
3482
+static int get_common_info(struct tep_handle *tep,
33743483 const char *type, int *offset, int *size)
33753484 {
3376
- struct event_format *event;
3377
- struct format_field *field;
3485
+ struct tep_event *event;
3486
+ struct tep_format_field *field;
33783487
33793488 /*
33803489 * All events should have the same common elements.
33813490 * Pick any event to find where the type is;
33823491 */
3383
- if (!pevent->events) {
3492
+ if (!tep->events) {
33843493 do_warning("no event_list!");
33853494 return -1;
33863495 }
33873496
3388
- event = pevent->events[0];
3497
+ event = tep->events[0];
33893498 field = tep_find_common_field(event, type);
33903499 if (!field)
33913500 return -1;
....@@ -3396,58 +3505,58 @@
33963505 return 0;
33973506 }
33983507
3399
-static int __parse_common(struct tep_handle *pevent, void *data,
3508
+static int __parse_common(struct tep_handle *tep, void *data,
34003509 int *size, int *offset, const char *name)
34013510 {
34023511 int ret;
34033512
34043513 if (!*size) {
3405
- ret = get_common_info(pevent, name, offset, size);
3514
+ ret = get_common_info(tep, name, offset, size);
34063515 if (ret < 0)
34073516 return ret;
34083517 }
3409
- return tep_read_number(pevent, data + *offset, *size);
3518
+ return tep_read_number(tep, data + *offset, *size);
34103519 }
34113520
3412
-static int trace_parse_common_type(struct tep_handle *pevent, void *data)
3521
+static int trace_parse_common_type(struct tep_handle *tep, void *data)
34133522 {
3414
- return __parse_common(pevent, data,
3415
- &pevent->type_size, &pevent->type_offset,
3523
+ return __parse_common(tep, data,
3524
+ &tep->type_size, &tep->type_offset,
34163525 "common_type");
34173526 }
34183527
3419
-static int parse_common_pid(struct tep_handle *pevent, void *data)
3528
+static int parse_common_pid(struct tep_handle *tep, void *data)
34203529 {
3421
- return __parse_common(pevent, data,
3422
- &pevent->pid_size, &pevent->pid_offset,
3530
+ return __parse_common(tep, data,
3531
+ &tep->pid_size, &tep->pid_offset,
34233532 "common_pid");
34243533 }
34253534
3426
-static int parse_common_pc(struct tep_handle *pevent, void *data)
3535
+static int parse_common_pc(struct tep_handle *tep, void *data)
34273536 {
3428
- return __parse_common(pevent, data,
3429
- &pevent->pc_size, &pevent->pc_offset,
3537
+ return __parse_common(tep, data,
3538
+ &tep->pc_size, &tep->pc_offset,
34303539 "common_preempt_count");
34313540 }
34323541
3433
-static int parse_common_flags(struct tep_handle *pevent, void *data)
3542
+static int parse_common_flags(struct tep_handle *tep, void *data)
34343543 {
3435
- return __parse_common(pevent, data,
3436
- &pevent->flags_size, &pevent->flags_offset,
3544
+ return __parse_common(tep, data,
3545
+ &tep->flags_size, &tep->flags_offset,
34373546 "common_flags");
34383547 }
34393548
3440
-static int parse_common_lock_depth(struct tep_handle *pevent, void *data)
3549
+static int parse_common_lock_depth(struct tep_handle *tep, void *data)
34413550 {
3442
- return __parse_common(pevent, data,
3443
- &pevent->ld_size, &pevent->ld_offset,
3551
+ return __parse_common(tep, data,
3552
+ &tep->ld_size, &tep->ld_offset,
34443553 "common_lock_depth");
34453554 }
34463555
3447
-static int parse_common_migrate_disable(struct tep_handle *pevent, void *data)
3556
+static int parse_common_migrate_disable(struct tep_handle *tep, void *data)
34483557 {
3449
- return __parse_common(pevent, data,
3450
- &pevent->ld_size, &pevent->ld_offset,
3558
+ return __parse_common(tep, data,
3559
+ &tep->ld_size, &tep->ld_offset,
34513560 "common_migrate_disable");
34523561 }
34533562
....@@ -3455,28 +3564,28 @@
34553564
34563565 /**
34573566 * tep_find_event - find an event by given id
3458
- * @pevent: a handle to the pevent
3567
+ * @tep: a handle to the trace event parser context
34593568 * @id: the id of the event
34603569 *
34613570 * Returns an event that has a given @id.
34623571 */
3463
-struct event_format *tep_find_event(struct tep_handle *pevent, int id)
3572
+struct tep_event *tep_find_event(struct tep_handle *tep, int id)
34643573 {
3465
- struct event_format **eventptr;
3466
- struct event_format key;
3467
- struct event_format *pkey = &key;
3574
+ struct tep_event **eventptr;
3575
+ struct tep_event key;
3576
+ struct tep_event *pkey = &key;
34683577
34693578 /* Check cache first */
3470
- if (pevent->last_event && pevent->last_event->id == id)
3471
- return pevent->last_event;
3579
+ if (tep->last_event && tep->last_event->id == id)
3580
+ return tep->last_event;
34723581
34733582 key.id = id;
34743583
3475
- eventptr = bsearch(&pkey, pevent->events, pevent->nr_events,
3476
- sizeof(*pevent->events), events_id_cmp);
3584
+ eventptr = bsearch(&pkey, tep->events, tep->nr_events,
3585
+ sizeof(*tep->events), events_id_cmp);
34773586
34783587 if (eventptr) {
3479
- pevent->last_event = *eventptr;
3588
+ tep->last_event = *eventptr;
34803589 return *eventptr;
34813590 }
34823591
....@@ -3485,27 +3594,27 @@
34853594
34863595 /**
34873596 * tep_find_event_by_name - find an event by given name
3488
- * @pevent: a handle to the pevent
3597
+ * @tep: a handle to the trace event parser context
34893598 * @sys: the system name to search for
34903599 * @name: the name of the event to search for
34913600 *
34923601 * This returns an event with a given @name and under the system
34933602 * @sys. If @sys is NULL the first event with @name is returned.
34943603 */
3495
-struct event_format *
3496
-tep_find_event_by_name(struct tep_handle *pevent,
3604
+struct tep_event *
3605
+tep_find_event_by_name(struct tep_handle *tep,
34973606 const char *sys, const char *name)
34983607 {
3499
- struct event_format *event;
3608
+ struct tep_event *event = NULL;
35003609 int i;
35013610
3502
- if (pevent->last_event &&
3503
- strcmp(pevent->last_event->name, name) == 0 &&
3504
- (!sys || strcmp(pevent->last_event->system, sys) == 0))
3505
- return pevent->last_event;
3611
+ if (tep->last_event &&
3612
+ strcmp(tep->last_event->name, name) == 0 &&
3613
+ (!sys || strcmp(tep->last_event->system, sys) == 0))
3614
+ return tep->last_event;
35063615
3507
- for (i = 0; i < pevent->nr_events; i++) {
3508
- event = pevent->events[i];
3616
+ for (i = 0; i < tep->nr_events; i++) {
3617
+ event = tep->events[i];
35093618 if (strcmp(event->name, name) == 0) {
35103619 if (!sys)
35113620 break;
....@@ -3513,31 +3622,31 @@
35133622 break;
35143623 }
35153624 }
3516
- if (i == pevent->nr_events)
3625
+ if (i == tep->nr_events)
35173626 event = NULL;
35183627
3519
- pevent->last_event = event;
3628
+ tep->last_event = event;
35203629 return event;
35213630 }
35223631
35233632 static unsigned long long
3524
-eval_num_arg(void *data, int size, struct event_format *event, struct print_arg *arg)
3633
+eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg *arg)
35253634 {
3526
- struct tep_handle *pevent = event->pevent;
3635
+ struct tep_handle *tep = event->tep;
35273636 unsigned long long val = 0;
35283637 unsigned long long left, right;
3529
- struct print_arg *typearg = NULL;
3530
- struct print_arg *larg;
3638
+ struct tep_print_arg *typearg = NULL;
3639
+ struct tep_print_arg *larg;
35313640 unsigned long offset;
35323641 unsigned int field_size;
35333642
35343643 switch (arg->type) {
3535
- case PRINT_NULL:
3644
+ case TEP_PRINT_NULL:
35363645 /* ?? */
35373646 return 0;
3538
- case PRINT_ATOM:
3647
+ case TEP_PRINT_ATOM:
35393648 return strtoull(arg->atom.atom, NULL, 0);
3540
- case PRINT_FIELD:
3649
+ case TEP_PRINT_FIELD:
35413650 if (!arg->field.field) {
35423651 arg->field.field = tep_find_any_field(event, arg->field.name);
35433652 if (!arg->field.field)
....@@ -3545,30 +3654,30 @@
35453654
35463655 }
35473656 /* must be a number */
3548
- val = tep_read_number(pevent, data + arg->field.field->offset,
3657
+ val = tep_read_number(tep, data + arg->field.field->offset,
35493658 arg->field.field->size);
35503659 break;
3551
- case PRINT_FLAGS:
3552
- case PRINT_SYMBOL:
3553
- case PRINT_INT_ARRAY:
3554
- case PRINT_HEX:
3555
- case PRINT_HEX_STR:
3660
+ case TEP_PRINT_FLAGS:
3661
+ case TEP_PRINT_SYMBOL:
3662
+ case TEP_PRINT_INT_ARRAY:
3663
+ case TEP_PRINT_HEX:
3664
+ case TEP_PRINT_HEX_STR:
35563665 break;
3557
- case PRINT_TYPE:
3666
+ case TEP_PRINT_TYPE:
35583667 val = eval_num_arg(data, size, event, arg->typecast.item);
35593668 return eval_type(val, arg, 0);
3560
- case PRINT_STRING:
3561
- case PRINT_BSTRING:
3562
- case PRINT_BITMASK:
3669
+ case TEP_PRINT_STRING:
3670
+ case TEP_PRINT_BSTRING:
3671
+ case TEP_PRINT_BITMASK:
35633672 return 0;
3564
- case PRINT_FUNC: {
3673
+ case TEP_PRINT_FUNC: {
35653674 struct trace_seq s;
35663675 trace_seq_init(&s);
35673676 val = process_defined_func(&s, data, size, event, arg);
35683677 trace_seq_destroy(&s);
35693678 return val;
35703679 }
3571
- case PRINT_OP:
3680
+ case TEP_PRINT_OP:
35723681 if (strcmp(arg->op.op, "[") == 0) {
35733682 /*
35743683 * Arrays are special, since we don't want
....@@ -3578,18 +3687,18 @@
35783687
35793688 /* handle typecasts */
35803689 larg = arg->op.left;
3581
- while (larg->type == PRINT_TYPE) {
3690
+ while (larg->type == TEP_PRINT_TYPE) {
35823691 if (!typearg)
35833692 typearg = larg;
35843693 larg = larg->typecast.item;
35853694 }
35863695
35873696 /* Default to long size */
3588
- field_size = pevent->long_size;
3697
+ field_size = tep->long_size;
35893698
35903699 switch (larg->type) {
3591
- case PRINT_DYNAMIC_ARRAY:
3592
- offset = tep_read_number(pevent,
3700
+ case TEP_PRINT_DYNAMIC_ARRAY:
3701
+ offset = tep_read_number(tep,
35933702 data + larg->dynarray.field->offset,
35943703 larg->dynarray.field->size);
35953704 if (larg->dynarray.field->elementsize)
....@@ -3602,7 +3711,7 @@
36023711 offset &= 0xffff;
36033712 offset += right;
36043713 break;
3605
- case PRINT_FIELD:
3714
+ case TEP_PRINT_FIELD:
36063715 if (!larg->field.field) {
36073716 larg->field.field =
36083717 tep_find_any_field(event, larg->field.name);
....@@ -3618,7 +3727,7 @@
36183727 default:
36193728 goto default_op; /* oops, all bets off */
36203729 }
3621
- val = tep_read_number(pevent,
3730
+ val = tep_read_number(tep,
36223731 data + offset, field_size);
36233732 if (typearg)
36243733 val = eval_type(val, typearg, 1);
....@@ -3718,8 +3827,8 @@
37183827 goto out_warning_op;
37193828 }
37203829 break;
3721
- case PRINT_DYNAMIC_ARRAY_LEN:
3722
- offset = tep_read_number(pevent,
3830
+ case TEP_PRINT_DYNAMIC_ARRAY_LEN:
3831
+ offset = tep_read_number(tep,
37233832 data + arg->dynarray.field->offset,
37243833 arg->dynarray.field->size);
37253834 /*
....@@ -3729,9 +3838,9 @@
37293838 */
37303839 val = (unsigned long long)(offset >> 16);
37313840 break;
3732
- case PRINT_DYNAMIC_ARRAY:
3841
+ case TEP_PRINT_DYNAMIC_ARRAY:
37333842 /* Without [], we pass the address to the dynamic data */
3734
- offset = tep_read_number(pevent,
3843
+ offset = tep_read_number(tep,
37353844 data + arg->dynarray.field->offset,
37363845 arg->dynarray.field->size);
37373846 /*
....@@ -3806,7 +3915,7 @@
38063915 trace_seq_printf(s, format, str);
38073916 }
38083917
3809
-static void print_bitmask_to_seq(struct tep_handle *pevent,
3918
+static void print_bitmask_to_seq(struct tep_handle *tep,
38103919 struct trace_seq *s, const char *format,
38113920 int len_arg, const void *data, int size)
38123921 {
....@@ -3836,9 +3945,9 @@
38363945 /*
38373946 * data points to a bit mask of size bytes.
38383947 * In the kernel, this is an array of long words, thus
3839
- * endianess is very important.
3948
+ * endianness is very important.
38403949 */
3841
- if (pevent->file_bigendian)
3950
+ if (tep->file_bigendian)
38423951 index = size - (len + 1);
38433952 else
38443953 index = len;
....@@ -3861,12 +3970,12 @@
38613970 }
38623971
38633972 static void print_str_arg(struct trace_seq *s, void *data, int size,
3864
- struct event_format *event, const char *format,
3865
- int len_arg, struct print_arg *arg)
3973
+ struct tep_event *event, const char *format,
3974
+ int len_arg, struct tep_print_arg *arg)
38663975 {
3867
- struct tep_handle *pevent = event->pevent;
3868
- struct print_flag_sym *flag;
3869
- struct format_field *field;
3976
+ struct tep_handle *tep = event->tep;
3977
+ struct tep_print_flag_sym *flag;
3978
+ struct tep_format_field *field;
38703979 struct printk_map *printk;
38713980 long long val, fval;
38723981 unsigned long long addr;
....@@ -3876,13 +3985,13 @@
38763985 int i, len;
38773986
38783987 switch (arg->type) {
3879
- case PRINT_NULL:
3988
+ case TEP_PRINT_NULL:
38803989 /* ?? */
38813990 return;
3882
- case PRINT_ATOM:
3991
+ case TEP_PRINT_ATOM:
38833992 print_str_to_seq(s, format, len_arg, arg->atom.atom);
38843993 return;
3885
- case PRINT_FIELD:
3994
+ case TEP_PRINT_FIELD:
38863995 field = arg->field.field;
38873996 if (!field) {
38883997 field = tep_find_any_field(event, arg->field.name);
....@@ -3900,8 +4009,8 @@
39004009 * and the size is the same as long_size, assume that it
39014010 * is a pointer.
39024011 */
3903
- if (!(field->flags & FIELD_IS_ARRAY) &&
3904
- field->size == pevent->long_size) {
4012
+ if (!(field->flags & TEP_FIELD_IS_ARRAY) &&
4013
+ field->size == tep->long_size) {
39054014
39064015 /* Handle heterogeneous recording and processing
39074016 * architectures
....@@ -3916,12 +4025,12 @@
39164025 * on 32-bit devices:
39174026 * In this case, 64 bits must be read.
39184027 */
3919
- addr = (pevent->long_size == 8) ?
4028
+ addr = (tep->long_size == 8) ?
39204029 *(unsigned long long *)(data + field->offset) :
39214030 (unsigned long long)*(unsigned int *)(data + field->offset);
39224031
39234032 /* Check if it matches a print format */
3924
- printk = find_printk(pevent, addr);
4033
+ printk = find_printk(tep, addr);
39254034 if (printk)
39264035 trace_seq_puts(s, printk->printk);
39274036 else
....@@ -3939,7 +4048,7 @@
39394048 print_str_to_seq(s, format, len_arg, str);
39404049 free(str);
39414050 break;
3942
- case PRINT_FLAGS:
4051
+ case TEP_PRINT_FLAGS:
39434052 val = eval_num_arg(data, size, event, arg->flags.field);
39444053 print = 0;
39454054 for (flag = arg->flags.flags; flag; flag = flag->next) {
....@@ -3962,7 +4071,7 @@
39624071 trace_seq_printf(s, "0x%llx", val);
39634072 }
39644073 break;
3965
- case PRINT_SYMBOL:
4074
+ case TEP_PRINT_SYMBOL:
39664075 val = eval_num_arg(data, size, event, arg->symbol.field);
39674076 for (flag = arg->symbol.symbols; flag; flag = flag->next) {
39684077 fval = eval_flag(flag->value);
....@@ -3974,11 +4083,11 @@
39744083 if (!flag)
39754084 trace_seq_printf(s, "0x%llx", val);
39764085 break;
3977
- case PRINT_HEX:
3978
- case PRINT_HEX_STR:
3979
- if (arg->hex.field->type == PRINT_DYNAMIC_ARRAY) {
4086
+ case TEP_PRINT_HEX:
4087
+ case TEP_PRINT_HEX_STR:
4088
+ if (arg->hex.field->type == TEP_PRINT_DYNAMIC_ARRAY) {
39804089 unsigned long offset;
3981
- offset = tep_read_number(pevent,
4090
+ offset = tep_read_number(tep,
39824091 data + arg->hex.field->dynarray.field->offset,
39834092 arg->hex.field->dynarray.field->size);
39844093 hex = data + (offset & 0xffff);
....@@ -3995,21 +4104,21 @@
39954104 }
39964105 len = eval_num_arg(data, size, event, arg->hex.size);
39974106 for (i = 0; i < len; i++) {
3998
- if (i && arg->type == PRINT_HEX)
4107
+ if (i && arg->type == TEP_PRINT_HEX)
39994108 trace_seq_putc(s, ' ');
40004109 trace_seq_printf(s, "%02x", hex[i]);
40014110 }
40024111 break;
40034112
4004
- case PRINT_INT_ARRAY: {
4113
+ case TEP_PRINT_INT_ARRAY: {
40054114 void *num;
40064115 int el_size;
40074116
4008
- if (arg->int_array.field->type == PRINT_DYNAMIC_ARRAY) {
4117
+ if (arg->int_array.field->type == TEP_PRINT_DYNAMIC_ARRAY) {
40094118 unsigned long offset;
4010
- struct format_field *field =
4119
+ struct tep_format_field *field =
40114120 arg->int_array.field->dynarray.field;
4012
- offset = tep_read_number(pevent,
4121
+ offset = tep_read_number(tep,
40134122 data + field->offset,
40144123 field->size);
40154124 num = data + (offset & 0xffff);
....@@ -4049,43 +4158,43 @@
40494158 }
40504159 break;
40514160 }
4052
- case PRINT_TYPE:
4161
+ case TEP_PRINT_TYPE:
40534162 break;
4054
- case PRINT_STRING: {
4163
+ case TEP_PRINT_STRING: {
40554164 int str_offset;
40564165
40574166 if (arg->string.offset == -1) {
4058
- struct format_field *f;
4167
+ struct tep_format_field *f;
40594168
40604169 f = tep_find_any_field(event, arg->string.string);
40614170 arg->string.offset = f->offset;
40624171 }
4063
- str_offset = data2host4(pevent, data + arg->string.offset);
4172
+ str_offset = data2host4(tep, *(unsigned int *)(data + arg->string.offset));
40644173 str_offset &= 0xffff;
40654174 print_str_to_seq(s, format, len_arg, ((char *)data) + str_offset);
40664175 break;
40674176 }
4068
- case PRINT_BSTRING:
4177
+ case TEP_PRINT_BSTRING:
40694178 print_str_to_seq(s, format, len_arg, arg->string.string);
40704179 break;
4071
- case PRINT_BITMASK: {
4180
+ case TEP_PRINT_BITMASK: {
40724181 int bitmask_offset;
40734182 int bitmask_size;
40744183
40754184 if (arg->bitmask.offset == -1) {
4076
- struct format_field *f;
4185
+ struct tep_format_field *f;
40774186
40784187 f = tep_find_any_field(event, arg->bitmask.bitmask);
40794188 arg->bitmask.offset = f->offset;
40804189 }
4081
- bitmask_offset = data2host4(pevent, data + arg->bitmask.offset);
4190
+ bitmask_offset = data2host4(tep, *(unsigned int *)(data + arg->bitmask.offset));
40824191 bitmask_size = bitmask_offset >> 16;
40834192 bitmask_offset &= 0xffff;
4084
- print_bitmask_to_seq(pevent, s, format, len_arg,
4193
+ print_bitmask_to_seq(tep, s, format, len_arg,
40854194 data + bitmask_offset, bitmask_size);
40864195 break;
40874196 }
4088
- case PRINT_OP:
4197
+ case TEP_PRINT_OP:
40894198 /*
40904199 * The only op for string should be ? :
40914200 */
....@@ -4099,7 +4208,7 @@
40994208 print_str_arg(s, data, size, event,
41004209 format, len_arg, arg->op.right->op.right);
41014210 break;
4102
- case PRINT_FUNC:
4211
+ case TEP_PRINT_FUNC:
41034212 process_defined_func(s, data, size, event, arg);
41044213 break;
41054214 default:
....@@ -4116,13 +4225,13 @@
41164225
41174226 static unsigned long long
41184227 process_defined_func(struct trace_seq *s, void *data, int size,
4119
- struct event_format *event, struct print_arg *arg)
4228
+ struct tep_event *event, struct tep_print_arg *arg)
41204229 {
41214230 struct tep_function_handler *func_handle = arg->func.func;
41224231 struct func_params *param;
41234232 unsigned long long *args;
41244233 unsigned long long ret;
4125
- struct print_arg *farg;
4234
+ struct tep_print_arg *farg;
41264235 struct trace_seq str;
41274236 struct save_str {
41284237 struct save_str *next;
....@@ -4199,9 +4308,9 @@
41994308 return ret;
42004309 }
42014310
4202
-static void free_args(struct print_arg *args)
4311
+static void free_args(struct tep_print_arg *args)
42034312 {
4204
- struct print_arg *next;
4313
+ struct tep_print_arg *next;
42054314
42064315 while (args) {
42074316 next = args->next;
....@@ -4211,18 +4320,18 @@
42114320 }
42124321 }
42134322
4214
-static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event_format *event)
4323
+static struct tep_print_arg *make_bprint_args(char *fmt, void *data, int size, struct tep_event *event)
42154324 {
4216
- struct tep_handle *pevent = event->pevent;
4217
- struct format_field *field, *ip_field;
4218
- struct print_arg *args, *arg, **next;
4325
+ struct tep_handle *tep = event->tep;
4326
+ struct tep_format_field *field, *ip_field;
4327
+ struct tep_print_arg *args, *arg, **next;
42194328 unsigned long long ip, val;
42204329 char *ptr;
42214330 void *bptr;
4222
- int vsize;
4331
+ int vsize = 0;
42234332
4224
- field = pevent->bprint_buf_field;
4225
- ip_field = pevent->bprint_ip_field;
4333
+ field = tep->bprint_buf_field;
4334
+ ip_field = tep->bprint_ip_field;
42264335
42274336 if (!field) {
42284337 field = tep_find_field(event, "buf");
....@@ -4235,11 +4344,11 @@
42354344 do_warning_event(event, "can't find ip field for binary printk");
42364345 return NULL;
42374346 }
4238
- pevent->bprint_buf_field = field;
4239
- pevent->bprint_ip_field = ip_field;
4347
+ tep->bprint_buf_field = field;
4348
+ tep->bprint_ip_field = ip_field;
42404349 }
42414350
4242
- ip = tep_read_number(pevent, data + ip_field->offset, ip_field->size);
4351
+ ip = tep_read_number(tep, data + ip_field->offset, ip_field->size);
42434352
42444353 /*
42454354 * The first arg is the IP pointer.
....@@ -4254,7 +4363,7 @@
42544363 arg->next = NULL;
42554364 next = &arg->next;
42564365
4257
- arg->type = PRINT_ATOM;
4366
+ arg->type = TEP_PRINT_ATOM;
42584367
42594368 if (asprintf(&arg->atom.atom, "%lld", ip) < 0)
42604369 goto out_free;
....@@ -4292,9 +4401,20 @@
42924401 switch (*ptr) {
42934402 case 's':
42944403 case 'S':
4404
+ case 'x':
4405
+ break;
42954406 case 'f':
42964407 case 'F':
4297
- break;
4408
+ /*
4409
+ * Pre-5.5 kernels use %pf and
4410
+ * %pF for printing symbols
4411
+ * while kernels since 5.5 use
4412
+ * %pfw for fwnodes. So check
4413
+ * %p[fF] isn't followed by 'w'.
4414
+ */
4415
+ if (ptr[1] != 'w')
4416
+ break;
4417
+ /* fall through */
42984418 default:
42994419 /*
43004420 * Older kernels do not process
....@@ -4309,14 +4429,16 @@
43094429 /* fall through */
43104430 case 'd':
43114431 case 'u':
4312
- case 'x':
43134432 case 'i':
4433
+ case 'x':
4434
+ case 'X':
4435
+ case 'o':
43144436 switch (ls) {
43154437 case 0:
43164438 vsize = 4;
43174439 break;
43184440 case 1:
4319
- vsize = pevent->long_size;
4441
+ vsize = tep->long_size;
43204442 break;
43214443 case 2:
43224444 vsize = 8;
....@@ -4333,7 +4455,7 @@
43334455 /* the pointers are always 4 bytes aligned */
43344456 bptr = (void *)(((unsigned long)bptr + 3) &
43354457 ~3);
4336
- val = tep_read_number(pevent, bptr, vsize);
4458
+ val = tep_read_number(tep, bptr, vsize);
43374459 bptr += vsize;
43384460 arg = alloc_arg();
43394461 if (!arg) {
....@@ -4342,7 +4464,7 @@
43424464 goto out_free;
43434465 }
43444466 arg->next = NULL;
4345
- arg->type = PRINT_ATOM;
4467
+ arg->type = TEP_PRINT_ATOM;
43464468 if (asprintf(&arg->atom.atom, "%lld", val) < 0) {
43474469 free(arg);
43484470 goto out_free;
....@@ -4366,7 +4488,7 @@
43664488 goto out_free;
43674489 }
43684490 arg->next = NULL;
4369
- arg->type = PRINT_BSTRING;
4491
+ arg->type = TEP_PRINT_BSTRING;
43704492 arg->string.string = strdup(bptr);
43714493 if (!arg->string.string)
43724494 goto out_free;
....@@ -4388,15 +4510,15 @@
43884510
43894511 static char *
43904512 get_bprint_format(void *data, int size __maybe_unused,
4391
- struct event_format *event)
4513
+ struct tep_event *event)
43924514 {
4393
- struct tep_handle *pevent = event->pevent;
4515
+ struct tep_handle *tep = event->tep;
43944516 unsigned long long addr;
4395
- struct format_field *field;
4517
+ struct tep_format_field *field;
43964518 struct printk_map *printk;
43974519 char *format;
43984520
4399
- field = pevent->bprint_fmt_field;
4521
+ field = tep->bprint_fmt_field;
44004522
44014523 if (!field) {
44024524 field = tep_find_field(event, "fmt");
....@@ -4404,61 +4526,111 @@
44044526 do_warning_event(event, "can't find format field for binary printk");
44054527 return NULL;
44064528 }
4407
- pevent->bprint_fmt_field = field;
4529
+ tep->bprint_fmt_field = field;
44084530 }
44094531
4410
- addr = tep_read_number(pevent, data + field->offset, field->size);
4532
+ addr = tep_read_number(tep, data + field->offset, field->size);
44114533
4412
- printk = find_printk(pevent, addr);
4534
+ printk = find_printk(tep, addr);
44134535 if (!printk) {
4414
- if (asprintf(&format, "%%pf: (NO FORMAT FOUND at %llx)\n", addr) < 0)
4536
+ if (asprintf(&format, "%%ps: (NO FORMAT FOUND at %llx)\n", addr) < 0)
44154537 return NULL;
44164538 return format;
44174539 }
44184540
4419
- if (asprintf(&format, "%s: %s", "%pf", printk->printk) < 0)
4541
+ if (asprintf(&format, "%s: %s", "%ps", printk->printk) < 0)
44204542 return NULL;
44214543
44224544 return format;
44234545 }
44244546
4425
-static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size,
4426
- struct event_format *event, struct print_arg *arg)
4547
+static int print_mac_arg(struct trace_seq *s, const char *format,
4548
+ void *data, int size, struct tep_event *event,
4549
+ struct tep_print_arg *arg)
44274550 {
4428
- unsigned char *buf;
44294551 const char *fmt = "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x";
4552
+ bool reverse = false;
4553
+ unsigned char *buf;
4554
+ int ret = 0;
44304555
4431
- if (arg->type == PRINT_FUNC) {
4556
+ if (arg->type == TEP_PRINT_FUNC) {
44324557 process_defined_func(s, data, size, event, arg);
4433
- return;
4558
+ return 0;
44344559 }
44354560
4436
- if (arg->type != PRINT_FIELD) {
4561
+ if (arg->type != TEP_PRINT_FIELD) {
44374562 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d",
44384563 arg->type);
4439
- return;
4564
+ return 0;
44404565 }
44414566
4442
- if (mac == 'm')
4567
+ if (format[0] == 'm') {
44434568 fmt = "%.2x%.2x%.2x%.2x%.2x%.2x";
4569
+ } else if (format[0] == 'M' && format[1] == 'F') {
4570
+ fmt = "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x";
4571
+ ret++;
4572
+ }
4573
+ if (format[1] == 'R') {
4574
+ reverse = true;
4575
+ ret++;
4576
+ }
4577
+
44444578 if (!arg->field.field) {
44454579 arg->field.field =
44464580 tep_find_any_field(event, arg->field.name);
44474581 if (!arg->field.field) {
44484582 do_warning_event(event, "%s: field %s not found",
44494583 __func__, arg->field.name);
4450
- return;
4584
+ return ret;
44514585 }
44524586 }
44534587 if (arg->field.field->size != 6) {
44544588 trace_seq_printf(s, "INVALIDMAC");
4455
- return;
4589
+ return ret;
44564590 }
4591
+
44574592 buf = data + arg->field.field->offset;
4458
- trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
4593
+ if (reverse)
4594
+ trace_seq_printf(s, fmt, buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]);
4595
+ else
4596
+ trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
4597
+
4598
+ return ret;
44594599 }
44604600
4461
-static void print_ip4_addr(struct trace_seq *s, char i, unsigned char *buf)
4601
+static int parse_ip4_print_args(struct tep_handle *tep,
4602
+ const char *ptr, bool *reverse)
4603
+{
4604
+ int ret = 0;
4605
+
4606
+ *reverse = false;
4607
+
4608
+ /* hnbl */
4609
+ switch (*ptr) {
4610
+ case 'h':
4611
+ if (tep->file_bigendian)
4612
+ *reverse = false;
4613
+ else
4614
+ *reverse = true;
4615
+ ret++;
4616
+ break;
4617
+ case 'l':
4618
+ *reverse = true;
4619
+ ret++;
4620
+ break;
4621
+ case 'n':
4622
+ case 'b':
4623
+ ret++;
4624
+ /* fall through */
4625
+ default:
4626
+ *reverse = false;
4627
+ break;
4628
+ }
4629
+
4630
+ return ret;
4631
+}
4632
+
4633
+static void print_ip4_addr(struct trace_seq *s, char i, bool reverse, unsigned char *buf)
44624634 {
44634635 const char *fmt;
44644636
....@@ -4467,7 +4639,11 @@
44674639 else
44684640 fmt = "%d.%d.%d.%d";
44694641
4470
- trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3]);
4642
+ if (reverse)
4643
+ trace_seq_printf(s, fmt, buf[3], buf[2], buf[1], buf[0]);
4644
+ else
4645
+ trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3]);
4646
+
44714647 }
44724648
44734649 static inline bool ipv6_addr_v4mapped(const struct in6_addr *a)
....@@ -4550,7 +4726,7 @@
45504726 if (useIPv4) {
45514727 if (needcolon)
45524728 trace_seq_printf(s, ":");
4553
- print_ip4_addr(s, 'I', &in6.s6_addr[12]);
4729
+ print_ip4_addr(s, 'I', false, &in6.s6_addr[12]);
45544730 }
45554731
45564732 return;
....@@ -4576,19 +4752,23 @@
45764752 * %pISpc print an IP address based on sockaddr; p adds port.
45774753 */
45784754 static int print_ipv4_arg(struct trace_seq *s, const char *ptr, char i,
4579
- void *data, int size, struct event_format *event,
4580
- struct print_arg *arg)
4755
+ void *data, int size, struct tep_event *event,
4756
+ struct tep_print_arg *arg)
45814757 {
4758
+ bool reverse = false;
45824759 unsigned char *buf;
4760
+ int ret;
45834761
4584
- if (arg->type == PRINT_FUNC) {
4762
+ ret = parse_ip4_print_args(event->tep, ptr, &reverse);
4763
+
4764
+ if (arg->type == TEP_PRINT_FUNC) {
45854765 process_defined_func(s, data, size, event, arg);
4586
- return 0;
4766
+ return ret;
45874767 }
45884768
4589
- if (arg->type != PRINT_FIELD) {
4769
+ if (arg->type != TEP_PRINT_FIELD) {
45904770 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
4591
- return 0;
4771
+ return ret;
45924772 }
45934773
45944774 if (!arg->field.field) {
....@@ -4597,7 +4777,7 @@
45974777 if (!arg->field.field) {
45984778 do_warning("%s: field %s not found",
45994779 __func__, arg->field.name);
4600
- return 0;
4780
+ return ret;
46014781 }
46024782 }
46034783
....@@ -4605,16 +4785,17 @@
46054785
46064786 if (arg->field.field->size != 4) {
46074787 trace_seq_printf(s, "INVALIDIPv4");
4608
- return 0;
4788
+ return ret;
46094789 }
4610
- print_ip4_addr(s, i, buf);
46114790
4612
- return 0;
4791
+ print_ip4_addr(s, i, reverse, buf);
4792
+ return ret;
4793
+
46134794 }
46144795
46154796 static int print_ipv6_arg(struct trace_seq *s, const char *ptr, char i,
4616
- void *data, int size, struct event_format *event,
4617
- struct print_arg *arg)
4797
+ void *data, int size, struct tep_event *event,
4798
+ struct tep_print_arg *arg)
46184799 {
46194800 char have_c = 0;
46204801 unsigned char *buf;
....@@ -4627,12 +4808,12 @@
46274808 rc++;
46284809 }
46294810
4630
- if (arg->type == PRINT_FUNC) {
4811
+ if (arg->type == TEP_PRINT_FUNC) {
46314812 process_defined_func(s, data, size, event, arg);
46324813 return rc;
46334814 }
46344815
4635
- if (arg->type != PRINT_FIELD) {
4816
+ if (arg->type != TEP_PRINT_FIELD) {
46364817 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
46374818 return rc;
46384819 }
....@@ -4663,13 +4844,15 @@
46634844 }
46644845
46654846 static int print_ipsa_arg(struct trace_seq *s, const char *ptr, char i,
4666
- void *data, int size, struct event_format *event,
4667
- struct print_arg *arg)
4847
+ void *data, int size, struct tep_event *event,
4848
+ struct tep_print_arg *arg)
46684849 {
46694850 char have_c = 0, have_p = 0;
46704851 unsigned char *buf;
46714852 struct sockaddr_storage *sa;
4853
+ bool reverse = false;
46724854 int rc = 0;
4855
+ int ret;
46734856
46744857 /* pISpc */
46754858 if (i == 'I') {
....@@ -4684,13 +4867,16 @@
46844867 rc++;
46854868 }
46864869 }
4870
+ ret = parse_ip4_print_args(event->tep, ptr, &reverse);
4871
+ ptr += ret;
4872
+ rc += ret;
46874873
4688
- if (arg->type == PRINT_FUNC) {
4874
+ if (arg->type == TEP_PRINT_FUNC) {
46894875 process_defined_func(s, data, size, event, arg);
46904876 return rc;
46914877 }
46924878
4693
- if (arg->type != PRINT_FIELD) {
4879
+ if (arg->type != TEP_PRINT_FIELD) {
46944880 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
46954881 return rc;
46964882 }
....@@ -4715,7 +4901,7 @@
47154901 return rc;
47164902 }
47174903
4718
- print_ip4_addr(s, i, (unsigned char *) &sa4->sin_addr);
4904
+ print_ip4_addr(s, i, reverse, (unsigned char *) &sa4->sin_addr);
47194905 if (have_p)
47204906 trace_seq_printf(s, ":%d", ntohs(sa4->sin_port));
47214907
....@@ -4745,35 +4931,157 @@
47454931 }
47464932
47474933 static int print_ip_arg(struct trace_seq *s, const char *ptr,
4748
- void *data, int size, struct event_format *event,
4749
- struct print_arg *arg)
4934
+ void *data, int size, struct tep_event *event,
4935
+ struct tep_print_arg *arg)
47504936 {
47514937 char i = *ptr; /* 'i' or 'I' */
4752
- char ver;
4753
- int rc = 0;
4938
+ int rc = 1;
47544939
4940
+ /* IP version */
47554941 ptr++;
4756
- rc++;
47574942
4758
- ver = *ptr;
4759
- ptr++;
4760
- rc++;
4761
-
4762
- switch (ver) {
4943
+ switch (*ptr) {
47634944 case '4':
4764
- rc += print_ipv4_arg(s, ptr, i, data, size, event, arg);
4945
+ rc += print_ipv4_arg(s, ptr + 1, i, data, size, event, arg);
47654946 break;
47664947 case '6':
4767
- rc += print_ipv6_arg(s, ptr, i, data, size, event, arg);
4948
+ rc += print_ipv6_arg(s, ptr + 1, i, data, size, event, arg);
47684949 break;
47694950 case 'S':
4770
- rc += print_ipsa_arg(s, ptr, i, data, size, event, arg);
4951
+ rc += print_ipsa_arg(s, ptr + 1, i, data, size, event, arg);
47714952 break;
47724953 default:
47734954 return 0;
47744955 }
47754956
47764957 return rc;
4958
+}
4959
+
4960
+static const int guid_index[16] = {3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15};
4961
+static const int uuid_index[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
4962
+
4963
+static int print_uuid_arg(struct trace_seq *s, const char *ptr,
4964
+ void *data, int size, struct tep_event *event,
4965
+ struct tep_print_arg *arg)
4966
+{
4967
+ const int *index = uuid_index;
4968
+ char *format = "%02x";
4969
+ int ret = 0;
4970
+ char *buf;
4971
+ int i;
4972
+
4973
+ switch (*(ptr + 1)) {
4974
+ case 'L':
4975
+ format = "%02X";
4976
+ /* fall through */
4977
+ case 'l':
4978
+ index = guid_index;
4979
+ ret++;
4980
+ break;
4981
+ case 'B':
4982
+ format = "%02X";
4983
+ /* fall through */
4984
+ case 'b':
4985
+ ret++;
4986
+ break;
4987
+ }
4988
+
4989
+ if (arg->type == TEP_PRINT_FUNC) {
4990
+ process_defined_func(s, data, size, event, arg);
4991
+ return ret;
4992
+ }
4993
+
4994
+ if (arg->type != TEP_PRINT_FIELD) {
4995
+ trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
4996
+ return ret;
4997
+ }
4998
+
4999
+ if (!arg->field.field) {
5000
+ arg->field.field =
5001
+ tep_find_any_field(event, arg->field.name);
5002
+ if (!arg->field.field) {
5003
+ do_warning("%s: field %s not found",
5004
+ __func__, arg->field.name);
5005
+ return ret;
5006
+ }
5007
+ }
5008
+
5009
+ if (arg->field.field->size != 16) {
5010
+ trace_seq_printf(s, "INVALIDUUID");
5011
+ return ret;
5012
+ }
5013
+
5014
+ buf = data + arg->field.field->offset;
5015
+
5016
+ for (i = 0; i < 16; i++) {
5017
+ trace_seq_printf(s, format, buf[index[i]] & 0xff);
5018
+ switch (i) {
5019
+ case 3:
5020
+ case 5:
5021
+ case 7:
5022
+ case 9:
5023
+ trace_seq_printf(s, "-");
5024
+ break;
5025
+ }
5026
+ }
5027
+
5028
+ return ret;
5029
+}
5030
+
5031
+static int print_raw_buff_arg(struct trace_seq *s, const char *ptr,
5032
+ void *data, int size, struct tep_event *event,
5033
+ struct tep_print_arg *arg, int print_len)
5034
+{
5035
+ int plen = print_len;
5036
+ char *delim = " ";
5037
+ int ret = 0;
5038
+ char *buf;
5039
+ int i;
5040
+ unsigned long offset;
5041
+ int arr_len;
5042
+
5043
+ switch (*(ptr + 1)) {
5044
+ case 'C':
5045
+ delim = ":";
5046
+ ret++;
5047
+ break;
5048
+ case 'D':
5049
+ delim = "-";
5050
+ ret++;
5051
+ break;
5052
+ case 'N':
5053
+ delim = "";
5054
+ ret++;
5055
+ break;
5056
+ }
5057
+
5058
+ if (arg->type == TEP_PRINT_FUNC) {
5059
+ process_defined_func(s, data, size, event, arg);
5060
+ return ret;
5061
+ }
5062
+
5063
+ if (arg->type != TEP_PRINT_DYNAMIC_ARRAY) {
5064
+ trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
5065
+ return ret;
5066
+ }
5067
+
5068
+ offset = tep_read_number(event->tep,
5069
+ data + arg->dynarray.field->offset,
5070
+ arg->dynarray.field->size);
5071
+ arr_len = (unsigned long long)(offset >> 16);
5072
+ buf = data + (offset & 0xffff);
5073
+
5074
+ if (arr_len < plen)
5075
+ plen = arr_len;
5076
+
5077
+ if (plen < 1)
5078
+ return ret;
5079
+
5080
+ trace_seq_printf(s, "%02x", buf[0] & 0xff);
5081
+ for (i = 1; i < plen; i++)
5082
+ trace_seq_printf(s, "%s%02x", delim, buf[i] & 0xff);
5083
+
5084
+ return ret;
47775085 }
47785086
47795087 static int is_printable_array(char *p, unsigned int len)
....@@ -4787,22 +5095,22 @@
47875095 }
47885096
47895097 void tep_print_field(struct trace_seq *s, void *data,
4790
- struct format_field *field)
5098
+ struct tep_format_field *field)
47915099 {
47925100 unsigned long long val;
47935101 unsigned int offset, len, i;
4794
- struct tep_handle *pevent = field->event->pevent;
5102
+ struct tep_handle *tep = field->event->tep;
47955103
4796
- if (field->flags & FIELD_IS_ARRAY) {
5104
+ if (field->flags & TEP_FIELD_IS_ARRAY) {
47975105 offset = field->offset;
47985106 len = field->size;
4799
- if (field->flags & FIELD_IS_DYNAMIC) {
4800
- val = tep_read_number(pevent, data + offset, len);
5107
+ if (field->flags & TEP_FIELD_IS_DYNAMIC) {
5108
+ val = tep_read_number(tep, data + offset, len);
48015109 offset = val;
48025110 len = offset >> 16;
48035111 offset &= 0xffff;
48045112 }
4805
- if (field->flags & FIELD_IS_STRING &&
5113
+ if (field->flags & TEP_FIELD_IS_STRING &&
48065114 is_printable_array(data + offset, len)) {
48075115 trace_seq_printf(s, "%s", (char *)data + offset);
48085116 } else {
....@@ -4814,21 +5122,21 @@
48145122 *((unsigned char *)data + offset + i));
48155123 }
48165124 trace_seq_putc(s, ']');
4817
- field->flags &= ~FIELD_IS_STRING;
5125
+ field->flags &= ~TEP_FIELD_IS_STRING;
48185126 }
48195127 } else {
4820
- val = tep_read_number(pevent, data + field->offset,
5128
+ val = tep_read_number(tep, data + field->offset,
48215129 field->size);
4822
- if (field->flags & FIELD_IS_POINTER) {
5130
+ if (field->flags & TEP_FIELD_IS_POINTER) {
48235131 trace_seq_printf(s, "0x%llx", val);
4824
- } else if (field->flags & FIELD_IS_SIGNED) {
5132
+ } else if (field->flags & TEP_FIELD_IS_SIGNED) {
48255133 switch (field->size) {
48265134 case 4:
48275135 /*
48285136 * If field is long then print it in hex.
48295137 * A long usually stores pointers.
48305138 */
4831
- if (field->flags & FIELD_IS_LONG)
5139
+ if (field->flags & TEP_FIELD_IS_LONG)
48325140 trace_seq_printf(s, "0x%x", (int)val);
48335141 else
48345142 trace_seq_printf(s, "%d", (int)val);
....@@ -4843,7 +5151,7 @@
48435151 trace_seq_printf(s, "%lld", val);
48445152 }
48455153 } else {
4846
- if (field->flags & FIELD_IS_LONG)
5154
+ if (field->flags & TEP_FIELD_IS_LONG)
48475155 trace_seq_printf(s, "0x%llx", val);
48485156 else
48495157 trace_seq_printf(s, "%llu", val);
....@@ -4852,9 +5160,9 @@
48525160 }
48535161
48545162 void tep_print_fields(struct trace_seq *s, void *data,
4855
- int size __maybe_unused, struct event_format *event)
5163
+ int size __maybe_unused, struct tep_event *event)
48565164 {
4857
- struct format_field *field;
5165
+ struct tep_format_field *field;
48585166
48595167 field = event->format.fields;
48605168 while (field) {
....@@ -4864,300 +5172,601 @@
48645172 }
48655173 }
48665174
4867
-static void pretty_print(struct trace_seq *s, void *data, int size, struct event_format *event)
5175
+static int print_function(struct trace_seq *s, const char *format,
5176
+ void *data, int size, struct tep_event *event,
5177
+ struct tep_print_arg *arg)
48685178 {
4869
- struct tep_handle *pevent = event->pevent;
4870
- struct print_fmt *print_fmt = &event->print_fmt;
4871
- struct print_arg *arg = print_fmt->args;
4872
- struct print_arg *args = NULL;
4873
- const char *ptr = print_fmt->format;
4874
- unsigned long long val;
48755179 struct func_map *func;
4876
- const char *saveptr;
4877
- struct trace_seq p;
4878
- char *bprint_fmt = NULL;
4879
- char format[32];
4880
- int show_func;
4881
- int len_as_arg;
4882
- int len_arg;
4883
- int len;
4884
- int ls;
5180
+ unsigned long long val;
48855181
4886
- if (event->flags & EVENT_FL_FAILED) {
5182
+ val = eval_num_arg(data, size, event, arg);
5183
+ func = find_func(event->tep, val);
5184
+ if (func) {
5185
+ trace_seq_puts(s, func->func);
5186
+ if (*format == 'F' || *format == 'S')
5187
+ trace_seq_printf(s, "+0x%llx", val - func->addr);
5188
+ } else {
5189
+ if (event->tep->long_size == 4)
5190
+ trace_seq_printf(s, "0x%lx", (long)val);
5191
+ else
5192
+ trace_seq_printf(s, "0x%llx", (long long)val);
5193
+ }
5194
+
5195
+ return 0;
5196
+}
5197
+
5198
+static int print_arg_pointer(struct trace_seq *s, const char *format, int plen,
5199
+ void *data, int size,
5200
+ struct tep_event *event, struct tep_print_arg *arg)
5201
+{
5202
+ unsigned long long val;
5203
+ int ret = 1;
5204
+
5205
+ if (arg->type == TEP_PRINT_BSTRING) {
5206
+ trace_seq_puts(s, arg->string.string);
5207
+ return 0;
5208
+ }
5209
+ while (*format) {
5210
+ if (*format == 'p') {
5211
+ format++;
5212
+ break;
5213
+ }
5214
+ format++;
5215
+ }
5216
+
5217
+ switch (*format) {
5218
+ case 'F':
5219
+ case 'f':
5220
+ case 'S':
5221
+ case 's':
5222
+ ret += print_function(s, format, data, size, event, arg);
5223
+ break;
5224
+ case 'M':
5225
+ case 'm':
5226
+ ret += print_mac_arg(s, format, data, size, event, arg);
5227
+ break;
5228
+ case 'I':
5229
+ case 'i':
5230
+ ret += print_ip_arg(s, format, data, size, event, arg);
5231
+ break;
5232
+ case 'U':
5233
+ ret += print_uuid_arg(s, format, data, size, event, arg);
5234
+ break;
5235
+ case 'h':
5236
+ ret += print_raw_buff_arg(s, format, data, size, event, arg, plen);
5237
+ break;
5238
+ default:
5239
+ ret = 0;
5240
+ val = eval_num_arg(data, size, event, arg);
5241
+ trace_seq_printf(s, "%p", (void *)(intptr_t)val);
5242
+ break;
5243
+ }
5244
+
5245
+ return ret;
5246
+
5247
+}
5248
+
5249
+static int print_arg_number(struct trace_seq *s, const char *format, int plen,
5250
+ void *data, int size, int ls,
5251
+ struct tep_event *event, struct tep_print_arg *arg)
5252
+{
5253
+ unsigned long long val;
5254
+
5255
+ val = eval_num_arg(data, size, event, arg);
5256
+
5257
+ switch (ls) {
5258
+ case -2:
5259
+ if (plen >= 0)
5260
+ trace_seq_printf(s, format, plen, (char)val);
5261
+ else
5262
+ trace_seq_printf(s, format, (char)val);
5263
+ break;
5264
+ case -1:
5265
+ if (plen >= 0)
5266
+ trace_seq_printf(s, format, plen, (short)val);
5267
+ else
5268
+ trace_seq_printf(s, format, (short)val);
5269
+ break;
5270
+ case 0:
5271
+ if (plen >= 0)
5272
+ trace_seq_printf(s, format, plen, (int)val);
5273
+ else
5274
+ trace_seq_printf(s, format, (int)val);
5275
+ break;
5276
+ case 1:
5277
+ if (plen >= 0)
5278
+ trace_seq_printf(s, format, plen, (long)val);
5279
+ else
5280
+ trace_seq_printf(s, format, (long)val);
5281
+ break;
5282
+ case 2:
5283
+ if (plen >= 0)
5284
+ trace_seq_printf(s, format, plen, (long long)val);
5285
+ else
5286
+ trace_seq_printf(s, format, (long long)val);
5287
+ break;
5288
+ default:
5289
+ do_warning_event(event, "bad count (%d)", ls);
5290
+ event->flags |= TEP_EVENT_FL_FAILED;
5291
+ }
5292
+ return 0;
5293
+}
5294
+
5295
+
5296
+static void print_arg_string(struct trace_seq *s, const char *format, int plen,
5297
+ void *data, int size,
5298
+ struct tep_event *event, struct tep_print_arg *arg)
5299
+{
5300
+ struct trace_seq p;
5301
+
5302
+ /* Use helper trace_seq */
5303
+ trace_seq_init(&p);
5304
+ print_str_arg(&p, data, size, event,
5305
+ format, plen, arg);
5306
+ trace_seq_terminate(&p);
5307
+ trace_seq_puts(s, p.buffer);
5308
+ trace_seq_destroy(&p);
5309
+}
5310
+
5311
+static int parse_arg_format_pointer(const char *format)
5312
+{
5313
+ int ret = 0;
5314
+ int index;
5315
+ int loop;
5316
+
5317
+ switch (*format) {
5318
+ case 'F':
5319
+ case 'S':
5320
+ case 'f':
5321
+ case 's':
5322
+ ret++;
5323
+ break;
5324
+ case 'M':
5325
+ case 'm':
5326
+ /* [mM]R , [mM]F */
5327
+ switch (format[1]) {
5328
+ case 'R':
5329
+ case 'F':
5330
+ ret++;
5331
+ break;
5332
+ }
5333
+ ret++;
5334
+ break;
5335
+ case 'I':
5336
+ case 'i':
5337
+ index = 2;
5338
+ loop = 1;
5339
+ switch (format[1]) {
5340
+ case 'S':
5341
+ /*[S][pfs]*/
5342
+ while (loop) {
5343
+ switch (format[index]) {
5344
+ case 'p':
5345
+ case 'f':
5346
+ case 's':
5347
+ ret++;
5348
+ index++;
5349
+ break;
5350
+ default:
5351
+ loop = 0;
5352
+ break;
5353
+ }
5354
+ }
5355
+ /* fall through */
5356
+ case '4':
5357
+ /* [4S][hnbl] */
5358
+ switch (format[index]) {
5359
+ case 'h':
5360
+ case 'n':
5361
+ case 'l':
5362
+ case 'b':
5363
+ ret++;
5364
+ index++;
5365
+ break;
5366
+ }
5367
+ if (format[1] == '4') {
5368
+ ret++;
5369
+ break;
5370
+ }
5371
+ /* fall through */
5372
+ case '6':
5373
+ /* [6S]c */
5374
+ if (format[index] == 'c')
5375
+ ret++;
5376
+ ret++;
5377
+ break;
5378
+ }
5379
+ ret++;
5380
+ break;
5381
+ case 'U':
5382
+ switch (format[1]) {
5383
+ case 'L':
5384
+ case 'l':
5385
+ case 'B':
5386
+ case 'b':
5387
+ ret++;
5388
+ break;
5389
+ }
5390
+ ret++;
5391
+ break;
5392
+ case 'h':
5393
+ switch (format[1]) {
5394
+ case 'C':
5395
+ case 'D':
5396
+ case 'N':
5397
+ ret++;
5398
+ break;
5399
+ }
5400
+ ret++;
5401
+ break;
5402
+ default:
5403
+ break;
5404
+ }
5405
+
5406
+ return ret;
5407
+}
5408
+
5409
+static void free_parse_args(struct tep_print_parse *arg)
5410
+{
5411
+ struct tep_print_parse *del;
5412
+
5413
+ while (arg) {
5414
+ del = arg;
5415
+ arg = del->next;
5416
+ free(del->format);
5417
+ free(del);
5418
+ }
5419
+}
5420
+
5421
+static int parse_arg_add(struct tep_print_parse **parse, char *format,
5422
+ enum tep_print_parse_type type,
5423
+ struct tep_print_arg *arg,
5424
+ struct tep_print_arg *len_as_arg,
5425
+ int ls)
5426
+{
5427
+ struct tep_print_parse *parg = NULL;
5428
+
5429
+ parg = calloc(1, sizeof(*parg));
5430
+ if (!parg)
5431
+ goto error;
5432
+ parg->format = strdup(format);
5433
+ if (!parg->format)
5434
+ goto error;
5435
+ parg->type = type;
5436
+ parg->arg = arg;
5437
+ parg->len_as_arg = len_as_arg;
5438
+ parg->ls = ls;
5439
+ *parse = parg;
5440
+ return 0;
5441
+error:
5442
+ if (parg) {
5443
+ free(parg->format);
5444
+ free(parg);
5445
+ }
5446
+ return -1;
5447
+}
5448
+
5449
+static int parse_arg_format(struct tep_print_parse **parse,
5450
+ struct tep_event *event,
5451
+ const char *format, struct tep_print_arg **arg)
5452
+{
5453
+ struct tep_print_arg *len_arg = NULL;
5454
+ char print_format[32];
5455
+ const char *start = format;
5456
+ int ret = 0;
5457
+ int ls = 0;
5458
+ int res;
5459
+ int len;
5460
+
5461
+ format++;
5462
+ ret++;
5463
+ for (; *format; format++) {
5464
+ switch (*format) {
5465
+ case '#':
5466
+ /* FIXME: need to handle properly */
5467
+ break;
5468
+ case 'h':
5469
+ ls--;
5470
+ break;
5471
+ case 'l':
5472
+ ls++;
5473
+ break;
5474
+ case 'L':
5475
+ ls = 2;
5476
+ break;
5477
+ case '.':
5478
+ case 'z':
5479
+ case 'Z':
5480
+ case '0' ... '9':
5481
+ case '-':
5482
+ break;
5483
+ case '*':
5484
+ /* The argument is the length. */
5485
+ if (!*arg) {
5486
+ do_warning_event(event, "no argument match");
5487
+ event->flags |= TEP_EVENT_FL_FAILED;
5488
+ goto out_failed;
5489
+ }
5490
+ if (len_arg) {
5491
+ do_warning_event(event, "argument already matched");
5492
+ event->flags |= TEP_EVENT_FL_FAILED;
5493
+ goto out_failed;
5494
+ }
5495
+ len_arg = *arg;
5496
+ *arg = (*arg)->next;
5497
+ break;
5498
+ case 'p':
5499
+ if (!*arg) {
5500
+ do_warning_event(event, "no argument match");
5501
+ event->flags |= TEP_EVENT_FL_FAILED;
5502
+ goto out_failed;
5503
+ }
5504
+ res = parse_arg_format_pointer(format + 1);
5505
+ if (res > 0) {
5506
+ format += res;
5507
+ ret += res;
5508
+ }
5509
+ len = ((unsigned long)format + 1) -
5510
+ (unsigned long)start;
5511
+ /* should never happen */
5512
+ if (len > 31) {
5513
+ do_warning_event(event, "bad format!");
5514
+ event->flags |= TEP_EVENT_FL_FAILED;
5515
+ len = 31;
5516
+ }
5517
+ memcpy(print_format, start, len);
5518
+ print_format[len] = 0;
5519
+
5520
+ parse_arg_add(parse, print_format,
5521
+ PRINT_FMT_ARG_POINTER, *arg, len_arg, ls);
5522
+ *arg = (*arg)->next;
5523
+ ret++;
5524
+ return ret;
5525
+ case 'd':
5526
+ case 'u':
5527
+ case 'i':
5528
+ case 'x':
5529
+ case 'X':
5530
+ case 'o':
5531
+ if (!*arg) {
5532
+ do_warning_event(event, "no argument match");
5533
+ event->flags |= TEP_EVENT_FL_FAILED;
5534
+ goto out_failed;
5535
+ }
5536
+
5537
+ len = ((unsigned long)format + 1) -
5538
+ (unsigned long)start;
5539
+
5540
+ /* should never happen */
5541
+ if (len > 30) {
5542
+ do_warning_event(event, "bad format!");
5543
+ event->flags |= TEP_EVENT_FL_FAILED;
5544
+ len = 31;
5545
+ }
5546
+ memcpy(print_format, start, len);
5547
+ print_format[len] = 0;
5548
+
5549
+ if (event->tep->long_size == 8 && ls == 1 &&
5550
+ sizeof(long) != 8) {
5551
+ char *p;
5552
+
5553
+ /* make %l into %ll */
5554
+ if (ls == 1 && (p = strchr(print_format, 'l')))
5555
+ memmove(p+1, p, strlen(p)+1);
5556
+ ls = 2;
5557
+ }
5558
+ if (ls < -2 || ls > 2) {
5559
+ do_warning_event(event, "bad count (%d)", ls);
5560
+ event->flags |= TEP_EVENT_FL_FAILED;
5561
+ }
5562
+ parse_arg_add(parse, print_format,
5563
+ PRINT_FMT_ARG_DIGIT, *arg, len_arg, ls);
5564
+ *arg = (*arg)->next;
5565
+ ret++;
5566
+ return ret;
5567
+ case 's':
5568
+ if (!*arg) {
5569
+ do_warning_event(event, "no matching argument");
5570
+ event->flags |= TEP_EVENT_FL_FAILED;
5571
+ goto out_failed;
5572
+ }
5573
+
5574
+ len = ((unsigned long)format + 1) -
5575
+ (unsigned long)start;
5576
+
5577
+ /* should never happen */
5578
+ if (len > 31) {
5579
+ do_warning_event(event, "bad format!");
5580
+ event->flags |= TEP_EVENT_FL_FAILED;
5581
+ len = 31;
5582
+ }
5583
+
5584
+ memcpy(print_format, start, len);
5585
+ print_format[len] = 0;
5586
+
5587
+ parse_arg_add(parse, print_format,
5588
+ PRINT_FMT_ARG_STRING, *arg, len_arg, 0);
5589
+ *arg = (*arg)->next;
5590
+ ret++;
5591
+ return ret;
5592
+ default:
5593
+ snprintf(print_format, 32, ">%c<", *format);
5594
+ parse_arg_add(parse, print_format,
5595
+ PRINT_FMT_STRING, NULL, NULL, 0);
5596
+ ret++;
5597
+ return ret;
5598
+ }
5599
+ ret++;
5600
+ }
5601
+
5602
+out_failed:
5603
+ return ret;
5604
+
5605
+}
5606
+
5607
+static int parse_arg_string(struct tep_print_parse **parse, const char *format)
5608
+{
5609
+ struct trace_seq s;
5610
+ int ret = 0;
5611
+
5612
+ trace_seq_init(&s);
5613
+ for (; *format; format++) {
5614
+ if (*format == '\\') {
5615
+ format++;
5616
+ ret++;
5617
+ switch (*format) {
5618
+ case 'n':
5619
+ trace_seq_putc(&s, '\n');
5620
+ break;
5621
+ case 't':
5622
+ trace_seq_putc(&s, '\t');
5623
+ break;
5624
+ case 'r':
5625
+ trace_seq_putc(&s, '\r');
5626
+ break;
5627
+ case '\\':
5628
+ trace_seq_putc(&s, '\\');
5629
+ break;
5630
+ default:
5631
+ trace_seq_putc(&s, *format);
5632
+ break;
5633
+ }
5634
+ } else if (*format == '%') {
5635
+ if (*(format + 1) == '%') {
5636
+ trace_seq_putc(&s, '%');
5637
+ format++;
5638
+ ret++;
5639
+ } else
5640
+ break;
5641
+ } else
5642
+ trace_seq_putc(&s, *format);
5643
+
5644
+ ret++;
5645
+ }
5646
+ trace_seq_terminate(&s);
5647
+ parse_arg_add(parse, s.buffer, PRINT_FMT_STRING, NULL, NULL, 0);
5648
+ trace_seq_destroy(&s);
5649
+
5650
+ return ret;
5651
+}
5652
+
5653
+static struct tep_print_parse *
5654
+parse_args(struct tep_event *event, const char *format, struct tep_print_arg *arg)
5655
+{
5656
+ struct tep_print_parse *parse_ret = NULL;
5657
+ struct tep_print_parse **parse = NULL;
5658
+ int ret;
5659
+ int len;
5660
+
5661
+ len = strlen(format);
5662
+ while (*format) {
5663
+ if (!parse_ret)
5664
+ parse = &parse_ret;
5665
+ if (*format == '%' && *(format + 1) != '%')
5666
+ ret = parse_arg_format(parse, event, format, &arg);
5667
+ else
5668
+ ret = parse_arg_string(parse, format);
5669
+ if (*parse)
5670
+ parse = &((*parse)->next);
5671
+
5672
+ len -= ret;
5673
+ if (len > 0)
5674
+ format += ret;
5675
+ else
5676
+ break;
5677
+ }
5678
+ return parse_ret;
5679
+}
5680
+
5681
+static void print_event_cache(struct tep_print_parse *parse, struct trace_seq *s,
5682
+ void *data, int size, struct tep_event *event)
5683
+{
5684
+ int len_arg;
5685
+
5686
+ while (parse) {
5687
+ if (parse->len_as_arg)
5688
+ len_arg = eval_num_arg(data, size, event, parse->len_as_arg);
5689
+ switch (parse->type) {
5690
+ case PRINT_FMT_ARG_DIGIT:
5691
+ print_arg_number(s, parse->format,
5692
+ parse->len_as_arg ? len_arg : -1, data,
5693
+ size, parse->ls, event, parse->arg);
5694
+ break;
5695
+ case PRINT_FMT_ARG_POINTER:
5696
+ print_arg_pointer(s, parse->format,
5697
+ parse->len_as_arg ? len_arg : 1,
5698
+ data, size, event, parse->arg);
5699
+ break;
5700
+ case PRINT_FMT_ARG_STRING:
5701
+ print_arg_string(s, parse->format,
5702
+ parse->len_as_arg ? len_arg : -1,
5703
+ data, size, event, parse->arg);
5704
+ break;
5705
+ case PRINT_FMT_STRING:
5706
+ default:
5707
+ trace_seq_printf(s, "%s", parse->format);
5708
+ break;
5709
+ }
5710
+ parse = parse->next;
5711
+ }
5712
+}
5713
+
5714
+static void pretty_print(struct trace_seq *s, void *data, int size, struct tep_event *event)
5715
+{
5716
+ struct tep_print_parse *parse = event->print_fmt.print_cache;
5717
+ struct tep_print_arg *args = NULL;
5718
+ char *bprint_fmt = NULL;
5719
+
5720
+ if (event->flags & TEP_EVENT_FL_FAILED) {
48875721 trace_seq_printf(s, "[FAILED TO PARSE]");
48885722 tep_print_fields(s, data, size, event);
48895723 return;
48905724 }
48915725
4892
- if (event->flags & EVENT_FL_ISBPRINT) {
5726
+ if (event->flags & TEP_EVENT_FL_ISBPRINT) {
48935727 bprint_fmt = get_bprint_format(data, size, event);
48945728 args = make_bprint_args(bprint_fmt, data, size, event);
4895
- arg = args;
4896
- ptr = bprint_fmt;
5729
+ parse = parse_args(event, bprint_fmt, args);
48975730 }
48985731
4899
- for (; *ptr; ptr++) {
4900
- ls = 0;
4901
- if (*ptr == '\\') {
4902
- ptr++;
4903
- switch (*ptr) {
4904
- case 'n':
4905
- trace_seq_putc(s, '\n');
4906
- break;
4907
- case 't':
4908
- trace_seq_putc(s, '\t');
4909
- break;
4910
- case 'r':
4911
- trace_seq_putc(s, '\r');
4912
- break;
4913
- case '\\':
4914
- trace_seq_putc(s, '\\');
4915
- break;
4916
- default:
4917
- trace_seq_putc(s, *ptr);
4918
- break;
4919
- }
5732
+ print_event_cache(parse, s, data, size, event);
49205733
4921
- } else if (*ptr == '%') {
4922
- saveptr = ptr;
4923
- show_func = 0;
4924
- len_as_arg = 0;
4925
- cont_process:
4926
- ptr++;
4927
- switch (*ptr) {
4928
- case '%':
4929
- trace_seq_putc(s, '%');
4930
- break;
4931
- case '#':
4932
- /* FIXME: need to handle properly */
4933
- goto cont_process;
4934
- case 'h':
4935
- ls--;
4936
- goto cont_process;
4937
- case 'l':
4938
- ls++;
4939
- goto cont_process;
4940
- case 'L':
4941
- ls = 2;
4942
- goto cont_process;
4943
- case '*':
4944
- /* The argument is the length. */
4945
- if (!arg) {
4946
- do_warning_event(event, "no argument match");
4947
- event->flags |= EVENT_FL_FAILED;
4948
- goto out_failed;
4949
- }
4950
- len_arg = eval_num_arg(data, size, event, arg);
4951
- len_as_arg = 1;
4952
- arg = arg->next;
4953
- goto cont_process;
4954
- case '.':
4955
- case 'z':
4956
- case 'Z':
4957
- case '0' ... '9':
4958
- case '-':
4959
- goto cont_process;
4960
- case 'p':
4961
- if (pevent->long_size == 4)
4962
- ls = 1;
4963
- else
4964
- ls = 2;
4965
-
4966
- if (isalnum(ptr[1]))
4967
- ptr++;
4968
-
4969
- if (arg->type == PRINT_BSTRING) {
4970
- trace_seq_puts(s, arg->string.string);
4971
- arg = arg->next;
4972
- break;
4973
- }
4974
-
4975
- if (*ptr == 'F' || *ptr == 'f' ||
4976
- *ptr == 'S' || *ptr == 's') {
4977
- show_func = *ptr;
4978
- } else if (*ptr == 'M' || *ptr == 'm') {
4979
- print_mac_arg(s, *ptr, data, size, event, arg);
4980
- arg = arg->next;
4981
- break;
4982
- } else if (*ptr == 'I' || *ptr == 'i') {
4983
- int n;
4984
-
4985
- n = print_ip_arg(s, ptr, data, size, event, arg);
4986
- if (n > 0) {
4987
- ptr += n - 1;
4988
- arg = arg->next;
4989
- break;
4990
- }
4991
- }
4992
-
4993
- /* fall through */
4994
- case 'd':
4995
- case 'i':
4996
- case 'x':
4997
- case 'X':
4998
- case 'u':
4999
- if (!arg) {
5000
- do_warning_event(event, "no argument match");
5001
- event->flags |= EVENT_FL_FAILED;
5002
- goto out_failed;
5003
- }
5004
-
5005
- len = ((unsigned long)ptr + 1) -
5006
- (unsigned long)saveptr;
5007
-
5008
- /* should never happen */
5009
- if (len > 31) {
5010
- do_warning_event(event, "bad format!");
5011
- event->flags |= EVENT_FL_FAILED;
5012
- len = 31;
5013
- }
5014
-
5015
- memcpy(format, saveptr, len);
5016
- format[len] = 0;
5017
-
5018
- val = eval_num_arg(data, size, event, arg);
5019
- arg = arg->next;
5020
-
5021
- if (show_func) {
5022
- func = find_func(pevent, val);
5023
- if (func) {
5024
- trace_seq_puts(s, func->func);
5025
- if (show_func == 'F')
5026
- trace_seq_printf(s,
5027
- "+0x%llx",
5028
- val - func->addr);
5029
- break;
5030
- }
5031
- }
5032
- if (pevent->long_size == 8 && ls == 1 &&
5033
- sizeof(long) != 8) {
5034
- char *p;
5035
-
5036
- /* make %l into %ll */
5037
- if (ls == 1 && (p = strchr(format, 'l')))
5038
- memmove(p+1, p, strlen(p)+1);
5039
- else if (strcmp(format, "%p") == 0)
5040
- strcpy(format, "0x%llx");
5041
- ls = 2;
5042
- }
5043
- switch (ls) {
5044
- case -2:
5045
- if (len_as_arg)
5046
- trace_seq_printf(s, format, len_arg, (char)val);
5047
- else
5048
- trace_seq_printf(s, format, (char)val);
5049
- break;
5050
- case -1:
5051
- if (len_as_arg)
5052
- trace_seq_printf(s, format, len_arg, (short)val);
5053
- else
5054
- trace_seq_printf(s, format, (short)val);
5055
- break;
5056
- case 0:
5057
- if (len_as_arg)
5058
- trace_seq_printf(s, format, len_arg, (int)val);
5059
- else
5060
- trace_seq_printf(s, format, (int)val);
5061
- break;
5062
- case 1:
5063
- if (len_as_arg)
5064
- trace_seq_printf(s, format, len_arg, (long)val);
5065
- else
5066
- trace_seq_printf(s, format, (long)val);
5067
- break;
5068
- case 2:
5069
- if (len_as_arg)
5070
- trace_seq_printf(s, format, len_arg,
5071
- (long long)val);
5072
- else
5073
- trace_seq_printf(s, format, (long long)val);
5074
- break;
5075
- default:
5076
- do_warning_event(event, "bad count (%d)", ls);
5077
- event->flags |= EVENT_FL_FAILED;
5078
- }
5079
- break;
5080
- case 's':
5081
- if (!arg) {
5082
- do_warning_event(event, "no matching argument");
5083
- event->flags |= EVENT_FL_FAILED;
5084
- goto out_failed;
5085
- }
5086
-
5087
- len = ((unsigned long)ptr + 1) -
5088
- (unsigned long)saveptr;
5089
-
5090
- /* should never happen */
5091
- if (len > 31) {
5092
- do_warning_event(event, "bad format!");
5093
- event->flags |= EVENT_FL_FAILED;
5094
- len = 31;
5095
- }
5096
-
5097
- memcpy(format, saveptr, len);
5098
- format[len] = 0;
5099
- if (!len_as_arg)
5100
- len_arg = -1;
5101
- /* Use helper trace_seq */
5102
- trace_seq_init(&p);
5103
- print_str_arg(&p, data, size, event,
5104
- format, len_arg, arg);
5105
- trace_seq_terminate(&p);
5106
- trace_seq_puts(s, p.buffer);
5107
- trace_seq_destroy(&p);
5108
- arg = arg->next;
5109
- break;
5110
- default:
5111
- trace_seq_printf(s, ">%c<", *ptr);
5112
-
5113
- }
5114
- } else
5115
- trace_seq_putc(s, *ptr);
5116
- }
5117
-
5118
- if (event->flags & EVENT_FL_FAILED) {
5119
-out_failed:
5120
- trace_seq_printf(s, "[FAILED TO PARSE]");
5121
- }
5122
-
5123
- if (args) {
5734
+ if (event->flags & TEP_EVENT_FL_ISBPRINT) {
5735
+ free_parse_args(parse);
51245736 free_args(args);
51255737 free(bprint_fmt);
51265738 }
51275739 }
51285740
5129
-/**
5130
- * tep_data_lat_fmt - parse the data for the latency format
5131
- * @pevent: a handle to the pevent
5132
- * @s: the trace_seq to write to
5133
- * @record: the record to read from
5134
- *
5741
+/*
51355742 * This parses out the Latency format (interrupts disabled,
51365743 * need rescheduling, in hard/soft interrupt, preempt count
51375744 * and lock depth) and places it into the trace_seq.
51385745 */
5139
-void tep_data_lat_fmt(struct tep_handle *pevent,
5140
- struct trace_seq *s, struct tep_record *record)
5746
+static void data_latency_format(struct tep_handle *tep, struct trace_seq *s,
5747
+ char *format, struct tep_record *record)
51415748 {
51425749 static int check_lock_depth = 1;
51435750 static int check_migrate_disable = 1;
51445751 static int lock_depth_exists;
51455752 static int migrate_disable_exists;
51465753 unsigned int lat_flags;
5754
+ struct trace_seq sq;
51475755 unsigned int pc;
5148
- int lock_depth;
5149
- int migrate_disable;
5756
+ int lock_depth = 0;
5757
+ int migrate_disable = 0;
51505758 int hardirq;
51515759 int softirq;
51525760 void *data = record->data;
51535761
5154
- lat_flags = parse_common_flags(pevent, data);
5155
- pc = parse_common_pc(pevent, data);
5762
+ trace_seq_init(&sq);
5763
+ lat_flags = parse_common_flags(tep, data);
5764
+ pc = parse_common_pc(tep, data);
51565765 /* lock_depth may not always exist */
51575766 if (lock_depth_exists)
5158
- lock_depth = parse_common_lock_depth(pevent, data);
5767
+ lock_depth = parse_common_lock_depth(tep, data);
51595768 else if (check_lock_depth) {
5160
- lock_depth = parse_common_lock_depth(pevent, data);
5769
+ lock_depth = parse_common_lock_depth(tep, data);
51615770 if (lock_depth < 0)
51625771 check_lock_depth = 0;
51635772 else
....@@ -5166,9 +5775,9 @@
51665775
51675776 /* migrate_disable may not always exist */
51685777 if (migrate_disable_exists)
5169
- migrate_disable = parse_common_migrate_disable(pevent, data);
5778
+ migrate_disable = parse_common_migrate_disable(tep, data);
51705779 else if (check_migrate_disable) {
5171
- migrate_disable = parse_common_migrate_disable(pevent, data);
5780
+ migrate_disable = parse_common_migrate_disable(tep, data);
51725781 if (migrate_disable < 0)
51735782 check_migrate_disable = 0;
51745783 else
....@@ -5178,7 +5787,7 @@
51785787 hardirq = lat_flags & TRACE_FLAG_HARDIRQ;
51795788 softirq = lat_flags & TRACE_FLAG_SOFTIRQ;
51805789
5181
- trace_seq_printf(s, "%c%c%c",
5790
+ trace_seq_printf(&sq, "%c%c%c",
51825791 (lat_flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
51835792 (lat_flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
51845793 'X' : '.',
....@@ -5188,162 +5797,158 @@
51885797 hardirq ? 'h' : softirq ? 's' : '.');
51895798
51905799 if (pc)
5191
- trace_seq_printf(s, "%x", pc);
5800
+ trace_seq_printf(&sq, "%x", pc);
51925801 else
5193
- trace_seq_putc(s, '.');
5802
+ trace_seq_printf(&sq, ".");
51945803
51955804 if (migrate_disable_exists) {
51965805 if (migrate_disable < 0)
5197
- trace_seq_putc(s, '.');
5806
+ trace_seq_printf(&sq, ".");
51985807 else
5199
- trace_seq_printf(s, "%d", migrate_disable);
5808
+ trace_seq_printf(&sq, "%d", migrate_disable);
52005809 }
52015810
52025811 if (lock_depth_exists) {
52035812 if (lock_depth < 0)
5204
- trace_seq_putc(s, '.');
5813
+ trace_seq_printf(&sq, ".");
52055814 else
5206
- trace_seq_printf(s, "%d", lock_depth);
5815
+ trace_seq_printf(&sq, "%d", lock_depth);
52075816 }
52085817
5818
+ if (sq.state == TRACE_SEQ__MEM_ALLOC_FAILED) {
5819
+ s->state = TRACE_SEQ__MEM_ALLOC_FAILED;
5820
+ return;
5821
+ }
5822
+
5823
+ trace_seq_terminate(&sq);
5824
+ trace_seq_puts(s, sq.buffer);
5825
+ trace_seq_destroy(&sq);
52095826 trace_seq_terminate(s);
52105827 }
52115828
52125829 /**
52135830 * tep_data_type - parse out the given event type
5214
- * @pevent: a handle to the pevent
5831
+ * @tep: a handle to the trace event parser context
52155832 * @rec: the record to read from
52165833 *
52175834 * This returns the event id from the @rec.
52185835 */
5219
-int tep_data_type(struct tep_handle *pevent, struct tep_record *rec)
5836
+int tep_data_type(struct tep_handle *tep, struct tep_record *rec)
52205837 {
5221
- return trace_parse_common_type(pevent, rec->data);
5222
-}
5223
-
5224
-/**
5225
- * tep_data_event_from_type - find the event by a given type
5226
- * @pevent: a handle to the pevent
5227
- * @type: the type of the event.
5228
- *
5229
- * This returns the event form a given @type;
5230
- */
5231
-struct event_format *tep_data_event_from_type(struct tep_handle *pevent, int type)
5232
-{
5233
- return tep_find_event(pevent, type);
5838
+ return trace_parse_common_type(tep, rec->data);
52345839 }
52355840
52365841 /**
52375842 * tep_data_pid - parse the PID from record
5238
- * @pevent: a handle to the pevent
5843
+ * @tep: a handle to the trace event parser context
52395844 * @rec: the record to parse
52405845 *
52415846 * This returns the PID from a record.
52425847 */
5243
-int tep_data_pid(struct tep_handle *pevent, struct tep_record *rec)
5848
+int tep_data_pid(struct tep_handle *tep, struct tep_record *rec)
52445849 {
5245
- return parse_common_pid(pevent, rec->data);
5850
+ return parse_common_pid(tep, rec->data);
52465851 }
52475852
52485853 /**
52495854 * tep_data_preempt_count - parse the preempt count from the record
5250
- * @pevent: a handle to the pevent
5855
+ * @tep: a handle to the trace event parser context
52515856 * @rec: the record to parse
52525857 *
52535858 * This returns the preempt count from a record.
52545859 */
5255
-int tep_data_preempt_count(struct tep_handle *pevent, struct tep_record *rec)
5860
+int tep_data_preempt_count(struct tep_handle *tep, struct tep_record *rec)
52565861 {
5257
- return parse_common_pc(pevent, rec->data);
5862
+ return parse_common_pc(tep, rec->data);
52585863 }
52595864
52605865 /**
52615866 * tep_data_flags - parse the latency flags from the record
5262
- * @pevent: a handle to the pevent
5867
+ * @tep: a handle to the trace event parser context
52635868 * @rec: the record to parse
52645869 *
52655870 * This returns the latency flags from a record.
52665871 *
52675872 * Use trace_flag_type enum for the flags (see event-parse.h).
52685873 */
5269
-int tep_data_flags(struct tep_handle *pevent, struct tep_record *rec)
5874
+int tep_data_flags(struct tep_handle *tep, struct tep_record *rec)
52705875 {
5271
- return parse_common_flags(pevent, rec->data);
5876
+ return parse_common_flags(tep, rec->data);
52725877 }
52735878
52745879 /**
52755880 * tep_data_comm_from_pid - return the command line from PID
5276
- * @pevent: a handle to the pevent
5881
+ * @tep: a handle to the trace event parser context
52775882 * @pid: the PID of the task to search for
52785883 *
52795884 * This returns a pointer to the command line that has the given
52805885 * @pid.
52815886 */
5282
-const char *tep_data_comm_from_pid(struct tep_handle *pevent, int pid)
5887
+const char *tep_data_comm_from_pid(struct tep_handle *tep, int pid)
52835888 {
52845889 const char *comm;
52855890
5286
- comm = find_cmdline(pevent, pid);
5891
+ comm = find_cmdline(tep, pid);
52875892 return comm;
52885893 }
52895894
5290
-static struct cmdline *
5291
-pid_from_cmdlist(struct tep_handle *pevent, const char *comm, struct cmdline *next)
5895
+static struct tep_cmdline *
5896
+pid_from_cmdlist(struct tep_handle *tep, const char *comm, struct tep_cmdline *next)
52925897 {
52935898 struct cmdline_list *cmdlist = (struct cmdline_list *)next;
52945899
52955900 if (cmdlist)
52965901 cmdlist = cmdlist->next;
52975902 else
5298
- cmdlist = pevent->cmdlist;
5903
+ cmdlist = tep->cmdlist;
52995904
53005905 while (cmdlist && strcmp(cmdlist->comm, comm) != 0)
53015906 cmdlist = cmdlist->next;
53025907
5303
- return (struct cmdline *)cmdlist;
5908
+ return (struct tep_cmdline *)cmdlist;
53045909 }
53055910
53065911 /**
53075912 * tep_data_pid_from_comm - return the pid from a given comm
5308
- * @pevent: a handle to the pevent
5913
+ * @tep: a handle to the trace event parser context
53095914 * @comm: the cmdline to find the pid from
53105915 * @next: the cmdline structure to find the next comm
53115916 *
53125917 * This returns the cmdline structure that holds a pid for a given
53135918 * comm, or NULL if none found. As there may be more than one pid for
53145919 * a given comm, the result of this call can be passed back into
5315
- * a recurring call in the @next paramater, and then it will find the
5920
+ * a recurring call in the @next parameter, and then it will find the
53165921 * next pid.
5317
- * Also, it does a linear seach, so it may be slow.
5922
+ * Also, it does a linear search, so it may be slow.
53185923 */
5319
-struct cmdline *tep_data_pid_from_comm(struct tep_handle *pevent, const char *comm,
5320
- struct cmdline *next)
5924
+struct tep_cmdline *tep_data_pid_from_comm(struct tep_handle *tep, const char *comm,
5925
+ struct tep_cmdline *next)
53215926 {
5322
- struct cmdline *cmdline;
5927
+ struct tep_cmdline *cmdline;
53235928
53245929 /*
53255930 * If the cmdlines have not been converted yet, then use
53265931 * the list.
53275932 */
5328
- if (!pevent->cmdlines)
5329
- return pid_from_cmdlist(pevent, comm, next);
5933
+ if (!tep->cmdlines)
5934
+ return pid_from_cmdlist(tep, comm, next);
53305935
53315936 if (next) {
53325937 /*
53335938 * The next pointer could have been still from
53345939 * a previous call before cmdlines were created
53355940 */
5336
- if (next < pevent->cmdlines ||
5337
- next >= pevent->cmdlines + pevent->cmdline_count)
5941
+ if (next < tep->cmdlines ||
5942
+ next >= tep->cmdlines + tep->cmdline_count)
53385943 next = NULL;
53395944 else
53405945 cmdline = next++;
53415946 }
53425947
53435948 if (!next)
5344
- cmdline = pevent->cmdlines;
5949
+ cmdline = tep->cmdlines;
53455950
5346
- while (cmdline < pevent->cmdlines + pevent->cmdline_count) {
5951
+ while (cmdline < tep->cmdlines + tep->cmdline_count) {
53475952 if (strcmp(cmdline->comm, comm) == 0)
53485953 return cmdline;
53495954 cmdline++;
....@@ -5353,12 +5958,13 @@
53535958
53545959 /**
53555960 * tep_cmdline_pid - return the pid associated to a given cmdline
5961
+ * @tep: a handle to the trace event parser context
53565962 * @cmdline: The cmdline structure to get the pid from
53575963 *
53585964 * Returns the pid for a give cmdline. If @cmdline is NULL, then
53595965 * -1 is returned.
53605966 */
5361
-int tep_cmdline_pid(struct tep_handle *pevent, struct cmdline *cmdline)
5967
+int tep_cmdline_pid(struct tep_handle *tep, struct tep_cmdline *cmdline)
53625968 {
53635969 struct cmdline_list *cmdlist = (struct cmdline_list *)cmdline;
53645970
....@@ -5369,33 +5975,28 @@
53695975 * If cmdlines have not been created yet, or cmdline is
53705976 * not part of the array, then treat it as a cmdlist instead.
53715977 */
5372
- if (!pevent->cmdlines ||
5373
- cmdline < pevent->cmdlines ||
5374
- cmdline >= pevent->cmdlines + pevent->cmdline_count)
5978
+ if (!tep->cmdlines ||
5979
+ cmdline < tep->cmdlines ||
5980
+ cmdline >= tep->cmdlines + tep->cmdline_count)
53755981 return cmdlist->pid;
53765982
53775983 return cmdline->pid;
53785984 }
53795985
5380
-/**
5381
- * tep_event_info - parse the data into the print format
5382
- * @s: the trace_seq to write to
5383
- * @event: the handle to the event
5384
- * @record: the record to read from
5385
- *
5986
+/*
53865987 * This parses the raw @data using the given @event information and
53875988 * writes the print format into the trace_seq.
53885989 */
5389
-void tep_event_info(struct trace_seq *s, struct event_format *event,
5390
- struct tep_record *record)
5990
+static void print_event_info(struct trace_seq *s, char *format, bool raw,
5991
+ struct tep_event *event, struct tep_record *record)
53915992 {
53925993 int print_pretty = 1;
53935994
5394
- if (event->pevent->print_raw || (event->flags & EVENT_FL_PRINTRAW))
5995
+ if (raw || (event->flags & TEP_EVENT_FL_PRINTRAW))
53955996 tep_print_fields(s, record->data, record->size, event);
53965997 else {
53975998
5398
- if (event->handler && !(event->flags & EVENT_FL_NOHANDLE))
5999
+ if (event->handler && !(event->flags & TEP_EVENT_FL_NOHANDLE))
53996000 print_pretty = event->handler(s, record, event,
54006001 event->context);
54016002
....@@ -5406,29 +6007,16 @@
54066007 trace_seq_terminate(s);
54076008 }
54086009
5409
-static bool is_timestamp_in_us(char *trace_clock, bool use_trace_clock)
5410
-{
5411
- if (!use_trace_clock)
5412
- return true;
5413
-
5414
- if (!strcmp(trace_clock, "local") || !strcmp(trace_clock, "global")
5415
- || !strcmp(trace_clock, "uptime") || !strcmp(trace_clock, "perf"))
5416
- return true;
5417
-
5418
- /* trace_clock is setting in tsc or counter mode */
5419
- return false;
5420
-}
5421
-
54226010 /**
54236011 * tep_find_event_by_record - return the event from a given record
5424
- * @pevent: a handle to the pevent
6012
+ * @tep: a handle to the trace event parser context
54256013 * @record: The record to get the event from
54266014 *
54276015 * Returns the associated event for a given record, or NULL if non is
54286016 * is found.
54296017 */
5430
-struct event_format *
5431
-tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record)
6018
+struct tep_event *
6019
+tep_find_event_by_record(struct tep_handle *tep, struct tep_record *record)
54326020 {
54336021 int type;
54346022
....@@ -5437,142 +6025,208 @@
54376025 return NULL;
54386026 }
54396027
5440
- type = trace_parse_common_type(pevent, record->data);
6028
+ type = trace_parse_common_type(tep, record->data);
54416029
5442
- return tep_find_event(pevent, type);
6030
+ return tep_find_event(tep, type);
54436031 }
54446032
5445
-/**
5446
- * tep_print_event_task - Write the event task comm, pid and CPU
5447
- * @pevent: a handle to the pevent
5448
- * @s: the trace_seq to write to
5449
- * @event: the handle to the record's event
5450
- * @record: The record to get the event from
5451
- *
5452
- * Writes the tasks comm, pid and CPU to @s.
6033
+/*
6034
+ * Writes the timestamp of the record into @s. Time divisor and precision can be
6035
+ * specified as part of printf @format string. Example:
6036
+ * "%3.1000d" - divide the time by 1000 and print the first 3 digits
6037
+ * before the dot. Thus, the timestamp "123456000" will be printed as
6038
+ * "123.456"
54536039 */
5454
-void tep_print_event_task(struct tep_handle *pevent, struct trace_seq *s,
5455
- struct event_format *event,
5456
- struct tep_record *record)
6040
+static void print_event_time(struct tep_handle *tep, struct trace_seq *s,
6041
+ char *format, struct tep_event *event,
6042
+ struct tep_record *record)
54576043 {
5458
- void *data = record->data;
6044
+ unsigned long long time;
6045
+ char *divstr;
6046
+ int prec = 0, pr;
6047
+ int div = 0;
6048
+ int p10 = 1;
6049
+
6050
+ if (isdigit(*(format + 1)))
6051
+ prec = atoi(format + 1);
6052
+ divstr = strchr(format, '.');
6053
+ if (divstr && isdigit(*(divstr + 1)))
6054
+ div = atoi(divstr + 1);
6055
+ time = record->ts;
6056
+ if (div) {
6057
+ time += div / 2;
6058
+ time /= div;
6059
+ }
6060
+ pr = prec;
6061
+ while (pr--)
6062
+ p10 *= 10;
6063
+
6064
+ if (p10 > 1 && p10 < time)
6065
+ trace_seq_printf(s, "%5llu.%0*llu", time / p10, prec, time % p10);
6066
+ else
6067
+ trace_seq_printf(s, "%12llu", time);
6068
+}
6069
+
6070
+struct print_event_type {
6071
+ enum {
6072
+ EVENT_TYPE_INT = 1,
6073
+ EVENT_TYPE_STRING,
6074
+ EVENT_TYPE_UNKNOWN,
6075
+ } type;
6076
+ char format[32];
6077
+};
6078
+
6079
+static void print_string(struct tep_handle *tep, struct trace_seq *s,
6080
+ struct tep_record *record, struct tep_event *event,
6081
+ const char *arg, struct print_event_type *type)
6082
+{
54596083 const char *comm;
54606084 int pid;
54616085
5462
- pid = parse_common_pid(pevent, data);
5463
- comm = find_cmdline(pevent, pid);
5464
-
5465
- if (pevent->latency_format) {
5466
- trace_seq_printf(s, "%8.8s-%-5d %3d",
5467
- comm, pid, record->cpu);
5468
- } else
5469
- trace_seq_printf(s, "%16s-%-5d [%03d]", comm, pid, record->cpu);
5470
-}
5471
-
5472
-/**
5473
- * tep_print_event_time - Write the event timestamp
5474
- * @pevent: a handle to the pevent
5475
- * @s: the trace_seq to write to
5476
- * @event: the handle to the record's event
5477
- * @record: The record to get the event from
5478
- * @use_trace_clock: Set to parse according to the @pevent->trace_clock
5479
- *
5480
- * Writes the timestamp of the record into @s.
5481
- */
5482
-void tep_print_event_time(struct tep_handle *pevent, struct trace_seq *s,
5483
- struct event_format *event,
5484
- struct tep_record *record,
5485
- bool use_trace_clock)
5486
-{
5487
- unsigned long secs;
5488
- unsigned long usecs;
5489
- unsigned long nsecs;
5490
- int p;
5491
- bool use_usec_format;
5492
-
5493
- use_usec_format = is_timestamp_in_us(pevent->trace_clock,
5494
- use_trace_clock);
5495
- if (use_usec_format) {
5496
- secs = record->ts / NSEC_PER_SEC;
5497
- nsecs = record->ts - secs * NSEC_PER_SEC;
6086
+ if (strncmp(arg, TEP_PRINT_LATENCY, strlen(TEP_PRINT_LATENCY)) == 0) {
6087
+ data_latency_format(tep, s, type->format, record);
6088
+ } else if (strncmp(arg, TEP_PRINT_COMM, strlen(TEP_PRINT_COMM)) == 0) {
6089
+ pid = parse_common_pid(tep, record->data);
6090
+ comm = find_cmdline(tep, pid);
6091
+ trace_seq_printf(s, type->format, comm);
6092
+ } else if (strncmp(arg, TEP_PRINT_INFO_RAW, strlen(TEP_PRINT_INFO_RAW)) == 0) {
6093
+ print_event_info(s, type->format, true, event, record);
6094
+ } else if (strncmp(arg, TEP_PRINT_INFO, strlen(TEP_PRINT_INFO)) == 0) {
6095
+ print_event_info(s, type->format, false, event, record);
6096
+ } else if (strncmp(arg, TEP_PRINT_NAME, strlen(TEP_PRINT_NAME)) == 0) {
6097
+ trace_seq_printf(s, type->format, event->name);
6098
+ } else {
6099
+ trace_seq_printf(s, "[UNKNOWN TEP TYPE %s]", arg);
54986100 }
54996101
5500
- if (pevent->latency_format) {
5501
- tep_data_lat_fmt(pevent, s, record);
5502
- }
5503
-
5504
- if (use_usec_format) {
5505
- if (pevent->flags & TEP_NSEC_OUTPUT) {
5506
- usecs = nsecs;
5507
- p = 9;
5508
- } else {
5509
- usecs = (nsecs + 500) / NSEC_PER_USEC;
5510
- /* To avoid usecs larger than 1 sec */
5511
- if (usecs >= USEC_PER_SEC) {
5512
- usecs -= USEC_PER_SEC;
5513
- secs++;
5514
- }
5515
- p = 6;
5516
- }
5517
-
5518
- trace_seq_printf(s, " %5lu.%0*lu:", secs, p, usecs);
5519
- } else
5520
- trace_seq_printf(s, " %12llu:", record->ts);
55216102 }
55226103
5523
-/**
5524
- * tep_print_event_data - Write the event data section
5525
- * @pevent: a handle to the pevent
5526
- * @s: the trace_seq to write to
5527
- * @event: the handle to the record's event
5528
- * @record: The record to get the event from
5529
- *
5530
- * Writes the parsing of the record's data to @s.
5531
- */
5532
-void tep_print_event_data(struct tep_handle *pevent, struct trace_seq *s,
5533
- struct event_format *event,
5534
- struct tep_record *record)
6104
+static void print_int(struct tep_handle *tep, struct trace_seq *s,
6105
+ struct tep_record *record, struct tep_event *event,
6106
+ int arg, struct print_event_type *type)
55356107 {
5536
- static const char *spaces = " "; /* 20 spaces */
5537
- int len;
6108
+ int param;
55386109
5539
- trace_seq_printf(s, " %s: ", event->name);
5540
-
5541
- /* Space out the event names evenly. */
5542
- len = strlen(event->name);
5543
- if (len < 20)
5544
- trace_seq_printf(s, "%.*s", 20 - len, spaces);
5545
-
5546
- tep_event_info(s, event, record);
5547
-}
5548
-
5549
-void tep_print_event(struct tep_handle *pevent, struct trace_seq *s,
5550
- struct tep_record *record, bool use_trace_clock)
5551
-{
5552
- struct event_format *event;
5553
-
5554
- event = tep_find_event_by_record(pevent, record);
5555
- if (!event) {
5556
- int i;
5557
- int type = trace_parse_common_type(pevent, record->data);
5558
-
5559
- do_warning("ug! no event found for type %d", type);
5560
- trace_seq_printf(s, "[UNKNOWN TYPE %d]", type);
5561
- for (i = 0; i < record->size; i++)
5562
- trace_seq_printf(s, " %02x",
5563
- ((unsigned char *)record->data)[i]);
6110
+ switch (arg) {
6111
+ case TEP_PRINT_CPU:
6112
+ param = record->cpu;
6113
+ break;
6114
+ case TEP_PRINT_PID:
6115
+ param = parse_common_pid(tep, record->data);
6116
+ break;
6117
+ case TEP_PRINT_TIME:
6118
+ return print_event_time(tep, s, type->format, event, record);
6119
+ default:
55646120 return;
55656121 }
6122
+ trace_seq_printf(s, type->format, param);
6123
+}
55666124
5567
- tep_print_event_task(pevent, s, event, record);
5568
- tep_print_event_time(pevent, s, event, record, use_trace_clock);
5569
- tep_print_event_data(pevent, s, event, record);
6125
+static int tep_print_event_param_type(char *format,
6126
+ struct print_event_type *type)
6127
+{
6128
+ char *str = format + 1;
6129
+ int i = 1;
6130
+
6131
+ type->type = EVENT_TYPE_UNKNOWN;
6132
+ while (*str) {
6133
+ switch (*str) {
6134
+ case 'd':
6135
+ case 'u':
6136
+ case 'i':
6137
+ case 'x':
6138
+ case 'X':
6139
+ case 'o':
6140
+ type->type = EVENT_TYPE_INT;
6141
+ break;
6142
+ case 's':
6143
+ type->type = EVENT_TYPE_STRING;
6144
+ break;
6145
+ }
6146
+ str++;
6147
+ i++;
6148
+ if (type->type != EVENT_TYPE_UNKNOWN)
6149
+ break;
6150
+ }
6151
+ memset(type->format, 0, 32);
6152
+ memcpy(type->format, format, i < 32 ? i : 31);
6153
+ return i;
6154
+}
6155
+
6156
+/**
6157
+ * tep_print_event - Write various event information
6158
+ * @tep: a handle to the trace event parser context
6159
+ * @s: the trace_seq to write to
6160
+ * @record: The record to get the event from
6161
+ * @format: a printf format string. Supported event fileds:
6162
+ * TEP_PRINT_PID, "%d" - event PID
6163
+ * TEP_PRINT_CPU, "%d" - event CPU
6164
+ * TEP_PRINT_COMM, "%s" - event command string
6165
+ * TEP_PRINT_NAME, "%s" - event name
6166
+ * TEP_PRINT_LATENCY, "%s" - event latency
6167
+ * TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
6168
+ * can be specified as part of this format string:
6169
+ * "%precision.divisord". Example:
6170
+ * "%3.1000d" - divide the time by 1000 and print the first
6171
+ * 3 digits before the dot. Thus, the time stamp
6172
+ * "123456000" will be printed as "123.456"
6173
+ * TEP_PRINT_INFO, "%s" - event information. If any width is specified in
6174
+ * the format string, the event information will be printed
6175
+ * in raw format.
6176
+ * Writes the specified event information into @s.
6177
+ */
6178
+void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
6179
+ struct tep_record *record, const char *fmt, ...)
6180
+{
6181
+ struct print_event_type type;
6182
+ char *format = strdup(fmt);
6183
+ char *current = format;
6184
+ char *str = format;
6185
+ int offset;
6186
+ va_list args;
6187
+ struct tep_event *event;
6188
+
6189
+ if (!format)
6190
+ return;
6191
+
6192
+ event = tep_find_event_by_record(tep, record);
6193
+ va_start(args, fmt);
6194
+ while (*current) {
6195
+ current = strchr(str, '%');
6196
+ if (!current) {
6197
+ trace_seq_puts(s, str);
6198
+ break;
6199
+ }
6200
+ memset(&type, 0, sizeof(type));
6201
+ offset = tep_print_event_param_type(current, &type);
6202
+ *current = '\0';
6203
+ trace_seq_puts(s, str);
6204
+ current += offset;
6205
+ switch (type.type) {
6206
+ case EVENT_TYPE_STRING:
6207
+ print_string(tep, s, record, event,
6208
+ va_arg(args, char*), &type);
6209
+ break;
6210
+ case EVENT_TYPE_INT:
6211
+ print_int(tep, s, record, event,
6212
+ va_arg(args, int), &type);
6213
+ break;
6214
+ case EVENT_TYPE_UNKNOWN:
6215
+ default:
6216
+ trace_seq_printf(s, "[UNKNOWN TYPE]");
6217
+ break;
6218
+ }
6219
+ str = current;
6220
+
6221
+ }
6222
+ va_end(args);
6223
+ free(format);
55706224 }
55716225
55726226 static int events_id_cmp(const void *a, const void *b)
55736227 {
5574
- struct event_format * const * ea = a;
5575
- struct event_format * const * eb = b;
6228
+ struct tep_event * const * ea = a;
6229
+ struct tep_event * const * eb = b;
55766230
55776231 if ((*ea)->id < (*eb)->id)
55786232 return -1;
....@@ -5585,8 +6239,8 @@
55856239
55866240 static int events_name_cmp(const void *a, const void *b)
55876241 {
5588
- struct event_format * const * ea = a;
5589
- struct event_format * const * eb = b;
6242
+ struct tep_event * const * ea = a;
6243
+ struct tep_event * const * eb = b;
55906244 int res;
55916245
55926246 res = strcmp((*ea)->name, (*eb)->name);
....@@ -5602,8 +6256,8 @@
56026256
56036257 static int events_system_cmp(const void *a, const void *b)
56046258 {
5605
- struct event_format * const * ea = a;
5606
- struct event_format * const * eb = b;
6259
+ struct tep_event * const * ea = a;
6260
+ struct tep_event * const * eb = b;
56076261 int res;
56086262
56096263 res = strcmp((*ea)->system, (*eb)->system);
....@@ -5617,59 +6271,124 @@
56176271 return events_id_cmp(a, b);
56186272 }
56196273
5620
-struct event_format **tep_list_events(struct tep_handle *pevent, enum event_sort_type sort_type)
6274
+static struct tep_event **list_events_copy(struct tep_handle *tep)
56216275 {
5622
- struct event_format **events;
6276
+ struct tep_event **events;
6277
+
6278
+ if (!tep)
6279
+ return NULL;
6280
+
6281
+ events = malloc(sizeof(*events) * (tep->nr_events + 1));
6282
+ if (!events)
6283
+ return NULL;
6284
+
6285
+ memcpy(events, tep->events, sizeof(*events) * tep->nr_events);
6286
+ events[tep->nr_events] = NULL;
6287
+ return events;
6288
+}
6289
+
6290
+static void list_events_sort(struct tep_event **events, int nr_events,
6291
+ enum tep_event_sort_type sort_type)
6292
+{
56236293 int (*sort)(const void *a, const void *b);
56246294
5625
- events = pevent->sort_events;
6295
+ switch (sort_type) {
6296
+ case TEP_EVENT_SORT_ID:
6297
+ sort = events_id_cmp;
6298
+ break;
6299
+ case TEP_EVENT_SORT_NAME:
6300
+ sort = events_name_cmp;
6301
+ break;
6302
+ case TEP_EVENT_SORT_SYSTEM:
6303
+ sort = events_system_cmp;
6304
+ break;
6305
+ default:
6306
+ sort = NULL;
6307
+ }
56266308
5627
- if (events && pevent->last_type == sort_type)
6309
+ if (sort)
6310
+ qsort(events, nr_events, sizeof(*events), sort);
6311
+}
6312
+
6313
+/**
6314
+ * tep_list_events - Get events, sorted by given criteria.
6315
+ * @tep: a handle to the tep context
6316
+ * @sort_type: desired sort order of the events in the array
6317
+ *
6318
+ * Returns an array of pointers to all events, sorted by the given
6319
+ * @sort_type criteria. The last element of the array is NULL. The returned
6320
+ * memory must not be freed, it is managed by the library.
6321
+ * The function is not thread safe.
6322
+ */
6323
+struct tep_event **tep_list_events(struct tep_handle *tep,
6324
+ enum tep_event_sort_type sort_type)
6325
+{
6326
+ struct tep_event **events;
6327
+
6328
+ if (!tep)
6329
+ return NULL;
6330
+
6331
+ events = tep->sort_events;
6332
+ if (events && tep->last_type == sort_type)
56286333 return events;
56296334
56306335 if (!events) {
5631
- events = malloc(sizeof(*events) * (pevent->nr_events + 1));
6336
+ events = list_events_copy(tep);
56326337 if (!events)
56336338 return NULL;
56346339
5635
- memcpy(events, pevent->events, sizeof(*events) * pevent->nr_events);
5636
- events[pevent->nr_events] = NULL;
5637
-
5638
- pevent->sort_events = events;
6340
+ tep->sort_events = events;
56396341
56406342 /* the internal events are sorted by id */
5641
- if (sort_type == EVENT_SORT_ID) {
5642
- pevent->last_type = sort_type;
6343
+ if (sort_type == TEP_EVENT_SORT_ID) {
6344
+ tep->last_type = sort_type;
56436345 return events;
56446346 }
56456347 }
56466348
5647
- switch (sort_type) {
5648
- case EVENT_SORT_ID:
5649
- sort = events_id_cmp;
5650
- break;
5651
- case EVENT_SORT_NAME:
5652
- sort = events_name_cmp;
5653
- break;
5654
- case EVENT_SORT_SYSTEM:
5655
- sort = events_system_cmp;
5656
- break;
5657
- default:
5658
- return events;
5659
- }
5660
-
5661
- qsort(events, pevent->nr_events, sizeof(*events), sort);
5662
- pevent->last_type = sort_type;
6349
+ list_events_sort(events, tep->nr_events, sort_type);
6350
+ tep->last_type = sort_type;
56636351
56646352 return events;
56656353 }
56666354
5667
-static struct format_field **
5668
-get_event_fields(const char *type, const char *name,
5669
- int count, struct format_field *list)
6355
+
6356
+/**
6357
+ * tep_list_events_copy - Thread safe version of tep_list_events()
6358
+ * @tep: a handle to the tep context
6359
+ * @sort_type: desired sort order of the events in the array
6360
+ *
6361
+ * Returns an array of pointers to all events, sorted by the given
6362
+ * @sort_type criteria. The last element of the array is NULL. The returned
6363
+ * array is newly allocated inside the function and must be freed by the caller
6364
+ */
6365
+struct tep_event **tep_list_events_copy(struct tep_handle *tep,
6366
+ enum tep_event_sort_type sort_type)
56706367 {
5671
- struct format_field **fields;
5672
- struct format_field *field;
6368
+ struct tep_event **events;
6369
+
6370
+ if (!tep)
6371
+ return NULL;
6372
+
6373
+ events = list_events_copy(tep);
6374
+ if (!events)
6375
+ return NULL;
6376
+
6377
+ /* the internal events are sorted by id */
6378
+ if (sort_type == TEP_EVENT_SORT_ID)
6379
+ return events;
6380
+
6381
+ list_events_sort(events, tep->nr_events, sort_type);
6382
+
6383
+ return events;
6384
+}
6385
+
6386
+static struct tep_format_field **
6387
+get_event_fields(const char *type, const char *name,
6388
+ int count, struct tep_format_field *list)
6389
+{
6390
+ struct tep_format_field **fields;
6391
+ struct tep_format_field *field;
56736392 int i = 0;
56746393
56756394 fields = malloc(sizeof(*fields) * (count + 1));
....@@ -5702,7 +6421,7 @@
57026421 * Returns an allocated array of fields. The last item in the array is NULL.
57036422 * The array must be freed with free().
57046423 */
5705
-struct format_field **tep_event_common_fields(struct event_format *event)
6424
+struct tep_format_field **tep_event_common_fields(struct tep_event *event)
57066425 {
57076426 return get_event_fields("common", event->name,
57086427 event->format.nr_common,
....@@ -5716,14 +6435,14 @@
57166435 * Returns an allocated array of fields. The last item in the array is NULL.
57176436 * The array must be freed with free().
57186437 */
5719
-struct format_field **tep_event_fields(struct event_format *event)
6438
+struct tep_format_field **tep_event_fields(struct tep_event *event)
57206439 {
57216440 return get_event_fields("event", event->name,
57226441 event->format.nr_fields,
57236442 event->format.fields);
57246443 }
57256444
5726
-static void print_fields(struct trace_seq *s, struct print_flag_sym *field)
6445
+static void print_fields(struct trace_seq *s, struct tep_print_flag_sym *field)
57276446 {
57286447 trace_seq_printf(s, "{ %s, %s }", field->value, field->str);
57296448 if (field->next) {
....@@ -5733,22 +6452,22 @@
57336452 }
57346453
57356454 /* for debugging */
5736
-static void print_args(struct print_arg *args)
6455
+static void print_args(struct tep_print_arg *args)
57376456 {
57386457 int print_paren = 1;
57396458 struct trace_seq s;
57406459
57416460 switch (args->type) {
5742
- case PRINT_NULL:
6461
+ case TEP_PRINT_NULL:
57436462 printf("null");
57446463 break;
5745
- case PRINT_ATOM:
6464
+ case TEP_PRINT_ATOM:
57466465 printf("%s", args->atom.atom);
57476466 break;
5748
- case PRINT_FIELD:
6467
+ case TEP_PRINT_FIELD:
57496468 printf("REC->%s", args->field.name);
57506469 break;
5751
- case PRINT_FLAGS:
6470
+ case TEP_PRINT_FLAGS:
57526471 printf("__print_flags(");
57536472 print_args(args->flags.field);
57546473 printf(", %s, ", args->flags.delim);
....@@ -5758,7 +6477,7 @@
57586477 trace_seq_destroy(&s);
57596478 printf(")");
57606479 break;
5761
- case PRINT_SYMBOL:
6480
+ case TEP_PRINT_SYMBOL:
57626481 printf("__print_symbolic(");
57636482 print_args(args->symbol.field);
57646483 printf(", ");
....@@ -5768,21 +6487,21 @@
57686487 trace_seq_destroy(&s);
57696488 printf(")");
57706489 break;
5771
- case PRINT_HEX:
6490
+ case TEP_PRINT_HEX:
57726491 printf("__print_hex(");
57736492 print_args(args->hex.field);
57746493 printf(", ");
57756494 print_args(args->hex.size);
57766495 printf(")");
57776496 break;
5778
- case PRINT_HEX_STR:
6497
+ case TEP_PRINT_HEX_STR:
57796498 printf("__print_hex_str(");
57806499 print_args(args->hex.field);
57816500 printf(", ");
57826501 print_args(args->hex.size);
57836502 printf(")");
57846503 break;
5785
- case PRINT_INT_ARRAY:
6504
+ case TEP_PRINT_INT_ARRAY:
57866505 printf("__print_array(");
57876506 print_args(args->int_array.field);
57886507 printf(", ");
....@@ -5791,18 +6510,18 @@
57916510 print_args(args->int_array.el_size);
57926511 printf(")");
57936512 break;
5794
- case PRINT_STRING:
5795
- case PRINT_BSTRING:
6513
+ case TEP_PRINT_STRING:
6514
+ case TEP_PRINT_BSTRING:
57966515 printf("__get_str(%s)", args->string.string);
57976516 break;
5798
- case PRINT_BITMASK:
6517
+ case TEP_PRINT_BITMASK:
57996518 printf("__get_bitmask(%s)", args->bitmask.bitmask);
58006519 break;
5801
- case PRINT_TYPE:
6520
+ case TEP_PRINT_TYPE:
58026521 printf("(%s)", args->typecast.type);
58036522 print_args(args->typecast.item);
58046523 break;
5805
- case PRINT_OP:
6524
+ case TEP_PRINT_OP:
58066525 if (strcmp(args->op.op, ":") == 0)
58076526 print_paren = 0;
58086527 if (print_paren)
....@@ -5834,13 +6553,13 @@
58346553 save_input_buf_ptr = input_buf_ptr;
58356554 save_input_buf_siz = input_buf_siz;
58366555
5837
- if (read_expected(EVENT_ITEM, "field") < 0)
6556
+ if (read_expected(TEP_EVENT_ITEM, "field") < 0)
58386557 return;
5839
- if (read_expected(EVENT_OP, ":") < 0)
6558
+ if (read_expected(TEP_EVENT_OP, ":") < 0)
58406559 return;
58416560
58426561 /* type */
5843
- if (read_expect_type(EVENT_ITEM, &token) < 0)
6562
+ if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
58446563 goto fail;
58456564 free_token(token);
58466565
....@@ -5848,42 +6567,42 @@
58486567 * If this is not a mandatory field, then test it first.
58496568 */
58506569 if (mandatory) {
5851
- if (read_expected(EVENT_ITEM, field) < 0)
6570
+ if (read_expected(TEP_EVENT_ITEM, field) < 0)
58526571 return;
58536572 } else {
5854
- if (read_expect_type(EVENT_ITEM, &token) < 0)
6573
+ if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
58556574 goto fail;
58566575 if (strcmp(token, field) != 0)
58576576 goto discard;
58586577 free_token(token);
58596578 }
58606579
5861
- if (read_expected(EVENT_OP, ";") < 0)
6580
+ if (read_expected(TEP_EVENT_OP, ";") < 0)
58626581 return;
5863
- if (read_expected(EVENT_ITEM, "offset") < 0)
6582
+ if (read_expected(TEP_EVENT_ITEM, "offset") < 0)
58646583 return;
5865
- if (read_expected(EVENT_OP, ":") < 0)
6584
+ if (read_expected(TEP_EVENT_OP, ":") < 0)
58666585 return;
5867
- if (read_expect_type(EVENT_ITEM, &token) < 0)
6586
+ if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
58686587 goto fail;
58696588 *offset = atoi(token);
58706589 free_token(token);
5871
- if (read_expected(EVENT_OP, ";") < 0)
6590
+ if (read_expected(TEP_EVENT_OP, ";") < 0)
58726591 return;
5873
- if (read_expected(EVENT_ITEM, "size") < 0)
6592
+ if (read_expected(TEP_EVENT_ITEM, "size") < 0)
58746593 return;
5875
- if (read_expected(EVENT_OP, ":") < 0)
6594
+ if (read_expected(TEP_EVENT_OP, ":") < 0)
58766595 return;
5877
- if (read_expect_type(EVENT_ITEM, &token) < 0)
6596
+ if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
58786597 goto fail;
58796598 *size = atoi(token);
58806599 free_token(token);
5881
- if (read_expected(EVENT_OP, ";") < 0)
6600
+ if (read_expected(TEP_EVENT_OP, ";") < 0)
58826601 return;
58836602 type = read_token(&token);
5884
- if (type != EVENT_NEWLINE) {
6603
+ if (type != TEP_EVENT_NEWLINE) {
58856604 /* newer versions of the kernel have a "signed" type */
5886
- if (type != EVENT_ITEM)
6605
+ if (type != TEP_EVENT_ITEM)
58876606 goto fail;
58886607
58896608 if (strcmp(token, "signed") != 0)
....@@ -5891,17 +6610,17 @@
58916610
58926611 free_token(token);
58936612
5894
- if (read_expected(EVENT_OP, ":") < 0)
6613
+ if (read_expected(TEP_EVENT_OP, ":") < 0)
58956614 return;
58966615
5897
- if (read_expect_type(EVENT_ITEM, &token))
6616
+ if (read_expect_type(TEP_EVENT_ITEM, &token))
58986617 goto fail;
58996618
59006619 free_token(token);
5901
- if (read_expected(EVENT_OP, ";") < 0)
6620
+ if (read_expected(TEP_EVENT_OP, ";") < 0)
59026621 return;
59036622
5904
- if (read_expect_type(EVENT_NEWLINE, &token))
6623
+ if (read_expect_type(TEP_EVENT_NEWLINE, &token))
59056624 goto fail;
59066625 }
59076626 fail:
....@@ -5918,7 +6637,7 @@
59186637
59196638 /**
59206639 * tep_parse_header_page - parse the data stored in the header page
5921
- * @pevent: the handle to the pevent
6640
+ * @tep: a handle to the trace event parser context
59226641 * @buf: the buffer storing the header page format string
59236642 * @size: the size of @buf
59246643 * @long_size: the long size to use if there is no header
....@@ -5928,7 +6647,7 @@
59286647 *
59296648 * /sys/kernel/debug/tracing/events/header_page
59306649 */
5931
-int tep_parse_header_page(struct tep_handle *pevent, char *buf, unsigned long size,
6650
+int tep_parse_header_page(struct tep_handle *tep, char *buf, unsigned long size,
59326651 int long_size)
59336652 {
59346653 int ignore;
....@@ -5938,27 +6657,27 @@
59386657 * Old kernels did not have header page info.
59396658 * Sorry but we just use what we find here in user space.
59406659 */
5941
- pevent->header_page_ts_size = sizeof(long long);
5942
- pevent->header_page_size_size = long_size;
5943
- pevent->header_page_data_offset = sizeof(long long) + long_size;
5944
- pevent->old_format = 1;
6660
+ tep->header_page_ts_size = sizeof(long long);
6661
+ tep->header_page_size_size = long_size;
6662
+ tep->header_page_data_offset = sizeof(long long) + long_size;
6663
+ tep->old_format = 1;
59456664 return -1;
59466665 }
59476666 init_input_buf(buf, size);
59486667
5949
- parse_header_field("timestamp", &pevent->header_page_ts_offset,
5950
- &pevent->header_page_ts_size, 1);
5951
- parse_header_field("commit", &pevent->header_page_size_offset,
5952
- &pevent->header_page_size_size, 1);
5953
- parse_header_field("overwrite", &pevent->header_page_overwrite,
6668
+ parse_header_field("timestamp", &tep->header_page_ts_offset,
6669
+ &tep->header_page_ts_size, 1);
6670
+ parse_header_field("commit", &tep->header_page_size_offset,
6671
+ &tep->header_page_size_size, 1);
6672
+ parse_header_field("overwrite", &tep->header_page_overwrite,
59546673 &ignore, 0);
5955
- parse_header_field("data", &pevent->header_page_data_offset,
5956
- &pevent->header_page_data_size, 1);
6674
+ parse_header_field("data", &tep->header_page_data_offset,
6675
+ &tep->header_page_data_size, 1);
59576676
59586677 return 0;
59596678 }
59606679
5961
-static int event_matches(struct event_format *event,
6680
+static int event_matches(struct tep_event *event,
59626681 int id, const char *sys_name,
59636682 const char *event_name)
59646683 {
....@@ -5981,11 +6700,11 @@
59816700 free(handle);
59826701 }
59836702
5984
-static int find_event_handle(struct tep_handle *pevent, struct event_format *event)
6703
+static int find_event_handle(struct tep_handle *tep, struct tep_event *event)
59856704 {
59866705 struct event_handler *handle, **next;
59876706
5988
- for (next = &pevent->handlers; *next;
6707
+ for (next = &tep->handlers; *next;
59896708 next = &(*next)->next) {
59906709 handle = *next;
59916710 if (event_matches(event, handle->id,
....@@ -6010,7 +6729,7 @@
60106729 }
60116730
60126731 /**
6013
- * __tep_parse_format - parse the event format
6732
+ * parse_format - parse the event format
60146733 * @buf: the buffer storing the event format string
60156734 * @size: the size of @buf
60166735 * @sys: the system the event belongs to
....@@ -6022,11 +6741,11 @@
60226741 *
60236742 * /sys/kernel/debug/tracing/events/.../.../format
60246743 */
6025
-enum tep_errno __tep_parse_format(struct event_format **eventp,
6026
- struct tep_handle *pevent, const char *buf,
6027
- unsigned long size, const char *sys)
6744
+static enum tep_errno parse_format(struct tep_event **eventp,
6745
+ struct tep_handle *tep, const char *buf,
6746
+ unsigned long size, const char *sys)
60286747 {
6029
- struct event_format *event;
6748
+ struct tep_event *event;
60306749 int ret;
60316750
60326751 init_input_buf(buf, size);
....@@ -6043,10 +6762,10 @@
60436762 }
60446763
60456764 if (strcmp(sys, "ftrace") == 0) {
6046
- event->flags |= EVENT_FL_ISFTRACE;
6765
+ event->flags |= TEP_EVENT_FL_ISFTRACE;
60476766
60486767 if (strcmp(event->name, "bprint") == 0)
6049
- event->flags |= EVENT_FL_ISBPRINT;
6768
+ event->flags |= TEP_EVENT_FL_ISBPRINT;
60506769 }
60516770
60526771 event->id = event_read_id();
....@@ -6065,8 +6784,8 @@
60656784 goto event_alloc_failed;
60666785 }
60676786
6068
- /* Add pevent to event so that it can be referenced */
6069
- event->pevent = pevent;
6787
+ /* Add tep to event so that it can be referenced */
6788
+ event->tep = tep;
60706789
60716790 ret = event_read_format(event);
60726791 if (ret < 0) {
....@@ -6078,7 +6797,7 @@
60786797 * If the event has an override, don't print warnings if the event
60796798 * print format fails to parse.
60806799 */
6081
- if (pevent && find_event_handle(pevent, event))
6800
+ if (tep && find_event_handle(tep, event))
60826801 show_warning = 0;
60836802
60846803 ret = event_read_print(event);
....@@ -6089,22 +6808,22 @@
60896808 goto event_parse_failed;
60906809 }
60916810
6092
- if (!ret && (event->flags & EVENT_FL_ISFTRACE)) {
6093
- struct format_field *field;
6094
- struct print_arg *arg, **list;
6811
+ if (!ret && (event->flags & TEP_EVENT_FL_ISFTRACE)) {
6812
+ struct tep_format_field *field;
6813
+ struct tep_print_arg *arg, **list;
60956814
60966815 /* old ftrace had no args */
60976816 list = &event->print_fmt.args;
60986817 for (field = event->format.fields; field; field = field->next) {
60996818 arg = alloc_arg();
61006819 if (!arg) {
6101
- event->flags |= EVENT_FL_FAILED;
6820
+ event->flags |= TEP_EVENT_FL_FAILED;
61026821 return TEP_ERRNO__OLD_FTRACE_ARG_FAILED;
61036822 }
6104
- arg->type = PRINT_FIELD;
6823
+ arg->type = TEP_PRINT_FIELD;
61056824 arg->field.name = strdup(field->name);
61066825 if (!arg->field.name) {
6107
- event->flags |= EVENT_FL_FAILED;
6826
+ event->flags |= TEP_EVENT_FL_FAILED;
61086827 free_arg(arg);
61096828 return TEP_ERRNO__OLD_FTRACE_ARG_FAILED;
61106829 }
....@@ -6112,13 +6831,17 @@
61126831 *list = arg;
61136832 list = &arg->next;
61146833 }
6115
- return 0;
61166834 }
6835
+
6836
+ if (!(event->flags & TEP_EVENT_FL_ISBPRINT))
6837
+ event->print_fmt.print_cache = parse_args(event,
6838
+ event->print_fmt.format,
6839
+ event->print_fmt.args);
61176840
61186841 return 0;
61196842
61206843 event_parse_failed:
6121
- event->flags |= EVENT_FL_FAILED;
6844
+ event->flags |= TEP_EVENT_FL_FAILED;
61226845 return ret;
61236846
61246847 event_alloc_failed:
....@@ -6130,18 +6853,18 @@
61306853 }
61316854
61326855 static enum tep_errno
6133
-__parse_event(struct tep_handle *pevent,
6134
- struct event_format **eventp,
6856
+__parse_event(struct tep_handle *tep,
6857
+ struct tep_event **eventp,
61356858 const char *buf, unsigned long size,
61366859 const char *sys)
61376860 {
6138
- int ret = __tep_parse_format(eventp, pevent, buf, size, sys);
6139
- struct event_format *event = *eventp;
6861
+ int ret = parse_format(eventp, tep, buf, size, sys);
6862
+ struct tep_event *event = *eventp;
61406863
61416864 if (event == NULL)
61426865 return ret;
61436866
6144
- if (pevent && add_event(pevent, event)) {
6867
+ if (tep && add_event(tep, event)) {
61456868 ret = TEP_ERRNO__MEM_ALLOC_FAILED;
61466869 goto event_add_failed;
61476870 }
....@@ -6153,13 +6876,13 @@
61536876 return 0;
61546877
61556878 event_add_failed:
6156
- tep_free_format(event);
6879
+ free_tep_event(event);
61576880 return ret;
61586881 }
61596882
61606883 /**
61616884 * tep_parse_format - parse the event format
6162
- * @pevent: the handle to the pevent
6885
+ * @tep: a handle to the trace event parser context
61636886 * @eventp: returned format
61646887 * @buf: the buffer storing the event format string
61656888 * @size: the size of @buf
....@@ -6172,17 +6895,17 @@
61726895 *
61736896 * /sys/kernel/debug/tracing/events/.../.../format
61746897 */
6175
-enum tep_errno tep_parse_format(struct tep_handle *pevent,
6176
- struct event_format **eventp,
6898
+enum tep_errno tep_parse_format(struct tep_handle *tep,
6899
+ struct tep_event **eventp,
61776900 const char *buf,
61786901 unsigned long size, const char *sys)
61796902 {
6180
- return __parse_event(pevent, eventp, buf, size, sys);
6903
+ return __parse_event(tep, eventp, buf, size, sys);
61816904 }
61826905
61836906 /**
61846907 * tep_parse_event - parse the event format
6185
- * @pevent: the handle to the pevent
6908
+ * @tep: a handle to the trace event parser context
61866909 * @buf: the buffer storing the event format string
61876910 * @size: the size of @buf
61886911 * @sys: the system the event belongs to
....@@ -6194,43 +6917,14 @@
61946917 *
61956918 * /sys/kernel/debug/tracing/events/.../.../format
61966919 */
6197
-enum tep_errno tep_parse_event(struct tep_handle *pevent, const char *buf,
6920
+enum tep_errno tep_parse_event(struct tep_handle *tep, const char *buf,
61986921 unsigned long size, const char *sys)
61996922 {
6200
- struct event_format *event = NULL;
6201
- return __parse_event(pevent, &event, buf, size, sys);
6923
+ struct tep_event *event = NULL;
6924
+ return __parse_event(tep, &event, buf, size, sys);
62026925 }
62036926
6204
-#undef _PE
6205
-#define _PE(code, str) str
6206
-static const char * const tep_error_str[] = {
6207
- TEP_ERRORS
6208
-};
6209
-#undef _PE
6210
-
6211
-int tep_strerror(struct tep_handle *pevent __maybe_unused,
6212
- enum tep_errno errnum, char *buf, size_t buflen)
6213
-{
6214
- int idx;
6215
- const char *msg;
6216
-
6217
- if (errnum >= 0) {
6218
- str_error_r(errnum, buf, buflen);
6219
- return 0;
6220
- }
6221
-
6222
- if (errnum <= __TEP_ERRNO__START ||
6223
- errnum >= __TEP_ERRNO__END)
6224
- return -1;
6225
-
6226
- idx = errnum - __TEP_ERRNO__START - 1;
6227
- msg = tep_error_str[idx];
6228
- snprintf(buf, buflen, "%s", msg);
6229
-
6230
- return 0;
6231
-}
6232
-
6233
-int get_field_val(struct trace_seq *s, struct format_field *field,
6927
+int get_field_val(struct trace_seq *s, struct tep_format_field *field,
62346928 const char *name, struct tep_record *record,
62356929 unsigned long long *val, int err)
62366930 {
....@@ -6263,11 +6957,11 @@
62636957 *
62646958 * On failure, it returns NULL.
62656959 */
6266
-void *tep_get_field_raw(struct trace_seq *s, struct event_format *event,
6960
+void *tep_get_field_raw(struct trace_seq *s, struct tep_event *event,
62676961 const char *name, struct tep_record *record,
62686962 int *len, int err)
62696963 {
6270
- struct format_field *field;
6964
+ struct tep_format_field *field;
62716965 void *data = record->data;
62726966 unsigned offset;
62736967 int dummy;
....@@ -6288,9 +6982,9 @@
62886982 len = &dummy;
62896983
62906984 offset = field->offset;
6291
- if (field->flags & FIELD_IS_DYNAMIC) {
6292
- offset = tep_read_number(event->pevent,
6293
- data + offset, field->size);
6985
+ if (field->flags & TEP_FIELD_IS_DYNAMIC) {
6986
+ offset = tep_read_number(event->tep,
6987
+ data + offset, field->size);
62946988 *len = offset >> 16;
62956989 offset &= 0xffff;
62966990 } else
....@@ -6310,11 +7004,11 @@
63107004 *
63117005 * Returns 0 on success -1 on field not found.
63127006 */
6313
-int tep_get_field_val(struct trace_seq *s, struct event_format *event,
7007
+int tep_get_field_val(struct trace_seq *s, struct tep_event *event,
63147008 const char *name, struct tep_record *record,
63157009 unsigned long long *val, int err)
63167010 {
6317
- struct format_field *field;
7011
+ struct tep_format_field *field;
63187012
63197013 if (!event)
63207014 return -1;
....@@ -6335,11 +7029,11 @@
63357029 *
63367030 * Returns 0 on success -1 on field not found.
63377031 */
6338
-int tep_get_common_field_val(struct trace_seq *s, struct event_format *event,
7032
+int tep_get_common_field_val(struct trace_seq *s, struct tep_event *event,
63397033 const char *name, struct tep_record *record,
63407034 unsigned long long *val, int err)
63417035 {
6342
- struct format_field *field;
7036
+ struct tep_format_field *field;
63437037
63447038 if (!event)
63457039 return -1;
....@@ -6360,11 +7054,11 @@
63607054 *
63617055 * Returns 0 on success -1 on field not found.
63627056 */
6363
-int tep_get_any_field_val(struct trace_seq *s, struct event_format *event,
7057
+int tep_get_any_field_val(struct trace_seq *s, struct tep_event *event,
63647058 const char *name, struct tep_record *record,
63657059 unsigned long long *val, int err)
63667060 {
6367
- struct format_field *field;
7061
+ struct tep_format_field *field;
63687062
63697063 if (!event)
63707064 return -1;
....@@ -6383,13 +7077,14 @@
63837077 * @record: The record with the field name.
63847078 * @err: print default error if failed.
63857079 *
6386
- * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
7080
+ * Returns positive value on success, negative in case of an error,
7081
+ * or 0 if buffer is full.
63877082 */
63887083 int tep_print_num_field(struct trace_seq *s, const char *fmt,
6389
- struct event_format *event, const char *name,
7084
+ struct tep_event *event, const char *name,
63907085 struct tep_record *record, int err)
63917086 {
6392
- struct format_field *field = tep_find_field(event, name);
7087
+ struct tep_format_field *field = tep_find_field(event, name);
63937088 unsigned long long val;
63947089
63957090 if (!field)
....@@ -6415,14 +7110,15 @@
64157110 * @record: The record with the field name.
64167111 * @err: print default error if failed.
64177112 *
6418
- * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
7113
+ * Returns positive value on success, negative in case of an error,
7114
+ * or 0 if buffer is full.
64197115 */
64207116 int tep_print_func_field(struct trace_seq *s, const char *fmt,
6421
- struct event_format *event, const char *name,
7117
+ struct tep_event *event, const char *name,
64227118 struct tep_record *record, int err)
64237119 {
6424
- struct format_field *field = tep_find_field(event, name);
6425
- struct tep_handle *pevent = event->pevent;
7120
+ struct tep_format_field *field = tep_find_field(event, name);
7121
+ struct tep_handle *tep = event->tep;
64267122 unsigned long long val;
64277123 struct func_map *func;
64287124 char tmp[128];
....@@ -6433,7 +7129,7 @@
64337129 if (tep_read_number_field(field, record->data, &val))
64347130 goto failed;
64357131
6436
- func = find_func(pevent, val);
7132
+ func = find_func(tep, val);
64377133
64387134 if (func)
64397135 snprintf(tmp, 128, "%s/0x%llx", func->func, func->addr - val);
....@@ -6465,7 +7161,7 @@
64657161
64667162 /**
64677163 * tep_register_print_function - register a helper function
6468
- * @pevent: the handle to the pevent
7164
+ * @tep: a handle to the trace event parser context
64697165 * @func: the function to process the helper function
64707166 * @ret_type: the return type of the helper function
64717167 * @name: the name of the helper function
....@@ -6478,7 +7174,7 @@
64787174 * The @parameters is a variable list of tep_func_arg_type enums that
64797175 * must end with TEP_FUNC_ARG_VOID.
64807176 */
6481
-int tep_register_print_function(struct tep_handle *pevent,
7177
+int tep_register_print_function(struct tep_handle *tep,
64827178 tep_func_handler func,
64837179 enum tep_func_arg_type ret_type,
64847180 char *name, ...)
....@@ -6490,7 +7186,7 @@
64907186 va_list ap;
64917187 int ret;
64927188
6493
- func_handle = find_func_handler(pevent, name);
7189
+ func_handle = find_func_handler(tep, name);
64947190 if (func_handle) {
64957191 /*
64967192 * This is most like caused by the users own
....@@ -6498,7 +7194,7 @@
64987194 * system defaults.
64997195 */
65007196 pr_stat("override of function helper '%s'", name);
6501
- remove_func_handler(pevent, name);
7197
+ remove_func_handler(tep, name);
65027198 }
65037199
65047200 func_handle = calloc(1, sizeof(*func_handle));
....@@ -6545,8 +7241,8 @@
65457241 }
65467242 va_end(ap);
65477243
6548
- func_handle->next = pevent->func_handlers;
6549
- pevent->func_handlers = func_handle;
7244
+ func_handle->next = tep->func_handlers;
7245
+ tep->func_handlers = func_handle;
65507246
65517247 return 0;
65527248 out_free:
....@@ -6557,7 +7253,7 @@
65577253
65587254 /**
65597255 * tep_unregister_print_function - unregister a helper function
6560
- * @pevent: the handle to the pevent
7256
+ * @tep: a handle to the trace event parser context
65617257 * @func: the function to process the helper function
65627258 * @name: the name of the helper function
65637259 *
....@@ -6565,28 +7261,28 @@
65657261 *
65667262 * Returns 0 if the handler was removed successully, -1 otherwise.
65677263 */
6568
-int tep_unregister_print_function(struct tep_handle *pevent,
7264
+int tep_unregister_print_function(struct tep_handle *tep,
65697265 tep_func_handler func, char *name)
65707266 {
65717267 struct tep_function_handler *func_handle;
65727268
6573
- func_handle = find_func_handler(pevent, name);
7269
+ func_handle = find_func_handler(tep, name);
65747270 if (func_handle && func_handle->func == func) {
6575
- remove_func_handler(pevent, name);
7271
+ remove_func_handler(tep, name);
65767272 return 0;
65777273 }
65787274 return -1;
65797275 }
65807276
6581
-static struct event_format *search_event(struct tep_handle *pevent, int id,
6582
- const char *sys_name,
6583
- const char *event_name)
7277
+static struct tep_event *search_event(struct tep_handle *tep, int id,
7278
+ const char *sys_name,
7279
+ const char *event_name)
65847280 {
6585
- struct event_format *event;
7281
+ struct tep_event *event;
65867282
65877283 if (id >= 0) {
65887284 /* search by id */
6589
- event = tep_find_event(pevent, id);
7285
+ event = tep_find_event(tep, id);
65907286 if (!event)
65917287 return NULL;
65927288 if (event_name && (strcmp(event_name, event->name) != 0))
....@@ -6594,7 +7290,7 @@
65947290 if (sys_name && (strcmp(sys_name, event->system) != 0))
65957291 return NULL;
65967292 } else {
6597
- event = tep_find_event_by_name(pevent, sys_name, event_name);
7293
+ event = tep_find_event_by_name(tep, sys_name, event_name);
65987294 if (!event)
65997295 return NULL;
66007296 }
....@@ -6603,7 +7299,7 @@
66037299
66047300 /**
66057301 * tep_register_event_handler - register a way to parse an event
6606
- * @pevent: the handle to the pevent
7302
+ * @tep: a handle to the trace event parser context
66077303 * @id: the id of the event to register
66087304 * @sys_name: the system name the event belongs to
66097305 * @event_name: the name of the event
....@@ -6617,15 +7313,21 @@
66177313 *
66187314 * If @id is >= 0, then it is used to find the event.
66197315 * else @sys_name and @event_name are used.
7316
+ *
7317
+ * Returns:
7318
+ * TEP_REGISTER_SUCCESS_OVERWRITE if an existing handler is overwritten
7319
+ * TEP_REGISTER_SUCCESS if a new handler is registered successfully
7320
+ * negative TEP_ERRNO_... in case of an error
7321
+ *
66207322 */
6621
-int tep_register_event_handler(struct tep_handle *pevent, int id,
7323
+int tep_register_event_handler(struct tep_handle *tep, int id,
66227324 const char *sys_name, const char *event_name,
66237325 tep_event_handler_func func, void *context)
66247326 {
6625
- struct event_format *event;
7327
+ struct tep_event *event;
66267328 struct event_handler *handle;
66277329
6628
- event = search_event(pevent, id, sys_name, event_name);
7330
+ event = search_event(tep, id, sys_name, event_name);
66297331 if (event == NULL)
66307332 goto not_found;
66317333
....@@ -6634,7 +7336,7 @@
66347336
66357337 event->handler = func;
66367338 event->context = context;
6637
- return 0;
7339
+ return TEP_REGISTER_SUCCESS_OVERWRITE;
66387340
66397341 not_found:
66407342 /* Save for later use. */
....@@ -6660,11 +7362,11 @@
66607362 }
66617363
66627364 handle->func = func;
6663
- handle->next = pevent->handlers;
6664
- pevent->handlers = handle;
7365
+ handle->next = tep->handlers;
7366
+ tep->handlers = handle;
66657367 handle->context = context;
66667368
6667
- return -1;
7369
+ return TEP_REGISTER_SUCCESS;
66687370 }
66697371
66707372 static int handle_matches(struct event_handler *handler, int id,
....@@ -6688,7 +7390,7 @@
66887390
66897391 /**
66907392 * tep_unregister_event_handler - unregister an existing event handler
6691
- * @pevent: the handle to the pevent
7393
+ * @tep: a handle to the trace event parser context
66927394 * @id: the id of the event to unregister
66937395 * @sys_name: the system name the handler belongs to
66947396 * @event_name: the name of the event handler
....@@ -6702,15 +7404,15 @@
67027404 *
67037405 * Returns 0 if handler was removed successfully, -1 if event was not found.
67047406 */
6705
-int tep_unregister_event_handler(struct tep_handle *pevent, int id,
7407
+int tep_unregister_event_handler(struct tep_handle *tep, int id,
67067408 const char *sys_name, const char *event_name,
67077409 tep_event_handler_func func, void *context)
67087410 {
6709
- struct event_format *event;
7411
+ struct tep_event *event;
67107412 struct event_handler *handle;
67117413 struct event_handler **next;
67127414
6713
- event = search_event(pevent, id, sys_name, event_name);
7415
+ event = search_event(tep, id, sys_name, event_name);
67147416 if (event == NULL)
67157417 goto not_found;
67167418
....@@ -6724,7 +7426,7 @@
67247426 }
67257427
67267428 not_found:
6727
- for (next = &pevent->handlers; *next; next = &(*next)->next) {
7429
+ for (next = &tep->handlers; *next; next = &(*next)->next) {
67287430 handle = *next;
67297431 if (handle_matches(handle, id, sys_name, event_name,
67307432 func, context))
....@@ -6741,24 +7443,33 @@
67417443 }
67427444
67437445 /**
6744
- * tep_alloc - create a pevent handle
7446
+ * tep_alloc - create a tep handle
67457447 */
67467448 struct tep_handle *tep_alloc(void)
67477449 {
6748
- struct tep_handle *pevent = calloc(1, sizeof(*pevent));
7450
+ struct tep_handle *tep = calloc(1, sizeof(*tep));
67497451
6750
- if (pevent)
6751
- pevent->ref_count = 1;
7452
+ if (tep) {
7453
+ tep->ref_count = 1;
7454
+ tep->host_bigendian = tep_is_bigendian();
7455
+ }
67527456
6753
- return pevent;
7457
+ return tep;
67547458 }
67557459
6756
-void tep_ref(struct tep_handle *pevent)
7460
+void tep_ref(struct tep_handle *tep)
67577461 {
6758
- pevent->ref_count++;
7462
+ tep->ref_count++;
67597463 }
67607464
6761
-void tep_free_format_field(struct format_field *field)
7465
+int tep_get_ref(struct tep_handle *tep)
7466
+{
7467
+ if (tep)
7468
+ return tep->ref_count;
7469
+ return 0;
7470
+}
7471
+
7472
+__hidden void free_tep_format_field(struct tep_format_field *field)
67627473 {
67637474 free(field->type);
67647475 if (field->alias != field->name)
....@@ -6767,24 +7478,24 @@
67677478 free(field);
67687479 }
67697480
6770
-static void free_format_fields(struct format_field *field)
7481
+static void free_format_fields(struct tep_format_field *field)
67717482 {
6772
- struct format_field *next;
7483
+ struct tep_format_field *next;
67737484
67747485 while (field) {
67757486 next = field->next;
6776
- tep_free_format_field(field);
7487
+ free_tep_format_field(field);
67777488 field = next;
67787489 }
67797490 }
67807491
6781
-static void free_formats(struct format *format)
7492
+static void free_formats(struct tep_format *format)
67827493 {
67837494 free_format_fields(format->common_fields);
67847495 free_format_fields(format->fields);
67857496 }
67867497
6787
-void tep_free_format(struct event_format *event)
7498
+__hidden void free_tep_event(struct tep_event *event)
67887499 {
67897500 free(event->name);
67907501 free(event->system);
....@@ -6793,15 +7504,15 @@
67937504
67947505 free(event->print_fmt.format);
67957506 free_args(event->print_fmt.args);
6796
-
7507
+ free_parse_args(event->print_fmt.print_cache);
67977508 free(event);
67987509 }
67997510
68007511 /**
6801
- * tep_free - free a pevent handle
6802
- * @pevent: the pevent handle to free
7512
+ * tep_free - free a tep handle
7513
+ * @tep: the tep handle to free
68037514 */
6804
-void tep_free(struct tep_handle *pevent)
7515
+void tep_free(struct tep_handle *tep)
68057516 {
68067517 struct cmdline_list *cmdlist, *cmdnext;
68077518 struct func_list *funclist, *funcnext;
....@@ -6810,21 +7521,21 @@
68107521 struct event_handler *handle;
68117522 int i;
68127523
6813
- if (!pevent)
7524
+ if (!tep)
68147525 return;
68157526
6816
- cmdlist = pevent->cmdlist;
6817
- funclist = pevent->funclist;
6818
- printklist = pevent->printklist;
7527
+ cmdlist = tep->cmdlist;
7528
+ funclist = tep->funclist;
7529
+ printklist = tep->printklist;
68197530
6820
- pevent->ref_count--;
6821
- if (pevent->ref_count)
7531
+ tep->ref_count--;
7532
+ if (tep->ref_count)
68227533 return;
68237534
6824
- if (pevent->cmdlines) {
6825
- for (i = 0; i < pevent->cmdline_count; i++)
6826
- free(pevent->cmdlines[i].comm);
6827
- free(pevent->cmdlines);
7535
+ if (tep->cmdlines) {
7536
+ for (i = 0; i < tep->cmdline_count; i++)
7537
+ free(tep->cmdlines[i].comm);
7538
+ free(tep->cmdlines);
68287539 }
68297540
68307541 while (cmdlist) {
....@@ -6834,12 +7545,12 @@
68347545 cmdlist = cmdnext;
68357546 }
68367547
6837
- if (pevent->func_map) {
6838
- for (i = 0; i < (int)pevent->func_count; i++) {
6839
- free(pevent->func_map[i].func);
6840
- free(pevent->func_map[i].mod);
7548
+ if (tep->func_map) {
7549
+ for (i = 0; i < (int)tep->func_count; i++) {
7550
+ free(tep->func_map[i].func);
7551
+ free(tep->func_map[i].mod);
68417552 }
6842
- free(pevent->func_map);
7553
+ free(tep->func_map);
68437554 }
68447555
68457556 while (funclist) {
....@@ -6850,16 +7561,16 @@
68507561 funclist = funcnext;
68517562 }
68527563
6853
- while (pevent->func_handlers) {
6854
- func_handler = pevent->func_handlers;
6855
- pevent->func_handlers = func_handler->next;
7564
+ while (tep->func_handlers) {
7565
+ func_handler = tep->func_handlers;
7566
+ tep->func_handlers = func_handler->next;
68567567 free_func_handle(func_handler);
68577568 }
68587569
6859
- if (pevent->printk_map) {
6860
- for (i = 0; i < (int)pevent->printk_count; i++)
6861
- free(pevent->printk_map[i].printk);
6862
- free(pevent->printk_map);
7570
+ if (tep->printk_map) {
7571
+ for (i = 0; i < (int)tep->printk_count; i++)
7572
+ free(tep->printk_map[i].printk);
7573
+ free(tep->printk_map);
68637574 }
68647575
68657576 while (printklist) {
....@@ -6869,24 +7580,24 @@
68697580 printklist = printknext;
68707581 }
68717582
6872
- for (i = 0; i < pevent->nr_events; i++)
6873
- tep_free_format(pevent->events[i]);
7583
+ for (i = 0; i < tep->nr_events; i++)
7584
+ free_tep_event(tep->events[i]);
68747585
6875
- while (pevent->handlers) {
6876
- handle = pevent->handlers;
6877
- pevent->handlers = handle->next;
7586
+ while (tep->handlers) {
7587
+ handle = tep->handlers;
7588
+ tep->handlers = handle->next;
68787589 free_handler(handle);
68797590 }
68807591
6881
- free(pevent->trace_clock);
6882
- free(pevent->events);
6883
- free(pevent->sort_events);
6884
- free(pevent->func_resolver);
7592
+ free(tep->events);
7593
+ free(tep->sort_events);
7594
+ free(tep->func_resolver);
7595
+ free_tep_plugin_paths(tep);
68857596
6886
- free(pevent);
7597
+ free(tep);
68877598 }
68887599
6889
-void tep_unref(struct tep_handle *pevent)
7600
+void tep_unref(struct tep_handle *tep)
68907601 {
6891
- tep_free(pevent);
7602
+ tep_free(tep);
68927603 }