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/>. */
24 /* Local non-gdb includes. */
27 #include "common/vec.h"
28 #include "complaints.h"
35 #include "parser-defs.h"
39 /* The type of the ELF sections where we will find the DOF programs
40 with information about probes. */
43 # define SHT_SUNW_dof 0x6ffffff4
46 /* The following structure represents a single argument for the
49 struct dtrace_probe_arg
51 dtrace_probe_arg (struct type
*type_
, std::string
&&type_str_
,
52 expression_up
&&expr_
)
53 : type (type_
), type_str (std::move (type_str_
)),
54 expr (std::move (expr_
))
57 /* The type of the probe argument. */
60 /* A string describing the type. */
63 /* The argument converted to an internal GDB expression. */
67 /* The following structure represents an enabler for a probe. */
69 struct dtrace_probe_enabler
71 /* Program counter where the is-enabled probe is installed. The
72 contents (nops, whatever...) stored at this address are
73 architecture dependent. */
77 /* Class that implements the static probe methods for "stap" probes. */
79 class dtrace_static_probe_ops
: public static_probe_ops
83 bool is_linespec (const char **linespecp
) const override
;
86 void get_probes (std::vector
<probe
*> *probesp
,
87 struct objfile
*objfile
) const override
;
90 const char *type_name () const override
;
93 bool can_enable () const override
99 std::vector
<struct info_probe_column
> gen_info_probes_table_header
103 /* DTrace static_probe_ops. */
105 const dtrace_static_probe_ops dtrace_static_probe_ops
{};
107 /* The following structure represents a dtrace probe. */
109 class dtrace_probe
: public probe
112 /* Constructor for dtrace_probe. */
113 dtrace_probe (std::string
&&name_
, std::string
&&provider_
, CORE_ADDR address_
,
114 struct gdbarch
*arch_
,
115 std::vector
<struct dtrace_probe_arg
> &&args_
,
116 std::vector
<struct dtrace_probe_enabler
> &&enablers_
)
117 : probe (std::move (name_
), std::move (provider_
), address_
, arch_
),
118 m_args (std::move (args_
)),
119 m_enablers (std::move (enablers_
)),
120 m_args_expr_built (false)
124 CORE_ADDR
get_relocated_address (struct objfile
*objfile
) override
;
127 unsigned get_argument_count (struct frame_info
*frame
) override
;
130 bool can_evaluate_arguments () const override
;
133 struct value
*evaluate_argument (unsigned n
,
134 struct frame_info
*frame
) override
;
137 void compile_to_ax (struct agent_expr
*aexpr
,
138 struct axs_value
*axs_value
,
139 unsigned n
) override
;
142 const static_probe_ops
*get_static_ops () const override
;
145 std::vector
<const char *> gen_info_probes_table_values () const override
;
148 void enable () override
;
151 void disable () override
;
153 /* Return the Nth argument of the probe. */
154 struct dtrace_probe_arg
*get_arg_by_number (unsigned n
,
155 struct gdbarch
*gdbarch
);
157 /* Build the GDB internal expressiosn that, once evaluated, will
158 calculate the values of the arguments of the probe. */
159 void build_arg_exprs (struct gdbarch
*gdbarch
);
161 /* Determine whether the probe is "enabled" or "disabled". A
162 disabled probe is a probe in which one or more enablers are
164 bool is_enabled () const;
167 /* A probe can have zero or more arguments. */
168 std::vector
<struct dtrace_probe_arg
> m_args
;
170 /* A probe can have zero or more "enablers" associated with it. */
171 std::vector
<struct dtrace_probe_enabler
> m_enablers
;
173 /* Whether the expressions for the arguments have been built. */
174 bool m_args_expr_built
;
177 /* DOF programs can contain an arbitrary number of sections of 26
178 different types. In order to support DTrace USDT probes we only
179 need to handle a subset of these section types, fortunately. These
180 section types are defined in the following enumeration.
182 See linux/dtrace/dof_defines.h for a complete list of section types
183 along with their values. */
185 enum dtrace_dof_sect_type
188 DTRACE_DOF_SECT_TYPE_NONE
= 0,
189 /* A dof_ecbdesc_t. */
190 DTRACE_DOF_SECT_TYPE_ECBDESC
= 3,
191 /* A string table. */
192 DTRACE_DOF_SECT_TYPE_STRTAB
= 8,
193 /* A dof_provider_t */
194 DTRACE_DOF_SECT_TYPE_PROVIDER
= 15,
195 /* Array of dof_probe_t */
196 DTRACE_DOF_SECT_TYPE_PROBES
= 16,
197 /* An array of probe arg mappings. */
198 DTRACE_DOF_SECT_TYPE_PRARGS
= 17,
199 /* An array of probe arg offsets. */
200 DTRACE_DOF_SECT_TYPE_PROFFS
= 18,
201 /* An array of probe is-enabled offsets. */
202 DTRACE_DOF_SECT_TYPE_PRENOFFS
= 26
205 /* The following collection of data structures map the structure of
206 DOF entities. Again, we only cover the subset of DOF used to
207 implement USDT probes.
209 See linux/dtrace/dof.h header for a complete list of data
212 /* Offsets to index the dofh_ident[] array defined below. */
214 enum dtrace_dof_ident
216 /* First byte of the magic number. */
217 DTRACE_DOF_ID_MAG0
= 0,
218 /* Second byte of the magic number. */
219 DTRACE_DOF_ID_MAG1
= 1,
220 /* Third byte of the magic number. */
221 DTRACE_DOF_ID_MAG2
= 2,
222 /* Fourth byte of the magic number. */
223 DTRACE_DOF_ID_MAG3
= 3,
224 /* An enum_dof_encoding value. */
225 DTRACE_DOF_ID_ENCODING
= 5
228 /* Possible values for dofh_ident[DOF_ID_ENCODING]. */
230 enum dtrace_dof_encoding
232 /* The DOF program is little-endian. */
233 DTRACE_DOF_ENCODE_LSB
= 1,
234 /* The DOF program is big-endian. */
235 DTRACE_DOF_ENCODE_MSB
= 2
238 /* A DOF header, which describes the contents of a DOF program: number
239 of sections, size, etc. */
241 struct dtrace_dof_hdr
243 /* Identification bytes (see above). */
244 uint8_t dofh_ident
[16];
245 /* File attribute flags (if any). */
247 /* Size of file header in bytes. */
248 uint32_t dofh_hdrsize
;
249 /* Size of section header in bytes. */
250 uint32_t dofh_secsize
;
251 /* Number of section headers. */
252 uint32_t dofh_secnum
;
253 /* File offset of section headers. */
254 uint64_t dofh_secoff
;
255 /* File size of loadable portion. */
256 uint64_t dofh_loadsz
;
257 /* File size of entire DOF file. */
258 uint64_t dofh_filesz
;
259 /* Reserved for future use. */
263 /* A DOF section, whose contents depend on its type. The several
264 supported section types are described in the enum
265 dtrace_dof_sect_type above. */
267 struct dtrace_dof_sect
269 /* Section type (see the define above). */
271 /* Section data memory alignment. */
273 /* Section flags (if any). */
275 /* Size of section entry (if table). */
276 uint32_t dofs_entsize
;
277 /* DOF + offset points to the section data. */
278 uint64_t dofs_offset
;
279 /* Size of section data in bytes. */
283 /* A DOF provider, which is the provider of a probe. */
285 struct dtrace_dof_provider
287 /* Link to a DTRACE_DOF_SECT_TYPE_STRTAB section. */
288 uint32_t dofpv_strtab
;
289 /* Link to a DTRACE_DOF_SECT_TYPE_PROBES section. */
290 uint32_t dofpv_probes
;
291 /* Link to a DTRACE_DOF_SECT_TYPE_PRARGS section. */
292 uint32_t dofpv_prargs
;
293 /* Link to a DTRACE_DOF_SECT_TYPE_PROFFS section. */
294 uint32_t dofpv_proffs
;
295 /* Provider name string. */
297 /* Provider attributes. */
298 uint32_t dofpv_provattr
;
299 /* Module attributes. */
300 uint32_t dofpv_modattr
;
301 /* Function attributes. */
302 uint32_t dofpv_funcattr
;
303 /* Name attributes. */
304 uint32_t dofpv_nameattr
;
305 /* Args attributes. */
306 uint32_t dofpv_argsattr
;
307 /* Link to a DTRACE_DOF_SECT_PRENOFFS section. */
308 uint32_t dofpv_prenoffs
;
311 /* A set of DOF probes and is-enabled probes sharing a base address
312 and several attributes. The particular locations and attributes of
313 each probe are maintained in arrays in several other DOF sections.
314 See the comment in dtrace_process_dof_probe for details on how
315 these attributes are stored. */
317 struct dtrace_dof_probe
319 /* Probe base address or offset. */
321 /* Probe function string. */
323 /* Probe name string. */
325 /* Native argument type strings. */
326 uint32_t dofpr_nargv
;
327 /* Translated argument type strings. */
328 uint32_t dofpr_xargv
;
329 /* Index of first argument mapping. */
330 uint32_t dofpr_argidx
;
331 /* Index of first offset entry. */
332 uint32_t dofpr_offidx
;
333 /* Native argument count. */
335 /* Translated argument count. */
337 /* Number of offset entries for probe. */
338 uint16_t dofpr_noffs
;
339 /* Index of first is-enabled offset. */
340 uint32_t dofpr_enoffidx
;
341 /* Number of is-enabled offsets. */
342 uint16_t dofpr_nenoffs
;
343 /* Reserved for future use. */
345 /* Reserved for future use. */
349 /* DOF supports two different encodings: MSB (big-endian) and LSB
350 (little-endian). The encoding is itself encoded in the DOF header.
351 The following function returns an unsigned value in the host
354 #define DOF_UINT(dof, field) \
355 extract_unsigned_integer ((gdb_byte *) &(field), \
357 (((dof)->dofh_ident[DTRACE_DOF_ID_ENCODING] \
358 == DTRACE_DOF_ENCODE_MSB) \
359 ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE))
361 /* The following macro applies a given byte offset to a DOF (a pointer
362 to a dtrace_dof_hdr structure) and returns the resulting
365 #define DTRACE_DOF_PTR(dof, offset) (&((char *) (dof))[(offset)])
367 /* The following macro returns a pointer to the beginning of a given
368 section in a DOF object. The section is referred to by its index
369 in the sections array. */
371 #define DTRACE_DOF_SECT(dof, idx) \
372 ((struct dtrace_dof_sect *) \
373 DTRACE_DOF_PTR ((dof), \
374 DOF_UINT ((dof), (dof)->dofh_secoff) \
375 + ((idx) * DOF_UINT ((dof), (dof)->dofh_secsize))))
377 /* Helper function to examine the probe described by the given PROBE
378 and PROVIDER data structures and add it to the PROBESP vector.
379 STRTAB, OFFTAB, EOFFTAB and ARGTAB are pointers to tables in the
380 DOF program containing the attributes for the probe. */
383 dtrace_process_dof_probe (struct objfile
*objfile
,
384 struct gdbarch
*gdbarch
,
385 std::vector
<probe
*> *probesp
,
386 struct dtrace_dof_hdr
*dof
,
387 struct dtrace_dof_probe
*probe
,
388 struct dtrace_dof_provider
*provider
,
389 char *strtab
, char *offtab
, char *eofftab
,
390 char *argtab
, uint64_t strtab_size
)
392 int i
, j
, num_probes
, num_enablers
;
395 /* Each probe section can define zero or more probes of two
398 - probe->dofpr_noffs regular probes whose program counters are
399 stored in 32bit words starting at probe->dofpr_addr +
400 offtab[probe->dofpr_offidx].
402 - probe->dofpr_nenoffs is-enabled probes whose program counters
403 are stored in 32bit words starting at probe->dofpr_addr +
404 eofftab[probe->dofpr_enoffidx].
406 However is-enabled probes are not probes per-se, but an
407 optimization hack that is implemented in the kernel in a very
408 similar way than normal probes. This is how we support
409 is-enabled probes on GDB:
411 - Our probes are always DTrace regular probes.
413 - Our probes can be associated with zero or more "enablers". The
414 list of enablers is built from the is-enabled probes defined in
417 - Probes having a non-empty list of enablers can be enabled or
418 disabled using the `enable probe' and `disable probe' commands
419 respectively. The `Enabled' column in the output of `info
420 probes' will read `yes' if the enablers are activated, `no'
423 - Probes having an empty list of enablers are always enabled.
424 The `Enabled' column in the output of `info probes' will
427 It follows that if there are DTrace is-enabled probes defined for
428 some provider/name but no DTrace regular probes defined then the
429 GDB user wont be able to enable/disable these conditionals. */
431 num_probes
= DOF_UINT (dof
, probe
->dofpr_noffs
);
435 /* Build the list of enablers for the probes defined in this Probe
437 std::vector
<struct dtrace_probe_enabler
> enablers
;
438 num_enablers
= DOF_UINT (dof
, probe
->dofpr_nenoffs
);
439 for (i
= 0; i
< num_enablers
; i
++)
441 struct dtrace_probe_enabler enabler
;
442 uint32_t enabler_offset
443 = ((uint32_t *) eofftab
)[DOF_UINT (dof
, probe
->dofpr_enoffidx
) + i
];
445 enabler
.address
= DOF_UINT (dof
, probe
->dofpr_addr
)
446 + DOF_UINT (dof
, enabler_offset
);
447 enablers
.push_back (enabler
);
450 for (i
= 0; i
< num_probes
; i
++)
452 uint32_t probe_offset
453 = ((uint32_t *) offtab
)[DOF_UINT (dof
, probe
->dofpr_offidx
) + i
];
455 /* Set the provider and the name of the probe. */
456 const char *probe_provider
457 = strtab
+ DOF_UINT (dof
, provider
->dofpv_name
);
458 const char *name
= strtab
+ DOF_UINT (dof
, probe
->dofpr_name
);
460 /* The probe address. */
462 = DOF_UINT (dof
, probe
->dofpr_addr
) + DOF_UINT (dof
, probe_offset
);
464 /* Number of arguments in the probe. */
465 int probe_argc
= DOF_UINT (dof
, probe
->dofpr_nargc
);
467 /* Store argument type descriptions. A description of the type
468 of the argument is in the (J+1)th null-terminated string
469 starting at 'strtab' + 'probe->dofpr_nargv'. */
470 std::vector
<struct dtrace_probe_arg
> args
;
471 p
= strtab
+ DOF_UINT (dof
, probe
->dofpr_nargv
);
472 for (j
= 0; j
< probe_argc
; j
++)
476 /* Set arg.expr to ensure all fields in expr are initialized and
477 the compiler will not warn when arg is used. */
478 std::string
type_str (p
);
480 /* Use strtab_size as a sentinel. */
481 while (*p
++ != '\0' && p
- strtab
< strtab_size
)
484 /* Try to parse a type expression from the type string. If
485 this does not work then we set the type to `long
487 struct type
*type
= builtin_type (gdbarch
)->builtin_long
;
491 expr
= parse_expression_with_language (type_str
.c_str (),
494 CATCH (ex
, RETURN_MASK_ERROR
)
499 if (expr
!= NULL
&& expr
.get ()->elts
[0].opcode
== OP_TYPE
)
500 type
= expr
.get ()->elts
[1].type
;
502 args
.emplace_back (type
, std::move (type_str
), std::move (expr
));
505 std::vector
<struct dtrace_probe_enabler
> enablers_copy
= enablers
;
506 dtrace_probe
*ret
= new dtrace_probe (std::string (name
),
507 std::string (probe_provider
),
510 std::move (enablers_copy
));
512 /* Successfully created probe. */
513 probesp
->push_back (ret
);
517 /* Helper function to collect the probes described in the DOF program
518 whose header is pointed by DOF and add them to the PROBESP vector.
519 SECT is the ELF section containing the DOF program and OBJFILE is
520 its containing object file. */
523 dtrace_process_dof (asection
*sect
, struct objfile
*objfile
,
524 std::vector
<probe
*> *probesp
, struct dtrace_dof_hdr
*dof
)
526 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
527 struct dtrace_dof_sect
*section
;
530 /* The first step is to check for the DOF magic number. If no valid
531 DOF data is found in the section then a complaint is issued to
532 the user and the section skipped. */
533 if (dof
->dofh_ident
[DTRACE_DOF_ID_MAG0
] != 0x7F
534 || dof
->dofh_ident
[DTRACE_DOF_ID_MAG1
] != 'D'
535 || dof
->dofh_ident
[DTRACE_DOF_ID_MAG2
] != 'O'
536 || dof
->dofh_ident
[DTRACE_DOF_ID_MAG3
] != 'F')
537 goto invalid_dof_data
;
539 /* Make sure the encoding mark is either DTRACE_DOF_ENCODE_LSB or
540 DTRACE_DOF_ENCODE_MSB. */
541 if (dof
->dofh_ident
[DTRACE_DOF_ID_ENCODING
] != DTRACE_DOF_ENCODE_LSB
542 && dof
->dofh_ident
[DTRACE_DOF_ID_ENCODING
] != DTRACE_DOF_ENCODE_MSB
)
543 goto invalid_dof_data
;
545 /* Make sure this DOF is not an enabling DOF, i.e. there are no ECB
546 Description sections. */
547 section
= (struct dtrace_dof_sect
*) DTRACE_DOF_PTR (dof
,
548 DOF_UINT (dof
, dof
->dofh_secoff
));
549 for (i
= 0; i
< DOF_UINT (dof
, dof
->dofh_secnum
); i
++, section
++)
550 if (section
->dofs_type
== DTRACE_DOF_SECT_TYPE_ECBDESC
)
553 /* Iterate over any section of type Provider and extract the probe
554 information from them. If there are no "provider" sections on
555 the DOF then we just return. */
556 section
= (struct dtrace_dof_sect
*) DTRACE_DOF_PTR (dof
,
557 DOF_UINT (dof
, dof
->dofh_secoff
));
558 for (i
= 0; i
< DOF_UINT (dof
, dof
->dofh_secnum
); i
++, section
++)
559 if (DOF_UINT (dof
, section
->dofs_type
) == DTRACE_DOF_SECT_TYPE_PROVIDER
)
561 struct dtrace_dof_provider
*provider
= (struct dtrace_dof_provider
*)
562 DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, section
->dofs_offset
));
563 struct dtrace_dof_sect
*strtab_s
564 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_strtab
));
565 struct dtrace_dof_sect
*probes_s
566 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_probes
));
567 struct dtrace_dof_sect
*args_s
568 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_prargs
));
569 struct dtrace_dof_sect
*offsets_s
570 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_proffs
));
571 struct dtrace_dof_sect
*eoffsets_s
572 = DTRACE_DOF_SECT (dof
, DOF_UINT (dof
, provider
->dofpv_prenoffs
));
573 char *strtab
= DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, strtab_s
->dofs_offset
));
574 char *offtab
= DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, offsets_s
->dofs_offset
));
575 char *eofftab
= DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, eoffsets_s
->dofs_offset
));
576 char *argtab
= DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, args_s
->dofs_offset
));
577 unsigned int entsize
= DOF_UINT (dof
, probes_s
->dofs_entsize
);
580 if (DOF_UINT (dof
, section
->dofs_size
)
581 < sizeof (struct dtrace_dof_provider
))
583 /* The section is smaller than expected, so do not use it.
584 This has been observed on x86-solaris 10. */
585 goto invalid_dof_data
;
588 /* Very, unlikely, but could crash gdb if not handled
591 goto invalid_dof_data
;
593 num_probes
= DOF_UINT (dof
, probes_s
->dofs_size
) / entsize
;
595 for (i
= 0; i
< num_probes
; i
++)
597 struct dtrace_dof_probe
*probe
= (struct dtrace_dof_probe
*)
598 DTRACE_DOF_PTR (dof
, DOF_UINT (dof
, probes_s
->dofs_offset
)
599 + (i
* DOF_UINT (dof
, probes_s
->dofs_entsize
)));
601 dtrace_process_dof_probe (objfile
,
604 provider
, strtab
, offtab
, eofftab
, argtab
,
605 DOF_UINT (dof
, strtab_s
->dofs_size
));
612 complaint (_("skipping section '%s' which does not contain valid DOF data."),
616 /* Implementation of 'build_arg_exprs' method. */
619 dtrace_probe::build_arg_exprs (struct gdbarch
*gdbarch
)
622 m_args_expr_built
= true;
624 /* Iterate over the arguments in the probe and build the
625 corresponding GDB internal expression that will generate the
626 value of the argument when executed at the PC of the probe. */
627 for (dtrace_probe_arg
&arg
: m_args
)
629 /* Initialize the expression builder. The language does not
630 matter, since we are using our own parser. */
631 expr_builder
builder (current_language
, gdbarch
);
633 /* The argument value, which is ABI dependent and casted to
635 gdbarch_dtrace_parse_probe_argument (gdbarch
, &builder
, 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 (&builder
, UNOP_CAST
);
643 write_exp_elt_type (&builder
, arg
.type
);
644 write_exp_elt_opcode (&builder
, UNOP_CAST
);
647 arg
.expr
= builder
.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 (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 (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 (_("could not obtain the contents of"
862 "section '%s' in objfile `%s'."),
863 sect
->name
, abfd
->filename
);
865 dtrace_process_dof (sect
, objfile
, probesp
,
866 (struct dtrace_dof_hdr
*) dof
);
872 /* Implementation of the type_name method. */
875 dtrace_static_probe_ops::type_name () const
880 /* Implementation of the gen_info_probes_table_header method. */
882 std::vector
<struct info_probe_column
>
883 dtrace_static_probe_ops::gen_info_probes_table_header () const
885 struct info_probe_column dtrace_probe_column
;
887 dtrace_probe_column
.field_name
= "enabled";
888 dtrace_probe_column
.print_name
= _("Enabled");
890 return std::vector
<struct info_probe_column
> { dtrace_probe_column
};
893 /* Implementation of the `info probes dtrace' command. */
896 info_probes_dtrace_command (const char *arg
, int from_tty
)
898 info_probes_for_spops (arg
, from_tty
, &dtrace_static_probe_ops
);
902 _initialize_dtrace_probe (void)
904 all_static_probe_ops
.push_back (&dtrace_static_probe_ops
);
906 add_cmd ("dtrace", class_info
, info_probes_dtrace_command
,
908 Show information about DTrace static probes.\n\
909 Usage: info probes dtrace [PROVIDER [NAME [OBJECT]]]\n\
910 Each argument is a regular expression, used to select probes.\n\
911 PROVIDER matches probe provider names.\n\
912 NAME matches the probe names.\n\
913 OBJECT matches the executable or shared library name."),
914 info_probes_cmdlist_get ());