21 #include <linux/module.h>
28 #define UPROBE_EVENT_SYSTEM "uprobes"
54 #define SIZEOF_TRACE_UPROBE(n) \
55 (offsetof(struct trace_uprobe, args) + \
56 (sizeof(struct probe_arg) * (n)))
58 static int register_uprobe_event(
struct trace_uprobe *tu);
59 static void unregister_uprobe_event(
struct trace_uprobe *tu);
70 alloc_trace_uprobe(
const char *
group,
const char *
event,
int nargs)
74 if (!event || !is_good_name(event))
77 if (!group || !is_good_name(group))
90 if (!tu->
class.system)
93 INIT_LIST_HEAD(&tu->
list);
107 for (i = 0; i < tu->
nr_args; i++)
117 static struct trace_uprobe *find_probe_event(
const char *event,
const char *group)
133 unregister_uprobe_event(tu);
134 free_trace_uprobe(tu);
138 static int register_trace_uprobe(
struct trace_uprobe *tu)
146 old_tp = find_probe_event(tu->
call.name, tu->
call.class->system);
149 unregister_trace_uprobe(old_tp);
151 ret = register_uprobe_event(tu);
153 pr_warning(
"Failed to register probe event(%d)\n", ret);
171 static int create_trace_uprobe(
int argc,
char **argv)
189 if (argv[0][0] ==
'-')
191 else if (argv[0][0] !=
'p') {
192 pr_info(
"Probe definition must be started with 'p', 'r' or" " '-'.\n");
196 if (argv[0][1] ==
':') {
206 pr_info(
"Group name is not specified\n");
211 pr_info(
"Event name is not specified\n");
220 pr_info(
"Delete command needs an event name.\n");
224 tu = find_probe_event(event, group);
228 pr_info(
"Event %s/%s doesn't exist.\n", group, event);
232 unregister_trace_uprobe(tu);
238 pr_info(
"Probe point is not specified.\n");
242 pr_info(
"probe point must be have a filename.\n");
245 arg =
strchr(argv[1],
':');
247 goto fail_address_parse;
253 goto fail_address_parse;
257 goto fail_address_parse;
272 goto fail_address_parse;
285 tu = alloc_trace_uprobe(group, event, argc);
287 pr_info(
"Failed to allocate trace_uprobe.(%d)\n", (
int)PTR_ERR(tu));
289 goto fail_address_parse;
296 pr_info(
"Failed to allocate filename.\n");
308 arg =
strchr(argv[i],
'=');
319 if (!tu->
args[i].name) {
320 pr_info(
"Failed to allocate argument[%d] name.\n", i);
325 if (!is_good_name(tu->
args[i].name)) {
326 pr_info(
"Invalid argument[%d] name: %s\n", i, tu->
args[i].name);
332 pr_info(
"Argument[%d] name '%s' conflicts with "
333 "another field.\n", i, argv[i]);
341 pr_info(
"Parse error at argument[%d]. (%d)\n", i, ret);
346 ret = register_trace_uprobe(tu);
352 free_trace_uprobe(tu);
359 pr_info(
"Failed to parse address.\n");
364 static void cleanup_all_probes(
void)
369 while (!list_empty(&uprobe_list)) {
371 unregister_trace_uprobe(tu);
377 static void *probes_seq_start(
struct seq_file *
m, loff_t *
pos)
383 static void *probes_seq_next(
struct seq_file *
m,
void *
v, loff_t *
pos)
388 static void probes_seq_stop(
struct seq_file *
m,
void *
v)
393 static int probes_seq_show(
struct seq_file *
m,
void *
v)
401 for (i = 0; i < tu->
nr_args; i++)
409 .start = probes_seq_start,
410 .next = probes_seq_next,
411 .stop = probes_seq_stop,
412 .show = probes_seq_show
415 static int probes_open(
struct inode *inode,
struct file *
file)
418 cleanup_all_probes();
420 return seq_open(file, &probes_seq_op);
423 static ssize_t probes_write(
struct file *file,
const char __user *
buffer,
424 size_t count, loff_t *ppos)
435 .write = probes_write,
439 static int probes_profile_seq_show(
struct seq_file *m,
void *v)
448 .start = probes_seq_start,
449 .next = probes_seq_next,
450 .stop = probes_seq_stop,
451 .show = probes_profile_seq_show
454 static int profile_open(
struct inode *inode,
struct file *file)
456 return seq_open(file, &profile_seq_op);
461 .open = profile_open,
475 unsigned long irq_flags;
483 size =
sizeof(*entry) + tu->
size;
486 size, irq_flags, pc);
492 data = (
u8 *)&entry[1];
493 for (i = 0; i < tu->
nr_args; i++)
494 call_fetch(&tu->
args[i].fetch, regs, data + tu->
args[i].offset);
522 data = (
u8 *)&field[1];
523 for (i = 0; i < tu->
nr_args; i++) {
524 if (!tu->
args[i].type->print(s, tu->
args[i].name,
525 data + tu->
args[i].offset, field))
548 utc->
cons.handler = uprobe_dispatcher;
563 static void probe_event_disable(
struct trace_uprobe *tu,
int flag)
582 for (i = 0; i < tu->
nr_args; i++) {
585 sizeof(field) + tu->
args[i].offset,
586 tu->
args[i].type->size,
587 tu->
args[i].type->is_signed,
596 #define LEN_OR_ZERO (len ? len - pos : 0)
597 static int __set_print_fmt(
struct trace_uprobe *tu,
char *buf,
int len)
610 for (i = 0; i < tu->
nr_args; i++) {
612 tu->
args[i].name, tu->
args[i].type->fmt);
617 for (i = 0; i < tu->
nr_args; i++) {
632 len = __set_print_fmt(tu,
NULL, 0);
638 __set_print_fmt(tu, print_fmt, len + 1);
639 tu->
call.print_fmt = print_fmt;
644 #ifdef CONFIG_PERF_EVENTS
655 __size =
sizeof(*entry) + tu->
size;
668 data = (
u8 *)&entry[1];
669 for (i = 0; i < tu->
nr_args; i++)
670 call_fetch(&tu->
args[i].fetch, regs, data + tu->
args[i].offset);
673 perf_trace_buf_submit(entry, size, rctx, entry->
ip, 1, regs, head,
NULL);
693 #ifdef CONFIG_PERF_EVENTS
694 case TRACE_REG_PERF_REGISTER:
697 case TRACE_REG_PERF_UNREGISTER:
718 uprobe_trace_func(tu, regs);
720 #ifdef CONFIG_PERF_EVENTS
722 uprobe_perf_func(tu, regs);
728 .trace = print_uprobe_event
731 static int register_uprobe_event(
struct trace_uprobe *tu)
737 INIT_LIST_HEAD(&call->
class->fields);
738 call->
event.funcs = &uprobe_funcs;
739 call->
class->define_fields = uprobe_event_define_fields;
741 if (set_print_fmt(tu) < 0)
750 call->
class->reg = trace_uprobe_register;
755 pr_info(
"Failed to register uprobe event: %s\n", call->
name);
763 static void unregister_uprobe_event(
struct trace_uprobe *tu)
772 static __init int init_uprobe_trace(
void)
781 NULL, &uprobe_events_ops);
784 NULL, &uprobe_profile_ops);