diff options
| author | Masami Hiramatsu <mhiramat@redhat.com> | 2010-04-12 13:17:08 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-04-14 16:26:28 -0400 |
| commit | 93ccae7a2227466a0d071fe52c51319f2f34c365 (patch) | |
| tree | ad98a4db74fff834ce79b83f21192713cc3665bc /kernel/trace | |
| parent | df0faf4be02996135bc3a06b4f34360449c78084 (diff) | |
tracing/kprobes: Support basic types on dynamic events
Support basic types of integer (u8, u16, u32, u64, s8, s16, s32, s64) in
kprobe tracer. With this patch, users can specify above basic types on
each arguments after ':'. If omitted, the argument type is set as
unsigned long (u32 or u64, arch-dependent).
e.g.
echo 'p account_system_time+0 hardirq_offset=%si:s32' > kprobe_events
adds a probe recording hardirq_offset in signed-32bits value on the
entry of account_system_time.
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20100412171708.3790.18599.stgit@localhost6.localdomain6>
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'kernel/trace')
| -rw-r--r-- | kernel/trace/trace.h | 16 | ||||
| -rw-r--r-- | kernel/trace/trace_kprobe.c | 535 |
2 files changed, 331 insertions, 220 deletions
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index bec2c973ff0c..3ebdb6bd2362 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h | |||
| @@ -102,29 +102,17 @@ struct syscall_trace_exit { | |||
| 102 | long ret; | 102 | long ret; |
| 103 | }; | 103 | }; |
| 104 | 104 | ||
| 105 | struct kprobe_trace_entry { | 105 | struct kprobe_trace_entry_head { |
| 106 | struct trace_entry ent; | 106 | struct trace_entry ent; |
| 107 | unsigned long ip; | 107 | unsigned long ip; |
| 108 | int nargs; | ||
| 109 | unsigned long args[]; | ||
| 110 | }; | 108 | }; |
| 111 | 109 | ||
| 112 | #define SIZEOF_KPROBE_TRACE_ENTRY(n) \ | 110 | struct kretprobe_trace_entry_head { |
| 113 | (offsetof(struct kprobe_trace_entry, args) + \ | ||
| 114 | (sizeof(unsigned long) * (n))) | ||
| 115 | |||
| 116 | struct kretprobe_trace_entry { | ||
| 117 | struct trace_entry ent; | 111 | struct trace_entry ent; |
| 118 | unsigned long func; | 112 | unsigned long func; |
| 119 | unsigned long ret_ip; | 113 | unsigned long ret_ip; |
| 120 | int nargs; | ||
| 121 | unsigned long args[]; | ||
| 122 | }; | 114 | }; |
| 123 | 115 | ||
| 124 | #define SIZEOF_KRETPROBE_TRACE_ENTRY(n) \ | ||
| 125 | (offsetof(struct kretprobe_trace_entry, args) + \ | ||
| 126 | (sizeof(unsigned long) * (n))) | ||
| 127 | |||
| 128 | /* | 116 | /* |
| 129 | * trace_flag_type is an enumeration that holds different | 117 | * trace_flag_type is an enumeration that holds different |
| 130 | * states when a trace occurs. These are: | 118 | * states when a trace occurs. These are: |
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 1251e367bae9..a7514326052b 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c | |||
| @@ -29,6 +29,8 @@ | |||
| 29 | #include <linux/ctype.h> | 29 | #include <linux/ctype.h> |
| 30 | #include <linux/ptrace.h> | 30 | #include <linux/ptrace.h> |
| 31 | #include <linux/perf_event.h> | 31 | #include <linux/perf_event.h> |
| 32 | #include <linux/stringify.h> | ||
| 33 | #include <asm/bitsperlong.h> | ||
| 32 | 34 | ||
| 33 | #include "trace.h" | 35 | #include "trace.h" |
| 34 | #include "trace_output.h" | 36 | #include "trace_output.h" |
| @@ -40,7 +42,6 @@ | |||
| 40 | 42 | ||
| 41 | /* Reserved field names */ | 43 | /* Reserved field names */ |
| 42 | #define FIELD_STRING_IP "__probe_ip" | 44 | #define FIELD_STRING_IP "__probe_ip" |
| 43 | #define FIELD_STRING_NARGS "__probe_nargs" | ||
| 44 | #define FIELD_STRING_RETIP "__probe_ret_ip" | 45 | #define FIELD_STRING_RETIP "__probe_ret_ip" |
| 45 | #define FIELD_STRING_FUNC "__probe_func" | 46 | #define FIELD_STRING_FUNC "__probe_func" |
| 46 | 47 | ||
| @@ -52,56 +53,102 @@ const char *reserved_field_names[] = { | |||
| 52 | "common_tgid", | 53 | "common_tgid", |
| 53 | "common_lock_depth", | 54 | "common_lock_depth", |
| 54 | FIELD_STRING_IP, | 55 | FIELD_STRING_IP, |
| 55 | FIELD_STRING_NARGS, | ||
| 56 | FIELD_STRING_RETIP, | 56 | FIELD_STRING_RETIP, |
| 57 | FIELD_STRING_FUNC, | 57 | FIELD_STRING_FUNC, |
| 58 | }; | 58 | }; |
| 59 | 59 | ||
| 60 | struct fetch_func { | 60 | /* Printing function type */ |
| 61 | unsigned long (*func)(struct pt_regs *, void *); | 61 | typedef int (*print_type_func_t)(struct trace_seq *, const char *, void *); |
| 62 | #define PRINT_TYPE_FUNC_NAME(type) print_type_##type | ||
| 63 | #define PRINT_TYPE_FMT_NAME(type) print_type_format_##type | ||
| 64 | |||
| 65 | /* Printing in basic type function template */ | ||
| 66 | #define DEFINE_BASIC_PRINT_TYPE_FUNC(type, fmt, cast) \ | ||
| 67 | static __kprobes int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, \ | ||
| 68 | const char *name, void *data)\ | ||
| 69 | { \ | ||
| 70 | return trace_seq_printf(s, " %s=" fmt, name, (cast)*(type *)data);\ | ||
| 71 | } \ | ||
| 72 | static const char PRINT_TYPE_FMT_NAME(type)[] = fmt; | ||
| 73 | |||
| 74 | DEFINE_BASIC_PRINT_TYPE_FUNC(u8, "%x", unsigned int) | ||
| 75 | DEFINE_BASIC_PRINT_TYPE_FUNC(u16, "%x", unsigned int) | ||
| 76 | DEFINE_BASIC_PRINT_TYPE_FUNC(u32, "%lx", unsigned long) | ||
| 77 | DEFINE_BASIC_PRINT_TYPE_FUNC(u64, "%llx", unsigned long long) | ||
| 78 | DEFINE_BASIC_PRINT_TYPE_FUNC(s8, "%d", int) | ||
| 79 | DEFINE_BASIC_PRINT_TYPE_FUNC(s16, "%d", int) | ||
| 80 | DEFINE_BASIC_PRINT_TYPE_FUNC(s32, "%ld", long) | ||
| 81 | DEFINE_BASIC_PRINT_TYPE_FUNC(s64, "%lld", long long) | ||
| 82 | |||
| 83 | /* Data fetch function type */ | ||
| 84 | typedef void (*fetch_func_t)(struct pt_regs *, void *, void *); | ||
| 85 | |||
| 86 | struct fetch_param { | ||
| 87 | fetch_func_t fn; | ||
| 62 | void *data; | 88 | void *data; |
| 63 | }; | 89 | }; |
| 64 | 90 | ||
| 65 | static __kprobes unsigned long call_fetch(struct fetch_func *f, | 91 | static __kprobes void call_fetch(struct fetch_param *fprm, |
| 66 | struct pt_regs *regs) | 92 | struct pt_regs *regs, void *dest) |
| 67 | { | 93 | { |
| 68 | return f->func(regs, f->data); | 94 | return fprm->fn(regs, fprm->data, dest); |
| 69 | } | 95 | } |
| 70 | 96 | ||
| 71 | /* fetch handlers */ | 97 | #define FETCH_FUNC_NAME(kind, type) fetch_##kind##_##type |
| 72 | static __kprobes unsigned long fetch_register(struct pt_regs *regs, | 98 | /* |
| 73 | void *offset) | 99 | * Define macro for basic types - we don't need to define s* types, because |
| 74 | { | 100 | * we have to care only about bitwidth at recording time. |
| 75 | return regs_get_register(regs, (unsigned int)((unsigned long)offset)); | 101 | */ |
| 102 | #define DEFINE_BASIC_FETCH_FUNCS(kind) \ | ||
| 103 | DEFINE_FETCH_##kind(u8) \ | ||
| 104 | DEFINE_FETCH_##kind(u16) \ | ||
| 105 | DEFINE_FETCH_##kind(u32) \ | ||
| 106 | DEFINE_FETCH_##kind(u64) | ||
| 107 | |||
| 108 | #define CHECK_BASIC_FETCH_FUNCS(kind, fn) \ | ||
| 109 | ((FETCH_FUNC_NAME(kind, u8) == fn) || \ | ||
| 110 | (FETCH_FUNC_NAME(kind, u16) == fn) || \ | ||
| 111 | (FETCH_FUNC_NAME(kind, u32) == fn) || \ | ||
| 112 | (FETCH_FUNC_NAME(kind, u64) == fn)) | ||
| 113 | |||
| 114 | /* Data fetch function templates */ | ||
| 115 | #define DEFINE_FETCH_reg(type) \ | ||
| 116 | static __kprobes void FETCH_FUNC_NAME(reg, type)(struct pt_regs *regs, \ | ||
| 117 | void *offset, void *dest) \ | ||
| 118 | { \ | ||
| 119 | *(type *)dest = (type)regs_get_register(regs, \ | ||
| 120 | (unsigned int)((unsigned long)offset)); \ | ||
| 76 | } | 121 | } |
| 77 | 122 | DEFINE_BASIC_FETCH_FUNCS(reg) | |
| 78 | static __kprobes unsigned long fetch_stack(struct pt_regs *regs, | 123 | |
| 79 | void *num) | 124 | #define DEFINE_FETCH_stack(type) \ |
| 80 | { | 125 | static __kprobes void FETCH_FUNC_NAME(stack, type)(struct pt_regs *regs,\ |
| 81 | return regs_get_kernel_stack_nth(regs, | 126 | void *offset, void *dest) \ |
| 82 | (unsigned int)((unsigned long)num)); | 127 | { \ |
| 128 | *(type *)dest = (type)regs_get_kernel_stack_nth(regs, \ | ||
| 129 | (unsigned int)((unsigned long)offset)); \ | ||
| 83 | } | 130 | } |
| 131 | DEFINE_BASIC_FETCH_FUNCS(stack) | ||
| 84 | 132 | ||
| 85 | static __kprobes unsigned long fetch_memory(struct pt_regs *regs, void *addr) | 133 | #define DEFINE_FETCH_retval(type) \ |
| 86 | { | 134 | static __kprobes void FETCH_FUNC_NAME(retval, type)(struct pt_regs *regs,\ |
| 87 | unsigned long retval; | 135 | void *dummy, void *dest) \ |
| 88 | 136 | { \ | |
| 89 | if (probe_kernel_address(addr, retval)) | 137 | *(type *)dest = (type)regs_return_value(regs); \ |
| 90 | return 0; | ||
| 91 | return retval; | ||
| 92 | } | 138 | } |
| 93 | 139 | DEFINE_BASIC_FETCH_FUNCS(retval) | |
| 94 | static __kprobes unsigned long fetch_retvalue(struct pt_regs *regs, | 140 | |
| 95 | void *dummy) | 141 | #define DEFINE_FETCH_memory(type) \ |
| 96 | { | 142 | static __kprobes void FETCH_FUNC_NAME(memory, type)(struct pt_regs *regs,\ |
| 97 | return regs_return_value(regs); | 143 | void *addr, void *dest) \ |
| 98 | } | 144 | <|
