blob: bba69d4556999e5081b018857acd230de6740eea [file] [log] [blame]
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -04001#ifndef _PROBE_FINDER_H
2#define _PROBE_FINDER_H
3
Masami Hiramatsu804b3602010-02-25 08:35:42 -05004#include <stdbool.h>
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -02005#include "util.h"
Masami Hiramatsu4235b042010-03-16 18:06:12 -04006#include "probe-event.h"
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -02007
Masami Hiramatsu27f3b242009-12-16 17:16:19 -05008#define MAX_PATH_LEN 256
9#define MAX_PROBE_BUFFER 1024
10#define MAX_PROBES 128
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040011
12static inline int is_c_varname(const char *name)
13{
14 /* TODO */
15 return isalpha(name[0]) || name[0] == '_';
16}
17
Masami Hiramatsu4b4da7f2010-03-22 13:10:26 -030018#ifdef DWARF_SUPPORT
Srikar Dronamraju0e608362010-07-29 19:43:51 +053019/* Find probe_trace_events specified by perf_probe_event from debuginfo */
20extern int find_probe_trace_events(int fd, struct perf_probe_event *pev,
21 struct probe_trace_event **tevs,
Masami Hiramatsuef4a3562010-04-21 15:56:40 -040022 int max_tevs);
Masami Hiramatsu4235b042010-03-16 18:06:12 -040023
Masami Hiramatsufb1587d2010-03-16 18:06:19 -040024/* Find a perf_probe_point from debuginfo */
Masami Hiramatsu469b9b82010-10-21 19:13:41 +090025extern int find_perf_probe_point(unsigned long addr,
Masami Hiramatsufb1587d2010-03-16 18:06:19 -040026 struct perf_probe_point *ppt);
27
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090028/* Find a line range */
Masami Hiramatsu631c9de2010-01-06 09:45:34 -050029extern int find_line_range(int fd, struct line_range *lr);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040030
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090031/* Find available variables */
32extern int find_available_vars_at(int fd, struct perf_probe_event *pev,
Masami Hiramatsufb8c5a52010-10-21 19:13:35 +090033 struct variable_list **vls, int max_points,
34 bool externs);
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090035
Masami Hiramatsu27f3b242009-12-16 17:16:19 -050036#include <dwarf.h>
Masami Hiramatsu804b3602010-02-25 08:35:42 -050037#include <libdw.h>
Masami Hiramatsu469b9b82010-10-21 19:13:41 +090038#include <libdwfl.h>
Masami Hiramatsu7752f1b2010-05-10 13:12:07 -040039#include <version.h>
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040040
41struct probe_finder {
Masami Hiramatsu4235b042010-03-16 18:06:12 -040042 struct perf_probe_event *pev; /* Target probe event */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090043
44 /* Callback when a probe point is found */
45 int (*callback)(Dwarf_Die *sp_die, struct probe_finder *pf);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040046
47 /* For function searching */
Arnaldo Carvalho de Meloeed05fe2010-04-05 12:53:45 -030048 int lno; /* Line number */
Masami Hiramatsu804b3602010-02-25 08:35:42 -050049 Dwarf_Addr addr; /* Address */
Masami Hiramatsu4235b042010-03-16 18:06:12 -040050 const char *fname; /* Real file name */
Masami Hiramatsu804b3602010-02-25 08:35:42 -050051 Dwarf_Die cu_die; /* Current CU */
Masami Hiramatsu4235b042010-03-16 18:06:12 -040052 struct list_head lcache; /* Line cache for lazy match */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040053
54 /* For variable searching */
Masami Hiramatsu7752f1b2010-05-10 13:12:07 -040055#if _ELFUTILS_PREREQ(0, 142)
Masami Hiramatsua34a9852010-04-12 13:17:29 -040056 Dwarf_CFI *cfi; /* Call Frame Information */
Masami Hiramatsu7752f1b2010-05-10 13:12:07 -040057#endif
Masami Hiramatsu804b3602010-02-25 08:35:42 -050058 Dwarf_Op *fb_ops; /* Frame base attribute */
Masami Hiramatsu4235b042010-03-16 18:06:12 -040059 struct perf_probe_arg *pvar; /* Current target variable */
Srikar Dronamraju0e608362010-07-29 19:43:51 +053060 struct probe_trace_arg *tvar; /* Current result variable */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040061};
Masami Hiramatsu631c9de2010-01-06 09:45:34 -050062
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090063struct 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
70struct 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 */
Masami Hiramatsufb8c5a52010-10-21 19:13:35 +090075 bool externs; /* Find external vars too */
76 bool child; /* Search child scopes */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090077};
78
Masami Hiramatsu631c9de2010-01-06 09:45:34 -050079struct line_finder {
Masami Hiramatsu804b3602010-02-25 08:35:42 -050080 struct line_range *lr; /* Target line range */
Masami Hiramatsu631c9de2010-01-06 09:45:34 -050081
Masami Hiramatsu804b3602010-02-25 08:35:42 -050082 const char *fname; /* File name */
83 int lno_s; /* Start line number */
84 int lno_e; /* End line number */
Masami Hiramatsu804b3602010-02-25 08:35:42 -050085 Dwarf_Die cu_die; /* Current CU */
Masami Hiramatsu631c9de2010-01-06 09:45:34 -050086 int found;
87};
88
Masami Hiramatsu4b4da7f2010-03-22 13:10:26 -030089#endif /* DWARF_SUPPORT */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040090
91#endif /*_PROBE_FINDER_H */