1 /* Generic static probe support for GDB.
3 Copyright (C) 2012-2017 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"
39 #include "common/gdb_optional.h"
41 typedef struct bound_probe bound_probe_s;
42 DEF_VEC_O (bound_probe_s);
46 /* A helper for parse_probes that decodes a probe specification in
47 SEARCH_PSPACE. It appends matching SALs to RESULT. */
50 parse_probes_in_pspace (const struct probe_ops *probe_ops,
51 struct program_space *search_pspace,
52 const char *objfile_namestr,
55 struct symtabs_and_lines *result)
57 struct objfile *objfile;
59 ALL_PSPACE_OBJFILES (search_pspace, objfile)
61 VEC (probe_p) *probes;
65 if (!objfile->sf || !objfile->sf->sym_probe_fns)
69 && FILENAME_CMP (objfile_name (objfile), objfile_namestr) != 0
70 && FILENAME_CMP (lbasename (objfile_name (objfile)),
71 objfile_namestr) != 0)
74 probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
76 for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++)
78 struct symtab_and_line *sal;
80 if (probe_ops != &probe_ops_any && probe->pops != probe_ops)
83 if (provider && strcmp (probe->provider, provider) != 0)
86 if (strcmp (probe->name, name) != 0)
90 result->sals = XRESIZEVEC (struct symtab_and_line, result->sals,
92 sal = &result->sals[result->nelts - 1];
96 sal->pc = get_probe_address (probe, objfile);
98 sal->section = find_pc_overlay (sal->pc);
99 sal->pspace = search_pspace;
101 sal->objfile = objfile;
106 /* See definition in probe.h. */
108 struct symtabs_and_lines
109 parse_probes (const struct event_location *location,
110 struct program_space *search_pspace,
111 struct linespec_result *canonical)
114 char *objfile_namestr = NULL, *provider = NULL, *name, *p;
115 struct cleanup *cleanup;
116 struct symtabs_and_lines result;
117 const struct probe_ops *probe_ops;
118 const char *arg_start, *cs;
123 gdb_assert (event_location_type (location) == PROBE_LOCATION);
124 arg_start = get_probe_location (location);
127 probe_ops = probe_linespec_to_ops (&cs);
128 if (probe_ops == NULL)
129 error (_("'%s' is not a probe linespec"), arg_start);
132 arg = skip_spaces (arg);
134 error (_("argument to `%s' missing"), arg_start);
136 arg_end = skip_to_space (arg);
138 /* We make a copy here so we can write over parts with impunity. */
139 arg = savestring (arg, arg_end - arg);
140 cleanup = make_cleanup (xfree, arg);
142 /* Extract each word from the argument, separated by ":"s. */
143 p = strchr (arg, ':');
146 /* This is `-p name'. */
154 p = strchr (hold, ':');
157 /* This is `-p provider:name'. */
163 /* This is `-p objfile:provider:name'. */
165 objfile_namestr = arg;
172 error (_("no probe name specified"));
173 if (provider && *provider == '\0')
174 error (_("invalid provider name"));
175 if (objfile_namestr && *objfile_namestr == '\0')
176 error (_("invalid objfile name"));
178 if (search_pspace != NULL)
180 parse_probes_in_pspace (probe_ops, search_pspace, objfile_namestr,
181 provider, name, &result);
185 struct program_space *pspace;
188 parse_probes_in_pspace (probe_ops, pspace, objfile_namestr,
189 provider, name, &result);
192 if (result.nelts == 0)
194 throw_error (NOT_FOUND_ERROR,
195 _("No probe matching objfile=`%s', provider=`%s', name=`%s'"),
196 objfile_namestr ? objfile_namestr : _("<any>"),
197 provider ? provider : _("<any>"),
205 canon = savestring (arg_start, arg_end - arg_start);
206 make_cleanup (xfree, canon);
207 canonical->special_display = 1;
208 canonical->pre_expanded = 1;
209 canonical->location = new_probe_location (canon);
212 do_cleanups (cleanup);
217 /* See definition in probe.h. */
220 find_probes_in_objfile (struct objfile *objfile, const char *provider,
223 VEC (probe_p) *probes, *result = NULL;
227 if (!objfile->sf || !objfile->sf->sym_probe_fns)
230 probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
231 for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++)
233 if (strcmp (probe->provider, provider) != 0)
236 if (strcmp (probe->name, name) != 0)
239 VEC_safe_push (probe_p, result, probe);
245 /* See definition in probe.h. */
248 find_probe_by_pc (CORE_ADDR pc)
250 struct objfile *objfile;
251 struct bound_probe result;
253 result.objfile = NULL;
256 ALL_OBJFILES (objfile)
258 VEC (probe_p) *probes;
262 if (!objfile->sf || !objfile->sf->sym_probe_fns
263 || objfile->sect_index_text == -1)
266 /* If this proves too inefficient, we can replace with a hash. */
267 probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
268 for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++)
269 if (get_probe_address (probe, objfile) == pc)
271 result.objfile = objfile;
272 result.probe = probe;
282 /* Make a vector of probes matching OBJNAME, PROVIDER, and PROBE_NAME.
283 If POPS is not NULL, only probes of this certain probe_ops will match.
284 Each argument is a regexp, or NULL, which matches anything. */
286 static VEC (bound_probe_s) *
287 collect_probes (char *objname, char *provider, char *probe_name,
288 const struct probe_ops *pops)
290 struct objfile *objfile;
291 VEC (bound_probe_s) *result = NULL;
292 struct cleanup *cleanup;
293 gdb::optional<compiled_regex> obj_pat, prov_pat, probe_pat;
295 cleanup = make_cleanup (VEC_cleanup (bound_probe_s), &result);
297 if (provider != NULL)
298 prov_pat.emplace (provider, REG_NOSUB, _("Invalid provider regexp"));
299 if (probe_name != NULL)
300 probe_pat.emplace (probe_name, REG_NOSUB, _("Invalid probe regexp"));
302 obj_pat.emplace (objname, REG_NOSUB, _("Invalid object file regexp"));
304 ALL_OBJFILES (objfile)
306 VEC (probe_p) *probes;
310 if (! objfile->sf || ! objfile->sf->sym_probe_fns)
315 if (obj_pat->exec (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 && prov_pat->exec (probe->provider, 0, NULL, 0) != 0)
333 && probe_pat->exec (probe->name, 0, NULL, 0) != 0)
336 bound.objfile = objfile;
338 VEC_safe_push (bound_probe_s, result, &bound);
342 discard_cleanups (cleanup);
346 /* A qsort comparison function for bound_probe_s objects. */
349 compare_probes (const void *a, const void *b)
351 const struct bound_probe *pa = (const struct bound_probe *) a;
352 const struct bound_probe *pb = (const struct bound_probe *) b;
355 v = strcmp (pa->probe->provider, pb->probe->provider);
359 v = strcmp (pa->probe->name, pb->probe->name);
363 if (pa->probe->address < pb->probe->address)
365 if (pa->probe->address > pb->probe->address)
368 return strcmp (objfile_name (pa->objfile), objfile_name (pb->objfile));
371 /* Helper function that generate entries in the ui_out table being
372 crafted by `info_probes_for_ops'. */
375 gen_ui_out_table_header_info (VEC (bound_probe_s) *probes,
376 const struct probe_ops *p)
378 /* `headings' refers to the names of the columns when printing `info
380 VEC (info_probe_column_s) *headings = NULL;
382 info_probe_column_s *column;
383 size_t headings_size;
386 gdb_assert (p != NULL);
388 if (p->gen_info_probes_table_header == NULL
389 && p->gen_info_probes_table_values == NULL)
392 gdb_assert (p->gen_info_probes_table_header != NULL
393 && p->gen_info_probes_table_values != NULL);
395 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
396 p->gen_info_probes_table_header (&headings);
398 headings_size = VEC_length (info_probe_column_s, headings);
401 VEC_iterate (info_probe_column_s, headings, ix, column);
404 struct bound_probe *probe;
406 size_t size_max = strlen (column->print_name);
408 for (jx = 0; VEC_iterate (bound_probe_s, probes, jx, probe); ++jx)
410 /* `probe_fields' refers to the values of each new field that this
411 probe will display. */
412 VEC (const_char_ptr) *probe_fields = NULL;
417 if (probe->probe->pops != p)
420 c2 = make_cleanup (VEC_cleanup (const_char_ptr), &probe_fields);
421 p->gen_info_probes_table_values (probe->probe, &probe_fields);
423 gdb_assert (VEC_length (const_char_ptr, probe_fields)
426 for (kx = 0; VEC_iterate (const_char_ptr, probe_fields, kx, val);
429 /* It is valid to have a NULL value here, which means that the
430 backend does not have something to write and this particular
431 field should be skipped. */
435 size_max = std::max (strlen (val), size_max);
440 current_uiout->table_header (size_max, ui_left,
441 column->field_name, column->print_name);
447 /* Helper function to print not-applicable strings for all the extra
448 columns defined in a probe_ops. */
451 print_ui_out_not_applicables (const struct probe_ops *pops)
454 VEC (info_probe_column_s) *headings = NULL;
455 info_probe_column_s *column;
458 if (pops->gen_info_probes_table_header == NULL)
461 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
462 pops->gen_info_probes_table_header (&headings);
465 VEC_iterate (info_probe_column_s, headings, ix, column);
467 current_uiout->field_string (column->field_name, _("n/a"));
472 /* Helper function to print extra information about a probe and an objfile
473 represented by PROBE. */
476 print_ui_out_info (struct probe *probe)
480 /* `values' refers to the actual values of each new field in the output
481 of `info probe'. `headings' refers to the names of each new field. */
482 VEC (const_char_ptr) *values = NULL;
483 VEC (info_probe_column_s) *headings = NULL;
484 info_probe_column_s *column;
487 gdb_assert (probe != NULL);
488 gdb_assert (probe->pops != NULL);
490 if (probe->pops->gen_info_probes_table_header == NULL
491 && probe->pops->gen_info_probes_table_values == NULL)
494 gdb_assert (probe->pops->gen_info_probes_table_header != NULL
495 && probe->pops->gen_info_probes_table_values != NULL);
497 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
498 make_cleanup (VEC_cleanup (const_char_ptr), &values);
500 probe->pops->gen_info_probes_table_header (&headings);
501 probe->pops->gen_info_probes_table_values (probe, &values);
503 gdb_assert (VEC_length (info_probe_column_s, headings)
504 == VEC_length (const_char_ptr, values));
507 VEC_iterate (info_probe_column_s, headings, ix, column);
510 const char *val = VEC_index (const_char_ptr, values, j++);
513 current_uiout->field_skip (column->field_name);
515 current_uiout->field_string (column->field_name, val);
521 /* Helper function that returns the number of extra fields which POPS will
525 get_number_extra_fields (const struct probe_ops *pops)
527 VEC (info_probe_column_s) *headings = NULL;
531 if (pops->gen_info_probes_table_header == NULL)
534 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
535 pops->gen_info_probes_table_header (&headings);
537 n = VEC_length (info_probe_column_s, headings);
544 /* Helper function that returns 1 if there is a probe in PROBES
545 featuring the given POPS. It returns 0 otherwise. */
548 exists_probe_with_pops (VEC (bound_probe_s) *probes,
549 const struct probe_ops *pops)
551 struct bound_probe *probe;
554 for (ix = 0; VEC_iterate (bound_probe_s, probes, ix, probe); ++ix)
555 if (probe->probe->pops == pops)
561 /* Helper function that parses a probe linespec of the form [PROVIDER
562 [PROBE [OBJNAME]]] from the provided string STR. */
565 parse_probe_linespec (const char *str, char **provider,
566 char **probe_name, char **objname)
568 *probe_name = *objname = NULL;
570 *provider = extract_arg_const (&str);
571 if (*provider != NULL)
573 *probe_name = extract_arg_const (&str);
574 if (*probe_name != NULL)
575 *objname = extract_arg_const (&str);
579 /* See comment in probe.h. */
582 info_probes_for_ops (const char *arg, int from_tty,
583 const struct probe_ops *pops)
585 char *provider, *probe_name = NULL, *objname = NULL;
586 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
587 VEC (bound_probe_s) *probes;
589 int ui_out_extra_fields = 0;
591 size_t size_name = strlen ("Name");
592 size_t size_objname = strlen ("Object");
593 size_t size_provider = strlen ("Provider");
594 size_t size_type = strlen ("Type");
595 struct bound_probe *probe;
596 struct gdbarch *gdbarch = get_current_arch ();
598 parse_probe_linespec (arg, &provider, &probe_name, &objname);
599 make_cleanup (xfree, provider);
600 make_cleanup (xfree, probe_name);
601 make_cleanup (xfree, objname);
603 probes = collect_probes (objname, provider, probe_name, pops);
604 make_cleanup (VEC_cleanup (probe_p), &probes);
608 const struct probe_ops *po;
611 /* If the probe_ops is NULL, it means the user has requested a "simple"
612 `info probes', i.e., she wants to print all information about all
613 probes. For that, we have to identify how many extra fields we will
614 need to add in the ui_out table.
616 To do that, we iterate over all probe_ops, querying each one about
617 its extra fields, and incrementing `ui_out_extra_fields' to reflect
618 that number. But note that we ignore the probe_ops for which no probes
619 are defined with the given search criteria. */
621 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix)
622 if (exists_probe_with_pops (probes, po))
623 ui_out_extra_fields += get_number_extra_fields (po);
626 ui_out_extra_fields = get_number_extra_fields (pops);
628 make_cleanup_ui_out_table_begin_end (current_uiout,
629 5 + ui_out_extra_fields,
630 VEC_length (bound_probe_s, probes),
633 if (!VEC_empty (bound_probe_s, probes))
634 qsort (VEC_address (bound_probe_s, probes),
635 VEC_length (bound_probe_s, probes),
636 sizeof (bound_probe_s), compare_probes);
638 /* What's the size of an address in our architecture? */
639 size_addr = gdbarch_addr_bit (gdbarch) == 64 ? 18 : 10;
641 /* Determining the maximum size of each field (`type', `provider',
642 `name' and `objname'). */
643 for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
645 const char *probe_type = probe->probe->pops->type_name (probe->probe);
647 size_type = std::max (strlen (probe_type), size_type);
648 size_name = std::max (strlen (probe->probe->name), size_name);
649 size_provider = std::max (strlen (probe->probe->provider), size_provider);
650 size_objname = std::max (strlen (objfile_name (probe->objfile)),
654 current_uiout->table_header (size_type, ui_left, "type", _("Type"));
655 current_uiout->table_header (size_provider, ui_left, "provider",
657 current_uiout->table_header (size_name, ui_left, "name", _("Name"));
658 current_uiout->table_header (size_addr, ui_left, "addr", _("Where"));
662 const struct probe_ops *po;
665 /* We have to generate the table header for each new probe type
666 that we will print. Note that this excludes probe types not
667 having any defined probe with the search criteria. */
668 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix)
669 if (exists_probe_with_pops (probes, po))
670 gen_ui_out_table_header_info (probes, po);
673 gen_ui_out_table_header_info (probes, pops);
675 current_uiout->table_header (size_objname, ui_left, "object", _("Object"));
676 current_uiout->table_body ();
678 for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
680 const char *probe_type = probe->probe->pops->type_name (probe->probe);
682 ui_out_emit_tuple tuple_emitter (current_uiout, "probe");
684 current_uiout->field_string ("type",probe_type);
685 current_uiout->field_string ("provider", probe->probe->provider);
686 current_uiout->field_string ("name", probe->probe->name);
687 current_uiout->field_core_addr (
688 "addr", probe->probe->arch,
689 get_probe_address (probe->probe, probe->objfile));
693 const struct probe_ops *po;
696 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po);
698 if (probe->probe->pops == po)
699 print_ui_out_info (probe->probe);
700 else if (exists_probe_with_pops (probes, po))
701 print_ui_out_not_applicables (po);
704 print_ui_out_info (probe->probe);
706 current_uiout->field_string ("object",
707 objfile_name (probe->objfile));
708 current_uiout->text ("\n");
711 any_found = !VEC_empty (bound_probe_s, probes);
712 do_cleanups (cleanup);
715 current_uiout->message (_("No probes matched.\n"));
718 /* Implementation of the `info probes' command. */
721 info_probes_command (char *arg, int from_tty)
723 info_probes_for_ops (arg, from_tty, NULL);
726 /* Implementation of the `enable probes' command. */
729 enable_probes_command (char *arg, int from_tty)
731 char *provider, *probe_name = NULL, *objname = NULL;
732 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
733 VEC (bound_probe_s) *probes;
734 struct bound_probe *probe;
737 parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
738 make_cleanup (xfree, provider);
739 make_cleanup (xfree, probe_name);
740 make_cleanup (xfree, objname);
742 probes = collect_probes (objname, provider, probe_name, NULL);
743 if (VEC_empty (bound_probe_s, probes))
745 current_uiout->message (_("No probes matched.\n"));
746 do_cleanups (cleanup);
750 /* Enable the selected probes, provided their backends support the
751 notion of enabling a probe. */
752 for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
754 const struct probe_ops *pops = probe->probe->pops;
756 if (pops->enable_probe != NULL)
758 pops->enable_probe (probe->probe);
759 current_uiout->message (_("Probe %s:%s enabled.\n"),
760 probe->probe->provider, probe->probe->name);
763 current_uiout->message (_("Probe %s:%s cannot be enabled.\n"),
764 probe->probe->provider, probe->probe->name);
767 do_cleanups (cleanup);
770 /* Implementation of the `disable probes' command. */
773 disable_probes_command (char *arg, int from_tty)
775 char *provider, *probe_name = NULL, *objname = NULL;
776 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
777 VEC (bound_probe_s) *probes;
778 struct bound_probe *probe;
781 parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
782 make_cleanup (xfree, provider);
783 make_cleanup (xfree, probe_name);
784 make_cleanup (xfree, objname);
786 probes = collect_probes (objname, provider, probe_name, NULL /* pops */);
787 if (VEC_empty (bound_probe_s, probes))
789 current_uiout->message (_("No probes matched.\n"));
790 do_cleanups (cleanup);
794 /* Disable the selected probes, provided their backends support the
795 notion of enabling a probe. */
796 for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
798 const struct probe_ops *pops = probe->probe->pops;
800 if (pops->disable_probe != NULL)
802 pops->disable_probe (probe->probe);
803 current_uiout->message (_("Probe %s:%s disabled.\n"),
804 probe->probe->provider, probe->probe->name);
807 current_uiout->message (_("Probe %s:%s cannot be disabled.\n"),
808 probe->probe->provider, probe->probe->name);
811 do_cleanups (cleanup);
814 /* See comments in probe.h. */
817 get_probe_address (struct probe *probe, struct objfile *objfile)
819 return probe->pops->get_probe_address (probe, objfile);
822 /* See comments in probe.h. */
825 get_probe_argument_count (struct probe *probe, struct frame_info *frame)
827 return probe->pops->get_probe_argument_count (probe, frame);
830 /* See comments in probe.h. */
833 can_evaluate_probe_arguments (struct probe *probe)
835 return probe->pops->can_evaluate_probe_arguments (probe);
838 /* See comments in probe.h. */
841 evaluate_probe_argument (struct probe *probe, unsigned n,
842 struct frame_info *frame)
844 return probe->pops->evaluate_probe_argument (probe, n, frame);
847 /* See comments in probe.h. */
850 probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n)
852 struct bound_probe probe;
855 probe = find_probe_by_pc (get_frame_pc (frame));
859 n_args = get_probe_argument_count (probe.probe, frame);
863 return evaluate_probe_argument (probe.probe, n, frame);
866 /* See comment in probe.h. */
868 const struct probe_ops *
869 probe_linespec_to_ops (const char **linespecp)
872 const struct probe_ops *probe_ops;
874 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, probe_ops); ix++)
875 if (probe_ops->is_linespec (linespecp))
881 /* See comment in probe.h. */
884 probe_is_linespec_by_keyword (const char **linespecp, const char *const *keywords)
886 const char *s = *linespecp;
887 const char *const *csp;
889 for (csp = keywords; *csp; csp++)
891 const char *keyword = *csp;
892 size_t len = strlen (keyword);
894 if (strncmp (s, keyword, len) == 0 && isspace (s[len]))
896 *linespecp += len + 1;
904 /* Implementation of `is_linespec' method for `struct probe_ops'. */
907 probe_any_is_linespec (const char **linespecp)
909 static const char *const keywords[] = { "-p", "-probe", NULL };
911 return probe_is_linespec_by_keyword (linespecp, keywords);
914 /* Dummy method used for `probe_ops_any'. */
917 probe_any_get_probes (VEC (probe_p) **probesp, struct objfile *objfile)
919 /* No probes can be provided by this dummy backend. */
922 /* Operations associated with a generic probe. */
924 const struct probe_ops probe_ops_any =
926 probe_any_is_linespec,
927 probe_any_get_probes,
930 /* See comments in probe.h. */
932 struct cmd_list_element **
933 info_probes_cmdlist_get (void)
935 static struct cmd_list_element *info_probes_cmdlist;
937 if (info_probes_cmdlist == NULL)
938 add_prefix_cmd ("probes", class_info, info_probes_command,
940 Show available static probes.\n\
941 Usage: info probes [all|TYPE [ARGS]]\n\
942 TYPE specifies the type of the probe, and can be one of the following:\n\
944 If you specify TYPE, there may be additional arguments needed by the\n\
946 If you do not specify any argument, or specify `all', then the command\n\
947 will show information about all types of probes."),
948 &info_probes_cmdlist, "info probes ",
949 0/*allow-unknown*/, &infolist);
951 return &info_probes_cmdlist;
956 /* This is called to compute the value of one of the $_probe_arg*
957 convenience variables. */
959 static struct value *
960 compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
963 struct frame_info *frame = get_selected_frame (_("No frame selected"));
964 CORE_ADDR pc = get_frame_pc (frame);
965 int sel = (int) (uintptr_t) data;
966 struct bound_probe pc_probe;
967 const struct sym_probe_fns *pc_probe_fns;
970 /* SEL == -1 means "_probe_argc". */
971 gdb_assert (sel >= -1);
973 pc_probe = find_probe_by_pc (pc);
974 if (pc_probe.probe == NULL)
975 error (_("No probe at PC %s"), core_addr_to_string (pc));
977 n_args = get_probe_argument_count (pc_probe.probe, frame);
979 return value_from_longest (builtin_type (arch)->builtin_int, n_args);
982 error (_("Invalid probe argument %d -- probe has %u arguments available"),
985 return evaluate_probe_argument (pc_probe.probe, sel, frame);
988 /* This is called to compile one of the $_probe_arg* convenience
989 variables into an agent expression. */
992 compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
993 struct axs_value *value, void *data)
995 CORE_ADDR pc = expr->scope;
996 int sel = (int) (uintptr_t) data;
997 struct bound_probe pc_probe;
998 const struct sym_probe_fns *pc_probe_fns;
1000 struct frame_info *frame = get_selected_frame (NULL);
1002 /* SEL == -1 means "_probe_argc". */
1003 gdb_assert (sel >= -1);
1005 pc_probe = find_probe_by_pc (pc);
1006 if (pc_probe.probe == NULL)
1007 error (_("No probe at PC %s"), core_addr_to_string (pc));
1009 n_args = get_probe_argument_count (pc_probe.probe, frame);
1013 value->kind = axs_rvalue;
1014 value->type = builtin_type (expr->gdbarch)->builtin_int;
1015 ax_const_l (expr, n_args);
1019 gdb_assert (sel >= 0);
1021 error (_("Invalid probe argument %d -- probe has %d arguments available"),
1024 pc_probe.probe->pops->compile_to_ax (pc_probe.probe, expr, value, sel);
1027 static const struct internalvar_funcs probe_funcs =
1035 VEC (probe_ops_cp) *all_probe_ops;
1037 void _initialize_probe (void);
1040 _initialize_probe (void)
1042 VEC_safe_push (probe_ops_cp, all_probe_ops, &probe_ops_any);
1044 create_internalvar_type_lazy ("_probe_argc", &probe_funcs,
1045 (void *) (uintptr_t) -1);
1046 create_internalvar_type_lazy ("_probe_arg0", &probe_funcs,
1047 (void *) (uintptr_t) 0);
1048 create_internalvar_type_lazy ("_probe_arg1", &probe_funcs,
1049 (void *) (uintptr_t) 1);
1050 create_internalvar_type_lazy ("_probe_arg2", &probe_funcs,
1051 (void *) (uintptr_t) 2);
1052 create_internalvar_type_lazy ("_probe_arg3", &probe_funcs,
1053 (void *) (uintptr_t) 3);
1054 create_internalvar_type_lazy ("_probe_arg4", &probe_funcs,
1055 (void *) (uintptr_t) 4);
1056 create_internalvar_type_lazy ("_probe_arg5", &probe_funcs,
1057 (void *) (uintptr_t) 5);
1058 create_internalvar_type_lazy ("_probe_arg6", &probe_funcs,
1059 (void *) (uintptr_t) 6);
1060 create_internalvar_type_lazy ("_probe_arg7", &probe_funcs,
1061 (void *) (uintptr_t) 7);
1062 create_internalvar_type_lazy ("_probe_arg8", &probe_funcs,
1063 (void *) (uintptr_t) 8);
1064 create_internalvar_type_lazy ("_probe_arg9", &probe_funcs,
1065 (void *) (uintptr_t) 9);
1066 create_internalvar_type_lazy ("_probe_arg10", &probe_funcs,
1067 (void *) (uintptr_t) 10);
1068 create_internalvar_type_lazy ("_probe_arg11", &probe_funcs,
1069 (void *) (uintptr_t) 11);
1071 add_cmd ("all", class_info, info_probes_command,
1073 Show information about all type of probes."),
1074 info_probes_cmdlist_get ());
1076 add_cmd ("probes", class_breakpoint, enable_probes_command, _("\
1078 Usage: enable probes [PROVIDER [NAME [OBJECT]]]\n\
1079 Each argument is a regular expression, used to select probes.\n\
1080 PROVIDER matches probe provider names.\n\
1081 NAME matches the probe names.\n\
1082 OBJECT matches the executable or shared library name.\n\
1083 If you do not specify any argument then the command will enable\n\
1084 all defined probes."),
1087 add_cmd ("probes", class_breakpoint, disable_probes_command, _("\
1089 Usage: disable probes [PROVIDER [NAME [OBJECT]]]\n\
1090 Each argument is a regular expression, used to select probes.\n\
1091 PROVIDER matches probe provider names.\n\
1092 NAME matches the probe names.\n\
1093 OBJECT matches the executable or shared library name.\n\
1094 If you do not specify any argument then the command will disable\n\
1095 all defined probes."),