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