Blame view
kernel/trace/trace_probe.h
11.6 KB
8ab83f564
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
/* * Common header file for probe-based Dynamic events. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * This code was copied from kernel/trace/trace_kprobe.h written by * Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> * * Updates to make this generic: * Copyright (C) IBM Corporation, 2010-2011 * Author: Srikar Dronamraju */ #include <linux/seq_file.h> #include <linux/slab.h> #include <linux/smp.h> |
8434dc934
|
28 |
#include <linux/tracefs.h> |
8ab83f564
|
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
#include <linux/types.h> #include <linux/string.h> #include <linux/ctype.h> #include <linux/ptrace.h> #include <linux/perf_event.h> #include <linux/kprobes.h> #include <linux/stringify.h> #include <linux/limits.h> #include <linux/uaccess.h> #include <asm/bitsperlong.h> #include "trace.h" #include "trace_output.h" #define MAX_TRACE_ARGS 128 #define MAX_ARGSTR_LEN 63 #define MAX_EVENT_NAME_LEN 64 #define MAX_STRING_SIZE PATH_MAX /* Reserved field names */ #define FIELD_STRING_IP "__probe_ip" #define FIELD_STRING_RETIP "__probe_ret_ip" #define FIELD_STRING_FUNC "__probe_func" #undef DEFINE_FIELD #define DEFINE_FIELD(type, item, name, is_signed) \ do { \ ret = trace_define_field(event_call, #type, name, \ offsetof(typeof(field), item), \ sizeof(field.item), is_signed, \ FILTER_OTHER); \ if (ret) \ return ret; \ } while (0) /* Flags for trace_probe */ #define TP_FLAG_TRACE 1 #define TP_FLAG_PROFILE 2 #define TP_FLAG_REGISTERED 4 /* data_rloc: data relative location, compatible with u32 */ #define make_data_rloc(len, roffs) \ (((u32)(len) << 16) | ((u32)(roffs) & 0xffff)) #define get_rloc_len(dl) ((u32)(dl) >> 16) #define get_rloc_offs(dl) ((u32)(dl) & 0xffff) /* * Convert data_rloc to data_loc: * data_rloc stores the offset from data_rloc itself, but data_loc * stores the offset from event entry. */ #define convert_rloc_to_loc(dl, offs) ((u32)(dl) + (offs)) |
3da0f1800
|
83 |
static nokprobe_inline void *get_rloc_data(u32 *dl) |
b26c74e11
|
84 85 86 87 88 |
{ return (u8 *)dl + get_rloc_offs(*dl); } /* For data_loc conversion */ |
3da0f1800
|
89 |
static nokprobe_inline void *get_loc_data(u32 *dl, void *ent) |
b26c74e11
|
90 91 92 |
{ return (u8 *)ent + get_rloc_offs(*dl); } |
8ab83f564
|
93 94 95 96 97 98 99 100 101 102 |
/* Data fetch function type */ typedef void (*fetch_func_t)(struct pt_regs *, void *, void *); /* Printing function type */ typedef int (*print_type_func_t)(struct trace_seq *, const char *, void *, void *); /* Fetch types */ enum { FETCH_MTD_reg = 0, FETCH_MTD_stack, FETCH_MTD_retval, |
35abb67de
|
103 |
FETCH_MTD_comm, |
8ab83f564
|
104 105 106 107 |
FETCH_MTD_memory, FETCH_MTD_symbol, FETCH_MTD_deref, FETCH_MTD_bitfield, |
b7e0bf341
|
108 |
FETCH_MTD_file_offset, |
8ab83f564
|
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
FETCH_MTD_END, }; /* Fetch type information table */ struct fetch_type { const char *name; /* Name of type */ size_t size; /* Byte size of type */ int is_signed; /* Signed flag */ print_type_func_t print; /* Print functions */ const char *fmt; /* Fromat string */ const char *fmttype; /* Name in format file */ /* Fetch functions */ fetch_func_t fetch[FETCH_MTD_END]; }; struct fetch_param { fetch_func_t fn; void *data; }; |
34fee3a10
|
128 129 130 |
/* For defining macros, define string/string_size types */ typedef u32 string; typedef u32 string_size; |
b26c74e11
|
131 132 133 134 135 |
#define PRINT_TYPE_FUNC_NAME(type) print_type_##type #define PRINT_TYPE_FMT_NAME(type) print_type_format_##type /* Printing in basic type function template */ #define DECLARE_BASIC_PRINT_TYPE_FUNC(type) \ |
3da0f1800
|
136 137 |
int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, const char *name, \ void *data, void *ent); \ |
b26c74e11
|
138 139 140 141 142 143 144 145 146 147 |
extern const char PRINT_TYPE_FMT_NAME(type)[] DECLARE_BASIC_PRINT_TYPE_FUNC(u8); DECLARE_BASIC_PRINT_TYPE_FUNC(u16); DECLARE_BASIC_PRINT_TYPE_FUNC(u32); DECLARE_BASIC_PRINT_TYPE_FUNC(u64); DECLARE_BASIC_PRINT_TYPE_FUNC(s8); DECLARE_BASIC_PRINT_TYPE_FUNC(s16); DECLARE_BASIC_PRINT_TYPE_FUNC(s32); DECLARE_BASIC_PRINT_TYPE_FUNC(s64); |
17ce3dc7e
|
148 149 150 151 |
DECLARE_BASIC_PRINT_TYPE_FUNC(x8); DECLARE_BASIC_PRINT_TYPE_FUNC(x16); DECLARE_BASIC_PRINT_TYPE_FUNC(x32); DECLARE_BASIC_PRINT_TYPE_FUNC(x64); |
b26c74e11
|
152 |
DECLARE_BASIC_PRINT_TYPE_FUNC(string); |
34fee3a10
|
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
#define FETCH_FUNC_NAME(method, type) fetch_##method##_##type /* Declare macro for basic types */ #define DECLARE_FETCH_FUNC(method, type) \ extern void FETCH_FUNC_NAME(method, type)(struct pt_regs *regs, \ void *data, void *dest) #define DECLARE_BASIC_FETCH_FUNCS(method) \ DECLARE_FETCH_FUNC(method, u8); \ DECLARE_FETCH_FUNC(method, u16); \ DECLARE_FETCH_FUNC(method, u32); \ DECLARE_FETCH_FUNC(method, u64) DECLARE_BASIC_FETCH_FUNCS(reg); #define fetch_reg_string NULL #define fetch_reg_string_size NULL |
34fee3a10
|
169 170 171 |
DECLARE_BASIC_FETCH_FUNCS(retval); #define fetch_retval_string NULL #define fetch_retval_string_size NULL |
34fee3a10
|
172 173 174 175 176 177 178 179 180 181 182 |
DECLARE_BASIC_FETCH_FUNCS(symbol); DECLARE_FETCH_FUNC(symbol, string); DECLARE_FETCH_FUNC(symbol, string_size); DECLARE_BASIC_FETCH_FUNCS(deref); DECLARE_FETCH_FUNC(deref, string); DECLARE_FETCH_FUNC(deref, string_size); DECLARE_BASIC_FETCH_FUNCS(bitfield); #define fetch_bitfield_string NULL #define fetch_bitfield_string_size NULL |
35abb67de
|
183 184 185 186 187 188 189 |
/* comm only makes sense as a string */ #define fetch_comm_u8 NULL #define fetch_comm_u16 NULL #define fetch_comm_u32 NULL #define fetch_comm_u64 NULL DECLARE_FETCH_FUNC(comm, string); DECLARE_FETCH_FUNC(comm, string_size); |
3fd996a29
|
190 191 192 193 194 195 196 197 198 |
/* * Define macro for basic types - we don't need to define s* types, because * we have to care only about bitwidth at recording time. */ #define DEFINE_BASIC_FETCH_FUNCS(method) \ DEFINE_FETCH_##method(u8) \ DEFINE_FETCH_##method(u16) \ DEFINE_FETCH_##method(u32) \ DEFINE_FETCH_##method(u64) |
b26c74e11
|
199 |
/* Default (unsigned long) fetch type */ |
bdca79c2b
|
200 |
#define __DEFAULT_FETCH_TYPE(t) x##t |
b26c74e11
|
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
#define _DEFAULT_FETCH_TYPE(t) __DEFAULT_FETCH_TYPE(t) #define DEFAULT_FETCH_TYPE _DEFAULT_FETCH_TYPE(BITS_PER_LONG) #define DEFAULT_FETCH_TYPE_STR __stringify(DEFAULT_FETCH_TYPE) #define ASSIGN_FETCH_FUNC(method, type) \ [FETCH_MTD_##method] = FETCH_FUNC_NAME(method, type) #define __ASSIGN_FETCH_TYPE(_name, ptype, ftype, _size, sign, _fmttype) \ {.name = _name, \ .size = _size, \ .is_signed = sign, \ .print = PRINT_TYPE_FUNC_NAME(ptype), \ .fmt = PRINT_TYPE_FMT_NAME(ptype), \ .fmttype = _fmttype, \ .fetch = { \ ASSIGN_FETCH_FUNC(reg, ftype), \ ASSIGN_FETCH_FUNC(stack, ftype), \ ASSIGN_FETCH_FUNC(retval, ftype), \ |
35abb67de
|
219 |
ASSIGN_FETCH_FUNC(comm, ftype), \ |
b26c74e11
|
220 221 222 223 |
ASSIGN_FETCH_FUNC(memory, ftype), \ ASSIGN_FETCH_FUNC(symbol, ftype), \ ASSIGN_FETCH_FUNC(deref, ftype), \ ASSIGN_FETCH_FUNC(bitfield, ftype), \ |
b7e0bf341
|
224 |
ASSIGN_FETCH_FUNC(file_offset, ftype), \ |
b26c74e11
|
225 226 227 228 229 |
} \ } #define ASSIGN_FETCH_TYPE(ptype, ftype, sign) \ __ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, #ptype) |
17ce3dc7e
|
230 231 232 |
/* If ptype is an alias of atype, use this macro (show atype in format) */ #define ASSIGN_FETCH_TYPE_ALIAS(ptype, atype, ftype, sign) \ __ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, #atype) |
34fee3a10
|
233 |
#define ASSIGN_FETCH_TYPE_END {} |
b26c74e11
|
234 235 |
#define FETCH_TYPE_STRING 0 #define FETCH_TYPE_STRSIZE 1 |
6b0b75514
|
236 |
#ifdef CONFIG_KPROBE_EVENTS |
1301a44e7
|
237 238 239 240 241 |
struct symbol_cache; unsigned long update_symbol_cache(struct symbol_cache *sc); void free_symbol_cache(struct symbol_cache *sc); struct symbol_cache *alloc_symbol_cache(const char *sym, long offset); #else |
e0d18fe06
|
242 243 244 245 246 247 248 |
/* uprobes do not support symbol fetch methods */ #define fetch_symbol_u8 NULL #define fetch_symbol_u16 NULL #define fetch_symbol_u32 NULL #define fetch_symbol_u64 NULL #define fetch_symbol_string NULL #define fetch_symbol_string_size NULL |
1301a44e7
|
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
struct symbol_cache { }; static inline unsigned long __used update_symbol_cache(struct symbol_cache *sc) { return 0; } static inline void __used free_symbol_cache(struct symbol_cache *sc) { } static inline struct symbol_cache * __used alloc_symbol_cache(const char *sym, long offset) { return NULL; } |
6b0b75514
|
265 |
#endif /* CONFIG_KPROBE_EVENTS */ |
1301a44e7
|
266 |
|
8ab83f564
|
267 268 269 270 271 272 273 274 |
struct probe_arg { struct fetch_param fetch; struct fetch_param fetch_size; unsigned int offset; /* Offset from argument entry */ const char *name; /* Name of this argument */ const char *comm; /* Command of this argument */ const struct fetch_type *type; /* Type of this argument */ }; |
c31ffb3ff
|
275 276 |
struct trace_probe { unsigned int flags; /* For TP_FLAG_* */ |
2425bcb92
|
277 278 |
struct trace_event_class class; struct trace_event_call call; |
c31ffb3ff
|
279 280 281 282 283 |
struct list_head files; ssize_t size; /* trace entry size */ unsigned int nr_args; struct probe_arg args[]; }; |
70ed91c6e
|
284 |
struct event_file_link { |
7f1d2f821
|
285 |
struct trace_event_file *file; |
70ed91c6e
|
286 287 |
struct list_head list; }; |
c31ffb3ff
|
288 289 290 291 292 293 294 295 296 |
static inline bool trace_probe_is_enabled(struct trace_probe *tp) { return !!(tp->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE)); } static inline bool trace_probe_is_registered(struct trace_probe *tp) { return !!(tp->flags & TP_FLAG_REGISTERED); } |
3da0f1800
|
297 |
static nokprobe_inline void call_fetch(struct fetch_param *fprm, |
8ab83f564
|
298 299 300 301 302 303 |
struct pt_regs *regs, void *dest) { return fprm->fn(regs, fprm->data, dest); } /* Check the name is good for event/group/fields */ |
f0132c4e0
|
304 |
static inline bool is_good_name(const char *name) |
8ab83f564
|
305 306 |
{ if (!isalpha(*name) && *name != '_') |
f0132c4e0
|
307 |
return false; |
8ab83f564
|
308 309 |
while (*++name != '\0') { if (!isalpha(*name) && !isdigit(*name) && *name != '_') |
f0132c4e0
|
310 |
return false; |
8ab83f564
|
311 |
} |
f0132c4e0
|
312 |
return true; |
8ab83f564
|
313 |
} |
70ed91c6e
|
314 |
static inline struct event_file_link * |
7f1d2f821
|
315 |
find_event_file_link(struct trace_probe *tp, struct trace_event_file *file) |
70ed91c6e
|
316 317 318 319 320 321 322 323 324 |
{ struct event_file_link *link; list_for_each_entry(link, &tp->files, list) if (link->file == file) return link; return NULL; } |
8ab83f564
|
325 |
extern int traceprobe_parse_probe_arg(char *arg, ssize_t *size, |
d9a16d3ab
|
326 327 |
struct probe_arg *parg, bool is_return, bool is_kprobe, const struct fetch_type *ftbl); |
8ab83f564
|
328 329 330 331 332 333 |
extern int traceprobe_conflict_field_name(const char *name, struct probe_arg *args, int narg); extern void traceprobe_update_arg(struct probe_arg *arg); extern void traceprobe_free_probe_arg(struct probe_arg *arg); |
70001527f
|
334 |
extern int traceprobe_split_symbol_offset(char *symbol, long *offset); |
8ab83f564
|
335 336 337 338 339 340 |
extern ssize_t traceprobe_probes_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos, int (*createfn)(int, char**)); extern int traceprobe_command(const char *buf, int (*createfn)(int, char**)); |
2dc101837
|
341 342 |
/* Sum up total data length for dynamic arraies (strings) */ |
3da0f1800
|
343 |
static nokprobe_inline int |
2dc101837
|
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
__get_data_size(struct trace_probe *tp, struct pt_regs *regs) { int i, ret = 0; u32 len; for (i = 0; i < tp->nr_args; i++) if (unlikely(tp->args[i].fetch_size.fn)) { call_fetch(&tp->args[i].fetch_size, regs, &len); ret += len; } return ret; } /* Store the value of each argument */ |
3da0f1800
|
359 |
static nokprobe_inline void |
2dc101837
|
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
store_trace_args(int ent_size, struct trace_probe *tp, struct pt_regs *regs, u8 *data, int maxlen) { int i; u32 end = tp->size; u32 *dl; /* Data (relative) location */ for (i = 0; i < tp->nr_args; i++) { if (unlikely(tp->args[i].fetch_size.fn)) { /* * First, we set the relative location and * maximum data length to *dl */ dl = (u32 *)(data + tp->args[i].offset); *dl = make_data_rloc(maxlen, end - tp->args[i].offset); /* Then try to fetch string or dynamic array data */ call_fetch(&tp->args[i].fetch, regs, dl); /* Reduce maximum length */ end += get_rloc_len(*dl); maxlen -= get_rloc_len(*dl); /* Trick here, convert data_rloc to data_loc */ *dl = convert_rloc_to_loc(*dl, ent_size + tp->args[i].offset); } else /* Just fetching data normally */ call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); } } |
5bf652aaf
|
389 390 |
extern int set_print_fmt(struct trace_probe *tp, bool is_return); |