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 std::vector<symtab_and_line> *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 if (probe_ops != &probe_ops_any && probe->pops != probe_ops)
81 if (provider && strcmp (probe->provider, provider) != 0)
84 if (strcmp (probe->name, name) != 0)
88 sal.pc = get_probe_address (probe, objfile);
90 sal.section = find_pc_overlay (sal.pc);
91 sal.pspace = search_pspace;
93 sal.objfile = objfile;
95 result->push_back (std::move (sal));
100 /* See definition in probe.h. */
102 std::vector<symtab_and_line>
103 parse_probes (const struct event_location *location,
104 struct program_space *search_pspace,
105 struct linespec_result *canonical)
108 char *objfile_namestr = NULL, *provider = NULL, *name, *p;
109 struct cleanup *cleanup;
110 const struct probe_ops *probe_ops;
111 const char *arg_start, *cs;
113 gdb_assert (event_location_type (location) == PROBE_LOCATION);
114 arg_start = get_probe_location (location);
117 probe_ops = probe_linespec_to_ops (&cs);
118 if (probe_ops == NULL)
119 error (_("'%s' is not a probe linespec"), arg_start);
122 arg = skip_spaces (arg);
124 error (_("argument to `%s' missing"), arg_start);
126 arg_end = skip_to_space (arg);
128 /* We make a copy here so we can write over parts with impunity. */
129 arg = savestring (arg, arg_end - arg);
130 cleanup = make_cleanup (xfree, arg);
132 /* Extract each word from the argument, separated by ":"s. */
133 p = strchr (arg, ':');
136 /* This is `-p name'. */
144 p = strchr (hold, ':');
147 /* This is `-p provider:name'. */
153 /* This is `-p objfile:provider:name'. */
155 objfile_namestr = arg;
162 error (_("no probe name specified"));
163 if (provider && *provider == '\0')
164 error (_("invalid provider name"));
165 if (objfile_namestr && *objfile_namestr == '\0')
166 error (_("invalid objfile name"));
168 std::vector<symtab_and_line> result;
169 if (search_pspace != NULL)
171 parse_probes_in_pspace (probe_ops, search_pspace, objfile_namestr,
172 provider, name, &result);
176 struct program_space *pspace;
179 parse_probes_in_pspace (probe_ops, pspace, objfile_namestr,
180 provider, name, &result);
185 throw_error (NOT_FOUND_ERROR,
186 _("No probe matching objfile=`%s', provider=`%s', name=`%s'"),
187 objfile_namestr ? objfile_namestr : _("<any>"),
188 provider ? provider : _("<any>"),
196 canon = savestring (arg_start, arg_end - arg_start);
197 make_cleanup (xfree, canon);
198 canonical->special_display = 1;
199 canonical->pre_expanded = 1;
200 canonical->location = new_probe_location (canon);
203 do_cleanups (cleanup);
208 /* See definition in probe.h. */
211 find_probes_in_objfile (struct objfile *objfile, const char *provider,
214 VEC (probe_p) *probes, *result = NULL;
218 if (!objfile->sf || !objfile->sf->sym_probe_fns)
221 probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
222 for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++)
224 if (strcmp (probe->provider, provider) != 0)
227 if (strcmp (probe->name, name) != 0)
230 VEC_safe_push (probe_p, result, probe);
236 /* See definition in probe.h. */
239 find_probe_by_pc (CORE_ADDR pc)
241 struct objfile *objfile;
242 struct bound_probe result;
244 result.objfile = NULL;
247 ALL_OBJFILES (objfile)
249 VEC (probe_p) *probes;
253 if (!objfile->sf || !objfile->sf->sym_probe_fns
254 || objfile->sect_index_text == -1)
257 /* If this proves too inefficient, we can replace with a hash. */
258 probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
259 for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++)
260 if (get_probe_address (probe, objfile) == pc)
262 result.objfile = objfile;
263 result.probe = probe;
273 /* Make a vector of probes matching OBJNAME, PROVIDER, and PROBE_NAME.
274 If POPS is not NULL, only probes of this certain probe_ops will match.
275 Each argument is a regexp, or NULL, which matches anything. */
277 static VEC (bound_probe_s) *
278 collect_probes (char *objname, char *provider, char *probe_name,
279 const struct probe_ops *pops)
281 struct objfile *objfile;
282 VEC (bound_probe_s) *result = NULL;
283 struct cleanup *cleanup;
284 gdb::optional<compiled_regex> obj_pat, prov_pat, probe_pat;
286 cleanup = make_cleanup (VEC_cleanup (bound_probe_s), &result);
288 if (provider != NULL)
289 prov_pat.emplace (provider, REG_NOSUB, _("Invalid provider regexp"));
290 if (probe_name != NULL)
291 probe_pat.emplace (probe_name, REG_NOSUB, _("Invalid probe regexp"));
293 obj_pat.emplace (objname, REG_NOSUB, _("Invalid object file regexp"));
295 ALL_OBJFILES (objfile)
297 VEC (probe_p) *probes;
301 if (! objfile->sf || ! objfile->sf->sym_probe_fns)
306 if (obj_pat->exec (objfile_name (objfile), 0, NULL, 0) != 0)
310 probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
312 for (ix = 0; VEC_iterate (probe_p, probes, ix, probe); ix++)
314 struct bound_probe bound;
316 if (pops != NULL && probe->pops != pops)
320 && prov_pat->exec (probe->provider, 0, NULL, 0) != 0)
324 && probe_pat->exec (probe->name, 0, NULL, 0) != 0)
327 bound.objfile = objfile;
329 VEC_safe_push (bound_probe_s, result, &bound);
333 discard_cleanups (cleanup);
337 /* A qsort comparison function for bound_probe_s objects. */
340 compare_probes (const void *a, const void *b)
342 const struct bound_probe *pa = (const struct bound_probe *) a;
343 const struct bound_probe *pb = (const struct bound_probe *) b;
346 v = strcmp (pa->probe->provider, pb->probe->provider);
350 v = strcmp (pa->probe->name, pb->probe->name);
354 if (pa->probe->address < pb->probe->address)
356 if (pa->probe->address > pb->probe->address)
359 return strcmp (objfile_name (pa->objfile), objfile_name (pb->objfile));
362 /* Helper function that generate entries in the ui_out table being
363 crafted by `info_probes_for_ops'. */
366 gen_ui_out_table_header_info (VEC (bound_probe_s) *probes,
367 const struct probe_ops *p)
369 /* `headings' refers to the names of the columns when printing `info
371 VEC (info_probe_column_s) *headings = NULL;
373 info_probe_column_s *column;
374 size_t headings_size;
377 gdb_assert (p != NULL);
379 if (p->gen_info_probes_table_header == NULL
380 && p->gen_info_probes_table_values == NULL)
383 gdb_assert (p->gen_info_probes_table_header != NULL
384 && p->gen_info_probes_table_values != NULL);
386 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
387 p->gen_info_probes_table_header (&headings);
389 headings_size = VEC_length (info_probe_column_s, headings);
392 VEC_iterate (info_probe_column_s, headings, ix, column);
395 struct bound_probe *probe;
397 size_t size_max = strlen (column->print_name);
399 for (jx = 0; VEC_iterate (bound_probe_s, probes, jx, probe); ++jx)
401 /* `probe_fields' refers to the values of each new field that this
402 probe will display. */
403 VEC (const_char_ptr) *probe_fields = NULL;
408 if (probe->probe->pops != p)
411 c2 = make_cleanup (VEC_cleanup (const_char_ptr), &probe_fields);
412 p->gen_info_probes_table_values (probe->probe, &probe_fields);
414 gdb_assert (VEC_length (const_char_ptr, probe_fields)
417 for (kx = 0; VEC_iterate (const_char_ptr, probe_fields, kx, val);
420 /* It is valid to have a NULL value here, which means that the
421 backend does not have something to write and this particular
422 field should be skipped. */
426 size_max = std::max (strlen (val), size_max);
431 current_uiout->table_header (size_max, ui_left,
432 column->field_name, column->print_name);
438 /* Helper function to print not-applicable strings for all the extra
439 columns defined in a probe_ops. */
442 print_ui_out_not_applicables (const struct probe_ops *pops)
445 VEC (info_probe_column_s) *headings = NULL;
446 info_probe_column_s *column;
449 if (pops->gen_info_probes_table_header == NULL)
452 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
453 pops->gen_info_probes_table_header (&headings);
456 VEC_iterate (info_probe_column_s, headings, ix, column);
458 current_uiout->field_string (column->field_name, _("n/a"));
463 /* Helper function to print extra information about a probe and an objfile
464 represented by PROBE. */
467 print_ui_out_info (struct probe *probe)
471 /* `values' refers to the actual values of each new field in the output
472 of `info probe'. `headings' refers to the names of each new field. */
473 VEC (const_char_ptr) *values = NULL;
474 VEC (info_probe_column_s) *headings = NULL;
475 info_probe_column_s *column;
478 gdb_assert (probe != NULL);
479 gdb_assert (probe->pops != NULL);
481 if (probe->pops->gen_info_probes_table_header == NULL
482 && probe->pops->gen_info_probes_table_values == NULL)
485 gdb_assert (probe->pops->gen_info_probes_table_header != NULL
486 && probe->pops->gen_info_probes_table_values != NULL);
488 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
489 make_cleanup (VEC_cleanup (const_char_ptr), &values);
491 probe->pops->gen_info_probes_table_header (&headings);
492 probe->pops->gen_info_probes_table_values (probe, &values);
494 gdb_assert (VEC_length (info_probe_column_s, headings)
495 == VEC_length (const_char_ptr, values));
498 VEC_iterate (info_probe_column_s, headings, ix, column);
501 const char *val = VEC_index (const_char_ptr, values, j++);
504 current_uiout->field_skip (column->field_name);
506 current_uiout->field_string (column->field_name, val);
512 /* Helper function that returns the number of extra fields which POPS will
516 get_number_extra_fields (const struct probe_ops *pops)
518 VEC (info_probe_column_s) *headings = NULL;
522 if (pops->gen_info_probes_table_header == NULL)
525 c = make_cleanup (VEC_cleanup (info_probe_column_s), &headings);
526 pops->gen_info_probes_table_header (&headings);
528 n = VEC_length (info_probe_column_s, headings);
535 /* Helper function that returns 1 if there is a probe in PROBES
536 featuring the given POPS. It returns 0 otherwise. */
539 exists_probe_with_pops (VEC (bound_probe_s) *probes,
540 const struct probe_ops *pops)
542 struct bound_probe *probe;
545 for (ix = 0; VEC_iterate (bound_probe_s, probes, ix, probe); ++ix)
546 if (probe->probe->pops == pops)
552 /* Helper function that parses a probe linespec of the form [PROVIDER
553 [PROBE [OBJNAME]]] from the provided string STR. */
556 parse_probe_linespec (const char *str, char **provider,
557 char **probe_name, char **objname)
559 *probe_name = *objname = NULL;
561 *provider = extract_arg_const (&str);
562 if (*provider != NULL)
564 *probe_name = extract_arg_const (&str);
565 if (*probe_name != NULL)
566 *objname = extract_arg_const (&str);
570 /* See comment in probe.h. */
573 info_probes_for_ops (const char *arg, int from_tty,
574 const struct probe_ops *pops)
576 char *provider, *probe_name = NULL, *objname = NULL;
577 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
578 VEC (bound_probe_s) *probes;
580 int ui_out_extra_fields = 0;
582 size_t size_name = strlen ("Name");
583 size_t size_objname = strlen ("Object");
584 size_t size_provider = strlen ("Provider");
585 size_t size_type = strlen ("Type");
586 struct bound_probe *probe;
587 struct gdbarch *gdbarch = get_current_arch ();
589 parse_probe_linespec (arg, &provider, &probe_name, &objname);
590 make_cleanup (xfree, provider);
591 make_cleanup (xfree, probe_name);
592 make_cleanup (xfree, objname);
594 probes = collect_probes (objname, provider, probe_name, pops);
595 make_cleanup (VEC_cleanup (probe_p), &probes);
599 const struct probe_ops *po;
602 /* If the probe_ops is NULL, it means the user has requested a "simple"
603 `info probes', i.e., she wants to print all information about all
604 probes. For that, we have to identify how many extra fields we will
605 need to add in the ui_out table.
607 To do that, we iterate over all probe_ops, querying each one about
608 its extra fields, and incrementing `ui_out_extra_fields' to reflect
609 that number. But note that we ignore the probe_ops for which no probes
610 are defined with the given search criteria. */
612 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix)
613 if (exists_probe_with_pops (probes, po))
614 ui_out_extra_fields += get_number_extra_fields (po);
617 ui_out_extra_fields = get_number_extra_fields (pops);
620 ui_out_emit_table table_emitter (current_uiout,
621 5 + ui_out_extra_fields,
622 VEC_length (bound_probe_s, probes),
625 if (!VEC_empty (bound_probe_s, probes))
626 qsort (VEC_address (bound_probe_s, probes),
627 VEC_length (bound_probe_s, probes),
628 sizeof (bound_probe_s), compare_probes);
630 /* What's the size of an address in our architecture? */
631 size_addr = gdbarch_addr_bit (gdbarch) == 64 ? 18 : 10;
633 /* Determining the maximum size of each field (`type', `provider',
634 `name' and `objname'). */
635 for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
637 const char *probe_type = probe->probe->pops->type_name (probe->probe);
639 size_type = std::max (strlen (probe_type), size_type);
640 size_name = std::max (strlen (probe->probe->name), size_name);
641 size_provider = std::max (strlen (probe->probe->provider), size_provider);
642 size_objname = std::max (strlen (objfile_name (probe->objfile)),
646 current_uiout->table_header (size_type, ui_left, "type", _("Type"));
647 current_uiout->table_header (size_provider, ui_left, "provider",
649 current_uiout->table_header (size_name, ui_left, "name", _("Name"));
650 current_uiout->table_header (size_addr, ui_left, "addr", _("Where"));
654 const struct probe_ops *po;
657 /* We have to generate the table header for each new probe type
658 that we will print. Note that this excludes probe types not
659 having any defined probe with the search criteria. */
660 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po); ++ix)
661 if (exists_probe_with_pops (probes, po))
662 gen_ui_out_table_header_info (probes, po);
665 gen_ui_out_table_header_info (probes, pops);
667 current_uiout->table_header (size_objname, ui_left, "object", _("Object"));
668 current_uiout->table_body ();
670 for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
672 const char *probe_type = probe->probe->pops->type_name (probe->probe);
674 ui_out_emit_tuple tuple_emitter (current_uiout, "probe");
676 current_uiout->field_string ("type",probe_type);
677 current_uiout->field_string ("provider", probe->probe->provider);
678 current_uiout->field_string ("name", probe->probe->name);
679 current_uiout->field_core_addr (
680 "addr", probe->probe->arch,
681 get_probe_address (probe->probe, probe->objfile));
685 const struct probe_ops *po;
688 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, po);
690 if (probe->probe->pops == po)
691 print_ui_out_info (probe->probe);
692 else if (exists_probe_with_pops (probes, po))
693 print_ui_out_not_applicables (po);
696 print_ui_out_info (probe->probe);
698 current_uiout->field_string ("object",
699 objfile_name (probe->objfile));
700 current_uiout->text ("\n");
703 any_found = !VEC_empty (bound_probe_s, probes);
705 do_cleanups (cleanup);
708 current_uiout->message (_("No probes matched.\n"));
711 /* Implementation of the `info probes' command. */
714 info_probes_command (char *arg, int from_tty)
716 info_probes_for_ops (arg, from_tty, NULL);
719 /* Implementation of the `enable probes' command. */
722 enable_probes_command (char *arg, int from_tty)
724 char *provider, *probe_name = NULL, *objname = NULL;
725 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
726 VEC (bound_probe_s) *probes;
727 struct bound_probe *probe;
730 parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
731 make_cleanup (xfree, provider);
732 make_cleanup (xfree, probe_name);
733 make_cleanup (xfree, objname);
735 probes = collect_probes (objname, provider, probe_name, NULL);
736 if (VEC_empty (bound_probe_s, probes))
738 current_uiout->message (_("No probes matched.\n"));
739 do_cleanups (cleanup);
743 /* Enable the selected probes, provided their backends support the
744 notion of enabling a probe. */
745 for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
747 const struct probe_ops *pops = probe->probe->pops;
749 if (pops->enable_probe != NULL)
751 pops->enable_probe (probe->probe);
752 current_uiout->message (_("Probe %s:%s enabled.\n"),
753 probe->probe->provider, probe->probe->name);
756 current_uiout->message (_("Probe %s:%s cannot be enabled.\n"),
757 probe->probe->provider, probe->probe->name);
760 do_cleanups (cleanup);
763 /* Implementation of the `disable probes' command. */
766 disable_probes_command (char *arg, int from_tty)
768 char *provider, *probe_name = NULL, *objname = NULL;
769 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
770 VEC (bound_probe_s) *probes;
771 struct bound_probe *probe;
774 parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
775 make_cleanup (xfree, provider);
776 make_cleanup (xfree, probe_name);
777 make_cleanup (xfree, objname);
779 probes = collect_probes (objname, provider, probe_name, NULL /* pops */);
780 if (VEC_empty (bound_probe_s, probes))
782 current_uiout->message (_("No probes matched.\n"));
783 do_cleanups (cleanup);
787 /* Disable the selected probes, provided their backends support the
788 notion of enabling a probe. */
789 for (i = 0; VEC_iterate (bound_probe_s, probes, i, probe); ++i)
791 const struct probe_ops *pops = probe->probe->pops;
793 if (pops->disable_probe != NULL)
795 pops->disable_probe (probe->probe);
796 current_uiout->message (_("Probe %s:%s disabled.\n"),
797 probe->probe->provider, probe->probe->name);
800 current_uiout->message (_("Probe %s:%s cannot be disabled.\n"),
801 probe->probe->provider, probe->probe->name);
804 do_cleanups (cleanup);
807 /* See comments in probe.h. */
810 get_probe_address (struct probe *probe, struct objfile *objfile)
812 return probe->pops->get_probe_address (probe, objfile);
815 /* See comments in probe.h. */
818 get_probe_argument_count (struct probe *probe, struct frame_info *frame)
820 return probe->pops->get_probe_argument_count (probe, frame);
823 /* See comments in probe.h. */
826 can_evaluate_probe_arguments (struct probe *probe)
828 return probe->pops->can_evaluate_probe_arguments (probe);
831 /* See comments in probe.h. */
834 evaluate_probe_argument (struct probe *probe, unsigned n,
835 struct frame_info *frame)
837 return probe->pops->evaluate_probe_argument (probe, n, frame);
840 /* See comments in probe.h. */
843 probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n)
845 struct bound_probe probe;
848 probe = find_probe_by_pc (get_frame_pc (frame));
852 n_args = get_probe_argument_count (probe.probe, frame);
856 return evaluate_probe_argument (probe.probe, n, frame);
859 /* See comment in probe.h. */
861 const struct probe_ops *
862 probe_linespec_to_ops (const char **linespecp)
865 const struct probe_ops *probe_ops;
867 for (ix = 0; VEC_iterate (probe_ops_cp, all_probe_ops, ix, probe_ops); ix++)
868 if (probe_ops->is_linespec (linespecp))
874 /* See comment in probe.h. */
877 probe_is_linespec_by_keyword (const char **linespecp, const char *const *keywords)
879 const char *s = *linespecp;
880 const char *const *csp;
882 for (csp = keywords; *csp; csp++)
884 const char *keyword = *csp;
885 size_t len = strlen (keyword);
887 if (strncmp (s, keyword, len) == 0 && isspace (s[len]))
889 *linespecp += len + 1;
897 /* Implementation of `is_linespec' method for `struct probe_ops'. */
900 probe_any_is_linespec (const char **linespecp)
902 static const char *const keywords[] = { "-p", "-probe", NULL };
904 return probe_is_linespec_by_keyword (linespecp, keywords);
907 /* Dummy method used for `probe_ops_any'. */
910 probe_any_get_probes (VEC (probe_p) **probesp, struct objfile *objfile)
912 /* No probes can be provided by this dummy backend. */
915 /* Operations associated with a generic probe. */
917 const struct probe_ops probe_ops_any =
919 probe_any_is_linespec,
920 probe_any_get_probes,
923 /* See comments in probe.h. */
925 struct cmd_list_element **
926 info_probes_cmdlist_get (void)
928 static struct cmd_list_element *info_probes_cmdlist;
930 if (info_probes_cmdlist == NULL)
931 add_prefix_cmd ("probes", class_info, info_probes_command,
933 Show available static probes.\n\
934 Usage: info probes [all|TYPE [ARGS]]\n\
935 TYPE specifies the type of the probe, and can be one of the following:\n\
937 If you specify TYPE, there may be additional arguments needed by the\n\
939 If you do not specify any argument, or specify `all', then the command\n\
940 will show information about all types of probes."),
941 &info_probes_cmdlist, "info probes ",
942 0/*allow-unknown*/, &infolist);
944 return &info_probes_cmdlist;
949 /* This is called to compute the value of one of the $_probe_arg*
950 convenience variables. */
952 static struct value *
953 compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
956 struct frame_info *frame = get_selected_frame (_("No frame selected"));
957 CORE_ADDR pc = get_frame_pc (frame);
958 int sel = (int) (uintptr_t) data;
959 struct bound_probe pc_probe;
960 const struct sym_probe_fns *pc_probe_fns;
963 /* SEL == -1 means "_probe_argc". */
964 gdb_assert (sel >= -1);
966 pc_probe = find_probe_by_pc (pc);
967 if (pc_probe.probe == NULL)
968 error (_("No probe at PC %s"), core_addr_to_string (pc));
970 n_args = get_probe_argument_count (pc_probe.probe, frame);
972 return value_from_longest (builtin_type (arch)->builtin_int, n_args);
975 error (_("Invalid probe argument %d -- probe has %u arguments available"),
978 return evaluate_probe_argument (pc_probe.probe, sel, frame);
981 /* This is called to compile one of the $_probe_arg* convenience
982 variables into an agent expression. */
985 compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
986 struct axs_value *value, void *data)
988 CORE_ADDR pc = expr->scope;
989 int sel = (int) (uintptr_t) data;
990 struct bound_probe pc_probe;
991 const struct sym_probe_fns *pc_probe_fns;
993 struct frame_info *frame = get_selected_frame (NULL);
995 /* SEL == -1 means "_probe_argc". */
996 gdb_assert (sel >= -1);
998 pc_probe = find_probe_by_pc (pc);
999 if (pc_probe.probe == NULL)
1000 error (_("No probe at PC %s"), core_addr_to_string (pc));
1002 n_args = get_probe_argument_count (pc_probe.probe, frame);
1006 value->kind = axs_rvalue;
1007 value->type = builtin_type (expr->gdbarch)->builtin_int;
1008 ax_const_l (expr, n_args);
1012 gdb_assert (sel >= 0);
1014 error (_("Invalid probe argument %d -- probe has %d arguments available"),
1017 pc_probe.probe->pops->compile_to_ax (pc_probe.probe, expr, value, sel);
1020 static const struct internalvar_funcs probe_funcs =
1028 VEC (probe_ops_cp) *all_probe_ops;
1031 _initialize_probe (void)
1033 VEC_safe_push (probe_ops_cp, all_probe_ops, &probe_ops_any);
1035 create_internalvar_type_lazy ("_probe_argc", &probe_funcs,
1036 (void *) (uintptr_t) -1);
1037 create_internalvar_type_lazy ("_probe_arg0", &probe_funcs,
1038 (void *) (uintptr_t) 0);
1039 create_internalvar_type_lazy ("_probe_arg1", &probe_funcs,
1040 (void *) (uintptr_t) 1);
1041 create_internalvar_type_lazy ("_probe_arg2", &probe_funcs,
1042 (void *) (uintptr_t) 2);
1043 create_internalvar_type_lazy ("_probe_arg3", &probe_funcs,
1044 (void *) (uintptr_t) 3);
1045 create_internalvar_type_lazy ("_probe_arg4", &probe_funcs,
1046 (void *) (uintptr_t) 4);
1047 create_internalvar_type_lazy ("_probe_arg5", &probe_funcs,
1048 (void *) (uintptr_t) 5);
1049 create_internalvar_type_lazy ("_probe_arg6", &probe_funcs,
1050 (void *) (uintptr_t) 6);
1051 create_internalvar_type_lazy ("_probe_arg7", &probe_funcs,
1052 (void *) (uintptr_t) 7);
1053 create_internalvar_type_lazy ("_probe_arg8", &probe_funcs,
1054 (void *) (uintptr_t) 8);
1055 create_internalvar_type_lazy ("_probe_arg9", &probe_funcs,
1056 (void *) (uintptr_t) 9);
1057 create_internalvar_type_lazy ("_probe_arg10", &probe_funcs,
1058 (void *) (uintptr_t) 10);
1059 create_internalvar_type_lazy ("_probe_arg11", &probe_funcs,
1060 (void *) (uintptr_t) 11);
1062 add_cmd ("all", class_info, info_probes_command,
1064 Show information about all type of probes."),
1065 info_probes_cmdlist_get ());
1067 add_cmd ("probes", class_breakpoint, enable_probes_command, _("\
1069 Usage: enable probes [PROVIDER [NAME [OBJECT]]]\n\
1070 Each argument is a regular expression, used to select probes.\n\
1071 PROVIDER matches probe provider names.\n\
1072 NAME matches the probe names.\n\
1073 OBJECT matches the executable or shared library name.\n\
1074 If you do not specify any argument then the command will enable\n\
1075 all defined probes."),
1078 add_cmd ("probes", class_breakpoint, disable_probes_command, _("\
1080 Usage: disable probes [PROVIDER [NAME [OBJECT]]]\n\
1081 Each argument is a regular expression, used to select probes.\n\
1082 PROVIDER matches probe provider names.\n\
1083 NAME matches the probe names.\n\
1084 OBJECT matches the executable or shared library name.\n\
1085 If you do not specify any argument then the command will disable\n\
1086 all defined probes."),