diff options
author | Ingo Molnar <mingo@elte.hu> | 2010-07-06 03:00:32 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-07-06 03:00:32 -0400 |
commit | 8bd0e1be25c43a9fbd33a8de06449088879d527a (patch) | |
tree | 8f24493dfd45df467faa69e2ecef67b8321932ef | |
parent | 39ef13a4ac28aa64cfe1bc36e6e00f1096707a28 (diff) | |
parent | b7dcb857cc3eb89136111fefe89780129c1af1d7 (diff) |
Merge branch 'perf/core' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux-2.6 into perf/core
-rw-r--r-- | Documentation/trace/kprobetrace.txt | 2 | ||||
-rw-r--r-- | kernel/trace/trace_kprobe.c | 370 | ||||
-rw-r--r-- | tools/perf/Documentation/perf-probe.txt | 4 | ||||
-rw-r--r-- | tools/perf/Makefile | 48 | ||||
-rw-r--r-- | tools/perf/util/probe-event.c | 71 | ||||
-rw-r--r-- | tools/perf/util/probe-event.h | 1 | ||||
-rw-r--r-- | tools/perf/util/probe-finder.c | 192 |
7 files changed, 523 insertions, 165 deletions
diff --git a/Documentation/trace/kprobetrace.txt b/Documentation/trace/kprobetrace.txt index ec94748ae65b..5f77d94598dd 100644 --- a/Documentation/trace/kprobetrace.txt +++ b/Documentation/trace/kprobetrace.txt | |||
@@ -42,7 +42,7 @@ Synopsis of kprobe_events | |||
42 | +|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**) | 42 | +|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**) |
43 | NAME=FETCHARG : Set NAME as the argument name of FETCHARG. | 43 | NAME=FETCHARG : Set NAME as the argument name of FETCHARG. |
44 | FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types | 44 | FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types |
45 | (u8/u16/u32/u64/s8/s16/s32/s64) are supported. | 45 | (u8/u16/u32/u64/s8/s16/s32/s64) and string are supported. |
46 | 46 | ||
47 | (*) only for return probe. | 47 | (*) only for return probe. |
48 | (**) this is useful for fetching a field of data structures. | 48 | (**) this is useful for fetching a field of data structures. |
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 3b831d8e201e..1b79d1c15726 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c | |||
@@ -30,6 +30,8 @@ | |||
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> | 32 | #include <linux/stringify.h> |
33 | #include <linux/limits.h> | ||
34 | #include <linux/uaccess.h> | ||
33 | #include <asm/bitsperlong.h> | 35 | #include <asm/bitsperlong.h> |
34 | 36 | ||
35 | #include "trace.h" | 37 | #include "trace.h" |
@@ -38,6 +40,7 @@ | |||
38 | #define MAX_TRACE_ARGS 128 | 40 | #define MAX_TRACE_ARGS 128 |
39 | #define MAX_ARGSTR_LEN 63 | 41 | #define MAX_ARGSTR_LEN 63 |
40 | #define MAX_EVENT_NAME_LEN 64 | 42 | #define MAX_EVENT_NAME_LEN 64 |
43 | #define MAX_STRING_SIZE PATH_MAX | ||
41 | #define KPROBE_EVENT_SYSTEM "kprobes" | 44 | #define KPROBE_EVENT_SYSTEM "kprobes" |
42 | 45 | ||
43 | /* Reserved field names */ | 46 | /* Reserved field names */ |
@@ -58,14 +61,16 @@ const char *reserved_field_names[] = { | |||
58 | }; | 61 | }; |
59 | 62 | ||
60 | /* Printing function type */ | 63 | /* Printing function type */ |
61 | typedef int (*print_type_func_t)(struct trace_seq *, const char *, void *); | 64 | typedef int (*print_type_func_t)(struct trace_seq *, const char *, void *, |
65 | void *); | ||
62 | #define PRINT_TYPE_FUNC_NAME(type) print_type_##type | 66 | #define PRINT_TYPE_FUNC_NAME(type) print_type_##type |
63 | #define PRINT_TYPE_FMT_NAME(type) print_type_format_##type | 67 | #define PRINT_TYPE_FMT_NAME(type) print_type_format_##type |
64 | 68 | ||
65 | /* Printing in basic type function template */ | 69 | /* Printing in basic type function template */ |
66 | #define DEFINE_BASIC_PRINT_TYPE_FUNC(type, fmt, cast) \ | 70 | #define DEFINE_BASIC_PRINT_TYPE_FUNC(type, fmt, cast) \ |
67 | static __kprobes int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, \ | 71 | static __kprobes int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, \ |
68 | const char *name, void *data)\ | 72 | const char *name, \ |
73 | void *data, void *ent)\ | ||
69 | { \ | 74 | { \ |
70 | return trace_seq_printf(s, " %s=" fmt, name, (cast)*(type *)data);\ | 75 | return trace_seq_printf(s, " %s=" fmt, name, (cast)*(type *)data);\ |
71 | } \ | 76 | } \ |
@@ -80,6 +85,49 @@ DEFINE_BASIC_PRINT_TYPE_FUNC(s16, "%d", int) | |||
80 | DEFINE_BASIC_PRINT_TYPE_FUNC(s32, "%ld", long) | 85 | DEFINE_BASIC_PRINT_TYPE_FUNC(s32, "%ld", long) |
81 | DEFINE_BASIC_PRINT_TYPE_FUNC(s64, "%lld", long long) | 86 | DEFINE_BASIC_PRINT_TYPE_FUNC(s64, "%lld", long long) |
82 | 87 | ||
88 | /* data_rloc: data relative location, compatible with u32 */ | ||
89 | #define make_data_rloc(len, roffs) \ | ||
90 | (((u32)(len) << 16) | ((u32)(roffs) & 0xffff)) | ||
91 | #define get_rloc_len(dl) ((u32)(dl) >> 16) | ||
92 | #define get_rloc_offs(dl) ((u32)(dl) & 0xffff) | ||
93 | |||
94 | static inline void *get_rloc_data(u32 *dl) | ||
95 | { | ||
96 | return (u8 *)dl + get_rloc_offs(*dl); | ||
97 | } | ||
98 | |||
99 | /* For data_loc conversion */ | ||
100 | static inline void *get_loc_data(u32 *dl, void *ent) | ||
101 | { | ||
102 | return (u8 *)ent + get_rloc_offs(*dl); | ||
103 | } | ||
104 | |||
105 | /* | ||
106 | * Convert data_rloc to data_loc: | ||
107 | * data_rloc stores the offset from data_rloc itself, but data_loc | ||
108 | * stores the offset from event entry. | ||
109 | */ | ||
110 | #define convert_rloc_to_loc(dl, offs) ((u32)(dl) + (offs)) | ||
111 | |||
112 | /* For defining macros, define string/string_size types */ | ||
113 | typedef u32 string; | ||
114 | typedef u32 string_size; | ||
115 | |||
116 | /* Print type function for string type */ | ||
117 | static __kprobes int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, | ||
118 | const char *name, | ||
119 | void *data, void *ent) | ||
120 | { | ||
121 | int len = *(u32 *)data >> 16; | ||
122 | |||
123 | if (!len) | ||
124 | return trace_seq_printf(s, " %s=(fault)", name); | ||
125 | else | ||
126 | return trace_seq_printf(s, " %s=\"%s\"", name, | ||
127 | (const char *)get_loc_data(data, ent)); | ||
128 | } | ||
129 | static const char PRINT_TYPE_FMT_NAME(string)[] = "\\\"%s\\\""; | ||
130 | |||
83 | /* Data fetch function type */ | 131 | /* Data fetch function type */ |
84 | typedef void (*fetch_func_t)(struct pt_regs *, void *, void *); | 132 | typedef void (*fetch_func_t)(struct pt_regs *, void *, void *); |
85 | 133 | ||
@@ -94,32 +142,38 @@ static __kprobes void call_fetch(struct fetch_param *fprm, | |||
94 | return fprm->fn(regs, fprm->data, dest); | 142 | return fprm->fn(regs, fprm->data, dest); |
95 | } | 143 | } |
96 | 144 | ||
97 | #define FETCH_FUNC_NAME(kind, type) fetch_##kind##_##type | 145 | #define FETCH_FUNC_NAME(method, type) fetch_##method##_##type |
98 | /* | 146 | /* |
99 | * Define macro for basic types - we don't need to define s* types, because | 147 | * Define macro for basic types - we don't need to define s* types, because |
100 | * we have to care only about bitwidth at recording time. | 148 | * we have to care only about bitwidth at recording time. |
101 | */ | 149 | */ |
102 | #define DEFINE_BASIC_FETCH_FUNCS(kind) \ | 150 | #define DEFINE_BASIC_FETCH_FUNCS(method) \ |
103 | DEFINE_FETCH_##kind(u8) \ | 151 | DEFINE_FETCH_##method(u8) \ |
104 | DEFINE_FETCH_##kind(u16) \ | 152 | DEFINE_FETCH_##method(u16) \ |
105 | DEFINE_FETCH_##kind(u32) \ | 153 | DEFINE_FETCH_##method(u32) \ |
106 | DEFINE_FETCH_##kind(u64) | 154 | DEFINE_FETCH_##method(u64) |
107 | 155 | ||
108 | #define CHECK_BASIC_FETCH_FUNCS(kind, fn) \ | 156 | #define CHECK_FETCH_FUNCS(method, fn) \ |
109 | ((FETCH_FUNC_NAME(kind, u8) == fn) || \ | 157 | (((FETCH_FUNC_NAME(method, u8) == fn) || \ |
110 | (FETCH_FUNC_NAME(kind, u16) == fn) || \ | 158 | (FETCH_FUNC_NAME(method, u16) == fn) || \ |
111 | (FETCH_FUNC_NAME(kind, u32) == fn) || \ | 159 | (FETCH_FUNC_NAME(method, u32) == fn) || \ |
112 | (FETCH_FUNC_NAME(kind, u64) == fn)) | 160 | (FETCH_FUNC_NAME(method, u64) == fn) || \ |
161 | (FETCH_FUNC_NAME(method, string) == fn) || \ | ||
162 | (FETCH_FUNC_NAME(method, string_size) == fn)) \ | ||
163 | && (fn != NULL)) | ||
113 | 164 | ||
114 | /* Data fetch function templates */ | 165 | /* Data fetch function templates */ |
115 | #define DEFINE_FETCH_reg(type) \ | 166 | #define DEFINE_FETCH_reg(type) \ |
116 | static __kprobes void FETCH_FUNC_NAME(reg, type)(struct pt_regs *regs, \ | 167 | static __kprobes void FETCH_FUNC_NAME(reg, type)(struct pt_regs *regs, \ |
117 | void *offset, void *dest) \ | 168 | void *offset, void *dest) \ |
118 | { \ | 169 | { \ |
119 | *(type *)dest = (type)regs_get_register(regs, \ | 170 | *(type *)dest = (type)regs_get_register(regs, \ |
120 | (unsigned int)((unsigned long)offset)); \ | 171 | (unsigned int)((unsigned long)offset)); \ |
121 | } | 172 | } |
122 | DEFINE_BASIC_FETCH_FUNCS(reg) | 173 | DEFINE_BASIC_FETCH_FUNCS(reg) |
174 | /* No string on the register */ | ||
175 | #define fetch_reg_string NULL | ||
176 | #define fetch_reg_string_size NULL | ||
123 | 177 | ||
124 | #define DEFINE_FETCH_stack(type) \ | 178 | #define DEFINE_FETCH_stack(type) \ |
125 | static __kprobes void FETCH_FUNC_NAME(stack, type)(struct pt_regs *regs,\ | 179 | static __kprobes void FETCH_FUNC_NAME(stack, type)(struct pt_regs *regs,\ |
@@ -129,6 +183,9 @@ static __kprobes void FETCH_FUNC_NAME(stack, type)(struct pt_regs *regs,\ | |||
129 | (unsigned int)((unsigned long)offset)); \ | 183 | (unsigned int)((unsigned long)offset)); \ |
130 | } | 184 | } |
131 | DEFINE_BASIC_FETCH_FUNCS(stack) | 185 | DEFINE_BASIC_FETCH_FUNCS(stack) |
186 | /* No string on the stack entry */ | ||
187 | #define fetch_stack_string NULL | ||
188 | #define fetch_stack_string_size NULL | ||
132 | 189 | ||
133 | #define DEFINE_FETCH_retval(type) \ | 190 | #define DEFINE_FETCH_retval(type) \ |
134 | static __kprobes void FETCH_FUNC_NAME(retval, type)(struct pt_regs *regs,\ | 191 | static __kprobes void FETCH_FUNC_NAME(retval, type)(struct pt_regs *regs,\ |
@@ -137,6 +194,9 @@ static __kprobes void FETCH_FUNC_NAME(retval, type)(struct pt_regs *regs,\ | |||
137 | *(type *)dest = (type)regs_return_value(regs); \ | 194 | *(type *)dest = (type)regs_return_value(regs); \ |
138 | } | 195 | } |
139 | DEFINE_BASIC_FETCH_FUNCS(retval) | 196 | DEFINE_BASIC_FETCH_FUNCS(retval) |
197 | /* No string on the retval */ | ||
198 | #define fetch_retval_string NULL | ||
199 | #define fetch_retval_string_size NULL | ||
140 | 200 | ||
141 | #define DEFINE_FETCH_memory(type) \ | 201 | #define DEFINE_FETCH_memory(type) \ |
142 | static __kprobes void FETCH_FUNC_NAME(memory, type)(struct pt_regs *regs,\ | 202 | static __kprobes void FETCH_FUNC_NAME(memory, type)(struct pt_regs *regs,\ |
@@ -149,6 +209,62 @@ static __kprobes void FETCH_FUNC_NAME(memory, type)(struct pt_regs *regs,\ | |||
149 | *(type *)dest = retval; \ | 209 | *(type *)dest = retval; \ |
150 | } | 210 | } |
151 | DEFINE_BASIC_FETCH_FUNCS(memory) | 211 | DEFINE_BASIC_FETCH_FUNCS(memory) |
212 | /* | ||
213 | * Fetch a null-terminated string. Caller MUST set *(u32 *)dest with max | ||
214 | * length and relative data location. | ||
215 | */ | ||
216 | static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs, | ||
217 | void *addr, void *dest) | ||
218 | { | ||
219 | long ret; | ||
220 | int maxlen = get_rloc_len(*(u32 *)dest); | ||
221 | u8 *dst = get_rloc_data(dest); | ||
222 | u8 *src = addr; | ||
223 | mm_segment_t old_fs = get_fs(); | ||
224 | if (!maxlen) | ||
225 | return; | ||
226 | /* | ||
227 | * Try to get string again, since the string can be changed while | ||
228 | * probing. | ||
229 | */ | ||
230 | set_fs(KERNEL_DS); | ||
231 | pagefault_disable(); | ||
232 | do | ||
233 | ret = __copy_from_user_inatomic(dst++, src++, 1); | ||
234 | while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen); | ||
235 | dst[-1] = '\0'; | ||
236 | pagefault_enable(); | ||
237 | set_fs(old_fs); | ||
238 | |||
239 | if (ret < 0) { /* Failed to fetch string */ | ||
240 | ((u8 *)get_rloc_data(dest))[0] = '\0'; | ||
241 | *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest)); | ||
242 | } else | ||
243 | *(u32 *)dest = make_data_rloc(src - (u8 *)addr, | ||
244 | get_rloc_offs(*(u32 *)dest)); | ||
245 | } | ||
246 | /* Return the length of string -- including null terminal byte */ | ||
247 | static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs, | ||
248 | void *addr, void *dest) | ||
249 | { | ||
250 | int ret, len = 0; | ||
251 | u8 c; | ||
252 | mm_segment_t old_fs = get_fs(); | ||
253 | |||
254 | set_fs(KERNEL_DS); | ||
255 | pagefault_disable(); | ||
256 | do { | ||
257 | ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1); | ||
258 | len++; | ||
259 | } while (c && ret == 0 && len < MAX_STRING_SIZE); | ||
260 | pagefault_enable(); | ||
261 | set_fs(old_fs); | ||
262 | |||
263 | if (ret < 0) /* Failed to check the length */ | ||
264 | *(u32 *)dest = 0; | ||
265 | else | ||
266 | *(u32 *)dest = len; | ||
267 | } | ||
152 | 268 | ||
153 | /* Memory fetching by symbol */ | 269 | /* Memory fetching by symbol */ |
154 | struct symbol_cache { | 270 | struct symbol_cache { |
@@ -203,6 +319,8 @@ static __kprobes void FETCH_FUNC_NAME(symbol, type)(struct pt_regs *regs,\ | |||
203 | *(type *)dest = 0; \ | 319 | *(type *)dest = 0; \ |
204 | } | 320 | } |
205 | DEFINE_BASIC_FETCH_FUNCS(symbol) | 321 | DEFINE_BASIC_FETCH_FUNCS(symbol) |
322 | DEFINE_FETCH_symbol(string) | ||
323 | DEFINE_FETCH_symbol(string_size) | ||
206 | 324 | ||
207 | /* Dereference memory access function */ | 325 | /* Dereference memory access function */ |
208 | struct deref_fetch_param { | 326 | struct deref_fetch_param { |
@@ -224,12 +342,14 @@ static __kprobes void FETCH_FUNC_NAME(deref, type)(struct pt_regs *regs,\ | |||
224 | *(type *)dest = 0; \ | 342 | *(type *)dest = 0; \ |
225 | } | 343 | } |
226 | DEFINE_BASIC_FETCH_FUNCS(deref) | 344 | DEFINE_BASIC_FETCH_FUNCS(deref) |
345 | DEFINE_FETCH_deref(string) | ||
346 | DEFINE_FETCH_deref(string_size) | ||
227 | 347 | ||
228 | static __kprobes void free_deref_fetch_param(struct deref_fetch_param *data) | 348 | static __kprobes void free_deref_fetch_param(struct deref_fetch_param *data) |
229 | { | 349 | { |
230 | if (CHECK_BASIC_FETCH_FUNCS(deref, data->orig.fn)) | 350 | if (CHECK_FETCH_FUNCS(deref, data->orig.fn)) |
231 | free_deref_fetch_param(data->orig.data); | 351 | free_deref_fetch_param(data->orig.data); |
232 | else if (CHECK_BASIC_FETCH_FUNCS(symbol, data->orig.fn)) | 352 | else if (CHECK_FETCH_FUNCS(symbol, data->orig.fn)) |
233 | free_symbol_cache(data->orig.data); | 353 | free_symbol_cache(data->orig.data); |
234 | kfree(data); | 354 | kfree(data); |
235 | } | 355 | } |
@@ -240,23 +360,43 @@ static __kprobes void free_deref_fetch_param(struct deref_fetch_param *data) | |||
240 | #define DEFAULT_FETCH_TYPE _DEFAULT_FETCH_TYPE(BITS_PER_LONG) | 360 | #define DEFAULT_FETCH_TYPE _DEFAULT_FETCH_TYPE(BITS_PER_LONG) |
241 | #define DEFAULT_FETCH_TYPE_STR __stringify(DEFAULT_FETCH_TYPE) | 361 | #define DEFAULT_FETCH_TYPE_STR __stringify(DEFAULT_FETCH_TYPE) |
242 | 362 | ||
243 | #define ASSIGN_FETCH_FUNC(kind, type) \ | 363 | /* Fetch types */ |
244 | .kind = FETCH_FUNC_NAME(kind, type) | 364 | enum { |
245 | 365 | FETCH_MTD_reg = 0, | |
246 | #define ASSIGN_FETCH_TYPE(ptype, ftype, sign) \ | 366 | FETCH_MTD_stack, |
247 | {.name = #ptype, \ | 367 | FETCH_MTD_retval, |
248 | .size = sizeof(ftype), \ | 368 | FETCH_MTD_memory, |
249 | .is_signed = sign, \ | 369 | FETCH_MTD_symbol, |
250 | .print = PRINT_TYPE_FUNC_NAME(ptype), \ | 370 | FETCH_MTD_deref, |
251 | .fmt = PRINT_TYPE_FMT_NAME(ptype), \ | 371 | FETCH_MTD_END, |
252 | ASSIGN_FETCH_FUNC(reg, ftype), \ | 372 | }; |
253 | ASSIGN_FETCH_FUNC(stack, ftype), \ | 373 | |
254 | ASSIGN_FETCH_FUNC(retval, ftype), \ | 374 | #define ASSIGN_FETCH_FUNC(method, type) \ |
255 | ASSIGN_FETCH_FUNC(memory, ftype), \ | 375 | [FETCH_MTD_##method] = FETCH_FUNC_NAME(method, type) |
256 | ASSIGN_FETCH_FUNC(symbol, ftype), \ | 376 | |
257 | ASSIGN_FETCH_FUNC(deref, ftype), \ | 377 | #define __ASSIGN_FETCH_TYPE(_name, ptype, ftype, _size, sign, _fmttype) \ |
378 | {.name = _name, \ | ||
379 | .size = _size, \ | ||
380 | .is_signed = sign, \ | ||
381 | .print = PRINT_TYPE_FUNC_NAME(ptype), \ | ||
382 | .fmt = PRINT_TYPE_FMT_NAME(ptype), \ | ||
383 | .fmttype = _fmttype, \ | ||
384 | .fetch = { \ | ||
385 | ASSIGN_FETCH_FUNC(reg, ftype), \ | ||
386 | ASSIGN_FETCH_FUNC(stack, ftype), \ | ||
387 | ASSIGN_FETCH_FUNC(retval, ftype), \ | ||
388 | ASSIGN_FETCH_FUNC(memory, ftype), \ | ||
389 | ASSIGN_FETCH_FUNC(symbol, ftype), \ | ||
390 | ASSIGN_FETCH_FUNC(deref, ftype), \ | ||
391 | } \ | ||
258 | } | 392 | } |
259 | 393 | ||
394 | #define ASSIGN_FETCH_TYPE(ptype, ftype, sign) \ | ||
395 | __ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, #ptype) | ||
396 | |||
397 | #define FETCH_TYPE_STRING 0 | ||
398 | #define FETCH_TYPE_STRSIZE 1 | ||
399 | |||
260 | /* Fetch type information table */ | 400 | /* Fetch type information table */ |
261 | static const struct fetch_type { | 401 | static const struct fetch_type { |
262 | const char *name; /* Name of type */ | 402 | const char *name; /* Name of type */ |
@@ -264,14 +404,16 @@ static const struct fetch_type { | |||
264 | int is_signed; /* Signed flag */ | 404 | int is_signed; /* Signed flag */ |
265 | print_type_func_t print; /* Print functions */ | 405 | print_type_func_t print; /* Print functions */ |
266 | const char *fmt; /* Fromat string */ | 406 | const char *fmt; /* Fromat string */ |
407 | const char *fmttype; /* Name in format file */ | ||
267 | /* Fetch functions */ | 408 | /* Fetch functions */ |
268 | fetch_func_t reg; | 409 | fetch_func_t fetch[FETCH_MTD_END]; |
269 | fetch_func_t stack; | ||
270 | fetch_func_t retval; | ||
271 | fetch_func_t memory; | ||
272 | fetch_func_t symbol; | ||
273 | fetch_func_t deref; | ||
274 | } fetch_type_table[] = { | 410 | } fetch_type_table[] = { |
411 | /* Special types */ | ||
412 | [FETCH_TYPE_STRING] = __ASSIGN_FETCH_TYPE("string", string, string, | ||
413 | sizeof(u32), 1, "__data_loc char[]"), | ||
414 | [FETCH_TYPE_STRSIZE] = __ASSIGN_FETCH_TYPE("string_size", u32, | ||
415 | string_size, sizeof(u32), 0, "u32"), | ||
416 | /* Basic types */ | ||
275 | ASSIGN_FETCH_TYPE(u8, u8, 0), | 417 | ASSIGN_FETCH_TYPE(u8, u8, 0), |
276 | ASSIGN_FETCH_TYPE(u16, u16, 0), | 418 | ASSIGN_FETCH_TYPE(u16, u16, 0), |
277 | ASSIGN_FETCH_TYPE(u32, u32, 0), | 419 | ASSIGN_FETCH_TYPE(u32, u32, 0), |
@@ -302,12 +444,28 @@ static __kprobes void fetch_stack_address(struct pt_regs *regs, | |||
302 | *(unsigned long *)dest = kernel_stack_pointer(regs); | 444 | *(unsigned long *)dest = kernel_stack_pointer(regs); |
303 | } | 445 | } |
304 | 446 | ||
447 | static fetch_func_t get_fetch_size_function(const struct fetch_type *type, | ||
448 | fetch_func_t orig_fn) | ||
449 | { | ||
450 | int i; | ||
451 | |||
452 | if (type != &fetch_type_table[FETCH_TYPE_STRING]) | ||
453 | return NULL; /* Only string type needs size function */ | ||
454 | for (i = 0; i < FETCH_MTD_END; i++) | ||
455 | if (type->fetch[i] == orig_fn) | ||
456 | return fetch_type_table[FETCH_TYPE_STRSIZE].fetch[i]; | ||
457 | |||
458 | WARN_ON(1); /* This should not happen */ | ||
459 | return NULL; | ||
460 | } | ||
461 | |||
305 | /** | 462 | /** |
306 | * Kprobe event core functions | 463 | * Kprobe event core functions |
307 | */ | 464 | */ |
308 | 465 | ||
309 | struct probe_arg { | 466 | struct probe_arg { |
310 | struct fetch_param fetch; | 467 | struct fetch_param fetch; |
468 | struct fetch_param fetch_size; | ||
311 | unsigned int offset; /* Offset from argument entry */ | 469 | unsigned int offset; /* Offset from argument entry */ |
312 | const char *name; /* Name of this argument */ | 470 | const char *name; /* Name of this argument */ |
313 | const char *comm; /* Command of this argument */ | 471 | const char *comm; /* Command of this argument */ |
@@ -429,9 +587,9 @@ error: | |||
429 | 587 | ||
430 | static void free_probe_arg(struct probe_arg *arg) | 588 | static void free_probe_arg(struct probe_arg *arg) |
431 | { | 589 | { |
432 | if (CHECK_BASIC_FETCH_FUNCS(deref, arg->fetch.fn)) | 590 | if (CHECK_FETCH_FUNCS(deref, arg->fetch.fn)) |
433 | free_deref_fetch_param(arg->fetch.data); | 591 | free_deref_fetch_param(arg->fetch.data); |
434 | else if (CHECK_BASIC_FETCH_FUNCS(symbol, arg->fetch.fn)) | 592 | else if (CHECK_FETCH_FUNCS(symbol, arg->fetch.fn)) |
435 | free_symbol_cache(arg->fetch.data); | 593 | free_symbol_cache(arg->fetch.data); |
436 | kfree(arg->name); | 594 | kfree(arg->name); |
437 | kfree(arg->comm); | 595 | kfree(arg->comm); |
@@ -548,7 +706,7 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t, | |||
548 | 706 | ||
549 | if (strcmp(arg, "retval") == 0) { | 707 | if (strcmp(arg, "retval") == 0) { |
550 | if (is_return) | 708 | if (is_return) |
551 | f->fn = t->retval; | 709 | f->fn = t->fetch[FETCH_MTD_retval]; |
552 | else | 710 | else |
553 | ret = -EINVAL; | 711 | ret = -EINVAL; |
554 | } else if (strncmp(arg, "stack", 5) == 0) { | 712 | } else if (strncmp(arg, "stack", 5) == 0) { |
@@ -562,7 +720,7 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t, | |||
562 | if (ret || param > PARAM_MAX_STACK) | 720 | if (ret || param > PARAM_MAX_STACK) |
563 | ret = -EINVAL; | 721 | ret = -EINVAL; |
564 | else { | 722 | else { |
565 | f->fn = t->stack; | 723 | f->fn = t->fetch[FETCH_MTD_stack]; |
566 | f->data = (void *)param; | 724 | f->data = (void *)param; |
567 | } | 725 | } |
568 | } else | 726 | } else |
@@ -588,7 +746,7 @@ static int __parse_probe_arg(char *arg, const struct fetch_type *t, | |||
588 | case '%': /* named register */ | 746 | case '%': /* named register */ |
589 | ret = regs_query_register_offset(arg + 1); | 747 | ret = regs_query_register_offset(arg + 1); |
590 | if (ret >= 0) { | 748 | if (ret >= 0) { |
591 | f->fn = t->reg; | 749 | f->fn = t->fetch[FETCH_MTD_reg]; |
592 | f->data = (void *)(unsigned long)ret; | 750 | f->data = (void *)(unsigned long)ret; |
593 | ret = 0; | 751 | ret = 0; |
594 | } | 752 | } |
@@ -598,7 +756,7 @@ static int __parse_probe_arg(char *arg, const struct fetch_type *t, | |||
598 | ret = strict_strtoul(arg + 1, 0, ¶m); | 756 | ret = strict_strtoul(arg + 1, 0, ¶m); |
599 | if (ret) | 757 | if (ret) |
600 | break; | 758 | break; |
601 | f->fn = t->memory; | 759 | f->fn = t->fetch[FETCH_MTD_memory]; |
602 | f->data = (void *)param; | 760 | f->data = (void *)param; |
603 | } else { | 761 | } else { |
604 | ret = split_symbol_offset(arg + 1, &offset); | 762 | ret = split_symbol_offset(arg + 1, &offset); |
@@ -606,7 +764,7 @@ static int __parse_probe_arg(char *arg, const struct fetch_type *t, | |||
606 | break; | 764 | break; |
607 | f->data = alloc_symbol_cache(arg + 1, offset); | 765 | f->data = alloc_symbol_cache(arg + 1, offset); |
608 | if (f->data) | 766 | if (f->data) |
609 | f->fn = t->symbol; | 767 | f->fn = t->fetch[FETCH_MTD_symbol]; |
610 | } | 768 | } |
611 | break; | 769 | break; |
612 | case '+': /* deref memory */ | 770 | case '+': /* deref memory */ |
@@ -636,14 +794,17 @@ static int __parse_probe_arg(char *arg, const struct fetch_type *t, | |||
636 | if (ret) | 794 | if (ret) |
637 | kfree(dprm); | 795 | kfree(dprm); |
638 | else { | 796 | else { |
639 | f->fn = t->deref; | 797 | f->fn = t->fetch[FETCH_MTD_deref]; |
640 | f->data = (void *)dprm; | 798 | f->data = (void *)dprm; |
641 | } | 799 | } |
642 | } | 800 | } |
643 | break; | 801 | break; |
644 | } | 802 | } |
645 | if (!ret && !f->fn) | 803 | if (!ret && !f->fn) { /* Parsed, but do not find fetch method */ |
804 | pr_info("%s type has no corresponding fetch method.\n", | ||
805 | t->name); | ||
646 | ret = -EINVAL; | 806 | ret = -EINVAL; |
807 | } | ||
647 | return ret; | 808 | return ret; |
648 | } | 809 | } |
649 | 810 | ||
@@ -652,6 +813,7 @@ static int parse_probe_arg(char *arg, struct trace_probe *tp, | |||
652 | struct probe_arg *parg, int is_return) | 813 | struct probe_arg *parg, int is_return) |
653 | { | 814 | { |
654 | const char *t; | 815 | const char *t; |
816 | int ret; | ||
655 | 817 | ||
656 | if (strlen(arg) > MAX_ARGSTR_LEN) { | 818 | if (strlen(arg) > MAX_ARGSTR_LEN) { |
657 | pr_info("Argument is too long.: %s\n", arg); | 819 | pr_info("Argument is too long.: %s\n", arg); |
@@ -674,7 +836,13 @@ static int parse_probe_arg(char *arg, struct trace_probe *tp, | |||
674 | } | 836 | } |
675 | parg->offset = tp->size; | 837 | parg->offset = tp->size; |
676 | tp->size += parg->type->size; | 838 | tp->size += parg->type->size; |
677 | return __parse_probe_arg(arg, parg->type, &parg->fetch, is_return); | 839 | ret = __parse_probe_arg(arg, parg->type, &parg->fetch, is_return); |
840 | if (ret >= 0) { | ||
841 | parg->fetch_size.fn = get_fetch_size_function(parg->type, | ||
842 | parg->fetch.fn); | ||
843 | parg->fetch_size.data = parg->fetch.data; | ||
844 | } | ||
845 | return ret; | ||
678 | } | 846 | } |
679 | 847 | ||
680 | /* Return 1 if name is reserved or already used by another argument */ | 848 | /* Return 1 if name is reserved or already used by another argument */ |
@@ -1043,6 +1211,54 @@ static const struct file_operations kprobe_profile_ops = { | |||
1043 | .release = seq_release, | 1211 | .release = seq_release, |
1044 | }; | 1212 | }; |
1045 | 1213 | ||
1214 | /* Sum up total data length for dynamic arraies (strings) */ | ||
1215 | static __kprobes int __get_data_size(struct trace_probe *tp, | ||
1216 | struct pt_regs *regs) | ||
1217 | { | ||
1218 | int i, ret = 0; | ||
1219 | u32 len; | ||
1220 | |||
1221 | for (i = 0; i < tp->nr_args; i++) | ||
1222 | if (unlikely(tp->args[i].fetch_size.fn)) { | ||
1223 | call_fetch(&tp->args[i].fetch_size, regs, &len); | ||
1224 | ret += len; | ||
1225 | } | ||
1226 | |||
1227 | return ret; | ||
1228 | } | ||
1229 | |||
1230 | /* Store the value of each argument */ | ||
1231 | static __kprobes void store_trace_args(int ent_size, struct trace_probe *tp, | ||
1232 | struct pt_regs *regs, | ||
1233 | u8 *data, int maxlen) | ||
1234 | { | ||
1235 | int i; | ||
1236 | u32 end = tp->size; | ||
1237 | u32 *dl; /* Data (relative) location */ | ||
1238 | |||
1239 | for (i = 0; i < tp->nr_args; i++) { | ||
1240 | if (unlikely(tp->args[i].fetch_size.fn)) { | ||
1241 | /* | ||
1242 | * First, we set the relative location and | ||
1243 | * maximum data length to *dl | ||
1244 | */ | ||
1245 | dl = (u32 *)(data + tp->args[i].offset); | ||
1246 | *dl = make_data_rloc(maxlen, end - tp->args[i].offset); | ||
1247 | /* Then try to fetch string or dynamic array data */ | ||
1248 | call_fetch(&tp->args[i].fetch, regs, dl); | ||
1249 | /* Reduce maximum length */ | ||
1250 | end += get_rloc_len(*dl); | ||
1251 | maxlen -= get_rloc_len(*dl); | ||
1252 | /* Trick here, convert data_rloc to data_loc */ | ||
1253 | *dl = convert_rloc_to_loc(*dl, | ||
1254 | ent_size + tp->args[i].offset); | ||
1255 | } else | ||
1256 | /* Just fetching data normally */ | ||
1257 | call_fetch(&tp->args[i].fetch, regs, | ||
1258 | data + tp->args[i].offset); | ||
1259 | } | ||
1260 | } | ||
1261 | |||
1046 | /* Kprobe handler */ | 1262 | /* Kprobe handler */ |
1047 | static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs) | 1263 | static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs) |
1048 | { | 1264 | { |
@@ -1050,8 +1266,7 @@ static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs) | |||
1050 | struct kprobe_trace_entry_head *entry; | 1266 | struct kprobe_trace_entry_head *entry; |
1051 | struct ring_buffer_event *event; | 1267 | struct ring_buffer_event *event; |
1052 | struct ring_buffer *buffer; | 1268 | struct ring_buffer *buffer; |
1053 | u8 *data; | 1269 | int size, dsize, pc; |
1054 | int size, i, pc; | ||
1055 | unsigned long irq_flags; | 1270 | unsigned long irq_flags; |
1056 | struct ftrace_event_call *call = &tp->call; | 1271 | struct ftrace_event_call *call = &tp->call; |
1057 | 1272 | ||
@@ -1060,7 +1275,8 @@ static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs) | |||
1060 | local_save_flags(irq_flags); | 1275 | local_save_flags(irq_flags); |
1061 | pc = preempt_count(); | 1276 | pc = preempt_count(); |
1062 | 1277 | ||
1063 | size = sizeof(*entry) + tp->size; | 1278 | dsize = __get_data_size(tp, regs); |
1279 | size = sizeof(*entry) + tp->size + dsize; | ||
1064 | 1280 | ||
1065 | event = trace_current_buffer_lock_reserve(&buffer, call->event.type, | 1281 | event = trace_current_buffer_lock_reserve(&buffer, call->event.type, |
1066 | size, irq_flags, pc); | 1282 | size, irq_flags, pc); |
@@ -1069,9 +1285,7 @@ static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs) | |||
1069 | 1285 | ||
1070 | entry = ring_buffer_event_data(event); | 1286 | entry = ring_buffer_event_data(event); |
1071 | entry->ip = (unsigned long)kp->addr; | 1287 | entry->ip = (unsigned long)kp->addr; |
1072 | data = (u8 *)&entry[1]; | 1288 | store_trace_args(sizeof(*entry), tp, regs, (u8 *)&entry[1], dsize); |
1073 | for (i = 0; i < tp->nr_args; i++) | ||
1074 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); | ||
1075 | 1289 | ||
1076 | if (!filter_current_check_discard(buffer, call, entry, event)) | 1290 | if (!filter_current_check_discard(buffer, call, entry, event)) |
1077 | trace_nowake_buffer_unlock_commit(buffer, event, irq_flags, pc); | 1291 | trace_nowake_buffer_unlock_commit(buffer, event, irq_flags, pc); |
@@ -1085,15 +1299,15 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri, | |||
1085 | struct kretprobe_trace_entry_head *entry; | 1299 | struct kretprobe_trace_entry_head *entry; |
1086 | struct ring_buffer_event *event; | 1300 | struct ring_buffer_event *event; |
1087 | struct ring_buffer *buffer; | 1301 | struct ring_buffer *buffer; |
1088 | u8 *data; | 1302 | int size, pc, dsize; |
1089 | int size, i, pc; | ||
1090 | unsigned long irq_flags; | 1303 | unsigned long irq_flags; |
1091 | struct ftrace_event_call *call = &tp->call; | 1304 | struct ftrace_event_call *call = &tp->call; |
1092 | 1305 | ||
1093 | local_save_flags(irq_flags); | 1306 | local_save_flags(irq_flags); |
1094 | pc = preempt_count(); | 1307 | pc = preempt_count(); |
1095 | 1308 | ||
1096 | size = sizeof(*entry) + tp->size; | 1309 | dsize = __get_data_size(tp, regs); |
1310 | size = sizeof(*entry) + tp->size + dsize; | ||
1097 | 1311 | ||
1098 | event = trace_current_buffer_lock_reserve(&buffer, call->event.type, | 1312 | event = trace_current_buffer_lock_reserve(&buffer, call->event.type, |
1099 | size, irq_flags, pc); | 1313 | size, irq_flags, pc); |
@@ -1103,9 +1317,7 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri, | |||
1103 | entry = ring_buffer_event_data(event); | 1317 | entry = ring_buffer_event_data(event); |
1104 | entry->func = (unsigned long)tp->rp.kp.addr; | 1318 | entry->func = (unsigned long)tp->rp.kp.addr; |
1105 | entry->ret_ip = (unsigned long)ri->ret_addr; | 1319 | entry->ret_ip = (unsigned long)ri->ret_addr; |
1106 | data = (u8 *)&entry[1]; | 1320 | store_trace_args(sizeof(*entry), tp, regs, (u8 *)&entry[1], dsize); |
1107 | for (i = 0; i < tp->nr_args; i++) | ||
1108 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); | ||
1109 | 1321 | ||
1110 | if (!filter_current_check_discard(buffer, call, entry, event)) | 1322 | if (!filter_current_check_discard(buffer, call, entry, event)) |
1111 | trace_nowake_buffer_unlock_commit(buffer, event, irq_flags, pc); | 1323 | trace_nowake_buffer_unlock_commit(buffer, event, irq_flags, pc); |
@@ -1137,7 +1349,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags, | |||
1137 | data = (u8 *)&field[1]; | 1349 | data = (u8 *)&field[1]; |
1138 | for (i = 0; i < tp->nr_args; i++) | 1350 | for (i = 0; i < tp->nr_args; i++) |
1139 | if (!tp->args[i].type->print(s, tp->args[i].name, | 1351 | if (!tp->args[i].type->print(s, tp->args[i].name, |
1140 | data + tp->args[i].offset)) | 1352 | data + tp->args[i].offset, field)) |
1141 | goto partial; | 1353 | goto partial; |
1142 | 1354 | ||
1143 | if (!trace_seq_puts(s, "\n")) | 1355 | if (!trace_seq_puts(s, "\n")) |
@@ -1179,7 +1391,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags, | |||
1179 | data = (u8 *)&field[1]; | 1391 | data = (u8 *)&field[1]; |
1180 | for (i = 0; i < tp->nr_args; i++) | 1392 | for (i = 0; i < tp->nr_args; i++) |
1181 | if (!tp->args[i].type->print(s, tp->args[i].name, | 1393 | if (!tp->args[i].type->print(s, tp->args[i].name, |
1182 | data + tp->args[i].offset)) | 1394 | data + tp->args[i].offset, field)) |
1183 | goto partial; | 1395 | goto partial; |
1184 | 1396 | ||
1185 | if (!trace_seq_puts(s, "\n")) | 1397 | if (!trace_seq_puts(s, "\n")) |
@@ -1234,7 +1446,7 @@ static int kprobe_event_define_fields(struct ftrace_event_call *event_call) | |||
1234 | DEFINE_FIELD(unsigned long, ip, FIELD_STRING_IP, 0); | 1446 | DEFINE_FIELD(unsigned long, ip, FIELD_STRING_IP, 0); |
1235 | /* Set argument names as fields */ | 1447 | /* Set argument names as fields */ |
1236 | for (i = 0; i < tp->nr_args; i++) { | 1448 | for (i = 0; i < tp->nr_args; i++) { |
1237 | ret = trace_define_field(event_call, tp->args[i].type->name, | 1449 | ret = trace_define_field(event_call, tp->args[i].type->fmttype, |
1238 | tp->args[i].name, | 1450 | tp->args[i].name, |
1239 | sizeof(field) + tp->args[i].offset, | 1451 | sizeof(field) + tp->args[i].offset, |
1240 | tp->args[i].type->size, | 1452 | tp->args[i].type->size, |
@@ -1256,7 +1468,7 @@ static int kretprobe_event_define_fields(struct ftrace_event_call *event_call) | |||
1256 | DEFINE_FIELD(unsigned long, ret_ip, FIELD_STRING_RETIP, 0); | 1468 | DEFINE_FIELD(unsigned long, ret_ip, FIELD_STRING_RETIP, 0); |
1257 | /* Set argument names as fields */ | 1469 | /* Set argument names as fields */ |
1258 | for (i = 0; i < tp->nr_args; i++) { | 1470 | for (i = 0; i < tp->nr_args; i++) { |
1259 | ret = trace_define_field(event_call, tp->args[i].type->name, | 1471 | ret = trace_define_field(event_call, tp->args[i].type->fmttype, |
1260 | tp->args[i].name, | 1472 | tp->args[i].name, |
1261 | sizeof(field) + tp->args[i].offset, | 1473 | sizeof(field) + tp->args[i].offset, |
1262 | tp->args[i].type->size, | 1474 | tp->args[i].type->size, |
@@ -1296,8 +1508,13 @@ static int __set_print_fmt(struct trace_probe *tp, char *buf, int len) | |||
1296 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg); | 1508 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg); |
1297 | 1509 | ||
1298 | for (i = 0; i < tp->nr_args; i++) { | 1510 | for (i = 0; i < tp->nr_args; i++) { |
1299 | pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s", | 1511 | if (strcmp(tp->args[i].type->name, "string") == 0) |
1300 | tp->args[i].name); | 1512 | pos += snprintf(buf + pos, LEN_OR_ZERO, |
1513 | ", __get_str(%s)", | ||
1514 | tp->args[i].name); | ||
1515 | else | ||
1516 | pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s", | ||
1517 | tp->args[i].name); | ||
1301 | } | 1518 | } |
1302 | 1519 | ||
1303 | #undef LEN_OR_ZERO | 1520 | #undef LEN_OR_ZERO |
@@ -1334,11 +1551,11 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp, | |||
1334 | struct ftrace_event_call *call = &tp->call; | 1551 | struct ftrace_event_call *call = &tp->call; |
1335 | struct kprobe_trace_entry_head *entry; | 1552 | struct kprobe_trace_entry_head *entry; |
1336 | struct hlist_head *head; | 1553 | struct hlist_head *head; |
1337 | u8 *data; | 1554 | int size, __size, dsize; |
1338 | int size, __size, i; | ||
1339 | int rctx; | 1555 | int rctx; |
1340 | 1556 | ||
1341 | __size = sizeof(*entry) + tp->size; | 1557 | dsize = __get_data_size(tp, regs); |
1558 | __size = sizeof(*entry) + tp->size + dsize; | ||
1342 | size = ALIGN(__size + sizeof(u32), sizeof(u64)); | 1559 | size = ALIGN(__size + sizeof(u32), sizeof(u64)); |
1343 | size -= sizeof(u32); | 1560 | size -= sizeof(u32); |
1344 | if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, | 1561 | if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, |
@@ -1350,9 +1567,8 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp, | |||
1350 | return; | 1567 | return; |
1351 | 1568 | ||
1352 | entry->ip = (unsigned long)kp->addr; | 1569 | entry->ip = (unsigned long)kp->addr; |
1353 | data = (u8 *)&entry[1]; | 1570 | memset(&entry[1], 0, dsize); |
1354 | for (i = 0; i < tp->nr_args; i++) | 1571 | store_trace_args(sizeof(*entry), tp, regs, (u8 *)&entry[1], dsize); |
1355 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); | ||
1356 | 1572 | ||
1357 | head = this_cpu_ptr(call->perf_events); | 1573 | head = this_cpu_ptr(call->perf_events); |
1358 | perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, regs, head); | 1574 | perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, regs, head); |
@@ -1366,11 +1582,11 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, | |||
1366 | struct ftrace_event_call *call = &tp->call; | 1582 | struct ftrace_event_call *call = &tp->call; |
1367 | struct kretprobe_trace_entry_head *entry; | 1583 | struct kretprobe_trace_entry_head *entry; |
1368 | struct hlist_head *head; | 1584 | struct hlist_head *head; |
1369 | u8 *data; | 1585 | int size, __size, dsize; |
1370 | int size, __size, i; | ||
1371 | int rctx; | 1586 | int rctx; |
1372 | 1587 | ||
1373 | __size = sizeof(*entry) + tp->size; | 1588 | dsize = __get_data_size(tp, regs); |
1589 | __size = sizeof(*entry) + tp->size + dsize; | ||
1374 | size = ALIGN(__size + sizeof(u32), sizeof(u64)); | 1590 | size = ALIGN(__size + sizeof(u32), sizeof(u64)); |
1375 | size -= sizeof(u32); | 1591 | size -= sizeof(u32); |
1376 | if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, | 1592 | if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, |
@@ -1383,9 +1599,7 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, | |||
1383 | 1599 | ||
1384 | entry->func = (unsigned long)tp->rp.kp.addr; | 1600 | entry->func = (unsigned long)tp->rp.kp.addr; |
1385 | entry->ret_ip = (unsigned long)ri->ret_addr; | 1601 | entry->ret_ip = (unsigned long)ri->ret_addr; |
1386 | data = (u8 *)&entry[1]; | 1602 | store_trace_args(sizeof(*entry), tp, regs, (u8 *)&entry[1], dsize); |
1387 | for (i = 0; i < tp->nr_args; i++) | ||
1388 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); | ||
1389 | 1603 | ||
1390 | head = this_cpu_ptr(call->perf_events); | 1604 | head = this_cpu_ptr(call->perf_events); |
1391 | perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, regs, head); | 1605 | perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, regs, head); |
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt index ea531d9d975c..27d52dae5a43 100644 --- a/tools/perf/Documentation/perf-probe.txt +++ b/tools/perf/Documentation/perf-probe.txt | |||
@@ -94,8 +94,8 @@ Each probe argument follows below syntax. | |||
94 | 94 | ||
95 | [NAME=]LOCALVAR|$retval|%REG|@SYMBOL[:TYPE] | 95 | [NAME=]LOCALVAR|$retval|%REG|@SYMBOL[:TYPE] |
96 | 96 | ||
97 | 'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.) | 97 | 'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.) |
98 | 'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. | 98 | 'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type. |
99 | 99 | ||
100 | LINE SYNTAX | 100 | LINE SYNTAX |
101 | ----------- | 101 | ----------- |
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 17a3692397c5..26f626d45a9e 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -605,33 +605,35 @@ endif | |||
605 | 605 | ||
606 | ifdef NO_DEMANGLE | 606 | ifdef NO_DEMANGLE |
607 | BASIC_CFLAGS += -DNO_DEMANGLE | 607 | BASIC_CFLAGS += -DNO_DEMANGLE |
608 | else ifdef HAVE_CPLUS_DEMANGLE | ||
609 | EXTLIBS += -liberty | ||
610 | BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE | ||
611 | else | 608 | else |
612 | FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd | 609 | ifdef HAVE_CPLUS_DEMANGLE |
613 | has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD)) | 610 | EXTLIBS += -liberty |
614 | ifeq ($(has_bfd),y) | 611 | BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE |
615 | EXTLIBS += -lbfd | 612 | else |
616 | else | 613 | FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd |
617 | FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty | 614 | has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD)) |
618 | has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY)) | 615 | ifeq ($(has_bfd),y) |
619 | ifeq ($(has_bfd_iberty),y) | 616 | EXTLIBS += -lbfd |
620 | EXTLIBS += -lbfd -liberty | ||
621 | else | 617 | else |
622 | FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz | 618 | FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty |
623 | has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z)) | 619 | has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY)) |
624 | ifeq ($(has_bfd_iberty_z),y) | 620 | ifeq ($(has_bfd_iberty),y) |
625 | EXTLIBS += -lbfd -liberty -lz | 621 | EXTLIBS += -lbfd -liberty |
626 | else | 622 | else |
627 | FLAGS_CPLUS_DEMANGLE=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -liberty | 623 | FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz |
628 | has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE)) | 624 | has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z)) |
629 | ifeq ($(has_cplus_demangle),y) | 625 | ifeq ($(has_bfd_iberty_z),y) |
630 | EXTLIBS += -liberty | 626 | EXTLIBS += -lbfd -liberty -lz |
631 | BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE | ||
632 | else | 627 | else |
633 | msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling) | 628 | FLAGS_CPLUS_DEMANGLE=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -liberty |
634 | BASIC_CFLAGS += -DNO_DEMANGLE | 629 | has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE)) |
630 | ifeq ($(has_cplus_demangle),y) | ||
631 | EXTLIBS += -liberty | ||
632 | BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE | ||
633 | else | ||
634 | msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling) | ||
635 | BASIC_CFLAGS += -DNO_DEMANGLE | ||
636 | endif | ||
635 | endif | 637 | endif |
636 | endif | 638 | endif |
637 | endif | 639 | endif |
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 914c67095d96..09cf5465e10a 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
@@ -557,7 +557,7 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) | |||
557 | /* Parse perf-probe event argument */ | 557 | /* Parse perf-probe event argument */ |
558 | static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) | 558 | static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) |
559 | { | 559 | { |
560 | char *tmp; | 560 | char *tmp, *goodname; |
561 | struct perf_probe_arg_field **fieldp; | 561 | struct perf_probe_arg_field **fieldp; |
562 | 562 | ||
563 | pr_debug("parsing arg: %s into ", str); | 563 | pr_debug("parsing arg: %s into ", str); |
@@ -580,7 +580,7 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) | |||
580 | pr_debug("type:%s ", arg->type); | 580 | pr_debug("type:%s ", arg->type); |
581 | } | 581 | } |
582 | 582 | ||
583 | tmp = strpbrk(str, "-."); | 583 | tmp = strpbrk(str, "-.["); |
584 | if (!is_c_varname(str) || !tmp) { | 584 | if (!is_c_varname(str) || !tmp) { |
585 | /* A variable, register, symbol or special value */ | 585 | /* A variable, register, symbol or special value */ |
586 | arg->var = strdup(str); | 586 | arg->var = strdup(str); |
@@ -590,10 +590,11 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) | |||
590 | return 0; | 590 | return 0; |
591 | } | 591 | } |
592 | 592 | ||
593 | /* Structure fields */ | 593 | /* Structure fields or array element */ |
594 | arg->var = strndup(str, tmp - str); | 594 | arg->var = strndup(str, tmp - str); |
595 | if (arg->var == NULL) | 595 | if (arg->var == NULL) |
596 | return -ENOMEM; | 596 | return -ENOMEM; |
597 | goodname = arg->var; | ||
597 | pr_debug("%s, ", arg->var); | 598 | pr_debug("%s, ", arg->var); |
598 | fieldp = &arg->field; | 599 | fieldp = &arg->field; |
599 | 600 | ||
@@ -601,22 +602,38 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) | |||
601 | *fieldp = zalloc(sizeof(struct perf_probe_arg_field)); | 602 | *fieldp = zalloc(sizeof(struct perf_probe_arg_field)); |
602 | if (*fieldp == NULL) | 603 | if (*fieldp == NULL) |
603 | return -ENOMEM; | 604 | return -ENOMEM; |
604 | if (*tmp == '.') { | 605 | if (*tmp == '[') { /* Array */ |
605 | str = tmp + 1; | 606 | str = tmp; |
606 | (*fieldp)->ref = false; | 607 | (*fieldp)->index = strtol(str + 1, &tmp, 0); |
607 | } else if (tmp[1] == '>') { | ||
608 | str = tmp + 2; | ||
609 | (*fieldp)->ref = true; | 608 | (*fieldp)->ref = true; |
610 | } else { | 609 | if (*tmp != ']' || tmp == str + 1) { |
611 | semantic_error("Argument parse error: %s\n", str); | 610 | semantic_error("Array index must be a" |
612 | return -EINVAL; | 611 | " number.\n"); |
612 | return -EINVAL; | ||
613 | } | ||
614 | tmp++; | ||
615 | if (*tmp == '\0') | ||
616 | tmp = NULL; | ||
617 | } else { /* Structure */ | ||
618 | if (*tmp == '.') { | ||
619 | str = tmp + 1; | ||
620 | (*fieldp)->ref = false; | ||
621 | } else if (tmp[1] == '>') { | ||
622 | str = tmp + 2; | ||
623 | (*fieldp)->ref = true; | ||
624 | } else { | ||
625 | semantic_error("Argument parse error: %s\n", | ||
626 | str); | ||
627 | return -EINVAL; | ||
628 | } | ||
629 | tmp = strpbrk(str, "-.["); | ||
613 | } | 630 | } |
614 | |||
615 | tmp = strpbrk(str, "-."); | ||
616 | if (tmp) { | 631 | if (tmp) { |
617 | (*fieldp)->name = strndup(str, tmp - str); | 632 | (*fieldp)->name = strndup(str, tmp - str); |
618 | if ((*fieldp)->name == NULL) | 633 | if ((*fieldp)->name == NULL) |
619 | return -ENOMEM; | 634 | return -ENOMEM; |
635 | if (*str != '[') | ||
636 | goodname = (*fieldp)->name; | ||
620 | pr_debug("%s(%d), ", (*fieldp)->name, (*fieldp)->ref); | 637 | pr_debug("%s(%d), ", (*fieldp)->name, (*fieldp)->ref); |
621 | fieldp = &(*fieldp)->next; | 638 | fieldp = &(*fieldp)->next; |
622 | } | 639 | } |
@@ -624,11 +641,13 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) | |||
624 | (*fieldp)->name = strdup(str); | 641 | (*fieldp)->name = strdup(str); |
625 | if ((*fieldp)->name == NULL) | 642 | if ((*fieldp)->name == NULL) |
626 | return -ENOMEM; | 643 | return -ENOMEM; |
644 | if (*str != '[') | ||
645 | goodname = (*fieldp)->name; | ||
627 | pr_debug("%s(%d)\n", (*fieldp)->name, (*fieldp)->ref); | 646 | pr_debug("%s(%d)\n", (*fieldp)->name, (*fieldp)->ref); |
628 | 647 | ||
629 | /* If no name is specified, set the last field name */ | 648 | /* If no name is specified, set the last field name (not array index)*/ |
630 | if (!arg->name) { | 649 | if (!arg->name) { |
631 | arg->name = strdup((*fieldp)->name); | 650 | arg->name = strdup(goodname); |
632 | if (arg->name == NULL) | 651 | if (arg->name == NULL) |
633 | return -ENOMEM; | 652 | return -ENOMEM; |
634 | } | 653 | } |
@@ -776,8 +795,11 @@ int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len) | |||
776 | len -= ret; | 795 | len -= ret; |
777 | 796 | ||
778 | while (field) { | 797 | while (field) { |
779 | ret = e_snprintf(tmp, len, "%s%s", field->ref ? "->" : ".", | 798 | if (field->name[0] == '[') |
780 | field->name); | 799 | ret = e_snprintf(tmp, len, "%s", field->name); |
800 | else | ||
801 | ret = e_snprintf(tmp, len, "%s%s", | ||
802 | field->ref ? "->" : ".", field->name); | ||
781 | if (ret <= 0) | 803 | if (ret <= 0) |
782 | goto error; | 804 | goto error; |
783 | tmp += ret; | 805 | tmp += ret; |
@@ -904,6 +926,7 @@ out: | |||
904 | static int synthesize_kprobe_trace_arg(struct kprobe_trace_arg *arg, | 926 | static int synthesize_kprobe_trace_arg(struct kprobe_trace_arg *arg, |
905 | char *buf, size_t buflen) | 927 | char *buf, size_t buflen) |
906 | { | 928 | { |
929 | struct kprobe_trace_arg_ref *ref = arg->ref; | ||
907 | int ret, depth = 0; | 930 | int ret, depth = 0; |
908 | char *tmp = buf; | 931 | char *tmp = buf; |
909 | 932 | ||
@@ -917,16 +940,24 @@ static int synthesize_kprobe_trace_arg(struct kprobe_trace_arg *arg, | |||
917 | buf += ret; | 940 | buf += ret; |
918 | buflen -= ret; | 941 | buflen -= ret; |
919 | 942 | ||
943 | /* Special case: @XXX */ | ||
944 | if (arg->value[0] == '@' && arg->ref) | ||
945 | ref = ref->next; | ||
946 | |||
920 | /* Dereferencing arguments */ | 947 | /* Dereferencing arguments */ |
921 | if (arg->ref) { | 948 | if (ref) { |
922 | depth = __synthesize_kprobe_trace_arg_ref(arg->ref, &buf, | 949 | depth = __synthesize_kprobe_trace_arg_ref(ref, &buf, |
923 | &buflen, 1); | 950 | &buflen, 1); |
924 | if (depth < 0) | 951 | if (depth < 0) |
925 | return depth; | 952 | return depth; |
926 | } | 953 | } |
927 | 954 | ||
928 | /* Print argument value */ | 955 | /* Print argument value */ |
929 | ret = e_snprintf(buf, buflen, "%s", arg->value); | 956 | if (arg->value[0] == '@' && arg->ref) |
957 | ret = e_snprintf(buf, buflen, "%s%+ld", arg->value, | ||
958 | arg->ref->offset); | ||
959 | else | ||
960 | ret = e_snprintf(buf, buflen, "%s", arg->value); | ||
930 | if (ret < 0) | 961 | if (ret < 0) |
931 | return ret; | 962 | return ret; |
932 | buf += ret; | 963 | buf += ret; |
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h index e9db1a214ca4..bc06d3e8bafa 100644 --- a/tools/perf/util/probe-event.h +++ b/tools/perf/util/probe-event.h | |||
@@ -50,6 +50,7 @@ struct perf_probe_point { | |||
50 | struct perf_probe_arg_field { | 50 | struct perf_probe_arg_field { |
51 | struct perf_probe_arg_field *next; /* Next field */ | 51 | struct perf_probe_arg_field *next; /* Next field */ |
52 | char *name; /* Name of the field */ | 52 | char *name; /* Name of the field */ |
53 | long index; /* Array index number */ | ||
53 | bool ref; /* Referencing flag */ | 54 | bool ref; /* Referencing flag */ |
54 | }; | 55 | }; |
55 | 56 | ||
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index baf665383498..3e64e1fa1051 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c | |||
@@ -406,14 +406,50 @@ static Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, | |||
406 | * Probe finder related functions | 406 | * Probe finder related functions |
407 | */ | 407 | */ |
408 | 408 | ||
409 | static struct kprobe_trace_arg_ref *alloc_trace_arg_ref(long offs) | ||
410 | { | ||
411 | struct kprobe_trace_arg_ref *ref; | ||
412 | ref = zalloc(sizeof(struct kprobe_trace_arg_ref)); | ||
413 | if (ref != NULL) | ||
414 | ref->offset = offs; | ||
415 | return ref; | ||
416 | } | ||
417 | |||
409 | /* Show a location */ | 418 | /* Show a location */ |
410 | static int convert_location(Dwarf_Op *op, struct probe_finder *pf) | 419 | static int convert_variable_location(Dwarf_Die *vr_die, struct probe_finder *pf) |
411 | { | 420 | { |
421 | Dwarf_Attribute attr; | ||
422 | Dwarf_Op *op; | ||
423 | size_t nops; | ||
412 | unsigned int regn; | 424 | unsigned int regn; |
413 | Dwarf_Word offs = 0; | 425 | Dwarf_Word offs = 0; |
414 | bool ref = false; | 426 | bool ref = false; |
415 | const char *regs; | 427 | const char *regs; |
416 | struct kprobe_trace_arg *tvar = pf->tvar; | 428 | struct kprobe_trace_arg *tvar = pf->tvar; |
429 | int ret; | ||
430 | |||
431 | /* TODO: handle more than 1 exprs */ | ||
432 | if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL || | ||
433 | dwarf_getlocation_addr(&attr, pf->addr, &op, &nops, 1) <= 0 || | ||
434 | nops == 0) { | ||
435 | /* TODO: Support const_value */ | ||
436 | pr_err("Failed to find the location of %s at this address.\n" | ||
437 | " Perhaps, it has been optimized out.\n", pf->pvar->var); | ||
438 | return -ENOENT; | ||
439 | } | ||
440 | |||
441 | if (op->atom == DW_OP_addr) { | ||
442 | /* Static variables on memory (not stack), make @varname */ | ||
443 | ret = strlen(dwarf_diename(vr_die)); | ||
444 | tvar->value = zalloc(ret + 2); | ||
445 | if (tvar->value == NULL) | ||
446 | return -ENOMEM; | ||
447 | snprintf(tvar->value, ret + 2, "@%s", dwarf_diename(vr_die)); | ||
448 | tvar->ref = alloc_trace_arg_ref((long)offs); | ||
449 | if (tvar->ref == NULL) | ||
450 | return -ENOMEM; | ||
451 | return 0; | ||
452 | } | ||
417 | 453 | ||
418 | /* If this is based on frame buffer, set the offset */ | 454 | /* If this is based on frame buffer, set the offset */ |
419 | if (op->atom == DW_OP_fbreg) { | 455 | if (op->atom == DW_OP_fbreg) { |
@@ -455,27 +491,72 @@ static int convert_location(Dwarf_Op *op, struct probe_finder *pf) | |||
455 | return -ENOMEM; | 491 | return -ENOMEM; |
456 | 492 | ||
457 | if (ref) { | 493 | if (ref) { |
458 | tvar->ref = zalloc(sizeof(struct kprobe_trace_arg_ref)); | 494 | tvar->ref = alloc_trace_arg_ref((long)offs); |
459 | if (tvar->ref == NULL) | 495 | if (tvar->ref == NULL) |
460 | return -ENOMEM; | 496 | return -ENOMEM; |
461 | tvar->ref->offset = (long)offs; | ||
462 | } | 497 | } |
463 | return 0; | 498 | return 0; |
464 | } | 499 | } |
465 | 500 | ||
466 | static int convert_variable_type(Dwarf_Die *vr_die, | 501 | static int convert_variable_type(Dwarf_Die *vr_die, |
467 | struct kprobe_trace_arg *targ) | 502 | struct kprobe_trace_arg *tvar, |
503 | const char *cast) | ||
468 | { | 504 | { |
505 | struct kprobe_trace_arg_ref **ref_ptr = &tvar->ref; | ||
469 | Dwarf_Die type; | 506 | Dwarf_Die type; |
470 | char buf[16]; | 507 | char buf[16]; |
471 | int ret; | 508 | int ret; |
472 | 509 | ||
510 | /* TODO: check all types */ | ||
511 | if (cast && strcmp(cast, "string") != 0) { | ||
512 | /* Non string type is OK */ | ||
513 | tvar->type = strdup(cast); | ||
514 | return (tvar->type == NULL) ? -ENOMEM : 0; | ||
515 | } | ||
516 | |||
473 | if (die_get_real_type(vr_die, &type) == NULL) { | 517 | if (die_get_real_type(vr_die, &type) == NULL) { |
474 | pr_warning("Failed to get a type information of %s.\n", | 518 | pr_warning("Failed to get a type information of %s.\n", |
475 | dwarf_diename(vr_die)); | 519 | dwarf_diename(vr_die)); |
476 | return -ENOENT; | 520 | return -ENOENT; |
477 | } | 521 | } |
478 | 522 | ||
523 | pr_debug("%s type is %s.\n", | ||
524 | dwarf_diename(vr_die), dwarf_diename(&type)); | ||
525 | |||
526 | if (cast && strcmp(cast, "string") == 0) { /* String type */ | ||
527 | ret = dwarf_tag(&type); | ||
528 | if (ret != DW_TAG_pointer_type && | ||
529 | ret != DW_TAG_array_type) { | ||
530 | pr_warning("Failed to cast into string: " | ||
531 | "%s(%s) is not a pointer nor array.", | ||
532 | dwarf_diename(vr_die), dwarf_diename(&type)); | ||
533 | return -EINVAL; | ||
534 | } | ||
535 | if (ret == DW_TAG_pointer_type) { | ||
536 | if (die_get_real_type(&type, &type) == NULL) { | ||
537 | pr_warning("Failed to get a type information."); | ||
538 | return -ENOENT; | ||
539 | } | ||
540 | while (*ref_ptr) | ||
541 | ref_ptr = &(*ref_ptr)->next; | ||
542 | /* Add new reference with offset +0 */ | ||
543 | *ref_ptr = zalloc(sizeof(struct kprobe_trace_arg_ref)); | ||
544 | if (*ref_ptr == NULL) { | ||
545 | pr_warning("Out of memory error\n"); | ||
546 | return -ENOMEM; | ||
547 | } | ||
548 | } | ||
549 | if (die_compare_name(&type, "char") != 0 && | ||
550 | die_compare_name(&type, "unsigned char") != 0) { | ||
551 | pr_warning("Failed to cast into string: " | ||
552 | "%s is not (unsigned) char *.", | ||
553 | dwarf_diename(vr_die)); | ||
554 | return -EINVAL; | ||
555 | } | ||
556 | tvar->type = strdup(cast); | ||
557 | return (tvar->type == NULL) ? -ENOMEM : 0; | ||
558 | } | ||
559 | |||
479 | ret = die_get_byte_size(&type) * 8; | 560 | ret = die_get_byte_size(&type) * 8; |
480 | if (ret) { | 561 | if (ret) { |
481 | /* Check the bitwidth */ | 562 | /* Check the bitwidth */ |
@@ -495,8 +576,8 @@ static int convert_variable_type(Dwarf_Die *vr_die, | |||
495 | strerror(-ret)); | 576 | strerror(-ret)); |
496 | return ret; | 577 | return ret; |
497 | } | 578 | } |
498 | targ->type = strdup(buf); | 579 | tvar->type = strdup(buf); |
499 | if (targ->type == NULL) | 580 | if (tvar->type == NULL) |
500 | return -ENOMEM; | 581 | return -ENOMEM; |
501 | } | 582 | } |
502 | return 0; | 583 | return 0; |
@@ -510,16 +591,44 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname, | |||
510 | struct kprobe_trace_arg_ref *ref = *ref_ptr; | 591 | struct kprobe_trace_arg_ref *ref = *ref_ptr; |
511 | Dwarf_Die type; | 592 | Dwarf_Die type; |
512 | Dwarf_Word offs; | 593 | Dwarf_Word offs; |
513 | int ret; | 594 | int ret, tag; |
514 | 595 | ||
515 | pr_debug("converting %s in %s\n", field->name, varname); | 596 | pr_debug("converting %s in %s\n", field->name, varname); |
516 | if (die_get_real_type(vr_die, &type) == NULL) { | 597 | if (die_get_real_type(vr_die, &type) == NULL) { |
517 | pr_warning("Failed to get the type of %s.\n", varname); | 598 | pr_warning("Failed to get the type of %s.\n", varname); |
518 | return -ENOENT; | 599 | return -ENOENT; |
519 | } | 600 | } |
520 | 601 | pr_debug2("Var real type: (%x)\n", (unsigned)dwarf_dieoffset(&type)); | |
521 | /* Check the pointer and dereference */ | 602 | tag = dwarf_tag(&type); |
522 | if (dwarf_tag(&type) == DW_TAG_pointer_type) { | 603 | |
604 | if (field->name[0] == '[' && | ||
605 | (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type)) { | ||
606 | if (field->next) | ||
607 | /* Save original type for next field */ | ||
608 | memcpy(die_mem, &type, sizeof(*die_mem)); | ||
609 | /* Get the type of this array */ | ||
610 | if (die_get_real_type(&type, &type) == NULL) { | ||
611 | pr_warning("Failed to get the type of %s.\n", varname); | ||
612 | return -ENOENT; | ||
613 | } | ||
614 | pr_debug2("Array real type: (%x)\n", | ||
615 | (unsigned)dwarf_dieoffset(&type)); | ||
616 | if (tag == DW_TAG_pointer_type) { | ||
617 | ref = zalloc(sizeof(struct kprobe_trace_arg_ref)); | ||
618 | if (ref == NULL) | ||
619 | return -ENOMEM; | ||
620 | if (*ref_ptr) | ||
621 | (*ref_ptr)->next = ref; | ||
622 | else | ||
623 | *ref_ptr = ref; | ||
624 | } | ||
625 | ref->offset += die_get_byte_size(&type) * field->index; | ||
626 | if (!field->next) | ||
627 | /* Save vr_die for converting types */ | ||
628 | memcpy(die_mem, vr_die, sizeof(*die_mem)); | ||
629 | goto next; | ||
630 | } else if (tag == DW_TAG_pointer_type) { | ||
631 | /* Check the pointer and dereference */ | ||
523 | if (!field->ref) { | 632 | if (!field->ref) { |
524 | pr_err("Semantic error: %s must be referred by '->'\n", | 633 | pr_err("Semantic error: %s must be referred by '->'\n", |
525 | field->name); | 634 | field->name); |
@@ -545,10 +654,15 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname, | |||
545 | *ref_ptr = ref; | 654 | *ref_ptr = ref; |
546 | } else { | 655 | } else { |
547 | /* Verify it is a data structure */ | 656 | /* Verify it is a data structure */ |
548 | if (dwarf_tag(&type) != DW_TAG_structure_type) { | 657 | if (tag != DW_TAG_structure_type) { |
549 | pr_warning("%s is not a data structure.\n", varname); | 658 | pr_warning("%s is not a data structure.\n", varname); |
550 | return -EINVAL; | 659 | return -EINVAL; |
551 | } | 660 | } |
661 | if (field->name[0] == '[') { | ||
662 | pr_err("Semantic error: %s is not a pointor nor array.", | ||
663 | varname); | ||
664 | return -EINVAL; | ||
665 | } | ||
552 | if (field->ref) { | 666 | if (field->ref) { |
553 | pr_err("Semantic error: %s must be referred by '.'\n", | 667 | pr_err("Semantic error: %s must be referred by '.'\n", |
554 | field->name); | 668 | field->name); |
@@ -575,6 +689,7 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname, | |||
575 | } | 689 | } |
576 | ref->offset += (long)offs; | 690 | ref->offset += (long)offs; |
577 | 691 | ||
692 | next: | ||
578 | /* Converting next field */ | 693 | /* Converting next field */ |
579 | if (field->next) | 694 | if (field->next) |
580 | return convert_variable_fields(die_mem, field->name, | 695 | return convert_variable_fields(die_mem, field->name, |
@@ -586,51 +701,32 @@ static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname, | |||
586 | /* Show a variables in kprobe event format */ | 701 | /* Show a variables in kprobe event format */ |
587 | static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf) | 702 | static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf) |
588 | { | 703 | { |
589 | Dwarf_Attribute attr; | ||
590 | Dwarf_Die die_mem; | 704 | Dwarf_Die die_mem; |
591 | Dwarf_Op *expr; | ||
592 | size_t nexpr; | ||
593 | int ret; | 705 | int ret; |
594 | 706 | ||
595 | if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL) | 707 | pr_debug("Converting variable %s into trace event.\n", |
596 | goto error; | 708 | dwarf_diename(vr_die)); |
597 | /* TODO: handle more than 1 exprs */ | ||
598 | ret = dwarf_getlocation_addr(&attr, pf->addr, &expr, &nexpr, 1); | ||
599 | if (ret <= 0 || nexpr == 0) | ||
600 | goto error; | ||
601 | 709 | ||
602 | ret = convert_location(expr, pf); | 710 | ret = convert_variable_location(vr_die, pf); |
603 | if (ret == 0 && pf->pvar->field) { | 711 | if (ret == 0 && pf->pvar->field) { |
604 | ret = convert_variable_fields(vr_die, pf->pvar->var, | 712 | ret = convert_variable_fields(vr_die, pf->pvar->var, |
605 | pf->pvar->field, &pf->tvar->ref, | 713 | pf->pvar->field, &pf->tvar->ref, |
606 | &die_mem); | 714 | &die_mem); |
607 | vr_die = &die_mem; | 715 | vr_die = &die_mem; |
608 | } | 716 | } |
609 | if (ret == 0) { | 717 | if (ret == 0) |
610 | if (pf->pvar->type) { | 718 | ret = convert_variable_type(vr_die, pf->tvar, pf->pvar->type); |
611 | pf->tvar->type = strdup(pf->pvar->type); | ||
612 | if (pf->tvar->type == NULL) | ||
613 | ret = -ENOMEM; | ||
614 | } else | ||
615 | ret = convert_variable_type(vr_die, pf->tvar); | ||
616 | } | ||
617 | /* *expr will be cached in libdw. Don't free it. */ | 719 | /* *expr will be cached in libdw. Don't free it. */ |
618 | return ret; | 720 | return ret; |
619 | error: | ||
620 | /* TODO: Support const_value */ | ||
621 | pr_err("Failed to find the location of %s at this address.\n" | ||
622 | " Perhaps, it has been optimized out.\n", pf->pvar->var); | ||
623 | return -ENOENT; | ||
624 | } | 721 | } |
625 | 722 | ||
626 | /* Find a variable in a subprogram die */ | 723 | /* Find a variable in a subprogram die */ |
627 | static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf) | 724 | static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf) |
628 | { | 725 | { |
629 | Dwarf_Die vr_die; | 726 | Dwarf_Die vr_die, *scopes; |
630 | char buf[32], *ptr; | 727 | char buf[32], *ptr; |
631 | int ret; | 728 | int ret, nscopes; |
632 | 729 | ||
633 | /* TODO: Support arrays */ | ||
634 | if (pf->pvar->name) | 730 | if (pf->pvar->name) |
635 | pf->tvar->name = strdup(pf->pvar->name); | 731 | pf->tvar->name = strdup(pf->pvar->name); |
636 | else { | 732 | else { |
@@ -657,12 +753,26 @@ static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
657 | pr_debug("Searching '%s' variable in context.\n", | 753 | pr_debug("Searching '%s' variable in context.\n", |
658 | pf->pvar->var); | 754 | pf->pvar->var); |
659 | /* Search child die for local variables and parameters. */ | 755 | /* Search child die for local variables and parameters. */ |
660 | if (!die_find_variable(sp_die, pf->pvar->var, &vr_die)) { | 756 | if (die_find_variable(sp_die, pf->pvar->var, &vr_die)) |
757 | ret = convert_variable(&vr_die, pf); | ||
758 | else { | ||
759 | /* Search upper class */ | ||
760 | nscopes = dwarf_getscopes_die(sp_die, &scopes); | ||
761 | if (nscopes > 0) { | ||
762 | ret = dwarf_getscopevar(scopes, nscopes, pf->pvar->var, | ||
763 | 0, NULL, 0, 0, &vr_die); | ||
764 | if (ret >= 0) | ||
765 | ret = convert_variable(&vr_die, pf); | ||
766 | else | ||
767 | ret = -ENOENT; | ||
768 | free(scopes); | ||
769 | } else | ||
770 | ret = -ENOENT; | ||
771 | } | ||
772 | if (ret < 0) | ||
661 | pr_warning("Failed to find '%s' in this function.\n", | 773 | pr_warning("Failed to find '%s' in this function.\n", |
662 | pf->pvar->var); | 774 | pf->pvar->var); |
663 | return -ENOENT; | 775 | return ret; |
664 | } | ||
665 | return convert_variable(&vr_die, pf); | ||
666 | } | 776 | } |
667 | 777 | ||
668 | /* Show a probe point to output buffer */ | 778 | /* Show a probe point to output buffer */ |