blob: 51137fccb9c81abf96f2fc0559437f552f6254f6 [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
Masami Hiramatsuf8bffbf2015-05-06 21:46:53 +090013#define PROBE_ARG_VARS "$vars"
14#define PROBE_ARG_PARAMS "$params"
15
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040016static inline int is_c_varname(const char *name)
17{
18 /* TODO */
19 return isalpha(name[0]) || name[0] == '_';
20}
21
Ingo Molnar89fe8082013-09-30 12:07:11 +020022#ifdef HAVE_DWARF_SUPPORT
Masami Hiramatsuff741782011-06-27 16:27:39 +090023
24#include "dwarf-aux.h"
25
26/* TODO: export debuginfo data structure even if no dwarf support */
27
28/* debug information structure */
29struct debuginfo {
30 Dwarf *dbg;
Masami Hiramatsu576b5232013-09-25 22:16:16 +090031 Dwfl_Module *mod;
Masami Hiramatsuff741782011-06-27 16:27:39 +090032 Dwfl *dwfl;
33 Dwarf_Addr bias;
34};
35
Masami Hiramatsua15ad2f2014-02-06 05:32:27 +000036/* This also tries to open distro debuginfo */
Arnaldo Carvalho de Melo3938bad2016-03-23 15:06:35 -030037struct debuginfo *debuginfo__new(const char *path);
38void debuginfo__delete(struct debuginfo *dbg);
Masami Hiramatsuff741782011-06-27 16:27:39 +090039
Srikar Dronamraju0e608362010-07-29 19:43:51 +053040/* Find probe_trace_events specified by perf_probe_event from debuginfo */
Arnaldo Carvalho de Melo3938bad2016-03-23 15:06:35 -030041int debuginfo__find_trace_events(struct debuginfo *dbg,
42 struct perf_probe_event *pev,
43 struct probe_trace_event **tevs);
Masami Hiramatsu4235b042010-03-16 18:06:12 -040044
Masami Hiramatsufb1587d2010-03-16 18:06:19 -040045/* Find a perf_probe_point from debuginfo */
Arnaldo Carvalho de Melo3938bad2016-03-23 15:06:35 -030046int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr,
47 struct perf_probe_point *ppt);
Masami Hiramatsufb1587d2010-03-16 18:06:19 -040048
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090049/* Find a line range */
Arnaldo Carvalho de Melo3938bad2016-03-23 15:06:35 -030050int debuginfo__find_line_range(struct debuginfo *dbg, 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 Melo3938bad2016-03-23 15:06:35 -030053int debuginfo__find_available_vars_at(struct debuginfo *dbg,
54 struct perf_probe_event *pev,
55 struct variable_list **vls);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040056
Naohiro Aota09ed8972015-03-13 14:18:40 +090057/* Find a src file from a DWARF tag path */
58int get_real_path(const char *raw_path, const char *comp_dir,
59 char **new_path);
60
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040061struct probe_finder {
Masami Hiramatsu4235b042010-03-16 18:06:12 -040062 struct perf_probe_event *pev; /* Target probe event */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090063
64 /* Callback when a probe point is found */
Masami Hiramatsu221d0612011-08-11 20:02:59 +090065 int (*callback)(Dwarf_Die *sc_die, struct probe_finder *pf);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040066
67 /* For function searching */
Arnaldo Carvalho de Meloeed05fe2010-04-05 12:53:45 -030068 int lno; /* Line number */
Masami Hiramatsu804b3602010-02-25 08:35:42 -050069 Dwarf_Addr addr; /* Address */
Masami Hiramatsu4235b042010-03-16 18:06:12 -040070 const char *fname; /* Real file name */
Masami Hiramatsu804b3602010-02-25 08:35:42 -050071 Dwarf_Die cu_die; /* Current CU */
Lin Mingcd25f8b2011-03-25 16:27:48 +080072 Dwarf_Die sp_die;
Masami Hiramatsu5a622572014-02-06 05:32:09 +000073 struct intlist *lcache; /* Line cache for lazy match */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040074
75 /* For variable searching */
Masami Hiramatsu7752f1b2010-05-10 13:12:07 -040076#if _ELFUTILS_PREREQ(0, 142)
Hemant Kumar270bde12016-02-02 20:56:46 +053077 /* Call Frame Information from .eh_frame */
78 Dwarf_CFI *cfi_eh;
79 /* Call Frame Information from .debug_frame */
80 Dwarf_CFI *cfi_dbg;
Masami Hiramatsu7752f1b2010-05-10 13:12:07 -040081#endif
Masami Hiramatsu804b3602010-02-25 08:35:42 -050082 Dwarf_Op *fb_ops; /* Frame base attribute */
Masami Hiramatsu4235b042010-03-16 18:06:12 -040083 struct perf_probe_arg *pvar; /* Current target variable */
Srikar Dronamraju0e608362010-07-29 19:43:51 +053084 struct probe_trace_arg *tvar; /* Current result variable */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040085};
Masami Hiramatsu631c9de2010-01-06 09:45:34 -050086
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090087struct trace_event_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 probe_trace_event *tevs; /* Found trace events */
91 int ntevs; /* Number of trace events */
92 int max_tevs; /* Max number of trace events */
93};
94
95struct available_var_finder {
96 struct probe_finder pf;
Masami Hiramatsu576b5232013-09-25 22:16:16 +090097 Dwfl_Module *mod; /* For solving symbols */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090098 struct variable_list *vls; /* Found variable lists */
99 int nvls; /* Number of variable lists */
100 int max_vls; /* Max no. of variable lists */
Masami Hiramatsufb8c5a52010-10-21 19:13:35 +0900101 bool child; /* Search child scopes */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900102};
103
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500104struct line_finder {
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500105 struct line_range *lr; /* Target line range */
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500106
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500107 const char *fname; /* File name */
108 int lno_s; /* Start line number */
109 int lno_e; /* End line number */
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500110 Dwarf_Die cu_die; /* Current CU */
Lin Mingcd25f8b2011-03-25 16:27:48 +0800111 Dwarf_Die sp_die;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500112 int found;
113};
114
Ingo Molnar89fe8082013-09-30 12:07:11 +0200115#endif /* HAVE_DWARF_SUPPORT */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400116
117#endif /*_PROBE_FINDER_H */