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