xref: /dragonfly/contrib/gdb-7/gdb/probe.h (revision ef5ccd6c)
1*ef5ccd6cSJohn Marino /* Generic SDT probe support for GDB.
2*ef5ccd6cSJohn Marino 
3*ef5ccd6cSJohn Marino    Copyright (C) 2012-2013 Free Software Foundation, Inc.
4*ef5ccd6cSJohn Marino 
5*ef5ccd6cSJohn Marino    This file is part of GDB.
6*ef5ccd6cSJohn Marino 
7*ef5ccd6cSJohn Marino    This program is free software; you can redistribute it and/or modify
8*ef5ccd6cSJohn Marino    it under the terms of the GNU General Public License as published by
9*ef5ccd6cSJohn Marino    the Free Software Foundation; either version 3 of the License, or
10*ef5ccd6cSJohn Marino    (at your option) any later version.
11*ef5ccd6cSJohn Marino 
12*ef5ccd6cSJohn Marino    This program is distributed in the hope that it will be useful,
13*ef5ccd6cSJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*ef5ccd6cSJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*ef5ccd6cSJohn Marino    GNU General Public License for more details.
16*ef5ccd6cSJohn Marino 
17*ef5ccd6cSJohn Marino    You should have received a copy of the GNU General Public License
18*ef5ccd6cSJohn Marino    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19*ef5ccd6cSJohn Marino 
20*ef5ccd6cSJohn Marino #if !defined (PROBE_H)
21*ef5ccd6cSJohn Marino #define PROBE_H 1
22*ef5ccd6cSJohn Marino 
23*ef5ccd6cSJohn Marino #include "gdb_vecs.h"
24*ef5ccd6cSJohn Marino 
25*ef5ccd6cSJohn Marino /* Definition of a vector of probes.  */
26*ef5ccd6cSJohn Marino 
27*ef5ccd6cSJohn Marino typedef struct probe *probe_p;
28*ef5ccd6cSJohn Marino DEF_VEC_P (probe_p);
29*ef5ccd6cSJohn Marino 
30*ef5ccd6cSJohn Marino struct linespec_result;
31*ef5ccd6cSJohn Marino 
32*ef5ccd6cSJohn Marino /* Structure useful for passing the header names in the method
33*ef5ccd6cSJohn Marino    `gen_ui_out_table_header'.  */
34*ef5ccd6cSJohn Marino 
35*ef5ccd6cSJohn Marino struct info_probe_column
36*ef5ccd6cSJohn Marino   {
37*ef5ccd6cSJohn Marino     /* The internal name of the field.  This string cannot be capitalized nor
38*ef5ccd6cSJohn Marino        localized, e.g., "extra_field".  */
39*ef5ccd6cSJohn Marino 
40*ef5ccd6cSJohn Marino     const char *field_name;
41*ef5ccd6cSJohn Marino 
42*ef5ccd6cSJohn Marino     /* The field name to be printed in the `info probes' command.  This
43*ef5ccd6cSJohn Marino        string can be capitalized and localized, e.g., _("Extra Field").  */
44*ef5ccd6cSJohn Marino     const char *print_name;
45*ef5ccd6cSJohn Marino   };
46*ef5ccd6cSJohn Marino 
47*ef5ccd6cSJohn Marino typedef struct info_probe_column info_probe_column_s;
48*ef5ccd6cSJohn Marino DEF_VEC_O (info_probe_column_s);
49*ef5ccd6cSJohn Marino 
50*ef5ccd6cSJohn Marino /* Operations associated with a probe.  */
51*ef5ccd6cSJohn Marino 
52*ef5ccd6cSJohn Marino struct probe_ops
53*ef5ccd6cSJohn Marino   {
54*ef5ccd6cSJohn Marino     /* Method responsible for verifying if LINESPECP is a valid linespec for
55*ef5ccd6cSJohn Marino        a probe breakpoint.  It should return 1 if it is, or zero if it is not.
56*ef5ccd6cSJohn Marino        It also should update LINESPECP in order to discard the breakpoint
57*ef5ccd6cSJohn Marino        option associated with this linespec.  For example, if the option is
58*ef5ccd6cSJohn Marino        `-probe', and the LINESPECP is `-probe abc', the function should
59*ef5ccd6cSJohn Marino        return 1 and set LINESPECP to `abc'.  */
60*ef5ccd6cSJohn Marino 
61*ef5ccd6cSJohn Marino     int (*is_linespec) (const char **linespecp);
62*ef5ccd6cSJohn Marino 
63*ef5ccd6cSJohn Marino     /* Function that should fill PROBES with known probes from OBJFILE.  */
64*ef5ccd6cSJohn Marino 
65*ef5ccd6cSJohn Marino     void (*get_probes) (VEC (probe_p) **probes, struct objfile *objfile);
66*ef5ccd6cSJohn Marino 
67*ef5ccd6cSJohn Marino     /* Function used to relocate addresses from PROBE according to some DELTA
68*ef5ccd6cSJohn Marino        provided.  */
69*ef5ccd6cSJohn Marino 
70*ef5ccd6cSJohn Marino     void (*relocate) (struct probe *probe, CORE_ADDR delta);
71*ef5ccd6cSJohn Marino 
72*ef5ccd6cSJohn Marino     /* Return the number of arguments of PROBE.  */
73*ef5ccd6cSJohn Marino 
74*ef5ccd6cSJohn Marino     unsigned (*get_probe_argument_count) (struct probe *probe);
75*ef5ccd6cSJohn Marino 
76*ef5ccd6cSJohn Marino     /* Evaluate the Nth argument from the PROBE, returning a value
77*ef5ccd6cSJohn Marino        corresponding to it.  The argument number is represented N.  */
78*ef5ccd6cSJohn Marino 
79*ef5ccd6cSJohn Marino     struct value *(*evaluate_probe_argument) (struct probe *probe,
80*ef5ccd6cSJohn Marino 					      unsigned n);
81*ef5ccd6cSJohn Marino 
82*ef5ccd6cSJohn Marino     /* Compile the Nth argument of the PROBE to an agent expression.
83*ef5ccd6cSJohn Marino        The argument number is represented by N.  */
84*ef5ccd6cSJohn Marino 
85*ef5ccd6cSJohn Marino     void (*compile_to_ax) (struct probe *probe, struct agent_expr *aexpr,
86*ef5ccd6cSJohn Marino 			   struct axs_value *axs_value, unsigned n);
87*ef5ccd6cSJohn Marino 
88*ef5ccd6cSJohn Marino     /* Set the semaphore associated with the PROBE.  This function only makes
89*ef5ccd6cSJohn Marino        sense if the probe has a concept of semaphore associated to a
90*ef5ccd6cSJohn Marino        probe.  */
91*ef5ccd6cSJohn Marino 
92*ef5ccd6cSJohn Marino     void (*set_semaphore) (struct probe *probe, struct gdbarch *gdbarch);
93*ef5ccd6cSJohn Marino 
94*ef5ccd6cSJohn Marino     /* Clear the semaphore associated with the PROBE.  This function only
95*ef5ccd6cSJohn Marino        makes sense if the probe has a concept of semaphore associated to
96*ef5ccd6cSJohn Marino        a probe.  */
97*ef5ccd6cSJohn Marino 
98*ef5ccd6cSJohn Marino     void (*clear_semaphore) (struct probe *probe, struct gdbarch *gdbarch);
99*ef5ccd6cSJohn Marino 
100*ef5ccd6cSJohn Marino     /* Function called to destroy PROBE's specific data.  This function
101*ef5ccd6cSJohn Marino        shall not free PROBE itself.  */
102*ef5ccd6cSJohn Marino 
103*ef5ccd6cSJohn Marino     void (*destroy) (struct probe *probe);
104*ef5ccd6cSJohn Marino 
105*ef5ccd6cSJohn Marino     /* Function responsible for providing the extra fields that will be
106*ef5ccd6cSJohn Marino        printed in the `info probes' command.  It should fill HEADS
107*ef5ccd6cSJohn Marino        with whatever extra fields it needs.  If the backend doesn't need
108*ef5ccd6cSJohn Marino        to print extra fields, it can set this method to NULL.  */
109*ef5ccd6cSJohn Marino 
110*ef5ccd6cSJohn Marino     void (*gen_info_probes_table_header) (VEC (info_probe_column_s) **heads);
111*ef5ccd6cSJohn Marino 
112*ef5ccd6cSJohn Marino     /* Function that will fill VALUES with the values of the extra fields
113*ef5ccd6cSJohn Marino        to be printed for PROBE.  If the backend implements the
114*ef5ccd6cSJohn Marino        `gen_ui_out_table_header' method, then it should implement
115*ef5ccd6cSJohn Marino        this method as well.  The backend should also guarantee that the
116*ef5ccd6cSJohn Marino        order and the number of values in the vector is exactly the same
117*ef5ccd6cSJohn Marino        as the order of the extra fields provided in the method
118*ef5ccd6cSJohn Marino        `gen_ui_out_table_header'.  If a certain field is to be skipped
119*ef5ccd6cSJohn Marino        when printing the information, you can push a NULL value in that
120*ef5ccd6cSJohn Marino        position in the vector.  */
121*ef5ccd6cSJohn Marino 
122*ef5ccd6cSJohn Marino     void (*gen_info_probes_table_values) (struct probe *probe,
123*ef5ccd6cSJohn Marino 					  VEC (const_char_ptr) **values);
124*ef5ccd6cSJohn Marino   };
125*ef5ccd6cSJohn Marino 
126*ef5ccd6cSJohn Marino /* Definition of a vector of probe_ops.  */
127*ef5ccd6cSJohn Marino 
128*ef5ccd6cSJohn Marino typedef const struct probe_ops *probe_ops_cp;
129*ef5ccd6cSJohn Marino DEF_VEC_P (probe_ops_cp);
130*ef5ccd6cSJohn Marino extern VEC (probe_ops_cp) *all_probe_ops;
131*ef5ccd6cSJohn Marino 
132*ef5ccd6cSJohn Marino /* The probe_ops associated with the generic probe.  */
133*ef5ccd6cSJohn Marino 
134*ef5ccd6cSJohn Marino extern const struct probe_ops probe_ops_any;
135*ef5ccd6cSJohn Marino 
136*ef5ccd6cSJohn Marino /* Helper function that, given KEYWORDS, iterate over it trying to match
137*ef5ccd6cSJohn Marino    each keyword with LINESPECP.  If it succeeds, it updates the LINESPECP
138*ef5ccd6cSJohn Marino    pointer and returns 1.  Otherwise, nothing is done to LINESPECP and zero
139*ef5ccd6cSJohn Marino    is returned.  */
140*ef5ccd6cSJohn Marino 
141*ef5ccd6cSJohn Marino extern int probe_is_linespec_by_keyword (const char **linespecp,
142*ef5ccd6cSJohn Marino 					 const char *const *keywords);
143*ef5ccd6cSJohn Marino 
144*ef5ccd6cSJohn Marino /* Return specific PROBE_OPS * matching *LINESPECP and possibly updating
145*ef5ccd6cSJohn Marino    *LINESPECP to skip its "-probe-type " prefix.  Return &probe_ops_any if
146*ef5ccd6cSJohn Marino    *LINESPECP matches "-probe ", that is any unspecific probe.  Return NULL if
147*ef5ccd6cSJohn Marino    *LINESPECP is not identified as any known probe type, *LINESPECP is not
148*ef5ccd6cSJohn Marino    modified in such case.  */
149*ef5ccd6cSJohn Marino 
150*ef5ccd6cSJohn Marino extern const struct probe_ops *probe_linespec_to_ops (const char **linespecp);
151*ef5ccd6cSJohn Marino 
152*ef5ccd6cSJohn Marino /* The probe itself.  The struct contains generic information about the
153*ef5ccd6cSJohn Marino    probe, and then some specific information which should be stored in
154*ef5ccd6cSJohn Marino    the `probe_info' field.  */
155*ef5ccd6cSJohn Marino 
156*ef5ccd6cSJohn Marino struct probe
157*ef5ccd6cSJohn Marino   {
158*ef5ccd6cSJohn Marino     /* The operations associated with this probe.  */
159*ef5ccd6cSJohn Marino     const struct probe_ops *pops;
160*ef5ccd6cSJohn Marino 
161*ef5ccd6cSJohn Marino     /* The objfile which contains this probe.  Even if the probe is also
162*ef5ccd6cSJohn Marino        present in a separate debug objfile, this variable always points to
163*ef5ccd6cSJohn Marino        the non-separate debug objfile.  */
164*ef5ccd6cSJohn Marino     struct objfile *objfile;
165*ef5ccd6cSJohn Marino 
166*ef5ccd6cSJohn Marino     /* The name of the probe.  */
167*ef5ccd6cSJohn Marino     const char *name;
168*ef5ccd6cSJohn Marino 
169*ef5ccd6cSJohn Marino     /* The provider of the probe.  It generally defaults to the name of
170*ef5ccd6cSJohn Marino        the objfile which contains the probe.  */
171*ef5ccd6cSJohn Marino     const char *provider;
172*ef5ccd6cSJohn Marino 
173*ef5ccd6cSJohn Marino     /* The address where the probe is inserted.  */
174*ef5ccd6cSJohn Marino     CORE_ADDR address;
175*ef5ccd6cSJohn Marino   };
176*ef5ccd6cSJohn Marino 
177*ef5ccd6cSJohn Marino /* A helper for linespec that decodes a probe specification.  It returns a
178*ef5ccd6cSJohn Marino    symtabs_and_lines object and updates *ARGPTR or throws an error.  The
179*ef5ccd6cSJohn Marino    argument PTYPE specifies the type of the probe(s) to be parsed.  */
180*ef5ccd6cSJohn Marino 
181*ef5ccd6cSJohn Marino extern struct symtabs_and_lines parse_probes (char **argptr,
182*ef5ccd6cSJohn Marino 					      struct linespec_result *canon);
183*ef5ccd6cSJohn Marino 
184*ef5ccd6cSJohn Marino /* Helper function to register the proper probe_ops to a newly created probe.
185*ef5ccd6cSJohn Marino    This function is mainly called from `sym_get_probes'.  */
186*ef5ccd6cSJohn Marino 
187*ef5ccd6cSJohn Marino extern void register_probe_ops (struct probe *probe);
188*ef5ccd6cSJohn Marino 
189*ef5ccd6cSJohn Marino /* Given a PC, find an associated probe with type PTYPE.  If a probe is
190*ef5ccd6cSJohn Marino    found, return it.  If no probe is found, return NULL.  */
191*ef5ccd6cSJohn Marino 
192*ef5ccd6cSJohn Marino extern struct probe *find_probe_by_pc (CORE_ADDR pc);
193*ef5ccd6cSJohn Marino 
194*ef5ccd6cSJohn Marino /* Search OBJFILE for a probe with the given PROVIDER, NAME and PTYPE.
195*ef5ccd6cSJohn Marino    Return a VEC of all probes that were found.  If no matching probe
196*ef5ccd6cSJohn Marino    is found, return NULL.  The caller must free the VEC.  */
197*ef5ccd6cSJohn Marino 
198*ef5ccd6cSJohn Marino extern VEC (probe_p) *find_probes_in_objfile (struct objfile *objfile,
199*ef5ccd6cSJohn Marino 					      const char *provider,
200*ef5ccd6cSJohn Marino 					      const char *name);
201*ef5ccd6cSJohn Marino 
202*ef5ccd6cSJohn Marino /* Generate a `info probes' command output for probe_ops represented by
203*ef5ccd6cSJohn Marino    POPS.  If POPS is NULL it considers any probes types.  It is a helper
204*ef5ccd6cSJohn Marino    function that can be used by the probe backends to print their
205*ef5ccd6cSJohn Marino    `info probe TYPE'.  */
206*ef5ccd6cSJohn Marino 
207*ef5ccd6cSJohn Marino extern void info_probes_for_ops (char *arg, int from_tty,
208*ef5ccd6cSJohn Marino 				 const struct probe_ops *pops);
209*ef5ccd6cSJohn Marino 
210*ef5ccd6cSJohn Marino /* Return the `cmd_list_element' associated with the `info probes' command,
211*ef5ccd6cSJohn Marino    or create a new one if it doesn't exist.  Helper function that serves the
212*ef5ccd6cSJohn Marino    purpose of avoiding the case of a backend using the `cmd_list_element'
213*ef5ccd6cSJohn Marino    associated with `info probes', without having it registered yet.  */
214*ef5ccd6cSJohn Marino 
215*ef5ccd6cSJohn Marino extern struct cmd_list_element **info_probes_cmdlist_get (void);
216*ef5ccd6cSJohn Marino 
217*ef5ccd6cSJohn Marino /* A convenience function that finds a probe at the PC in FRAME and
218*ef5ccd6cSJohn Marino    evaluates argument N, with 0 <= N < number_of_args.  If there is no
219*ef5ccd6cSJohn Marino    probe at that location, or if the probe does not have enough arguments,
220*ef5ccd6cSJohn Marino    this returns NULL.  */
221*ef5ccd6cSJohn Marino 
222*ef5ccd6cSJohn Marino extern struct value *probe_safe_evaluate_at_pc (struct frame_info *frame,
223*ef5ccd6cSJohn Marino 						unsigned n);
224*ef5ccd6cSJohn Marino 
225*ef5ccd6cSJohn Marino #endif /* !defined (PROBE_H) */
226