Skip to content

Commit 6218bf9

Browse files
mhiramatrostedt
authored andcommitted
tracing/probe: Add immediate parameter support
Add immediate value parameter (\1234) support to probe events. This allows you to specify an immediate (or dummy) parameter instead of fetching from memory or register. This feature looks odd, but imagine when you put a probe on a code to trace some data. If the code is compiled into 2 instructions and 1 instruction has a value but other has nothing since it is optimized out. In that case, you can not fold those into one event, even if ftrace supported multiple probes on one event. With this feature, you can set a dummy value like foo=\deadbeef instead of something like foo=%di. Link: http://lkml.kernel.org/r/156095690733.28024.13258186548822649469.stgit@devnote2 Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent ab10d69 commit 6218bf9

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

Documentation/trace/kprobetrace.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Synopsis of kprobe_events
5252
$retval : Fetch return value.(\*2)
5353
$comm : Fetch current task comm.
5454
+|-[u]OFFS(FETCHARG) : Fetch memory at FETCHARG +|- OFFS address.(\*3)(\*4)
55+
\IMM : Store an immediate value to the argument.
5556
NAME=FETCHARG : Set NAME as the argument name of FETCHARG.
5657
FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types
5758
(u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal types

Documentation/trace/uprobetracer.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Synopsis of uprobe_tracer
4545
$retval : Fetch return value.(\*1)
4646
$comm : Fetch current task comm.
4747
+|-[u]OFFS(FETCHARG) : Fetch memory at FETCHARG +|- OFFS address.(\*2)(\*3)
48+
\IMM : Store an immediate value to the argument.
4849
NAME=FETCHARG : Set NAME as the argument name of FETCHARG.
4950
FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types
5051
(u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal types

kernel/trace/trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4848,7 +4848,7 @@ static const char readme_msg[] =
48484848
#else
48494849
"\t $stack<index>, $stack, $retval, $comm,\n"
48504850
#endif
4851-
"\t +|-[u]<offset>(<fetcharg>)\n"
4851+
"\t +|-[u]<offset>(<fetcharg>), \\imm-value\n"
48524852
"\t type: s8/16/32/64, u8/16/32/64, x8/16/32/64, string, symbol,\n"
48534853
"\t b<bit-width>@<bit-offset>/<container-size>, ustring,\n"
48544854
"\t <type>\\[<array-size>\\]\n"

kernel/trace/trace_probe.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,17 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t,
316316
return -EINVAL;
317317
}
318318

319+
static int str_to_immediate(char *str, unsigned long *imm)
320+
{
321+
if (isdigit(str[0]))
322+
return kstrtoul(str, 0, imm);
323+
else if (str[0] == '-')
324+
return kstrtol(str, 0, (long *)imm);
325+
else if (str[0] == '+')
326+
return kstrtol(str + 1, 0, (long *)imm);
327+
return -EINVAL;
328+
}
329+
319330
/* Recursive argument parser */
320331
static int
321332
parse_probe_arg(char *arg, const struct fetch_type *type,
@@ -444,6 +455,13 @@ parse_probe_arg(char *arg, const struct fetch_type *type,
444455
code->offset = offset;
445456
}
446457
break;
458+
case '\\': /* Immediate value */
459+
ret = str_to_immediate(arg + 1, &code->immediate);
460+
if (ret)
461+
trace_probe_log_err(offs + 1, BAD_IMM);
462+
else
463+
code->op = FETCH_OP_IMM;
464+
break;
447465
}
448466
if (!ret && code->op == FETCH_OP_NOP) {
449467
/* Parsed, but do not find fetch method */

kernel/trace/trace_probe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,
408408
C(BAD_VAR, "Invalid $-valiable specified"), \
409409
C(BAD_REG_NAME, "Invalid register name"), \
410410
C(BAD_MEM_ADDR, "Invalid memory address"), \
411+
C(BAD_IMM, "Invalid immediate value"), \
411412
C(FILE_ON_KPROBE, "File offset is not available with kprobe"), \
412413
C(BAD_FILE_OFFS, "Invalid file offset value"), \
413414
C(SYM_ON_UPROBE, "Symbol is not available with uprobe"), \

0 commit comments

Comments
 (0)