blob: ebf8c8c814531ff4efaf5a7461c2ef6a7414df69 [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 Hiramatsu5a622572014-02-06 05:32:09 +00006#include "intlist.h"
Masami Hiramatsu4235b042010-03-16 18:06:12 -04007#include "probe-event.h"
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -02008
Masami Hiramatsu27f3b242009-12-16 17:16:19 -05009#define MAX_PROBE_BUFFER 1024
10#define MAX_PROBES 128
Masami Hiramatsu7969ec72013-10-11 16:10:23 +090011#define MAX_PROBE_ARGS 128
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040012
13static inline int is_c_varname(const char *name)
14{
15 /* TODO */
16 return isalpha(name[0]) || name[0] == '_';
17}
18
Ingo Molnar89fe8082013-09-30 12:07:11 +020019#ifdef HAVE_DWARF_SUPPORT
Masami Hiramatsuff741782011-06-27 16:27:39 +090020
21#include "dwarf-aux.h"
22
23/* TODO: export debuginfo data structure even if no dwarf support */
24
25/* debug information structure */
26struct debuginfo {
27 Dwarf *dbg;
Masami Hiramatsu576b5232013-09-25 22:16:16 +090028 Dwfl_Module *mod;
Masami Hiramatsuff741782011-06-27 16:27:39 +090029 Dwfl *dwfl;
30 Dwarf_Addr bias;
31};
32
Masami Hiramatsua15ad2f2014-02-06 05:32:27 +000033/* This also tries to open distro debuginfo */
Masami Hiramatsuff741782011-06-27 16:27:39 +090034extern struct debuginfo *debuginfo__new(const char *path);
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030035extern void debuginfo__delete(struct debuginfo *dbg);
Masami Hiramatsuff741782011-06-27 16:27:39 +090036
Srikar Dronamraju0e608362010-07-29 19:43:51 +053037/* Find probe_trace_events specified by perf_probe_event from debuginfo */
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030038extern int debuginfo__find_trace_events(struct debuginfo *dbg,
Masami Hiramatsuff741782011-06-27 16:27:39 +090039 struct perf_probe_event *pev,
40 struct probe_trace_event **tevs,
41 int max_tevs);
Masami Hiramatsu4235b042010-03-16 18:06:12 -040042
Masami Hiramatsufb1587d2010-03-16 18:06:19 -040043/* Find a perf_probe_point from debuginfo */
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030044extern int debuginfo__find_probe_point(struct debuginfo *dbg,
Masami Hiramatsuff741782011-06-27 16:27:39 +090045 unsigned long addr,
46 struct perf_probe_point *ppt);
Masami Hiramatsufb1587d2010-03-16 18:06:19 -040047
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090048/* Find a line range */
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030049extern int debuginfo__find_line_range(struct debuginfo *dbg,
Masami Hiramatsuff741782011-06-27 16:27:39 +090050 struct line_range *lr);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040051
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090052/* Find available variables */
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030053extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,
Masami Hiramatsuff741782011-06-27 16:27:39 +090054 struct perf_probe_event *pev,
55 struct variable_list **vls,
56 int max_points, bool externs);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040057
Naohiro Aota09ed8972015-03-13 14:18:40 +090058/* Find a src file from a DWARF tag path */
59int get_real_path(const char *raw_path, const char *comp_dir,
60 char **new_path);
61
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040062struct probe_finder {
Masami Hiramatsu4235b042010-03-16 18:06:12 -040063 struct perf_probe_event *pev; /* Target probe event */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090064
65 /* Callback when a probe point is found */
Masami Hiramatsu221d0612011-08-11 20:02:59 +090066 int (*callback)(Dwarf_Die *sc_die, struct probe_finder *pf);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040067
68 /* For function searching */
Arnaldo Carvalho de Meloeed05fe2010-04-05 12:53:45 -030069 int lno; /* Line number */
Masami Hiramatsu804b3602010-02-25 08:35:42 -050070 Dwarf_Addr addr; /* Address */
Masami Hiramatsu4235b042010-03-16 18:06:12 -040071 const char *fname; /* Real file name */
Masami Hiramatsu804b3602010-02-25 08:35:42 -050072 Dwarf_Die cu_die; /* Current CU */
Lin Mingcd25f8b2011-03-25 16:27:48 +080073 Dwarf_Die sp_die;
Masami Hiramatsu5a622572014-02-06 05:32:09 +000074 struct intlist *lcache; /* Line cache for lazy match */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040075
76 /* For variable searching */
Masami Hiramatsu7752f1b2010-05-10 13:12:07 -040077#if _ELFUTILS_PREREQ(0, 142)
Masami Hiramatsua34a9852010-04-12 13:17:29 -040078 Dwarf_CFI *cfi; /* Call Frame Information */
Masami Hiramatsu7752f1b2010-05-10 13:12:07 -040079#endif
Masami Hiramatsu804b3602010-02-25 08:35:42 -050080 Dwarf_Op *fb_ops; /* Frame base attribute */
Masami Hiramatsu4235b042010-03-16 18:06:12 -040081 struct perf_probe_arg *pvar; /* Current target variable */
Srikar Dronamraju0e608362010-07-29 19:43:51 +053082 struct probe_trace_arg *tvar; /* Current result variable */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040083};
Masami Hiramatsu631c9de2010-01-06 09:45:34 -050084
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090085struct trace_event_finder {
86 struct probe_finder pf;
Masami Hiramatsu576b5232013-09-25 22:16:16 +090087 Dwfl_Module *mod; /* For solving symbols */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090088 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
93struct available_var_finder {
94 struct probe_finder pf;
Masami Hiramatsu576b5232013-09-25 22:16:16 +090095 Dwfl_Module *mod; /* For solving symbols */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090096 struct variable_list *vls; /* Found variable lists */
97 int nvls; /* Number of variable lists */
98 int max_vls; /* Max no. of variable lists */
Masami Hiramatsufb8c5a52010-10-21 19:13:35 +090099 bool externs; /* Find external vars too */
100 bool child; /* Search child scopes */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900101};
102
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500103struct line_finder {
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500104 struct line_range *lr; /* Target line range */
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500105
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500106 const char *fname; /* File name */
107 int lno_s; /* Start line number */
108 int lno_e; /* End line number */
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500109 Dwarf_Die cu_die; /* Current CU */
Lin Mingcd25f8b2011-03-25 16:27:48 +0800110 Dwarf_Die sp_die;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500111 int found;
112};
113
Ingo Molnar89fe8082013-09-30 12:07:11 +0200114#endif /* HAVE_DWARF_SUPPORT */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400115
116#endif /*_PROBE_FINDER_H */