The set_print_fmt() functions are implemented almost same for [ku]probes. Move it to a common place and get rid of the duplication.
Showing the changes to kernel/trace (4 of 4 files). Show all
Unified · Split
| @@ -964,67 +964,6 @@ static int kretprobe_event_define_fields(struct ftrace_event_call *event_call) · 963 unmodified lines | ||
| 964 | 964 | return 0; |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | −static int __set_print_fmt(struct trace_kprobe *tk, char *buf, int len) | |
| 968 | −{ | |
| 969 | − int i; | |
| 970 | − int pos = 0; | |
| 971 | − | |
| 972 | − const char *fmt, *arg; | |
| 973 | − | |
| 974 | − if (!trace_kprobe_is_return(tk)) { | |
| 975 | − fmt = "(%lx)"; | |
| 976 | − arg = "REC->" FIELD_STRING_IP; | |
| 977 | − } else { | |
| 978 | − fmt = "(%lx <- %lx)"; | |
| 979 | − arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP; | |
| 980 | − } | |
| 981 | − | |
| 982 | − /* When len=0, we just calculate the needed length */ | |
| 983 | −#define LEN_OR_ZERO (len ? len - pos : 0) | |
| 984 | − | |
| 985 | − pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt); | |
| 986 | − | |
| 987 | − for (i = 0; i < tk->tp.nr_args; i++) { | |
| 988 | − pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%s", | |
| 989 | − tk->tp.args[i].name, tk->tp.args[i].type->fmt); | |
| 990 | − } | |
| 991 | − | |
| 992 | − pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg); | |
| 993 | − | |
| 994 | − for (i = 0; i < tk->tp.nr_args; i++) { | |
| 995 | − if (strcmp(tk->tp.args[i].type->name, "string") == 0) | |
| 996 | − pos += snprintf(buf + pos, LEN_OR_ZERO, | |
| 997 | − ", __get_str(%s)", | |
| 998 | − tk->tp.args[i].name); | |
| 999 | − else | |
| 1000 | − pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s", | |
| 1001 | − tk->tp.args[i].name); | |
| 1002 | − } | |
| 1003 | − | |
| 1004 | −#undef LEN_OR_ZERO | |
| 1005 | − | |
| 1006 | − /* return the length of print_fmt */ | |
| 1007 | − return pos; | |
| 1008 | −} | |
| 1009 | − | |
| 1010 | −static int set_print_fmt(struct trace_kprobe *tk) | |
| 1011 | −{ | |
| 1012 | − int len; | |
| 1013 | − char *print_fmt; | |
| 1014 | − | |
| 1015 | − /* First: called with 0 length to calculate the needed length */ | |
| 1016 | − len = __set_print_fmt(tk, NULL, 0); | |
| 1017 | − print_fmt = kmalloc(len + 1, GFP_KERNEL); | |
| 1018 | − if (!print_fmt) | |
| 1019 | − return -ENOMEM; | |
| 1020 | − | |
| 1021 | − /* Second: actually write the @print_fmt */ | |
| 1022 | − __set_print_fmt(tk, print_fmt, len + 1); | |
| 1023 | − tk->tp.call.print_fmt = print_fmt; | |
| 1024 | − | |
| 1025 | − return 0; | |
| 1026 | −} | |
| 1027 | − | |
| 1028 | 967 | #ifdef CONFIG_PERF_EVENTS |
| 1029 | 968 | |
| 1030 | 969 | /* Kprobe profile handler */ |
| @@ -1175,7 +1114,7 @@ static int register_kprobe_event(struct trace_kprobe *tk) · 144 unmodified lines | ||
| 1175 | 1114 | call->event.funcs = &kprobe_funcs; |
| 1176 | 1115 | call->class->define_fields = kprobe_event_define_fields; |
| 1177 | 1116 | } |
| 1178 | − if (set_print_fmt(tk) < 0) | |
| 1117 | + if (set_print_fmt(&tk->tp, trace_kprobe_is_return(tk)) < 0) | |
| 1179 | 1118 | return -ENOMEM; |
| 1180 | 1119 | ret = register_ftrace_event(&call->event); |
| 1181 | 1120 | if (!ret) { |
| @@ -837,3 +837,65 @@ out: · 836 unmodified lines | ||
| 837 | 837 | |
| 838 | 838 | return ret; |
| 839 | 839 | } |
| 840 | + | |
| 841 | +static int __set_print_fmt(struct trace_probe *tp, char *buf, int len, | |
| 842 | + bool is_return) | |
| 843 | +{ | |
| 844 | + int i; | |
| 845 | + int pos = 0; | |
| 846 | + | |
| 847 | + const char *fmt, *arg; | |
| 848 | + | |
| 849 | + if (!is_return) { | |
| 850 | + fmt = "(%lx)"; | |
| 851 | + arg = "REC->" FIELD_STRING_IP; | |
| 852 | + } else { | |
| 853 | + fmt = "(%lx <- %lx)"; | |
| 854 | + arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP; | |
| 855 | + } | |
| 856 | + | |
| 857 | + /* When len=0, we just calculate the needed length */ | |
| 858 | +#define LEN_OR_ZERO (len ? len - pos : 0) | |
| 859 | + | |
| 860 | + pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt); | |
| 861 | + | |
| 862 | + for (i = 0; i < tp->nr_args; i++) { | |
| 863 | + pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%s", | |
| 864 | + tp->args[i].name, tp->args[i].type->fmt); | |
| 865 | + } | |
| 866 | + | |
| 867 | + pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg); | |
| 868 | + | |
| 869 | + for (i = 0; i < tp->nr_args; i++) { | |
| 870 | + if (strcmp(tp->args[i].type->name, "string") == 0) | |
| 871 | + pos += snprintf(buf + pos, LEN_OR_ZERO, | |
| 872 | + ", __get_str(%s)", | |
| 873 | + tp->args[i].name); | |
| 874 | + else | |
| 875 | + pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s", | |
| 876 | + tp->args[i].name); | |
| 877 | + } | |
| 878 | + | |
| 879 | +#undef LEN_OR_ZERO | |
| 880 | + | |
| 881 | + /* return the length of print_fmt */ | |
| 882 | + return pos; | |
| 883 | +} | |
| 884 | + | |
| 885 | +int set_print_fmt(struct trace_probe *tp, bool is_return) | |
| 886 | +{ | |
| 887 | + int len; | |
| 888 | + char *print_fmt; | |
| 889 | + | |
| 890 | + /* First: called with 0 length to calculate the needed length */ | |
| 891 | + len = __set_print_fmt(tp, NULL, 0, is_return); | |
| 892 | + print_fmt = kmalloc(len + 1, GFP_KERNEL); | |
| 893 | + if (!print_fmt) | |
| 894 | + return -ENOMEM; | |
| 895 | + | |
| 896 | + /* Second: actually write the @print_fmt */ | |
| 897 | + __set_print_fmt(tp, print_fmt, len + 1, is_return); | |
| 898 | + tp->call.print_fmt = print_fmt; | |
| 899 | + | |
| 900 | + return 0; | |
| 901 | +} | |
| @@ -226,3 +226,5 @@ store_trace_args(int ent_size, struct trace_probe *tp, struct pt_regs *regs, · 225 unmodified lines | ||
| 226 | 226 | data + tp->args[i].offset); |
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | + | |
| 230 | +extern int set_print_fmt(struct trace_probe *tp, bool is_return); | |
| @@ -682,59 +682,6 @@ static int uprobe_event_define_fields(struct ftrace_event_call *event_call) · 681 unmodified lines | ||
| 682 | 682 | return 0; |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | −#define LEN_OR_ZERO (len ? len - pos : 0) | |
| 686 | −static int __set_print_fmt(struct trace_uprobe *tu, char *buf, int len) | |
| 687 | −{ | |
| 688 | − const char *fmt, *arg; | |
| 689 | − int i; | |
| 690 | − int pos = 0; | |
| 691 | − | |
| 692 | − if (is_ret_probe(tu)) { | |
| 693 | − fmt = "(%lx <- %lx)"; | |
| 694 | − arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP; | |
| 695 | − } else { | |
| 696 | − fmt = "(%lx)"; | |
| 697 | − arg = "REC->" FIELD_STRING_IP; | |
| 698 | − } | |
| 699 | − | |
| 700 | − /* When len=0, we just calculate the needed length */ | |
| 701 | − | |
| 702 | − pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt); | |
| 703 | − | |
| 704 | − for (i = 0; i < tu->tp.nr_args; i++) { | |
| 705 | − pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%s", | |
| 706 | − tu->tp.args[i].name, tu->tp.args[i].type->fmt); | |
| 707 | − } | |
| 708 | − | |
| 709 | − pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg); | |
| 710 | − | |
| 711 | − for (i = 0; i < tu->tp.nr_args; i++) { | |
| 712 | − pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s", | |
| 713 | − tu->tp.args[i].name); | |
| 714 | − } | |
| 715 | − | |
| 716 | − return pos; /* return the length of print_fmt */ | |
| 717 | −} | |
| 718 | −#undef LEN_OR_ZERO | |
| 719 | − | |
| 720 | −static int set_print_fmt(struct trace_uprobe *tu) | |
| 721 | −{ | |
| 722 | − char *print_fmt; | |
| 723 | − int len; | |
| 724 | − | |
| 725 | − /* First: called with 0 length to calculate the needed length */ | |
| 726 | − len = __set_print_fmt(tu, NULL, 0); | |
| 727 | − print_fmt = kmalloc(len + 1, GFP_KERNEL); | |
| 728 | − if (!print_fmt) | |
| 729 | − return -ENOMEM; | |
| 730 | − | |
| 731 | − /* Second: actually write the @print_fmt */ | |
| 732 | − __set_print_fmt(tu, print_fmt, len + 1); | |
| 733 | − tu->tp.call.print_fmt = print_fmt; | |
| 734 | − | |
| 735 | − return 0; | |
| 736 | −} | |
| 737 | − | |
| 738 | 685 | #ifdef CONFIG_PERF_EVENTS |
| 739 | 686 | static bool |
| 740 | 687 | __uprobe_perf_filter(struct trace_uprobe_filter *filter, struct mm_struct *mm) |
| @@ -966,7 +913,7 @@ static int register_uprobe_event(struct trace_uprobe *tu) · 225 unmodified lines | ||
| 966 | 913 | call->event.funcs = &uprobe_funcs; |
| 967 | 914 | call->class->define_fields = uprobe_event_define_fields; |
| 968 | 915 | |
| 969 | − if (set_print_fmt(tu) < 0) | |
| 916 | + if (set_print_fmt(&tu->tp, is_ret_probe(tu)) < 0) | |
| 970 | 917 | return -ENOMEM; |
| 971 | 918 | |
| 972 | 919 | ret = register_ftrace_event(&call->event); |