blob: 3b7d63018960d7ff6a6808ce81eff2d34b40bd09 [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_PROBE_BUFFER 1024
9#define MAX_PROBES 128
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040010
11static inline int is_c_varname(const char *name)
12{
13 /* TODO */
14 return isalpha(name[0]) || name[0] == '_';
15}
16
Masami Hiramatsu4b4da7f2010-03-22 13:10:26 -030017#ifdef DWARF_SUPPORT
Masami Hiramatsuff741782011-06-27 16:27:39 +090018
19#include "dwarf-aux.h"
20
21/* TODO: export debuginfo data structure even if no dwarf support */
22
23/* debug information structure */
24struct debuginfo {
25 Dwarf *dbg;
Masami Hiramatsu576b5232013-09-25 22:16:16 +090026 Dwfl_Module *mod;
Masami Hiramatsuff741782011-06-27 16:27:39 +090027 Dwfl *dwfl;
28 Dwarf_Addr bias;
29};
30
31extern struct debuginfo *debuginfo__new(const char *path);
32extern struct debuginfo *debuginfo__new_online_kernel(unsigned long addr);
33extern void debuginfo__delete(struct debuginfo *self);
34
Srikar Dronamraju0e608362010-07-29 19:43:51 +053035/* Find probe_trace_events specified by perf_probe_event from debuginfo */
Masami Hiramatsuff741782011-06-27 16:27:39 +090036extern int debuginfo__find_trace_events(struct debuginfo *self,
37 struct perf_probe_event *pev,
38 struct probe_trace_event **tevs,
39 int max_tevs);
Masami Hiramatsu4235b042010-03-16 18:06:12 -040040
Masami Hiramatsufb1587d2010-03-16 18:06:19 -040041/* Find a perf_probe_point from debuginfo */
Masami Hiramatsuff741782011-06-27 16:27:39 +090042extern int debuginfo__find_probe_point(struct debuginfo *self,
43 unsigned long addr,
44 struct perf_probe_point *ppt);
Masami Hiramatsufb1587d2010-03-16 18:06:19 -040045
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090046/* Find a line range */
Masami Hiramatsuff741782011-06-27 16:27:39 +090047extern int debuginfo__find_line_range(struct debuginfo *self,
48 struct line_range *lr);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040049
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090050/* Find available variables */
Masami Hiramatsuff741782011-06-27 16:27:39 +090051extern int debuginfo__find_available_vars_at(struct debuginfo *self,
52 struct perf_probe_event *pev,
53 struct variable_list **vls,
54 int max_points, bool externs);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040055
56struct probe_finder {
Masami Hiramatsu4235b042010-03-16 18:06:12 -040057 struct perf_probe_event *pev; /* Target probe event */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090058
59 /* Callback when a probe point is found */
Masami Hiramatsu221d0612011-08-11 20:02:59 +090060 int (*callback)(Dwarf_Die *sc_die, struct probe_finder *pf);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040061
62 /* For function searching */
Arnaldo Carvalho de Meloeed05fe2010-04-05 12:53:45 -030063 int lno; /* Line number */
Masami Hiramatsu804b3602010-02-25 08:35:42 -050064 Dwarf_Addr addr; /* Address */
Masami Hiramatsu4235b042010-03-16 18:06:12 -040065 const char *fname; /* Real file name */
Masami Hiramatsu804b3602010-02-25 08:35:42 -050066 Dwarf_Die cu_die; /* Current CU */
Lin Mingcd25f8b2011-03-25 16:27:48 +080067 Dwarf_Die sp_die;
Masami Hiramatsu4235b042010-03-16 18:06:12 -040068 struct list_head lcache; /* Line cache for lazy match */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040069
70 /* For variable searching */
Masami Hiramatsu7752f1b2010-05-10 13:12:07 -040071#if _ELFUTILS_PREREQ(0, 142)
Masami Hiramatsua34a9852010-04-12 13:17:29 -040072 Dwarf_CFI *cfi; /* Call Frame Information */
Masami Hiramatsu7752f1b2010-05-10 13:12:07 -040073#endif
Masami Hiramatsu804b3602010-02-25 08:35:42 -050074 Dwarf_Op *fb_ops; /* Frame base attribute */
Masami Hiramatsu4235b042010-03-16 18:06:12 -040075 struct perf_probe_arg *pvar; /* Current target variable */
Srikar Dronamraju0e608362010-07-29 19:43:51 +053076 struct probe_trace_arg *tvar; /* Current result variable */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040077};
Masami Hiramatsu631c9de2010-01-06 09:45:34 -050078
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090079struct trace_event_finder {
80 struct probe_finder pf;
Masami Hiramatsu576b5232013-09-25 22:16:16 +090081 Dwfl_Module *mod; /* For solving symbols */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090082 struct probe_trace_event *tevs; /* Found trace events */
83 int ntevs; /* Number of trace events */
84 int max_tevs; /* Max number of trace events */
85};
86
87struct available_var_finder {
88 struct probe_finder pf;
Masami Hiramatsu576b5232013-09-25 22:16:16 +090089 Dwfl_Module *mod; /* For solving symbols */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090090 struct variable_list *vls; /* Found variable lists */
91 int nvls; /* Number of variable lists */
92 int max_vls; /* Max no. of variable lists */
Masami Hiramatsufb8c5a52010-10-21 19:13:35 +090093 bool externs; /* Find external vars too */
94 bool child; /* Search child scopes */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090095};
96
Masami Hiramatsu631c9de2010-01-06 09:45:34 -050097struct line_finder {
Masami Hiramatsu804b3602010-02-25 08:35:42 -050098 struct line_range *lr; /* Target line range */
Masami Hiramatsu631c9de2010-01-06 09:45:34 -050099
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500100 const char *fname; /* File name */
101 int lno_s; /* Start line number */
102 int lno_e; /* End line number */
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500103 Dwarf_Die cu_die; /* Current CU */
Lin Mingcd25f8b2011-03-25 16:27:48 +0800104 Dwarf_Die sp_die;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500105 int found;
106};
107
Masami Hiramatsu4b4da7f2010-03-22 13:10:26 -0300108#endif /* DWARF_SUPPORT */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400109
110#endif /*_PROBE_FINDER_H */