1 /* Generic static probe support for GDB.
3 Copyright (C) 2012-2016 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
23 #include "cli/cli-cmds.h"
24 #include "cli/cli-utils.h"
27 #include "progspace.h"
28 #include "filenames.h"
30 #include "gdb_regex.h"
32 #include "arch-utils.h"
40 typedef struct bound_probe bound_probe_s;
41 DEF_VEC_O (bound_probe_s);
45 /* A helper for parse_probes that decodes a probe specification in
46 SEARCH_PSPACE. It appends matching SALs to RESULT. */
49 parse_probes_in_pspace (const struct probe_ops *probe_ops,
50 struct program_space *search_pspace,
51 const char *objfile_namestr,
54 struct symtabs_and_lines *result)
56 struct objfile *objfile;
58 ALL_PSPACE_OBJFILES (search_pspace, objfile)
60 VEC (probe_p) *probes;
64 if (!objfile->sf || !objfile->sf->sym_probe_fns)
68 && FILENAME_CMP (objfile_name (objfile), objfile_namestr) != 0
69 && FILENAME_CMP (lbasename (objfile_name (objfile)),
70 objfile_namestr) != 0)
73 probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
75 for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++)
77 struct symtab_and_line *sal;
79 if (probe_ops != &probe_ops_any && probe->pops != probe_ops)
82 if (provider && strcmp (probe->provider, provider) != 0)
85 if (strcmp (probe->name, name) != 0)
89 result->sals = XRESIZEVEC (struct symtab_and_line, result->sals,
91 sal = &result->sals[result->nelts - 1];
95 sal->pc = get_probe_address (probe, objfile);
97 sal->section = find_pc_overlay (sal->pc);
98 sal->pspace = search_pspace;
100 sal->objfile = objfile;
105 /* See definition in probe.h. */
107 struct symtabs_and_lines
108 parse_probes (const struct event_location *location,
109 struct program_space *search_pspace,
110 struct linespec_result *canonical)
113 char *objfile_namestr = NULL, *provider = NULL, *name, *p;
114 struct cleanup *cleanup;
115 struct symtabs_and_lines result;
116 const struct probe_ops *probe_ops;
117 const char *arg_start, *cs;
122 gdb_assert (event_location_type (location) == PROBE_LOCATION);
123 arg_start = get_probe_location (location);
126 probe_ops = probe_linespec_to_ops (&cs);
127 if (probe_ops == NULL)
128 error (_("'%s' is not a probe linespec"), arg_start);
131 arg = skip_spaces (arg);
133 error (_("argument to `%s' missing"), arg_start);
135 arg_end = skip_to_space (arg);
137 /* We make a copy here so we can write over parts with impunity. */
138 arg = savestring (arg, arg_end - arg);
139 cleanup = make_cleanup (xfree, arg);
141 /* Extract each word from the argument, separated by ":"s. */
142 p = strchr (arg, ':');
145 /* This is `-p name'. */
153 p = strchr (hold, ':');
156 /* This is `-p provider:name'. */
162 /* This is `-p objfile:provider:name'. */
164 objfile_namestr = arg;
171 error (_("no probe name specified"));
172 if (provider && *provider == '\0')
173 error (_("invalid provider name"));
174 if (objfile_namestr && *objfile_namestr == '\0')
175 error (_("invalid objfile name"));
177 if (search_pspace != NULL)
179 parse_probes_in_pspace (probe_ops, search_pspace, objfile_namestr,
180 provider, name, &result);
184 struct program_space *pspace;
187 parse_probes_in_pspace (probe_ops, pspace, objfile_namestr,
188 provider, name, &result);
191 if (result.nelts == 0)
193 throw_error (NOT_FOUND_ERROR,
194 _("No probe matching objfile=`%s', provider=`%s', name=`%s'"),
195 objfile_namestr ? objfile_namestr : _("<any>"),
196 provider ? provider : _("<any>"),
204 canon = savestring (arg_start, arg_end - arg_start);
205 make_cleanup (xfree, canon);
206 canonical->special_display = 1;
207 canonical->pre_expanded = 1;
208 canonical->location = new_probe_location (canon);
211 do_cleanups (cleanup);
216 /* See definition in probe.h. */
219 find_probes_in_objfile (struct objfile *objfile, const char *provider,
222 VEC (probe_p) *probes, *result = NULL;
226 if (!objfile->sf || !objfile->sf->sym_probe_fns)
229 probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
230 for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++)
232 if (strcmp (probe->provider, provider) != 0)
235 if (strcmp (probe->name, name) != 0)
238 VEC_safe_push (probe_p, result, probe);
244 /* See definition in probe.h. */
247 find_probe_by_pc (CORE_ADDR pc)
249 struct objfile *objfile;
250 struct bound_probe result;
252 result.objfile = NULL;
255 ALL_OBJFILES (objfile)
257 VEC (probe_p) *probes;
261 if (!objfile->sf || !objfile->sf->sym_probe_fns
262 || objfile->sect_index_text == -1)
265 /* If this proves too inefficient, we can replace with a hash. */
266 probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
267 for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++)
268 if (get_probe_address (probe, objfile) == pc)
270 result.objfile = objfile;
271 result.probe = probe;
281 /* Make a vector of probes matching OBJNAME, PROVIDER, and PROBE_NAME.
282 If POPS is not NULL, only probes of this certain probe_ops will match.
283 Each argument is a regexp, or NULL, which matches anything. */
285 static VEC (bound_probe_s) *
286 collect_probes (char *objname, char *provider, char *probe_name,
287 const struct probe_ops *pops)
289 struct objfile *objfile;
290 VEC (bound_probe_s) *result = NULL;
291 struct cleanup *cleanup, *cleanup_temps;
292 regex_t obj_pat, prov_pat, probe_pat;
294 cleanup = make_cleanup (VEC_cleanup (bound_probe_s), &result);
296 cleanup_temps = make_cleanup (null_cleanup, NULL);
297 if (provider != NULL)
298 compile_rx_or_error (&prov_pat, provider, _("Invalid provider regexp"));
299 if (probe_name != NULL)
300 compile_rx_or_error (&probe_pat, probe_name, _("Invalid probe regexp"));
302 compile_rx_or_error (&obj_pat, objname, _("Invalid object file regexp"));
304 ALL_OBJFILES (objfile)
306 VEC (probe_p) *probes;
310 if (! objfile->sf || ! objfile->sf->sym_probe_fns)
315 if (regexec (&obj_pat, objfile_name (objfile), 0, NULL, 0) != 0)
319 probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
321 for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++)
323 struct bound_probe bound;
325 if (pops != NULL && probe->pops != pops)
329 && regexec (&prov_pat, probe->provider, 0, NULL, 0) != 0)
333 && regexec (&probe_pat, probe->name, 0, NULL, 0) != 0)
336 bound.objfile = objfile;
338 VEC_safe_push (bound_probe_s, result, &bound);
342 do_cleanups (cleanup_temps);
343 discard_cleanups (cleanup);
347 /* A qsort comparison function for bound_probe_s objects. */
350 compare_probes (const void *a, const void *b)
352 const struct bound_probe *pa = (const struct bound_probe *) a;
353 const struct bound_probe *pb = (const struct bound_probe *) b;
356 v = strcmp (pa->probe->provider, pb->probe->provider);
360 v = strcmp (pa->probe->name, pb->probe->name);
364 if (pa->probe->address < pb->probe->address)
366 if (pa->probe->address > pb->probe->address)
369 return strcmp (objfile_name (pa->objfile), objfile_name (pb->objfile));
372 /* Helper function that generate entries in the ui_out table being
373 crafted by `info_probes_for_ops'. */
376 gen_ui_out_table_header_info (VEC (bound_probe_s) *probes,
377 const struct probe_ops *p)
379 /* `headings' refers to the names of the columns when printing `info
381 VEC (info_probe_column_s) *headings = NULL;
383 info_probe_column_s *column;
384 size_t headings_size;
387 gdb_assert (p != NULL);
389 if (p->gen_info_probes_table_header == NULL
390 && p->gen_info_probes_table_values == NULL)
393 gdb_assert (p->gen_info_probes_table_header != NULL
394 && p->gen_info_probes_table_values != NULL);
396 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
397 p->gen_info_probes_table_header (&headings);
399 headings_size = VEC_length (info_probe_column_s, headings);
402 VEC_iterate (info_probe_column_s, headings, ix, column);
405 struct bound_probe *probe;
407 size_t size_max = strlen (column->print_name);
409 for (jx = 0; VEC_iterate (bound_probe_s, probes, jx, probe); ++jx)
411 /* `probe_fields' refers to the values of each new field that this
412 probe will display. */
413 VEC (const_char_ptr) *probe_fields = NULL;
418 if (probe->probe->pops != p)
421 c2 = make_cleanup (VEC_cleanup (const_char_ptr), &probe_fields);
422 p->gen_info_probes_table_values (probe->probe, &probe_fields);
424 gdb_assert (VEC_length (const_char_ptr, probe_fields)
427 for (kx = 0; VEC_iterate (const_char_ptr, probe_fields, kx, val);
430 /* It is valid to have a NULL value here, which means that the
431 backend does not have something to write and this particular
432 field should be skipped. */
436 size_max = std::max (strlen (val), size_max);
441 ui_out_table_header (current_uiout, size_max, ui_left,
442 column->field_name, column->print_name);
448 /* Helper function to print not-applicable strings for all the extra
449 columns defined in a probe_ops. */
452 print_ui_out_not_applicables (const struct probe_ops *pops)
455 VEC (info_probe_column_s) *headings = NULL;
456 info_probe_column_s *column;
459 if (pops->gen_info_probes_table_header == NULL)
462 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
463 pops->gen_info_probes_table_header (&headings);
466 VEC_iterate (info_probe_column_s, headings, ix, column);
468 ui_out_field_string (current_uiout, column->field_name, _("n/a"));
473 /* Helper function to print extra information about a probe and an objfile
474 represented by PROBE. */
477 print_ui_out_info (struct probe *probe)
481 /* `values' refers to the actual values of each new field in the output
482 of `info probe'. `headings' refers to the names of each new field. */
483 VEC (const_char_ptr) *values = NULL;
484 VEC (info_probe_column_s) *headings = NULL;
485 info_probe_column_s *column;
488 gdb_assert (probe != NULL);
489 gdb_assert (probe->pops != NULL);
491 if (probe->pops->gen_info_probes_table_header == NULL
492 && probe->pops->gen_info_probes_table_values == NULL)
495 gdb_assert (probe->pops->gen_info_probes_table_header != NULL
496 && probe->pops->gen_info_probes_table_values != NULL);
498 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
499 make_cleanup (VEC_cleanup (const_char_ptr), &values);
501 probe->pops->gen_info_probes_table_header (&headings);
502 probe->pops->gen_info_probes_table_values (probe, &values);
504 gdb_assert (VEC_length (info_probe_column_s, headings)
505 == VEC_length (const_char_ptr, values));
508 VEC_iterate (info_probe_column_s, headings, ix, column);
511 const char *val = VEC_index (const_char_ptr, values, j++);
514 ui_out_field_skip (current_uiout, column->field_name);
516 ui_out_field_string (current_uiout, column->field_name, val);
522 /* Helper function that returns the number of extra fields which POPS will
526 get_number_extra_fields (const struct probe_ops *pops)
528 VEC (info_probe_column_s) *headings = NULL;
532 if (pops->gen_info_probes_table_header == NULL)
535 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
536 pops->gen_info_probes_table_header (&headings);
538 n = VEC_length (info_probe_column_s, headings);
545 /* Helper function that returns 1 if there is a probe in PROBES
546 featuring the given POPS. It returns 0 otherwise. */
549 exists_probe_with_pops (VEC (bound_probe_s) *probes,
550 const struct probe_ops *pops)
552 struct bound_probe *probe;
555 for (ix = 0; VEC_iterate (bound_probe_s, probes, ix, probe); ++ix)
556 if (probe->probe->pops == pops)
562 /* Helper function that parses a probe linespec of the form [PROVIDER
563 [PROBE [OBJNAME]]] from the provided string STR. */
566 parse_probe_linespec (const char *str, char **provider,
567 char **probe_name, char **objname)
569 *probe_name = *objname = NULL;
571 *provider = extract_arg_const (&str);
572 if (*provider != NULL)
574 *probe_name = extract_arg_const (&str);
575 if (*probe_name != NULL)
576 *objname = extract_arg_const (&str);
580 /* See comment in probe.h. */
583 info_probes_for_ops (const char *arg, int from_tty,
584 const struct probe_ops *pops)
586 char *provider, *probe_name = NULL, *objname = NULL;
587 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
588 VEC (bound_probe_s) *probes;
590 int ui_out_extra_fields = 0;
592 size_t size_name = strlen ("Name");
593 size_t size_objname = strlen ("Object");
594 size_t size_provider = strlen ("Provider");
595 size_t size_type = strlen ("Type");
596 struct bound_probe *probe;
597 struct gdbarch *gdbarch = get_current_arch ();
599 parse_probe_linespec (arg, &provider, &probe_name, &objname);
600 make_cleanup (xfree, provider);
601 make_cleanup (xfree, probe_name);
602 make_cleanup (xfree, objname);
604 probes = collect_probes (objname, provider, probe_name, pops);
605 make_cleanup (VEC_cleanup (probe_p), &probes);
609 const struct probe_ops *po;
612 /* If the probe_ops is NULL, it means the user has requested a "simple"
613 `info probes', i.e., she wants to print all information about all
614 probes. For that, we have to identify how many extra fields we will
615 need to add in the ui_out table.
617 To do that, we iterate over all probe_ops, querying each one about
618 its extra fields, and incrementing `ui_out_extra_fields' to reflect
619 that number. But note that we ignore the probe_ops for which no probes
620 are defined with the given search criteria. */
622 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix)
623 if (exists_probe_with_pops (probes, po))
624 ui_out_extra_fields += get_number_extra_fields (po);
627 ui_out_extra_fields = get_number_extra_fields (pops);
629 make_cleanup_ui_out_table_begin_end (current_uiout,
630 5 + ui_out_extra_fields,
631 VEC_length (bound_probe_s, probes),
634 if (!VEC_empty (bound_probe_s, probes))
635 qsort (VEC_address (bound_probe_s, probes),
636 VEC_length (bound_probe_s, probes),
637 sizeof (bound_probe_s), compare_probes);
639 /* What's the size of an address in our architecture? */
640 size_addr = gdbarch_addr_bit (gdbarch) == 64 ? 18 : 10;
642 /* Determining the maximum size of each field (`type', `provider',
643 `name' and `objname'). */
644 for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
646 const char *probe_type = probe->probe->pops->type_name (probe->probe);
648 size_type = std::max (strlen (probe_type), size_type);
649 size_name = std::max (strlen (probe->probe->name), size_name);
650 size_provider = std::max (strlen (probe->probe->provider), size_provider);
651 size_objname = std::max (strlen (objfile_name (probe->objfile)),
655 ui_out_table_header (current_uiout, size_type, ui_left, "type", _("Type"));
656 ui_out_table_header (current_uiout, size_provider, ui_left, "provider",
658 ui_out_table_header (current_uiout, size_name, ui_left, "name", _("Name"));
659 ui_out_table_header (current_uiout, size_addr, ui_left, "addr", _("Where"));
663 const struct probe_ops *po;
666 /* We have to generate the table header for each new probe type
667 that we will print. Note that this excludes probe types not
668 having any defined probe with the search criteria. */
669 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix)
670 if (exists_probe_with_pops (probes, po))
671 gen_ui_out_table_header_info (probes, po);
674 gen_ui_out_table_header_info (probes, pops);
676 ui_out_table_header (current_uiout, size_objname, ui_left, "object",
678 ui_out_table_body (current_uiout);
680 for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
682 struct cleanup *inner;
683 const char *probe_type = probe->probe->pops->type_name (probe->probe);
685 inner = make_cleanup_ui_out_tuple_begin_end (current_uiout, "probe");
687 ui_out_field_string (current_uiout, "type",probe_type);
688 ui_out_field_string (current_uiout, "provider", probe->probe->provider);
689 ui_out_field_string (current_uiout, "name", probe->probe->name);
690 ui_out_field_core_addr (current_uiout, "addr",
692 get_probe_address (probe->probe, probe->objfile));
696 const struct probe_ops *po;
699 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po);
701 if (probe->probe->pops == po)
702 print_ui_out_info (probe->probe);
703 else if (exists_probe_with_pops (probes, po))
704 print_ui_out_not_applicables (po);
707 print_ui_out_info (probe->probe);
709 ui_out_field_string (current_uiout, "object",
710 objfile_name (probe->objfile));
711 ui_out_text (current_uiout, "\n");
716 any_found = !VEC_empty (bound_probe_s, probes);
717 do_cleanups (cleanup);
720 ui_out_message (current_uiout, 0, _("No probes matched.\n"));
723 /* Implementation of the `info probes' command. */
726 info_probes_command (char *arg, int from_tty)
728 info_probes_for_ops (arg, from_tty, NULL);
731 /* Implementation of the `enable probes' command. */
734 enable_probes_command (char *arg, int from_tty)
736 char *provider, *probe_name = NULL, *objname = NULL;
737 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
738 VEC (bound_probe_s) *probes;
739 struct bound_probe *probe;
742 parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
743 make_cleanup (xfree, provider);
744 make_cleanup (xfree, probe_name);
745 make_cleanup (xfree, objname);
747 probes = collect_probes (objname, provider, probe_name, NULL);
748 if (VEC_empty (bound_probe_s, probes))
750 ui_out_message (current_uiout, 0, _("No probes matched.\n"));
751 do_cleanups (cleanup);
755 /* Enable the selected probes, provided their backends support the
756 notion of enabling a probe. */
757 for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
759 const struct probe_ops *pops = probe->probe->pops;
761 if (pops->enable_probe != NULL)
763 pops->enable_probe (probe->probe);
764 ui_out_message (current_uiout, 0,
765 _("Probe %s:%s enabled.\n"),
766 probe->probe->provider, probe->probe->name);
769 ui_out_message (current_uiout, 0,
770 _("Probe %s:%s cannot be enabled.\n"),
771 probe->probe->provider, probe->probe->name);
774 do_cleanups (cleanup);
777 /* Implementation of the `disable probes' command. */
780 disable_probes_command (char *arg, int from_tty)
782 char *provider, *probe_name = NULL, *objname = NULL;
783 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
784 VEC (bound_probe_s) *probes;
785 struct bound_probe *probe;
788 parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
789 make_cleanup (xfree, provider);
790 make_cleanup (xfree, probe_name);
791 make_cleanup (xfree, objname);
793 probes = collect_probes (objname, provider, probe_name, NULL /* pops */);
794 if (VEC_empty (bound_probe_s, probes))
796 ui_out_message (current_uiout, 0, _("No probes matched.\n"));
797 do_cleanups (cleanup);
801 /* Disable the selected probes, provided their backends support the
802 notion of enabling a probe. */
803 for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
805 const struct probe_ops *pops = probe->probe->pops;
807 if (pops->disable_probe != NULL)
809 pops->disable_probe (probe->probe);
810 ui_out_message (current_uiout, 0,
811 _("Probe %s:%s disabled.\n"),
812 probe->probe->provider, probe->probe->name);
815 ui_out_message (current_uiout, 0,
816 _("Probe %s:%s cannot be disabled.\n"),
817 probe->probe->provider, probe->probe->name);
820 do_cleanups (cleanup);
823 /* See comments in probe.h. */
826 get_probe_address (struct probe *probe, struct objfile *objfile)
828 return probe->pops->get_probe_address (probe, objfile);
831 /* See comments in probe.h. */
834 get_probe_argument_count (struct probe *probe, struct frame_info *frame)
836 return probe->pops->get_probe_argument_count (probe, frame);
839 /* See comments in probe.h. */
842 can_evaluate_probe_arguments (struct probe *probe)
844 return probe->pops->can_evaluate_probe_arguments (probe);
847 /* See comments in probe.h. */
850 evaluate_probe_argument (struct probe *probe, unsigned n,
851 struct frame_info *frame)
853 return probe->pops->evaluate_probe_argument (probe, n, frame);
856 /* See comments in probe.h. */
859 probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n)
861 struct bound_probe probe;
864 probe = find_probe_by_pc (get_frame_pc (frame));
868 n_args = get_probe_argument_count (probe.probe, frame);
872 return evaluate_probe_argument (probe.probe, n, frame);
875 /* See comment in probe.h. */
877 const struct probe_ops *
878 probe_linespec_to_ops (const char **linespecp)
881 const struct probe_ops *probe_ops;
883 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, probe_ops); ix++)
884 if (probe_ops->is_linespec (linespecp))
890 /* See comment in probe.h. */
893 probe_is_linespec_by_keyword (const char **linespecp, const char *const *keywords)
895 const char *s = *linespecp;
896 const char *const *csp;
898 for (csp = keywords; *csp; csp++)
900 const char *keyword = *csp;
901 size_t len = strlen (keyword);
903 if (strncmp (s, keyword, len) == 0 && isspace (s[len]))
905 *linespecp += len + 1;
913 /* Implementation of `is_linespec' method for `struct probe_ops'. */
916 probe_any_is_linespec (const char **linespecp)
918 static const char *const keywords[] = { "-p", "-probe", NULL };
920 return probe_is_linespec_by_keyword (linespecp, keywords);
923 /* Dummy method used for `probe_ops_any'. */
926 probe_any_get_probes (VEC (probe_p) **probesp, struct objfile *objfile)
928 /* No probes can be provided by this dummy backend. */
931 /* Operations associated with a generic probe. */
933 const struct probe_ops probe_ops_any =
935 probe_any_is_linespec,
936 probe_any_get_probes,
939 /* See comments in probe.h. */
941 struct cmd_list_element **
942 info_probes_cmdlist_get (void)
944 static struct cmd_list_element *info_probes_cmdlist;
946 if (info_probes_cmdlist == NULL)
947 add_prefix_cmd ("probes", class_info, info_probes_command,
949 Show available static probes.\n\
950 Usage: info probes [all|TYPE [ARGS]]\n\
951 TYPE specifies the type of the probe, and can be one of the following:\n\
953 If you specify TYPE, there may be additional arguments needed by the\n\
955 If you do not specify any argument, or specify `all', then the command\n\
956 will show information about all types of probes."),
957 &info_probes_cmdlist, "info probes ",
958 0/*allow-unknown*/, &infolist);
960 return &info_probes_cmdlist;
965 /* This is called to compute the value of one of the $_probe_arg*
966 convenience variables. */
968 static struct value *
969 compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
972 struct frame_info *frame = get_selected_frame (_("No frame selected"));
973 CORE_ADDR pc = get_frame_pc (frame);
974 int sel = (int) (uintptr_t) data;
975 struct bound_probe pc_probe;
976 const struct sym_probe_fns *pc_probe_fns;
979 /* SEL == -1 means "_probe_argc". */
980 gdb_assert (sel >= -1);
982 pc_probe = find_probe_by_pc (pc);
983 if (pc_probe.probe == NULL)
984 error (_("No probe at PC %s"), core_addr_to_string (pc));
986 n_args = get_probe_argument_count (pc_probe.probe, frame);
988 return value_from_longest (builtin_type (arch)->builtin_int, n_args);
991 error (_("Invalid probe argument %d -- probe has %u arguments available"),
994 return evaluate_probe_argument (pc_probe.probe, sel, frame);
997 /* This is called to compile one of the $_probe_arg* convenience
998 variables into an agent expression. */
1001 compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
1002 struct axs_value *value, void *data)
1004 CORE_ADDR pc = expr->scope;
1005 int sel = (int) (uintptr_t) data;
1006 struct bound_probe pc_probe;
1007 const struct sym_probe_fns *pc_probe_fns;
1009 struct frame_info *frame = get_selected_frame (NULL);
1011 /* SEL == -1 means "_probe_argc". */
1012 gdb_assert (sel >= -1);
1014 pc_probe = find_probe_by_pc (pc);
1015 if (pc_probe.probe == NULL)
1016 error (_("No probe at PC %s"), core_addr_to_string (pc));
1018 n_args = get_probe_argument_count (pc_probe.probe, frame);
1022 value->kind = axs_rvalue;
1023 value->type = builtin_type (expr->gdbarch)->builtin_int;
1024 ax_const_l (expr, n_args);
1028 gdb_assert (sel >= 0);
1030 error (_("Invalid probe argument %d -- probe has %d arguments available"),
1033 pc_probe.probe->pops->compile_to_ax (pc_probe.probe, expr, value, sel);
1036 static const struct internalvar_funcs probe_funcs =
1044 VEC (probe_ops_cp) *all_probe_ops;
1046 void _initialize_probe (void);
1049 _initialize_probe (void)
1051 VEC_safe_push (probe_ops_cp, all_probe_ops, &probe_ops_any);
1053 create_internalvar_type_lazy ("_probe_argc", &probe_funcs,
1054 (void *) (uintptr_t) -1);
1055 create_internalvar_type_lazy ("_probe_arg0", &probe_funcs,
1056 (void *) (uintptr_t) 0);
1057 create_internalvar_type_lazy ("_probe_arg1", &probe_funcs,
1058 (void *) (uintptr_t) 1);
1059 create_internalvar_type_lazy ("_probe_arg2", &probe_funcs,
1060 (void *) (uintptr_t) 2);
1061 create_internalvar_type_lazy ("_probe_arg3", &probe_funcs,
1062 (void *) (uintptr_t) 3);
1063 create_internalvar_type_lazy ("_probe_arg4", &probe_funcs,
1064 (void *) (uintptr_t) 4);
1065 create_internalvar_type_lazy ("_probe_arg5", &probe_funcs,
1066 (void *) (uintptr_t) 5);
1067 create_internalvar_type_lazy ("_probe_arg6", &probe_funcs,
1068 (void *) (uintptr_t) 6);
1069 create_internalvar_type_lazy ("_probe_arg7", &probe_funcs,
1070 (void *) (uintptr_t) 7);
1071 create_internalvar_type_lazy ("_probe_arg8", &probe_funcs,
1072 (void *) (uintptr_t) 8);
1073 create_internalvar_type_lazy ("_probe_arg9", &probe_funcs,
1074 (void *) (uintptr_t) 9);
1075 create_internalvar_type_lazy ("_probe_arg10", &probe_funcs,
1076 (void *) (uintptr_t) 10);
1077 create_internalvar_type_lazy ("_probe_arg11", &probe_funcs,
1078 (void *) (uintptr_t) 11);
1080 add_cmd ("all", class_info, info_probes_command,
1082 Show information about all type of probes."),
1083 info_probes_cmdlist_get ());
1085 add_cmd ("probes", class_breakpoint, enable_probes_command, _("\
1087 Usage: enable probes [PROVIDER [NAME [OBJECT]]]\n\
1088 Each argument is a regular expression, used to select probes.\n\
1089 PROVIDER matches probe provider names.\n\
1090 NAME matches the probe names.\n\
1091 OBJECT matches the executable or shared library name.\n\
1092 If you do not specify any argument then the command will enable\n\
1093 all defined probes."),
1096 add_cmd ("probes", class_breakpoint, disable_probes_command, _("\
1098 Usage: disable probes [PROVIDER [NAME [OBJECT]]]\n\
1099 Each argument is a regular expression, used to select probes.\n\
1100 PROVIDER matches probe provider names.\n\
1101 NAME matches the probe names.\n\
1102 OBJECT matches the executable or shared library name.\n\
1103 If you do not specify any argument then the command will disable\n\
1104 all defined probes."),