tracing/kprobes: Init print_fmt for kprobe events
This is part of a patch set that removes the show_format method in the ftrace event macros. Add the print_fmt initialization to the kprobe events. The print_fmt is still not used, but will be in the follow up patches. Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> LKML-Reference: <4B273D45.3080100@cn.fujitsu.com> Acked-by: Masami Hiramatsu <mhiramat@redhat.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
This commit is contained in:
parent
50307a45f8
commit
a342a0280b
1 changed files with 63 additions and 1 deletions
|
@ -1250,6 +1250,62 @@ static int kretprobe_event_show_format(struct ftrace_event_call *call,
|
||||||
", REC->" FIELD_STRING_RETIP);
|
", REC->" FIELD_STRING_RETIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int __set_print_fmt(struct trace_probe *tp, char *buf, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int pos = 0;
|
||||||
|
|
||||||
|
const char *fmt, *arg;
|
||||||
|
|
||||||
|
if (!probe_is_return(tp)) {
|
||||||
|
fmt = "(%lx)";
|
||||||
|
arg = "REC->" FIELD_STRING_IP;
|
||||||
|
} else {
|
||||||
|
fmt = "(%lx <- %lx)";
|
||||||
|
arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* When len=0, we just calculate the needed length */
|
||||||
|
#define LEN_OR_ZERO (len ? len - pos : 0)
|
||||||
|
|
||||||
|
pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt);
|
||||||
|
|
||||||
|
for (i = 0; i < tp->nr_args; i++) {
|
||||||
|
pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%%lx",
|
||||||
|
tp->args[i].name);
|
||||||
|
}
|
||||||
|
|
||||||
|
pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg);
|
||||||
|
|
||||||
|
for (i = 0; i < tp->nr_args; i++) {
|
||||||
|
pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s",
|
||||||
|
tp->args[i].name);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef LEN_OR_ZERO
|
||||||
|
|
||||||
|
/* return the length of print_fmt */
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int set_print_fmt(struct trace_probe *tp)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
char *print_fmt;
|
||||||
|
|
||||||
|
/* First: called with 0 length to calculate the needed length */
|
||||||
|
len = __set_print_fmt(tp, NULL, 0);
|
||||||
|
print_fmt = kmalloc(len + 1, GFP_KERNEL);
|
||||||
|
if (!print_fmt)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
/* Second: actually write the @print_fmt */
|
||||||
|
__set_print_fmt(tp, print_fmt, len + 1);
|
||||||
|
tp->call.print_fmt = print_fmt;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_EVENT_PROFILE
|
#ifdef CONFIG_EVENT_PROFILE
|
||||||
|
|
||||||
/* Kprobe profile handler */
|
/* Kprobe profile handler */
|
||||||
|
@ -1456,10 +1512,14 @@ static int register_probe_event(struct trace_probe *tp)
|
||||||
call->show_format = kprobe_event_show_format;
|
call->show_format = kprobe_event_show_format;
|
||||||
call->define_fields = kprobe_event_define_fields;
|
call->define_fields = kprobe_event_define_fields;
|
||||||
}
|
}
|
||||||
|
if (set_print_fmt(tp) < 0)
|
||||||
|
return -ENOMEM;
|
||||||
call->event = &tp->event;
|
call->event = &tp->event;
|
||||||
call->id = register_ftrace_event(&tp->event);
|
call->id = register_ftrace_event(&tp->event);
|
||||||
if (!call->id)
|
if (!call->id) {
|
||||||
|
kfree(call->print_fmt);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
}
|
||||||
call->enabled = 0;
|
call->enabled = 0;
|
||||||
call->regfunc = probe_event_enable;
|
call->regfunc = probe_event_enable;
|
||||||
call->unregfunc = probe_event_disable;
|
call->unregfunc = probe_event_disable;
|
||||||
|
@ -1472,6 +1532,7 @@ static int register_probe_event(struct trace_probe *tp)
|
||||||
ret = trace_add_event_call(call);
|
ret = trace_add_event_call(call);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_info("Failed to register kprobe event: %s\n", call->name);
|
pr_info("Failed to register kprobe event: %s\n", call->name);
|
||||||
|
kfree(call->print_fmt);
|
||||||
unregister_ftrace_event(&tp->event);
|
unregister_ftrace_event(&tp->event);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1481,6 +1542,7 @@ static void unregister_probe_event(struct trace_probe *tp)
|
||||||
{
|
{
|
||||||
/* tp->event is unregistered in trace_remove_event_call() */
|
/* tp->event is unregistered in trace_remove_event_call() */
|
||||||
trace_remove_event_call(&tp->call);
|
trace_remove_event_call(&tp->call);
|
||||||
|
kfree(tp->call.print_fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make a debugfs interface for controling probe points */
|
/* Make a debugfs interface for controling probe points */
|
||||||
|
|
Loading…
Add table
Reference in a new issue