Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _PROBE_FINDER_H
0003 #define _PROBE_FINDER_H
0004 
0005 #include <stdbool.h>
0006 #include "intlist.h"
0007 #include "build-id.h"
0008 #include "probe-event.h"
0009 #include <linux/ctype.h>
0010 
0011 #define MAX_PROBE_BUFFER    1024
0012 #define MAX_PROBES       128
0013 #define MAX_PROBE_ARGS       128
0014 
0015 #define PROBE_ARG_VARS      "$vars"
0016 #define PROBE_ARG_PARAMS    "$params"
0017 
0018 static inline int is_c_varname(const char *name)
0019 {
0020     /* TODO */
0021     return isalpha(name[0]) || name[0] == '_';
0022 }
0023 
0024 #ifdef HAVE_DWARF_SUPPORT
0025 
0026 #include "dwarf-aux.h"
0027 
0028 /* TODO: export debuginfo data structure even if no dwarf support */
0029 
0030 /* debug information structure */
0031 struct debuginfo {
0032     Dwarf       *dbg;
0033     Dwfl_Module *mod;
0034     Dwfl        *dwfl;
0035     Dwarf_Addr  bias;
0036     const unsigned char *build_id;
0037 };
0038 
0039 /* This also tries to open distro debuginfo */
0040 struct debuginfo *debuginfo__new(const char *path);
0041 void debuginfo__delete(struct debuginfo *dbg);
0042 
0043 /* Find probe_trace_events specified by perf_probe_event from debuginfo */
0044 int debuginfo__find_trace_events(struct debuginfo *dbg,
0045                  struct perf_probe_event *pev,
0046                  struct probe_trace_event **tevs);
0047 
0048 /* Find a perf_probe_point from debuginfo */
0049 int debuginfo__find_probe_point(struct debuginfo *dbg, u64 addr,
0050                 struct perf_probe_point *ppt);
0051 
0052 int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs,
0053                    bool adjust_offset);
0054 
0055 /* Find a line range */
0056 int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr);
0057 
0058 /* Find available variables */
0059 int debuginfo__find_available_vars_at(struct debuginfo *dbg,
0060                       struct perf_probe_event *pev,
0061                       struct variable_list **vls);
0062 
0063 /* Find a src file from a DWARF tag path */
0064 int find_source_path(const char *raw_path, const char *sbuild_id,
0065              const char *comp_dir, char **new_path);
0066 
0067 struct probe_finder {
0068     struct perf_probe_event *pev;       /* Target probe event */
0069     struct debuginfo    *dbg;
0070 
0071     /* Callback when a probe point is found */
0072     int (*callback)(Dwarf_Die *sc_die, struct probe_finder *pf);
0073 
0074     /* For function searching */
0075     int         lno;        /* Line number */
0076     Dwarf_Addr      addr;       /* Address */
0077     const char      *fname;     /* Real file name */
0078     Dwarf_Die       cu_die;     /* Current CU */
0079     Dwarf_Die       sp_die;
0080     struct intlist      *lcache;    /* Line cache for lazy match */
0081 
0082     /* For variable searching */
0083 #if _ELFUTILS_PREREQ(0, 142)
0084     /* Call Frame Information from .eh_frame */
0085     Dwarf_CFI       *cfi_eh;
0086     /* Call Frame Information from .debug_frame */
0087     Dwarf_CFI       *cfi_dbg;
0088 #endif
0089     Dwarf_Op        *fb_ops;    /* Frame base attribute */
0090     unsigned int        machine;    /* Target machine arch */
0091     struct perf_probe_arg   *pvar;      /* Current target variable */
0092     struct probe_trace_arg  *tvar;      /* Current result variable */
0093     bool            skip_empty_arg; /* Skip non-exist args */
0094 };
0095 
0096 struct trace_event_finder {
0097     struct probe_finder pf;
0098     Dwfl_Module     *mod;       /* For solving symbols */
0099     struct probe_trace_event *tevs;     /* Found trace events */
0100     int         ntevs;      /* Number of trace events */
0101     int         max_tevs;   /* Max number of trace events */
0102 };
0103 
0104 struct available_var_finder {
0105     struct probe_finder pf;
0106     Dwfl_Module     *mod;       /* For solving symbols */
0107     struct variable_list    *vls;       /* Found variable lists */
0108     int         nvls;       /* Number of variable lists */
0109     int         max_vls;    /* Max no. of variable lists */
0110     bool            child;      /* Search child scopes */
0111 };
0112 
0113 struct line_finder {
0114     struct line_range   *lr;        /* Target line range */
0115 
0116     const char      *fname;     /* File name */
0117     int         lno_s;      /* Start line number */
0118     int         lno_e;      /* End line number */
0119     Dwarf_Die       cu_die;     /* Current CU */
0120     Dwarf_Die       sp_die;
0121     int         found;
0122 };
0123 
0124 #endif /* HAVE_DWARF_SUPPORT */
0125 
0126 #endif /*_PROBE_FINDER_H */