1 /* DTrace probe support for GDB.
3 Copyright (C) 2014-2018 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 /* The following structure represents a single argument for the
47 struct dtrace_probe_arg
49 dtrace_probe_arg (struct type
*type_
, std::string
&&type_str_
,
50 expression_up
&&expr_
)
51 : type (type_
), type_str (std::move (type_str_
)),
52 expr (std::move (expr_
))
55 /* The type of the probe argument. */
58 /* A string describing the type. */
61 /* The argument converted to an internal GDB expression. */
65 /* The following structure represents an enabler for a probe. */
67 struct dtrace_probe_enabler
69 /* Program counter where the is-enabled probe is installed. The
70 contents (nops, whatever...) stored at this address are
71 architecture dependent. */
75 /* Class that implements the static probe methods for "stap" probes. */
77 class dtrace_static_probe_ops
: public static_probe_ops
81 bool is_linespec (const char **linespecp
) const override
;
84 void get_probes (std::vector
<probe
*> *probesp
,
85 struct objfile
*objfile
) const override
;
88 const char *type_name () const override
;
91 bool can_enable () const override
97 std::vector
<struct info_probe_column
> gen_info_probes_table_header
101 /* DTrace static_probe_ops. */
103 const dtrace_static_probe_ops dtrace_static_probe_ops
;
105 /* The following structure represents a dtrace probe. */
107 class dtrace_probe
: public probe
110 /* Constructor for dtrace_probe. */
111 dtrace_probe (std::string
&&name_
, std::string
&&provider_
, CORE_ADDR address_
,
112 struct gdbarch
*arch_
,
113 std::vector
<struct dtrace_probe_arg
> &&args_
,
114 std::vector
<struct dtrace_probe_enabler
> &&enablers_
)
115 : probe (std::move (name_
), std::move (provider_
), address_
, arch_
),
116 m_args (std::move (args_
)),
117 m_enablers (std::move (enablers_
)),
118 m_args_expr_built (false)
122 CORE_ADDR
get_relocated_address (struct objfile
*objfile
) override
;
125 unsigned get_argument_count (struct frame_info
*frame
) override
;
128 bool can_evaluate_arguments () const override
;
131 struct value
*evaluate_argument (unsigned n
,
132 struct frame_info
*frame
) override
;
135 void compile_to_ax (struct agent_expr
*aexpr
,
136 struct axs_value
*axs_value
,
137 unsigned n
) override
;
140 const static_probe_ops
*get_static_ops () const override
;
143 std::vector
<const char *> gen_info_probes_table_values () const override
;
146 void enable () override
;
149 void disable () override
;
151 /* Return the Nth argument of the probe. */
152 struct dtrace_probe_arg
*get_arg_by_number (unsigned n
,
153 struct gdbarch
*gdbarch
);
155 /* Build the GDB internal expressiosn that, once evaluated, will
156 calculate the values of the arguments of the probe. */
157 void build_arg_exprs (struct gdbarch
*gdbarch
);
159 /* Determine whether the probe is "enabled" or "disabled". A
160 disabled probe is a probe in which one or more enablers are
162 bool is_enabled () const;
165 /* A probe can have zero or more arguments. */
166 std::vector
<struct dtrace_probe_arg
> m_args
;
168 /* A probe can have zero or more "enablers" associated with it. */
169 std::vector
<struct dtrace_probe_enabler
> m_enablers
;
171 /* Whether the expressions for the arguments have been built. */
172 bool m_args_expr_built
;
175 /* DOF programs can contain an arbitrary number of sections of 26
176 different types. In order to support DTrace USDT probes we only
177 need to handle a subset of these section types, fortunately. These
178 section types are defined in the following enumeration.
180 See linux/dtrace/dof_defines.h for a complete list of section types
181 along with their values. */
183 enum dtrace_dof_sect_type
186 DTRACE_DOF_SECT_TYPE_NONE
= 0,
187 /* A dof_ecbdesc_t. */
188 DTRACE_DOF_SECT_TYPE_ECBDESC
= 3,
189 /* A string table. */
190 DTRACE_DOF_SECT_TYPE_STRTAB
= 8,
191 /* A dof_provider_t */
192 DTRACE_DOF_SECT_TYPE_PROVIDER
= 15,
193 /* Array of dof_probe_t */
194 DTRACE_DOF_SECT_TYPE_PROBES
= 16,
195 /* An array of probe arg mappings. */
196 DTRACE_DOF_SECT_TYPE_PRARGS
= 17,
197 /* An array of probe arg offsets. */
198 DTRACE_DOF_SECT_TYPE_PROFFS
= 18,
199 /* An array of probe is-enabled offsets. */
200 DTRACE_DOF_SECT_TYPE_PRENOFFS
= 26
203 /* The following collection of data structures map the structure of
204 DOF entities. Again, we only cover the subset of DOF used to
205 implement USDT probes.
207 See linux/dtrace/dof.h header for a complete list of data
210 /* Offsets to index the dofh_ident[] array defined below. */
212 enum dtrace_dof_ident
214 /* First byte of the magic number. */
215 DTRACE_DOF_ID_MAG0
= 0,
216 /* Second byte of the magic number. */
217 DTRACE_DOF_ID_MAG1
= 1,
218 /* Third byte of the magic number. */
219 DTRACE_DOF_ID_MAG2
= 2,
220 /* Fourth byte of the magic number. */
221 DTRACE_DOF_ID_MAG3
= 3,
222 /* An enum_dof_encoding value. */
223 DTRACE_DOF_ID_ENCODING
= 5
226 /* Possible values for dofh_ident[DOF_ID_ENCODING]. */
228 enum dtrace_dof_encoding
230 /* The DOF program is little-endian. */
231 DTRACE_DOF_ENCODE_LSB
= 1,
232 /* The DOF program is big-endian. */
233 DTRACE_DOF_ENCODE_MSB
= 2
236 /* A DOF header, which describes the contents of a DOF program: number
237 of sections, size, etc. */
239 struct dtrace_dof_hdr
241 /* Identification bytes (see above). */
242 uint8_t dofh_ident
[16];
243 /* File attribute flags (if any). */
245 /* Size of file header in bytes. */
246 uint32_t dofh_hdrsize
;
247 /* Size of section header in bytes. */
248 uint32_t dofh_secsize
;
249 /* Number of section headers. */
250 uint32_t dofh_secnum
;
251 /* File offset of section headers. */
252 uint64_t dofh_secoff
;
253 /* File size of loadable portion. */
254 uint64_t dofh_loadsz
;
255 /* File size of entire DOF file. */
256 uint64_t dofh_filesz
;
257 /* Reserved for future use. */
261 /* A DOF section, whose contents depend on its type. The several
262 supported section types are described in the enum
263 dtrace_dof_sect_type above. */
265 struct dtrace_dof_sect
267 /* Section type (see the define above). */
269 /* Section data memory alignment. */
271 /* Section flags (if any). */
273 /* Size of section entry (if table). */
274 uint32_t dofs_entsize
;
275 /* DOF + offset points to the section data. */
276 uint64_t dofs_offset
;
277 /* Size of section data in bytes. */
281 /* A DOF provider, which is the provider of a probe. */
283 struct dtrace_dof_provider
285 /* Link to a DTRACE_DOF_SECT_TYPE_STRTAB section. */
286 uint32_t dofpv_strtab
;
287 /* Link to a DTRACE_DOF_SECT_TYPE_PROBES section. */
288 uint32_t dofpv_probes
;
289 /* Link to a DTRACE_DOF_SECT_TYPE_PRARGS section. */
290 uint32_t dofpv_prargs
;
291 /* Link to a DTRACE_DOF_SECT_TYPE_PROFFS section. */
292 uint32_t dofpv_proffs
;
293 /* Provider name string. */
295 /* Provider attributes. */
296 uint32_t dofpv_provattr
;
297 /* Module attributes. */
298 uint32_t dofpv_modattr
;
299 /* Function attributes. */
300 uint32_t dofpv_funcattr
;
301 /* Name attributes. */
302 uint32_t dofpv_nameattr
;
303 /* Args attributes. */
304 uint32_t dofpv_argsattr
;
305 /* Link to a DTRACE_DOF_SECT_PRENOFFS section. */
306 uint32_t dofpv_prenoffs
;
309 /* A set of DOF probes and is-enabled probes sharing a base address
310 and several attributes. The particular locations and attributes of
311 each probe are maintained in arrays in several other DOF sections.
312 See the comment in dtrace_process_dof_probe for details on how
313 these attributes are stored. */
315 struct dtrace_dof_probe
317 /* Probe base address or offset. */
319 /* Probe function string. */
321 /* Probe name string. */
323 /* Native argument type strings. */
324 uint32_t dofpr_nargv
;
325 /* Translated argument type strings. */
326 uint32_t dofpr_xargv
;
327 /* Index of first argument mapping. */
328 uint32_t dofpr_argidx
;
329 /* Index of first offset entry. */
330 uint32_t dofpr_offidx
;
331 /* Native argument count. */
333 /* Translated argument count. */
335 /* Number of offset entries for probe. */
336 uint16_t dofpr_noffs
;
337 /* Index of first is-enabled offset. */
338 uint32_t dofpr_enoffidx
;
339 /* Number of is-enabled offsets. */
340 uint16_t dofpr_nenoffs
;
341 /* Reserved for future use. */
343 /* Reserved for future use. */
347 /* DOF supports two different encodings: MSB (big-endian) and LSB
348 (little-endian). The encoding is itself encoded in the DOF header.
349 The following function returns an unsigned value in the host
352 #define DOF_UINT(dof, field) \
353 extract_unsigned_integer ((gdb_byte *) &(field), \
355 (((dof)->dofh_ident[DTRACE_DOF_ID_ENCODING] \
356 == DTRACE_DOF_ENCODE_MSB) \
357 ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE))
359 /* The following macro applies a given byte offset to a DOF (a pointer
360 to a dtrace_dof_hdr structure) and returns the resulting
363 #define DTRACE_DOF_PTR(dof, offset) (&((char *) (dof))[(offset)])
365 /* The following macro returns a pointer to the beginning of a given
366 section in a DOF object. The section is referred to by its index
367 in the sections array. */
369 #define DTRACE_DOF_SECT(dof, idx) \
370 ((struct dtrace_dof_sect *) \
371 DTRACE_DOF_PTR ((dof), \
372 DOF_UINT ((dof), (dof)->dofh_secoff) \
373 + ((idx) * DOF_UINT ((dof), (dof)->dofh_secsize))))
375 /* Helper function to examine the probe described by the given PROBE
376 and PROVIDER data structures and add it to the PROBESP vector.
377 STRTAB, OFFTAB, EOFFTAB and ARGTAB are pointers to tables in the
378 DOF program containing the attributes for the probe. */
381 dtrace_process_dof_probe (struct objfile
*objfile
,
382 struct gdbarch
*gdbarch
,
383 std::vector
<probe
*> *probesp
,
384 struct dtrace_dof_hdr
*dof
,
385 struct dtrace_dof_probe
*probe
,
386 struct dtrace_dof_provider
*provider
,
387 char *strtab
, char *offtab
, char *eofftab
,
388 char *argtab
, uint64_t strtab_size
)
390 int i
, j
, num_probes
, num_enablers
;
393 /* Each probe section can define zero or more probes of two
396 - probe->dofpr_noffs regular probes whose program counters are
397 stored in 32bit words starting at probe->dofpr_addr +
398 offtab[probe->dofpr_offidx].
400 - probe->dofpr_nenoffs is-enabled probes whose program counters
401 are stored in 32bit words starting at probe->dofpr_addr +
402 eofftab[probe->dofpr_enoffidx].
404 However is-enabled probes are not probes per-se, but an
405 optimization hack that is implemented in the kernel in a very
406 similar way than normal probes. This is how we support
407 is-enabled probes on GDB:
409 - Our probes are always DTrace regular probes.
411 - Our probes can be associated with zero or more "enablers". The
412 list of enablers is built from the is-enabled probes defined in
415 - Probes having a non-empty list of enablers can be enabled or
416 disabled using the `enable probe' and `disable probe' commands
417 respectively. The `Enabled' column in the output of `info
418 probes' will read `yes' if the enablers are activated, `no'
421 - Probes having an empty list of enablers are always enabled.
422 The `Enabled' column in the output of `info probes' will
425 It follows that if there are DTrace is-enabled probes defined for
426 some provider/name but no DTrace regular probes defined then the
427 GDB user wont be able to enable/disable these conditionals. */
429 num_probes
= DOF_UINT (dof
, probe
->dofpr_noffs
);
433 /* Build the list of enablers for the probes defined in this Probe
435 std::vector
<struct dtrace_probe_enabler
> enablers
;
436 num_enablers
= DOF_UINT (dof
, probe
->dofpr_nenoffs
);
437 for (i
= 0; i
< num_enablers
; i
++)
439 struct dtrace_probe_enabler enabler
;
440 uint32_t enabler_offset
441 = ((uint32_t *) eofftab
)[DOF_UINT (dof
, probe
->dofpr_enoffidx
) + i
];
443 enabler
.address
= DOF_UINT (dof
, probe
->dofpr_addr
)
444 + DOF_UINT (dof
, enabler_offset
);
445 enablers
.push_back (enabler
);
448 for (i
= 0; i
< num_probes
; i
++)
450 uint32_t probe_offset
451 = ((uint32_t *) offtab
)[DOF_UINT (dof
, probe
->dofpr_offidx
) + i
];
453 /* Set the provider and the name of the probe. */
454 const char *probe_provider
455 = strtab
+ DOF_UINT (dof
, provider
->dofpv_name
);
456 const char *name
= strtab
+ DOF_UINT (dof
, probe
->dofpr_name
);
458 /* The probe address. */
460 = DOF_UINT (dof
, probe
->dofpr_addr
) + DOF_UINT (dof
, probe_offset
);
462 /* Number of arguments in the probe. */
463 int probe_argc
= DOF_UINT (dof
, probe
->dofpr_nargc
);
465 /* Store argument type descriptions. A description of the type
466 of the argument is in the (J+1)th null-terminated string
467 starting at 'strtab' + 'probe->dofpr_nargv'. */
468 std::vector
<struct dtrace_probe_arg
> args
;
469 p
= strtab
+ DOF_UINT (dof
, probe
->dofpr_nargv
);
470 for (j
= 0; j
< probe_argc
; j
++)
474 /* Set arg.expr to ensure all fields in expr are initialized and
475 the compiler will not warn when arg is used. */
476 std::string
type_str (p
);
478 /* Use strtab_size as a sentinel. */
479 while (*p
++ != '\0' && p
- strtab
< strtab_size
)
482 /* Try to parse a type expression from the type string. If
483 this does not work then we set the type to `long
485 struct type
*type
= builtin_type (gdbarch
)->builtin_long
;
489 expr
= parse_expression_with_language (type_str
.c_str (),
492 CATCH (ex
, RETURN_MASK_ERROR
)
497 if (expr
!= NULL
&& expr
.get ()->elts
[0].opcode
== OP_TYPE
)
498 type
= expr
.get ()->elts
[1].type
;
500 args
.emplace_back (type
, std::move (type_str
), std::move (expr
));
503 std::vector
<struct dtrace_probe_enabler
> enablers_copy
= enablers
;
504 dtrace_probe
*ret
= new dtrace_probe (std::string (name
),
505 std::string (probe_provider
),
508 std::move (enablers_copy
));
510 /* Successfully created probe. */
511 probesp
->push_back (ret
);
515 /* Helper function to collect the probes described in the DOF program
516 whose header is pointed by DOF and add them to the PROBESP vector.
517 SECT is the ELF section containing the DOF program and OBJFILE is
518 its containing object file. */
521 dtrace_process_dof (asection
*sect
, struct objfile
*objfile
,
522 std::vector
<probe
*> *probesp
, struct dtrace_dof_hdr
*dof
)
524 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
525 struct dtrace_dof_sect
*section
;
528 /* The first step is to check for the DOF magic number. If no valid
529 DOF data is found in the section then a complaint is issued to
530 the user and the section skipped. */
531 if (dof
->dofh_ident
[DTRACE_DOF_ID_MAG0
] != 0x7F
532 || dof
->dofh_ident
[DTRACE_DOF_ID_MAG1
] != 'D'
533 || dof
->dofh_ident
[DTRACE_DOF_ID_MAG2
] != 'O'
534 || dof
->dofh_ident
[DTRACE_DOF_ID_MAG3
] != 'F')
535 goto invalid_dof_data
;
537 /* Make sure the encoding mark is either DTRACE_DOF_ENCODE_LSB or
538 DTRACE_DOF_ENCODE_MSB. */
539 if (dof
->dofh_ident
[DTRACE_DOF_ID_ENCODING
] != DTRACE_DOF_ENCODE_LSB
540 && dof
->dofh_ident
[DTRACE_DOF_ID_ENCODING
] != DTRACE_DOF_ENCODE_MSB
)
541 goto invalid_dof_data
;
543 /* Make sure this DOF is not an enabling DOF, i.e. there are no ECB
544 Description sections. */
545 section
= (struct dtrace_dof_sect
*) DTRACE_DOF_PTR (dof
,
546 DOF_UINT (dof
, dof
->dofh_secoff
));
547 for (i
= 0; i
< DOF_UINT (dof
, dof
->dofh_secnum
); i
++, section
++)
548 if (section
->dofs_type
== DTRACE_DOF_SECT_TYPE_ECBDESC
)
551 /* Iterate over any section of type Provider and extract the probe
552 information from them. If there are no "provider" sections on
553 the DOF then we just return. */
554 section
= (struct dtrace_dof_sect
*) DTRACE_DOF_PTR (dof
,
555 DOF_UINT (dof
, dof
->dofh_secoff
));
556 for (i
= 0; i
< DOF_UINT (dof
, dof
->dofh_secnum
); i
++, section
++)
557 if (DOF_UINT (dof
, section
->dofs_type
) == DTRACE_DOF_SECT_TYPE_PROVIDER
)
559 struct dtrace_dof_provider
*provider
= (struct dtrace_dof_provider
*)
560 DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, section
->dofs_offset
));
561 struct dtrace_dof_sect
*strtab_s
562 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_strtab
));
563 struct dtrace_dof_sect
*probes_s
564 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_probes
));
565 struct dtrace_dof_sect
*args_s
566 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_prargs
));
567 struct dtrace_dof_sect
*offsets_s
568 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_proffs
));
569 struct dtrace_dof_sect
*eoffsets_s
570 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_prenoffs
));
571 char *strtab
= DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, strtab_s
->dofs_offset
));
572 char *offtab
= DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, offsets_s
->dofs_offset
));
573 char *eofftab
= DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, eoffsets_s
->dofs_offset
));
574 char *argtab
= DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, args_s
->dofs_offset
));
575 unsigned int entsize
= DOF_UINT (dof
, probes_s
->dofs_entsize
);
578 if (DOF_UINT (dof
, section
->dofs_size
)
579 < sizeof (struct dtrace_dof_provider
))
581 /* The section is smaller than expected, so do not use it.
582 This has been observed on x86-solaris 10. */
583 goto invalid_dof_data
;
586 /* Very, unlikely, but could crash gdb if not handled
589 goto invalid_dof_data
;
591 num_probes
= DOF_UINT (dof
, probes_s
->dofs_size
) / entsize
;
593 for (i
= 0; i
< num_probes
; i
++)
595 struct dtrace_dof_probe
*probe
= (struct dtrace_dof_probe
*)
596 DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, probes_s
->dofs_offset
)
597 + (i
* DOF_UINT (dof
, probes_s
->dofs_entsize
)));
599 dtrace_process_dof_probe (objfile
,
602 provider
, strtab
, offtab
, eofftab
, argtab
,
603 DOF_UINT (dof
, strtab_s
->dofs_size
));
610 complaint (&symfile_complaints
,
611 _("skipping section '%s' which does not contain valid DOF data."),
615 /* Implementation of 'build_arg_exprs' method. */
618 dtrace_probe::build_arg_exprs (struct gdbarch
*gdbarch
)
621 m_args_expr_built
= true;
623 /* Iterate over the arguments in the probe and build the
624 corresponding GDB internal expression that will generate the
625 value of the argument when executed at the PC of the probe. */
626 for (dtrace_probe_arg
&arg
: m_args
)
628 /* Initialize the expression buffer in the parser state. The
629 language does not matter, since we are using our own
631 parser_state
pstate (10, current_language
, gdbarch
);
633 /* The argument value, which is ABI dependent and casted to
635 gdbarch_dtrace_parse_probe_argument (gdbarch
, &pstate
, argc
);
637 /* Casting to the expected type, but only if the type was
638 recognized at probe load time. Otherwise the argument will
639 be evaluated as the long integer passed to the probe. */
640 if (arg
.type
!= NULL
)
642 write_exp_elt_opcode (&pstate
, UNOP_CAST
);
643 write_exp_elt_type (&pstate
, arg
.type
);
644 write_exp_elt_opcode (&pstate
, UNOP_CAST
);
647 arg
.expr
= pstate
.release ();
648 prefixify_expression (arg
.expr
.get ());
653 /* Implementation of 'get_arg_by_number' method. */
655 struct dtrace_probe_arg
*
656 dtrace_probe::get_arg_by_number (unsigned n
, struct gdbarch
*gdbarch
)
658 if (!m_args_expr_built
)
659 this->build_arg_exprs (gdbarch
);
661 if (n
> m_args
.size ())
662 internal_error (__FILE__
, __LINE__
,
663 _("Probe '%s' has %d arguments, but GDB is requesting\n"
664 "argument %u. This should not happen. Please\n"
666 this->get_name ().c_str (),
667 (int) m_args
.size (), n
);
672 /* Implementation of the probe is_enabled method. */
675 dtrace_probe::is_enabled () const
677 struct gdbarch
*gdbarch
= this->get_gdbarch ();
679 for (const dtrace_probe_enabler
&enabler
: m_enablers
)
680 if (!gdbarch_dtrace_probe_is_enabled (gdbarch
, enabler
.address
))
686 /* Implementation of the get_probe_address method. */
689 dtrace_probe::get_relocated_address (struct objfile
*objfile
)
691 return this->get_address () + ANOFFSET (objfile
->section_offsets
,
692 SECT_OFF_DATA (objfile
));
695 /* Implementation of the get_argument_count method. */
698 dtrace_probe::get_argument_count (struct frame_info
*frame
)
700 return m_args
.size ();
703 /* Implementation of the can_evaluate_arguments method. */
706 dtrace_probe::can_evaluate_arguments () const
708 struct gdbarch
*gdbarch
= this->get_gdbarch ();
710 return gdbarch_dtrace_parse_probe_argument_p (gdbarch
);
713 /* Implementation of the evaluate_argument method. */
716 dtrace_probe::evaluate_argument (unsigned n
,
717 struct frame_info
*frame
)
719 struct gdbarch
*gdbarch
= this->get_gdbarch ();
720 struct dtrace_probe_arg
*arg
;
723 arg
= this->get_arg_by_number (n
, gdbarch
);
724 return evaluate_subexp_standard (arg
->type
, arg
->expr
.get (), &pos
,
728 /* Implementation of the compile_to_ax method. */
731 dtrace_probe::compile_to_ax (struct agent_expr
*expr
, struct axs_value
*value
,
734 struct dtrace_probe_arg
*arg
;
735 union exp_element
*pc
;
737 arg
= this->get_arg_by_number (n
, expr
->gdbarch
);
739 pc
= arg
->expr
->elts
;
740 gen_expr (arg
->expr
.get (), &pc
, expr
, value
);
742 require_rvalue (expr
, value
);
743 value
->type
= arg
->type
;
746 /* Implementation of the 'get_static_ops' method. */
748 const static_probe_ops
*
749 dtrace_probe::get_static_ops () const
751 return &dtrace_static_probe_ops
;
754 /* Implementation of the gen_info_probes_table_values method. */
756 std::vector
<const char *>
757 dtrace_probe::gen_info_probes_table_values () const
759 const char *val
= NULL
;
761 if (m_enablers
.empty ())
763 else if (!gdbarch_dtrace_probe_is_enabled_p (this->get_gdbarch ()))
765 else if (this->is_enabled ())
770 return std::vector
<const char *> { val
};
773 /* Implementation of the enable method. */
776 dtrace_probe::enable ()
778 struct gdbarch
*gdbarch
= this->get_gdbarch ();
780 /* Enabling a dtrace probe implies patching the text section of the
781 running process, so make sure the inferior is indeed running. */
782 if (ptid_equal (inferior_ptid
, null_ptid
))
783 error (_("No inferior running"));
786 if (this->is_enabled ())
789 /* Iterate over all defined enabler in the given probe and enable
790 them all using the corresponding gdbarch hook. */
791 for (const dtrace_probe_enabler
&enabler
: m_enablers
)
792 if (gdbarch_dtrace_enable_probe_p (gdbarch
))
793 gdbarch_dtrace_enable_probe (gdbarch
, enabler
.address
);
797 /* Implementation of the disable_probe method. */
800 dtrace_probe::disable ()
802 struct gdbarch
*gdbarch
= this->get_gdbarch ();
804 /* Disabling a dtrace probe implies patching the text section of the
805 running process, so make sure the inferior is indeed running. */
806 if (ptid_equal (inferior_ptid
, null_ptid
))
807 error (_("No inferior running"));
810 if (!this->is_enabled ())
813 /* Are we trying to disable a probe that does not have any enabler
815 if (m_enablers
.empty ())
816 error (_("Probe %s:%s cannot be disabled: no enablers."),
817 this->get_provider ().c_str (), this->get_name ().c_str ());
819 /* Iterate over all defined enabler in the given probe and disable
820 them all using the corresponding gdbarch hook. */
821 for (dtrace_probe_enabler
&enabler
: m_enablers
)
822 if (gdbarch_dtrace_disable_probe_p (gdbarch
))
823 gdbarch_dtrace_disable_probe (gdbarch
, enabler
.address
);
826 /* Implementation of the is_linespec method. */
829 dtrace_static_probe_ops::is_linespec (const char **linespecp
) const
831 static const char *const keywords
[] = { "-pdtrace", "-probe-dtrace", NULL
};
833 return probe_is_linespec_by_keyword (linespecp
, keywords
);
836 /* Implementation of the get_probes method. */
839 dtrace_static_probe_ops::get_probes (std::vector
<probe
*> *probesp
,
840 struct objfile
*objfile
) const
842 bfd
*abfd
= objfile
->obfd
;
843 asection
*sect
= NULL
;
845 /* Do nothing in case this is a .debug file, instead of the objfile
847 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
850 /* Iterate over the sections in OBJFILE looking for DTrace
852 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
854 if (elf_section_data (sect
)->this_hdr
.sh_type
== SHT_SUNW_dof
)
858 /* Read the contents of the DOF section and then process it to
859 extract the information of any probe defined into it. */
860 if (!bfd_malloc_and_get_section (abfd
, sect
, &dof
))
861 complaint (&symfile_complaints
,
862 _("could not obtain the contents of"
863 "section '%s' in objfile `%s'."),
864 sect
->name
, abfd
->filename
);
866 dtrace_process_dof (sect
, objfile
, probesp
,
867 (struct dtrace_dof_hdr
*) dof
);
873 /* Implementation of the type_name method. */
876 dtrace_static_probe_ops::type_name () const
881 /* Implementation of the gen_info_probes_table_header method. */
883 std::vector
<struct info_probe_column
>
884 dtrace_static_probe_ops::gen_info_probes_table_header () const
886 struct info_probe_column dtrace_probe_column
;
888 dtrace_probe_column
.field_name
= "enabled";
889 dtrace_probe_column
.print_name
= _("Enabled");
891 return std::vector
<struct info_probe_column
> { dtrace_probe_column
};
894 /* Implementation of the `info probes dtrace' command. */
897 info_probes_dtrace_command (const char *arg
, int from_tty
)
899 info_probes_for_spops (arg
, from_tty
, &dtrace_static_probe_ops
);
903 _initialize_dtrace_probe (void)
905 all_static_probe_ops
.push_back (&dtrace_static_probe_ops
);
907 add_cmd ("dtrace", class_info
, info_probes_dtrace_command
,
909 Show information about DTrace static probes.\n\
910 Usage: info probes dtrace [PROVIDER [NAME [OBJECT]]]\n\
911 Each argument is a regular expression, used to select probes.\n\
912 PROVIDER matches probe provider names.\n\
913 NAME matches the probe names.\n\
914 OBJECT matches the executable or shared library name."),
915 info_probes_cmdlist_get ());