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