aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/probe-event.c
diff options
context:
space:
mode:
authorMasami Hiramatsu <mhiramat@redhat.com>2010-03-16 18:05:30 -0400
committerIngo Molnar <mingo@elte.hu>2010-03-17 06:32:29 -0400
commit31facc5f1ac674fbcc29f212377e589396bb934c (patch)
treeb89ad49ac394299501d247efe82c3a409f74a110 /tools/perf/util/probe-event.c
parenta1d37d5285bcda07f9c0b80a2634ca20ab545297 (diff)
perf probe: Use wrapper functions
Use wrapped functions as much as possible, to check out of memory conditions in perf probe. Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com> Cc: systemtap <systemtap@sources.redhat.com> Cc: DLE <dle-develop@lists.sourceforge.net> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> LKML-Reference: <20100316220530.32050.53951.stgit@localhost6.localdomain6> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/probe-event.c')
-rw-r--r--tools/perf/util/probe-event.c46
1 files changed, 17 insertions, 29 deletions
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 7c004b6ef24f..88a3b6d75c7c 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -33,6 +33,7 @@
33#include <limits.h> 33#include <limits.h>
34 34
35#undef _GNU_SOURCE 35#undef _GNU_SOURCE
36#include "util.h"
36#include "event.h" 37#include "event.h"
37#include "string.h" 38#include "string.h"
38#include "strlist.h" 39#include "strlist.h"
@@ -90,9 +91,9 @@ void parse_line_range_desc(const char *arg, struct line_range *lr)
90 if (*tmp != '\0') 91 if (*tmp != '\0')
91 semantic_error("Tailing with invalid character '%d'.", 92 semantic_error("Tailing with invalid character '%d'.",
92 *tmp); 93 *tmp);
93 tmp = strndup(arg, (ptr - arg)); 94 tmp = xstrndup(arg, (ptr - arg));
94 } else 95 } else
95 tmp = strdup(arg); 96 tmp = xstrdup(arg);
96 97
97 if (strchr(tmp, '.')) 98 if (strchr(tmp, '.'))
98 lr->file = tmp; 99 lr->file = tmp;
@@ -135,7 +136,7 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp)
135 if (!check_event_name(arg)) 136 if (!check_event_name(arg))
136 semantic_error("%s is bad for event name -it must " 137 semantic_error("%s is bad for event name -it must "
137 "follow C symbol-naming rule.", arg); 138 "follow C symbol-naming rule.", arg);
138 pp->event = strdup(arg); 139 pp->event = xstrdup(arg);
139 arg = tmp; 140 arg = tmp;
140 } 141 }
141 142
@@ -147,17 +148,16 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp)
147 148
148 /* Check arg is function or file and copy it */ 149 /* Check arg is function or file and copy it */
149 if (strchr(arg, '.')) /* File */ 150 if (strchr(arg, '.')) /* File */
150 pp->file = strdup(arg); 151 pp->file = xstrdup(arg);
151 else /* Function */ 152 else /* Function */
152 pp->function = strdup(arg); 153 pp->function = xstrdup(arg);
153 DIE_IF(pp->file == NULL && pp->function == NULL);
154 154
155 /* Parse other options */ 155 /* Parse other options */
156 while (ptr) { 156 while (ptr) {
157 arg = ptr; 157 arg = ptr;
158 c = nc; 158 c = nc;
159 if (c == ';') { /* Lazy pattern must be the last part */ 159 if (c == ';') { /* Lazy pattern must be the last part */
160 pp->lazy_line = strdup(arg); 160 pp->lazy_line = xstrdup(arg);
161 break; 161 break;
162 } 162 }
163 ptr = strpbrk(arg, ";:+@%"); 163 ptr = strpbrk(arg, ";:+@%");
@@ -181,8 +181,7 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp)
181 case '@': /* File name */ 181 case '@': /* File name */
182 if (pp->file) 182 if (pp->file)
183 semantic_error("SRC@SRC is not allowed."); 183 semantic_error("SRC@SRC is not allowed.");
184 pp->file = strdup(arg); 184 pp->file = xstrdup(arg);
185 DIE_IF(pp->file == NULL);
186 break; 185 break;
187 case '%': /* Probe places */ 186 case '%': /* Probe places */
188 if (strcmp(arg, "return") == 0) { 187 if (strcmp(arg, "return") == 0) {
@@ -247,11 +246,9 @@ void parse_perf_probe_event(const char *str, struct probe_point *pp,
247 246
248 /* Copy arguments and ensure return probe has no C argument */ 247 /* Copy arguments and ensure return probe has no C argument */
249 pp->nr_args = argc - 1; 248 pp->nr_args = argc - 1;
250 pp->args = zalloc(sizeof(char *) * pp->nr_args); 249 pp->args = xzalloc(sizeof(char *) * pp->nr_args);
251 for (i = 0; i < pp->nr_args; i++) { 250 for (i = 0; i < pp->nr_args; i++) {
252 pp->args[i] = strdup(argv[i + 1]); 251 pp->args[i] = xstrdup(argv[i + 1]);
253 if (!pp->args[i])
254 die("Failed to copy argument.");
255 if (is_c_varname(pp->args[i])) { 252 if (is_c_varname(pp->args[i])) {
256 if (pp->retprobe) 253 if (pp->retprobe)
257 semantic_error("You can't specify local" 254 semantic_error("You can't specify local"
@@ -299,14 +296,12 @@ void parse_trace_kprobe_event(const char *str, struct probe_point *pp)
299 pp->file = NULL; 296 pp->file = NULL;
300 297
301 pp->nr_args = argc - 2; 298 pp->nr_args = argc - 2;
302 pp->args = zalloc(sizeof(char *) * pp->nr_args); 299 pp->args = xzalloc(sizeof(char *) * pp->nr_args);
303 for (i = 0; i < pp->nr_args; i++) { 300 for (i = 0; i < pp->nr_args; i++) {
304 p = strchr(argv[i + 2], '='); 301 p = strchr(argv[i + 2], '=');
305 if (p) /* We don't need which register is assigned. */ 302 if (p) /* We don't need which register is assigned. */
306 *p = '\0'; 303 *p = '\0';
307 pp->args[i] = strdup(argv[i + 2]); 304 pp->args[i] = xstrdup(argv[i + 2]);
308 if (!pp->args[i])
309 die("Failed to copy argument.");
310 } 305 }
311 306
312 argv_free(argv); 307 argv_free(argv);
@@ -319,10 +314,8 @@ int synthesize_perf_probe_point(struct probe_point *pp)
319 char offs[64] = "", line[64] = ""; 314 char offs[64] = "", line[64] = "";
320 int ret; 315 int ret;
321 316
322 pp->probes[0] = buf = zalloc(MAX_CMDLEN); 317 pp->probes[0] = buf = xzalloc(MAX_CMDLEN);
323 pp->found = 1; 318 pp->found = 1;
324 if (!buf)
325 die("Failed to allocate memory by zalloc.");
326 if (pp->offset) { 319 if (pp->offset) {
327 ret = e_snprintf(offs, 64, "+%d", pp->offset); 320 ret = e_snprintf(offs, 64, "+%d", pp->offset);
328 if (ret <= 0) 321 if (ret <= 0)
@@ -380,9 +373,7 @@ int synthesize_trace_kprobe_event(struct probe_point *pp)
380 char *buf; 373 char *buf;
381 int i, len, ret; 374 int i, len, ret;
382 375
383 pp->probes[0] = buf = zalloc(MAX_CMDLEN); 376 pp->probes[0] = buf = xzalloc(MAX_CMDLEN);
384 if (!buf)
385 die("Failed to allocate memory by zalloc.");
386 ret = e_snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset); 377 ret = e_snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset);
387 if (ret <= 0) 378 if (ret <= 0)
388 goto error; 379 goto error;
@@ -612,10 +603,9 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes,
612 for (j = 0; j < nr_probes; j++) { 603 for (j = 0; j < nr_probes; j++) {
613 pp = probes + j; 604 pp = probes + j;
614 if (!pp->event) 605 if (!pp->event)
615 pp->event = strdup(pp->function); 606 pp->event = xstrdup(pp->function);
616 if (!pp->group) 607 if (!pp->group)
617 pp->group = strdup(PERFPROBE_GROUP); 608 pp->group = xstrdup(PERFPROBE_GROUP);
618 DIE_IF(!pp->event || !pp->group);
619 /* If force_add is true, suffix search is allowed */ 609 /* If force_add is true, suffix search is allowed */
620 allow_suffix = force_add; 610 allow_suffix = force_add;
621 for (i = 0; i < pp->found; i++) { 611 for (i = 0; i < pp->found; i++) {
@@ -709,9 +699,7 @@ void del_trace_kprobe_events(struct strlist *dellist)
709 namelist = get_perf_event_names(fd, true); 699 namelist = get_perf_event_names(fd, true);
710 700
711 strlist__for_each(ent, dellist) { 701 strlist__for_each(ent, dellist) {
712 str = strdup(ent->s); 702 str = xstrdup(ent->s);
713 if (!str)
714 die("Failed to copy event.");
715 pr_debug("Parsing: %s\n", str); 703 pr_debug("Parsing: %s\n", str);
716 p = strchr(str, ':'); 704 p = strchr(str, ':');
717 if (p) { 705 if (p) {