Commit | Line | Data |
---|---|---|
55aa24fb SDJ |
1 | /* Generic SDT probe support for GDB. |
2 | ||
61baf725 | 3 | Copyright (C) 2012-2017 Free Software Foundation, Inc. |
55aa24fb SDJ |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #if !defined (PROBE_H) | |
21 | #define PROBE_H 1 | |
22 | ||
f00aae0f KS |
23 | struct event_location; |
24 | ||
55aa24fb SDJ |
25 | #include "gdb_vecs.h" |
26 | ||
48faced0 DE |
27 | /* Definition of a vector of probes. */ |
28 | ||
29 | typedef struct probe *probe_p; | |
30 | DEF_VEC_P (probe_p); | |
31 | ||
55aa24fb SDJ |
32 | struct linespec_result; |
33 | ||
34 | /* Structure useful for passing the header names in the method | |
35 | `gen_ui_out_table_header'. */ | |
36 | ||
37 | struct info_probe_column | |
38 | { | |
39 | /* The internal name of the field. This string cannot be capitalized nor | |
40 | localized, e.g., "extra_field". */ | |
41 | ||
42 | const char *field_name; | |
43 | ||
44 | /* The field name to be printed in the `info probes' command. This | |
45 | string can be capitalized and localized, e.g., _("Extra Field"). */ | |
46 | const char *print_name; | |
47 | }; | |
48 | ||
49 | typedef struct info_probe_column info_probe_column_s; | |
50 | DEF_VEC_O (info_probe_column_s); | |
51 | ||
52 | /* Operations associated with a probe. */ | |
53 | ||
54 | struct probe_ops | |
55 | { | |
56 | /* Method responsible for verifying if LINESPECP is a valid linespec for | |
57 | a probe breakpoint. It should return 1 if it is, or zero if it is not. | |
58 | It also should update LINESPECP in order to discard the breakpoint | |
59 | option associated with this linespec. For example, if the option is | |
60 | `-probe', and the LINESPECP is `-probe abc', the function should | |
61 | return 1 and set LINESPECP to `abc'. */ | |
62 | ||
63 | int (*is_linespec) (const char **linespecp); | |
64 | ||
65 | /* Function that should fill PROBES with known probes from OBJFILE. */ | |
66 | ||
aaa63a31 | 67 | void (*get_probes) (std::vector<probe *> *probes, struct objfile *objfile); |
55aa24fb | 68 | |
729662a5 TT |
69 | /* Compute the probe's relocated address. OBJFILE is the objfile |
70 | in which the probe originated. */ | |
55aa24fb | 71 | |
729662a5 TT |
72 | CORE_ADDR (*get_probe_address) (struct probe *probe, |
73 | struct objfile *objfile); | |
55aa24fb | 74 | |
f469e8ce SDJ |
75 | /* Return the number of arguments of PROBE. This function can |
76 | throw an exception. */ | |
55aa24fb | 77 | |
08a6411c SDJ |
78 | unsigned (*get_probe_argument_count) (struct probe *probe, |
79 | struct frame_info *frame); | |
55aa24fb | 80 | |
25f9533e SDJ |
81 | /* Return 1 if the probe interface can evaluate the arguments of probe |
82 | PROBE, zero otherwise. See the comments on | |
83 | sym_probe_fns:can_evaluate_probe_arguments for more details. */ | |
84 | ||
85 | int (*can_evaluate_probe_arguments) (struct probe *probe); | |
86 | ||
55aa24fb | 87 | /* Evaluate the Nth argument from the PROBE, returning a value |
f469e8ce SDJ |
88 | corresponding to it. The argument number is represented N. |
89 | This function can throw an exception. */ | |
55aa24fb SDJ |
90 | |
91 | struct value *(*evaluate_probe_argument) (struct probe *probe, | |
08a6411c SDJ |
92 | unsigned n, |
93 | struct frame_info *frame); | |
55aa24fb SDJ |
94 | |
95 | /* Compile the Nth argument of the PROBE to an agent expression. | |
96 | The argument number is represented by N. */ | |
97 | ||
6bac7473 | 98 | void (*compile_to_ax) (struct probe *probe, struct agent_expr *aexpr, |
55aa24fb SDJ |
99 | struct axs_value *axs_value, unsigned n); |
100 | ||
101 | /* Set the semaphore associated with the PROBE. This function only makes | |
102 | sense if the probe has a concept of semaphore associated to a | |
0ea5cda8 | 103 | probe, otherwise it can be set to NULL. */ |
55aa24fb | 104 | |
729662a5 TT |
105 | void (*set_semaphore) (struct probe *probe, struct objfile *objfile, |
106 | struct gdbarch *gdbarch); | |
55aa24fb SDJ |
107 | |
108 | /* Clear the semaphore associated with the PROBE. This function only | |
109 | makes sense if the probe has a concept of semaphore associated to | |
0ea5cda8 | 110 | a probe, otherwise it can be set to NULL. */ |
55aa24fb | 111 | |
729662a5 TT |
112 | void (*clear_semaphore) (struct probe *probe, struct objfile *objfile, |
113 | struct gdbarch *gdbarch); | |
55aa24fb SDJ |
114 | |
115 | /* Function called to destroy PROBE's specific data. This function | |
116 | shall not free PROBE itself. */ | |
117 | ||
118 | void (*destroy) (struct probe *probe); | |
119 | ||
6f9b8491 JM |
120 | /* Return a pointer to a name identifying the probe type. This is |
121 | the string that will be displayed in the "Type" column of the | |
122 | `info probes' command. */ | |
123 | ||
124 | const char *(*type_name) (struct probe *probe); | |
125 | ||
55aa24fb SDJ |
126 | /* Function responsible for providing the extra fields that will be |
127 | printed in the `info probes' command. It should fill HEADS | |
128 | with whatever extra fields it needs. If the backend doesn't need | |
129 | to print extra fields, it can set this method to NULL. */ | |
130 | ||
131 | void (*gen_info_probes_table_header) (VEC (info_probe_column_s) **heads); | |
132 | ||
133 | /* Function that will fill VALUES with the values of the extra fields | |
6bac7473 SDJ |
134 | to be printed for PROBE. If the backend implements the |
135 | `gen_ui_out_table_header' method, then it should implement | |
55aa24fb SDJ |
136 | this method as well. The backend should also guarantee that the |
137 | order and the number of values in the vector is exactly the same | |
138 | as the order of the extra fields provided in the method | |
139 | `gen_ui_out_table_header'. If a certain field is to be skipped | |
140 | when printing the information, you can push a NULL value in that | |
141 | position in the vector. */ | |
142 | ||
143 | void (*gen_info_probes_table_values) (struct probe *probe, | |
55aa24fb | 144 | VEC (const_char_ptr) **values); |
9aca2ff8 JM |
145 | |
146 | /* Enable a probe. The semantics of "enabling" a probe depend on | |
147 | the specific backend and the field can be NULL in case enabling | |
f469e8ce SDJ |
148 | probes is not supported. This function can throw an |
149 | exception. */ | |
9aca2ff8 JM |
150 | |
151 | void (*enable_probe) (struct probe *probe); | |
152 | ||
153 | /* Disable a probe. The semantics of "disabling" a probe depend | |
154 | on the specific backend and the field can be NULL in case | |
f469e8ce SDJ |
155 | disabling probes is not supported. This function can throw an |
156 | exception. */ | |
9aca2ff8 JM |
157 | |
158 | void (*disable_probe) (struct probe *probe); | |
55aa24fb SDJ |
159 | }; |
160 | ||
161 | /* Definition of a vector of probe_ops. */ | |
162 | ||
0782db84 | 163 | extern std::vector<const probe_ops *> all_probe_ops; |
55aa24fb SDJ |
164 | |
165 | /* The probe_ops associated with the generic probe. */ | |
166 | ||
167 | extern const struct probe_ops probe_ops_any; | |
168 | ||
169 | /* Helper function that, given KEYWORDS, iterate over it trying to match | |
170 | each keyword with LINESPECP. If it succeeds, it updates the LINESPECP | |
171 | pointer and returns 1. Otherwise, nothing is done to LINESPECP and zero | |
172 | is returned. */ | |
173 | ||
174 | extern int probe_is_linespec_by_keyword (const char **linespecp, | |
175 | const char *const *keywords); | |
176 | ||
177 | /* Return specific PROBE_OPS * matching *LINESPECP and possibly updating | |
178 | *LINESPECP to skip its "-probe-type " prefix. Return &probe_ops_any if | |
179 | *LINESPECP matches "-probe ", that is any unspecific probe. Return NULL if | |
180 | *LINESPECP is not identified as any known probe type, *LINESPECP is not | |
181 | modified in such case. */ | |
182 | ||
183 | extern const struct probe_ops *probe_linespec_to_ops (const char **linespecp); | |
184 | ||
185 | /* The probe itself. The struct contains generic information about the | |
186 | probe, and then some specific information which should be stored in | |
187 | the `probe_info' field. */ | |
188 | ||
189 | struct probe | |
190 | { | |
191 | /* The operations associated with this probe. */ | |
192 | const struct probe_ops *pops; | |
193 | ||
729662a5 TT |
194 | /* The probe's architecture. */ |
195 | struct gdbarch *arch; | |
6bac7473 | 196 | |
55aa24fb SDJ |
197 | /* The name of the probe. */ |
198 | const char *name; | |
199 | ||
200 | /* The provider of the probe. It generally defaults to the name of | |
201 | the objfile which contains the probe. */ | |
202 | const char *provider; | |
203 | ||
729662a5 TT |
204 | /* The address where the probe is inserted, relative to |
205 | SECT_OFF_TEXT. */ | |
55aa24fb SDJ |
206 | CORE_ADDR address; |
207 | }; | |
208 | ||
729662a5 TT |
209 | /* A bound probe holds a pointer to a probe and a pointer to the |
210 | probe's defining objfile. This is needed because probes are | |
211 | independent of the program space and thus require relocation at | |
212 | their point of use. */ | |
213 | ||
214 | struct bound_probe | |
1eac6bea SM |
215 | { |
216 | /* Create an empty bound_probe object. */ | |
729662a5 | 217 | |
1eac6bea SM |
218 | bound_probe () |
219 | {} | |
729662a5 | 220 | |
1eac6bea | 221 | /* Create and initialize a bound_probe object using PROBE and OBJFILE. */ |
729662a5 | 222 | |
1eac6bea SM |
223 | bound_probe (struct probe *probe_, struct objfile *objfile_) |
224 | : probe (probe_), objfile (objfile_) | |
225 | {} | |
226 | ||
227 | /* The probe. */ | |
228 | ||
229 | struct probe *probe = NULL; | |
230 | ||
231 | /* The objfile in which the probe originated. */ | |
232 | ||
233 | struct objfile *objfile = NULL; | |
234 | }; | |
729662a5 | 235 | |
6c5b2ebe PA |
236 | /* A helper for linespec that decodes a probe specification. It |
237 | returns a std::vector<symtab_and_line> object and updates LOC or | |
238 | throws an error. */ | |
239 | ||
240 | extern std::vector<symtab_and_line> parse_probes | |
241 | (const struct event_location *loc, | |
242 | struct program_space *pspace, | |
243 | struct linespec_result *canon); | |
55aa24fb SDJ |
244 | |
245 | /* Helper function to register the proper probe_ops to a newly created probe. | |
246 | This function is mainly called from `sym_get_probes'. */ | |
247 | ||
248 | extern void register_probe_ops (struct probe *probe); | |
249 | ||
ff887920 | 250 | /* Given a PC, find an associated probe. If a probe is found, return |
729662a5 TT |
251 | it. If no probe is found, return a bound probe whose fields are |
252 | both NULL. */ | |
55aa24fb | 253 | |
729662a5 | 254 | extern struct bound_probe find_probe_by_pc (CORE_ADDR pc); |
55aa24fb | 255 | |
ff887920 TT |
256 | /* Search OBJFILE for a probe with the given PROVIDER, NAME. Return a |
257 | VEC of all probes that were found. If no matching probe is found, | |
258 | return NULL. The caller must free the VEC. */ | |
55aa24fb SDJ |
259 | |
260 | extern VEC (probe_p) *find_probes_in_objfile (struct objfile *objfile, | |
261 | const char *provider, | |
262 | const char *name); | |
263 | ||
264 | /* Generate a `info probes' command output for probe_ops represented by | |
265 | POPS. If POPS is NULL it considers any probes types. It is a helper | |
266 | function that can be used by the probe backends to print their | |
267 | `info probe TYPE'. */ | |
268 | ||
8236def8 | 269 | extern void info_probes_for_ops (const char *arg, int from_tty, |
55aa24fb SDJ |
270 | const struct probe_ops *pops); |
271 | ||
272 | /* Return the `cmd_list_element' associated with the `info probes' command, | |
273 | or create a new one if it doesn't exist. Helper function that serves the | |
274 | purpose of avoiding the case of a backend using the `cmd_list_element' | |
275 | associated with `info probes', without having it registered yet. */ | |
276 | ||
277 | extern struct cmd_list_element **info_probes_cmdlist_get (void); | |
278 | ||
729662a5 TT |
279 | /* Compute the probe's relocated address. OBJFILE is the objfile in |
280 | which the probe originated. */ | |
281 | ||
282 | extern CORE_ADDR get_probe_address (struct probe *probe, | |
283 | struct objfile *objfile); | |
284 | ||
f469e8ce SDJ |
285 | /* Return the argument count of the specified probe. |
286 | ||
287 | This function can throw an exception. */ | |
9ee6a5ac | 288 | |
08a6411c SDJ |
289 | extern unsigned get_probe_argument_count (struct probe *probe, |
290 | struct frame_info *frame); | |
9ee6a5ac | 291 | |
25f9533e SDJ |
292 | /* Return 1 if the probe interface associated with PROBE can evaluate |
293 | arguments, zero otherwise. See the comments on the definition of | |
294 | sym_probe_fns:can_evaluate_probe_arguments for more details. */ | |
295 | ||
296 | extern int can_evaluate_probe_arguments (struct probe *probe); | |
297 | ||
9ee6a5ac | 298 | /* Evaluate argument N of the specified probe. N must be between 0 |
f469e8ce SDJ |
299 | inclusive and get_probe_argument_count exclusive. |
300 | ||
301 | This function can throw an exception. */ | |
9ee6a5ac GB |
302 | |
303 | extern struct value *evaluate_probe_argument (struct probe *probe, | |
08a6411c SDJ |
304 | unsigned n, |
305 | struct frame_info *frame); | |
9ee6a5ac | 306 | |
55aa24fb SDJ |
307 | /* A convenience function that finds a probe at the PC in FRAME and |
308 | evaluates argument N, with 0 <= N < number_of_args. If there is no | |
309 | probe at that location, or if the probe does not have enough arguments, | |
310 | this returns NULL. */ | |
311 | ||
312 | extern struct value *probe_safe_evaluate_at_pc (struct frame_info *frame, | |
313 | unsigned n); | |
314 | ||
315 | #endif /* !defined (PROBE_H) */ |