1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _PROBE_FINDER_H 3 #define _PROBE_FINDER_H 4 5 #include <stdbool.h> 6 #include "intlist.h" 7 #include "build-id.h" 8 #include "probe-event.h" 9 #include <linux/ctype.h> 10 11 #define MAX_PROBE_BUFFER 1024 12 #define MAX_PROBES 128 13 #define MAX_PROBE_ARGS 128 14 15 #define PROBE_ARG_VARS "$vars" 16 #define PROBE_ARG_PARAMS "$params" 17 18 static inline int is_c_varname(const char *name) 19 { 20 /* TODO */ 21 return isalpha(name[0]) || name[0] == '_'; 22 } 23 24 #ifdef HAVE_LIBDW_SUPPORT 25 26 #include "dwarf-aux.h" 27 #include "debuginfo.h" 28 29 /* Check the language code is known C */ 30 bool is_known_C_lang(int lang); 31 32 /* Find probe_trace_events specified by perf_probe_event from debuginfo */ 33 int debuginfo__find_trace_events(struct debuginfo *dbg, 34 struct perf_probe_event *pev, 35 struct probe_trace_event **tevs); 36 37 /* Find a perf_probe_point from debuginfo */ 38 int debuginfo__find_probe_point(struct debuginfo *dbg, u64 addr, 39 struct perf_probe_point *ppt); 40 41 /* Find a line range */ 42 int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr); 43 44 /* Find available variables */ 45 int debuginfo__find_available_vars_at(struct debuginfo *dbg, 46 struct perf_probe_event *pev, 47 struct variable_list **vls); 48 49 /* Find a src file from a DWARF tag path */ 50 int find_source_path(const char *raw_path, const char *sbuild_id, 51 const char *comp_dir, char **new_path); 52 53 struct probe_finder { 54 struct perf_probe_event *pev; /* Target probe event */ 55 struct debuginfo *dbg; 56 57 /* Callback when a probe point is found */ 58 int (*callback)(Dwarf_Die *sc_die, struct probe_finder *pf); 59 60 /* For function searching */ 61 int lno; /* Line number */ 62 Dwarf_Addr addr; /* Address */ 63 const char *fname; /* Real file name */ 64 Dwarf_Die cu_die; /* Current CU */ 65 Dwarf_Die sp_die; 66 struct intlist *lcache; /* Line cache for lazy match */ 67 68 /* For variable searching */ 69 /* Call Frame Information from .eh_frame. Owned by this struct. */ 70 Dwarf_CFI *cfi_eh; 71 /* Call Frame Information from .debug_frame. Not owned. */ 72 Dwarf_CFI *cfi_dbg; 73 Dwarf_Op *fb_ops; /* Frame base attribute */ 74 unsigned int e_machine; /* ELF target machine arch */ 75 unsigned int e_flags; /* ELF target machine flags */ 76 struct perf_probe_arg *pvar; /* Current target variable */ 77 struct probe_trace_arg *tvar; /* Current result variable */ 78 bool skip_empty_arg; /* Skip non-exist args */ 79 }; 80 81 struct trace_event_finder { 82 struct probe_finder pf; 83 Dwfl_Module *mod; /* For solving symbols */ 84 struct probe_trace_event *tevs; /* Found trace events */ 85 int ntevs; /* Number of trace events */ 86 int max_tevs; /* Max number of trace events */ 87 }; 88 89 struct available_var_finder { 90 struct probe_finder pf; 91 Dwfl_Module *mod; /* For solving symbols */ 92 struct variable_list *vls; /* Found variable lists */ 93 int nvls; /* Number of variable lists */ 94 int max_vls; /* Max no. of variable lists */ 95 bool child; /* Search child scopes */ 96 }; 97 98 struct line_finder { 99 struct line_range *lr; /* Target line range */ 100 101 const char *fname; /* File name */ 102 int lno_s; /* Start line number */ 103 int lno_e; /* End line number */ 104 Dwarf_Die cu_die; /* Current CU */ 105 Dwarf_Die sp_die; 106 int found; 107 }; 108 109 #else 110 #define is_known_C_lang(lang) (false) 111 #endif /* HAVE_LIBDW_SUPPORT */ 112 113 #endif /*_PROBE_FINDER_H */ 114