Skip to content

Commit 007517a

Browse files
committed
tracing/probe: Change traceprobe_set_print_fmt() to take a type
Instead of a boolean "is_return" have traceprobe_set_print_fmt() take a type (currently just PROBE_PRINT_NORMAL and PROBE_PRINT_RETURN). This will simplify adding different types. For example, the development of the event_probe, will need its own type as it prints an event, and not an IP. Link: https://lkml.kernel.org/r/[email protected] Acked-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 845cbf3 commit 007517a

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

kernel/trace/trace_kprobe.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ static int __trace_kprobe_create(int argc, const char *argv[])
742742
bool is_return = false;
743743
char *symbol = NULL, *tmp = NULL;
744744
const char *event = NULL, *group = KPROBE_EVENT_SYSTEM;
745+
enum probe_print_type ptype;
745746
int maxactive = 0;
746747
long offset = 0;
747748
void *addr = NULL;
@@ -875,7 +876,8 @@ static int __trace_kprobe_create(int argc, const char *argv[])
875876
goto error; /* This can be -ENOMEM */
876877
}
877878

878-
ret = traceprobe_set_print_fmt(&tk->tp, is_return);
879+
ptype = is_return ? PROBE_PRINT_RETURN : PROBE_PRINT_NORMAL;
880+
ret = traceprobe_set_print_fmt(&tk->tp, ptype);
879881
if (ret < 0)
880882
goto error;
881883

@@ -1799,6 +1801,7 @@ struct trace_event_call *
17991801
create_local_trace_kprobe(char *func, void *addr, unsigned long offs,
18001802
bool is_return)
18011803
{
1804+
enum probe_print_type ptype;
18021805
struct trace_kprobe *tk;
18031806
int ret;
18041807
char *event;
@@ -1822,7 +1825,9 @@ create_local_trace_kprobe(char *func, void *addr, unsigned long offs,
18221825

18231826
init_trace_event_call(tk);
18241827

1825-
if (traceprobe_set_print_fmt(&tk->tp, trace_kprobe_is_return(tk)) < 0) {
1828+
ptype = trace_kprobe_is_return(tk) ?
1829+
PROBE_PRINT_RETURN : PROBE_PRINT_NORMAL;
1830+
if (traceprobe_set_print_fmt(&tk->tp, ptype) < 0) {
18261831
ret = -ENOMEM;
18271832
goto error;
18281833
}

kernel/trace/trace_probe.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -851,19 +851,25 @@ int traceprobe_update_arg(struct probe_arg *arg)
851851
/* When len=0, we just calculate the needed length */
852852
#define LEN_OR_ZERO (len ? len - pos : 0)
853853
static int __set_print_fmt(struct trace_probe *tp, char *buf, int len,
854-
bool is_return)
854+
enum probe_print_type ptype)
855855
{
856856
struct probe_arg *parg;
857857
int i, j;
858858
int pos = 0;
859859
const char *fmt, *arg;
860860

861-
if (!is_return) {
861+
switch (ptype) {
862+
case PROBE_PRINT_NORMAL:
862863
fmt = "(%lx)";
863864
arg = "REC->" FIELD_STRING_IP;
864-
} else {
865+
break;
866+
case PROBE_PRINT_RETURN:
865867
fmt = "(%lx <- %lx)";
866868
arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
869+
break;
870+
default:
871+
WARN_ON_ONCE(1);
872+
return 0;
867873
}
868874

869875
pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt);
@@ -912,20 +918,20 @@ static int __set_print_fmt(struct trace_probe *tp, char *buf, int len,
912918
}
913919
#undef LEN_OR_ZERO
914920

915-
int traceprobe_set_print_fmt(struct trace_probe *tp, bool is_return)
921+
int traceprobe_set_print_fmt(struct trace_probe *tp, enum probe_print_type ptype)
916922
{
917923
struct trace_event_call *call = trace_probe_event_call(tp);
918924
int len;
919925
char *print_fmt;
920926

921927
/* First: called with 0 length to calculate the needed length */
922-
len = __set_print_fmt(tp, NULL, 0, is_return);
928+
len = __set_print_fmt(tp, NULL, 0, ptype);
923929
print_fmt = kmalloc(len + 1, GFP_KERNEL);
924930
if (!print_fmt)
925931
return -ENOMEM;
926932

927933
/* Second: actually write the @print_fmt */
928-
__set_print_fmt(tp, print_fmt, len + 1, is_return);
934+
__set_print_fmt(tp, print_fmt, len + 1, ptype);
929935
call->print_fmt = print_fmt;
930936

931937
return 0;

kernel/trace/trace_probe.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,12 @@ extern int traceprobe_split_symbol_offset(char *symbol, long *offset);
363363
int traceprobe_parse_event_name(const char **pevent, const char **pgroup,
364364
char *buf, int offset);
365365

366-
extern int traceprobe_set_print_fmt(struct trace_probe *tp, bool is_return);
366+
enum probe_print_type {
367+
PROBE_PRINT_NORMAL,
368+
PROBE_PRINT_RETURN,
369+
};
370+
371+
extern int traceprobe_set_print_fmt(struct trace_probe *tp, enum probe_print_type ptype);
367372

368373
#ifdef CONFIG_PERF_EVENTS
369374
extern struct trace_event_call *

kernel/trace/trace_uprobe.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ static int __trace_uprobe_create(int argc, const char **argv)
536536
const char *event = NULL, *group = UPROBE_EVENT_SYSTEM;
537537
char *arg, *filename, *rctr, *rctr_end, *tmp;
538538
char buf[MAX_EVENT_NAME_LEN];
539+
enum probe_print_type ptype;
539540
struct path path;
540541
unsigned long offset, ref_ctr_offset;
541542
bool is_return = false;
@@ -687,7 +688,8 @@ static int __trace_uprobe_create(int argc, const char **argv)
687688
goto error;
688689
}
689690

690-
ret = traceprobe_set_print_fmt(&tu->tp, is_ret_probe(tu));
691+
ptype = is_ret_probe(tu) ? PROBE_PRINT_RETURN : PROBE_PRINT_NORMAL;
692+
ret = traceprobe_set_print_fmt(&tu->tp, ptype);
691693
if (ret < 0)
692694
goto error;
693695

@@ -1578,6 +1580,7 @@ struct trace_event_call *
15781580
create_local_trace_uprobe(char *name, unsigned long offs,
15791581
unsigned long ref_ctr_offset, bool is_return)
15801582
{
1583+
enum probe_print_type ptype;
15811584
struct trace_uprobe *tu;
15821585
struct path path;
15831586
int ret;
@@ -1612,7 +1615,8 @@ create_local_trace_uprobe(char *name, unsigned long offs,
16121615
tu->filename = kstrdup(name, GFP_KERNEL);
16131616
init_trace_event_call(tu);
16141617

1615-
if (traceprobe_set_print_fmt(&tu->tp, is_ret_probe(tu)) < 0) {
1618+
ptype = is_ret_probe(tu) ? PROBE_PRINT_RETURN : PROBE_PRINT_NORMAL;
1619+
if (traceprobe_set_print_fmt(&tu->tp, ptype) < 0) {
16161620
ret = -ENOMEM;
16171621
goto error;
16181622
}

0 commit comments

Comments
 (0)