1 /* DTrace probe support for GDB.
3 Copyright (C) 2014-2016 Free Software Foundation, Inc.
5 Contributed by Oracle, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
29 #include "complaints.h"
34 #include "parser-defs.h"
37 /* The type of the ELF sections where we will find the DOF programs
38 with information about probes. */
41 # define SHT_SUNW_dof 0x6ffffff4
44 /* Forward declaration. */
46 extern const struct probe_ops dtrace_probe_ops;
48 /* The following structure represents a single argument for the
51 struct dtrace_probe_arg
53 /* The type of the probe argument. */
56 /* A string describing the type. */
59 /* The argument converted to an internal GDB expression. */
60 struct expression *expr;
63 typedef struct dtrace_probe_arg dtrace_probe_arg_s;
64 DEF_VEC_O (dtrace_probe_arg_s);
66 /* The following structure represents an enabler for a probe. */
68 struct dtrace_probe_enabler
70 /* Program counter where the is-enabled probe is installed. The
71 contents (nops, whatever...) stored at this address are
72 architecture dependent. */
76 typedef struct dtrace_probe_enabler dtrace_probe_enabler_s;
77 DEF_VEC_O (dtrace_probe_enabler_s);
79 /* The following structure represents a dtrace probe. */
83 /* Generic information about the probe. This must be the first
84 element of this struct, in order to maintain binary compatibility
85 with the `struct probe' and be able to fully abstract it. */
88 /* A probe can have zero or more arguments. */
90 VEC (dtrace_probe_arg_s) *args;
92 /* A probe can have zero or more "enablers" associated with it. */
93 VEC (dtrace_probe_enabler_s) *enablers;
95 /* Whether the expressions for the arguments have been built. */
96 unsigned int args_expr_built : 1;
99 /* Implementation of the probe_is_linespec method. */
102 dtrace_probe_is_linespec (const char **linespecp)
104 static const char *const keywords[] = { "-pdtrace", "-probe-dtrace", NULL };
106 return probe_is_linespec_by_keyword (linespecp, keywords);
109 /* DOF programs can contain an arbitrary number of sections of 26
110 different types. In order to support DTrace USDT probes we only
111 need to handle a subset of these section types, fortunately. These
112 section types are defined in the following enumeration.
114 See linux/dtrace/dof_defines.h for a complete list of section types
115 along with their values. */
117 enum dtrace_dof_sect_type
120 DTRACE_DOF_SECT_TYPE_NONE = 0,
121 /* A dof_ecbdesc_t. */
122 DTRACE_DOF_SECT_TYPE_ECBDESC = 3,
123 /* A string table. */
124 DTRACE_DOF_SECT_TYPE_STRTAB = 8,
125 /* A dof_provider_t */
126 DTRACE_DOF_SECT_TYPE_PROVIDER = 15,
127 /* Array of dof_probe_t */
128 DTRACE_DOF_SECT_TYPE_PROBES = 16,
129 /* An array of probe arg mappings. */
130 DTRACE_DOF_SECT_TYPE_PRARGS = 17,
131 /* An array of probe arg offsets. */
132 DTRACE_DOF_SECT_TYPE_PROFFS = 18,
133 /* An array of probe is-enabled offsets. */
134 DTRACE_DOF_SECT_TYPE_PRENOFFS = 26
137 /* The following collection of data structures map the structure of
138 DOF entities. Again, we only cover the subset of DOF used to
139 implement USDT probes.
141 See linux/dtrace/dof.h header for a complete list of data
144 /* Offsets to index the dofh_ident[] array defined below. */
146 enum dtrace_dof_ident
148 /* First byte of the magic number. */
149 DTRACE_DOF_ID_MAG0 = 0,
150 /* Second byte of the magic number. */
151 DTRACE_DOF_ID_MAG1 = 1,
152 /* Third byte of the magic number. */
153 DTRACE_DOF_ID_MAG2 = 2,
154 /* Fourth byte of the magic number. */
155 DTRACE_DOF_ID_MAG3 = 3,
156 /* An enum_dof_encoding value. */
157 DTRACE_DOF_ID_ENCODING = 5
160 /* Possible values for dofh_ident[DOF_ID_ENCODING]. */
162 enum dtrace_dof_encoding
164 /* The DOF program is little-endian. */
165 DTRACE_DOF_ENCODE_LSB = 1,
166 /* The DOF program is big-endian. */
167 DTRACE_DOF_ENCODE_MSB = 2
170 /* A DOF header, which describes the contents of a DOF program: number
171 of sections, size, etc. */
173 struct dtrace_dof_hdr
175 /* Identification bytes (see above). */
176 uint8_t dofh_ident[16];
177 /* File attribute flags (if any). */
179 /* Size of file header in bytes. */
180 uint32_t dofh_hdrsize;
181 /* Size of section header in bytes. */
182 uint32_t dofh_secsize;
183 /* Number of section headers. */
184 uint32_t dofh_secnum;
185 /* File offset of section headers. */
186 uint64_t dofh_secoff;
187 /* File size of loadable portion. */
188 uint64_t dofh_loadsz;
189 /* File size of entire DOF file. */
190 uint64_t dofh_filesz;
191 /* Reserved for future use. */
195 /* A DOF section, whose contents depend on its type. The several
196 supported section types are described in the enum
197 dtrace_dof_sect_type above. */
199 struct dtrace_dof_sect
201 /* Section type (see the define above). */
203 /* Section data memory alignment. */
205 /* Section flags (if any). */
207 /* Size of section entry (if table). */
208 uint32_t dofs_entsize;
209 /* DOF + offset points to the section data. */
210 uint64_t dofs_offset;
211 /* Size of section data in bytes. */
215 /* A DOF provider, which is the provider of a probe. */
217 struct dtrace_dof_provider
219 /* Link to a DTRACE_DOF_SECT_TYPE_STRTAB section. */
220 uint32_t dofpv_strtab;
221 /* Link to a DTRACE_DOF_SECT_TYPE_PROBES section. */
222 uint32_t dofpv_probes;
223 /* Link to a DTRACE_DOF_SECT_TYPE_PRARGS section. */
224 uint32_t dofpv_prargs;
225 /* Link to a DTRACE_DOF_SECT_TYPE_PROFFS section. */
226 uint32_t dofpv_proffs;
227 /* Provider name string. */
229 /* Provider attributes. */
230 uint32_t dofpv_provattr;
231 /* Module attributes. */
232 uint32_t dofpv_modattr;
233 /* Function attributes. */
234 uint32_t dofpv_funcattr;
235 /* Name attributes. */
236 uint32_t dofpv_nameattr;
237 /* Args attributes. */
238 uint32_t dofpv_argsattr;
239 /* Link to a DTRACE_DOF_SECT_PRENOFFS section. */
240 uint32_t dofpv_prenoffs;
243 /* A set of DOF probes and is-enabled probes sharing a base address
244 and several attributes. The particular locations and attributes of
245 each probe are maintained in arrays in several other DOF sections.
246 See the comment in dtrace_process_dof_probe for details on how
247 these attributes are stored. */
249 struct dtrace_dof_probe
251 /* Probe base address or offset. */
253 /* Probe function string. */
255 /* Probe name string. */
257 /* Native argument type strings. */
258 uint32_t dofpr_nargv;
259 /* Translated argument type strings. */
260 uint32_t dofpr_xargv;
261 /* Index of first argument mapping. */
262 uint32_t dofpr_argidx;
263 /* Index of first offset entry. */
264 uint32_t dofpr_offidx;
265 /* Native argument count. */
267 /* Translated argument count. */
269 /* Number of offset entries for probe. */
270 uint16_t dofpr_noffs;
271 /* Index of first is-enabled offset. */
272 uint32_t dofpr_enoffidx;
273 /* Number of is-enabled offsets. */
274 uint16_t dofpr_nenoffs;
275 /* Reserved for future use. */
277 /* Reserved for future use. */
281 /* DOF supports two different encodings: MSB (big-endian) and LSB
282 (little-endian). The encoding is itself encoded in the DOF header.
283 The following function returns an unsigned value in the host
286 #define DOF_UINT(dof, field) \
287 extract_unsigned_integer ((gdb_byte *) &(field), \
289 (((dof)->dofh_ident[DTRACE_DOF_ID_ENCODING] \
290 == DTRACE_DOF_ENCODE_MSB) \
291 ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE))
293 /* The following macro applies a given byte offset to a DOF (a pointer
294 to a dtrace_dof_hdr structure) and returns the resulting
297 #define DTRACE_DOF_PTR(dof, offset) (&((char *) (dof))[(offset)])
299 /* The following macro returns a pointer to the beginning of a given
300 section in a DOF object. The section is referred to by its index
301 in the sections array. */
303 #define DTRACE_DOF_SECT(dof, idx) \
304 ((struct dtrace_dof_sect *) \
305 DTRACE_DOF_PTR ((dof), \
306 DOF_UINT ((dof), (dof)->dofh_secoff) \
307 + ((idx) * DOF_UINT ((dof), (dof)->dofh_secsize))))
309 /* Helper function to examine the probe described by the given PROBE
310 and PROVIDER data structures and add it to the PROBESP vector.
311 STRTAB, OFFTAB, EOFFTAB and ARGTAB are pointers to tables in the
312 DOF program containing the attributes for the probe. */
315 dtrace_process_dof_probe (struct objfile *objfile,
316 struct gdbarch *gdbarch, VEC (probe_p) **probesp,
317 struct dtrace_dof_hdr *dof,
318 struct dtrace_dof_probe *probe,
319 struct dtrace_dof_provider *provider,
320 char *strtab, char *offtab, char *eofftab,
321 char *argtab, uint64_t strtab_size)
323 int i, j, num_probes, num_enablers;
324 struct cleanup *cleanup;
325 VEC (dtrace_probe_enabler_s) *enablers;
328 /* Each probe section can define zero or more probes of two
331 - probe->dofpr_noffs regular probes whose program counters are
332 stored in 32bit words starting at probe->dofpr_addr +
333 offtab[probe->dofpr_offidx].
335 - probe->dofpr_nenoffs is-enabled probes whose program counters
336 are stored in 32bit words starting at probe->dofpr_addr +
337 eofftab[probe->dofpr_enoffidx].
339 However is-enabled probes are not probes per-se, but an
340 optimization hack that is implemented in the kernel in a very
341 similar way than normal probes. This is how we support
342 is-enabled probes on GDB:
344 - Our probes are always DTrace regular probes.
346 - Our probes can be associated with zero or more "enablers". The
347 list of enablers is built from the is-enabled probes defined in
350 - Probes having a non-empty list of enablers can be enabled or
351 disabled using the `enable probe' and `disable probe' commands
352 respectively. The `Enabled' column in the output of `info
353 probes' will read `yes' if the enablers are activated, `no'
356 - Probes having an empty list of enablers are always enabled.
357 The `Enabled' column in the output of `info probes' will
360 It follows that if there are DTrace is-enabled probes defined for
361 some provider/name but no DTrace regular probes defined then the
362 GDB user wont be able to enable/disable these conditionals. */
364 num_probes = DOF_UINT (dof, probe->dofpr_noffs);
368 /* Build the list of enablers for the probes defined in this Probe
372 = make_cleanup (VEC_cleanup (dtrace_probe_enabler_s), &enablers);
373 num_enablers = DOF_UINT (dof, probe->dofpr_nenoffs);
374 for (i = 0; i < num_enablers; i++)
376 struct dtrace_probe_enabler enabler;
377 uint32_t enabler_offset
378 = ((uint32_t *) eofftab)[DOF_UINT (dof, probe->dofpr_enoffidx) + i];
380 enabler.address = DOF_UINT (dof, probe->dofpr_addr)
381 + DOF_UINT (dof, enabler_offset);
382 VEC_safe_push (dtrace_probe_enabler_s, enablers, &enabler);
385 for (i = 0; i < num_probes; i++)
387 uint32_t probe_offset
388 = ((uint32_t *) offtab)[DOF_UINT (dof, probe->dofpr_offidx) + i];
389 struct dtrace_probe *ret =
390 XOBNEW (&objfile->per_bfd->storage_obstack, struct dtrace_probe);
392 ret->p.pops = &dtrace_probe_ops;
393 ret->p.arch = gdbarch;
394 ret->args_expr_built = 0;
396 /* Set the provider and the name of the probe. */
398 = xstrdup (strtab + DOF_UINT (dof, provider->dofpv_name));
399 ret->p.name = xstrdup (strtab + DOF_UINT (dof, probe->dofpr_name));
401 /* The probe address. */
403 = DOF_UINT (dof, probe->dofpr_addr) + DOF_UINT (dof, probe_offset);
405 /* Number of arguments in the probe. */
406 ret->probe_argc = DOF_UINT (dof, probe->dofpr_nargc);
408 /* Store argument type descriptions. A description of the type
409 of the argument is in the (J+1)th null-terminated string
410 starting at 'strtab' + 'probe->dofpr_nargv'. */
412 p = strtab + DOF_UINT (dof, probe->dofpr_nargv);
413 for (j = 0; j < ret->probe_argc; j++)
415 struct dtrace_probe_arg arg;
416 struct expression *expr = NULL;
418 /* Set arg.expr to ensure all fields in expr are initialized and
419 the compiler will not warn when arg is used. */
421 arg.type_str = xstrdup (p);
423 /* Use strtab_size as a sentinel. */
424 while (*p++ != '\0' && p - strtab < strtab_size);
426 /* Try to parse a type expression from the type string. If
427 this does not work then we set the type to `long
429 arg.type = builtin_type (gdbarch)->builtin_long;
433 expr = parse_expression_with_language (arg.type_str, language_c);
435 CATCH (ex, RETURN_MASK_ERROR)
441 if (expr != NULL && expr->elts[0].opcode == OP_TYPE)
442 arg.type = expr->elts[1].type;
444 VEC_safe_push (dtrace_probe_arg_s, ret->args, &arg);
447 /* Add the vector of enablers to this probe, if any. */
448 ret->enablers = VEC_copy (dtrace_probe_enabler_s, enablers);
450 /* Successfully created probe. */
451 VEC_safe_push (probe_p, *probesp, (struct probe *) ret);
454 do_cleanups (cleanup);
457 /* Helper function to collect the probes described in the DOF program
458 whose header is pointed by DOF and add them to the PROBESP vector.
459 SECT is the ELF section containing the DOF program and OBJFILE is
460 its containing object file. */
463 dtrace_process_dof (asection *sect, struct objfile *objfile,
464 VEC (probe_p) **probesp, struct dtrace_dof_hdr *dof)
466 bfd *abfd = objfile->obfd;
467 int size = bfd_get_arch_size (abfd) / 8;
468 struct gdbarch *gdbarch = get_objfile_arch (objfile);
469 struct dtrace_dof_sect *section;
472 /* The first step is to check for the DOF magic number. If no valid
473 DOF data is found in the section then a complaint is issued to
474 the user and the section skipped. */
475 if (dof->dofh_ident[DTRACE_DOF_ID_MAG0] != 0x7F
476 || dof->dofh_ident[DTRACE_DOF_ID_MAG1] != 'D'
477 || dof->dofh_ident[DTRACE_DOF_ID_MAG2] != 'O'
478 || dof->dofh_ident[DTRACE_DOF_ID_MAG3] != 'F')
479 goto invalid_dof_data;
481 /* Make sure the encoding mark is either DTRACE_DOF_ENCODE_LSB or
482 DTRACE_DOF_ENCODE_MSB. */
483 if (dof->dofh_ident[DTRACE_DOF_ID_ENCODING] != DTRACE_DOF_ENCODE_LSB
484 && dof->dofh_ident[DTRACE_DOF_ID_ENCODING] != DTRACE_DOF_ENCODE_MSB)
485 goto invalid_dof_data;
487 /* Make sure this DOF is not an enabling DOF, i.e. there are no ECB
488 Description sections. */
489 section = (struct dtrace_dof_sect *) DTRACE_DOF_PTR (dof,
490 DOF_UINT (dof, dof->dofh_secoff));
491 for (i = 0; i < DOF_UINT (dof, dof->dofh_secnum); i++, section++)
492 if (section->dofs_type == DTRACE_DOF_SECT_TYPE_ECBDESC)
495 /* Iterate over any section of type Provider and extract the probe
496 information from them. If there are no "provider" sections on
497 the DOF then we just return. */
498 section = (struct dtrace_dof_sect *) DTRACE_DOF_PTR (dof,
499 DOF_UINT (dof, dof->dofh_secoff));
500 for (i = 0; i < DOF_UINT (dof, dof->dofh_secnum); i++, section++)
501 if (DOF_UINT (dof, section->dofs_type) == DTRACE_DOF_SECT_TYPE_PROVIDER)
503 struct dtrace_dof_provider *provider = (struct dtrace_dof_provider *)
504 DTRACE_DOF_PTR (dof, DOF_UINT (dof, section->dofs_offset));
505 struct dtrace_dof_sect *strtab_s
506 = DTRACE_DOF_SECT (dof, DOF_UINT (dof, provider->dofpv_strtab));
507 struct dtrace_dof_sect *probes_s
508 = DTRACE_DOF_SECT (dof, DOF_UINT (dof, provider->dofpv_probes));
509 struct dtrace_dof_sect *args_s
510 = DTRACE_DOF_SECT (dof, DOF_UINT (dof, provider->dofpv_prargs));
511 struct dtrace_dof_sect *offsets_s
512 = DTRACE_DOF_SECT (dof, DOF_UINT (dof, provider->dofpv_proffs));
513 struct dtrace_dof_sect *eoffsets_s
514 = DTRACE_DOF_SECT (dof, DOF_UINT (dof, provider->dofpv_prenoffs));
515 char *strtab = DTRACE_DOF_PTR (dof, DOF_UINT (dof, strtab_s->dofs_offset));
516 char *offtab = DTRACE_DOF_PTR (dof, DOF_UINT (dof, offsets_s->dofs_offset));
517 char *eofftab = DTRACE_DOF_PTR (dof, DOF_UINT (dof, eoffsets_s->dofs_offset));
518 char *argtab = DTRACE_DOF_PTR (dof, DOF_UINT (dof, args_s->dofs_offset));
519 unsigned int entsize = DOF_UINT (dof, probes_s->dofs_entsize);
522 if (DOF_UINT (dof, section->dofs_size)
523 < sizeof (struct dtrace_dof_provider))
525 /* The section is smaller than expected, so do not use it.
526 This has been observed on x86-solaris 10. */
527 goto invalid_dof_data;
530 /* Very, unlikely, but could crash gdb if not handled
533 goto invalid_dof_data;
535 num_probes = DOF_UINT (dof, probes_s->dofs_size) / entsize;
537 for (i = 0; i < num_probes; i++)
539 struct dtrace_dof_probe *probe = (struct dtrace_dof_probe *)
540 DTRACE_DOF_PTR (dof, DOF_UINT (dof, probes_s->dofs_offset)
541 + (i * DOF_UINT (dof, probes_s->dofs_entsize)));
543 dtrace_process_dof_probe (objfile,
546 provider, strtab, offtab, eofftab, argtab,
547 DOF_UINT (dof, strtab_s->dofs_size));
554 complaint (&symfile_complaints,
555 _("skipping section '%s' which does not contain valid DOF data."),
559 /* Helper function to build the GDB internal expressiosn that, once
560 evaluated, will calculate the values of the arguments of a given
564 dtrace_build_arg_exprs (struct dtrace_probe *probe,
565 struct gdbarch *gdbarch)
567 struct parser_state pstate;
568 struct dtrace_probe_arg *arg;
571 probe->args_expr_built = 1;
573 /* Iterate over the arguments in the probe and build the
574 corresponding GDB internal expression that will generate the
575 value of the argument when executed at the PC of the probe. */
576 for (i = 0; i < probe->probe_argc; i++)
578 struct cleanup *back_to;
580 arg = VEC_index (dtrace_probe_arg_s, probe->args, i);
582 /* Initialize the expression buffer in the parser state. The
583 language does not matter, since we are using our own
585 initialize_expout (&pstate, 10, current_language, gdbarch);
586 back_to = make_cleanup (free_current_contents, &pstate.expout);
588 /* The argument value, which is ABI dependent and casted to
590 gdbarch_dtrace_parse_probe_argument (gdbarch, &pstate, i);
592 discard_cleanups (back_to);
594 /* Casting to the expected type, but only if the type was
595 recognized at probe load time. Otherwise the argument will
596 be evaluated as the long integer passed to the probe. */
597 if (arg->type != NULL)
599 write_exp_elt_opcode (&pstate, UNOP_CAST);
600 write_exp_elt_type (&pstate, arg->type);
601 write_exp_elt_opcode (&pstate, UNOP_CAST);
604 reallocate_expout (&pstate);
605 arg->expr = pstate.expout;
606 prefixify_expression (arg->expr);
610 /* Helper function to return the Nth argument of a given PROBE. */
612 static struct dtrace_probe_arg *
613 dtrace_get_arg (struct dtrace_probe *probe, unsigned n,
614 struct gdbarch *gdbarch)
616 if (!probe->args_expr_built)
617 dtrace_build_arg_exprs (probe, gdbarch);
619 return VEC_index (dtrace_probe_arg_s, probe->args, n);
622 /* Implementation of the get_probes method. */
625 dtrace_get_probes (VEC (probe_p) **probesp, struct objfile *objfile)
627 bfd *abfd = objfile->obfd;
628 asection *sect = NULL;
630 /* Do nothing in case this is a .debug file, instead of the objfile
632 if (objfile->separate_debug_objfile_backlink != NULL)
635 /* Iterate over the sections in OBJFILE looking for DTrace
637 for (sect = abfd->sections; sect != NULL; sect = sect->next)
639 if (elf_section_data (sect)->this_hdr.sh_type == SHT_SUNW_dof)
643 /* Read the contents of the DOF section and then process it to
644 extract the information of any probe defined into it. */
645 if (!bfd_malloc_and_get_section (abfd, sect, &dof))
646 complaint (&symfile_complaints,
647 _("could not obtain the contents of"
648 "section '%s' in objfile `%s'."),
649 sect->name, abfd->filename);
651 dtrace_process_dof (sect, objfile, probesp,
652 (struct dtrace_dof_hdr *) dof);
658 /* Helper function to determine whether a given probe is "enabled" or
659 "disabled". A disabled probe is a probe in which one or more
660 enablers are disabled. */
663 dtrace_probe_is_enabled (struct dtrace_probe *probe)
666 struct gdbarch *gdbarch = probe->p.arch;
667 struct dtrace_probe_enabler *enabler;
670 VEC_iterate (dtrace_probe_enabler_s, probe->enablers, i, enabler);
672 if (!gdbarch_dtrace_probe_is_enabled (gdbarch, enabler->address))
678 /* Implementation of the get_probe_address method. */
681 dtrace_get_probe_address (struct probe *probe, struct objfile *objfile)
683 gdb_assert (probe->pops == &dtrace_probe_ops);
684 return probe->address + ANOFFSET (objfile->section_offsets,
685 SECT_OFF_DATA (objfile));
688 /* Implementation of the get_probe_argument_count method. */
691 dtrace_get_probe_argument_count (struct probe *probe_generic,
692 struct frame_info *frame)
694 struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe_generic;
696 gdb_assert (probe_generic->pops == &dtrace_probe_ops);
698 return dtrace_probe->probe_argc;
701 /* Implementation of the can_evaluate_probe_arguments method. */
704 dtrace_can_evaluate_probe_arguments (struct probe *probe_generic)
706 struct gdbarch *gdbarch = probe_generic->arch;
708 gdb_assert (probe_generic->pops == &dtrace_probe_ops);
709 return gdbarch_dtrace_parse_probe_argument_p (gdbarch);
712 /* Implementation of the evaluate_probe_argument method. */
714 static struct value *
715 dtrace_evaluate_probe_argument (struct probe *probe_generic, unsigned n,
716 struct frame_info *frame)
718 struct gdbarch *gdbarch = probe_generic->arch;
719 struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe_generic;
720 struct dtrace_probe_arg *arg;
723 gdb_assert (probe_generic->pops == &dtrace_probe_ops);
725 arg = dtrace_get_arg (dtrace_probe, n, gdbarch);
726 return evaluate_subexp_standard (arg->type, arg->expr, &pos, EVAL_NORMAL);
729 /* Implementation of the compile_to_ax method. */
732 dtrace_compile_to_ax (struct probe *probe_generic, struct agent_expr *expr,
733 struct axs_value *value, unsigned n)
735 struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe_generic;
736 struct dtrace_probe_arg *arg;
737 union exp_element *pc;
739 gdb_assert (probe_generic->pops == &dtrace_probe_ops);
741 arg = dtrace_get_arg (dtrace_probe, n, expr->gdbarch);
743 pc = arg->expr->elts;
744 gen_expr (arg->expr, &pc, expr, value);
746 require_rvalue (expr, value);
747 value->type = arg->type;
750 /* Implementation of the probe_destroy method. */
753 dtrace_probe_destroy (struct probe *probe_generic)
755 struct dtrace_probe *probe = (struct dtrace_probe *) probe_generic;
756 struct dtrace_probe_arg *arg;
759 gdb_assert (probe_generic->pops == &dtrace_probe_ops);
761 for (i = 0; VEC_iterate (dtrace_probe_arg_s, probe->args, i, arg); i++)
763 xfree (arg->type_str);
767 VEC_free (dtrace_probe_enabler_s, probe->enablers);
768 VEC_free (dtrace_probe_arg_s, probe->args);
771 /* Implementation of the type_name method. */
774 dtrace_type_name (struct probe *probe_generic)
776 gdb_assert (probe_generic->pops == &dtrace_probe_ops);
780 /* Implementation of the gen_info_probes_table_header method. */
783 dtrace_gen_info_probes_table_header (VEC (info_probe_column_s) **heads)
785 info_probe_column_s dtrace_probe_column;
787 dtrace_probe_column.field_name = "enabled";
788 dtrace_probe_column.print_name = _("Enabled");
790 VEC_safe_push (info_probe_column_s, *heads, &dtrace_probe_column);
793 /* Implementation of the gen_info_probes_table_values method. */
796 dtrace_gen_info_probes_table_values (struct probe *probe_generic,
797 VEC (const_char_ptr) **ret)
799 struct dtrace_probe *probe = (struct dtrace_probe *) probe_generic;
800 const char *val = NULL;
802 gdb_assert (probe_generic->pops == &dtrace_probe_ops);
804 if (VEC_empty (dtrace_probe_enabler_s, probe->enablers))
806 else if (!gdbarch_dtrace_probe_is_enabled_p (probe_generic->arch))
808 else if (dtrace_probe_is_enabled (probe))
813 VEC_safe_push (const_char_ptr, *ret, val);
816 /* Implementation of the enable_probe method. */
819 dtrace_enable_probe (struct probe *probe)
821 struct gdbarch *gdbarch = probe->arch;
822 struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe;
823 struct dtrace_probe_enabler *enabler;
826 gdb_assert (probe->pops == &dtrace_probe_ops);
828 /* Enabling a dtrace probe implies patching the text section of the
829 running process, so make sure the inferior is indeed running. */
830 if (ptid_equal (inferior_ptid, null_ptid))
831 error (_("No inferior running"));
834 if (dtrace_probe_is_enabled (dtrace_probe))
837 /* Iterate over all defined enabler in the given probe and enable
838 them all using the corresponding gdbarch hook. */
841 VEC_iterate (dtrace_probe_enabler_s, dtrace_probe->enablers, i, enabler);
843 if (gdbarch_dtrace_enable_probe_p (gdbarch))
844 gdbarch_dtrace_enable_probe (gdbarch, enabler->address);
848 /* Implementation of the disable_probe method. */
851 dtrace_disable_probe (struct probe *probe)
853 struct gdbarch *gdbarch = probe->arch;
854 struct dtrace_probe *dtrace_probe = (struct dtrace_probe *) probe;
855 struct dtrace_probe_enabler *enabler;
858 gdb_assert (probe->pops == &dtrace_probe_ops);
860 /* Disabling a dtrace probe implies patching the text section of the
861 running process, so make sure the inferior is indeed running. */
862 if (ptid_equal (inferior_ptid, null_ptid))
863 error (_("No inferior running"));
866 if (!dtrace_probe_is_enabled (dtrace_probe))
869 /* Are we trying to disable a probe that does not have any enabler
871 if (VEC_empty (dtrace_probe_enabler_s, dtrace_probe->enablers))
872 error (_("Probe %s:%s cannot be disabled: no enablers."), probe->provider, probe->name);
874 /* Iterate over all defined enabler in the given probe and disable
875 them all using the corresponding gdbarch hook. */
878 VEC_iterate (dtrace_probe_enabler_s, dtrace_probe->enablers, i, enabler);
880 if (gdbarch_dtrace_disable_probe_p (gdbarch))
881 gdbarch_dtrace_disable_probe (gdbarch, enabler->address);
884 /* DTrace probe_ops. */
886 const struct probe_ops dtrace_probe_ops =
888 dtrace_probe_is_linespec,
890 dtrace_get_probe_address,
891 dtrace_get_probe_argument_count,
892 dtrace_can_evaluate_probe_arguments,
893 dtrace_evaluate_probe_argument,
894 dtrace_compile_to_ax,
895 NULL, /* set_semaphore */
896 NULL, /* clear_semaphore */
897 dtrace_probe_destroy,
899 dtrace_gen_info_probes_table_header,
900 dtrace_gen_info_probes_table_values,
905 /* Implementation of the `info probes dtrace' command. */
908 info_probes_dtrace_command (char *arg, int from_tty)
910 info_probes_for_ops (arg, from_tty, &dtrace_probe_ops);
913 void _initialize_dtrace_probe (void);
916 _initialize_dtrace_probe (void)
918 VEC_safe_push (probe_ops_cp, all_probe_ops, &dtrace_probe_ops);
920 add_cmd ("dtrace", class_info, info_probes_dtrace_command,
922 Show information about DTrace static probes.\n\
923 Usage: info probes dtrace [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."),
928 info_probes_cmdlist_get ());