Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 1 | #ifndef _PROBE_FINDER_H |
| 2 | #define _PROBE_FINDER_H |
| 3 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 4 | #include <stdbool.h> |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 5 | #include "util.h" |
Masami Hiramatsu | 5a62257 | 2014-02-06 05:32:09 +0000 | [diff] [blame] | 6 | #include "intlist.h" |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 7 | #include "probe-event.h" |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 8 | |
Masami Hiramatsu | 27f3b24 | 2009-12-16 17:16:19 -0500 | [diff] [blame] | 9 | #define MAX_PROBE_BUFFER 1024 |
| 10 | #define MAX_PROBES 128 |
Masami Hiramatsu | 7969ec7 | 2013-10-11 16:10:23 +0900 | [diff] [blame] | 11 | #define MAX_PROBE_ARGS 128 |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 12 | |
Masami Hiramatsu | f8bffbf | 2015-05-06 21:46:53 +0900 | [diff] [blame] | 13 | #define PROBE_ARG_VARS "$vars" |
| 14 | #define PROBE_ARG_PARAMS "$params" |
| 15 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 16 | static inline int is_c_varname(const char *name) |
| 17 | { |
| 18 | /* TODO */ |
| 19 | return isalpha(name[0]) || name[0] == '_'; |
| 20 | } |
| 21 | |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 22 | #ifdef HAVE_DWARF_SUPPORT |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 23 | |
| 24 | #include "dwarf-aux.h" |
| 25 | |
| 26 | /* TODO: export debuginfo data structure even if no dwarf support */ |
| 27 | |
| 28 | /* debug information structure */ |
| 29 | struct debuginfo { |
| 30 | Dwarf *dbg; |
Masami Hiramatsu | 576b523 | 2013-09-25 22:16:16 +0900 | [diff] [blame] | 31 | Dwfl_Module *mod; |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 32 | Dwfl *dwfl; |
| 33 | Dwarf_Addr bias; |
| 34 | }; |
| 35 | |
Masami Hiramatsu | a15ad2f | 2014-02-06 05:32:27 +0000 | [diff] [blame] | 36 | /* This also tries to open distro debuginfo */ |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 37 | extern struct debuginfo *debuginfo__new(const char *path); |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 38 | extern void debuginfo__delete(struct debuginfo *dbg); |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 39 | |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 40 | /* Find probe_trace_events specified by perf_probe_event from debuginfo */ |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 41 | extern int debuginfo__find_trace_events(struct debuginfo *dbg, |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 42 | struct perf_probe_event *pev, |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 43 | struct probe_trace_event **tevs); |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 44 | |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 45 | /* Find a perf_probe_point from debuginfo */ |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 46 | extern int debuginfo__find_probe_point(struct debuginfo *dbg, |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 47 | unsigned long addr, |
| 48 | struct perf_probe_point *ppt); |
Masami Hiramatsu | fb1587d | 2010-03-16 18:06:19 -0400 | [diff] [blame] | 49 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 50 | /* Find a line range */ |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 51 | extern int debuginfo__find_line_range(struct debuginfo *dbg, |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 52 | struct line_range *lr); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 53 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 54 | /* Find available variables */ |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 55 | extern int debuginfo__find_available_vars_at(struct debuginfo *dbg, |
Masami Hiramatsu | ff74178 | 2011-06-27 16:27:39 +0900 | [diff] [blame] | 56 | struct perf_probe_event *pev, |
Masami Hiramatsu | ddb2f58 | 2015-05-08 10:03:31 +0900 | [diff] [blame] | 57 | struct variable_list **vls); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 58 | |
Naohiro Aota | 09ed897 | 2015-03-13 14:18:40 +0900 | [diff] [blame] | 59 | /* Find a src file from a DWARF tag path */ |
| 60 | int get_real_path(const char *raw_path, const char *comp_dir, |
| 61 | char **new_path); |
| 62 | |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 63 | struct probe_finder { |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 64 | struct perf_probe_event *pev; /* Target probe event */ |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 65 | |
| 66 | /* Callback when a probe point is found */ |
Masami Hiramatsu | 221d061 | 2011-08-11 20:02:59 +0900 | [diff] [blame] | 67 | int (*callback)(Dwarf_Die *sc_die, struct probe_finder *pf); |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 68 | |
| 69 | /* For function searching */ |
Arnaldo Carvalho de Melo | eed05fe | 2010-04-05 12:53:45 -0300 | [diff] [blame] | 70 | int lno; /* Line number */ |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 71 | Dwarf_Addr addr; /* Address */ |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 72 | const char *fname; /* Real file name */ |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 73 | Dwarf_Die cu_die; /* Current CU */ |
Lin Ming | cd25f8b | 2011-03-25 16:27:48 +0800 | [diff] [blame] | 74 | Dwarf_Die sp_die; |
Masami Hiramatsu | 5a62257 | 2014-02-06 05:32:09 +0000 | [diff] [blame] | 75 | struct intlist *lcache; /* Line cache for lazy match */ |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 76 | |
| 77 | /* For variable searching */ |
Masami Hiramatsu | 7752f1b | 2010-05-10 13:12:07 -0400 | [diff] [blame] | 78 | #if _ELFUTILS_PREREQ(0, 142) |
Hemant Kumar | 270bde1 | 2016-02-02 20:56:46 +0530 | [diff] [blame^] | 79 | /* Call Frame Information from .eh_frame */ |
| 80 | Dwarf_CFI *cfi_eh; |
| 81 | /* Call Frame Information from .debug_frame */ |
| 82 | Dwarf_CFI *cfi_dbg; |
Masami Hiramatsu | 7752f1b | 2010-05-10 13:12:07 -0400 | [diff] [blame] | 83 | #endif |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 84 | Dwarf_Op *fb_ops; /* Frame base attribute */ |
Masami Hiramatsu | 4235b04 | 2010-03-16 18:06:12 -0400 | [diff] [blame] | 85 | struct perf_probe_arg *pvar; /* Current target variable */ |
Srikar Dronamraju | 0e60836 | 2010-07-29 19:43:51 +0530 | [diff] [blame] | 86 | struct probe_trace_arg *tvar; /* Current result variable */ |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 87 | }; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 88 | |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 89 | struct trace_event_finder { |
| 90 | struct probe_finder pf; |
Masami Hiramatsu | 576b523 | 2013-09-25 22:16:16 +0900 | [diff] [blame] | 91 | Dwfl_Module *mod; /* For solving symbols */ |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 92 | struct probe_trace_event *tevs; /* Found trace events */ |
| 93 | int ntevs; /* Number of trace events */ |
| 94 | int max_tevs; /* Max number of trace events */ |
| 95 | }; |
| 96 | |
| 97 | struct available_var_finder { |
| 98 | struct probe_finder pf; |
Masami Hiramatsu | 576b523 | 2013-09-25 22:16:16 +0900 | [diff] [blame] | 99 | Dwfl_Module *mod; /* For solving symbols */ |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 100 | struct variable_list *vls; /* Found variable lists */ |
| 101 | int nvls; /* Number of variable lists */ |
| 102 | int max_vls; /* Max no. of variable lists */ |
Masami Hiramatsu | fb8c5a5 | 2010-10-21 19:13:35 +0900 | [diff] [blame] | 103 | bool child; /* Search child scopes */ |
Masami Hiramatsu | cf6eb48 | 2010-10-21 19:13:23 +0900 | [diff] [blame] | 104 | }; |
| 105 | |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 106 | struct line_finder { |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 107 | struct line_range *lr; /* Target line range */ |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 108 | |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 109 | const char *fname; /* File name */ |
| 110 | int lno_s; /* Start line number */ |
| 111 | int lno_e; /* End line number */ |
Masami Hiramatsu | 804b360 | 2010-02-25 08:35:42 -0500 | [diff] [blame] | 112 | Dwarf_Die cu_die; /* Current CU */ |
Lin Ming | cd25f8b | 2011-03-25 16:27:48 +0800 | [diff] [blame] | 113 | Dwarf_Die sp_die; |
Masami Hiramatsu | 631c9de | 2010-01-06 09:45:34 -0500 | [diff] [blame] | 114 | int found; |
| 115 | }; |
| 116 | |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 117 | #endif /* HAVE_DWARF_SUPPORT */ |
Masami Hiramatsu | 4ea42b1 | 2009-10-08 17:17:38 -0400 | [diff] [blame] | 118 | |
| 119 | #endif /*_PROBE_FINDER_H */ |