Commit | Line | Data |
---|---|---|
55aa24fb SDJ |
1 | /* Generic static probe support for GDB. |
2 | ||
32d0add0 | 3 | Copyright (C) 2012-2015 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 | #include "defs.h" | |
21 | #include "probe.h" | |
22 | #include "command.h" | |
23 | #include "cli/cli-cmds.h" | |
24 | #include "cli/cli-utils.h" | |
25 | #include "objfiles.h" | |
26 | #include "symtab.h" | |
27 | #include "progspace.h" | |
28 | #include "filenames.h" | |
55aa24fb SDJ |
29 | #include "linespec.h" |
30 | #include "gdb_regex.h" | |
31 | #include "frame.h" | |
32 | #include "arch-utils.h" | |
33 | #include <ctype.h> | |
34 | ||
729662a5 TT |
35 | typedef struct bound_probe bound_probe_s; |
36 | DEF_VEC_O (bound_probe_s); | |
37 | ||
55aa24fb SDJ |
38 | \f |
39 | ||
40 | /* See definition in probe.h. */ | |
41 | ||
42 | struct symtabs_and_lines | |
43 | parse_probes (char **argptr, struct linespec_result *canonical) | |
44 | { | |
45 | char *arg_start, *arg_end, *arg; | |
4721dc18 | 46 | char *objfile_namestr = NULL, *provider = NULL, *name, *p; |
55aa24fb SDJ |
47 | struct cleanup *cleanup; |
48 | struct symtabs_and_lines result; | |
49 | struct objfile *objfile; | |
50 | struct program_space *pspace; | |
51 | const struct probe_ops *probe_ops; | |
52 | const char *cs; | |
53 | ||
54 | result.sals = NULL; | |
55 | result.nelts = 0; | |
56 | ||
57 | arg_start = *argptr; | |
58 | ||
59 | cs = *argptr; | |
60 | probe_ops = probe_linespec_to_ops (&cs); | |
1bff71c3 SDJ |
61 | if (probe_ops == NULL) |
62 | error (_("'%s' is not a probe linespec"), arg_start); | |
55aa24fb SDJ |
63 | |
64 | arg = (char *) cs; | |
65 | arg = skip_spaces (arg); | |
66 | if (!*arg) | |
67 | error (_("argument to `%s' missing"), arg_start); | |
68 | ||
69 | arg_end = skip_to_space (arg); | |
70 | ||
71 | /* We make a copy here so we can write over parts with impunity. */ | |
72 | arg = savestring (arg, arg_end - arg); | |
73 | cleanup = make_cleanup (xfree, arg); | |
74 | ||
75 | /* Extract each word from the argument, separated by ":"s. */ | |
76 | p = strchr (arg, ':'); | |
77 | if (p == NULL) | |
78 | { | |
79 | /* This is `-p name'. */ | |
80 | name = arg; | |
81 | } | |
82 | else | |
83 | { | |
84 | char *hold = p + 1; | |
85 | ||
86 | *p = '\0'; | |
87 | p = strchr (hold, ':'); | |
88 | if (p == NULL) | |
89 | { | |
90 | /* This is `-p provider:name'. */ | |
91 | provider = arg; | |
92 | name = hold; | |
93 | } | |
94 | else | |
95 | { | |
96 | /* This is `-p objfile:provider:name'. */ | |
97 | *p = '\0'; | |
4721dc18 | 98 | objfile_namestr = arg; |
55aa24fb SDJ |
99 | provider = hold; |
100 | name = p + 1; | |
101 | } | |
102 | } | |
103 | ||
104 | if (*name == '\0') | |
105 | error (_("no probe name specified")); | |
106 | if (provider && *provider == '\0') | |
107 | error (_("invalid provider name")); | |
4721dc18 | 108 | if (objfile_namestr && *objfile_namestr == '\0') |
55aa24fb SDJ |
109 | error (_("invalid objfile name")); |
110 | ||
111 | ALL_PSPACES (pspace) | |
112 | ALL_PSPACE_OBJFILES (pspace, objfile) | |
113 | { | |
114 | VEC (probe_p) *probes; | |
115 | struct probe *probe; | |
116 | int ix; | |
117 | ||
118 | if (!objfile->sf || !objfile->sf->sym_probe_fns) | |
119 | continue; | |
120 | ||
4721dc18 | 121 | if (objfile_namestr |
4262abfb JK |
122 | && FILENAME_CMP (objfile_name (objfile), objfile_namestr) != 0 |
123 | && FILENAME_CMP (lbasename (objfile_name (objfile)), | |
124 | objfile_namestr) != 0) | |
55aa24fb SDJ |
125 | continue; |
126 | ||
55aa24fb SDJ |
127 | probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); |
128 | ||
129 | for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) | |
130 | { | |
131 | struct symtab_and_line *sal; | |
132 | ||
133 | if (probe_ops != &probe_ops_any && probe->pops != probe_ops) | |
134 | continue; | |
135 | ||
136 | if (provider && strcmp (probe->provider, provider) != 0) | |
137 | continue; | |
138 | ||
139 | if (strcmp (probe->name, name) != 0) | |
140 | continue; | |
141 | ||
142 | ++result.nelts; | |
143 | result.sals = xrealloc (result.sals, | |
144 | result.nelts | |
145 | * sizeof (struct symtab_and_line)); | |
146 | sal = &result.sals[result.nelts - 1]; | |
147 | ||
148 | init_sal (sal); | |
149 | ||
729662a5 | 150 | sal->pc = get_probe_address (probe, objfile); |
55aa24fb SDJ |
151 | sal->explicit_pc = 1; |
152 | sal->section = find_pc_overlay (sal->pc); | |
153 | sal->pspace = pspace; | |
154 | sal->probe = probe; | |
729662a5 | 155 | sal->objfile = objfile; |
55aa24fb SDJ |
156 | } |
157 | } | |
158 | ||
159 | if (result.nelts == 0) | |
160 | { | |
161 | throw_error (NOT_FOUND_ERROR, | |
162 | _("No probe matching objfile=`%s', provider=`%s', name=`%s'"), | |
4721dc18 | 163 | objfile_namestr ? objfile_namestr : _("<any>"), |
55aa24fb SDJ |
164 | provider ? provider : _("<any>"), |
165 | name); | |
166 | } | |
167 | ||
168 | if (canonical) | |
169 | { | |
170 | canonical->special_display = 1; | |
171 | canonical->pre_expanded = 1; | |
172 | canonical->addr_string = savestring (*argptr, arg_end - *argptr); | |
173 | } | |
174 | ||
175 | *argptr = arg_end; | |
176 | do_cleanups (cleanup); | |
177 | ||
178 | return result; | |
179 | } | |
180 | ||
181 | /* See definition in probe.h. */ | |
182 | ||
183 | VEC (probe_p) * | |
184 | find_probes_in_objfile (struct objfile *objfile, const char *provider, | |
185 | const char *name) | |
186 | { | |
187 | VEC (probe_p) *probes, *result = NULL; | |
188 | int ix; | |
189 | struct probe *probe; | |
190 | ||
191 | if (!objfile->sf || !objfile->sf->sym_probe_fns) | |
192 | return NULL; | |
193 | ||
194 | probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); | |
195 | for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) | |
196 | { | |
197 | if (strcmp (probe->provider, provider) != 0) | |
198 | continue; | |
199 | ||
200 | if (strcmp (probe->name, name) != 0) | |
201 | continue; | |
202 | ||
203 | VEC_safe_push (probe_p, result, probe); | |
204 | } | |
205 | ||
206 | return result; | |
207 | } | |
208 | ||
209 | /* See definition in probe.h. */ | |
210 | ||
729662a5 | 211 | struct bound_probe |
6bac7473 | 212 | find_probe_by_pc (CORE_ADDR pc) |
55aa24fb SDJ |
213 | { |
214 | struct objfile *objfile; | |
729662a5 TT |
215 | struct bound_probe result; |
216 | ||
217 | result.objfile = NULL; | |
218 | result.probe = NULL; | |
55aa24fb SDJ |
219 | |
220 | ALL_OBJFILES (objfile) | |
221 | { | |
222 | VEC (probe_p) *probes; | |
223 | int ix; | |
224 | struct probe *probe; | |
225 | ||
729662a5 TT |
226 | if (!objfile->sf || !objfile->sf->sym_probe_fns |
227 | || objfile->sect_index_text == -1) | |
55aa24fb SDJ |
228 | continue; |
229 | ||
230 | /* If this proves too inefficient, we can replace with a hash. */ | |
231 | probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); | |
232 | for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) | |
729662a5 TT |
233 | if (get_probe_address (probe, objfile) == pc) |
234 | { | |
235 | result.objfile = objfile; | |
236 | result.probe = probe; | |
237 | return result; | |
238 | } | |
55aa24fb SDJ |
239 | } |
240 | ||
729662a5 | 241 | return result; |
55aa24fb SDJ |
242 | } |
243 | ||
244 | \f | |
245 | ||
55aa24fb SDJ |
246 | /* Make a vector of probes matching OBJNAME, PROVIDER, and PROBE_NAME. |
247 | If POPS is not NULL, only probes of this certain probe_ops will match. | |
248 | Each argument is a regexp, or NULL, which matches anything. */ | |
249 | ||
729662a5 | 250 | static VEC (bound_probe_s) * |
55aa24fb SDJ |
251 | collect_probes (char *objname, char *provider, char *probe_name, |
252 | const struct probe_ops *pops) | |
253 | { | |
254 | struct objfile *objfile; | |
729662a5 | 255 | VEC (bound_probe_s) *result = NULL; |
55aa24fb SDJ |
256 | struct cleanup *cleanup, *cleanup_temps; |
257 | regex_t obj_pat, prov_pat, probe_pat; | |
258 | ||
729662a5 | 259 | cleanup = make_cleanup (VEC_cleanup (bound_probe_s), &result); |
55aa24fb SDJ |
260 | |
261 | cleanup_temps = make_cleanup (null_cleanup, NULL); | |
db26349c TT |
262 | if (provider != NULL) |
263 | compile_rx_or_error (&prov_pat, provider, _("Invalid provider regexp")); | |
264 | if (probe_name != NULL) | |
265 | compile_rx_or_error (&probe_pat, probe_name, _("Invalid probe regexp")); | |
266 | if (objname != NULL) | |
267 | compile_rx_or_error (&obj_pat, objname, _("Invalid object file regexp")); | |
55aa24fb SDJ |
268 | |
269 | ALL_OBJFILES (objfile) | |
270 | { | |
271 | VEC (probe_p) *probes; | |
272 | struct probe *probe; | |
273 | int ix; | |
274 | ||
275 | if (! objfile->sf || ! objfile->sf->sym_probe_fns) | |
276 | continue; | |
277 | ||
278 | if (objname) | |
279 | { | |
4262abfb | 280 | if (regexec (&obj_pat, objfile_name (objfile), 0, NULL, 0) != 0) |
55aa24fb SDJ |
281 | continue; |
282 | } | |
283 | ||
284 | probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile); | |
285 | ||
286 | for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++) | |
287 | { | |
729662a5 TT |
288 | struct bound_probe bound; |
289 | ||
55aa24fb SDJ |
290 | if (pops != NULL && probe->pops != pops) |
291 | continue; | |
292 | ||
293 | if (provider | |
294 | && regexec (&prov_pat, probe->provider, 0, NULL, 0) != 0) | |
295 | continue; | |
296 | ||
297 | if (probe_name | |
298 | && regexec (&probe_pat, probe->name, 0, NULL, 0) != 0) | |
299 | continue; | |
300 | ||
729662a5 TT |
301 | bound.objfile = objfile; |
302 | bound.probe = probe; | |
303 | VEC_safe_push (bound_probe_s, result, &bound); | |
55aa24fb SDJ |
304 | } |
305 | } | |
306 | ||
307 | do_cleanups (cleanup_temps); | |
308 | discard_cleanups (cleanup); | |
309 | return result; | |
310 | } | |
311 | ||
729662a5 | 312 | /* A qsort comparison function for bound_probe_s objects. */ |
55aa24fb SDJ |
313 | |
314 | static int | |
6bac7473 | 315 | compare_probes (const void *a, const void *b) |
55aa24fb | 316 | { |
729662a5 TT |
317 | const struct bound_probe *pa = (const struct bound_probe *) a; |
318 | const struct bound_probe *pb = (const struct bound_probe *) b; | |
55aa24fb SDJ |
319 | int v; |
320 | ||
729662a5 | 321 | v = strcmp (pa->probe->provider, pb->probe->provider); |
55aa24fb SDJ |
322 | if (v) |
323 | return v; | |
324 | ||
729662a5 | 325 | v = strcmp (pa->probe->name, pb->probe->name); |
55aa24fb SDJ |
326 | if (v) |
327 | return v; | |
328 | ||
729662a5 | 329 | if (pa->probe->address < pb->probe->address) |
55aa24fb | 330 | return -1; |
729662a5 | 331 | if (pa->probe->address > pb->probe->address) |
55aa24fb SDJ |
332 | return 1; |
333 | ||
4262abfb | 334 | return strcmp (objfile_name (pa->objfile), objfile_name (pb->objfile)); |
55aa24fb SDJ |
335 | } |
336 | ||
337 | /* Helper function that generate entries in the ui_out table being | |
338 | crafted by `info_probes_for_ops'. */ | |
339 | ||
340 | static void | |
729662a5 | 341 | gen_ui_out_table_header_info (VEC (bound_probe_s) *probes, |
55aa24fb SDJ |
342 | const struct probe_ops *p) |
343 | { | |
344 | /* `headings' refers to the names of the columns when printing `info | |
345 | probes'. */ | |
346 | VEC (info_probe_column_s) *headings = NULL; | |
347 | struct cleanup *c; | |
348 | info_probe_column_s *column; | |
349 | size_t headings_size; | |
350 | int ix; | |
351 | ||
352 | gdb_assert (p != NULL); | |
353 | ||
354 | if (p->gen_info_probes_table_header == NULL | |
355 | && p->gen_info_probes_table_values == NULL) | |
356 | return; | |
357 | ||
358 | gdb_assert (p->gen_info_probes_table_header != NULL | |
359 | && p->gen_info_probes_table_values != NULL); | |
360 | ||
361 | c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings); | |
362 | p->gen_info_probes_table_header (&headings); | |
363 | ||
364 | headings_size = VEC_length (info_probe_column_s, headings); | |
365 | ||
366 | for (ix = 0; | |
367 | VEC_iterate (info_probe_column_s, headings, ix, column); | |
368 | ++ix) | |
369 | { | |
729662a5 | 370 | struct bound_probe *probe; |
55aa24fb SDJ |
371 | int jx; |
372 | size_t size_max = strlen (column->print_name); | |
373 | ||
729662a5 | 374 | for (jx = 0; VEC_iterate (bound_probe_s, probes, jx, probe); ++jx) |
55aa24fb SDJ |
375 | { |
376 | /* `probe_fields' refers to the values of each new field that this | |
377 | probe will display. */ | |
378 | VEC (const_char_ptr) *probe_fields = NULL; | |
379 | struct cleanup *c2; | |
380 | const char *val; | |
381 | int kx; | |
382 | ||
729662a5 | 383 | if (probe->probe->pops != p) |
55aa24fb SDJ |
384 | continue; |
385 | ||
386 | c2 = make_cleanup (VEC_cleanup (const_char_ptr), &probe_fields); | |
729662a5 | 387 | p->gen_info_probes_table_values (probe->probe, &probe_fields); |
55aa24fb SDJ |
388 | |
389 | gdb_assert (VEC_length (const_char_ptr, probe_fields) | |
390 | == headings_size); | |
391 | ||
392 | for (kx = 0; VEC_iterate (const_char_ptr, probe_fields, kx, val); | |
393 | ++kx) | |
394 | { | |
395 | /* It is valid to have a NULL value here, which means that the | |
396 | backend does not have something to write and this particular | |
397 | field should be skipped. */ | |
398 | if (val == NULL) | |
399 | continue; | |
400 | ||
401 | size_max = max (strlen (val), size_max); | |
402 | } | |
403 | do_cleanups (c2); | |
404 | } | |
405 | ||
406 | ui_out_table_header (current_uiout, size_max, ui_left, | |
407 | column->field_name, column->print_name); | |
408 | } | |
409 | ||
410 | do_cleanups (c); | |
411 | } | |
412 | ||
6f9b8491 JM |
413 | /* Helper function to print not-applicable strings for all the extra |
414 | columns defined in a probe_ops. */ | |
415 | ||
416 | static void | |
417 | print_ui_out_not_applicables (const struct probe_ops *pops) | |
418 | { | |
419 | struct cleanup *c; | |
420 | VEC (info_probe_column_s) *headings = NULL; | |
421 | info_probe_column_s *column; | |
422 | int ix; | |
423 | ||
424 | if (pops->gen_info_probes_table_header == NULL) | |
425 | return; | |
426 | ||
427 | c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings); | |
428 | pops->gen_info_probes_table_header (&headings); | |
429 | ||
430 | for (ix = 0; | |
431 | VEC_iterate (info_probe_column_s, headings, ix, column); | |
432 | ++ix) | |
433 | ui_out_field_string (current_uiout, column->field_name, _("n/a")); | |
434 | ||
435 | do_cleanups (c); | |
436 | } | |
437 | ||
55aa24fb | 438 | /* Helper function to print extra information about a probe and an objfile |
6bac7473 | 439 | represented by PROBE. */ |
55aa24fb SDJ |
440 | |
441 | static void | |
6bac7473 | 442 | print_ui_out_info (struct probe *probe) |
55aa24fb SDJ |
443 | { |
444 | int ix; | |
445 | int j = 0; | |
446 | /* `values' refers to the actual values of each new field in the output | |
447 | of `info probe'. `headings' refers to the names of each new field. */ | |
448 | VEC (const_char_ptr) *values = NULL; | |
449 | VEC (info_probe_column_s) *headings = NULL; | |
450 | info_probe_column_s *column; | |
451 | struct cleanup *c; | |
452 | ||
6bac7473 SDJ |
453 | gdb_assert (probe != NULL); |
454 | gdb_assert (probe->pops != NULL); | |
55aa24fb | 455 | |
6bac7473 SDJ |
456 | if (probe->pops->gen_info_probes_table_header == NULL |
457 | && probe->pops->gen_info_probes_table_values == NULL) | |
55aa24fb SDJ |
458 | return; |
459 | ||
6bac7473 SDJ |
460 | gdb_assert (probe->pops->gen_info_probes_table_header != NULL |
461 | && probe->pops->gen_info_probes_table_values != NULL); | |
55aa24fb SDJ |
462 | |
463 | c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings); | |
464 | make_cleanup (VEC_cleanup (const_char_ptr), &values); | |
465 | ||
6bac7473 SDJ |
466 | probe->pops->gen_info_probes_table_header (&headings); |
467 | probe->pops->gen_info_probes_table_values (probe, &values); | |
55aa24fb SDJ |
468 | |
469 | gdb_assert (VEC_length (info_probe_column_s, headings) | |
470 | == VEC_length (const_char_ptr, values)); | |
471 | ||
472 | for (ix = 0; | |
473 | VEC_iterate (info_probe_column_s, headings, ix, column); | |
474 | ++ix) | |
475 | { | |
476 | const char *val = VEC_index (const_char_ptr, values, j++); | |
477 | ||
478 | if (val == NULL) | |
479 | ui_out_field_skip (current_uiout, column->field_name); | |
480 | else | |
481 | ui_out_field_string (current_uiout, column->field_name, val); | |
482 | } | |
483 | ||
484 | do_cleanups (c); | |
485 | } | |
486 | ||
487 | /* Helper function that returns the number of extra fields which POPS will | |
488 | need. */ | |
489 | ||
490 | static int | |
491 | get_number_extra_fields (const struct probe_ops *pops) | |
492 | { | |
493 | VEC (info_probe_column_s) *headings = NULL; | |
494 | struct cleanup *c; | |
495 | int n; | |
496 | ||
497 | if (pops->gen_info_probes_table_header == NULL) | |
498 | return 0; | |
499 | ||
500 | c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings); | |
501 | pops->gen_info_probes_table_header (&headings); | |
502 | ||
503 | n = VEC_length (info_probe_column_s, headings); | |
504 | ||
505 | do_cleanups (c); | |
506 | ||
507 | return n; | |
508 | } | |
509 | ||
6f9b8491 JM |
510 | /* Helper function that returns 1 if there is a probe in PROBES |
511 | featuring the given POPS. It returns 0 otherwise. */ | |
512 | ||
513 | static int | |
514 | exists_probe_with_pops (VEC (bound_probe_s) *probes, | |
515 | const struct probe_ops *pops) | |
516 | { | |
517 | struct bound_probe *probe; | |
518 | int ix; | |
519 | ||
520 | for (ix = 0; VEC_iterate (bound_probe_s, probes, ix, probe); ++ix) | |
521 | if (probe->probe->pops == pops) | |
522 | return 1; | |
523 | ||
524 | return 0; | |
525 | } | |
526 | ||
55aa24fb SDJ |
527 | /* See comment in probe.h. */ |
528 | ||
529 | void | |
8236def8 TT |
530 | info_probes_for_ops (const char *arg, int from_tty, |
531 | const struct probe_ops *pops) | |
55aa24fb | 532 | { |
6bac7473 | 533 | char *provider, *probe_name = NULL, *objname = NULL; |
55aa24fb | 534 | struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); |
729662a5 | 535 | VEC (bound_probe_s) *probes; |
55aa24fb SDJ |
536 | int i, any_found; |
537 | int ui_out_extra_fields = 0; | |
538 | size_t size_addr; | |
539 | size_t size_name = strlen ("Name"); | |
540 | size_t size_objname = strlen ("Object"); | |
541 | size_t size_provider = strlen ("Provider"); | |
6f9b8491 | 542 | size_t size_type = strlen ("Type"); |
729662a5 | 543 | struct bound_probe *probe; |
55aa24fb SDJ |
544 | struct gdbarch *gdbarch = get_current_arch (); |
545 | ||
546 | /* Do we have a `provider:probe:objfile' style of linespec? */ | |
8236def8 | 547 | provider = extract_arg_const (&arg); |
55aa24fb SDJ |
548 | if (provider) |
549 | { | |
550 | make_cleanup (xfree, provider); | |
551 | ||
8236def8 | 552 | probe_name = extract_arg_const (&arg); |
6bac7473 | 553 | if (probe_name) |
55aa24fb | 554 | { |
6bac7473 | 555 | make_cleanup (xfree, probe_name); |
55aa24fb | 556 | |
8236def8 | 557 | objname = extract_arg_const (&arg); |
55aa24fb SDJ |
558 | if (objname) |
559 | make_cleanup (xfree, objname); | |
560 | } | |
561 | } | |
562 | ||
6f9b8491 JM |
563 | probes = collect_probes (objname, provider, probe_name, pops); |
564 | make_cleanup (VEC_cleanup (probe_p), &probes); | |
565 | ||
55aa24fb SDJ |
566 | if (pops == NULL) |
567 | { | |
568 | const struct probe_ops *po; | |
569 | int ix; | |
570 | ||
571 | /* If the probe_ops is NULL, it means the user has requested a "simple" | |
572 | `info probes', i.e., she wants to print all information about all | |
573 | probes. For that, we have to identify how many extra fields we will | |
574 | need to add in the ui_out table. | |
575 | ||
576 | To do that, we iterate over all probe_ops, querying each one about | |
577 | its extra fields, and incrementing `ui_out_extra_fields' to reflect | |
6f9b8491 JM |
578 | that number. But note that we ignore the probe_ops for which no probes |
579 | are defined with the given search criteria. */ | |
55aa24fb SDJ |
580 | |
581 | for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix) | |
6f9b8491 JM |
582 | if (exists_probe_with_pops (probes, po)) |
583 | ui_out_extra_fields += get_number_extra_fields (po); | |
55aa24fb SDJ |
584 | } |
585 | else | |
586 | ui_out_extra_fields = get_number_extra_fields (pops); | |
587 | ||
55aa24fb | 588 | make_cleanup_ui_out_table_begin_end (current_uiout, |
6f9b8491 | 589 | 5 + ui_out_extra_fields, |
729662a5 | 590 | VEC_length (bound_probe_s, probes), |
55aa24fb SDJ |
591 | "StaticProbes"); |
592 | ||
729662a5 TT |
593 | if (!VEC_empty (bound_probe_s, probes)) |
594 | qsort (VEC_address (bound_probe_s, probes), | |
595 | VEC_length (bound_probe_s, probes), | |
596 | sizeof (bound_probe_s), compare_probes); | |
55aa24fb SDJ |
597 | |
598 | /* What's the size of an address in our architecture? */ | |
599 | size_addr = gdbarch_addr_bit (gdbarch) == 64 ? 18 : 10; | |
600 | ||
6f9b8491 JM |
601 | /* Determining the maximum size of each field (`type', `provider', |
602 | `name' and `objname'). */ | |
729662a5 | 603 | for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i) |
55aa24fb | 604 | { |
6f9b8491 JM |
605 | const char *probe_type = probe->probe->pops->type_name (probe->probe); |
606 | ||
607 | size_type = max (strlen (probe_type), size_type); | |
729662a5 TT |
608 | size_name = max (strlen (probe->probe->name), size_name); |
609 | size_provider = max (strlen (probe->probe->provider), size_provider); | |
4262abfb | 610 | size_objname = max (strlen (objfile_name (probe->objfile)), size_objname); |
55aa24fb SDJ |
611 | } |
612 | ||
6f9b8491 | 613 | ui_out_table_header (current_uiout, size_type, ui_left, "type", _("Type")); |
55aa24fb SDJ |
614 | ui_out_table_header (current_uiout, size_provider, ui_left, "provider", |
615 | _("Provider")); | |
616 | ui_out_table_header (current_uiout, size_name, ui_left, "name", _("Name")); | |
617 | ui_out_table_header (current_uiout, size_addr, ui_left, "addr", _("Where")); | |
618 | ||
619 | if (pops == NULL) | |
620 | { | |
621 | const struct probe_ops *po; | |
622 | int ix; | |
623 | ||
6f9b8491 JM |
624 | /* We have to generate the table header for each new probe type |
625 | that we will print. Note that this excludes probe types not | |
626 | having any defined probe with the search criteria. */ | |
55aa24fb | 627 | for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix) |
6f9b8491 JM |
628 | if (exists_probe_with_pops (probes, po)) |
629 | gen_ui_out_table_header_info (probes, po); | |
55aa24fb SDJ |
630 | } |
631 | else | |
6bac7473 | 632 | gen_ui_out_table_header_info (probes, pops); |
55aa24fb SDJ |
633 | |
634 | ui_out_table_header (current_uiout, size_objname, ui_left, "object", | |
635 | _("Object")); | |
636 | ui_out_table_body (current_uiout); | |
637 | ||
729662a5 | 638 | for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i) |
55aa24fb SDJ |
639 | { |
640 | struct cleanup *inner; | |
6f9b8491 | 641 | const char *probe_type = probe->probe->pops->type_name (probe->probe); |
55aa24fb SDJ |
642 | |
643 | inner = make_cleanup_ui_out_tuple_begin_end (current_uiout, "probe"); | |
644 | ||
6f9b8491 | 645 | ui_out_field_string (current_uiout, "type",probe_type); |
729662a5 TT |
646 | ui_out_field_string (current_uiout, "provider", probe->probe->provider); |
647 | ui_out_field_string (current_uiout, "name", probe->probe->name); | |
55aa24fb | 648 | ui_out_field_core_addr (current_uiout, "addr", |
729662a5 TT |
649 | probe->probe->arch, |
650 | get_probe_address (probe->probe, probe->objfile)); | |
55aa24fb SDJ |
651 | |
652 | if (pops == NULL) | |
653 | { | |
654 | const struct probe_ops *po; | |
655 | int ix; | |
656 | ||
657 | for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); | |
658 | ++ix) | |
729662a5 TT |
659 | if (probe->probe->pops == po) |
660 | print_ui_out_info (probe->probe); | |
6f9b8491 JM |
661 | else if (exists_probe_with_pops (probes, po)) |
662 | print_ui_out_not_applicables (po); | |
55aa24fb SDJ |
663 | } |
664 | else | |
729662a5 | 665 | print_ui_out_info (probe->probe); |
55aa24fb | 666 | |
4262abfb JK |
667 | ui_out_field_string (current_uiout, "object", |
668 | objfile_name (probe->objfile)); | |
55aa24fb SDJ |
669 | ui_out_text (current_uiout, "\n"); |
670 | ||
671 | do_cleanups (inner); | |
672 | } | |
673 | ||
729662a5 | 674 | any_found = !VEC_empty (bound_probe_s, probes); |
55aa24fb SDJ |
675 | do_cleanups (cleanup); |
676 | ||
677 | if (!any_found) | |
678 | ui_out_message (current_uiout, 0, _("No probes matched.\n")); | |
679 | } | |
680 | ||
681 | /* Implementation of the `info probes' command. */ | |
682 | ||
683 | static void | |
684 | info_probes_command (char *arg, int from_tty) | |
685 | { | |
686 | info_probes_for_ops (arg, from_tty, NULL); | |
687 | } | |
688 | ||
689 | /* See comments in probe.h. */ | |
690 | ||
729662a5 TT |
691 | CORE_ADDR |
692 | get_probe_address (struct probe *probe, struct objfile *objfile) | |
693 | { | |
694 | return probe->pops->get_probe_address (probe, objfile); | |
695 | } | |
696 | ||
697 | /* See comments in probe.h. */ | |
698 | ||
9ee6a5ac | 699 | unsigned |
08a6411c | 700 | get_probe_argument_count (struct probe *probe, struct frame_info *frame) |
9ee6a5ac | 701 | { |
08a6411c | 702 | return probe->pops->get_probe_argument_count (probe, frame); |
9ee6a5ac GB |
703 | } |
704 | ||
705 | /* See comments in probe.h. */ | |
706 | ||
25f9533e SDJ |
707 | int |
708 | can_evaluate_probe_arguments (struct probe *probe) | |
709 | { | |
37fbcad0 | 710 | return probe->pops->can_evaluate_probe_arguments (probe); |
25f9533e SDJ |
711 | } |
712 | ||
713 | /* See comments in probe.h. */ | |
714 | ||
9ee6a5ac | 715 | struct value * |
08a6411c SDJ |
716 | evaluate_probe_argument (struct probe *probe, unsigned n, |
717 | struct frame_info *frame) | |
9ee6a5ac | 718 | { |
08a6411c | 719 | return probe->pops->evaluate_probe_argument (probe, n, frame); |
9ee6a5ac GB |
720 | } |
721 | ||
722 | /* See comments in probe.h. */ | |
723 | ||
55aa24fb SDJ |
724 | struct value * |
725 | probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n) | |
726 | { | |
729662a5 | 727 | struct bound_probe probe; |
2b963b68 | 728 | unsigned n_args; |
55aa24fb | 729 | |
6bac7473 | 730 | probe = find_probe_by_pc (get_frame_pc (frame)); |
729662a5 | 731 | if (!probe.probe) |
55aa24fb | 732 | return NULL; |
55aa24fb | 733 | |
729662a5 | 734 | n_args = get_probe_argument_count (probe.probe, frame); |
2b963b68 | 735 | if (n >= n_args) |
55aa24fb SDJ |
736 | return NULL; |
737 | ||
729662a5 | 738 | return evaluate_probe_argument (probe.probe, n, frame); |
55aa24fb SDJ |
739 | } |
740 | ||
741 | /* See comment in probe.h. */ | |
742 | ||
743 | const struct probe_ops * | |
744 | probe_linespec_to_ops (const char **linespecp) | |
745 | { | |
746 | int ix; | |
747 | const struct probe_ops *probe_ops; | |
748 | ||
749 | for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, probe_ops); ix++) | |
750 | if (probe_ops->is_linespec (linespecp)) | |
751 | return probe_ops; | |
752 | ||
753 | return NULL; | |
754 | } | |
755 | ||
756 | /* See comment in probe.h. */ | |
757 | ||
758 | int | |
759 | probe_is_linespec_by_keyword (const char **linespecp, const char *const *keywords) | |
760 | { | |
761 | const char *s = *linespecp; | |
762 | const char *const *csp; | |
763 | ||
764 | for (csp = keywords; *csp; csp++) | |
765 | { | |
766 | const char *keyword = *csp; | |
767 | size_t len = strlen (keyword); | |
768 | ||
769 | if (strncmp (s, keyword, len) == 0 && isspace (s[len])) | |
770 | { | |
771 | *linespecp += len + 1; | |
772 | return 1; | |
773 | } | |
774 | } | |
775 | ||
776 | return 0; | |
777 | } | |
778 | ||
779 | /* Implementation of `is_linespec' method for `struct probe_ops'. */ | |
780 | ||
781 | static int | |
782 | probe_any_is_linespec (const char **linespecp) | |
783 | { | |
784 | static const char *const keywords[] = { "-p", "-probe", NULL }; | |
785 | ||
786 | return probe_is_linespec_by_keyword (linespecp, keywords); | |
787 | } | |
788 | ||
789 | /* Dummy method used for `probe_ops_any'. */ | |
790 | ||
791 | static void | |
792 | probe_any_get_probes (VEC (probe_p) **probesp, struct objfile *objfile) | |
793 | { | |
794 | /* No probes can be provided by this dummy backend. */ | |
795 | } | |
796 | ||
797 | /* Operations associated with a generic probe. */ | |
798 | ||
799 | const struct probe_ops probe_ops_any = | |
800 | { | |
801 | probe_any_is_linespec, | |
802 | probe_any_get_probes, | |
803 | }; | |
804 | ||
805 | /* See comments in probe.h. */ | |
806 | ||
807 | struct cmd_list_element ** | |
808 | info_probes_cmdlist_get (void) | |
809 | { | |
810 | static struct cmd_list_element *info_probes_cmdlist; | |
811 | ||
812 | if (info_probes_cmdlist == NULL) | |
813 | add_prefix_cmd ("probes", class_info, info_probes_command, | |
814 | _("\ | |
815 | Show available static probes.\n\ | |
816 | Usage: info probes [all|TYPE [ARGS]]\n\ | |
817 | TYPE specifies the type of the probe, and can be one of the following:\n\ | |
818 | - stap\n\ | |
819 | If you specify TYPE, there may be additional arguments needed by the\n\ | |
820 | subcommand.\n\ | |
821 | If you do not specify any argument, or specify `all', then the command\n\ | |
822 | will show information about all types of probes."), | |
823 | &info_probes_cmdlist, "info probes ", | |
824 | 0/*allow-unknown*/, &infolist); | |
825 | ||
826 | return &info_probes_cmdlist; | |
827 | } | |
828 | ||
829 | VEC (probe_ops_cp) *all_probe_ops; | |
830 | ||
831 | void _initialize_probe (void); | |
832 | ||
833 | void | |
834 | _initialize_probe (void) | |
835 | { | |
836 | VEC_safe_push (probe_ops_cp, all_probe_ops, &probe_ops_any); | |
837 | ||
838 | add_cmd ("all", class_info, info_probes_command, | |
839 | _("\ | |
840 | Show information about all type of probes."), | |
841 | info_probes_cmdlist_get ()); | |
842 | } |