diff options
author | Irina Tirdea <irina.tirdea@intel.com> | 2012-09-20 16:37:50 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-24 10:49:31 -0400 |
commit | bcbd004020bf0d725722be75da35fd326ff63ef4 (patch) | |
tree | 82510369c7a6583b40a7d81d2ff4bbab6f835804 | |
parent | 37e9d750e672d6fa8c25463bd76240410bbbc786 (diff) |
perf tools: remove sscanf extension %as
perf uses sscanf extension %as to read and allocate a string in the same
step. This is a non-standard extension only present in new versions of
glibc.
Replacing the use of sscanf and %as with strtok_r calls in order to
parse a given string into its components. This is needed in Android
since bionic does not support
%as extension for sscanf.
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1348173470-4936-1-git-send-email-irina.tirdea@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/probe-event.c | 36 | ||||
-rw-r--r-- | tools/perf/util/trace-event-parse.c | 18 |
2 files changed, 37 insertions, 17 deletions
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 4ce04c2281d3..49a256e6e0a2 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
@@ -1100,6 +1100,7 @@ static int parse_probe_trace_command(const char *cmd, | |||
1100 | struct probe_trace_point *tp = &tev->point; | 1100 | struct probe_trace_point *tp = &tev->point; |
1101 | char pr; | 1101 | char pr; |
1102 | char *p; | 1102 | char *p; |
1103 | char *argv0_str = NULL, *fmt, *fmt1_str, *fmt2_str, *fmt3_str; | ||
1103 | int ret, i, argc; | 1104 | int ret, i, argc; |
1104 | char **argv; | 1105 | char **argv; |
1105 | 1106 | ||
@@ -1116,14 +1117,27 @@ static int parse_probe_trace_command(const char *cmd, | |||
1116 | } | 1117 | } |
1117 | 1118 | ||
1118 | /* Scan event and group name. */ | 1119 | /* Scan event and group name. */ |
1119 | ret = sscanf(argv[0], "%c:%a[^/ \t]/%a[^ \t]", | 1120 | argv0_str = strdup(argv[0]); |
1120 | &pr, (float *)(void *)&tev->group, | 1121 | if (argv0_str == NULL) { |
1121 | (float *)(void *)&tev->event); | 1122 | ret = -ENOMEM; |
1122 | if (ret != 3) { | 1123 | goto out; |
1124 | } | ||
1125 | fmt1_str = strtok_r(argv0_str, ":", &fmt); | ||
1126 | fmt2_str = strtok_r(NULL, "/", &fmt); | ||
1127 | fmt3_str = strtok_r(NULL, " \t", &fmt); | ||
1128 | if (fmt1_str == NULL || strlen(fmt1_str) != 1 || fmt2_str == NULL | ||
1129 | || fmt3_str == NULL) { | ||
1123 | semantic_error("Failed to parse event name: %s\n", argv[0]); | 1130 | semantic_error("Failed to parse event name: %s\n", argv[0]); |
1124 | ret = -EINVAL; | 1131 | ret = -EINVAL; |
1125 | goto out; | 1132 | goto out; |
1126 | } | 1133 | } |
1134 | pr = fmt1_str[0]; | ||
1135 | tev->group = strdup(fmt2_str); | ||
1136 | tev->event = strdup(fmt3_str); | ||
1137 | if (tev->group == NULL || tev->event == NULL) { | ||
1138 | ret = -ENOMEM; | ||
1139 | goto out; | ||
1140 | } | ||
1127 | pr_debug("Group:%s Event:%s probe:%c\n", tev->group, tev->event, pr); | 1141 | pr_debug("Group:%s Event:%s probe:%c\n", tev->group, tev->event, pr); |
1128 | 1142 | ||
1129 | tp->retprobe = (pr == 'r'); | 1143 | tp->retprobe = (pr == 'r'); |
@@ -1135,10 +1149,17 @@ static int parse_probe_trace_command(const char *cmd, | |||
1135 | p++; | 1149 | p++; |
1136 | } else | 1150 | } else |
1137 | p = argv[1]; | 1151 | p = argv[1]; |
1138 | ret = sscanf(p, "%a[^+]+%lu", (float *)(void *)&tp->symbol, | 1152 | fmt1_str = strtok_r(p, "+", &fmt); |
1139 | &tp->offset); | 1153 | tp->symbol = strdup(fmt1_str); |
1140 | if (ret == 1) | 1154 | if (tp->symbol == NULL) { |
1155 | ret = -ENOMEM; | ||
1156 | goto out; | ||
1157 | } | ||
1158 | fmt2_str = strtok_r(NULL, "", &fmt); | ||
1159 | if (fmt2_str == NULL) | ||
1141 | tp->offset = 0; | 1160 | tp->offset = 0; |
1161 | else | ||
1162 | tp->offset = strtoul(fmt2_str, NULL, 10); | ||
1142 | 1163 | ||
1143 | tev->nargs = argc - 2; | 1164 | tev->nargs = argc - 2; |
1144 | tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs); | 1165 | tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs); |
@@ -1162,6 +1183,7 @@ static int parse_probe_trace_command(const char *cmd, | |||
1162 | } | 1183 | } |
1163 | ret = 0; | 1184 | ret = 0; |
1164 | out: | 1185 | out: |
1186 | free(argv0_str); | ||
1165 | argv_free(argv); | 1187 | argv_free(argv); |
1166 | return ret; | 1188 | return ret; |
1167 | } | 1189 | } |
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c index aa4c860a21d1..3aabcd687cd5 100644 --- a/tools/perf/util/trace-event-parse.c +++ b/tools/perf/util/trace-event-parse.c | |||
@@ -229,24 +229,22 @@ void parse_proc_kallsyms(struct pevent *pevent, | |||
229 | char *next = NULL; | 229 | char *next = NULL; |
230 | char *addr_str; | 230 | char *addr_str; |
231 | char *mod; | 231 | char *mod; |
232 | char ch; | 232 | char *fmt; |
233 | 233 | ||
234 | line = strtok_r(file, "\n", &next); | 234 | line = strtok_r(file, "\n", &next); |
235 | while (line) { | 235 | while (line) { |
236 | mod = NULL; | 236 | mod = NULL; |
237 | sscanf(line, "%as %c %as\t[%as", | 237 | addr_str = strtok_r(line, " ", &fmt); |
238 | (float *)(void *)&addr_str, /* workaround gcc warning */ | ||
239 | &ch, (float *)(void *)&func, (float *)(void *)&mod); | ||
240 | addr = strtoull(addr_str, NULL, 16); | 238 | addr = strtoull(addr_str, NULL, 16); |
241 | free(addr_str); | 239 | /* skip character */ |
242 | 240 | strtok_r(NULL, " ", &fmt); | |
243 | /* truncate the extra ']' */ | 241 | func = strtok_r(NULL, "\t", &fmt); |
242 | mod = strtok_r(NULL, "]", &fmt); | ||
243 | /* truncate the extra '[' */ | ||
244 | if (mod) | 244 | if (mod) |
245 | mod[strlen(mod) - 1] = 0; | 245 | mod = mod + 1; |
246 | 246 | ||
247 | pevent_register_function(pevent, func, addr, mod); | 247 | pevent_register_function(pevent, func, addr, mod); |
248 | free(func); | ||
249 | free(mod); | ||
250 | 248 | ||
251 | line = strtok_r(NULL, "\n", &next); | 249 | line = strtok_r(NULL, "\n", &next); |
252 | } | 250 | } |