uprobes tracer: Add stack/memory/retval access support
PATCH 1/1 uprobes tracer: Add stack/memory/retval access support
Event arguments except @SYM are supported. They are @ADDR, $stack, $stackN, $retval, and offs(arguments).
--- kernel/trace/trace_kprobe.c | 6 +- kernel/trace/trace_probe.c | 162 ++++++++++++++++++++++++++++++------------- kernel/trace/trace_probe.h | 6 +- kernel/trace/trace_uprobe.c | 6 +- 4 files changed, 124 insertions(+), 56 deletions(-)
kernel/trace/trace_kprobe.c +3 -3
@@ -683,7 +683,7 @@ static __kprobes int __get_data_size(struct trace_probe *tp,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); +call_fetch (&tp->args[i].fetch_size, regs, &len, true); ret += len; }
@@ -708,7 +708,7 @@ static __kprobes void store_trace_args(int ent_size, struct trace_probe *tp, 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); +call_fetch (&tp->args[i].fetch, regs, dl, true);/* Reduce maximum length */ end +=get_rloc_len (*dl); maxlen -=get_rloc_len (*dl);
@@ -718,7 +718,7 @@ static __kprobes void store_trace_args(int ent_size, struct trace_probe *tp, }else /* Just fetching data normally */ call_fetch (&tp->args[i].fetch, regs, - data + tp->args[i].offset); + data + tp->args[i].offset, true); } }
kernel/trace/trace_probe.c +114 -48
282 lines not on this page · raw message
kernel/trace/trace_probe.h +3 -3
@@ -83,7 +83,7 @@#define convert_rloc_to_loc (dl, offs) ((u32)(dl) + (offs))/* Data fetch function type */ -typedef void (*fetch_func_t )(struct pt_regs *,void *,void *); +typedef void (*fetch_func_t )(struct pt_regs *,void *,void *,bool );/* Printing function type */ typedef int (*print_type_func_t )(struct trace_seq *,const char *,void *,void *);
@@ -126,9 +126,9 @@ struct probe_arg { };static inline __kprobes void call_fetch (struct fetch_param *fprm, -struct pt_regs *regs,void *dest) +struct pt_regs *regs,void *dest,bool kprobe) { -return fprm->fn (regs, fprm->data, dest); +return fprm->fn (regs, fprm->data, dest, kprobe); }/* Check the name is good for event/group/fields */
kernel/trace/trace_uprobe.c +4 -2
@@ -491,7 +491,8 @@ static void uprobe_trace_func(struct trace_uprobe *tu, struct pt_regs *regs) entry->ip =uprobe_get_swbp_addr (task_pt_regs (current)); data = (u8 *)&entry[1 ];for (i =0 ; i < tu->nr_args; i++) -call_fetch (&tu->args[i].fetch, regs, data + tu->args[i].offset); +call_fetch (&tu->args[i].fetch, regs, + data + tu->args[i].offset, false);if (!filter_current_check_discard (buffer, call, entry, event))trace_buffer_unlock_commit (buffer, event, irq_flags, pc);
@@ -667,7 +668,8 @@ static void uprobe_perf_func(struct trace_uprobe *tu, struct pt_regs *regs) entry->ip =uprobe_get_swbp_addr (task_pt_regs (current)); data = (u8 *)&entry[1 ];for (i =0 ; i < tu->nr_args; i++) -call_fetch (&tu->args[i].fetch, regs, data + tu->args[i].offset); +call_fetch (&tu->args[i].fetch, regs, data + tu->args[i].offset, + false); head =this_cpu_ptr (call->perf_events);perf_trace_buf_submit (entry, size, rctx, entry->ip,1 , regs, head,NULL );
Signature · 1 line
1.7.10.4
Quoted 7 lines · Hyeoncheol Lee
Event arguments except @SYM are supported. They are @ADDR, $stack, $stackN, $retval, and offs(arguments).
Cc Masami Hiramatsu <[email protected]>Cc Srikar Dronamraju <[email protected]>Signed-off-by Hyeoncheol Lee <[email protected]>---
[...]
Quoted 4 lines
#define
DEFINE_FETCH_stack(type)\
static__kprobesvoidFETCH_FUNC_NAME(stack, type)(structpt_regs*regs,\kernel/trace/trace_probe.c +1
-1- void *offset, void *dest) \ + void *offset, void *dest, \
kernel/trace/trace_probe.c DEFINE_BASIC_FETCH_FUNCS(reg) · line 169
Quoted 10 lines
kernel/trace/trace_probe.c +6
-1+ bool kprobe) \ { \ - *(type *)dest = (type )regs_get_kernel_stack_nth (regs, \ +if (kprobe) \ + *(type *)dest = (type )regs_get_kernel_stack_nth (regs, \ (unsigned int )((unsigned long )offset)); \ +else \ + *(type *)dest = (type )regs_get_user_stack_nth (regs, \ + (unsigned int )((unsigned long )offset)); \ }
Hmm, I don't think this is a good way to do that.
If fetching user space objects is different from the kernel one, we'd better introduce new fetch handlers for it, instead of checking a bool flag every time, because it will be done on every events.
Thank you,
Signature · 4 lines
Masami HIRAMATSU IT Management Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
2012/10/16 Masami Hiramatsu <[email protected]>:
Quoted 31 lines
Quoted 7 lines · Hyeoncheol Lee
Event arguments except @SYM are supported. They are @ADDR, $stack, $stackN, $retval, and offs(arguments).
Cc Masami Hiramatsu <[email protected]>Cc Srikar Dronamraju <[email protected]>Signed-off-by Hyeoncheol Lee <[email protected]>---
[...]
Quoted 4 lines
#define
DEFINE_FETCH_stack(type)\
static__kprobesvoidFETCH_FUNC_NAME(stack, type)(structpt_regs*regs,\kernel/trace/trace_probe.c +1
-1- void *offset, void *dest) \ + void *offset, void *dest, \kernel/trace/trace_probe.c DEFINE_BASIC_FETCH_FUNCS(reg) · line 169
Quoted 10 lines
kernel/trace/trace_probe.c +6
-1+ bool kprobe) \ { \ - *(type *)dest = (type )regs_get_kernel_stack_nth (regs, \ +if (kprobe) \ + *(type *)dest = (type )regs_get_kernel_stack_nth (regs, \ (unsigned int )((unsigned long )offset)); \ +else \ + *(type *)dest = (type )regs_get_user_stack_nth (regs, \ + (unsigned int )((unsigned long )offset)); \ }Hmm, I don't think this is a good way to do that.
If fetching user space objects is different from the kernel one, we'd better introduce new fetch handlers for it, instead of checking a bool flag every time, because it will be done on every events.
Quoted 10 lines
Thank you,
--
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
Yes
Thank you for your comment