Commit d00bbea9 authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Steven Rostedt (VMware)

tracing: Integrate similar probe argument parsers

Integrate similar argument parsers for kprobes and uprobes events
into traceprobe_parse_probe_arg().

Link: http://lkml.kernel.org/r/154140850016.17322.9836787731210512176.stgit@devboxReviewed-by: default avatarTom Zanussi <tom.zanussi@linux.intel.com>
Tested-by: default avatarTom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent faacb361
...@@ -548,7 +548,6 @@ static int create_trace_kprobe(int argc, char **argv) ...@@ -548,7 +548,6 @@ static int create_trace_kprobe(int argc, char **argv)
bool is_return = false, is_delete = false; bool is_return = false, is_delete = false;
char *symbol = NULL, *event = NULL, *group = NULL; char *symbol = NULL, *event = NULL, *group = NULL;
int maxactive = 0; int maxactive = 0;
char *arg;
long offset = 0; long offset = 0;
void *addr = NULL; void *addr = NULL;
char buf[MAX_EVENT_NAME_LEN]; char buf[MAX_EVENT_NAME_LEN];
...@@ -676,54 +675,11 @@ static int create_trace_kprobe(int argc, char **argv) ...@@ -676,54 +675,11 @@ static int create_trace_kprobe(int argc, char **argv)
} }
/* parse arguments */ /* parse arguments */
ret = 0;
for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) { for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
struct probe_arg *parg = &tk->tp.args[i]; ret = traceprobe_parse_probe_arg(&tk->tp, i, argv[i], flags);
if (ret)
/* Increment count for freeing args in error case */
tk->tp.nr_args++;
/* Parse argument name */
arg = strchr(argv[i], '=');
if (arg) {
*arg++ = '\0';
parg->name = kstrdup(argv[i], GFP_KERNEL);
} else {
arg = argv[i];
/* If argument name is omitted, set "argN" */
snprintf(buf, MAX_EVENT_NAME_LEN, "arg%d", i + 1);
parg->name = kstrdup(buf, GFP_KERNEL);
}
if (!parg->name) {
pr_info("Failed to allocate argument[%d] name.\n", i);
ret = -ENOMEM;
goto error;
}
if (!is_good_name(parg->name)) {
pr_info("Invalid argument[%d] name: %s\n",
i, parg->name);
ret = -EINVAL;
goto error;
}
if (traceprobe_conflict_field_name(parg->name,
tk->tp.args, i)) {
pr_info("Argument[%d] name '%s' conflicts with "
"another field.\n", i, argv[i]);
ret = -EINVAL;
goto error;
}
/* Parse fetch argument */
ret = traceprobe_parse_probe_arg(arg, &tk->tp.size, parg,
flags);
if (ret) {
pr_info("Parse error at argument[%d]. (%d)\n", i, ret);
goto error; goto error;
} }
}
ret = register_trace_kprobe(tk); ret = register_trace_kprobe(tk);
if (ret) if (ret)
......
...@@ -348,7 +348,7 @@ static int __parse_bitfield_probe_arg(const char *bf, ...@@ -348,7 +348,7 @@ static int __parse_bitfield_probe_arg(const char *bf,
} }
/* String length checking wrapper */ /* String length checking wrapper */
int traceprobe_parse_probe_arg(char *arg, ssize_t *size, static int traceprobe_parse_probe_arg_body(char *arg, ssize_t *size,
struct probe_arg *parg, unsigned int flags) struct probe_arg *parg, unsigned int flags)
{ {
struct fetch_insn *code, *scode, *tmp = NULL; struct fetch_insn *code, *scode, *tmp = NULL;
...@@ -491,7 +491,7 @@ int traceprobe_parse_probe_arg(char *arg, ssize_t *size, ...@@ -491,7 +491,7 @@ int traceprobe_parse_probe_arg(char *arg, ssize_t *size,
} }
/* Return 1 if name is reserved or already used by another argument */ /* Return 1 if name is reserved or already used by another argument */
int traceprobe_conflict_field_name(const char *name, static int traceprobe_conflict_field_name(const char *name,
struct probe_arg *args, int narg) struct probe_arg *args, int narg)
{ {
int i; int i;
...@@ -507,6 +507,47 @@ int traceprobe_conflict_field_name(const char *name, ...@@ -507,6 +507,47 @@ int traceprobe_conflict_field_name(const char *name,
return 0; return 0;
} }
int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, char *arg,
unsigned int flags)
{
struct probe_arg *parg = &tp->args[i];
char *body;
int ret;
/* Increment count for freeing args in error case */
tp->nr_args++;
body = strchr(arg, '=');
if (body) {
parg->name = kmemdup_nul(arg, body - arg, GFP_KERNEL);
body++;
} else {
/* If argument name is omitted, set "argN" */
parg->name = kasprintf(GFP_KERNEL, "arg%d", i + 1);
body = arg;
}
if (!parg->name)
return -ENOMEM;
if (!is_good_name(parg->name)) {
pr_info("Invalid argument[%d] name: %s\n",
i, parg->name);
return -EINVAL;
}
if (traceprobe_conflict_field_name(parg->name, tp->args, i)) {
pr_info("Argument[%d]: '%s' conflicts with another field.\n",
i, parg->name);
return -EINVAL;
}
/* Parse fetch argument */
ret = traceprobe_parse_probe_arg_body(body, &tp->size, parg, flags);
if (ret)
pr_info("Parse error at argument[%d]. (%d)\n", i, ret);
return ret;
}
void traceprobe_free_probe_arg(struct probe_arg *arg) void traceprobe_free_probe_arg(struct probe_arg *arg)
{ {
struct fetch_insn *code = arg->code; struct fetch_insn *code = arg->code;
......
...@@ -272,11 +272,8 @@ find_event_file_link(struct trace_probe *tp, struct trace_event_file *file) ...@@ -272,11 +272,8 @@ find_event_file_link(struct trace_probe *tp, struct trace_event_file *file)
#define TPARG_FL_FENTRY BIT(2) #define TPARG_FL_FENTRY BIT(2)
#define TPARG_FL_MASK GENMASK(2, 0) #define TPARG_FL_MASK GENMASK(2, 0)
extern int traceprobe_parse_probe_arg(char *arg, ssize_t *size, extern int traceprobe_parse_probe_arg(struct trace_probe *tp, int i,
struct probe_arg *parg, unsigned int flags); char *arg, unsigned int flags);
extern int traceprobe_conflict_field_name(const char *name,
struct probe_arg *args, int narg);
extern int traceprobe_update_arg(struct probe_arg *arg); extern int traceprobe_update_arg(struct probe_arg *arg);
extern void traceprobe_free_probe_arg(struct probe_arg *arg); extern void traceprobe_free_probe_arg(struct probe_arg *arg);
......
...@@ -517,52 +517,12 @@ static int create_trace_uprobe(int argc, char **argv) ...@@ -517,52 +517,12 @@ static int create_trace_uprobe(int argc, char **argv)
} }
/* parse arguments */ /* parse arguments */
ret = 0;
for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) { for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
struct probe_arg *parg = &tu->tp.args[i]; ret = traceprobe_parse_probe_arg(&tu->tp, i, argv[i],
/* Increment count for freeing args in error case */
tu->tp.nr_args++;
/* Parse argument name */
arg = strchr(argv[i], '=');
if (arg) {
*arg++ = '\0';
parg->name = kstrdup(argv[i], GFP_KERNEL);
} else {
arg = argv[i];
/* If argument name is omitted, set "argN" */
snprintf(buf, MAX_EVENT_NAME_LEN, "arg%d", i + 1);
parg->name = kstrdup(buf, GFP_KERNEL);
}
if (!parg->name) {
pr_info("Failed to allocate argument[%d] name.\n", i);
ret = -ENOMEM;
goto error;
}
if (!is_good_name(parg->name)) {
pr_info("Invalid argument[%d] name: %s\n", i, parg->name);
ret = -EINVAL;
goto error;
}
if (traceprobe_conflict_field_name(parg->name, tu->tp.args, i)) {
pr_info("Argument[%d] name '%s' conflicts with "
"another field.\n", i, argv[i]);
ret = -EINVAL;
goto error;
}
/* Parse fetch argument */
ret = traceprobe_parse_probe_arg(arg, &tu->tp.size, parg,
is_return ? TPARG_FL_RETURN : 0); is_return ? TPARG_FL_RETURN : 0);
if (ret) { if (ret)
pr_info("Parse error at argument[%d]. (%d)\n", i, ret);
goto error; goto error;
} }
}
ret = register_trace_uprobe(tu); ret = register_trace_uprobe(tu);
if (ret) if (ret)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment