GDB (xrefs)
Loading...
Searching...
No Matches
probe.c
Go to the documentation of this file.
1/* Generic static probe support for GDB.
2
3 Copyright (C) 2012-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "probe.h"
22#include "command.h"
23#include "cli/cli-cmds.h"
24#include "cli/cli-utils.h"
25#include "objfiles.h"
26#include "symtab.h"
27#include "progspace.h"
28#include "filenames.h"
29#include "linespec.h"
30#include "gdbsupport/gdb_regex.h"
31#include "frame.h"
32#include "arch-utils.h"
33#include "value.h"
34#include "ax.h"
35#include "ax-gdb.h"
36#include "location.h"
37#include <ctype.h>
38#include <algorithm>
39#include "gdbsupport/gdb_optional.h"
40
41/* Class that implements the static probe methods for "any" probe. */
42
44{
45public:
46 /* See probe.h. */
47 bool is_linespec (const char **linespecp) const override;
48
49 /* See probe.h. */
50 void get_probes (std::vector<std::unique_ptr<probe>> *probesp,
51 struct objfile *objfile) const override;
52
53 /* See probe.h. */
54 const char *type_name () const override;
55
56 /* See probe.h. */
57 std::vector<struct info_probe_column> gen_info_probes_table_header
58 () const override;
59};
60
61/* Static operations associated with a generic probe. */
62
64
65/* A helper for parse_probes that decodes a probe specification in
66 SEARCH_PSPACE. It appends matching SALs to RESULT. */
67
68static void
70 struct program_space *search_pspace,
71 const char *objfile_namestr,
72 const char *provider,
73 const char *name,
74 std::vector<symtab_and_line> *result)
75{
76 for (objfile *objfile : search_pspace->objfiles ())
77 {
78 if (!objfile->sf || !objfile->sf->sym_probe_fns)
79 continue;
80
81 if (objfile_namestr
82 && FILENAME_CMP (objfile_name (objfile), objfile_namestr) != 0
83 && FILENAME_CMP (lbasename (objfile_name (objfile)),
84 objfile_namestr) != 0)
85 continue;
86
87 const std::vector<std::unique_ptr<probe>> &probes
89
90 for (auto &p : probes)
91 {
92 if (spops != &any_static_probe_ops && p->get_static_ops () != spops)
93 continue;
94
95 if (provider != NULL && p->get_provider () != provider)
96 continue;
97
98 if (p->get_name () != name)
99 continue;
100
101 symtab_and_line sal;
102 sal.pc = p->get_relocated_address (objfile);
103 sal.explicit_pc = 1;
104 sal.section = find_pc_overlay (sal.pc);
105 sal.pspace = search_pspace;
106 sal.prob = p.get ();
107 sal.objfile = objfile;
108
109 result->push_back (std::move (sal));
110 }
111 }
112}
113
114/* See definition in probe.h. */
115
116std::vector<symtab_and_line>
118 struct program_space *search_pspace,
119 struct linespec_result *canonical)
120{
121 char *arg_end, *arg;
122 char *objfile_namestr = NULL, *provider = NULL, *name, *p;
123 const char *arg_start, *cs;
124
125 gdb_assert (locspec->type () == PROBE_LOCATION_SPEC);
126 arg_start = locspec->to_string ();
127
128 cs = arg_start;
130 if (spops == NULL)
131 error (_("'%s' is not a probe linespec"), arg_start);
132
133 arg = (char *) cs;
134 arg = skip_spaces (arg);
135 if (!*arg)
136 error (_("argument to `%s' missing"), arg_start);
137
138 arg_end = skip_to_space (arg);
139
140 /* We make a copy here so we can write over parts with impunity. */
141 std::string copy (arg, arg_end - arg);
142 arg = &copy[0];
143
144 /* Extract each word from the argument, separated by ":"s. */
145 p = strchr (arg, ':');
146 if (p == NULL)
147 {
148 /* This is `-p name'. */
149 name = arg;
150 }
151 else
152 {
153 char *hold = p + 1;
154
155 *p = '\0';
156 p = strchr (hold, ':');
157 if (p == NULL)
158 {
159 /* This is `-p provider:name'. */
160 provider = arg;
161 name = hold;
162 }
163 else
164 {
165 /* This is `-p objfile:provider:name'. */
166 *p = '\0';
167 objfile_namestr = arg;
168 provider = hold;
169 name = p + 1;
170 }
171 }
172
173 if (*name == '\0')
174 error (_("no probe name specified"));
175 if (provider && *provider == '\0')
176 error (_("invalid provider name"));
177 if (objfile_namestr && *objfile_namestr == '\0')
178 error (_("invalid objfile name"));
179
180 std::vector<symtab_and_line> result;
181 if (search_pspace != NULL)
182 {
183 parse_probes_in_pspace (spops, search_pspace, objfile_namestr,
184 provider, name, &result);
185 }
186 else
187 {
188 for (struct program_space *pspace : program_spaces)
189 parse_probes_in_pspace (spops, pspace, objfile_namestr,
190 provider, name, &result);
191 }
192
193 if (result.empty ())
194 {
195 throw_error (NOT_FOUND_ERROR,
196 _("No probe matching objfile=`%s', provider=`%s', name=`%s'"),
197 objfile_namestr ? objfile_namestr : _("<any>"),
198 provider ? provider : _("<any>"),
199 name);
200 }
201
202 if (canonical)
203 {
204 std::string canon (arg_start, arg_end - arg_start);
205 canonical->special_display = 1;
206 canonical->pre_expanded = 1;
207 canonical->locspec = new_probe_location_spec (std::move (canon));
208 }
209
210 return result;
211}
212
213/* See definition in probe.h. */
214
215std::vector<probe *>
216find_probes_in_objfile (struct objfile *objfile, const char *provider,
217 const char *name)
218{
219 std::vector<probe *> result;
220
221 if (!objfile->sf || !objfile->sf->sym_probe_fns)
222 return result;
223
224 const std::vector<std::unique_ptr<probe>> &probes
226 for (auto &p : probes)
227 {
228 if (p->get_provider () != provider)
229 continue;
230
231 if (p->get_name () != name)
232 continue;
233
234 result.push_back (p.get ());
235 }
236
237 return result;
238}
239
240/* See definition in probe.h. */
241
242struct bound_probe
243find_probe_by_pc (CORE_ADDR pc)
244{
245 struct bound_probe result;
246
247 result.objfile = NULL;
248 result.prob = NULL;
249
251 {
252 if (!objfile->sf || !objfile->sf->sym_probe_fns
253 || objfile->sect_index_text == -1)
254 continue;
255
256 /* If this proves too inefficient, we can replace with a hash. */
257 const std::vector<std::unique_ptr<probe>> &probes
259 for (auto &p : probes)
260 if (p->get_relocated_address (objfile) == pc)
261 {
262 result.objfile = objfile;
263 result.prob = p.get ();
264 return result;
265 }
266 }
267
268 return result;
269}
270
271
272
273/* Make a vector of probes matching OBJNAME, PROVIDER, and PROBE_NAME.
274 If SPOPS is not &any_static_probe_ops, only probes related to this
275 specific static probe ops will match. Each argument is a regexp,
276 or NULL, which matches anything. */
277
278static std::vector<bound_probe>
279collect_probes (const std::string &objname, const std::string &provider,
280 const std::string &probe_name, const static_probe_ops *spops)
281{
282 std::vector<bound_probe> result;
283 gdb::optional<compiled_regex> obj_pat, prov_pat, probe_pat;
284
285 if (!provider.empty ())
286 prov_pat.emplace (provider.c_str (), REG_NOSUB,
287 _("Invalid provider regexp"));
288 if (!probe_name.empty ())
289 probe_pat.emplace (probe_name.c_str (), REG_NOSUB,
290 _("Invalid probe regexp"));
291 if (!objname.empty ())
292 obj_pat.emplace (objname.c_str (), REG_NOSUB,
293 _("Invalid object file regexp"));
294
296 {
297 if (! objfile->sf || ! objfile->sf->sym_probe_fns)
298 continue;
299
300 if (obj_pat)
301 {
302 if (obj_pat->exec (objfile_name (objfile), 0, NULL, 0) != 0)
303 continue;
304 }
305
306 const std::vector<std::unique_ptr<probe>> &probes
308
309 for (auto &p : probes)
310 {
311 if (spops != &any_static_probe_ops && p->get_static_ops () != spops)
312 continue;
313
314 if (prov_pat
315 && prov_pat->exec (p->get_provider ().c_str (), 0, NULL, 0) != 0)
316 continue;
317
318 if (probe_pat
319 && probe_pat->exec (p->get_name ().c_str (), 0, NULL, 0) != 0)
320 continue;
321
322 result.emplace_back (p.get (), objfile);
323 }
324 }
325
326 return result;
327}
328
329/* A qsort comparison function for bound_probe_s objects. */
330
331static bool
333{
334 int v;
335
336 v = a.prob->get_provider ().compare (b.prob->get_provider ());
337 if (v != 0)
338 return v < 0;
339
340 v = a.prob->get_name ().compare (b.prob->get_name ());
341 if (v != 0)
342 return v < 0;
343
344 if (a.prob->get_address () != b.prob->get_address ())
345 return a.prob->get_address () < b.prob->get_address ();
346
347 return strcmp (objfile_name (a.objfile), objfile_name (b.objfile)) < 0;
348}
349
350/* Helper function that generate entries in the ui_out table being
351 crafted by `info_probes_for_ops'. */
352
353static void
354gen_ui_out_table_header_info (const std::vector<bound_probe> &probes,
355 const static_probe_ops *spops)
356{
357 /* `headings' refers to the names of the columns when printing `info
358 probes'. */
359 gdb_assert (spops != NULL);
360
361 std::vector<struct info_probe_column> headings
363
364 for (const info_probe_column &column : headings)
365 {
366 size_t size_max = strlen (column.print_name);
367
368 for (const bound_probe &probe : probes)
369 {
370 /* `probe_fields' refers to the values of each new field that this
371 probe will display. */
372
373 if (probe.prob->get_static_ops () != spops)
374 continue;
375
376 std::vector<const char *> probe_fields
378
379 gdb_assert (probe_fields.size () == headings.size ());
380
381 for (const char *val : probe_fields)
382 {
383 /* It is valid to have a NULL value here, which means that the
384 backend does not have something to write and this particular
385 field should be skipped. */
386 if (val == NULL)
387 continue;
388
389 size_max = std::max (strlen (val), size_max);
390 }
391 }
392
393 current_uiout->table_header (size_max, ui_left,
394 column.field_name, column.print_name);
395 }
396}
397
398/* Helper function to print not-applicable strings for all the extra
399 columns defined in a static_probe_ops. */
400
401static void
403{
404 std::vector<struct info_probe_column> headings
406
407 for (const info_probe_column &column : headings)
408 current_uiout->field_string (column.field_name, _("n/a"));
409}
410
411/* Helper function to print extra information about a probe and an objfile
412 represented by PROBE. */
413
414static void
416{
417 /* `values' refers to the actual values of each new field in the output
418 of `info probe'. `headings' refers to the names of each new field. */
419 gdb_assert (probe != NULL);
420 std::vector<struct info_probe_column> headings
422 std::vector<const char *> values
424
425 gdb_assert (headings.size () == values.size ());
426
427 for (int ix = 0; ix < headings.size (); ++ix)
428 {
429 struct info_probe_column column = headings[ix];
430 const char *val = values[ix];
431
432 if (val == NULL)
433 current_uiout->field_skip (column.field_name);
434 else
435 current_uiout->field_string (column.field_name, val);
436 }
437}
438
439/* Helper function that returns the number of extra fields which POPS will
440 need. */
441
442static int
444{
445 return spops->gen_info_probes_table_header ().size ();
446}
447
448/* Helper function that returns true if there is a probe in PROBES
449 featuring the given SPOPS. It returns false otherwise. */
450
451static bool
452exists_probe_with_spops (const std::vector<bound_probe> &probes,
453 const static_probe_ops *spops)
454{
455 for (const bound_probe &probe : probes)
456 if (probe.prob->get_static_ops () == spops)
457 return true;
458
459 return false;
460}
461
462/* Helper function that parses a probe linespec of the form [PROVIDER
463 [PROBE [OBJNAME]]] from the provided string STR. */
464
465static void
466parse_probe_linespec (const char *str, std::string *provider,
467 std::string *probe_name, std::string *objname)
468{
469 *probe_name = *objname = "";
470
471 *provider = extract_arg (&str);
472 if (!provider->empty ())
473 {
474 *probe_name = extract_arg (&str);
475 if (!probe_name->empty ())
476 *objname = extract_arg (&str);
477 }
478}
479
480/* See comment in probe.h. */
481
482void
483info_probes_for_spops (const char *arg, int from_tty,
484 const static_probe_ops *spops)
485{
486 std::string provider, probe_name, objname;
487 int any_found;
488 int ui_out_extra_fields = 0;
489 size_t size_addr;
490 size_t size_name = strlen ("Name");
491 size_t size_objname = strlen ("Object");
492 size_t size_provider = strlen ("Provider");
493 size_t size_type = strlen ("Type");
494 struct gdbarch *gdbarch = get_current_arch ();
495
496 parse_probe_linespec (arg, &provider, &probe_name, &objname);
497
498 std::vector<bound_probe> probes
499 = collect_probes (objname, provider, probe_name, spops);
500
501 if (spops == &any_static_probe_ops)
502 {
503 /* If SPOPS is &any_static_probe_ops, it means the user has
504 requested a "simple" `info probes', i.e., she wants to print
505 all information about all probes. For that, we have to
506 identify how many extra fields we will need to add in the
507 ui_out table.
508
509 To do that, we iterate over all static_probe_ops, querying
510 each one about its extra fields, and incrementing
511 `ui_out_extra_fields' to reflect that number. But note that
512 we ignore the static_probe_ops for which no probes are
513 defined with the given search criteria. */
514
515 for (const static_probe_ops *po : all_static_probe_ops)
516 if (exists_probe_with_spops (probes, po))
517 ui_out_extra_fields += get_number_extra_fields (po);
518 }
519 else
520 ui_out_extra_fields = get_number_extra_fields (spops);
521
522 {
523 ui_out_emit_table table_emitter (current_uiout,
524 5 + ui_out_extra_fields,
525 probes.size (), "StaticProbes");
526
527 std::sort (probes.begin (), probes.end (), compare_probes);
528
529 /* What's the size of an address in our architecture? */
530 size_addr = gdbarch_addr_bit (gdbarch) == 64 ? 18 : 10;
531
532 /* Determining the maximum size of each field (`type', `provider',
533 `name' and `objname'). */
534 for (const bound_probe &probe : probes)
535 {
536 const char *probe_type = probe.prob->get_static_ops ()->type_name ();
537
538 size_type = std::max (strlen (probe_type), size_type);
539 size_name = std::max (probe.prob->get_name ().size (), size_name);
540 size_provider = std::max (probe.prob->get_provider ().size (),
541 size_provider);
542 size_objname = std::max (strlen (objfile_name (probe.objfile)),
543 size_objname);
544 }
545
546 current_uiout->table_header (size_type, ui_left, "type", _("Type"));
547 current_uiout->table_header (size_provider, ui_left, "provider",
548 _("Provider"));
549 current_uiout->table_header (size_name, ui_left, "name", _("Name"));
550 current_uiout->table_header (size_addr, ui_left, "addr", _("Where"));
551
552 if (spops == &any_static_probe_ops)
553 {
554 /* We have to generate the table header for each new probe type
555 that we will print. Note that this excludes probe types not
556 having any defined probe with the search criteria. */
557 for (const static_probe_ops *po : all_static_probe_ops)
558 if (exists_probe_with_spops (probes, po))
559 gen_ui_out_table_header_info (probes, po);
560 }
561 else
562 gen_ui_out_table_header_info (probes, spops);
563
564 current_uiout->table_header (size_objname, ui_left, "object", _("Object"));
565 current_uiout->table_body ();
566
567 for (const bound_probe &probe : probes)
568 {
569 const char *probe_type = probe.prob->get_static_ops ()->type_name ();
570
571 ui_out_emit_tuple tuple_emitter (current_uiout, "probe");
572
573 current_uiout->field_string ("type", probe_type);
574 current_uiout->field_string ("provider", probe.prob->get_provider ());
575 current_uiout->field_string ("name", probe.prob->get_name ());
576 current_uiout->field_core_addr ("addr", probe.prob->get_gdbarch (),
578 (probe.objfile));
579
580 if (spops == &any_static_probe_ops)
581 {
582 for (const static_probe_ops *po : all_static_probe_ops)
583 {
584 if (probe.prob->get_static_ops () == po)
586 else if (exists_probe_with_spops (probes, po))
588 }
589 }
590 else
592
593 current_uiout->field_string ("object",
594 objfile_name (probe.objfile));
595 current_uiout->text ("\n");
596 }
597
598 any_found = !probes.empty ();
599 }
600
601 if (!any_found)
602 current_uiout->message (_("No probes matched.\n"));
603}
604
605/* Implementation of the `info probes' command. */
606
607static void
608info_probes_command (const char *arg, int from_tty)
609{
611}
612
613/* Implementation of the `enable probes' command. */
614
615static void
616enable_probes_command (const char *arg, int from_tty)
617{
618 std::string provider, probe_name, objname;
619
620 parse_probe_linespec (arg, &provider, &probe_name, &objname);
621
622 std::vector<bound_probe> probes
623 = collect_probes (objname, provider, probe_name, &any_static_probe_ops);
624 if (probes.empty ())
625 {
626 current_uiout->message (_("No probes matched.\n"));
627 return;
628 }
629
630 /* Enable the selected probes, provided their backends support the
631 notion of enabling a probe. */
632 for (const bound_probe &probe: probes)
633 {
634 if (probe.prob->get_static_ops ()->can_enable ())
635 {
636 probe.prob->enable ();
637 current_uiout->message (_("Probe %s:%s enabled.\n"),
638 probe.prob->get_provider ().c_str (),
639 probe.prob->get_name ().c_str ());
640 }
641 else
642 current_uiout->message (_("Probe %s:%s cannot be enabled.\n"),
643 probe.prob->get_provider ().c_str (),
644 probe.prob->get_name ().c_str ());
645 }
646}
647
648/* Implementation of the `disable probes' command. */
649
650static void
651disable_probes_command (const char *arg, int from_tty)
652{
653 std::string provider, probe_name, objname;
654
655 parse_probe_linespec (arg, &provider, &probe_name, &objname);
656
657 std::vector<bound_probe> probes
658 = collect_probes (objname, provider, probe_name, &any_static_probe_ops);
659 if (probes.empty ())
660 {
661 current_uiout->message (_("No probes matched.\n"));
662 return;
663 }
664
665 /* Disable the selected probes, provided their backends support the
666 notion of enabling a probe. */
667 for (const bound_probe &probe : probes)
668 {
669 if (probe.prob->get_static_ops ()->can_enable ())
670 {
671 probe.prob->disable ();
672 current_uiout->message (_("Probe %s:%s disabled.\n"),
673 probe.prob->get_provider ().c_str (),
674 probe.prob->get_name ().c_str ());
675 }
676 else
677 current_uiout->message (_("Probe %s:%s cannot be disabled.\n"),
678 probe.prob->get_provider ().c_str (),
679 probe.prob->get_name ().c_str ());
680 }
681}
682
683static bool ignore_probes_p = false;
684static bool ignore_probes_idx = 0;
686static gdb::optional<compiled_regex> ignore_probes_prov_pat[2];
687static gdb::optional<compiled_regex> ignore_probes_name_pat[2];
688static gdb::optional<compiled_regex> ignore_probes_obj_pat[2];
689
690/* See comments in probe.h. */
691
692bool
693ignore_probe_p (const char *provider, const char *name,
694 const char *objfile_name, const char *type)
695{
696 if (!ignore_probes_p)
697 return false;
698
699 gdb::optional<compiled_regex> &re_prov
701 gdb::optional<compiled_regex> &re_name
703 gdb::optional<compiled_regex> &re_obj
705
706 bool res
707 = ((!re_prov
708 || re_prov->exec (provider, 0, NULL, 0) == 0)
709 && (!re_name
710 || re_name->exec (name, 0, NULL, 0) == 0)
711 && (!re_obj
712 || re_obj->exec (objfile_name, 0, NULL, 0) == 0));
713
714 if (res && ignore_probes_verbose_p)
715 gdb_printf (gdb_stdlog, _("Ignoring %s probe %s %s in %s.\n"),
716 type, provider, name, objfile_name);
717
718 return res;
719}
720
721/* Implementation of the `maintenance ignore-probes' command. */
722
723static void
724ignore_probes_command (const char *arg, int from_tty)
725{
726 std::string ignore_provider, ignore_probe_name, ignore_objname;
727
728 bool verbose_p = false;
729 if (arg != nullptr)
730 {
731 const char *idx = arg;
732 std::string s = extract_arg (&idx);
733
734 if (strcmp (s.c_str (), "-reset") == 0)
735 {
736 if (*idx != '\0')
737 error (_("-reset: no arguments allowed"));
738
739 ignore_probes_p = false;
740 gdb_printf (gdb_stdout, _("ignore-probes filter has been reset\n"));
741 return;
742 }
743
744 if (strcmp (s.c_str (), "-verbose") == 0
745 || strcmp (s.c_str (), "-v") == 0)
746 {
747 verbose_p = true;
748 arg = idx;
749 }
750 }
751
752 parse_probe_linespec (arg, &ignore_provider, &ignore_probe_name,
753 &ignore_objname);
754
755 /* Parse the regular expressions, making sure that the old regular
756 expressions are still valid if an exception is throw. */
757 int new_ignore_probes_idx = 1 - ignore_probes_idx;
758 gdb::optional<compiled_regex> &re_prov
759 = ignore_probes_prov_pat[new_ignore_probes_idx];
760 gdb::optional<compiled_regex> &re_name
761 = ignore_probes_name_pat[new_ignore_probes_idx];
762 gdb::optional<compiled_regex> &re_obj
763 = ignore_probes_obj_pat[new_ignore_probes_idx];
764 re_prov.reset ();
765 re_name.reset ();
766 re_obj.reset ();
767 if (!ignore_provider.empty ())
768 re_prov.emplace (ignore_provider.c_str (), REG_NOSUB,
769 _("Invalid provider regexp"));
770 if (!ignore_probe_name.empty ())
771 re_name.emplace (ignore_probe_name.c_str (), REG_NOSUB,
772 _("Invalid probe regexp"));
773 if (!ignore_objname.empty ())
774 re_obj.emplace (ignore_objname.c_str (), REG_NOSUB,
775 _("Invalid object file regexp"));
776 ignore_probes_idx = new_ignore_probes_idx;
777
778 ignore_probes_p = true;
779 ignore_probes_verbose_p = verbose_p;
780 gdb_printf (gdb_stdout, _("ignore-probes filter has been set to:\n"));
781 gdb_printf (gdb_stdout, _("PROVIDER: '%s'\n"), ignore_provider.c_str ());
782 gdb_printf (gdb_stdout, _("PROBE_NAME: '%s'\n"), ignore_probe_name.c_str ());
783 gdb_printf (gdb_stdout, _("OBJNAME: '%s'\n"), ignore_objname.c_str ());
784}
785
786/* See comments in probe.h. */
787
788struct value *
790{
791 struct bound_probe probe;
792 unsigned n_args;
793
795 if (!probe.prob)
796 return NULL;
797
798 n_args = probe.prob->get_argument_count (get_frame_arch (frame));
799 if (n >= n_args)
800 return NULL;
801
802 return probe.prob->evaluate_argument (n, frame);
803}
804
805/* See comment in probe.h. */
806
807const struct static_probe_ops *
808probe_linespec_to_static_ops (const char **linespecp)
809{
810 for (const static_probe_ops *ops : all_static_probe_ops)
811 if (ops->is_linespec (linespecp))
812 return ops;
813
814 return NULL;
815}
816
817/* See comment in probe.h. */
818
819int
820probe_is_linespec_by_keyword (const char **linespecp, const char *const *keywords)
821{
822 const char *s = *linespecp;
823 const char *const *csp;
824
825 for (csp = keywords; *csp; csp++)
826 {
827 const char *keyword = *csp;
828 size_t len = strlen (keyword);
829
830 if (strncmp (s, keyword, len) == 0 && isspace (s[len]))
831 {
832 *linespecp += len + 1;
833 return 1;
834 }
835 }
836
837 return 0;
838}
839
840/* Implementation of `is_linespec' method. */
841
842bool
843any_static_probe_ops::is_linespec (const char **linespecp) const
844{
845 static const char *const keywords[] = { "-p", "-probe", NULL };
846
847 return probe_is_linespec_by_keyword (linespecp, keywords);
848}
849
850/* Implementation of 'get_probes' method. */
851
852void
853any_static_probe_ops::get_probes (std::vector<std::unique_ptr<probe>> *probesp,
854 struct objfile *objfile) const
855{
856 /* No probes can be provided by this dummy backend. */
857}
858
859/* Implementation of the 'type_name' method. */
860
861const char *
863{
864 return NULL;
865}
866
867/* Implementation of the 'gen_info_probes_table_header' method. */
868
869std::vector<struct info_probe_column>
871{
872 return std::vector<struct info_probe_column> ();
873}
874
875/* See comments in probe.h. */
876
877struct cmd_list_element **
879{
880 static struct cmd_list_element *info_probes_cmdlist;
881
882 if (info_probes_cmdlist == NULL)
884 _("\
885Show available static probes.\n\
886Usage: info probes [all|TYPE [ARGS]]\n\
887TYPE specifies the type of the probe, and can be one of the following:\n\
888 - stap\n\
889If you specify TYPE, there may be additional arguments needed by the\n\
890subcommand.\n\
891If you do not specify any argument, or specify `all', then the command\n\
892will show information about all types of probes."),
893 &info_probes_cmdlist, 0/*allow-unknown*/, &infolist);
894
895 return &info_probes_cmdlist;
896}
897
898
899
900/* This is called to compute the value of one of the $_probe_arg*
901 convenience variables. */
902
903static struct value *
905 void *data)
906{
907 frame_info_ptr frame = get_selected_frame (_("No frame selected"));
908 CORE_ADDR pc = get_frame_pc (frame);
909 int sel = (int) (uintptr_t) data;
910 struct bound_probe pc_probe;
911 unsigned n_args;
912
913 /* SEL == -1 means "_probe_argc". */
914 gdb_assert (sel >= -1);
915
916 pc_probe = find_probe_by_pc (pc);
917 if (pc_probe.prob == NULL)
918 error (_("No probe at PC %s"), core_addr_to_string (pc));
919
920 n_args = pc_probe.prob->get_argument_count (arch);
921 if (sel == -1)
922 return value_from_longest (builtin_type (arch)->builtin_int, n_args);
923
924 if (sel >= n_args)
925 error (_("Invalid probe argument %d -- probe has %u arguments available"),
926 sel, n_args);
927
928 return pc_probe.prob->evaluate_argument (sel, frame);
929}
930
931/* This is called to compile one of the $_probe_arg* convenience
932 variables into an agent expression. */
933
934static void
936 struct axs_value *value, void *data)
937{
938 CORE_ADDR pc = expr->scope;
939 int sel = (int) (uintptr_t) data;
940 struct bound_probe pc_probe;
941 int n_args;
942
943 /* SEL == -1 means "_probe_argc". */
944 gdb_assert (sel >= -1);
945
946 pc_probe = find_probe_by_pc (pc);
947 if (pc_probe.prob == NULL)
948 error (_("No probe at PC %s"), core_addr_to_string (pc));
949
950 n_args = pc_probe.prob->get_argument_count (expr->gdbarch);
951
952 if (sel == -1)
953 {
954 value->kind = axs_rvalue;
955 value->type = builtin_type (expr->gdbarch)->builtin_int;
956 ax_const_l (expr, n_args);
957 return;
958 }
959
960 gdb_assert (sel >= 0);
961 if (sel >= n_args)
962 error (_("Invalid probe argument %d -- probe has %d arguments available"),
963 sel, n_args);
964
965 pc_probe.prob->compile_to_ax (expr, value, sel);
966}
967
968static const struct internalvar_funcs probe_funcs =
969{
972};
973
974
975std::vector<const static_probe_ops *> all_static_probe_ops;
976
977void _initialize_probe ();
978void
980{
982
984 (void *) (uintptr_t) -1);
986 (void *) (uintptr_t) 0);
988 (void *) (uintptr_t) 1);
990 (void *) (uintptr_t) 2);
992 (void *) (uintptr_t) 3);
994 (void *) (uintptr_t) 4);
996 (void *) (uintptr_t) 5);
998 (void *) (uintptr_t) 6);
1000 (void *) (uintptr_t) 7);
1002 (void *) (uintptr_t) 8);
1004 (void *) (uintptr_t) 9);
1005 create_internalvar_type_lazy ("_probe_arg10", &probe_funcs,
1006 (void *) (uintptr_t) 10);
1007 create_internalvar_type_lazy ("_probe_arg11", &probe_funcs,
1008 (void *) (uintptr_t) 11);
1009
1011 _("\
1012Show information about all type of probes."),
1014
1016Enable probes.\n\
1017Usage: enable probes [PROVIDER [NAME [OBJECT]]]\n\
1018Each argument is a regular expression, used to select probes.\n\
1019PROVIDER matches probe provider names.\n\
1020NAME matches the probe names.\n\
1021OBJECT matches the executable or shared library name.\n\
1022If you do not specify any argument then the command will enable\n\
1023all defined probes."),
1024 &enablelist);
1025
1027Disable probes.\n\
1028Usage: disable probes [PROVIDER [NAME [OBJECT]]]\n\
1029Each argument is a regular expression, used to select probes.\n\
1030PROVIDER matches probe provider names.\n\
1031NAME matches the probe names.\n\
1032OBJECT matches the executable or shared library name.\n\
1033If you do not specify any argument then the command will disable\n\
1034all defined probes."),
1035 &disablelist);
1036
1037 add_cmd ("ignore-probes", class_maintenance, ignore_probes_command, _("\
1038Ignore probes.\n\
1039Usage: maintenance ignore-probes [-v|-verbose] [PROVIDER [NAME [OBJECT]]]\n\
1040 maintenance ignore-probes -reset\n\
1041Each argument is a regular expression, used to select probes.\n\
1042PROVIDER matches probe provider names.\n\
1043NAME matches the probe names.\n\
1044OBJECT matches the executable or shared library name.\n\
1045If you do not specify any argument then the command will ignore\n\
1046all defined probes. To reset the ignore-probes filter, use the -reset form.\n\
1047Only supported for SystemTap probes."),
1049}
const char *const name
struct gdbarch * get_current_arch(void)
Definition arch-utils.c:846
@ axs_rvalue
Definition ax-gdb.h:57
void ax_const_l(struct agent_expr *x, LONGEST l)
Definition ax-general.c:182
void get_probes(std::vector< std::unique_ptr< probe > > *probesp, struct objfile *objfile) const override
Definition probe.c:853
bool is_linespec(const char **linespecp) const override
Definition probe.c:843
const char * type_name() const override
Definition probe.c:862
std::vector< struct info_probe_column > gen_info_probes_table_header() const override
Definition probe.c:870
Definition probe.h:115
virtual struct value * evaluate_argument(unsigned n, frame_info_ptr frame)=0
virtual std::vector< const char * > gen_info_probes_table_values() const
Definition probe.h:182
virtual const static_probe_ops * get_static_ops() const =0
virtual CORE_ADDR get_relocated_address(struct objfile *objfile)=0
virtual void compile_to_ax(struct agent_expr *aexpr, struct axs_value *axs_value, unsigned n)=0
const std::string & get_name() const
Definition probe.h:199
virtual unsigned get_argument_count(struct gdbarch *gdbarch)=0
virtual void disable()
Definition probe.h:195
virtual void enable()
Definition probe.h:189
const std::string & get_provider() const
Definition probe.h:205
CORE_ADDR get_address() const
Definition probe.h:211
struct gdbarch * get_gdbarch() const
Definition probe.h:217
virtual std::vector< struct info_probe_column > gen_info_probes_table_header() const =0
virtual bool can_enable() const
Definition probe.h:76
virtual const char * type_name() const =0
struct cmd_list_element * infolist
Definition cli-cmds.c:91
struct cmd_list_element * disablelist
Definition cli-cmds.c:99
struct cmd_list_element * maintenancelist
Definition cli-cmds.c:143
struct cmd_list_element * enablelist
Definition cli-cmds.c:95
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition cli-decode.c:233
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
Definition cli-decode.c:357
std::string extract_arg(const char **arg)
Definition cli-utils.c:383
@ class_maintenance
Definition command.h:65
@ class_breakpoint
Definition command.h:60
@ class_info
Definition command.h:59
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2712
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
Definition frame.c:3027
frame_info_ptr get_selected_frame(const char *message)
Definition frame.c:1888
int gdbarch_addr_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1739
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition gdbtypes.c:6168
location_spec_up new_probe_location_spec(std::string &&probe)
Definition location.c:249
@ PROBE_LOCATION_SPEC
Definition location.h:67
Definition ada-exp.h:87
const char * objfile_name(const struct objfile *objfile)
Definition objfiles.c:1259
const struct static_probe_ops * probe_linespec_to_static_ops(const char **linespecp)
Definition probe.c:808
static gdb::optional< compiled_regex > ignore_probes_prov_pat[2]
Definition probe.c:686
static gdb::optional< compiled_regex > ignore_probes_name_pat[2]
Definition probe.c:687
static void gen_ui_out_table_header_info(const std::vector< bound_probe > &probes, const static_probe_ops *spops)
Definition probe.c:354
static void info_probes_command(const char *arg, int from_tty)
Definition probe.c:608
static void print_ui_out_info(probe *probe)
Definition probe.c:415
void info_probes_for_spops(const char *arg, int from_tty, const static_probe_ops *spops)
Definition probe.c:483
static void parse_probe_linespec(const char *str, std::string *provider, std::string *probe_name, std::string *objname)
Definition probe.c:466
static gdb::optional< compiled_regex > ignore_probes_obj_pat[2]
Definition probe.c:688
void _initialize_probe()
Definition probe.c:979
static void disable_probes_command(const char *arg, int from_tty)
Definition probe.c:651
static void compile_probe_arg(struct internalvar *ivar, struct agent_expr *expr, struct axs_value *value, void *data)
Definition probe.c:935
static bool exists_probe_with_spops(const std::vector< bound_probe > &probes, const static_probe_ops *spops)
Definition probe.c:452
int probe_is_linespec_by_keyword(const char **linespecp, const char *const *keywords)
Definition probe.c:820
std::vector< const static_probe_ops * > all_static_probe_ops
Definition probe.c:975
static void print_ui_out_not_applicables(const static_probe_ops *spops)
Definition probe.c:402
static bool ignore_probes_verbose_p
Definition probe.c:685
static bool ignore_probes_p
Definition probe.c:683
static int get_number_extra_fields(const static_probe_ops *spops)
Definition probe.c:443
std::vector< probe * > find_probes_in_objfile(struct objfile *objfile, const char *provider, const char *name)
Definition probe.c:216
std::vector< symtab_and_line > parse_probes(const location_spec *locspec, struct program_space *search_pspace, struct linespec_result *canonical)
Definition probe.c:117
static struct value * compute_probe_arg(struct gdbarch *arch, struct internalvar *ivar, void *data)
Definition probe.c:904
static std::vector< bound_probe > collect_probes(const std::string &objname, const std::string &provider, const std::string &probe_name, const static_probe_ops *spops)
Definition probe.c:279
static const struct internalvar_funcs probe_funcs
Definition probe.c:968
static bool ignore_probes_idx
Definition probe.c:684
static void parse_probes_in_pspace(const static_probe_ops *spops, struct program_space *search_pspace, const char *objfile_namestr, const char *provider, const char *name, std::vector< symtab_and_line > *result)
Definition probe.c:69
static void ignore_probes_command(const char *arg, int from_tty)
Definition probe.c:724
struct cmd_list_element ** info_probes_cmdlist_get(void)
Definition probe.c:878
bool ignore_probe_p(const char *provider, const char *name, const char *objfile_name, const char *type)
Definition probe.c:693
static bool compare_probes(const bound_probe &a, const bound_probe &b)
Definition probe.c:332
struct value * probe_safe_evaluate_at_pc(frame_info_ptr frame, unsigned n)
Definition probe.c:789
struct bound_probe find_probe_by_pc(CORE_ADDR pc)
Definition probe.c:243
static void enable_probes_command(const char *arg, int from_tty)
Definition probe.c:616
struct program_space * current_program_space
Definition progspace.c:40
std::vector< struct program_space * > program_spaces
Definition progspace.c:37
probe * prob
Definition probe.h:255
struct objfile * objfile
Definition probe.h:258
struct type * builtin_int
Definition gdbtypes.h:2080
const char * field_name
Definition probe.h:35
bool special_display
Definition linespec.h:65
bool pre_expanded
Definition linespec.h:71
location_spec_up locspec
Definition linespec.h:75
enum location_spec_type type() const
Definition location.h:108
const char * to_string() const
Definition location.h:92
const struct sym_fns * sf
Definition objfiles.h:768
int sect_index_text
Definition objfiles.h:798
objfiles_range objfiles()
Definition progspace.h:209
const struct sym_probe_fns * sym_probe_fns
Definition symfile.h:175
const std::vector< std::unique_ptr< probe > > &(* sym_get_probes)(struct objfile *)
Definition symfile.h:113
struct obj_section * section
Definition symtab.h:2330
struct objfile * objfile
Definition symtab.h:2350
probe * prob
Definition symtab.h:2347
CORE_ADDR pc
Definition symtab.h:2337
struct program_space * pspace
Definition symtab.h:2326
Definition value.h:130
struct gdbarch * arch() const
Definition value.c:167
struct type * type() const
Definition value.h:180
struct obj_section * find_pc_overlay(CORE_ADDR pc)
Definition symfile.c:3174
@ ui_left
Definition ui-out.h:45
#define current_uiout
Definition ui-out.h:40
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
#define gdb_stdlog
Definition utils.h:190
#define gdb_stdout
Definition utils.h:182
struct internalvar * create_internalvar_type_lazy(const char *name, const struct internalvar_funcs *funcs, void *data)
Definition value.c:1966
struct value * value_from_longest(struct type *type, LONGEST num)
Definition value.c:3438