GDB (API)
/home/stan/gdb/src/gdb/probe.h
Go to the documentation of this file.
00001 /* Generic SDT probe support for GDB.
00002 
00003    Copyright (C) 2012-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #if !defined (PROBE_H)
00021 #define PROBE_H 1
00022 
00023 #include "gdb_vecs.h"
00024 
00025 /* Definition of a vector of probes.  */
00026 
00027 typedef struct probe *probe_p;
00028 DEF_VEC_P (probe_p);
00029 
00030 struct linespec_result;
00031 
00032 /* Structure useful for passing the header names in the method
00033    `gen_ui_out_table_header'.  */
00034 
00035 struct info_probe_column
00036   {
00037     /* The internal name of the field.  This string cannot be capitalized nor
00038        localized, e.g., "extra_field".  */
00039 
00040     const char *field_name;
00041 
00042     /* The field name to be printed in the `info probes' command.  This
00043        string can be capitalized and localized, e.g., _("Extra Field").  */
00044     const char *print_name;
00045   };
00046 
00047 typedef struct info_probe_column info_probe_column_s;
00048 DEF_VEC_O (info_probe_column_s);
00049 
00050 /* Operations associated with a probe.  */
00051 
00052 struct probe_ops
00053   {
00054     /* Method responsible for verifying if LINESPECP is a valid linespec for
00055        a probe breakpoint.  It should return 1 if it is, or zero if it is not.
00056        It also should update LINESPECP in order to discard the breakpoint
00057        option associated with this linespec.  For example, if the option is
00058        `-probe', and the LINESPECP is `-probe abc', the function should
00059        return 1 and set LINESPECP to `abc'.  */
00060 
00061     int (*is_linespec) (const char **linespecp);
00062 
00063     /* Function that should fill PROBES with known probes from OBJFILE.  */
00064 
00065     void (*get_probes) (VEC (probe_p) **probes, struct objfile *objfile);
00066 
00067     /* Function used to relocate addresses from PROBE according to some DELTA
00068        provided.  */
00069 
00070     void (*relocate) (struct probe *probe, CORE_ADDR delta);
00071 
00072     /* Return the number of arguments of PROBE.  */
00073 
00074     unsigned (*get_probe_argument_count) (struct probe *probe);
00075 
00076     /* Return 1 if the probe interface can evaluate the arguments of probe
00077        PROBE, zero otherwise.  See the comments on
00078        sym_probe_fns:can_evaluate_probe_arguments for more details.  */
00079 
00080     int (*can_evaluate_probe_arguments) (struct probe *probe);
00081 
00082     /* Evaluate the Nth argument from the PROBE, returning a value
00083        corresponding to it.  The argument number is represented N.  */
00084 
00085     struct value *(*evaluate_probe_argument) (struct probe *probe,
00086                                               unsigned n);
00087 
00088     /* Compile the Nth argument of the PROBE to an agent expression.
00089        The argument number is represented by N.  */
00090 
00091     void (*compile_to_ax) (struct probe *probe, struct agent_expr *aexpr,
00092                            struct axs_value *axs_value, unsigned n);
00093 
00094     /* Set the semaphore associated with the PROBE.  This function only makes
00095        sense if the probe has a concept of semaphore associated to a
00096        probe.  */
00097 
00098     void (*set_semaphore) (struct probe *probe, struct gdbarch *gdbarch);
00099 
00100     /* Clear the semaphore associated with the PROBE.  This function only
00101        makes sense if the probe has a concept of semaphore associated to
00102        a probe.  */
00103 
00104     void (*clear_semaphore) (struct probe *probe, struct gdbarch *gdbarch);
00105 
00106     /* Function called to destroy PROBE's specific data.  This function
00107        shall not free PROBE itself.  */
00108 
00109     void (*destroy) (struct probe *probe);
00110 
00111     /* Function responsible for providing the extra fields that will be
00112        printed in the `info probes' command.  It should fill HEADS
00113        with whatever extra fields it needs.  If the backend doesn't need
00114        to print extra fields, it can set this method to NULL.  */
00115 
00116     void (*gen_info_probes_table_header) (VEC (info_probe_column_s) **heads);
00117 
00118     /* Function that will fill VALUES with the values of the extra fields
00119        to be printed for PROBE.  If the backend implements the
00120        `gen_ui_out_table_header' method, then it should implement
00121        this method as well.  The backend should also guarantee that the
00122        order and the number of values in the vector is exactly the same
00123        as the order of the extra fields provided in the method
00124        `gen_ui_out_table_header'.  If a certain field is to be skipped
00125        when printing the information, you can push a NULL value in that
00126        position in the vector.  */
00127 
00128     void (*gen_info_probes_table_values) (struct probe *probe,
00129                                           VEC (const_char_ptr) **values);
00130   };
00131 
00132 /* Definition of a vector of probe_ops.  */
00133 
00134 typedef const struct probe_ops *probe_ops_cp;
00135 DEF_VEC_P (probe_ops_cp);
00136 extern VEC (probe_ops_cp) *all_probe_ops;
00137 
00138 /* The probe_ops associated with the generic probe.  */
00139 
00140 extern const struct probe_ops probe_ops_any;
00141 
00142 /* Helper function that, given KEYWORDS, iterate over it trying to match
00143    each keyword with LINESPECP.  If it succeeds, it updates the LINESPECP
00144    pointer and returns 1.  Otherwise, nothing is done to LINESPECP and zero
00145    is returned.  */
00146 
00147 extern int probe_is_linespec_by_keyword (const char **linespecp,
00148                                          const char *const *keywords);
00149 
00150 /* Return specific PROBE_OPS * matching *LINESPECP and possibly updating
00151    *LINESPECP to skip its "-probe-type " prefix.  Return &probe_ops_any if
00152    *LINESPECP matches "-probe ", that is any unspecific probe.  Return NULL if
00153    *LINESPECP is not identified as any known probe type, *LINESPECP is not
00154    modified in such case.  */
00155 
00156 extern const struct probe_ops *probe_linespec_to_ops (const char **linespecp);
00157 
00158 /* The probe itself.  The struct contains generic information about the
00159    probe, and then some specific information which should be stored in
00160    the `probe_info' field.  */
00161 
00162 struct probe
00163   {
00164     /* The operations associated with this probe.  */
00165     const struct probe_ops *pops;
00166 
00167     /* The objfile which contains this probe.  Even if the probe is also
00168        present in a separate debug objfile, this variable always points to
00169        the non-separate debug objfile.  */
00170     struct objfile *objfile;
00171 
00172     /* The name of the probe.  */
00173     const char *name;
00174 
00175     /* The provider of the probe.  It generally defaults to the name of
00176        the objfile which contains the probe.  */
00177     const char *provider;
00178 
00179     /* The address where the probe is inserted.  */
00180     CORE_ADDR address;
00181   };
00182 
00183 /* A helper for linespec that decodes a probe specification.  It returns a
00184    symtabs_and_lines object and updates *ARGPTR or throws an error.  The
00185    argument PTYPE specifies the type of the probe(s) to be parsed.  */
00186 
00187 extern struct symtabs_and_lines parse_probes (char **argptr,
00188                                               struct linespec_result *canon);
00189 
00190 /* Helper function to register the proper probe_ops to a newly created probe.
00191    This function is mainly called from `sym_get_probes'.  */
00192 
00193 extern void register_probe_ops (struct probe *probe);
00194 
00195 /* Given a PC, find an associated probe with type PTYPE.  If a probe is
00196    found, return it.  If no probe is found, return NULL.  */
00197 
00198 extern struct probe *find_probe_by_pc (CORE_ADDR pc);
00199 
00200 /* Search OBJFILE for a probe with the given PROVIDER, NAME and PTYPE.
00201    Return a VEC of all probes that were found.  If no matching probe
00202    is found, return NULL.  The caller must free the VEC.  */
00203 
00204 extern VEC (probe_p) *find_probes_in_objfile (struct objfile *objfile,
00205                                               const char *provider,
00206                                               const char *name);
00207 
00208 /* Generate a `info probes' command output for probe_ops represented by
00209    POPS.  If POPS is NULL it considers any probes types.  It is a helper
00210    function that can be used by the probe backends to print their
00211    `info probe TYPE'.  */
00212 
00213 extern void info_probes_for_ops (char *arg, int from_tty,
00214                                  const struct probe_ops *pops);
00215 
00216 /* Return the `cmd_list_element' associated with the `info probes' command,
00217    or create a new one if it doesn't exist.  Helper function that serves the
00218    purpose of avoiding the case of a backend using the `cmd_list_element'
00219    associated with `info probes', without having it registered yet.  */
00220 
00221 extern struct cmd_list_element **info_probes_cmdlist_get (void);
00222 
00223 /* Return the argument count of the specified probe.  */
00224 
00225 extern unsigned get_probe_argument_count (struct probe *probe);
00226 
00227 /* Return 1 if the probe interface associated with PROBE can evaluate
00228    arguments, zero otherwise.  See the comments on the definition of
00229    sym_probe_fns:can_evaluate_probe_arguments for more details.  */
00230 
00231 extern int can_evaluate_probe_arguments (struct probe *probe);
00232 
00233 /* Evaluate argument N of the specified probe.  N must be between 0
00234    inclusive and get_probe_argument_count exclusive.  */
00235 
00236 extern struct value *evaluate_probe_argument (struct probe *probe,
00237                                               unsigned n);
00238 
00239 /* A convenience function that finds a probe at the PC in FRAME and
00240    evaluates argument N, with 0 <= N < number_of_args.  If there is no
00241    probe at that location, or if the probe does not have enough arguments,
00242    this returns NULL.  */
00243 
00244 extern struct value *probe_safe_evaluate_at_pc (struct frame_info *frame,
00245                                                 unsigned n);
00246 
00247 #endif /* !defined (PROBE_H) */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines