xref: /openbmc/linux/tools/perf/util/probe-finder.h (revision 52fb57e7)
1 #ifndef _PROBE_FINDER_H
2 #define _PROBE_FINDER_H
3 
4 #include <stdbool.h>
5 #include "util.h"
6 #include "intlist.h"
7 #include "probe-event.h"
8 
9 #define MAX_PROBE_BUFFER	1024
10 #define MAX_PROBES		 128
11 #define MAX_PROBE_ARGS		 128
12 
13 static inline int is_c_varname(const char *name)
14 {
15 	/* TODO */
16 	return isalpha(name[0]) || name[0] == '_';
17 }
18 
19 #ifdef HAVE_DWARF_SUPPORT
20 
21 #include "dwarf-aux.h"
22 
23 /* TODO: export debuginfo data structure even if no dwarf support */
24 
25 /* debug information structure */
26 struct debuginfo {
27 	Dwarf		*dbg;
28 	Dwfl_Module	*mod;
29 	Dwfl		*dwfl;
30 	Dwarf_Addr	bias;
31 };
32 
33 /* This also tries to open distro debuginfo */
34 extern struct debuginfo *debuginfo__new(const char *path);
35 extern void debuginfo__delete(struct debuginfo *dbg);
36 
37 /* Find probe_trace_events specified by perf_probe_event from debuginfo */
38 extern int debuginfo__find_trace_events(struct debuginfo *dbg,
39 					struct perf_probe_event *pev,
40 					struct probe_trace_event **tevs,
41 					int max_tevs);
42 
43 /* Find a perf_probe_point from debuginfo */
44 extern int debuginfo__find_probe_point(struct debuginfo *dbg,
45 				       unsigned long addr,
46 				       struct perf_probe_point *ppt);
47 
48 /* Find a line range */
49 extern int debuginfo__find_line_range(struct debuginfo *dbg,
50 				      struct line_range *lr);
51 
52 /* Find available variables */
53 extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,
54 					     struct perf_probe_event *pev,
55 					     struct variable_list **vls,
56 					     int max_points, bool externs);
57 
58 /* Find a src file from a DWARF tag path */
59 int get_real_path(const char *raw_path, const char *comp_dir,
60 			 char **new_path);
61 
62 struct probe_finder {
63 	struct perf_probe_event	*pev;		/* Target probe event */
64 
65 	/* Callback when a probe point is found */
66 	int (*callback)(Dwarf_Die *sc_die, struct probe_finder *pf);
67 
68 	/* For function searching */
69 	int			lno;		/* Line number */
70 	Dwarf_Addr		addr;		/* Address */
71 	const char		*fname;		/* Real file name */
72 	Dwarf_Die		cu_die;		/* Current CU */
73 	Dwarf_Die		sp_die;
74 	struct intlist		*lcache;	/* Line cache for lazy match */
75 
76 	/* For variable searching */
77 #if _ELFUTILS_PREREQ(0, 142)
78 	Dwarf_CFI		*cfi;		/* Call Frame Information */
79 #endif
80 	Dwarf_Op		*fb_ops;	/* Frame base attribute */
81 	struct perf_probe_arg	*pvar;		/* Current target variable */
82 	struct probe_trace_arg	*tvar;		/* Current result variable */
83 };
84 
85 struct trace_event_finder {
86 	struct probe_finder	pf;
87 	Dwfl_Module		*mod;		/* For solving symbols */
88 	struct probe_trace_event *tevs;		/* Found trace events */
89 	int			ntevs;		/* Number of trace events */
90 	int			max_tevs;	/* Max number of trace events */
91 };
92 
93 struct available_var_finder {
94 	struct probe_finder	pf;
95 	Dwfl_Module		*mod;		/* For solving symbols */
96 	struct variable_list	*vls;		/* Found variable lists */
97 	int			nvls;		/* Number of variable lists */
98 	int			max_vls;	/* Max no. of variable lists */
99 	bool			externs;	/* Find external vars too */
100 	bool			child;		/* Search child scopes */
101 };
102 
103 struct line_finder {
104 	struct line_range	*lr;		/* Target line range */
105 
106 	const char		*fname;		/* File name */
107 	int			lno_s;		/* Start line number */
108 	int			lno_e;		/* End line number */
109 	Dwarf_Die		cu_die;		/* Current CU */
110 	Dwarf_Die		sp_die;
111 	int			found;
112 };
113 
114 #endif /* HAVE_DWARF_SUPPORT */
115 
116 #endif /*_PROBE_FINDER_H */
117