blob: 670c477bf8cf3966f0de238633b759e02aeaffe4 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -04002#ifndef _PROBE_FINDER_H
3#define _PROBE_FINDER_H
4
Masami Hiramatsu804b3602010-02-25 08:35:42 -05005#include <stdbool.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 Melo3052ba52019-06-25 17:27:31 -03008#include <linux/ctype.h>
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -02009
Masami Hiramatsu27f3b242009-12-16 17:16:19 -050010#define MAX_PROBE_BUFFER 1024
11#define MAX_PROBES 128
Masami Hiramatsu7969ec72013-10-11 16:10:23 +090012#define MAX_PROBE_ARGS 128
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040013
Masami Hiramatsuf8bffbf2015-05-06 21:46:53 +090014#define PROBE_ARG_VARS "$vars"
15#define PROBE_ARG_PARAMS "$params"
16
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040017static inline int is_c_varname(const char *name)
18{
19 /* TODO */
20 return isalpha(name[0]) || name[0] == '_';
21}
22
Ingo Molnar89fe8082013-09-30 12:07:11 +020023#ifdef HAVE_DWARF_SUPPORT
Masami Hiramatsuff741782011-06-27 16:27:39 +090024
25#include "dwarf-aux.h"
26
27/* TODO: export debuginfo data structure even if no dwarf support */
28
29/* debug information structure */
30struct debuginfo {
31 Dwarf *dbg;
Masami Hiramatsu576b5232013-09-25 22:16:16 +090032 Dwfl_Module *mod;
Masami Hiramatsuff741782011-06-27 16:27:39 +090033 Dwfl *dwfl;
34 Dwarf_Addr bias;
35};
36
Masami Hiramatsua15ad2f2014-02-06 05:32:27 +000037/* This also tries to open distro debuginfo */
Arnaldo Carvalho de Melo3938bad2016-03-23 15:06:35 -030038struct debuginfo *debuginfo__new(const char *path);
39void debuginfo__delete(struct debuginfo *dbg);
Masami Hiramatsuff741782011-06-27 16:27:39 +090040
Srikar Dronamraju0e608362010-07-29 19:43:51 +053041/* Find probe_trace_events specified by perf_probe_event from debuginfo */
Arnaldo Carvalho de Melo3938bad2016-03-23 15:06:35 -030042int debuginfo__find_trace_events(struct debuginfo *dbg,
43 struct perf_probe_event *pev,
44 struct probe_trace_event **tevs);
Masami Hiramatsu4235b042010-03-16 18:06:12 -040045
Masami Hiramatsufb1587d2010-03-16 18:06:19 -040046/* Find a perf_probe_point from debuginfo */
Arnaldo Carvalho de Melo3938bad2016-03-23 15:06:35 -030047int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr,
48 struct perf_probe_point *ppt);
Masami Hiramatsufb1587d2010-03-16 18:06:19 -040049
Masami Hiramatsu613f0502017-01-11 15:01:57 +090050int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs,
51 bool adjust_offset);
52
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090053/* Find a line range */
Arnaldo Carvalho de Melo3938bad2016-03-23 15:06:35 -030054int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040055
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090056/* Find available variables */
Arnaldo Carvalho de Melo3938bad2016-03-23 15:06:35 -030057int debuginfo__find_available_vars_at(struct debuginfo *dbg,
58 struct perf_probe_event *pev,
59 struct variable_list **vls);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040060
Naohiro Aota09ed8972015-03-13 14:18:40 +090061/* Find a src file from a DWARF tag path */
62int get_real_path(const char *raw_path, const char *comp_dir,
63 char **new_path);
64
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040065struct probe_finder {
Masami Hiramatsu4235b042010-03-16 18:06:12 -040066 struct perf_probe_event *pev; /* Target probe event */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090067
68 /* Callback when a probe point is found */
Masami Hiramatsu221d0612011-08-11 20:02:59 +090069 int (*callback)(Dwarf_Die *sc_die, struct probe_finder *pf);
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040070
71 /* For function searching */
Arnaldo Carvalho de Meloeed05fe2010-04-05 12:53:45 -030072 int lno; /* Line number */
Masami Hiramatsu804b3602010-02-25 08:35:42 -050073 Dwarf_Addr addr; /* Address */
Masami Hiramatsu4235b042010-03-16 18:06:12 -040074 const char *fname; /* Real file name */
Masami Hiramatsu804b3602010-02-25 08:35:42 -050075 Dwarf_Die cu_die; /* Current CU */
Lin Mingcd25f8b2011-03-25 16:27:48 +080076 Dwarf_Die sp_die;
Masami Hiramatsu5a622572014-02-06 05:32:09 +000077 struct intlist *lcache; /* Line cache for lazy match */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040078
79 /* For variable searching */
Masami Hiramatsu7752f1b2010-05-10 13:12:07 -040080#if _ELFUTILS_PREREQ(0, 142)
Hemant Kumar270bde12016-02-02 20:56:46 +053081 /* Call Frame Information from .eh_frame */
82 Dwarf_CFI *cfi_eh;
83 /* Call Frame Information from .debug_frame */
84 Dwarf_CFI *cfi_dbg;
Masami Hiramatsu7752f1b2010-05-10 13:12:07 -040085#endif
Masami Hiramatsu804b3602010-02-25 08:35:42 -050086 Dwarf_Op *fb_ops; /* Frame base attribute */
Masami Hiramatsu293d5b42016-08-26 01:24:57 +090087 unsigned int machine; /* Target machine arch */
Masami Hiramatsu4235b042010-03-16 18:06:12 -040088 struct perf_probe_arg *pvar; /* Current target variable */
Srikar Dronamraju0e608362010-07-29 19:43:51 +053089 struct probe_trace_arg *tvar; /* Current result variable */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040090};
Masami Hiramatsu631c9de2010-01-06 09:45:34 -050091
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090092struct trace_event_finder {
93 struct probe_finder pf;
Masami Hiramatsu576b5232013-09-25 22:16:16 +090094 Dwfl_Module *mod; /* For solving symbols */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090095 struct probe_trace_event *tevs; /* Found trace events */
96 int ntevs; /* Number of trace events */
97 int max_tevs; /* Max number of trace events */
98};
99
100struct available_var_finder {
101 struct probe_finder pf;
Masami Hiramatsu576b5232013-09-25 22:16:16 +0900102 Dwfl_Module *mod; /* For solving symbols */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900103 struct variable_list *vls; /* Found variable lists */
104 int nvls; /* Number of variable lists */
105 int max_vls; /* Max no. of variable lists */
Masami Hiramatsufb8c5a52010-10-21 19:13:35 +0900106 bool child; /* Search child scopes */
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900107};
108
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500109struct line_finder {
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500110 struct line_range *lr; /* Target line range */
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500111
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500112 const char *fname; /* File name */
113 int lno_s; /* Start line number */
114 int lno_e; /* End line number */
Masami Hiramatsu804b3602010-02-25 08:35:42 -0500115 Dwarf_Die cu_die; /* Current CU */
Lin Mingcd25f8b2011-03-25 16:27:48 +0800116 Dwarf_Die sp_die;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500117 int found;
118};
119
Ingo Molnar89fe8082013-09-30 12:07:11 +0200120#endif /* HAVE_DWARF_SUPPORT */
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400121
122#endif /*_PROBE_FINDER_H */