• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: LGPL-2.1 */
2 /*
3  * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
4  *
5  */
6 #ifndef __TEP_PARSE_EVENTS_H
7 #define __TEP_PARSE_EVENTS_H
8 
9 #include <stdbool.h>
10 #include <stdarg.h>
11 #include <stdio.h>
12 #include <regex.h>
13 #include <string.h>
14 
15 #include "trace-seq.h"
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #ifndef __maybe_unused
22 #define __maybe_unused __attribute__((unused))
23 #endif
24 
25 #ifndef DEBUG_RECORD
26 #define DEBUG_RECORD 0
27 #endif
28 
29 struct tep_record {
30 	unsigned long long	ts;
31 	unsigned long long	offset;
32 	long long		missed_events;	/* buffer dropped events before */
33 	int			record_size;	/* size of binary record */
34 	int			size;		/* size of data */
35 	void			*data;
36 	int			cpu;
37 	int			ref_count;
38 	int			locked;		/* Do not free, even if ref_count is zero */
39 	void			*priv;
40 #if DEBUG_RECORD
41 	struct tep_record	*prev;
42 	struct tep_record	*next;
43 	long			alloc_addr;
44 #endif
45 };
46 
47 /* ----------------------- tep ----------------------- */
48 
49 struct tep_handle;
50 struct tep_event;
51 
52 typedef int (*tep_event_handler_func)(struct trace_seq *s,
53 				      struct tep_record *record,
54 				      struct tep_event *event,
55 				      void *context);
56 
57 typedef int (*tep_plugin_load_func)(struct tep_handle *tep);
58 typedef int (*tep_plugin_unload_func)(struct tep_handle *tep);
59 
60 struct tep_plugin_option {
61 	struct tep_plugin_option	*next;
62 	void				*handle;
63 	char				*file;
64 	char				*name;
65 	char				*plugin_alias;
66 	char				*description;
67 	const char			*value;
68 	void				*priv;
69 	int				set;
70 };
71 
72 /*
73  * Plugin hooks that can be called:
74  *
75  * TEP_PLUGIN_LOADER:  (required)
76  *   The function name to initialized the plugin.
77  *
78  *   int TEP_PLUGIN_LOADER(struct tep_handle *tep)
79  *
80  * TEP_PLUGIN_UNLOADER:  (optional)
81  *   The function called just before unloading
82  *
83  *   int TEP_PLUGIN_UNLOADER(struct tep_handle *tep)
84  *
85  * TEP_PLUGIN_OPTIONS:  (optional)
86  *   Plugin options that can be set before loading
87  *
88  *   struct tep_plugin_option TEP_PLUGIN_OPTIONS[] = {
89  *	{
90  *		.name = "option-name",
91  *		.plugin_alias = "override-file-name", (optional)
92  *		.description = "description of option to show users",
93  *	},
94  *	{
95  *		.name = NULL,
96  *	},
97  *   };
98  *
99  *   Array must end with .name = NULL;
100  *
101  *
102  *   .plugin_alias is used to give a shorter name to access
103  *   the vairable. Useful if a plugin handles more than one event.
104  *
105  *   If .value is not set, then it is considered a boolean and only
106  *   .set will be processed. If .value is defined, then it is considered
107  *   a string option and .set will be ignored.
108  *
109  * TEP_PLUGIN_ALIAS: (optional)
110  *   The name to use for finding options (uses filename if not defined)
111  */
112 #define TEP_PLUGIN_LOADER tep_plugin_loader
113 #define TEP_PLUGIN_UNLOADER tep_plugin_unloader
114 #define TEP_PLUGIN_OPTIONS tep_plugin_options
115 #define TEP_PLUGIN_ALIAS tep_plugin_alias
116 #define _MAKE_STR(x)	#x
117 #define MAKE_STR(x)	_MAKE_STR(x)
118 #define TEP_PLUGIN_LOADER_NAME MAKE_STR(TEP_PLUGIN_LOADER)
119 #define TEP_PLUGIN_UNLOADER_NAME MAKE_STR(TEP_PLUGIN_UNLOADER)
120 #define TEP_PLUGIN_OPTIONS_NAME MAKE_STR(TEP_PLUGIN_OPTIONS)
121 #define TEP_PLUGIN_ALIAS_NAME MAKE_STR(TEP_PLUGIN_ALIAS)
122 
123 enum tep_format_flags {
124 	TEP_FIELD_IS_ARRAY	= 1,
125 	TEP_FIELD_IS_POINTER	= 2,
126 	TEP_FIELD_IS_SIGNED	= 4,
127 	TEP_FIELD_IS_STRING	= 8,
128 	TEP_FIELD_IS_DYNAMIC	= 16,
129 	TEP_FIELD_IS_LONG	= 32,
130 	TEP_FIELD_IS_FLAG	= 64,
131 	TEP_FIELD_IS_SYMBOLIC	= 128,
132 	TEP_FIELD_IS_RELATIVE	= 256,
133 };
134 
135 struct tep_format_field {
136 	struct tep_format_field	*next;
137 	struct tep_event	*event;
138 	char			*type;
139 	char			*name;
140 	char			*alias;
141 	int			offset;
142 	int			size;
143 	unsigned int		arraylen;
144 	unsigned int		elementsize;
145 	unsigned long		flags;
146 };
147 
148 struct tep_format {
149 	int			nr_common;
150 	int			nr_fields;
151 	struct tep_format_field	*common_fields;
152 	struct tep_format_field	*fields;
153 };
154 
155 struct tep_print_arg_atom {
156 	char			*atom;
157 };
158 
159 struct tep_print_arg_string {
160 	char			*string;
161 	int			offset;		// for backward compatibility
162 	struct tep_format_field	*field;
163 };
164 
165 struct tep_print_arg_bitmask {
166 	char			*bitmask;
167 	int			offset;		// for backward compatibility
168 	struct tep_format_field	*field;
169 };
170 
171 struct tep_print_arg_field {
172 	char			*name;
173 	struct tep_format_field	*field;
174 };
175 
176 struct tep_print_flag_sym {
177 	struct tep_print_flag_sym	*next;
178 	char				*value;
179 	char				*str;
180 };
181 
182 struct tep_print_arg_typecast {
183 	char 			*type;
184 	struct tep_print_arg	*item;
185 };
186 
187 struct tep_print_arg_flags {
188 	struct tep_print_arg		*field;
189 	char				*delim;
190 	struct tep_print_flag_sym	*flags;
191 };
192 
193 struct tep_print_arg_symbol {
194 	struct tep_print_arg		*field;
195 	struct tep_print_flag_sym	*symbols;
196 };
197 
198 struct tep_print_arg_hex {
199 	struct tep_print_arg	*field;
200 	struct tep_print_arg	*size;
201 };
202 
203 struct tep_print_arg_int_array {
204 	struct tep_print_arg	*field;
205 	struct tep_print_arg	*count;
206 	struct tep_print_arg	*el_size;
207 };
208 
209 struct tep_print_arg_dynarray {
210 	struct tep_format_field	*field;
211 	struct tep_print_arg	*index;
212 };
213 
214 struct tep_print_arg;
215 
216 struct tep_print_arg_op {
217 	char			*op;
218 	int			prio;
219 	struct tep_print_arg	*left;
220 	struct tep_print_arg	*right;
221 };
222 
223 struct tep_function_handler;
224 
225 struct tep_print_arg_func {
226 	struct tep_function_handler	*func;
227 	struct tep_print_arg		*args;
228 };
229 
230 enum tep_print_arg_type {
231 	TEP_PRINT_NULL,
232 	TEP_PRINT_ATOM,
233 	TEP_PRINT_FIELD,
234 	TEP_PRINT_FLAGS,
235 	TEP_PRINT_SYMBOL,
236 	TEP_PRINT_HEX,
237 	TEP_PRINT_INT_ARRAY,
238 	TEP_PRINT_TYPE,
239 	TEP_PRINT_STRING,
240 	TEP_PRINT_BSTRING,
241 	TEP_PRINT_DYNAMIC_ARRAY,
242 	TEP_PRINT_OP,
243 	TEP_PRINT_FUNC,
244 	TEP_PRINT_BITMASK,
245 	TEP_PRINT_DYNAMIC_ARRAY_LEN,
246 	TEP_PRINT_HEX_STR,
247 	TEP_PRINT_CPUMASK,
248 };
249 
250 struct tep_print_arg {
251 	struct tep_print_arg		*next;
252 	enum tep_print_arg_type		type;
253 	union {
254 		struct tep_print_arg_atom	atom;
255 		struct tep_print_arg_field	field;
256 		struct tep_print_arg_typecast	typecast;
257 		struct tep_print_arg_flags	flags;
258 		struct tep_print_arg_symbol	symbol;
259 		struct tep_print_arg_hex	hex;
260 		struct tep_print_arg_int_array	int_array;
261 		struct tep_print_arg_func	func;
262 		struct tep_print_arg_string	string;
263 		struct tep_print_arg_bitmask	bitmask;
264 		struct tep_print_arg_op		op;
265 		struct tep_print_arg_dynarray	dynarray;
266 	};
267 };
268 
269 struct tep_print_parse;
270 
271 struct tep_print_fmt {
272 	char			*format;
273 	struct tep_print_arg	*args;
274 	struct tep_print_parse	*print_cache;
275 };
276 
277 struct tep_event {
278 	struct tep_handle	*tep;
279 	char			*name;
280 	int			id;
281 	int			flags;
282 	struct tep_format	format;
283 	struct tep_print_fmt	print_fmt;
284 	char			*system;
285 	tep_event_handler_func	handler;
286 	void			*context;
287 };
288 
289 enum {
290 	TEP_EVENT_FL_ISFTRACE	= 0x01,
291 	TEP_EVENT_FL_ISPRINT	= 0x02,
292 	TEP_EVENT_FL_ISBPRINT	= 0x04,
293 	TEP_EVENT_FL_ISFUNCENT	= 0x10,
294 	TEP_EVENT_FL_ISFUNCRET	= 0x20,
295 	TEP_EVENT_FL_NOHANDLE	= 0x40,
296 	TEP_EVENT_FL_PRINTRAW	= 0x80,
297 
298 	TEP_EVENT_FL_FAILED	= 0x80000000
299 };
300 
301 enum tep_event_sort_type {
302 	TEP_EVENT_SORT_ID,
303 	TEP_EVENT_SORT_NAME,
304 	TEP_EVENT_SORT_SYSTEM,
305 };
306 
307 enum tep_event_type {
308 	TEP_EVENT_ERROR,
309 	TEP_EVENT_NONE,
310 	TEP_EVENT_SPACE,
311 	TEP_EVENT_NEWLINE,
312 	TEP_EVENT_OP,
313 	TEP_EVENT_DELIM,
314 	TEP_EVENT_ITEM,
315 	TEP_EVENT_DQUOTE,
316 	TEP_EVENT_SQUOTE,
317 };
318 
319 typedef unsigned long long (*tep_func_handler)(struct trace_seq *s,
320 					       unsigned long long *args);
321 
322 enum tep_func_arg_type {
323 	TEP_FUNC_ARG_VOID,
324 	TEP_FUNC_ARG_INT,
325 	TEP_FUNC_ARG_LONG,
326 	TEP_FUNC_ARG_STRING,
327 	TEP_FUNC_ARG_PTR,
328 	TEP_FUNC_ARG_MAX_TYPES
329 };
330 
331 enum tep_flag {
332 	TEP_NSEC_OUTPUT		= 1,	/* output in NSECS */
333 	TEP_DISABLE_SYS_PLUGINS	= 1 << 1,
334 	TEP_DISABLE_PLUGINS	= 1 << 2,
335 };
336 
337 #define TEP_ERRORS 							      \
338 	_PE(MEM_ALLOC_FAILED,	"failed to allocate memory"),		      \
339 	_PE(PARSE_EVENT_FAILED,	"failed to parse event"),		      \
340 	_PE(READ_ID_FAILED,	"failed to read event id"),		      \
341 	_PE(READ_FORMAT_FAILED,	"failed to read event format"),		      \
342 	_PE(READ_PRINT_FAILED,	"failed to read event print fmt"), 	      \
343 	_PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\
344 	_PE(INVALID_ARG_TYPE,	"invalid argument type"),		      \
345 	_PE(INVALID_EXP_TYPE,	"invalid expression type"),		      \
346 	_PE(INVALID_OP_TYPE,	"invalid operator type"),		      \
347 	_PE(INVALID_EVENT_NAME,	"invalid event name"),			      \
348 	_PE(EVENT_NOT_FOUND,	"no event found"),			      \
349 	_PE(SYNTAX_ERROR,	"syntax error"),			      \
350 	_PE(ILLEGAL_RVALUE,	"illegal rvalue"),			      \
351 	_PE(ILLEGAL_LVALUE,	"illegal lvalue for string comparison"),      \
352 	_PE(INVALID_REGEX,	"regex did not compute"),		      \
353 	_PE(ILLEGAL_STRING_CMP,	"illegal comparison for string"), 	      \
354 	_PE(ILLEGAL_INTEGER_CMP,"illegal comparison for integer"), 	      \
355 	_PE(REPARENT_NOT_OP,	"cannot reparent other than OP"),	      \
356 	_PE(REPARENT_FAILED,	"failed to reparent filter OP"),	      \
357 	_PE(BAD_FILTER_ARG,	"bad arg in filter tree"),		      \
358 	_PE(UNEXPECTED_TYPE,	"unexpected type (not a value)"),	      \
359 	_PE(ILLEGAL_TOKEN,	"illegal token"),			      \
360 	_PE(INVALID_PAREN,	"open parenthesis cannot come here"), 	      \
361 	_PE(UNBALANCED_PAREN,	"unbalanced number of parenthesis"),	      \
362 	_PE(UNKNOWN_TOKEN,	"unknown token"),			      \
363 	_PE(FILTER_NOT_FOUND,	"no filter found"),			      \
364 	_PE(NOT_A_NUMBER,	"must have number field"),		      \
365 	_PE(NO_FILTER,		"no filters exists"),			      \
366 	_PE(FILTER_MISS,	"record does not match to filter")
367 
368 #undef _PE
369 #define _PE(__code, __str) TEP_ERRNO__ ## __code
370 enum tep_errno {
371 	TEP_ERRNO__SUCCESS			= 0,
372 	TEP_ERRNO__FILTER_MATCH			= TEP_ERRNO__SUCCESS,
373 
374 	/*
375 	 * Choose an arbitrary negative big number not to clash with standard
376 	 * errno since SUS requires the errno has distinct positive values.
377 	 * See 'Issue 6' in the link below.
378 	 *
379 	 * https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
380 	 */
381 	__TEP_ERRNO__START			= -100000,
382 
383 	TEP_ERRORS,
384 
385 	__TEP_ERRNO__END,
386 };
387 #undef _PE
388 
389 struct tep_plugin_list;
390 
391 #define INVALID_PLUGIN_LIST_OPTION	((char **)((unsigned long)-1))
392 
393 enum tep_plugin_load_priority {
394 	TEP_PLUGIN_FIRST,
395 	TEP_PLUGIN_LAST,
396 };
397 
398 int tep_add_plugin_path(struct tep_handle *tep, char *path,
399 			enum tep_plugin_load_priority prio);
400 struct tep_plugin_list *tep_load_plugins(struct tep_handle *tep);
401 void tep_unload_plugins(struct tep_plugin_list *plugin_list,
402 			struct tep_handle *tep);
403 void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
404 			   void (*load_plugin)(struct tep_handle *tep,
405 					       const char *path,
406 					       const char *name,
407 					       void *data),
408 			   void *data);
409 char **tep_plugin_list_options(void);
410 void tep_plugin_free_options_list(char **list);
411 int tep_plugin_add_options(const char *name,
412 			   struct tep_plugin_option *options);
413 int tep_plugin_add_option(const char *name, const char *val);
414 void tep_plugin_remove_options(struct tep_plugin_option *options);
415 void tep_plugin_print_options(struct trace_seq *s);
416 void tep_print_plugins(struct trace_seq *s,
417 			const char *prefix, const char *suffix,
418 			const struct tep_plugin_list *list);
419 
420 /* tep_handle */
421 typedef char *(tep_func_resolver_t)(void *priv,
422 				    unsigned long long *addrp, char **modp);
423 void tep_set_flag(struct tep_handle *tep, int flag);
424 void tep_clear_flag(struct tep_handle *tep, enum tep_flag flag);
425 bool tep_test_flag(struct tep_handle *tep, enum tep_flag flags);
426 
tep_is_bigendian(void)427 static inline int tep_is_bigendian(void)
428 {
429 	unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
430 	unsigned int val;
431 
432 	memcpy(&val, str, 4);
433 	return val == 0x01020304;
434 }
435 
436 /* taken from kernel/trace/trace.h */
437 enum trace_flag_type {
438 	TRACE_FLAG_IRQS_OFF		= 0x01,
439 	TRACE_FLAG_IRQS_NOSUPPORT	= 0x02,
440 	TRACE_FLAG_NEED_RESCHED		= 0x04,
441 	TRACE_FLAG_HARDIRQ		= 0x08,
442 	TRACE_FLAG_SOFTIRQ		= 0x10,
443 };
444 
445 int tep_set_function_resolver(struct tep_handle *tep,
446 			      tep_func_resolver_t *func, void *priv);
447 void tep_reset_function_resolver(struct tep_handle *tep);
448 int tep_register_comm(struct tep_handle *tep, const char *comm, int pid);
449 int tep_override_comm(struct tep_handle *tep, const char *comm, int pid);
450 int tep_parse_saved_cmdlines(struct tep_handle *tep, const char *buf);
451 int tep_parse_kallsyms(struct tep_handle *tep, const char *kallsyms);
452 int tep_register_function(struct tep_handle *tep, char *name,
453 			  unsigned long long addr, char *mod);
454 int tep_parse_printk_formats(struct tep_handle *tep, const char *buf);
455 int tep_register_print_string(struct tep_handle *tep, const char *fmt,
456 			      unsigned long long addr);
457 bool tep_is_pid_registered(struct tep_handle *tep, int pid);
458 
459 struct tep_event *tep_get_event(struct tep_handle *tep, int index);
460 
461 #define TEP_PRINT_INFO		"INFO"
462 #define TEP_PRINT_INFO_RAW	"INFO_RAW"
463 #define TEP_PRINT_COMM		"COMM"
464 #define TEP_PRINT_LATENCY	"LATENCY"
465 #define TEP_PRINT_NAME		"NAME"
466 #define TEP_PRINT_PID		1U
467 #define TEP_PRINT_TIME		2U
468 #define TEP_PRINT_CPU		3U
469 
470 void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
471 		     struct tep_record *record, const char *fmt, ...)
472 	__attribute__ ((format (printf, 4, 5)));
473 
474 int tep_parse_header_page(struct tep_handle *tep, char *buf, unsigned long size,
475 			  int long_size);
476 
477 enum tep_errno tep_parse_event(struct tep_handle *tep, const char *buf,
478 			       unsigned long size, const char *sys);
479 enum tep_errno tep_parse_format(struct tep_handle *tep,
480 				struct tep_event **eventp,
481 				const char *buf,
482 				unsigned long size, const char *sys);
483 
484 void *tep_get_field_raw(struct trace_seq *s, struct tep_event *event,
485 			const char *name, struct tep_record *record,
486 			int *len, int err);
487 
488 int tep_get_field_val(struct trace_seq *s, struct tep_event *event,
489 		      const char *name, struct tep_record *record,
490 		      unsigned long long *val, int err);
491 int tep_get_common_field_val(struct trace_seq *s, struct tep_event *event,
492 			     const char *name, struct tep_record *record,
493 			     unsigned long long *val, int err);
494 int tep_get_any_field_val(struct trace_seq *s, struct tep_event *event,
495 			  const char *name, struct tep_record *record,
496 			  unsigned long long *val, int err);
497 
498 int tep_print_num_field(struct trace_seq *s, const char *fmt,
499 			struct tep_event *event, const char *name,
500 			struct tep_record *record, int err);
501 
502 int tep_print_func_field(struct trace_seq *s, const char *fmt,
503 			 struct tep_event *event, const char *name,
504 			 struct tep_record *record, int err);
505 
506 enum tep_reg_handler {
507 	TEP_REGISTER_SUCCESS = 0,
508 	TEP_REGISTER_SUCCESS_OVERWRITE,
509 };
510 
511 int tep_register_event_handler(struct tep_handle *tep, int id,
512 			       const char *sys_name, const char *event_name,
513 			       tep_event_handler_func func, void *context);
514 int tep_unregister_event_handler(struct tep_handle *tep, int id,
515 				 const char *sys_name, const char *event_name,
516 				 tep_event_handler_func func, void *context);
517 int tep_register_print_function(struct tep_handle *tep,
518 				tep_func_handler func,
519 				enum tep_func_arg_type ret_type,
520 				char *name, ...);
521 int tep_unregister_print_function(struct tep_handle *tep,
522 				  tep_func_handler func, char *name);
523 
524 struct tep_format_field *tep_find_common_field(struct tep_event *event, const char *name);
525 struct tep_format_field *tep_find_field(struct tep_event *event, const char *name);
526 struct tep_format_field *tep_find_any_field(struct tep_event *event, const char *name);
527 
528 const char *tep_find_function(struct tep_handle *tep, unsigned long long addr);
529 unsigned long long
530 tep_find_function_address(struct tep_handle *tep, unsigned long long addr);
531 int tep_find_function_info(struct tep_handle *tep, unsigned long long addr,
532 			   const char **name, unsigned long long *start,
533 			   unsigned long *size);
534 unsigned long long tep_read_number(struct tep_handle *tep, const void *ptr, int size);
535 int tep_read_number_field(struct tep_format_field *field, const void *data,
536 			  unsigned long long *value);
537 
538 struct tep_event *tep_get_first_event(struct tep_handle *tep);
539 int tep_get_events_count(struct tep_handle *tep);
540 struct tep_event *tep_find_event(struct tep_handle *tep, int id);
541 
542 struct tep_event *
543 tep_find_event_by_name(struct tep_handle *tep, const char *sys, const char *name);
544 struct tep_event *
545 tep_find_event_by_record(struct tep_handle *tep, struct tep_record *record);
546 
547 int tep_data_type(struct tep_handle *tep, struct tep_record *rec);
548 int tep_data_pid(struct tep_handle *tep, struct tep_record *rec);
549 int tep_data_preempt_count(struct tep_handle *tep, struct tep_record *rec);
550 int tep_data_flags(struct tep_handle *tep, struct tep_record *rec);
551 const char *tep_data_comm_from_pid(struct tep_handle *tep, int pid);
552 struct tep_cmdline;
553 struct tep_cmdline *tep_data_pid_from_comm(struct tep_handle *tep, const char *comm,
554 					   struct tep_cmdline *next);
555 int tep_cmdline_pid(struct tep_handle *tep, struct tep_cmdline *cmdline);
556 
557 void tep_print_field_content(struct trace_seq *s, void *data, int size,
558 			     struct tep_format_field *field);
559 void tep_record_print_fields(struct trace_seq *s,
560 			     struct tep_record *record,
561 			     struct tep_event *event);
562 void tep_record_print_selected_fields(struct trace_seq *s,
563 				      struct tep_record *record,
564 				      struct tep_event *event,
565 				      unsigned long long select_mask);
566 void tep_print_fields(struct trace_seq *s, void *data,
567 		      int size __maybe_unused, struct tep_event *event);
568 int tep_strerror(struct tep_handle *tep, enum tep_errno errnum,
569 		 char *buf, size_t buflen);
570 
571 struct tep_event **tep_list_events(struct tep_handle *tep, enum tep_event_sort_type);
572 struct tep_event **tep_list_events_copy(struct tep_handle *tep,
573 					enum tep_event_sort_type);
574 struct tep_format_field **tep_event_common_fields(struct tep_event *event);
575 struct tep_format_field **tep_event_fields(struct tep_event *event);
576 
577 int tep_get_function_count(struct tep_handle *tep);
578 
579 enum tep_endian {
580         TEP_LITTLE_ENDIAN = 0,
581         TEP_BIG_ENDIAN
582 };
583 int tep_get_cpus(struct tep_handle *tep);
584 void tep_set_cpus(struct tep_handle *tep, int cpus);
585 int tep_get_long_size(struct tep_handle *tep);
586 void tep_set_long_size(struct tep_handle *tep, int long_size);
587 int tep_get_page_size(struct tep_handle *tep);
588 int tep_get_sub_buffer_size(struct tep_handle *tep);
589 void tep_set_page_size(struct tep_handle *tep, int _page_size);
590 bool tep_is_file_bigendian(struct tep_handle *tep);
591 void tep_set_file_bigendian(struct tep_handle *tep, enum tep_endian endian);
592 bool tep_is_local_bigendian(struct tep_handle *tep);
593 void tep_set_local_bigendian(struct tep_handle *tep, enum tep_endian endian);
594 int tep_get_header_page_size(struct tep_handle *tep);
595 int tep_get_header_timestamp_size(struct tep_handle *tep);
596 bool tep_is_old_format(struct tep_handle *tep);
597 void tep_set_test_filters(struct tep_handle *tep, int test_filters);
598 
599 struct tep_handle *tep_alloc(void);
600 void tep_free(struct tep_handle *tep);
601 void tep_ref(struct tep_handle *tep);
602 void tep_unref(struct tep_handle *tep);
603 int tep_get_ref(struct tep_handle *tep);
604 
605 struct kbuffer *tep_kbuffer(struct tep_handle *tep);
606 
607 /* for debugging */
608 void tep_print_funcs(struct tep_handle *tep);
609 void tep_print_printk(struct tep_handle *tep);
610 
611 /* ----------------------- filtering ----------------------- */
612 
613 enum tep_filter_boolean_type {
614 	TEP_FILTER_FALSE,
615 	TEP_FILTER_TRUE,
616 };
617 
618 enum tep_filter_op_type {
619 	TEP_FILTER_OP_AND = 1,
620 	TEP_FILTER_OP_OR,
621 	TEP_FILTER_OP_NOT,
622 };
623 
624 enum tep_filter_cmp_type {
625 	TEP_FILTER_CMP_NONE,
626 	TEP_FILTER_CMP_EQ,
627 	TEP_FILTER_CMP_NE,
628 	TEP_FILTER_CMP_GT,
629 	TEP_FILTER_CMP_LT,
630 	TEP_FILTER_CMP_GE,
631 	TEP_FILTER_CMP_LE,
632 	TEP_FILTER_CMP_MATCH,
633 	TEP_FILTER_CMP_NOT_MATCH,
634 	TEP_FILTER_CMP_REGEX,
635 	TEP_FILTER_CMP_NOT_REGEX,
636 };
637 
638 enum tep_filter_exp_type {
639 	TEP_FILTER_EXP_NONE,
640 	TEP_FILTER_EXP_ADD,
641 	TEP_FILTER_EXP_SUB,
642 	TEP_FILTER_EXP_MUL,
643 	TEP_FILTER_EXP_DIV,
644 	TEP_FILTER_EXP_MOD,
645 	TEP_FILTER_EXP_RSHIFT,
646 	TEP_FILTER_EXP_LSHIFT,
647 	TEP_FILTER_EXP_AND,
648 	TEP_FILTER_EXP_OR,
649 	TEP_FILTER_EXP_XOR,
650 	TEP_FILTER_EXP_NOT,
651 };
652 
653 enum tep_filter_arg_type {
654 	TEP_FILTER_ARG_NONE,
655 	TEP_FILTER_ARG_BOOLEAN,
656 	TEP_FILTER_ARG_VALUE,
657 	TEP_FILTER_ARG_FIELD,
658 	TEP_FILTER_ARG_EXP,
659 	TEP_FILTER_ARG_OP,
660 	TEP_FILTER_ARG_NUM,
661 	TEP_FILTER_ARG_STR,
662 };
663 
664 enum tep_filter_value_type {
665 	TEP_FILTER_NUMBER,
666 	TEP_FILTER_STRING,
667 	TEP_FILTER_CHAR
668 };
669 
670 struct tep_filter_arg;
671 
672 struct tep_filter_arg_boolean {
673 	enum tep_filter_boolean_type	value;
674 };
675 
676 struct tep_filter_arg_field {
677 	struct tep_format_field		*field;
678 };
679 
680 struct tep_filter_arg_value {
681 	enum tep_filter_value_type	type;
682 	union {
683 		char			*str;
684 		unsigned long long	val;
685 	};
686 };
687 
688 struct tep_filter_arg_op {
689 	enum tep_filter_op_type		type;
690 	struct tep_filter_arg		*left;
691 	struct tep_filter_arg		*right;
692 };
693 
694 struct tep_filter_arg_exp {
695 	enum tep_filter_exp_type	type;
696 	struct tep_filter_arg		*left;
697 	struct tep_filter_arg		*right;
698 };
699 
700 struct tep_filter_arg_num {
701 	enum tep_filter_cmp_type	type;
702 	struct tep_filter_arg		*left;
703 	struct tep_filter_arg		*right;
704 };
705 
706 struct tep_filter_arg_str {
707 	enum tep_filter_cmp_type	type;
708 	struct tep_format_field		*field;
709 	char				*val;
710 	char				*buffer;
711 	regex_t				reg;
712 };
713 
714 struct tep_filter_arg {
715 	enum tep_filter_arg_type		type;
716 	union {
717 		struct tep_filter_arg_boolean	boolean;
718 		struct tep_filter_arg_field	field;
719 		struct tep_filter_arg_value	value;
720 		struct tep_filter_arg_op	op;
721 		struct tep_filter_arg_exp	exp;
722 		struct tep_filter_arg_num	num;
723 		struct tep_filter_arg_str	str;
724 	};
725 };
726 
727 struct tep_filter_type {
728 	int			event_id;
729 	struct tep_event	*event;
730 	struct tep_filter_arg	*filter;
731 };
732 
733 #define TEP_FILTER_ERROR_BUFSZ  1024
734 
735 struct tep_event_filter {
736 	struct tep_handle	*tep;
737 	int			filters;
738 	struct tep_filter_type	*event_filters;
739 	char			error_buffer[TEP_FILTER_ERROR_BUFSZ];
740 };
741 
742 struct tep_event_filter *tep_filter_alloc(struct tep_handle *tep);
743 
744 /* for backward compatibility */
745 #define FILTER_NONE		TEP_ERRNO__NO_FILTER
746 #define FILTER_NOEXIST		TEP_ERRNO__FILTER_NOT_FOUND
747 #define FILTER_MISS		TEP_ERRNO__FILTER_MISS
748 #define FILTER_MATCH		TEP_ERRNO__FILTER_MATCH
749 
750 enum tep_errno tep_filter_add_filter_str(struct tep_event_filter *filter,
751 					 const char *filter_str);
752 
753 enum tep_errno tep_filter_match(struct tep_event_filter *filter,
754 				struct tep_record *record);
755 
756 int tep_filter_strerror(struct tep_event_filter *filter, enum tep_errno err,
757 			char *buf, size_t buflen);
758 
759 int tep_event_filtered(struct tep_event_filter *filter,
760 		       int event_id);
761 
762 void tep_filter_reset(struct tep_event_filter *filter);
763 
764 void tep_filter_free(struct tep_event_filter *filter);
765 
766 char *tep_filter_make_string(struct tep_event_filter *filter, int event_id);
767 
768 int tep_filter_remove_event(struct tep_event_filter *filter,
769 			    int event_id);
770 
771 int tep_filter_copy(struct tep_event_filter *dest, struct tep_event_filter *source);
772 
773 int tep_filter_compare(struct tep_event_filter *filter1, struct tep_event_filter *filter2);
774 
775 /* Control library logs */
776 enum tep_loglevel {
777 	TEP_LOG_NONE = 0,
778 	TEP_LOG_CRITICAL,
779 	TEP_LOG_ERROR,
780 	TEP_LOG_WARNING,
781 	TEP_LOG_INFO,
782 	TEP_LOG_DEBUG,
783 	TEP_LOG_ALL
784 };
785 void tep_set_loglevel(enum tep_loglevel level);
786 
787 /*
788  * Part of the KVM plugin. Will pass the current @event and @record
789  * as well as a pointer to the address to a guest kernel function.
790  * This is currently a weak function defined in the KVM plugin and
791  * should never be called. But a tool can override it, and this will
792  * be called when the kvm plugin has an address it needs the function
793  * name of.
794  *
795  * This function should return the function name for the given address
796  * and optionally, it can update @paddr to include the start of the function
797  * such that the kvm plugin can include an offset.
798  *
799  * For an application to be able to override the weak version in the
800  * plugin, it must be compiled with the gcc -rdynamic option that will
801  * allow the dynamic linker to use the application's function to
802  * override this callback.
803  */
804 const char *tep_plugin_kvm_get_func(struct tep_event *event,
805 				    struct tep_record *record,
806 				    unsigned long long *paddr);
807 
808 /*
809  * tep_plugin_kvm_put_func() is another weak function that can be used
810  * to call back into the application if the function name returned by
811  * tep_plugin_kvm_get_func() needs to be freed.
812  */
813 void tep_plugin_kvm_put_func(const char *func);
814 
815 /* DEPRECATED */
816 void tep_print_field(struct trace_seq *s, void *data,
817 		     struct tep_format_field *field);
818 
819 #ifdef __cplusplus
820 }
821 #endif
822 
823 #endif /* _PARSE_EVENTS_H */
824