tracing/probes: Move event parameter fetching code to common parser

Move trace event parameter fetching code to common parser in
trace_probe.c. This simplifies eprobe's trace-event variable fetching
code by introducing a parse context data structure.

Link: https://lore.kernel.org/all/168507472950.913472.2812253181558471278.stgit@mhiramat.roam.corp.google.com/

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
This commit is contained in:
Masami Hiramatsu (Google)
2023-06-06 21:39:56 +09:00
parent e2d0d7b2f4
commit 1b8b0cd754
6 changed files with 161 additions and 138 deletions

View File

@@ -227,37 +227,6 @@ error:
return ERR_PTR(ret); return ERR_PTR(ret);
} }
static int trace_eprobe_tp_arg_update(struct trace_eprobe *ep, int i)
{
struct probe_arg *parg = &ep->tp.args[i];
struct ftrace_event_field *field;
struct list_head *head;
int ret = -ENOENT;
head = trace_get_fields(ep->event);
list_for_each_entry(field, head, link) {
if (!strcmp(parg->code->data, field->name)) {
kfree(parg->code->data);
parg->code->data = field;
return 0;
}
}
/*
* Argument not found on event. But allow for comm and COMM
* to be used to get the current->comm.
*/
if (strcmp(parg->code->data, "COMM") == 0 ||
strcmp(parg->code->data, "comm") == 0) {
parg->code->op = FETCH_OP_COMM;
ret = 0;
}
kfree(parg->code->data);
parg->code->data = NULL;
return ret;
}
static int eprobe_event_define_fields(struct trace_event_call *event_call) static int eprobe_event_define_fields(struct trace_event_call *event_call)
{ {
struct eprobe_trace_entry_head field; struct eprobe_trace_entry_head field;
@@ -817,19 +786,16 @@ find_and_get_event(const char *system, const char *event_name)
static int trace_eprobe_tp_update_arg(struct trace_eprobe *ep, const char *argv[], int i) static int trace_eprobe_tp_update_arg(struct trace_eprobe *ep, const char *argv[], int i)
{ {
unsigned int flags = TPARG_FL_KERNEL | TPARG_FL_TEVENT; struct traceprobe_parse_context ctx = {
.event = ep->event,
.flags = TPARG_FL_KERNEL | TPARG_FL_TEVENT,
};
int ret; int ret;
ret = traceprobe_parse_probe_arg(&ep->tp, i, argv[i], flags); ret = traceprobe_parse_probe_arg(&ep->tp, i, argv[i], &ctx);
if (ret) if (ret)
return ret; return ret;
if (ep->tp.args[i].code->op == FETCH_OP_TP_ARG) {
ret = trace_eprobe_tp_arg_update(ep, i);
if (ret)
trace_probe_log_err(0, BAD_ATTACH_ARG);
}
/* Handle symbols "@" */ /* Handle symbols "@" */
if (!ret) if (!ret)
ret = traceprobe_update_arg(&ep->tp.args[i]); ret = traceprobe_update_arg(&ep->tp.args[i]);

View File

@@ -1047,8 +1047,10 @@ static int __trace_fprobe_create(int argc, const char *argv[])
/* parse arguments */ /* parse arguments */
for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) { for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
struct traceprobe_parse_context ctx = { .flags = flags };
trace_probe_log_set_index(i + 2); trace_probe_log_set_index(i + 2);
ret = traceprobe_parse_probe_arg(&tf->tp, i, argv[i], flags); ret = traceprobe_parse_probe_arg(&tf->tp, i, argv[i], &ctx);
if (ret) if (ret)
goto error; /* This can be -ENOMEM */ goto error; /* This can be -ENOMEM */
} }

View File

@@ -867,8 +867,10 @@ static int __trace_kprobe_create(int argc, const char *argv[])
/* parse arguments */ /* parse arguments */
for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) { for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
struct traceprobe_parse_context ctx = { .flags = flags };
trace_probe_log_set_index(i + 2); trace_probe_log_set_index(i + 2);
ret = traceprobe_parse_probe_arg(&tk->tp, i, argv[i], flags); ret = traceprobe_parse_probe_arg(&tk->tp, i, argv[i], &ctx);
if (ret) if (ret)
goto error; /* This can be -ENOMEM */ goto error; /* This can be -ENOMEM */
} }

View File

@@ -283,74 +283,114 @@ int traceprobe_parse_event_name(const char **pevent, const char **pgroup,
return 0; return 0;
} }
static int parse_trace_event_arg(char *arg, struct fetch_insn *code,
struct traceprobe_parse_context *ctx)
{
struct ftrace_event_field *field;
struct list_head *head;
head = trace_get_fields(ctx->event);
list_for_each_entry(field, head, link) {
if (!strcmp(arg, field->name)) {
code->op = FETCH_OP_TP_ARG;
code->data = field;
return 0;
}
}
return -ENOENT;
}
#define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long)) #define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long))
static int parse_probe_vars(char *arg, const struct fetch_type *t, static int parse_probe_vars(char *arg, const struct fetch_type *t,
struct fetch_insn *code, unsigned int flags, int offs) struct fetch_insn *code,
struct traceprobe_parse_context *ctx)
{ {
unsigned long param; unsigned long param;
int err = TP_ERR_BAD_VAR;
int ret = 0; int ret = 0;
int len; int len;
if (flags & TPARG_FL_TEVENT) { if (ctx->flags & TPARG_FL_TEVENT) {
if (code->data) if (code->data)
return -EFAULT; return -EFAULT;
code->data = kstrdup(arg, GFP_KERNEL); ret = parse_trace_event_arg(arg, code, ctx);
if (!code->data) if (!ret)
return -ENOMEM; return 0;
code->op = FETCH_OP_TP_ARG; if (strcmp(arg, "comm") == 0 || strcmp(arg, "COMM") == 0) {
} else if (strcmp(arg, "retval") == 0) { code->op = FETCH_OP_COMM;
if (flags & TPARG_FL_RETURN) { return 0;
code->op = FETCH_OP_RETVAL;
} else {
trace_probe_log_err(offs, RETVAL_ON_PROBE);
ret = -EINVAL;
} }
} else if ((len = str_has_prefix(arg, "stack"))) { /* backward compatibility */
ctx->offset = 0;
goto inval;
}
if (strcmp(arg, "retval") == 0) {
if (ctx->flags & TPARG_FL_RETURN) {
code->op = FETCH_OP_RETVAL;
return 0;
}
err = TP_ERR_RETVAL_ON_PROBE;
goto inval;
}
len = str_has_prefix(arg, "stack");
if (len) {
if (arg[len] == '\0') { if (arg[len] == '\0') {
code->op = FETCH_OP_STACKP; code->op = FETCH_OP_STACKP;
} else if (isdigit(arg[len])) { return 0;
ret = kstrtoul(arg + len, 10, &param);
if (ret) {
goto inval_var;
} else if ((flags & TPARG_FL_KERNEL) &&
param > PARAM_MAX_STACK) {
trace_probe_log_err(offs, BAD_STACK_NUM);
ret = -EINVAL;
} else {
code->op = FETCH_OP_STACK;
code->param = (unsigned int)param;
}
} else
goto inval_var;
} else if (strcmp(arg, "comm") == 0 || strcmp(arg, "COMM") == 0) {
code->op = FETCH_OP_COMM;
#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API
} else if (tparg_is_function_entry(flags) &&
(len = str_has_prefix(arg, "arg"))) {
ret = kstrtoul(arg + len, 10, &param);
if (ret) {
goto inval_var;
} else if (!param || param > PARAM_MAX_STACK) {
trace_probe_log_err(offs, BAD_ARG_NUM);
return -EINVAL;
} }
if (isdigit(arg[len])) {
ret = kstrtoul(arg + len, 10, &param);
if (ret)
goto inval;
if ((ctx->flags & TPARG_FL_KERNEL) &&
param > PARAM_MAX_STACK) {
err = TP_ERR_BAD_STACK_NUM;
goto inval;
}
code->op = FETCH_OP_STACK;
code->param = (unsigned int)param;
return 0;
}
goto inval;
}
if (strcmp(arg, "comm") == 0 || strcmp(arg, "COMM") == 0) {
code->op = FETCH_OP_COMM;
return 0;
}
#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API
len = str_has_prefix(arg, "arg");
if (len && tparg_is_function_entry(ctx->flags)) {
ret = kstrtoul(arg + len, 10, &param);
if (ret)
goto inval;
if (!param || param > PARAM_MAX_STACK) {
err = TP_ERR_BAD_ARG_NUM;
goto inval;
}
code->op = FETCH_OP_ARG; code->op = FETCH_OP_ARG;
code->param = (unsigned int)param - 1; code->param = (unsigned int)param - 1;
/* /*
* The tracepoint probe will probe a stub function, and the * The tracepoint probe will probe a stub function, and the
* first parameter of the stub is a dummy and should be ignored. * first parameter of the stub is a dummy and should be ignored.
*/ */
if (flags & TPARG_FL_TPOINT) if (ctx->flags & TPARG_FL_TPOINT)
code->param++; code->param++;
return 0;
}
#endif #endif
} else
goto inval_var;
return ret; inval:
__trace_probe_log_err(ctx->offset, err);
inval_var:
trace_probe_log_err(offs, BAD_VAR);
return -EINVAL; return -EINVAL;
} }
@@ -383,7 +423,7 @@ static int __parse_imm_string(char *str, char **pbuf, int offs)
static int static int
parse_probe_arg(char *arg, const struct fetch_type *type, parse_probe_arg(char *arg, const struct fetch_type *type,
struct fetch_insn **pcode, struct fetch_insn *end, struct fetch_insn **pcode, struct fetch_insn *end,
unsigned int flags, int offs) struct traceprobe_parse_context *ctx)
{ {
struct fetch_insn *code = *pcode; struct fetch_insn *code = *pcode;
unsigned long param; unsigned long param;
@@ -394,13 +434,13 @@ parse_probe_arg(char *arg, const struct fetch_type *type,
switch (arg[0]) { switch (arg[0]) {
case '$': case '$':
ret = parse_probe_vars(arg + 1, type, code, flags, offs); ret = parse_probe_vars(arg + 1, type, code, ctx);
break; break;
case '%': /* named register */ case '%': /* named register */
if (flags & (TPARG_FL_TEVENT | TPARG_FL_FPROBE)) { if (ctx->flags & (TPARG_FL_TEVENT | TPARG_FL_FPROBE)) {
/* eprobe and fprobe do not handle registers */ /* eprobe and fprobe do not handle registers */
trace_probe_log_err(offs, BAD_VAR); trace_probe_log_err(ctx->offset, BAD_VAR);
break; break;
} }
ret = regs_query_register_offset(arg + 1); ret = regs_query_register_offset(arg + 1);
@@ -409,14 +449,14 @@ parse_probe_arg(char *arg, const struct fetch_type *type,
code->param = (unsigned int)ret; code->param = (unsigned int)ret;
ret = 0; ret = 0;
} else } else
trace_probe_log_err(offs, BAD_REG_NAME); trace_probe_log_err(ctx->offset, BAD_REG_NAME);
break; break;
case '@': /* memory, file-offset or symbol */ case '@': /* memory, file-offset or symbol */
if (isdigit(arg[1])) { if (isdigit(arg[1])) {
ret = kstrtoul(arg + 1, 0, &param); ret = kstrtoul(arg + 1, 0, &param);
if (ret) { if (ret) {
trace_probe_log_err(offs, BAD_MEM_ADDR); trace_probe_log_err(ctx->offset, BAD_MEM_ADDR);
break; break;
} }
/* load address */ /* load address */
@@ -424,13 +464,13 @@ parse_probe_arg(char *arg, const struct fetch_type *type,
code->immediate = param; code->immediate = param;
} else if (arg[1] == '+') { } else if (arg[1] == '+') {
/* kprobes don't support file offsets */ /* kprobes don't support file offsets */
if (flags & TPARG_FL_KERNEL) { if (ctx->flags & TPARG_FL_KERNEL) {
trace_probe_log_err(offs, FILE_ON_KPROBE); trace_probe_log_err(ctx->offset, FILE_ON_KPROBE);
return -EINVAL; return -EINVAL;
} }
ret = kstrtol(arg + 2, 0, &offset); ret = kstrtol(arg + 2, 0, &offset);
if (ret) { if (ret) {
trace_probe_log_err(offs, BAD_FILE_OFFS); trace_probe_log_err(ctx->offset, BAD_FILE_OFFS);
break; break;
} }
@@ -438,8 +478,8 @@ parse_probe_arg(char *arg, const struct fetch_type *type,
code->immediate = (unsigned long)offset; // imm64? code->immediate = (unsigned long)offset; // imm64?
} else { } else {
/* uprobes don't support symbols */ /* uprobes don't support symbols */
if (!(flags & TPARG_FL_KERNEL)) { if (!(ctx->flags & TPARG_FL_KERNEL)) {
trace_probe_log_err(offs, SYM_ON_UPROBE); trace_probe_log_err(ctx->offset, SYM_ON_UPROBE);
return -EINVAL; return -EINVAL;
} }
/* Preserve symbol for updating */ /* Preserve symbol for updating */
@@ -448,7 +488,7 @@ parse_probe_arg(char *arg, const struct fetch_type *type,
if (!code->data) if (!code->data)
return -ENOMEM; return -ENOMEM;
if (++code == end) { if (++code == end) {
trace_probe_log_err(offs, TOO_MANY_OPS); trace_probe_log_err(ctx->offset, TOO_MANY_OPS);
return -EINVAL; return -EINVAL;
} }
code->op = FETCH_OP_IMM; code->op = FETCH_OP_IMM;
@@ -456,7 +496,7 @@ parse_probe_arg(char *arg, const struct fetch_type *type,
} }
/* These are fetching from memory */ /* These are fetching from memory */
if (++code == end) { if (++code == end) {
trace_probe_log_err(offs, TOO_MANY_OPS); trace_probe_log_err(ctx->offset, TOO_MANY_OPS);
return -EINVAL; return -EINVAL;
} }
*pcode = code; *pcode = code;
@@ -475,36 +515,38 @@ parse_probe_arg(char *arg, const struct fetch_type *type,
arg++; /* Skip '+', because kstrtol() rejects it. */ arg++; /* Skip '+', because kstrtol() rejects it. */
tmp = strchr(arg, '('); tmp = strchr(arg, '(');
if (!tmp) { if (!tmp) {
trace_probe_log_err(offs, DEREF_NEED_BRACE); trace_probe_log_err(ctx->offset, DEREF_NEED_BRACE);
return -EINVAL; return -EINVAL;
} }
*tmp = '\0'; *tmp = '\0';
ret = kstrtol(arg, 0, &offset); ret = kstrtol(arg, 0, &offset);
if (ret) { if (ret) {
trace_probe_log_err(offs, BAD_DEREF_OFFS); trace_probe_log_err(ctx->offset, BAD_DEREF_OFFS);
break; break;
} }
offs += (tmp + 1 - arg) + (arg[0] != '-' ? 1 : 0); ctx->offset += (tmp + 1 - arg) + (arg[0] != '-' ? 1 : 0);
arg = tmp + 1; arg = tmp + 1;
tmp = strrchr(arg, ')'); tmp = strrchr(arg, ')');
if (!tmp) { if (!tmp) {
trace_probe_log_err(offs + strlen(arg), trace_probe_log_err(ctx->offset + strlen(arg),
DEREF_OPEN_BRACE); DEREF_OPEN_BRACE);
return -EINVAL; return -EINVAL;
} else { } else {
const struct fetch_type *t2 = find_fetch_type(NULL, flags); const struct fetch_type *t2 = find_fetch_type(NULL, ctx->flags);
int cur_offs = ctx->offset;
*tmp = '\0'; *tmp = '\0';
ret = parse_probe_arg(arg, t2, &code, end, flags, offs); ret = parse_probe_arg(arg, t2, &code, end, ctx);
if (ret) if (ret)
break; break;
ctx->offset = cur_offs;
if (code->op == FETCH_OP_COMM || if (code->op == FETCH_OP_COMM ||
code->op == FETCH_OP_DATA) { code->op == FETCH_OP_DATA) {
trace_probe_log_err(offs, COMM_CANT_DEREF); trace_probe_log_err(ctx->offset, COMM_CANT_DEREF);
return -EINVAL; return -EINVAL;
} }
if (++code == end) { if (++code == end) {
trace_probe_log_err(offs, TOO_MANY_OPS); trace_probe_log_err(ctx->offset, TOO_MANY_OPS);
return -EINVAL; return -EINVAL;
} }
*pcode = code; *pcode = code;
@@ -515,7 +557,7 @@ parse_probe_arg(char *arg, const struct fetch_type *type,
break; break;
case '\\': /* Immediate value */ case '\\': /* Immediate value */
if (arg[1] == '"') { /* Immediate string */ if (arg[1] == '"') { /* Immediate string */
ret = __parse_imm_string(arg + 2, &tmp, offs + 2); ret = __parse_imm_string(arg + 2, &tmp, ctx->offset + 2);
if (ret) if (ret)
break; break;
code->op = FETCH_OP_DATA; code->op = FETCH_OP_DATA;
@@ -523,7 +565,7 @@ parse_probe_arg(char *arg, const struct fetch_type *type,
} else { } else {
ret = str_to_immediate(arg + 1, &code->immediate); ret = str_to_immediate(arg + 1, &code->immediate);
if (ret) if (ret)
trace_probe_log_err(offs + 1, BAD_IMM); trace_probe_log_err(ctx->offset + 1, BAD_IMM);
else else
code->op = FETCH_OP_IMM; code->op = FETCH_OP_IMM;
} }
@@ -531,7 +573,7 @@ parse_probe_arg(char *arg, const struct fetch_type *type,
} }
if (!ret && code->op == FETCH_OP_NOP) { if (!ret && code->op == FETCH_OP_NOP) {
/* Parsed, but do not find fetch method */ /* Parsed, but do not find fetch method */
trace_probe_log_err(offs, BAD_FETCH_ARG); trace_probe_log_err(ctx->offset, BAD_FETCH_ARG);
ret = -EINVAL; ret = -EINVAL;
} }
return ret; return ret;
@@ -576,12 +618,13 @@ static int __parse_bitfield_probe_arg(const char *bf,
/* String length checking wrapper */ /* String length checking wrapper */
static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
struct probe_arg *parg, unsigned int flags, int offset) struct probe_arg *parg,
struct traceprobe_parse_context *ctx)
{ {
struct fetch_insn *code, *scode, *tmp = NULL; struct fetch_insn *code, *scode, *tmp = NULL;
char *t, *t2, *t3; char *t, *t2, *t3;
char *arg;
int ret, len; int ret, len;
char *arg;
arg = kstrdup(argv, GFP_KERNEL); arg = kstrdup(argv, GFP_KERNEL);
if (!arg) if (!arg)
@@ -590,10 +633,10 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
ret = -EINVAL; ret = -EINVAL;
len = strlen(arg); len = strlen(arg);
if (len > MAX_ARGSTR_LEN) { if (len > MAX_ARGSTR_LEN) {
trace_probe_log_err(offset, ARG_TOO_LONG); trace_probe_log_err(ctx->offset, ARG_TOO_LONG);
goto out; goto out;
} else if (len == 0) { } else if (len == 0) {
trace_probe_log_err(offset, NO_ARG_BODY); trace_probe_log_err(ctx->offset, NO_ARG_BODY);
goto out; goto out;
} }
@@ -611,23 +654,24 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
*t2++ = '\0'; *t2++ = '\0';
t3 = strchr(t2, ']'); t3 = strchr(t2, ']');
if (!t3) { if (!t3) {
offset += t2 + strlen(t2) - arg; int offs = t2 + strlen(t2) - arg;
trace_probe_log_err(offset,
trace_probe_log_err(ctx->offset + offs,
ARRAY_NO_CLOSE); ARRAY_NO_CLOSE);
goto out; goto out;
} else if (t3[1] != '\0') { } else if (t3[1] != '\0') {
trace_probe_log_err(offset + t3 + 1 - arg, trace_probe_log_err(ctx->offset + t3 + 1 - arg,
BAD_ARRAY_SUFFIX); BAD_ARRAY_SUFFIX);
goto out; goto out;
} }
*t3 = '\0'; *t3 = '\0';
if (kstrtouint(t2, 0, &parg->count) || !parg->count) { if (kstrtouint(t2, 0, &parg->count) || !parg->count) {
trace_probe_log_err(offset + t2 - arg, trace_probe_log_err(ctx->offset + t2 - arg,
BAD_ARRAY_NUM); BAD_ARRAY_NUM);
goto out; goto out;
} }
if (parg->count > MAX_ARRAY_LEN) { if (parg->count > MAX_ARRAY_LEN) {
trace_probe_log_err(offset + t2 - arg, trace_probe_log_err(ctx->offset + t2 - arg,
ARRAY_TOO_BIG); ARRAY_TOO_BIG);
goto out; goto out;
} }
@@ -638,17 +682,17 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
* Since $comm and immediate string can not be dereferenced, * Since $comm and immediate string can not be dereferenced,
* we can find those by strcmp. But ignore for eprobes. * we can find those by strcmp. But ignore for eprobes.
*/ */
if (!(flags & TPARG_FL_TEVENT) && if (!(ctx->flags & TPARG_FL_TEVENT) &&
(strcmp(arg, "$comm") == 0 || strcmp(arg, "$COMM") == 0 || (strcmp(arg, "$comm") == 0 || strcmp(arg, "$COMM") == 0 ||
strncmp(arg, "\\\"", 2) == 0)) { strncmp(arg, "\\\"", 2) == 0)) {
/* The type of $comm must be "string", and not an array. */ /* The type of $comm must be "string", and not an array. */
if (parg->count || (t && strcmp(t, "string"))) if (parg->count || (t && strcmp(t, "string")))
goto out; goto out;
parg->type = find_fetch_type("string", flags); parg->type = find_fetch_type("string", ctx->flags);
} else } else
parg->type = find_fetch_type(t, flags); parg->type = find_fetch_type(t, ctx->flags);
if (!parg->type) { if (!parg->type) {
trace_probe_log_err(offset + (t ? (t - arg) : 0), BAD_TYPE); trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0), BAD_TYPE);
goto out; goto out;
} }
parg->offset = *size; parg->offset = *size;
@@ -670,7 +714,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
code[FETCH_INSN_MAX - 1].op = FETCH_OP_END; code[FETCH_INSN_MAX - 1].op = FETCH_OP_END;
ret = parse_probe_arg(arg, parg->type, &code, &code[FETCH_INSN_MAX - 1], ret = parse_probe_arg(arg, parg->type, &code, &code[FETCH_INSN_MAX - 1],
flags, offset); ctx);
if (ret) if (ret)
goto fail; goto fail;
@@ -681,7 +725,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
if (code->op != FETCH_OP_REG && code->op != FETCH_OP_STACK && if (code->op != FETCH_OP_REG && code->op != FETCH_OP_STACK &&
code->op != FETCH_OP_RETVAL && code->op != FETCH_OP_ARG && code->op != FETCH_OP_RETVAL && code->op != FETCH_OP_ARG &&
code->op != FETCH_OP_DEREF && code->op != FETCH_OP_TP_ARG) { code->op != FETCH_OP_DEREF && code->op != FETCH_OP_TP_ARG) {
trace_probe_log_err(offset + (t ? (t - arg) : 0), trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0),
BAD_SYMSTRING); BAD_SYMSTRING);
goto fail; goto fail;
} }
@@ -689,7 +733,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
if (code->op != FETCH_OP_DEREF && code->op != FETCH_OP_UDEREF && if (code->op != FETCH_OP_DEREF && code->op != FETCH_OP_UDEREF &&
code->op != FETCH_OP_IMM && code->op != FETCH_OP_COMM && code->op != FETCH_OP_IMM && code->op != FETCH_OP_COMM &&
code->op != FETCH_OP_DATA && code->op != FETCH_OP_TP_ARG) { code->op != FETCH_OP_DATA && code->op != FETCH_OP_TP_ARG) {
trace_probe_log_err(offset + (t ? (t - arg) : 0), trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0),
BAD_STRING); BAD_STRING);
goto fail; goto fail;
} }
@@ -708,7 +752,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
*/ */
code++; code++;
if (code->op != FETCH_OP_NOP) { if (code->op != FETCH_OP_NOP) {
trace_probe_log_err(offset, TOO_MANY_OPS); trace_probe_log_err(ctx->offset, TOO_MANY_OPS);
goto fail; goto fail;
} }
} }
@@ -731,7 +775,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
} else { } else {
code++; code++;
if (code->op != FETCH_OP_NOP) { if (code->op != FETCH_OP_NOP) {
trace_probe_log_err(offset, TOO_MANY_OPS); trace_probe_log_err(ctx->offset, TOO_MANY_OPS);
goto fail; goto fail;
} }
code->op = FETCH_OP_ST_RAW; code->op = FETCH_OP_ST_RAW;
@@ -742,7 +786,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
if (t != NULL) { if (t != NULL) {
ret = __parse_bitfield_probe_arg(t, parg->type, &code); ret = __parse_bitfield_probe_arg(t, parg->type, &code);
if (ret) { if (ret) {
trace_probe_log_err(offset + t - arg, BAD_BITFIELD); trace_probe_log_err(ctx->offset + t - arg, BAD_BITFIELD);
goto fail; goto fail;
} }
} }
@@ -752,13 +796,13 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
if (scode->op != FETCH_OP_ST_MEM && if (scode->op != FETCH_OP_ST_MEM &&
scode->op != FETCH_OP_ST_STRING && scode->op != FETCH_OP_ST_STRING &&
scode->op != FETCH_OP_ST_USTRING) { scode->op != FETCH_OP_ST_USTRING) {
trace_probe_log_err(offset + (t ? (t - arg) : 0), trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0),
BAD_STRING); BAD_STRING);
goto fail; goto fail;
} }
code++; code++;
if (code->op != FETCH_OP_NOP) { if (code->op != FETCH_OP_NOP) {
trace_probe_log_err(offset, TOO_MANY_OPS); trace_probe_log_err(ctx->offset, TOO_MANY_OPS);
goto fail; goto fail;
} }
code->op = FETCH_OP_LP_ARRAY; code->op = FETCH_OP_LP_ARRAY;
@@ -807,7 +851,7 @@ static int traceprobe_conflict_field_name(const char *name,
} }
int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, const char *arg, int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, const char *arg,
unsigned int flags) struct traceprobe_parse_context *ctx)
{ {
struct probe_arg *parg = &tp->args[i]; struct probe_arg *parg = &tp->args[i];
const char *body; const char *body;
@@ -842,9 +886,9 @@ int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, const char *arg,
trace_probe_log_err(0, USED_ARG_NAME); trace_probe_log_err(0, USED_ARG_NAME);
return -EINVAL; return -EINVAL;
} }
ctx->offset = body - arg;
/* Parse fetch argument */ /* Parse fetch argument */
return traceprobe_parse_probe_arg_body(body, &tp->size, parg, flags, return traceprobe_parse_probe_arg_body(body, &tp->size, parg, ctx);
body - arg);
} }
void traceprobe_free_probe_arg(struct probe_arg *arg) void traceprobe_free_probe_arg(struct probe_arg *arg)

View File

@@ -378,8 +378,15 @@ static inline bool tparg_is_function_entry(unsigned int flags)
return (flags & TPARG_FL_LOC_MASK) == (TPARG_FL_KERNEL | TPARG_FL_FENTRY); return (flags & TPARG_FL_LOC_MASK) == (TPARG_FL_KERNEL | TPARG_FL_FENTRY);
} }
struct traceprobe_parse_context {
struct trace_event_call *event;
unsigned int flags;
int offset;
};
extern int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, extern int traceprobe_parse_probe_arg(struct trace_probe *tp, int i,
const char *argv, unsigned int flags); const char *argv,
struct traceprobe_parse_context *ctx);
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);

View File

@@ -686,10 +686,12 @@ static int __trace_uprobe_create(int argc, const char **argv)
/* parse arguments */ /* parse arguments */
for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) { for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
struct traceprobe_parse_context ctx = {
.flags = (is_return ? TPARG_FL_RETURN : 0) | TPARG_FL_USER,
};
trace_probe_log_set_index(i + 2); trace_probe_log_set_index(i + 2);
ret = traceprobe_parse_probe_arg(&tu->tp, i, argv[i], ret = traceprobe_parse_probe_arg(&tu->tp, i, argv[i], &ctx);
(is_return ? TPARG_FL_RETURN : 0) |
TPARG_FL_USER);
if (ret) if (ret)
goto error; goto error;
} }