diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2013-11-26 00:19:59 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2014-01-02 16:17:38 -0500 |
commit | b26c74e116ad8433da22a72f03d148f88aab36e5 (patch) | |
tree | 0271078555494bacaf7ae15e82f68352e47b541a /kernel/trace | |
parent | 5bf652aaf46ca6ae477ea0d162e68d577cf244aa (diff) |
tracing/probes: Move fetch function helpers to trace_probe.h
Move fetch function helper macros/functions to the header file and
make them external. This is preparation of supporting uprobe fetch
table in next patch.
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: zhangwei(Jovi) <jovi.zhangwei@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'kernel/trace')
-rw-r--r-- | kernel/trace/trace_probe.c | 74 | ||||
-rw-r--r-- | kernel/trace/trace_probe.h | 65 |
2 files changed, 78 insertions, 61 deletions
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index d8347b01ce89..c26bc9eaa2ac 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c | |||
@@ -35,19 +35,15 @@ const char *reserved_field_names[] = { | |||
35 | FIELD_STRING_FUNC, | 35 | FIELD_STRING_FUNC, |
36 | }; | 36 | }; |
37 | 37 | ||
38 | /* Printing function type */ | ||
39 | #define PRINT_TYPE_FUNC_NAME(type) print_type_##type | ||
40 | #define PRINT_TYPE_FMT_NAME(type) print_type_format_##type | ||
41 | |||
42 | /* Printing in basic type function template */ | 38 | /* Printing in basic type function template */ |
43 | #define DEFINE_BASIC_PRINT_TYPE_FUNC(type, fmt) \ | 39 | #define DEFINE_BASIC_PRINT_TYPE_FUNC(type, fmt) \ |
44 | static __kprobes int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, \ | 40 | __kprobes int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, \ |
45 | const char *name, \ | 41 | const char *name, \ |
46 | void *data, void *ent) \ | 42 | void *data, void *ent) \ |
47 | { \ | 43 | { \ |
48 | return trace_seq_printf(s, " %s=" fmt, name, *(type *)data); \ | 44 | return trace_seq_printf(s, " %s=" fmt, name, *(type *)data); \ |
49 | } \ | 45 | } \ |
50 | static const char PRINT_TYPE_FMT_NAME(type)[] = fmt; | 46 | const char PRINT_TYPE_FMT_NAME(type)[] = fmt; |
51 | 47 | ||
52 | DEFINE_BASIC_PRINT_TYPE_FUNC(u8 , "0x%x") | 48 | DEFINE_BASIC_PRINT_TYPE_FUNC(u8 , "0x%x") |
53 | DEFINE_BASIC_PRINT_TYPE_FUNC(u16, "0x%x") | 49 | DEFINE_BASIC_PRINT_TYPE_FUNC(u16, "0x%x") |
@@ -58,23 +54,12 @@ DEFINE_BASIC_PRINT_TYPE_FUNC(s16, "%d") | |||
58 | DEFINE_BASIC_PRINT_TYPE_FUNC(s32, "%d") | 54 | DEFINE_BASIC_PRINT_TYPE_FUNC(s32, "%d") |
59 | DEFINE_BASIC_PRINT_TYPE_FUNC(s64, "%Ld") | 55 | DEFINE_BASIC_PRINT_TYPE_FUNC(s64, "%Ld") |
60 | 56 | ||
61 | static inline void *get_rloc_data(u32 *dl) | ||
62 | { | ||
63 | return (u8 *)dl + get_rloc_offs(*dl); | ||
64 | } | ||
65 | |||
66 | /* For data_loc conversion */ | ||
67 | static inline void *get_loc_data(u32 *dl, void *ent) | ||
68 | { | ||
69 | return (u8 *)ent + get_rloc_offs(*dl); | ||
70 | } | ||
71 | |||
72 | /* For defining macros, define string/string_size types */ | 57 | /* For defining macros, define string/string_size types */ |
73 | typedef u32 string; | 58 | typedef u32 string; |
74 | typedef u32 string_size; | 59 | typedef u32 string_size; |
75 | 60 | ||
76 | /* Print type function for string type */ | 61 | /* Print type function for string type */ |
77 | static __kprobes int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, | 62 | __kprobes int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, |
78 | const char *name, | 63 | const char *name, |
79 | void *data, void *ent) | 64 | void *data, void *ent) |
80 | { | 65 | { |
@@ -87,7 +72,7 @@ static __kprobes int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, | |||
87 | (const char *)get_loc_data(data, ent)); | 72 | (const char *)get_loc_data(data, ent)); |
88 | } | 73 | } |
89 | 74 | ||
90 | static const char PRINT_TYPE_FMT_NAME(string)[] = "\\\"%s\\\""; | 75 | const char PRINT_TYPE_FMT_NAME(string)[] = "\\\"%s\\\""; |
91 | 76 | ||
92 | #define FETCH_FUNC_NAME(method, type) fetch_##method##_##type | 77 | #define FETCH_FUNC_NAME(method, type) fetch_##method##_##type |
93 | /* | 78 | /* |
@@ -111,7 +96,7 @@ DEFINE_FETCH_##method(u64) | |||
111 | 96 | ||
112 | /* Data fetch function templates */ | 97 | /* Data fetch function templates */ |
113 | #define DEFINE_FETCH_reg(type) \ | 98 | #define DEFINE_FETCH_reg(type) \ |
114 | static __kprobes void FETCH_FUNC_NAME(reg, type)(struct pt_regs *regs, \ | 99 | __kprobes void FETCH_FUNC_NAME(reg, type)(struct pt_regs *regs, \ |
115 | void *offset, void *dest) \ | 100 | void *offset, void *dest) \ |
116 | { \ | 101 | { \ |
117 | *(type *)dest = (type)regs_get_register(regs, \ | 102 | *(type *)dest = (type)regs_get_register(regs, \ |
@@ -123,7 +108,7 @@ DEFINE_BASIC_FETCH_FUNCS(reg) | |||
123 | #define fetch_reg_string_size NULL | 108 | #define fetch_reg_string_size NULL |
124 | 109 | ||
125 | #define DEFINE_FETCH_stack(type) \ | 110 | #define DEFINE_FETCH_stack(type) \ |
126 | static __kprobes void FETCH_FUNC_NAME(stack, type)(struct pt_regs *regs,\ | 111 | __kprobes void FETCH_FUNC_NAME(stack, type)(struct pt_regs *regs, \ |
127 | void *offset, void *dest) \ | 112 | void *offset, void *dest) \ |
128 | { \ | 113 | { \ |
129 | *(type *)dest = (type)regs_get_kernel_stack_nth(regs, \ | 114 | *(type *)dest = (type)regs_get_kernel_stack_nth(regs, \ |
@@ -135,7 +120,7 @@ DEFINE_BASIC_FETCH_FUNCS(stack) | |||
135 | #define fetch_stack_string_size NULL | 120 | #define fetch_stack_string_size NULL |
136 | 121 | ||
137 | #define DEFINE_FETCH_retval(type) \ | 122 | #define DEFINE_FETCH_retval(type) \ |
138 | static __kprobes void FETCH_FUNC_NAME(retval, type)(struct pt_regs *regs,\ | 123 | __kprobes void FETCH_FUNC_NAME(retval, type)(struct pt_regs *regs, \ |
139 | void *dummy, void *dest) \ | 124 | void *dummy, void *dest) \ |
140 | { \ | 125 | { \ |
141 | *(type *)dest = (type)regs_return_value(regs); \ | 126 | *(type *)dest = (type)regs_return_value(regs); \ |
@@ -146,7 +131,7 @@ DEFINE_BASIC_FETCH_FUNCS(retval) | |||
146 | #define fetch_retval_string_size NULL | 131 | #define fetch_retval_string_size NULL |
147 | 132 | ||
148 | #define DEFINE_FETCH_memory(type) \ | 133 | #define DEFINE_FETCH_memory(type) \ |
149 | static __kprobes void FETCH_FUNC_NAME(memory, type)(struct pt_regs *regs,\ | 134 | __kprobes void FETCH_FUNC_NAME(memory, type)(struct pt_regs *regs, \ |
150 | void *addr, void *dest) \ | 135 | void *addr, void *dest) \ |
151 | { \ | 136 | { \ |
152 | type retval; \ | 137 | type retval; \ |
@@ -160,7 +145,7 @@ DEFINE_BASIC_FETCH_FUNCS(memory) | |||
160 | * Fetch a null-terminated string. Caller MUST set *(u32 *)dest with max | 145 | * Fetch a null-terminated string. Caller MUST set *(u32 *)dest with max |
161 | * length and relative data location. | 146 | * length and relative data location. |
162 | */ | 147 | */ |
163 | static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs, | 148 | __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs, |
164 | void *addr, void *dest) | 149 | void *addr, void *dest) |
165 | { | 150 | { |
166 | long ret; | 151 | long ret; |
@@ -197,7 +182,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs, | |||
197 | } | 182 | } |
198 | 183 | ||
199 | /* Return the length of string -- including null terminal byte */ | 184 | /* Return the length of string -- including null terminal byte */ |
200 | static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs, | 185 | __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs, |
201 | void *addr, void *dest) | 186 | void *addr, void *dest) |
202 | { | 187 | { |
203 | mm_segment_t old_fs; | 188 | mm_segment_t old_fs; |
@@ -268,7 +253,7 @@ static struct symbol_cache *alloc_symbol_cache(const char *sym, long offset) | |||
268 | } | 253 | } |
269 | 254 | ||
270 | #define DEFINE_FETCH_symbol(type) \ | 255 | #define DEFINE_FETCH_symbol(type) \ |
271 | static __kprobes void FETCH_FUNC_NAME(symbol, type)(struct pt_regs *regs,\ | 256 | __kprobes void FETCH_FUNC_NAME(symbol, type)(struct pt_regs *regs, \ |
272 | void *data, void *dest) \ | 257 | void *data, void *dest) \ |
273 | { \ | 258 | { \ |
274 | struct symbol_cache *sc = data; \ | 259 | struct symbol_cache *sc = data; \ |
@@ -288,7 +273,7 @@ struct deref_fetch_param { | |||
288 | }; | 273 | }; |
289 | 274 | ||
290 | #define DEFINE_FETCH_deref(type) \ | 275 | #define DEFINE_FETCH_deref(type) \ |
291 | static __kprobes void FETCH_FUNC_NAME(deref, type)(struct pt_regs *regs,\ | 276 | __kprobes void FETCH_FUNC_NAME(deref, type)(struct pt_regs *regs, \ |
292 | void *data, void *dest) \ | 277 | void *data, void *dest) \ |
293 | { \ | 278 | { \ |
294 | struct deref_fetch_param *dprm = data; \ | 279 | struct deref_fetch_param *dprm = data; \ |
@@ -329,7 +314,7 @@ struct bitfield_fetch_param { | |||
329 | }; | 314 | }; |
330 | 315 | ||
331 | #define DEFINE_FETCH_bitfield(type) \ | 316 | #define DEFINE_FETCH_bitfield(type) \ |
332 | static __kprobes void FETCH_FUNC_NAME(bitfield, type)(struct pt_regs *regs,\ | 317 | __kprobes void FETCH_FUNC_NAME(bitfield, type)(struct pt_regs *regs, \ |
333 | void *data, void *dest) \ | 318 | void *data, void *dest) \ |
334 | { \ | 319 | { \ |
335 | struct bitfield_fetch_param *bprm = data; \ | 320 | struct bitfield_fetch_param *bprm = data; \ |
@@ -374,39 +359,6 @@ free_bitfield_fetch_param(struct bitfield_fetch_param *data) | |||
374 | kfree(data); | 359 | kfree(data); |
375 | } | 360 | } |
376 | 361 | ||
377 | /* Default (unsigned long) fetch type */ | ||
378 | #define __DEFAULT_FETCH_TYPE(t) u##t | ||
379 | #define _DEFAULT_FETCH_TYPE(t) __DEFAULT_FETCH_TYPE(t) | ||
380 | #define DEFAULT_FETCH_TYPE _DEFAULT_FETCH_TYPE(BITS_PER_LONG) | ||
381 | #define DEFAULT_FETCH_TYPE_STR __stringify(DEFAULT_FETCH_TYPE) | ||
382 | |||
383 | #define ASSIGN_FETCH_FUNC(method, type) \ | ||
384 | [FETCH_MTD_##method] = FETCH_FUNC_NAME(method, type) | ||
385 | |||
386 | #define __ASSIGN_FETCH_TYPE(_name, ptype, ftype, _size, sign, _fmttype) \ | ||
387 | {.name = _name, \ | ||
388 | .size = _size, \ | ||
389 | .is_signed = sign, \ | ||
390 | .print = PRINT_TYPE_FUNC_NAME(ptype), \ | ||
391 | .fmt = PRINT_TYPE_FMT_NAME(ptype), \ | ||
392 | .fmttype = _fmttype, \ | ||
393 | .fetch = { \ | ||
394 | ASSIGN_FETCH_FUNC(reg, ftype), \ | ||
395 | ASSIGN_FETCH_FUNC(stack, ftype), \ | ||
396 | ASSIGN_FETCH_FUNC(retval, ftype), \ | ||
397 | ASSIGN_FETCH_FUNC(memory, ftype), \ | ||
398 | ASSIGN_FETCH_FUNC(symbol, ftype), \ | ||
399 | ASSIGN_FETCH_FUNC(deref, ftype), \ | ||
400 | ASSIGN_FETCH_FUNC(bitfield, ftype), \ | ||
401 | } \ | ||
402 | } | ||
403 | |||
404 | #define ASSIGN_FETCH_TYPE(ptype, ftype, sign) \ | ||
405 | __ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, #ptype) | ||
406 | |||
407 | #define FETCH_TYPE_STRING 0 | ||
408 | #define FETCH_TYPE_STRSIZE 1 | ||
409 | |||
410 | /* Fetch type information table */ | 362 | /* Fetch type information table */ |
411 | static const struct fetch_type fetch_type_table[] = { | 363 | static const struct fetch_type fetch_type_table[] = { |
412 | /* Special types */ | 364 | /* Special types */ |
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index 2c979cb66367..bd621c08b6c6 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h | |||
@@ -81,6 +81,17 @@ | |||
81 | */ | 81 | */ |
82 | #define convert_rloc_to_loc(dl, offs) ((u32)(dl) + (offs)) | 82 | #define convert_rloc_to_loc(dl, offs) ((u32)(dl) + (offs)) |
83 | 83 | ||
84 | static inline void *get_rloc_data(u32 *dl) | ||
85 | { | ||
86 | return (u8 *)dl + get_rloc_offs(*dl); | ||
87 | } | ||
88 | |||
89 | /* For data_loc conversion */ | ||
90 | static inline void *get_loc_data(u32 *dl, void *ent) | ||
91 | { | ||
92 | return (u8 *)ent + get_rloc_offs(*dl); | ||
93 | } | ||
94 | |||
84 | /* Data fetch function type */ | 95 | /* Data fetch function type */ |
85 | typedef void (*fetch_func_t)(struct pt_regs *, void *, void *); | 96 | typedef void (*fetch_func_t)(struct pt_regs *, void *, void *); |
86 | /* Printing function type */ | 97 | /* Printing function type */ |
@@ -115,6 +126,60 @@ struct fetch_param { | |||
115 | void *data; | 126 | void *data; |
116 | }; | 127 | }; |
117 | 128 | ||
129 | #define PRINT_TYPE_FUNC_NAME(type) print_type_##type | ||
130 | #define PRINT_TYPE_FMT_NAME(type) print_type_format_##type | ||
131 | |||
132 | /* Printing in basic type function template */ | ||
133 | #define DECLARE_BASIC_PRINT_TYPE_FUNC(type) \ | ||
134 | __kprobes int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, \ | ||
135 | const char *name, \ | ||
136 | void *data, void *ent); \ | ||
137 | extern const char PRINT_TYPE_FMT_NAME(type)[] | ||
138 | |||
139 | DECLARE_BASIC_PRINT_TYPE_FUNC(u8); | ||
140 | DECLARE_BASIC_PRINT_TYPE_FUNC(u16); | ||
141 | DECLARE_BASIC_PRINT_TYPE_FUNC(u32); | ||
142 | DECLARE_BASIC_PRINT_TYPE_FUNC(u64); | ||
143 | DECLARE_BASIC_PRINT_TYPE_FUNC(s8); | ||
144 | DECLARE_BASIC_PRINT_TYPE_FUNC(s16); | ||
145 | DECLARE_BASIC_PRINT_TYPE_FUNC(s32); | ||
146 | DECLARE_BASIC_PRINT_TYPE_FUNC(s64); | ||
147 | DECLARE_BASIC_PRINT_TYPE_FUNC(string); | ||
148 | |||
149 | /* Default (unsigned long) fetch type */ | ||
150 | #define __DEFAULT_FETCH_TYPE(t) u##t | ||
151 | #define _DEFAULT_FETCH_TYPE(t) __DEFAULT_FETCH_TYPE(t) | ||
152 | #define DEFAULT_FETCH_TYPE _DEFAULT_FETCH_TYPE(BITS_PER_LONG) | ||
153 | #define DEFAULT_FETCH_TYPE_STR __stringify(DEFAULT_FETCH_TYPE) | ||
154 | |||
155 | #define ASSIGN_FETCH_FUNC(method, type) \ | ||
156 | [FETCH_MTD_##method] = FETCH_FUNC_NAME(method, type) | ||
157 | |||
158 | #define __ASSIGN_FETCH_TYPE(_name, ptype, ftype, _size, sign, _fmttype) \ | ||
159 | {.name = _name, \ | ||
160 | .size = _size, \ | ||
161 | .is_signed = sign, \ | ||
162 | .print = PRINT_TYPE_FUNC_NAME(ptype), \ | ||
163 | .fmt = PRINT_TYPE_FMT_NAME(ptype), \ | ||
164 | .fmttype = _fmttype, \ | ||
165 | .fetch = { \ | ||
166 | ASSIGN_FETCH_FUNC(reg, ftype), \ | ||
167 | ASSIGN_FETCH_FUNC(stack, ftype), \ | ||
168 | ASSIGN_FETCH_FUNC(retval, ftype), \ | ||
169 | ASSIGN_FETCH_FUNC(memory, ftype), \ | ||
170 | ASSIGN_FETCH_FUNC(symbol, ftype), \ | ||
171 | ASSIGN_FETCH_FUNC(deref, ftype), \ | ||
172 | ASSIGN_FETCH_FUNC(bitfield, ftype), \ | ||
173 | } \ | ||
174 | } | ||
175 | |||
176 | #define ASSIGN_FETCH_TYPE(ptype, ftype, sign) \ | ||
177 | __ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, #ptype) | ||
178 | |||
179 | #define FETCH_TYPE_STRING 0 | ||
180 | #define FETCH_TYPE_STRSIZE 1 | ||
181 | |||
182 | |||
118 | struct probe_arg { | 183 | struct probe_arg { |
119 | struct fetch_param fetch; | 184 | struct fetch_param fetch; |
120 | struct fetch_param fetch_size; | 185 | struct fetch_param fetch_size; |