xref: /openbmc/linux/tools/perf/util/probe-event.h (revision 31af04cd)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _PROBE_EVENT_H
3 #define _PROBE_EVENT_H
4 
5 #include <linux/compiler.h>
6 #include <stdbool.h>
7 #include "intlist.h"
8 #include "namespaces.h"
9 
10 /* Probe related configurations */
11 struct probe_conf {
12 	bool	show_ext_vars;
13 	bool	show_location_range;
14 	bool	force_add;
15 	bool	no_inlines;
16 	bool	cache;
17 	int	max_probes;
18 };
19 extern struct probe_conf probe_conf;
20 extern bool probe_event_dry_run;
21 
22 struct symbol;
23 
24 /* kprobe-tracer and uprobe-tracer tracing point */
25 struct probe_trace_point {
26 	char		*realname;	/* function real name (if needed) */
27 	char		*symbol;	/* Base symbol */
28 	char		*module;	/* Module name */
29 	unsigned long	offset;		/* Offset from symbol */
30 	unsigned long	ref_ctr_offset;	/* SDT reference counter offset */
31 	unsigned long	address;	/* Actual address of the trace point */
32 	bool		retprobe;	/* Return probe flag */
33 };
34 
35 /* probe-tracer tracing argument referencing offset */
36 struct probe_trace_arg_ref {
37 	struct probe_trace_arg_ref	*next;	/* Next reference */
38 	long				offset;	/* Offset value */
39 };
40 
41 /* kprobe-tracer and uprobe-tracer tracing argument */
42 struct probe_trace_arg {
43 	char				*name;	/* Argument name */
44 	char				*value;	/* Base value */
45 	char				*type;	/* Type name */
46 	struct probe_trace_arg_ref	*ref;	/* Referencing offset */
47 };
48 
49 /* kprobe-tracer and uprobe-tracer tracing event (point + arg) */
50 struct probe_trace_event {
51 	char				*event;	/* Event name */
52 	char				*group;	/* Group name */
53 	struct probe_trace_point	point;	/* Trace point */
54 	int				nargs;	/* Number of args */
55 	bool				uprobes;	/* uprobes only */
56 	struct probe_trace_arg		*args;	/* Arguments */
57 };
58 
59 /* Perf probe probing point */
60 struct perf_probe_point {
61 	char		*file;		/* File path */
62 	char		*function;	/* Function name */
63 	int		line;		/* Line number */
64 	bool		retprobe;	/* Return probe flag */
65 	char		*lazy_line;	/* Lazy matching pattern */
66 	unsigned long	offset;		/* Offset from function entry */
67 	unsigned long	abs_address;	/* Absolute address of the point */
68 };
69 
70 /* Perf probe probing argument field chain */
71 struct perf_probe_arg_field {
72 	struct perf_probe_arg_field	*next;	/* Next field */
73 	char				*name;	/* Name of the field */
74 	long				index;	/* Array index number */
75 	bool				ref;	/* Referencing flag */
76 };
77 
78 /* Perf probe probing argument */
79 struct perf_probe_arg {
80 	char				*name;	/* Argument name */
81 	char				*var;	/* Variable name */
82 	char				*type;	/* Type name */
83 	struct perf_probe_arg_field	*field;	/* Structure fields */
84 };
85 
86 /* Perf probe probing event (point + arg) */
87 struct perf_probe_event {
88 	char			*event;	/* Event name */
89 	char			*group;	/* Group name */
90 	struct perf_probe_point	point;	/* Probe point */
91 	int			nargs;	/* Number of arguments */
92 	bool			sdt;	/* SDT/cached event flag */
93 	bool			uprobes;	/* Uprobe event flag */
94 	char			*target;	/* Target binary */
95 	struct perf_probe_arg	*args;	/* Arguments */
96 	struct probe_trace_event *tevs;
97 	int			ntevs;
98 	struct nsinfo		*nsi;	/* Target namespace */
99 };
100 
101 /* Line range */
102 struct line_range {
103 	char			*file;		/* File name */
104 	char			*function;	/* Function name */
105 	int			start;		/* Start line number */
106 	int			end;		/* End line number */
107 	int			offset;		/* Start line offset */
108 	char			*path;		/* Real path name */
109 	char			*comp_dir;	/* Compile directory */
110 	struct intlist		*line_list;	/* Visible lines */
111 };
112 
113 struct strlist;
114 
115 /* List of variables */
116 struct variable_list {
117 	struct probe_trace_point	point;	/* Actual probepoint */
118 	struct strlist			*vars;	/* Available variables */
119 };
120 
121 struct map;
122 int init_probe_symbol_maps(bool user_only);
123 void exit_probe_symbol_maps(void);
124 
125 /* Command string to events */
126 int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev);
127 int parse_probe_trace_command(const char *cmd, struct probe_trace_event *tev);
128 
129 /* Events to command string */
130 char *synthesize_perf_probe_command(struct perf_probe_event *pev);
131 char *synthesize_probe_trace_command(struct probe_trace_event *tev);
132 char *synthesize_perf_probe_arg(struct perf_probe_arg *pa);
133 char *synthesize_perf_probe_point(struct perf_probe_point *pp);
134 
135 int perf_probe_event__copy(struct perf_probe_event *dst,
136 			   struct perf_probe_event *src);
137 
138 bool perf_probe_with_var(struct perf_probe_event *pev);
139 
140 /* Check the perf_probe_event needs debuginfo */
141 bool perf_probe_event_need_dwarf(struct perf_probe_event *pev);
142 
143 /* Release event contents */
144 void clear_perf_probe_event(struct perf_probe_event *pev);
145 void clear_probe_trace_event(struct probe_trace_event *tev);
146 
147 /* Command string to line-range */
148 int parse_line_range_desc(const char *cmd, struct line_range *lr);
149 
150 /* Release line range members */
151 void line_range__clear(struct line_range *lr);
152 
153 /* Initialize line range */
154 int line_range__init(struct line_range *lr);
155 
156 int add_perf_probe_events(struct perf_probe_event *pevs, int npevs);
157 int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs);
158 int apply_perf_probe_events(struct perf_probe_event *pevs, int npevs);
159 int show_probe_trace_events(struct perf_probe_event *pevs, int npevs);
160 void cleanup_perf_probe_events(struct perf_probe_event *pevs, int npevs);
161 
162 struct strfilter;
163 
164 int del_perf_probe_events(struct strfilter *filter);
165 
166 int show_perf_probe_event(const char *group, const char *event,
167 			  struct perf_probe_event *pev,
168 			  const char *module, bool use_stdout);
169 int show_perf_probe_events(struct strfilter *filter);
170 int show_line_range(struct line_range *lr, const char *module,
171 		    struct nsinfo *nsi, bool user);
172 int show_available_vars(struct perf_probe_event *pevs, int npevs,
173 			struct strfilter *filter);
174 int show_available_funcs(const char *module, struct nsinfo *nsi,
175 			 struct strfilter *filter, bool user);
176 void arch__fix_tev_from_maps(struct perf_probe_event *pev,
177 			     struct probe_trace_event *tev, struct map *map,
178 			     struct symbol *sym);
179 
180 /* If there is no space to write, returns -E2BIG. */
181 int e_snprintf(char *str, size_t size, const char *format, ...) __printf(3, 4);
182 
183 /* Maximum index number of event-name postfix */
184 #define MAX_EVENT_INDEX	1024
185 
186 int copy_to_probe_trace_arg(struct probe_trace_arg *tvar,
187 			    struct perf_probe_arg *pvar);
188 
189 struct map *get_target_map(const char *target, struct nsinfo *nsi, bool user);
190 
191 void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
192 					   int ntevs);
193 
194 #endif /*_PROBE_EVENT_H */
195