1 #ifndef _PROBE_FINDER_H
2 #define _PROBE_FINDER_H
3 
4 #include <stdbool.h>
5 #include "util.h"
6 #include "probe-event.h"
7 
8 #define MAX_PATH_LEN		 256
9 #define MAX_PROBE_BUFFER	1024
10 #define MAX_PROBES		 128
11 
is_c_varname(const char * name)12 static inline int is_c_varname(const char *name)
13 {
14 	/* TODO */
15 	return isalpha(name[0]) || name[0] == '_';
16 }
17 
18 #ifdef DWARF_SUPPORT
19 /* Find probe_trace_events specified by perf_probe_event from debuginfo */
20 extern int find_probe_trace_events(int fd, struct perf_probe_event *pev,
21 				    struct probe_trace_event **tevs,
22 				    int max_tevs);
23 
24 /* Find a perf_probe_point from debuginfo */
25 extern int find_perf_probe_point(unsigned long addr,
26 				 struct perf_probe_point *ppt);
27 
28 /* Find a line range */
29 extern int find_line_range(int fd, struct line_range *lr);
30 
31 /* Find available variables */
32 extern int find_available_vars_at(int fd, struct perf_probe_event *pev,
33 				  struct variable_list **vls, int max_points,
34 				  bool externs);
35 
36 #include <dwarf.h>
37 #include <elfutils/libdw.h>
38 #include <elfutils/libdwfl.h>
39 #include <elfutils/version.h>
40 
41 struct probe_finder {
42 	struct perf_probe_event	*pev;		/* Target probe event */
43 
44 	/* Callback when a probe point is found */
45 	int (*callback)(Dwarf_Die *sp_die, struct probe_finder *pf);
46 
47 	/* For function searching */
48 	int			lno;		/* Line number */
49 	Dwarf_Addr		addr;		/* Address */
50 	const char		*fname;		/* Real file name */
51 	Dwarf_Die		cu_die;		/* Current CU */
52 	struct list_head	lcache;		/* Line cache for lazy match */
53 
54 	/* For variable searching */
55 #if _ELFUTILS_PREREQ(0, 142)
56 	Dwarf_CFI		*cfi;		/* Call Frame Information */
57 #endif
58 	Dwarf_Op		*fb_ops;	/* Frame base attribute */
59 	struct perf_probe_arg	*pvar;		/* Current target variable */
60 	struct probe_trace_arg	*tvar;		/* Current result variable */
61 };
62 
63 struct trace_event_finder {
64 	struct probe_finder	pf;
65 	struct probe_trace_event *tevs;		/* Found trace events */
66 	int			ntevs;		/* Number of trace events */
67 	int			max_tevs;	/* Max number of trace events */
68 };
69 
70 struct available_var_finder {
71 	struct probe_finder	pf;
72 	struct variable_list	*vls;		/* Found variable lists */
73 	int			nvls;		/* Number of variable lists */
74 	int			max_vls;	/* Max no. of variable lists */
75 	bool			externs;	/* Find external vars too */
76 	bool			child;		/* Search child scopes */
77 };
78 
79 struct line_finder {
80 	struct line_range	*lr;		/* Target line range */
81 
82 	const char		*fname;		/* File name */
83 	int			lno_s;		/* Start line number */
84 	int			lno_e;		/* End line number */
85 	Dwarf_Die		cu_die;		/* Current CU */
86 	int			found;
87 };
88 
89 #endif /* DWARF_SUPPORT */
90 
91 #endif /*_PROBE_FINDER_H */
92