GDB (xrefs)

/tmp/gdb-8.1/gdb/probe.c
Go to the documentation of this file.
1 /* Generic static probe support for GDB.
2
3 Copyright (C) 2012-2018 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 "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 "common/gdb_optional.h"
40
41 /* Class that implements the static probe methods for "any" probe. */
42
43 class any_static_probe_ops : public static_probe_ops
44 {
45 public:
46 /* See probe.h. */
47 bool is_linespec (const char **linespecp) const override;
48
49 /* See probe.h. */
50 void get_probes (std::vector<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
63 const any_static_probe_ops any_static_probe_ops;
64
65 /* A helper for parse_probes that decodes a probe specification in
66 SEARCH_PSPACE. It appends matching SALs to RESULT. */
67
68 static void
69 parse_probes_in_pspace (const static_probe_ops *spops,
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 struct objfile *objfile;
77
78 ALL_PSPACE_OBJFILES (search_pspace, objfile)
79 {
80 if (!objfile->sf || !objfile->sf->sym_probe_fns)
81 continue;
82
83 if (objfile_namestr
84 && FILENAME_CMP (objfile_name (objfile), objfile_namestr) != 0
85 && FILENAME_CMP (lbasename (objfile_name (objfile)),
86 objfile_namestr) != 0)
87 continue;
88
89 const std::vector<probe *> &probes
90 = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
91
92 for (probe *p : probes)
93 {
94 if (spops != &any_static_probe_ops && p->get_static_ops () != spops)
95 continue;
96
97 if (provider != NULL && p->get_provider () != provider)
98 continue;
99
100 if (p->get_name () != name)
101 continue;
102
103 symtab_and_line sal;
104 sal.pc = p->get_relocated_address (objfile);
105 sal.explicit_pc = 1;
106 sal.section = find_pc_overlay (sal.pc);
107 sal.pspace = search_pspace;
108 sal.prob = p;
109 sal.objfile = objfile;
110
111 result->push_back (std::move (sal));
112 }
113 }
114 }
115
116 /* See definition in probe.h. */
117
118 std::vector<symtab_and_line>
119 parse_probes (const struct event_location *location,
120 struct program_space *search_pspace,
121 struct linespec_result *canonical)
122 {
123 char *arg_end, *arg;
124 char *objfile_namestr = NULL, *provider = NULL, *name, *p;
125 const char *arg_start, *cs;
126
127 gdb_assert (event_location_type (location) == PROBE_LOCATION);
128 arg_start = get_probe_location (location);
129
130 cs = arg_start;
131 const static_probe_ops *spops = probe_linespec_to_static_ops (&cs);
132 if (spops == NULL)
133 error (_("'%s' is not a probe linespec"), arg_start);
134
135 arg = (char *) cs;
136 arg = skip_spaces (arg);
137 if (!*arg)
138 error (_("argument to `%s' missing"), arg_start);
139
140 arg_end = skip_to_space (arg);
141
142 /* We make a copy here so we can write over parts with impunity. */
143 std::string copy (arg, arg_end - arg);
144 arg = &copy[0];
145
146 /* Extract each word from the argument, separated by ":"s. */
147 p = strchr (arg, ':');
148 if (p == NULL)
149 {
150 /* This is `-p name'. */
151 name = arg;
152 }
153 else
154 {
155 char *hold = p + 1;
156
157 *p = '\0';
158 p = strchr (hold, ':');
159 if (p == NULL)
160 {
161 /* This is `-p provider:name'. */
162 provider = arg;
163 name = hold;
164 }
165 else
166 {
167 /* This is `-p objfile:provider:name'. */
168 *p = '\0';
169 objfile_namestr = arg;
170 provider = hold;
171 name = p + 1;
172 }
173 }
174
175 if (*name == '\0')
176 error (_("no probe name specified"));
177 if (provider && *provider == '\0')
178 error (_("invalid provider name"));
179 if (objfile_namestr && *objfile_namestr == '\0')
180 error (_("invalid objfile name"));
181
182 std::vector<symtab_and_line> result;
183 if (search_pspace != NULL)
184 {
185 parse_probes_in_pspace (spops, search_pspace, objfile_namestr,
186 provider, name, &result);
187 }
188 else
189 {
190 struct program_space *pspace;
191
192 ALL_PSPACES (pspace)
193 parse_probes_in_pspace (spops, pspace, objfile_namestr,
194 provider, name, &result);
195 }
196
197 if (result.empty ())
198 {
199 throw_error (NOT_FOUND_ERROR,
200 _("No probe matching objfile=`%s', provider=`%s', name=`%s'"),
201 objfile_namestr ? objfile_namestr : _("<any>"),
202 provider ? provider : _("<any>"),
203 name);
204 }
205
206 if (canonical)
207 {
208 std::string canon (arg_start, arg_end - arg_start);
209 canonical->special_display = 1;
210 canonical->pre_expanded = 1;
211 canonical->location = new_probe_location (canon.c_str ());
212 }
213
214 return result;
215 }
216
217 /* See definition in probe.h. */
218
219 std::vector<probe *>
220 find_probes_in_objfile (struct objfile *objfile, const char *provider,
221 const char *name)
222 {
223 std::vector<probe *> result;
224
225 if (!objfile->sf || !objfile->sf->sym_probe_fns)
226 return result;
227
228 const std::vector<probe *> &probes
229 = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
230 for (probe *p : probes)
231 {
232 if (p->get_provider () != provider)
233 continue;
234
235 if (p->get_name () != name)
236 continue;
237
238 result.push_back (p);
239 }
240
241 return result;
242 }
243
244 /* See definition in probe.h. */
245
246 struct bound_probe
247 find_probe_by_pc (CORE_ADDR pc)
248 {
249 struct objfile *objfile;
250 struct bound_probe result;
251
252 result.objfile = NULL;
253 result.prob = NULL;
254
255 ALL_OBJFILES (objfile)
256 {
257 if (!objfile->sf || !objfile->sf->sym_probe_fns
258 || objfile->sect_index_text == -1)
259 continue;
260
261 /* If this proves too inefficient, we can replace with a hash. */
262 const std::vector<probe *> &probes
263 = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
264 for (probe *p : probes)
265 if (p->get_relocated_address (objfile) == pc)
266 {
267 result.objfile = objfile;
268 result.prob = p;
269 return result;
270 }
271 }
272
273 return result;
274 }
275
276
277
278 /* Make a vector of probes matching OBJNAME, PROVIDER, and PROBE_NAME.
279 If SPOPS is not &any_static_probe_ops, only probes related to this
280 specific static probe ops will match. Each argument is a regexp,
281 or NULL, which matches anything. */
282
283 static std::vector<bound_probe>
284 collect_probes (const std::string &objname, const std::string &provider,
285 const std::string &probe_name, const static_probe_ops *spops)
286 {
287 struct objfile *objfile;
288 std::vector<bound_probe> result;
289 gdb::optional<compiled_regex> obj_pat, prov_pat, probe_pat;
290
291 if (!provider.empty ())
292 prov_pat.emplace (provider.c_str (), REG_NOSUB,
293 _("Invalid provider regexp"));
294 if (!probe_name.empty ())
295 probe_pat.emplace (probe_name.c_str (), REG_NOSUB,
296 _("Invalid probe regexp"));
297 if (!objname.empty ())
298 obj_pat.emplace (objname.c_str (), REG_NOSUB,
299 _("Invalid object file regexp"));
300
301 ALL_OBJFILES (objfile)
302 {
303 if (! objfile->sf || ! objfile->sf->sym_probe_fns)
304 continue;
305
306 if (obj_pat)
307 {
308 if (obj_pat->exec (objfile_name (objfile), 0, NULL, 0) != 0)
309 continue;
310 }
311
312 const std::vector<probe *> &probes
313 = objfile->sf->sym_probe_fns->sym_get_probes (objfile);
314
315 for (probe *p : probes)
316 {
317 if (spops != &any_static_probe_ops && p->get_static_ops () != spops)
318 continue;
319
320 if (prov_pat
321 && prov_pat->exec (p->get_provider ().c_str (), 0, NULL, 0) != 0)
322 continue;
323
324 if (probe_pat
325 && probe_pat->exec (p->get_name ().c_str (), 0, NULL, 0) != 0)
326 continue;
327
328 result.emplace_back (p, objfile);
329 }
330 }
331
332 return result;
333 }
334
335 /* A qsort comparison function for bound_probe_s objects. */
336
337 static bool
338 compare_probes (const bound_probe &a, const bound_probe &b)
339 {
340 int v;
341
342 v = a.prob->get_provider ().compare (b.prob->get_provider ());
343 if (v != 0)
344 return v < 0;
345
346 v = a.prob->get_name ().compare (b.prob->get_name ());
347 if (v != 0)
348 return v < 0;
349
350 if (a.prob->get_address () != b.prob->get_address ())
351 return a.prob->get_address () < b.prob->get_address ();
352
353 return strcmp (objfile_name (a.objfile), objfile_name (b.objfile)) < 0;
354 }
355
356 /* Helper function that generate entries in the ui_out table being
357 crafted by `info_probes_for_ops'. */
358
359 static void
360 gen_ui_out_table_header_info (const std::vector<bound_probe> &probes,
361 const static_probe_ops *spops)
362 {
363 /* `headings' refers to the names of the columns when printing `info
364 probes'. */
365 gdb_assert (spops != NULL);
366
367 std::vector<struct info_probe_column> headings
368 = spops->gen_info_probes_table_header ();
369
370 for (const info_probe_column &column : headings)
371 {
372 size_t size_max = strlen (column.print_name);
373
374 for (const bound_probe &probe : probes)
375 {
376 /* `probe_fields' refers to the values of each new field that this
377 probe will display. */
378
379 if (probe.prob->get_static_ops () != spops)
380 continue;
381
382 std::vector<const char *> probe_fields
383 = probe.prob->gen_info_probes_table_values ();
384
385 gdb_assert (probe_fields.size () == headings.size ());
386
387 for (const char *val : probe_fields)
388 {
389 /* It is valid to have a NULL value here, which means that the
390 backend does not have something to write and this particular
391 field should be skipped. */
392 if (val == NULL)
393 continue;
394
395 size_max = std::max (strlen (val), size_max);
396 }
397 }
398
399 current_uiout->table_header (size_max, ui_left,
400 column.field_name, column.print_name);
401 }
402 }
403
404 /* Helper function to print not-applicable strings for all the extra
405 columns defined in a static_probe_ops. */
406
407 static void
408 print_ui_out_not_applicables (const static_probe_ops *spops)
409 {
410 std::vector<struct info_probe_column> headings
411 = spops->gen_info_probes_table_header ();
412
413 for (const info_probe_column &column : headings)
414 current_uiout->field_string (column.field_name, _("n/a"));
415 }
416
417 /* Helper function to print extra information about a probe and an objfile
418 represented by PROBE. */
419
420 static void
421 print_ui_out_info (probe *probe)
422 {
423 /* `values' refers to the actual values of each new field in the output
424 of `info probe'. `headings' refers to the names of each new field. */
425 gdb_assert (probe != NULL);
426 std::vector<struct info_probe_column> headings
427 = probe->get_static_ops ()->gen_info_probes_table_header ();
428 std::vector<const char *> values
429 = probe->gen_info_probes_table_values ();
430
431 gdb_assert (headings.size () == values.size ());
432
433 for (int ix = 0; ix < headings.size (); ++ix)
434 {
435 struct info_probe_column column = headings[ix];
436 const char *val = values[ix];
437
438 if (val == NULL)
439 current_uiout->field_skip (column.field_name);
440 else
441 current_uiout->field_string (column.field_name, val);
442 }
443 }
444
445 /* Helper function that returns the number of extra fields which POPS will
446 need. */
447
448 static int
449 get_number_extra_fields (const static_probe_ops *spops)
450 {
451 return spops->gen_info_probes_table_header ().size ();
452 }
453
454 /* Helper function that returns true if there is a probe in PROBES
455 featuring the given SPOPS. It returns false otherwise. */
456
457 static bool
458 exists_probe_with_spops (const std::vector<bound_probe> &probes,
459 const static_probe_ops *spops)
460 {
461 for (const bound_probe &probe : probes)
462 if (probe.prob->get_static_ops () == spops)
463 return true;
464
465 return false;
466 }
467
468 /* Helper function that parses a probe linespec of the form [PROVIDER
469 [PROBE [OBJNAME]]] from the provided string STR. */
470
471 static void
472 parse_probe_linespec (const char *str, std::string *provider,
473 std::string *probe_name, std::string *objname)
474 {
475 *probe_name = *objname = "";
476
477 *provider = extract_arg (&str);
478 if (!provider->empty ())
479 {
480 *probe_name = extract_arg (&str);
481 if (!probe_name->empty ())
482 *objname = extract_arg (&str);
483 }
484 }
485
486 /* See comment in probe.h. */
487
488 void
489 info_probes_for_spops (const char *arg, int from_tty,
490 const static_probe_ops *spops)
491 {
492 std::string provider, probe_name, objname;
493 int any_found;
494 int ui_out_extra_fields = 0;
495 size_t size_addr;
496 size_t size_name = strlen ("Name");
497 size_t size_objname = strlen ("Object");
498 size_t size_provider = strlen ("Provider");
499 size_t size_type = strlen ("Type");
500 struct gdbarch *gdbarch = get_current_arch ();
501
502 parse_probe_linespec (arg, &provider, &probe_name, &objname);
503
504 std::vector<bound_probe> probes
505 = collect_probes (objname, provider, probe_name, spops);
506
507 if (spops == &any_static_probe_ops)
508 {
509 /* If SPOPS is &any_static_probe_ops, it means the user has
510 requested a "simple" `info probes', i.e., she wants to print
511 all information about all probes. For that, we have to
512 identify how many extra fields we will need to add in the
513 ui_out table.
514
515 To do that, we iterate over all static_probe_ops, querying
516 each one about its extra fields, and incrementing
517 `ui_out_extra_fields' to reflect that number. But note that
518 we ignore the static_probe_ops for which no probes are
519 defined with the given search criteria. */
520
521 for (const static_probe_ops *po : all_static_probe_ops)
522 if (exists_probe_with_spops (probes, po))
523 ui_out_extra_fields += get_number_extra_fields (po);
524 }
525 else
526 ui_out_extra_fields = get_number_extra_fields (spops);
527
528 {
529 ui_out_emit_table table_emitter (current_uiout,
530 5 + ui_out_extra_fields,
531 probes.size (), "StaticProbes");
532
533 std::sort (probes.begin (), probes.end (), compare_probes);
534
535 /* What's the size of an address in our architecture? */
536 size_addr = gdbarch_addr_bit (gdbarch) == 64 ? 18 : 10;
537
538 /* Determining the maximum size of each field (`type', `provider',
539 `name' and `objname'). */
540 for (const bound_probe &probe : probes)
541 {
542 const char *probe_type = probe.prob->get_static_ops ()->type_name ();
543
544 size_type = std::max (strlen (probe_type), size_type);
545 size_name = std::max (probe.prob->get_name ().size (), size_name);
546 size_provider = std::max (probe.prob->get_provider ().size (),
547 size_provider);
548 size_objname = std::max (strlen (objfile_name (probe.objfile)),
549 size_objname);
550 }
551
552 current_uiout->table_header (size_type, ui_left, "type", _("Type"));
553 current_uiout->table_header (size_provider, ui_left, "provider",
554 _("Provider"));
555 current_uiout->table_header (size_name, ui_left, "name", _("Name"));
556 current_uiout->table_header (size_addr, ui_left, "addr", _("Where"));
557
558 if (spops == &any_static_probe_ops)
559 {
560 /* We have to generate the table header for each new probe type
561 that we will print. Note that this excludes probe types not
562 having any defined probe with the search criteria. */
563 for (const static_probe_ops *po : all_static_probe_ops)
564 if (exists_probe_with_spops (probes, po))
565 gen_ui_out_table_header_info (probes, po);
566 }
567 else
568 gen_ui_out_table_header_info (probes, spops);
569
570 current_uiout->table_header (size_objname, ui_left, "object", _("Object"));
571 current_uiout->table_body ();
572
573 for (const bound_probe &probe : probes)
574 {
575 const char *probe_type = probe.prob->get_static_ops ()->type_name ();
576
577 ui_out_emit_tuple tuple_emitter (current_uiout, "probe");
578
579 current_uiout->field_string ("type", probe_type);
580 current_uiout->field_string ("provider",
581 probe.prob->get_provider ().c_str ());
582 current_uiout->field_string ("name", probe.prob->get_name ().c_str ());
583 current_uiout->field_core_addr ("addr", probe.prob->get_gdbarch (),
584 probe.prob->get_relocated_address
585 (probe.objfile));
586
587 if (spops == &any_static_probe_ops)
588 {
589 for (const static_probe_ops *po : all_static_probe_ops)
590 {
591 if (probe.prob->get_static_ops () == po)
592 print_ui_out_info (probe.prob);
593 else if (exists_probe_with_spops (probes, po))
594 print_ui_out_not_applicables (po);
595 }
596 }
597 else
598 print_ui_out_info (probe.prob);
599
600 current_uiout->field_string ("object",
601 objfile_name (probe.objfile));
602 current_uiout->text ("\n");
603 }
604
605 any_found = !probes.empty ();
606 }
607
608 if (!any_found)
609 current_uiout->message (_("No probes matched.\n"));
610 }
611
612 /* Implementation of the `info probes' command. */
613
614 static void
615 info_probes_command (const char *arg, int from_tty)
616 {
617 info_probes_for_spops (arg, from_tty, &any_static_probe_ops);
618 }
619
620 /* Implementation of the `enable probes' command. */
621
622 static void
623 enable_probes_command (const char *arg, int from_tty)
624 {
625 std::string provider, probe_name, objname;
626
627 parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
628
629 std::vector<bound_probe> probes
630 = collect_probes (objname, provider, probe_name, &any_static_probe_ops);
631 if (probes.empty ())
632 {
633 current_uiout->message (_("No probes matched.\n"));
634 return;
635 }
636
637 /* Enable the selected probes, provided their backends support the
638 notion of enabling a probe. */
639 for (const bound_probe &probe: probes)
640 {
641 if (probe.prob->get_static_ops ()->can_enable ())
642 {
643 probe.prob->enable ();
644 current_uiout->message (_("Probe %s:%s enabled.\n"),
645 probe.prob->get_provider ().c_str (),
646 probe.prob->get_name ().c_str ());
647 }
648 else
649 current_uiout->message (_("Probe %s:%s cannot be enabled.\n"),
650 probe.prob->get_provider ().c_str (),
651 probe.prob->get_name ().c_str ());
652 }
653 }
654
655 /* Implementation of the `disable probes' command. */
656
657 static void
658 disable_probes_command (const char *arg, int from_tty)
659 {
660 std::string provider, probe_name, objname;
661
662 parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
663
664 std::vector<bound_probe> probes
665 = collect_probes (objname, provider, probe_name, &any_static_probe_ops);
666 if (probes.empty ())
667 {
668 current_uiout->message (_("No probes matched.\n"));
669 return;
670 }
671
672 /* Disable the selected probes, provided their backends support the
673 notion of enabling a probe. */
674 for (const bound_probe &probe : probes)
675 {
676 if (probe.prob->get_static_ops ()->can_enable ())
677 {
678 probe.prob->disable ();
679 current_uiout->message (_("Probe %s:%s disabled.\n"),
680 probe.prob->get_provider ().c_str (),
681 probe.prob->get_name ().c_str ());
682 }
683 else
684 current_uiout->message (_("Probe %s:%s cannot be disabled.\n"),
685 probe.prob->get_provider ().c_str (),
686 probe.prob->get_name ().c_str ());
687 }
688 }
689
690 /* See comments in probe.h. */
691
692 struct value *
693 probe_safe_evaluate_at_pc (struct frame_info *frame, unsigned n)
694 {
695 struct bound_probe probe;
696 unsigned n_args;
697
698 probe = find_probe_by_pc (get_frame_pc (frame));
699 if (!probe.prob)
700 return NULL;
701
702 n_args = probe.prob->get_argument_count (frame);
703 if (n >= n_args)
704 return NULL;
705
706 return probe.prob->evaluate_argument (n, frame);
707 }
708
709 /* See comment in probe.h. */
710
711 const struct static_probe_ops *
712 probe_linespec_to_static_ops (const char **linespecp)
713 {
714 for (const static_probe_ops *ops : all_static_probe_ops)
715 if (ops->is_linespec (linespecp))
716 return ops;
717
718 return NULL;
719 }
720
721 /* See comment in probe.h. */
722
723 int
724 probe_is_linespec_by_keyword (const char **linespecp, const char *const *keywords)
725 {
726 const char *s = *linespecp;
727 const char *const *csp;
728
729 for (csp = keywords; *csp; csp++)
730 {
731 const char *keyword = *csp;
732 size_t len = strlen (keyword);
733
734 if (strncmp (s, keyword, len) == 0 && isspace (s[len]))
735 {
736 *linespecp += len + 1;
737 return 1;
738 }
739 }
740
741 return 0;
742 }
743
744 /* Implementation of `is_linespec' method. */
745
746 bool
747 any_static_probe_ops::is_linespec (const char **linespecp) const
748 {
749 static const char *const keywords[] = { "-p", "-probe", NULL };
750
751 return probe_is_linespec_by_keyword (linespecp, keywords);
752 }
753
754 /* Implementation of 'get_probes' method. */
755
756 void
757 any_static_probe_ops::get_probes (std::vector<probe *> *probesp,
758 struct objfile *objfile) const
759 {
760 /* No probes can be provided by this dummy backend. */
761 }
762
763 /* Implementation of the 'type_name' method. */
764
765 const char *
766 any_static_probe_ops::type_name () const
767 {
768 return NULL;
769 }
770
771 /* Implementation of the 'gen_info_probes_table_header' method. */
772
773 std::vector<struct info_probe_column>
774 any_static_probe_ops::gen_info_probes_table_header () const
775 {
776 return std::vector<struct info_probe_column> ();
777 }
778
779 /* See comments in probe.h. */
780
781 struct cmd_list_element **
782 info_probes_cmdlist_get (void)
783 {
784 static struct cmd_list_element *info_probes_cmdlist;
785
786 if (info_probes_cmdlist == NULL)
787 add_prefix_cmd ("probes", class_info, info_probes_command,
788 _("\
789 Show available static probes.\n\
790 Usage: info probes [all|TYPE [ARGS]]\n\
791 TYPE specifies the type of the probe, and can be one of the following:\n\
792 - stap\n\
793 If you specify TYPE, there may be additional arguments needed by the\n\
794 subcommand.\n\
795 If you do not specify any argument, or specify `all', then the command\n\
796 will show information about all types of probes."),
797 &info_probes_cmdlist, "info probes ",
798 0/*allow-unknown*/, &infolist);
799
800 return &info_probes_cmdlist;
801 }
802
803
804
805 /* This is called to compute the value of one of the $_probe_arg*
806 convenience variables. */
807
808 static struct value *
809 compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
810 void *data)
811 {
812 struct frame_info *frame = get_selected_frame (_("No frame selected"));
813 CORE_ADDR pc = get_frame_pc (frame);
814 int sel = (int) (uintptr_t) data;
815 struct bound_probe pc_probe;
816 unsigned n_args;
817
818 /* SEL == -1 means "_probe_argc". */
819 gdb_assert (sel >= -1);
820
821 pc_probe = find_probe_by_pc (pc);
822 if (pc_probe.prob == NULL)
823 error (_("No probe at PC %s"), core_addr_to_string (pc));
824
825 n_args = pc_probe.prob->get_argument_count (frame);
826 if (sel == -1)
827 return value_from_longest (builtin_type (arch)->builtin_int, n_args);
828
829 if (sel >= n_args)
830 error (_("Invalid probe argument %d -- probe has %u arguments available"),
831 sel, n_args);
832
833 return pc_probe.prob->evaluate_argument (sel, frame);
834 }
835
836 /* This is called to compile one of the $_probe_arg* convenience
837 variables into an agent expression. */
838
839 static void
840 compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
841 struct axs_value *value, void *data)
842 {
843 CORE_ADDR pc = expr->scope;
844 int sel = (int) (uintptr_t) data;
845 struct bound_probe pc_probe;
846 int n_args;
847 struct frame_info *frame = get_selected_frame (NULL);
848
849 /* SEL == -1 means "_probe_argc". */
850 gdb_assert (sel >= -1);
851
852 pc_probe = find_probe_by_pc (pc);
853 if (pc_probe.prob == NULL)
854 error (_("No probe at PC %s"), core_addr_to_string (pc));
855
856 n_args = pc_probe.prob->get_argument_count (frame);
857
858 if (sel == -1)
859 {
860 value->kind = axs_rvalue;
861 value->type = builtin_type (expr->gdbarch)->builtin_int;
862 ax_const_l (expr, n_args);
863 return;
864 }
865
866 gdb_assert (sel >= 0);
867 if (sel >= n_args)
868 error (_("Invalid probe argument %d -- probe has %d arguments available"),
869 sel, n_args);
870
871 pc_probe.prob->compile_to_ax (expr, value, sel);
872 }
873
874 static const struct internalvar_funcs probe_funcs =
875 {
876 compute_probe_arg,
877 compile_probe_arg,
878 NULL
879 };
880
881
882 std::vector<const static_probe_ops *> all_static_probe_ops;
883
884 void
885 _initialize_probe (void)
886 {
887 all_static_probe_ops.push_back (&any_static_probe_ops);
888
889 create_internalvar_type_lazy ("_probe_argc", &probe_funcs,
890 (void *) (uintptr_t) -1);
891 create_internalvar_type_lazy ("_probe_arg0", &probe_funcs,
892 (void *) (uintptr_t) 0);
893 create_internalvar_type_lazy ("_probe_arg1", &probe_funcs,
894 (void *) (uintptr_t) 1);
895 create_internalvar_type_lazy ("_probe_arg2", &probe_funcs,
896 (void *) (uintptr_t) 2);
897 create_internalvar_type_lazy ("_probe_arg3", &probe_funcs,
898 (void *) (uintptr_t) 3);
899 create_internalvar_type_lazy ("_probe_arg4", &probe_funcs,
900 (void *) (uintptr_t) 4);
901 create_internalvar_type_lazy ("_probe_arg5", &probe_funcs,
902 (void *) (uintptr_t) 5);
903 create_internalvar_type_lazy ("_probe_arg6", &probe_funcs,
904 (void *) (uintptr_t) 6);
905 create_internalvar_type_lazy ("_probe_arg7", &probe_funcs,
906 (void *) (uintptr_t) 7);
907 create_internalvar_type_lazy ("_probe_arg8", &probe_funcs,
908 (void *) (uintptr_t) 8);
909 create_internalvar_type_lazy ("_probe_arg9", &probe_funcs,
910 (void *) (uintptr_t) 9);
911 create_internalvar_type_lazy ("_probe_arg10", &probe_funcs,
912 (void *) (uintptr_t) 10);
913 create_internalvar_type_lazy ("_probe_arg11", &probe_funcs,
914 (void *) (uintptr_t) 11);
915
916 add_cmd ("all", class_info, info_probes_command,
917 _("\
918 Show information about all type of probes."),
919 info_probes_cmdlist_get ());
920
921 add_cmd ("probes", class_breakpoint, enable_probes_command, _("\
922 Enable probes.\n\
923 Usage: enable probes [PROVIDER [NAME [OBJECT]]]\n\
924 Each argument is a regular expression, used to select probes.\n\
925 PROVIDER matches probe provider names.\n\
926 NAME matches the probe names.\n\
927 OBJECT matches the executable or shared library name.\n\
928 If you do not specify any argument then the command will enable\n\
929 all defined probes."),
930 &enablelist);
931
932 add_cmd ("probes", class_breakpoint, disable_probes_command, _("\
933 Disable probes.\n\
934 Usage: disable probes [PROVIDER [NAME [OBJECT]]]\n\
935 Each argument is a regular expression, used to select probes.\n\
936 PROVIDER matches probe provider names.\n\
937 NAME matches the probe names.\n\
938 OBJECT matches the executable or shared library name.\n\
939 If you do not specify any argument then the command will disable\n\
940 all defined probes."),
941 &disablelist);
942
943 }
objfile::sect_index_text
int sect_index_text
Definition: objfiles.h:409
gdbarch
Definition: gdbarch.c:127
string
const char * string
Definition: signals.c:50
probe
Definition: probe.h:112
axs_value
Definition: ax-gdb.h:77
bound_probe::prob
probe * prob
Definition: probe.h:253
collect_probes
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:284
any_static_probe_ops
Definition: probe.c:43
probe::enable
virtual void enable()
Definition: probe.h:187
get_selected_frame
struct frame_info * get_selected_frame(const char *message)
Definition: frame.c:1638
probe::evaluate_argument
virtual struct value * evaluate_argument(unsigned n, struct frame_info *frame)=0
get_frame_pc
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2376
probe_linespec_to_static_ops
const struct static_probe_ops * probe_linespec_to_static_ops(const char **linespecp)
Definition: probe.c:712
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
value::type
struct type * type
Definition: value.c:266
ui_out_emit_type
Definition: ui-out.h:192
_initialize_probe
void _initialize_probe(void)
Definition: probe.c:885
command.h
get_probe_location
const char * get_probe_location(const struct event_location *location)
Definition: location.c:169
enablelist
struct cmd_list_element * enablelist
Definition: cli-cmds.c:87
info_probes_command
static void info_probes_command(const char *arg, int from_tty)
Definition: probe.c:615
cmd_list_element
Definition: cli-decode.h:46
gdb_regex.h
progspace.h
extract_arg
std::string extract_arg(const char **arg)
Definition: cli-utils.c:259
builtin_type
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition: gdbtypes.c:5217
static_probe_ops::gen_info_probes_table_header
virtual std::vector< struct info_probe_column > gen_info_probes_table_header() const =0
ax-gdb.h
info_probes_cmdlist_get
struct cmd_list_element ** info_probes_cmdlist_get(void)
Definition: probe.c:782
cli-cmds.h
add_cmd
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:262
agent_expr
Definition: ax.h:83
frame_info
Definition: frame.c:85
probe::get_address
CORE_ADDR get_address() const
Definition: probe.h:209
any_static_probe_ops::gen_info_probes_table_header
std::vector< struct info_probe_column > gen_info_probes_table_header() const override
Definition: probe.c:774
symtab_and_line::section
struct obj_section * section
Definition: symtab.h:1753
agent_expr::gdbarch
struct gdbarch * gdbarch
Definition: ax.h:100
info_probe_column
Definition: probe.h:29
skip_spaces
char * skip_spaces(char *chp)
Definition: common-utils.c:337
info_probes_for_spops
void info_probes_for_spops(const char *arg, int from_tty, const static_probe_ops *spops)
Definition: probe.c:489
_
#define _(String)
Definition: gdb_locale.h:35
linespec_result::location
event_location_up location
Definition: linespec.h:76
probe_safe_evaluate_at_pc
struct value * probe_safe_evaluate_at_pc(struct frame_info *frame, unsigned n)
Definition: probe.c:693
ui_left
Definition: ui-out.h:44
defs.h
builtin_type
Definition: gdbtypes.h:1495
compare_probes
static bool compare_probes(const bound_probe &a, const bound_probe &b)
Definition: probe.c:338
internalvar
Definition: value.c:2070
ax.h
class_info
Definition: command.h:42
probe::get_provider
const std::string & get_provider() const
Definition: probe.h:203
disable_probes_command
static void disable_probes_command(const char *arg, int from_tty)
Definition: probe.c:658
compile_probe_arg
static void compile_probe_arg(struct internalvar *ivar, struct agent_expr *expr, struct axs_value *value, void *data)
Definition: probe.c:840
any_static_probe_ops::get_probes
void get_probes(std::vector< probe *> *probesp, struct objfile *objfile) const override
Definition: probe.c:757
linespec_result::pre_expanded
bool pre_expanded
Definition: linespec.h:72
any_static_probe_ops::type_name
const char * type_name() const override
Definition: probe.c:766
sym_fns::sym_probe_fns
const struct sym_probe_fns * sym_probe_fns
Definition: symfile.h:365
objfiles.h
arch-utils.h
find_pc_overlay
struct obj_section * find_pc_overlay(CORE_ADDR pc)
Definition: symfile.c:3173
add_prefix_cmd
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
Definition: cli-decode.c:367
symtab.h
probe_is_linespec_by_keyword
int probe_is_linespec_by_keyword(const char **linespecp, const char *const *keywords)
Definition: probe.c:724
infolist
struct cmd_list_element * infolist
Definition: cli-cmds.c:83
name
const char *const name
Definition: aarch64-tdep.c:76
exists_probe_with_spops
static bool exists_probe_with_spops(const std::vector< bound_probe > &probes, const static_probe_ops *spops)
Definition: probe.c:458
internalvar_funcs
Definition: value.h:946
bound_probe::objfile
struct objfile * objfile
Definition: probe.h:256
gdb_optional.h
sym_probe_fns::sym_get_probes
const std::vector< probe * > &(* sym_get_probes)(struct objfile *)
Definition: symfile.h:296
print_ui_out_info
static void print_ui_out_info(probe *probe)
Definition: probe.c:421
parse_probes_in_pspace
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
objfile::objfile
objfile(bfd *, const char *, objfile_flags)
Definition: objfiles.c:373
print_ui_out_not_applicables
static void print_ui_out_not_applicables(const static_probe_ops *spops)
Definition: probe.c:408
probe_funcs
static const struct internalvar_funcs probe_funcs
Definition: probe.c:874
probe::get_name
const std::string & get_name() const
Definition: probe.h:197
cli-utils.h
frame.h
objfile::sf
const struct sym_fns * sf
Definition: objfiles.h:381
current_uiout
#define current_uiout
Definition: ui-out.h:39
parse_probes
std::vector< symtab_and_line > parse_probes(const struct event_location *location, struct program_space *search_pspace, struct linespec_result *canonical)
Definition: probe.c:119
symtab_and_line::objfile
struct objfile * objfile
Definition: symtab.h:1768
get_current_arch
struct gdbarch * get_current_arch(void)
Definition: arch-utils.c:798
info_probe_column::field_name
const char * field_name
Definition: probe.h:33
NOT_FOUND_ERROR
Definition: common-exceptions.h:57
axs_rvalue
Definition: ax-gdb.h:58
event_location
Definition: location.c:36
value_from_longest
struct value * value_from_longest(struct type *type, LONGEST num)
Definition: value.c:3534
probe::gen_info_probes_table_values
virtual std::vector< const char * > gen_info_probes_table_values() const
Definition: probe.h:180
linespec.h
skip_to_space
const char * skip_to_space(const char *chp)
Definition: common-utils.c:361
gdbarch_addr_bit
int gdbarch_addr_bit(struct gdbarch *gdbarch)
Definition: gdbarch.c:1848
static_probe_ops
Definition: probe.h:52
gen_ui_out_table_header_info
static void gen_ui_out_table_header_info(const std::vector< bound_probe > &probes, const static_probe_ops *spops)
Definition: probe.c:360
probe::get_relocated_address
virtual CORE_ADDR get_relocated_address(struct objfile *objfile)=0
any_static_probe_ops
const any_static_probe_ops any_static_probe_ops
Definition: probe.c:63
objfile_name
const char * objfile_name(const struct objfile *objfile)
Definition: objfiles.c:1557
probe::get_argument_count
virtual unsigned get_argument_count(struct frame_info *frame)=0
bound_probe
Definition: probe.h:241
keyword
Definition: m2-exp.c:2540
gdb_assert
#define gdb_assert(expr)
Definition: gdb_assert.h:32
value
Definition: value.c:169
event_location_type
event_location_type
Definition: location.h:54
disablelist
struct cmd_list_element * disablelist
Definition: cli-cmds.c:91
new_probe_location
event_location_up new_probe_location(const char *probe)
Definition: location.c:155
all_static_probe_ops
std::vector< const static_probe_ops * > all_static_probe_ops
Definition: probe.c:882
any_static_probe_ops::is_linespec
bool is_linespec(const char **linespecp) const override
Definition: probe.c:747
objfile
Definition: objfiles.h:286
symtab_and_line
Definition: symtab.h:1746
static_probe_ops::can_enable
virtual bool can_enable() const
Definition: probe.h:74
gdb::optional::emplace
T & emplace(Args &&... args)
Definition: gdb_optional.h:152
linespec_result::special_display
bool special_display
Definition: linespec.h:66
ALL_PSPACES
#define ALL_PSPACES(pspace)
Definition: progspace.h:243
gdb::optional< compiled_regex >
PROBE_LOCATION
Definition: location.h:66
class_breakpoint
Definition: command.h:42
linespec_result
Definition: linespec.h:56
symtab_and_line::pspace
struct program_space * pspace
Definition: symtab.h:1749
probe::compile_to_ax
virtual void compile_to_ax(struct agent_expr *aexpr, struct axs_value *axs_value, unsigned n)=0
static_probe_ops::type_name
virtual const char * type_name() const =0
symtab_and_line::prob
probe * prob
Definition: symtab.h:1765
symtab_and_line::pc
CORE_ADDR pc
Definition: symtab.h:1759
probe.h
find_probe_by_pc
struct bound_probe find_probe_by_pc(CORE_ADDR pc)
Definition: probe.c:247
value.h
location.h
ax_const_l
void ax_const_l(struct agent_expr *x, LONGEST l)
Definition: ax-general.c:229
parse_probe_linespec
static void parse_probe_linespec(const char *str, std::string *provider, std::string *probe_name, std::string *objname)
Definition: probe.c:472
find_probes_in_objfile
std::vector< probe * > find_probes_in_objfile(struct objfile *objfile, const char *provider, const char *name)
Definition: probe.c:220
core_addr_to_string
const char * core_addr_to_string(const CORE_ADDR addr)
Definition: print-utils.c:295
probe::disable
virtual void disable()
Definition: probe.h:193
ALL_OBJFILES
#define ALL_OBJFILES(obj)
Definition: objfiles.h:582
compute_probe_arg
static struct value * compute_probe_arg(struct gdbarch *arch, struct internalvar *ivar, void *data)
Definition: probe.c:809
probe::get_static_ops
virtual const static_probe_ops * get_static_ops() const =0
ALL_PSPACE_OBJFILES
#define ALL_PSPACE_OBJFILES(ss, obj)
Definition: objfiles.h:579
enable_probes_command
static void enable_probes_command(const char *arg, int from_tty)
Definition: probe.c:623
create_internalvar_type_lazy
struct internalvar * create_internalvar_type_lazy(const char *name, const struct internalvar_funcs *funcs, void *data)
Definition: value.c:2177
ui_out_emit_table
Definition: ui-out.h:219
error
void error(const char *fmt,...)
Definition: errors.c:38
get_number_extra_fields
static int get_number_extra_fields(const static_probe_ops *spops)
Definition: probe.c:449
throw_error
void throw_error(enum errors error, const char *fmt,...)
Definition: common-exceptions.c:389
symtab_and_line::explicit_pc
bool explicit_pc
Definition: symtab.h:1761
program_space
Definition: progspace.h:137
probe::get_gdbarch
struct gdbarch * get_gdbarch() const
Definition: probe.h:215
agent_expr::scope
CORE_ADDR scope
Definition: ax.h:103
builtin_type::builtin_int
struct type * builtin_int
Definition: gdbtypes.h:1503
compiled_regex::exec
int exec(const char *string, size_t nmatch, regmatch_t pmatch[], int eflags) const
Definition: gdb_regex.c:45