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 if (!objfile
->sf
|| !objfile
->sf
->sym_probe_fns
)
65 && FILENAME_CMP (objfile_name (objfile
), objfile_namestr
) != 0
66 && FILENAME_CMP (lbasename (objfile_name (objfile
)),
67 objfile_namestr
) != 0)
70 const std::vector
<probe
*> &probes
71 = objfile
->sf
->sym_probe_fns
->sym_get_probes (objfile
);
73 for (struct probe
*probe
: probes
)
75 if (probe_ops
!= &probe_ops_any
&& probe
->pops
!= probe_ops
)
78 if (provider
&& strcmp (probe
->provider
, provider
) != 0)
81 if (strcmp (probe
->name
, name
) != 0)
85 sal
.pc
= get_probe_address (probe
, objfile
);
87 sal
.section
= find_pc_overlay (sal
.pc
);
88 sal
.pspace
= search_pspace
;
90 sal
.objfile
= objfile
;
92 result
->push_back (std::move (sal
));
97 /* See definition in probe.h. */
99 std::vector
<symtab_and_line
>
100 parse_probes (const struct event_location
*location
,
101 struct program_space
*search_pspace
,
102 struct linespec_result
*canonical
)
105 char *objfile_namestr
= NULL
, *provider
= NULL
, *name
, *p
;
106 struct cleanup
*cleanup
;
107 const struct probe_ops
*probe_ops
;
108 const char *arg_start
, *cs
;
110 gdb_assert (event_location_type (location
) == PROBE_LOCATION
);
111 arg_start
= get_probe_location (location
);
114 probe_ops
= probe_linespec_to_ops (&cs
);
115 if (probe_ops
== NULL
)
116 error (_("'%s' is not a probe linespec"), arg_start
);
119 arg
= skip_spaces (arg
);
121 error (_("argument to `%s' missing"), arg_start
);
123 arg_end
= skip_to_space (arg
);
125 /* We make a copy here so we can write over parts with impunity. */
126 arg
= savestring (arg
, arg_end
- arg
);
127 cleanup
= make_cleanup (xfree
, arg
);
129 /* Extract each word from the argument, separated by ":"s. */
130 p
= strchr (arg
, ':');
133 /* This is `-p name'. */
141 p
= strchr (hold
, ':');
144 /* This is `-p provider:name'. */
150 /* This is `-p objfile:provider:name'. */
152 objfile_namestr
= arg
;
159 error (_("no probe name specified"));
160 if (provider
&& *provider
== '\0')
161 error (_("invalid provider name"));
162 if (objfile_namestr
&& *objfile_namestr
== '\0')
163 error (_("invalid objfile name"));
165 std::vector
<symtab_and_line
> result
;
166 if (search_pspace
!= NULL
)
168 parse_probes_in_pspace (probe_ops
, search_pspace
, objfile_namestr
,
169 provider
, name
, &result
);
173 struct program_space
*pspace
;
176 parse_probes_in_pspace (probe_ops
, pspace
, objfile_namestr
,
177 provider
, name
, &result
);
182 throw_error (NOT_FOUND_ERROR
,
183 _("No probe matching objfile=`%s', provider=`%s', name=`%s'"),
184 objfile_namestr
? objfile_namestr
: _("<any>"),
185 provider
? provider
: _("<any>"),
193 canon
= savestring (arg_start
, arg_end
- arg_start
);
194 make_cleanup (xfree
, canon
);
195 canonical
->special_display
= 1;
196 canonical
->pre_expanded
= 1;
197 canonical
->location
= new_probe_location (canon
);
200 do_cleanups (cleanup
);
205 /* See definition in probe.h. */
208 find_probes_in_objfile (struct objfile
*objfile
, const char *provider
,
211 VEC (probe_p
) *result
= NULL
;
213 if (!objfile
->sf
|| !objfile
->sf
->sym_probe_fns
)
216 const std::vector
<probe
*> &probes
217 = objfile
->sf
->sym_probe_fns
->sym_get_probes (objfile
);
218 for (struct probe
*probe
: probes
)
220 if (strcmp (probe
->provider
, provider
) != 0)
223 if (strcmp (probe
->name
, name
) != 0)
226 VEC_safe_push (probe_p
, result
, probe
);
232 /* See definition in probe.h. */
235 find_probe_by_pc (CORE_ADDR pc
)
237 struct objfile
*objfile
;
238 struct bound_probe result
;
240 result
.objfile
= NULL
;
243 ALL_OBJFILES (objfile
)
245 if (!objfile
->sf
|| !objfile
->sf
->sym_probe_fns
246 || objfile
->sect_index_text
== -1)
249 /* If this proves too inefficient, we can replace with a hash. */
250 const std::vector
<probe
*> &probes
251 = objfile
->sf
->sym_probe_fns
->sym_get_probes (objfile
);
252 for (struct probe
*probe
: probes
)
253 if (get_probe_address (probe
, objfile
) == pc
)
255 result
.objfile
= objfile
;
256 result
.probe
= probe
;
266 /* Make a vector of probes matching OBJNAME, PROVIDER, and PROBE_NAME.
267 If POPS is not NULL, only probes of this certain probe_ops will match.
268 Each argument is a regexp, or NULL, which matches anything. */
270 static VEC (bound_probe_s
) *
271 collect_probes (const std::string
&objname
, const std::string
&provider
,
272 const std::string
&probe_name
, const struct probe_ops
*pops
)
274 struct objfile
*objfile
;
275 VEC (bound_probe_s
) *result
= NULL
;
276 struct cleanup
*cleanup
;
277 gdb::optional
<compiled_regex
> obj_pat
, prov_pat
, probe_pat
;
279 cleanup
= make_cleanup (VEC_cleanup (bound_probe_s
), &result
);
281 if (!provider
.empty ())
282 prov_pat
.emplace (provider
.c_str (), REG_NOSUB
,
283 _("Invalid provider regexp"));
284 if (!probe_name
.empty ())
285 probe_pat
.emplace (probe_name
.c_str (), REG_NOSUB
,
286 _("Invalid probe regexp"));
287 if (!objname
.empty ())
288 obj_pat
.emplace (objname
.c_str (), REG_NOSUB
,
289 _("Invalid object file regexp"));
291 ALL_OBJFILES (objfile
)
293 if (! objfile
->sf
|| ! objfile
->sf
->sym_probe_fns
)
298 if (obj_pat
->exec (objfile_name (objfile
), 0, NULL
, 0) != 0)
302 const std::vector
<probe
*> &probes
303 = objfile
->sf
->sym_probe_fns
->sym_get_probes (objfile
);
305 for (struct probe
*probe
: probes
)
307 struct bound_probe bound
;
309 if (pops
!= NULL
&& probe
->pops
!= pops
)
313 && prov_pat
->exec (probe
->provider
, 0, NULL
, 0) != 0)
317 && probe_pat
->exec (probe
->name
, 0, NULL
, 0) != 0)
320 bound
.objfile
= objfile
;
322 VEC_safe_push (bound_probe_s
, result
, &bound
);
326 discard_cleanups (cleanup
);
330 /* A qsort comparison function for bound_probe_s objects. */
333 compare_probes (const void *a
, const void *b
)
335 const struct bound_probe
*pa
= (const struct bound_probe
*) a
;
336 const struct bound_probe
*pb
= (const struct bound_probe
*) b
;
339 v
= strcmp (pa
->probe
->provider
, pb
->probe
->provider
);
343 v
= strcmp (pa
->probe
->name
, pb
->probe
->name
);
347 if (pa
->probe
->address
< pb
->probe
->address
)
349 if (pa
->probe
->address
> pb
->probe
->address
)
352 return strcmp (objfile_name (pa
->objfile
), objfile_name (pb
->objfile
));
355 /* Helper function that generate entries in the ui_out table being
356 crafted by `info_probes_for_ops'. */
359 gen_ui_out_table_header_info (VEC (bound_probe_s
) *probes
,
360 const struct probe_ops
*p
)
362 /* `headings' refers to the names of the columns when printing `info
364 VEC (info_probe_column_s
) *headings
= NULL
;
366 info_probe_column_s
*column
;
367 size_t headings_size
;
370 gdb_assert (p
!= NULL
);
372 if (p
->gen_info_probes_table_header
== NULL
373 && p
->gen_info_probes_table_values
== NULL
)
376 gdb_assert (p
->gen_info_probes_table_header
!= NULL
377 && p
->gen_info_probes_table_values
!= NULL
);
379 c
= make_cleanup (VEC_cleanup (info_probe_column_s
), &headings
);
380 p
->gen_info_probes_table_header (&headings
);
382 headings_size
= VEC_length (info_probe_column_s
, headings
);
385 VEC_iterate (info_probe_column_s
, headings
, ix
, column
);
388 struct bound_probe
*probe
;
390 size_t size_max
= strlen (column
->print_name
);
392 for (jx
= 0; VEC_iterate (bound_probe_s
, probes
, jx
, probe
); ++jx
)
394 /* `probe_fields' refers to the values of each new field that this
395 probe will display. */
396 VEC (const_char_ptr
) *probe_fields
= NULL
;
401 if (probe
->probe
->pops
!= p
)
404 c2
= make_cleanup (VEC_cleanup (const_char_ptr
), &probe_fields
);
405 p
->gen_info_probes_table_values (probe
->probe
, &probe_fields
);
407 gdb_assert (VEC_length (const_char_ptr
, probe_fields
)
410 for (kx
= 0; VEC_iterate (const_char_ptr
, probe_fields
, kx
, val
);
413 /* It is valid to have a NULL value here, which means that the
414 backend does not have something to write and this particular
415 field should be skipped. */
419 size_max
= std::max (strlen (val
), size_max
);
424 current_uiout
->table_header (size_max
, ui_left
,
425 column
->field_name
, column
->print_name
);
431 /* Helper function to print not-applicable strings for all the extra
432 columns defined in a probe_ops. */
435 print_ui_out_not_applicables (const struct probe_ops
*pops
)
438 VEC (info_probe_column_s
) *headings
= NULL
;
439 info_probe_column_s
*column
;
442 if (pops
->gen_info_probes_table_header
== NULL
)
445 c
= make_cleanup (VEC_cleanup (info_probe_column_s
), &headings
);
446 pops
->gen_info_probes_table_header (&headings
);
449 VEC_iterate (info_probe_column_s
, headings
, ix
, column
);
451 current_uiout
->field_string (column
->field_name
, _("n/a"));
456 /* Helper function to print extra information about a probe and an objfile
457 represented by PROBE. */
460 print_ui_out_info (struct probe
*probe
)
464 /* `values' refers to the actual values of each new field in the output
465 of `info probe'. `headings' refers to the names of each new field. */
466 VEC (const_char_ptr
) *values
= NULL
;
467 VEC (info_probe_column_s
) *headings
= NULL
;
468 info_probe_column_s
*column
;
471 gdb_assert (probe
!= NULL
);
472 gdb_assert (probe
->pops
!= NULL
);
474 if (probe
->pops
->gen_info_probes_table_header
== NULL
475 && probe
->pops
->gen_info_probes_table_values
== NULL
)
478 gdb_assert (probe
->pops
->gen_info_probes_table_header
!= NULL
479 && probe
->pops
->gen_info_probes_table_values
!= NULL
);
481 c
= make_cleanup (VEC_cleanup (info_probe_column_s
), &headings
);
482 make_cleanup (VEC_cleanup (const_char_ptr
), &values
);
484 probe
->pops
->gen_info_probes_table_header (&headings
);
485 probe
->pops
->gen_info_probes_table_values (probe
, &values
);
487 gdb_assert (VEC_length (info_probe_column_s
, headings
)
488 == VEC_length (const_char_ptr
, values
));
491 VEC_iterate (info_probe_column_s
, headings
, ix
, column
);
494 const char *val
= VEC_index (const_char_ptr
, values
, j
++);
497 current_uiout
->field_skip (column
->field_name
);
499 current_uiout
->field_string (column
->field_name
, val
);
505 /* Helper function that returns the number of extra fields which POPS will
509 get_number_extra_fields (const struct probe_ops
*pops
)
511 VEC (info_probe_column_s
) *headings
= NULL
;
515 if (pops
->gen_info_probes_table_header
== NULL
)
518 c
= make_cleanup (VEC_cleanup (info_probe_column_s
), &headings
);
519 pops
->gen_info_probes_table_header (&headings
);
521 n
= VEC_length (info_probe_column_s
, headings
);
528 /* Helper function that returns 1 if there is a probe in PROBES
529 featuring the given POPS. It returns 0 otherwise. */
532 exists_probe_with_pops (VEC (bound_probe_s
) *probes
,
533 const struct probe_ops
*pops
)
535 struct bound_probe
*probe
;
538 for (ix
= 0; VEC_iterate (bound_probe_s
, probes
, ix
, probe
); ++ix
)
539 if (probe
->probe
->pops
== pops
)
545 /* Helper function that parses a probe linespec of the form [PROVIDER
546 [PROBE [OBJNAME]]] from the provided string STR. */
549 parse_probe_linespec (const char *str
, std::string
*provider
,
550 std::string
*probe_name
, std::string
*objname
)
552 *probe_name
= *objname
= "";
554 *provider
= extract_arg (&str
);
555 if (!provider
->empty ())
557 *probe_name
= extract_arg (&str
);
558 if (!probe_name
->empty ())
559 *objname
= extract_arg (&str
);
563 /* See comment in probe.h. */
566 info_probes_for_ops (const char *arg
, int from_tty
,
567 const struct probe_ops
*pops
)
569 std::string provider
, probe_name
, objname
;
570 struct cleanup
*cleanup
= make_cleanup (null_cleanup
, NULL
);
571 VEC (bound_probe_s
) *probes
;
573 int ui_out_extra_fields
= 0;
575 size_t size_name
= strlen ("Name");
576 size_t size_objname
= strlen ("Object");
577 size_t size_provider
= strlen ("Provider");
578 size_t size_type
= strlen ("Type");
579 struct bound_probe
*probe
;
580 struct gdbarch
*gdbarch
= get_current_arch ();
582 parse_probe_linespec (arg
, &provider
, &probe_name
, &objname
);
584 probes
= collect_probes (objname
, provider
, probe_name
, pops
);
585 make_cleanup (VEC_cleanup (probe_p
), &probes
);
589 const struct probe_ops
*po
;
592 /* If the probe_ops is NULL, it means the user has requested a "simple"
593 `info probes', i.e., she wants to print all information about all
594 probes. For that, we have to identify how many extra fields we will
595 need to add in the ui_out table.
597 To do that, we iterate over all probe_ops, querying each one about
598 its extra fields, and incrementing `ui_out_extra_fields' to reflect
599 that number. But note that we ignore the probe_ops for which no probes
600 are defined with the given search criteria. */
602 for (ix
= 0; VEC_iterate (probe_ops_cp
, all_probe_ops
, ix
, po
); ++ix
)
603 if (exists_probe_with_pops (probes
, po
))
604 ui_out_extra_fields
+= get_number_extra_fields (po
);
607 ui_out_extra_fields
= get_number_extra_fields (pops
);
610 ui_out_emit_table
table_emitter (current_uiout
,
611 5 + ui_out_extra_fields
,
612 VEC_length (bound_probe_s
, probes
),
615 if (!VEC_empty (bound_probe_s
, probes
))
616 qsort (VEC_address (bound_probe_s
, probes
),
617 VEC_length (bound_probe_s
, probes
),
618 sizeof (bound_probe_s
), compare_probes
);
620 /* What's the size of an address in our architecture? */
621 size_addr
= gdbarch_addr_bit (gdbarch
) == 64 ? 18 : 10;
623 /* Determining the maximum size of each field (`type', `provider',
624 `name' and `objname'). */
625 for (i
= 0; VEC_iterate (bound_probe_s
, probes
, i
, probe
); ++i
)
627 const char *probe_type
= probe
->probe
->pops
->type_name (probe
->probe
);
629 size_type
= std::max (strlen (probe_type
), size_type
);
630 size_name
= std::max (strlen (probe
->probe
->name
), size_name
);
631 size_provider
= std::max (strlen (probe
->probe
->provider
), size_provider
);
632 size_objname
= std::max (strlen (objfile_name (probe
->objfile
)),
636 current_uiout
->table_header (size_type
, ui_left
, "type", _("Type"));
637 current_uiout
->table_header (size_provider
, ui_left
, "provider",
639 current_uiout
->table_header (size_name
, ui_left
, "name", _("Name"));
640 current_uiout
->table_header (size_addr
, ui_left
, "addr", _("Where"));
644 const struct probe_ops
*po
;
647 /* We have to generate the table header for each new probe type
648 that we will print. Note that this excludes probe types not
649 having any defined probe with the search criteria. */
650 for (ix
= 0; VEC_iterate (probe_ops_cp
, all_probe_ops
, ix
, po
); ++ix
)
651 if (exists_probe_with_pops (probes
, po
))
652 gen_ui_out_table_header_info (probes
, po
);
655 gen_ui_out_table_header_info (probes
, pops
);
657 current_uiout
->table_header (size_objname
, ui_left
, "object", _("Object"));
658 current_uiout
->table_body ();
660 for (i
= 0; VEC_iterate (bound_probe_s
, probes
, i
, probe
); ++i
)
662 const char *probe_type
= probe
->probe
->pops
->type_name (probe
->probe
);
664 ui_out_emit_tuple
tuple_emitter (current_uiout
, "probe");
666 current_uiout
->field_string ("type",probe_type
);
667 current_uiout
->field_string ("provider", probe
->probe
->provider
);
668 current_uiout
->field_string ("name", probe
->probe
->name
);
669 current_uiout
->field_core_addr (
670 "addr", probe
->probe
->arch
,
671 get_probe_address (probe
->probe
, probe
->objfile
));
675 const struct probe_ops
*po
;
678 for (ix
= 0; VEC_iterate (probe_ops_cp
, all_probe_ops
, ix
, po
);
680 if (probe
->probe
->pops
== po
)
681 print_ui_out_info (probe
->probe
);
682 else if (exists_probe_with_pops (probes
, po
))
683 print_ui_out_not_applicables (po
);
686 print_ui_out_info (probe
->probe
);
688 current_uiout
->field_string ("object",
689 objfile_name (probe
->objfile
));
690 current_uiout
->text ("\n");
693 any_found
= !VEC_empty (bound_probe_s
, probes
);
695 do_cleanups (cleanup
);
698 current_uiout
->message (_("No probes matched.\n"));
701 /* Implementation of the `info probes' command. */
704 info_probes_command (char *arg
, int from_tty
)
706 info_probes_for_ops (arg
, from_tty
, NULL
);
709 /* Implementation of the `enable probes' command. */
712 enable_probes_command (char *arg
, int from_tty
)
714 std::string provider
, probe_name
, objname
;
715 struct cleanup
*cleanup
= make_cleanup (null_cleanup
, NULL
);
716 VEC (bound_probe_s
) *probes
;
717 struct bound_probe
*probe
;
720 parse_probe_linespec ((const char *) arg
, &provider
, &probe_name
, &objname
);
722 probes
= collect_probes (objname
, provider
, probe_name
, NULL
);
723 if (VEC_empty (bound_probe_s
, probes
))
725 current_uiout
->message (_("No probes matched.\n"));
726 do_cleanups (cleanup
);
730 /* Enable the selected probes, provided their backends support the
731 notion of enabling a probe. */
732 for (i
= 0; VEC_iterate (bound_probe_s
, probes
, i
, probe
); ++i
)
734 const struct probe_ops
*pops
= probe
->probe
->pops
;
736 if (pops
->enable_probe
!= NULL
)
738 pops
->enable_probe (probe
->probe
);
739 current_uiout
->message (_("Probe %s:%s enabled.\n"),
740 probe
->probe
->provider
, probe
->probe
->name
);
743 current_uiout
->message (_("Probe %s:%s cannot be enabled.\n"),
744 probe
->probe
->provider
, probe
->probe
->name
);
747 do_cleanups (cleanup
);
750 /* Implementation of the `disable probes' command. */
753 disable_probes_command (char *arg
, int from_tty
)
755 std::string provider
, probe_name
, objname
;
756 struct cleanup
*cleanup
= make_cleanup (null_cleanup
, NULL
);
757 VEC (bound_probe_s
) *probes
;
758 struct bound_probe
*probe
;
761 parse_probe_linespec ((const char *) arg
, &provider
, &probe_name
, &objname
);
763 probes
= collect_probes (objname
, provider
, probe_name
, NULL
/* pops */);
764 if (VEC_empty (bound_probe_s
, probes
))
766 current_uiout
->message (_("No probes matched.\n"));
767 do_cleanups (cleanup
);
771 /* Disable the selected probes, provided their backends support the
772 notion of enabling a probe. */
773 for (i
= 0; VEC_iterate (bound_probe_s
, probes
, i
, probe
); ++i
)
775 const struct probe_ops
*pops
= probe
->probe
->pops
;
777 if (pops
->disable_probe
!= NULL
)
779 pops
->disable_probe (probe
->probe
);
780 current_uiout
->message (_("Probe %s:%s disabled.\n"),
781 probe
->probe
->provider
, probe
->probe
->name
);
784 current_uiout
->message (_("Probe %s:%s cannot be disabled.\n"),
785 probe
->probe
->provider
, probe
->probe
->name
);
788 do_cleanups (cleanup
);
791 /* See comments in probe.h. */
794 get_probe_address (struct probe
*probe
, struct objfile
*objfile
)
796 return probe
->pops
->get_probe_address (probe
, objfile
);
799 /* See comments in probe.h. */
802 get_probe_argument_count (struct probe
*probe
, struct frame_info
*frame
)
804 return probe
->pops
->get_probe_argument_count (probe
, frame
);
807 /* See comments in probe.h. */
810 can_evaluate_probe_arguments (struct probe
*probe
)
812 return probe
->pops
->can_evaluate_probe_arguments (probe
);
815 /* See comments in probe.h. */
818 evaluate_probe_argument (struct probe
*probe
, unsigned n
,
819 struct frame_info
*frame
)
821 return probe
->pops
->evaluate_probe_argument (probe
, n
, frame
);
824 /* See comments in probe.h. */
827 probe_safe_evaluate_at_pc (struct frame_info
*frame
, unsigned n
)
829 struct bound_probe probe
;
832 probe
= find_probe_by_pc (get_frame_pc (frame
));
836 n_args
= get_probe_argument_count (probe
.probe
, frame
);
840 return evaluate_probe_argument (probe
.probe
, n
, frame
);
843 /* See comment in probe.h. */
845 const struct probe_ops
*
846 probe_linespec_to_ops (const char **linespecp
)
849 const struct probe_ops
*probe_ops
;
851 for (ix
= 0; VEC_iterate (probe_ops_cp
, all_probe_ops
, ix
, probe_ops
); ix
++)
852 if (probe_ops
->is_linespec (linespecp
))
858 /* See comment in probe.h. */
861 probe_is_linespec_by_keyword (const char **linespecp
, const char *const *keywords
)
863 const char *s
= *linespecp
;
864 const char *const *csp
;
866 for (csp
= keywords
; *csp
; csp
++)
868 const char *keyword
= *csp
;
869 size_t len
= strlen (keyword
);
871 if (strncmp (s
, keyword
, len
) == 0 && isspace (s
[len
]))
873 *linespecp
+= len
+ 1;
881 /* Implementation of `is_linespec' method for `struct probe_ops'. */
884 probe_any_is_linespec (const char **linespecp
)
886 static const char *const keywords
[] = { "-p", "-probe", NULL
};
888 return probe_is_linespec_by_keyword (linespecp
, keywords
);
891 /* Dummy method used for `probe_ops_any'. */
894 probe_any_get_probes (std::vector
<probe
*> *probesp
, struct objfile
*objfile
)
896 /* No probes can be provided by this dummy backend. */
899 /* Operations associated with a generic probe. */
901 const struct probe_ops probe_ops_any
=
903 probe_any_is_linespec
,
904 probe_any_get_probes
,
907 /* See comments in probe.h. */
909 struct cmd_list_element
**
910 info_probes_cmdlist_get (void)
912 static struct cmd_list_element
*info_probes_cmdlist
;
914 if (info_probes_cmdlist
== NULL
)
915 add_prefix_cmd ("probes", class_info
, info_probes_command
,
917 Show available static probes.\n\
918 Usage: info probes [all|TYPE [ARGS]]\n\
919 TYPE specifies the type of the probe, and can be one of the following:\n\
921 If you specify TYPE, there may be additional arguments needed by the\n\
923 If you do not specify any argument, or specify `all', then the command\n\
924 will show information about all types of probes."),
925 &info_probes_cmdlist
, "info probes ",
926 0/*allow-unknown*/, &infolist
);
928 return &info_probes_cmdlist
;
933 /* This is called to compute the value of one of the $_probe_arg*
934 convenience variables. */
936 static struct value
*
937 compute_probe_arg (struct gdbarch
*arch
, struct internalvar
*ivar
,
940 struct frame_info
*frame
= get_selected_frame (_("No frame selected"));
941 CORE_ADDR pc
= get_frame_pc (frame
);
942 int sel
= (int) (uintptr_t) data
;
943 struct bound_probe pc_probe
;
944 const struct sym_probe_fns
*pc_probe_fns
;
947 /* SEL == -1 means "_probe_argc". */
948 gdb_assert (sel
>= -1);
950 pc_probe
= find_probe_by_pc (pc
);
951 if (pc_probe
.probe
== NULL
)
952 error (_("No probe at PC %s"), core_addr_to_string (pc
));
954 n_args
= get_probe_argument_count (pc_probe
.probe
, frame
);
956 return value_from_longest (builtin_type (arch
)->builtin_int
, n_args
);
959 error (_("Invalid probe argument %d -- probe has %u arguments available"),
962 return evaluate_probe_argument (pc_probe
.probe
, sel
, frame
);
965 /* This is called to compile one of the $_probe_arg* convenience
966 variables into an agent expression. */
969 compile_probe_arg (struct internalvar
*ivar
, struct agent_expr
*expr
,
970 struct axs_value
*value
, void *data
)
972 CORE_ADDR pc
= expr
->scope
;
973 int sel
= (int) (uintptr_t) data
;
974 struct bound_probe pc_probe
;
975 const struct sym_probe_fns
*pc_probe_fns
;
977 struct frame_info
*frame
= get_selected_frame (NULL
);
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
);
990 value
->kind
= axs_rvalue
;
991 value
->type
= builtin_type (expr
->gdbarch
)->builtin_int
;
992 ax_const_l (expr
, n_args
);
996 gdb_assert (sel
>= 0);
998 error (_("Invalid probe argument %d -- probe has %d arguments available"),
1001 pc_probe
.probe
->pops
->compile_to_ax (pc_probe
.probe
, expr
, value
, sel
);
1004 static const struct internalvar_funcs probe_funcs
=
1012 VEC (probe_ops_cp
) *all_probe_ops
;
1015 _initialize_probe (void)
1017 VEC_safe_push (probe_ops_cp
, all_probe_ops
, &probe_ops_any
);
1019 create_internalvar_type_lazy ("_probe_argc", &probe_funcs
,
1020 (void *) (uintptr_t) -1);
1021 create_internalvar_type_lazy ("_probe_arg0", &probe_funcs
,
1022 (void *) (uintptr_t) 0);
1023 create_internalvar_type_lazy ("_probe_arg1", &probe_funcs
,
1024 (void *) (uintptr_t) 1);
1025 create_internalvar_type_lazy ("_probe_arg2", &probe_funcs
,
1026 (void *) (uintptr_t) 2);
1027 create_internalvar_type_lazy ("_probe_arg3", &probe_funcs
,
1028 (void *) (uintptr_t) 3);
1029 create_internalvar_type_lazy ("_probe_arg4", &probe_funcs
,
1030 (void *) (uintptr_t) 4);
1031 create_internalvar_type_lazy ("_probe_arg5", &probe_funcs
,
1032 (void *) (uintptr_t) 5);
1033 create_internalvar_type_lazy ("_probe_arg6", &probe_funcs
,
1034 (void *) (uintptr_t) 6);
1035 create_internalvar_type_lazy ("_probe_arg7", &probe_funcs
,
1036 (void *) (uintptr_t) 7);
1037 create_internalvar_type_lazy ("_probe_arg8", &probe_funcs
,
1038 (void *) (uintptr_t) 8);
1039 create_internalvar_type_lazy ("_probe_arg9", &probe_funcs
,
1040 (void *) (uintptr_t) 9);
1041 create_internalvar_type_lazy ("_probe_arg10", &probe_funcs
,
1042 (void *) (uintptr_t) 10);
1043 create_internalvar_type_lazy ("_probe_arg11", &probe_funcs
,
1044 (void *) (uintptr_t) 11);
1046 add_cmd ("all", class_info
, info_probes_command
,
1048 Show information about all type of probes."),
1049 info_probes_cmdlist_get ());
1051 add_cmd ("probes", class_breakpoint
, enable_probes_command
, _("\
1053 Usage: enable probes [PROVIDER [NAME [OBJECT]]]\n\
1054 Each argument is a regular expression, used to select probes.\n\
1055 PROVIDER matches probe provider names.\n\
1056 NAME matches the probe names.\n\
1057 OBJECT matches the executable or shared library name.\n\
1058 If you do not specify any argument then the command will enable\n\
1059 all defined probes."),
1062 add_cmd ("probes", class_breakpoint
, disable_probes_command
, _("\
1064 Usage: disable probes [PROVIDER [NAME [OBJECT]]]\n\
1065 Each argument is a regular expression, used to select probes.\n\
1066 PROVIDER matches probe provider names.\n\
1067 NAME matches the probe names.\n\
1068 OBJECT matches the executable or shared library name.\n\
1069 If you do not specify any argument then the command will disable\n\
1070 all defined probes."),