1 /* DTrace probe support for GDB.
3 Copyright (C) 2014-2019 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/>. */
28 #include "complaints.h"
33 #include "parser-defs.h"
36 /* The type of the ELF sections where we will find the DOF programs
37 with information about probes. */
40 # define SHT_SUNW_dof 0x6ffffff4
43 /* The following structure represents a single argument for the
46 struct dtrace_probe_arg
48 dtrace_probe_arg (struct type
*type_
, std::string
&&type_str_
,
49 expression_up
&&expr_
)
50 : type (type_
), type_str (std::move (type_str_
)),
51 expr (std::move (expr_
))
54 /* The type of the probe argument. */
57 /* A string describing the type. */
60 /* The argument converted to an internal GDB expression. */
64 /* The following structure represents an enabler for a probe. */
66 struct dtrace_probe_enabler
68 /* Program counter where the is-enabled probe is installed. The
69 contents (nops, whatever...) stored at this address are
70 architecture dependent. */
74 /* Class that implements the static probe methods for "stap" probes. */
76 class dtrace_static_probe_ops
: public static_probe_ops
80 bool is_linespec (const char **linespecp
) const override
;
83 void get_probes (std::vector
<std::unique_ptr
<probe
>> *probesp
,
84 struct objfile
*objfile
) const override
;
87 const char *type_name () const override
;
90 bool can_enable () const override
96 std::vector
<struct info_probe_column
> gen_info_probes_table_header
100 /* DTrace static_probe_ops. */
102 const dtrace_static_probe_ops dtrace_static_probe_ops
{};
104 /* The following structure represents a dtrace probe. */
106 class dtrace_probe
: public probe
109 /* Constructor for dtrace_probe. */
110 dtrace_probe (std::string
&&name_
, std::string
&&provider_
, CORE_ADDR address_
,
111 struct gdbarch
*arch_
,
112 std::vector
<struct dtrace_probe_arg
> &&args_
,
113 std::vector
<struct dtrace_probe_enabler
> &&enablers_
)
114 : probe (std::move (name_
), std::move (provider_
), address_
, arch_
),
115 m_args (std::move (args_
)),
116 m_enablers (std::move (enablers_
)),
117 m_args_expr_built (false)
121 CORE_ADDR
get_relocated_address (struct objfile
*objfile
) override
;
124 unsigned get_argument_count (struct gdbarch
*gdbarch
) override
;
127 bool can_evaluate_arguments () const override
;
130 struct value
*evaluate_argument (unsigned n
,
131 struct frame_info
*frame
) override
;
134 void compile_to_ax (struct agent_expr
*aexpr
,
135 struct axs_value
*axs_value
,
136 unsigned n
) override
;
139 const static_probe_ops
*get_static_ops () const override
;
142 std::vector
<const char *> gen_info_probes_table_values () const override
;
145 void enable () override
;
148 void disable () override
;
150 /* Return the Nth argument of the probe. */
151 struct dtrace_probe_arg
*get_arg_by_number (unsigned n
,
152 struct gdbarch
*gdbarch
);
154 /* Build the GDB internal expression that, once evaluated, will
155 calculate the values of the arguments of the probe. */
156 void build_arg_exprs (struct gdbarch
*gdbarch
);
158 /* Determine whether the probe is "enabled" or "disabled". A
159 disabled probe is a probe in which one or more enablers are
161 bool is_enabled () const;
164 /* A probe can have zero or more arguments. */
165 std::vector
<struct dtrace_probe_arg
> m_args
;
167 /* A probe can have zero or more "enablers" associated with it. */
168 std::vector
<struct dtrace_probe_enabler
> m_enablers
;
170 /* Whether the expressions for the arguments have been built. */
171 bool m_args_expr_built
;
174 /* DOF programs can contain an arbitrary number of sections of 26
175 different types. In order to support DTrace USDT probes we only
176 need to handle a subset of these section types, fortunately. These
177 section types are defined in the following enumeration.
179 See linux/dtrace/dof_defines.h for a complete list of section types
180 along with their values. */
182 enum dtrace_dof_sect_type
185 DTRACE_DOF_SECT_TYPE_NONE
= 0,
186 /* A dof_ecbdesc_t. */
187 DTRACE_DOF_SECT_TYPE_ECBDESC
= 3,
188 /* A string table. */
189 DTRACE_DOF_SECT_TYPE_STRTAB
= 8,
190 /* A dof_provider_t */
191 DTRACE_DOF_SECT_TYPE_PROVIDER
= 15,
192 /* Array of dof_probe_t */
193 DTRACE_DOF_SECT_TYPE_PROBES
= 16,
194 /* An array of probe arg mappings. */
195 DTRACE_DOF_SECT_TYPE_PRARGS
= 17,
196 /* An array of probe arg offsets. */
197 DTRACE_DOF_SECT_TYPE_PROFFS
= 18,
198 /* An array of probe is-enabled offsets. */
199 DTRACE_DOF_SECT_TYPE_PRENOFFS
= 26
202 /* The following collection of data structures map the structure of
203 DOF entities. Again, we only cover the subset of DOF used to
204 implement USDT probes.
206 See linux/dtrace/dof.h header for a complete list of data
209 /* Offsets to index the dofh_ident[] array defined below. */
211 enum dtrace_dof_ident
213 /* First byte of the magic number. */
214 DTRACE_DOF_ID_MAG0
= 0,
215 /* Second byte of the magic number. */
216 DTRACE_DOF_ID_MAG1
= 1,
217 /* Third byte of the magic number. */
218 DTRACE_DOF_ID_MAG2
= 2,
219 /* Fourth byte of the magic number. */
220 DTRACE_DOF_ID_MAG3
= 3,
221 /* An enum_dof_encoding value. */
222 DTRACE_DOF_ID_ENCODING
= 5
225 /* Possible values for dofh_ident[DOF_ID_ENCODING]. */
227 enum dtrace_dof_encoding
229 /* The DOF program is little-endian. */
230 DTRACE_DOF_ENCODE_LSB
= 1,
231 /* The DOF program is big-endian. */
232 DTRACE_DOF_ENCODE_MSB
= 2
235 /* A DOF header, which describes the contents of a DOF program: number
236 of sections, size, etc. */
238 struct dtrace_dof_hdr
240 /* Identification bytes (see above). */
241 uint8_t dofh_ident
[16];
242 /* File attribute flags (if any). */
244 /* Size of file header in bytes. */
245 uint32_t dofh_hdrsize
;
246 /* Size of section header in bytes. */
247 uint32_t dofh_secsize
;
248 /* Number of section headers. */
249 uint32_t dofh_secnum
;
250 /* File offset of section headers. */
251 uint64_t dofh_secoff
;
252 /* File size of loadable portion. */
253 uint64_t dofh_loadsz
;
254 /* File size of entire DOF file. */
255 uint64_t dofh_filesz
;
256 /* Reserved for future use. */
260 /* A DOF section, whose contents depend on its type. The several
261 supported section types are described in the enum
262 dtrace_dof_sect_type above. */
264 struct dtrace_dof_sect
266 /* Section type (see the define above). */
268 /* Section data memory alignment. */
270 /* Section flags (if any). */
272 /* Size of section entry (if table). */
273 uint32_t dofs_entsize
;
274 /* DOF + offset points to the section data. */
275 uint64_t dofs_offset
;
276 /* Size of section data in bytes. */
280 /* A DOF provider, which is the provider of a probe. */
282 struct dtrace_dof_provider
284 /* Link to a DTRACE_DOF_SECT_TYPE_STRTAB section. */
285 uint32_t dofpv_strtab
;
286 /* Link to a DTRACE_DOF_SECT_TYPE_PROBES section. */
287 uint32_t dofpv_probes
;
288 /* Link to a DTRACE_DOF_SECT_TYPE_PRARGS section. */
289 uint32_t dofpv_prargs
;
290 /* Link to a DTRACE_DOF_SECT_TYPE_PROFFS section. */
291 uint32_t dofpv_proffs
;
292 /* Provider name string. */
294 /* Provider attributes. */
295 uint32_t dofpv_provattr
;
296 /* Module attributes. */
297 uint32_t dofpv_modattr
;
298 /* Function attributes. */
299 uint32_t dofpv_funcattr
;
300 /* Name attributes. */
301 uint32_t dofpv_nameattr
;
302 /* Args attributes. */
303 uint32_t dofpv_argsattr
;
304 /* Link to a DTRACE_DOF_SECT_PRENOFFS section. */
305 uint32_t dofpv_prenoffs
;
308 /* A set of DOF probes and is-enabled probes sharing a base address
309 and several attributes. The particular locations and attributes of
310 each probe are maintained in arrays in several other DOF sections.
311 See the comment in dtrace_process_dof_probe for details on how
312 these attributes are stored. */
314 struct dtrace_dof_probe
316 /* Probe base address or offset. */
318 /* Probe function string. */
320 /* Probe name string. */
322 /* Native argument type strings. */
323 uint32_t dofpr_nargv
;
324 /* Translated argument type strings. */
325 uint32_t dofpr_xargv
;
326 /* Index of first argument mapping. */
327 uint32_t dofpr_argidx
;
328 /* Index of first offset entry. */
329 uint32_t dofpr_offidx
;
330 /* Native argument count. */
332 /* Translated argument count. */
334 /* Number of offset entries for probe. */
335 uint16_t dofpr_noffs
;
336 /* Index of first is-enabled offset. */
337 uint32_t dofpr_enoffidx
;
338 /* Number of is-enabled offsets. */
339 uint16_t dofpr_nenoffs
;
340 /* Reserved for future use. */
342 /* Reserved for future use. */
346 /* DOF supports two different encodings: MSB (big-endian) and LSB
347 (little-endian). The encoding is itself encoded in the DOF header.
348 The following function returns an unsigned value in the host
351 #define DOF_UINT(dof, field) \
352 extract_unsigned_integer ((gdb_byte *) &(field), \
354 (((dof)->dofh_ident[DTRACE_DOF_ID_ENCODING] \
355 == DTRACE_DOF_ENCODE_MSB) \
356 ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE))
358 /* The following macro applies a given byte offset to a DOF (a pointer
359 to a dtrace_dof_hdr structure) and returns the resulting
362 #define DTRACE_DOF_PTR(dof, offset) (&((char *) (dof))[(offset)])
364 /* The following macro returns a pointer to the beginning of a given
365 section in a DOF object. The section is referred to by its index
366 in the sections array. */
368 #define DTRACE_DOF_SECT(dof, idx) \
369 ((struct dtrace_dof_sect *) \
370 DTRACE_DOF_PTR ((dof), \
371 DOF_UINT ((dof), (dof)->dofh_secoff) \
372 + ((idx) * DOF_UINT ((dof), (dof)->dofh_secsize))))
374 /* Helper function to examine the probe described by the given PROBE
375 and PROVIDER data structures and add it to the PROBESP vector.
376 STRTAB, OFFTAB, EOFFTAB and ARGTAB are pointers to tables in the
377 DOF program containing the attributes for the probe. */
380 dtrace_process_dof_probe (struct objfile
*objfile
,
381 struct gdbarch
*gdbarch
,
382 std::vector
<std::unique_ptr
<probe
>> *probesp
,
383 struct dtrace_dof_hdr
*dof
,
384 struct dtrace_dof_probe
*probe
,
385 struct dtrace_dof_provider
*provider
,
386 char *strtab
, char *offtab
, char *eofftab
,
387 char *argtab
, uint64_t strtab_size
)
389 int i
, j
, num_probes
, num_enablers
;
392 /* Each probe section can define zero or more probes of two
395 - probe->dofpr_noffs regular probes whose program counters are
396 stored in 32bit words starting at probe->dofpr_addr +
397 offtab[probe->dofpr_offidx].
399 - probe->dofpr_nenoffs is-enabled probes whose program counters
400 are stored in 32bit words starting at probe->dofpr_addr +
401 eofftab[probe->dofpr_enoffidx].
403 However is-enabled probes are not probes per-se, but an
404 optimization hack that is implemented in the kernel in a very
405 similar way than normal probes. This is how we support
406 is-enabled probes on GDB:
408 - Our probes are always DTrace regular probes.
410 - Our probes can be associated with zero or more "enablers". The
411 list of enablers is built from the is-enabled probes defined in
414 - Probes having a non-empty list of enablers can be enabled or
415 disabled using the `enable probe' and `disable probe' commands
416 respectively. The `Enabled' column in the output of `info
417 probes' will read `yes' if the enablers are activated, `no'
420 - Probes having an empty list of enablers are always enabled.
421 The `Enabled' column in the output of `info probes' will
424 It follows that if there are DTrace is-enabled probes defined for
425 some provider/name but no DTrace regular probes defined then the
426 GDB user wont be able to enable/disable these conditionals. */
428 num_probes
= DOF_UINT (dof
, probe
->dofpr_noffs
);
432 /* Build the list of enablers for the probes defined in this Probe
434 std::vector
<struct dtrace_probe_enabler
> enablers
;
435 num_enablers
= DOF_UINT (dof
, probe
->dofpr_nenoffs
);
436 for (i
= 0; i
< num_enablers
; i
++)
438 struct dtrace_probe_enabler enabler
;
439 uint32_t enabler_offset
440 = ((uint32_t *) eofftab
)[DOF_UINT (dof
, probe
->dofpr_enoffidx
) + i
];
442 enabler
.address
= DOF_UINT (dof
, probe
->dofpr_addr
)
443 + DOF_UINT (dof
, enabler_offset
);
444 enablers
.push_back (enabler
);
447 for (i
= 0; i
< num_probes
; i
++)
449 uint32_t probe_offset
450 = ((uint32_t *) offtab
)[DOF_UINT (dof
, probe
->dofpr_offidx
) + i
];
452 /* Set the provider and the name of the probe. */
453 const char *probe_provider
454 = strtab
+ DOF_UINT (dof
, provider
->dofpv_name
);
455 const char *name
= strtab
+ DOF_UINT (dof
, probe
->dofpr_name
);
457 /* The probe address. */
459 = DOF_UINT (dof
, probe
->dofpr_addr
) + DOF_UINT (dof
, probe_offset
);
461 /* Number of arguments in the probe. */
462 int probe_argc
= DOF_UINT (dof
, probe
->dofpr_nargc
);
464 /* Store argument type descriptions. A description of the type
465 of the argument is in the (J+1)th null-terminated string
466 starting at 'strtab' + 'probe->dofpr_nargv'. */
467 std::vector
<struct dtrace_probe_arg
> args
;
468 p
= strtab
+ DOF_UINT (dof
, probe
->dofpr_nargv
);
469 for (j
= 0; j
< probe_argc
; j
++)
473 /* Set arg.expr to ensure all fields in expr are initialized and
474 the compiler will not warn when arg is used. */
475 std::string
type_str (p
);
477 /* Use strtab_size as a sentinel. */
478 while (*p
++ != '\0' && p
- strtab
< strtab_size
)
481 /* Try to parse a type expression from the type string. If
482 this does not work then we set the type to `long
484 struct type
*type
= builtin_type (gdbarch
)->builtin_long
;
488 expr
= parse_expression_with_language (type_str
.c_str (),
491 catch (const gdb_exception_error
&ex
)
495 if (expr
!= NULL
&& expr
.get ()->elts
[0].opcode
== OP_TYPE
)
496 type
= expr
.get ()->elts
[1].type
;
498 args
.emplace_back (type
, std::move (type_str
), std::move (expr
));
501 std::vector
<struct dtrace_probe_enabler
> enablers_copy
= enablers
;
502 dtrace_probe
*ret
= new dtrace_probe (std::string (name
),
503 std::string (probe_provider
),
506 std::move (enablers_copy
));
508 /* Successfully created probe. */
509 probesp
->emplace_back (ret
);
513 /* Helper function to collect the probes described in the DOF program
514 whose header is pointed by DOF and add them to the PROBESP vector.
515 SECT is the ELF section containing the DOF program and OBJFILE is
516 its containing object file. */
519 dtrace_process_dof (asection
*sect
, struct objfile
*objfile
,
520 std::vector
<std::unique_ptr
<probe
>> *probesp
,
521 struct dtrace_dof_hdr
*dof
)
523 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
524 struct dtrace_dof_sect
*section
;
527 /* The first step is to check for the DOF magic number. If no valid
528 DOF data is found in the section then a complaint is issued to
529 the user and the section skipped. */
530 if (dof
->dofh_ident
[DTRACE_DOF_ID_MAG0
] != 0x7F
531 || dof
->dofh_ident
[DTRACE_DOF_ID_MAG1
] != 'D'
532 || dof
->dofh_ident
[DTRACE_DOF_ID_MAG2
] != 'O'
533 || dof
->dofh_ident
[DTRACE_DOF_ID_MAG3
] != 'F')
534 goto invalid_dof_data
;
536 /* Make sure the encoding mark is either DTRACE_DOF_ENCODE_LSB or
537 DTRACE_DOF_ENCODE_MSB. */
538 if (dof
->dofh_ident
[DTRACE_DOF_ID_ENCODING
] != DTRACE_DOF_ENCODE_LSB
539 && dof
->dofh_ident
[DTRACE_DOF_ID_ENCODING
] != DTRACE_DOF_ENCODE_MSB
)
540 goto invalid_dof_data
;
542 /* Make sure this DOF is not an enabling DOF, i.e. there are no ECB
543 Description sections. */
544 section
= (struct dtrace_dof_sect
*) DTRACE_DOF_PTR (dof
,
545 DOF_UINT (dof
, dof
->dofh_secoff
));
546 for (i
= 0; i
< DOF_UINT (dof
, dof
->dofh_secnum
); i
++, section
++)
547 if (section
->dofs_type
== DTRACE_DOF_SECT_TYPE_ECBDESC
)
550 /* Iterate over any section of type Provider and extract the probe
551 information from them. If there are no "provider" sections on
552 the DOF then we just return. */
553 section
= (struct dtrace_dof_sect
*) DTRACE_DOF_PTR (dof
,
554 DOF_UINT (dof
, dof
->dofh_secoff
));
555 for (i
= 0; i
< DOF_UINT (dof
, dof
->dofh_secnum
); i
++, section
++)
556 if (DOF_UINT (dof
, section
->dofs_type
) == DTRACE_DOF_SECT_TYPE_PROVIDER
)
558 struct dtrace_dof_provider
*provider
= (struct dtrace_dof_provider
*)
559 DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, section
->dofs_offset
));
560 struct dtrace_dof_sect
*strtab_s
561 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_strtab
));
562 struct dtrace_dof_sect
*probes_s
563 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_probes
));
564 struct dtrace_dof_sect
*args_s
565 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_prargs
));
566 struct dtrace_dof_sect
*offsets_s
567 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_proffs
));
568 struct dtrace_dof_sect
*eoffsets_s
569 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_prenoffs
));
570 char *strtab
= DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, strtab_s
->dofs_offset
));
571 char *offtab
= DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, offsets_s
->dofs_offset
));
572 char *eofftab
= DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, eoffsets_s
->dofs_offset
));
573 char *argtab
= DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, args_s
->dofs_offset
));
574 unsigned int entsize
= DOF_UINT (dof
, probes_s
->dofs_entsize
);
577 if (DOF_UINT (dof
, section
->dofs_size
)
578 < sizeof (struct dtrace_dof_provider
))
580 /* The section is smaller than expected, so do not use it.
581 This has been observed on x86-solaris 10. */
582 goto invalid_dof_data
;
585 /* Very, unlikely, but could crash gdb if not handled
588 goto invalid_dof_data
;
590 num_probes
= DOF_UINT (dof
, probes_s
->dofs_size
) / entsize
;
592 for (i
= 0; i
< num_probes
; i
++)
594 struct dtrace_dof_probe
*probe
= (struct dtrace_dof_probe
*)
595 DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, probes_s
->dofs_offset
)
596 + (i
* DOF_UINT (dof
, probes_s
->dofs_entsize
)));
598 dtrace_process_dof_probe (objfile
,
601 provider
, strtab
, offtab
, eofftab
, argtab
,
602 DOF_UINT (dof
, strtab_s
->dofs_size
));
609 complaint (_("skipping section '%s' which does not contain valid DOF data."),
613 /* Implementation of 'build_arg_exprs' method. */
616 dtrace_probe::build_arg_exprs (struct gdbarch
*gdbarch
)
619 m_args_expr_built
= true;
621 /* Iterate over the arguments in the probe and build the
622 corresponding GDB internal expression that will generate the
623 value of the argument when executed at the PC of the probe. */
624 for (dtrace_probe_arg
&arg
: m_args
)
626 /* Initialize the expression builder. The language does not
627 matter, since we are using our own parser. */
628 expr_builder
builder (current_language
, gdbarch
);
630 /* The argument value, which is ABI dependent and casted to
632 gdbarch_dtrace_parse_probe_argument (gdbarch
, &builder
, argc
);
634 /* Casting to the expected type, but only if the type was
635 recognized at probe load time. Otherwise the argument will
636 be evaluated as the long integer passed to the probe. */
637 if (arg
.type
!= NULL
)
639 write_exp_elt_opcode (&builder
, UNOP_CAST
);
640 write_exp_elt_type (&builder
, arg
.type
);
641 write_exp_elt_opcode (&builder
, UNOP_CAST
);
644 arg
.expr
= builder
.release ();
645 prefixify_expression (arg
.expr
.get ());
650 /* Implementation of 'get_arg_by_number' method. */
652 struct dtrace_probe_arg
*
653 dtrace_probe::get_arg_by_number (unsigned n
, struct gdbarch
*gdbarch
)
655 if (!m_args_expr_built
)
656 this->build_arg_exprs (gdbarch
);
658 if (n
> m_args
.size ())
659 internal_error (__FILE__
, __LINE__
,
660 _("Probe '%s' has %d arguments, but GDB is requesting\n"
661 "argument %u. This should not happen. Please\n"
663 this->get_name ().c_str (),
664 (int) m_args
.size (), n
);
669 /* Implementation of the probe is_enabled method. */
672 dtrace_probe::is_enabled () const
674 struct gdbarch
*gdbarch
= this->get_gdbarch ();
676 for (const dtrace_probe_enabler
&enabler
: m_enablers
)
677 if (!gdbarch_dtrace_probe_is_enabled (gdbarch
, enabler
.address
))
683 /* Implementation of the get_probe_address method. */
686 dtrace_probe::get_relocated_address (struct objfile
*objfile
)
688 return this->get_address () + ANOFFSET (objfile
->section_offsets
,
689 SECT_OFF_DATA (objfile
));
692 /* Implementation of the get_argument_count method. */
695 dtrace_probe::get_argument_count (struct gdbarch
*gdbarch
)
697 return m_args
.size ();
700 /* Implementation of the can_evaluate_arguments method. */
703 dtrace_probe::can_evaluate_arguments () const
705 struct gdbarch
*gdbarch
= this->get_gdbarch ();
707 return gdbarch_dtrace_parse_probe_argument_p (gdbarch
);
710 /* Implementation of the evaluate_argument method. */
713 dtrace_probe::evaluate_argument (unsigned n
,
714 struct frame_info
*frame
)
716 struct gdbarch
*gdbarch
= this->get_gdbarch ();
717 struct dtrace_probe_arg
*arg
;
720 arg
= this->get_arg_by_number (n
, gdbarch
);
721 return evaluate_subexp_standard (arg
->type
, arg
->expr
.get (), &pos
,
725 /* Implementation of the compile_to_ax method. */
728 dtrace_probe::compile_to_ax (struct agent_expr
*expr
, struct axs_value
*value
,
731 struct dtrace_probe_arg
*arg
;
732 union exp_element
*pc
;
734 arg
= this->get_arg_by_number (n
, expr
->gdbarch
);
736 pc
= arg
->expr
->elts
;
737 gen_expr (arg
->expr
.get (), &pc
, expr
, value
);
739 require_rvalue (expr
, value
);
740 value
->type
= arg
->type
;
743 /* Implementation of the 'get_static_ops' method. */
745 const static_probe_ops
*
746 dtrace_probe::get_static_ops () const
748 return &dtrace_static_probe_ops
;
751 /* Implementation of the gen_info_probes_table_values method. */
753 std::vector
<const char *>
754 dtrace_probe::gen_info_probes_table_values () const
756 const char *val
= NULL
;
758 if (m_enablers
.empty ())
760 else if (!gdbarch_dtrace_probe_is_enabled_p (this->get_gdbarch ()))
762 else if (this->is_enabled ())
767 return std::vector
<const char *> { val
};
770 /* Implementation of the enable method. */
773 dtrace_probe::enable ()
775 struct gdbarch
*gdbarch
= this->get_gdbarch ();
777 /* Enabling a dtrace probe implies patching the text section of the
778 running process, so make sure the inferior is indeed running. */
779 if (inferior_ptid
== null_ptid
)
780 error (_("No inferior running"));
783 if (this->is_enabled ())
786 /* Iterate over all defined enabler in the given probe and enable
787 them all using the corresponding gdbarch hook. */
788 for (const dtrace_probe_enabler
&enabler
: m_enablers
)
789 if (gdbarch_dtrace_enable_probe_p (gdbarch
))
790 gdbarch_dtrace_enable_probe (gdbarch
, enabler
.address
);
794 /* Implementation of the disable_probe method. */
797 dtrace_probe::disable ()
799 struct gdbarch
*gdbarch
= this->get_gdbarch ();
801 /* Disabling a dtrace probe implies patching the text section of the
802 running process, so make sure the inferior is indeed running. */
803 if (inferior_ptid
== null_ptid
)
804 error (_("No inferior running"));
807 if (!this->is_enabled ())
810 /* Are we trying to disable a probe that does not have any enabler
812 if (m_enablers
.empty ())
813 error (_("Probe %s:%s cannot be disabled: no enablers."),
814 this->get_provider ().c_str (), this->get_name ().c_str ());
816 /* Iterate over all defined enabler in the given probe and disable
817 them all using the corresponding gdbarch hook. */
818 for (dtrace_probe_enabler
&enabler
: m_enablers
)
819 if (gdbarch_dtrace_disable_probe_p (gdbarch
))
820 gdbarch_dtrace_disable_probe (gdbarch
, enabler
.address
);
823 /* Implementation of the is_linespec method. */
826 dtrace_static_probe_ops::is_linespec (const char **linespecp
) const
828 static const char *const keywords
[] = { "-pdtrace", "-probe-dtrace", NULL
};
830 return probe_is_linespec_by_keyword (linespecp
, keywords
);
833 /* Implementation of the get_probes method. */
836 dtrace_static_probe_ops::get_probes
837 (std::vector
<std::unique_ptr
<probe
>> *probesp
,
838 struct objfile
*objfile
) const
840 bfd
*abfd
= objfile
->obfd
;
841 asection
*sect
= NULL
;
843 /* Do nothing in case this is a .debug file, instead of the objfile
845 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
848 /* Iterate over the sections in OBJFILE looking for DTrace
850 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
852 if (elf_section_data (sect
)->this_hdr
.sh_type
== SHT_SUNW_dof
)
856 /* Read the contents of the DOF section and then process it to
857 extract the information of any probe defined into it. */
858 if (bfd_malloc_and_get_section (abfd
, sect
, &dof
) && dof
!= NULL
)
859 dtrace_process_dof (sect
, objfile
, probesp
,
860 (struct dtrace_dof_hdr
*) dof
);
862 complaint (_("could not obtain the contents of"
863 "section '%s' in objfile `%s'."),
864 sect
->name
, abfd
->filename
);
871 /* Implementation of the type_name method. */
874 dtrace_static_probe_ops::type_name () const
879 /* Implementation of the gen_info_probes_table_header method. */
881 std::vector
<struct info_probe_column
>
882 dtrace_static_probe_ops::gen_info_probes_table_header () const
884 struct info_probe_column dtrace_probe_column
;
886 dtrace_probe_column
.field_name
= "enabled";
887 dtrace_probe_column
.print_name
= _("Enabled");
889 return std::vector
<struct info_probe_column
> { dtrace_probe_column
};
892 /* Implementation of the `info probes dtrace' command. */
895 info_probes_dtrace_command (const char *arg
, int from_tty
)
897 info_probes_for_spops (arg
, from_tty
, &dtrace_static_probe_ops
);
901 _initialize_dtrace_probe (void)
903 all_static_probe_ops
.push_back (&dtrace_static_probe_ops
);
905 add_cmd ("dtrace", class_info
, info_probes_dtrace_command
,
907 Show information about DTrace static probes.\n\
908 Usage: info probes dtrace [PROVIDER [NAME [OBJECT]]]\n\
909 Each argument is a regular expression, used to select probes.\n\
910 PROVIDER matches probe provider names.\n\
911 NAME matches the probe names.\n\
912 OBJECT matches the executable or shared library name."),
913 info_probes_cmdlist_get ());