Skip to content

Commit 56de763

Browse files
mhiramatrostedt
authored andcommitted
tracing: probeevent: Cleanup print argument functions
Cleanup the print-argument function to decouple it into print-name and print-value, so that it can support more flexible expression, like array type. Link: http://lkml.kernel.org/r/152465859635.26224.13452846788717102315.stgit@devbox Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent a6ca88b commit 56de763

File tree

4 files changed

+29
-31
lines changed

4 files changed

+29
-31
lines changed

kernel/trace/trace_kprobe.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,8 +1136,6 @@ print_kprobe_event(struct trace_iterator *iter, int flags,
11361136
struct kprobe_trace_entry_head *field;
11371137
struct trace_seq *s = &iter->seq;
11381138
struct trace_probe *tp;
1139-
u8 *data;
1140-
int i;
11411139

11421140
field = (struct kprobe_trace_entry_head *)iter->ent;
11431141
tp = container_of(event, struct trace_probe, call.event);
@@ -1149,11 +1147,9 @@ print_kprobe_event(struct trace_iterator *iter, int flags,
11491147

11501148
trace_seq_putc(s, ')');
11511149

1152-
data = (u8 *)&field[1];
1153-
for (i = 0; i < tp->nr_args; i++)
1154-
if (!tp->args[i].type->print(s, tp->args[i].name,
1155-
data + tp->args[i].offset, field))
1156-
goto out;
1150+
if (print_probe_args(s, tp->args, tp->nr_args,
1151+
(u8 *)&field[1], field) < 0)
1152+
goto out;
11571153

11581154
trace_seq_putc(s, '\n');
11591155
out:
@@ -1167,8 +1163,6 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,
11671163
struct kretprobe_trace_entry_head *field;
11681164
struct trace_seq *s = &iter->seq;
11691165
struct trace_probe *tp;
1170-
u8 *data;
1171-
int i;
11721166

11731167
field = (struct kretprobe_trace_entry_head *)iter->ent;
11741168
tp = container_of(event, struct trace_probe, call.event);
@@ -1185,11 +1179,9 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,
11851179

11861180
trace_seq_putc(s, ')');
11871181

1188-
data = (u8 *)&field[1];
1189-
for (i = 0; i < tp->nr_args; i++)
1190-
if (!tp->args[i].type->print(s, tp->args[i].name,
1191-
data + tp->args[i].offset, field))
1192-
goto out;
1182+
if (print_probe_args(s, tp->args, tp->nr_args,
1183+
(u8 *)&field[1], field) < 0)
1184+
goto out;
11931185

11941186
trace_seq_putc(s, '\n');
11951187

kernel/trace/trace_probe.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ const char *reserved_field_names[] = {
2626

2727
/* Printing in basic type function template */
2828
#define DEFINE_BASIC_PRINT_TYPE_FUNC(tname, type, fmt) \
29-
int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, const char *name, \
30-
void *data, void *ent) \
29+
int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, void *data, void *ent)\
3130
{ \
32-
trace_seq_printf(s, " %s=" fmt, name, *(type *)data); \
31+
trace_seq_printf(s, fmt, *(type *)data); \
3332
return !trace_seq_has_overflowed(s); \
3433
} \
3534
const char PRINT_TYPE_FMT_NAME(tname)[] = fmt; \
@@ -49,15 +48,14 @@ DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x")
4948
DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx")
5049

5150
/* Print type function for string type */
52-
int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, const char *name,
53-
void *data, void *ent)
51+
int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, void *data, void *ent)
5452
{
5553
int len = *(u32 *)data >> 16;
5654

5755
if (!len)
58-
trace_seq_printf(s, " %s=(fault)", name);
56+
trace_seq_puts(s, "(fault)");
5957
else
60-
trace_seq_printf(s, " %s=\"%s\"", name,
58+
trace_seq_printf(s, "\"%s\"",
6159
(const char *)get_loc_data(data, ent));
6260
return !trace_seq_has_overflowed(s);
6361
}

kernel/trace/trace_probe.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static nokprobe_inline void *get_loc_data(u32 *dl, void *ent)
8282
/* Data fetch function type */
8383
typedef void (*fetch_func_t)(struct pt_regs *, void *, void *);
8484
/* Printing function type */
85-
typedef int (*print_type_func_t)(struct trace_seq *, const char *, void *, void *);
85+
typedef int (*print_type_func_t)(struct trace_seq *, void *, void *);
8686

8787
/* Fetch types */
8888
enum {
@@ -124,8 +124,7 @@ typedef u32 string_size;
124124

125125
/* Printing in basic type function template */
126126
#define DECLARE_BASIC_PRINT_TYPE_FUNC(type) \
127-
int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, const char *name, \
128-
void *data, void *ent); \
127+
int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, void *data, void *ent);\
129128
extern const char PRINT_TYPE_FMT_NAME(type)[]
130129

131130
DECLARE_BASIC_PRINT_TYPE_FUNC(u8);
@@ -403,6 +402,20 @@ store_trace_args(int ent_size, struct trace_probe *tp, struct pt_regs *regs,
403402
}
404403
}
405404

405+
static inline int
406+
print_probe_args(struct trace_seq *s, struct probe_arg *args, int nr_args,
407+
u8 *data, void *field)
408+
{
409+
int i;
410+
411+
for (i = 0; i < nr_args; i++) {
412+
trace_seq_printf(s, " %s=", args[i].name);
413+
if (!args[i].type->print(s, data + args[i].offset, field))
414+
return -ENOMEM;
415+
}
416+
return 0;
417+
}
418+
406419
extern int set_print_fmt(struct trace_probe *tp, bool is_return);
407420

408421
#ifdef CONFIG_PERF_EVENTS

kernel/trace/trace_uprobe.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,6 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e
892892
struct trace_seq *s = &iter->seq;
893893
struct trace_uprobe *tu;
894894
u8 *data;
895-
int i;
896895

897896
entry = (struct uprobe_trace_entry_head *)iter->ent;
898897
tu = container_of(event, struct trace_uprobe, tp.call.event);
@@ -909,12 +908,8 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e
909908
data = DATAOF_TRACE_ENTRY(entry, false);
910909
}
911910

912-
for (i = 0; i < tu->tp.nr_args; i++) {
913-
struct probe_arg *parg = &tu->tp.args[i];
914-
915-
if (!parg->type->print(s, parg->name, data + parg->offset, entry))
916-
goto out;
917-
}
911+
if (print_probe_args(s, tu->tp.args, tu->tp.nr_args, data, entry) < 0)
912+
goto out;
918913

919914
trace_seq_putc(s, '\n');
920915

0 commit comments

Comments
 (0)