diff options
author | Masami Hiramatsu <mhiramat@kernel.org> | 2018-04-25 08:16:36 -0400 |
---|---|---|
committer | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2018-10-10 22:19:06 -0400 |
commit | 56de763052792669d61d79a087611da9a7f04d4e (patch) | |
tree | 087acf36262ac16db4e522adb472a3b0e63c1959 | |
parent | a6ca88b241d5e929e6e60b12ad8cd288f0ffa256 (diff) |
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>
-rw-r--r-- | kernel/trace/trace_kprobe.c | 20 | ||||
-rw-r--r-- | kernel/trace/trace_probe.c | 12 | ||||
-rw-r--r-- | kernel/trace/trace_probe.h | 19 | ||||
-rw-r--r-- | kernel/trace/trace_uprobe.c | 9 |
4 files changed, 29 insertions, 31 deletions
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 508396edc56a..6326c71181aa 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c | |||
@@ -1136,8 +1136,6 @@ print_kprobe_event(struct trace_iterator *iter, int flags, | |||
1136 | struct kprobe_trace_entry_head *field; | 1136 | struct kprobe_trace_entry_head *field; |
1137 | struct trace_seq *s = &iter->seq; | 1137 | struct trace_seq *s = &iter->seq; |
1138 | struct trace_probe *tp; | 1138 | struct trace_probe *tp; |
1139 | u8 *data; | ||
1140 | int i; | ||
1141 | 1139 | ||
1142 | field = (struct kprobe_trace_entry_head *)iter->ent; | 1140 | field = (struct kprobe_trace_entry_head *)iter->ent; |
1143 | tp = container_of(event, struct trace_probe, call.event); | 1141 | tp = container_of(event, struct trace_probe, call.event); |
@@ -1149,11 +1147,9 @@ print_kprobe_event(struct trace_iterator *iter, int flags, | |||
1149 | 1147 | ||
1150 | trace_seq_putc(s, ')'); | 1148 | trace_seq_putc(s, ')'); |
1151 | 1149 | ||
1152 | data = (u8 *)&field[1]; | 1150 | if (print_probe_args(s, tp->args, tp->nr_args, |
1153 | for (i = 0; i < tp->nr_args; i++) | 1151 | (u8 *)&field[1], field) < 0) |
1154 | if (!tp->args[i].type->print(s, tp->args[i].name, | 1152 | goto out; |
1155 | data + tp->args[i].offset, field)) | ||
1156 | goto out; | ||
1157 | 1153 | ||
1158 | trace_seq_putc(s, '\n'); | 1154 | trace_seq_putc(s, '\n'); |
1159 | out: | 1155 | out: |
@@ -1167,8 +1163,6 @@ print_kretprobe_event(struct trace_iterator *iter, int flags, | |||
1167 | struct kretprobe_trace_entry_head *field; | 1163 | struct kretprobe_trace_entry_head *field; |
1168 | struct trace_seq *s = &iter->seq; | 1164 | struct trace_seq *s = &iter->seq; |
1169 | struct trace_probe *tp; | 1165 | struct trace_probe *tp; |
1170 | u8 *data; | ||
1171 | int i; | ||
1172 | 1166 | ||
1173 | field = (struct kretprobe_trace_entry_head *)iter->ent; | 1167 | field = (struct kretprobe_trace_entry_head *)iter->ent; |
1174 | tp = container_of(event, struct trace_probe, call.event); | 1168 | tp = container_of(event, struct trace_probe, call.event); |
@@ -1185,11 +1179,9 @@ print_kretprobe_event(struct trace_iterator *iter, int flags, | |||
1185 | 1179 | ||
1186 | trace_seq_putc(s, ')'); | 1180 | trace_seq_putc(s, ')'); |
1187 | 1181 | ||
1188 | data = (u8 *)&field[1]; | 1182 | if (print_probe_args(s, tp->args, tp->nr_args, |
1189 | for (i = 0; i < tp->nr_args; i++) | 1183 | (u8 *)&field[1], field) < 0) |
1190 | if (!tp->args[i].type->print(s, tp->args[i].name, | 1184 | goto out; |
1191 | data + tp->args[i].offset, field)) | ||
1192 | goto out; | ||
1193 | 1185 | ||
1194 | trace_seq_putc(s, '\n'); | 1186 | trace_seq_putc(s, '\n'); |
1195 | 1187 | ||
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index e99c3ce7aa65..e2c184eaa7db 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c | |||
@@ -26,10 +26,9 @@ const char *reserved_field_names[] = { | |||
26 | 26 | ||
27 | /* Printing in basic type function template */ | 27 | /* Printing in basic type function template */ |
28 | #define DEFINE_BASIC_PRINT_TYPE_FUNC(tname, type, fmt) \ | 28 | #define DEFINE_BASIC_PRINT_TYPE_FUNC(tname, type, fmt) \ |
29 | int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, const char *name, \ | 29 | int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, void *data, void *ent)\ |
30 | void *data, void *ent) \ | ||
31 | { \ | 30 | { \ |
32 | trace_seq_printf(s, " %s=" fmt, name, *(type *)data); \ | 31 | trace_seq_printf(s, fmt, *(type *)data); \ |
33 | return !trace_seq_has_overflowed(s); \ | 32 | return !trace_seq_has_overflowed(s); \ |
34 | } \ | 33 | } \ |
35 | const char PRINT_TYPE_FMT_NAME(tname)[] = fmt; \ | 34 | const char PRINT_TYPE_FMT_NAME(tname)[] = fmt; \ |
@@ -49,15 +48,14 @@ DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x") | |||
49 | DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx") | 48 | DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx") |
50 | 49 | ||
51 | /* Print type function for string type */ | 50 | /* Print type function for string type */ |
52 | int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, const char *name, | 51 | int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, void *data, void *ent) |
53 | void *data, void *ent) | ||
54 | { | 52 | { |
55 | int len = *(u32 *)data >> 16; | 53 | int len = *(u32 *)data >> 16; |
56 | 54 | ||
57 | if (!len) | 55 | if (!len) |
58 | trace_seq_printf(s, " %s=(fault)", name); | 56 | trace_seq_puts(s, "(fault)"); |
59 | else | 57 | else |
60 | trace_seq_printf(s, " %s=\"%s\"", name, | 58 | trace_seq_printf(s, "\"%s\"", |
61 | (const char *)get_loc_data(data, ent)); | 59 | (const char *)get_loc_data(data, ent)); |
62 | return !trace_seq_has_overflowed(s); | 60 | return !trace_seq_has_overflowed(s); |
63 | } | 61 | } |
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index 03b10f3201a5..8254a061ac35 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h | |||
@@ -82,7 +82,7 @@ static nokprobe_inline void *get_loc_data(u32 *dl, void *ent) | |||
82 | /* Data fetch function type */ | 82 | /* Data fetch function type */ |
83 | typedef void (*fetch_func_t)(struct pt_regs *, void *, void *); | 83 | typedef void (*fetch_func_t)(struct pt_regs *, void *, void *); |
84 | /* Printing function type */ | 84 | /* 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 *); |
86 | 86 | ||
87 | /* Fetch types */ | 87 | /* Fetch types */ |
88 | enum { | 88 | enum { |
@@ -124,8 +124,7 @@ typedef u32 string_size; | |||
124 | 124 | ||
125 | /* Printing in basic type function template */ | 125 | /* Printing in basic type function template */ |
126 | #define DECLARE_BASIC_PRINT_TYPE_FUNC(type) \ | 126 | #define DECLARE_BASIC_PRINT_TYPE_FUNC(type) \ |
127 | int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, const char *name, \ | 127 | int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, void *data, void *ent);\ |
128 | void *data, void *ent); \ | ||
129 | extern const char PRINT_TYPE_FMT_NAME(type)[] | 128 | extern const char PRINT_TYPE_FMT_NAME(type)[] |
130 | 129 | ||
131 | DECLARE_BASIC_PRINT_TYPE_FUNC(u8); | 130 | DECLARE_BASIC_PRINT_TYPE_FUNC(u8); |
@@ -403,6 +402,20 @@ store_trace_args(int ent_size, struct trace_probe *tp, struct pt_regs *regs, | |||
403 | } | 402 | } |
404 | } | 403 | } |
405 | 404 | ||
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 | |||
406 | extern int set_print_fmt(struct trace_probe *tp, bool is_return); | 419 | extern int set_print_fmt(struct trace_probe *tp, bool is_return); |
407 | 420 | ||
408 | #ifdef CONFIG_PERF_EVENTS | 421 | #ifdef CONFIG_PERF_EVENTS |
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index d09638706fe0..c55753e1079e 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c | |||
@@ -892,7 +892,6 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e | |||
892 | struct trace_seq *s = &iter->seq; | 892 | struct trace_seq *s = &iter->seq; |
893 | struct trace_uprobe *tu; | 893 | struct trace_uprobe *tu; |
894 | u8 *data; | 894 | u8 *data; |
895 | int i; | ||
896 | 895 | ||
897 | entry = (struct uprobe_trace_entry_head *)iter->ent; | 896 | entry = (struct uprobe_trace_entry_head *)iter->ent; |
898 | tu = container_of(event, struct trace_uprobe, tp.call.event); | 897 | 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 | |||
909 | data = DATAOF_TRACE_ENTRY(entry, false); | 908 | data = DATAOF_TRACE_ENTRY(entry, false); |
910 | } | 909 | } |
911 | 910 | ||
912 | for (i = 0; i < tu->tp.nr_args; i++) { | 911 | if (print_probe_args(s, tu->tp.args, tu->tp.nr_args, data, entry) < 0) |
913 | struct probe_arg *parg = &tu->tp.args[i]; | 912 | goto out; |
914 | |||
915 | if (!parg->type->print(s, parg->name, data + parg->offset, entry)) | ||
916 | goto out; | ||
917 | } | ||
918 | 913 | ||
919 | trace_seq_putc(s, '\n'); | 914 | trace_seq_putc(s, '\n'); |
920 | 915 | ||